Commit 73847e4e authored by Paul Gascou-Vaillancourt's avatar Paul Gascou-Vaillancourt Committed by Paul Gascou-Vaillancourt

Initialize the challenge if the username check fails

parent ba4e9659
...@@ -112,9 +112,14 @@ export default { ...@@ -112,9 +112,14 @@ export default {
await this.initArkoseLabs(); await this.initArkoseLabs();
} }
} catch (e) { } catch (e) {
// If the requests fails with a 404 code, we can fail silently. if (e.response?.status === 404) {
// We show a generic error message for any other failure. // We ignore 404 errors as it just means the username does not exist.
if (e.response?.status !== 404) { } else if (e.response?.status) {
// If the request failed with any other error code, we initialize the challenge to make
// sure it isn't being bypassed by purposefully making the endpoint fail.
this.initArkoseLabs();
} else {
// For any other failure, we show the initialization error message.
this.handleArkoseLabsFailure(e); this.handleArkoseLabsFailure(e);
} }
} finally { } finally {
......
...@@ -214,16 +214,41 @@ describe('SignInArkoseApp', () => { ...@@ -214,16 +214,41 @@ describe('SignInArkoseApp', () => {
}); });
}); });
describe('when the REST endpoint fails', () => { describe('when the username check fails', () => {
beforeEach(async () => { beforeEach(async () => {
jest.spyOn(console, 'error').mockImplementation(() => {}); jest.spyOn(console, 'error').mockImplementation(() => {});
});
it('with a 404, nothing happens', async () => {
axiosMock.onGet().reply(404);
initArkoseLabs(MOCK_USERNAME);
await waitForPromises();
expect(initArkoseLabsScript).not.toHaveBeenCalled();
expectHiddenArkoseLabsError();
});
it('with some other HTTP error, the challenge is initialized', async () => {
axiosMock.onGet().reply(500); axiosMock.onGet().reply(500);
initArkoseLabs(MOCK_USERNAME); initArkoseLabs(MOCK_USERNAME);
await waitForPromises(); await waitForPromises();
expect(initArkoseLabsScript).toHaveBeenCalled();
expectHiddenArkoseLabsError();
});
it('due to the script inclusion, an error is shown', async () => {
const error = new Error();
initArkoseLabsScript.mockImplementation(() => {
throw new Error();
}); });
axiosMock.onGet().reply(200, { result: true });
initArkoseLabs(MOCK_USERNAME);
await waitForPromises();
it('shows initialization error', () => {
expectArkoseLabsInitError(); expectArkoseLabsInitError();
// eslint-disable-next-line no-console
expect(console.error).toHaveBeenCalledWith('ArkoseLabs initialization error', error);
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment