summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2010-03-29 08:00:43 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2010-03-30 21:38:31 -0700
commite2b9b11e226d02f584f847aa7ab20d21c6e2af3b (patch)
tree6a476866aed6ad0e50dd344046a8de6ac33b57f2
parent4dbdd733ec3527c4c62eed643b2f73145c293baf (diff)
downloadDotNetOpenAuth-e2b9b11e226d02f584f847aa7ab20d21c6e2af3b.zip
DotNetOpenAuth-e2b9b11e226d02f584f847aa7ab20d21c6e2af3b.tar.gz
DotNetOpenAuth-e2b9b11e226d02f584f847aa7ab20d21c6e2af3b.tar.bz2
Fixed equality checks for the problematic URIs, and added a regression test for it.
Also added reporting of full vs. partial trust hosting.
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs32
-rw-r--r--src/DotNetOpenAuth/OpenId/UriIdentifier.cs35
2 files changed, 53 insertions, 14 deletions
diff --git a/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs b/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs
index 0c51ac1..c7822f3 100644
--- a/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs
@@ -130,19 +130,25 @@ namespace DotNetOpenAuth.Test.OpenId {
[TestCase]
public void EqualsTest() {
- Assert.AreEqual(new UriIdentifier(this.goodUri), new UriIdentifier(this.goodUri));
- // This next test is an interesting side-effect of passing off to Uri.Equals. But it's probably ok.
- Assert.AreEqual(new UriIdentifier(this.goodUri), new UriIdentifier(this.goodUri + "#frag"));
- Assert.AreNotEqual(new UriIdentifier(this.goodUri), new UriIdentifier(this.goodUri + "a"));
- Assert.AreNotEqual(null, new UriIdentifier(this.goodUri));
- Assert.IsTrue(new UriIdentifier(this.goodUri).Equals(this.goodUri));
-
- Assert.AreEqual(Identifier.Parse("HTTP://WWW.FOO.COM/abc", true), Identifier.Parse("http://www.foo.com/abc", true));
- Assert.AreEqual(Identifier.Parse("HTTP://WWW.FOO.COM/abc", true), Identifier.Parse("http://www.foo.com/abc", false));
- Assert.AreEqual(Identifier.Parse("HTTP://WWW.FOO.COM/abc", false), Identifier.Parse("http://www.foo.com/abc", false));
- Assert.AreNotEqual(Identifier.Parse("http://www.foo.com/abc", true), Identifier.Parse("http://www.foo.com/ABC", true));
- Assert.AreNotEqual(Identifier.Parse("http://www.foo.com/abc", true), Identifier.Parse("http://www.foo.com/ABC", false));
- Assert.AreNotEqual(Identifier.Parse("http://www.foo.com/abc", false), Identifier.Parse("http://www.foo.com/ABC", false));
+ TestAsFullAndPartialTrust(fulltrust => {
+ Assert.AreEqual(new UriIdentifier(this.goodUri), new UriIdentifier(this.goodUri));
+ // This next test is an interesting side-effect of passing off to Uri.Equals. But it's probably ok.
+ Assert.AreEqual(new UriIdentifier(this.goodUri), new UriIdentifier(this.goodUri + "#frag"));
+ Assert.AreEqual(new UriIdentifier("http://a/b./c."), new UriIdentifier("http://a/b./c.#frag"));
+ Assert.AreNotEqual(new UriIdentifier(this.goodUri), new UriIdentifier(this.goodUri + "a"));
+ Assert.AreNotEqual(null, new UriIdentifier(this.goodUri));
+ Assert.IsTrue(new UriIdentifier(this.goodUri).Equals(this.goodUri));
+
+ Assert.AreEqual(Identifier.Parse("HTTP://WWW.FOO.COM/abc", true), Identifier.Parse("http://www.foo.com/abc", true));
+ Assert.AreEqual(Identifier.Parse("HTTP://WWW.FOO.COM/abc", true), Identifier.Parse("http://www.foo.com/abc", false));
+ Assert.AreEqual(Identifier.Parse("HTTP://WWW.FOO.COM/abc", false), Identifier.Parse("http://www.foo.com/abc", false));
+ Assert.AreNotEqual(Identifier.Parse("http://www.foo.com/abc", true), Identifier.Parse("http://www.foo.com/ABC", true));
+ Assert.AreNotEqual(Identifier.Parse("http://www.foo.com/abc", true), Identifier.Parse("http://www.foo.com/ABC", false));
+ Assert.AreNotEqual(Identifier.Parse("http://www.foo.com/abc", false), Identifier.Parse("http://www.foo.com/ABC", false));
+
+ Assert.AreNotEqual(Identifier.Parse("http://a/b./c."), Identifier.Parse("http://a/b/c."));
+ Assert.AreEqual(Identifier.Parse("http://a/b./c."), Identifier.Parse("http://a/b./c."));
+ });
}
[TestCase]
diff --git a/src/DotNetOpenAuth/OpenId/UriIdentifier.cs b/src/DotNetOpenAuth/OpenId/UriIdentifier.cs
index 9f2c646..0608952 100644
--- a/src/DotNetOpenAuth/OpenId/UriIdentifier.cs
+++ b/src/DotNetOpenAuth/OpenId/UriIdentifier.cs
@@ -84,9 +84,12 @@ namespace DotNetOpenAuth.OpenId {
publishableHttpParser.Initialize(true);
publishableHttpsParser.Initialize(true);
schemeSubstitution = true;
+ Logger.OpenId.Debug(".NET Uri class path compression overridden.");
+ Reporting.RecordFeatureUse("FullTrust");
} catch (SecurityException) {
// We must be running in partial trust. Nothing more we can do.
Logger.OpenId.Warn("Unable to coerce .NET to stop compressing URI paths due to partial trust limitations. Some URL identifiers may be unable to complete login.");
+ Reporting.RecordFeatureUse("PartialTrust");
}
}
@@ -225,7 +228,12 @@ namespace DotNetOpenAuth.OpenId {
if (other == null) {
return false;
}
- return this.Uri == other.Uri;
+
+ if (this.ProblematicNormalization || other.ProblematicNormalization) {
+ return new SimpleUri(this.OriginalString).Equals(new SimpleUri(other.OriginalString));
+ } else {
+ return this.Uri == other.Uri;
+ }
}
/// <summary>
@@ -580,6 +588,31 @@ namespace DotNetOpenAuth.OpenId {
}
/// <summary>
+ /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
+ /// </summary>
+ /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
+ /// <returns>
+ /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
+ /// </returns>
+ /// <exception cref="T:System.NullReferenceException">
+ /// The <paramref name="obj"/> parameter is null.
+ /// </exception>
+ public override bool Equals(object obj) {
+ SimpleUri other = obj as SimpleUri;
+ if (other == null) {
+ return false;
+ }
+
+ // Note that this equality check is intentionally leaving off the Fragment part
+ // to match Uri behavior, and is intentionally being case sensitive and insensitive
+ // for different parts.
+ return string.Equals(this.Scheme, other.Scheme, StringComparison.OrdinalIgnoreCase) &&
+ string.Equals(this.Authority, other.Authority, StringComparison.OrdinalIgnoreCase) &&
+ string.Equals(this.Path, other.Path, StringComparison.Ordinal) &&
+ string.Equals(this.Query, other.Query, StringComparison.Ordinal);
+ }
+
+ /// <summary>
/// Normalizes the characters that are escaped in the given URI path.
/// </summary>
/// <param name="path">The path to normalize.</param>