-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added e2e tests for enterprise SSO setup link (#2728)
* Added e2e tests for enterprise SSO setup link generic SAML 2.0 workflow * Replaced useSWR with fetch api in setuplinks * Addressed review comment - Refactored code to remove localor.all - removed extract awaits like page repload * Refactored code - used fixtures to create setup link - removed unnecessary code
- Loading branch information
1 parent
654fdd4
commit 73b1337
Showing
5 changed files
with
176 additions
and
11 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './portal'; | ||
export * from './sso-page'; | ||
export * from './dsync-page'; | ||
export * from './setuplink-page'; |
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,82 @@ | ||
import { Page, expect } from '@playwright/test'; | ||
|
||
const TEST_SETUPLINK_REDIRECT_URL = 'http://localhost:3366'; | ||
const TEST_SETUPLINK_DEFAULT_REDIRECT_URL = 'http://localhost:3366/login/saml'; | ||
const TEST_SETUPLINK_ADMIN_URL = '/admin/sso-connection/setup-link'; | ||
const TEST_SETUPLINK_URL_LABEL_SELECTOR = | ||
'Share this link with your customers to allow them to set up the integrationClose'; | ||
|
||
export class SetupLinkPage { | ||
setupLinkUrl: string; | ||
constructor( | ||
public readonly page: Page, | ||
public readonly product: string, | ||
public readonly tenant: string, | ||
public readonly adminPage: string = TEST_SETUPLINK_ADMIN_URL, | ||
public readonly redirectUrl: string = TEST_SETUPLINK_REDIRECT_URL, | ||
public readonly defaultRedirectUrl: string = TEST_SETUPLINK_DEFAULT_REDIRECT_URL | ||
) { | ||
this.page = page; | ||
this.product = product; | ||
this.tenant = tenant; | ||
this.adminPage = adminPage; | ||
this.redirectUrl = redirectUrl; | ||
this.defaultRedirectUrl = defaultRedirectUrl; | ||
this.setupLinkUrl = ''; | ||
} | ||
|
||
async createSetupLink() { | ||
// Go to admin/sso-connection/setup-link page and create setup link | ||
await this.page.goto(this.adminPage); | ||
await this.page.getByRole('button', { name: 'New Setup Link' }).click(); | ||
await this.page.getByPlaceholder('Acme SSO').fill('acme-test'); | ||
await this.page.getByLabel('Description (Optional)').fill('acme test'); | ||
await this.page.getByPlaceholder('acme', { exact: true }).fill(this.tenant); | ||
await this.page.getByPlaceholder('MyApp').fill(this.product); | ||
await this.page.getByPlaceholder('http://localhost:3366', { exact: true }).fill(this.redirectUrl); | ||
await this.page.getByPlaceholder('http://localhost:3366/login/').fill(this.defaultRedirectUrl); | ||
|
||
await this.page.getByRole('button', { name: 'Create Setup Link' }).click(); | ||
|
||
// Extract generated setup link | ||
this.setupLinkUrl = await this.page | ||
.getByText(TEST_SETUPLINK_URL_LABEL_SELECTOR) | ||
.locator('input[type="text"]') | ||
.first() | ||
.inputValue(); | ||
} | ||
|
||
async getSetupLinkUrl(): Promise<string> { | ||
return this.setupLinkUrl; | ||
} | ||
|
||
async isSetupLinkCreated() { | ||
// Go back to new connections page | ||
await this.page.goto(TEST_SETUPLINK_ADMIN_URL); | ||
|
||
// Await for rows loaded | ||
await expect(this.page.getByRole('table')).toBeVisible(); | ||
|
||
// Check if setup link is created | ||
await expect( | ||
this.page.getByText(this.tenant, { exact: true }), | ||
'Failed to create setup link' | ||
).toBeVisible(); | ||
await expect( | ||
this.page.getByText(this.product, { exact: true }), | ||
'Failed to create setup link' | ||
).toBeVisible(); | ||
} | ||
|
||
async removeSetupLink() { | ||
// Go back to setup link admin url | ||
await this.page.goto(TEST_SETUPLINK_ADMIN_URL); | ||
|
||
// Await for rows loaded | ||
await expect(this.page.getByRole('table')).toBeVisible(); | ||
|
||
// Delete the created setuplink | ||
await this.page.getByRole('button').nth(5).click(); | ||
await this.page.getByRole('button', { name: 'Delete' }).click(); | ||
} | ||
} |
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,78 @@ | ||
import { expect, test as baseTest } from '@playwright/test'; | ||
import { Portal, SetupLinkPage } from 'e2e/support/fixtures'; | ||
|
||
const TEST_SETUPLINK_MOCKSAML_ORIGIN = process.env.MOCKSAML_ORIGIN || 'https://mocksaml.com'; | ||
const TEST_SETUPLINK_MOCK_METADATA_URL = `${TEST_SETUPLINK_MOCKSAML_ORIGIN}/api/saml/metadata`; | ||
|
||
const TEST_SETUPLINK_ADMIN_CONNECTION = '/admin/sso-connection'; | ||
const TENANT = 'acme-setuplink-test.com'; | ||
const PRODUCT = 'acme-setuplink-test'; | ||
|
||
type MyFixtures = { | ||
portal: Portal; | ||
setuplinkPage: SetupLinkPage; | ||
}; | ||
|
||
export const test = baseTest.extend<MyFixtures>({ | ||
portal: async ({ page }, use) => { | ||
const portal = new Portal(page); | ||
await portal.doCredentialsLogin(); | ||
await use(portal); | ||
}, | ||
setuplinkPage: async ({ page }, use) => { | ||
const setuplinkPage = new SetupLinkPage(page, PRODUCT, TENANT); | ||
await use(setuplinkPage); | ||
}, | ||
}); | ||
|
||
test.describe('Admin Portal Enterprise SSO SetupLink using generic SAML 2.0', () => { | ||
test('should be able to create setup link and sso connection using generic SAML 2.0', async ({ | ||
page, | ||
setuplinkPage, | ||
}) => { | ||
// Create setup link | ||
await setuplinkPage.createSetupLink(); | ||
|
||
// get setuplink url | ||
const linkContent = await setuplinkPage.getSetupLinkUrl(); | ||
|
||
// Open new tab and go to setup link page | ||
const context = page.context(); | ||
const setupLinkPage = await context.newPage(); | ||
await setupLinkPage.goto(linkContent); | ||
|
||
// Create SSO connection using generic SAML 2.0 workflow | ||
await setupLinkPage.getByRole('button', { name: 'Generic SAML 2.0' }).click(); | ||
await setupLinkPage.getByRole('button', { name: 'Next Step' }).click(); | ||
await setupLinkPage.getByRole('button', { name: 'Next Step' }).click(); | ||
await setupLinkPage | ||
.getByPlaceholder('Paste the Metadata URL here') | ||
.fill(TEST_SETUPLINK_MOCK_METADATA_URL); | ||
await setupLinkPage.getByRole('button', { name: 'Save' }).click(); | ||
|
||
await setupLinkPage.waitForURL(/\/setup\/.+\/sso-connection$/); | ||
await expect(setupLinkPage.getByRole('cell', { name: 'saml.example.com' })).toBeVisible(); | ||
await setupLinkPage.close(); | ||
|
||
// Go to connections page | ||
await page.goto(TEST_SETUPLINK_ADMIN_CONNECTION); | ||
|
||
// Check if new SSO connection is created | ||
await expect( | ||
page.getByText(TENANT, { exact: true }), | ||
'Failed to create new sso connection from setup-link' | ||
).toBeVisible(); | ||
await expect( | ||
page.getByText(PRODUCT, { exact: true }), | ||
'Failed to create new sso connection from setup-link' | ||
).toBeVisible(); | ||
|
||
// Delete the SSO connection | ||
await page.getByLabel('Edit').click(); | ||
await page.getByRole('button', { name: 'Delete' }).click(); | ||
await page.getByRole('button', { name: 'Confirm' }).click(); | ||
|
||
// remove setup link | ||
await setuplinkPage.removeSetupLink(); | ||
}); | ||
}); |
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