fix(dashboard): validate __Host- cookie vs RequireHttpsCookie; surface login flags (mxaccessgw#196)
O19: reject a __Host- CookieName with RequireHttpsCookie=false at startup. O20: project DisableLogin, AutoLoginUser, RequireHttpsCookie and CookieName into EffectiveDashboardConfiguration and show them on the Settings page. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -100,6 +100,29 @@ public sealed class GatewayConfigurationProviderTests
|
||||
Project(widened).Dashboard.UntaggedSessionVisibility);
|
||||
}
|
||||
|
||||
/// <summary>The login/cookie flags are projected so the Settings page can show them (R21-O20).</summary>
|
||||
[Fact]
|
||||
public void GetEffectiveConfiguration_ProjectsLoginAndCookieFlags()
|
||||
{
|
||||
GatewayOptions options = new()
|
||||
{
|
||||
Dashboard = new DashboardOptions
|
||||
{
|
||||
DisableLogin = true,
|
||||
AutoLoginUser = "dev",
|
||||
RequireHttpsCookie = false,
|
||||
CookieName = "gw-a",
|
||||
},
|
||||
};
|
||||
|
||||
EffectiveDashboardConfiguration dashboard = Project(options).Dashboard;
|
||||
|
||||
Assert.True(dashboard.DisableLogin);
|
||||
Assert.Equal("dev", dashboard.AutoLoginUser);
|
||||
Assert.False(dashboard.RequireHttpsCookie);
|
||||
Assert.Equal("gw-a", dashboard.CookieName);
|
||||
}
|
||||
|
||||
/// <summary>The pre-existing dashboard members keep coming from the options they always did.</summary>
|
||||
[Fact]
|
||||
public void GetEffectiveConfiguration_CopiesTheOtherDashboardMembers()
|
||||
|
||||
@@ -952,6 +952,30 @@ public sealed class GatewayOptionsValidatorTests
|
||||
Assert.True(result.Succeeded);
|
||||
}
|
||||
|
||||
/// <summary>A __Host- cookie name with RequireHttpsCookie=false is a cookie browsers drop (R21-O19).</summary>
|
||||
[Fact]
|
||||
public void Validate_Fails_WhenHostPrefixedCookieNameWithoutRequireHttpsCookie()
|
||||
{
|
||||
GatewayOptions options = CloneWithDashboard(
|
||||
ValidOptions(),
|
||||
new DashboardOptions { CookieName = "__Host-Custom", RequireHttpsCookie = false });
|
||||
ValidateOptionsResult result = new GatewayOptionsValidator().Validate(null, options);
|
||||
Assert.True(result.Failed);
|
||||
Assert.Contains(result.Failures!, f => f.Contains("__Host-") && f.Contains("RequireHttpsCookie"));
|
||||
}
|
||||
|
||||
/// <summary>__Host- is fine when the cookie is always Secure; a plain name is fine without it.</summary>
|
||||
[Fact]
|
||||
public void Validate_Succeeds_ForValidCookieNameCombinations()
|
||||
{
|
||||
Assert.True(new GatewayOptionsValidator().Validate(null, CloneWithDashboard(
|
||||
ValidOptions(),
|
||||
new DashboardOptions { CookieName = "__Host-Custom", RequireHttpsCookie = true })).Succeeded);
|
||||
Assert.True(new GatewayOptionsValidator().Validate(null, CloneWithDashboard(
|
||||
ValidOptions(),
|
||||
new DashboardOptions { CookieName = "MyCookie", RequireHttpsCookie = false })).Succeeded);
|
||||
}
|
||||
|
||||
/// <summary>Verifies a populated GroupToTag map with well-formed tags passes validation.</summary>
|
||||
[Fact]
|
||||
public void Validate_Succeeds_WhenGroupToTagWellFormed()
|
||||
|
||||
Reference in New Issue
Block a user