Skip to content

Commit

Permalink
Merge branch 'main' into 918-rwd-menu
Browse files Browse the repository at this point in the history
  • Loading branch information
meissadia authored Oct 29, 2024
2 parents e64f3fe + ce3fc42 commit 1926079
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 16 deletions.
13 changes: 12 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,15 @@ SBL_LOGOUT_REDIRECT_URL=""
SBL_VALIDATION_TIMEOUT_SECONDS="1200"
SBL_LONGPOLLING_DELAY_SECONDS="backoff"
SBL_UPLOAD_FILE_SIZE_LIMIT_BYTES="50000000"
SBL_ENABLE_PLAYWRIGHT_TEST_SETTINGS="false"
SBL_ENABLE_PLAYWRIGHT_TEST_SETTINGS="false"
SBL_PLAYWRIGHT_TEST_TARGET="http://localhost:8899"
SBL_PLAYWRIGHT_TEST_KC_TARGET="http://localhost:8880/"
SBL_PLAYWRIGHT_TEST_KC_REALM="regtech"
SBL_PLAYWRIGHT_TEST_KC_CLI_USERNAME="admin"
SBL_PLAYWRIGHT_TEST_KC_CLI_CLIENT_ID="admin-cli"
SBL_PLAYWRIGHT_TEST_KC_CLI_CLIENT_SECRET="local_test_only"
SBL_PLAYWRIGHT_TEST_KC_CLI_GRANT_TYPE="client_credentials"
SBL_PLAYWRIGHT_TEST_KC_ADMIN_USERNAME="admin1"
SBL_PLAYWRIGHT_TEST_KC_ADMIN_PASSWORD="admin"
SBL_PLAYWRIGHT_TEST_KC_ADMIN_CLIENT_ID="regtech-client"
SBL_PLAYWRIGHT_TEST_KC_ADMIN_GRANT_TYPE="password"
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ env:
SBL_LONGPOLLING_DELAY_SECONDS: "backoff"
SBL_UPLOAD_FILE_SIZE_LIMIT_BYTES: "50000000"
SBL_ENABLE_PLAYWRIGHT_TEST_SETTINGS: "false"
SBL_PLAYWRIGHT_TEST_TARGET: "http://localhost:8899"
SBL_PLAYWRIGHT_TEST_KC_TARGET: "http://localhost:8880/"
SBL_PLAYWRIGHT_TEST_KC_REALM: "regtech"
SBL_PLAYWRIGHT_TEST_KC_CLI_USERNAME: "admin"
SBL_PLAYWRIGHT_TEST_KC_CLI_CLIENT_ID: "admin-cli"
SBL_PLAYWRIGHT_TEST_KC_CLI_CLIENT_SECRET: "local_test_only"
SBL_PLAYWRIGHT_TEST_KC_CLI_GRANT_TYPE: "client_credentials"
SBL_PLAYWRIGHT_TEST_KC_ADMIN_USERNAME: "admin1"
SBL_PLAYWRIGHT_TEST_KC_ADMIN_PASSWORD: "admin"
SBL_PLAYWRIGHT_TEST_KC_ADMIN_CLIENT_ID: "regtech-client"
SBL_PLAYWRIGHT_TEST_KC_ADMIN_GRANT_TYPE: "password"

jobs:
React:
Expand Down
11 changes: 11 additions & 0 deletions ENV-GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ SBL_VALIDATION_TIMEOUT_SECONDS="1200"
SBL_LONGPOLLING_DELAY_SECONDS="backoff"
SBL_UPLOAD_FILE_SIZE_LIMIT_BYTES="50000000"
SBL_ENABLE_PLAYWRIGHT_TEST_SETTINGS="false"
SBL_PLAYWRIGHT_TEST_TARGET="http://localhost:8899"
SBL_PLAYWRIGHT_TEST_KC_TARGET="http://localhost:8880/"
SBL_PLAYWRIGHT_TEST_KC_REALM="regtech"
SBL_PLAYWRIGHT_TEST_KC_CLI_USERNAME="admin"
SBL_PLAYWRIGHT_TEST_KC_CLI_CLIENT_ID="admin-cli"
SBL_PLAYWRIGHT_TEST_KC_CLI_CLIENT_SECRET="local_test_only"
SBL_PLAYWRIGHT_TEST_KC_CLI_GRANT_TYPE="client_credentials"
SBL_PLAYWRIGHT_TEST_KC_ADMIN_USERNAME="admin1"
SBL_PLAYWRIGHT_TEST_KC_ADMIN_PASSWORD="admin"
SBL_PLAYWRIGHT_TEST_KC_ADMIN_CLIENT_ID="regtech-client"
SBL_PLAYWRIGHT_TEST_KC_ADMIN_GRANT_TYPE="password"
```

### To add a new environment variable
Expand Down
43 changes: 43 additions & 0 deletions e2e/utils/authConstants.ts
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,
},
};
17 changes: 9 additions & 8 deletions e2e/utils/createKeycloakUser.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { KeycloakAdminClient } from '@s3pweb/keycloak-admin-client-cjs';
import { config } from './authConstants';

export class KeycloakService {
private readonly kcAdminClient: KeycloakAdminClient;

constructor() {
this.kcAdminClient = new KeycloakAdminClient({
baseUrl: 'http://localhost:8880/',
realmName: 'regtech',
baseUrl: config.target,
realmName: config.realm,
});
}
}

const kcAdminClient = new KeycloakAdminClient({
baseUrl: 'http://localhost:8880/',
realmName: 'regtech',
baseUrl: config.target,
realmName: config.realm,
});

interface CreateKeycloakUserProperties {
Expand All @@ -35,10 +36,10 @@ export default async function createKeycloakUser({
// Authorize with username / password
try {
await kcAdminClient.auth({
username: 'admin',
clientId: 'admin-cli',
clientSecret: 'local_test_only',
grantType: 'client_credentials',
username: config.cli.username,
clientId: config.cli.clientId,
clientSecret: config.cli.clientSecret,
grantType: config.cli.grantType,
});
} catch (error) {
// eslint-disable-next-line no-console
Expand Down
16 changes: 10 additions & 6 deletions e2e/utils/getKeycloakToken.ts
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;
}
}
4 changes: 3 additions & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ const config: PlaywrightTestConfig = {
},
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
baseURL: 'http://localhost:8899/',
baseURL: `${
process.env.SBL_PLAYWRIGHT_TEST_TARGET ?? 'http://localhost:8899'
}/`,

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
Expand Down
11 changes: 11 additions & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ interface ImportMetaEnv {
readonly SBL_LONGPOLLING_DELAY_SECONDS: string;
readonly SBL_UPLOAD_FILE_SIZE_LIMIT_BYTES: string;
readonly SBL_ENABLE_PLAYWRIGHT_TEST_SETTINGS: string;
readonly SBL_PLAYWRIGHT_TEST_TARGET: string;
readonly SBL_PLAYWRIGHT_TEST_KC_TARGET: string;
readonly SBL_PLAYWRIGHT_TEST_KC_REALM: string;
readonly SBL_PLAYWRIGHT_TEST_KC_CLI_USERNAME: string;
readonly SBL_PLAYWRIGHT_TEST_KC_CLI_CLIENT_ID: string;
readonly SBL_PLAYWRIGHT_TEST_KC_CLI_CLIENT_SECRET: string;
readonly SBL_PLAYWRIGHT_TEST_KC_CLI_GRANT_TYPE: string;
readonly SBL_PLAYWRIGHT_TEST_KC_ADMIN_USERNAME: string;
readonly SBL_PLAYWRIGHT_TEST_KC_ADMIN_PASSWORD: string;
readonly SBL_PLAYWRIGHT_TEST_KC_ADMIN_CLIENT_ID: string;
readonly SBL_PLAYWRIGHT_TEST_KC_ADMIN_GRANT_TYPE: string;
}

interface ImportMeta {
Expand Down

0 comments on commit 1926079

Please sign in to comment.