summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/OpenId
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.Test/OpenId')
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs376
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Messages/IndirectSignedResponseTests.cs222
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Messages/PositiveAssertionResponseTests.cs146
3 files changed, 372 insertions, 372 deletions
diff --git a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
index 8637cfd..1f54b32 100644
--- a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
@@ -1,188 +1,188 @@
-//-----------------------------------------------------------------------
-// <copyright file="AssociationHandshakeTests.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.Test.OpenId {
- using System;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OpenId;
- using DotNetOpenAuth.OpenId.Messages;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
-
- [TestClass]
- public class AssociationHandshakeTests : OpenIdTestBase {
- [TestInitialize]
- public override void SetUp() {
- base.SetUp();
- }
-
- [TestMethod]
- public void AssociateUnencrypted() {
- this.ParameterizedAssociationTest(new Uri("https://host"));
- }
-
- [TestMethod]
- public void AssociateDiffieHellmanOverHttp() {
- this.ParameterizedAssociationTest(new Uri("http://host"));
- }
-
- [TestMethod, Ignore]
- public void AssociateDiffieHellmanOverHttps() {
- // TODO: test the RP and OP agreeing to use Diffie-Hellman over HTTPS.
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Verifies that the RP and OP can renegotiate an association type if the RP's
- /// initial request for an association is for a type the OP doesn't support.
- /// </summary>
- [TestMethod, Ignore]
- public void AssociateRenegotiateBitLength() {
- // TODO: test where the RP asks for an association type that the OP doesn't support
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Verifies that the RP cannot get caught in an infinite loop if a bad OP
- /// keeps sending it association retry messages.
- /// </summary>
- [TestMethod, Ignore]
- public void AssociateRenegotiateBitLengthRPStopsAfterOneRetry() {
- // TODO: code here
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Verifies security settings limit RP's initial associate request
- /// </summary>
- [TestMethod, Ignore]
- public void AssociateRequestDeterminedBySecuritySettings() {
- // TODO: Code here
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Verifies security settings limit RP's acceptance of OP's counter-suggestion
- /// </summary>
- [TestMethod, Ignore]
- public void AssociateRenegotiateLimitedByRPSecuritySettings() {
- // TODO: Code here
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Verifies security settings limit OP's set of acceptable association types.
- /// </summary>
- [TestMethod, Ignore]
- public void AssociateLimitedByOPSecuritySettings() {
- // TODO: Code here
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Verifies the RP can recover with no association after receiving an
- /// associate error response from the OP when no suggested association
- /// type is included.
- /// </summary>
- [TestMethod, Ignore]
- public void AssociateContinueAfterOpenIdError() {
- // TODO: Code here
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Verifies that the RP can recover from an invalid or non-existent
- /// response from the OP, for example in the HTTP timeout case.
- /// </summary>
- [TestMethod, Ignore]
- public void AssociateContinueAfterHttpError() {
- // TODO: Code here
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Runs a parameterized association flow test using all supported OpenID versions.
- /// </summary>
- /// <param name="opEndpoint">The OP endpoint to simulate using.</param>
- private void ParameterizedAssociationTest(Uri opEndpoint) {
- foreach (Protocol protocol in Protocol.AllPracticalVersions) {
- var endpoint = new ProviderEndpointDescription(opEndpoint, protocol.Version);
- var associationType = protocol.Version.Major < 2 ? protocol.Args.SignatureAlgorithm.HMAC_SHA1 : protocol.Args.SignatureAlgorithm.HMAC_SHA256;
- this.ParameterizedAssociationTest(endpoint, associationType);
- }
- }
-
- /// <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="expectedAssociationType">
- /// The value of the openid.assoc_type parameter expected,
- /// or null if a failure is anticipated.
- /// </param>
- private void ParameterizedAssociationTest(
- ProviderEndpointDescription opDescription,
- string expectedAssociationType) {
- Protocol protocol = Protocol.Lookup(opDescription.ProtocolVersion);
- bool expectSuccess = expectedAssociationType != null;
- bool expectDiffieHellman = !opDescription.Endpoint.IsTransportSecure();
- Association rpAssociation = null, opAssociation;
- AssociateSuccessfulResponse associateSuccessfulResponse = null;
- AssociateUnsuccessfulResponse associateUnsuccessfulResponse = null;
- OpenIdCoordinator coordinator = new OpenIdCoordinator(
- rp => {
- rp.SecuritySettings = this.RelyingPartySecuritySettings;
- rpAssociation = rp.GetAssociation(opDescription);
- },
- op => {
- op.SecuritySettings = this.ProviderSecuritySettings;
- op.AutoRespond();
- });
- coordinator.IncomingMessageFilter = message => {
- Assert.AreSame(opDescription.ProtocolVersion, message.ProtocolVersion, "The message was recognized as version {0} but was expected to be {1}.", message.ProtocolVersion, opDescription.ProtocolVersion);
- var associateSuccess = message as AssociateSuccessfulResponse;
- var associateFailed = message as AssociateUnsuccessfulResponse;
- if (associateSuccess != null) {
- associateSuccessfulResponse = associateSuccess;
- }
- if (associateFailed != null) {
- associateUnsuccessfulResponse = associateFailed;
- }
- };
- coordinator.OutgoingMessageFilter = message => {
- Assert.AreSame(opDescription.ProtocolVersion, message.ProtocolVersion, "The message was for version {0} but was expected to be for {1}.", message.ProtocolVersion, opDescription.ProtocolVersion);
- };
- 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(protocol));
- Assert.AreEqual(expectedAssociationType, opAssociation.GetAssociationType(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));
- }
- }
- }
-}
+//-----------------------------------------------------------------------
+// <copyright file="AssociationHandshakeTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.OpenId {
+ using System;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OpenId;
+ using DotNetOpenAuth.OpenId.Messages;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class AssociationHandshakeTests : OpenIdTestBase {
+ [TestInitialize]
+ public override void SetUp() {
+ base.SetUp();
+ }
+
+ [TestMethod]
+ public void AssociateUnencrypted() {
+ this.ParameterizedAssociationTest(new Uri("https://host"));
+ }
+
+ [TestMethod]
+ public void AssociateDiffieHellmanOverHttp() {
+ this.ParameterizedAssociationTest(new Uri("http://host"));
+ }
+
+ [TestMethod, Ignore]
+ public void AssociateDiffieHellmanOverHttps() {
+ // TODO: test the RP and OP agreeing to use Diffie-Hellman over HTTPS.
+ throw new NotImplementedException();
+ }
+
+ /// <summary>
+ /// Verifies that the RP and OP can renegotiate an association type if the RP's
+ /// initial request for an association is for a type the OP doesn't support.
+ /// </summary>
+ [TestMethod, Ignore]
+ public void AssociateRenegotiateBitLength() {
+ // TODO: test where the RP asks for an association type that the OP doesn't support
+ throw new NotImplementedException();
+ }
+
+ /// <summary>
+ /// Verifies that the RP cannot get caught in an infinite loop if a bad OP
+ /// keeps sending it association retry messages.
+ /// </summary>
+ [TestMethod, Ignore]
+ public void AssociateRenegotiateBitLengthRPStopsAfterOneRetry() {
+ // TODO: code here
+ throw new NotImplementedException();
+ }
+
+ /// <summary>
+ /// Verifies security settings limit RP's initial associate request
+ /// </summary>
+ [TestMethod, Ignore]
+ public void AssociateRequestDeterminedBySecuritySettings() {
+ // TODO: Code here
+ throw new NotImplementedException();
+ }
+
+ /// <summary>
+ /// Verifies security settings limit RP's acceptance of OP's counter-suggestion
+ /// </summary>
+ [TestMethod, Ignore]
+ public void AssociateRenegotiateLimitedByRPSecuritySettings() {
+ // TODO: Code here
+ throw new NotImplementedException();
+ }
+
+ /// <summary>
+ /// Verifies security settings limit OP's set of acceptable association types.
+ /// </summary>
+ [TestMethod, Ignore]
+ public void AssociateLimitedByOPSecuritySettings() {
+ // TODO: Code here
+ throw new NotImplementedException();
+ }
+
+ /// <summary>
+ /// Verifies the RP can recover with no association after receiving an
+ /// associate error response from the OP when no suggested association
+ /// type is included.
+ /// </summary>
+ [TestMethod, Ignore]
+ public void AssociateContinueAfterOpenIdError() {
+ // TODO: Code here
+ throw new NotImplementedException();
+ }
+
+ /// <summary>
+ /// Verifies that the RP can recover from an invalid or non-existent
+ /// response from the OP, for example in the HTTP timeout case.
+ /// </summary>
+ [TestMethod, Ignore]
+ public void AssociateContinueAfterHttpError() {
+ // TODO: Code here
+ throw new NotImplementedException();
+ }
+
+ /// <summary>
+ /// Runs a parameterized association flow test using all supported OpenID versions.
+ /// </summary>
+ /// <param name="opEndpoint">The OP endpoint to simulate using.</param>
+ private void ParameterizedAssociationTest(Uri opEndpoint) {
+ foreach (Protocol protocol in Protocol.AllPracticalVersions) {
+ var endpoint = new ProviderEndpointDescription(opEndpoint, protocol.Version);
+ var associationType = protocol.Version.Major < 2 ? protocol.Args.SignatureAlgorithm.HMAC_SHA1 : protocol.Args.SignatureAlgorithm.HMAC_SHA256;
+ this.ParameterizedAssociationTest(endpoint, associationType);
+ }
+ }
+
+ /// <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="expectedAssociationType">
+ /// The value of the openid.assoc_type parameter expected,
+ /// or null if a failure is anticipated.
+ /// </param>
+ private void ParameterizedAssociationTest(
+ ProviderEndpointDescription opDescription,
+ string expectedAssociationType) {
+ Protocol protocol = Protocol.Lookup(opDescription.ProtocolVersion);
+ bool expectSuccess = expectedAssociationType != null;
+ bool expectDiffieHellman = !opDescription.Endpoint.IsTransportSecure();
+ Association rpAssociation = null, opAssociation;
+ AssociateSuccessfulResponse associateSuccessfulResponse = null;
+ AssociateUnsuccessfulResponse associateUnsuccessfulResponse = null;
+ OpenIdCoordinator coordinator = new OpenIdCoordinator(
+ rp => {
+ rp.SecuritySettings = this.RelyingPartySecuritySettings;
+ rpAssociation = rp.GetAssociation(opDescription);
+ },
+ op => {
+ op.SecuritySettings = this.ProviderSecuritySettings;
+ op.AutoRespond();
+ });
+ coordinator.IncomingMessageFilter = message => {
+ Assert.AreSame(opDescription.ProtocolVersion, message.Version, "The message was recognized as version {0} but was expected to be {1}.", message.Version, opDescription.ProtocolVersion);
+ var associateSuccess = message as AssociateSuccessfulResponse;
+ var associateFailed = message as AssociateUnsuccessfulResponse;
+ if (associateSuccess != null) {
+ associateSuccessfulResponse = associateSuccess;
+ }
+ if (associateFailed != null) {
+ associateUnsuccessfulResponse = associateFailed;
+ }
+ };
+ coordinator.OutgoingMessageFilter = message => {
+ Assert.AreSame(opDescription.ProtocolVersion, message.Version, "The message was for version {0} but was expected to be for {1}.", message.Version, opDescription.ProtocolVersion);
+ };
+ 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(protocol));
+ Assert.AreEqual(expectedAssociationType, opAssociation.GetAssociationType(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/Messages/IndirectSignedResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectSignedResponseTests.cs
index 8900e76..f0a9cc2 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectSignedResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Messages/IndirectSignedResponseTests.cs
@@ -1,111 +1,111 @@
-//-----------------------------------------------------------------------
-// <copyright file="IndirectSignedResponseTests.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.Test.OpenId.Messages {
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.Messaging.Bindings;
- using DotNetOpenAuth.OpenId;
- using DotNetOpenAuth.OpenId.ChannelElements;
- using DotNetOpenAuth.OpenId.Messages;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
-
- [TestClass]
- public class IndirectSignedResponseTests : OpenIdTestBase {
- private const string CreationDateString = "2005-05-15T17:11:51Z";
- private readonly DateTime creationDate = DateTime.Parse(CreationDateString, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
- private CheckIdRequest request;
- private IndirectSignedResponse response;
- private IndirectSignedResponse unsolicited;
- private Protocol protocol;
-
- [TestInitialize]
- public override void SetUp() {
- base.SetUp();
-
- this.protocol = Protocol.V20;
- this.request = new CheckIdRequest(this.protocol.Version, ProviderUri, false);
- this.request.ReturnTo = RPUri;
- this.response = new IndirectSignedResponse(this.request);
-
- this.unsolicited = new IndirectSignedResponse(this.protocol.Version, RPUri);
- }
-
- [TestMethod]
- public void CtorFromRequest() {
- Assert.AreEqual(this.protocol.Args.Mode.id_res, this.response.Mode);
- Assert.AreEqual(this.request.ProtocolVersion, this.response.ProtocolVersion);
- Assert.AreEqual(this.request.ReturnTo, this.response.Recipient);
- Assert.AreEqual(ProviderUri, this.response.ProviderEndpoint);
- Assert.IsTrue(DateTime.UtcNow - ((ITamperResistantOpenIdMessage)this.response).UtcCreationDate < TimeSpan.FromSeconds(5));
- }
-
- [TestMethod]
- public void CtorUnsolicited() {
- Assert.AreEqual(this.protocol.Args.Mode.id_res, this.unsolicited.Mode);
- Assert.AreEqual(this.protocol.Version, this.unsolicited.ProtocolVersion);
- Assert.AreEqual(RPUri, this.unsolicited.Recipient);
- 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);
- }
-
- [TestMethod]
- public void ResponseNonceSetter() {
- const string HybridValue = CreationDateString + "UNIQUE";
- var responseAccessor = IndirectSignedResponse_Accessor.AttachShadow(this.response);
- IReplayProtectedProtocolMessage responseReplay = this.response;
- responseAccessor.ResponseNonce = HybridValue;
- Assert.AreEqual(HybridValue, responseAccessor.ResponseNonce);
- Assert.AreEqual(this.creationDate, responseReplay.UtcCreationDate);
- Assert.AreEqual("UNIQUE", responseReplay.Nonce);
-
- responseAccessor.ResponseNonce = null;
- Assert.IsNull(responseReplay.Nonce);
- }
-
- [TestMethod]
- public void ResponseNonceGetter() {
- var responseAccessor = IndirectSignedResponse_Accessor.AttachShadow(this.response);
- IReplayProtectedProtocolMessage responseReplay = this.response;
- responseReplay.Nonce = "UnIqUe";
- responseReplay.UtcCreationDate = this.creationDate;
-
- Assert.AreEqual(CreationDateString + "UnIqUe", responseAccessor.ResponseNonce);
- Assert.AreEqual("UnIqUe", responseReplay.Nonce);
- Assert.AreEqual(this.creationDate, responseReplay.UtcCreationDate);
- }
-
- [TestMethod]
- public void UtcCreationDateConvertsToUniversal() {
- IReplayProtectedProtocolMessage responseReplay = this.response;
- DateTime local = DateTime.Parse("1982-01-01", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
- if (local.Kind != DateTimeKind.Local) {
- Assert.Inconclusive("Test cannot manage to create a local time.");
- }
-
- responseReplay.UtcCreationDate = local;
- DateTime utcCreationDate = responseReplay.UtcCreationDate;
- Assert.AreEqual(DateTimeKind.Utc, utcCreationDate.Kind, "Local time should have been converted to universal time.");
- Assert.AreNotEqual(local.Hour, utcCreationDate.Hour, "The hour was expected to change (unless local time _is_ UTC time for this PC!)");
-
- // Now try setting UTC time just to make sure it DOESN'T mangle the hour
- if (this.creationDate.Kind != DateTimeKind.Utc) {
- Assert.Inconclusive("We need a UTC datetime to set with.");
- }
- responseReplay.UtcCreationDate = this.creationDate;
- utcCreationDate = responseReplay.UtcCreationDate;
- Assert.AreEqual(DateTimeKind.Utc, utcCreationDate.Kind);
- Assert.AreEqual(this.creationDate.Hour, utcCreationDate.Hour, "The hour should match since both times are UTC time.");
- }
- }
-}
+//-----------------------------------------------------------------------
+// <copyright file="IndirectSignedResponseTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.OpenId.Messages {
+ using System;
+ using System.Collections.Generic;
+ using System.Globalization;
+ using System.Linq;
+ using System.Text;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.Messaging.Bindings;
+ using DotNetOpenAuth.OpenId;
+ using DotNetOpenAuth.OpenId.ChannelElements;
+ using DotNetOpenAuth.OpenId.Messages;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class IndirectSignedResponseTests : OpenIdTestBase {
+ private const string CreationDateString = "2005-05-15T17:11:51Z";
+ private readonly DateTime creationDate = DateTime.Parse(CreationDateString, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
+ private CheckIdRequest request;
+ private IndirectSignedResponse response;
+ private IndirectSignedResponse unsolicited;
+ private Protocol protocol;
+
+ [TestInitialize]
+ public override void SetUp() {
+ base.SetUp();
+
+ this.protocol = Protocol.V20;
+ this.request = new CheckIdRequest(this.protocol.Version, ProviderUri, false);
+ this.request.ReturnTo = RPUri;
+ this.response = new IndirectSignedResponse(this.request);
+
+ this.unsolicited = new IndirectSignedResponse(this.protocol.Version, RPUri);
+ }
+
+ [TestMethod]
+ public void CtorFromRequest() {
+ 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.IsTrue(DateTime.UtcNow - ((ITamperResistantOpenIdMessage)this.response).UtcCreationDate < TimeSpan.FromSeconds(5));
+ }
+
+ [TestMethod]
+ public void CtorUnsolicited() {
+ Assert.AreEqual(this.protocol.Args.Mode.id_res, this.unsolicited.Mode);
+ Assert.AreEqual(this.protocol.Version, this.unsolicited.Version);
+ Assert.AreEqual(RPUri, this.unsolicited.Recipient);
+ 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);
+ }
+
+ [TestMethod]
+ public void ResponseNonceSetter() {
+ const string HybridValue = CreationDateString + "UNIQUE";
+ var responseAccessor = IndirectSignedResponse_Accessor.AttachShadow(this.response);
+ IReplayProtectedProtocolMessage responseReplay = this.response;
+ responseAccessor.ResponseNonce = HybridValue;
+ Assert.AreEqual(HybridValue, responseAccessor.ResponseNonce);
+ Assert.AreEqual(this.creationDate, responseReplay.UtcCreationDate);
+ Assert.AreEqual("UNIQUE", responseReplay.Nonce);
+
+ responseAccessor.ResponseNonce = null;
+ Assert.IsNull(responseReplay.Nonce);
+ }
+
+ [TestMethod]
+ public void ResponseNonceGetter() {
+ var responseAccessor = IndirectSignedResponse_Accessor.AttachShadow(this.response);
+ IReplayProtectedProtocolMessage responseReplay = this.response;
+ responseReplay.Nonce = "UnIqUe";
+ responseReplay.UtcCreationDate = this.creationDate;
+
+ Assert.AreEqual(CreationDateString + "UnIqUe", responseAccessor.ResponseNonce);
+ Assert.AreEqual("UnIqUe", responseReplay.Nonce);
+ Assert.AreEqual(this.creationDate, responseReplay.UtcCreationDate);
+ }
+
+ [TestMethod]
+ public void UtcCreationDateConvertsToUniversal() {
+ IReplayProtectedProtocolMessage responseReplay = this.response;
+ DateTime local = DateTime.Parse("1982-01-01", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
+ if (local.Kind != DateTimeKind.Local) {
+ Assert.Inconclusive("Test cannot manage to create a local time.");
+ }
+
+ responseReplay.UtcCreationDate = local;
+ DateTime utcCreationDate = responseReplay.UtcCreationDate;
+ Assert.AreEqual(DateTimeKind.Utc, utcCreationDate.Kind, "Local time should have been converted to universal time.");
+ Assert.AreNotEqual(local.Hour, utcCreationDate.Hour, "The hour was expected to change (unless local time _is_ UTC time for this PC!)");
+
+ // Now try setting UTC time just to make sure it DOESN'T mangle the hour
+ if (this.creationDate.Kind != DateTimeKind.Utc) {
+ Assert.Inconclusive("We need a UTC datetime to set with.");
+ }
+ responseReplay.UtcCreationDate = this.creationDate;
+ utcCreationDate = responseReplay.UtcCreationDate;
+ Assert.AreEqual(DateTimeKind.Utc, utcCreationDate.Kind);
+ Assert.AreEqual(this.creationDate.Hour, utcCreationDate.Hour, "The hour should match since both times are UTC time.");
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/PositiveAssertionResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/PositiveAssertionResponseTests.cs
index 164b46b..ee5f69f 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Messages/PositiveAssertionResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Messages/PositiveAssertionResponseTests.cs
@@ -1,73 +1,73 @@
-//-----------------------------------------------------------------------
-// <copyright file="PositiveAssertionResponseTests.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.Test.OpenId.Messages {
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.Messaging.Bindings;
- using DotNetOpenAuth.OpenId;
- using DotNetOpenAuth.OpenId.Messages;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
-
- [TestClass]
- public class PositiveAssertionResponseTests : OpenIdTestBase {
- private const string CreationDateString = "2005-05-15T17:11:51Z";
- private readonly DateTime creationDate = DateTime.Parse(CreationDateString, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
- private CheckIdRequest request;
- private PositiveAssertionResponse response;
- private PositiveAssertionResponse unsolicited;
- private Protocol protocol;
-
- [TestInitialize]
- public override void SetUp() {
- base.SetUp();
-
- this.protocol = Protocol.V20;
- this.request = new CheckIdRequest(this.protocol.Version, ProviderUri, false);
- this.request.ReturnTo = RPUri;
- this.response = new PositiveAssertionResponse(this.request);
-
- this.unsolicited = new PositiveAssertionResponse(this.protocol.Version, RPUri);
- }
-
- [TestMethod]
- public void CtorFromRequest() {
- Assert.AreEqual(this.protocol.Args.Mode.id_res, this.response.Mode);
- Assert.AreEqual(this.request.ProtocolVersion, this.response.ProtocolVersion);
- Assert.AreEqual(this.request.ReturnTo, this.response.Recipient);
- Assert.AreEqual(ProviderUri, this.response.ProviderEndpoint);
- }
-
- [TestMethod]
- public void CtorUnsolicited() {
- Assert.AreEqual(this.protocol.Args.Mode.id_res, this.unsolicited.Mode);
- Assert.AreEqual(this.protocol.Version, this.unsolicited.ProtocolVersion);
- Assert.AreEqual(RPUri, this.unsolicited.Recipient);
-
- Assert.IsNull(this.unsolicited.ProviderEndpoint);
- this.unsolicited.ProviderEndpoint = ProviderUri;
- Assert.AreEqual(ProviderUri, this.unsolicited.ProviderEndpoint);
- }
-
- /// <summary>
- /// Verifies that local_id and claimed_id can either be null or specified.
- /// </summary>
- [TestMethod]
- public void ClaimedIdAndLocalIdSpecifiedIsValid() {
- this.response.LocalIdentifier = "http://local";
- this.response.ClaimedIdentifier = "http://claimedid";
- this.response.EnsureValidMessage();
-
- this.response.LocalIdentifier = null;
- this.response.ClaimedIdentifier = null;
- this.response.EnsureValidMessage();
- }
- }
-}
+//-----------------------------------------------------------------------
+// <copyright file="PositiveAssertionResponseTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.OpenId.Messages {
+ using System;
+ using System.Collections.Generic;
+ using System.Globalization;
+ using System.Linq;
+ using System.Text;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.Messaging.Bindings;
+ using DotNetOpenAuth.OpenId;
+ using DotNetOpenAuth.OpenId.Messages;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class PositiveAssertionResponseTests : OpenIdTestBase {
+ private const string CreationDateString = "2005-05-15T17:11:51Z";
+ private readonly DateTime creationDate = DateTime.Parse(CreationDateString, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
+ private CheckIdRequest request;
+ private PositiveAssertionResponse response;
+ private PositiveAssertionResponse unsolicited;
+ private Protocol protocol;
+
+ [TestInitialize]
+ public override void SetUp() {
+ base.SetUp();
+
+ this.protocol = Protocol.V20;
+ this.request = new CheckIdRequest(this.protocol.Version, ProviderUri, false);
+ this.request.ReturnTo = RPUri;
+ this.response = new PositiveAssertionResponse(this.request);
+
+ this.unsolicited = new PositiveAssertionResponse(this.protocol.Version, RPUri);
+ }
+
+ [TestMethod]
+ public void CtorFromRequest() {
+ 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);
+ }
+
+ [TestMethod]
+ public void CtorUnsolicited() {
+ Assert.AreEqual(this.protocol.Args.Mode.id_res, this.unsolicited.Mode);
+ Assert.AreEqual(this.protocol.Version, this.unsolicited.Version);
+ Assert.AreEqual(RPUri, this.unsolicited.Recipient);
+
+ Assert.IsNull(this.unsolicited.ProviderEndpoint);
+ this.unsolicited.ProviderEndpoint = ProviderUri;
+ Assert.AreEqual(ProviderUri, this.unsolicited.ProviderEndpoint);
+ }
+
+ /// <summary>
+ /// Verifies that local_id and claimed_id can either be null or specified.
+ /// </summary>
+ [TestMethod]
+ public void ClaimedIdAndLocalIdSpecifiedIsValid() {
+ this.response.LocalIdentifier = "http://local";
+ this.response.ClaimedIdentifier = "http://claimedid";
+ this.response.EnsureValidMessage();
+
+ this.response.LocalIdentifier = null;
+ this.response.ClaimedIdentifier = null;
+ this.response.EnsureValidMessage();
+ }
+ }
+}