|
|
@ -15,7 +15,7 @@ using Xunit; |
|
|
namespace OpenIddict.Tests { |
|
|
namespace OpenIddict.Tests { |
|
|
public class OpenIddictExtensionsTests { |
|
|
public class OpenIddictExtensionsTests { |
|
|
[Fact] |
|
|
[Fact] |
|
|
public void UseOpenIddict_AnExceptionIsThrownWhenServicesAreNotRegistered() { |
|
|
public void UseOpenIddict_ThrowsAnExceptionWhenServicesAreNotRegistered() { |
|
|
// Arrange
|
|
|
// Arrange
|
|
|
var services = new ServiceCollection(); |
|
|
var services = new ServiceCollection(); |
|
|
|
|
|
|
|
|
@ -29,7 +29,7 @@ namespace OpenIddict.Tests { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void UseOpenIddict_AnExceptionIsThrownWhenNoDistributedCacheIsRegisteredIfRequestCachingIsEnabled() { |
|
|
public void UseOpenIddict_ThrowsAnExceptionWhenNoDistributedCacheIsRegisteredIfRequestCachingIsEnabled() { |
|
|
// Arrange
|
|
|
// Arrange
|
|
|
var services = new ServiceCollection(); |
|
|
var services = new ServiceCollection(); |
|
|
|
|
|
|
|
|
@ -46,7 +46,7 @@ namespace OpenIddict.Tests { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void UseOpenIddict_AnExceptionIsThrownWhenNoSigningCredentialsIsRegistered() { |
|
|
public void UseOpenIddict_ThrowsAnExceptionWhenNoSigningCredentialsIsRegistered() { |
|
|
// Arrange
|
|
|
// Arrange
|
|
|
var services = new ServiceCollection(); |
|
|
var services = new ServiceCollection(); |
|
|
services.AddOpenIddict(); |
|
|
services.AddOpenIddict(); |
|
|
@ -62,7 +62,7 @@ namespace OpenIddict.Tests { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void UseOpenIddict_AnExceptionIsThrownWhenNoFlowIsEnabled() { |
|
|
public void UseOpenIddict_ThrowsAnExceptionWhenNoFlowIsEnabled() { |
|
|
// Arrange
|
|
|
// Arrange
|
|
|
var services = new ServiceCollection(); |
|
|
var services = new ServiceCollection(); |
|
|
|
|
|
|
|
|
@ -83,7 +83,7 @@ namespace OpenIddict.Tests { |
|
|
[Theory] |
|
|
[Theory] |
|
|
[InlineData(OpenIdConnectConstants.GrantTypes.AuthorizationCode)] |
|
|
[InlineData(OpenIdConnectConstants.GrantTypes.AuthorizationCode)] |
|
|
[InlineData(OpenIdConnectConstants.GrantTypes.Implicit)] |
|
|
[InlineData(OpenIdConnectConstants.GrantTypes.Implicit)] |
|
|
public void UseOpenIddict_AnExceptionIsThrownWhenAuthorizationEndpointIsDisabled(string flow) { |
|
|
public void UseOpenIddict_ThrowsAnExceptionWhenAuthorizationEndpointIsDisabled(string flow) { |
|
|
// Arrange
|
|
|
// Arrange
|
|
|
var services = new ServiceCollection(); |
|
|
var services = new ServiceCollection(); |
|
|
|
|
|
|
|
|
@ -109,7 +109,7 @@ namespace OpenIddict.Tests { |
|
|
[InlineData(OpenIdConnectConstants.GrantTypes.ClientCredentials)] |
|
|
[InlineData(OpenIdConnectConstants.GrantTypes.ClientCredentials)] |
|
|
[InlineData(OpenIdConnectConstants.GrantTypes.Password)] |
|
|
[InlineData(OpenIdConnectConstants.GrantTypes.Password)] |
|
|
[InlineData(OpenIdConnectConstants.GrantTypes.RefreshToken)] |
|
|
[InlineData(OpenIdConnectConstants.GrantTypes.RefreshToken)] |
|
|
public void UseOpenIddict_AnExceptionIsThrownWhenTokenEndpointIsDisabled(string flow) { |
|
|
public void UseOpenIddict_ThrowsAnExceptionWhenTokenEndpointIsDisabled(string flow) { |
|
|
// Arrange
|
|
|
// Arrange
|
|
|
var services = new ServiceCollection(); |
|
|
var services = new ServiceCollection(); |
|
|
|
|
|
|
|
|
@ -131,6 +131,29 @@ namespace OpenIddict.Tests { |
|
|
"client credentials, password and refresh token flows.", exception.Message); |
|
|
"client credentials, password and refresh token flows.", exception.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public void UseOpenIddict_ThrowsAnExceptionWhenTokenRevocationIsDisabled() { |
|
|
|
|
|
// Arrange
|
|
|
|
|
|
var services = new ServiceCollection(); |
|
|
|
|
|
|
|
|
|
|
|
services.AddOpenIddict() |
|
|
|
|
|
.AddSigningCertificate( |
|
|
|
|
|
assembly: typeof(OpenIddictProviderTests).GetTypeInfo().Assembly, |
|
|
|
|
|
resource: "OpenIddict.Tests.Certificate.pfx", |
|
|
|
|
|
password: "OpenIddict") |
|
|
|
|
|
.EnableAuthorizationEndpoint("/connect/authorize") |
|
|
|
|
|
.EnableRevocationEndpoint("/connect/revocation") |
|
|
|
|
|
.AllowImplicitFlow() |
|
|
|
|
|
.DisableTokenRevocation(); |
|
|
|
|
|
|
|
|
|
|
|
var builder = new ApplicationBuilder(services.BuildServiceProvider()); |
|
|
|
|
|
|
|
|
|
|
|
// Act and assert
|
|
|
|
|
|
var exception = Assert.Throws<InvalidOperationException>(() => builder.UseOpenIddict()); |
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal("The revocation endpoint cannot be enabled when token revocation is disabled.", exception.Message); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void Configure_OptionsAreCorrectlyAmended() { |
|
|
public void Configure_OptionsAreCorrectlyAmended() { |
|
|
// Arrange
|
|
|
// Arrange
|
|
|
@ -413,6 +436,42 @@ namespace OpenIddict.Tests { |
|
|
Assert.Equal(PathString.Empty, options.Value.CryptographyEndpointPath); |
|
|
Assert.Equal(PathString.Empty, options.Value.CryptographyEndpointPath); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public void DisableSlidingExpiration_SlidingExpirationIsDisabled() { |
|
|
|
|
|
// Arrange
|
|
|
|
|
|
var services = new ServiceCollection(); |
|
|
|
|
|
services.AddOptions(); |
|
|
|
|
|
|
|
|
|
|
|
var builder = new OpenIddictBuilder(services); |
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
builder.DisableSlidingExpiration(); |
|
|
|
|
|
|
|
|
|
|
|
var provider = services.BuildServiceProvider(); |
|
|
|
|
|
var options = provider.GetRequiredService<IOptions<OpenIddictOptions>>(); |
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.False(options.Value.UseSlidingExpiration); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public void DisableTokenRevocation_TokenRevocationIsDisabled() { |
|
|
|
|
|
// Arrange
|
|
|
|
|
|
var services = new ServiceCollection(); |
|
|
|
|
|
services.AddOptions(); |
|
|
|
|
|
|
|
|
|
|
|
var builder = new OpenIddictBuilder(services); |
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
builder.DisableTokenRevocation(); |
|
|
|
|
|
|
|
|
|
|
|
var provider = services.BuildServiceProvider(); |
|
|
|
|
|
var options = provider.GetRequiredService<IOptions<OpenIddictOptions>>(); |
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.True(options.Value.DisableTokenRevocation); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void EnableAuthorizationEndpoint_AuthorizationEndpointIsEnabled() { |
|
|
public void EnableAuthorizationEndpoint_AuthorizationEndpointIsEnabled() { |
|
|
// Arrange
|
|
|
// Arrange
|
|
|
|