diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-02-09 07:42:31 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-02-09 07:42:31 -0800 |
commit | c5c80c48a98e5ddfe56da2894a0e961de4ca557b (patch) | |
tree | 16d6d57b860ee24387fc8bccff9e6e1298f13373 /src/DotNetOpenAuth.Test/OpenId | |
parent | 1224fab92832edca08b58b971537b426abb02024 (diff) | |
download | DotNetOpenAuth-c5c80c48a98e5ddfe56da2894a0e961de4ca557b.zip DotNetOpenAuth-c5c80c48a98e5ddfe56da2894a0e961de4ca557b.tar.gz DotNetOpenAuth-c5c80c48a98e5ddfe56da2894a0e961de4ca557b.tar.bz2 |
Constructors on all OpenID direct response messages now require the OpenID version of the message, allowing for RPs to receive response messages in versions differing from their request message.
Also added test to verify this, and OpenIdProvider error messages w/o requiring ASP.NET hosting.
Diffstat (limited to 'src/DotNetOpenAuth.Test/OpenId')
7 files changed, 31 insertions, 26 deletions
diff --git a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs index 8739ead..01c2cf5 100644 --- a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs @@ -143,7 +143,7 @@ namespace DotNetOpenAuth.Test.OpenId { var request = op.Channel.ReadFromRequest<AssociateRequest>(); // Send a response that suggests a foreign association type. - AssociateUnsuccessfulResponse renegotiateResponse = new AssociateUnsuccessfulResponse(request); + AssociateUnsuccessfulResponse renegotiateResponse = new AssociateUnsuccessfulResponse(request.Version, request); renegotiateResponse.AssociationType = "HMAC-UNKNOWN"; renegotiateResponse.SessionType = "DH-UNKNOWN"; op.Channel.Send(renegotiateResponse); @@ -167,7 +167,7 @@ namespace DotNetOpenAuth.Test.OpenId { var request = op.Channel.ReadFromRequest<AssociateRequest>(); // Send a response that suggests a no encryption. - AssociateUnsuccessfulResponse renegotiateResponse = new AssociateUnsuccessfulResponse(request); + AssociateUnsuccessfulResponse renegotiateResponse = new AssociateUnsuccessfulResponse(request.Version, request); renegotiateResponse.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA1; renegotiateResponse.SessionType = protocol.Args.SessionType.NoEncryption; op.Channel.Send(renegotiateResponse); @@ -192,7 +192,7 @@ namespace DotNetOpenAuth.Test.OpenId { var request = op.Channel.ReadFromRequest<AssociateRequest>(); // Send a mismatched response - AssociateUnsuccessfulResponse renegotiateResponse = new AssociateUnsuccessfulResponse(request); + AssociateUnsuccessfulResponse renegotiateResponse = new AssociateUnsuccessfulResponse(request.Version, request); renegotiateResponse.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA1; renegotiateResponse.SessionType = protocol.Args.SessionType.DH_SHA256; op.Channel.Send(renegotiateResponse); @@ -217,7 +217,7 @@ namespace DotNetOpenAuth.Test.OpenId { var request = op.Channel.ReadFromRequest<AssociateRequest>(); // Send a renegotiate response - AssociateUnsuccessfulResponse renegotiateResponse = new AssociateUnsuccessfulResponse(request); + AssociateUnsuccessfulResponse renegotiateResponse = new AssociateUnsuccessfulResponse(request.Version, request); renegotiateResponse.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA1; renegotiateResponse.SessionType = protocol.Args.SessionType.DH_SHA1; op.Channel.Send(renegotiateResponse); @@ -226,7 +226,7 @@ namespace DotNetOpenAuth.Test.OpenId { request = op.Channel.ReadFromRequest<AssociateRequest>(); // Send ANOTHER renegotiate response, at which point the DNOI RP should give up. - renegotiateResponse = new AssociateUnsuccessfulResponse(request); + renegotiateResponse = new AssociateUnsuccessfulResponse(request.Version, request); renegotiateResponse.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA256; renegotiateResponse.SessionType = protocol.Args.SessionType.DH_SHA256; op.Channel.Send(renegotiateResponse); diff --git a/src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs b/src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs index b20886b..d0966e7 100644 --- a/src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs @@ -134,14 +134,14 @@ namespace DotNetOpenAuth.Test.OpenId { if (positive && !sharedAssociation) { var checkauthRequest = op.Channel.ReadFromRequest<CheckAuthenticationRequest>(); - var checkauthResponse = new CheckAuthenticationResponse(checkauthRequest); + var checkauthResponse = new CheckAuthenticationResponse(checkauthRequest.Version, checkauthRequest); checkauthResponse.IsValid = checkauthRequest.IsValid; op.Channel.Send(checkauthResponse); if (!tamper) { // Respond to the replay attack. checkauthRequest = op.Channel.ReadFromRequest<CheckAuthenticationRequest>(); - checkauthResponse = new CheckAuthenticationResponse(checkauthRequest); + checkauthResponse = new CheckAuthenticationResponse(checkauthRequest.Version, checkauthRequest); checkauthResponse.IsValid = checkauthRequest.IsValid; op.Channel.Send(checkauthResponse); } diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnencryptedResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnencryptedResponseTests.cs index 16f76cf..89609f6 100644 --- a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnencryptedResponseTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnencryptedResponseTests.cs @@ -18,7 +18,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages { [TestInitialize] public void Setup() { var request = new AssociateUnencryptedRequest(Protocol.V20.Version, new Uri("http://host")); - this.response = new AssociateUnencryptedResponse(request); + this.response = new AssociateUnencryptedResponse(request.Version, request); } [TestMethod] diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnsuccessfulResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnsuccessfulResponseTests.cs index b6f6914..e803400 100644 --- a/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnsuccessfulResponseTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/Messages/AssociateUnsuccessfulResponseTests.cs @@ -18,7 +18,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages { [TestInitialize] public void Setup() { var request = new AssociateUnencryptedRequest(Protocol.V20.Version, new Uri("http://host")); - this.response = new AssociateUnsuccessfulResponse(request); + this.response = new AssociateUnsuccessfulResponse(request.Version, request); } [TestMethod] diff --git a/src/DotNetOpenAuth.Test/OpenId/Messages/DirectErrorResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Messages/DirectErrorResponseTests.cs index afd3e0f..3a5e824 100644 --- a/src/DotNetOpenAuth.Test/OpenId/Messages/DirectErrorResponseTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/Messages/DirectErrorResponseTests.cs @@ -21,7 +21,7 @@ namespace DotNetOpenAuth.Test.OpenId.Messages { base.SetUp(); var request = new AssociateUnencryptedRequest(Protocol.V20.Version, new Uri("http://host")); - this.response = new DirectErrorResponse(request); + this.response = new DirectErrorResponse(request.Version, request); } [TestMethod] diff --git a/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs b/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs index 6db5d1b..b45dc1b 100644 --- a/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs +++ b/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs @@ -126,8 +126,12 @@ namespace DotNetOpenAuth.Test.OpenId { /// 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) { + while (!((CoordinatingChannel)provider.Channel).RemoteChannel.IsDisposed) { + IRequest request = provider.GetRequest(); + if (request == null) { + continue; + } + if (!request.IsResponseReady) { var authRequest = (DotNetOpenAuth.OpenId.Provider.IAuthenticationRequest)request; switch (this.AutoProviderScenario) { diff --git a/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs b/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs index bb035c3..114a135 100644 --- a/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs @@ -101,21 +101,22 @@ namespace DotNetOpenAuth.Test.OpenId.Provider { coordinator.Run(); } - ////[TestMethod] - ////public void BadRequestsGenerateValidErrorResponses() { - //// var coordinator = new OpenIdCoordinator( - //// rp => { - //// var nonOpenIdMessage = new Mocks.TestDirectedMessage(); - //// nonOpenIdMessage.Recipient = OPUri; - //// nonOpenIdMessage.HttpMethods = HttpDeliveryMethods.PostRequest; - //// MessagingTestBase.GetStandardTestMessage(MessagingTestBase.FieldFill.AllRequired, nonOpenIdMessage); - //// var response = rp.Channel.Request<DirectErrorResponse>(nonOpenIdMessage); - //// Assert.IsNotNull(response.ErrorMessage); - //// }, - //// AutoProvider); + [TestMethod] + public void BadRequestsGenerateValidErrorResponses() { + var coordinator = new OpenIdCoordinator( + rp => { + var nonOpenIdMessage = new Mocks.TestDirectedMessage(); + nonOpenIdMessage.Recipient = OPUri; + nonOpenIdMessage.HttpMethods = HttpDeliveryMethods.PostRequest; + MessagingTestBase.GetStandardTestMessage(MessagingTestBase.FieldFill.AllRequired, nonOpenIdMessage); + var response = rp.Channel.Request<DirectErrorResponse>(nonOpenIdMessage); + Assert.IsNotNull(response.ErrorMessage); + Assert.AreEqual(Protocol.Default.Version, response.Version); + }, + AutoProvider); - //// coordinator.Run(); - ////} + coordinator.Run(); + } [TestMethod] public void BadRequestsGenerateValidErrorResponsesHosted() { |