Path: redb-identity/tests/redb.Identity.Tests/FullStack/ApplicationRequestUrisTests.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/ApplicationRequestUrisTests.cs
----
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;
///
/// A client's registered request_uris over the HTTP management API, stored on the provider under test: set
/// by update, read back exactly (fragment included), cleared by an empty array.
///
[Collection("ProductionHttp")]
public class ApplicationRequestUrisTests
{
private const string Path = "/api/v1/identity/applications";
private readonly ProductionHttpFixture _fx;
public ApplicationRequestUrisTests(ProductionHttpFixture fx) => _fx = fx;
[Fact]
public async Task Request_uris_round_trip_through_the_store()
{
var clientId = "requri-" + Guid.NewGuid().ToString("N")[..12];
var (created, createdBody) = await Send(HttpMethod.Post, Path, new
{
clientId,
displayName = "Request URIs",
clientType = "confidential",
clientSecret = "requri-secret-" + Guid.NewGuid().ToString("N"),
});
((int)created).Should().BeInRange(200, 299, createdBody);
var id = Json(createdBody).GetProperty("id").GetString();
string[] uris = ["https://client.example.com/ro.jwt#q9_hash", "https://client.example.com/ro2.jwt?v=1"];
var (updated, updatedBody) = await Send(HttpMethod.Put, $"{Path}/{id}", new { requestUris = uris });
((int)updated).Should().BeInRange(200, 299, updatedBody);
var (_, read) = await Send(HttpMethod.Get, $"{Path}/{id}", null);
Json(read).GetProperty("requestUris").EnumerateArray().Select(e => e.GetString()).Should().Equal(uris);
var (_, cleared) = await Send(HttpMethod.Put, $"{Path}/{id}", new { requestUris = Array.Empty() });
var left = Json(cleared).TryGetProperty("requestUris", out var after) && after.ValueKind is JsonValueKind.Array
? after.GetArrayLength() : 0;
left.Should().Be(0, cleared);
}
private async Task<(System.Net.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;
}