-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +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[]; | ||
} | ||
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[]; | ||
}; |
44 changes: 22 additions & 22 deletions
44
backend/api/src/handlers/types/client-registry-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
export type clientRegistryResponse = { | ||
client_name: string; | ||
public_key: string; | ||
public_key_source: null | string; | ||
redirect_uris: string[]; | ||
contacts: string[]; | ||
scopes: string[]; | ||
subject_type: string; | ||
service_type: string; | ||
sector_identifier_uri: string; | ||
client_id: string; | ||
post_logout_redirect_uris: string[]; | ||
back_channel_logout_uri: null | string; | ||
token_endpoint_auth_method: string; | ||
response_type: string; | ||
jar_validation_required: boolean; | ||
claims: string[]; | ||
client_type: string; | ||
id_token_signing_algorithm: "ES256" | "RS256"; | ||
jwks_uri: null | string; | ||
channel: null | string; | ||
max_age_enabled: boolean; | ||
}; | ||
client_name: string; | ||
public_key: string; | ||
public_key_source: null | string; | ||
redirect_uris: string[]; | ||
contacts: string[]; | ||
scopes: string[]; | ||
subject_type: string; | ||
service_type: string; | ||
sector_identifier_uri: string; | ||
client_id: string; | ||
post_logout_redirect_uris: string[]; | ||
back_channel_logout_uri: null | string; | ||
token_endpoint_auth_method: string; | ||
response_type: string; | ||
jar_validation_required: boolean; | ||
claims: string[]; | ||
client_type: string; | ||
id_token_signing_algorithm: "ES256" | "RS256"; | ||
jwks_uri: null | string; | ||
channel: null | string; | ||
max_age_enabled: boolean; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,28 +2,43 @@ | |
|
||
import {MatchersV3, PactV3} from "@pact-foundation/pact"; | ||
import * as path from "path"; | ||
import { public_key, registerClientHandler, RegisterClientPayload } from "../../../src/handlers/auth/register-client"; | ||
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"; | ||
import {mockLambdaContext} from "../../handlers/utils"; | ||
import {updateClientInRegistryHandler, UpdateClientPayload} from "../../../src/handlers/auth/update-client"; | ||
|
||
beforeAll((): void => { | ||
jest.setTimeout(200000); | ||
jest.setTimeout(400000); | ||
}); | ||
|
||
describe("ClientRegistryProvider", () => { | ||
const {like} = MatchersV3; | ||
|
||
const provider = new PactV3({ | ||
dir: path.resolve(process.cwd(), "pacts"), | ||
logLevel: "debug", | ||
port: 8080, | ||
consumer: "SSEAdminAPIClient", | ||
provider: "ClientRegistryProvider" | ||
}); | ||
// let provider: PactV3; | ||
|
||
// beforeEach(() => { | ||
// provider = new PactV3({ | ||
// dir: path.resolve(process.cwd(), "pacts"), | ||
// logLevel: "debug", | ||
// port: 8080, | ||
// host: "127.0.0.1", | ||
// consumer: "SSEAdminAPIClient", | ||
// provider: "ClientRegistryProvider" | ||
// }); | ||
// }); | ||
|
||
describe("When a POST request is made to create a client", () => { | ||
const provider = new PactV3({ | ||
dir: path.resolve(process.cwd(), "pacts"), | ||
logLevel: "debug", | ||
port: 8080, | ||
host: "127.0.0.1", | ||
consumer: "SSEAdminAPIClient", | ||
provider: "ClientRegistryProvider" | ||
}); | ||
const contactEmail = "[email protected]"; | ||
const serviceName = "My test service"; | ||
const postEvent: RegisterClientPayload = { | ||
contactEmail: "[email protected]", | ||
service: { | ||
|
@@ -33,23 +48,23 @@ describe("ClientRegistryProvider", () => { | |
}; | ||
|
||
const client_config: clientConfigRequest = { | ||
client_name: postEvent.service.serviceName, | ||
client_name: serviceName, | ||
public_key: public_key, | ||
redirect_uris: ["http://localhost/"], | ||
contacts: [postEvent.contactEmail], | ||
contacts: [contactEmail], | ||
scopes: ["openid", "email", "phone"], | ||
subject_type: "pairwise", | ||
service_type: "MANDATORY", | ||
sector_identifier_uri: "http://gov.uk", | ||
client_locs: ["P2"] | ||
}; | ||
|
||
const expected_response: clientRegistryResponse = createExpectedResponse(); | ||
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.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; | ||
|
@@ -79,19 +94,27 @@ describe("ClientRegistryProvider", () => { | |
} | ||
}); | ||
|
||
await provider.executeTest(async mockProvider => { | ||
return provider.executeTest(async mockProvider => { | ||
process.env.AUTH_REGISTRATION_BASE_URL = mockProvider.url; | ||
const results = await registerClientHandler(postEvent, mockLambdaContext); | ||
const [results] = await Promise.all([registerClientHandler(postEvent, mockLambdaContext)]); | ||
expect(JSON.parse(results.body)).toMatchObject(expected_response); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("When a PUT request is made to update a client", () => { | ||
const provider = new PactV3({ | ||
dir: path.resolve(process.cwd(), "pacts"), | ||
logLevel: "debug", | ||
port: 8080, | ||
host: "127.0.0.1", | ||
consumer: "SSEAdminAPIClient", | ||
provider: "ClientRegistryProvider" | ||
}); | ||
const updatesForClient = { | ||
contacts: ["new.eamil@digital.cabinet-office.gov.uk"], | ||
contacts: ["new.email@digital.cabinet-office.gov.uk"], | ||
subject_type: "pairwise" | ||
} | ||
}; | ||
|
||
const putEvent: UpdateClientPayload = { | ||
clientId: "testClientIdExampleText1234", | ||
|
@@ -100,9 +123,9 @@ describe("ClientRegistryProvider", () => { | |
updates: { | ||
...updatesForClient | ||
} | ||
} | ||
}; | ||
|
||
let expected_response: any = createExpectedResponse(); | ||
const expected_response: clientRegistryResponse = createExpectedResponse(); | ||
|
||
expected_response.contacts = updatesForClient.contacts; | ||
expected_response.subject_type = updatesForClient.subject_type; | ||
|
@@ -113,10 +136,9 @@ describe("ClientRegistryProvider", () => { | |
.uponReceiving("configuration to update a client") | ||
.withRequest({ | ||
method: "PUT", | ||
path: `/connect/register/${putEvent.clientId}`, | ||
contentType: "application/json", | ||
path: "/connect/register/testClientIdExampleText1234", | ||
headers: { | ||
"Content-Type": "application/json;" | ||
"Content-Type": "application/json" | ||
}, | ||
body: updatesForClient | ||
}) | ||
|
@@ -129,10 +151,15 @@ describe("ClientRegistryProvider", () => { | |
} | ||
}); | ||
|
||
await provider.executeTest(async mockProvider => { | ||
console.log("Before test execution"); | ||
|
||
return provider.executeTest(async mockProvider => { | ||
process.env.AUTH_REGISTRATION_BASE_URL = mockProvider.url; | ||
const results = await updateClientInRegistryHandler(putEvent, mockLambdaContext); | ||
console.log("Before lambda"); | ||
const [results] = await Promise.all([updateClientInRegistryHandler(putEvent, mockLambdaContext)]); | ||
console.log("After lambda"); | ||
expect(JSON.parse(results.body)).toMatchObject(expected_response); | ||
console.log("After json parse") | ||
}); | ||
}); | ||
}); | ||
|
@@ -155,12 +182,11 @@ describe("ClientRegistryProvider", () => { | |
response_type: "code", | ||
jar_validation_required: false, | ||
claims: [], | ||
client_type: "web", | ||
client_type: "web", | ||
id_token_signing_algorithm: "ES256", | ||
jwks_uri: null, | ||
channel: "WEB", | ||
max_age_enabled: false | ||
} | ||
|
||
}; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters