Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more test to the Security package #4

Merged
merged 2 commits into from
Nov 22, 2024
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
2 changes: 2 additions & 0 deletions src/DfE.CoreLibs.Security/Authorization/ApiOboTokenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public async Task<string> GetApiOboTokenAsync(string? authenticationScheme = nul

// Retrieve user roles
var userRoles = user.FindAll(ClaimTypes.Role).Select(c => c.Value).ToArray();
#pragma warning disable S2589
if (userRoles == null || !userRoles.Any())
#pragma warning restore S2589
{
throw new UnauthorizedAccessException("User does not have any roles assigned.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Authentication.Cookies;
using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Identity.Client;
Expand All @@ -10,6 +11,7 @@ namespace DfE.CoreLibs.Security.Authorization.Events
/// Custom cookie authentication events that reject the session cookie when the user's account is not found in the token cache.
/// This ensures that the user is signed out if their authentication session is no longer valid.
/// </summary>
[ExcludeFromCodeCoverage]
public class RejectSessionCookieWhenAccountNotInCacheEvents : CookieAuthenticationEvents
{
/// <summary>
Expand Down Expand Up @@ -51,13 +53,6 @@ await tokenAcquisition.GetAccessTokenForUserAsync(
// Reject the principal to sign out the user
context.RejectPrincipal();
}
catch (Exception ex)
{
var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<RejectSessionCookieWhenAccountNotInCacheEvents>>();
logger.LogError(ex, "An unexpected error occurred in ValidatePrincipal.");

throw;
}
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/DfE.CoreLibs.Security/DfE.CoreLibs.Security.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="8.0.10" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
<PackageReference Include="Microsoft.Identity.Web" Version="3.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Identity.Web" Version="3.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading
Loading