diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-09-13 13:42:46 -0700 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2008-09-13 13:42:46 -0700 |
commit | f665e1e639319918385fcc8397f8c0d5009e3bdd (patch) | |
tree | 6219f476ab24bc187eac79b501d7de73c9acd234 /src/DotNetOAuth.Test/Mocks/MockReplayProtectionBindingElement.cs | |
parent | 61650a6ec207c94cb92e27227dac75606c3e7e00 (diff) | |
download | DotNetOpenAuth-f665e1e639319918385fcc8397f8c0d5009e3bdd.zip DotNetOpenAuth-f665e1e639319918385fcc8397f8c0d5009e3bdd.tar.gz DotNetOpenAuth-f665e1e639319918385fcc8397f8c0d5009e3bdd.tar.bz2 |
Totally refactored signing, expiration and replay detection into extensible channel binding elements.
Diffstat (limited to 'src/DotNetOAuth.Test/Mocks/MockReplayProtectionBindingElement.cs')
-rw-r--r-- | src/DotNetOAuth.Test/Mocks/MockReplayProtectionBindingElement.cs | 45 |
1 files changed, 45 insertions, 0 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
+ }
+}
|