summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-04-01 08:34:10 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2008-04-01 08:48:37 -0700
commit485e974bcbfe45d0d1b9c56ba0ed8a61b14e3072 (patch)
tree5fdf0b094b745db0747bc80004b76e6f6f188b29
parentc64499007bcf3332bca3fc6c7cb7f557f659dec0 (diff)
downloadDotNetOpenAuth-485e974bcbfe45d0d1b9c56ba0ed8a61b14e3072.zip
DotNetOpenAuth-485e974bcbfe45d0d1b9c56ba0ed8a61b14e3072.tar.gz
DotNetOpenAuth-485e974bcbfe45d0d1b9c56ba0ed8a61b14e3072.tar.bz2
Fixed HTML discovery where invalid URLs are encountered.
Also added several XRDS discovery tests.
-rw-r--r--src/DotNetOpenId.Test/UriIdentifierTests.cs92
-rw-r--r--src/DotNetOpenId.TestWeb/App_Code/Util.cs19
-rw-r--r--src/DotNetOpenId.TestWeb/htmldiscovery/html20relative.aspx9
-rw-r--r--src/DotNetOpenId.TestWeb/xrdsdiscovery/XrdsReferencedInHead.aspx17
-rw-r--r--src/DotNetOpenId.TestWeb/xrdsdiscovery/XrdsReferencedInHttpHeader.aspx20
-rw-r--r--src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds-irrelevant.aspx12
-rw-r--r--src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds10.aspx13
-rw-r--r--src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds1020.aspx18
-rw-r--r--src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds11.aspx13
-rw-r--r--src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds20.aspx13
-rw-r--r--src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds2010a.aspx18
-rw-r--r--src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds2010b.aspx18
-rw-r--r--src/DotNetOpenId/Extensions/Constants.cs1
-rw-r--r--src/DotNetOpenId/Protocol.cs7
-rw-r--r--src/DotNetOpenId/Provider/IdentityEndpoint.cs2
-rw-r--r--src/DotNetOpenId/UriIdentifier.cs18
16 files changed, 258 insertions, 32 deletions
diff --git a/src/DotNetOpenId.Test/UriIdentifierTests.cs b/src/DotNetOpenId.Test/UriIdentifierTests.cs
index 6fa5b7f..8747bf6 100644
--- a/src/DotNetOpenId.Test/UriIdentifierTests.cs
+++ b/src/DotNetOpenId.Test/UriIdentifierTests.cs
@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using DotNetOpenId.RelyingParty;
+using System.Net;
+using DotNetOpenId.Extensions;
namespace DotNetOpenId.Test {
[TestFixture]
@@ -55,46 +57,86 @@ namespace DotNetOpenId.Test {
Assert.AreNotEqual(goodUri, new UriIdentifier(goodUri));
}
- void discover(string page, ProtocolVersion version, Identifier expectedLocalId, bool useRedirect) {
+ void discover(string url, ProtocolVersion version, Identifier expectedLocalId, bool expectSreg, bool useRedirect) {
Protocol protocol = Protocol.Lookup(version);
- UriIdentifier claimedId = TestSupport.GetFullUrl("/htmldiscovery/" + page);
+ UriIdentifier claimedId = TestSupport.GetFullUrl(url);
UriIdentifier userSuppliedIdentifier = TestSupport.GetFullUrl(
- "htmldiscovery/redirect.aspx?target=" + page);
+ "htmldiscovery/redirect.aspx?target=" + url);
if (expectedLocalId == null) expectedLocalId = claimedId;
- ServiceEndpoint se = useRedirect ? userSuppliedIdentifier.Discover() : claimedId.Discover();
- Assert.IsNotNull(se, page + " failed to be discovered.");
+ Identifier idToDiscover = useRedirect ? userSuppliedIdentifier : claimedId;
+ // confirm the page exists (validates the test)
+ WebRequest.Create(idToDiscover).GetResponse().Close();
+ ServiceEndpoint se = idToDiscover.Discover();
+ Assert.IsNotNull(se, url + " failed to be discovered.");
Assert.AreSame(protocol, se.Protocol);
Assert.AreEqual(claimedId, se.ClaimedIdentifier);
Assert.AreEqual(expectedLocalId, se.ProviderLocalIdentifier);
- Assert.AreEqual(1, se.ProviderSupportedServiceTypeUris.Length);
- Assert.AreEqual(protocol.ClaimedIdentifierServiceTypeURI, se.ProviderSupportedServiceTypeUris[0]);
+ Assert.AreEqual(expectSreg ? 2 : 1, se.ProviderSupportedServiceTypeUris.Length);
+ Assert.IsTrue(Array.IndexOf(se.ProviderSupportedServiceTypeUris, protocol.ClaimedIdentifierServiceTypeURI)>=0);
+ if (expectSreg)
+ Assert.IsTrue(Array.IndexOf(se.ProviderSupportedServiceTypeUris, Constants.sreg.TypeUri) >= 0);
}
- void discover(string scenario, ProtocolVersion version, Identifier expectedLocalId) {
- string page = scenario + ".aspx";
- discover(page, version, expectedLocalId, false);
- discover(page, version, expectedLocalId, true);
+ void discoverXrds(string page, ProtocolVersion version, Identifier expectedLocalId) {
+ discover("/xrdsdiscovery/" + page + ".aspx", version, expectedLocalId, true, false);
+ discover("/xrdsdiscovery/" + page + ".aspx", version, expectedLocalId, true, true);
+ }
+ void discoverHtml(string page, ProtocolVersion version, Identifier expectedLocalId, bool useRedirect) {
+ discover("/htmldiscovery/" + page, version, expectedLocalId, false, useRedirect);
}
- void failDiscovery(string scenario) {
+ void discoverHtml(string scenario, ProtocolVersion version, Identifier expectedLocalId) {
string page = scenario + ".aspx";
- UriIdentifier userSuppliedId = TestSupport.GetFullUrl("htmldiscovery/" + page);
- Assert.IsNull(userSuppliedId.Discover());
+ discoverHtml(page, version, expectedLocalId, false);
+ discoverHtml(page, version, expectedLocalId, true);
+ }
+ void failDiscover(string url) {
+ UriIdentifier userSuppliedId = TestSupport.GetFullUrl(url);
+ WebRequest.Create((Uri)userSuppliedId).GetResponse().Close(); // confirm the page exists ...
+ Assert.IsNull(userSuppliedId.Discover()); // ... but that no endpoint info is discoverable
+ }
+ void failDiscoverHtml(string scenario) {
+ failDiscover("htmldiscovery/" + scenario + ".aspx");
+ }
+ void failDiscoverXrds(string scenario) {
+ failDiscover("xrdsdiscovery/" + scenario + ".aspx");
}
[Test]
public void HtmlDiscover_11() {
- discover("html10prov", ProtocolVersion.V11, null);
- discover("html10both", ProtocolVersion.V11, "http://c/d");
- failDiscovery("html10del");
+ discoverHtml("html10prov", ProtocolVersion.V11, null);
+ discoverHtml("html10both", ProtocolVersion.V11, "http://c/d");
+ failDiscoverHtml("html10del");
}
[Test]
public void HtmlDiscover_20() {
- discover("html20prov", ProtocolVersion.V20, null);
- discover("html20both", ProtocolVersion.V20, "http://c/d");
- failDiscovery("html20del");
- discover("html2010", ProtocolVersion.V20, "http://c/d");
- discover("html1020", ProtocolVersion.V20, "http://c/d");
- discover("html2010combinedA", ProtocolVersion.V20, "http://c/d");
- discover("html2010combinedB", ProtocolVersion.V20, "http://c/d");
- discover("html2010combinedC", ProtocolVersion.V20, "http://c/d");
+ discoverHtml("html20prov", ProtocolVersion.V20, null);
+ discoverHtml("html20both", ProtocolVersion.V20, "http://c/d");
+ failDiscoverHtml("html20del");
+ discoverHtml("html2010", ProtocolVersion.V20, "http://c/d");
+ discoverHtml("html1020", ProtocolVersion.V20, "http://c/d");
+ discoverHtml("html2010combinedA", ProtocolVersion.V20, "http://c/d");
+ discoverHtml("html2010combinedB", ProtocolVersion.V20, "http://c/d");
+ discoverHtml("html2010combinedC", ProtocolVersion.V20, "http://c/d");
+ failDiscoverHtml("html20relative");
+ }
+ [Test]
+ public void XrdsDiscoveryFromHead() {
+ discoverXrds("XrdsReferencedInHead", ProtocolVersion.V10, null);
+ }
+ [Test]
+ public void XrdsDiscoveryFromHttpHeader() {
+ discoverXrds("XrdsReferencedInHttpHeader", ProtocolVersion.V10, null);
+ }
+ [Test]
+ public void XrdsDirectDiscovery_10() {
+ failDiscoverXrds("xrds-irrelevant");
+ discoverXrds("xrds10", ProtocolVersion.V10, null);
+ discoverXrds("xrds11", ProtocolVersion.V11, null);
+ discoverXrds("xrds1020", ProtocolVersion.V10, null);
+ }
+ [Test]
+ public void XrdsDirectDiscovery_20() {
+ discoverXrds("xrds20", ProtocolVersion.V20, null);
+ discoverXrds("xrds2010a", ProtocolVersion.V20, null);
+ discoverXrds("xrds2010b", ProtocolVersion.V20, null);
}
}
}
diff --git a/src/DotNetOpenId.TestWeb/App_Code/Util.cs b/src/DotNetOpenId.TestWeb/App_Code/Util.cs
new file mode 100644
index 0000000..0565cba
--- /dev/null
+++ b/src/DotNetOpenId.TestWeb/App_Code/Util.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Data;
+using System.Configuration;
+using System.Web;
+using System.Web.Security;
+using System.Web.UI;
+using System.Web.UI.HtmlControls;
+using System.Web.UI.WebControls;
+using System.Web.UI.WebControls.WebParts;
+
+/// <summary>
+/// Summary description for Utilcs
+/// </summary>
+public static class Util {
+ public static Uri GetFullUrl(string relativeUri) {
+ return new Uri(HttpContext.Current.Request.Url,
+ HttpContext.Current.Response.ApplyAppPathModifier(relativeUri));
+ }
+}
diff --git a/src/DotNetOpenId.TestWeb/htmldiscovery/html20relative.aspx b/src/DotNetOpenId.TestWeb/htmldiscovery/html20relative.aspx
new file mode 100644
index 0000000..b13520c
--- /dev/null
+++ b/src/DotNetOpenId.TestWeb/htmldiscovery/html20relative.aspx
@@ -0,0 +1,9 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>Untitled Page</title>
+ <link rel="openid2.provider" href="../a/b" />
+</head>
+<body>
+</body>
+</html>
diff --git a/src/DotNetOpenId.TestWeb/xrdsdiscovery/XrdsReferencedInHead.aspx b/src/DotNetOpenId.TestWeb/xrdsdiscovery/XrdsReferencedInHead.aspx
new file mode 100644
index 0000000..fabb2aa
--- /dev/null
+++ b/src/DotNetOpenId.TestWeb/xrdsdiscovery/XrdsReferencedInHead.aspx
@@ -0,0 +1,17 @@
+<%@ Page Language="C#" %>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<script runat="server">
+</script>
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head runat="server">
+ <title>Untitled Page</title>
+ <meta http-equiv="X-XRDS-Location" content="<%=Util.GetFullUrl("xrds1020.aspx")%>"/>
+</head>
+<body>
+ <form id="form1" runat="server">
+ </form>
+</body>
+</html>
diff --git a/src/DotNetOpenId.TestWeb/xrdsdiscovery/XrdsReferencedInHttpHeader.aspx b/src/DotNetOpenId.TestWeb/xrdsdiscovery/XrdsReferencedInHttpHeader.aspx
new file mode 100644
index 0000000..b31c707
--- /dev/null
+++ b/src/DotNetOpenId.TestWeb/xrdsdiscovery/XrdsReferencedInHttpHeader.aspx
@@ -0,0 +1,20 @@
+<%@ Page Language="C#" %>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<script runat="server">
+ protected override void OnLoad(EventArgs e) {
+ base.OnLoad(e);
+ Response.AddHeader("X-XRDS-Location", Util.GetFullUrl("xrds1020.aspx").AbsoluteUri);
+ }
+</script>
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head runat="server">
+ <title>Untitled Page</title>
+</head>
+<body>
+ <form id="form1" runat="server">
+ </form>
+</body>
+</html>
diff --git a/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds-irrelevant.aspx b/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds-irrelevant.aspx
new file mode 100644
index 0000000..3cdebab
--- /dev/null
+++ b/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds-irrelevant.aspx
@@ -0,0 +1,12 @@
+<%@ Page Language="C#" AutoEventWireup="true" ContentType="application/xrds+xml" %><?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS
+ xmlns:xrds="xri://$xrds"
+ xmlns:openid="http://openid.net/xmlns/1.0"
+ xmlns="xri://$xrd*($v*2.0)">
+ <XRD>
+ <Service priority="10">
+ <Type>junk</Type>
+ <URI>http://a/b</URI>
+ </Service>
+ </XRD>
+</xrds:XRDS>
diff --git a/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds10.aspx b/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds10.aspx
new file mode 100644
index 0000000..1b1af80
--- /dev/null
+++ b/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds10.aspx
@@ -0,0 +1,13 @@
+<%@ Page Language="C#" AutoEventWireup="true" ContentType="application/xrds+xml" %><?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS
+ xmlns:xrds="xri://$xrds"
+ xmlns:openid="http://openid.net/xmlns/1.0"
+ xmlns="xri://$xrd*($v*2.0)">
+ <XRD>
+ <Service priority="10">
+ <Type>http://openid.net/signon/1.0</Type>
+ <Type>http://openid.net/sreg/1.0</Type>
+ <URI>http://a/b</URI>
+ </Service>
+ </XRD>
+</xrds:XRDS>
diff --git a/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds1020.aspx b/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds1020.aspx
new file mode 100644
index 0000000..067aa8a
--- /dev/null
+++ b/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds1020.aspx
@@ -0,0 +1,18 @@
+<%@ Page Language="C#" AutoEventWireup="true" ContentType="application/xrds+xml" %><?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS
+ xmlns:xrds="xri://$xrds"
+ xmlns:openid="http://openid.net/xmlns/1.0"
+ xmlns="xri://$xrd*($v*2.0)">
+ <XRD>
+ <Service priority="10">
+ <Type>http://openid.net/signon/1.0</Type>
+ <Type>http://openid.net/sreg/1.0</Type>
+ <URI>http://a/b</URI>
+ </Service>
+ <Service priority="20">
+ <Type>http://specs.openid.net/auth/2.0/signon</Type>
+ <Type>http://openid.net/sreg/1.0</Type>
+ <URI>http://c/d</URI>
+ </Service>
+ </XRD>
+</xrds:XRDS>
diff --git a/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds11.aspx b/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds11.aspx
new file mode 100644
index 0000000..fd522b4
--- /dev/null
+++ b/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds11.aspx
@@ -0,0 +1,13 @@
+<%@ Page Language="C#" AutoEventWireup="true" ContentType="application/xrds+xml" %><?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS
+ xmlns:xrds="xri://$xrds"
+ xmlns:openid="http://openid.net/xmlns/1.0"
+ xmlns="xri://$xrd*($v*2.0)">
+ <XRD>
+ <Service priority="10">
+ <Type>http://openid.net/signon/1.1</Type>
+ <Type>http://openid.net/sreg/1.0</Type>
+ <URI>http://a/b</URI>
+ </Service>
+ </XRD>
+</xrds:XRDS>
diff --git a/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds20.aspx b/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds20.aspx
new file mode 100644
index 0000000..b31a47a
--- /dev/null
+++ b/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds20.aspx
@@ -0,0 +1,13 @@
+<%@ Page Language="C#" AutoEventWireup="true" ContentType="application/xrds+xml" %><?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS
+ xmlns:xrds="xri://$xrds"
+ xmlns:openid="http://openid.net/xmlns/1.0"
+ xmlns="xri://$xrd*($v*2.0)">
+ <XRD>
+ <Service priority="10">
+ <Type>http://specs.openid.net/auth/2.0/signon</Type>
+ <Type>http://openid.net/sreg/1.0</Type>
+ <URI>http://a/b</URI>
+ </Service>
+ </XRD>
+</xrds:XRDS>
diff --git a/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds2010a.aspx b/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds2010a.aspx
new file mode 100644
index 0000000..efac545
--- /dev/null
+++ b/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds2010a.aspx
@@ -0,0 +1,18 @@
+<%@ Page Language="C#" AutoEventWireup="true" ContentType="application/xrds+xml" %><?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS
+ xmlns:xrds="xri://$xrds"
+ xmlns:openid="http://openid.net/xmlns/1.0"
+ xmlns="xri://$xrd*($v*2.0)">
+ <XRD>
+ <Service priority="10">
+ <Type>http://specs.openid.net/auth/2.0/signon</Type>
+ <Type>http://openid.net/sreg/1.0</Type>
+ <URI>http://a/b</URI>
+ </Service>
+ <Service priority="20">
+ <Type>http://openid.net/signon/1.0</Type>
+ <Type>http://openid.net/sreg/1.0</Type>
+ <URI>http://c/d</URI>
+ </Service>
+ </XRD>
+</xrds:XRDS>
diff --git a/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds2010b.aspx b/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds2010b.aspx
new file mode 100644
index 0000000..c853092
--- /dev/null
+++ b/src/DotNetOpenId.TestWeb/xrdsdiscovery/xrds2010b.aspx
@@ -0,0 +1,18 @@
+<%@ Page Language="C#" AutoEventWireup="true" ContentType="application/xrds+xml" %><?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS
+ xmlns:xrds="xri://$xrds"
+ xmlns:openid="http://openid.net/xmlns/1.0"
+ xmlns="xri://$xrd*($v*2.0)">
+ <XRD>
+ <Service priority="20">
+ <Type>http://openid.net/signon/1.0</Type>
+ <Type>http://openid.net/sreg/1.0</Type>
+ <URI>http://c/d</URI>
+ </Service>
+ <Service priority="10">
+ <Type>http://specs.openid.net/auth/2.0/signon</Type>
+ <Type>http://openid.net/sreg/1.0</Type>
+ <URI>http://a/b</URI>
+ </Service>
+ </XRD>
+</xrds:XRDS>
diff --git a/src/DotNetOpenId/Extensions/Constants.cs b/src/DotNetOpenId/Extensions/Constants.cs
index ae4c99b..9a59bff 100644
--- a/src/DotNetOpenId/Extensions/Constants.cs
+++ b/src/DotNetOpenId/Extensions/Constants.cs
@@ -9,6 +9,7 @@ namespace DotNetOpenId.Extensions {
/// </summary>
internal static class Constants {
internal static class sreg {
+ internal const string TypeUri = "http://openid.net/sreg/1.0";
internal const string sreg_ns = "http://openid.net/extensions/sreg/1.1";
internal const string sreg_compatibility_alias = "sreg";
internal const string policy_url = "policy_url";
diff --git a/src/DotNetOpenId/Protocol.cs b/src/DotNetOpenId/Protocol.cs
index f0aeb63..50761bc 100644
--- a/src/DotNetOpenId/Protocol.cs
+++ b/src/DotNetOpenId/Protocol.cs
@@ -4,8 +4,9 @@ using System.Text;
namespace DotNetOpenId {
public enum ProtocolVersion {
+ V10,
V11,
- V20
+ V20,
}
/// <summary>
@@ -83,6 +84,7 @@ namespace DotNetOpenId {
}
public static Protocol Lookup(ProtocolVersion version) {
switch (version) {
+ case ProtocolVersion.V10: return Protocol.v10;
case ProtocolVersion.V11: return Protocol.v11;
case ProtocolVersion.V20: return Protocol.v20;
default: throw new ArgumentOutOfRangeException("version");
@@ -290,5 +292,8 @@ namespace DotNetOpenId {
public override int GetHashCode() {
return Version.GetHashCode();
}
+ public override string ToString() {
+ return string.Format("OpenID Authentication {0}.{1}", Version.Major, Version.Minor);
+ }
}
}
diff --git a/src/DotNetOpenId/Provider/IdentityEndpoint.cs b/src/DotNetOpenId/Provider/IdentityEndpoint.cs
index f976597..ce7b34f 100644
--- a/src/DotNetOpenId/Provider/IdentityEndpoint.cs
+++ b/src/DotNetOpenId/Provider/IdentityEndpoint.cs
@@ -48,7 +48,7 @@ namespace DotNetOpenId.Provider {
#endregion
internal Protocol Protocol {
- get { return ProviderVersion == ProtocolVersion.V11 ? Protocol.v11 : Protocol.v20; }
+ get { return Protocol.Lookup(ProviderVersion); }
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings")]
diff --git a/src/DotNetOpenId/UriIdentifier.cs b/src/DotNetOpenId/UriIdentifier.cs
index d511b32..1a42571 100644
--- a/src/DotNetOpenId/UriIdentifier.cs
+++ b/src/DotNetOpenId/UriIdentifier.cs
@@ -6,6 +6,7 @@ using DotNetOpenId.Yadis;
using System.Collections.Specialized;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
+using System.Diagnostics;
namespace DotNetOpenId {
class UriIdentifier : Identifier {
@@ -112,9 +113,10 @@ namespace DotNetOpenId {
// rel attributes are supposed to be interpreted with case INsensitivity,
// and is a space-delimited list of values. (http://www.htmlhelp.com/reference/html40/values.html#linktypes)
if (Regex.IsMatch(linkTag.Attributes["rel"], @"\b" + Regex.Escape(protocol.HtmlDiscoveryProviderKey) + @"\b", RegexOptions.IgnoreCase)) {
- providerEndpoint = new Uri(linkTag.Href);
- discoveredProtocol = protocol;
- break;
+ if (Uri.TryCreate(linkTag.Href, UriKind.Absolute, out providerEndpoint)) {
+ discoveredProtocol = protocol;
+ break;
+ }
}
}
if (providerEndpoint != null) break;
@@ -124,8 +126,14 @@ namespace DotNetOpenId {
// See if a LocalId tag of the discovered version exists
foreach (var linkTag in linkTags) {
if (Regex.IsMatch(linkTag.Attributes["rel"], @"\b" + Regex.Escape(discoveredProtocol.HtmlDiscoveryLocalIdKey) + @"\b", RegexOptions.IgnoreCase)) {
- providerLocalIdentifier = new Uri(linkTag.Href);
- break;
+ if (Identifier.IsValid(linkTag.Href)) {
+ providerLocalIdentifier = linkTag.Href;
+ break;
+ } else {
+ if (TraceUtil.Switch.TraceWarning)
+ Trace.TraceWarning("Skipping endpoint data because local id is badly formed ({0}).", linkTag.Href);
+ return null; // badly formed URL used as LocalId
+ }
}
}