generated from cfpb/open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[e2e] Make tests runnable against dev deployment (#1029)
Made tests configurable through environment variables in preparation for running against the dev deployment ## Changes - Created environment variables for test - Added Constants file to pull in the environment variables for test - Updated hard coded locations to use the values in the Constants file instead - Updated playwright config to pull in the base url as an environment variable ## How to test this PR 1. Read the Notes 2. Pull the branch 3. Relaunch the stack if necessary 4. Run the e2e tests and verify that they all still pass 5. Play with the envars if you wish and see that the behavior changes as the envars do ## Notest - There appears to be a test failure in InstitutionProfile.spec.ts that is coming from Design System React. - If you encounter this, you can ignore it.
- Loading branch information
1 parent
ce7802d
commit ce3fc42
Showing
8 changed files
with
110 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { GrantTypes } from '@keycloak/keycloak-admin-client/lib/utils/auth'; | ||
|
||
export interface KeycloakCLIConfig { | ||
username: string; | ||
clientId: string; | ||
clientSecret: string; | ||
grantType: GrantTypes; | ||
} | ||
|
||
export interface KeycloakAdminConfig { | ||
username: string; | ||
password: string; | ||
clientId: string; | ||
grantType: GrantTypes; | ||
} | ||
|
||
export interface KeycloakConfig { | ||
target: string; | ||
realm: string; | ||
admin: KeycloakAdminConfig; | ||
cli: KeycloakCLIConfig; | ||
} | ||
|
||
export const config: KeycloakConfig = { | ||
target: process.env.SBL_PLAYWRIGHT_TEST_KC_TARGET ?? 'http://localhost:8880/', | ||
realm: process.env.SBL_PLAYWRIGHT_TEST_KC_REALM ?? 'regtech', | ||
admin: { | ||
username: process.env.SBL_PLAYWRIGHT_TEST_KC_ADMIN_USERNAME ?? 'admin1', | ||
password: process.env.SBL_PLAYWRIGHT_TEST_KC_ADMIN_PASSWORD ?? 'admin', | ||
clientId: | ||
process.env.SBL_PLAYWRIGHT_TEST_KC_ADMIN_CLIENT_ID ?? 'regtech-client', | ||
grantType: (process.env.SBL_PLAYWRIGHT_TEST_KC_ADMIN_GRANT_TYPE ?? | ||
'password') as GrantTypes, | ||
}, | ||
cli: { | ||
username: process.env.SBL_PLAYWRIGHT_TEST_KC_CLI_USERNAME ?? 'admin', | ||
clientSecret: | ||
process.env.SBL_PLAYWRIGHT_TEST_KC_CLI_CLIENT_SECRET ?? 'local_test_only', | ||
clientId: process.env.SBL_PLAYWRIGHT_TEST_KC_CLI_CLIENT_ID ?? 'admin-cli', | ||
grantType: (process.env.SBL_PLAYWRIGHT_TEST_KC_CLI_GRANT_TYPE ?? | ||
'client_credentials') as GrantTypes, | ||
}, | ||
}; |
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,23 +1,27 @@ | ||
import axios from 'axios'; | ||
import { config } from './authConstants'; | ||
|
||
export default async function getAdminKeycloakToken(): Promise<string> { | ||
const encodedParameters = new URLSearchParams(); | ||
encodedParameters.set('username', 'admin1'); | ||
encodedParameters.set('password', 'admin'); | ||
encodedParameters.set('grant_type', 'password'); | ||
encodedParameters.set('client_id', 'regtech-client'); | ||
encodedParameters.set('username', config.admin.username); | ||
encodedParameters.set('password', config.admin.password); | ||
encodedParameters.set('grant_type', config.admin.grantType); | ||
encodedParameters.set('client_id', config.admin.clientId); | ||
|
||
const optionsForGetAdminKeycloakToken = { | ||
method: 'POST', | ||
url: 'http://localhost:8880/realms/regtech/protocol/openid-connect/token', | ||
url: `${config.target}/realms/${config.realm}/protocol/openid-connect/token`, | ||
data: encodedParameters, | ||
}; | ||
try { | ||
const { data } = await axios.request(optionsForGetAdminKeycloakToken); | ||
return data.access_token as string; | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.log('error when trying to fetch an admin token from keycloak :>> ', error); | ||
console.log( | ||
'error when trying to fetch an admin token from keycloak :>> ', | ||
error, | ||
); | ||
throw error; | ||
} | ||
} |
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