Skip to content

Commit

Permalink
test: [M3-7496] - Add test for Proxy user -> Parent account token exp…
Browse files Browse the repository at this point in the history
…iration prompt (linode#10341)

* Clean up Cypress login local storage

* Export factories from index

* Add session expiry test upon switching back to Parent

* Added changeset: Add UI test for account switch flow with expired Parent token

* Update packages/manager/cypress/e2e/core/parentChild/token-expiration.spec.ts

Co-authored-by: Mariah Jacobs <[email protected]>

* Update packages/manager/cypress/e2e/core/parentChild/token-expiration.spec.ts

Co-authored-by: Mariah Jacobs <[email protected]>
  • Loading branch information
jdamore-linode and mjac0bs authored Apr 3, 2024
1 parent 0016832 commit c76351e
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 12 deletions.
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-10341-tests-1712073647415.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Add UI test for account switch flow with expired Parent token ([#10341](https://github.com/linode/manager/pull/10341))
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import {
mockAppendFeatureFlags,
mockGetFeatureFlagClientstream,
} from 'support/intercepts/feature-flags';
import { mockGetLinodes } from 'support/intercepts/linodes';
import { makeFeatureFlagData } from 'support/util/feature-flags';
import {
accountFactory,
accountUserFactory,
profileFactory,
} from 'src/factories';
import { randomLabel, randomString } from 'support/util/random';
import {
mockGetAccount,
mockGetChildAccounts,
} from 'support/intercepts/account';
import { mockGetProfile } from 'support/intercepts/profile';
import { DateTime } from 'luxon';
import { ui } from 'support/ui';

const mockChildAccount = accountFactory.build({
company: 'Partner Company',
});

const mockChildAccountProxyUser = accountUserFactory.build({
username: randomLabel(),
user_type: 'proxy',
});

const mockChildAccountProxyProfile = profileFactory.build({
username: mockChildAccountProxyUser.username,
user_type: 'proxy',
});

describe('Parent/Child token expiration', () => {
// @TODO M3-7554, M3-7559: Remove feature flag mocks after launch and clean-up.
beforeEach(() => {
mockAppendFeatureFlags({
parentChildAccountAccess: makeFeatureFlagData(true),
});
mockGetFeatureFlagClientstream();
});

/*
* - Confirms flow when a Proxy user attempts to switch back to a Parent account with expired auth token.
* - Uses mock API and local storage data.
*/
it('shows session expiry prompt upon switching back to Parent account with expired Parent token', () => {
mockGetLinodes([]).as('getLinodes');
mockGetAccount(mockChildAccount);
mockGetProfile(mockChildAccountProxyProfile);
mockGetChildAccounts([]);

// Mock local storage parent token expiry to have already passed.
cy.visitWithLogin('/', {
localStorageOverrides: {
proxy_user: true,
'authentication/parent_token/token': `Bearer ${randomString(32)}`,
'authentication/parent_token/expire': DateTime.local()
.minus({ minutes: 30 })
.toISO(),
'authentication/parent_token/scopes': '*',
},
});

// Wait for page load, then click "Switch Account" button.
cy.wait('@getLinodes');
ui.userMenuButton.find().should('be.visible').click();

ui.userMenu
.find()
.should('be.visible')
.within(() => {
ui.button
.findByTitle('Switch Account')
.should('be.visible')
.should('be.enabled')
.click();
});

// Confirm session expiry prompt, and that clicking "Log In" prompts login flow.
ui.dialog
.findByTitle('Session expired')
.should('be.visible')
.within(() => {
ui.button
.findByTitle('Log in')
.should('be.visible')
.should('be.enabled')
.click();
});

cy.url().should('endWith', '/logout');
});
});
12 changes: 4 additions & 8 deletions packages/manager/cypress/support/setup/login-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@ const overrideLocalStorage = (
};

const _loginWithToken = (win: Window) => {
win.localStorage.setItem('authentication/oauth-token', oauthToken);
win.localStorage.setItem('authentication/scopes', '*');
// cy.log(window.localStorage.getItem('authentication/oauth-token'));
const expireDate = DateTime.local().plus({ days: 30 });
const isoExpire = expireDate.toISO();
// cy.log(isoExpire);
win.localStorage.setItem('authentication/expires', isoExpire);
win.localStorage.setItem('authentication/expire-datetime', isoExpire);
win.localStorage.setItem('authentication/token', 'Bearer ' + oauthToken);
win.localStorage.setItem('authentication/expire', isoExpire);
win.localStorage.setItem(
'authentication/expire',
DateTime.local().plus({ days: 30 }).toISO()
);
};

/**
Expand Down
14 changes: 10 additions & 4 deletions packages/manager/src/factories/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
export * from './account';
export * from './accountAgreements';
export * from './accountAvailability';
export * from './accountSettings';
export * from './accountLogin';
export * from './accountMaintenance';
export * from './accountOAuth';
export * from './accountPayment';
export * from './accountSettings';
export * from './accountUsers';
export * from './aclb';
export * from './betas';
export * from './billing';
Expand All @@ -13,17 +16,19 @@ export * from './disk';
export * from './domain';
export * from './entityTransfers';
export * from './events';
export * from './featureFlags';
export * from './firewalls';
export * from './grants';
export * from './images';
export * from './kubernetesCluster';
export * from './linodeConfigs';
export * from './linodeConfigInterfaceFactory';
export * from './linodeConfigs';
export * from './linodes';
export * from './longviewClient';
export * from './longviewDisks';
export * from './longviewProcess';
export * from './longviewService';
export * from './longviewResponse';
export * from './longviewService';
export * from './longviewSubscription';
export * from './longviewTopProcesses';
export * from './managed';
Expand All @@ -33,6 +38,7 @@ export * from './notification';
export * from './oauth';
export * from './objectStorage';
export * from './placementGroups';
export * from './preferences';
export * from './profile';
export * from './promotionalOffer';
export * from './regions';
Expand All @@ -42,8 +48,8 @@ export * from './subnets';
export * from './support';
export * from './tags';
export * from './types';
export * from './volume';
export * from './vlans';
export * from './volume';
export * from './vpcs';

// Convert factory output to our itemsById pattern
Expand Down

0 comments on commit c76351e

Please sign in to comment.