Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ version.json

# Please, add your custom content below!
.idea
.env

# dependencies
node_modules
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
//".devcontainer": true,
".github": false,
".vscode": false
}
},
}
9 changes: 9 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# Playwright
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/allure-results
/target
20 changes: 20 additions & 0 deletions tests/config/main.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { config as baseConfig } from './playwright.base.config';
import { getReporters } from './reporters';

const localConfig: PlaywrightTestConfig = {
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: getReporters('api-test'),
...baseConfig,
//globalSetup: require.resolve('./setup/globalSetup'),
//globalTeardown: require.resolve('./setup/globalTeardown'),
testIgnore: [],
projects: [
{
name: 'sandbox',
testMatch: 'tests/messages/get_single_letter/*.spec.ts',
},
],
};

export default localConfig;
42 changes: 42 additions & 0 deletions tests/config/playwright.base.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { PlaywrightTestConfig } from '@playwright/test';

const baseUrl = process.env.NHSD_APIM_PROXY_URL || 'http://localhost:3000/';
const envMaxInstances = Number.parseInt(process.env.WORKERS_MAX_INST!) || 10;
/**
* See https://playwright.dev/docs/test-configuration.
*/
export const config: PlaywrightTestConfig = {
testDir: '../sandbox/messages/get_single_letter/',
testMatch: '*.spec.ts/',
/* Maximum time one test can run for. */
timeout: 60 * 1000,
workers: envMaxInstances,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 5000,
},
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,

/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: baseUrl,
ignoreHTTPSErrors: true,
trace: 'on-first-retry',
/* Slows down Playwright operations by the specified amount of milliseconds. */
launchOptions: {
slowMo: 0,
},
},
};
export default config;
42 changes: 42 additions & 0 deletions tests/config/reporters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { ReporterDescription } from '@playwright/test';

const resultsDir = process.env.RESULTS_DIR || 'results';
const reportsDir = process.env.REPORTS_DIR || 'reports';

export function getReporters(allureFolder: string) {
return [
[
'allure-playwright',
{
outputFolder: `./target/reports/allure-results/${allureFolder}`,
detail: false,
suiteTitle: true,
open: 'always',
environmentInfo: {
E2E_NODE_VERSION: process.env.ENVIRONMENT,
E2E_OS: process.platform,
},
},
],
[
'html',
{
outputFolder: `../target/test-artifacts/${reportsDir}/html-report`,
open: process.env.CI ? 'never' : 'on-failure',
},
],
['list', { printSteps: true }],
[
'junit',
{
outputFile: `../target/test-artifacts/${resultsDir}/junit-results.xml`,
},
],
[
'json',
{
outputFile: `../target/test-artifacts/${resultsDir}/json-results.json`,
},
],
] as ReporterDescription[];
}
1 change: 1 addition & 0 deletions tests/constants/api_constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const LETTERS_ENDPOINT = 'letters';
34 changes: 34 additions & 0 deletions tests/mtls/mtls_test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { test, expect, request, APIRequestContext } from '@playwright/test';

// Assume you have your constants in a config file
const PROXY_URL = process.env.PROXY_URL;

test('should fail when connecting without client certificate', async () => {

let apiContext: APIRequestContext | null = null;

try {
apiContext = await request.newContext();
const response = await apiContext.get(PROXY_URL!, {
headers: { "X-Client-Id": "hello" }
});

// Check if request succeeded or failed
if (response.ok()) {
throw new Error(
`Expected connection failure, but got success with status ${response.status()}`
);
}
// Assert on the actual error code returned by the gateway
// For mTLS, often 401, 403, or 502 depending on infra config
expect(response.ok()).toBeFalsy();

} catch (err: any) {
// If the request truly fails at the TLS layer, Playwright will throw instead
expect(err.message).toMatch(/SSL|certificate|ECONNRESET|socket/i);
} finally {
if (apiContext) {
await apiContext.dispose();
}
}
});
179 changes: 179 additions & 0 deletions tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"author": "",
"dependencies": {
"allure-js-commons": "^3.3.3",
"charenc": "^0.0.2",
"crypt": "^0.0.2",
"dotenv": "^17.2.2",
"fsevents": "^2.3.2",
"is-buffer": "^1.1.6",
"md5": "^2.3.0",
"playwright": "^1.54.2",
"playwright-core": "^1.54.2",
"undici-types": "^7.10.0"
},
"description": "",
"devDependencies": {
"@playwright/test": "^1.55.0",
"@types/node": "^24.3.1",
"allure-commandline": "^2.34.1",
"allure-playwright": "^3.3.3"
},
"keywords": [],
"license": "ISC",
"main": "index.js",
"name": "tests",
"scripts": {
"clean": "rimraf $(pwd)/target",
"test": "playwright test tests --config=config/main.config.ts --max-failures=10"
},
"version": "1.0.0"
}
Loading
Loading