Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Honour EnableDeviceAuthorizationEndpoint in IsEndpointEnabled #3645

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}