Skip to content

Commit

Permalink
ATO-1237: change response object to assert full client registry object
Browse files Browse the repository at this point in the history
 - added a client config request object
 - update body matcher to use like instead of eachLike as eachLike are for arrays of objects which was causing an error
  • Loading branch information
isaac-GDS committed Jan 14, 2025
1 parent 6eaaa35 commit 6bb8bf1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 31 deletions.
11 changes: 11 additions & 0 deletions backend/api/src/handlers/types/client-config-request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type clientConfigRequest = {
client_name: string;
public_key: string;
redirect_uris: string[];
contacts: string[];
scopes: string[];
subject_type: string;
service_type: string;
sector_identifier_uri: string;
client_locs: string[];
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import {MatchersV3, PactV3} from "@pact-foundation/pact";
import * as path from "path";
import {public_key, registerClientHandler, RegisterClientPayload} from "../../../src/handlers/auth/register-client";
import {clientConfigRequest} from "../../../src/handlers/types/client-config-request";
import {clientRegistryResponse} from "../../../src/handlers/types/client-registry-response";
import {mockLambdaContext} from "../../handlers/utils";
import {updateClientInRegistryHandler, UpdateClientPayload} from "../../../src/handlers/auth/update-client";
Expand All @@ -12,7 +13,7 @@ beforeAll((): void => {
});

describe("ClientRegistryProvider", () => {
const {eachLike} = MatchersV3;
const {like} = MatchersV3;

const provider = new PactV3({
dir: path.resolve(process.cwd(), "pacts"),
Expand All @@ -31,7 +32,7 @@ describe("ClientRegistryProvider", () => {
}
};

const client_config = {
const client_config: clientConfigRequest = {
client_name: postEvent.service.serviceName,
public_key: public_key,
redirect_uris: ["http://localhost/"],
Expand All @@ -43,7 +44,18 @@ describe("ClientRegistryProvider", () => {
client_locs: ["P2"]
};

const {client_locs, ...expected_returned_values} = client_config;
const expected_response: clientRegistryResponse = createExpectedResponse();

expected_response.client_name = client_config.client_name;
expected_response.public_key = client_config.public_key;
expected_response.redirect_uris = client_config.redirect_uris;
expected_response.contacts = client_config.contacts;
expected_response.scopes = client_config.scopes;
expected_response.subject_type = client_config.subject_type;
expected_response.service_type = client_config.service_type;
expected_response.sector_identifier_uri = client_config.sector_identifier_uri;
expected_response.public_key_source = null;
expected_response.channel = null;

test("it should return an a client registry object when adding a client", async () => {
provider
Expand All @@ -59,7 +71,7 @@ describe("ClientRegistryProvider", () => {
})
.willRespondWith({
status: 200,
body: eachLike(expected_returned_values),
body: like(expected_response),
contentType: "application/json",
headers: {
"Content-Type": "application/json"
Expand All @@ -69,7 +81,7 @@ describe("ClientRegistryProvider", () => {
await provider.executeTest(async mockProvider => {
process.env.AUTH_REGISTRATION_BASE_URL = mockProvider.url;
const results = await registerClientHandler(postEvent, mockLambdaContext);
expect(JSON.parse(results.body)).toMatchObject(expected_returned_values);
expect(JSON.parse(results.body)).toMatchObject(expected_response);
});
});
});
Expand All @@ -81,37 +93,18 @@ describe("ClientRegistryProvider", () => {
};

const putEvent: UpdateClientPayload = {
clientId: "testClientId",
clientId: "testClientIdExampleText1234",
serviceId: "testServiceId",
selfServiceClientId: "testSelfServiceClientId",
updates: {
...updatesForClient
}
};

const expected_response: clientRegistryResponse = {
client_name: "testClientUpdateResponseName",
public_key: "testClientPublicKey",
public_key_source: "STATIC",
redirect_uris: ["http://testClientUrl"],
contacts: updatesForClient.contacts,
scopes: ["openid", "email"],
subject_type: updatesForClient.subject_type,
service_type: "MANDATORY",
sector_identifier_uri: "http://gov.uk",
client_id: "testClientId",
post_logout_redirect_uris: [],
back_channel_logout_uri: null,
token_endpoint_auth_method: "private_key_jwt",
response_type: "code",
jar_validation_required: false,
claims: [],
client_type: "web",
id_token_signing_algorithm: "ES256",
jwks_uri: null,
channel: "WEB",
max_age_enabled: false
};
const expected_response: clientRegistryResponse = createExpectedResponse();

expected_response.contacts = updatesForClient.contacts;
expected_response.subject_type = updatesForClient.subject_type;

test("it should return an a client registry object when updating a client", async () => {
provider
Expand All @@ -127,7 +120,7 @@ describe("ClientRegistryProvider", () => {
})
.willRespondWith({
status: 200,
body: eachLike(expected_response),
body: like(expected_response),
contentType: "application/json",
headers: {
"Content-Type": "application/json"
Expand All @@ -137,8 +130,34 @@ describe("ClientRegistryProvider", () => {
await provider.executeTest(async mockProvider => {
process.env.AUTH_REGISTRATION_BASE_URL = mockProvider.url;
const results = await updateClientInRegistryHandler(putEvent, mockLambdaContext);
expect(JSON.parse(results.body)[0]).toMatchObject(expected_response);
expect(JSON.parse(results.body)).toMatchObject(expected_response);
});
});
});

function createExpectedResponse(): clientRegistryResponse {
return {
client_name: "testClientUpdateResponseName",
public_key: "testClientPublicKey",
public_key_source: "STATIC",
redirect_uris: ["http://testClientUrl"],
contacts: [],
scopes: ["openid", "email"],
subject_type: "pairwise",
service_type: "MANDATORY",
sector_identifier_uri: "http://gov.uk",
client_id: "testClientIdExampleText1234",
post_logout_redirect_uris: [],
back_channel_logout_uri: null,
token_endpoint_auth_method: "private_key_jwt",
response_type: "code",
jar_validation_required: false,
claims: [],
client_type: "web",
id_token_signing_algorithm: "ES256",
jwks_uri: null,
channel: "WEB",
max_age_enabled: false
};
}
});

0 comments on commit 6bb8bf1

Please sign in to comment.