SDA-3592 Prevent redirection on form submission (#1365)

This commit is contained in:
Salah Benmoussati 2022-04-07 10:38:02 +02:00 committed by GitHub
parent 43df94f828
commit 5ce8544273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 6 deletions

View File

@ -33,12 +33,13 @@ describe('basic auth', () => {
});
it('should call submit login', () => {
const fakeEvent = { preventDefault: () => {} };
const { ipcRenderer } = require('./__mocks__/electron');
const spy: jest.SpyInstance = jest.spyOn(ipcRenderer, 'send');
const wrapper: ShallowWrapper = shallow(React.createElement(BasicAuth));
wrapper.find('#username').simulate('change', usernameTargetMock);
wrapper.find('#password').simulate('change', passwordTargetMock);
wrapper.find('#basicAuth').simulate('submit');
wrapper.find('#basicAuth').simulate('submit', fakeEvent);
expect(spy).lastCalledWith('basic-auth-login', {
...usernameMock,
...passwordMock,

View File

@ -1493,13 +1493,20 @@ export class WindowHandler {
{
width: 360,
height: isMac ? 270 : 295,
alwaysOnTop: true,
skipTaskbar: true,
resizable: false,
show: false,
modal: true,
autoHideMenuBar: true,
resizable: false,
frame: false,
transparent: true,
fullscreenable: false,
acceptFirstMouse: true,
},
{
devTools: isDevEnv,
sandbox: IS_SAND_BOXED,
nodeIntegration: IS_NODE_INTEGRATION_ENABLED,
devTools: true,
},
);
opts.parent = window;

View File

@ -19,7 +19,7 @@ const BASIC_AUTH_NAMESPACE = 'BasicAuth';
export default class BasicAuth extends React.Component<{}, IState> {
private readonly eventHandlers = {
onChange: (event) => this.change(event),
onSubmit: () => this.submit(),
onSubmit: (event) => this.submit(event),
onClose: () => this.close(),
};
@ -140,7 +140,8 @@ export default class BasicAuth extends React.Component<{}, IState> {
/**
* Submits the form with provided username and password info
*/
private submit(): void {
private submit(event): void {
event.preventDefault();
const { username, password } = this.state;
if (username && password) {
ipcRenderer.send('basic-auth-login', { username, password });