summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-01-03 08:37:01 -0800
committerAndrew <andrewarnott@gmail.com>2009-01-03 08:37:01 -0800
commitbc816ee12352c93eb6c47796c0a9cb76a3f68d0b (patch)
tree19a27ea231f165fef761327e61d88e5c41ad0d4d /src
parentd1cdbd8cbc5ee5901ff8d4e81ba7b3a84f1188dd (diff)
downloadDotNetOpenAuth-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')
-rw-r--r--src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj1
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs9
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/CoordinatingUserAgentResponse.cs29
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs8
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionTestBase.cs4
-rw-r--r--src/DotNetOpenAuth/Messaging/UserAgentResponse.cs2
-rw-r--r--src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs2
7 files changed, 44 insertions, 11 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();
}
diff --git a/src/DotNetOpenAuth/Messaging/UserAgentResponse.cs b/src/DotNetOpenAuth/Messaging/UserAgentResponse.cs
index f093161..0e47945 100644
--- a/src/DotNetOpenAuth/Messaging/UserAgentResponse.cs
+++ b/src/DotNetOpenAuth/Messaging/UserAgentResponse.cs
@@ -136,7 +136,7 @@ namespace DotNetOpenAuth.Messaging {
/// Automatically sends the appropriate response to the user agent.
/// Requires a current HttpContext.
/// </summary>
- public void Send() {
+ public virtual void Send() {
if (HttpContext.Current == null) {
throw new InvalidOperationException(MessagingStrings.CurrentHttpContextRequired);
}
diff --git a/src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs b/src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs
index 3ee91f1..d1f28b3 100644
--- a/src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs
+++ b/src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs
@@ -74,7 +74,7 @@ namespace DotNetOpenAuth.OpenId.Provider {
var associateRequest = request as AssociateRequest;
if (associateRequest != null) {
IProtocolMessage response = associateRequest.CreateResponse(this.AssociationStore);
- this.Channel.Send(response);
+ this.Channel.Send(response).Send();
} else {
// TODO: code here
throw new NotImplementedException();