Skip to content

Commit 6ac166e

Browse files
authored
before release
* API changed a bit before release, readmefile, version bump * updated tests * updated tests * small code cleanup
1 parent b98c34c commit 6ac166e

File tree

6 files changed

+47
-3
lines changed

6 files changed

+47
-3
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using NSubstitute;
2+
using QAToolKit.Core.Interfaces;
3+
using System;
4+
using System.Threading.Tasks;
5+
using Xunit;
6+
7+
namespace QAToolKit.Auth.Test.Keycloak
8+
{
9+
public class KeycloakAuthenticatorTests
10+
{
11+
[Fact]
12+
public async Task CreateAuthenticatonServiceTest_Success()
13+
{
14+
var authenticator = Substitute.For<IAuthenticationService>();
15+
await authenticator.GetAccessToken();
16+
Assert.Single(authenticator.ReceivedCalls());
17+
}
18+
19+
[Fact]
20+
public async Task CreateAuthenticatonServiceWithReturnsTest_Success()
21+
{
22+
var authenticator = Substitute.For<IAuthenticationService>();
23+
authenticator.GetAccessToken().Returns(args => "12345");
24+
25+
Assert.Equal("12345", await authenticator.GetAccessToken());
26+
Assert.Single(authenticator.ReceivedCalls());
27+
}
28+
29+
[Fact]
30+
public void CreateKeycloakOptionsTest_Success()
31+
{
32+
var options = new KeycloakOptions();
33+
options.AddClientCredentialFlowParameters(new Uri("https://api.com/token"), "12345", "12345");
34+
options.AddUserNameForImpersonation("myemail@email.com");
35+
36+
var keycloakOptions = Substitute.For<Action<KeycloakOptions>>();
37+
keycloakOptions.Invoke(options);
38+
Assert.Single(keycloakOptions.ReceivedCalls());
39+
}
40+
}
41+
}

src/QAToolKit.Auth.Test/QAToolKit.Auth.Test.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
</PackageReference>
1414
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
1515
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
16-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
17+
<PackageReference Include="NSubstitute" Version="4.2.2" />
1718
<PackageReference Include="xunit" Version="2.4.1" />
1819
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
1920
<PrivateAssets>all</PrivateAssets>

src/QAToolKit.Auth/Keycloak/Exceptions/KeycloakAccessDeniedException.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace QAToolKit.Auth.Exceptions
55
/// <summary>
66
/// Keycloak access denied exception
77
/// </summary>
8+
[Serializable]
89
public class KeycloakAccessDeniedException : Exception
910
{
1011
/// <summary>

src/QAToolKit.Auth/Keycloak/Exceptions/KeycloakException.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace QAToolKit.Auth.Exceptions
55
/// <summary>
66
/// Keycloak exception
77
/// </summary>
8+
[Serializable]
89
public class KeycloakException : Exception
910
{
1011
/// <summary>

src/QAToolKit.Auth/Keycloak/Exceptions/KeycloakUnauthorizedClientException.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace QAToolKit.Auth.Exceptions
55
/// <summary>
66
/// Keycloak unauthorized client exception
77
/// </summary>
8+
[Serializable]
89
public class KeycloakUnauthorizedClientException : Exception
910
{
1011
/// <summary>

src/QAToolKit.Auth/Keycloak/KeycloakTokenService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace QAToolKit.Auth
99
{
1010
internal class KeycloakTokenService : IDisposable
1111
{
12-
private const int TokenValidityOffsetSeconds = 15;
1312
private readonly HttpClient _client;
1413
private readonly Uri _tokenEndpoint;
1514
private readonly string _clientId;
@@ -121,7 +120,7 @@ private HttpRequestMessage CreateBasicTokenEndpointRequest()
121120
return request;
122121
}
123122

124-
private void SetRequestAcceptHeader(HttpRequestMessage req)
123+
private static void SetRequestAcceptHeader(HttpRequestMessage req)
125124
{
126125
req.Headers.Add("Accept", "application/json");
127126
}

0 commit comments

Comments
 (0)