summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs96
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/OpenIdScenarioTests.cs88
3 files changed, 97 insertions, 89 deletions
diff --git a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
index 1bc5355..0e460bd 100644
--- a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
+++ b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
@@ -104,7 +104,7 @@
<Compile Include="OpenId\Messages\DirectErrorResponseTests.cs" />
<Compile Include="OpenId\Messages\IndirectErrorResponseTests.cs" />
<Compile Include="OpenId\OpenIdCoordinator.cs" />
- <Compile Include="OpenId\OpenIdScenarioTests.cs" />
+ <Compile Include="OpenId\AssociationHandshakeTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Messaging\ResponseTests.cs" />
<Compile Include="OAuth\AppendixScenarios.cs" />
diff --git a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
new file mode 100644
index 0000000..103a252
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
@@ -0,0 +1,96 @@
+//-----------------------------------------------------------------------
+// <copyright file="AssociationHandshakeTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.OpenId {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OpenId;
+ using DotNetOpenAuth.OpenId.Messages;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class AssociationHandshakeTests {
+ [TestMethod]
+ public void AssociateDiffieHellmanMessages() {
+ var opDescription = new ProviderEndpointDescription(new Uri("http://host"), Protocol.V20);
+ ParameterizedAssociationTest(opDescription, true, Protocol.V20.Args.SignatureAlgorithm.HMAC_SHA1);
+ }
+
+ [TestMethod]
+ public void AssociateUnencryptedMessages() {
+ var opDescription = new ProviderEndpointDescription(new Uri("https://host"), Protocol.V20);
+ ParameterizedAssociationTest(opDescription, false, Protocol.V20.Args.SignatureAlgorithm.HMAC_SHA1);
+ }
+
+ /// <summary>
+ /// Runs a parameterized association flow test.
+ /// </summary>
+ /// <param name="opDescription">
+ /// The description of the Provider that the relying party uses to formulate the request.
+ /// The specific host is not used, but the scheme is significant.
+ /// </param>
+ /// <param name="expectDiffieHellman">True if a DH session is expected to be used.</param>
+ /// <param name="expectedAssociationType">
+ /// The value of the openid.assoc_type parameter expected,
+ /// or null if a failure is anticipated.
+ /// </param>
+ private void ParameterizedAssociationTest(
+ ProviderEndpointDescription opDescription,
+ bool expectDiffieHellman,
+ string expectedAssociationType) {
+ bool expectSuccess = expectedAssociationType != null;
+ Association rpAssociation = null, opAssociation;
+ AssociateSuccessfulResponse associateSuccessfulResponse = null;
+ AssociateUnsuccessfulResponse associateUnsuccessfulResponse = null;
+ OpenIdCoordinator coordinator = new OpenIdCoordinator(
+ rp => {
+ rpAssociation = rp.GetAssociation(opDescription);
+ },
+ op => {
+ op.AutoRespond();
+ });
+ coordinator.IncomingMessageFilter = (message) => {
+ var associateSuccess = message as AssociateSuccessfulResponse;
+ var associateFailed = message as AssociateUnsuccessfulResponse;
+ if (associateSuccess != null) {
+ associateSuccessfulResponse = associateSuccess;
+ }
+ if (associateFailed != null) {
+ associateUnsuccessfulResponse = associateFailed;
+ }
+ };
+ coordinator.Run();
+
+ if (expectSuccess) {
+ Assert.IsNotNull(rpAssociation);
+ Assert.AreSame(rpAssociation, coordinator.RelyingParty.AssociationStore.GetAssociation(opDescription.Endpoint, rpAssociation.Handle));
+ opAssociation = coordinator.Provider.AssociationStore.GetAssociation(AssociationRelyingPartyType.Smart, rpAssociation.Handle);
+ Assert.IsNotNull(opAssociation, "The Provider should have stored the association.");
+
+ Assert.AreEqual(opAssociation.Handle, rpAssociation.Handle);
+ Assert.AreEqual(expectedAssociationType, rpAssociation.GetAssociationType(opDescription.Protocol));
+ Assert.AreEqual(expectedAssociationType, opAssociation.GetAssociationType(opDescription.Protocol));
+ Assert.IsTrue(Math.Abs(opAssociation.SecondsTillExpiration - rpAssociation.SecondsTillExpiration) < 60);
+ Assert.IsTrue(MessagingUtilities.AreEquivalent(opAssociation.SecretKey, rpAssociation.SecretKey));
+
+ if (expectDiffieHellman) {
+ Assert.IsInstanceOfType(associateSuccessfulResponse, typeof(AssociateDiffieHellmanResponse));
+ var diffieHellmanResponse = (AssociateDiffieHellmanResponse)associateSuccessfulResponse;
+ Assert.IsFalse(MessagingUtilities.AreEquivalent(diffieHellmanResponse.EncodedMacKey, rpAssociation.SecretKey), "Key should have been encrypted.");
+ } else {
+ Assert.IsInstanceOfType(associateSuccessfulResponse, typeof(AssociateUnencryptedResponse));
+ var unencryptedResponse = (AssociateUnencryptedResponse)associateSuccessfulResponse;
+ }
+ } else {
+ Assert.IsNull(coordinator.RelyingParty.AssociationStore.GetAssociation(opDescription.Endpoint));
+ Assert.IsNull(coordinator.Provider.AssociationStore.GetAssociation(AssociationRelyingPartyType.Smart));
+ }
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.Test/OpenId/OpenIdScenarioTests.cs b/src/DotNetOpenAuth.Test/OpenId/OpenIdScenarioTests.cs
deleted file mode 100644
index db0bf27..0000000
--- a/src/DotNetOpenAuth.Test/OpenId/OpenIdScenarioTests.cs
+++ /dev/null
@@ -1,88 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="OpenIdScenarioTests.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.Test.OpenId {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OpenId;
- using DotNetOpenAuth.OpenId.Messages;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
-
- [TestClass]
- public class OpenIdScenarioTests {
- private readonly Protocol Protocol = Protocol.V20;
-
- [TestMethod]
- public void AssociateDiffieHellmanMessages() {
- Association rpAssociation = null, opAssociation;
- AssociateDiffieHellmanResponse associateResponse = null;
- var opDescription = new ProviderEndpointDescription(new Uri("http://host"), this.Protocol);
- OpenIdCoordinator coordinator = new OpenIdCoordinator(
- rp => {
- rpAssociation = rp.GetAssociation(opDescription);
- },
- op => {
- op.AutoRespond();
- });
- coordinator.IncomingMessageFilter = (message) => {
- var associateResponseMessage = message as AssociateDiffieHellmanResponse;
- if (associateResponseMessage != null) {
- // capture this message so we can analyze it later
- associateResponse = associateResponseMessage;
- }
- };
- coordinator.Run();
- Assert.IsNotNull(rpAssociation);
- Assert.AreSame(rpAssociation, coordinator.RelyingParty.AssociationStore.GetAssociation(opDescription.Endpoint, rpAssociation.Handle));
- opAssociation = coordinator.Provider.AssociationStore.GetAssociation(AssociationRelyingPartyType.Smart, rpAssociation.Handle);
- Assert.IsNotNull(opAssociation, "The Provider should have stored the association.");
-
- Assert.AreEqual(opAssociation.Handle, rpAssociation.Handle);
- Assert.IsFalse(MessagingUtilities.AreEquivalent(associateResponse.EncodedMacKey, rpAssociation.SecretKey), "Key should have been encrypted.");
- Assert.IsTrue(Math.Abs(opAssociation.SecondsTillExpiration - rpAssociation.SecondsTillExpiration) < 60);
- Assert.IsTrue(MessagingUtilities.AreEquivalent(opAssociation.SecretKey, rpAssociation.SecretKey));
- }
-
- [TestMethod]
- public void AssociateUnencryptedMessages() {
- Association rpAssociation = null, opAssociation;
- AssociateUnencryptedResponse associateResponse = null;
- bool unencryptedRequestSent = false;
- var opDescription = new ProviderEndpointDescription(new Uri("https://host"), this.Protocol);
- OpenIdCoordinator coordinator = new OpenIdCoordinator(
- rp => {
- rpAssociation = rp.GetAssociation(opDescription);
- },
- op => {
- op.AutoRespond();
- });
- coordinator.IncomingMessageFilter = message => {
- var associateResponseMessage = message as AssociateUnencryptedResponse;
- if (associateResponseMessage != null) {
- // capture this message as it comes into the RP so we can analyze it later
- associateResponse = associateResponseMessage;
- }
- };
- coordinator.OutgoingMessageFilter = message => {
- // we want to check that the RP is sending a request that doesn't require DH
- unencryptedRequestSent |= message is AssociateUnencryptedRequest;
- };
- coordinator.Run();
- Assert.IsNotNull(rpAssociation);
- Assert.AreSame(rpAssociation, coordinator.RelyingParty.AssociationStore.GetAssociation(opDescription.Endpoint, rpAssociation.Handle));
- opAssociation = coordinator.Provider.AssociationStore.GetAssociation(AssociationRelyingPartyType.Smart, rpAssociation.Handle);
- Assert.IsNotNull(opAssociation, "The Provider should have stored the association.");
-
- Assert.IsTrue(unencryptedRequestSent, "An unencrypted association request should have been used since HTTPS was the transport.");
- Assert.AreEqual(opAssociation.Handle, rpAssociation.Handle);
- Assert.IsTrue(Math.Abs(opAssociation.SecondsTillExpiration - rpAssociation.SecondsTillExpiration) < 60);
- Assert.IsTrue(MessagingUtilities.AreEquivalent(opAssociation.SecretKey, rpAssociation.SecretKey));
- }
- }
-}