debian-mirror-gitlab/spec/frontend/authentication/webauthn/error_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-10-27 15:23:28 +05:30
import setWindowLocation from 'helpers/set_window_location_helper';
2020-11-24 15:15:51 +05:30
import WebAuthnError from '~/authentication/webauthn/error';
2023-05-27 22:25:52 +05:30
import { WEBAUTHN_AUTHENTICATE, WEBAUTHN_REGISTER } from '~/authentication/webauthn/constants';
2020-11-24 15:15:51 +05:30
describe('WebAuthnError', () => {
it.each([
[
'NotSupportedError',
'Your device is not compatible with GitLab. Please try another device',
2023-05-27 22:25:52 +05:30
WEBAUTHN_AUTHENTICATE,
2020-11-24 15:15:51 +05:30
],
2023-05-27 22:25:52 +05:30
['InvalidStateError', 'This device has not been registered with us.', WEBAUTHN_AUTHENTICATE],
['InvalidStateError', 'This device has already been registered with us.', WEBAUTHN_REGISTER],
['UnknownError', 'There was a problem communicating with your device.', WEBAUTHN_REGISTER],
2020-11-24 15:15:51 +05:30
])('exception %s will have message %s, flow type: %s', (exception, expectedMessage, flowType) => {
expect(new WebAuthnError(new DOMException('', exception), flowType).message()).toEqual(
expectedMessage,
);
});
describe('SecurityError', () => {
it('returns a descriptive error if https is disabled', () => {
2021-10-27 15:23:28 +05:30
setWindowLocation('http://localhost');
2020-11-24 15:15:51 +05:30
const expectedMessage =
'WebAuthn only works with HTTPS-enabled websites. Contact your administrator for more details.';
expect(
2023-05-27 22:25:52 +05:30
new WebAuthnError(new DOMException('', 'SecurityError'), WEBAUTHN_AUTHENTICATE).message(),
2020-11-24 15:15:51 +05:30
).toEqual(expectedMessage);
});
it('returns a generic error if https is enabled', () => {
2021-10-27 15:23:28 +05:30
setWindowLocation('https://localhost');
2020-11-24 15:15:51 +05:30
const expectedMessage = 'There was a problem communicating with your device.';
expect(
2023-05-27 22:25:52 +05:30
new WebAuthnError(new DOMException('', 'SecurityError'), WEBAUTHN_AUTHENTICATE).message(),
2020-11-24 15:15:51 +05:30
).toEqual(expectedMessage);
});
});
});