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
|
//-----------------------------------------------------------------------
// <copyright file="HostProcessedRequestTests.cs" company="Outercurve Foundation">
// Copyright (c) Outercurve Foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Test.OpenId.Provider {
using System;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.Messages;
using DotNetOpenAuth.OpenId.Provider;
using NUnit.Framework;
[TestFixture]
public class HostProcessedRequestTests : OpenIdTestBase {
private Protocol protocol;
private OpenIdProvider provider;
private CheckIdRequest checkIdRequest;
private AuthenticationRequest request;
[SetUp]
public override void SetUp() {
base.SetUp();
this.protocol = Protocol.Default;
this.provider = this.CreateProvider();
this.checkIdRequest = new CheckIdRequest(this.protocol.Version, OPUri, DotNetOpenAuth.OpenId.AuthenticationRequestMode.Setup);
this.checkIdRequest.Realm = RPRealmUri;
this.checkIdRequest.ReturnTo = RPUri;
this.request = new AuthenticationRequest(this.provider, this.checkIdRequest);
}
[TestCase]
public void IsReturnUrlDiscoverableNoResponse() {
Assert.AreEqual(RelyingPartyDiscoveryResult.NoServiceDocument, this.request.IsReturnUrlDiscoverable(this.provider.Channel.WebRequestHandler));
}
[TestCase]
public void IsReturnUrlDiscoverableValidResponse() {
this.MockResponder.RegisterMockRPDiscovery();
this.request = new AuthenticationRequest(this.provider, this.checkIdRequest);
Assert.AreEqual(RelyingPartyDiscoveryResult.Success, this.request.IsReturnUrlDiscoverable(this.provider.Channel.WebRequestHandler));
}
/// <summary>
/// Verifies that when discovery would be performed over standard HTTP and RequireSsl
/// is set, that discovery fails.
/// </summary>
[TestCase]
public void IsReturnUrlDiscoverableNotSsl() {
this.provider.SecuritySettings.RequireSsl = true;
this.MockResponder.RegisterMockRPDiscovery();
Assert.AreEqual(RelyingPartyDiscoveryResult.NoServiceDocument, this.request.IsReturnUrlDiscoverable(this.provider.Channel.WebRequestHandler));
}
/// <summary>
/// Verifies that when discovery would be performed over HTTPS that discovery succeeds.
/// </summary>
[TestCase]
public void IsReturnUrlDiscoverableRequireSsl() {
this.MockResponder.RegisterMockRPDiscovery();
this.checkIdRequest.Realm = RPRealmUriSsl;
this.checkIdRequest.ReturnTo = RPUriSsl;
// Try once with RequireSsl
this.provider.SecuritySettings.RequireSsl = true;
this.request = new AuthenticationRequest(this.provider, this.checkIdRequest);
Assert.AreEqual(RelyingPartyDiscoveryResult.Success, this.request.IsReturnUrlDiscoverable(this.provider.Channel.WebRequestHandler));
// And again without RequireSsl
this.provider.SecuritySettings.RequireSsl = false;
this.request = new AuthenticationRequest(this.provider, this.checkIdRequest);
Assert.AreEqual(RelyingPartyDiscoveryResult.Success, this.request.IsReturnUrlDiscoverable(this.provider.Channel.WebRequestHandler));
}
[TestCase]
public void IsReturnUrlDiscoverableValidButNoMatch() {
this.MockResponder.RegisterMockRPDiscovery();
this.provider.SecuritySettings.RequireSsl = false; // reset for another failure test case
this.checkIdRequest.ReturnTo = new Uri("http://somerandom/host");
this.request = new AuthenticationRequest(this.provider, this.checkIdRequest);
Assert.AreEqual(RelyingPartyDiscoveryResult.NoMatchingReturnTo, this.request.IsReturnUrlDiscoverable(this.provider.Channel.WebRequestHandler));
}
}
}
|