From 6bb8bf175f54936f4f3f76a80c52ea3a0b1cbd79 Mon Sep 17 00:00:00 2001 From: Isaac Au Date: Mon, 6 Jan 2025 07:32:28 +0000 Subject: [PATCH] ATO-1237: change response object to assert full client registry object - 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 --- .../handlers/types/client-config-request.ts | 11 +++ .../tests/testClientRegistryContract.spec.ts | 81 ++++++++++++------- 2 files changed, 61 insertions(+), 31 deletions(-) create mode 100644 backend/api/src/handlers/types/client-config-request.ts diff --git a/backend/api/src/handlers/types/client-config-request.ts b/backend/api/src/handlers/types/client-config-request.ts new file mode 100644 index 000000000..5ad56bd57 --- /dev/null +++ b/backend/api/src/handlers/types/client-config-request.ts @@ -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[]; +}; diff --git a/backend/api/tests/contract-tests/tests/testClientRegistryContract.spec.ts b/backend/api/tests/contract-tests/tests/testClientRegistryContract.spec.ts index 0ba266f42..acafe6ab1 100644 --- a/backend/api/tests/contract-tests/tests/testClientRegistryContract.spec.ts +++ b/backend/api/tests/contract-tests/tests/testClientRegistryContract.spec.ts @@ -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"; @@ -12,7 +13,7 @@ beforeAll((): void => { }); describe("ClientRegistryProvider", () => { - const {eachLike} = MatchersV3; + const {like} = MatchersV3; const provider = new PactV3({ dir: path.resolve(process.cwd(), "pacts"), @@ -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/"], @@ -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 @@ -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" @@ -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); }); }); }); @@ -81,7 +93,7 @@ describe("ClientRegistryProvider", () => { }; const putEvent: UpdateClientPayload = { - clientId: "testClientId", + clientId: "testClientIdExampleText1234", serviceId: "testServiceId", selfServiceClientId: "testSelfServiceClientId", updates: { @@ -89,29 +101,10 @@ describe("ClientRegistryProvider", () => { } }; - 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 @@ -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" @@ -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 + }; + } });