|
| 1 | +using Microsoft.Extensions.Logging; |
| 2 | +using QAToolKit.Auth.IdentityServer4; |
| 3 | +using System; |
| 4 | +using Xunit; |
| 5 | +using Xunit.Abstractions; |
| 6 | + |
| 7 | +namespace QAToolKit.Auth.Test.IdentityServer4 |
| 8 | +{ |
| 9 | + public class IdentityServer4OptionsTests |
| 10 | + { |
| 11 | + private readonly ILogger<IdentityServer4OptionsTests> _logger; |
| 12 | + |
| 13 | + public IdentityServer4OptionsTests(ITestOutputHelper testOutputHelper) |
| 14 | + { |
| 15 | + var loggerFactory = new LoggerFactory(); |
| 16 | + loggerFactory.AddProvider(new XunitLoggerProvider(testOutputHelper)); |
| 17 | + _logger = loggerFactory.CreateLogger<IdentityServer4OptionsTests>(); |
| 18 | + } |
| 19 | + |
| 20 | + [Fact] |
| 21 | + public void KeycloakOptionsTest_Successful() |
| 22 | + { |
| 23 | + var options = new IdentityServer4Options(); |
| 24 | + options.AddClientCredentialFlowParameters(new Uri("https://api.com/token"), "12345", "12345"); |
| 25 | + |
| 26 | + Assert.Equal("12345", options.ClientId); |
| 27 | + Assert.Equal("12345", options.Secret); |
| 28 | + Assert.Equal(new Uri("https://api.com/token"), options.TokenEndpoint); |
| 29 | + } |
| 30 | + |
| 31 | + [Fact] |
| 32 | + public void KeycloakOptionsNoImpersonationTest_Successful() |
| 33 | + { |
| 34 | + var options = new IdentityServer4Options(); |
| 35 | + options.AddClientCredentialFlowParameters(new Uri("https://api.com/token"), "12345", "12345"); |
| 36 | + |
| 37 | + Assert.Equal("12345", options.ClientId); |
| 38 | + Assert.Equal("12345", options.Secret); |
| 39 | + Assert.Equal(new Uri("https://api.com/token"), options.TokenEndpoint); |
| 40 | + } |
| 41 | + |
| 42 | + [Theory] |
| 43 | + [InlineData("", "")] |
| 44 | + [InlineData(null, null)] |
| 45 | + [InlineData(null, "test")] |
| 46 | + [InlineData("test", null)] |
| 47 | + public void KeycloakOptionsUriNullTest_Fails(string clientId, string clientSecret) |
| 48 | + { |
| 49 | + var options = new IdentityServer4Options(); |
| 50 | + Assert.Throws<ArgumentNullException>(() => options.AddClientCredentialFlowParameters(null, clientId, clientSecret)); |
| 51 | + } |
| 52 | + |
| 53 | + [Theory] |
| 54 | + [InlineData("", "")] |
| 55 | + [InlineData(null, null)] |
| 56 | + [InlineData(null, "test")] |
| 57 | + [InlineData("test", null)] |
| 58 | + public void KeycloakOptionsWrongUriTest_Fails(string clientId, string clientSecret) |
| 59 | + { |
| 60 | + var options = new IdentityServer4Options(); |
| 61 | + Assert.Throws<UriFormatException>(() => options.AddClientCredentialFlowParameters(new Uri("https"), clientId, clientSecret)); |
| 62 | + } |
| 63 | + |
| 64 | + [Theory] |
| 65 | + [InlineData("", "")] |
| 66 | + [InlineData(null, null)] |
| 67 | + [InlineData(null, "test")] |
| 68 | + [InlineData("test", null)] |
| 69 | + public void KeycloakOptionsCorrectUriTest_Fails(string clientId, string clientSecret) |
| 70 | + { |
| 71 | + var options = new IdentityServer4Options(); |
| 72 | + Assert.Throws<ArgumentNullException>(() => options.AddClientCredentialFlowParameters(new Uri("https://localhost/token"), clientId, clientSecret)); |
| 73 | + } |
| 74 | + } |
| 75 | +} |
0 commit comments