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 {
await this.initArkoseLabs();
}
} catch (e) {
// If the requests fails with a 404 code, we can fail silently.
// We show a generic error message for any other failure.
if (e.response?.status !== 404) {
if (e.response?.status === 404) {
// We ignore 404 errors as it just means the username does not exist.
} 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);
}
} finally {
......
......@@ -214,16 +214,41 @@ describe('SignInArkoseApp', () => {
});
});
describe('when the REST endpoint fails', () => {
describe('when the username check fails', () => {
beforeEach(async () => {
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);
initArkoseLabs(MOCK_USERNAME);
await waitForPromises();
expect(initArkoseLabsScript).toHaveBeenCalled();
expectHiddenArkoseLabsError();
});
it('shows initialization error', () => {
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();
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