diff options
Diffstat (limited to 'spec/frontend/authentication/webauthn')
-rw-r--r-- | spec/frontend/authentication/webauthn/error_spec.js | 16 | ||||
-rw-r--r-- | spec/frontend/authentication/webauthn/register_spec.js | 8 |
2 files changed, 6 insertions, 18 deletions
diff --git a/spec/frontend/authentication/webauthn/error_spec.js b/spec/frontend/authentication/webauthn/error_spec.js index 26f1ca5e27d..9b71f77dde2 100644 --- a/spec/frontend/authentication/webauthn/error_spec.js +++ b/spec/frontend/authentication/webauthn/error_spec.js @@ -1,3 +1,4 @@ +import setWindowLocation from 'helpers/set_window_location_helper'; import WebAuthnError from '~/authentication/webauthn/error'; describe('WebAuthnError', () => { @@ -17,19 +18,8 @@ describe('WebAuthnError', () => { }); describe('SecurityError', () => { - const { location } = window; - - beforeEach(() => { - delete window.location; - window.location = {}; - }); - - afterEach(() => { - window.location = location; - }); - it('returns a descriptive error if https is disabled', () => { - window.location.protocol = 'http:'; + setWindowLocation('http://localhost'); const expectedMessage = 'WebAuthn only works with HTTPS-enabled websites. Contact your administrator for more details.'; @@ -39,7 +29,7 @@ describe('WebAuthnError', () => { }); it('returns a generic error if https is enabled', () => { - window.location.protocol = 'https:'; + setWindowLocation('https://localhost'); const expectedMessage = 'There was a problem communicating with your device.'; expect( diff --git a/spec/frontend/authentication/webauthn/register_spec.js b/spec/frontend/authentication/webauthn/register_spec.js index 43cd3d7ca34..0f8ea2b635f 100644 --- a/spec/frontend/authentication/webauthn/register_spec.js +++ b/spec/frontend/authentication/webauthn/register_spec.js @@ -1,4 +1,5 @@ import $ from 'jquery'; +import setWindowLocation from 'helpers/set_window_location_helper'; import waitForPromises from 'helpers/wait_for_promises'; import WebAuthnRegister from '~/authentication/webauthn/register'; import MockWebAuthnDevice from './mock_webauthn_device'; @@ -50,17 +51,14 @@ describe('WebAuthnRegister', () => { }); describe('when unsupported', () => { - const { location, PublicKeyCredential } = window; + const { PublicKeyCredential } = window; beforeEach(() => { - delete window.location; delete window.credentials; - window.location = {}; window.PublicKeyCredential = undefined; }); afterEach(() => { - window.location = location; window.PublicKeyCredential = PublicKeyCredential; }); @@ -69,7 +67,7 @@ describe('WebAuthnRegister', () => { ${false} | ${'WebAuthn only works with HTTPS-enabled websites'} ${true} | ${'Please use a supported browser, e.g. Chrome (67+) or Firefox'} `('when https is $httpsEnabled', ({ httpsEnabled, expectedText }) => { - window.location.protocol = httpsEnabled ? 'https:' : 'http:'; + setWindowLocation(`${httpsEnabled ? 'https:' : 'http:'}//localhost`); component.start(); expect(findMessage().text()).toContain(expectedText); |