Path: redb-identity/tests/redb.Identity.Web.Tests/DevTlsContractTests.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.Web.Tests/DevTlsContractTests.cs ---- using System.IO; using System.Linq; using System.Text.Json; using AwesomeAssertions; using Xunit; namespace redb.Identity.Web.Tests; /// /// W6-1: HTTPS by default in development. Pins the launch profile to a /// configuration that includes an HTTPS endpoint, so a future "no need /// for certs, just use http" edit does not silently downgrade the dev /// loop and let cookie/CSRF defences regress to no-op. /// public class DevTlsContractTests { private static string LaunchSettingsPath() { // Tests run from bin/Debug/netX/ — climb up to the Web project's Properties. var here = AppContext.BaseDirectory; var dir = new DirectoryInfo(here); while (dir is not null && dir.Name != "redb.Identity.Web.Tests") dir = dir.Parent; if (dir?.Parent?.Parent is null) throw new InvalidOperationException( $"Could not locate repo layout from {here}"); // tests/redb.Identity.Web.Tests/ -> tests/ -> redb.Identity/ -> src/redb.Identity.Web/Properties/launchSettings.json var root = dir.Parent.Parent; return Path.Combine( root.FullName, "src", "redb.Identity.Web", "Properties", "launchSettings.json"); } [Fact] public void LaunchSettings_HasHttpsProfile_BoundToDevPort() { var path = LaunchSettingsPath(); File.Exists(path).Should().BeTrue($"launchSettings.json missing at {path}"); using var doc = JsonDocument.Parse(File.ReadAllText(path)); var profiles = doc.RootElement.GetProperty("profiles"); profiles.TryGetProperty("https", out var https).Should().BeTrue( "An 'https' launch profile MUST exist so `dotnet run` and IDE F5 bring up the BFF " + "with TLS by default (W6-1)."); var applicationUrl = https.GetProperty("applicationUrl").GetString() ?? string.Empty; applicationUrl.Should().Contain("https://", "applicationUrl MUST include an https:// binding (got '{0}').", applicationUrl); var env = https.GetProperty("environmentVariables").GetProperty("ASPNETCORE_ENVIRONMENT").GetString(); env.Should().Be("Development", "the https profile is the dev profile"); } [Fact] public void DevelopmentAppSettings_RequiresHttpsMetadata() { var path = Path.Combine( Path.GetDirectoryName(LaunchSettingsPath())!, "..", "appsettings.Development.json"); path = Path.GetFullPath(path); File.Exists(path).Should().BeTrue($"appsettings.Development.json missing at {path}"); using var doc = JsonDocument.Parse(File.ReadAllText(path)); var identity = doc.RootElement.GetProperty("Identity"); identity.GetProperty("Authority").GetString().Should().StartWith("https://", "BFF dev config must point at an https authority so OIDC discovery validates the TLS chain."); identity.GetProperty("RequireHttpsMetadata").GetBoolean().Should().BeTrue( "Setting RequireHttpsMetadata=false in committed dev config silently disables " + "metadata signature validation; require the developer to opt-in per-machine if needed."); } [Fact] public void ShippedAppSettings_RequiresHttpsMetadata() { // appsettings.json ships with the application: it is the default of every deployment, not a // developer's convenience. The Development test above guards the dev loop; this one guards // what a deployment gets when nobody overrides anything. var path = Path.GetFullPath(Path.Combine( Path.GetDirectoryName(LaunchSettingsPath())!, "..", "appsettings.json")); File.Exists(path).Should().BeTrue($"appsettings.json missing at {path}"); using var doc = JsonDocument.Parse(File.ReadAllText(path)); var identity = doc.RootElement.GetProperty("Identity"); identity.GetProperty("Authority").GetString().Should().StartWith("https://", "the shipped default authority must be https; an http authority is a per-deployment decision."); identity.GetProperty("RequireHttpsMetadata").GetBoolean().Should().BeTrue( "RequireHttpsMetadata=false in the shipped defaults turns off the https requirement for OIDC " + "discovery in every deployment at once. The code default is true; a deployment that really " + "talks to an http authority sets false explicitly for itself."); } }