Path: redb-identity/tests/redb.Identity.Tests/FullStack/FederationProviderBlankSecretTests.cs Snapshot: redb-identity, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-identity Page: https://redbase.app/src/dev-2026-12-06/redb-identity/tests/redb.Identity.Tests/FullStack/FederationProviderBlankSecretTests.cs ---- using System.Net; using System.Net.Http.Headers; using System.Net.Http.Json; using System.Text.Json; using AwesomeAssertions; using redb.Identity.Tests.Infrastructure; using Xunit; namespace redb.Identity.Tests.FullStack; /// /// One rule for a federation provider's client secret on create and update, over the HTTP management API: the empty /// string means no secret, a value of white space only is refused with 400 and leaves the stored secret as it was. /// [Collection("ProductionHttp")] public class FederationProviderBlankSecretTests { private const string Path = "/api/v1/identity/federation-providers"; private readonly ProductionHttpFixture _fx; public FederationProviderBlankSecretTests(ProductionHttpFixture fx) => _fx = fx; [Fact] public async Task Empty_secret_on_create_is_no_secret() { var (status, body) = await Send(HttpMethod.Post, Path, Provider(string.Empty)); ((int)status).Should().BeInRange(200, 299, body); Json(body).GetProperty("hasSecret").GetBoolean().Should().BeFalse(body); } [Theory] [InlineData(" ")] [InlineData(" \t ")] public async Task White_space_secret_on_create_is_refused(string secret) { var (status, body) = await Send(HttpMethod.Post, Path, Provider(secret)); status.Should().Be(HttpStatusCode.BadRequest, body); body.Should().Contain("validation_error"); } [Fact] public async Task White_space_secret_on_update_is_refused_and_keeps_the_stored_secret() { var (created, createdBody) = await Send(HttpMethod.Post, Path, Provider("kept-secret")); ((int)created).Should().BeInRange(200, 299, createdBody); var id = Json(createdBody).GetProperty("id").GetString(); var (status, body) = await Send(HttpMethod.Put, $"{Path}/{id}", new { clientSecret = " " }); status.Should().Be(HttpStatusCode.BadRequest, body); body.Should().Contain("validation_error"); var (_, read) = await Send(HttpMethod.Get, $"{Path}/{id}", null); Json(read).GetProperty("hasSecret").GetBoolean().Should().BeTrue(read); } [Fact] public async Task Empty_secret_on_update_clears_it() { var (_, createdBody) = await Send(HttpMethod.Post, Path, Provider("to-clear")); var id = Json(createdBody).GetProperty("id").GetString(); var (status, body) = await Send(HttpMethod.Put, $"{Path}/{id}", new { clientSecret = string.Empty }); ((int)status).Should().BeInRange(200, 299, body); Json(body).GetProperty("hasSecret").GetBoolean().Should().BeFalse(body); } private static object Provider(string secret) => new { providerId = "blank-" + Guid.NewGuid().ToString("N")[..12], kind = "oidc", displayName = "Blank secret", authority = "https://idp.example.test/", clientId = "blank-client", clientSecret = secret, enabled = false, }; private async Task<(HttpStatusCode Status, string Body)> Send(HttpMethod method, string path, object? body) { using var request = new HttpRequestMessage(method, path); if (body is not null) request.Content = JsonContent.Create(body); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _fx.ManagementToken); using var response = await _fx.Http.SendAsync(request); return (response.StatusCode, await response.Content.ReadAsStringAsync()); } private static JsonElement Json(string body) => JsonDocument.Parse(body).RootElement; }