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

Commit

Permalink
Honour EnableDeviceAuthorizationEndpoint in IsEndpointEnabled (#3645)
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-underwood authored and leastprivilege committed Oct 22, 2019
1 parent 40eec71 commit 684b441
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 1 deletion.
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);
}
}
}

0 comments on commit 684b441

Please sign in to comment.