diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-03 15:10:00 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-03 15:10:00 +0300 |
commit | 14a32c2d551a646525b1fabd93cb70a0e6924478 (patch) | |
tree | 782ba91ba786aee2cda379704e7f2ebcb5b46748 /spec/frontend | |
parent | 11c2f3b08c3bab4718a97360d1502f90793d028b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/authentication/u2f/authenticate_spec.js | 104 | ||||
-rw-r--r-- | spec/frontend/authentication/u2f/mock_u2f_device.js | 23 | ||||
-rw-r--r-- | spec/frontend/authentication/u2f/register_spec.js | 84 | ||||
-rw-r--r-- | spec/frontend/authentication/u2f/util_spec.js | 61 | ||||
-rw-r--r-- | spec/frontend/fixtures/u2f.rb | 48 |
5 files changed, 0 insertions, 320 deletions
diff --git a/spec/frontend/authentication/u2f/authenticate_spec.js b/spec/frontend/authentication/u2f/authenticate_spec.js deleted file mode 100644 index 3ae7fcf1c49..00000000000 --- a/spec/frontend/authentication/u2f/authenticate_spec.js +++ /dev/null @@ -1,104 +0,0 @@ -import $ from 'jquery'; -import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; -import U2FAuthenticate from '~/authentication/u2f/authenticate'; -import 'vendor/u2f'; -import MockU2FDevice from './mock_u2f_device'; - -describe('U2FAuthenticate', () => { - let u2fDevice; - let container; - let component; - - beforeEach(() => { - loadHTMLFixture('u2f/authenticate.html'); - u2fDevice = new MockU2FDevice(); - container = $('#js-authenticate-token-2fa'); - component = new U2FAuthenticate( - container, - '#js-login-token-2fa-form', - { - sign_requests: [], - }, - document.querySelector('#js-login-2fa-device'), - document.querySelector('.js-2fa-form'), - ); - }); - - afterEach(() => { - resetHTMLFixture(); - }); - - describe('with u2f unavailable', () => { - let oldu2f; - - beforeEach(() => { - jest.spyOn(component, 'switchToFallbackUI').mockImplementation(() => {}); - oldu2f = window.u2f; - window.u2f = null; - }); - - afterEach(() => { - window.u2f = oldu2f; - }); - - it('falls back to normal 2fa', async () => { - await component.start(); - expect(component.switchToFallbackUI).toHaveBeenCalled(); - }); - }); - - describe('with u2f available', () => { - beforeEach(() => { - // bypass automatic form submission within renderAuthenticated - jest.spyOn(component, 'renderAuthenticated').mockReturnValue(true); - u2fDevice = new MockU2FDevice(); - - return component.start(); - }); - - it('allows authenticating via a U2F device', () => { - const inProgressMessage = container.find('p'); - - expect(inProgressMessage.text()).toContain('Trying to communicate with your device'); - u2fDevice.respondToAuthenticateRequest({ - deviceData: 'this is data from the device', - }); - - expect(component.renderAuthenticated).toHaveBeenCalledWith( - '{"deviceData":"this is data from the device"}', - ); - }); - - describe('errors', () => { - it('displays an error message', () => { - const setupButton = container.find('#js-login-2fa-device'); - setupButton.trigger('click'); - u2fDevice.respondToAuthenticateRequest({ - errorCode: 'error!', - }); - const errorMessage = container.find('p'); - - expect(errorMessage.text()).toContain('There was a problem communicating with your device'); - }); - - it('allows retrying authentication after an error', () => { - let setupButton = container.find('#js-login-2fa-device'); - setupButton.trigger('click'); - u2fDevice.respondToAuthenticateRequest({ - errorCode: 'error!', - }); - const retryButton = container.find('#js-token-2fa-try-again'); - retryButton.trigger('click'); - setupButton = container.find('#js-login-2fa-device'); - setupButton.trigger('click'); - u2fDevice.respondToAuthenticateRequest({ - deviceData: 'this is data from the device', - }); - - expect(component.renderAuthenticated).toHaveBeenCalledWith( - '{"deviceData":"this is data from the device"}', - ); - }); - }); - }); -}); diff --git a/spec/frontend/authentication/u2f/mock_u2f_device.js b/spec/frontend/authentication/u2f/mock_u2f_device.js deleted file mode 100644 index ec8425a4e3e..00000000000 --- a/spec/frontend/authentication/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/frontend/authentication/u2f/register_spec.js b/spec/frontend/authentication/u2f/register_spec.js deleted file mode 100644 index 23d1e5c7dee..00000000000 --- a/spec/frontend/authentication/u2f/register_spec.js +++ /dev/null @@ -1,84 +0,0 @@ -import $ from 'jquery'; -import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; -import { trimText } from 'helpers/text_helper'; -import U2FRegister from '~/authentication/u2f/register'; -import 'vendor/u2f'; -import MockU2FDevice from './mock_u2f_device'; - -describe('U2FRegister', () => { - let u2fDevice; - let container; - let component; - - beforeEach(() => { - loadHTMLFixture('u2f/register.html'); - u2fDevice = new MockU2FDevice(); - container = $('#js-register-token-2fa'); - component = new U2FRegister(container, {}); - return component.start(); - }); - - afterEach(() => { - resetHTMLFixture(); - }); - - it('allows registering a U2F device', () => { - const setupButton = container.find('#js-setup-token-2fa-device'); - - expect(trimText(setupButton.text())).toBe('Set up new device'); - setupButton.trigger('click'); - const inProgressMessage = container.children('p'); - - expect(inProgressMessage.text()).toContain('Trying to communicate with your device'); - u2fDevice.respondToRegisterRequest({ - deviceData: 'this is data from the device', - }); - const registeredMessage = container.find('p'); - const deviceResponse = 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 = container.find('#js-setup-token-2fa-device'); - setupButton.trigger('click'); - u2fDevice.respondToRegisterRequest({ - errorCode: 4, - }); - const errorMessage = container.find('p'); - - expect(errorMessage.text()).toContain('already been registered with us'); - }); - - it('displays an error message for other errors', () => { - const setupButton = container.find('#js-setup-token-2fa-device'); - setupButton.trigger('click'); - u2fDevice.respondToRegisterRequest({ - errorCode: 'error!', - }); - const errorMessage = container.find('p'); - - expect(errorMessage.text()).toContain('There was a problem communicating with your device'); - }); - - it('allows retrying registration after an error', () => { - let setupButton = container.find('#js-setup-token-2fa-device'); - setupButton.trigger('click'); - u2fDevice.respondToRegisterRequest({ - errorCode: 'error!', - }); - const retryButton = container.find('#js-token-2fa-try-again'); - retryButton.trigger('click'); - setupButton = container.find('#js-setup-token-2fa-device'); - setupButton.trigger('click'); - u2fDevice.respondToRegisterRequest({ - deviceData: 'this is data from the device', - }); - const registeredMessage = container.find('p'); - - expect(registeredMessage.text()).toContain('Your device was successfully set up!'); - }); - }); -}); diff --git a/spec/frontend/authentication/u2f/util_spec.js b/spec/frontend/authentication/u2f/util_spec.js deleted file mode 100644 index 67fd4c73243..00000000000 --- a/spec/frontend/authentication/u2f/util_spec.js +++ /dev/null @@ -1,61 +0,0 @@ -import { canInjectU2fApi } from '~/authentication/u2f/util'; - -describe('U2F Utils', () => { - describe('canInjectU2fApi', () => { - it('returns false for Chrome < 41', () => { - const userAgent = - 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.28 Safari/537.36'; - - expect(canInjectU2fApi(userAgent)).toBe(false); - }); - - it('returns true for Chrome >= 41', () => { - const userAgent = - 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'; - - expect(canInjectU2fApi(userAgent)).toBe(true); - }); - - it('returns false for Opera < 40', () => { - const userAgent = - 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36 OPR/32.0.1948.25'; - - expect(canInjectU2fApi(userAgent)).toBe(false); - }); - - it('returns true for Opera >= 40', () => { - const userAgent = - 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 OPR/43.0.2442.991'; - - expect(canInjectU2fApi(userAgent)).toBe(true); - }); - - it('returns false for Safari', () => { - const userAgent = - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4'; - - expect(canInjectU2fApi(userAgent)).toBe(false); - }); - - it('returns false for Chrome on Android', () => { - const userAgent = - 'Mozilla/5.0 (Linux; Android 7.0; VS988 Build/NRD90U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3145.0 Mobile Safari/537.36'; - - expect(canInjectU2fApi(userAgent)).toBe(false); - }); - - it('returns false for Chrome on iOS', () => { - const userAgent = - 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1'; - - expect(canInjectU2fApi(userAgent)).toBe(false); - }); - - it('returns false for Safari on iOS', () => { - const userAgent = - 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A356 Safari/604.1'; - - expect(canInjectU2fApi(userAgent)).toBe(false); - }); - }); -}); diff --git a/spec/frontend/fixtures/u2f.rb b/spec/frontend/fixtures/u2f.rb deleted file mode 100644 index 96820c9ae80..00000000000 --- a/spec/frontend/fixtures/u2f.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.context 'U2F' do - include JavaScriptFixturesHelpers - - let(:user) { create(:user, :two_factor_via_u2f, otp_secret: 'otpsecret:coolkids') } - - before do - stub_feature_flags(webauthn: false) - end - - describe SessionsController, '(JavaScript fixtures)', type: :controller do - include DeviseHelpers - - render_views - - before do - set_devise_mapping(context: @request) - end - - it 'u2f/authenticate.html' do - allow(controller).to receive(:find_user).and_return(user) - - post :create, params: { user: { login: user.username, password: user.password } } - - expect(response).to be_successful - end - end - - describe Profiles::TwoFactorAuthsController, '(JavaScript fixtures)', type: :controller do - render_views - - before do - sign_in(user) - allow_next_instance_of(Profiles::TwoFactorAuthsController) do |instance| - allow(instance).to receive(:build_qr_code).and_return('qrcode:blackandwhitesquares') - end - end - - it 'u2f/register.html' do - get :show - - expect(response).to be_successful - end - end -end |