summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.Test')
-rw-r--r--src/DotNetOpenAuth.Test/App.config10
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs4
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs26
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs17
4 files changed, 52 insertions, 5 deletions
diff --git a/src/DotNetOpenAuth.Test/App.config b/src/DotNetOpenAuth.Test/App.config
index 2182312..359e25f 100644
--- a/src/DotNetOpenAuth.Test/App.config
+++ b/src/DotNetOpenAuth.Test/App.config
@@ -1,8 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
+ <section name="uri" type="System.Configuration.UriSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<section name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth"/>
</configSections>
+
+ <!-- The uri section is necessary to turn on .NET 3.5 support for IDN (international domain names),
+ which is necessary for OpenID urls with unicode characters in the domain/host name.
+ It is also required to put the Uri class into RFC 3986 escaping mode, which OpenID and OAuth require. -->
+ <uri>
+ <idn enabled="All"/>
+ <iriParsing enabled="true"/>
+ </uri>
+
<dotNetOpenAuth>
<!-- The values here are carefully chosen to be somewhat weird so that tests can be
reasonably confident that if the values are the weird ones here that they did
diff --git a/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs b/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs
index ac94ea2..669abbc 100644
--- a/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs
@@ -79,8 +79,8 @@ namespace DotNetOpenAuth.Test.Messaging {
Assert.AreEqual(HttpStatusCode.Redirect, response.Status);
StringAssert.StartsWith(response.Headers[HttpResponseHeader.Location], "http://provider/path");
foreach (var pair in expected) {
- string key = HttpUtility.UrlEncode(pair.Key);
- string value = HttpUtility.UrlEncode(pair.Value);
+ string key = MessagingUtilities.EscapeUriDataStringRfc3986(pair.Key);
+ string value = MessagingUtilities.EscapeUriDataStringRfc3986(pair.Value);
string substring = string.Format("{0}={1}", key, value);
StringAssert.Contains(response.Headers[HttpResponseHeader.Location], substring);
}
diff --git a/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs b/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs
index 2b1d961..26ce4cd 100644
--- a/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs
@@ -22,7 +22,7 @@ namespace DotNetOpenAuth.Test.Messaging
var args = new Dictionary<string, string>();
args.Add("a", "b");
args.Add("c/d", "e/f");
- Assert.AreEqual("a=b&c%2fd=e%2ff", MessagingUtilities.CreateQueryString(args));
+ Assert.AreEqual("a=b&c%2Fd=e%2Ff", MessagingUtilities.CreateQueryString(args));
}
[TestMethod]
@@ -42,11 +42,11 @@ namespace DotNetOpenAuth.Test.Messaging
args.Add("a", "b");
args.Add("c/d", "e/f");
MessagingUtilities.AppendQueryArgs(uri, args);
- Assert.AreEqual("http://baseline.org/page?a=b&c%2fd=e%2ff", uri.Uri.AbsoluteUri);
+ Assert.AreEqual("http://baseline.org/page?a=b&c%2Fd=e%2Ff", uri.Uri.AbsoluteUri);
args.Clear();
args.Add("g", "h");
MessagingUtilities.AppendQueryArgs(uri, args);
- Assert.AreEqual("http://baseline.org/page?a=b&c%2fd=e%2ff&g=h", uri.Uri.AbsoluteUri);
+ Assert.AreEqual("http://baseline.org/page?a=b&c%2Fd=e%2Ff&g=h", uri.Uri.AbsoluteUri);
}
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
@@ -119,5 +119,25 @@ namespace DotNetOpenAuth.Test.Messaging
Assert.AreEqual(headers[HttpResponseHeader.ContentType], response.ContentType);
}
+
+ /// <summary>
+ /// Verifies RFC 3986 compliant URI escaping, as required by the OpenID and OAuth specifications.
+ /// </summary>
+ /// <remarks>
+ /// The tests in this method come from http://wiki.oauth.net/TestCases
+ /// </remarks>
+ [TestMethod]
+ public void EscapeUriDataStringRfc3986Tests() {
+ Assert.AreEqual("abcABC123", MessagingUtilities.EscapeUriDataStringRfc3986("abcABC123"));
+ Assert.AreEqual("-._~", MessagingUtilities.EscapeUriDataStringRfc3986("-._~"));
+ Assert.AreEqual("%25", MessagingUtilities.EscapeUriDataStringRfc3986("%"));
+ Assert.AreEqual("%2B", MessagingUtilities.EscapeUriDataStringRfc3986("+"));
+ Assert.AreEqual("%26%3D%2A", MessagingUtilities.EscapeUriDataStringRfc3986("&=*"));
+ Assert.AreEqual("%0A", MessagingUtilities.EscapeUriDataStringRfc3986("\n"));
+ Assert.AreEqual("%20", MessagingUtilities.EscapeUriDataStringRfc3986(" "));
+ Assert.AreEqual("%7F", MessagingUtilities.EscapeUriDataStringRfc3986("\u007f"));
+ Assert.AreEqual("%C2%80", MessagingUtilities.EscapeUriDataStringRfc3986("\u0080"));
+ Assert.AreEqual("%E3%80%81", MessagingUtilities.EscapeUriDataStringRfc3986("\u3001"));
+ }
}
}
diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
index e654f02..3bbe6e3 100644
--- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingChannel.cs
@@ -45,6 +45,12 @@ namespace DotNetOpenAuth.Test.Mocks {
private EventWaitHandle incomingMessageSignal = new AutoResetEvent(false);
/// <summary>
+ /// A thread-coordinating signal that is set briefly by this thread whenever
+ /// a message is picked up.
+ /// </summary>
+ private EventWaitHandle messageReceivedSignal = new AutoResetEvent(false);
+
+ /// <summary>
/// A flag used to indicate when this channel is waiting for a message
/// to arrive.
/// </summary>
@@ -126,6 +132,12 @@ namespace DotNetOpenAuth.Test.Mocks {
/// </summary>
/// <param name="message">The message that this channel should receive. This message will be cloned.</param>
internal void PostMessage(IProtocolMessage message) {
+ if (this.incomingMessage != null) {
+ // The remote party hasn't picked up the last message we sent them.
+ // Wait for a short period for them to pick it up before failing.
+ TestBase.TestLogger.Warn("We're blocked waiting to send a message to the remote party and they haven't processed the last message we sent them.");
+ this.RemoteChannel.messageReceivedSignal.WaitOne(500);
+ }
ErrorUtilities.VerifyInternal(this.incomingMessage == null, "Oops, a message is already waiting for the remote party!");
this.incomingMessage = this.MessageDescriptions.GetAccessor(message).Serialize();
var directedMessage = message as IDirectedProtocolMessage;
@@ -273,6 +285,11 @@ namespace DotNetOpenAuth.Test.Mocks {
recipient = this.incomingMessageRecipient;
this.incomingMessage = null;
this.incomingMessageRecipient = null;
+
+ // Briefly signal to another thread that might be waiting for our inbox to be empty
+ this.messageReceivedSignal.Set();
+ this.messageReceivedSignal.Reset();
+
return response;
}
}