Skip to content

Commit 90a2c29

Browse files
[CDAPI-95]: Updated endpoint validation to require Composition and included initial validation
1 parent f55afb7 commit 90a2c29

41 files changed

Lines changed: 1231 additions & 815 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bruno/APIM/Get_Auth_Token.bru

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ meta {
55
}
66

77
post {
8-
url: https://internal-dev.api.service.nhs.uk/oauth2/token
8+
url: https://{{APIM_ENV}}.api.service.nhs.uk/oauth2/token
99
body: formUrlEncoded
1010
auth: none
1111
}
@@ -16,12 +16,50 @@ body:form-urlencoded {
1616
}
1717

1818
script:pre-request {
19-
const { generateAuthToken } = require("../common/auth-token");
20-
generateAuthToken(bru, req, "https://internal-dev.api.service.nhs.uk/oauth2/token", "kid-1");
19+
function generateAuthToken(bru, req, audienceUrl, kid) {
20+
const jwt = require("jsonwebtoken");
21+
const fs = require("node:fs");
22+
const crypto = require("node:crypto");
23+
24+
const secret = bru.getEnvVar("JWT_SECRET");
25+
const privateKeyPath = bru.getEnvVar("PRIVATE_KEY_PATH");
26+
27+
if (!secret) {
28+
throw new Error("JWT_SECRET environment variable is missing.");
29+
}
30+
if (!privateKeyPath) {
31+
throw new Error("PRIVATE_KEY_PATH environment variable is missing.");
32+
}
33+
34+
const privateKey = fs.readFileSync(privateKeyPath);
35+
36+
const payload = {
37+
sub: secret,
38+
iss: secret,
39+
jti: crypto.randomUUID(),
40+
aud: audienceUrl,
41+
exp: (Date.now() / 1000) + 300
42+
};
43+
44+
const options = {
45+
algorithm: 'RS512',
46+
header: { kid: kid }
47+
};
48+
49+
const token = jwt.sign(payload, privateKey, options);
50+
51+
let new_body = req.getBody();
52+
new_body.push({ name: "client_assertion", value: token });
53+
54+
req.setBody(new_body);
55+
}
56+
57+
const environment = bru.getGlobalEnvVar("APIM_ENV")
58+
generateAuthToken(bru, req, `https://${environment}.api.service.nhs.uk/oauth2/token`, bru.getEnvVar("KID"));
2159
}
2260

2361
script:post-response {
24-
bru.setEnvVar("auth_token", res.getBody().access_token)
62+
bru.setGlobalEnvVar("auth_token", res.getBody().access_token)
2563
}
2664

2765
settings {

bruno/APIM/Post_Document_Bundle_via_APIM.bru

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ meta {
55
}
66

77
post {
8-
url: https://internal-dev.api.service.nhs.uk/pathology-laboratory-reporting-pr-{{PR_NUMBER}}/FHIR/R4/Bundle
8+
url: https://{{APIM_ENV}}.api.service.nhs.uk/pathology-laboratory-reporting-pr-{{PR_NUMBER}}/FHIR/R4/Bundle
99
body: json
1010
auth: inherit
1111
}
@@ -20,14 +20,16 @@ body:json {
2020
"type": "document",
2121
"entry": [
2222
{
23-
"fullUrl": "patient",
24-
"resource": {
25-
"resourceType": "Patient",
26-
"identifier": {
27-
"system": "https://fhir.nhs.uk/Id/nhs-number",
28-
"value": "test-nhs-number"
29-
}
23+
"fullUrl": "composition",
24+
"resource": {
25+
"resourceType": "Composition",
26+
"subject": {
27+
"identifier": {
28+
"system": "https://fhir.nhs.uk/Id/nhs-number",
29+
"value": "test-nhs-number"
30+
}
3031
}
32+
}
3133
}
3234
]
3335
}

bruno/APIM/README.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,35 @@ Your feature branch must have an open pull request (draft or ready for review) t
1414

1515
The following environment variables will need to be configured in Bruno:
1616

17-
| Variable | Description | Example |
18-
| ------------------ | ---------------------------------------------------- | ----------------------------- |
19-
| `PRIVATE_KEY_PATH` | Path to your private key file on your local machine | `/home/user/.ssh/api-key.pem` |
20-
| `JWT_SECRET` | Active API Key from your Developer Hub application | `your-api-key-here` |
21-
| `PR_NUMBER` | The pull request number for your preview environment | `123` |
17+
| Variable | Description | Example |
18+
| ------------------ | ---------------------------------------------------- | ----------------------------- |
19+
| `PRIVATE_KEY_PATH` | Path to your private key file on your local machine | `/home/user/.ssh/api-key.pem` |
20+
| `JWT_SECRET` | Active API Key from your Developer Hub application | `your-api-key-here` |
21+
| `PR_NUMBER` | The pull request number for your preview environment | `123` |
22+
| `APIM_ENV` | The APIM environment you're testing against | `internal-dev` |
23+
| `KID` | The Key ID to utilise when generating an access token | `INT-1` |
2224

23-
### 3. Developer Hub Application Setup
25+
### 3. Bruno Global Environment Variables
26+
27+
The following environment variables also need to be configured as global variables in Bruno:
28+
29+
| Variable | Description | Example | Secret |
30+
| ------------------ | ----------------------------------------------------- | ----------------------------- | ------ |
31+
| `APIM_ENV` | The APIM environment you're testing against | `internal-dev` | |
32+
| `auth_token` | The auth token to use when accessing APIM | `your-auth-token-here` | x |
33+
34+
### 4. Developer Hub Application Setup
2435

2536
Register an application on the [Internal Developer Hub](https://dos-internal.ptl.api.platform.nhs.uk/Index):
2637

2738
1. Generate a public/private key pair
2839
2. Upload the public key to your application
2940
3. Copy the **Active API Key** and set it as the `JWT_SECRET` environment variable in Bruno
3041

31-
### 4. Configure Proxy Endpoint
42+
### 5. Configure Proxy Endpoint
3243

33-
The POST request URL automatically targets your preview environment proxy using the `PR_NUMBER` environment variable, which you will need to set. The URL follows this format:
44+
The POST request URL automatically targets your preview environment proxy using the `PR_NUMBER` and `APIM_ENV` environment variables, which you will need to set. The URL follows this format:
3445

3546
```text
36-
https://internal-dev.api.service.nhs.uk/pathology-laboratory-reporting-pr-{{PR_NUMBER}}/FHIR/R4/Bundle
47+
https://{{APIM_ENV}}.api.service.nhs.uk/pathology-laboratory-reporting-pr-{{PR_NUMBER}}/FHIR/R4/Bundle
3748
```

bruno/APIM/environments/APIM.bru

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ vars:secret [
22
PRIVATE_KEY_PATH,
33
JWT_SECRET,
44
PR_NUMBER,
5-
auth_token
5+
KID
66
]

bruno/PDM/Bundle/Post_a_Batch_Bundle_with_gets.bru

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ meta {
55
}
66

77
post {
8-
url: https://int.api.service.nhs.uk/patient-data-manager/FHIR/R4/
8+
url: https://{{APIM_ENV}}.api.service.nhs.uk/patient-data-manager/FHIR/R4/
99
body: json
1010
auth: inherit
1111
}

bruno/PDM/Bundle/Post_a_Transaction_Bundle.bru

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ meta {
55
}
66

77
post {
8-
url: https://int.api.service.nhs.uk/patient-data-manager/FHIR/R4/
8+
url: https://{{APIM_ENV}}.api.service.nhs.uk/patient-data-manager/FHIR/R4/
99
body: json
1010
auth: inherit
1111
}

bruno/PDM/Bundle/folder.bru

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
meta {
22
name: Bundle
3-
seq: 6
3+
seq: 4
44
}
55

66
auth {

bruno/PDM/Document/Post_a_Document.bru

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ meta {
55
}
66

77
post {
8-
url: https://int.api.service.nhs.uk/patient-data-manager/FHIR/R4/Bundle
8+
url: https://{{APIM_ENV}}.api.service.nhs.uk/patient-data-manager/FHIR/R4/Bundle
99
body: json
1010
auth: inherit
1111
}

bruno/PDM/Document/Post_a_Document_Pathology-Bundle-CRP-Report-Document-Example.bru

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ meta {
55
}
66

77
post {
8-
url: https://int.api.service.nhs.uk/patient-data-manager/FHIR/R4/Bundle
8+
url: https://{{APIM_ENV}}.api.service.nhs.uk/patient-data-manager/FHIR/R4/Bundle
99
body: json
1010
auth: inherit
1111
}

bruno/PDM/Document/Retrieve_Document.bru

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ meta {
55
}
66

77
get {
8-
url: https://int.api.service.nhs.uk/patient-data-manager/FHIR/R4/Bundle/6a0c6a4d-9941-35cf-b83d-76fa4b880a85
8+
url: https://{{APIM_ENV}}.api.service.nhs.uk/patient-data-manager/FHIR/R4/Bundle/6a0c6a4d-9941-35cf-b83d-76fa4b880a85
99
body: none
1010
auth: inherit
1111
}

0 commit comments

Comments
 (0)