summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenId.Test
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenId.Test')
-rw-r--r--src/DotNetOpenId.Test/EndToEndTesting.cs47
-rw-r--r--src/DotNetOpenId.Test/IdentifierTests.cs3
-rw-r--r--src/DotNetOpenId.Test/RelyingParty/OpenIdRelyingPartyTest.cs117
-rw-r--r--src/DotNetOpenId.Test/RelyingParty/ServiceEndpointTests.cs98
-rw-r--r--src/DotNetOpenId.Test/RelyingParty/TokenTest.cs14
-rw-r--r--src/DotNetOpenId.Test/TestSupport.cs39
-rw-r--r--src/DotNetOpenId.Test/UriIdentifierTests.cs37
-rw-r--r--src/DotNetOpenId.Test/XriIdentifierTests.cs42
8 files changed, 328 insertions, 69 deletions
diff --git a/src/DotNetOpenId.Test/EndToEndTesting.cs b/src/DotNetOpenId.Test/EndToEndTesting.cs
index 8f94744..1997638 100644
--- a/src/DotNetOpenId.Test/EndToEndTesting.cs
+++ b/src/DotNetOpenId.Test/EndToEndTesting.cs
@@ -25,10 +25,16 @@ namespace DotNetOpenId.Test {
void parameterizedTest(UriIdentifier identityUrl,
AuthenticationRequestMode requestMode, AuthenticationStatus expectedResult,
bool tryReplayAttack, bool provideStore) {
- parameterizedProgrammaticTest(identityUrl, requestMode, expectedResult, tryReplayAttack, provideStore);
+ parameterizedProgrammaticTest(identityUrl, identityUrl, requestMode, expectedResult, tryReplayAttack, provideStore);
parameterizedWebClientTest(identityUrl, requestMode, expectedResult, tryReplayAttack, provideStore);
}
- void parameterizedProgrammaticTest(UriIdentifier identityUrl,
+ void parameterizedTest(UriIdentifier opIdentifier, UriIdentifier claimedIdentifier,
+ AuthenticationRequestMode requestMode, AuthenticationStatus expectedResult,
+ bool tryReplayAttack, bool provideStore) {
+ parameterizedProgrammaticTest(opIdentifier, claimedIdentifier, requestMode, expectedResult, tryReplayAttack, provideStore);
+ parameterizedWebClientTest(opIdentifier, requestMode, expectedResult, tryReplayAttack, provideStore);
+ }
+ void parameterizedProgrammaticTest(UriIdentifier identityUrl, UriIdentifier claimedUrl,
AuthenticationRequestMode requestMode, AuthenticationStatus expectedResult,
bool tryReplayAttack, bool provideStore) {
var store = provideStore ? appStore : null;
@@ -74,7 +80,7 @@ namespace DotNetOpenId.Test {
}
consumer = new OpenIdRelyingParty(store, redirectUrl, HttpUtility.ParseQueryString(redirectUrl.Query));
Assert.AreEqual(expectedResult, consumer.Response.Status);
- Assert.AreEqual(identityUrl, consumer.Response.ClaimedIdentifier);
+ Assert.AreEqual(claimedUrl, consumer.Response.ClaimedIdentifier);
// Try replay attack
if (tryReplayAttack) {
@@ -268,5 +274,40 @@ namespace DotNetOpenId.Test {
false
);
}
+ [Test]
+ public void Pass_Setup_ApproveOnSetup_DirectedIdentity_20() {
+ parameterizedTest(
+ TestSupport.GetOPIdentityUrl(TestSupport.Scenarios.ApproveOnSetup),
+ TestSupport.GetDirectedIdentityUrl(TestSupport.Scenarios.ApproveOnSetup, ProtocolVersion.V20),
+ AuthenticationRequestMode.Setup,
+ AuthenticationStatus.Authenticated,
+ true,
+ true);
+ }
+ [Test]
+ public void Pass_NoStore_ApproveOnSetup_DirectedIdentity_20() {
+ parameterizedTest(
+ TestSupport.GetOPIdentityUrl(TestSupport.Scenarios.ApproveOnSetup),
+ TestSupport.GetDirectedIdentityUrl(TestSupport.Scenarios.ApproveOnSetup, ProtocolVersion.V20),
+ AuthenticationRequestMode.Setup,
+ AuthenticationStatus.Authenticated,
+ true,
+ false);
+ }
+
+ [Test]
+ public void ProviderAddedFragmentRemainsInClaimedIdentifier() {
+ Uri userSuppliedIdentifier = TestSupport.GetIdentityUrl(TestSupport.Scenarios.AutoApprovalAddFragment, ProtocolVersion.V20);
+ UriBuilder claimedIdentifier = new UriBuilder(userSuppliedIdentifier);
+ claimedIdentifier.Fragment = "frag";
+ parameterizedProgrammaticTest(
+ userSuppliedIdentifier,
+ claimedIdentifier.Uri,
+ AuthenticationRequestMode.Setup,
+ AuthenticationStatus.Authenticated,
+ false,
+ true
+ );
+ }
}
}
diff --git a/src/DotNetOpenId.Test/IdentifierTests.cs b/src/DotNetOpenId.Test/IdentifierTests.cs
index 0f13ae2..562ed90 100644
--- a/src/DotNetOpenId.Test/IdentifierTests.cs
+++ b/src/DotNetOpenId.Test/IdentifierTests.cs
@@ -51,9 +51,6 @@ namespace DotNetOpenId.Test {
id = Identifier.Parse(uriNoScheme);
Assert.IsInstanceOfType(typeof(UriIdentifier), id);
Assert.AreEqual(uri, ((UriIdentifier)id).Uri.AbsoluteUri);
- // verify that fragments are stripped
- id = Identifier.Parse(uri + "#fragment");
- Assert.AreEqual(uri, ((UriIdentifier)id).Uri.AbsoluteUri);
}
[Test, ExpectedException(typeof(ArgumentNullException))]
diff --git a/src/DotNetOpenId.Test/RelyingParty/OpenIdRelyingPartyTest.cs b/src/DotNetOpenId.Test/RelyingParty/OpenIdRelyingPartyTest.cs
index a2ca984..2503207 100644
--- a/src/DotNetOpenId.Test/RelyingParty/OpenIdRelyingPartyTest.cs
+++ b/src/DotNetOpenId.Test/RelyingParty/OpenIdRelyingPartyTest.cs
@@ -1,9 +1,10 @@
using System;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.Web;
using DotNetOpenId.RelyingParty;
using NUnit.Framework;
using ProviderMemoryStore = DotNetOpenId.AssociationMemoryStore<DotNetOpenId.AssociationRelyingPartyType>;
-using System.Web;
-using System.Collections.Specialized;
namespace DotNetOpenId.Test.RelyingParty {
[TestFixture]
@@ -21,6 +22,11 @@ namespace DotNetOpenId.Test.RelyingParty {
UntrustedWebRequest.WhitelistHosts.Add("localhost");
}
+ [TearDown]
+ public void TearDown() {
+ UntrustedWebRequest.MockRequests = null;
+ }
+
[Test]
[ExpectedException(typeof(InvalidOperationException))]
public void DefaultCtorWithoutContext() {
@@ -52,6 +58,15 @@ namespace DotNetOpenId.Test.RelyingParty {
}
[Test]
+ public void CreateRequestStripsFragment() {
+ var consumer = new OpenIdRelyingParty(store, simpleNonOpenIdRequest, new NameValueCollection());
+ UriBuilder userSuppliedIdentifier = new UriBuilder((Uri)TestSupport.GetIdentityUrl(TestSupport.Scenarios.AutoApproval, ProtocolVersion.V20));
+ userSuppliedIdentifier.Fragment = "c";
+ IAuthenticationRequest request = consumer.CreateRequest(userSuppliedIdentifier.Uri, realm, returnTo);
+ Assert.AreEqual(0, new Uri(request.ClaimedIdentifier).Fragment.Length);
+ }
+
+ [Test]
public void AssociationCreationWithStore() {
var providerStore = new ProviderMemoryStore();
@@ -142,5 +157,103 @@ namespace DotNetOpenId.Test.RelyingParty {
var returnToArgs = HttpUtility.ParseQueryString(requestArgs[protocol.openid.return_to]);
Assert.AreEqual("c+d", returnToArgs["a+b"]);
}
+
+ static ServiceEndpoint getServiceEndpoint(int? servicePriority, int? uriPriority) {
+ Protocol protocol = Protocol.v20;
+ ServiceEndpoint ep = ServiceEndpoint.CreateForClaimedIdentifier(
+ TestSupport.GetIdentityUrl(TestSupport.Scenarios.AutoApproval, ProtocolVersion.V20),
+ TestSupport.GetDelegateUrl(TestSupport.Scenarios.AutoApproval),
+ TestSupport.GetFullUrl(TestSupport.ProviderPage),
+ new[] { protocol.ClaimedIdentifierServiceTypeURI },
+ servicePriority,
+ uriPriority
+ );
+ return ep;
+ }
+
+ [Test]
+ public void DefaultEndpointOrder() {
+ var consumer = new OpenIdRelyingParty(null, null, null);
+ Assert.AreSame(OpenIdRelyingParty.DefaultEndpointOrder, consumer.EndpointOrder);
+ var defaultEndpointOrder = OpenIdRelyingParty.DefaultEndpointOrder;
+ // Test service priority ordering
+ Assert.AreEqual(-1, defaultEndpointOrder(getServiceEndpoint(10, null), getServiceEndpoint(20, null)));
+ Assert.AreEqual(1, defaultEndpointOrder(getServiceEndpoint(20, null), getServiceEndpoint(10, null)));
+ Assert.AreEqual(0, defaultEndpointOrder(getServiceEndpoint(10, null), getServiceEndpoint(10, null)));
+ Assert.AreEqual(-1, defaultEndpointOrder(getServiceEndpoint(20, null), getServiceEndpoint(null, null)));
+ Assert.AreEqual(1, defaultEndpointOrder(getServiceEndpoint(null, null), getServiceEndpoint(10, null)));
+ Assert.AreEqual(0, defaultEndpointOrder(getServiceEndpoint(null, null), getServiceEndpoint(null, null)));
+ // Test secondary type uri ordering
+ Assert.AreEqual(-1, defaultEndpointOrder(getServiceEndpoint(10, 10), getServiceEndpoint(10, 20)));
+ Assert.AreEqual(1, defaultEndpointOrder(getServiceEndpoint(10, 20), getServiceEndpoint(10, 10)));
+ Assert.AreEqual(0, defaultEndpointOrder(getServiceEndpoint(10, 5), getServiceEndpoint(10, 5)));
+ // test that it is secondary...
+ Assert.AreEqual(1, defaultEndpointOrder(getServiceEndpoint(20, 10), getServiceEndpoint(10, 20)));
+ Assert.AreEqual(-1, defaultEndpointOrder(getServiceEndpoint(null, 10), getServiceEndpoint(null, 20)));
+ Assert.AreEqual(1, defaultEndpointOrder(getServiceEndpoint(null, 20), getServiceEndpoint(null, 10)));
+ Assert.AreEqual(0, defaultEndpointOrder(getServiceEndpoint(null, 10), getServiceEndpoint(null, 10)));
+ }
+
+ [Test]
+ public void DefaultFilter() {
+ var consumer = new OpenIdRelyingParty(null, null, null);
+ Assert.IsNull(consumer.EndpointFilter);
+ }
+
+ [Test]
+ public void MultipleServiceEndpoints() {
+ string xrds = @"<?xml version='1.0' encoding='UTF-8'?>
+<XRD xmlns='xri://$xrd*($v*2.0)'>
+ <Query>=MultipleEndpoint</Query>
+ <ProviderID>=!91F2.8153.F600.AE24</ProviderID>
+ <CanonicalID>=!91F2.8153.F600.AE24</CanonicalID>
+ <Service>
+ <ProviderID>@!7F6F.F50.A4E4.1133</ProviderID>
+ <Type select='true'>xri://+i-service*(+contact)*($v*1.0)</Type>
+ <Type match='null'/>
+ <Path select='true'>(+contact)</Path>
+ <Path match='null'/>
+ <MediaType match='default'/>
+ <URI append='qxri'>http://contact.freexri.com/contact/</URI>
+ </Service>
+ <Service priority='20'>
+ <ProviderID>@!7F6F.F50.A4E4.1133</ProviderID>
+ <Type select='true'>http://openid.net/signon/1.0</Type>
+ <Path select='true'>(+login)</Path>
+ <Path match='default'/>
+ <MediaType match='default'/>
+ <URI append='none' priority='2'>http://authn.freexri.com/auth10/</URI>
+ <URI append='none' priority='1'>https://authn.freexri.com/auth10/</URI>
+ </Service>
+ <Service priority='10'>
+ <ProviderID>@!7F6F.F50.A4E4.1133</ProviderID>
+ <Type select='true'>http://specs.openid.net/auth/2.0/signon</Type>
+ <Path select='true'>(+login)</Path>
+ <Path match='default'/>
+ <MediaType match='default'/>
+ <URI append='none' priority='2'>http://authn.freexri.com/auth20/</URI>
+ <URI append='none' priority='1'>https://authn.freexri.com/auth20/</URI>
+ </Service>
+ <ServedBy>OpenXRI</ServedBy>
+</XRD>";
+ UntrustedWebRequest.MockRequests = TestSupport.GenerateMockXrdsResponses(new Dictionary<string, string> {
+ {"https://xri.net/=MultipleEndpoint?_xrd_r=application/xrd%2Bxml;sep=false", xrds},
+ {"https://xri.net/=!91F2.8153.F600.AE24?_xrd_r=application/xrd%2Bxml;sep=false", xrds},
+ });
+ OpenIdRelyingParty rp = new OpenIdRelyingParty(null, null, null);
+ Realm realm = new Realm("http://somerealm");
+ Uri return_to = new Uri("http://somerealm/return_to");
+ IAuthenticationRequest request = rp.CreateRequest("=MultipleEndpoint", realm, return_to);
+ Assert.AreEqual("https://authn.freexri.com/auth20/", request.Provider.Uri.AbsoluteUri);
+ rp.EndpointOrder = (se1, se2) => -se1.ServicePriority.Value.CompareTo(se2.ServicePriority.Value);
+ request = rp.CreateRequest("=MultipleEndpoint", realm, return_to);
+ Assert.AreEqual("https://authn.freexri.com/auth10/", request.Provider.Uri.AbsoluteUri);
+
+ // Now test the filter. Auth20 would come out on top, if we didn't select it out with the filter.
+ rp.EndpointOrder = OpenIdRelyingParty.DefaultEndpointOrder;
+ rp.EndpointFilter = (se) => se.Uri.AbsoluteUri == "https://authn.freexri.com/auth10/";
+ request = rp.CreateRequest("=MultipleEndpoint", realm, return_to);
+ Assert.AreEqual("https://authn.freexri.com/auth10/", request.Provider.Uri.AbsoluteUri);
+ }
}
}
diff --git a/src/DotNetOpenId.Test/RelyingParty/ServiceEndpointTests.cs b/src/DotNetOpenId.Test/RelyingParty/ServiceEndpointTests.cs
index b85044b..cb2a61b 100644
--- a/src/DotNetOpenId.Test/RelyingParty/ServiceEndpointTests.cs
+++ b/src/DotNetOpenId.Test/RelyingParty/ServiceEndpointTests.cs
@@ -1,32 +1,37 @@
using System;
using System.Collections.Generic;
-using System.Linq;
+using System.IO;
using System.Text;
-using NUnit.Framework;
using DotNetOpenId.RelyingParty;
-using System.IO;
+using NUnit.Framework;
+using System.Diagnostics;
namespace DotNetOpenId.Test.RelyingParty {
[TestFixture]
public class ServiceEndpointTests {
- Identifier claimedId = "http://claimedid.justatest.com";
+ UriIdentifier claimedId = new UriIdentifier("http://claimedid.justatest.com");
+ XriIdentifier claimedXri = new XriIdentifier("=!9B72.7DD1.50A9.5CCD");
+ XriIdentifier userSuppliedXri = new XriIdentifier("=Arnot");
Uri providerEndpoint = new Uri("http://someprovider.com");
Identifier localId = "http://localid.someprovider.com";
string[] v20TypeUris = { Protocol.v20.ClaimedIdentifierServiceTypeURI };
string[] v11TypeUris = { Protocol.v11.ClaimedIdentifierServiceTypeURI };
+ int servicePriority = 10;
+ int uriPriority = 10;
[Test]
public void Ctor() {
- ServiceEndpoint se = new ServiceEndpoint(claimedId, providerEndpoint, localId, v20TypeUris);
+ ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(claimedId, localId, providerEndpoint, v20TypeUris, servicePriority, uriPriority);
Assert.AreSame(claimedId, se.ClaimedIdentifier);
Assert.AreSame(providerEndpoint, se.ProviderEndpoint);
Assert.AreSame(localId, se.ProviderLocalIdentifier);
Assert.AreSame(v20TypeUris, se.ProviderSupportedServiceTypeUris);
+ Assert.AreEqual(servicePriority, ((IXrdsProviderEndpoint)se).ServicePriority);
}
[Test]
public void CtorImpliedLocalIdentifier() {
- ServiceEndpoint se = new ServiceEndpoint(claimedId, providerEndpoint, null, v20TypeUris);
+ ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(claimedId, null, providerEndpoint, v20TypeUris, servicePriority, uriPriority);
Assert.AreSame(claimedId, se.ClaimedIdentifier);
Assert.AreSame(providerEndpoint, se.ProviderEndpoint);
Assert.AreSame(claimedId, se.ProviderLocalIdentifier);
@@ -35,25 +40,26 @@ namespace DotNetOpenId.Test.RelyingParty {
[Test]
public void ProtocolDetection() {
- ServiceEndpoint se = new ServiceEndpoint(claimedId, providerEndpoint, localId, v20TypeUris);
+ ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(claimedId, localId, providerEndpoint, v20TypeUris, servicePriority, uriPriority);
Assert.AreSame(Protocol.v20, se.Protocol);
- se = new ServiceEndpoint(claimedId, providerEndpoint, localId,
- new[] { Protocol.v20.OPIdentifierServiceTypeURI });
+ se = ServiceEndpoint.CreateForClaimedIdentifier(claimedId, localId, providerEndpoint,
+ new[] { Protocol.v20.OPIdentifierServiceTypeURI }, servicePriority, uriPriority);
Assert.AreSame(Protocol.v20, se.Protocol);
- se = new ServiceEndpoint(claimedId, providerEndpoint, localId, v11TypeUris);
+ se = ServiceEndpoint.CreateForClaimedIdentifier(claimedId, localId, providerEndpoint, v11TypeUris, servicePriority, uriPriority);
Assert.AreSame(Protocol.v11, se.Protocol);
}
[Test, ExpectedException(typeof(InvalidOperationException))]
public void ProtocolDetectionWithoutClues() {
- ServiceEndpoint se = new ServiceEndpoint(claimedId, providerEndpoint, localId,
- new[] { Protocol.v20.HtmlDiscoveryLocalIdKey }); // random type URI irrelevant to detection
+ ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(
+ claimedId, localId, providerEndpoint,
+ new[] { Protocol.v20.HtmlDiscoveryLocalIdKey }, servicePriority, uriPriority); // random type URI irrelevant to detection
Protocol p = se.Protocol;
}
[Test]
- public void Serialization() {
- ServiceEndpoint se = new ServiceEndpoint(claimedId, providerEndpoint, localId, v20TypeUris);
+ public void SerializationWithUri() {
+ ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(claimedId, localId, providerEndpoint, v20TypeUris, servicePriority, uriPriority);
StringBuilder sb = new StringBuilder();
using (StringWriter sw = new StringWriter(sb)) {
se.Serialize(sw);
@@ -62,25 +68,77 @@ namespace DotNetOpenId.Test.RelyingParty {
ServiceEndpoint se2 = ServiceEndpoint.Deserialize(sr);
Assert.AreEqual(se, se2);
Assert.AreEqual(se.Protocol.Version, se2.Protocol.Version, "Particularly interested in this, since type URIs are not serialized but version info is.");
+ Assert.AreEqual(se.UserSuppliedIdentifier, se2.UserSuppliedIdentifier);
+ Assert.AreEqual(se.FriendlyIdentifierForDisplay, se2.FriendlyIdentifierForDisplay);
+ }
+ }
+
+ [Test]
+ public void SerializationWithXri() {
+ ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(claimedXri, userSuppliedXri, localId, providerEndpoint, v20TypeUris, servicePriority, uriPriority);
+ StringBuilder sb = new StringBuilder();
+ using (StringWriter sw = new StringWriter(sb)) {
+ se.Serialize(sw);
+ }
+ using (StringReader sr = new StringReader(sb.ToString())) {
+ ServiceEndpoint se2 = ServiceEndpoint.Deserialize(sr);
+ Assert.AreEqual(se, se2);
+ Assert.AreEqual(se.Protocol.Version, se2.Protocol.Version, "Particularly interested in this, since type URIs are not serialized but version info is.");
+ Assert.AreEqual(se.UserSuppliedIdentifier, se2.UserSuppliedIdentifier);
+ Assert.AreEqual(se.FriendlyIdentifierForDisplay, se2.FriendlyIdentifierForDisplay);
}
}
[Test]
public void EqualsTests() {
- ServiceEndpoint se = new ServiceEndpoint(claimedId, providerEndpoint, localId, v20TypeUris);
- ServiceEndpoint se2 = new ServiceEndpoint(claimedId, providerEndpoint, localId, v20TypeUris);
+ ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(claimedId, localId, providerEndpoint, v20TypeUris, servicePriority, uriPriority);
+ ServiceEndpoint se2 = ServiceEndpoint.CreateForClaimedIdentifier(claimedId, localId, providerEndpoint, v20TypeUris, (int?)null, (int?)null);
Assert.AreEqual(se2, se);
Assert.AreNotEqual(se, null);
Assert.AreNotEqual(null, se);
- ServiceEndpoint se3 = new ServiceEndpoint(claimedId + "a", providerEndpoint, localId, v20TypeUris);
+ ServiceEndpoint se3 = ServiceEndpoint.CreateForClaimedIdentifier(new UriIdentifier(claimedId + "a"), localId, providerEndpoint, v20TypeUris, servicePriority, uriPriority);
Assert.AreNotEqual(se, se3);
- se3 = new ServiceEndpoint(claimedId, new Uri(providerEndpoint.AbsoluteUri + "a"), localId, v20TypeUris);
+ se3 = ServiceEndpoint.CreateForClaimedIdentifier(claimedId, localId, new Uri(providerEndpoint.AbsoluteUri + "a"), v20TypeUris, servicePriority, uriPriority);
Assert.AreNotEqual(se, se3);
- se3 = new ServiceEndpoint(claimedId, providerEndpoint, localId + "a", v20TypeUris);
+ se3 = ServiceEndpoint.CreateForClaimedIdentifier(claimedId, localId + "a", providerEndpoint, v20TypeUris, servicePriority, uriPriority);
Assert.AreNotEqual(se, se3);
- se3 = new ServiceEndpoint(claimedId, providerEndpoint, localId, v11TypeUris);
+ se3 = ServiceEndpoint.CreateForClaimedIdentifier(claimedId, localId, providerEndpoint, v11TypeUris, servicePriority, uriPriority);
Assert.AreNotEqual(se, se3);
+
+ // make sure that Collection<T>.Contains works as desired.
+ List<ServiceEndpoint> list = new List<ServiceEndpoint>();
+ list.Add(se);
+ Assert.IsTrue(list.Contains(se2));
+ }
+
+ [Test]
+ public void FriendlyIdentifierForDisplay() {
+ Uri providerEndpoint= new Uri("http://someprovider");
+ Identifier localId = "someuser";
+ string[] serviceTypeUris = new string[0];
+ ServiceEndpoint se;
+
+ // strip of protocol and fragment
+ se = ServiceEndpoint.CreateForClaimedIdentifier("http://someprovider.somedomain.com:79/someuser#frag",
+ localId, providerEndpoint, serviceTypeUris, null, null);
+ Assert.AreEqual("someprovider.somedomain.com:79/someuser", se.FriendlyIdentifierForDisplay);
+
+ // unescape characters
+ Uri foreignUri = new Uri("http://server崎/村");
+ se = ServiceEndpoint.CreateForClaimedIdentifier(foreignUri, localId, providerEndpoint, serviceTypeUris, null, null);
+ Assert.AreEqual("server崎/村", se.FriendlyIdentifierForDisplay);
+
+ // restore user supplied identifier to XRIs
+ se = ServiceEndpoint.CreateForClaimedIdentifier(new XriIdentifier("=!9B72.7DD1.50A9.5CCD"),
+ new XriIdentifier("=Arnott崎村"), localId, providerEndpoint, serviceTypeUris, null, null);
+ Assert.AreEqual("=!9B72.7DD1.50A9.5CCD (=Arnott崎村)", se.FriendlyIdentifierForDisplay);
+
+ // If UserSuppliedIdentifier is the same as the ClaimedIdentifier, don't display it twice...
+ se = ServiceEndpoint.CreateForClaimedIdentifier(
+ new XriIdentifier("=!9B72.7DD1.50A9.5CCD"), new XriIdentifier("=!9B72.7DD1.50A9.5CCD"),
+ localId, providerEndpoint, serviceTypeUris, null, null);
+ Assert.AreEqual("=!9B72.7DD1.50A9.5CCD", se.FriendlyIdentifierForDisplay);
}
}
}
diff --git a/src/DotNetOpenId.Test/RelyingParty/TokenTest.cs b/src/DotNetOpenId.Test/RelyingParty/TokenTest.cs
index b83c47f..c57f68a 100644
--- a/src/DotNetOpenId.Test/RelyingParty/TokenTest.cs
+++ b/src/DotNetOpenId.Test/RelyingParty/TokenTest.cs
@@ -1,20 +1,18 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
+using DotNetOpenId.RelyingParty;
using NUnit.Framework;
-using DotNetOpenId.RelyingParty;
-using System.Threading;
namespace DotNetOpenId.Test.RelyingParty {
[TestFixture]
public class TokenTest {
static ServiceEndpoint getServiceEndpoint(TestSupport.Scenarios scenario, ProtocolVersion version) {
Protocol protocol = Protocol.Lookup(version);
- ServiceEndpoint ep = new ServiceEndpoint(
+ ServiceEndpoint ep = ServiceEndpoint.CreateForClaimedIdentifier(
TestSupport.GetIdentityUrl(scenario, version),
- TestSupport.GetFullUrl(TestSupport.ProviderPage),
TestSupport.GetDelegateUrl(scenario),
- new[] { protocol.ClaimedIdentifierServiceTypeURI }
+ TestSupport.GetFullUrl(TestSupport.ProviderPage),
+ new[] { protocol.ClaimedIdentifierServiceTypeURI },
+ 10,
+ 10
);
return ep;
}
diff --git a/src/DotNetOpenId.Test/TestSupport.cs b/src/DotNetOpenId.Test/TestSupport.cs
index be17494..7022941 100644
--- a/src/DotNetOpenId.Test/TestSupport.cs
+++ b/src/DotNetOpenId.Test/TestSupport.cs
@@ -16,12 +16,14 @@ public class TestSupport {
public static readonly string TestWebDirectory = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\src\DotNetOpenId.TestWeb"));
public const string HostTestPage = "HostTest.aspx";
const string identityPage = "IdentityEndpoint.aspx";
+ const string directedIdentityPage = "DirectedIdentityEndpoint.aspx";
public const string ProviderPage = "ProviderEndpoint.aspx";
public const string MobileConsumerPage = "RelyingPartyMobile.aspx";
public const string ConsumerPage = "RelyingParty.aspx";
public enum Scenarios {
// Authentication test scenarios
AutoApproval,
+ AutoApprovalAddFragment,
ApproveOnSetup,
AlwaysDeny,
@@ -35,12 +37,24 @@ public class TestSupport {
/// </summary>
ExtensionPartialCooperation,
}
+ internal static UriIdentifier GetOPIdentityUrl(Scenarios scenario) {
+ UriBuilder builder = new UriBuilder(Host.BaseUri);
+ builder.Path = "/opdefault.aspx";
+ builder.Query = "user=" + scenario;
+ return new UriIdentifier(builder.Uri);
+ }
internal static UriIdentifier GetIdentityUrl(Scenarios scenario, ProtocolVersion providerVersion) {
UriBuilder builder = new UriBuilder(Host.BaseUri);
builder.Path = "/" + identityPage;
builder.Query = "user=" + scenario + "&version=" + providerVersion;
return new UriIdentifier(builder.Uri);
}
+ internal static UriIdentifier GetDirectedIdentityUrl(Scenarios scenario, ProtocolVersion providerVersion) {
+ UriBuilder builder = new UriBuilder(Host.BaseUri);
+ builder.Path = "/" + directedIdentityPage;
+ builder.Query = "user=" + scenario + "&version=" + providerVersion;
+ return new UriIdentifier(builder.Uri);
+ }
public static Identifier GetDelegateUrl(Scenarios scenario) {
return new UriIdentifier(new Uri(Host.BaseUri, "/" + scenario));
}
@@ -56,6 +70,25 @@ public class TestSupport {
internal static AspNetHost Host { get; private set; }
internal static EncodingInterceptor Interceptor { get; private set; }
+ internal static UntrustedWebRequest.MockRequestResponse GenerateMockXrdsResponses(IDictionary<string, string> requestUriAndResponseBody) {
+ return (uri, body, acceptTypes) => {
+ string contentType = "text/xml; saml=false; https=false; charset=UTF-8";
+ string contentEncoding = null;
+ MemoryStream stream = new MemoryStream();
+ StreamWriter sw = new StreamWriter(stream);
+ Assert.IsNull(body);
+ string responseBody;
+ if (!requestUriAndResponseBody.TryGetValue(uri.AbsoluteUri, out responseBody)) {
+ Assert.Fail("Unexpected HTTP request: {0}", uri);
+ }
+ sw.Write(responseBody);
+ sw.Flush();
+ stream.Seek(0, SeekOrigin.Begin);
+ return new UntrustedWebResponse(uri, uri, new WebHeaderCollection(),
+ HttpStatusCode.OK, contentType, contentEncoding, stream);
+ };
+ }
+
[SetUp]
public void SetUp() {
Host = AspNetHost.CreateHost(TestSupport.TestWebDirectory);
@@ -92,6 +125,12 @@ public class TestSupport {
}
nvc[protocol.openid.sig] = Convert.ToBase64String(assoc.Sign(subsetDictionary, signed));
}
+
+ public static IAssociationStore<AssociationRelyingPartyType> ProviderStoreContext {
+ get {
+ return DotNetOpenId.Provider.OpenIdProvider.HttpApplicationStore;
+ }
+ }
}
static class TestExtensions {
diff --git a/src/DotNetOpenId.Test/UriIdentifierTests.cs b/src/DotNetOpenId.Test/UriIdentifierTests.cs
index cd42d48..16d8b51 100644
--- a/src/DotNetOpenId.Test/UriIdentifierTests.cs
+++ b/src/DotNetOpenId.Test/UriIdentifierTests.cs
@@ -1,10 +1,9 @@
using System;
-using System.Collections.Generic;
-using System.Text;
-using NUnit.Framework;
-using DotNetOpenId.RelyingParty;
+using System.Linq;
using System.Net;
using DotNetOpenId.Extensions.SimpleRegistration;
+using DotNetOpenId.RelyingParty;
+using NUnit.Framework;
namespace DotNetOpenId.Test {
[TestFixture]
@@ -45,6 +44,21 @@ namespace DotNetOpenId.Test {
Assert.AreEqual(new Uri(goodUri), uri.Uri);
}
+ /// <summary>
+ /// Verifies that the fragment is not stripped from an Identifier.
+ /// </summary>
+ /// <remarks>
+ /// Although fragments should be stripped from user supplied identifiers,
+ /// they should NOT be stripped from claimed identifiers. So the UriIdentifier
+ /// class, which serves both identifier types, must not do the stripping.
+ /// </remarks>
+ [Test]
+ public void DoesNotStripFragment() {
+ Uri original = new Uri("http://a/b#c");
+ UriIdentifier identifier = new UriIdentifier(original);
+ Assert.AreEqual(original.Fragment, identifier.Uri.Fragment);
+ }
+
[Test]
public void IsValid() {
Assert.IsTrue(UriIdentifier.IsValidUri(goodUri));
@@ -53,6 +67,14 @@ namespace DotNetOpenId.Test {
}
[Test]
+ public void TrimFragment() {
+ Identifier noFragment = UriIdentifier.Parse("http://a/b");
+ Identifier fragment = UriIdentifier.Parse("http://a/b#c");
+ Assert.AreSame(noFragment, noFragment.TrimFragment());
+ Assert.AreEqual(noFragment, fragment.TrimFragment());
+ }
+
+ [Test]
public void ToStringTest() {
Assert.AreEqual(goodUri, new UriIdentifier(goodUri).ToString());
}
@@ -60,6 +82,8 @@ namespace DotNetOpenId.Test {
[Test]
public void EqualsTest() {
Assert.AreEqual(new UriIdentifier(goodUri), new UriIdentifier(goodUri));
+ // This next test is an interesting side-effect of passing off to Uri.Equals. But it's probably ok.
+ Assert.AreEqual(new UriIdentifier(goodUri), new UriIdentifier(goodUri + "#frag"));
Assert.AreNotEqual(new UriIdentifier(goodUri), new UriIdentifier(goodUri + "a"));
Assert.AreNotEqual(null, new UriIdentifier(goodUri));
Assert.AreNotEqual(goodUri, new UriIdentifier(goodUri));
@@ -71,6 +95,7 @@ namespace DotNetOpenId.Test {
Assert.IsTrue(UriIdentifier.IsValidUri(unicodeUrl));
Identifier id;
Assert.IsTrue(UriIdentifier.TryParse(unicodeUrl, out id));
+ Assert.AreEqual("/opaffirmative/%E5%B4%8E%E6%9D%91.aspx", ((UriIdentifier)id).Uri.AbsolutePath);
Assert.AreEqual(Uri.EscapeUriString(unicodeUrl), id.ToString());
}
@@ -83,7 +108,7 @@ namespace DotNetOpenId.Test {
Identifier idToDiscover = useRedirect ? userSuppliedIdentifier : claimedId;
// confirm the page exists (validates the test)
WebRequest.Create(idToDiscover).GetResponse().Close();
- ServiceEndpoint se = idToDiscover.Discover();
+ ServiceEndpoint se = idToDiscover.Discover().FirstOrDefault();
Assert.IsNotNull(se, url + " failed to be discovered.");
Assert.AreSame(protocol, se.Protocol);
Assert.AreEqual(claimedId, se.ClaimedIdentifier);
@@ -107,7 +132,7 @@ namespace DotNetOpenId.Test {
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
+ Assert.AreEqual(0, userSuppliedId.Discover().Count()); // ... but that no endpoint info is discoverable
}
void failDiscoverHtml(string scenario) {
failDiscover("htmldiscovery/" + scenario + ".aspx");
diff --git a/src/DotNetOpenId.Test/XriIdentifierTests.cs b/src/DotNetOpenId.Test/XriIdentifierTests.cs
index 72ae1c1..8ce2726 100644
--- a/src/DotNetOpenId.Test/XriIdentifierTests.cs
+++ b/src/DotNetOpenId.Test/XriIdentifierTests.cs
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
-using System.Text;
-using NUnit.Framework;
-using DotNetOpenId.RelyingParty;
-using System.Net;
using System.IO;
+using System.Linq;
+using System.Net;
+using DotNetOpenId.RelyingParty;
+using NUnit.Framework;
namespace DotNetOpenId.Test {
[TestFixture]
@@ -56,6 +56,12 @@ namespace DotNetOpenId.Test {
}
[Test]
+ public void TrimFragment() {
+ Identifier xri = new XriIdentifier(goodXri);
+ Assert.AreSame(xri, xri.TrimFragment());
+ }
+
+ [Test]
public void ToStringTest() {
Assert.AreEqual(goodXri, new XriIdentifier(goodXri).ToString());
}
@@ -69,7 +75,7 @@ namespace DotNetOpenId.Test {
}
private ServiceEndpoint verifyCanonicalId(Identifier iname, string expectedClaimedIdentifier) {
- ServiceEndpoint se = iname.Discover();
+ ServiceEndpoint se = iname.Discover().FirstOrDefault();
if (expectedClaimedIdentifier != null) {
Assert.IsNotNull(se);
Assert.AreEqual(expectedClaimedIdentifier, se.ClaimedIdentifier.ToString(), "i-name {0} discovery resulted in unexpected CanonicalId", iname);
@@ -80,25 +86,6 @@ namespace DotNetOpenId.Test {
return se;
}
- UntrustedWebRequest.MockRequestResponse generateMockXrdsResponses(IDictionary<string, string> requestUriAndResponseBody) {
- return (uri, body, acceptTypes) => {
- string contentType = "text/xml; saml=false; https=false; charset=UTF-8";
- string contentEncoding = null;
- MemoryStream stream = new MemoryStream();
- StreamWriter sw = new StreamWriter(stream);
- Assert.IsNull(body);
- string responseBody;
- if (!requestUriAndResponseBody.TryGetValue(uri.AbsoluteUri, out responseBody)) {
- Assert.Fail("Unexpected HTTP request: {0}", uri);
- }
- sw.Write(responseBody);
- sw.Flush();
- stream.Seek(0, SeekOrigin.Begin);
- return new UntrustedWebResponse(uri, uri, new WebHeaderCollection(),
- HttpStatusCode.OK, contentType, contentEncoding, stream);
- };
- }
-
[Test]
public void Discover() {
string xrds = @"<?xml version='1.0' encoding='UTF-8'?>
@@ -136,13 +123,14 @@ namespace DotNetOpenId.Test {
{"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},
};
- UntrustedWebRequest.MockRequests = generateMockXrdsResponses(mocks);
+ UntrustedWebRequest.MockRequests = TestSupport.GenerateMockXrdsResponses(mocks);
string expectedCanonicalId = "=!9B72.7DD1.50A9.5CCD";
ServiceEndpoint se = verifyCanonicalId("=Arnott", expectedCanonicalId);
Assert.AreEqual(Protocol.v10, se.Protocol);
Assert.AreEqual("http://1id.com/sso", se.ProviderEndpoint.ToString());
Assert.AreEqual(se.ClaimedIdentifier, se.ProviderLocalIdentifier);
+ Assert.AreEqual("=!9B72.7DD1.50A9.5CCD (=Arnott)", se.FriendlyIdentifierForDisplay);
}
[Test]
@@ -361,7 +349,7 @@ uEyb50RJ7DWmXctSC0b3eymZ2lSXxAWNOsNy
</X509Data>
</KeyInfo>
</XRD>";
- UntrustedWebRequest.MockRequests = generateMockXrdsResponses(new Dictionary<string, string> {
+ UntrustedWebRequest.MockRequests = TestSupport.GenerateMockXrdsResponses(new Dictionary<string, string> {
{ "https://xri.net/@llli?_xrd_r=application/xrd%2Bxml;sep=false", llliResponse},
{ "https://xri.net/@!72CD.A072.157E.A9C6?_xrd_r=application/xrd%2Bxml;sep=false", llliResponse},
@@ -386,7 +374,7 @@ uEyb50RJ7DWmXctSC0b3eymZ2lSXxAWNOsNy
[Test]
public void DiscoveryCommunityInameDelegateWithoutCanonicalID() {
- UntrustedWebRequest.MockRequests = generateMockXrdsResponses(new Dictionary<string, string> {
+ UntrustedWebRequest.MockRequests = TestSupport.GenerateMockXrdsResponses(new Dictionary<string, string> {
{ "https://xri.net/=Web*andrew.arnott?_xrd_r=application/xrd%2Bxml;sep=false", @"<?xml version='1.0' encoding='UTF-8'?>
<XRD xmlns='xri://$xrd*($v*2.0)'>
<Query>*andrew.arnott</Query>