summaryrefslogtreecommitdiffstats
path: root/src/DotNetOAuth.Test
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOAuth.Test')
-rw-r--r--src/DotNetOAuth.Test/DotNetOAuth.Test.csproj2
-rw-r--r--src/DotNetOAuth.Test/Messaging/Bindings/StandardExpirationBindingElementTests.cs (renamed from src/DotNetOAuth.Test/Messaging/StandardExpirationBindingElementTests.cs)2
-rw-r--r--src/DotNetOAuth.Test/Messaging/ChannelTests.cs13
-rw-r--r--src/DotNetOAuth.Test/Messaging/MessagingTestBase.cs13
-rw-r--r--src/DotNetOAuth.Test/Mocks/MockReplayProtectionBindingElement.cs10
-rw-r--r--src/DotNetOAuth.Test/Mocks/MockSigningBindingElement.cs10
-rw-r--r--src/DotNetOAuth.Test/Mocks/MockTransformationBindingElement.cs10
-rw-r--r--src/DotNetOAuth.Test/Mocks/TestDirectedMessage.cs6
-rw-r--r--src/DotNetOAuth.Test/Mocks/TestSignedDirectedMessage.cs4
9 files changed, 58 insertions, 12 deletions
diff --git a/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj b/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj
index 7d6c942..09b5974 100644
--- a/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj
+++ b/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj
@@ -64,7 +64,7 @@
<Compile Include="Messaging\DictionaryXmlReaderTests.cs" />
<Compile Include="Messaging\HttpRequestInfoTests.cs" />
<Compile Include="Messaging\ProtocolExceptionTests.cs" />
- <Compile Include="Messaging\StandardExpirationBindingElementTests.cs" />
+ <Compile Include="Messaging\Bindings\StandardExpirationBindingElementTests.cs" />
<Compile Include="Mocks\MockTransformationBindingElement.cs" />
<Compile Include="Mocks\MockReplayProtectionBindingElement.cs" />
<Compile Include="Mocks\TestBaseMessage.cs" />
diff --git a/src/DotNetOAuth.Test/Messaging/StandardExpirationBindingElementTests.cs b/src/DotNetOAuth.Test/Messaging/Bindings/StandardExpirationBindingElementTests.cs
index 84b12c6..6ba1cfc 100644
--- a/src/DotNetOAuth.Test/Messaging/StandardExpirationBindingElementTests.cs
+++ b/src/DotNetOAuth.Test/Messaging/Bindings/StandardExpirationBindingElementTests.cs
@@ -4,7 +4,7 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace DotNetOAuth.Test.Messaging {
+namespace DotNetOAuth.Test.Messaging.Bindings {
using System;
using DotNetOAuth.Messaging;
using DotNetOAuth.Messaging.Bindings;
diff --git a/src/DotNetOAuth.Test/Messaging/ChannelTests.cs b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs
index e4381a6..ac7e8d5 100644
--- a/src/DotNetOAuth.Test/Messaging/ChannelTests.cs
+++ b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs
@@ -285,5 +285,18 @@ namespace DotNetOAuth.Test.Messaging {
Assert.AreSame(expire, channel.BindingElements[3]);
Assert.AreSame(sign, channel.BindingElements[4]);
}
+
+ [TestMethod, ExpectedException(typeof(UnprotectedMessageException))]
+ public void InsufficientlyProtectedMessageSent() {
+ var message = new TestSignedDirectedMessage(MessageTransport.Direct);
+ message.Recipient = new Uri("http://localtest");
+ this.Channel.Send(message);
+ }
+
+ [TestMethod, ExpectedException(typeof(UnprotectedMessageException))]
+ public void InsufficientlyProtectedMessageReceived() {
+ this.Channel = CreateChannel(MessageProtection.None, MessageProtection.TamperProtection);
+ this.ParameterizedReceiveProtectedTest(DateTime.Now, false);
+ }
}
}
diff --git a/src/DotNetOAuth.Test/Messaging/MessagingTestBase.cs b/src/DotNetOAuth.Test/Messaging/MessagingTestBase.cs
index b0b4eba..a21b000 100644
--- a/src/DotNetOAuth.Test/Messaging/MessagingTestBase.cs
+++ b/src/DotNetOAuth.Test/Messaging/MessagingTestBase.cs
@@ -59,18 +59,25 @@ namespace DotNetOAuth.Test {
}
internal static Channel CreateChannel(MessageProtection capability, MessageProtection recognition) {
- bool signing = false, expiration = false, replay = false;
var bindingElements = new List<IChannelBindingElement>();
if (capability >= MessageProtection.TamperProtection) {
bindingElements.Add(new MockSigningBindingElement());
- signing = true;
}
if (capability >= MessageProtection.Expiration) {
bindingElements.Add(new StandardExpirationBindingElement());
- expiration = true;
}
if (capability >= MessageProtection.ReplayProtection) {
bindingElements.Add(new MockReplayProtectionBindingElement());
+ }
+
+ bool signing = false, expiration = false, replay = false;
+ if (recognition >= MessageProtection.TamperProtection) {
+ signing = true;
+ }
+ if (recognition >= MessageProtection.Expiration) {
+ expiration = true;
+ }
+ if (recognition >= MessageProtection.ReplayProtection) {
replay = true;
}
diff --git a/src/DotNetOAuth.Test/Mocks/MockReplayProtectionBindingElement.cs b/src/DotNetOAuth.Test/Mocks/MockReplayProtectionBindingElement.cs
index 1b80b5b..805ace5 100644
--- a/src/DotNetOAuth.Test/Mocks/MockReplayProtectionBindingElement.cs
+++ b/src/DotNetOAuth.Test/Mocks/MockReplayProtectionBindingElement.cs
@@ -18,14 +18,17 @@ namespace DotNetOAuth.Test.Mocks {
get { return MessageProtection.ReplayProtection; }
}
- void IChannelBindingElement.PrepareMessageForSending(IProtocolMessage message) {
+ bool IChannelBindingElement.PrepareMessageForSending(IProtocolMessage message) {
var replayMessage = message as IReplayProtectedProtocolMessage;
if (replayMessage != null) {
replayMessage.Nonce = "someNonce";
+ return true;
}
+
+ return false;
}
- void IChannelBindingElement.PrepareMessageForReceiving(IProtocolMessage message) {
+ bool 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");
@@ -34,7 +37,10 @@ namespace DotNetOAuth.Test.Mocks {
throw new ReplayedMessageException(message);
}
this.messageReceived = true;
+ return true;
}
+
+ return false;
}
#endregion
diff --git a/src/DotNetOAuth.Test/Mocks/MockSigningBindingElement.cs b/src/DotNetOAuth.Test/Mocks/MockSigningBindingElement.cs
index 8aa8020..3dc9039 100644
--- a/src/DotNetOAuth.Test/Mocks/MockSigningBindingElement.cs
+++ b/src/DotNetOAuth.Test/Mocks/MockSigningBindingElement.cs
@@ -21,20 +21,26 @@ namespace DotNetOAuth.Test.Mocks {
get { return MessageProtection.TamperProtection; }
}
- void IChannelBindingElement.PrepareMessageForSending(IProtocolMessage message) {
+ bool IChannelBindingElement.PrepareMessageForSending(IProtocolMessage message) {
ISignedOAuthMessage signedMessage = message as ISignedOAuthMessage;
if (signedMessage != null) {
signedMessage.Signature = MessageSignature;
+ return true;
}
+
+ return false;
}
- void IChannelBindingElement.PrepareMessageForReceiving(IProtocolMessage message) {
+ bool IChannelBindingElement.PrepareMessageForReceiving(IProtocolMessage message) {
ISignedOAuthMessage signedMessage = message as ISignedOAuthMessage;
if (signedMessage != null) {
if (signedMessage.Signature != MessageSignature) {
throw new InvalidSignatureException(message);
}
+ return true;
}
+
+ return false;
}
#endregion
diff --git a/src/DotNetOAuth.Test/Mocks/MockTransformationBindingElement.cs b/src/DotNetOAuth.Test/Mocks/MockTransformationBindingElement.cs
index cd75e34..a569754 100644
--- a/src/DotNetOAuth.Test/Mocks/MockTransformationBindingElement.cs
+++ b/src/DotNetOAuth.Test/Mocks/MockTransformationBindingElement.cs
@@ -29,19 +29,25 @@ namespace DotNetOAuth.Test.Mocks {
get { return MessageProtection.None; }
}
- void IChannelBindingElement.PrepareMessageForSending(IProtocolMessage message) {
+ bool IChannelBindingElement.PrepareMessageForSending(IProtocolMessage message) {
var testMessage = message as TestMessage;
if (testMessage != null) {
testMessage.Name = this.transform + testMessage.Name;
+ return true;
}
+
+ return false;
}
- void IChannelBindingElement.PrepareMessageForReceiving(IProtocolMessage message) {
+ bool 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);
+ return true;
}
+
+ return false;
}
#endregion
diff --git a/src/DotNetOAuth.Test/Mocks/TestDirectedMessage.cs b/src/DotNetOAuth.Test/Mocks/TestDirectedMessage.cs
index 9e4cd38..30a290d 100644
--- a/src/DotNetOAuth.Test/Mocks/TestDirectedMessage.cs
+++ b/src/DotNetOAuth.Test/Mocks/TestDirectedMessage.cs
@@ -39,7 +39,7 @@ namespace DotNetOAuth.Test.Mocks {
}
MessageProtection IProtocolMessage.RequiredProtection {
- get { return MessageProtection.None; }
+ get { return this.RequiredProtection; }
}
MessageTransport IProtocolMessage.Transport {
@@ -53,5 +53,9 @@ namespace DotNetOAuth.Test.Mocks {
}
#endregion
+
+ protected virtual MessageProtection RequiredProtection {
+ get { return MessageProtection.None; }
+ }
}
}
diff --git a/src/DotNetOAuth.Test/Mocks/TestSignedDirectedMessage.cs b/src/DotNetOAuth.Test/Mocks/TestSignedDirectedMessage.cs
index 81cae4f..f051173 100644
--- a/src/DotNetOAuth.Test/Mocks/TestSignedDirectedMessage.cs
+++ b/src/DotNetOAuth.Test/Mocks/TestSignedDirectedMessage.cs
@@ -24,5 +24,9 @@ namespace DotNetOAuth.Test.Mocks {
}
#endregion
+
+ protected override MessageProtection RequiredProtection {
+ get { return MessageProtection.TamperProtection; }
+ }
}
}