summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-04-30 22:23:29 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2009-04-30 23:28:10 -0700
commit08b82b6108b179762fd30485382814ee6ffffaa0 (patch)
tree635d0758a89c97065552ce188c7f81b077f5142e /src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
parentc946714b6bd210fdba1afc68daa77aa972f765e9 (diff)
downloadDotNetOpenAuth-08b82b6108b179762fd30485382814ee6ffffaa0.zip
DotNetOpenAuth-08b82b6108b179762fd30485382814ee6ffffaa0.tar.gz
DotNetOpenAuth-08b82b6108b179762fd30485382814ee6ffffaa0.tar.bz2
Added more tests to verify correct behavior of OAuth Authorization header and message parts in different places.
Fixed a bug in the signature construction process the test found.
Diffstat (limited to 'src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs')
-rw-r--r--src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs77
1 files changed, 74 insertions, 3 deletions
diff --git a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
index 401153d..d660748 100644
--- a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
+++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
@@ -15,6 +15,7 @@ namespace DotNetOpenAuth.Test.ChannelElements {
using System.Xml;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Bindings;
+ using DotNetOpenAuth.Messaging.Reflection;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.Test.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -69,6 +70,41 @@ namespace DotNetOpenAuth.Test.ChannelElements {
this.ParameterizedReceiveTest(HttpDeliveryMethods.AuthorizationHeaderRequest);
}
+ /// <summary>
+ /// Verifies that the OAuth ReadFromRequest method gathers parameters
+ /// from the Authorization header, the query string and the entity form data.
+ /// </summary>
+ [TestMethod]
+ public void ReadFromRequestAuthorizationScattered() {
+ // Start by creating a standard POST HTTP request.
+ var fields = new Dictionary<string, string> {
+ { "age", "15" },
+ };
+ HttpRequestInfo requestInfo = CreateHttpRequestInfo(HttpDeliveryMethods.PostRequest, fields);
+
+ // Now add another field to the request URL
+ UriBuilder builder = new UriBuilder(requestInfo.Url);
+ builder.Query = "Name=Andrew";
+ requestInfo.Url = builder.Uri;
+ requestInfo.RawUrl = builder.Path + builder.Query + builder.Fragment;
+
+ // Finally, add an Authorization header
+ fields = new Dictionary<string, string> {
+ { "Location", "http://hostb/pathB" },
+ { "Timestamp", XmlConvert.ToString(DateTime.UtcNow, XmlDateTimeSerializationMode.Utc) },
+ };
+ requestInfo.Headers.Add(HttpRequestHeader.Authorization, CreateAuthorizationHeader(fields));
+
+ IDirectedProtocolMessage requestMessage = this.channel.ReadFromRequest(requestInfo);
+
+ Assert.IsNotNull(requestMessage);
+ Assert.IsInstanceOfType(requestMessage, typeof(TestMessage));
+ TestMessage testMessage = (TestMessage)requestMessage;
+ Assert.AreEqual(15, testMessage.Age);
+ Assert.AreEqual("Andrew", testMessage.Name);
+ Assert.AreEqual("http://hostb/pathB", testMessage.Location.AbsoluteUri);
+ }
+
[TestMethod]
public void ReadFromRequestForm() {
this.ParameterizedReceiveTest(HttpDeliveryMethods.PostRequest);
@@ -144,6 +180,43 @@ namespace DotNetOpenAuth.Test.ChannelElements {
this.ParameterizedRequestTest(HttpDeliveryMethods.AuthorizationHeaderRequest);
}
+ /// <summary>
+ /// Verifies that message parts can be distributed to the query, form, and Authorization header.
+ /// </summary>
+ [TestMethod]
+ public void RequestUsingAuthorizationHeaderScattered() {
+ TestDirectedMessage request = new TestDirectedMessage(MessageTransport.Direct) {
+ Age = 15,
+ Name = "Andrew",
+ Location = new Uri("http://hostb/pathB"),
+ Recipient = new Uri("http://localtest"),
+ Timestamp = DateTime.UtcNow,
+ HttpMethods = HttpDeliveryMethods.AuthorizationHeaderRequest,
+ };
+
+
+ // ExtraData should appear in the form since this is a POST request,
+ // and only official message parts get a place in the Authorization header.
+ ((IProtocolMessage)request).ExtraData["appearinform"] = "formish";
+ request.Recipient = new Uri("http://localhost/?appearinquery=queryish");
+ request.HttpMethods = HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest;
+
+ HttpWebRequest webRequest = this.channel.InitializeRequest(request);
+ Assert.IsNotNull(webRequest);
+ Assert.AreEqual("POST", webRequest.Method);
+ Assert.AreEqual(request.Recipient, webRequest.RequestUri);
+
+ var declaredParts = new Dictionary<string, string> {
+ { "age", request.Age.ToString() },
+ { "Name", request.Name },
+ { "Location", request.Location.AbsoluteUri },
+ { "Timestamp", XmlConvert.ToString(request.Timestamp, XmlDateTimeSerializationMode.Utc) },
+ };
+
+ Assert.AreEqual(CreateAuthorizationHeader(declaredParts), webRequest.Headers[HttpRequestHeader.Authorization]);
+ Assert.AreEqual("appearinform=formish", this.webRequestHandler.RequestEntityAsString);
+ }
+
[TestMethod]
public void RequestUsingGet() {
this.ParameterizedRequestTest(HttpDeliveryMethods.GetRequest);
@@ -171,9 +244,7 @@ namespace DotNetOpenAuth.Test.ChannelElements {
}
private static string CreateAuthorizationHeader(IDictionary<string, string> fields) {
- if (fields == null) {
- throw new ArgumentNullException("fields");
- }
+ ErrorUtilities.VerifyArgumentNotNull(fields, "fields");
StringBuilder authorization = new StringBuilder();
authorization.Append("OAuth ");