Repository navigation
Expand file tree
/
Copy pathAuthenticationHandlerFacts.cs
More file actions
95 lines (81 loc) · 3.22 KB
/
Copy pathAuthenticationHandlerFacts.cs
File metadata and controls
95 lines (81 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// 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 System.Threading.Tasks;
using Microsoft.AspNet.Http.Features.Authentication;
using Microsoft.AspNet.Http.Internal;
using Microsoft.Framework.Logging;
using Xunit;
namespace Microsoft.AspNet.Authentication
{
public class AuthenticationHandlerFacts
{
[Fact]
public void ShouldHandleSchemeAreDeterminedOnlyByMatchingAuthenticationScheme()
{
var handler = new TestHandler("Alpha");
var passiveNoMatch = handler.ShouldHandleScheme("Beta");
handler = new TestHandler("Alpha");
var passiveWithMatch = handler.ShouldHandleScheme("Alpha");
Assert.False(passiveNoMatch);
Assert.True(passiveWithMatch);
}
[Fact]
public void AutomaticHandlerInAutomaticModeHandlesEmptyChallenges()
{
var handler = new TestAutoHandler("ignored", true);
Assert.True(handler.ShouldHandleScheme(""));
}
[Fact]
public void AutomaticHandlerShouldHandleSchemeWhenSchemeMatches()
{
var handler = new TestAutoHandler("Alpha", true);
Assert.True(handler.ShouldHandleScheme("Alpha"));
}
[Fact]
public void AutomaticHandlerShouldNotHandleChallengeWhenSchemeDoesNotMatches()
{
var handler = new TestAutoHandler("Dog", true);
Assert.False(handler.ShouldHandleScheme("Alpha"));
}
[Fact]
public void AutomaticHandlerShouldNotHandleChallengeWhenSchemesNotEmpty()
{
var handler = new TestAutoHandler(null, true);
Assert.False(handler.ShouldHandleScheme("Alpha"));
}
private class TestHandler : AuthenticationHandler<AuthenticationOptions>
{
public TestHandler(string scheme)
{
Initialize(new TestOptions(), new DefaultHttpContext(), new LoggerFactory().CreateLogger("TestHandler"), Framework.WebEncoders.UrlEncoder.Default);
Options.AuthenticationScheme = scheme;
}
public override Task<AuthenticationTicket> AuthenticateAsync()
{
throw new NotImplementedException();
}
}
private class TestOptions : AuthenticationOptions { }
private class TestAutoOptions : AuthenticationOptions
{
public TestAutoOptions()
{
AutomaticAuthentication = true;
}
}
private class TestAutoHandler : AuthenticationHandler<TestAutoOptions>
{
public TestAutoHandler(string scheme, bool auto)
{
Initialize(new TestAutoOptions(), new DefaultHttpContext(), new LoggerFactory().CreateLogger("TestHandler"), Framework.WebEncoders.UrlEncoder.Default);
Options.AuthenticationScheme = scheme;
Options.AutomaticAuthentication = auto;
}
public override Task<AuthenticationTicket> AuthenticateAsync()
{
throw new NotImplementedException();
}
}
}
}