Skip to content

Commit

Permalink
started update to .net8
Browse files Browse the repository at this point in the history
  • Loading branch information
doerrD committed Feb 18, 2024
1 parent 52b1634 commit f361582
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

namespace softaware.Authentication.Basic.AspNetCore.Test
{
public class TestStartup
public class TestStartup(IWebHostEnvironment env)
{
public TestStartup(IWebHostEnvironment env)
{
}

/// <summary>
/// This method gets called by the runtime. Use this method to add services to the container.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@

namespace softaware.Authentication.Basic.AspNetCore.Test
{
public class TestWebApplicationFactory : WebApplicationFactory<TestStartup>
public class TestWebApplicationFactory(IBasicAuthorizationProvider basicAuthorizationProvider)
: WebApplicationFactory<TestStartup>
{
private readonly IBasicAuthorizationProvider basicAuthorizationProvider;

public TestWebApplicationFactory(IBasicAuthorizationProvider basicAuthorizationProvider)
{
this.basicAuthorizationProvider = basicAuthorizationProvider;
}
private readonly IBasicAuthorizationProvider basicAuthorizationProvider = basicAuthorizationProvider;

protected override IWebHostBuilder CreateWebHostBuilder()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>

<IsPackable>false</IsPackable>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="7.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.4" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="8.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.2" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

namespace softaware.Authentication.Hmac.AspNetCore
{
internal class BasicAuthenticationHandler : AuthenticationHandler<BasicAuthenticationSchemeOptions>
internal class BasicAuthenticationHandler(
IOptionsMonitor<BasicAuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder encoder)
: AuthenticationHandler<BasicAuthenticationSchemeOptions>(options, logger, encoder)
{
private class ValidationResult
{
Expand All @@ -24,11 +26,6 @@ private class ValidationResult
public string Password { get; set; }
}

public BasicAuthenticationHandler(IOptionsMonitor<BasicAuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock)
: base(options, logger, encoder, clock)
{
}

protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
{
if (this.Options.AuthorizationProvider == null)
Expand All @@ -51,13 +48,13 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
if (validationResult.Valid)
{
var claimsToSet = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, validationResult.Username)
{
new(ClaimTypes.NameIdentifier, validationResult.Username)
};

if (this.Options.AddPasswordAsClaim)
{
claimsToSet.Add(new Claim(this.Options.PasswordClaimType, validationResult.Password));
claimsToSet.Add(new(this.Options.PasswordClaimType, validationResult.Password));
}

var principal = new ClaimsPrincipal(new ClaimsIdentity(claimsToSet, BasicAuthenticationDefaults.AuthenticationType, ClaimTypes.NameIdentifier, ClaimTypes.Role));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@

namespace softaware.Authentication.Basic.AspNetCore
{
public class BasicAuthenticationPostConfigureOptions : IPostConfigureOptions<BasicAuthenticationSchemeOptions>
public class BasicAuthenticationPostConfigureOptions(IBasicAuthorizationProvider basicAuthorizationProvider = null)
: IPostConfigureOptions<BasicAuthenticationSchemeOptions>
{
private readonly IBasicAuthorizationProvider basicAuthorizationProvider;

public BasicAuthenticationPostConfigureOptions(IBasicAuthorizationProvider basicAuthorizationProvider = null)
{
this.basicAuthorizationProvider = basicAuthorizationProvider;
}
private readonly IBasicAuthorizationProvider basicAuthorizationProvider = basicAuthorizationProvider;

public void PostConfigure(string name, BasicAuthenticationSchemeOptions options)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<Version>4.0.0</Version>
<Version>5.0.0</Version>
<PackageProjectUrl>https://github.com/softawaregmbh/library-authentication</PackageProjectUrl>
<RepositoryUrl>https://github.com/softawaregmbh/library-authentication</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand All @@ -16,18 +16,20 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<PackageReleaseNotes>Remove support for net461</PackageReleaseNotes>
<PackageReleaseNotes>Update to net8.0</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<Content Include="..\Assets\package-icon.png" Link="package-icon.png" Pack="true" PackagePath="/" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<Version>2.0.0</Version>
<Version>3.0.0</Version>
<PackageProjectUrl>https://github.com/softawaregmbh/library-authentication</PackageProjectUrl>
<RepositoryUrl>https://github.com/softawaregmbh/library-authentication</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand All @@ -22,7 +22,7 @@
<Content Include="..\Assets\package-icon.png" Link="package-icon.png" Pack="true" PackagePath="/" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class BasicAuthenticationClientConfiguration
{
public string Username { get; set; }

public string Password { get; set; }
}
}
2 changes: 2 additions & 0 deletions softaware.Authentication.Basic/BasicAuthenticationDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
public class BasicAuthenticationDefaults
{
public const string AuthenticationScheme = "Basic";

public const string AuthenticationType = "Basic";

public const string PasswordClaimType = "Password";
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<Version>2.0.0</Version>
<Version>3.0.0</Version>
<PackageProjectUrl>https://github.com/softawaregmbh/library-authentication</PackageProjectUrl>
<RepositoryUrl>https://github.com/softawaregmbh/library-authentication</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand All @@ -23,7 +23,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
11 changes: 6 additions & 5 deletions softaware.Authentication.Hmac.AspNetCore.Test/MiddlewareTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task Request_WithDeprecatedHmacAuthorizedAppsOption_Authorized()
"MNpx/353+rW+pqv8UbRTAtO1yoabl8/RFDAv/615u5w=");

var response = await client.GetAsync("api/test");
Assert.True(response.StatusCode == HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[Fact]
Expand All @@ -94,7 +94,7 @@ public async Task Request_WithDefaultAuthorizationProvider_Authorized()
"MNpx/353+rW+pqv8UbRTAtO1yoabl8/RFDAv/615u5w=");

var response = await client.GetAsync("api/test");
Assert.True(response.StatusCode == HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[Fact]
Expand All @@ -108,7 +108,7 @@ public async Task Request_Authorized_WithTrustProxy()
client.DefaultRequestHeaders.Add("X-Forwarded-Proto", "http");

var response = await client.GetAsync("api/test");
Assert.True(response.StatusCode == HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[Fact]
Expand All @@ -122,7 +122,7 @@ public async Task Request_Unauthorized_WithTrustProxy()
client.DefaultRequestHeaders.Add("X-Forwarded-Proto", "https");

var response = await client.GetAsync("api/test");
Assert.True(response.StatusCode == HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
}

[Theory]
Expand Down Expand Up @@ -241,7 +241,7 @@ private static HttpClient GetHttpClient(
handlers.Add(new RemoveHashingMethodDelegatingHandler());
}

return factory.CreateDefaultClient(handlers.ToArray());
return factory.CreateDefaultClient([.. handlers]);
}

private static HttpClient GetHttpClientWithHmacAutenticatedAppsOption(IDictionary<string, string> hmacAuthenticatedApps, string appId, string apiKey)
Expand All @@ -250,6 +250,7 @@ private static HttpClient GetHttpClientWithHmacAutenticatedAppsOption(IDictionar
{
o.HmacAuthenticatedApps = hmacAuthenticatedApps;
});

return factory.CreateDefaultClient(new ApiKeyDelegatingHandler(appId, apiKey));
}

Expand Down
6 changes: 1 addition & 5 deletions softaware.Authentication.Hmac.AspNetCore.Test/TestStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

namespace softaware.Authentication.Hmac.AspNetCore.Test
{
public class TestStartup
public class TestStartup(IWebHostEnvironment env)
{
public TestStartup(IWebHostEnvironment env)
{
}

/// <summary>
/// This method gets called by the runtime. Use this method to add services to the container.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@

namespace softaware.Authentication.Hmac.AspNetCore.Test
{
public class TestWebApplicationFactory : WebApplicationFactory<TestStartup>
public class TestWebApplicationFactory(Action<HmacAuthenticationSchemeOptions> configureOptions)
: WebApplicationFactory<TestStartup>
{
private readonly Action<HmacAuthenticationSchemeOptions> configureOptions;

public TestWebApplicationFactory(Action<HmacAuthenticationSchemeOptions> configureOptions)
{
this.configureOptions = configureOptions;
}
private readonly Action<HmacAuthenticationSchemeOptions> configureOptions = configureOptions;

protected override IWebHostBuilder CreateWebHostBuilder()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@

namespace softaware.Authentication.Hmac.AspNetCore.Test
{
public class TestWebApplicationFactoryWithDefaultAuthorizationProvider : WebApplicationFactory<TestStartup>
public class TestWebApplicationFactoryWithDefaultAuthorizationProvider(IDictionary<string, string> hmacAuthenticatedApps)
: WebApplicationFactory<TestStartup>
{
private readonly IDictionary<string, string> hmacAuthenticatedApps;

public TestWebApplicationFactoryWithDefaultAuthorizationProvider(IDictionary<string, string> hmacAuthenticatedApps)
{
this.hmacAuthenticatedApps = hmacAuthenticatedApps ?? throw new ArgumentNullException(nameof(hmacAuthenticatedApps));
}
private readonly IDictionary<string, string> hmacAuthenticatedApps = hmacAuthenticatedApps ?? throw new ArgumentNullException(nameof(hmacAuthenticatedApps));

protected override IWebHostBuilder CreateWebHostBuilder()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>

<IsPackable>false</IsPackable>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="Xunit.Combinatorial" Version="1.5.25" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="Xunit.Combinatorial" Version="1.6.24" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit f361582

Please sign in to comment.