|
import { test, expect, Page } from '@playwright/test' |
|
import { |
|
baseURLFromFlags, |
|
dropdownSelect, |
|
pageAction, |
|
userSessionFile, |
|
} from './lib' |
|
import Chance from 'chance' |
|
import { createService } from './lib/service' |
|
const c = new Chance() |
|
|
|
test.describe.configure({ mode: 'parallel' }) |
|
test.use({ |
|
storageState: userSessionFile, |
|
baseURL: baseURLFromFlags(['univ-keys']), |
|
}) |
|
|
|
async function setup(page: Page, isMobile: boolean): Promise<string> { |
|
const intKeyName = 'uik-key ' + c.name() |
|
const serviceName = 'uik-service ' + c.name() |
|
const serviceDescription = c.sentence() |
|
const serviceURL = await createService(page, serviceName, serviceDescription) |
|
|
|
await page.getByRole('link', { name: 'Integration Keys' }).click() |
|
|
|
await pageAction(page, 'Create Integration Key') |
|
await page.fill('input[name=name]', intKeyName) |
|
await dropdownSelect(page, 'Type', 'Universal Integration Key') |
|
await page.click('button[type=submit]') |
|
await page.waitForURL(/\/services\/.+\/integration-keys\/.+$/) |
|
|
|
const bread = page.locator('header nav') |
|
await expect(bread.getByRole('link', { name: 'Services' })).toBeVisible() |
|
if (!isMobile) { |
|
|
|
await expect(bread.getByRole('link', { name: serviceName })).toBeVisible() |
|
await expect( |
|
bread.getByRole('link', { name: 'Integration Keys' }), |
|
).toBeVisible() |
|
} |
|
await expect(bread.getByRole('link', { name: intKeyName })).toBeVisible() |
|
|
|
return serviceURL |
|
} |
|
|
|
test('create universal key, add rule with action', async ({ |
|
page, |
|
isMobile, |
|
}) => { |
|
await setup(page, isMobile) |
|
const ruleName = c.name() |
|
const ruleDesc = c.sentence({ words: 5 }) |
|
const ruleNewDesc = c.sentence({ words: 3 }) |
|
|
|
|
|
await page.getByRole('button', { name: 'Create Rule' }).click() |
|
await page.fill('input[name=name]', ruleName) |
|
await page.fill('input[name=description]', ruleDesc) |
|
const editor = await page |
|
.getByTestId('code-conditionExpr') |
|
.locator('.cm-editor') |
|
await editor.click() |
|
await page.keyboard.insertText('true') |
|
await page.getByRole('button', { name: 'Submit' }).click() |
|
await expect(page.locator('[role=dialog]')).toBeHidden() |
|
|
|
|
|
await expect(page.locator('body')).toContainText(ruleName) |
|
await expect(page.locator('body')).toContainText(ruleDesc) |
|
|
|
|
|
await page |
|
.locator('li', { hasText: ruleName }) |
|
.getByRole('button', { name: 'Other Actions' }) |
|
.click() |
|
await page.getByRole('menuitem', { name: 'Edit Rule' }).click() |
|
|
|
|
|
await page.fill('input[name=description]', ruleNewDesc) |
|
await page.getByRole('button', { name: 'Submit' }).click() |
|
await expect(page.locator('[role=dialog]')).toBeHidden() |
|
|
|
|
|
await expect(page.locator('body')).toContainText(ruleName) |
|
await expect(page.locator('body')).toContainText(ruleNewDesc) |
|
|
|
|
|
await expect( |
|
page.locator('li', { hasText: ruleName }).getByTestId('no-actions'), |
|
).toBeVisible() |
|
|
|
|
|
await page |
|
.locator('li', { hasText: ruleName }) |
|
.getByRole('button', { name: 'Other Actions' }) |
|
.click() |
|
await page.getByRole('menuitem', { name: 'Add Action' }).click() |
|
|
|
|
|
await page.getByRole('button', { name: 'Submit' }).click() |
|
await expect( |
|
page.locator('li', { hasText: ruleName }).getByTestId('no-actions'), |
|
).toBeHidden() |
|
|
|
|
|
await page.getByTestId('destination-chip').getByTestId('EditIcon').click() |
|
|
|
|
|
await page.getByLabel('Delete this action').click() |
|
await page.getByRole('button', { name: 'Submit' }).click() |
|
await expect(page.locator('[role=dialog]')).toBeHidden() |
|
|
|
|
|
await expect( |
|
page.locator('li', { hasText: ruleName }).getByTestId('no-actions'), |
|
).toBeVisible() |
|
|
|
|
|
await page |
|
.locator('li', { hasText: ruleName }) |
|
.getByRole('button', { name: 'Other Actions' }) |
|
.click() |
|
await page.getByRole('menuitem', { name: 'Delete Rule' }).click() |
|
expect( |
|
page.locator('[data-cy=dialog-title]', { hasText: 'Are you sure?' }), |
|
).toBeVisible() |
|
await page.getByRole('button', { name: 'Confirm' }).click() |
|
|
|
|
|
await expect(page.locator('[data-cy=list-empty-message]')).toHaveText( |
|
'No rules exist for this integration key.', |
|
) |
|
}) |
|
|
|
test('create primary auth token then promote a second auth token', async ({ |
|
page, |
|
playwright, |
|
isMobile, |
|
}) => { |
|
const serviceURL = await setup(page, isMobile) |
|
|
|
await expect(page.locator('[data-cy=details]')).toContainText( |
|
'Auth Token: N/A', |
|
) |
|
|
|
await page.getByRole('button', { name: 'Generate Auth Token' }).click() |
|
await page.getByRole('button', { name: 'Generate' }).click() |
|
|
|
const origPrimaryToken = await page |
|
.getByRole('button', { name: 'Copy' }) |
|
.textContent() |
|
expect(origPrimaryToken).not.toBeNull() |
|
await page.getByRole('button', { name: 'Done' }).click() |
|
|
|
function tokenHint(token: string): string { |
|
return token.slice(0, 2) + '...' + token.slice(-4) |
|
} |
|
|
|
await expect(page.locator('[data-cy=details]')).toContainText( |
|
tokenHint(origPrimaryToken as string), |
|
) |
|
|
|
const req = await playwright.request.newContext({ |
|
baseURL: baseURLFromFlags(['univ-keys']), |
|
extraHTTPHeaders: { 'Content-Type': 'application/json', Cookie: '' }, |
|
}) |
|
|
|
async function testKey(key: string, status: number): Promise<void> { |
|
const auth = { Authorization: key ? 'Bearer ' + key : '' } |
|
const resp = await req.post('/api/v2/uik', { headers: auth, data: {} }) |
|
expect(resp.status()).toBe(status) |
|
} |
|
|
|
await testKey('', 401) |
|
await testKey(origPrimaryToken as string, 204) |
|
|
|
await page.getByRole('button', { name: 'Generate Secondary Token' }).click() |
|
await page.getByRole('button', { name: 'Generate' }).click() |
|
const firstSecondaryToken = await page |
|
.getByRole('button', { name: 'Copy' }) |
|
.textContent() |
|
expect(origPrimaryToken).not.toBeNull() |
|
await page.getByRole('button', { name: 'Done' }).click() |
|
|
|
await expect(page.locator('[data-cy=details]')).toContainText( |
|
tokenHint(origPrimaryToken as string), |
|
) |
|
await expect(page.locator('[data-cy=details]')).toContainText( |
|
tokenHint(firstSecondaryToken as string), |
|
) |
|
|
|
|
|
await testKey(origPrimaryToken as string, 204) |
|
await testKey(firstSecondaryToken as string, 204) |
|
|
|
await page.getByRole('button', { name: 'Delete Secondary Token' }).click() |
|
await page.getByLabel('I acknowledge the impact of this action').click() |
|
await page.getByRole('button', { name: 'Submit' }).click() |
|
await expect(page.locator('[data-cy=details]')).not.toContainText( |
|
tokenHint(firstSecondaryToken as string), |
|
) |
|
await testKey(origPrimaryToken as string, 204) |
|
await testKey(firstSecondaryToken as string, 401) |
|
|
|
await page.getByRole('button', { name: 'Generate Secondary Token' }).click() |
|
await page.getByRole('button', { name: 'Generate' }).click() |
|
const secondSecondaryToken = await page |
|
.getByRole('button', { name: 'Copy' }) |
|
.textContent() |
|
expect(secondSecondaryToken).not.toBeNull() |
|
await page.getByRole('button', { name: 'Done' }).click() |
|
|
|
await page.getByRole('button', { name: 'Promote Secondary Token' }).click() |
|
await page.getByLabel('I acknowledge the impact of this action').click() |
|
await page.getByRole('button', { name: 'Promote Key' }).click() |
|
|
|
await expect(page.locator('[data-cy=details]')).toContainText( |
|
tokenHint(secondSecondaryToken as string), |
|
) |
|
await expect(page.locator('[data-cy=details]')).not.toContainText( |
|
tokenHint(origPrimaryToken as string), |
|
) |
|
|
|
await testKey(origPrimaryToken as string, 401) |
|
await testKey(secondSecondaryToken as string, 204) |
|
|
|
await page.goto(serviceURL) |
|
await page.getByRole('button', { name: 'Delete' }).click() |
|
await page.getByRole('button', { name: 'Confirm' }).click() |
|
await page.waitForURL(/services$/) |
|
}) |
|
|