summaryrefslogtreecommitdiffstats
path: root/src/DotNetOAuth.Test/Mocks
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOAuth.Test/Mocks')
-rw-r--r--src/DotNetOAuth.Test/Mocks/MockReplayProtectionBindingElement.cs45
-rw-r--r--src/DotNetOAuth.Test/Mocks/MockSigningBindingElement.cs41
-rw-r--r--src/DotNetOAuth.Test/Mocks/MockTransformationBindingElement.cs49
-rw-r--r--src/DotNetOAuth.Test/Mocks/TestChannel.cs4
-rw-r--r--src/DotNetOAuth.Test/Mocks/TestReplayProtectedChannel.cs35
-rw-r--r--src/DotNetOAuth.Test/Mocks/TestSigningChannel.cs29
6 files changed, 137 insertions, 66 deletions
diff --git a/src/DotNetOAuth.Test/Mocks/MockReplayProtectionBindingElement.cs b/src/DotNetOAuth.Test/Mocks/MockReplayProtectionBindingElement.cs
new file mode 100644
index 0000000..ff1d709
--- /dev/null
+++ b/src/DotNetOAuth.Test/Mocks/MockReplayProtectionBindingElement.cs
@@ -0,0 +1,45 @@
+//-----------------------------------------------------------------------
+// <copyright file="MockReplayProtectionBindingElement.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth.Test.Mocks {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using DotNetOAuth.Messaging;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ internal class MockReplayProtectionBindingElement : IChannelBindingElement {
+ private bool messageReceived;
+
+ #region IChannelBindingElement Members
+
+ ChannelProtection IChannelBindingElement.Protection {
+ get { return ChannelProtection.ReplayProtection; }
+ }
+
+ void IChannelBindingElement.PrepareMessageForSending(IProtocolMessage message) {
+ var replayMessage = message as IReplayProtectedProtocolMessage;
+ if (replayMessage != null) {
+ replayMessage.Nonce = "someNonce";
+ }
+ }
+
+ void IChannelBindingElement.PrepareMessageForReceiving(IProtocolMessage message) {
+ var replayMessage = message as IReplayProtectedProtocolMessage;
+ if (replayMessage != null) {
+ Assert.AreEqual("someNonce", replayMessage.Nonce, "The nonce didn't serialize correctly, or something");
+ // this mock implementation passes the first time and fails subsequent times.
+ if (this.messageReceived) {
+ throw new ReplayedMessageException(message);
+ }
+ this.messageReceived = true;
+ }
+ }
+
+ #endregion
+ }
+}
diff --git a/src/DotNetOAuth.Test/Mocks/MockSigningBindingElement.cs b/src/DotNetOAuth.Test/Mocks/MockSigningBindingElement.cs
new file mode 100644
index 0000000..5cf8be6
--- /dev/null
+++ b/src/DotNetOAuth.Test/Mocks/MockSigningBindingElement.cs
@@ -0,0 +1,41 @@
+//-----------------------------------------------------------------------
+// <copyright file="MockSigningBindingElement.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth.Test.Mocks {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using DotNetOAuth.Messaging;
+
+ internal class MockSigningBindingElement : IChannelBindingElement {
+ internal const string MessageSignature = "mocksignature";
+
+ #region IChannelBindingElement Members
+
+ ChannelProtection IChannelBindingElement.Protection {
+ get { return ChannelProtection.TamperProtection; }
+ }
+
+ void IChannelBindingElement.PrepareMessageForSending(IProtocolMessage message) {
+ ISignedProtocolMessage signedMessage = message as ISignedProtocolMessage;
+ if (signedMessage != null) {
+ signedMessage.Signature = MessageSignature;
+ }
+ }
+
+ void IChannelBindingElement.PrepareMessageForReceiving(IProtocolMessage message) {
+ ISignedProtocolMessage signedMessage = message as ISignedProtocolMessage;
+ if (signedMessage != null) {
+ if (signedMessage.Signature != MessageSignature) {
+ throw new InvalidSignatureException(message);
+ }
+ }
+ }
+
+ #endregion
+ }
+}
diff --git a/src/DotNetOAuth.Test/Mocks/MockTransformationBindingElement.cs b/src/DotNetOAuth.Test/Mocks/MockTransformationBindingElement.cs
new file mode 100644
index 0000000..7a1320b
--- /dev/null
+++ b/src/DotNetOAuth.Test/Mocks/MockTransformationBindingElement.cs
@@ -0,0 +1,49 @@
+//-----------------------------------------------------------------------
+// <copyright file="MockTransformationBindingElement.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth.Test.Mocks {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using DotNetOAuth.Messaging;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ internal class MockTransformationBindingElement : IChannelBindingElement {
+ private string transform;
+
+ internal MockTransformationBindingElement(string transform) {
+ if (transform == null) {
+ throw new ArgumentNullException("transform");
+ }
+
+ this.transform = transform;
+ }
+
+ #region IChannelBindingElement Members
+
+ ChannelProtection IChannelBindingElement.Protection {
+ get { return ChannelProtection.None; }
+ }
+
+ void IChannelBindingElement.PrepareMessageForSending(IProtocolMessage message) {
+ var testMessage = message as TestMessage;
+ if (testMessage != null) {
+ testMessage.Name = this.transform + testMessage.Name;
+ }
+ }
+
+ void IChannelBindingElement.PrepareMessageForReceiving(IProtocolMessage message) {
+ var testMessage = message as TestMessage;
+ if (testMessage != null) {
+ StringAssert.StartsWith(testMessage.Name, this.transform);
+ testMessage.Name = testMessage.Name.Substring(this.transform.Length);
+ }
+ }
+
+ #endregion
+ }
+}
diff --git a/src/DotNetOAuth.Test/Mocks/TestChannel.cs b/src/DotNetOAuth.Test/Mocks/TestChannel.cs
index 2431af1..b69b756 100644
--- a/src/DotNetOAuth.Test/Mocks/TestChannel.cs
+++ b/src/DotNetOAuth.Test/Mocks/TestChannel.cs
@@ -16,8 +16,8 @@ namespace DotNetOAuth.Test.Mocks {
: this(new TestMessageTypeProvider()) {
}
- internal TestChannel(IMessageTypeProvider messageTypeProvider)
- : base(messageTypeProvider) {
+ internal TestChannel(IMessageTypeProvider messageTypeProvider, params IChannelBindingElement[] bindingElements)
+ : base(messageTypeProvider, bindingElements) {
}
protected override IProtocolMessage RequestInternal(IDirectedProtocolMessage request) {
diff --git a/src/DotNetOAuth.Test/Mocks/TestReplayProtectedChannel.cs b/src/DotNetOAuth.Test/Mocks/TestReplayProtectedChannel.cs
deleted file mode 100644
index d57b72c..0000000
--- a/src/DotNetOAuth.Test/Mocks/TestReplayProtectedChannel.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="TestReplayProtectedChannel.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Test.Mocks {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using DotNetOAuth.Messaging;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
-
- internal class TestReplayProtectedChannel : TestSigningChannel {
- private bool messageReceived;
-
- internal TestReplayProtectedChannel()
- : base(true, true) {
- }
-
- protected override bool IsMessageReplayed(DotNetOAuth.Messaging.IReplayProtectedProtocolMessage message) {
- Assert.AreEqual("someNonce", message.Nonce, "The nonce didn't serialize correctly, or something");
- // this mock implementation passes the first time and fails subsequent times.
- bool replay = this.messageReceived;
- this.messageReceived = true;
- return replay;
- }
-
- protected override void ApplyReplayProtection(IReplayProtectedProtocolMessage message) {
- message.Nonce = "someNonce";
- // no-op
- }
- }
-}
diff --git a/src/DotNetOAuth.Test/Mocks/TestSigningChannel.cs b/src/DotNetOAuth.Test/Mocks/TestSigningChannel.cs
deleted file mode 100644
index 60037ee..0000000
--- a/src/DotNetOAuth.Test/Mocks/TestSigningChannel.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="TestSigningChannel.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Test.Mocks {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using DotNetOAuth.Messaging;
-
- internal class TestSigningChannel : TestChannel {
- internal const string MessageSignature = "mocksignature";
-
- internal TestSigningChannel(bool expiring, bool replay)
- : base(new TestMessageTypeProvider(true, expiring, replay)) {
- }
-
- protected override void Sign(ISignedProtocolMessage message) {
- message.Signature = MessageSignature;
- }
-
- protected override bool IsSignatureValid(ISignedProtocolMessage message) {
- return message.Signature == MessageSignature;
- }
- }
-}