-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Jasper Herzberg <jhrzbrg@outlook.com>
- Loading branch information
1 parent
4d76234
commit 5f551bd
Showing
37 changed files
with
708 additions
and
174 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
### Development Tokens | ||
|
||
This file contains some development tokens that can be used to directly call the | ||
API with pre-defined claims. The test users are equivalent to the users used in | ||
[E2Es](../spa-e2e/README.md) and the test users registered in the development | ||
application of our AAD. | ||
|
||
| **Username** | **ID** (`oid`) | **First name** (`first_name`) | **Last name** (`last_name`) | **Emails** (`emails`) | Token | | ||
| ------------ | ------------------------------------ | ----------------------------- | --------------------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| testuser | c0cc4404-7907-4480-86d3-ba4bfc513c6d | Test | User | testuser@kordis-leitstelle.de | `eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJvaWQiOiIxMjM0IiwiZW1haWxzIjpbInRlc3R1c2VyQHRlc3QuY29tIl0sImdpdmVuX25hbWUiOiJUZXN0IiwiZmFtaWx5X25hbWUiOiJVc2VyIDEifQ.` | | ||
|
||
The claims will be mapped to the | ||
[AuthUser](../../libs/shared/auth/src/lib/auth-user.model.ts) Model in the | ||
[AuthInterceptor](../../libs/api/auth/src/lib/interceptors/auth.interceptor.ts). |
This file was deleted.
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,18 @@ | ||
# Kordis E2E Tests | ||
|
||
For End-to-End testing we use | ||
[Playwright](https://playwright.dev/docs/api/class-playwright). You can run all | ||
Tests with `npm run e2e`. By default, tests are run in headless mode, you can | ||
adjust the [Playwright configuration](./playwright.config.ts) if needed for | ||
local testing. Make sure that you serve the API and the SPA | ||
`npm run serve:all:prod`. If you want to test against an Azure Active Directory | ||
as OAuth Provider, you have to also specify `AADB2C_TEST_USERS` as env variable | ||
with the test users username and password | ||
`[['testusername', 'testpassword'], ...]` (check the | ||
[auth setup](./src/auth.setup.ts) for more information). In this case, the SPA | ||
environment also needs an OAuth configuration. If you leave it empty, it will | ||
run with the Dev Login, which is the default for local dev workstations. | ||
|
||
We have a set of test users. Each test can be executed in the context of a user | ||
with the [`asUser(<username>)`](./src/test-users.ts) function. No need to | ||
explicitly log in or out. |
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,18 +1,38 @@ | ||
import { test as setup } from '@playwright/test'; | ||
|
||
import { LoginPo } from './page-objects/login.po'; | ||
import { getAuthStoragePath, testUserPasswords } from './test-users'; | ||
import { TestUsernames, getAuthStoragePath, testUsernames } from './test-users'; | ||
|
||
// Documentation: https://playwright.dev/docs/auth#multiple-signed-in-roles | ||
|
||
setup('authenticate as testusers', async ({ browser }) => { | ||
for (const [username, password] of testUserPasswords.entries()) { | ||
const context = await browser.newContext(); | ||
const page = await context.newPage(); | ||
await new LoginPo(page).login(username, password); | ||
await page.waitForURL('/protected'); | ||
/** | ||
* If Active Directory B2C Users are set, we use them (e.g. in Next Deployment E2Es), | ||
* otherwise we fall back to our preset users for the DevAuthModule that have the same claims and usernames. | ||
*/ | ||
if (process.env.AADB2C_TEST_USERS) { | ||
const testUserPasswords: ReadonlyMap<TestUsernames, string> = new Map( | ||
JSON.parse(process.env.AADB2C_TEST_USERS), | ||
); | ||
|
||
await context.storageState({ path: getAuthStoragePath(username) }); | ||
await context.close(); | ||
for (const [username, password] of testUserPasswords.entries()) { | ||
const context = await browser.newContext(); | ||
const page = await context.newPage(); | ||
await new LoginPo(page).loginWithB2C(username, password); | ||
await page.waitForURL('/protected'); | ||
|
||
await context.storageState({ path: getAuthStoragePath(username) }); | ||
await context.close(); | ||
} | ||
} else { | ||
for (const username of testUsernames) { | ||
const context = await browser.newContext(); | ||
const page = await context.newPage(); | ||
await new LoginPo(page).loginViaDevAuth(username); | ||
await page.waitForURL('/protected'); | ||
|
||
await context.storageState({ path: getAuthStoragePath(username) }); | ||
await context.close(); | ||
} | ||
} | ||
}); |
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 |
---|---|---|
@@ -1,21 +1,12 @@ | ||
import { config as configEnv } from 'dotenv'; | ||
import * as path from 'path'; | ||
import { test } from '@playwright/test'; | ||
|
||
export type testUsernames = 'testuser'; | ||
export const testUsernames = ['testuser'] as const; | ||
export type TestUsernames = (typeof testUsernames)[number]; | ||
|
||
if (!process.env.CI) { | ||
configEnv({ | ||
path: path.resolve(__dirname, '../../.env'), | ||
}); | ||
export function getAuthStoragePath(username: TestUsernames): string { | ||
return `playwright/.auth/${username}.json`; | ||
} | ||
|
||
/* | ||
You should take a close look at what test user runs what test, so you do not use any user that might execute test that have side effects on your test! | ||
*/ | ||
export const testUserPasswords: ReadonlyMap<testUsernames, string> = new Map( | ||
JSON.parse(process.env.TEST_USERS), | ||
); | ||
|
||
export function getAuthStoragePath(username: testUsernames): string { | ||
return `playwright/.auth/${username}.json`; | ||
export function asUser(username: TestUsernames): void { | ||
test.use({ storageState: getAuthStoragePath(username) }); | ||
} |
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,8 @@ | ||
import { AuthConfig } from 'angular-oauth2-oidc'; | ||
|
||
export type Environment = { | ||
production: boolean; | ||
apiUrl: string; | ||
deploymentName: string; | ||
oauth?: { discoveryDocumentUrl: string; config: AuthConfig }; | ||
}; |
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,21 +1,8 @@ | ||
export const environment = { | ||
import { Environment } from './environment.model'; | ||
|
||
export const environment: Environment = { | ||
production: $IS_PRODUCTION, | ||
deploymentName: '$DEPLOYMENT_NAME', | ||
apiUrl: '$API_URL', | ||
oauth: { // todo: replace this with /$/OAUTH_CONFIG before merge into main | ||
config: { | ||
redirectUri: window.origin + '/auth', | ||
oidc: true, | ||
responseType: 'code', | ||
clientId: '6b5aa2b3-6237-44ba-8448-252052e73831', | ||
issuer: | ||
'https://kordisleitstelle.b2clogin.com/5b974891-a530-4e68-ac04-e26a18c3bd46/v2.0/', | ||
tokenEndpoint: | ||
'https://kordisleitstelle.b2clogin.com/kordisleitstelle.onmicrosoft.com/b2c_1_signin/oauth2/v2.0/token', | ||
scope: 'openid offline_access 6b5aa2b3-6237-44ba-8448-252052e73831', | ||
strictDiscoveryDocumentValidation: false, | ||
}, | ||
discoveryDocumentUrl: | ||
'https://kordisleitstelle.b2clogin.com/kordisleitstelle.onmicrosoft.com/B2C_1_SignIn/v2.0/.well-known/openid-configuration', | ||
}, | ||
oauth: $OAUTH_CONFIG as any, | ||
}; |
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,23 +1,7 @@ | ||
import { AuthConfig } from 'angular-oauth2-oidc'; | ||
import { Environment } from './environment.model'; | ||
|
||
export const environment = { | ||
export const environment: Environment = { | ||
production: false, | ||
deploymentName: 'Dev Local', | ||
apiUrl: 'https://localhost:3333', | ||
oauth: { | ||
config: { | ||
redirectUri: window.origin + '/auth', | ||
oidc: true, | ||
responseType: 'code', | ||
clientId: '6b5aa2b3-6237-44ba-8448-252052e73831', | ||
issuer: | ||
'https://kordisleitstelle.b2clogin.com/5b974891-a530-4e68-ac04-e26a18c3bd46/v2.0/', | ||
tokenEndpoint: | ||
'https://kordisleitstelle.b2clogin.com/kordisleitstelle.onmicrosoft.com/b2c_1_signin/oauth2/v2.0/token', | ||
scope: 'openid offline_access 6b5aa2b3-6237-44ba-8448-252052e73831', | ||
strictDiscoveryDocumentValidation: false, | ||
} as AuthConfig, | ||
discoveryDocumentUrl: | ||
'https://kordisleitstelle.b2clogin.com/kordisleitstelle.onmicrosoft.com/B2C_1_SignIn/v2.0/.well-known/openid-configuration', | ||
}, | ||
apiUrl: 'https://localhost:3000', | ||
}; |
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
Oops, something went wrong.