Clean up tests
- Make Facebook test server asynchronous to avoid having to block for the result. - Clean up some formatting.
This commit is contained in:
parent
90064ce9df
commit
d24fddcf59
|
|
@ -426,15 +426,15 @@ namespace Microsoft.AspNetCore.Authentication.Facebook
|
|||
{
|
||||
var server = CreateServer(
|
||||
app => { },
|
||||
services => services.AddAuthentication().AddFacebook(o => {
|
||||
services => services.AddAuthentication().AddFacebook(o =>
|
||||
{
|
||||
o.AppId = "whatever";
|
||||
o.AppSecret = "whatever";
|
||||
o.SignInScheme = FacebookDefaults.AuthenticationScheme;
|
||||
}),
|
||||
context =>
|
||||
async context =>
|
||||
{
|
||||
// Gross
|
||||
context.ChallengeAsync("Facebook").GetAwaiter().GetResult();
|
||||
await context.ChallengeAsync("Facebook");
|
||||
return true;
|
||||
});
|
||||
var error = await Assert.ThrowsAsync<InvalidOperationException>(() => server.SendAsync("https://example.com/challenge"));
|
||||
|
|
@ -446,14 +446,14 @@ namespace Microsoft.AspNetCore.Authentication.Facebook
|
|||
{
|
||||
var server = CreateServer(
|
||||
app => { },
|
||||
services => services.AddAuthentication(o => o.DefaultScheme = FacebookDefaults.AuthenticationScheme).AddFacebook(o => {
|
||||
services => services.AddAuthentication(o => o.DefaultScheme = FacebookDefaults.AuthenticationScheme).AddFacebook(o =>
|
||||
{
|
||||
o.AppId = "whatever";
|
||||
o.AppSecret = "whatever";
|
||||
}),
|
||||
context =>
|
||||
async context =>
|
||||
{
|
||||
// Gross
|
||||
context.ChallengeAsync("Facebook").GetAwaiter().GetResult();
|
||||
await context.ChallengeAsync("Facebook");
|
||||
return true;
|
||||
});
|
||||
var error = await Assert.ThrowsAsync<InvalidOperationException>(() => server.SendAsync("https://example.com/challenge"));
|
||||
|
|
@ -465,14 +465,14 @@ namespace Microsoft.AspNetCore.Authentication.Facebook
|
|||
{
|
||||
var server = CreateServer(
|
||||
app => { },
|
||||
services => services.AddAuthentication(o => o.DefaultSignInScheme = FacebookDefaults.AuthenticationScheme).AddFacebook(o => {
|
||||
services => services.AddAuthentication(o => o.DefaultSignInScheme = FacebookDefaults.AuthenticationScheme).AddFacebook(o =>
|
||||
{
|
||||
o.AppId = "whatever";
|
||||
o.AppSecret = "whatever";
|
||||
}),
|
||||
context =>
|
||||
async context =>
|
||||
{
|
||||
// Gross
|
||||
context.ChallengeAsync("Facebook").GetAwaiter().GetResult();
|
||||
await context.ChallengeAsync("Facebook");
|
||||
return true;
|
||||
});
|
||||
var error = await Assert.ThrowsAsync<InvalidOperationException>(() => server.SendAsync("https://example.com/challenge"));
|
||||
|
|
@ -498,10 +498,9 @@ namespace Microsoft.AspNetCore.Authentication.Facebook
|
|||
var server = CreateServer(
|
||||
app => { },
|
||||
services => services.AddAuthentication().AddFacebook(o => o.SignInScheme = "Whatever"),
|
||||
context =>
|
||||
async context =>
|
||||
{
|
||||
// REVIEW: Gross.
|
||||
Assert.Throws<ArgumentException>("AppId", () => context.ChallengeAsync("Facebook").GetAwaiter().GetResult());
|
||||
await Assert.ThrowsAsync<ArgumentException>("AppId", () => context.ChallengeAsync("Facebook"));
|
||||
return true;
|
||||
});
|
||||
var transaction = await server.SendAsync("http://example.com/challenge");
|
||||
|
|
@ -514,10 +513,9 @@ namespace Microsoft.AspNetCore.Authentication.Facebook
|
|||
var server = CreateServer(
|
||||
app => { },
|
||||
services => services.AddAuthentication().AddFacebook(o => o.AppId = "Whatever"),
|
||||
context =>
|
||||
async context =>
|
||||
{
|
||||
// REVIEW: Gross.
|
||||
Assert.Throws<ArgumentException>("AppSecret", () => context.ChallengeAsync("Facebook").GetAwaiter().GetResult());
|
||||
await Assert.ThrowsAsync<ArgumentException>("AppSecret", () => context.ChallengeAsync("Facebook"));
|
||||
return true;
|
||||
});
|
||||
var transaction = await server.SendAsync("http://example.com/challenge");
|
||||
|
|
@ -550,10 +548,9 @@ namespace Microsoft.AspNetCore.Authentication.Facebook
|
|||
};
|
||||
});
|
||||
},
|
||||
context =>
|
||||
async context =>
|
||||
{
|
||||
// REVIEW: Gross.
|
||||
context.ChallengeAsync("Facebook").GetAwaiter().GetResult();
|
||||
await context.ChallengeAsync("Facebook");
|
||||
return true;
|
||||
});
|
||||
var transaction = await server.SendAsync("http://example.com/challenge");
|
||||
|
|
@ -643,10 +640,9 @@ namespace Microsoft.AspNetCore.Authentication.Facebook
|
|||
o.AppSecret = "Test App Secret";
|
||||
});
|
||||
},
|
||||
context =>
|
||||
async context =>
|
||||
{
|
||||
// REVIEW: gross
|
||||
context.ChallengeAsync("Facebook").GetAwaiter().GetResult();
|
||||
await context.ChallengeAsync("Facebook");
|
||||
return true;
|
||||
});
|
||||
var transaction = await server.SendAsync("http://example.com/challenge");
|
||||
|
|
@ -728,7 +724,7 @@ namespace Microsoft.AspNetCore.Authentication.Facebook
|
|||
Assert.Contains("&access_token=", finalUserInfoEndpoint);
|
||||
}
|
||||
|
||||
private static TestServer CreateServer(Action<IApplicationBuilder> configure, Action<IServiceCollection> configureServices, Func<HttpContext, bool> handler)
|
||||
private static TestServer CreateServer(Action<IApplicationBuilder> configure, Action<IServiceCollection> configureServices, Func<HttpContext, Task<bool>> handler)
|
||||
{
|
||||
var builder = new WebHostBuilder()
|
||||
.Configure(app =>
|
||||
|
|
@ -736,7 +732,7 @@ namespace Microsoft.AspNetCore.Authentication.Facebook
|
|||
configure?.Invoke(app);
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
if (handler == null || !handler(context))
|
||||
if (handler == null || !await handler(context))
|
||||
{
|
||||
await next();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -551,7 +551,6 @@ namespace Microsoft.AspNetCore.Authentication.Google
|
|||
{
|
||||
o.ClientId = "Test Id";
|
||||
o.ClientSecret = "Test Secret";
|
||||
//AutomaticChallenge = true
|
||||
},
|
||||
context =>
|
||||
{
|
||||
|
|
@ -559,8 +558,7 @@ namespace Microsoft.AspNetCore.Authentication.Google
|
|||
var res = context.Response;
|
||||
if (req.Path == new PathString("/challenge2"))
|
||||
{
|
||||
return context.ChallengeAsync("Google", new AuthenticationProperties(
|
||||
new Dictionary<string, string>()
|
||||
return context.ChallengeAsync("Google", new AuthenticationProperties(new Dictionary<string, string>()
|
||||
{
|
||||
{ "scope", "https://www.googleapis.com/auth/plus.login" },
|
||||
{ "access_type", "offline" },
|
||||
|
|
|
|||
Loading…
Reference in New Issue