diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-12-19 16:24:25 -0800 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2008-12-19 16:24:25 -0800 |
commit | 89c77e698e1e03f157db71da66576ef564c918ae (patch) | |
tree | aa0e5c871b210d8a792d1847cb76ae283e772aab /src/DotNetOpenAuth.Test | |
parent | 77f5b1550164c409ee6b4e41c372037832d112c3 (diff) | |
download | DotNetOpenAuth-89c77e698e1e03f157db71da66576ef564c918ae.zip DotNetOpenAuth-89c77e698e1e03f157db71da66576ef564c918ae.tar.gz DotNetOpenAuth-89c77e698e1e03f157db71da66576ef564c918ae.tar.bz2 |
Lots of work toward extensions.
Diffstat (limited to 'src/DotNetOpenAuth.Test')
6 files changed, 616 insertions, 616 deletions
diff --git a/src/DotNetOpenAuth.Test/Messaging/ProtocolExceptionTests.cs b/src/DotNetOpenAuth.Test/Messaging/ProtocolExceptionTests.cs index 02aea64..f245702 100644 --- a/src/DotNetOpenAuth.Test/Messaging/ProtocolExceptionTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/ProtocolExceptionTests.cs @@ -1,97 +1,97 @@ -//----------------------------------------------------------------------- -// <copyright file="ProtocolExceptionTests.cs" company="Andrew Arnott"> -// Copyright (c) Andrew Arnott. All rights reserved. -// </copyright> -//----------------------------------------------------------------------- - -namespace DotNetOpenAuth.Test.Messaging { - using System; - using DotNetOpenAuth.Messaging; - using Microsoft.VisualStudio.TestTools.UnitTesting; - - [TestClass] - public class ProtocolExceptionTests : TestBase { - [TestMethod] - public void CtorDefault() { - ProtocolException ex = new ProtocolException(); - } - - [TestMethod] - public void CtorWithTextMessage() { - ProtocolException ex = new ProtocolException("message"); - Assert.AreEqual("message", ex.Message); - } - - [TestMethod] - public void CtorWithTextMessageAndInnerException() { - Exception innerException = new Exception(); - ProtocolException ex = new ProtocolException("message", innerException); - Assert.AreEqual("message", ex.Message); - Assert.AreSame(innerException, ex.InnerException); - } - - [TestMethod] - public void CtorWithProtocolMessage() { - IProtocolMessage request = new Mocks.TestDirectedMessage(); - Uri receiver = new Uri("http://receiver"); - ProtocolException ex = new ProtocolException("some error occurred", request, receiver); - IDirectedProtocolMessage msg = (IDirectedProtocolMessage)ex; - Assert.AreEqual("some error occurred", ex.Message); - Assert.AreSame(receiver, msg.Recipient); - Assert.AreEqual(request.ProtocolVersion, msg.ProtocolVersion); - Assert.AreEqual(request.Transport, msg.Transport); - msg.EnsureValidMessage(); - } - - [TestMethod, ExpectedException(typeof(ArgumentNullException))] - public void CtorWithNullProtocolMessage() { - new ProtocolException("message", null, new Uri("http://receiver")); - } - - [TestMethod, ExpectedException(typeof(ArgumentNullException))] - public void CtorWithNullReceiver() { - new ProtocolException("message", new Mocks.TestDirectedMessage(MessageTransport.Indirect), null); - } - - /// <summary> - /// Tests that exceptions being sent as direct responses do not need an explicit receiver. - /// </summary> - [TestMethod] - public void CtorUndirectedMessageWithNullReceiver() { - IProtocolMessage request = new Mocks.TestDirectedMessage(MessageTransport.Direct); - ProtocolException ex = new ProtocolException("message", request, null); - IDirectedProtocolMessage msg = (IDirectedProtocolMessage)ex; - Assert.IsNull(msg.Recipient); - Assert.AreEqual(request.ProtocolVersion, msg.ProtocolVersion); - Assert.AreEqual(request.Transport, msg.Transport); - } - - [TestMethod, ExpectedException(typeof(InvalidOperationException))] - public void ProtocolVersionWithoutMessage() { - ProtocolException ex = new ProtocolException(); - IDirectedProtocolMessage msg = (IDirectedProtocolMessage)ex; - var temp = msg.ProtocolVersion; - } - - [TestMethod, ExpectedException(typeof(InvalidOperationException))] - public void TransportWithoutMessage() { - ProtocolException ex = new ProtocolException(); - IDirectedProtocolMessage msg = (IDirectedProtocolMessage)ex; - var temp = msg.Transport; - } - - [TestMethod, ExpectedException(typeof(InvalidOperationException))] - public void RecipientWithoutMessage() { - ProtocolException ex = new ProtocolException(); - IDirectedProtocolMessage msg = (IDirectedProtocolMessage)ex; - var temp = msg.Recipient; - } - - [TestMethod, ExpectedException(typeof(InvalidOperationException))] - public void EnsureValidMessageWithoutMessage() { - ProtocolException ex = new ProtocolException(); - IDirectedProtocolMessage msg = (IDirectedProtocolMessage)ex; - msg.EnsureValidMessage(); - } - } -} +//-----------------------------------------------------------------------
+// <copyright file="ProtocolExceptionTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.Messaging {
+ using System;
+ using DotNetOpenAuth.Messaging;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class ProtocolExceptionTests : TestBase {
+ [TestMethod]
+ public void CtorDefault() {
+ ProtocolException ex = new ProtocolException();
+ }
+
+ [TestMethod]
+ public void CtorWithTextMessage() {
+ ProtocolException ex = new ProtocolException("message");
+ Assert.AreEqual("message", ex.Message);
+ }
+
+ [TestMethod]
+ public void CtorWithTextMessageAndInnerException() {
+ Exception innerException = new Exception();
+ ProtocolException ex = new ProtocolException("message", innerException);
+ Assert.AreEqual("message", ex.Message);
+ Assert.AreSame(innerException, ex.InnerException);
+ }
+
+ [TestMethod]
+ public void CtorWithProtocolMessage() {
+ IProtocolMessage request = new Mocks.TestDirectedMessage();
+ Uri receiver = new Uri("http://receiver");
+ ProtocolException ex = new ProtocolException("some error occurred", request, receiver);
+ IDirectedProtocolMessage msg = (IDirectedProtocolMessage)ex;
+ Assert.AreEqual("some error occurred", ex.Message);
+ Assert.AreSame(receiver, msg.Recipient);
+ Assert.AreEqual(request.Version, msg.Version);
+ Assert.AreEqual(request.Transport, msg.Transport);
+ msg.EnsureValidMessage();
+ }
+
+ [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ public void CtorWithNullProtocolMessage() {
+ new ProtocolException("message", null, new Uri("http://receiver"));
+ }
+
+ [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ public void CtorWithNullReceiver() {
+ new ProtocolException("message", new Mocks.TestDirectedMessage(MessageTransport.Indirect), null);
+ }
+
+ /// <summary>
+ /// Tests that exceptions being sent as direct responses do not need an explicit receiver.
+ /// </summary>
+ [TestMethod]
+ public void CtorUndirectedMessageWithNullReceiver() {
+ IProtocolMessage request = new Mocks.TestDirectedMessage(MessageTransport.Direct);
+ ProtocolException ex = new ProtocolException("message", request, null);
+ IDirectedProtocolMessage msg = (IDirectedProtocolMessage)ex;
+ Assert.IsNull(msg.Recipient);
+ Assert.AreEqual(request.Version, msg.Version);
+ Assert.AreEqual(request.Transport, msg.Transport);
+ }
+
+ [TestMethod, ExpectedException(typeof(InvalidOperationException))]
+ public void ProtocolVersionWithoutMessage() {
+ ProtocolException ex = new ProtocolException();
+ IDirectedProtocolMessage msg = (IDirectedProtocolMessage)ex;
+ var temp = msg.Version;
+ }
+
+ [TestMethod, ExpectedException(typeof(InvalidOperationException))]
+ public void TransportWithoutMessage() {
+ ProtocolException ex = new ProtocolException();
+ IDirectedProtocolMessage msg = (IDirectedProtocolMessage)ex;
+ var temp = msg.Transport;
+ }
+
+ [TestMethod, ExpectedException(typeof(InvalidOperationException))]
+ public void RecipientWithoutMessage() {
+ ProtocolException ex = new ProtocolException();
+ IDirectedProtocolMessage msg = (IDirectedProtocolMessage)ex;
+ var temp = msg.Recipient;
+ }
+
+ [TestMethod, ExpectedException(typeof(InvalidOperationException))]
+ public void EnsureValidMessageWithoutMessage() {
+ ProtocolException ex = new ProtocolException();
+ IDirectedProtocolMessage msg = (IDirectedProtocolMessage)ex;
+ msg.EnsureValidMessage();
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.Test/Mocks/TestBaseMessage.cs b/src/DotNetOpenAuth.Test/Mocks/TestBaseMessage.cs index 212907f..49b11bf 100644 --- a/src/DotNetOpenAuth.Test/Mocks/TestBaseMessage.cs +++ b/src/DotNetOpenAuth.Test/Mocks/TestBaseMessage.cs @@ -1,65 +1,65 @@ -//----------------------------------------------------------------------- -// <copyright file="TestBaseMessage.cs" company="Andrew Arnott"> -// Copyright (c) Andrew Arnott. All rights reserved. -// </copyright> -//----------------------------------------------------------------------- - -namespace DotNetOpenAuth.Test.Mocks { - using System; - using System.Collections.Generic; - using System.Runtime.Serialization; - using DotNetOpenAuth.Messaging; - using DotNetOpenAuth.Messaging.Reflection; - - internal interface IBaseMessageExplicitMembers { - string ExplicitProperty { get; set; } - } - - internal class TestBaseMessage : IProtocolMessage, IBaseMessageExplicitMembers { - private Dictionary<string, string> extraData = new Dictionary<string, string>(); - private bool incoming; - - [MessagePart("age", IsRequired = true)] - public int Age { get; set; } - - [MessagePart] - public string Name { get; set; } - - [MessagePart("explicit")] - string IBaseMessageExplicitMembers.ExplicitProperty { get; set; } - - Version IProtocolMessage.ProtocolVersion { - get { return new Version(1, 0); } - } - - MessageProtections IProtocolMessage.RequiredProtection { - get { return MessageProtections.None; } - } - - MessageTransport IProtocolMessage.Transport { - get { return MessageTransport.Indirect; } - } - - IDictionary<string, string> IProtocolMessage.ExtraData { - get { return this.extraData; } - } - - bool IProtocolMessage.Incoming { - get { return this.incoming; } - } - - internal string PrivatePropertyAccessor { - get { return this.PrivateProperty; } - set { this.PrivateProperty = value; } - } - - [MessagePart("private")] - private string PrivateProperty { get; set; } - - void IProtocolMessage.EnsureValidMessage() { } - - internal void SetAsIncoming() { - this.incoming = true; - } - } -} +//-----------------------------------------------------------------------
+// <copyright file="TestBaseMessage.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.Mocks {
+ using System;
+ using System.Collections.Generic;
+ using System.Runtime.Serialization;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.Messaging.Reflection;
+
+ internal interface IBaseMessageExplicitMembers {
+ string ExplicitProperty { get; set; }
+ }
+
+ internal class TestBaseMessage : IProtocolMessage, IBaseMessageExplicitMembers {
+ private Dictionary<string, string> extraData = new Dictionary<string, string>();
+ private bool incoming;
+
+ [MessagePart("age", IsRequired = true)]
+ public int Age { get; set; }
+
+ [MessagePart]
+ public string Name { get; set; }
+
+ [MessagePart("explicit")]
+ string IBaseMessageExplicitMembers.ExplicitProperty { get; set; }
+
+ Version IMessage.Version {
+ get { return new Version(1, 0); }
+ }
+
+ MessageProtections IProtocolMessage.RequiredProtection {
+ get { return MessageProtections.None; }
+ }
+
+ MessageTransport IProtocolMessage.Transport {
+ get { return MessageTransport.Indirect; }
+ }
+
+ IDictionary<string, string> IMessage.ExtraData {
+ get { return this.extraData; }
+ }
+
+ bool IMessage.Incoming {
+ get { return this.incoming; }
+ }
+
+ internal string PrivatePropertyAccessor {
+ get { return this.PrivateProperty; }
+ set { this.PrivateProperty = value; }
+ }
+
+ [MessagePart("private")]
+ private string PrivateProperty { get; set; }
+
+ void IMessage.EnsureValidMessage() { }
+
+ internal void SetAsIncoming() {
+ this.incoming = true;
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.Test/Mocks/TestMessage.cs b/src/DotNetOpenAuth.Test/Mocks/TestMessage.cs index 4a168a1..a2f5328 100644 --- a/src/DotNetOpenAuth.Test/Mocks/TestMessage.cs +++ b/src/DotNetOpenAuth.Test/Mocks/TestMessage.cs @@ -1,82 +1,82 @@ -//----------------------------------------------------------------------- -// <copyright file="TestMessage.cs" company="Andrew Arnott"> -// Copyright (c) Andrew Arnott. All rights reserved. -// </copyright> -//----------------------------------------------------------------------- - -namespace DotNetOpenAuth.Test.Mocks { - using System; - using System.Collections.Generic; - using System.Runtime.Serialization; - using DotNetOpenAuth.Messaging; - using DotNetOpenAuth.Messaging.Reflection; - - internal abstract class TestMessage : IDirectResponseProtocolMessage { - private MessageTransport transport; - private Dictionary<string, string> extraData = new Dictionary<string, string>(); - private bool incoming; - - protected TestMessage() - : this(MessageTransport.Direct) { - } - - protected TestMessage(MessageTransport transport) { - this.transport = transport; - } - - [MessagePart("age", IsRequired = true)] - public int Age { get; set; } - [MessagePart("Name")] - public string Name { get; set; } - [MessagePart] - public string EmptyMember { get; set; } - [MessagePart(null)] // null name tests that Location is still the name. - public Uri Location { get; set; } - [MessagePart(IsRequired = true)] - public DateTime Timestamp { get; set; } - - #region IProtocolMessage Properties - - Version IProtocolMessage.ProtocolVersion { - get { return new Version(1, 0); } - } - - MessageProtections IProtocolMessage.RequiredProtection { - get { return MessageProtections.None; } - } - - MessageTransport IProtocolMessage.Transport { - get { return this.transport; } - } - - IDictionary<string, string> IProtocolMessage.ExtraData { - get { return this.extraData; } - } - - bool IProtocolMessage.Incoming { - get { return this.incoming; } - } - - #endregion - - #region IDirectResponseProtocolMessage Members - - public IDirectedProtocolMessage OriginatingRequest { get; set; } - - #endregion - - #region IProtocolMessage Methods - - void IProtocolMessage.EnsureValidMessage() { - if (this.EmptyMember != null || this.Age < 0) { - throw new ProtocolException(); - } - } - - #endregion - - internal void SetAsIncoming() { - this.incoming = true; - } - } -} +//-----------------------------------------------------------------------
+// <copyright file="TestMessage.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.Mocks {
+ using System;
+ using System.Collections.Generic;
+ using System.Runtime.Serialization;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.Messaging.Reflection;
+
+ internal abstract class TestMessage : IDirectResponseProtocolMessage {
+ private MessageTransport transport;
+ private Dictionary<string, string> extraData = new Dictionary<string, string>();
+ private bool incoming;
+
+ protected TestMessage()
+ : this(MessageTransport.Direct) {
+ }
+
+ protected TestMessage(MessageTransport transport) {
+ this.transport = transport;
+ }
+
+ [MessagePart("age", IsRequired = true)]
+ public int Age { get; set; }
+ [MessagePart("Name")]
+ public string Name { get; set; }
+ [MessagePart]
+ public string EmptyMember { get; set; }
+ [MessagePart(null)] // null name tests that Location is still the name.
+ public Uri Location { get; set; }
+ [MessagePart(IsRequired = true)]
+ public DateTime Timestamp { get; set; }
+
+ #region IProtocolMessage Properties
+
+ Version IMessage.Version {
+ get { return new Version(1, 0); }
+ }
+
+ MessageProtections IProtocolMessage.RequiredProtection {
+ get { return MessageProtections.None; }
+ }
+
+ MessageTransport IProtocolMessage.Transport {
+ get { return this.transport; }
+ }
+
+ IDictionary<string, string> IMessage.ExtraData {
+ get { return this.extraData; }
+ }
+
+ bool IMessage.Incoming {
+ get { return this.incoming; }
+ }
+
+ #endregion
+
+ #region IDirectResponseProtocolMessage Members
+
+ public IDirectedProtocolMessage OriginatingRequest { get; set; }
+
+ #endregion
+
+ #region IMessage Methods
+
+ void IMessage.EnsureValidMessage() {
+ if (this.EmptyMember != null || this.Age < 0) {
+ throw new ProtocolException();
+ }
+ }
+
+ #endregion
+
+ internal void SetAsIncoming() {
+ this.incoming = true;
+ }
+ }
+}
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();
+ }
+ }
+}
|