-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AzureB2C, IdentityServer 4 client credential flow support
* AzureB2C, IdentityServer 4 client credential flow support, refactored foundation, new tests
- Loading branch information
Showing
26 changed files
with
604 additions
and
215 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<Version>0.1.7</Version> | ||
<Version>0.2.2</Version> | ||
</PropertyGroup> | ||
</Project> |
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
41 changes: 41 additions & 0 deletions
41
src/QAToolKit.Auth.Test/AzureB2C/AzureB2CAuthenticatorTests.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,41 @@ | ||
using NSubstitute; | ||
using QAToolKit.Auth.AzureB2C; | ||
using QAToolKit.Core.Interfaces; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace QAToolKit.Auth.Test.AzureB2C | ||
{ | ||
public class AzureB2CAuthenticatorTests | ||
{ | ||
[Fact] | ||
public async Task CreateAuthenticatonServiceTest_Success() | ||
{ | ||
var authenticator = Substitute.For<IAuthenticationService>(); | ||
await authenticator.GetAccessToken(); | ||
Assert.Single(authenticator.ReceivedCalls()); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateAuthenticatonServiceWithReturnsTest_Success() | ||
{ | ||
var authenticator = Substitute.For<IAuthenticationService>(); | ||
authenticator.GetAccessToken().Returns(args => "12345"); | ||
|
||
Assert.Equal("12345", await authenticator.GetAccessToken()); | ||
Assert.Single(authenticator.ReceivedCalls()); | ||
} | ||
|
||
[Fact] | ||
public void CreateAzureB2COptionsTest_Success() | ||
{ | ||
var options = new AzureB2COptions(); | ||
options.AddClientCredentialFlowParameters(new Uri("https://api.com/token"), "12345", "12345"); | ||
|
||
var azureB2COptions = Substitute.For<Action<AzureB2COptions>>(); | ||
azureB2COptions.Invoke(options); | ||
Assert.Single(azureB2COptions.ReceivedCalls()); | ||
} | ||
} | ||
} |
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,75 @@ | ||
using Microsoft.Extensions.Logging; | ||
using QAToolKit.Auth.AzureB2C; | ||
using System; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace QAToolKit.Auth.Test.AzureB2C | ||
{ | ||
public class AzureB2COptionsTests | ||
{ | ||
private readonly ILogger<AzureB2COptionsTests> _logger; | ||
|
||
public AzureB2COptionsTests(ITestOutputHelper testOutputHelper) | ||
{ | ||
var loggerFactory = new LoggerFactory(); | ||
loggerFactory.AddProvider(new XunitLoggerProvider(testOutputHelper)); | ||
_logger = loggerFactory.CreateLogger<AzureB2COptionsTests>(); | ||
} | ||
|
||
[Fact] | ||
public void KeycloakOptionsTest_Successful() | ||
{ | ||
var options = new AzureB2COptions(); | ||
options.AddClientCredentialFlowParameters(new Uri("https://api.com/token"), "12345", "12345"); | ||
|
||
Assert.Equal("12345", options.ClientId); | ||
Assert.Equal("12345", options.Secret); | ||
Assert.Equal(new Uri("https://api.com/token"), options.TokenEndpoint); | ||
} | ||
|
||
[Fact] | ||
public void KeycloakOptionsNoImpersonationTest_Successful() | ||
{ | ||
var options = new AzureB2COptions(); | ||
options.AddClientCredentialFlowParameters(new Uri("https://api.com/token"), "12345", "12345"); | ||
|
||
Assert.Equal("12345", options.ClientId); | ||
Assert.Equal("12345", options.Secret); | ||
Assert.Equal(new Uri("https://api.com/token"), options.TokenEndpoint); | ||
} | ||
|
||
[Theory] | ||
[InlineData("", "")] | ||
[InlineData(null, null)] | ||
[InlineData(null, "test")] | ||
[InlineData("test", null)] | ||
public void KeycloakOptionsUriNullTest_Fails(string clientId, string clientSecret) | ||
{ | ||
var options = new AzureB2COptions(); | ||
Assert.Throws<ArgumentNullException>(() => options.AddClientCredentialFlowParameters(null, clientId, clientSecret)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("", "")] | ||
[InlineData(null, null)] | ||
[InlineData(null, "test")] | ||
[InlineData("test", null)] | ||
public void KeycloakOptionsWrongUriTest_Fails(string clientId, string clientSecret) | ||
{ | ||
var options = new AzureB2COptions(); | ||
Assert.Throws<UriFormatException>(() => options.AddClientCredentialFlowParameters(new Uri("https"), clientId, clientSecret)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("", "")] | ||
[InlineData(null, null)] | ||
[InlineData(null, "test")] | ||
[InlineData("test", null)] | ||
public void KeycloakOptionsCorrectUriTest_Fails(string clientId, string clientSecret) | ||
{ | ||
var options = new AzureB2COptions(); | ||
Assert.Throws<ArgumentNullException>(() => options.AddClientCredentialFlowParameters(new Uri("https://localhost/token"), clientId, clientSecret)); | ||
} | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
src/QAToolKit.Auth.Test/IdentityServer4/IdentityServer4AuthenticatorTests.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,41 @@ | ||
using NSubstitute; | ||
using QAToolKit.Auth.IdentityServer4; | ||
using QAToolKit.Core.Interfaces; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace QAToolKit.Auth.Test.IdentityServer4 | ||
{ | ||
public class IdentityServer4AuthenticatorTests | ||
{ | ||
[Fact] | ||
public async Task CreateAuthenticatonServiceTest_Success() | ||
{ | ||
var authenticator = Substitute.For<IAuthenticationService>(); | ||
await authenticator.GetAccessToken(); | ||
Assert.Single(authenticator.ReceivedCalls()); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateAuthenticatonServiceWithReturnsTest_Success() | ||
{ | ||
var authenticator = Substitute.For<IAuthenticationService>(); | ||
authenticator.GetAccessToken().Returns(args => "12345"); | ||
|
||
Assert.Equal("12345", await authenticator.GetAccessToken()); | ||
Assert.Single(authenticator.ReceivedCalls()); | ||
} | ||
|
||
[Fact] | ||
public void CreateIdentityServer4OptionsTest_Success() | ||
{ | ||
var options = new IdentityServer4Options(); | ||
options.AddClientCredentialFlowParameters(new Uri("https://api.com/token"), "12345", "12345"); | ||
|
||
var id4Options = Substitute.For<Action<IdentityServer4Options>>(); | ||
id4Options.Invoke(options); | ||
Assert.Single(id4Options.ReceivedCalls()); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/QAToolKit.Auth.Test/IdentityServer4/IdentityServer4OptionsTests.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,75 @@ | ||
using Microsoft.Extensions.Logging; | ||
using QAToolKit.Auth.IdentityServer4; | ||
using System; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace QAToolKit.Auth.Test.IdentityServer4 | ||
{ | ||
public class IdentityServer4OptionsTests | ||
{ | ||
private readonly ILogger<IdentityServer4OptionsTests> _logger; | ||
|
||
public IdentityServer4OptionsTests(ITestOutputHelper testOutputHelper) | ||
{ | ||
var loggerFactory = new LoggerFactory(); | ||
loggerFactory.AddProvider(new XunitLoggerProvider(testOutputHelper)); | ||
_logger = loggerFactory.CreateLogger<IdentityServer4OptionsTests>(); | ||
} | ||
|
||
[Fact] | ||
public void KeycloakOptionsTest_Successful() | ||
{ | ||
var options = new IdentityServer4Options(); | ||
options.AddClientCredentialFlowParameters(new Uri("https://api.com/token"), "12345", "12345"); | ||
|
||
Assert.Equal("12345", options.ClientId); | ||
Assert.Equal("12345", options.Secret); | ||
Assert.Equal(new Uri("https://api.com/token"), options.TokenEndpoint); | ||
} | ||
|
||
[Fact] | ||
public void KeycloakOptionsNoImpersonationTest_Successful() | ||
{ | ||
var options = new IdentityServer4Options(); | ||
options.AddClientCredentialFlowParameters(new Uri("https://api.com/token"), "12345", "12345"); | ||
|
||
Assert.Equal("12345", options.ClientId); | ||
Assert.Equal("12345", options.Secret); | ||
Assert.Equal(new Uri("https://api.com/token"), options.TokenEndpoint); | ||
} | ||
|
||
[Theory] | ||
[InlineData("", "")] | ||
[InlineData(null, null)] | ||
[InlineData(null, "test")] | ||
[InlineData("test", null)] | ||
public void KeycloakOptionsUriNullTest_Fails(string clientId, string clientSecret) | ||
{ | ||
var options = new IdentityServer4Options(); | ||
Assert.Throws<ArgumentNullException>(() => options.AddClientCredentialFlowParameters(null, clientId, clientSecret)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("", "")] | ||
[InlineData(null, null)] | ||
[InlineData(null, "test")] | ||
[InlineData("test", null)] | ||
public void KeycloakOptionsWrongUriTest_Fails(string clientId, string clientSecret) | ||
{ | ||
var options = new IdentityServer4Options(); | ||
Assert.Throws<UriFormatException>(() => options.AddClientCredentialFlowParameters(new Uri("https"), clientId, clientSecret)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("", "")] | ||
[InlineData(null, null)] | ||
[InlineData(null, "test")] | ||
[InlineData("test", null)] | ||
public void KeycloakOptionsCorrectUriTest_Fails(string clientId, string clientSecret) | ||
{ | ||
var options = new IdentityServer4Options(); | ||
Assert.Throws<ArgumentNullException>(() => options.AddClientCredentialFlowParameters(new Uri("https://localhost/token"), clientId, clientSecret)); | ||
} | ||
} | ||
} |
Oops, something went wrong.