//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Test.OpenId.DiscoveryServices {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.RelyingParty;
using DotNetOpenAuth.Test.Mocks;
using NUnit.Framework;
[TestFixture]
public class XriDiscoveryProxyServiceTests : OpenIdTestBase {
[Test]
public async Task Discover() {
string xrds = @"
*Arnott
2008-07-14T02:03:24.000Z
xri://=
!9b72.7dd1.50a9.5ccd
=!9B72.7DD1.50A9.5CCD
xri://!!1008
xri://+i-service*(+contact)*($v*1.0)
(+contact)
http://1id.com/contact/
xri://!!1008
xri://+i-service*(+forwarding)*($v*1.0)
http://1id.com/
xri://!!1008
http://openid.net/signon/1.0
http://1id.com/sso
";
var mocks = new Dictionary {
{ "https://xri.net/=Arnott?_xrd_r=application/xrd%2Bxml;sep=false", xrds },
{ "https://xri.net/=!9B72.7DD1.50A9.5CCD?_xrd_r=application/xrd%2Bxml;sep=false", xrds },
};
this.RegisterMockXrdsResponses(mocks);
string expectedCanonicalId = "=!9B72.7DD1.50A9.5CCD";
IdentifierDiscoveryResult se = await this.VerifyCanonicalIdAsync("=Arnott", expectedCanonicalId);
Assert.AreEqual(Protocol.V10, Protocol.Lookup(se.Version));
Assert.AreEqual("http://1id.com/sso", se.ProviderEndpoint.ToString());
Assert.AreEqual(se.ClaimedIdentifier, se.ProviderLocalIdentifier);
Assert.AreEqual("=Arnott", se.FriendlyIdentifierForDisplay);
}
[Test]
public async Task DiscoverCommunityInameCanonicalIDs() {
string llliResponse = @"
*llli
2008-07-14T02:21:06.000Z
xri://@
!72cd.a072.157e.a9c6
@!72CD.A072.157E.A9C6
xri://!!1003!103
http://openid.net/signon/1.0
https://login.llli.org/server/
xri://!!1003!103
xri://+i-service*(+forwarding)*($v*1.0)
(+index)
http://linksafe-forward.ezibroker.net/forwarding/
xri://!!1003!103
xri://$res*auth*($v*2.0)
application/xrds+xml;trust=none
http://resolve.ezibroker.net/resolve/@llli/
xri://!!1003!103
xri://+i-service*(+contact)*($v*1.0)
(+contact)
http://linksafe-contact.ezibroker.net/contact/
";
string llliAreaResponse = @"
*area
SUCCESS
SUCCESS
2008-07-15T01:21:07.000Z
xri://!!1003
0000.0000.3B9A.CA0C
@!72CD.A072.157E.A9C6!0000.0000.3B9A.CA0C
xri://!!1003!103
http://openid.net/signon/1.0
https://login.llli.org/server/
xri://!!1003!103
xri://+i-service*(+contact)*($v*1.0)
(+contact)
http://linksafe-contact.ezibroker.net/contact/
xri://!!1003!103
xri://+i-service*(+forwarding)*($v*1.0)
(+index)
http://linksafe-forward.ezibroker.net/forwarding/
xri://!!1003!103
xri://$res*auth*($v*2.0)
application/xrds+xml;trust=none
http://resolve.ezibroker.net/resolve/@llli*area/
";
string llliAreaCanadaUnattachedResponse = @"
*canada.unattached
SUCCESS
SUCCESS
2008-07-15T01:21:08.000Z
xri://!!1003
0000.0000.3B9A.CA41
@!72CD.A072.157E.A9C6!0000.0000.3B9A.CA0C!0000.0000.3B9A.CA41
xri://!!1003!103
http://openid.net/signon/1.0
https://login.llli.org/server/
xri://!!1003!103
xri://+i-service*(+contact)*($v*1.0)
(+contact)
http://linksafe-contact.ezibroker.net/contact/
xri://!!1003!103
xri://+i-service*(+forwarding)*($v*1.0)
(+index)
http://linksafe-forward.ezibroker.net/forwarding/
xri://!!1003!103
xri://$res*auth*($v*2.0)
application/xrds+xml;trust=none
http://resolve.ezibroker.net/resolve/@llli*area*canada.unattached/
";
string llliAreaCanadaUnattachedAdaResponse = @"
*ada
SUCCESS
SUCCESS
2008-07-15T01:21:10.000Z
xri://!!1003
0000.0000.3B9A.CA01
@!72CD.A072.157E.A9C6!0000.0000.3B9A.CA0C!0000.0000.3B9A.CA41!0000.0000.3B9A.CA01
xri://!!1003!103
http://openid.net/signon/1.0
https://login.llli.org/server/
xri://!!1003!103
xri://+i-service*(+contact)*($v*1.0)
(+contact)
http://linksafe-contact.ezibroker.net/contact/
xri://!!1003!103
xri://+i-service*(+forwarding)*($v*1.0)
(+index)
http://linksafe-forward.ezibroker.net/forwarding/
";
string webResponse = @"
*Web
2008-07-14T02:21:12.000Z
xri://=
!91f2.8153.f600.ae24
=!91F2.8153.F600.AE24
xri://+i-service*(+locator)*($v*1.0)
(+locator)
http://locator.fullxri.com/locator/
xri://=web
xri://$res*auth*($v*2.0)
xri://$res*auth*($v*2.0)
application/xrds+xml
https://resolve.freexri.com/ns/=web/
http://resolve.freexri.com/ns/=web/
http://openid.net/signon/1.0
http://specs.openid.net/auth/2.0/signon
(+login)
http://authn.fullxri.com/authentication/
https://authn.fullxri.com/authentication/
xri://+i-service*(+contact)*($v*1.0)
(+contact)
http://contact.fullxri.com/contact/
MIIExzCCA6+gAwIBAgIJAM+MlFr0Sth6MA0GCSqGSIb3DQEBBQUAMIGdMR8wHQYD
VQQDExZTdXBlcnZpbGxhaW46IFRoZSBSb290MQswCQYDVQQGEwJVUzERMA8GA1UE
CBMITmV3IFlvcmsxDzANBgNVBAcTBkdvdGhhbTEgMB4GA1UEChMXU3VwZXJ2aWxs
YWluIFVuaXZlcnNpdHkxJzAlBgkqhkiG9w0BCQEWGHBlbmd1aW5Ac3VwZXJ2aWxs
YWluLmVkdTAeFw0wNjA4MTcxOTU5NTNaFw0xMTA4MTYxOTU5NTNaMIGdMR8wHQYD
VQQDExZTdXBlcnZpbGxhaW46IFRoZSBSb290MQswCQYDVQQGEwJVUzERMA8GA1UE
CBMITmV3IFlvcmsxDzANBgNVBAcTBkdvdGhhbTEgMB4GA1UEChMXU3VwZXJ2aWxs
YWluIFVuaXZlcnNpdHkxJzAlBgkqhkiG9w0BCQEWGHBlbmd1aW5Ac3VwZXJ2aWxs
YWluLmVkdTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL6uFqas4dK6
A2wTZL0viRQNJrPyFnFBDSZGib/2ijhgzed/vvmZ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
{ "https://xri.net/@llli?_xrd_r=application/xrd%2Bxml;sep=false", llliResponse },
{ "https://xri.net/@llli*area?_xrd_r=application/xrd%2Bxml;sep=false", llliAreaResponse },
{ "https://xri.net/@llli*area*canada.unattached?_xrd_r=application/xrd%2Bxml;sep=false", llliAreaCanadaUnattachedResponse },
{ "https://xri.net/@llli*area*canada.unattached*ada?_xrd_r=application/xrd%2Bxml;sep=false", llliAreaCanadaUnattachedAdaResponse },
{ "https://xri.net/=Web?_xrd_r=application/xrd%2Bxml;sep=false", webResponse },
});
await this.VerifyCanonicalIdAsync("@llli", "@!72CD.A072.157E.A9C6");
await this.VerifyCanonicalIdAsync("@llli*area", "@!72CD.A072.157E.A9C6!0000.0000.3B9A.CA0C");
await this.VerifyCanonicalIdAsync("@llli*area*canada.unattached", "@!72CD.A072.157E.A9C6!0000.0000.3B9A.CA0C!0000.0000.3B9A.CA41");
await this.VerifyCanonicalIdAsync("@llli*area*canada.unattached*ada", "@!72CD.A072.157E.A9C6!0000.0000.3B9A.CA0C!0000.0000.3B9A.CA41!0000.0000.3B9A.CA01");
await this.VerifyCanonicalIdAsync("=Web", "=!91F2.8153.F600.AE24");
}
[Test]
public async Task DiscoveryCommunityInameDelegateWithoutCanonicalID() {
this.RegisterMockXrdsResponses(new Dictionary {
{ "https://xri.net/=Web*andrew.arnott?_xrd_r=application/xrd%2Bxml;sep=false", @"
*andrew.arnott
Success
Success
2008-07-14T03:30:59.722Z
=!91F2.8153.F600.AE24
http://openid.net/signon/1.0
(+login)
http://www.myopenid.com/server
http://blog.nerdbank.net
@!7F6F.F50.A4E4.1133
xri://+i-service*(+contact)*($v*1.0)
(+contact)
http://contact.freexri.com/contact/
@!7F6F.F50.A4E4.1133
xri://+i-service*(+forwarding)*($v*1.0)
(+index)
http://forwarding.freexri.com/forwarding/
@!7F6F.F50.A4E4.1133
http://openid.net/signon/1.0
(+login)
http://authn.freexri.com/authentication/
https://authn.freexri.com/authentication/
OpenXRI
" },
{ "https://xri.net/@id*andrewarnott?_xrd_r=application/xrd%2Bxml;sep=false", @"
*andrewarnott
Success
Success
2008-07-14T03:31:00.466Z
@!B1E8.C27B.E41C.25C3
http://openid.net/signon/1.0
(+login)
http://www.myopenid.com/server
http://blog.nerdbank.net
@!7F6F.F50.A4E4.1133
xri://+i-service*(+contact)*($v*1.0)
(+contact)
http://contact.freexri.com/contact/
@!7F6F.F50.A4E4.1133
xri://+i-service*(+forwarding)*($v*1.0)
(+index)
http://forwarding.freexri.com/forwarding/
OpenXRI
" },
});
// Consistent with spec section 7.3.2.3, we do not permit
// delegation on XRI discovery when there is no CanonicalID present.
await this.VerifyCanonicalIdAsync("=Web*andrew.arnott", null);
await this.VerifyCanonicalIdAsync("@id*andrewarnott", null);
}
private async Task VerifyCanonicalIdAsync(Identifier iname, string expectedClaimedIdentifier) {
var se = (await this.DiscoverAsync(iname)).FirstOrDefault();
if (expectedClaimedIdentifier != null) {
Assert.IsNotNull(se);
Assert.AreEqual(expectedClaimedIdentifier, se.ClaimedIdentifier.ToString(), "i-name {0} discovery resulted in unexpected CanonicalId", iname);
Assert.IsTrue(se.Capabilities.Count > 0);
} else {
Assert.IsNull(se);
}
return se;
}
}
}