Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 0 additions & 61 deletions EstateManagementUI.BlazorServer.Tests/Pages/CounterPageTests.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@inject IPermissionService PermissionService
@inject IPermissionKeyProvider PermissionKeyProvider

@if (isTestMode)
@if (testMode == TestMode.Full || testMode == TestMode.AuthenticationOnly)
{
<div class="relative">
<button type="button" @onclick="ToggleDropdown" @onclick:stopPropagation
Expand Down Expand Up @@ -56,7 +56,7 @@
}

@code {
private bool isTestMode;
private TestMode testMode;
private string currentRole = "Administrator";
private bool isDropdownOpen = false;

Expand All @@ -69,7 +69,11 @@

protected override async Task OnInitializedAsync()
{
isTestMode = Configuration.GetValue<bool>("AppSettings:TestMode", false);
//isTestMode = Configuration.GetValue<bool>("AppSettings:TestMode", false);
// Check if running in test mode
var testModeConfig = Configuration.GetValue<String>("AppSettings:TestMode", "Disabled");
// Convert to enum
testMode = Enum.Parse<TestMode>(testModeConfig, ignoreCase: true);

// Get the actual current role from authentication
var actualRole = await PermissionService.GetUserRoleAsync();
Expand All @@ -79,7 +83,7 @@
protected override async Task OnParametersSetAsync()
{
// Update current role when parameters change (e.g., after navigation)
if (isTestMode)
if (testMode == TestMode.AuthenticationOnly || testMode == TestMode.Full)
{
var actualRole = await PermissionService.GetUserRoleAsync();
if (!string.IsNullOrEmpty(actualRole))
Expand Down
19 changes: 0 additions & 19 deletions EstateManagementUI.BlazorServer/Components/Pages/Counter.razor

This file was deleted.

38 changes: 22 additions & 16 deletions EstateManagementUI.BlazorServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

try
{
var certificate = new X509Certificate2(certificateFile, "password");

Check warning on line 52 in EstateManagementUI.BlazorServer/Program.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test

'X509Certificate2.X509Certificate2(string, string?)' is obsolete: 'Loading certificate data through the constructor or Import is obsolete. Use X509CertificateLoader instead to load certificates.' (https://aka.ms/dotnet-warnings/SYSLIB0057)
Console.WriteLine($"Certificate loaded successfully. Subject: {certificate.Subject}");
listenOptions.UseHttps(certificate);
}
Expand All @@ -66,7 +66,10 @@
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

// Check if running in test mode
var testMode = builder.Configuration.GetValue<bool>("AppSettings:TestMode", false);
var testModeConfig = builder.Configuration.GetValue<String>("AppSettings:TestMode", "Disabled");
// Convert to enum
var testMode = Enum.Parse<TestMode>(testModeConfig, ignoreCase: true);

Console.WriteLine($"Application running in Test Mode: {testMode}");

// Add services to the container.
Expand All @@ -83,7 +86,7 @@
});

// Configure authentication based on mode
if (testMode)
if (testMode == TestMode.AuthenticationOnly || testMode == TestMode.Full)
{
// Test mode: Use test authentication handler to bypass OIDC
builder.Services.AddAuthentication(options =>
Expand Down Expand Up @@ -119,7 +122,7 @@

// Use helper method to get adjusted addresses for integration testing
var (authorityAddress, issuerAddress) = AuthenticationHelpers.GetSecurityServiceAddresses(
authority,

Check warning on line 125 in EstateManagementUI.BlazorServer/Program.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test

Possible null reference argument for parameter 'authority' in '(string authorityAddress, string issuerAddress) AuthenticationHelpers.GetSecurityServiceAddresses(string authority, string? securityServiceLocalPort, string? securityServicePort)'.
securityServiceLocalPort,
securityServicePort);

Expand Down Expand Up @@ -167,6 +170,7 @@
NameClaimType = "name",
RoleClaimType = "role"
};
options.ClaimActions.MapAllExcept("iss", "nbf", "exp", "aud", "nonce", "iat", "c_hash");

// Set MetadataAddress to use the authority address
options.MetadataAddress = $"{authorityAddress}/.well-known/openid-configuration";
Expand Down Expand Up @@ -200,7 +204,7 @@
Console.WriteLine("Registered Permission services");

// Register MediatR service based on test mode
if (testMode)
if (testMode == TestMode.BackedByTestDataStore || testMode == TestMode.Full)
{
Console.WriteLine("Registering TestMediatorService with in-memory test data store");
builder.Services.AddSingleton<ITestDataStore, TestDataStore>();
Expand Down Expand Up @@ -236,13 +240,19 @@
.AddInteractiveServerRenderMode();

// Add login endpoint - behavior depends on test mode
if (testMode)
if (testMode == TestMode.AuthenticationOnly || testMode == TestMode.Full)
{
app.MapGet("/login", (HttpContext context) =>
{
// In test mode, redirect directly to home since authentication is automatic
return Results.Redirect("/");
}).AllowAnonymous();

app.MapGet("/logout", (HttpContext context) =>
{
// In test mode, just redirect to home
return Results.Redirect("/");
}).RequireAuthorization();
}
else
{
Expand All @@ -260,19 +270,7 @@
authenticationSchemes: new[] { OpenIdConnectDefaults.AuthenticationScheme }
);
}).AllowAnonymous();
}

// Add logout endpoint - behavior depends on test mode
if (testMode)
{
app.MapGet("/logout", (HttpContext context) =>
{
// In test mode, just redirect to home
return Results.Redirect("/");
}).RequireAuthorization();
}
else
{
app.MapGet("/logout", async (HttpContext context) =>
{
await context.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);
Expand All @@ -282,3 +280,11 @@
}

app.Run();


enum TestMode {
Disabled,
AuthenticationOnly,
BackedByTestDataStore,
Full
}
8 changes: 4 additions & 4 deletions EstateManagementUI.BlazorServer/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
"AppSettings": {
"SecurityServiceLocalPort": null,
"SecurityServicePort": null,
"HttpClientIgnoreCertificateErrors": false,
"TestMode": true
"HttpClientIgnoreCertificateErrors": false,
"TestMode": "BackedByTestDataStore"
},
"Authentication": {
"Authority": "https://localhost:5001",
"ClientId": "estateUIClient",
"ClientSecret": "Secret1",
"ClientId": "managementUIClient",
"ClientSecret": "d192cbc46d834d0da90e8a9d50ded543",
"CallbackPath": "/signin-oidc",
"ResponseType": "code id_token",
"Scopes": [
Expand Down
Loading