Skip to content

Commit c76351e

Browse files
test: [M3-7496] - Add test for Proxy user -> Parent account token expiration 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]>
1 parent 0016832 commit c76351e

File tree

4 files changed

+114
-12
lines changed

4 files changed

+114
-12
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Tests
3+
---
4+
5+
Add UI test for account switch flow with expired Parent token ([#10341](https://github.com/linode/manager/pull/10341))
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import {
2+
mockAppendFeatureFlags,
3+
mockGetFeatureFlagClientstream,
4+
} from 'support/intercepts/feature-flags';
5+
import { mockGetLinodes } from 'support/intercepts/linodes';
6+
import { makeFeatureFlagData } from 'support/util/feature-flags';
7+
import {
8+
accountFactory,
9+
accountUserFactory,
10+
profileFactory,
11+
} from 'src/factories';
12+
import { randomLabel, randomString } from 'support/util/random';
13+
import {
14+
mockGetAccount,
15+
mockGetChildAccounts,
16+
} from 'support/intercepts/account';
17+
import { mockGetProfile } from 'support/intercepts/profile';
18+
import { DateTime } from 'luxon';
19+
import { ui } from 'support/ui';
20+
21+
const mockChildAccount = accountFactory.build({
22+
company: 'Partner Company',
23+
});
24+
25+
const mockChildAccountProxyUser = accountUserFactory.build({
26+
username: randomLabel(),
27+
user_type: 'proxy',
28+
});
29+
30+
const mockChildAccountProxyProfile = profileFactory.build({
31+
username: mockChildAccountProxyUser.username,
32+
user_type: 'proxy',
33+
});
34+
35+
describe('Parent/Child token expiration', () => {
36+
// @TODO M3-7554, M3-7559: Remove feature flag mocks after launch and clean-up.
37+
beforeEach(() => {
38+
mockAppendFeatureFlags({
39+
parentChildAccountAccess: makeFeatureFlagData(true),
40+
});
41+
mockGetFeatureFlagClientstream();
42+
});
43+
44+
/*
45+
* - Confirms flow when a Proxy user attempts to switch back to a Parent account with expired auth token.
46+
* - Uses mock API and local storage data.
47+
*/
48+
it('shows session expiry prompt upon switching back to Parent account with expired Parent token', () => {
49+
mockGetLinodes([]).as('getLinodes');
50+
mockGetAccount(mockChildAccount);
51+
mockGetProfile(mockChildAccountProxyProfile);
52+
mockGetChildAccounts([]);
53+
54+
// Mock local storage parent token expiry to have already passed.
55+
cy.visitWithLogin('/', {
56+
localStorageOverrides: {
57+
proxy_user: true,
58+
'authentication/parent_token/token': `Bearer ${randomString(32)}`,
59+
'authentication/parent_token/expire': DateTime.local()
60+
.minus({ minutes: 30 })
61+
.toISO(),
62+
'authentication/parent_token/scopes': '*',
63+
},
64+
});
65+
66+
// Wait for page load, then click "Switch Account" button.
67+
cy.wait('@getLinodes');
68+
ui.userMenuButton.find().should('be.visible').click();
69+
70+
ui.userMenu
71+
.find()
72+
.should('be.visible')
73+
.within(() => {
74+
ui.button
75+
.findByTitle('Switch Account')
76+
.should('be.visible')
77+
.should('be.enabled')
78+
.click();
79+
});
80+
81+
// Confirm session expiry prompt, and that clicking "Log In" prompts login flow.
82+
ui.dialog
83+
.findByTitle('Session expired')
84+
.should('be.visible')
85+
.within(() => {
86+
ui.button
87+
.findByTitle('Log in')
88+
.should('be.visible')
89+
.should('be.enabled')
90+
.click();
91+
});
92+
93+
cy.url().should('endWith', '/logout');
94+
});
95+
});

packages/manager/cypress/support/setup/login-command.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@ const overrideLocalStorage = (
1414
};
1515

1616
const _loginWithToken = (win: Window) => {
17-
win.localStorage.setItem('authentication/oauth-token', oauthToken);
1817
win.localStorage.setItem('authentication/scopes', '*');
19-
// cy.log(window.localStorage.getItem('authentication/oauth-token'));
20-
const expireDate = DateTime.local().plus({ days: 30 });
21-
const isoExpire = expireDate.toISO();
22-
// cy.log(isoExpire);
23-
win.localStorage.setItem('authentication/expires', isoExpire);
24-
win.localStorage.setItem('authentication/expire-datetime', isoExpire);
2518
win.localStorage.setItem('authentication/token', 'Bearer ' + oauthToken);
26-
win.localStorage.setItem('authentication/expire', isoExpire);
19+
win.localStorage.setItem(
20+
'authentication/expire',
21+
DateTime.local().plus({ days: 30 }).toISO()
22+
);
2723
};
2824

2925
/**

packages/manager/src/factories/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
export * from './account';
2+
export * from './accountAgreements';
23
export * from './accountAvailability';
3-
export * from './accountSettings';
4+
export * from './accountLogin';
45
export * from './accountMaintenance';
56
export * from './accountOAuth';
67
export * from './accountPayment';
8+
export * from './accountSettings';
9+
export * from './accountUsers';
710
export * from './aclb';
811
export * from './betas';
912
export * from './billing';
@@ -13,17 +16,19 @@ export * from './disk';
1316
export * from './domain';
1417
export * from './entityTransfers';
1518
export * from './events';
19+
export * from './featureFlags';
1620
export * from './firewalls';
21+
export * from './grants';
1722
export * from './images';
1823
export * from './kubernetesCluster';
19-
export * from './linodeConfigs';
2024
export * from './linodeConfigInterfaceFactory';
25+
export * from './linodeConfigs';
2126
export * from './linodes';
2227
export * from './longviewClient';
2328
export * from './longviewDisks';
2429
export * from './longviewProcess';
25-
export * from './longviewService';
2630
export * from './longviewResponse';
31+
export * from './longviewService';
2732
export * from './longviewSubscription';
2833
export * from './longviewTopProcesses';
2934
export * from './managed';
@@ -33,6 +38,7 @@ export * from './notification';
3338
export * from './oauth';
3439
export * from './objectStorage';
3540
export * from './placementGroups';
41+
export * from './preferences';
3642
export * from './profile';
3743
export * from './promotionalOffer';
3844
export * from './regions';
@@ -42,8 +48,8 @@ export * from './subnets';
4248
export * from './support';
4349
export * from './tags';
4450
export * from './types';
45-
export * from './volume';
4651
export * from './vlans';
52+
export * from './volume';
4753
export * from './vpcs';
4854

4955
// Convert factory output to our itemsById pattern

0 commit comments

Comments
 (0)