diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-24 09:09:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-24 09:09:25 +0000 |
commit | 6f7881ee9dcec34141a8f34fc814b56b366d2b48 (patch) | |
tree | 25f72a06874b32b1049b79a9d7f4f1b7bca43b9b /spec/javascripts | |
parent | 8c8bf44fa64f98114f7439f751c92d59a44b3218 (diff) | |
download | gitlab-ce-6f7881ee9dcec34141a8f34fc814b56b366d2b48.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/javascripts')
-rw-r--r-- | spec/javascripts/u2f/authenticate_spec.js | 102 | ||||
-rw-r--r-- | spec/javascripts/u2f/mock_u2f_device.js | 23 | ||||
-rw-r--r-- | spec/javascripts/u2f/register_spec.js | 79 |
3 files changed, 0 insertions, 204 deletions
diff --git a/spec/javascripts/u2f/authenticate_spec.js b/spec/javascripts/u2f/authenticate_spec.js deleted file mode 100644 index 8f9cb270729..00000000000 --- a/spec/javascripts/u2f/authenticate_spec.js +++ /dev/null @@ -1,102 +0,0 @@ -import $ from 'jquery'; -import U2FAuthenticate from '~/u2f/authenticate'; -import 'vendor/u2f'; -import MockU2FDevice from './mock_u2f_device'; - -describe('U2FAuthenticate', function() { - preloadFixtures('u2f/authenticate.html'); - - beforeEach(() => { - loadFixtures('u2f/authenticate.html'); - this.u2fDevice = new MockU2FDevice(); - this.container = $('#js-authenticate-u2f'); - this.component = new U2FAuthenticate( - this.container, - '#js-login-u2f-form', - { - sign_requests: [], - }, - document.querySelector('#js-login-2fa-device'), - document.querySelector('.js-2fa-form'), - ); - }); - - describe('with u2f unavailable', () => { - beforeEach(() => { - spyOn(this.component, 'switchToFallbackUI'); - this.oldu2f = window.u2f; - window.u2f = null; - }); - - afterEach(() => { - window.u2f = this.oldu2f; - }); - - it('falls back to normal 2fa', done => { - this.component - .start() - .then(() => { - expect(this.component.switchToFallbackUI).toHaveBeenCalled(); - done(); - }) - .catch(done.fail); - }); - }); - - describe('with u2f available', () => { - beforeEach(done => { - // bypass automatic form submission within renderAuthenticated - spyOn(this.component, 'renderAuthenticated').and.returnValue(true); - this.u2fDevice = new MockU2FDevice(); - - this.component - .start() - .then(done) - .catch(done.fail); - }); - - it('allows authenticating via a U2F device', () => { - const inProgressMessage = this.container.find('p'); - - expect(inProgressMessage.text()).toContain('Trying to communicate with your device'); - this.u2fDevice.respondToAuthenticateRequest({ - deviceData: 'this is data from the device', - }); - - expect(this.component.renderAuthenticated).toHaveBeenCalledWith( - '{"deviceData":"this is data from the device"}', - ); - }); - - describe('errors', () => { - it('displays an error message', () => { - const setupButton = this.container.find('#js-login-u2f-device'); - setupButton.trigger('click'); - this.u2fDevice.respondToAuthenticateRequest({ - errorCode: 'error!', - }); - const errorMessage = this.container.find('p'); - - expect(errorMessage.text()).toContain('There was a problem communicating with your device'); - }); - return it('allows retrying authentication after an error', () => { - let setupButton = this.container.find('#js-login-u2f-device'); - setupButton.trigger('click'); - this.u2fDevice.respondToAuthenticateRequest({ - errorCode: 'error!', - }); - const retryButton = this.container.find('#js-u2f-try-again'); - retryButton.trigger('click'); - setupButton = this.container.find('#js-login-u2f-device'); - setupButton.trigger('click'); - this.u2fDevice.respondToAuthenticateRequest({ - deviceData: 'this is data from the device', - }); - - expect(this.component.renderAuthenticated).toHaveBeenCalledWith( - '{"deviceData":"this is data from the device"}', - ); - }); - }); - }); -}); diff --git a/spec/javascripts/u2f/mock_u2f_device.js b/spec/javascripts/u2f/mock_u2f_device.js deleted file mode 100644 index ec8425a4e3e..00000000000 --- a/spec/javascripts/u2f/mock_u2f_device.js +++ /dev/null @@ -1,23 +0,0 @@ -/* eslint-disable no-unused-expressions */ - -export default class MockU2FDevice { - constructor() { - this.respondToAuthenticateRequest = this.respondToAuthenticateRequest.bind(this); - this.respondToRegisterRequest = this.respondToRegisterRequest.bind(this); - window.u2f || (window.u2f = {}); - window.u2f.register = (appId, registerRequests, signRequests, callback) => { - this.registerCallback = callback; - }; - window.u2f.sign = (appId, challenges, signRequests, callback) => { - this.authenticateCallback = callback; - }; - } - - respondToRegisterRequest(params) { - return this.registerCallback(params); - } - - respondToAuthenticateRequest(params) { - return this.authenticateCallback(params); - } -} diff --git a/spec/javascripts/u2f/register_spec.js b/spec/javascripts/u2f/register_spec.js deleted file mode 100644 index a75ceca9f4c..00000000000 --- a/spec/javascripts/u2f/register_spec.js +++ /dev/null @@ -1,79 +0,0 @@ -import $ from 'jquery'; -import U2FRegister from '~/u2f/register'; -import 'vendor/u2f'; -import MockU2FDevice from './mock_u2f_device'; - -describe('U2FRegister', function() { - preloadFixtures('u2f/register.html'); - - beforeEach(done => { - loadFixtures('u2f/register.html'); - this.u2fDevice = new MockU2FDevice(); - this.container = $('#js-register-u2f'); - this.component = new U2FRegister(this.container, $('#js-register-u2f-templates'), {}, 'token'); - this.component - .start() - .then(done) - .catch(done.fail); - }); - - it('allows registering a U2F device', () => { - const setupButton = this.container.find('#js-setup-u2f-device'); - - expect(setupButton.text()).toBe('Set up new U2F device'); - setupButton.trigger('click'); - const inProgressMessage = this.container.children('p'); - - expect(inProgressMessage.text()).toContain('Trying to communicate with your device'); - this.u2fDevice.respondToRegisterRequest({ - deviceData: 'this is data from the device', - }); - const registeredMessage = this.container.find('p'); - const deviceResponse = this.container.find('#js-device-response'); - - expect(registeredMessage.text()).toContain('Your device was successfully set up!'); - expect(deviceResponse.val()).toBe('{"deviceData":"this is data from the device"}'); - }); - - describe('errors', () => { - it("doesn't allow the same device to be registered twice (for the same user", () => { - const setupButton = this.container.find('#js-setup-u2f-device'); - setupButton.trigger('click'); - this.u2fDevice.respondToRegisterRequest({ - errorCode: 4, - }); - const errorMessage = this.container.find('p'); - - expect(errorMessage.text()).toContain('already been registered with us'); - }); - - it('displays an error message for other errors', () => { - const setupButton = this.container.find('#js-setup-u2f-device'); - setupButton.trigger('click'); - this.u2fDevice.respondToRegisterRequest({ - errorCode: 'error!', - }); - const errorMessage = this.container.find('p'); - - expect(errorMessage.text()).toContain('There was a problem communicating with your device'); - }); - - it('allows retrying registration after an error', () => { - let setupButton = this.container.find('#js-setup-u2f-device'); - setupButton.trigger('click'); - this.u2fDevice.respondToRegisterRequest({ - errorCode: 'error!', - }); - const retryButton = this.container.find('#U2FTryAgain'); - retryButton.trigger('click'); - setupButton = this.container.find('#js-setup-u2f-device'); - setupButton.trigger('click'); - this.u2fDevice.respondToRegisterRequest({ - deviceData: 'this is data from the device', - }); - const registeredMessage = this.container.find('p'); - - expect(registeredMessage.text()).toContain('Your device was successfully set up!'); - }); - }); -}); |