Permalink
Browse files

Merge branch 'v2.1' into v2.2

Conflicts:

	src/DotNetOpenId/Strings.Designer.cs
	src/DotNetOpenId/Strings.resx
  • Loading branch information...
2 parents 53bbb4d + e985d1e commit c97145c20fff3677b8c58e12e07ac99e6e3ea734 @AArnott AArnott committed Jun 19, 2008
@@ -62,23 +62,49 @@ public class XriIdentifierTests {
Assert.AreNotEqual(goodXri, new XriIdentifier(goodXri));
}
- [Test]
- public void Discover() {
+ private ServiceEndpoint verifyCanonicalId(Identifier iname, string expectedClaimedIdentifier) {
// This test requires a network connection
- Identifier id = "=Arnott";
ServiceEndpoint se = null;
try {
- se = id.Discover();
+ se = iname.Discover();
} catch (WebException ex) {
if (ex.Message.Contains("remote name could not be resolved"))
Assert.Ignore("This test requires a network connection.");
}
- Assert.IsNotNull(se);
+ if (expectedClaimedIdentifier != null) {
+ Assert.IsNotNull(se);
+ Assert.AreEqual(expectedClaimedIdentifier, se.ClaimedIdentifier.ToString(), "i-name {0} discovery resulted in unexpected CanonicalId", iname);
+ Assert.AreEqual(1, se.ProviderSupportedServiceTypeUris.Length);
+ } else {
+ Assert.IsNull(se);
+ }
+ return se;
+ }
+
+ [Test]
+ public void Discover() {
+ string expectedCanonicalId = "=!9B72.7DD1.50A9.5CCD";
+ ServiceEndpoint se = verifyCanonicalId("=Arnott", expectedCanonicalId);
Assert.AreEqual(Protocol.v10, se.Protocol);
- Assert.AreEqual("=!9B72.7DD1.50A9.5CCD", se.ClaimedIdentifier.ToString());
Assert.AreEqual("http://1id.com/sso", se.ProviderEndpoint.ToString());
- Assert.AreEqual("=!9B72.7DD1.50A9.5CCD", se.ProviderLocalIdentifier.ToString());
- Assert.AreEqual(1, se.ProviderSupportedServiceTypeUris.Length);
+ Assert.AreEqual(se.ClaimedIdentifier, se.ProviderLocalIdentifier);
+ }
+
+ [Test]
+ public void DiscoverCommunityInameCanonicalIDs() {
+ verifyCanonicalId("@llli", "@!72CD.A072.157E.A9C6");
+ verifyCanonicalId("@llli*area", "@!72CD.A072.157E.A9C6!0000.0000.3B9A.CA0C");
+ verifyCanonicalId("@llli*area*canada.unattached", "@!72CD.A072.157E.A9C6!0000.0000.3B9A.CA0C!0000.0000.3B9A.CA41");
+ verifyCanonicalId("@llli*area*canada.unattached*ada", "@!72CD.A072.157E.A9C6!0000.0000.3B9A.CA0C!0000.0000.3B9A.CA41!0000.0000.3B9A.CA01");
+ verifyCanonicalId("=Web", "=!91F2.8153.F600.AE24");
+ }
+
+ [Test]
+ public void DiscoveryCommunityInameDelegateWithoutCanonicalID() {
+ // Consistent with spec section 7.3.2.3, we do not permit
+ // delegation on XRI discovery when there is no CanonicalID present.
+ verifyCanonicalId("=Web*andrew.arnott", null);
+ verifyCanonicalId("@id*andrewarnott", null);
}
}
}
@@ -122,13 +122,13 @@ internal class KeyValueFormEncoding : IProtocolMessageEncoding {
string[] parts = line.Split(new[] { ':' }, 2);
if (parts.Length != 2) {
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
- Strings.InvalidKeyValueFormCharacterMissing, ':'));
+ Strings.InvalidKeyValueFormCharacterMissing, ':', line_num, line));
}
if (ConformanceLevel > KeyValueFormConformanceLevel.Loose) {
if (char.IsWhiteSpace(parts[0], parts[0].Length-1) ||
char.IsWhiteSpace(parts[1], 0)) {
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
- Strings.InvalidCharacterInKeyValueFormInput, ' '));
+ Strings.InvalidCharacterInKeyValueFormInput, ' ', line_num, line));
}
}
if (ConformanceLevel < KeyValueFormConformanceLevel.OpenId20) {
@@ -143,7 +143,7 @@ internal class KeyValueFormEncoding : IProtocolMessageEncoding {
reader.BaseStream.Seek(-1, SeekOrigin.End);
if (reader.BaseStream.ReadByte() != '\n') {
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
- Strings.InvalidKeyValueFormCharacterMissing, "\\n"));
+ Strings.InvalidKeyValueFormCharacterMissing, "\\n", line_num, line));
}
}
return dict;
View
@@ -5,6 +5,7 @@
using DotNetOpenId.Yadis;
using DotNetOpenId.Provider;
using System.Collections.Generic;
+using System.Xml;
namespace DotNetOpenId {
/// <summary>
@@ -274,11 +275,15 @@ internal Realm(UriBuilder realmUriBuilder)
Strings.RealmCausedRedirectUponDiscovery, yadisResult.RequestUri));
}
if (yadisResult.IsXrds) {
- XrdsDocument xrds = new XrdsDocument(yadisResult.ResponseText);
- return xrds.FindRelyingPartyReceivingEndpoints();
+ try {
+ XrdsDocument xrds = new XrdsDocument(yadisResult.ResponseText);
+ return xrds.FindRelyingPartyReceivingEndpoints();
+ } catch (XmlException ex) {
+ throw new OpenIdException(Strings.InvalidXRDSDocument, ex);
+ }
}
}
- return new List<DotNetOpenId.Provider.RelyingPartyReceivingEndpoint>(); // empty list
+ return new RelyingPartyReceivingEndpoint[0];
}
/// <summary>

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -160,10 +160,10 @@
<value>ClaimedIdentifier and LocalIdentifier must be the same when IsIdentifierSelect is true.</value>
</data>
<data name="InvalidCharacterInKeyValueFormInput" xml:space="preserve">
- <value>Cannot encode '{0}' because it contains an illegal character for Key-Value Form encoding.</value>
+ <value>Cannot encode '{0}' because it contains an illegal character for Key-Value Form encoding. (line {1}: '{2}')</value>
</data>
<data name="InvalidKeyValueFormCharacterMissing" xml:space="preserve">
- <value>Cannot decode Key-Value Form because a line was found without a '{0}' character.</value>
+ <value>Cannot decode Key-Value Form because a line was found without a '{0}' character. (line {1}: '{2}')</value>
</data>
<data name="InvalidNonce" xml:space="preserve">
<value>The nonce was not in the expected format.</value>
@@ -186,6 +186,9 @@
<data name="InvalidUri" xml:space="preserve">
<value>The value '{0}' is not a valid URI.</value>
</data>
+ <data name="InvalidXRDSDocument" xml:space="preserve">
+ <value>Failure parsing XRDS document.</value>
+ </data>
<data name="InvalidXri" xml:space="preserve">
<value>Not a recognized XRI format: '{0}'.</value>
</data>
@@ -202,7 +205,7 @@
<value>The '{0}' and '{1}' parameters must both be or not be '{2}'.</value>
</data>
<data name="MissingCanonicalIDElement" xml:space="preserve">
- <value>The XRDS document is missing the required CanonicalID element.</value>
+ <value>The XRDS document for XRI {0} is missing the required CanonicalID element.</value>
</data>
<data name="MissingInternalQueryParameter" xml:space="preserve">
<value>Query parameter '{0}' was missing from the query.</value>
@@ -49,7 +49,15 @@ class XriIdentifier : Identifier {
return xri;
}
- const string xriResolverProxy = "http://xri.net/{0}?_xrd_r=application/xrds%2Bxml;sep=false";
+ /// <summary>
+ /// The magic URL that will provide us an XRDS document for a given XRI identifier.
+ /// </summary>
+ /// <remarks>
+ /// We use application/xrd+xml instead of application/xrds+xml because it gets
+ /// xri.net to automatically give us exactly the right XRD element for community i-names
+ /// automatically, saving us having to choose which one to use out of the result.
+ /// </remarks>
+ const string xriResolverProxy = "http://xri.net/{0}?_xrd_r=application/xrd%2Bxml;sep=false";
/// <summary>
/// Resolves the XRI to a URL from which an XRDS document may be downloaded.
/// </summary>
@@ -13,8 +13,11 @@ class ServiceElement : XrdsNode, IComparable<ServiceElement> {
get { return (XrdElement)ParentNode; }
}
- public int Priority {
- get { return Node.SelectSingleNode("@priority", XmlNamespaceResolver).ValueAsInt; }
+ public int? Priority {
+ get {
+ XPathNavigator n = Node.SelectSingleNode("@priority", XmlNamespaceResolver);
+ return n != null ? n.ValueAsInt : (int?)null;
+ }
}
public IEnumerable<UriElement> UriElements {
@@ -41,7 +44,7 @@ class ServiceElement : XrdsNode, IComparable<ServiceElement> {
XPathNodeIterator types = Node.Select("xrd:Type", XmlNamespaceResolver);
string[] typeUris = new string[types.Count];
int i = 0;
- foreach(XPathNavigator type in types) {
+ foreach (XPathNavigator type in types) {
typeUris[i++] = type.Value;
}
return typeUris;
@@ -50,7 +53,7 @@ class ServiceElement : XrdsNode, IComparable<ServiceElement> {
public Identifier ProviderLocalIdentifier {
get {
- var n = Node.SelectSingleNode("xrd:LocalID", XmlNamespaceResolver)
+ var n = Node.SelectSingleNode("xrd:LocalID", XmlNamespaceResolver)
?? Node.SelectSingleNode("openid10:Delegate", XmlNamespaceResolver);
return (n != null) ? n.Value : null;
}
@@ -59,7 +62,18 @@ class ServiceElement : XrdsNode, IComparable<ServiceElement> {
#region IComparable<ServiceElement> Members
public int CompareTo(ServiceElement other) {
- return Priority.CompareTo(other.Priority);
+ if (other == null) return -1;
+ if (Priority.HasValue && other.Priority.HasValue) {
+ return Priority.Value.CompareTo(other.Priority.Value);
+ } else {
+ if (Priority.HasValue) {
+ return -1;
+ } else if (other.Priority.HasValue) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
}
#endregion
@@ -5,6 +5,7 @@
using System.Collections.Generic;
using DotNetOpenId.RelyingParty;
using DotNetOpenId.Provider;
+using System.Diagnostics;
namespace DotNetOpenId.Yadis {
class XrdsDocument : XrdsNode {
@@ -21,7 +22,15 @@ public XrdsDocument(string xml)
public IEnumerable<XrdElement> XrdElements {
get {
- foreach (XPathNavigator node in Node.Select("/xrds:XRDS/xrd:XRD", XmlNamespaceResolver)) {
+ // We may be looking at a full XRDS document (in the case of YADIS discovery)
+ // or we may be looking at just an individual XRD element from a larger document
+ // if we asked xri.net for just one.
+ if (Node.SelectSingleNode("/xrds:XRDS", XmlNamespaceResolver) != null) {
+ foreach (XPathNavigator node in Node.Select("/xrds:XRDS/xrd:XRD", XmlNamespaceResolver)) {
+ yield return new XrdElement(node, this);
+ }
+ } else {
+ XPathNavigator node = Node.SelectSingleNode("/xrd:XRD", XmlNamespaceResolver);
yield return new XrdElement(node, this);
}
}
@@ -35,7 +44,7 @@ public XrdsDocument(string xml)
return createServiceEndpoint(userSuppliedIdentifier);
}
- ServiceEndpoint createServiceEndpoint(Identifier claimedIdentifier) {
+ ServiceEndpoint createServiceEndpoint(Identifier userSuppliedOrClaimedIdentifier) {
// First search for OP Identifier service elements
foreach (var service in findOPIdentifierServices()) {
foreach (var uri in service.UriElements) {
@@ -49,12 +58,17 @@ public XrdsDocument(string xml)
foreach (var service in findClaimedIdentifierServices()) {
foreach (var uri in service.UriElements) {
// spec section 7.3.2.3 on Claimed Id -> CanonicalID substitution
- if (claimedIdentifier is XriIdentifier) {
- if (service.Xrd.CanonicalID == null)
- throw new OpenIdException(Strings.MissingCanonicalIDElement, claimedIdentifier);
- claimedIdentifier = service.Xrd.CanonicalID;
+ if (userSuppliedOrClaimedIdentifier is XriIdentifier) {
+ if (service.Xrd.CanonicalID == null) {
+ if (TraceUtil.Switch.TraceWarning) {
+ Trace.TraceWarning(Strings.MissingCanonicalIDElement, userSuppliedOrClaimedIdentifier);
+ }
+ return null;
+ }
+ // In the case of XRI names, the ClaimedId is actually the CanonicalID.
+ userSuppliedOrClaimedIdentifier = service.Xrd.CanonicalID;
}
- return new ServiceEndpoint(claimedIdentifier, uri.Uri,
+ return new ServiceEndpoint(userSuppliedOrClaimedIdentifier, uri.Uri,
service.ProviderLocalIdentifier, service.TypeElementUris);
}
}

0 comments on commit c97145c

Please sign in to comment.