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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
using System;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using DotNetOpenId.RelyingParty;
using DotNetOpenId.Test.Mocks;
using NUnit.Framework;
namespace DotNetOpenId.Test {
[TestFixture]
public class EndToEndTesting {
[SetUp]
public void Setup() {
if (!UntrustedWebRequest.WhitelistHosts.Contains("localhost"))
UntrustedWebRequest.WhitelistHosts.Add("localhost");
}
[TearDown]
public void TearDown() {
MockHttpRequest.Reset();
}
void parameterizedTest(TestSupport.Scenarios scenario, ProtocolVersion version,
AuthenticationRequestMode requestMode, AuthenticationStatus expectedResult) {
Identifier claimedId = TestSupport.GetMockIdentifier(scenario, version);
parameterizedProgrammaticTest(scenario, version, claimedId, requestMode, expectedResult, true);
parameterizedProgrammaticTest(scenario, version, claimedId, requestMode, expectedResult, false);
}
void parameterizedOPIdentifierTest(TestSupport.Scenarios scenario,
AuthenticationRequestMode requestMode, AuthenticationStatus expectedResult) {
ProtocolVersion version = ProtocolVersion.V20; // only this version supports directed identity
UriIdentifier claimedIdentifier = TestSupport.GetDirectedIdentityUrl(TestSupport.Scenarios.ApproveOnSetup, version);
Identifier opIdentifier = TestSupport.GetMockOPIdentifier(TestSupport.Scenarios.ApproveOnSetup, claimedIdentifier);
parameterizedProgrammaticOPIdentifierTest(opIdentifier, version, claimedIdentifier, requestMode, expectedResult, true);
parameterizedProgrammaticOPIdentifierTest(opIdentifier, version, claimedIdentifier, requestMode, expectedResult, false);
}
void parameterizedProgrammaticTest(TestSupport.Scenarios scenario, ProtocolVersion version,
Identifier claimedUrl, AuthenticationRequestMode requestMode,
AuthenticationStatus expectedResult, bool provideStore) {
var request = TestSupport.CreateRelyingPartyRequest(!provideStore, scenario, version);
request.Mode = requestMode;
var rpResponse = TestSupport.CreateRelyingPartyResponseThroughProvider(request,
opReq => opReq.IsAuthenticated = expectedResult == AuthenticationStatus.Authenticated);
Assert.AreEqual(expectedResult, rpResponse.Status);
Assert.AreEqual(claimedUrl, rpResponse.ClaimedIdentifier);
}
void parameterizedProgrammaticOPIdentifierTest(Identifier opIdentifier, ProtocolVersion version,
Identifier claimedUrl, AuthenticationRequestMode requestMode,
AuthenticationStatus expectedResult, bool provideStore) {
var rp = TestSupport.CreateRelyingParty(provideStore ? TestSupport.RelyingPartyStore : null, null, null);
var returnTo = TestSupport.GetFullUrl(TestSupport.ConsumerPage);
var realm = new Realm(TestSupport.GetFullUrl(TestSupport.ConsumerPage).AbsoluteUri);
var request = rp.CreateRequest(opIdentifier, realm, returnTo);
request.Mode = requestMode;
var rpResponse = TestSupport.CreateRelyingPartyResponseThroughProvider(request,
opReq => {
opReq.IsAuthenticated = expectedResult == AuthenticationStatus.Authenticated;
if (opReq.IsAuthenticated.Value) {
opReq.ClaimedIdentifier = claimedUrl;
}
});
Assert.AreEqual(expectedResult, rpResponse.Status);
if (rpResponse.Status == AuthenticationStatus.Authenticated) {
Assert.AreEqual(claimedUrl, rpResponse.ClaimedIdentifier);
} else if (rpResponse.Status == AuthenticationStatus.SetupRequired) {
Assert.IsNull(rpResponse.ClaimedIdentifier);
Assert.IsNull(rpResponse.FriendlyIdentifierForDisplay);
Assert.IsNull(rpResponse.Exception);
Assert.IsInstanceOfType(typeof(ISetupRequiredAuthenticationResponse), rpResponse);
Assert.AreEqual(opIdentifier.ToString(), ((ISetupRequiredAuthenticationResponse)rpResponse).ClaimedOrProviderIdentifier.ToString());
}
}
[Test]
public void Pass_Setup_AutoApproval_11() {
parameterizedTest(
TestSupport.Scenarios.AutoApproval, ProtocolVersion.V11,
AuthenticationRequestMode.Setup,
AuthenticationStatus.Authenticated
);
}
[Test]
public void Pass_Setup_AutoApproval_20() {
parameterizedTest(
TestSupport.Scenarios.AutoApproval, ProtocolVersion.V20,
AuthenticationRequestMode.Setup,
AuthenticationStatus.Authenticated
);
}
[Test]
public void Pass_Immediate_AutoApproval_11() {
parameterizedTest(
TestSupport.Scenarios.AutoApproval, ProtocolVersion.V11,
AuthenticationRequestMode.Immediate,
AuthenticationStatus.Authenticated
);
}
[Test]
public void Pass_Immediate_AutoApproval_20() {
parameterizedTest(
TestSupport.Scenarios.AutoApproval, ProtocolVersion.V20,
AuthenticationRequestMode.Immediate,
AuthenticationStatus.Authenticated
);
}
[Test]
public void Fail_Immediate_ApproveOnSetup_11() {
parameterizedTest(
TestSupport.Scenarios.ApproveOnSetup, ProtocolVersion.V11,
AuthenticationRequestMode.Immediate,
AuthenticationStatus.SetupRequired
);
}
[Test]
public void Fail_Immediate_ApproveOnSetup_20() {
parameterizedTest(
TestSupport.Scenarios.ApproveOnSetup, ProtocolVersion.V20,
AuthenticationRequestMode.Immediate,
AuthenticationStatus.SetupRequired
);
}
[Test]
public void Pass_Setup_ApproveOnSetup_11() {
parameterizedTest(
TestSupport.Scenarios.ApproveOnSetup, ProtocolVersion.V11,
AuthenticationRequestMode.Setup,
AuthenticationStatus.Authenticated
);
}
[Test]
public void Pass_Setup_ApproveOnSetup_20() {
parameterizedTest(
TestSupport.Scenarios.ApproveOnSetup, ProtocolVersion.V20,
AuthenticationRequestMode.Setup,
AuthenticationStatus.Authenticated
);
}
[Test]
public void Pass_Immediate_AutoApproval_DirectedIdentity_20() {
parameterizedOPIdentifierTest(
TestSupport.Scenarios.AutoApproval,
AuthenticationRequestMode.Immediate,
AuthenticationStatus.Authenticated);
}
[Test]
public void Pass_Setup_ApproveOnSetup_DirectedIdentity_20() {
parameterizedOPIdentifierTest(
TestSupport.Scenarios.ApproveOnSetup,
AuthenticationRequestMode.Setup,
AuthenticationStatus.Authenticated);
}
[Test]
public void Fail_Immediate_ApproveOnSetup_DirectedIdentity_20() {
parameterizedOPIdentifierTest(
TestSupport.Scenarios.ApproveOnSetup,
AuthenticationRequestMode.Immediate,
AuthenticationStatus.SetupRequired);
}
[Test]
public void ProviderAddedFragmentRemainsInClaimedIdentifier() {
Identifier userSuppliedIdentifier = TestSupport.GetMockIdentifier(TestSupport.Scenarios.AutoApprovalAddFragment, ProtocolVersion.V20);
UriBuilder claimedIdentifier = new UriBuilder(userSuppliedIdentifier);
claimedIdentifier.Fragment = "frag";
parameterizedProgrammaticTest(
TestSupport.Scenarios.AutoApprovalAddFragment, ProtocolVersion.V20,
claimedIdentifier.Uri,
AuthenticationRequestMode.Setup,
AuthenticationStatus.Authenticated,
true
);
}
[Test]
public void SampleScriptedTest() {
var rpReq = TestSupport.CreateRelyingPartyRequest(false, TestSupport.Scenarios.AutoApproval, ProtocolVersion.V20);
var rpResp = TestSupport.CreateRelyingPartyResponseThroughProvider(rpReq, opReq => opReq.IsAuthenticated = true);
Assert.AreEqual(AuthenticationStatus.Authenticated, rpResp.Status);
}
}
}
|