123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- import {mountWithTheme} from 'sentry-test/enzyme';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {mountGlobalModal} from 'sentry-test/modal';
- import {Client} from 'sentry/api';
- import AccountSecurityDetails from 'sentry/views/settings/account/accountSecurity/accountSecurityDetails';
- import AccountSecurityWrapper from 'sentry/views/settings/account/accountSecurity/accountSecurityWrapper';
- const ENDPOINT = '/users/me/authenticators/';
- const ACCOUNT_EMAILS_ENDPOINT = '/users/me/emails/';
- const ORG_ENDPOINT = '/organizations/';
- describe('AccountSecurityDetails', function () {
- let wrapper;
- let routerContext;
- let router;
- let params;
- describe('Totp', function () {
- beforeAll(function () {
- Client.clearMockResponses();
- params = {
- authId: 15,
- };
- ({router, routerContext} = initializeOrg({
- router: {
- params,
- },
- }));
- Client.addMockResponse({
- url: ENDPOINT,
- body: TestStubs.AllAuthenticators(),
- });
- Client.addMockResponse({
- url: ORG_ENDPOINT,
- body: TestStubs.Organizations(),
- });
- Client.addMockResponse({
- url: `${ENDPOINT}15/`,
- body: TestStubs.Authenticators().Totp(),
- });
- Client.addMockResponse({
- url: ACCOUNT_EMAILS_ENDPOINT,
- body: TestStubs.AccountEmails(),
- });
- wrapper = mountWithTheme(
- <AccountSecurityWrapper router={router} params={params}>
- <AccountSecurityDetails router={router} params={params} />
- </AccountSecurityWrapper>,
- routerContext
- );
- });
- it('has enrolled circle indicator', function () {
- expect(wrapper.find('AuthenticatorStatus').prop('enabled')).toBe(true);
- });
- it('has created and last used dates', function () {
- expect(wrapper.find('AuthenticatorDate')).toHaveLength(2);
- });
- it('can remove method', async function () {
- const deleteMock = Client.addMockResponse({
- url: `${ENDPOINT}15/`,
- method: 'DELETE',
- });
- wrapper.find('RemoveConfirm Button').simulate('click');
- const modal = await mountGlobalModal();
- modal.find('Button[priority="primary"]').simulate('click');
- expect(deleteMock).toHaveBeenCalled();
- });
- it('can remove one of multiple 2fa methods when org requires 2fa', async function () {
- Client.addMockResponse({
- url: ORG_ENDPOINT,
- body: TestStubs.Organizations({require2FA: true}),
- });
- const deleteMock = Client.addMockResponse({
- url: `${ENDPOINT}15/`,
- method: 'DELETE',
- });
- wrapper = mountWithTheme(
- <AccountSecurityWrapper router={router} params={params}>
- <AccountSecurityDetails router={router} params={params} />
- </AccountSecurityWrapper>,
- routerContext
- );
- wrapper.find('RemoveConfirm Button').simulate('click');
- const modal = await mountGlobalModal();
- modal.find('Button[priority="primary"]').simulate('click');
- expect(deleteMock).toHaveBeenCalled();
- });
- it('can not remove last 2fa method when org requires 2fa', async function () {
- Client.addMockResponse({
- url: ORG_ENDPOINT,
- body: TestStubs.Organizations({require2FA: true}),
- });
- Client.addMockResponse({
- url: ENDPOINT,
- body: [TestStubs.Authenticators().Totp()],
- });
- const deleteMock = Client.addMockResponse({
- url: `${ENDPOINT}15/`,
- method: 'DELETE',
- });
- wrapper = mountWithTheme(
- <AccountSecurityWrapper router={router} params={params}>
- <AccountSecurityDetails router={router} params={params} />
- </AccountSecurityWrapper>,
- routerContext
- );
- wrapper.find('RemoveConfirm Button').simulate('click');
- const modal = await mountGlobalModal();
- expect(modal.find('Modal[show=true]').exists()).toBe(false);
- expect(deleteMock).not.toHaveBeenCalled();
- });
- });
- describe('Recovery', function () {
- beforeEach(function () {
- params = {authId: 16};
- ({router, routerContext} = initializeOrg({
- router: {
- params,
- },
- }));
- Client.clearMockResponses();
- Client.addMockResponse({
- url: ENDPOINT,
- body: TestStubs.AllAuthenticators(),
- });
- Client.addMockResponse({
- url: ORG_ENDPOINT,
- body: TestStubs.Organizations(),
- });
- Client.addMockResponse({
- url: `${ENDPOINT}16/`,
- body: TestStubs.Authenticators().Recovery(),
- });
- Client.addMockResponse({
- url: ACCOUNT_EMAILS_ENDPOINT,
- body: TestStubs.AccountEmails(),
- });
- wrapper = mountWithTheme(
- <AccountSecurityWrapper router={router} params={params}>
- <AccountSecurityDetails router={router} params={params} />
- </AccountSecurityWrapper>,
- routerContext
- );
- });
- it('has enrolled circle indicator', function () {
- expect(wrapper.find('AuthenticatorStatus').prop('enabled')).toBe(true);
- });
- it('has created and last used dates', function () {
- expect(wrapper.find('AuthenticatorDate')).toHaveLength(2);
- });
- it('does not have remove button', function () {
- expect(wrapper.find('RemoveConfirm')).toHaveLength(0);
- });
- it('regenerates codes', function () {
- const deleteMock = Client.addMockResponse({
- url: `${ENDPOINT}16/`,
- method: 'PUT',
- });
- wrapper.find('RecoveryCodes').prop('onRegenerateBackupCodes')();
- expect(deleteMock).toHaveBeenCalled();
- });
- it('has copy, print and download buttons', function () {
- const codes = 'ABCD-1234 \nEFGH-5678';
- const downloadCodes = `Button[href="data:text/plain;charset=utf-8,${codes}"]`;
- expect(wrapper.find(downloadCodes)).toHaveLength(1);
- wrapper.find(downloadCodes).simulate('click');
- expect(wrapper.find('button[aria-label="print"]')).toHaveLength(1);
- expect(wrapper.find('iframe[name="printable"]')).toHaveLength(1);
- expect(wrapper.find(`Clipboard[value="${codes}"]`)).toHaveLength(1);
- });
- });
- });
|