Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for .NET 6 #188

Merged
merged 11 commits into from
Mar 30, 2022
Prev Previous commit
Fix tests failing in Travis.
  • Loading branch information
laura-rodriguez committed Mar 29, 2022
commit 2df124e7eb6408891f5f366f1a10656a85d6c1df
70 changes: 54 additions & 16 deletions Okta.AspNetCore.Test/OpenIdConnectOptionsHelperShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,40 @@ public class OpenIdConnectOptionsHelperShould
[Theory]
[InlineData(true)]
[InlineData(false)]
public void SetOpenIdConnectsOptions(bool getClaimsFromUserInfoEndpoint)
public async Task SetOpenIdConnectsOptions(bool getClaimsFromUserInfoEndpoint)
{
var mockTokenValidatedEvent = Substitute.For<Func<OpenIdConnectTokenValidatedContext, Task>>();
var mockUserInfoReceivedEvent = Substitute.For<Func<UserInformationReceivedContext, Task>>();
var mockOktaExceptionEvent = Substitute.For<Func<RemoteFailureContext, Task>>();
var mockAuthenticationFailedEvent = Substitute.For<Func<OpenIdConnectAuthenticationFailedContext, Task>>();
var mockRedirectToIdentityProvider = Substitute.For<Func<RedirectContext, Task>>();
bool invoked = false;

Func<OpenIdConnectTokenValidatedContext, Task> mockTokenValidatedEvent = context =>
{
invoked = true;
return Task.CompletedTask;
};

Func<UserInformationReceivedContext, Task> mockUserInfoReceivedEvent = context =>
{
invoked = true;
return Task.CompletedTask;
};

Func<RemoteFailureContext, Task> mockOktaExceptionEvent = context =>
{
invoked = true;
return Task.CompletedTask;
};

Func<OpenIdConnectAuthenticationFailedContext, Task> mockAuthenticationFailedEvent = context =>
{
invoked = true;
return Task.CompletedTask;
};

Func<RedirectContext, Task> mockRedirectToIdentityProvider = context =>
{
invoked = true;
return Task.CompletedTask;
};

var mockHttpHandler = Substitute.For<HttpMessageHandler>();

var oktaMvcOptions = new OktaMvcOptions
Expand Down Expand Up @@ -88,21 +115,31 @@ public void SetOpenIdConnectsOptions(bool getClaimsFromUserInfoEndpoint)
oidcOptions.CallbackPath.Value.Should().Be(oktaMvcOptions.CallbackPath);

// Check the event was call once with a null parameter
oidcOptions.Events.OnTokenValidated(null);
mockTokenValidatedEvent.Received(1).Invoke(null);
oidcOptions.Events.OnAuthenticationFailed(null);
mockAuthenticationFailedEvent.Received(1).Invoke(null);
oidcOptions.Events.OnRemoteFailure(null);
mockOktaExceptionEvent.Received(1).Invoke(null);
oidcOptions.Events.OnRedirectToIdentityProvider(null);
mockRedirectToIdentityProvider.Received(1).Invoke(null);
await oidcOptions.Events.OnTokenValidated(default);
invoked.Should().BeTrue();
invoked = false;

await oidcOptions.Events.OnAuthenticationFailed(default);
invoked.Should().BeTrue();
invoked = false;


await oidcOptions.Events.OnRemoteFailure(default);
invoked.Should().BeTrue();
invoked = false;


await oidcOptions.Events.OnRedirectToIdentityProvider(default);
invoked.Should().BeTrue();
invoked = false;

// UserInfo event is mapped only when GetClaimsFromUserInfoEndpoint = true
if (oidcOptions.GetClaimsFromUserInfoEndpoint)
{
// Check the event was call once with a null parameter
oidcOptions.Events.OnUserInformationReceived(null);
mockUserInfoReceivedEvent.Received(1).Invoke(null);
await oidcOptions.Events.OnUserInformationReceived(default);
invoked.Should().BeTrue();
invoked = false;
}
}

Expand All @@ -123,6 +160,7 @@ public async Task SetJwtBearerOptions()
invoked = true;
return Task.CompletedTask;
};

var oktaWebApiOptions = new OktaWebApiOptions
{
AuthorizationServerId = "bar",
Expand Down