Merge TestDefaultValues with TestServerBuilder
This commit is contained in:
parent
abc1b37ee1
commit
562eb7054a
|
|
@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Authentication.Tests.OpenIdConnect
|
||||||
properties.Items.Add(OpenIdConnectDefaults.UserstatePropertiesKey, userState);
|
properties.Items.Add(OpenIdConnectDefaults.UserstatePropertiesKey, userState);
|
||||||
|
|
||||||
var server = TestServerBuilder.CreateServer(settings.Options, handler: null, properties: properties);
|
var server = TestServerBuilder.CreateServer(settings.Options, handler: null, properties: properties);
|
||||||
var transaction = await TestTransaction.SendAsync(server, TestDefaultValues.TestHost + TestServerBuilder.ChallengeWithProperties);
|
var transaction = await TestTransaction.SendAsync(server, TestServerBuilder.TestHost + TestServerBuilder.ChallengeWithProperties);
|
||||||
|
|
||||||
var res = transaction.Response;
|
var res = transaction.Response;
|
||||||
Assert.Equal(HttpStatusCode.Redirect, res.StatusCode);
|
Assert.Equal(HttpStatusCode.Redirect, res.StatusCode);
|
||||||
|
|
@ -317,6 +317,6 @@ namespace Microsoft.AspNetCore.Authentication.Tests.OpenIdConnect
|
||||||
Assert.Contains("expires", secondCookie);
|
Assert.Contains("expires", secondCookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ChallengeEndpoint => TestDefaultValues.TestHost + TestServerBuilder.Challenge;
|
private static string ChallengeEndpoint => TestServerBuilder.TestHost + TestServerBuilder.Challenge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Authentication.Tests.OpenIdConnect
|
||||||
{
|
{
|
||||||
var options = new OpenIdConnectOptions
|
var options = new OpenIdConnectOptions
|
||||||
{
|
{
|
||||||
Authority = TestDefaultValues.DefaultAuthority,
|
Authority = TestServerBuilder.DefaultAuthority,
|
||||||
ClientId = Guid.NewGuid().ToString(),
|
ClientId = Guid.NewGuid().ToString(),
|
||||||
SignInScheme = Guid.NewGuid().ToString()
|
SignInScheme = Guid.NewGuid().ToString()
|
||||||
};
|
};
|
||||||
|
|
@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Authentication.Tests.OpenIdConnect
|
||||||
TestConfigurationException<ArgumentException>(
|
TestConfigurationException<ArgumentException>(
|
||||||
new OpenIdConnectOptions
|
new OpenIdConnectOptions
|
||||||
{
|
{
|
||||||
Authority = TestDefaultValues.DefaultAuthority,
|
Authority = TestServerBuilder.DefaultAuthority,
|
||||||
ClientId = Guid.NewGuid().ToString()
|
ClientId = Guid.NewGuid().ToString()
|
||||||
},
|
},
|
||||||
ex => Assert.Equal("SignInScheme", ex.ParamName));
|
ex => Assert.Equal("SignInScheme", ex.ParamName));
|
||||||
|
|
@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Authentication.Tests.OpenIdConnect
|
||||||
new OpenIdConnectOptions
|
new OpenIdConnectOptions
|
||||||
{
|
{
|
||||||
SignInScheme = "TestScheme",
|
SignInScheme = "TestScheme",
|
||||||
Authority = TestDefaultValues.DefaultAuthority,
|
Authority = TestServerBuilder.DefaultAuthority,
|
||||||
},
|
},
|
||||||
ex => Assert.Equal("ClientId", ex.ParamName));
|
ex => Assert.Equal("ClientId", ex.ParamName));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,10 +48,10 @@ namespace Microsoft.AspNetCore.Authentication.Tests.OpenIdConnect
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task SignOutWithDefaultRedirectUri()
|
public async Task SignOutWithDefaultRedirectUri()
|
||||||
{
|
{
|
||||||
var configuration = TestDefaultValues.CreateDefaultOpenIdConnectConfiguration();
|
var configuration = TestServerBuilder.CreateDefaultOpenIdConnectConfiguration();
|
||||||
var server = TestServerBuilder.CreateServer(new OpenIdConnectOptions
|
var server = TestServerBuilder.CreateServer(new OpenIdConnectOptions
|
||||||
{
|
{
|
||||||
Authority = TestDefaultValues.DefaultAuthority,
|
Authority = TestServerBuilder.DefaultAuthority,
|
||||||
ClientId = "Test Id",
|
ClientId = "Test Id",
|
||||||
Configuration = configuration
|
Configuration = configuration
|
||||||
});
|
});
|
||||||
|
|
@ -64,10 +64,10 @@ namespace Microsoft.AspNetCore.Authentication.Tests.OpenIdConnect
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task SignOutWithCustomRedirectUri()
|
public async Task SignOutWithCustomRedirectUri()
|
||||||
{
|
{
|
||||||
var configuration = TestDefaultValues.CreateDefaultOpenIdConnectConfiguration();
|
var configuration = TestServerBuilder.CreateDefaultOpenIdConnectConfiguration();
|
||||||
var server = TestServerBuilder.CreateServer(new OpenIdConnectOptions
|
var server = TestServerBuilder.CreateServer(new OpenIdConnectOptions
|
||||||
{
|
{
|
||||||
Authority = TestDefaultValues.DefaultAuthority,
|
Authority = TestServerBuilder.DefaultAuthority,
|
||||||
ClientId = "Test Id",
|
ClientId = "Test Id",
|
||||||
Configuration = configuration,
|
Configuration = configuration,
|
||||||
PostLogoutRedirectUri = "https://example.com/logout"
|
PostLogoutRedirectUri = "https://example.com/logout"
|
||||||
|
|
@ -81,10 +81,10 @@ namespace Microsoft.AspNetCore.Authentication.Tests.OpenIdConnect
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task SignOutWith_Specific_RedirectUri_From_Authentication_Properites()
|
public async Task SignOutWith_Specific_RedirectUri_From_Authentication_Properites()
|
||||||
{
|
{
|
||||||
var configuration = TestDefaultValues.CreateDefaultOpenIdConnectConfiguration();
|
var configuration = TestServerBuilder.CreateDefaultOpenIdConnectConfiguration();
|
||||||
var server = TestServerBuilder.CreateServer(new OpenIdConnectOptions
|
var server = TestServerBuilder.CreateServer(new OpenIdConnectOptions
|
||||||
{
|
{
|
||||||
Authority = TestDefaultValues.DefaultAuthority,
|
Authority = TestServerBuilder.DefaultAuthority,
|
||||||
ClientId = "Test Id",
|
ClientId = "Test Id",
|
||||||
Configuration = configuration,
|
Configuration = configuration,
|
||||||
PostLogoutRedirectUri = "https://example.com/logout"
|
PostLogoutRedirectUri = "https://example.com/logout"
|
||||||
|
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.IdentityModel.Protocols;
|
|
||||||
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Authentication.Tests.OpenIdConnect
|
|
||||||
{
|
|
||||||
internal class TestDefaultValues
|
|
||||||
{
|
|
||||||
public static readonly string DefaultAuthority = @"https://login.microsoftonline.com/common";
|
|
||||||
|
|
||||||
public static readonly string TestHost = @"https://example.com";
|
|
||||||
|
|
||||||
public static OpenIdConnectOptions CreateOpenIdConnectOptions() =>
|
|
||||||
new OpenIdConnectOptions
|
|
||||||
{
|
|
||||||
Authority = TestDefaultValues.DefaultAuthority,
|
|
||||||
ClientId = Guid.NewGuid().ToString(),
|
|
||||||
Configuration = TestDefaultValues.CreateDefaultOpenIdConnectConfiguration()
|
|
||||||
};
|
|
||||||
|
|
||||||
public static OpenIdConnectOptions CreateOpenIdConnectOptions(Action<OpenIdConnectOptions> update)
|
|
||||||
{
|
|
||||||
var options = CreateOpenIdConnectOptions();
|
|
||||||
|
|
||||||
if (update != null)
|
|
||||||
{
|
|
||||||
update(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static OpenIdConnectConfiguration CreateDefaultOpenIdConnectConfiguration() =>
|
|
||||||
new OpenIdConnectConfiguration()
|
|
||||||
{
|
|
||||||
AuthorizationEndpoint = DefaultAuthority + "/oauth2/authorize",
|
|
||||||
EndSessionEndpoint = DefaultAuthority + "/oauth2/endsessionendpoint",
|
|
||||||
TokenEndpoint = DefaultAuthority + "/oauth2/token"
|
|
||||||
};
|
|
||||||
|
|
||||||
public static IConfigurationManager<OpenIdConnectConfiguration> CreateDefaultOpenIdConnectConfigurationManager() =>
|
|
||||||
new StaticConfigurationManager<OpenIdConnectConfiguration>(CreateDefaultOpenIdConnectConfiguration());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -12,17 +12,52 @@ using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Authentication;
|
using Microsoft.AspNetCore.Http.Authentication;
|
||||||
using Microsoft.AspNetCore.TestHost;
|
using Microsoft.AspNetCore.TestHost;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.IdentityModel.Protocols;
|
||||||
|
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Authentication.Tests.OpenIdConnect
|
namespace Microsoft.AspNetCore.Authentication.Tests.OpenIdConnect
|
||||||
{
|
{
|
||||||
internal class TestServerBuilder
|
internal class TestServerBuilder
|
||||||
{
|
{
|
||||||
|
public static readonly string DefaultAuthority = @"https://login.microsoftonline.com/common";
|
||||||
|
public static readonly string TestHost = @"https://example.com";
|
||||||
public static readonly string Challenge = "/challenge";
|
public static readonly string Challenge = "/challenge";
|
||||||
public static readonly string ChallengeWithOutContext = "/challengeWithOutContext";
|
public static readonly string ChallengeWithOutContext = "/challengeWithOutContext";
|
||||||
public static readonly string ChallengeWithProperties = "/challengeWithProperties";
|
public static readonly string ChallengeWithProperties = "/challengeWithProperties";
|
||||||
public static readonly string Signin = "/signin";
|
public static readonly string Signin = "/signin";
|
||||||
public static readonly string Signout = "/signout";
|
public static readonly string Signout = "/signout";
|
||||||
|
|
||||||
|
public static OpenIdConnectOptions CreateOpenIdConnectOptions() =>
|
||||||
|
new OpenIdConnectOptions
|
||||||
|
{
|
||||||
|
Authority = DefaultAuthority,
|
||||||
|
ClientId = Guid.NewGuid().ToString(),
|
||||||
|
Configuration = CreateDefaultOpenIdConnectConfiguration()
|
||||||
|
};
|
||||||
|
|
||||||
|
public static OpenIdConnectOptions CreateOpenIdConnectOptions(Action<OpenIdConnectOptions> update)
|
||||||
|
{
|
||||||
|
var options = CreateOpenIdConnectOptions();
|
||||||
|
|
||||||
|
if (update != null)
|
||||||
|
{
|
||||||
|
update(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OpenIdConnectConfiguration CreateDefaultOpenIdConnectConfiguration() =>
|
||||||
|
new OpenIdConnectConfiguration()
|
||||||
|
{
|
||||||
|
AuthorizationEndpoint = DefaultAuthority + "/oauth2/authorize",
|
||||||
|
EndSessionEndpoint = DefaultAuthority + "/oauth2/endsessionendpoint",
|
||||||
|
TokenEndpoint = DefaultAuthority + "/oauth2/token"
|
||||||
|
};
|
||||||
|
|
||||||
|
public static IConfigurationManager<OpenIdConnectConfiguration> CreateDefaultOpenIdConnectConfigurationManager() =>
|
||||||
|
new StaticConfigurationManager<OpenIdConnectConfiguration>(CreateDefaultOpenIdConnectConfiguration());
|
||||||
|
|
||||||
public static TestServer CreateServer(OpenIdConnectOptions options)
|
public static TestServer CreateServer(OpenIdConnectOptions options)
|
||||||
{
|
{
|
||||||
return CreateServer(options, handler: null, properties: null);
|
return CreateServer(options, handler: null, properties: null);
|
||||||
|
|
@ -94,4 +129,4 @@ namespace Microsoft.AspNetCore.Authentication.Tests.OpenIdConnect
|
||||||
return new TestServer(builder);
|
return new TestServer(builder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Authentication.Tests.OpenIdConnect
|
||||||
|
|
||||||
public TestSettings(Action<OpenIdConnectOptions> configure)
|
public TestSettings(Action<OpenIdConnectOptions> configure)
|
||||||
{
|
{
|
||||||
_options = TestDefaultValues.CreateOpenIdConnectOptions(configure);
|
_options = TestServerBuilder.CreateOpenIdConnectOptions(configure);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestSettings(OpenIdConnectOptions options)
|
public TestSettings(OpenIdConnectOptions options)
|
||||||
|
|
@ -193,7 +193,7 @@ namespace Microsoft.AspNetCore.Authentication.Tests.OpenIdConnect
|
||||||
ValidateQueryParameter(OpenIdConnectParameterNames.Scope, string.Join(" ", _options.Scope), actualQuery, errors, htmlEncoded);
|
ValidateQueryParameter(OpenIdConnectParameterNames.Scope, string.Join(" ", _options.Scope), actualQuery, errors, htmlEncoded);
|
||||||
|
|
||||||
private void ValidateRedirectUri(IDictionary<string, string> actualQuery, ICollection<string> errors, bool htmlEncoded) =>
|
private void ValidateRedirectUri(IDictionary<string, string> actualQuery, ICollection<string> errors, bool htmlEncoded) =>
|
||||||
ValidateQueryParameter(OpenIdConnectParameterNames.RedirectUri, TestDefaultValues.TestHost + _options.CallbackPath, actualQuery, errors, htmlEncoded);
|
ValidateQueryParameter(OpenIdConnectParameterNames.RedirectUri, TestServerBuilder.TestHost + _options.CallbackPath, actualQuery, errors, htmlEncoded);
|
||||||
|
|
||||||
private void ValidateResource(IDictionary<string, string> actualQuery, ICollection<string> errors, bool htmlEncoded) =>
|
private void ValidateResource(IDictionary<string, string> actualQuery, ICollection<string> errors, bool htmlEncoded) =>
|
||||||
ValidateQueryParameter(OpenIdConnectParameterNames.RedirectUri, _options.Resource, actualQuery, errors, htmlEncoded);
|
ValidateQueryParameter(OpenIdConnectParameterNames.RedirectUri, _options.Resource, actualQuery, errors, htmlEncoded);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue