Skip to content

Commit

Permalink
[DMS-376] Add Register Test Pact File
Browse files Browse the repository at this point in the history
Signed-off-by: Moises Siles <[email protected]>
  • Loading branch information
msilesgap committed Nov 11, 2024
1 parent 8830d1c commit e6e6b82
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@
"name": "ConfigurationService-API"
},
"interactions": [
{
"description": "A register request when registration is disabled",
"request": {
"body": {
"clientid": "CSClient2",
"clientsecret": "test123@Puiu",
"displayname": "[email protected]"
},
"headers": {
"Content-Type": "application/json"
},
"method": "POST",
"path": "/connect/register"
},
"response": {
"headers": {
"Content-Type": "application/json"
},
"status": 404
}
},
{
"description": "A request for an access token with a valid credentials",
"request": {
Expand Down Expand Up @@ -37,4 +58,4 @@
"provider": {
"name": "Register"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,34 @@ await pact.VerifyAsync(async ctx =>
content.Should().NotBeNull();
});
}

[Test]
public async Task When_allow_registration_is_disabled()
{
pact.UponReceiving("A register request when registration is disabled")
.WithRequest(HttpMethod.Post, "/connect/register")
.WithJsonBody(new
{
clientid = "CSClient2",
clientsecret = "test123@Puiu",
displayname = "[email protected]"
})
.WithHeader("Content-Type", "application/json")
.WillRespond()
.WithStatus(HttpStatusCode.Forbidden)
.WithHeader("Content-Type", "application/json");

await pact.VerifyAsync(async ctx =>
{
var client = new HttpClient();

// Act
var requestBody = new { clientid = "CSClient2", clientsecret = "test123@Puiu", displayname = "[email protected]" };
var response = await client.PostAsJsonAsync($"{ctx.MockServerUri}connect/register", requestBody);
var content = await response.Content.ReadAsStringAsync();
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
});
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public void ConfigureServices(IServiceCollection services)
services.AddSingleton<IEndpointModule, HealthModule>();
services.AddSingleton<IClientRepository, FakeClientRepository>();
services.AddTransient<IValidateOptions<IdentitySettings>, IdentitySettingsValidator>();

services.Configure<IdentitySettings>(opts =>
{
opts.AllowRegistration = true;
});
}

public static void Configure(IApplicationBuilder app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"Pact": {
"PactURL": "http://localhost:5120",
"PactFilePath": "../../../../EdFi.DmsConfigurationService.Frontend.AspNetCore.ContractTest.ConsumerTests/pacts/ConfigurationService-API-DMS-API.json",
"RegisterPactFilePath": "../../../../EdFi.DmsConfigurationService.Frontend.AspNetCore.ContractTest.ConsumerTests/pacts/ConfigurationService-API-DMS-API.json",
"RegisterPactFilePath": "../../../../EdFi.DmsConfigurationService.Frontend.AspNetCore.ContractTest.ConsumerTests/pacts/ConfigurationService-API-Register.json",
"ProviderStatePath": "provider-states"
}
}

0 comments on commit e6e6b82

Please sign in to comment.