summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-01-29 08:04:48 -0800
committerAndrew <andrewarnott@gmail.com>2009-01-29 08:10:59 -0800
commit6da8acfa0ddc095ae3e9ba9fb884db53764c3f1d (patch)
treec56fff5fae6ec74a8988e3fa3b22a47c0ce79369
parentfd7dfdcf439eb1869ff83dfdfac58536691c187f (diff)
downloadDotNetOpenAuth-6da8acfa0ddc095ae3e9ba9fb884db53764c3f1d.zip
DotNetOpenAuth-6da8acfa0ddc095ae3e9ba9fb884db53764c3f1d.tar.gz
DotNetOpenAuth-6da8acfa0ddc095ae3e9ba9fb884db53764c3f1d.tar.bz2
Refactored test helpers to remove TestSupport and move its functionality into OpenIdTestBase.
-rw-r--r--.gitignore4
-rw-r--r--src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj1
-rw-r--r--src/DotNetOpenAuth.Test/Hosting/HostingTests.cs4
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs2
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/MockHttpRequest.cs16
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs22
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs4
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs6
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/ChannelElements/SigningBindingElementTests.cs6
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/DiffieHellmanTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionTestUtilities.cs4
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Messages/AssociateRequestTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Messages/IndirectErrorResponseTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Messages/IndirectSignedResponseTests.cs8
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Messages/NegativeAssertionResponseTests.cs18
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Messages/PositiveAssertionResponseTests.cs8
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs130
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Provider/AuthenticationRequestTest.cs12
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/RelyingParty/AuthenticationRequestTests.cs12
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/RelyingParty/OpenIdRelyingPartyTests.cs20
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/RelyingParty/PositiveAuthenticationResponseTests.cs10
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/RelyingParty/ServiceEndpointTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/TestSupport.cs440
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs70
-rw-r--r--src/DotNetOpenAuth.Test/TestBase.cs12
-rw-r--r--src/DotNetOpenAuth.Test/TestUtilities.cs5
27 files changed, 260 insertions, 564 deletions
diff --git a/.gitignore b/.gitignore
index be67a21..b9661dfd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,7 @@ PrecompiledWeb
*.suo
*.cache
*.user
+*.tmp
+*.ldf
+*.mdf
+*.swx
diff --git a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
index bb2346c..a3fda95 100644
--- a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
+++ b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
@@ -154,7 +154,6 @@
<Compile Include="OpenId\RelyingParty\OpenIdRelyingPartyTests.cs" />
<Compile Include="OpenId\RelyingParty\RelyingPartySecuritySettingsTests.cs" />
<Compile Include="OpenId\RelyingParty\ServiceEndpointTests.cs" />
- <Compile Include="OpenId\TestSupport.cs" />
<Compile Include="OpenId\UriIdentifierTests.cs" />
<Compile Include="OpenId\XriIdentifierTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
diff --git a/src/DotNetOpenAuth.Test/Hosting/HostingTests.cs b/src/DotNetOpenAuth.Test/Hosting/HostingTests.cs
index a9146ee..f65d081 100644
--- a/src/DotNetOpenAuth.Test/Hosting/HostingTests.cs
+++ b/src/DotNetOpenAuth.Test/Hosting/HostingTests.cs
@@ -15,10 +15,10 @@ namespace DotNetOpenAuth.Test.Hosting {
using DotNetOpenAuth.Test.OpenId;
[TestClass]
- public class HostingTests {
+ public class HostingTests : TestBase {
[TestMethod]
public void AspHostBasicTest() {
- using (AspNetHost host = AspNetHost.CreateHost(TestSupport.TestWebDirectory)) {
+ using (AspNetHost host = AspNetHost.CreateHost(TestWebDirectory)) {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(host.BaseUri);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
index edf60e6..ed0cb10 100644
--- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
@@ -101,7 +101,7 @@ namespace DotNetOpenAuth.Test.Mocks {
lock (waitingForMessageCoordinationLock) {
this.simulationCompleted = true;
if (this.RemoteChannel.waitingForMessage && this.RemoteChannel.incomingMessage == null) {
- TestSupport.Logger.Debug("CoordinatingChannel is closing while remote channel is waiting for an incoming message. Signaling channel to unblock it to receive a null message.");
+ TestUtilities.TestLogger.Debug("CoordinatingChannel is closing while remote channel is waiting for an incoming message. Signaling channel to unblock it to receive a null message.");
this.RemoteChannel.incomingMessageSignal.Set();
}
}
diff --git a/src/DotNetOpenAuth.Test/Mocks/MockHttpRequest.cs b/src/DotNetOpenAuth.Test/Mocks/MockHttpRequest.cs
index 500edb1..19836c0 100644
--- a/src/DotNetOpenAuth.Test/Mocks/MockHttpRequest.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/MockHttpRequest.cs
@@ -34,7 +34,7 @@ namespace DotNetOpenAuth.Test.Mocks {
if (!untrustedHandler.WhitelistHosts.Contains("localhost")) {
untrustedHandler.WhitelistHosts.Add("localhost");
}
- untrustedHandler.WhitelistHosts.Add(OpenIdTestBase.ProviderUri.Host);
+ untrustedHandler.WhitelistHosts.Add(OpenIdTestBase.OPUri.Host);
MockHttpRequest mock = new MockHttpRequest(untrustedHandler);
testHandler.Callback = mock.GetMockResponse;
return mock;
@@ -141,14 +141,12 @@ namespace DotNetOpenAuth.Test.Mocks {
}
internal Identifier RegisterMockXrdsResponse(string embeddedResourcePath) {
- UriIdentifier id = TestSupport.GetFullUrl(embeddedResourcePath);
- this.RegisterMockResponse(id, "application/xrds+xml", TestSupport.LoadEmbeddedFile(embeddedResourcePath));
+ UriIdentifier id = new Uri(new Uri("http://localhost/"), embeddedResourcePath);
+ this.RegisterMockResponse(id, "application/xrds+xml", OpenIdTestBase.LoadEmbeddedFile(embeddedResourcePath));
return id;
}
internal void RegisterMockRPDiscovery() {
- Uri rpRealmUri = TestSupport.Realm.UriWithWildcardChangedToWww;
-
string template = @"<xrds:XRDS xmlns:xrds='xri://$xrds' xmlns:openid='http://openid.net/xmlns/1.0' xmlns='xri://$xrd*($v*2.0)'>
<XRD>
<Service priority='10'>
@@ -157,9 +155,13 @@ namespace DotNetOpenAuth.Test.Mocks {
</Service>
</XRD>
</xrds:XRDS>";
- string xrds = string.Format(CultureInfo.InvariantCulture, template, HttpUtility.HtmlEncode(Protocol.V20.RPReturnToTypeURI), HttpUtility.HtmlEncode(rpRealmUri.AbsoluteUri));
+ string xrds = string.Format(
+ CultureInfo.InvariantCulture,
+ template,
+ HttpUtility.HtmlEncode(Protocol.V20.RPReturnToTypeURI),
+ HttpUtility.HtmlEncode(OpenIdTestBase.RPRealmUri.AbsoluteUri));
- this.RegisterMockResponse(rpRealmUri, ContentTypes.Xrds, xrds);
+ this.RegisterMockResponse(OpenIdTestBase.RPRealmUri, ContentTypes.Xrds, xrds);
}
internal void DeleteResponse(Uri requestUri) {
diff --git a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
index e33f5de..36f07d1 100644
--- a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
@@ -53,7 +53,7 @@ namespace DotNetOpenAuth.Test.OpenId {
Assert.AreEqual(request.AssociationType, response.AssociationType);
Assert.AreEqual(request.SessionType, response.SessionType);
},
- TestSupport.AutoProvider);
+ AutoProvider);
coordinator.Run();
}
@@ -70,7 +70,7 @@ namespace DotNetOpenAuth.Test.OpenId {
// the OP and RP are behaving as expected.
OpenIdCoordinator coordinator = new OpenIdCoordinator(
rp => {
- var opDescription = new ProviderEndpointDescription(ProviderUri, protocol.Version);
+ var opDescription = new ProviderEndpointDescription(OPUri, protocol.Version);
Association association = rp.AssociationManager.GetOrCreateAssociation(opDescription);
Assert.IsNotNull(association, "Association failed to be created.");
Assert.AreEqual(protocol.Args.SignatureAlgorithm.HMAC_SHA1, association.GetAssociationType(protocol));
@@ -123,7 +123,7 @@ namespace DotNetOpenAuth.Test.OpenId {
Assert.AreEqual(protocol.Args.SignatureAlgorithm.HMAC_SHA1, response.AssociationType);
Assert.AreEqual(protocol.Args.SessionType.DH_SHA1, response.SessionType);
},
- TestSupport.AutoProvider);
+ AutoProvider);
coordinator.Run();
}
@@ -135,7 +135,7 @@ namespace DotNetOpenAuth.Test.OpenId {
Protocol protocol = Protocol.V20;
OpenIdCoordinator coordinator = new OpenIdCoordinator(
rp => {
- var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(ProviderUri, protocol.Version));
+ var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(OPUri, protocol.Version));
Assert.IsNull(association, "The RP should quietly give up when the OP misbehaves.");
},
op => {
@@ -159,7 +159,7 @@ namespace DotNetOpenAuth.Test.OpenId {
Protocol protocol = Protocol.V20;
OpenIdCoordinator coordinator = new OpenIdCoordinator(
rp => {
- var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(ProviderUri, protocol.Version));
+ var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(OPUri, protocol.Version));
Assert.IsNull(association, "The RP should quietly give up when the OP misbehaves.");
},
op => {
@@ -184,7 +184,7 @@ namespace DotNetOpenAuth.Test.OpenId {
Protocol protocol = Protocol.V20;
OpenIdCoordinator coordinator = new OpenIdCoordinator(
rp => {
- var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(ProviderUri, protocol.Version));
+ var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(OPUri, protocol.Version));
Assert.IsNull(association, "The RP should quietly give up when the OP misbehaves.");
},
op => {
@@ -209,7 +209,7 @@ namespace DotNetOpenAuth.Test.OpenId {
Protocol protocol = Protocol.V20;
OpenIdCoordinator coordinator = new OpenIdCoordinator(
rp => {
- var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(ProviderUri, protocol.Version));
+ var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(OPUri, protocol.Version));
Assert.IsNull(association, "The RP should quietly give up when the OP misbehaves.");
},
op => {
@@ -243,12 +243,12 @@ namespace DotNetOpenAuth.Test.OpenId {
OpenIdCoordinator coordinator = new OpenIdCoordinator(
rp => {
rp.SecuritySettings.MinimumHashBitLength = 256;
- var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(ProviderUri, protocol.Version));
+ var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(OPUri, protocol.Version));
Assert.IsNull(association, "No association should have been created when RP and OP could not agree on association strength.");
},
op => {
op.SecuritySettings.MaximumHashBitLength = 160;
- TestSupport.AutoProvider(op);
+ AutoProvider(op);
});
coordinator.Run();
}
@@ -259,9 +259,9 @@ namespace DotNetOpenAuth.Test.OpenId {
/// </summary>
[TestMethod]
public void AssociateQuietlyFailsAfterHttpError() {
- this.MockResponder.RegisterMockNotFound(ProviderUri);
+ this.MockResponder.RegisterMockNotFound(OPUri);
var rp = this.CreateRelyingParty();
- var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(ProviderUri, Protocol.V20.Version));
+ var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(OPUri, Protocol.V20.Version));
Assert.IsNull(association);
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs b/src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs
index f40f7b1..b20886b 100644
--- a/src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs
@@ -71,10 +71,10 @@ namespace DotNetOpenAuth.Test.OpenId {
Association association = sharedAssociation ? HmacShaAssociation.Create(protocol, protocol.Args.SignatureAlgorithm.Best, AssociationRelyingPartyType.Smart, securitySettings) : null;
var coordinator = new OpenIdCoordinator(
rp => {
- var request = new CheckIdRequest(protocol.Version, ProviderUri, AuthenticationRequestMode.Immediate);
+ var request = new CheckIdRequest(protocol.Version, OPUri, AuthenticationRequestMode.Immediate);
if (association != null) {
- TestSupport.StoreAssociation(rp, ProviderUri, association);
+ StoreAssociation(rp, OPUri, association);
request.AssociationHandle = association.Handle;
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs
index e0fac9e..948cd1a 100644
--- a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs
@@ -32,7 +32,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements {
this.factory = new OpenIdExtensionFactory();
this.factory.RegisterExtension(MockOpenIdExtension.Factory);
this.rpElement = new ExtensionsBindingElement(this.factory, new RelyingPartySecuritySettings());
- this.request = new SignedResponseRequest(Protocol.Default.Version, OpenIdTestBase.ProviderUri, AuthenticationRequestMode.Immediate);
+ this.request = new SignedResponseRequest(Protocol.Default.Version, OpenIdTestBase.OPUri, AuthenticationRequestMode.Immediate);
}
[TestMethod]
@@ -60,7 +60,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements {
/// </summary>
[TestMethod]
public void PrepareMessageForSendingNonExtendableMessage() {
- IProtocolMessage request = new AssociateDiffieHellmanRequest(Protocol.Default.Version, OpenIdTestBase.ProviderUri);
+ IProtocolMessage request = new AssociateDiffieHellmanRequest(Protocol.Default.Version, OpenIdTestBase.OPUri);
Assert.IsFalse(this.rpElement.PrepareMessageForSending(request));
}
@@ -178,7 +178,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements {
ErrorUtilities.VerifyArgumentNotNull(protocol, "protocol");
IndirectSignedResponse response = new IndirectSignedResponse(protocol.Version, RPUri);
- response.ProviderEndpoint = ProviderUri;
+ response.ProviderEndpoint = OPUri;
response.Extensions.Add(new MockOpenIdExtension("pv", "ev"));
return response;
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/SigningBindingElementTests.cs b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/SigningBindingElementTests.cs
index 2f5ddff..78b96e6 100644
--- a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/SigningBindingElementTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/SigningBindingElementTests.cs
@@ -30,9 +30,9 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements {
store.StoreAssociation(AssociationRelyingPartyType.Smart, association);
SigningBindingElement signer = new SigningBindingElement(store, settings);
- IndirectSignedResponse message = new IndirectSignedResponse(protocol.Version, RPUri);
+ IndirectSignedResponse message = new IndirectSignedResponse(protocol.Version, new Uri("http://rp"));
ITamperResistantOpenIdMessage signedMessage = message;
- message.ProviderEndpoint = ProviderUri;
+ message.ProviderEndpoint = new Uri("http://provider");
signedMessage.UtcCreationDate = DateTime.Parse("1/1/2009");
signedMessage.AssociationHandle = association.Handle;
Assert.IsTrue(signer.PrepareMessageForSending(message));
@@ -48,7 +48,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements {
SigningBindingElement sbe = new SigningBindingElement(new AssociationMemoryStore<AssociationRelyingPartyType>(), new ProviderSecuritySettings());
IndirectSignedResponse response = new IndirectSignedResponse(protocol.Version, RPUri);
response.ReturnTo = RPUri;
- response.ProviderEndpoint = ProviderUri;
+ response.ProviderEndpoint = OPUri;
response.ExtraData["someunsigned"] = "value";
response.ExtraData["openid.somesigned"] = "value";
diff --git a/src/DotNetOpenAuth.Test/OpenId/DiffieHellmanTests.cs b/src/DotNetOpenAuth.Test/OpenId/DiffieHellmanTests.cs
index 1c7a089..fbbea71 100644
--- a/src/DotNetOpenAuth.Test/OpenId/DiffieHellmanTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/DiffieHellmanTests.cs
@@ -24,7 +24,7 @@ namespace DotNetOpenAuth.Test.OpenId {
[TestMethod, Timeout(15000)]
public void TestPublic() {
- TextReader reader = new StringReader(TestSupport.LoadEmbeddedFile("dhpriv.txt"));
+ TextReader reader = new StringReader(OpenIdTestBase.LoadEmbeddedFile("dhpriv.txt"));
try {
string line;
diff --git a/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionTestUtilities.cs b/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionTestUtilities.cs
index 2e12331..7792ad9 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionTestUtilities.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionTestUtilities.cs
@@ -36,8 +36,8 @@ namespace DotNetOpenAuth.Test.OpenId.Extensions {
var coordinator = new OpenIdCoordinator(
rp => {
RegisterExtension(rp.Channel, Mocks.MockOpenIdExtension.Factory);
- var requestBase = new CheckIdRequest(protocol.Version, OpenIdTestBase.ProviderUri, AuthenticationRequestMode.Immediate);
- TestSupport.StoreAssociation(rp, OpenIdTestBase.ProviderUri, association);
+ var requestBase = new CheckIdRequest(protocol.Version, OpenIdTestBase.OPUri, AuthenticationRequestMode.Immediate);
+ OpenIdTestBase.StoreAssociation(rp, OpenIdTestBase.OPUri, association);
requestBase.AssociationHandle = association.Handle;
requestBase.ClaimedIdentifier = "http://claimedid";
requestBase.LocalIdentifier = "http://localid";
diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateRequestTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateRequestTests.cs
index b83155c..ef2aa05 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateRequestTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateRequestTests.cs
@@ -84,7 +84,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
SecuritySettings securitySettings = new RelyingPartySecuritySettings();
securitySettings.MinimumHashBitLength = 160;
securitySettings.MaximumHashBitLength = 160;
- ProviderEndpointDescription provider = new ProviderEndpointDescription(ProviderUri, protocol.Version);
+ ProviderEndpointDescription provider = new ProviderEndpointDescription(OPUri, protocol.Version);
Assert.AreEqual(AssociateRequest.Create(securitySettings, provider).AssociationType, protocol.Args.SignatureAlgorithm.HMAC_SHA1);
securitySettings.MinimumHashBitLength = 384;
diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectErrorResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectErrorResponseTests.cs
index 093518d..3448358 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectErrorResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectErrorResponseTests.cs
@@ -18,7 +18,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
[TestInitialize]
public void Setup() {
- CheckIdRequest request = new CheckIdRequest(Protocol.V20.Version, ProviderUri, AuthenticationRequestMode.Immediate);
+ CheckIdRequest request = new CheckIdRequest(Protocol.V20.Version, OPUri, AuthenticationRequestMode.Immediate);
request.ReturnTo = RPUri;
this.response = new IndirectErrorResponse(request);
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectSignedResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectSignedResponseTests.cs
index d8c1735..8ee43cd 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectSignedResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectSignedResponseTests.cs
@@ -32,7 +32,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
base.SetUp();
this.protocol = Protocol.V20;
- this.request = new CheckIdRequest(this.protocol.Version, ProviderUri, AuthenticationRequestMode.Setup);
+ this.request = new CheckIdRequest(this.protocol.Version, OPUri, AuthenticationRequestMode.Setup);
this.request.ReturnTo = RPUri;
this.response = new IndirectSignedResponse(this.request);
@@ -44,7 +44,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
Assert.AreEqual(this.protocol.Args.Mode.id_res, this.response.Mode);
Assert.AreEqual(this.request.Version, this.response.Version);
Assert.AreEqual(this.request.ReturnTo, this.response.Recipient);
- Assert.AreEqual(ProviderUri, this.response.ProviderEndpoint);
+ Assert.AreEqual(OPUri, this.response.ProviderEndpoint);
Assert.IsTrue(DateTime.UtcNow - ((ITamperResistantOpenIdMessage)this.response).UtcCreationDate < TimeSpan.FromSeconds(5));
}
@@ -56,8 +56,8 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
Assert.IsTrue(DateTime.UtcNow - ((ITamperResistantOpenIdMessage)this.unsolicited).UtcCreationDate < TimeSpan.FromSeconds(5));
Assert.IsNull(this.unsolicited.ProviderEndpoint);
- this.unsolicited.ProviderEndpoint = ProviderUri;
- Assert.AreEqual(ProviderUri, this.unsolicited.ProviderEndpoint);
+ this.unsolicited.ProviderEndpoint = OPUri;
+ Assert.AreEqual(OPUri, this.unsolicited.ProviderEndpoint);
}
[TestMethod]
diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/NegativeAssertionResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/NegativeAssertionResponseTests.cs
index c3995b4..7876732 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Messages/NegativeAssertionResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Messages/NegativeAssertionResponseTests.cs
@@ -24,14 +24,14 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
[TestMethod]
public void Mode() {
- var setupRequestV1 = new CheckIdRequest(Protocol.V10.Version, ProviderUri, AuthenticationRequestMode.Setup);
+ var setupRequestV1 = new CheckIdRequest(Protocol.V10.Version, OPUri, AuthenticationRequestMode.Setup);
setupRequestV1.ReturnTo = RPUri;
- var immediateRequestV1 = new CheckIdRequest(Protocol.V10.Version, ProviderUri, AuthenticationRequestMode.Immediate);
+ var immediateRequestV1 = new CheckIdRequest(Protocol.V10.Version, OPUri, AuthenticationRequestMode.Immediate);
immediateRequestV1.ReturnTo = RPUri;
- var setupRequestV2 = new CheckIdRequest(Protocol.V20.Version, ProviderUri, AuthenticationRequestMode.Setup);
+ var setupRequestV2 = new CheckIdRequest(Protocol.V20.Version, OPUri, AuthenticationRequestMode.Setup);
setupRequestV2.ReturnTo = RPUri;
- var immediateRequestV2 = new CheckIdRequest(Protocol.V20.Version, ProviderUri, AuthenticationRequestMode.Immediate);
+ var immediateRequestV2 = new CheckIdRequest(Protocol.V20.Version, OPUri, AuthenticationRequestMode.Immediate);
immediateRequestV2.ReturnTo = RPUri;
Assert.AreEqual("id_res", new NegativeAssertionResponse(immediateRequestV1).Mode);
@@ -47,14 +47,14 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
[TestMethod, ExpectedException(typeof(ProtocolException))]
public void UserSetupUrlRequiredInV1Immediate() {
- var immediateRequestV1 = new CheckIdRequest(Protocol.V10.Version, ProviderUri, AuthenticationRequestMode.Immediate);
+ var immediateRequestV1 = new CheckIdRequest(Protocol.V10.Version, OPUri, AuthenticationRequestMode.Immediate);
immediateRequestV1.ReturnTo = RPUri;
new NegativeAssertionResponse(immediateRequestV1).EnsureValidMessage();
}
[TestMethod]
public void UserSetupUrlSetForV1Immediate() {
- var immediateRequestV1 = new CheckIdRequest(Protocol.V10.Version, ProviderUri, AuthenticationRequestMode.Immediate);
+ var immediateRequestV1 = new CheckIdRequest(Protocol.V10.Version, OPUri, AuthenticationRequestMode.Immediate);
immediateRequestV1.ReturnTo = RPUri;
var response = new NegativeAssertionResponse(immediateRequestV1);
response.UserSetupUrl = new Uri("http://usersetup");
@@ -63,15 +63,15 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
[TestMethod]
public void UserSetupUrlNotRequiredInV1SetupOrV2() {
- var setupRequestV1 = new CheckIdRequest(Protocol.V10.Version, ProviderUri, AuthenticationRequestMode.Setup);
+ var setupRequestV1 = new CheckIdRequest(Protocol.V10.Version, OPUri, AuthenticationRequestMode.Setup);
setupRequestV1.ReturnTo = RPUri;
new NegativeAssertionResponse(setupRequestV1).EnsureValidMessage();
- var setupRequestV2 = new CheckIdRequest(Protocol.V20.Version, ProviderUri, AuthenticationRequestMode.Setup);
+ var setupRequestV2 = new CheckIdRequest(Protocol.V20.Version, OPUri, AuthenticationRequestMode.Setup);
setupRequestV2.ReturnTo = RPUri;
new NegativeAssertionResponse(setupRequestV2).EnsureValidMessage();
- var immediateRequestV2 = new CheckIdRequest(Protocol.V20.Version, ProviderUri, AuthenticationRequestMode.Immediate);
+ var immediateRequestV2 = new CheckIdRequest(Protocol.V20.Version, OPUri, AuthenticationRequestMode.Immediate);
immediateRequestV2.ReturnTo = RPUri;
new NegativeAssertionResponse(immediateRequestV2).EnsureValidMessage();
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/PositiveAssertionResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/PositiveAssertionResponseTests.cs
index 978bac8..faa6a91 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Messages/PositiveAssertionResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Messages/PositiveAssertionResponseTests.cs
@@ -31,7 +31,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
base.SetUp();
this.protocol = Protocol.V20;
- this.request = new CheckIdRequest(this.protocol.Version, ProviderUri, AuthenticationRequestMode.Setup);
+ this.request = new CheckIdRequest(this.protocol.Version, OPUri, AuthenticationRequestMode.Setup);
this.request.ReturnTo = RPUri;
this.response = new PositiveAssertionResponse(this.request);
@@ -43,7 +43,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
Assert.AreEqual(this.protocol.Args.Mode.id_res, this.response.Mode);
Assert.AreEqual(this.request.Version, this.response.Version);
Assert.AreEqual(this.request.ReturnTo, this.response.Recipient);
- Assert.AreEqual(ProviderUri, this.response.ProviderEndpoint);
+ Assert.AreEqual(OPUri, this.response.ProviderEndpoint);
}
[TestMethod]
@@ -53,8 +53,8 @@ namespace DotNetOpenAuth.Test.OpenId.Messages {
Assert.AreEqual(RPUri, this.unsolicited.Recipient);
Assert.IsNull(this.unsolicited.ProviderEndpoint);
- this.unsolicited.ProviderEndpoint = ProviderUri;
- Assert.AreEqual(ProviderUri, this.unsolicited.ProviderEndpoint);
+ this.unsolicited.ProviderEndpoint = OPUri;
+ Assert.AreEqual(OPUri, this.unsolicited.ProviderEndpoint);
}
/// <summary>
diff --git a/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs b/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs
index 273b150..e5b2093 100644
--- a/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs
@@ -14,16 +14,40 @@ namespace DotNetOpenAuth.Test.OpenId {
using DotNetOpenAuth.OpenId.RelyingParty;
using DotNetOpenAuth.Test.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
+ using System.Reflection;
+ using System.IO;
public class OpenIdTestBase : TestBase {
internal IDirectSslWebRequestHandler RequestHandler;
internal MockHttpRequest MockResponder;
- protected internal static readonly Uri ProviderUri = new Uri("http://provider");
- protected internal static readonly Uri RPUri = new Uri("http://rp");
protected const string IdentifierSelect = "http://specs.openid.net/auth/2.0/identifier_select";
+ protected internal static readonly Uri BaseMockUri = new Uri("http://localhost/");
+ protected internal static readonly Uri BaseMockUriSsl = new Uri("https://localhost/");
+
+ protected internal static readonly Uri OPUri = new Uri(BaseMockUri, "/provider/endpoint");
+ protected internal static readonly Uri OPUriSsl = new Uri(BaseMockUriSsl, "/provider/endpoint");
+ protected internal static readonly Uri[] OPLocalIdentifiers = new[] { new Uri(OPUri, "/provider/someUser0"), new Uri(OPUri, "/provider/someUser1") };
+ protected internal static readonly Uri[] OPLocalIdentifiersSsl = new[] { new Uri(OPUriSsl, "/provider/someUser0"), new Uri(OPUriSsl, "/provider/someUser1") };
+
+ // Vanity URLs are Claimed Identifiers that delegate to some OP and its local identifier.
+ protected internal static readonly Uri VanityUri = new Uri(BaseMockUri, "/userControlled/identity");
+ protected internal static readonly Uri VanityUriSsl = new Uri(BaseMockUriSsl, "/userControlled/identity");
+
+ protected internal static readonly Uri RPUri = new Uri(BaseMockUri, "/relyingparty/login");
+ protected internal static readonly Uri RPUriSsl = new Uri(BaseMockUriSsl, "/relyingparty/login");
+ protected internal static readonly Uri RPRealmUri = new Uri(BaseMockUri, "/relyingparty/");
+ protected internal static readonly Uri RPRealmUriSsl = new Uri(BaseMockUriSsl, "/relyingparty/");
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="OpenIdTestBase"/> class.
+ /// </summary>
+ internal OpenIdTestBase() {
+ this.AutoProviderScenario = Scenarios.AutoApproval;
+ }
+
protected RelyingPartySecuritySettings RelyingPartySecuritySettings { get; private set; }
protected ProviderSecuritySettings ProviderSecuritySettings { get; private set; }
@@ -37,14 +61,108 @@ namespace DotNetOpenAuth.Test.OpenId {
this.MockResponder = MockHttpRequest.CreateUntrustedMockHttpHandler();
this.RequestHandler = this.MockResponder.MockWebRequestHandler;
+ this.AutoProviderScenario = Scenarios.AutoApproval;
+ }
+
+ public enum Scenarios {
+ AutoApproval,
+ AutoApprovalAddFragment,
+ ApproveOnSetup,
+ AlwaysDeny,
+ }
+
+ internal Scenarios AutoProviderScenario { get; set; }
+
+
+ /// <summary>
+ /// Forces storage of an association in an RP's association store.
+ /// </summary>
+ /// <param name="relyingParty">The relying party.</param>
+ /// <param name="providerEndpoint">The provider endpoint.</param>
+ /// <param name="association">The association.</param>
+ internal static void StoreAssociation(OpenIdRelyingParty relyingParty, Uri providerEndpoint, Association association) {
+ var associationManagerAccessor = AssociationManager_Accessor.AttachShadow(relyingParty.AssociationManager);
+ associationManagerAccessor.associationStore.StoreAssociation(providerEndpoint, association);
+ }
+
+ /// <summary>
+ /// Returns the content of a given embedded resource.
+ /// </summary>
+ /// <param name="path">The path of the file as it appears within the project,
+ /// where the leading / marks the root directory of the project.</param>
+ /// <returns>The content of the requested resource.</returns>
+ internal static string LoadEmbeddedFile(string path) {
+ if (!path.StartsWith("/")) {
+ path = "/" + path;
+ }
+ path = "DotNetOpenAuth.Test.OpenId" + path.Replace('/', '.');
+ Stream resource = Assembly.GetExecutingAssembly().GetManifestResourceStream(path);
+ if (resource == null) {
+ throw new ArgumentException();
+ }
+ using (StreamReader sr = new StreamReader(resource)) {
+ return sr.ReadToEnd();
+ }
+ }
+
+ internal static ServiceEndpoint GetServiceEndpoint(int user, ProtocolVersion providerVersion, int servicePriority, bool useSsl) {
+ var providerEndpoint = new ProviderEndpointDescription(
+ useSsl ? OpenIdTestBase.OPUriSsl : OpenIdTestBase.OPUri,
+ new string[] { Protocol.Lookup(providerVersion).ClaimedIdentifierServiceTypeURI });
+ return ServiceEndpoint.CreateForClaimedIdentifier(
+ useSsl ? OPLocalIdentifiersSsl[user] : OPLocalIdentifiers[user],
+ useSsl ? OPLocalIdentifiersSsl[user] : OPLocalIdentifiers[user],
+ useSsl ? OPLocalIdentifiersSsl[user] : OPLocalIdentifiers[user],
+ providerEndpoint,
+ servicePriority,
+ 10);
+ }
+
+ /// <summary>
+ /// A default implementation of a simple provider that responds to authentication requests
+ /// per the scenario that is being simulated.
+ /// </summary>
+ /// <param name="provider">The OpenIdProvider on which the process messages.</param>
+ /// <remarks>
+ /// This is a very useful method to pass to the OpenIdCoordinator constructor for the Provider argument.
+ /// </remarks>
+ internal void AutoProvider(OpenIdProvider provider) {
+ IRequest request;
+ while ((request = provider.GetRequest()) != null) {
+ if (!request.IsResponseReady) {
+ var authRequest = (DotNetOpenAuth.OpenId.Provider.IAuthenticationRequest)request;
+ switch (this.AutoProviderScenario) {
+ case Scenarios.AutoApproval:
+ authRequest.IsAuthenticated = true;
+ break;
+ case Scenarios.AutoApprovalAddFragment:
+ authRequest.SetClaimedIdentifierFragment("frag");
+ authRequest.IsAuthenticated = true;
+ break;
+ case Scenarios.ApproveOnSetup:
+ authRequest.IsAuthenticated = !authRequest.Immediate;
+ break;
+ case Scenarios.AlwaysDeny:
+ authRequest.IsAuthenticated = false;
+ break;
+ default:
+ // All other scenarios are done programmatically only.
+ throw new InvalidOperationException("Unrecognized scenario");
+ }
+ }
+
+ request.Response.Send();
+ }
}
- protected Identifier GetMockIdentifier(TestSupport.Scenarios scenario, ProtocolVersion providerVersion) {
- return this.GetMockIdentifier(scenario, providerVersion, false);
+ protected Identifier GetMockIdentifier(ProtocolVersion providerVersion) {
+ return this.GetMockIdentifier(providerVersion, false);
}
- protected Identifier GetMockIdentifier(TestSupport.Scenarios scenario, ProtocolVersion providerVersion, bool useSsl) {
- return TestSupport.GetMockIdentifier(scenario, this.MockResponder, providerVersion, useSsl);
+ protected Identifier GetMockIdentifier(ProtocolVersion providerVersion, bool useSsl) {
+ ServiceEndpoint se = GetServiceEndpoint(0, providerVersion, 10, useSsl);
+ UriIdentifier identityUri = useSsl ? OpenIdTestBase.OPLocalIdentifiersSsl[0] : OpenIdTestBase.OPLocalIdentifiers[0];
+ return new MockIdentifier(identityUri, this.MockResponder, new ServiceEndpoint[] { se });
}
/// <summary>
diff --git a/src/DotNetOpenAuth.Test/OpenId/Provider/AuthenticationRequestTest.cs b/src/DotNetOpenAuth.Test/OpenId/Provider/AuthenticationRequestTest.cs
index a46f92c..078ffb4 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Provider/AuthenticationRequestTest.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Provider/AuthenticationRequestTest.cs
@@ -22,9 +22,9 @@ namespace DotNetOpenAuth.Test.OpenId.Provider {
// Construct a V1 immediate request
Protocol protocol = Protocol.V11;
OpenIdProvider provider = this.CreateProvider();
- CheckIdRequest immediateRequest = new CheckIdRequest(protocol.Version, ProviderUri, DotNetOpenAuth.OpenId.RelyingParty.AuthenticationRequestMode.Immediate);
- immediateRequest.Realm = TestSupport.Realm;
- immediateRequest.ReturnTo = TestSupport.ReturnTo;
+ CheckIdRequest immediateRequest = new CheckIdRequest(protocol.Version, OPUri, DotNetOpenAuth.OpenId.RelyingParty.AuthenticationRequestMode.Immediate);
+ immediateRequest.Realm = RPRealmUri;
+ immediateRequest.ReturnTo = RPUri;
immediateRequest.LocalIdentifier = "http://somebody";
AuthenticationRequest request = new AuthenticationRequest(provider, immediateRequest);
@@ -50,9 +50,9 @@ namespace DotNetOpenAuth.Test.OpenId.Provider {
public void IsReturnUrlDiscoverable() {
Protocol protocol = Protocol.Default;
OpenIdProvider provider = this.CreateProvider();
- CheckIdRequest checkIdRequest = new CheckIdRequest(protocol.Version, ProviderUri, DotNetOpenAuth.OpenId.RelyingParty.AuthenticationRequestMode.Setup);
- checkIdRequest.Realm = TestSupport.Realm;
- checkIdRequest.ReturnTo = TestSupport.ReturnTo;
+ CheckIdRequest checkIdRequest = new CheckIdRequest(protocol.Version, OPUri, DotNetOpenAuth.OpenId.RelyingParty.AuthenticationRequestMode.Setup);
+ checkIdRequest.Realm = RPRealmUri;
+ checkIdRequest.ReturnTo = RPUri;
AuthenticationRequest request = new AuthenticationRequest(provider, checkIdRequest);
Assert.IsFalse(request.IsReturnUrlDiscoverable);
diff --git a/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs b/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs
index d420c5e..cd807da 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs
@@ -84,7 +84,7 @@ namespace DotNetOpenAuth.Test.OpenId.Provider {
HttpRequestInfo httpInfo = new HttpRequestInfo();
httpInfo.Url = new Uri("http://someUri");
Assert.IsNull(this.provider.GetRequest(httpInfo), "An irrelevant request should return null.");
- var providerDescription = new ProviderEndpointDescription(OpenIdTestBase.ProviderUri, Protocol.Default.Version);
+ var providerDescription = new ProviderEndpointDescription(OpenIdTestBase.OPUri, Protocol.Default.Version);
// Test some non-empty request scenario.
OpenIdCoordinator coordinator = new OpenIdCoordinator(
diff --git a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/AuthenticationRequestTests.cs b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/AuthenticationRequestTests.cs
index bf897b6..e73ec13 100644
--- a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/AuthenticationRequestTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/AuthenticationRequestTests.cs
@@ -19,8 +19,8 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
[TestClass]
public class AuthenticationRequestTests : OpenIdTestBase {
- private readonly Realm realm = new Realm(TestSupport.GetFullUrl(TestSupport.ConsumerPage).AbsoluteUri);
- private readonly Uri returnTo = TestSupport.GetFullUrl(TestSupport.ConsumerPage);
+ private readonly Realm realm = new Realm("http://localhost/rp.aspx");
+ private readonly Uri returnTo = new Uri("http://localhost/rp.aspx");
private readonly Identifier claimedId = "http://claimedId";
private readonly Identifier delegatedLocalId = "http://localId";
private readonly Protocol protocol = Protocol.Default;
@@ -70,7 +70,7 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
public void CreateRequestMessage() {
OpenIdCoordinator coordinator = new OpenIdCoordinator(
rp => {
- Identifier id = this.GetMockIdentifier(TestSupport.Scenarios.AutoApproval, ProtocolVersion.V20);
+ Identifier id = this.GetMockIdentifier(ProtocolVersion.V20);
IAuthenticationRequest authRequest = rp.CreateRequest(id, this.realm, this.returnTo);
// Add some callback arguments
@@ -97,7 +97,7 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
Assert.AreEqual(1, req.Extensions.Count);
Assert.IsTrue(req.Extensions.Contains(sregRequest));
},
- TestSupport.AutoProvider);
+ AutoProvider);
coordinator.Run();
}
@@ -108,7 +108,7 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
public void Provider() {
IAuthenticationRequest_Accessor authRequest = this.CreateAuthenticationRequest(this.claimedId, this.claimedId);
Assert.IsNotNull(authRequest.Provider);
- Assert.AreEqual(ProviderUri, authRequest.Provider.Uri);
+ Assert.AreEqual(OPUri, authRequest.Provider.Uri);
Assert.AreEqual(this.protocol.Version, authRequest.Provider.Version);
}
@@ -122,7 +122,7 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
}
private AuthenticationRequest_Accessor CreateAuthenticationRequest(Identifier claimedIdentifier, Identifier providerLocalIdentifier) {
- ProviderEndpointDescription providerEndpoint = new ProviderEndpointDescription(ProviderUri, this.protocol.Version);
+ ProviderEndpointDescription providerEndpoint = new ProviderEndpointDescription(OPUri, this.protocol.Version);
ServiceEndpoint endpoint = ServiceEndpoint.CreateForClaimedIdentifier(claimedIdentifier, providerLocalIdentifier, providerEndpoint, 10, 5);
ServiceEndpoint_Accessor endpointAccessor = ServiceEndpoint_Accessor.AttachShadow(endpoint);
OpenIdRelyingParty rp = this.CreateRelyingParty();
diff --git a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/OpenIdRelyingPartyTests.cs b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/OpenIdRelyingPartyTests.cs
index edcab87..d2a75de 100644
--- a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/OpenIdRelyingPartyTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/OpenIdRelyingPartyTests.cs
@@ -25,8 +25,8 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
[TestMethod]
public void CreateRequestDumbMode() {
var rp = new OpenIdRelyingParty(null);
- Identifier id = this.GetMockIdentifier(TestSupport.Scenarios.AutoApproval, ProtocolVersion.V20);
- var authReq = rp.CreateRequest(id, TestSupport.Realm, TestSupport.ReturnTo);
+ Identifier id = this.GetMockIdentifier(ProtocolVersion.V20);
+ var authReq = rp.CreateRequest(id, RPRealmUri, RPUri);
CheckIdRequest requestMessage = (CheckIdRequest)authReq.RedirectingResponse.OriginalMessage;
Assert.IsNull(requestMessage.AssociationHandle);
}
@@ -40,18 +40,18 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
[TestMethod]
public void CreateRequest() {
var rp = this.CreateRelyingParty();
- TestSupport.StoreAssociation(rp, TestSupport.GetFullUrl("/" + TestSupport.ProviderPage), HmacShaAssociation.Create("somehandle", new byte[20], TimeSpan.FromDays(1)));
- Identifier id = Identifier.Parse(GetMockIdentifier(TestSupport.Scenarios.AutoApproval, ProtocolVersion.V20));
- var req = rp.CreateRequest(id, TestSupport.Realm, TestSupport.ReturnTo);
+ StoreAssociation(rp, OPUri, HmacShaAssociation.Create("somehandle", new byte[20], TimeSpan.FromDays(1)));
+ Identifier id = Identifier.Parse(GetMockIdentifier(ProtocolVersion.V20));
+ var req = rp.CreateRequest(id, RPRealmUri, RPUri);
Assert.IsNotNull(req);
}
[TestMethod]
public void CreateRequests() {
var rp = this.CreateRelyingParty();
- TestSupport.StoreAssociation(rp, TestSupport.GetFullUrl("/" + TestSupport.ProviderPage), HmacShaAssociation.Create("somehandle", new byte[20], TimeSpan.FromDays(1)));
- Identifier id = Identifier.Parse(GetMockIdentifier(TestSupport.Scenarios.AutoApproval, ProtocolVersion.V20));
- var requests = rp.CreateRequests(id, TestSupport.Realm, TestSupport.ReturnTo);
+ StoreAssociation(rp, OPUri, HmacShaAssociation.Create("somehandle", new byte[20], TimeSpan.FromDays(1)));
+ Identifier id = Identifier.Parse(GetMockIdentifier(ProtocolVersion.V20));
+ var requests = rp.CreateRequests(id, RPRealmUri, RPUri);
Assert.AreEqual(1, requests.Count());
}
@@ -60,7 +60,7 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
Uri nonOpenId = new Uri("http://www.microsoft.com/");
var rp = this.CreateRelyingParty();
this.MockResponder.RegisterMockResponse(nonOpenId, "text/html", "<html/>");
- rp.CreateRequest(nonOpenId, TestSupport.Realm, TestSupport.ReturnTo);
+ rp.CreateRequest(nonOpenId, RPRealmUri, RPUri);
}
[TestMethod]
@@ -68,7 +68,7 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
Uri nonOpenId = new Uri("http://www.microsoft.com/");
var rp = this.CreateRelyingParty();
this.MockResponder.RegisterMockResponse(nonOpenId, "text/html", "<html/>");
- var requests = rp.CreateRequests(nonOpenId, TestSupport.Realm, TestSupport.ReturnTo);
+ var requests = rp.CreateRequests(nonOpenId, RPRealmUri, RPUri);
Assert.AreEqual(0, requests.Count());
}
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/PositiveAuthenticationResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/PositiveAuthenticationResponseTests.cs
index b3812ce..48473e0 100644
--- a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/PositiveAuthenticationResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/PositiveAuthenticationResponseTests.cs
@@ -15,8 +15,8 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
[TestClass]
public class PositiveAuthenticationResponseTests : OpenIdTestBase {
- private readonly Realm realm = new Realm(TestSupport.GetFullUrl(TestSupport.ConsumerPage).AbsoluteUri);
- private readonly Uri returnTo = TestSupport.GetFullUrl(TestSupport.ConsumerPage);
+ private readonly Realm realm = new Realm("http://localhost/rp.aspx");
+ private readonly Uri returnTo = new Uri("http://localhost/rp.aspx");
[TestInitialize]
public override void SetUp() {
@@ -61,10 +61,10 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
private PositiveAssertionResponse GetPositiveAssertion() {
Protocol protocol = Protocol.Default;
PositiveAssertionResponse assertion = new PositiveAssertionResponse(protocol.Version, this.returnTo);
- assertion.ClaimedIdentifier = TestSupport.GetMockIdentifier(TestSupport.Scenarios.AutoApproval, this.MockResponder, protocol.ProtocolVersion);
- assertion.LocalIdentifier = TestSupport.GetDelegateUrl(TestSupport.Scenarios.AutoApproval);
+ assertion.ClaimedIdentifier = this.GetMockIdentifier(protocol.ProtocolVersion, false);
+ assertion.LocalIdentifier = OPLocalIdentifiers[0];
assertion.ReturnTo = this.returnTo;
- assertion.ProviderEndpoint = TestSupport.GetFullUrl("/" + TestSupport.ProviderPage, null, false);
+ assertion.ProviderEndpoint = OPUri;
return assertion;
}
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/ServiceEndpointTests.cs b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/ServiceEndpointTests.cs
index c62549d..7b71eef 100644
--- a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/ServiceEndpointTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/ServiceEndpointTests.cs
@@ -205,7 +205,7 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
Assert.IsFalse(se.IsExtensionSupported("http://someextension/typeuri"));
ProviderEndpointDescription ped = new ProviderEndpointDescription(
- ProviderUri,
+ OPUri,
new[] { Protocol.V20.ClaimedIdentifierServiceTypeURI, "http://someextension", Constants.sreg_ns });
se = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedXri, this.userSuppliedXri, this.localId, ped, this.servicePriority, this.uriPriority);
Assert.IsTrue(se.IsExtensionSupported<ClaimsRequest>());
diff --git a/src/DotNetOpenAuth.Test/OpenId/TestSupport.cs b/src/DotNetOpenAuth.Test/OpenId/TestSupport.cs
deleted file mode 100644
index 5223c12..0000000
--- a/src/DotNetOpenAuth.Test/OpenId/TestSupport.cs
+++ /dev/null
@@ -1,440 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="TestSupport.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.Test.OpenId {
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Reflection;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OpenId;
- using DotNetOpenAuth.OpenId.Provider;
- using DotNetOpenAuth.OpenId.RelyingParty;
- using DotNetOpenAuth.Test.Mocks;
- ////using DotNetOpenAuth.Test.UI;
- using log4net;
-
- public class TestSupport {
- public const string HostTestPage = "HostTest.aspx";
-
- public const string ProviderPage = "ProviderEndpoint.aspx";
-
- public const string DirectedProviderEndpoint = "DirectedProviderEndpoint.aspx";
-
- public const string MobileConsumerPage = "RelyingPartyMobile.aspx";
-
- public const string ConsumerPage = "RelyingParty.aspx";
-
- public const string OPDefaultPage = "OPDefault.aspx";
-
- public static readonly ILog Logger = LogManager.GetLogger("DotNetOpenId.Test");
-
- public static readonly string TestWebDirectory = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\..\src\DotNetOpenAuth.TestWeb"));
-
- private const string IdentityPage = "IdentityEndpoint.aspx";
-
- private const string DirectedIdentityPage = "DirectedIdentityEndpoint.aspx";
-
- public enum Scenarios {
- // Authentication test scenarios
- AutoApproval,
-
- AutoApprovalAddFragment,
-
- ApproveOnSetup,
-
- AlwaysDeny,
-
- /* Extension test scenarios */
-
- /// <summary>
- /// Provides all required and requested fields.
- /// </summary>
- ExtensionFullCooperation,
-
- /// <summary>
- /// Provides only those fields marked as required.
- /// </summary>
- ExtensionPartialCooperation,
- }
-
- public static Uri ReturnTo {
- get { return TestSupport.GetFullUrl(TestSupport.ConsumerPage); }
- }
-
- public static Realm Realm {
- get { return new Realm(TestSupport.GetFullUrl(TestSupport.ConsumerPage).AbsoluteUri); }
- }
-
- public static Identifier GetDelegateUrl(Scenarios scenario) {
- return GetDelegateUrl(scenario, false);
- }
-
- public static Identifier GetDelegateUrl(Scenarios scenario, bool useSsl) {
- return new UriIdentifier(GetFullUrl("/" + scenario, null, useSsl));
- }
-
- public static Uri GetFullUrl(string url) {
- return GetFullUrl(url, null, false);
- }
-
- public static Uri GetFullUrl(string url, string key, object value) {
- var dictionary = new Dictionary<string, string> {
- { key, value.ToString() },
- };
- return GetFullUrl(url, dictionary, false);
- }
-
- public static Uri GetFullUrl(string url, IDictionary<string, string> args, bool useSsl) {
- Uri defaultUriBase = new Uri(useSsl ? "https://localhost/" : "http://localhost/");
- Uri baseUri =/* UITestSupport.Host != null ? UITestSupport.Host.BaseUri : */defaultUriBase;
- UriBuilder builder = new UriBuilder(new Uri(baseUri, url));
- MessagingUtilities.AppendQueryArgs(builder, args);
- return builder.Uri;
- }
-
- /// <summary>
- /// Returns the content of a given embedded resource.
- /// </summary>
- /// <param name="path">The path of the file as it appears within the project,
- /// where the leading / marks the root directory of the project.</param>
- /// <returns>The content of the requested resource.</returns>
- internal static string LoadEmbeddedFile(string path) {
- if (!path.StartsWith("/")) {
- path = "/" + path;
- }
- path = "DotNetOpenAuth.Test.OpenId" + path.Replace('/', '.');
- Stream resource = Assembly.GetExecutingAssembly().GetManifestResourceStream(path);
- if (resource == null) {
- throw new ArgumentException();
- }
- using (StreamReader sr = new StreamReader(resource)) {
- return sr.ReadToEnd();
- }
- }
-
- ////internal static UriIdentifier GetOPIdentityUrl(Scenarios scenario, bool useSsl) {
- //// var args = new Dictionary<string, string> {
- //// { "user", scenario.ToString() },
- ////};
- //// return new UriIdentifier(GetFullUrl("/" + OPDefaultPage, args, useSsl));
- ////}
- internal static UriIdentifier GetIdentityUrl(Scenarios scenario, ProtocolVersion providerVersion) {
- return GetIdentityUrl(scenario, providerVersion, false);
- }
-
- internal static UriIdentifier GetIdentityUrl(Scenarios scenario, ProtocolVersion providerVersion, bool useSsl) {
- var dictionary = new Dictionary<string, string> {
- { "user", scenario.ToString() },
- { "version", providerVersion.ToString() },
- };
- return new UriIdentifier(GetFullUrl("/" + IdentityPage, dictionary, useSsl));
- }
-
- internal static MockIdentifier GetMockIdentifier(Scenarios scenario, MockHttpRequest mockRequest, ProtocolVersion providerVersion) {
- return GetMockIdentifier(scenario, mockRequest, providerVersion, false);
- }
-
- internal static MockIdentifier GetMockIdentifier(Scenarios scenario, MockHttpRequest mockRequest, ProtocolVersion providerVersion, bool useSsl) {
- ServiceEndpoint se = GetServiceEndpoint(scenario, providerVersion, 10, useSsl);
- return new MockIdentifier(GetIdentityUrl(scenario, providerVersion, useSsl), mockRequest, new ServiceEndpoint[] { se });
- }
-
- internal static ServiceEndpoint GetServiceEndpoint(Scenarios scenario, ProtocolVersion providerVersion, int servicePriority, bool useSsl) {
- var providerEndpoint = new ProviderEndpointDescription(GetFullUrl("/" + ProviderPage, null, useSsl), new string[] { Protocol.Lookup(providerVersion).ClaimedIdentifierServiceTypeURI });
- return ServiceEndpoint.CreateForClaimedIdentifier(
- GetIdentityUrl(scenario, providerVersion, useSsl),
- GetIdentityUrl(scenario, providerVersion, useSsl),
- GetDelegateUrl(scenario, useSsl),
- providerEndpoint,
- servicePriority,
- 10);
- }
-
- /// <summary>
- /// A default implementation of a simple provider that responds to authentication requests
- /// per the scenario that is being simulated.
- /// </summary>
- /// <param name="provider">The OpenIdProvider on which the process messages.</param>
- /// <remarks>
- /// This is a very useful method to pass to the OpenIdCoordinator constructor for the Provider argument.
- /// </remarks>
- internal static void AutoProvider(OpenIdProvider provider) {
- IRequest request;
- while ((request = provider.GetRequest()) != null) {
- if (!request.IsResponseReady) {
- var authRequest = (DotNetOpenAuth.OpenId.Provider.IAuthenticationRequest)request;
- var scenario = (Scenarios)Enum.Parse(typeof(Scenarios), new Uri(authRequest.LocalIdentifier).AbsolutePath.TrimStart('/'));
- switch (scenario) {
- case TestSupport.Scenarios.AutoApproval:
- authRequest.IsAuthenticated = true;
- break;
- case Scenarios.AutoApprovalAddFragment:
- authRequest.SetClaimedIdentifierFragment("frag");
- authRequest.IsAuthenticated = true;
- break;
- case TestSupport.Scenarios.ApproveOnSetup:
- authRequest.IsAuthenticated = !authRequest.Immediate;
- break;
- case Scenarios.AlwaysDeny:
- authRequest.IsAuthenticated = false;
- break;
- default:
- // All other scenarios are done programmatically only.
- throw new InvalidOperationException("Unrecognized scenario");
- }
- }
-
- request.Response.Send();
- }
- }
-
- /// <summary>
- /// Forces storage of an association in an RP's association store.
- /// </summary>
- /// <param name="relyingParty">The relying party.</param>
- /// <param name="providerEndpoint">The provider endpoint.</param>
- /// <param name="association">The association.</param>
- internal static void StoreAssociation(OpenIdRelyingParty relyingParty, Uri providerEndpoint, Association association) {
- var associationManagerAccessor = AssociationManager_Accessor.AttachShadow(relyingParty.AssociationManager);
- associationManagerAccessor.associationStore.StoreAssociation(providerEndpoint, association);
- }
-
- ////internal static UriIdentifier GetDirectedIdentityUrl(Scenarios scenario, ProtocolVersion providerVersion) {
- //// return GetDirectedIdentityUrl(scenario, providerVersion, false);
- ////}
-
- ////internal static UriIdentifier GetDirectedIdentityUrl(Scenarios scenario, ProtocolVersion providerVersion, bool useSsl) {
- //// return new UriIdentifier(GetFullUrl("/" + DirectedIdentityPage, new Dictionary<string, string> {
- //// { "user", scenario.ToString() },
- //// { "version", providerVersion.ToString() },
- //// }, useSsl));
- ////}
-
- ////internal static IRelyingPartyApplicationStore RelyingPartyStore;
- ////internal static IProviderAssociationStore ProviderStore;
- /////// <summary>
- /////// Generates a new, stateful <see cref="OpenIdRelyingParty"/> whose direct messages
- /////// will be automatically handled by an internal <see cref="OpenIdProvider"/>
- /////// that uses the shared <see cref="ProviderStore"/>.
- /////// </summary>
- ////internal static OpenIdRelyingParty CreateRelyingParty(NameValueCollection fields) {
- //// return CreateRelyingParty(RelyingPartyStore, null, fields);
- ////}
- ////internal static OpenIdRelyingParty CreateRelyingParty(IRelyingPartyApplicationStore store, NameValueCollection fields) {
- //// return CreateRelyingParty(store, null, fields);
- ////}
- /////// <summary>
- /////// Generates a new <see cref="OpenIdRelyingParty"/> whose direct messages
- /////// will be automatically handled by an internal <see cref="OpenIdProvider"/>
- /////// that uses the shared <see cref="ProviderStore"/>.
- /////// </summary>
- ////internal static OpenIdRelyingParty CreateRelyingParty(IRelyingPartyApplicationStore store, Uri requestUrl, NameValueCollection fields) {
- //// var rp = new OpenIdRelyingParty(store, requestUrl ?? GetFullUrl(ConsumerPage), fields ?? new NameValueCollection());
- //// if (fields == null || fields.Count == 0) {
- //// Assert.IsNull(rp.Response);
- //// }
- //// rp.DirectMessageChannel = new DirectMessageTestRedirector(ProviderStore);
- //// return rp;
- ////}
- ////internal static DotNetOpenId.RelyingParty.IAuthenticationRequest CreateRelyingPartyRequest(bool stateless, Scenarios scenario, ProtocolVersion version, bool useSsl) {
- //// // Publish RP discovery information
- //// MockHttpRequest.RegisterMockRPDiscovery();
-
- //// var rp = TestSupport.CreateRelyingParty(stateless ? null : RelyingPartyStore, null);
- //// var rpReq = rp.CreateRequest(TestSupport.GetMockIdentifier(scenario, version, useSsl), Realm, ReturnTo);
-
- //// // Sidetrack: verify URLs and other default properties
- //// {
- //// Assert.AreEqual(AuthenticationRequestMode.Setup, rpReq.Mode);
- //// Assert.AreEqual(Realm, rpReq.Realm);
- //// Assert.AreEqual(ReturnTo, rpReq.ReturnToUrl);
- //// }
-
- //// return rpReq;
- ////}
- /////// <summary>
- /////// Generates a new <see cref="OpenIdRelyingParty"/> ready to process a
- /////// response from an <see cref="OpenIdProvider"/>.
- /////// </summary>
- ////internal static IAuthenticationResponse CreateRelyingPartyResponse(IRelyingPartyApplicationStore store, IResponse providerResponse) {
- //// return CreateRelyingPartyResponse(store, providerResponse, false);
- ////}
- ////internal static IAuthenticationResponse CreateRelyingPartyResponse(IRelyingPartyApplicationStore store, IResponse providerResponse, bool requireSsl) {
- //// if (providerResponse == null) throw new ArgumentNullException("providerResponse");
-
- //// var opAuthWebResponse = (Response)providerResponse;
- //// var opAuthResponse = (EncodableResponse)opAuthWebResponse.EncodableMessage;
- //// var rp = CreateRelyingParty(store, opAuthResponse.RedirectUrl,
- //// opAuthResponse.EncodedFields.ToNameValueCollection());
- //// rp.Settings.RequireSsl = requireSsl;
- //// // Get the response now, before trying the replay attack. The Response
- //// // property is lazily-evaluated, so the replay attack can be evaluated first
- //// // and pass, while this one that SUPPOSED to pass fails, if we don't force it now.
- //// var response = rp.Response;
-
- //// // Side-track to test for replay attack while we're at it.
- //// // This simulates a network sniffing user who caught the
- //// // authenticating query en route to either the user agent or
- //// // the consumer, and tries the same query to the consumer in an
- //// // attempt to spoof the identity of the authenticating user.
- //// try {
- //// Logger.Info("Attempting replay attack...");
- //// var replayRP = CreateRelyingParty(store, opAuthResponse.RedirectUrl,
- //// opAuthResponse.EncodedFields.ToNameValueCollection());
- //// replayRP.Settings.RequireSsl = requireSsl;
- //// Assert.AreNotEqual(AuthenticationStatus.Authenticated, replayRP.Response.Status, "Replay attack succeeded!");
- //// } catch (OpenIdException) { // nonce already used
- //// // another way to pass
- //// }
-
- //// // Return the result of the initial response (not the replay attack one).
- //// return response;
- ////}
- /////// <summary>
- /////// Generates a new <see cref="OpenIdProvider"/> that uses the shared
- /////// store in <see cref="ProviderStore"/>.
- /////// </summary>
- ////internal static OpenIdProvider CreateProvider(NameValueCollection fields) {
- //// return CreateProvider(fields, false);
- ////}
- ////internal static OpenIdProvider CreateProvider(NameValueCollection fields, bool useSsl) {
- //// Protocol protocol = fields != null ? Protocol.Detect(fields.ToDictionary()) : Protocol.V20;
- //// Uri opEndpoint = GetFullUrl(ProviderPage, null, useSsl);
- //// var provider = new OpenIdProvider(ProviderStore, opEndpoint, opEndpoint, fields ?? new NameValueCollection());
- //// return provider;
- ////}
- ////internal static OpenIdProvider CreateProviderForRequest(DotNetOpenId.RelyingParty.IAuthenticationRequest request) {
- //// IResponse relyingPartyAuthenticationRequest = request.RedirectingResponse;
- //// var rpWebMessageToOP = (Response)relyingPartyAuthenticationRequest;
- //// var rpMessageToOP = (IndirectMessageRequest)rpWebMessageToOP.EncodableMessage;
- //// var opEndpoint = (ServiceEndpoint)request.Provider;
- //// var provider = new OpenIdProvider(ProviderStore, opEndpoint.ProviderEndpoint,
- //// opEndpoint.ProviderEndpoint, rpMessageToOP.EncodedFields.ToNameValueCollection());
- //// return provider;
- ////}
- ////internal static IResponse CreateProviderResponseToRequest(
- //// DotNetOpenId.RelyingParty.IAuthenticationRequest request,
- //// Action<DotNetOpenId.Provider.IAuthenticationRequest> prepareProviderResponse) {
- //// {
- //// // Sidetrack: Verify the return_to and realm URLs
- //// var consumerToProviderQuery = HttpUtility.ParseQueryString(request.RedirectingResponse.ExtractUrl().Query);
- //// Protocol protocol = Protocol.Detect(consumerToProviderQuery.ToDictionary());
- //// Assert.IsTrue(consumerToProviderQuery[protocol.openid.return_to].StartsWith(request.ReturnToUrl.AbsoluteUri, StringComparison.Ordinal));
- //// Assert.AreEqual(request.Realm.ToString(), consumerToProviderQuery[protocol.openid.Realm]);
- //// }
-
- //// var op = TestSupport.CreateProviderForRequest(request);
- //// var opReq = (DotNetOpenId.Provider.IAuthenticationRequest)op.Request;
- //// prepareProviderResponse(opReq);
- //// Assert.IsTrue(opReq.IsResponseReady);
- //// return opReq.Response;
- ////}
- ////internal static IAuthenticationResponse CreateRelyingPartyResponseThroughProvider(
- //// DotNetOpenId.RelyingParty.IAuthenticationRequest request,
- //// Action<DotNetOpenId.Provider.IAuthenticationRequest> providerAction) {
- //// var rpReq = (AuthenticationRequest)request;
- //// var opResponse = CreateProviderResponseToRequest(rpReq, providerAction);
- //// // Be careful to use whatever store the original RP was using.
- //// var rp = CreateRelyingPartyResponse(rpReq.RelyingParty.Store, opResponse,
- //// ((AuthenticationRequest)request).RelyingParty.Settings.RequireSsl);
- //// Assert.IsNotNull(rp);
- //// return rp;
- ////}
-
- ////[SetUp]
- ////public void SetUp() {
- //// log4net.Config.XmlConfigurator.Configure(Assembly.GetExecutingAssembly().GetManifestResourceStream("DotNetOpenId.Test.Logging.config"));
-
- //// ResetStores();
- ////}
-
- ////[TearDown]
- ////public void TearDown() {
- //// log4net.LogManager.Shutdown();
- ////}
-
- ////internal static void ResetStores() {
- //// RelyingPartyStore = new ApplicationMemoryStore();
- //// ProviderStore = new ProviderMemoryStore();
- ////}
-
- ////internal static void SetAuthenticationFromScenario(Scenarios scenario, DotNetOpenId.Provider.IAuthenticationRequest request) {
- //// Assert.IsTrue(request.IsReturnUrlDiscoverable);
- //// switch (scenario) {
- //// case TestSupport.Scenarios.ExtensionFullCooperation:
- //// case TestSupport.Scenarios.ExtensionPartialCooperation:
- //// case TestSupport.Scenarios.AutoApproval:
- //// // immediately approve
- //// request.IsAuthenticated = true;
- //// break;
- //// case TestSupport.Scenarios.AutoApprovalAddFragment:
- //// request.SetClaimedIdentifierFragment("frag");
- //// request.IsAuthenticated = true;
- //// break;
- //// case TestSupport.Scenarios.ApproveOnSetup:
- //// request.IsAuthenticated = !request.Immediate;
- //// break;
- //// case TestSupport.Scenarios.AlwaysDeny:
- //// request.IsAuthenticated = false;
- //// break;
- //// default:
- //// throw new InvalidOperationException("Unrecognized scenario");
- //// }
- ////}
-
- /////// <summary>
- /////// Uses an RPs stored association to resign an altered message from a Provider,
- /////// to simulate a Provider that deliberately sent a bad message in an attempt
- /////// to thwart RP security.
- /////// </summary>
- ////internal static void Resign(NameValueCollection nvc, IRelyingPartyApplicationStore store) {
- //// Debug.Assert(nvc != null);
- //// Debug.Assert(store != null);
- //// var dict = Util.NameValueCollectionToDictionary(nvc);
- //// Protocol protocol = Protocol.Detect(dict);
- //// Uri providerEndpoint = new Uri(nvc[protocol.openid.op_endpoint]);
- //// string assoc_handle = nvc[protocol.openid.assoc_handle];
- //// Association assoc = store.GetAssociation(providerEndpoint, assoc_handle);
- //// Debug.Assert(assoc != null, "Association not found in RP's store. Maybe you're communicating with a hosted OP instead of the TestSupport one?");
- //// IList<string> signed = nvc[protocol.openid.signed].Split(',');
- //// var subsetDictionary = new Dictionary<string, string>();
- //// foreach (string signedKey in signed) {
- //// string keyName = protocol.openid.Prefix + signedKey;
- //// subsetDictionary.Add(signedKey, dict[keyName]);
- //// }
- //// nvc[protocol.openid.sig] = Convert.ToBase64String(assoc.Sign(subsetDictionary, signed));
- ////}
-
- ////public static IAssociationStore<AssociationRelyingPartyType> ProviderStoreContext {
- //// get {
- //// return DotNetOpenId.Provider.OpenIdProvider.HttpApplicationStore;
- //// }
- ////}
- ////internal static MockIdentifier GetMockOPIdentifier(Scenarios scenario, UriIdentifier expectedClaimedId) {
- //// return GetMockOPIdentifier(scenario, expectedClaimedId, false, false);
- ////}
- ////internal static MockIdentifier GetMockOPIdentifier(Scenarios scenario, UriIdentifier expectedClaimedId, bool useSslOpIdentifier, bool useSslProviderEndpoint) {
- //// var fields = new Dictionary<string, string> {
- //// { "user", scenario.ToString() },
- ////};
- //// Uri opEndpoint = GetFullUrl(DirectedProviderEndpoint, fields, useSslProviderEndpoint);
- //// Uri opIdentifier = GetOPIdentityUrl(scenario, useSslOpIdentifier);
- //// ServiceEndpoint se = ServiceEndpoint.CreateForProviderIdentifier(
- //// opIdentifier,
- //// opEndpoint,
- //// new string[] { Protocol.V20.OPIdentifierServiceTypeURI },
- //// 10,
- //// 10);
-
- //// // Register the Claimed Identifier that directed identity will choose so that RP
- //// // discovery on that identifier can be mocked up.
- //// MockHttpRequest.RegisterMockXrdsResponse(expectedClaimedId, se);
-
- //// return new MockIdentifier(opIdentifier, new ServiceEndpoint[] { se });
- ////}
- }
-} \ No newline at end of file
diff --git a/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs b/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs
index d3cccc7..cf904c0 100644
--- a/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs
@@ -161,15 +161,15 @@ namespace DotNetOpenAuth.Test.OpenId {
[TestMethod]
public void XrdsDiscoveryFromHead() {
- this.MockResponder.RegisterMockResponse(new Uri("http://localhost/xrds1020.xml"), "application/xrds+xml", TestSupport.LoadEmbeddedFile("/Discovery/xrdsdiscovery/xrds1020.xml"));
+ this.MockResponder.RegisterMockResponse(new Uri("http://localhost/xrds1020.xml"), "application/xrds+xml", LoadEmbeddedFile("/Discovery/xrdsdiscovery/xrds1020.xml"));
this.DiscoverXrds("XrdsReferencedInHead.html", ProtocolVersion.V10, null);
}
[TestMethod]
public void XrdsDiscoveryFromHttpHeader() {
WebHeaderCollection headers = new WebHeaderCollection();
- headers.Add("X-XRDS-Location", TestSupport.GetFullUrl("http://localhost/xrds1020.xml").AbsoluteUri);
- this.MockResponder.RegisterMockResponse(new Uri("http://localhost/xrds1020.xml"), "application/xrds+xml", TestSupport.LoadEmbeddedFile("/Discovery/xrdsdiscovery/xrds1020.xml"));
+ headers.Add("X-XRDS-Location", new Uri("http://localhost/xrds1020.xml").AbsoluteUri);
+ this.MockResponder.RegisterMockResponse(new Uri("http://localhost/xrds1020.xml"), "application/xrds+xml", LoadEmbeddedFile("/Discovery/xrdsdiscovery/xrds1020.xml"));
this.DiscoverXrds("XrdsReferencedInHttpHeader.html", ProtocolVersion.V10, null, headers);
}
@@ -214,11 +214,11 @@ namespace DotNetOpenAuth.Test.OpenId {
[TestMethod]
public void DiscoveryWithRedirects() {
- Identifier claimedId = TestSupport.GetMockIdentifier(TestSupport.Scenarios.AutoApproval, this.MockResponder, ProtocolVersion.V20);
+ Identifier claimedId = this.GetMockIdentifier(ProtocolVersion.V20, false);
// Add a couple of chained redirect pages that lead to the claimedId.
- Uri userSuppliedUri = TestSupport.GetFullUrl("/someSecurePage", null, true);
- Uri insecureMidpointUri = TestSupport.GetFullUrl("/insecureStop");
+ Uri userSuppliedUri = new Uri("https://localhost/someSecurePage");
+ Uri insecureMidpointUri = new Uri("http://localhost/insecureStop");
this.MockResponder.RegisterMockRedirect(userSuppliedUri, insecureMidpointUri);
this.MockResponder.RegisterMockRedirect(insecureMidpointUri, new Uri(claimedId.ToString()));
@@ -259,12 +259,12 @@ namespace DotNetOpenAuth.Test.OpenId {
[TestMethod]
public void DiscoverRequireSslWithSecureRedirects() {
- Identifier claimedId = TestSupport.GetMockIdentifier(TestSupport.Scenarios.AutoApproval, this.MockResponder, ProtocolVersion.V20, true);
+ Identifier claimedId = this.GetMockIdentifier(ProtocolVersion.V20, true);
// Add a couple of chained redirect pages that lead to the claimedId.
// All redirects should be secure.
- Uri userSuppliedUri = TestSupport.GetFullUrl("/someSecurePage", null, true);
- Uri secureMidpointUri = TestSupport.GetFullUrl("/secureStop", null, true);
+ Uri userSuppliedUri = new Uri("https://localhost/someSecurePage");
+ Uri secureMidpointUri = new Uri("https://localhost/secureStop");
this.MockResponder.RegisterMockRedirect(userSuppliedUri, secureMidpointUri);
this.MockResponder.RegisterMockRedirect(secureMidpointUri, new Uri(claimedId.ToString()));
@@ -274,13 +274,13 @@ namespace DotNetOpenAuth.Test.OpenId {
[TestMethod, ExpectedException(typeof(ProtocolException))]
public void DiscoverRequireSslWithInsecureRedirect() {
- Identifier claimedId = TestSupport.GetMockIdentifier(TestSupport.Scenarios.AutoApproval, this.MockResponder, ProtocolVersion.V20, true);
+ Identifier claimedId = this.GetMockIdentifier(ProtocolVersion.V20, true);
// Add a couple of chained redirect pages that lead to the claimedId.
// Include an insecure HTTP jump in those redirects to verify that
// the ultimate endpoint is never found as a result of high security profile.
- Uri userSuppliedUri = TestSupport.GetFullUrl("/someSecurePage", null, true);
- Uri insecureMidpointUri = TestSupport.GetFullUrl("/insecureStop");
+ Uri userSuppliedUri = new Uri("https://localhost/someSecurePage");
+ Uri insecureMidpointUri = new Uri("http://localhost/insecureStop");
this.MockResponder.RegisterMockRedirect(userSuppliedUri, insecureMidpointUri);
this.MockResponder.RegisterMockRedirect(insecureMidpointUri, new Uri(claimedId.ToString()));
@@ -290,8 +290,8 @@ namespace DotNetOpenAuth.Test.OpenId {
[TestMethod]
public void DiscoveryRequireSslWithInsecureXrdsInSecureHtmlHead() {
- var insecureXrdsSource = TestSupport.GetMockIdentifier(TestSupport.Scenarios.AutoApproval, this.MockResponder, ProtocolVersion.V20, false);
- Uri secureClaimedUri = TestSupport.GetFullUrl("/secureId", null, true);
+ var insecureXrdsSource = this.GetMockIdentifier(ProtocolVersion.V20, false);
+ Uri secureClaimedUri = new Uri("https://localhost/secureId");
string html = string.Format("<html><head><meta http-equiv='X-XRDS-Location' content='{0}'/></head><body></body></html>", insecureXrdsSource);
this.MockResponder.RegisterMockResponse(secureClaimedUri, "text/html", html);
@@ -302,25 +302,21 @@ namespace DotNetOpenAuth.Test.OpenId {
[TestMethod]
public void DiscoveryRequireSslWithInsecureXrdsInSecureHttpHeader() {
- var insecureXrdsSource = TestSupport.GetMockIdentifier(TestSupport.Scenarios.AutoApproval, this.MockResponder, ProtocolVersion.V20, false);
- Uri secureClaimedUri = TestSupport.GetFullUrl("/secureId", null, true);
+ var insecureXrdsSource = this.GetMockIdentifier(ProtocolVersion.V20, false);
string html = "<html><head></head><body></body></html>";
WebHeaderCollection headers = new WebHeaderCollection {
{ "X-XRDS-Location", insecureXrdsSource }
};
- this.MockResponder.RegisterMockResponse(secureClaimedUri, secureClaimedUri, "text/html", headers, html);
+ this.MockResponder.RegisterMockResponse(VanityUriSsl, VanityUriSsl, "text/html", headers, html);
- Identifier userSuppliedIdentifier = new UriIdentifier(secureClaimedUri, true);
+ Identifier userSuppliedIdentifier = new UriIdentifier(VanityUriSsl, true);
Assert.AreEqual(0, userSuppliedIdentifier.Discover(this.RequestHandler).Count());
}
[TestMethod]
public void DiscoveryRequireSslWithInsecureXrdsButSecureLinkTags() {
- var insecureXrdsSource = TestSupport.GetMockIdentifier(TestSupport.Scenarios.AutoApproval, this.MockResponder, ProtocolVersion.V20, false);
- Uri secureClaimedUri = TestSupport.GetFullUrl("/secureId", null, true);
-
- Identifier localIdForLinkTag = TestSupport.GetDelegateUrl(TestSupport.Scenarios.AlwaysDeny, true);
+ var insecureXrdsSource = this.GetMockIdentifier(ProtocolVersion.V20, false);
string html = string.Format(
@"
<html><head>
@@ -329,19 +325,22 @@ namespace DotNetOpenAuth.Test.OpenId {
<link rel='openid2.local_id' href='{2}' />
</head><body></body></html>",
HttpUtility.HtmlEncode(insecureXrdsSource),
- HttpUtility.HtmlEncode(TestSupport.GetFullUrl("/" + TestSupport.ProviderPage, null, true).AbsoluteUri),
- HttpUtility.HtmlEncode(localIdForLinkTag.ToString()));
- this.MockResponder.RegisterMockResponse(secureClaimedUri, "text/html", html);
+ HttpUtility.HtmlEncode(OPUriSsl.AbsoluteUri),
+ HttpUtility.HtmlEncode(OPLocalIdentifiersSsl[1].AbsoluteUri));
+ this.MockResponder.RegisterMockResponse(VanityUriSsl, "text/html", html);
- Identifier userSuppliedIdentifier = new UriIdentifier(secureClaimedUri, true);
- Assert.AreEqual(localIdForLinkTag, userSuppliedIdentifier.Discover(this.RequestHandler).Single().ProviderLocalIdentifier);
+ Identifier userSuppliedIdentifier = new UriIdentifier(VanityUriSsl, true);
+
+ // We verify that the XRDS was ignored and the LINK tags were used
+ // because the XRDS OP-LocalIdentifier uses different local identifiers.
+ Assert.AreEqual(OPLocalIdentifiersSsl[1], userSuppliedIdentifier.Discover(this.RequestHandler).Single().ProviderLocalIdentifier);
}
[TestMethod]
public void DiscoveryRequiresSslIgnoresInsecureEndpointsInXrds() {
- var insecureEndpoint = TestSupport.GetServiceEndpoint(TestSupport.Scenarios.AutoApproval, ProtocolVersion.V20, 10, false);
- var secureEndpoint = TestSupport.GetServiceEndpoint(TestSupport.Scenarios.ApproveOnSetup, ProtocolVersion.V20, 20, true);
- UriIdentifier secureClaimedId = new UriIdentifier(TestSupport.GetFullUrl("/claimedId", null, true), true);
+ var insecureEndpoint = GetServiceEndpoint(0, ProtocolVersion.V20, 10, false);
+ var secureEndpoint = GetServiceEndpoint(1, ProtocolVersion.V20, 20, true);
+ UriIdentifier secureClaimedId = new UriIdentifier(VanityUriSsl, true);
this.MockResponder.RegisterMockXrdsResponse(secureClaimedId, new ServiceEndpoint[] { insecureEndpoint, secureEndpoint });
Assert.AreEqual(secureEndpoint.ProviderLocalIdentifier, secureClaimedId.Discover(this.RequestHandler).Single().ProviderLocalIdentifier);
}
@@ -352,8 +351,9 @@ namespace DotNetOpenAuth.Test.OpenId {
private void Discover(string url, ProtocolVersion version, Identifier expectedLocalId, bool expectSreg, bool useRedirect, WebHeaderCollection headers) {
Protocol protocol = Protocol.Lookup(version);
- UriIdentifier claimedId = TestSupport.GetFullUrl(url);
- UriIdentifier userSuppliedIdentifier = TestSupport.GetFullUrl(
+ Uri baseUrl = new Uri("http://localhost/");
+ UriIdentifier claimedId = new Uri(baseUrl, url);
+ UriIdentifier userSuppliedIdentifier = new Uri(baseUrl,
"Discovery/htmldiscovery/redirect.aspx?target=" + url);
if (expectedLocalId == null) {
expectedLocalId = claimedId;
@@ -368,7 +368,7 @@ namespace DotNetOpenAuth.Test.OpenId {
} else {
throw new InvalidOperationException();
}
- this.MockResponder.RegisterMockResponse(new Uri(idToDiscover), claimedId, contentType, headers ?? new WebHeaderCollection(), TestSupport.LoadEmbeddedFile(url));
+ this.MockResponder.RegisterMockResponse(new Uri(idToDiscover), claimedId, contentType, headers ?? new WebHeaderCollection(), LoadEmbeddedFile(url));
ServiceEndpoint se = idToDiscover.Discover(this.RequestHandler).FirstOrDefault();
Assert.IsNotNull(se, url + " failed to be discovered.");
@@ -405,9 +405,9 @@ namespace DotNetOpenAuth.Test.OpenId {
}
private void FailDiscover(string url) {
- UriIdentifier userSuppliedId = TestSupport.GetFullUrl(url);
+ UriIdentifier userSuppliedId = new Uri(new Uri("http://localhost"), url);
- this.MockResponder.RegisterMockResponse(new Uri(userSuppliedId), userSuppliedId, "text/html", TestSupport.LoadEmbeddedFile(url));
+ this.MockResponder.RegisterMockResponse(new Uri(userSuppliedId), userSuppliedId, "text/html", LoadEmbeddedFile(url));
Assert.AreEqual(0, userSuppliedId.Discover(this.RequestHandler).Count()); // ... but that no endpoint info is discoverable
}
diff --git a/src/DotNetOpenAuth.Test/TestBase.cs b/src/DotNetOpenAuth.Test/TestBase.cs
index 9ec0858..0d84a0d 100644
--- a/src/DotNetOpenAuth.Test/TestBase.cs
+++ b/src/DotNetOpenAuth.Test/TestBase.cs
@@ -5,6 +5,7 @@
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Test {
+ using System.IO;
using System.Reflection;
using DotNetOpenAuth.OAuth.Messages;
using log4net;
@@ -15,9 +16,16 @@ namespace DotNetOpenAuth.Test {
/// </summary>
public class TestBase {
/// <summary>
- /// The logger that tests should use.
+ /// The full path to the directory that contains the test ASP.NET site.
/// </summary>
- internal static readonly ILog TestLogger = LogManager.GetLogger("DotNetOpenAuth.Test");
+ internal static readonly string TestWebDirectory = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\..\src\DotNetOpenAuth.TestWeb"));
+
+ /// <summary>
+ /// Gets the logger that tests should use.
+ /// </summary>
+ internal static ILog TestLogger {
+ get { return TestUtilities.TestLogger; }
+ }
/// <summary>
/// Gets or sets the test context which provides
diff --git a/src/DotNetOpenAuth.Test/TestUtilities.cs b/src/DotNetOpenAuth.Test/TestUtilities.cs
index a2ff689..b8c6be9 100644
--- a/src/DotNetOpenAuth.Test/TestUtilities.cs
+++ b/src/DotNetOpenAuth.Test/TestUtilities.cs
@@ -8,10 +8,15 @@ namespace DotNetOpenAuth.Test {
using System;
using System.Collections.Generic;
using System.Linq;
+ using log4net;
/// <summary>
/// An assortment of methods useful for testing.
/// </summary>
internal class TestUtilities {
+ /// <summary>
+ /// The logger that tests should use.
+ /// </summary>
+ internal static readonly ILog TestLogger = LogManager.GetLogger("DotNetOpenAuth.Test");
}
}