forked from linode/manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: [M3-7496] - Add test for Proxy user -> Parent account token exp…
…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
1 parent
0016832
commit c76351e
Showing
4 changed files
with
114 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
95 changes: 95 additions & 0 deletions
95
packages/manager/cypress/e2e/core/parentChild/token-expiration.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters