diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-01-03 08:37:01 -0800 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2009-01-03 08:37:01 -0800 |
commit | bc816ee12352c93eb6c47796c0a9cb76a3f68d0b (patch) | |
tree | 19a27ea231f165fef761327e61d88e5c41ad0d4d /src/DotNetOpenAuth.Test | |
parent | d1cdbd8cbc5ee5901ff8d4e81ba7b3a84f1188dd (diff) | |
download | DotNetOpenAuth-bc816ee12352c93eb6c47796c0a9cb76a3f68d0b.zip DotNetOpenAuth-bc816ee12352c93eb6c47796c0a9cb76a3f68d0b.tar.gz DotNetOpenAuth-bc816ee12352c93eb6c47796c0a9cb76a3f68d0b.tar.bz2 |
Fixed mock CoordinatingChannel to send direct responses and indirect messages while more truly simulating the ordinary channel experience.
Diffstat (limited to 'src/DotNetOpenAuth.Test')
5 files changed, 42 insertions, 9 deletions
diff --git a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj index e763374..2ab2db7 100644 --- a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj +++ b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj @@ -77,6 +77,7 @@ <Compile Include="Messaging\Reflection\MessagePartTests.cs" /> <Compile Include="Messaging\Reflection\ValueMappingTests.cs" /> <Compile Include="Mocks\CoordinatingChannel.cs" /> + <Compile Include="Mocks\CoordinatingUserAgentResponse.cs" /> <Compile Include="Mocks\InMemoryTokenManager.cs" /> <Compile Include="Mocks\MockHttpRequest.cs" /> <Compile Include="Mocks\MockIdentifier.cs" /> diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs index 2c10db9..6fe5248 100644 --- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs +++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs @@ -44,6 +44,11 @@ namespace DotNetOpenAuth.Test.Mocks { this.VerifyMessageAfterReceiving(CloneSerializedParts(message)); } + internal void PostMessage(IProtocolMessage message) { + this.incomingMessage = CloneSerializedParts(message); + this.incomingMessageSignal.Set(); + } + protected internal override HttpRequestInfo GetRequestFromContext() { return new HttpRequestInfo((IDirectedProtocolMessage)this.AwaitIncomingMessage()); } @@ -62,9 +67,7 @@ namespace DotNetOpenAuth.Test.Mocks { protected override UserAgentResponse SendDirectMessageResponse(IProtocolMessage response) { this.ProcessMessageFilter(response, true); - this.RemoteChannel.incomingMessage = CloneSerializedParts(response); - this.RemoteChannel.incomingMessageSignal.Set(); - return null; + return new CoordinatingUserAgentResponse(CloneSerializedParts(response), this.RemoteChannel); } protected override UserAgentResponse SendIndirectMessage(IDirectedProtocolMessage message) { diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingUserAgentResponse.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingUserAgentResponse.cs new file mode 100644 index 0000000..4897e98 --- /dev/null +++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingUserAgentResponse.cs @@ -0,0 +1,29 @@ +//----------------------------------------------------------------------- +// <copyright file="CoordinatingUserAgentResponse.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.Test.Mocks { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using DotNetOpenAuth.Messaging; + + internal class CoordinatingUserAgentResponse : UserAgentResponse { + private CoordinatingChannel receivingChannel; + + internal CoordinatingUserAgentResponse(IProtocolMessage message, CoordinatingChannel receivingChannel) { + ErrorUtilities.VerifyArgumentNotNull(message, "message"); + ErrorUtilities.VerifyArgumentNotNull(receivingChannel, "receivingChannel"); + + this.receivingChannel = receivingChannel; + this.OriginalMessage = message; + } + + public override void Send() { + this.receivingChannel.PostMessage(this.OriginalMessage); + } + } +} diff --git a/src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs b/src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs index d05ddd8..5ac1deb 100644 --- a/src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs @@ -83,7 +83,7 @@ namespace DotNetOpenAuth.Test.OpenId { request.ClaimedIdentifier = "http://claimedid"; request.LocalIdentifier = "http://localid"; request.ReturnTo = RPUri; - rp.Channel.Send(request); + rp.Channel.Send(request).Send(); if (positive) { if (tamper) { try { @@ -132,20 +132,20 @@ namespace DotNetOpenAuth.Test.OpenId { } else { response = new NegativeAssertionResponse(request) { UserSetupUrl = userSetupUrl }; } - op.Channel.Send(response); + op.Channel.Send(response).Send(); if (positive && !sharedAssociation) { var checkauthRequest = op.Channel.ReadFromRequest<CheckAuthenticationRequest>(); var checkauthResponse = new CheckAuthenticationResponse(checkauthRequest); checkauthResponse.IsValid = checkauthRequest.IsValid; - op.Channel.Send(checkauthResponse); + op.Channel.Send(checkauthResponse).Send(); if (!tamper) { // Respond to the replay attack. checkauthRequest = op.Channel.ReadFromRequest<CheckAuthenticationRequest>(); checkauthResponse = new CheckAuthenticationResponse(checkauthRequest); checkauthResponse.IsValid = checkauthRequest.IsValid; - op.Channel.Send(checkauthResponse); + op.Channel.Send(checkauthResponse).Send(); } } }); diff --git a/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionTestBase.cs b/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionTestBase.cs index c616ed3..09a9a8a 100644 --- a/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionTestBase.cs +++ b/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionTestBase.cs @@ -35,7 +35,7 @@ namespace DotNetOpenAuth.Test.OpenId.Extensions { requestBase.Extensions.Add(extension); } - rp.Channel.Send(requestBase); + rp.Channel.Send(requestBase).Send(); var response = rp.Channel.ReadFromRequest<PositiveAssertionResponse>(); var receivedResponses = response.Extensions.Cast<IOpenIdMessageExtension>(); @@ -53,7 +53,7 @@ namespace DotNetOpenAuth.Test.OpenId.Extensions { response.Extensions.Add(extensionResponse); } - op.Channel.Send(response); + op.Channel.Send(response).Send(); }); coordinator.Run(); } |