Skip to content

Commit e025708

Browse files
committed
WIP
1 parent 4ebe225 commit e025708

File tree

8 files changed

+39
-56
lines changed

8 files changed

+39
-56
lines changed

Diff for: .env.example

+8-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ DATABASE_URL=
1313
# API URL
1414
NEXT_PUBLIC_API_URL=http://localhost:5000/api/
1515

16-
##########################################################################
17-
# Compulsory when running Playwright tests:
18-
##########################################################################
19-
# E2E test user credentials
20-
E2E_USER_USERNAME=
21-
E2E_USER_PASSWORD=
22-
2316
##########################################################################
2417
# Compulsory in production (aka when NODE_ENV=production):
2518
##########################################################################
@@ -122,3 +115,11 @@ WEB_CONCURRENCY= # default 1
122115

123116
# Refetch interval used to refresh session (seconds)
124117
REFETCH_INTERVAL= # default 60
118+
119+
##################################
120+
# Special for Docker Compose
121+
##################################
122+
123+
# This determines the issuer of the JWT token. In the Playwright tests, and when using the
124+
# API in the Docker container locally, this should be set to "http://keycloak:8080".
125+
KC_HOSTNAME= # by default resolves to http://localhost:8083

Diff for: .github/workflows/playwright.yml

+1-8
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,10 @@ jobs:
1717
environment: test-environment
1818
env:
1919
DATABASE_URL: ${{ vars.DATABASE_URL }}
20-
E2E_USER_USERNAME: ${{ secrets.E2E_USER_USERNAME }}
21-
E2E_USER_PASSWORD: ${{ secrets.E2E_USER_PASSWORD }}
22-
KEYCLOAK_URL: ${{ vars.KEYCLOAK_URL }}
23-
KEYCLOAK_REALM: ${{ secrets.KEYCLOAK_REALM }}
24-
KEYCLOAK_CLIENT_ID_UI: ${{ secrets.KEYCLOAK_CLIENT_ID_UI }}
25-
KEYCLOAK_CLIENT_SECRET_UI: ${{ secrets.KEYCLOAK_CLIENT_SECRET_UI }}
26-
KEYCLOAK_CLIENT_ID_API: ${{ secrets.KEYCLOAK_CLIENT_ID_API }}
27-
KEYCLOAK_CLIENT_SECRET_API: ${{ secrets.KEYCLOAK_CLIENT_SECRET_API }}
2820
NEXTAUTH_URL: http://localhost:3000
2921
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
3022
NEXT_PUBLIC_API_URL: http://localhost:3001/api/
23+
KC_HOSTNAME: http://keycloak:8080
3124
steps:
3225
- uses: actions/checkout@v4
3326
- uses: actions/setup-node@v4

Diff for: README.md

-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ To run this project you will need Node.js, npm and Docker installed.
4242

4343
```shell
4444
DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres
45-
E2E_USER_USERNAME=
46-
E2E_USER_PASSWORD=
4745
```
4846

4947
See [.env.example](https://github.com/doubleopen-project/dos/blob/main/.env.example) file for other non-compulsory configurable variables.

Diff for: apps/api/playwright.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default defineConfig({
1919

2020
testDir: "./tests/e2e",
2121
/* Run tests in files in parallel */
22-
fullyParallel: true,
22+
//fullyParallel: true,
2323
/* Fail the build on CI if you accidentally left test.only in the source code. */
2424
forbidOnly: !!process.env.CI,
2525
/* Retry on CI only */

Diff for: apps/api/tests/e2e/api.spec.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,21 @@ import {
1111
import test, { expect } from "@playwright/test";
1212
import { Zodios, ZodiosInstance } from "@zodios/core";
1313
import AdmZip from "adm-zip";
14+
import { authConfig } from "common-helpers";
1415
import { getPresignedPutUrl, S3Client } from "s3-helpers";
1516
import { dosAPI, userAPI } from "validation-helpers";
1617

1718
/**
1819
* Construct Zodios callers for the API endpoints to easily call them in the tests.
1920
*/
2021

21-
const server = process.env.KEYCLOAK_URL;
22-
const realm = process.env.KEYCLOAK_REALM;
23-
const clientId = process.env.KEYCLOAK_CLIENT_ID_API;
24-
const clientSecret = process.env.KEYCLOAK_CLIENT_SECRET_API;
25-
const username = process.env.E2E_USER_USERNAME;
26-
const password = process.env.E2E_USER_PASSWORD;
27-
28-
if (!server || !realm || !clientId || !clientSecret || !username || !password) {
29-
throw new Error(
30-
"KEYCLOAK_URL, KEYCLOAK_REALM, KEYCLOAK_CLIENT_ID_API, KEYCLOAK_CLIENT_SECRET_API, E2E_USER_USERNAME and E2E_USER_PASSWORD environment variables must be set",
31-
);
32-
}
22+
const server = authConfig.url;
23+
const realm = authConfig.realm;
24+
const clientId = authConfig.clientIdUI;
25+
const clientSecret = authConfig.clientSecretUI;
26+
const username = "test-user";
27+
const password = "test-user";
28+
const apiPort = process.env.PORT || "3001";
3329

3430
const s3Client = S3Client(
3531
process.env.NODE_ENV !== "production",
@@ -72,13 +68,17 @@ test.describe("API lets authenticated users to", () => {
7268
const body = await result.json();
7369
keycloakToken = (body as { access_token: string }).access_token;
7470

75-
userZodios = new Zodios("http://localhost:3001/api/user/", userAPI, {
76-
axiosConfig: {
77-
headers: {
78-
Authorization: `Bearer ${keycloakToken}`,
71+
userZodios = new Zodios(
72+
`http://localhost:${apiPort}/api/user`,
73+
userAPI,
74+
{
75+
axiosConfig: {
76+
headers: {
77+
Authorization: `Bearer ${keycloakToken}`,
78+
},
7979
},
8080
},
81-
});
81+
);
8282

8383
const userToken = await userZodios.put("/token", undefined, {
8484
headers: {
@@ -88,7 +88,7 @@ test.describe("API lets authenticated users to", () => {
8888

8989
dosToken = userToken.token;
9090

91-
dosZodios = new Zodios("http://localhost:3001/api/", dosAPI, {
91+
dosZodios = new Zodios(`http://localhost:${apiPort}/api/`, dosAPI, {
9292
axiosConfig: {
9393
headers: {
9494
Authorization: `Bearer ${dosToken}`,

Diff for: apps/clearance_ui/tests/e2e/global.setup.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import { expect, test as setup } from "@playwright/test";
66
import { STORAGE_STATE } from "../../playwright.config";
77

88
setup("logs in", async ({ page }) => {
9-
if (!process.env.E2E_USER_USERNAME || !process.env.E2E_USER_PASSWORD) {
10-
throw new Error(
11-
"E2E_USER_USERNAME and E2E_USER_PASSWORD environment variables must be set",
12-
);
13-
}
149
// Clear old session cookie from the browser
1510
await page.goto("/api/auth/signout");
1611

@@ -24,8 +19,8 @@ setup("logs in", async ({ page }) => {
2419
await page.click("button:has-text('Sign in with Keycloak')");
2520

2621
// Fill the login form
27-
await page.fill("#username", process.env.E2E_USER_USERNAME);
28-
await page.fill("#password", process.env.E2E_USER_PASSWORD);
22+
await page.fill("#username", "test-user");
23+
await page.fill("#password", "test-user");
2924

3025
// Submit login form
3126
await page.click('button[type="submit"]');

Diff for: docker-compose.yml

+9-11
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ services:
8585
environment:
8686
- KC_BOOTSTRAP_ADMIN_USERNAME=keycloak-admin
8787
- KC_BOOTSTRAP_ADMIN_PASSWORD=keycloak-admin
88+
- KC_HOSTNAME=$KC_HOSTNAME # Set this to http://keycloak:8080 when using API in docker-compose
8889
healthcheck:
8990
test: timeout 10s bash -c ':> /dev/tcp/localhost/8080'
9091
interval: 10s
@@ -112,10 +113,7 @@ services:
112113
- 3001:3001
113114
environment:
114115
- DATABASE_URL=postgresql://postgres:postgres@postgres:5432/postgres
115-
- KEYCLOAK_URL=$KEYCLOAK_URL
116-
- KEYCLOAK_REALM=$KEYCLOAK_REALM
117-
- KEYCLOAK_CLIENT_ID_API=$KEYCLOAK_CLIENT_ID_API
118-
- KEYCLOAK_CLIENT_SECRET_API=$KEYCLOAK_CLIENT_SECRET_API
116+
- KEYCLOAK_URL=http://keycloak:8080
119117
- ALLOWED_ORIGINS=http://localhost:3002,http://localhost:3000
120118
- SPACES_ENDPOINT=http://minio:9000
121119
- REDIS_URL=redis://redis:6379
@@ -138,6 +136,12 @@ services:
138136
minio:
139137
condition: service_healthy
140138
required: true
139+
keycloak:
140+
condition: service_healthy
141+
required: true
142+
terraform:
143+
condition: service_completed_successfully
144+
required: true
141145

142146
scanner-worker:
143147
build:
@@ -158,13 +162,7 @@ services:
158162
environment:
159163
- NEXTAUTH_URL=http://localhost:3002
160164
- NEXTAUTH_SECRET=$NEXTAUTH_SECRET
161-
- KEYCLOAK_URL=$KEYCLOAK_URL
162-
- KEYCLOAK_CLIENT_ID_UI=$KEYCLOAK_CLIENT_ID_UI
163-
- KEYCLOAK_CLIENT_ID_API=$KEYCLOAK_CLIENT_ID_API
164-
- KEYCLOAK_CLIENT_SECRET_UI=$KEYCLOAK_CLIENT_SECRET_UI
165-
- KEYCLOAK_REALM=dos-dev
166-
ports:
167-
- 3002:3000
165+
- KEYCLOAK_URL=http://keycloak:8080
168166

169167
volumes:
170168
db-data:

Diff for: turbo.json

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
"DB_RETRY_INTERVAL",
1212
"DEBUG",
1313
"DL_CONCURRENCY",
14-
"E2E_USER_USERNAME",
15-
"E2E_USER_PASSWORD",
1614
"KEYCLOAK_CLIENT_ID_API",
1715
"KEYCLOAK_CLIENT_ID_UI",
1816
"KEYCLOAK_CLIENT_SECRET_API",

0 commit comments

Comments
 (0)