-
Notifications
You must be signed in to change notification settings - Fork 357
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 #1486 from DuendeSoftware/joe/6.3.x/logout-token-i…
…ssuer Fix logout token iss when issuer is missing
- Loading branch information
Showing
3 changed files
with
88 additions
and
3 deletions.
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
76 changes: 76 additions & 0 deletions
76
test/IdentityServer.UnitTests/Services/Default/DefaultBackChannelLogoutServiceTests.cs
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,76 @@ | ||
// Copyright (c) Duende Software. All rights reserved. | ||
// See LICENSE in the project root for license information. | ||
|
||
|
||
using System.Collections.Generic; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using Duende.IdentityServer; | ||
using Duende.IdentityServer.Configuration; | ||
using Duende.IdentityServer.Services; | ||
using FluentAssertions; | ||
using IdentityModel; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.IdentityModel.Tokens; | ||
using UnitTests.Common; | ||
using UnitTests.Services.Default.KeyManagement; | ||
using UnitTests.Validation.Setup; | ||
using Xunit; | ||
|
||
namespace UnitTests.Services.Default; | ||
|
||
public class DefaultBackChannelLogoutServiceTests | ||
{ | ||
private class ServiceTestHarness : DefaultBackChannelLogoutService | ||
{ | ||
public ServiceTestHarness( | ||
ISystemClock clock, | ||
IdentityServerTools tools, | ||
ILogoutNotificationService logoutNotificationService, | ||
IBackChannelLogoutHttpClient backChannelLogoutHttpClient, | ||
IIssuerNameService issuerNameService, | ||
ILogger<IBackChannelLogoutService> logger) | ||
: base(clock, tools, logoutNotificationService, backChannelLogoutHttpClient, issuerNameService, logger) | ||
{ | ||
} | ||
|
||
|
||
// CreateTokenAsync is protected, so we use this wrapper to exercise it in our tests | ||
public async Task<string> ExerciseCreateTokenAsync(BackChannelLogoutRequest request) | ||
{ | ||
return await CreateTokenAsync(request); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task CreateTokenAsync_Should_Set_Issuer_Correctly() | ||
{ | ||
var expected = "https://identity.example.com"; | ||
|
||
var mockKeyMaterialService = new MockKeyMaterialService(); | ||
var signingKey = new SigningCredentials(CryptoHelper.CreateRsaSecurityKey(), CryptoHelper.GetRsaSigningAlgorithmValue(IdentityServerConstants.RsaSigningAlgorithm.RS256)); | ||
mockKeyMaterialService.SigningCredentials.Add(signingKey); | ||
|
||
var tokenCreation = new DefaultTokenCreationService(new MockClock(), mockKeyMaterialService, TestIdentityServerOptions.Create(), TestLogger.Create<DefaultTokenCreationService>()); | ||
|
||
var issuerNameService = new TestIssuerNameService(expected); | ||
var tools = new IdentityServerTools( | ||
null, // service provider is unused | ||
issuerNameService, | ||
tokenCreation, | ||
new MockClock() | ||
); | ||
|
||
var subject = new ServiceTestHarness(null, tools, null, null, issuerNameService, null); | ||
var rawToken = await subject.ExerciseCreateTokenAsync(new BackChannelLogoutRequest | ||
{ | ||
ClientId = "test_client", | ||
SubjectId = "test_sub", | ||
}); | ||
|
||
|
||
var payload = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(Base64Url.Decode(rawToken.Split('.')[1])); | ||
payload["iss"].GetString().Should().Be(expected); | ||
} | ||
} |