diff --git a/src/IdentityServer4/src/Extensions/EndpointOptionsExtensions.cs b/src/IdentityServer4/src/Extensions/EndpointOptionsExtensions.cs index 58e64484f3..04dc333e08 100644 --- a/src/IdentityServer4/src/Extensions/EndpointOptionsExtensions.cs +++ b/src/IdentityServer4/src/Extensions/EndpointOptionsExtensions.cs @@ -17,7 +17,9 @@ public static bool IsEndpointEnabled(this EndpointsOptions options, Endpoint end case EndpointNames.Authorize: return options.EnableAuthorizeEndpoint; case EndpointNames.CheckSession: - return options.EnableCheckSessionEndpoint; + return options.EnableCheckSessionEndpoint; + case EndpointNames.DeviceAuthorization: + return options.EnableDeviceAuthorizationEndpoint; case EndpointNames.Discovery: return options.EnableDiscoveryEndpoint; case EndpointNames.EndSession: diff --git a/src/IdentityServer4/test/IdentityServer.UnitTests/Extensions/EndpointOptionsExtensionsTests.cs b/src/IdentityServer4/test/IdentityServer.UnitTests/Extensions/EndpointOptionsExtensionsTests.cs new file mode 100644 index 0000000000..1fc853958d --- /dev/null +++ b/src/IdentityServer4/test/IdentityServer.UnitTests/Extensions/EndpointOptionsExtensionsTests.cs @@ -0,0 +1,135 @@ +using IdentityServer4.Configuration; +using IdentityServer4.Extensions; +using IdentityServer4.Hosting; +using Xunit; +using static IdentityServer4.Constants; + +namespace IdentityServer.UnitTests.Extensions +{ + public class EndpointOptionsExtensionsTests + { + private readonly EndpointsOptions _options = new EndpointsOptions(); + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void IsEndpointEnabledShouldReturnExpectedForAuthorizeEndpoint(bool expectedIsEndpointEnabled) + { + _options.EnableAuthorizeEndpoint = expectedIsEndpointEnabled; + + Assert.Equal( + expectedIsEndpointEnabled, + _options.IsEndpointEnabled( + CreateTestEndpoint(EndpointNames.Authorize))); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void IsEndpointEnabledShouldReturnExpectedForCheckSessionEndpoint(bool expectedIsEndpointEnabled) + { + _options.EnableCheckSessionEndpoint = expectedIsEndpointEnabled; + + Assert.Equal( + expectedIsEndpointEnabled, + _options.IsEndpointEnabled( + CreateTestEndpoint(EndpointNames.CheckSession))); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void IsEndpointEnabledShouldReturnExpectedForDeviceAuthorizationEndpoint(bool expectedIsEndpointEnabled) + { + _options.EnableDeviceAuthorizationEndpoint = expectedIsEndpointEnabled; + + Assert.Equal( + expectedIsEndpointEnabled, + _options.IsEndpointEnabled( + CreateTestEndpoint(EndpointNames.DeviceAuthorization))); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void IsEndpointEnabledShouldReturnExpectedForDiscoveryEndpoint(bool expectedIsEndpointEnabled) + { + _options.EnableDiscoveryEndpoint = expectedIsEndpointEnabled; + + Assert.Equal( + expectedIsEndpointEnabled, + _options.IsEndpointEnabled( + CreateTestEndpoint(EndpointNames.Discovery))); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void IsEndpointEnabledShouldReturnExpectedForEndSessionEndpoint(bool expectedIsEndpointEnabled) + { + _options.EnableEndSessionEndpoint = expectedIsEndpointEnabled; + + Assert.Equal( + expectedIsEndpointEnabled, + _options.IsEndpointEnabled( + CreateTestEndpoint(EndpointNames.EndSession))); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void IsEndpointEnabledShouldReturnExpectedForIntrospectionEndpoint(bool expectedIsEndpointEnabled) + { + _options.EnableIntrospectionEndpoint = expectedIsEndpointEnabled; + + Assert.Equal( + expectedIsEndpointEnabled, + _options.IsEndpointEnabled( + CreateTestEndpoint(EndpointNames.Introspection))); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void IsEndpointEnabledShouldReturnExpectedForTokenEndpoint(bool expectedIsEndpointEnabled) + { + _options.EnableTokenEndpoint = expectedIsEndpointEnabled; + + Assert.Equal( + expectedIsEndpointEnabled, + _options.IsEndpointEnabled( + CreateTestEndpoint(EndpointNames.Token))); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void IsEndpointEnabledShouldReturnExpectedForRevocationEndpoint(bool expectedIsEndpointEnabled) + { + _options.EnableTokenRevocationEndpoint = expectedIsEndpointEnabled; + + Assert.Equal( + expectedIsEndpointEnabled, + _options.IsEndpointEnabled( + CreateTestEndpoint(EndpointNames.Revocation))); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void IsEndpointEnabledShouldReturnExpectedForUserInfoEndpoint(bool expectedIsEndpointEnabled) + { + _options.EnableUserInfoEndpoint = expectedIsEndpointEnabled; + + Assert.Equal( + expectedIsEndpointEnabled, + _options.IsEndpointEnabled( + CreateTestEndpoint(EndpointNames.UserInfo))); + } + + private Endpoint CreateTestEndpoint(string name) + { + return new Endpoint(name, "", null); + } + } +}