summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-11-18 07:33:29 -0800
committerAndrew <andrewarnott@gmail.com>2008-11-18 07:33:29 -0800
commit587c9b421f3f0b3607662050c1b1546f203cc8f9 (patch)
tree896aa100bd0fdc00f9f7891cc53d8192247d85f1 /src/DotNetOpenAuth.Test
parent6c26c72a01e8ae62474f78e1d44b849c673f8e4e (diff)
downloadDotNetOpenAuth-587c9b421f3f0b3607662050c1b1546f203cc8f9.zip
DotNetOpenAuth-587c9b421f3f0b3607662050c1b1546f203cc8f9.tar.gz
DotNetOpenAuth-587c9b421f3f0b3607662050c1b1546f203cc8f9.tar.bz2
Moved association creation logic from test assembly to library.
Diffstat (limited to 'src/DotNetOpenAuth.Test')
-rw-r--r--src/DotNetOpenAuth.Test/CoordinatorBase.cs4
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs26
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/OpenIdCoordinator.cs4
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/ScenarioTests.cs16
4 files changed, 40 insertions, 10 deletions
diff --git a/src/DotNetOpenAuth.Test/CoordinatorBase.cs b/src/DotNetOpenAuth.Test/CoordinatorBase.cs
index 9c16eac..4463dde 100644
--- a/src/DotNetOpenAuth.Test/CoordinatorBase.cs
+++ b/src/DotNetOpenAuth.Test/CoordinatorBase.cs
@@ -22,6 +22,10 @@ namespace DotNetOpenAuth.Test {
this.party2Action = party2Action;
}
+ protected internal Action<IProtocolMessage> IncomingMessageFilter { get; set; }
+
+ protected internal Action<IProtocolMessage> OutgoingMessageFilter { get; set; }
+
internal abstract void Run();
protected void RunCore(T1 party1Object, T2 party2Object) {
diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
index bba9285..bb094af 100644
--- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
@@ -17,12 +17,16 @@ namespace DotNetOpenAuth.Test.Mocks {
private EventWaitHandle incomingMessageSignal = new AutoResetEvent(false);
private IProtocolMessage incomingMessage;
private Response incomingRawResponse;
+ private Action<IProtocolMessage> incomingMessageFilter;
+ private Action<IProtocolMessage> outgoingMessageFilter;
- internal CoordinatingChannel(Channel wrappedChannel)
+ internal CoordinatingChannel(Channel wrappedChannel, Action<IProtocolMessage> incomingMessageFilter, Action<IProtocolMessage> outgoingMessageFilter)
: base(GetMessageTypeProvider(wrappedChannel), wrappedChannel.BindingElements.ToArray()) {
ErrorUtilities.VerifyArgumentNotNull(wrappedChannel, "wrappedChannel");
this.wrappedChannel = wrappedChannel;
+ this.incomingMessageFilter = incomingMessageFilter;
+ this.outgoingMessageFilter = outgoingMessageFilter;
}
/// <summary>
@@ -35,26 +39,32 @@ namespace DotNetOpenAuth.Test.Mocks {
}
protected override IProtocolMessage RequestInternal(IDirectedProtocolMessage request) {
+ this.ProcessMessageFilter(request, true);
HttpRequestInfo requestInfo = this.SpoofHttpMethod(request);
// Drop the outgoing message in the other channel's in-slot and let them know it's there.
this.RemoteChannel.incomingMessage = requestInfo.Message;
this.RemoteChannel.incomingMessageSignal.Set();
// Now wait for a response...
- return this.AwaitIncomingMessage();
+ IProtocolMessage response = this.AwaitIncomingMessage();
+ this.ProcessMessageFilter(response, false);
+ return response;
}
protected override Response SendDirectMessageResponse(IProtocolMessage response) {
+ this.ProcessMessageFilter(response, true);
this.RemoteChannel.incomingMessage = CloneSerializedParts(response, null);
this.RemoteChannel.incomingMessageSignal.Set();
return null;
}
protected override Response SendIndirectMessage(IDirectedProtocolMessage message) {
+ this.ProcessMessageFilter(message, true);
// In this mock transport, direct and indirect messages are the same.
return this.SendDirectMessageResponse(message);
}
protected override IDirectedProtocolMessage ReadFromRequestInternal(HttpRequestInfo request) {
+ this.ProcessMessageFilter(request.Message, false);
return request.Message;
}
@@ -104,5 +114,17 @@ namespace DotNetOpenAuth.Test.Mocks {
this.incomingMessage = null;
return response;
}
+
+ private void ProcessMessageFilter(IProtocolMessage message, bool outgoing) {
+ if (outgoing) {
+ if (this.outgoingMessageFilter != null) {
+ this.outgoingMessageFilter(message);
+ }
+ } else {
+ if (this.incomingMessageFilter != null) {
+ this.incomingMessageFilter(message);
+ }
+ }
+ }
}
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/OpenIdCoordinator.cs b/src/DotNetOpenAuth.Test/OpenId/OpenIdCoordinator.cs
index 78fb921..6ec2f38 100644
--- a/src/DotNetOpenAuth.Test/OpenId/OpenIdCoordinator.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/OpenIdCoordinator.cs
@@ -21,8 +21,8 @@ namespace DotNetOpenAuth.Test.OpenId {
OpenIdRelyingParty rp = new OpenIdRelyingParty();
OpenIdProvider op = new OpenIdProvider();
- var rpCoordinatingChannel = new CoordinatingChannel(rp.Channel);
- var opCoordinatingChannel = new CoordinatingChannel(op.Channel);
+ var rpCoordinatingChannel = new CoordinatingChannel(rp.Channel, this.IncomingMessageFilter, this.OutgoingMessageFilter);
+ var opCoordinatingChannel = new CoordinatingChannel(op.Channel, this.IncomingMessageFilter, this.OutgoingMessageFilter);
rpCoordinatingChannel.RemoteChannel = opCoordinatingChannel;
opCoordinatingChannel.RemoteChannel = rpCoordinatingChannel;
diff --git a/src/DotNetOpenAuth.Test/OpenId/ScenarioTests.cs b/src/DotNetOpenAuth.Test/OpenId/ScenarioTests.cs
index f3d78e8..ddcae42 100644
--- a/src/DotNetOpenAuth.Test/OpenId/ScenarioTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/ScenarioTests.cs
@@ -21,14 +21,11 @@ namespace DotNetOpenAuth.Test.OpenId {
[TestMethod]
public void AssociateDiffieHellmanMessages() {
Association rpAssociation = null, opAssociation = null;
+ AssociateDiffieHellmanResponse associateResponse = null;
OpenIdCoordinator coordinator = new OpenIdCoordinator(
rp => {
- var associateRequest = new AssociateDiffieHellmanRequest(new Uri("http://host"));
- associateRequest.AssociationType = Protocol.Args.SignatureAlgorithm.HMAC_SHA1;
- associateRequest.SessionType = Protocol.Args.SessionType.DH_SHA1;
- associateRequest.InitializeRequest();
- var associateResponse = rp.Channel.Request<AssociateDiffieHellmanResponse>(associateRequest);
- rpAssociation = associateResponse.CreateAssociation(associateRequest);
+ var op = new ProviderEndpointDescription(new Uri("http://host"), Protocol);
+ rpAssociation = rp.GetAssociation(op);
Assert.IsNotNull(rpAssociation);
Assert.IsFalse(MessagingUtilities.AreEquivalent(associateResponse.EncodedMacKey, rpAssociation.SecretKey), "Key should have been encrypted.");
},
@@ -39,6 +36,13 @@ namespace DotNetOpenAuth.Test.OpenId {
opAssociation = response.CreateAssociation(associateRequest);
op.Channel.Send(response);
});
+ coordinator.IncomingMessageFilter = (message) => {
+ var associateResponseMessage = message as AssociateDiffieHellmanResponse;
+ if (associateResponseMessage != null) {
+ // capture this message so we can analyze it later
+ associateResponse = associateResponseMessage;
+ }
+ };
coordinator.Run();
Assert.AreEqual(opAssociation.Handle, rpAssociation.Handle);
Assert.IsTrue(Math.Abs(opAssociation.SecondsTillExpiration - rpAssociation.SecondsTillExpiration) < 60);