Skip to content
This repository has been archived by the owner on Nov 14, 2022. It is now read-only.

Commit

Permalink
Merged PR 5598: Improved WireMock.Net TheIdentityHubServiceTests by @…
Browse files Browse the repository at this point in the history
…StefH suggestions

Improved WireMock.Net TheIdentityHubServiceTests by @StefH suggestions

Related work items: #58196
  • Loading branch information
hiddehs committed Aug 20, 2020
2 parents a89baa0 + acb115a commit b30510d
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Components.Tests/Icc/TheIdentityHubServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,23 @@ public class TheIdentityHubServiceTests
private ITheIdentityHubService _TheIdentityHubService;
private IOptionsMonitor<TheIdentityHubOptions> _Options;
private WireMockServer _Server;
private int _TestPort = 8081;

[TestInitialize]
public void Initialize()
{
var logger = new TestLogger<TheIdentityHubService>();
_Server = WireMockServer.Start();

if (_Server.Urls.Length < 1)
{
Assert.Fail("WireMockServer not started correctly");
return;
}

var serviceCollection = new ServiceCollection();
serviceCollection.AddCustomOptions(TheIdentityHubDefaults.AuthenticationScheme, options =>
{
options.TheIdentityHubUrl = new Uri("http://localhost:" + _TestPort);
options.TheIdentityHubUrl = new Uri(_Server.Urls[0]);
options.Tenant = "ggdghornl_test";
options.ClientId = "0";
options.ClientSecret = "supersecret";
Expand All @@ -66,8 +72,8 @@ public void Validate_If_Service_Is_Initialized()
public void VerifyTokenShouldReturnTrueOnValidToken()
{
var validToken = "valid_access_token";
_Server = WireMockServer.Start(_TestPort);

_Server.Reset();
_Server.Given(
Request.Create()
.WithHeader("Authorization", "Bearer " + validToken)
Expand All @@ -81,15 +87,14 @@ public void VerifyTokenShouldReturnTrueOnValidToken()
);

Assert.IsTrue(_TheIdentityHubService.VerifyToken(validToken).Result);
_Server.Stop();
}

[TestMethod]
public void VerifyTokenShouldReturnFalseOnInValidToken()
{
var validToken = "invalid_access_token";
_Server = WireMockServer.Start(_TestPort);

_Server.Reset();
_Server.Given(
Request.Create()
.WithHeader("Authorization", "Bearer " + validToken)
Expand All @@ -103,16 +108,15 @@ public void VerifyTokenShouldReturnFalseOnInValidToken()
);

Assert.IsFalse(_TheIdentityHubService.VerifyToken(validToken).Result);
_Server.Stop();
}


[TestMethod]
public void VerifyAccessTokenRevocation()
{
var validToken = "valid_access_token";
_Server = WireMockServer.Start(_TestPort);

_Server.Reset();
_Server.Given(
Request.Create().UsingPost()
.WithHeader("Authorization", "Bearer " + validToken)
Expand All @@ -125,16 +129,14 @@ public void VerifyAccessTokenRevocation()
.WithBody("{\"msg\":\"Access Token revoked\"}")
);
Assert.IsTrue(_TheIdentityHubService.RevokeAccessToken(validToken).Result);
Console.WriteLine(_Server.LogEntries);
_Server.Stop();
}

[TestMethod]
public void VerifyInvalidAccessTokenRevocation()
{
var invalidAccessToken = "invalid_access_token";
_Server = WireMockServer.Start(_TestPort);

_Server.Reset();
_Server.Given(
Request.Create().UsingPost()
.WithHeader("Authorization", "Bearer " + invalidAccessToken)
Expand All @@ -147,8 +149,6 @@ public void VerifyInvalidAccessTokenRevocation()
.WithBody("{\"error\":\"Invalid AccessToken\"}")
);
Assert.IsFalse(_TheIdentityHubService.RevokeAccessToken(invalidAccessToken).Result);

_Server.Stop();
}
}
}
Expand Down

0 comments on commit b30510d

Please sign in to comment.