diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 09:16:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 09:16:11 +0000 |
commit | edaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch) | |
tree | 11f143effbfeba52329fb7afbd05e6e2a3790241 /spec/frontend/profile | |
parent | d8a5691316400a0f7ec4f83832698f1988eb27c1 (diff) | |
download | gitlab-ce-edaa33dee2ff2f7ea3fac488d41558eb5f86d68c.tar.gz |
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'spec/frontend/profile')
-rw-r--r-- | spec/frontend/profile/account/components/update_username_spec.js | 2 | ||||
-rw-r--r-- | spec/frontend/profile/add_ssh_key_validation_spec.js | 36 |
2 files changed, 24 insertions, 14 deletions
diff --git a/spec/frontend/profile/account/components/update_username_spec.js b/spec/frontend/profile/account/components/update_username_spec.js index 42adefcd0bb..bda07af4feb 100644 --- a/spec/frontend/profile/account/components/update_username_spec.js +++ b/spec/frontend/profile/account/components/update_username_spec.js @@ -79,6 +79,8 @@ describe('UpdateUsername component', () => { beforeEach(async () => { createComponent(); + // setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details + // eslint-disable-next-line no-restricted-syntax wrapper.setData({ newUsername }); await wrapper.vm.$nextTick(); diff --git a/spec/frontend/profile/add_ssh_key_validation_spec.js b/spec/frontend/profile/add_ssh_key_validation_spec.js index 1fec864599c..a6bcca0ccb3 100644 --- a/spec/frontend/profile/add_ssh_key_validation_spec.js +++ b/spec/frontend/profile/add_ssh_key_validation_spec.js @@ -3,18 +3,18 @@ import AddSshKeyValidation from '../../../app/assets/javascripts/profile/add_ssh describe('AddSshKeyValidation', () => { describe('submit', () => { it('returns true if isValid is true', () => { - const addSshKeyValidation = new AddSshKeyValidation({}); - jest.spyOn(AddSshKeyValidation, 'isPublicKey').mockReturnValue(true); + const addSshKeyValidation = new AddSshKeyValidation([], {}); + jest.spyOn(addSshKeyValidation, 'isPublicKey').mockReturnValue(true); - expect(addSshKeyValidation.submit()).toBeTruthy(); + expect(addSshKeyValidation.submit()).toBe(true); }); it('calls preventDefault and toggleWarning if isValid is false', () => { - const addSshKeyValidation = new AddSshKeyValidation({}); + const addSshKeyValidation = new AddSshKeyValidation([], {}); const event = { preventDefault: jest.fn(), }; - jest.spyOn(AddSshKeyValidation, 'isPublicKey').mockReturnValue(false); + jest.spyOn(addSshKeyValidation, 'isPublicKey').mockReturnValue(false); jest.spyOn(addSshKeyValidation, 'toggleWarning').mockImplementation(() => {}); addSshKeyValidation.submit(event); @@ -31,14 +31,15 @@ describe('AddSshKeyValidation', () => { warningElement.classList.add('hide'); const addSshKeyValidation = new AddSshKeyValidation( + [], {}, warningElement, originalSubmitElement, ); addSshKeyValidation.toggleWarning(true); - expect(warningElement.classList.contains('hide')).toBeFalsy(); - expect(originalSubmitElement.classList.contains('hide')).toBeTruthy(); + expect(warningElement.classList.contains('hide')).toBe(false); + expect(originalSubmitElement.classList.contains('hide')).toBe(true); }); it('hides warningElement and shows originalSubmitElement if isVisible is false', () => { @@ -47,25 +48,32 @@ describe('AddSshKeyValidation', () => { originalSubmitElement.classList.add('hide'); const addSshKeyValidation = new AddSshKeyValidation( + [], {}, warningElement, originalSubmitElement, ); addSshKeyValidation.toggleWarning(false); - expect(warningElement.classList.contains('hide')).toBeTruthy(); - expect(originalSubmitElement.classList.contains('hide')).toBeFalsy(); + expect(warningElement.classList.contains('hide')).toBe(true); + expect(originalSubmitElement.classList.contains('hide')).toBe(false); }); }); describe('isPublicKey', () => { - it('returns false if probably invalid public ssh key', () => { - expect(AddSshKeyValidation.isPublicKey('nope')).toBeFalsy(); + it('returns false if value begins with an algorithm name that is unsupported', () => { + const addSshKeyValidation = new AddSshKeyValidation(['ssh-rsa', 'ssh-algorithm'], {}); + + expect(addSshKeyValidation.isPublicKey('nope key')).toBe(false); + expect(addSshKeyValidation.isPublicKey('ssh- key')).toBe(false); + expect(addSshKeyValidation.isPublicKey('unsupported-ssh-rsa key')).toBe(false); }); - it('returns true if probably valid public ssh key', () => { - expect(AddSshKeyValidation.isPublicKey('ssh-')).toBeTruthy(); - expect(AddSshKeyValidation.isPublicKey('ecdsa-sha2-')).toBeTruthy(); + it('returns true if value begins with an algorithm name that is supported', () => { + const addSshKeyValidation = new AddSshKeyValidation(['ssh-rsa', 'ssh-algorithm'], {}); + + expect(addSshKeyValidation.isPublicKey('ssh-rsa key')).toBe(true); + expect(addSshKeyValidation.isPublicKey('ssh-algorithm key')).toBe(true); }); }); }); |