Skip to content
This repository was archived by the owner on Mar 20, 2019. It is now read-only.

Commit 209d9ee

Browse files
committed
Fixed StyleCop issues and added a couple of HMAC signature tests.
1 parent 44cc811 commit 209d9ee

7 files changed

Lines changed: 99 additions & 1 deletion

File tree

File renamed without changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//-----------------------------------------------------------------------
2+
// <copyright file="HmacSha1SigningBindingElementTests.cs" company="Andrew Arnott">
3+
// Copyright (c) Andrew Arnott. All rights reserved.
4+
// </copyright>
5+
//-----------------------------------------------------------------------
6+
7+
namespace DotNetOAuth.Test.ChannelElements {
8+
using DotNetOAuth.ChannelElements;
9+
using DotNetOAuth.Messages;
10+
using Microsoft.VisualStudio.TestTools.UnitTesting;
11+
12+
[TestClass]
13+
public class HmacSha1SigningBindingElementTests : MessagingTestBase {
14+
[TestMethod]
15+
public void SignatureTest() {
16+
RequestTokenMessage message = SigningBindingElementBaseTests.CreateTestRequestTokenMessage();
17+
18+
HmacSha1SigningBindingElement_Accessor hmac = new HmacSha1SigningBindingElement_Accessor();
19+
Assert.AreEqual("kR0LhH8UqylaLfR%2FesXVVlP4sQI%3D", hmac.GetSignature(message));
20+
}
21+
}
22+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//-----------------------------------------------------------------------
2+
// <copyright file="SigningBindingElementBaseTests.cs" company="Andrew Arnott">
3+
// Copyright (c) Andrew Arnott. All rights reserved.
4+
// </copyright>
5+
//-----------------------------------------------------------------------
6+
7+
namespace DotNetOAuth.Test.ChannelElements {
8+
using DotNetOAuth.ChannelElements;
9+
using DotNetOAuth.Messages;
10+
using DotNetOAuth.Messaging;
11+
using DotNetOAuth.Messaging.Reflection;
12+
using Microsoft.VisualStudio.TestTools.UnitTesting;
13+
14+
[TestClass]
15+
public class SigningBindingElementBaseTests : MessagingTestBase {
16+
[TestMethod]
17+
public void BaseSignatureStringTest() {
18+
RequestTokenMessage message = CreateTestRequestTokenMessage();
19+
20+
Assert.AreEqual(
21+
"GET&https%3A%2F%2Fwww.google.com%2Faccounts%2FOAuthGetRequestToken&oauth_consumer_key%3Dnerdbank.org%26oauth_nonce%3Dfe4045a3f0efdd1e019fa8f8ae3f5c38%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1222665749%26oauth_version%3D1.0%26scope%3Dhttp%253A%252F%252Fwww.google.com%252Fm8%252Ffeeds%252F",
22+
SigningBindingElementBase_Accessor.ConstructSignatureBaseString(message));
23+
}
24+
25+
internal static RequestTokenMessage CreateTestRequestTokenMessage() {
26+
MessageReceivingEndpoint endpoint = new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthGetRequestToken", HttpDeliveryMethod.AuthorizationHeaderRequest);
27+
RequestTokenMessage message = new RequestTokenMessage(endpoint);
28+
message.ConsumerKey = "nerdbank.org";
29+
message.ConsumerSecret = "nerdbanksecret";
30+
var signedMessage = (ITamperResistantOAuthMessage)message;
31+
signedMessage.HttpMethod = "GET";
32+
signedMessage.SignatureMethod = "HMAC-SHA1";
33+
MessageDictionary dictionary = new MessageDictionary(message);
34+
dictionary["oauth_timestamp"] = "1222665749";
35+
dictionary["oauth_nonce"] = "fe4045a3f0efdd1e019fa8f8ae3f5c38";
36+
dictionary["scope"] = "http://www.google.com/m8/feeds/";
37+
return message;
38+
}
39+
}
40+
}

src/DotNetOAuth.Test/DotNetOAuth.Test.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
</Reference>
5959
</ItemGroup>
6060
<ItemGroup>
61+
<Compile Include="ChannelElements\SigningBindingElementBaseTests.cs" />
62+
<Compile Include="ChannelElements\HmacSha1SigningBindingElementTests.cs" />
6163
<Compile Include="Messaging\CollectionAssert.cs" />
6264
<Compile Include="Messaging\MessageSerializerTests.cs" />
6365
<Compile Include="Messaging\Reflection\MessageDescriptionTests.cs" />

src/DotNetOAuth/ChannelElements/OAuthHttpMethodBindingElement.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,27 @@ namespace DotNetOAuth.ChannelElements {
1111
using System.Text;
1212
using DotNetOAuth.Messaging;
1313

14+
/// <summary>
15+
/// Sets the HTTP Method property on a signed message before the signing module gets to it.
16+
/// </summary>
1417
internal class OAuthHttpMethodBindingElement : IChannelBindingElement {
15-
1618
#region IChannelBindingElement Members
1719

20+
/// <summary>
21+
/// Gets the protection offered (if any) by this binding element.
22+
/// </summary>
1823
public MessageProtection Protection {
1924
get { return MessageProtection.None; }
2025
}
2126

27+
/// <summary>
28+
/// Prepares a message for sending based on the rules of this channel binding element.
29+
/// </summary>
30+
/// <param name="message">The message to prepare for sending.</param>
31+
/// <returns>
32+
/// True if the <paramref name="message"/> applied to this binding element
33+
/// and the operation was successful. False otherwise.
34+
/// </returns>
2235
public bool PrepareMessageForSending(IProtocolMessage message) {
2336
var oauthMessage = message as ITamperResistantOAuthMessage;
2437

@@ -40,6 +53,19 @@ public bool PrepareMessageForSending(IProtocolMessage message) {
4053
}
4154
}
4255

56+
/// <summary>
57+
/// Performs any transformation on an incoming message that may be necessary and/or
58+
/// validates an incoming message based on the rules of this channel binding element.
59+
/// </summary>
60+
/// <param name="message">The incoming message to process.</param>
61+
/// <returns>
62+
/// True if the <paramref name="message"/> applied to this binding element
63+
/// and the operation was successful. False if the operation did not apply to this message.
64+
/// </returns>
65+
/// <exception cref="ProtocolException">
66+
/// Thrown when the binding element rules indicate that this message is invalid and should
67+
/// NOT be processed.
68+
/// </exception>
4369
public bool PrepareMessageForReceiving(IProtocolMessage message) {
4470
return false;
4571
}

src/DotNetOAuth/Messages/MessageBase.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ internal abstract class MessageBase : IOAuthDirectedMessage {
3838
private MessageReceivingEndpoint recipient;
3939

4040
#if DEBUG
41+
/// <summary>
42+
/// Initializes static members of the <see cref="MessageBase"/> class.
43+
/// </summary>
4144
static MessageBase() {
4245
LowSecurityMode = true;
4346
}

src/DotNetOAuth/Messaging/MessagingUtilities.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ internal static MessageReceivingEndpoint GetRecipient(this HttpRequestInfo reque
140140
return new MessageReceivingEndpoint(request.Url, request.HttpMethod == "GET" ? HttpDeliveryMethod.GetRequest : HttpDeliveryMethod.PostRequest);
141141
}
142142

143+
/// <summary>
144+
/// Copies some extra parameters into a message.
145+
/// </summary>
146+
/// <param name="message">The message to copy the extra data into.</param>
147+
/// <param name="extraParameters">The extra data to copy into the message. May be null to do nothing.</param>
143148
internal static void AddExtraFields(this IProtocolMessage message, IDictionary<string, string> extraParameters) {
144149
if (message == null) {
145150
throw new ArgumentNullException("message");

0 commit comments

Comments
 (0)