Skip to content

Commit 72aa73e

Browse files
Tests
1 parent 205633f commit 72aa73e

File tree

8 files changed

+108
-44
lines changed

8 files changed

+108
-44
lines changed

.vscode/settings.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,14 @@
1111
//".devcontainer": true,
1212
".github": false,
1313
".vscode": false
14-
}
14+
},
15+
"cSpell.words": [
16+
"Afwo",
17+
"apikey",
18+
"APIM",
19+
"headerauth",
20+
"headervalue",
21+
"NHSD",
22+
"Ogub"
23+
]
1524
}

tests/config/playwright.base.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { PlaywrightTestConfig } from '@playwright/test';
2+
import { getReporters } from './reporters';
23

34
const baseUrl = process.env.NHSD_APIM_PROXY_URL || 'http://localhost:3000/';
45
const envMaxInstances = Number.parseInt(process.env.WORKERS_MAX_INST!) || 10;
@@ -8,6 +9,7 @@ const envMaxInstances = Number.parseInt(process.env.WORKERS_MAX_INST!) || 10;
89
export const config: PlaywrightTestConfig = {
910
testDir: '../sandbox/messages/get_single_letter/',
1011
testMatch: '**/*.ts',
12+
reporter: getReporters('api-test'),
1113
/* Maximum time one test can run for. */
1214
timeout: 60 * 1000,
1315
workers: envMaxInstances,

tests/constants/api_constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
//export const COMMSTABLENAME = `comms-${env}-api-stg-comms-mgr`;
2+
export const DEV_API_GATEWAY_URL = "https://internal-dev.api.service.nhs.uk/nhs-notify-supplier-PR-136/";
3+
export const API_KEY = "F3ir2EgOReLtHOgubFxCTAfwoERoFEgu";
4+
export const LETTERS_ENDPOINT = 'letters';

tests/mtls/mtls_test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { test, expect, request, APIRequestContext } from '@playwright/test';
2+
import { DEV_API_GATEWAY_URL } from '../constants/api_constants';
3+
4+
// Assume you have your constants in a config file
5+
const INT_API_GATEWAY_URL = DEV_API_GATEWAY_URL;
6+
7+
test.describe('test mTLS connection', () => {
8+
test('Ensure that the mTLS is enabled on internal-dev API backend services', async () => {
9+
let apiContext: APIRequestContext | null = null;
10+
11+
try {
12+
// Create a new request context (without client certs)
13+
apiContext = await request.newContext();
14+
15+
// Expect this GET request to throw due to SSL/mTLS enforcement
16+
await expect(async () => {
17+
await apiContext!.get(INT_API_GATEWAY_URL, {
18+
headers: { "X-Client-Id": "hello" }
19+
});
20+
}).rejects.toThrow();
21+
} finally {
22+
if (apiContext) {
23+
await apiContext.dispose();
24+
}
25+
}
26+
});
27+
});

tests/mtls/test_mtls.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { test, expect, request, APIRequestContext } from '@playwright/test';
2+
3+
// Assume you have your constants in a config file
4+
const INT_API_GATEWAY_URL = process.env.INT_API_GATEWAY_URL || "https://your-int-api-gateway-url";
5+
6+
test.describe('mTLS Integration API', () => {
7+
test('should fail when connecting without client certificate', async () => {
8+
let apiContext: APIRequestContext | null = null;
9+
10+
try {
11+
// Create a new request context (without client certs)
12+
apiContext = await request.newContext();
13+
14+
// Expect this GET request to throw due to SSL/mTLS enforcement
15+
await expect(async () => {
16+
await apiContext!.get(INT_API_GATEWAY_URL, {
17+
headers: { "X-Client-Id": "hello" }
18+
});
19+
}).rejects.toThrow();
20+
} finally {
21+
if (apiContext) {
22+
await apiContext.dispose();
23+
}
24+
}
25+
});
26+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { test, expect } from '@playwright/test';
2+
import { DEV_API_GATEWAY_URL, LETTERS_ENDPOINT} from '../../../constants/api_constants';
3+
4+
// Constants
5+
const status = "PENDING";
6+
7+
test("401 when invalid APIKEY is passed", async ({ request }) => {
8+
const headers = {
9+
headerauth1 : 'headervalue1',
10+
apikey : '',
11+
Authorization: '1234'
12+
};
13+
14+
const API_URL = process.env.NHSD_APIM_PROXY_URL || DEV_API_GATEWAY_URL;
15+
const API_GATEWAY_URL = `${API_URL}${LETTERS_ENDPOINT}`;
16+
17+
const response = await request.get(API_GATEWAY_URL, {
18+
params: {
19+
status: `${status}`
20+
},
21+
headers
22+
});
23+
24+
await expect(response.status()).toBe(401);
25+
});

tests/sandbox/messages/get_single_letter/test_404.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
import { test, expect, APIRequestContext } from '@playwright/test';
1+
import { test, expect } from '@playwright/test';
2+
import { API_KEY, DEV_API_GATEWAY_URL, LETTERS_ENDPOINT} from '../../../constants/api_constants';
23

34
// Constants
4-
const CORRELATION_IDS = '228aac39-542d-4803-b28e-5de9e100b9f8';
5-
const REQUEST_ID = 'xx';
6-
const MESSAGES_ENDPOINT = '/letter'; // Update this path to match your constant
7-
const status = "PENDING";
5+
const STATUS = 'PENDING';
86

9-
// Parameterized test in Playwright
10-
test("200 when valid request ID", async ({ request }) => {
11-
const headers = {
12-
'Accept': '*/*',
13-
'Content-Type': 'application/json',
14-
};
7+
test("200 when valid input is passed", async ({ request }) => {
8+
const headers = {
9+
headerauth1 : 'headervalue1',
10+
apikey : API_KEY,
11+
Authorization: '1234'
12+
};
1513

16-
headers['X-Correlation-Id'] = CORRELATION_IDS;
14+
const API_URL = process.env.NHSD_APIM_PROXY_URL || DEV_API_GATEWAY_URL;
15+
const API_GATEWAY_URL = `${API_URL}${LETTERS_ENDPOINT}`;
1716

18-
const response = await request.get(`${process.env.NHSD_APIM_PROXY_URL}${MESSAGES_ENDPOINT}`, {
17+
const response = await request.get(API_GATEWAY_URL, {
1918
params: {
20-
id: `${REQUEST_ID}`
19+
status: `${STATUS}`
2120
},
2221
headers
2322
});
2423

24+
console.log(await response.json());
2525
await expect(response.status()).toBe(200);
26+
expect(response.ok()).toBeTruthy();
2627
});

0 commit comments

Comments
 (0)