-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from DuendeSoftware/brock/case-sensitive-authz…
…-scheme use case sensitive values for authorization scheme
- Loading branch information
Showing
9 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) Duende Software. All rights reserved. | ||
// See LICENSE in the project root for license information. | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using RichardSzalay.MockHttp; | ||
|
||
namespace Duende.AccessTokenManagement.Tests; | ||
|
||
public class AccessTokenHandlerTests | ||
{ | ||
TestDPoPProofService _testDPoPProofService = new TestDPoPProofService(); | ||
TestHttpMessageHandler _testHttpMessageHandler = new TestHttpMessageHandler(); | ||
|
||
AccessTokenHandlerSubject _subject; | ||
|
||
public AccessTokenHandlerTests() | ||
{ | ||
_subject = new AccessTokenHandlerSubject(_testDPoPProofService, new TestDPoPNonceStore(), new TestLoggerProvider().CreateLogger("AccessTokenHandlerSubject")); | ||
_subject.InnerHandler = _testHttpMessageHandler; | ||
} | ||
|
||
[Fact] | ||
public async Task lower_case_token_type_should_be_converted_to_case_sensitive() | ||
{ | ||
var client = new HttpClient(_subject); | ||
|
||
{ | ||
_subject.AccessToken.AccessTokenType = "bearer"; | ||
|
||
var response = await client.GetAsync("https://test/api"); | ||
|
||
_testHttpMessageHandler.Request!.Headers.Authorization!.Scheme.ShouldBe("Bearer"); | ||
} | ||
|
||
{ | ||
_subject.AccessToken.AccessTokenType = "dpop"; | ||
|
||
var response = await client.GetAsync("https://test/api"); | ||
|
||
_testHttpMessageHandler.Request!.Headers.Authorization!.Scheme.ShouldBe("DPoP"); | ||
} | ||
} | ||
|
||
public class TestHttpMessageHandler : HttpMessageHandler | ||
{ | ||
public HttpRequestMessage? Request { get; set; } | ||
public HttpResponseMessage Response { get; set; } = new HttpResponseMessage(System.Net.HttpStatusCode.NoContent); | ||
|
||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
Request = request; | ||
return Task.FromResult(Response); | ||
} | ||
} | ||
|
||
public class AccessTokenHandlerSubject : AccessTokenHandler | ||
{ | ||
public ClientCredentialsToken AccessToken { get; set; } = new ClientCredentialsToken | ||
{ | ||
AccessToken = "at", | ||
AccessTokenType = "bearer", | ||
}; | ||
|
||
public AccessTokenHandlerSubject(IDPoPProofService dPoPProofService, IDPoPNonceStore dPoPNonceStore, ILogger logger) : base(dPoPProofService, dPoPNonceStore, logger) | ||
{ | ||
} | ||
|
||
protected override Task<ClientCredentialsToken> GetAccessTokenAsync(bool forceRenewal, CancellationToken cancellationToken) | ||
{ | ||
return Task.FromResult(AccessToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) Duende Software. All rights reserved. | ||
// See LICENSE in the project root for license information. | ||
|
||
|
||
namespace Duende.AccessTokenManagement.Tests; | ||
|
||
public class TestDPoPNonceStore : IDPoPNonceStore | ||
{ | ||
public Task<string?> GetNonceAsync(DPoPNonceContext context, CancellationToken cancellationToken = default) | ||
{ | ||
return Task.FromResult<string?>(null); | ||
} | ||
|
||
public Task StoreNonceAsync(DPoPNonceContext context, string nonce, CancellationToken cancellationToken = default) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
// Copyright (c) Duende Software. All rights reserved. | ||
// See LICENSE in the project root for license information. | ||
|
||
global using Xunit; | ||
global using Shouldly; |