diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-09-09 08:54:21 -0700 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2008-09-09 08:54:21 -0700 |
commit | 6f2ee87f545b26ed320aad94be5fd042c409f5f9 (patch) | |
tree | c959b1b4313cca1af3e2045f78c30f0240c4fbaa /src | |
parent | 4d3d57f1951644de1b11842008d153bad30ef009 (diff) | |
download | DotNetOpenAuth-6f2ee87f545b26ed320aad94be5fd042c409f5f9.zip DotNetOpenAuth-6f2ee87f545b26ed320aad94be5fd042c409f5f9.tar.gz DotNetOpenAuth-6f2ee87f545b26ed320aad94be5fd042c409f5f9.tar.bz2 |
Added some channel tests and fixed a bug.
Diffstat (limited to 'src')
-rw-r--r-- | src/.gitignore | 6 | ||||
-rw-r--r-- | src/DotNetOAuth.Test/.gitignore | 1 | ||||
-rw-r--r-- | src/DotNetOAuth.Test/Messaging/ChannelTests.cs | 56 | ||||
-rw-r--r-- | src/DotNetOAuth.Test/Mocks/TestChannel.cs | 2 | ||||
-rw-r--r-- | src/DotNetOAuth/.gitignore | 6 | ||||
-rw-r--r-- | src/DotNetOAuth/Messaging/Channel.cs | 2 |
6 files changed, 62 insertions, 11 deletions
diff --git a/src/.gitignore b/src/.gitignore index 084a966..3c83c2e 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,4 +1,8 @@ StyleCop.Cache +PrecompiledWeb *.suo *.cache -PrecompiledWeb +*.user +bin +obj +Bin diff --git a/src/DotNetOAuth.Test/.gitignore b/src/DotNetOAuth.Test/.gitignore deleted file mode 100644 index 58b701f..0000000 --- a/src/DotNetOAuth.Test/.gitignore +++ /dev/null @@ -1 +0,0 @@ -StyleCop.Cache diff --git a/src/DotNetOAuth.Test/Messaging/ChannelTests.cs b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs index a2909c4..6750739 100644 --- a/src/DotNetOAuth.Test/Messaging/ChannelTests.cs +++ b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs @@ -9,6 +9,8 @@ namespace DotNetOAuth.Test.Messaging { using System.Collections.Generic;
using System.IO;
using System.Net;
+ using System.Text;
+ using System.Web;
using DotNetOAuth.Messaging;
using DotNetOAuth.Test.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -46,8 +48,18 @@ namespace DotNetOAuth.Test.Messaging { this.ParameterizedReceiveTest("POST");
}
+ [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ public void SendNull() {
+ this.channel.Send(null);
+ }
+
+ [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ public void SendNull2() {
+ this.channel.Send(null, new TestDirectedMessage());
+ }
+
[TestMethod]
- public void SendIndirectMessage() {
+ public void SendIndirectMessage301Get() {
IProtocolMessage message = new TestDirectedMessage {
Age = 15,
Name = "Andrew",
@@ -63,6 +75,48 @@ namespace DotNetOAuth.Test.Messaging { StringAssert.Contains(response.Headers[HttpResponseHeader.Location], "Location=http%3a%2f%2fhost%2fpath");
}
+ [TestMethod]
+ public void SendIndirectMessageFormPost() {
+ // We craft a very large message to force fallback to form POST.
+ // We'll also stick some HTML reserved characters in the string value
+ // to test proper character escaping.
+ var message = new TestDirectedMessage {
+ Age = 15,
+ Name = "c<b" + new string('a', 10 * 1024),
+ Location = new Uri("http://host/path"),
+ Recipient = new Uri("http://provider/path"),
+ };
+ this.channel.Send(message);
+ Response response = this.channel.DequeueIndirectOrResponseMessage();
+ Assert.AreEqual(HttpStatusCode.OK, response.Status, "A form redirect should be an HTTP successful response.");
+ Assert.IsNull(response.Headers[HttpResponseHeader.Location], "There should not be a redirection header in the response.");
+ string body = Encoding.UTF8.GetString(response.Body);
+ StringAssert.Contains(body, "<form ");
+ StringAssert.Contains(body, "action=\"http://provider/path\"");
+ StringAssert.Contains(body, "method=\"post\"");
+ StringAssert.Contains(body, "<input type=\"hidden\" name=\"age\" value=\"15\" />");
+ StringAssert.Contains(body, "<input type=\"hidden\" name=\"Location\" value=\"http://host/path\" />");
+ StringAssert.Contains(body, "<input type=\"hidden\" name=\"Name\" value=\"" + HttpUtility.HtmlEncode(message.Name) + "\" />");
+ StringAssert.Contains(body, ".submit()", "There should be some javascript to automate form submission.");
+ }
+
+ /// <summary>
+ /// Tests that a direct message is sent when the appropriate message type is provided.
+ /// </summary>
+ /// <remarks>
+ /// Since this is a mock channel that doesn't actually formulate a direct message response,
+ /// we just check that the right method was called.
+ /// </remarks>
+ [TestMethod, ExpectedException(typeof(NotImplementedException), "SendDirectMessageResponse")]
+ public void SendDirectMessageResponse() {
+ IProtocolMessage message = new TestMessage {
+ Age = 15,
+ Name = "Andrew",
+ Location = new Uri("http://host/path"),
+ };
+ this.channel.Send(message);
+ }
+
private static HttpRequestInfo CreateHttpRequest(string method, IDictionary<string, string> fields) {
string query = MessagingUtilities.CreateQueryString(fields);
UriBuilder requestUri = new UriBuilder("http://localhost/path");
diff --git a/src/DotNetOAuth.Test/Mocks/TestChannel.cs b/src/DotNetOAuth.Test/Mocks/TestChannel.cs index 1920a38..632257e 100644 --- a/src/DotNetOAuth.Test/Mocks/TestChannel.cs +++ b/src/DotNetOAuth.Test/Mocks/TestChannel.cs @@ -25,7 +25,7 @@ namespace DotNetOAuth.Test.Mocks { }
protected override void SendDirectMessageResponse(IProtocolMessage response) {
- throw new NotImplementedException();
+ throw new NotImplementedException("SendDirectMessageResponse");
}
protected override void ReportErrorToUser(ProtocolException exception) {
diff --git a/src/DotNetOAuth/.gitignore b/src/DotNetOAuth/.gitignore deleted file mode 100644 index 31c006d..0000000 --- a/src/DotNetOAuth/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -StyleCop.Cache -*.user -bin -obj -Bin -StyleCop.Cache diff --git a/src/DotNetOAuth/Messaging/Channel.cs b/src/DotNetOAuth/Messaging/Channel.cs index 40261b1..2c5e225 100644 --- a/src/DotNetOAuth/Messaging/Channel.cs +++ b/src/DotNetOAuth/Messaging/Channel.cs @@ -299,7 +299,7 @@ namespace DotNetOAuth.Messaging { hiddenFields);
bodyWriter.Flush();
Response response = new Response {
- Status = HttpStatusCode.Redirect,
+ Status = HttpStatusCode.OK,
Headers = headers,
Body = body.ToArray(),
OriginalMessage = message
|