Skip to content

Commit

Permalink
before release
Browse files Browse the repository at this point in the history
* API changed a bit before release, readmefile, version bump

* updated tests

* updated tests

* small code cleanup
  • Loading branch information
mihaj authored Dec 6, 2020
1 parent b98c34c commit 6ac166e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
41 changes: 41 additions & 0 deletions src/QAToolKit.Auth.Test/Keycloak/KeycloakAuthenticatorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using NSubstitute;
using QAToolKit.Core.Interfaces;
using System;
using System.Threading.Tasks;
using Xunit;

namespace QAToolKit.Auth.Test.Keycloak
{
public class KeycloakAuthenticatorTests
{
[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 CreateKeycloakOptionsTest_Success()
{
var options = new KeycloakOptions();
options.AddClientCredentialFlowParameters(new Uri("https://api.com/token"), "12345", "12345");
options.AddUserNameForImpersonation("myemail@email.com");

var keycloakOptions = Substitute.For<Action<KeycloakOptions>>();
keycloakOptions.Invoke(options);
Assert.Single(keycloakOptions.ReceivedCalls());
}
}
}
3 changes: 2 additions & 1 deletion src/QAToolKit.Auth.Test/QAToolKit.Auth.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace QAToolKit.Auth.Exceptions
/// <summary>
/// Keycloak access denied exception
/// </summary>
[Serializable]
public class KeycloakAccessDeniedException : Exception
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace QAToolKit.Auth.Exceptions
/// <summary>
/// Keycloak exception
/// </summary>
[Serializable]
public class KeycloakException : Exception
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace QAToolKit.Auth.Exceptions
/// <summary>
/// Keycloak unauthorized client exception
/// </summary>
[Serializable]
public class KeycloakUnauthorizedClientException : Exception
{
/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions src/QAToolKit.Auth/Keycloak/KeycloakTokenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace QAToolKit.Auth
{
internal class KeycloakTokenService : IDisposable
{
private const int TokenValidityOffsetSeconds = 15;
private readonly HttpClient _client;
private readonly Uri _tokenEndpoint;
private readonly string _clientId;
Expand Down Expand Up @@ -121,7 +120,7 @@ private HttpRequestMessage CreateBasicTokenEndpointRequest()
return request;
}

private void SetRequestAcceptHeader(HttpRequestMessage req)
private static void SetRequestAcceptHeader(HttpRequestMessage req)
{
req.Headers.Add("Accept", "application/json");
}
Expand Down

0 comments on commit 6ac166e

Please sign in to comment.