|
| 1 | +// Copyright (c) Duende Software. All rights reserved. |
| 2 | +// See LICENSE in the project root for license information. |
| 3 | + |
| 4 | +using Duende.IdentityServer.Licensing.V2.Diagnostics.DiagnosticEntries; |
| 5 | +using Microsoft.AspNetCore.Authentication; |
| 6 | +using UnitTests.Common; |
| 7 | + |
| 8 | +namespace IdentityServer.UnitTests.Licensing.V2.DiagnosticEntries; |
| 9 | + |
| 10 | +public class AuthSchemeInfoDiagnosticEntryTests |
| 11 | +{ |
| 12 | + |
| 13 | + private readonly MockAuthenticationSchemeProvider _mockAuthenticationSchemeProvider; |
| 14 | + private readonly AuthSchemeInfoDiagnosticEntry _subject; |
| 15 | + |
| 16 | + public AuthSchemeInfoDiagnosticEntryTests() |
| 17 | + { |
| 18 | + _mockAuthenticationSchemeProvider = new MockAuthenticationSchemeProvider(); |
| 19 | + _subject = new AuthSchemeInfoDiagnosticEntry(_mockAuthenticationSchemeProvider); |
| 20 | + } |
| 21 | + |
| 22 | + [Fact] |
| 23 | + public async Task WriteAsync_ShouldWriteAuthSchemeInfo() |
| 24 | + { |
| 25 | + var testAuthenticationScheme = new AuthenticationScheme("TestScheme", "Test Scheme", typeof(MockAuthenticationHandler)); |
| 26 | + _mockAuthenticationSchemeProvider.RemoveScheme("scheme"); |
| 27 | + _mockAuthenticationSchemeProvider.AddScheme(testAuthenticationScheme); |
| 28 | + |
| 29 | + var result = await DiagnosticEntryTestHelper.WriteEntryToJson(_subject); |
| 30 | + |
| 31 | + var authSchemeInfo = result.RootElement.GetProperty("AuthSchemeInfo"); |
| 32 | + var authSchemes = authSchemeInfo.GetProperty("Schemes"); |
| 33 | + var firstEntry = authSchemes.EnumerateArray().First(); |
| 34 | + firstEntry.GetProperty("TestScheme").GetString().ShouldBe("UnitTests.Common.MockAuthenticationHandler"); |
| 35 | + } |
| 36 | + |
| 37 | + [Fact] |
| 38 | + public async Task WriteAsync_ShouldWriteAllRegisteredAuthSchemes() |
| 39 | + { |
| 40 | + _mockAuthenticationSchemeProvider.RemoveScheme("scheme"); |
| 41 | + _mockAuthenticationSchemeProvider.AddScheme(new AuthenticationScheme("FirstTestScheme", "First Test Scheme", typeof(MockAuthenticationHandler))); |
| 42 | + _mockAuthenticationSchemeProvider.AddScheme(new AuthenticationScheme("SecondTestScheme", "Second Test Scheme", typeof(MockAuthenticationHandler))); |
| 43 | + |
| 44 | + var result = await DiagnosticEntryTestHelper.WriteEntryToJson(_subject); |
| 45 | + |
| 46 | + var authSchemeInfo = result.RootElement.GetProperty("AuthSchemeInfo"); |
| 47 | + var authSchemes = authSchemeInfo.GetProperty("Schemes"); |
| 48 | + authSchemes.GetArrayLength().ShouldBe(2); |
| 49 | + } |
| 50 | +} |
0 commit comments