-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add basic smoke test for sonarqube with sso (#77)
## Description Fixes #70 --------- Co-authored-by: zamaz <71521611+zachariahmiller@users.noreply.github.com> Co-authored-by: Wayne Starr <Racer159@users.noreply.github.com>
- Loading branch information
1 parent
624399d
commit 8db5ada
Showing
10 changed files
with
248 additions
and
7 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { test as setup, expect } from '@playwright/test'; | ||
import { authFile } from './playwright.config'; | ||
|
||
setup('authenticate', async ({ page, context }) => { | ||
await page.goto('/sessions/new'); | ||
|
||
await page.locator('.identity-provider-link').click(); | ||
await page.getByLabel('Username or email').fill('doug'); | ||
await page.getByLabel('Password').fill('unicorn123!@#'); | ||
|
||
await page.getByRole("button", { name: "Log In" }).click(); | ||
|
||
await page.waitForURL('/projects'); // successful redirect | ||
|
||
// ensure auth cookies were set | ||
const cookies = await context.cookies(); | ||
const keycloakCookie = cookies.find( | ||
(cookie) => cookie.name === "KEYCLOAK_SESSION", | ||
); | ||
|
||
expect(keycloakCookie).toBeDefined(); | ||
expect(keycloakCookie?.value).not.toBe(""); | ||
expect(keycloakCookie?.domain).toContain("sso."); | ||
|
||
await page.context().storageState({ path: authFile }); | ||
|
||
await expect(page).toHaveURL('/projects'); | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,9 @@ | ||
{ | ||
"name": "uds-package-sonarqube", | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"@playwright/test": "^1.43.1", | ||
"@types/node": "^20.12.12", | ||
"typescript": "^5.4.5" | ||
} | ||
} |
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,43 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
export const playwrightDir = '.playwright'; | ||
export const authFile = `${playwrightDir}/auth/user.json`; | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
fullyParallel: true, | ||
forbidOnly: !!process.env.CI, // fail CI if you accidently leave `test.only` in source | ||
retries: process.env.CI ? 1 : 0, | ||
workers: 1, | ||
reporter: [ | ||
// Reporter to use. See https://playwright.dev/docs/test-reporters | ||
['html', { outputFolder: `${playwrightDir}/reports`, open: 'never' }], | ||
['json', { outputFile: `${playwrightDir}/reports/test-results.json`, open: 'never' }], | ||
['list'] | ||
], | ||
|
||
outputDir: `${playwrightDir}/output`, | ||
|
||
use: { | ||
baseURL: process.env.BASE_URL || 'https://sonarqube.uds.dev', // for `await page.goto('/')` etc | ||
trace: 'on-first-retry', // collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer | ||
}, | ||
|
||
projects: [ | ||
{ name: 'setup', testMatch: /.*\.setup\.ts/ }, // authentication | ||
|
||
...[ | ||
'Desktop Chrome', | ||
'Desktop Firefox', | ||
].map((p) => ({ | ||
name: devices[p].defaultBrowserType, | ||
dependencies: ['setup'], | ||
use: { | ||
...devices[p], | ||
storageState: authFile, | ||
}, | ||
})), | ||
], | ||
}); |
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,19 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
function randomProjectName() { | ||
return `uds-package-sonarqube-${Math.floor((Math.random() * 1000))}`; | ||
} | ||
|
||
test('create a project', async ({ page }) => { | ||
await page.goto('/projects/create'); | ||
|
||
const projectName = randomProjectName(); | ||
|
||
await page.getByRole('button', { name: 'Manually' }).click(); | ||
await page.getByLabel('Project display name*').fill(projectName); | ||
await page.getByRole('button', { name: 'Set Up' }).click(); | ||
|
||
await expect(page).toHaveURL(`/dashboard?id=${projectName}`); | ||
|
||
await expect(page.getByRole('heading', { level: 1 })).toContainText(projectName); | ||
}); |
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,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ | ||
"module": "commonjs", /* Specify what module code is generated. */ | ||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ | ||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ | ||
"strict": true, /* Enable all strict type-checking options. */ | ||
"skipLibCheck": true /* Skip type checking all .d.ts files. */ | ||
} | ||
} |