diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-11-24 23:41:41 -0800 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2008-11-24 23:41:41 -0800 |
commit | 3d69557f925cb7e05e85b0b99371faaf9c2109c6 (patch) | |
tree | c6bb15be6693a7d97ad87079393a340a2ef2024a /src/DotNetOpenAuth.Test | |
parent | 85c813a005a2494bb71066215de8db1d7ab056d2 (diff) | |
download | DotNetOpenAuth-3d69557f925cb7e05e85b0b99371faaf9c2109c6.zip DotNetOpenAuth-3d69557f925cb7e05e85b0b99371faaf9c2109c6.tar.gz DotNetOpenAuth-3d69557f925cb7e05e85b0b99371faaf9c2109c6.tar.bz2 |
Several hundred StyleCop fixes.
Diffstat (limited to 'src/DotNetOpenAuth.Test')
-rw-r--r-- | src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs | 12 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/Hosting/HttpHost.cs | 61 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs | 59 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/Mocks/MockHttpRequest.cs | 41 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/Mocks/MockIdentifier.cs | 16 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/OpenId/IdentifierTests.cs | 34 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs | 4 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/OpenId/TestSupport.cs | 154 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/OpenId/UI/UITestSupport.cs | 8 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs | 221 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/OpenId/XriIdentifierTests.cs | 92 |
11 files changed, 379 insertions, 323 deletions
diff --git a/src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs b/src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs index 0bbca5e..015a00b 100644 --- a/src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs +++ b/src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs @@ -1,4 +1,10 @@ -namespace DotNetOpenAuth.Test.Hosting { +//----------------------------------------------------------------------- +// <copyright file="AspNetHost.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.Test.Hosting { using System; using System.IO; using System.Net; @@ -12,8 +18,8 @@ /// Hosts a 'portable' version of the OpenIdProvider for testing itself and the /// RelyingParty against it. /// </summary> - class AspNetHost : MarshalByRefObject { - HttpHost httpHost; + internal class AspNetHost : MarshalByRefObject { + private HttpHost httpHost; public AspNetHost() { httpHost = HttpHost.CreateHost(this); diff --git a/src/DotNetOpenAuth.Test/Hosting/HttpHost.cs b/src/DotNetOpenAuth.Test/Hosting/HttpHost.cs index 9606cb7..06001ce 100644 --- a/src/DotNetOpenAuth.Test/Hosting/HttpHost.cs +++ b/src/DotNetOpenAuth.Test/Hosting/HttpHost.cs @@ -1,4 +1,10 @@ -namespace DotNetOpenAuth.Test.Hosting { +//----------------------------------------------------------------------- +// <copyright file="HttpHost.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.Test.Hosting { using System; using System.Globalization; using System.IO; @@ -6,33 +12,33 @@ using System.Threading; class HttpHost : IDisposable { - HttpListener listener; - public int Port { get; private set; } - Thread listenerThread; - AspNetHost aspNetHost; + private HttpListener listener; + private Thread listenerThread; + private AspNetHost aspNetHost; - HttpHost(AspNetHost aspNetHost) { + private HttpHost(AspNetHost aspNetHost) { this.aspNetHost = aspNetHost; - Port = 59687; + this.Port = 59687; Random r = new Random(); tryAgain: try { - listener = new HttpListener(); - listener.Prefixes.Add(string.Format(CultureInfo.InvariantCulture, - "http://localhost:{0}/", Port)); - listener.Start(); + this.listener = new HttpListener(); + this.listener.Prefixes.Add(string.Format(CultureInfo.InvariantCulture, "http://localhost:{0}/", this.Port)); + this.listener.Start(); } catch (HttpListenerException ex) { if (ex.Message.Contains("conflicts")) { - Port += r.Next(1, 20); + this.Port += r.Next(1, 20); goto tryAgain; } throw; } - listenerThread = new Thread(processRequests); - listenerThread.Start(); + this.listenerThread = new Thread(ProcessRequests); + this.listenerThread.Start(); } + public int Port { get; private set; } + public static HttpHost CreateHost(AspNetHost aspNetHost) { return new HttpHost(aspNetHost); } @@ -40,23 +46,15 @@ public static HttpHost CreateHost(string webDirectory) { return new HttpHost(AspNetHost.CreateHost(webDirectory)); } - void processRequests() { - try { - while (true) { - var context = listener.GetContext(); - aspNetHost.BeginProcessRequest(context); - } - } catch (HttpListenerException) { - // the listener is probably being shut down - } - } - + public Uri BaseUri { - get { return new Uri("http://localhost:" + Port.ToString() + "/"); } + get { return new Uri("http://localhost:" + this.Port.ToString() + "/"); } } + public string ProcessRequest(string url) { return ProcessRequest(url, null); } + public string ProcessRequest(string url, string body) { WebRequest request = WebRequest.Create(new Uri(BaseUri, url)); if (body != null) { @@ -89,5 +87,16 @@ } #endregion + + private void ProcessRequests() { + try { + while (true) { + var context = this.listener.GetContext(); + this.aspNetHost.BeginProcessRequest(context); + } + } catch (HttpListenerException) { + // the listener is probably being shut down + } + } } } diff --git a/src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs b/src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs index 29f1c4c..6d1ee8d 100644 --- a/src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs +++ b/src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs @@ -1,10 +1,20 @@ -namespace DotNetOpenAuth.Test.Hosting { +//----------------------------------------------------------------------- +// <copyright file="TestingWorkerRequest.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.Test.Hosting { using System; using System.IO; using System.Net; using System.Web.Hosting; - class TestingWorkerRequest : SimpleWorkerRequest { + internal class TestingWorkerRequest : SimpleWorkerRequest { + private Stream entityStream; + private HttpListenerContext context; + private TextWriter writer; + public TestingWorkerRequest(string page, string query, Stream entityStream, TextWriter writer) : base(page, query, writer) { this.entityStream = entityStream; @@ -17,74 +27,71 @@ this.writer = output; } - Stream entityStream; - HttpListenerContext context; - TextWriter writer; public override string GetFilePath() { - string filePath = context.Request.Url.LocalPath.Replace("/", "\\"); + string filePath = this.context.Request.Url.LocalPath.Replace("/", "\\"); if (filePath.EndsWith("\\", StringComparison.Ordinal)) filePath += "default.aspx"; return filePath; } public override int GetLocalPort() { - return context.Request.Url.Port; + return this.context.Request.Url.Port; } public override string GetServerName() { - return context.Request.Url.Host; + return this.context.Request.Url.Host; } public override string GetQueryString() { - return context.Request.Url.Query.TrimStart('?'); + return this.context.Request.Url.Query.TrimStart('?'); } public override string GetHttpVerbName() { - return context.Request.HttpMethod; + return this.context.Request.HttpMethod; } public override string GetLocalAddress() { - return context.Request.LocalEndPoint.Address.ToString(); + return this.context.Request.LocalEndPoint.Address.ToString(); } public override string GetHttpVersion() { return "HTTP/1.1"; } public override string GetProtocol() { - return context.Request.Url.Scheme; + return this.context.Request.Url.Scheme; } public override string GetRawUrl() { - return context.Request.RawUrl; + return this.context.Request.RawUrl; } public override int GetTotalEntityBodyLength() { - return (int)context.Request.ContentLength64; + return (int)this.context.Request.ContentLength64; } public override string GetKnownRequestHeader(int index) { - return context.Request.Headers[GetKnownRequestHeaderName(index)]; + return this.context.Request.Headers[GetKnownRequestHeaderName(index)]; } public override string GetUnknownRequestHeader(string name) { - return context.Request.Headers[name]; + return this.context.Request.Headers[name]; } public override bool IsEntireEntityBodyIsPreloaded() { return false; } public override int ReadEntityBody(byte[] buffer, int size) { - return entityStream.Read(buffer, 0, size); + return this.entityStream.Read(buffer, 0, size); } public override int ReadEntityBody(byte[] buffer, int offset, int size) { - return entityStream.Read(buffer, offset, size); + return this.entityStream.Read(buffer, offset, size); } public override void SendCalculatedContentLength(int contentLength) { - context.Response.ContentLength64 = contentLength; + this.context.Response.ContentLength64 = contentLength; } public override void SendStatus(int statusCode, string statusDescription) { - if (context != null) { - context.Response.StatusCode = statusCode; - context.Response.StatusDescription = statusDescription; + if (this.context != null) { + this.context.Response.StatusCode = statusCode; + this.context.Response.StatusDescription = statusDescription; } } public override void SendKnownResponseHeader(int index, string value) { - if (context != null) { - context.Response.Headers[(HttpResponseHeader)index] = value; + if (this.context != null) { + this.context.Response.Headers[(HttpResponseHeader)index] = value; } } public override void SendUnknownResponseHeader(string name, string value) { - if (context != null) { - context.Response.Headers[name] = value; + if (this.context != null) { + this.context.Response.Headers[name] = value; } } } diff --git a/src/DotNetOpenAuth.Test/Mocks/MockHttpRequest.cs b/src/DotNetOpenAuth.Test/Mocks/MockHttpRequest.cs index 1473bf0..08e4473 100644 --- a/src/DotNetOpenAuth.Test/Mocks/MockHttpRequest.cs +++ b/src/DotNetOpenAuth.Test/Mocks/MockHttpRequest.cs @@ -26,27 +26,8 @@ return mock; } - private MockHttpRequest(IDirectSslWebRequestHandler mockHandler) { - ErrorUtilities.VerifyArgumentNotNull(mockHandler, "mockHandler"); - this.MockWebRequestHandler = mockHandler; - } - internal IDirectSslWebRequestHandler MockWebRequestHandler { get; private set; } - private DirectWebResponse GetMockResponse(HttpWebRequest request) { - DirectWebResponse response; - if (this.registeredMockResponses.TryGetValue(request.RequestUri, out response)) { - // reset response stream position so this response can be reused on a subsequent request. - response.ResponseStream.Seek(0, SeekOrigin.Begin); - return response; - } else { - ////Assert.Fail("Unexpected HTTP request: {0}", uri); - Logger.WarnFormat("Unexpected HTTP request: {0}", request.RequestUri); - return new DirectWebResponse(request.RequestUri, request.RequestUri, new WebHeaderCollection(), HttpStatusCode.NotFound, - "text/html", null, new MemoryStream()); - } - } - internal void RegisterMockResponse(DirectWebResponse response) { if (response == null) throw new ArgumentNullException("response"); if (registeredMockResponses.ContainsKey(response.RequestUri)) { @@ -134,6 +115,7 @@ RegisterMockResponse(respondingUri, ContentTypes.Xrds, xrds.ToString()); } + internal void RegisterMockXrdsResponse(UriIdentifier directedIdentityAssignedIdentifier, ServiceEndpoint providerEndpoint) { ServiceEndpoint identityEndpoint = ServiceEndpoint.CreateForClaimedIdentifier( directedIdentityAssignedIdentifier, @@ -144,11 +126,13 @@ 10); RegisterMockXrdsResponse(identityEndpoint); } + internal Identifier RegisterMockXrdsResponse(string embeddedResourcePath) { UriIdentifier id = TestSupport.GetFullUrl(embeddedResourcePath); RegisterMockResponse(id, "application/xrds+xml", TestSupport.LoadEmbeddedFile(embeddedResourcePath)); return id; } + internal void RegisterMockRPDiscovery() { Uri rpRealmUri = TestSupport.Realm.UriWithWildcardChangedToWww; @@ -179,5 +163,24 @@ redirectionHeaders, HttpStatusCode.Redirect, null, null, new MemoryStream()); RegisterMockResponse(response); } + + private MockHttpRequest(IDirectSslWebRequestHandler mockHandler) { + ErrorUtilities.VerifyArgumentNotNull(mockHandler, "mockHandler"); + this.MockWebRequestHandler = mockHandler; + } + + private DirectWebResponse GetMockResponse(HttpWebRequest request) { + DirectWebResponse response; + if (this.registeredMockResponses.TryGetValue(request.RequestUri, out response)) { + // reset response stream position so this response can be reused on a subsequent request. + response.ResponseStream.Seek(0, SeekOrigin.Begin); + return response; + } else { + ////Assert.Fail("Unexpected HTTP request: {0}", uri); + Logger.WarnFormat("Unexpected HTTP request: {0}", request.RequestUri); + return new DirectWebResponse(request.RequestUri, request.RequestUri, new WebHeaderCollection(), HttpStatusCode.NotFound, + "text/html", null, new MemoryStream()); + } + } } } diff --git a/src/DotNetOpenAuth.Test/Mocks/MockIdentifier.cs b/src/DotNetOpenAuth.Test/Mocks/MockIdentifier.cs index 2b7a7a9..007a1d6 100644 --- a/src/DotNetOpenAuth.Test/Mocks/MockIdentifier.cs +++ b/src/DotNetOpenAuth.Test/Mocks/MockIdentifier.cs @@ -16,10 +16,10 @@ using DotNetOpenAuth.Messaging; /// to perform discovery, it returns a preset list of sevice endpoints to avoid /// having a dependency on a hosted web site to actually perform discovery on. /// </summary> - class MockIdentifier : Identifier { - IEnumerable<ServiceEndpoint> endpoints; - MockHttpRequest mockHttpRequest; - Identifier wrappedIdentifier; + internal class MockIdentifier : Identifier { + private IEnumerable<ServiceEndpoint> endpoints; + private MockHttpRequest mockHttpRequest; + private Identifier wrappedIdentifier; public MockIdentifier(Identifier wrappedIdentifier, MockHttpRequest mockHttpRequest, IEnumerable<ServiceEndpoint> endpoints) : base(false) { @@ -37,7 +37,7 @@ using DotNetOpenAuth.Messaging; } internal override IEnumerable<ServiceEndpoint> Discover(IDirectSslWebRequestHandler requestHandler) { - return endpoints; + return this.endpoints; } internal override Identifier TrimFragment() { @@ -54,15 +54,15 @@ using DotNetOpenAuth.Messaging; } public override string ToString() { - return wrappedIdentifier.ToString(); + return this.wrappedIdentifier.ToString(); } public override bool Equals(object obj) { - return wrappedIdentifier.Equals(obj); + return this.wrappedIdentifier.Equals(obj); } public override int GetHashCode() { - return wrappedIdentifier.GetHashCode(); + return this.wrappedIdentifier.GetHashCode(); } } } diff --git a/src/DotNetOpenAuth.Test/OpenId/IdentifierTests.cs b/src/DotNetOpenAuth.Test/OpenId/IdentifierTests.cs index 941aa70..7bc60c7 100644 --- a/src/DotNetOpenAuth.Test/OpenId/IdentifierTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/IdentifierTests.cs @@ -1,21 +1,27 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using DotNetOpenAuth.OpenId; +//----------------------------------------------------------------------- +// <copyright file="IdentifierTests.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- namespace DotNetOpenAuth.Test.OpenId { + using System; + using System.Collections.Generic; + using System.Linq; + using DotNetOpenAuth.OpenId; + using Microsoft.VisualStudio.TestTools.UnitTesting; + [TestClass] public class IdentifierTests { - string uri = "http://www.yahoo.com/"; - string uriNoScheme = "www.yahoo.com"; - string uriHttps = "https://www.yahoo.com/"; - string xri = "=arnott*andrew"; + private string uri = "http://www.yahoo.com/"; + private string uriNoScheme = "www.yahoo.com"; + private string uriHttps = "https://www.yahoo.com/"; + private string xri = "=arnott*andrew"; [TestMethod] public void Parse() { - Assert.IsInstanceOfType(Identifier.Parse(uri), typeof(UriIdentifier)); - Assert.IsInstanceOfType(Identifier.Parse(xri), typeof(XriIdentifier)); + Assert.IsInstanceOfType(Identifier.Parse(this.uri), typeof(UriIdentifier)); + Assert.IsInstanceOfType(Identifier.Parse(this.xri), typeof(XriIdentifier)); } /// <summary> @@ -40,9 +46,9 @@ namespace DotNetOpenAuth.Test.OpenId { [TestMethod] public void ParseEndUserSuppliedUriIdentifier() { // verify a fully-qualified Uri - var id = Identifier.Parse(uri); + var id = Identifier.Parse(this.uri); Assert.IsInstanceOfType(id, typeof(UriIdentifier)); - Assert.AreEqual(uri, ((UriIdentifier)id).Uri.AbsoluteUri); + Assert.AreEqual(this.uri, ((UriIdentifier)id).Uri.AbsoluteUri); // verify an HTTPS Uri id = Identifier.Parse(uriHttps); Assert.IsInstanceOfType(id, typeof(UriIdentifier)); @@ -50,7 +56,7 @@ namespace DotNetOpenAuth.Test.OpenId { // verify that if the scheme is missing it is added automatically id = Identifier.Parse(uriNoScheme); Assert.IsInstanceOfType(id, typeof(UriIdentifier)); - Assert.AreEqual(uri, ((UriIdentifier)id).Uri.AbsoluteUri); + Assert.AreEqual(this.uri, ((UriIdentifier)id).Uri.AbsoluteUri); } [TestMethod, ExpectedException(typeof(ArgumentNullException))] diff --git a/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs b/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs index 82cf976..7deafef 100644 --- a/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs +++ b/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs @@ -6,11 +6,11 @@ namespace DotNetOpenAuth.Test.OpenId { using DotNetOpenAuth.Configuration; + using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.Provider; using DotNetOpenAuth.OpenId.RelyingParty; - using Microsoft.VisualStudio.TestTools.UnitTesting; using DotNetOpenAuth.Test.Mocks; - using DotNetOpenAuth.Messaging; + using Microsoft.VisualStudio.TestTools.UnitTesting; public class OpenIdTestBase : TestBase { protected RelyingPartySecuritySettings RelyingPartySecuritySettings { get; private set; } diff --git a/src/DotNetOpenAuth.Test/OpenId/TestSupport.cs b/src/DotNetOpenAuth.Test/OpenId/TestSupport.cs index 4e742dc..4470b99 100644 --- a/src/DotNetOpenAuth.Test/OpenId/TestSupport.cs +++ b/src/DotNetOpenAuth.Test/OpenId/TestSupport.cs @@ -7,29 +7,19 @@ namespace DotNetOpenAuth.Test.OpenId { using System; using System.Collections.Generic; - using System.Collections.Specialized; - using System.Diagnostics; using System.IO; using System.Reflection; - using System.Web; - using DotNetOpenAuth; + using DotNetOAuth.Test.OpenId.UI; + using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId; - using DotNetOpenAuth.OpenId.Provider; using DotNetOpenAuth.OpenId.RelyingParty; using DotNetOpenAuth.Test.Mocks; //using DotNetOpenAuth.Test.UI; using log4net; - using IProviderAssociationStore = DotNetOpenAuth.OpenId.IAssociationStore<DotNetOpenAuth.OpenId.AssociationRelyingPartyType>; - using ProviderMemoryStore = DotNetOpenAuth.OpenId.AssociationMemoryStore<DotNetOpenAuth.OpenId.AssociationRelyingPartyType>; - using Microsoft.VisualStudio.TestTools.UnitTesting; - using DotNetOAuth.Test.OpenId.UI; - using DotNetOpenAuth.Messaging; 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 DirectedProviderEndpoint = "DirectedProviderEndpoint.aspx"; public const string MobileConsumerPage = "RelyingPartyMobile.aspx"; @@ -42,6 +32,8 @@ namespace DotNetOpenAuth.Test.OpenId { get { return new Realm(TestSupport.GetFullUrl(TestSupport.ConsumerPage).AbsoluteUri); } } public readonly static ILog Logger = LogManager.GetLogger("DotNetOpenId.Test"); + private const string IdentityPage = "IdentityEndpoint.aspx"; + private const string DirectedIdentityPage = "DirectedIdentityEndpoint.aspx"; public enum Scenarios { // Authentication test scenarios @@ -61,82 +53,24 @@ namespace DotNetOpenAuth.Test.OpenId { ExtensionPartialCooperation, } - ////internal static UriIdentifier GetOPIdentityUrl(Scenarios scenario, bool useSsl) { - //// var args = new Dictionary<string, string> { - //// { "user", scenario.ToString() }, - ////}; - //// return new UriIdentifier(GetFullUrl("/" + OPDefaultPage, args, useSsl)); - ////} - internal static UriIdentifier GetIdentityUrl(Scenarios scenario, ProtocolVersion providerVersion) { - return GetIdentityUrl(scenario, providerVersion, false); - } - internal static UriIdentifier GetIdentityUrl(Scenarios scenario, ProtocolVersion providerVersion, bool useSsl) { - return new UriIdentifier(GetFullUrl("/" + identityPage, new Dictionary<string, string> { - { "user", scenario.ToString() }, - { "version", providerVersion.ToString() }, - }, useSsl)); - } - ////internal static UriIdentifier GetDirectedIdentityUrl(Scenarios scenario, ProtocolVersion providerVersion) { - //// return GetDirectedIdentityUrl(scenario, providerVersion, false); - ////} - ////internal static UriIdentifier GetDirectedIdentityUrl(Scenarios scenario, ProtocolVersion providerVersion, bool useSsl) { - //// return new UriIdentifier(GetFullUrl("/" + directedIdentityPage, new Dictionary<string, string> { - //// { "user", scenario.ToString() }, - //// { "version", providerVersion.ToString() }, - ////}, useSsl)); - ////} public static Identifier GetDelegateUrl(Scenarios scenario) { return GetDelegateUrl(scenario, false); } + public static Identifier GetDelegateUrl(Scenarios scenario, bool useSsl) { return new UriIdentifier(GetFullUrl("/" + scenario, null, useSsl)); } - internal static MockIdentifier GetMockIdentifier(Scenarios scenario, MockHttpRequest mockRequest, ProtocolVersion providerVersion) { - return GetMockIdentifier(scenario, mockRequest, providerVersion, false); - } - internal static MockIdentifier GetMockIdentifier(Scenarios scenario, MockHttpRequest mockRequest, ProtocolVersion providerVersion, bool useSsl) { - ServiceEndpoint se = GetServiceEndpoint(scenario, providerVersion, 10, useSsl); - return new MockIdentifier(GetIdentityUrl(scenario, providerVersion, useSsl), mockRequest, new ServiceEndpoint[] { se }); - } - internal static ServiceEndpoint GetServiceEndpoint(Scenarios scenario, ProtocolVersion providerVersion, int servicePriority, bool useSsl) { - return ServiceEndpoint.CreateForClaimedIdentifier( - GetIdentityUrl(scenario, providerVersion, useSsl), - GetDelegateUrl(scenario, useSsl), - GetFullUrl("/" + ProviderPage, null, useSsl), - new string[] { Protocol.Lookup(providerVersion).ClaimedIdentifierServiceTypeURI }, - servicePriority, - 10); - } - ////internal static MockIdentifier GetMockOPIdentifier(Scenarios scenario, UriIdentifier expectedClaimedId) { - //// return GetMockOPIdentifier(scenario, expectedClaimedId, false, false); - ////} - ////internal static MockIdentifier GetMockOPIdentifier(Scenarios scenario, UriIdentifier expectedClaimedId, bool useSslOpIdentifier, bool useSslProviderEndpoint) { - //// var fields = new Dictionary<string, string> { - //// { "user", scenario.ToString() }, - ////}; - //// Uri opEndpoint = GetFullUrl(DirectedProviderEndpoint, fields, useSslProviderEndpoint); - //// Uri opIdentifier = GetOPIdentityUrl(scenario, useSslOpIdentifier); - //// ServiceEndpoint se = ServiceEndpoint.CreateForProviderIdentifier( - //// opIdentifier, - //// opEndpoint, - //// new string[] { Protocol.V20.OPIdentifierServiceTypeURI }, - //// 10, - //// 10); - - //// // Register the Claimed Identifier that directed identity will choose so that RP - //// // discovery on that identifier can be mocked up. - //// MockHttpRequest.RegisterMockXrdsResponse(expectedClaimedId, se); - - //// return new MockIdentifier(opIdentifier, new ServiceEndpoint[] { se }); - ////} + public static Uri GetFullUrl(string url) { return GetFullUrl(url, null, false); } + public static Uri GetFullUrl(string url, string key, object value) { return GetFullUrl(url, new Dictionary<string, string> { { key, value.ToString() }, }, false); } + public static Uri GetFullUrl(string url, IDictionary<string, string> args, bool useSsl) { Uri defaultUriBase = new Uri(useSsl ? "https://localhost/" : "http://localhost/"); Uri baseUri = UITestSupport.Host != null ? UITestSupport.Host.BaseUri : defaultUriBase; @@ -154,12 +88,60 @@ namespace DotNetOpenAuth.Test.OpenId { if (!path.StartsWith("/")) path = "/" + path; path = "DotNetOpenAuth.Test.OpenId" + path.Replace('/', '.'); Stream resource = Assembly.GetExecutingAssembly().GetManifestResourceStream(path); - if (resource == null) throw new ArgumentException(); + if (resource == null) { + throw new ArgumentException(); + } using (StreamReader sr = new StreamReader(resource)) { return sr.ReadToEnd(); } } + ////internal static UriIdentifier GetOPIdentityUrl(Scenarios scenario, bool useSsl) { + //// var args = new Dictionary<string, string> { + //// { "user", scenario.ToString() }, + ////}; + //// return new UriIdentifier(GetFullUrl("/" + OPDefaultPage, args, useSsl)); + ////} + internal static UriIdentifier GetIdentityUrl(Scenarios scenario, ProtocolVersion providerVersion) { + return GetIdentityUrl(scenario, providerVersion, false); + } + + internal static UriIdentifier GetIdentityUrl(Scenarios scenario, ProtocolVersion providerVersion, bool useSsl) { + return new UriIdentifier(GetFullUrl("/" + IdentityPage, new Dictionary<string, string> { + { "user", scenario.ToString() }, + { "version", providerVersion.ToString() }, + }, useSsl)); + } + + internal static MockIdentifier GetMockIdentifier(Scenarios scenario, MockHttpRequest mockRequest, ProtocolVersion providerVersion) { + return GetMockIdentifier(scenario, mockRequest, providerVersion, false); + } + + internal static MockIdentifier GetMockIdentifier(Scenarios scenario, MockHttpRequest mockRequest, ProtocolVersion providerVersion, bool useSsl) { + ServiceEndpoint se = GetServiceEndpoint(scenario, providerVersion, 10, useSsl); + return new MockIdentifier(GetIdentityUrl(scenario, providerVersion, useSsl), mockRequest, new ServiceEndpoint[] { se }); + } + + internal static ServiceEndpoint GetServiceEndpoint(Scenarios scenario, ProtocolVersion providerVersion, int servicePriority, bool useSsl) { + return ServiceEndpoint.CreateForClaimedIdentifier( + GetIdentityUrl(scenario, providerVersion, useSsl), + GetDelegateUrl(scenario, useSsl), + GetFullUrl("/" + ProviderPage, null, useSsl), + new string[] { Protocol.Lookup(providerVersion).ClaimedIdentifierServiceTypeURI }, + servicePriority, + 10); + } + + ////internal static UriIdentifier GetDirectedIdentityUrl(Scenarios scenario, ProtocolVersion providerVersion) { + //// return GetDirectedIdentityUrl(scenario, providerVersion, false); + ////} + ////internal static UriIdentifier GetDirectedIdentityUrl(Scenarios scenario, ProtocolVersion providerVersion, bool useSsl) { + //// return new UriIdentifier(GetFullUrl("/" + directedIdentityPage, new Dictionary<string, string> { + //// { "user", scenario.ToString() }, + //// { "version", providerVersion.ToString() }, + ////}, useSsl)); + ////} + ////internal static IRelyingPartyApplicationStore RelyingPartyStore; ////internal static IProviderAssociationStore ProviderStore; /////// <summary> @@ -360,5 +342,27 @@ namespace DotNetOpenAuth.Test.OpenId { //// return DotNetOpenId.Provider.OpenIdProvider.HttpApplicationStore; //// } ////} + ////internal static MockIdentifier GetMockOPIdentifier(Scenarios scenario, UriIdentifier expectedClaimedId) { + //// return GetMockOPIdentifier(scenario, expectedClaimedId, false, false); + ////} + ////internal static MockIdentifier GetMockOPIdentifier(Scenarios scenario, UriIdentifier expectedClaimedId, bool useSslOpIdentifier, bool useSslProviderEndpoint) { + //// var fields = new Dictionary<string, string> { + //// { "user", scenario.ToString() }, + ////}; + //// Uri opEndpoint = GetFullUrl(DirectedProviderEndpoint, fields, useSslProviderEndpoint); + //// Uri opIdentifier = GetOPIdentityUrl(scenario, useSslOpIdentifier); + //// ServiceEndpoint se = ServiceEndpoint.CreateForProviderIdentifier( + //// opIdentifier, + //// opEndpoint, + //// new string[] { Protocol.V20.OPIdentifierServiceTypeURI }, + //// 10, + //// 10); + + //// // Register the Claimed Identifier that directed identity will choose so that RP + //// // discovery on that identifier can be mocked up. + //// MockHttpRequest.RegisterMockXrdsResponse(expectedClaimedId, se); + + //// return new MockIdentifier(opIdentifier, new ServiceEndpoint[] { se }); + ////} } }
\ No newline at end of file diff --git a/src/DotNetOpenAuth.Test/OpenId/UI/UITestSupport.cs b/src/DotNetOpenAuth.Test/OpenId/UI/UITestSupport.cs index da18fa9..92008ad 100644 --- a/src/DotNetOpenAuth.Test/OpenId/UI/UITestSupport.cs +++ b/src/DotNetOpenAuth.Test/OpenId/UI/UITestSupport.cs @@ -1,4 +1,10 @@ -namespace DotNetOAuth.Test.OpenId.UI { +//----------------------------------------------------------------------- +// <copyright file="UITestSupport.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOAuth.Test.OpenId.UI { using DotNetOpenAuth.Test.Hosting; ////[SetUpFixture] diff --git a/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs b/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs index f9b54b4..1dfb173 100644 --- a/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs @@ -9,17 +9,16 @@ namespace DotNetOpenAuth.Test.OpenId { using System.Linq; using System.Net; using System.Web; + using DotNetOpenAuth.Messaging; + using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.RelyingParty; - using DotNetOpenAuth.Test.Mocks; using Microsoft.VisualStudio.TestTools.UnitTesting; - using DotNetOpenAuth.OpenId; - using DotNetOpenAuth.Messaging; [TestClass] public class UriIdentifierTests : OpenIdTestBase { - string goodUri = "http://blog.nerdbank.net/"; - string relativeUri = "host/path"; - string badUri = "som%-)830w8vf/?.<>,ewackedURI"; + private string goodUri = "http://blog.nerdbank.net/"; + private string relativeUri = "host/path"; + private string badUri = "som%-)830w8vf/?.<>,ewackedURI"; [TestInitialize] public override void SetUp() { @@ -43,13 +42,13 @@ namespace DotNetOpenAuth.Test.OpenId { [TestMethod, ExpectedException(typeof(UriFormatException))] public void CtorBadUri() { - new UriIdentifier(badUri); + new UriIdentifier(this.badUri); } [TestMethod] public void CtorGoodUri() { - var uri = new UriIdentifier(goodUri); - Assert.AreEqual(new Uri(goodUri), uri.Uri); + var uri = new UriIdentifier(this.goodUri); + Assert.AreEqual(new Uri(this.goodUri), uri.Uri); Assert.IsFalse(uri.SchemeImplicitlyPrepended); Assert.IsFalse(uri.IsDiscoverySecureEndToEnd); } @@ -102,8 +101,8 @@ namespace DotNetOpenAuth.Test.OpenId { [TestMethod] public void IsValid() { - Assert.IsTrue(UriIdentifier.IsValidUri(goodUri)); - Assert.IsFalse(UriIdentifier.IsValidUri(badUri)); + Assert.IsTrue(UriIdentifier.IsValidUri(this.goodUri)); + Assert.IsFalse(UriIdentifier.IsValidUri(this.badUri)); Assert.IsTrue(UriIdentifier.IsValidUri(relativeUri), "URL lacking http:// prefix should have worked anyway."); } @@ -117,17 +116,17 @@ namespace DotNetOpenAuth.Test.OpenId { [TestMethod] public void ToStringTest() { - Assert.AreEqual(goodUri, new UriIdentifier(goodUri).ToString()); + Assert.AreEqual(this.goodUri, new UriIdentifier(this.goodUri).ToString()); } [TestMethod] public void EqualsTest() { - Assert.AreEqual(new UriIdentifier(goodUri), new UriIdentifier(goodUri)); + 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(goodUri), new UriIdentifier(goodUri + "#frag")); - Assert.AreNotEqual(new UriIdentifier(goodUri), new UriIdentifier(goodUri + "a")); - Assert.AreNotEqual(null, new UriIdentifier(goodUri)); - Assert.AreEqual(goodUri, new UriIdentifier(goodUri)); + 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.AreEqual(this.goodUri, new UriIdentifier(this.goodUri)); } [TestMethod] @@ -140,113 +139,54 @@ namespace DotNetOpenAuth.Test.OpenId { Assert.AreEqual(Uri.EscapeUriString(unicodeUrl), id.ToString()); } - void discover(string url, ProtocolVersion version, Identifier expectedLocalId, bool expectSreg, bool useRedirect) { - discover(url, version, expectedLocalId, expectSreg, useRedirect, null); - } - void discover(string url, ProtocolVersion version, Identifier expectedLocalId, bool expectSreg, bool useRedirect, WebHeaderCollection headers) { - Protocol protocol = Protocol.Lookup(version); - UriIdentifier claimedId = TestSupport.GetFullUrl(url); - UriIdentifier userSuppliedIdentifier = TestSupport.GetFullUrl( - "Discovery/htmldiscovery/redirect.aspx?target=" + url); - if (expectedLocalId == null) expectedLocalId = claimedId; - Identifier idToDiscover = useRedirect ? userSuppliedIdentifier : claimedId; - - string contentType; - if (url.EndsWith("html")) { - contentType = "text/html"; - } else if (url.EndsWith("xml")) { - contentType = "application/xrds+xml"; - } else { - throw new InvalidOperationException(); - } - this.mockResponder.RegisterMockResponse(new Uri(idToDiscover), claimedId, contentType, - headers ?? new WebHeaderCollection(), TestSupport.LoadEmbeddedFile(url)); - - ServiceEndpoint se = idToDiscover.Discover(this.requestHandler).FirstOrDefault(); - 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(expectSreg ? 2 : 1, se.ProviderSupportedServiceTypeUris.Length); - Assert.IsTrue(Array.IndexOf(se.ProviderSupportedServiceTypeUris, protocol.ClaimedIdentifierServiceTypeURI) >= 0); - - // TODO: re-enable this line once extensions support is added back in. - ////Assert.AreEqual(expectSreg, se.IsExtensionSupported(new ClaimsRequest())); - } - void discoverXrds(string page, ProtocolVersion version, Identifier expectedLocalId) { - discoverXrds(page, version, expectedLocalId, null); - } - void discoverXrds(string page, ProtocolVersion version, Identifier expectedLocalId, WebHeaderCollection headers) { - if (!page.Contains(".")) page += ".xml"; - discover("/Discovery/xrdsdiscovery/" + page, version, expectedLocalId, true, false, headers); - discover("/Discovery/xrdsdiscovery/" + page, version, expectedLocalId, true, true, headers); - } - void discoverHtml(string page, ProtocolVersion version, Identifier expectedLocalId, bool useRedirect) { - discover("/Discovery/htmldiscovery/" + page, version, expectedLocalId, false, useRedirect); - } - void discoverHtml(string scenario, ProtocolVersion version, Identifier expectedLocalId) { - string page = scenario + ".html"; - discoverHtml(page, version, expectedLocalId, false); - discoverHtml(page, version, expectedLocalId, true); - } - void failDiscover(string url) { - UriIdentifier userSuppliedId = TestSupport.GetFullUrl(url); - - this.mockResponder.RegisterMockResponse(new Uri(userSuppliedId), userSuppliedId, "text/html", - TestSupport.LoadEmbeddedFile(url)); - - Assert.AreEqual(0, userSuppliedId.Discover(this.requestHandler).Count()); // ... but that no endpoint info is discoverable - } - void failDiscoverHtml(string scenario) { - failDiscover("/Discovery/htmldiscovery/" + scenario + ".html"); - } - void failDiscoverXrds(string scenario) { - failDiscover("/Discovery/xrdsdiscovery/" + scenario + ".xml"); - } [TestMethod] public void HtmlDiscover_11() { - discoverHtml("html10prov", ProtocolVersion.V11, null); - discoverHtml("html10both", ProtocolVersion.V11, "http://c/d"); - failDiscoverHtml("html10del"); + this.DiscoverHtml("html10prov", ProtocolVersion.V11, null); + this.DiscoverHtml("html10both", ProtocolVersion.V11, "http://c/d"); + this.FailDiscoverHtml("html10del"); } + [TestMethod] public void HtmlDiscover_20() { - 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"); + this.DiscoverHtml("html20prov", ProtocolVersion.V20, null); + this.DiscoverHtml("html20both", ProtocolVersion.V20, "http://c/d"); + this.FailDiscoverHtml("html20del"); + this.DiscoverHtml("html2010", ProtocolVersion.V20, "http://c/d"); + this.DiscoverHtml("html1020", ProtocolVersion.V20, "http://c/d"); + this.DiscoverHtml("html2010combinedA", ProtocolVersion.V20, "http://c/d"); + this.DiscoverHtml("html2010combinedB", ProtocolVersion.V20, "http://c/d"); + this.DiscoverHtml("html2010combinedC", ProtocolVersion.V20, "http://c/d"); + this.FailDiscoverHtml("html20relative"); } + [TestMethod] public void XrdsDiscoveryFromHead() { this.mockResponder.RegisterMockResponse(new Uri("http://localhost/xrds1020.xml"), "application/xrds+xml", TestSupport.LoadEmbeddedFile("/Discovery/xrdsdiscovery/xrds1020.xml")); - discoverXrds("XrdsReferencedInHead.html", ProtocolVersion.V10, null); + this.DiscoverXrds("XrdsReferencedInHead.html", ProtocolVersion.V10, null); } + [TestMethod] public void XrdsDiscoveryFromHttpHeader() { WebHeaderCollection headers = new WebHeaderCollection(); headers.Add("X-XRDS-Location", TestSupport.GetFullUrl("http://localhost/xrds1020.xml").AbsoluteUri); - this.mockResponder.RegisterMockResponse(new Uri("http://localhost/xrds1020.xml"), - "application/xrds+xml", TestSupport.LoadEmbeddedFile("/Discovery/xrdsdiscovery/xrds1020.xml")); - discoverXrds("XrdsReferencedInHttpHeader.html", ProtocolVersion.V10, null, headers); + this.mockResponder.RegisterMockResponse(new Uri("http://localhost/xrds1020.xml"), "application/xrds+xml", TestSupport.LoadEmbeddedFile("/Discovery/xrdsdiscovery/xrds1020.xml")); + this.DiscoverXrds("XrdsReferencedInHttpHeader.html", ProtocolVersion.V10, null, headers); } + [TestMethod] public void XrdsDirectDiscovery_10() { - failDiscoverXrds("xrds-irrelevant"); - discoverXrds("xrds10", ProtocolVersion.V10, null); - discoverXrds("xrds11", ProtocolVersion.V11, null); - discoverXrds("xrds1020", ProtocolVersion.V10, null); + this.FailDiscoverXrds("xrds-irrelevant"); + this.DiscoverXrds("xrds10", ProtocolVersion.V10, null); + this.DiscoverXrds("xrds11", ProtocolVersion.V11, null); + this.DiscoverXrds("xrds1020", ProtocolVersion.V10, null); } + [TestMethod] public void XrdsDirectDiscovery_20() { - discoverXrds("xrds20", ProtocolVersion.V20, null); - discoverXrds("xrds2010a", ProtocolVersion.V20, null); - discoverXrds("xrds2010b", ProtocolVersion.V20, null); + this.DiscoverXrds("xrds20", ProtocolVersion.V20, null); + this.DiscoverXrds("xrds2010a", ProtocolVersion.V20, null); + this.DiscoverXrds("xrds2010b", ProtocolVersion.V20, null); } [TestMethod] @@ -354,8 +294,7 @@ namespace DotNetOpenAuth.Test.OpenId { var insecureXrdsSource = TestSupport.GetMockIdentifier(TestSupport.Scenarios.AutoApproval, this.mockResponder, ProtocolVersion.V20, false); Uri secureClaimedUri = TestSupport.GetFullUrl("/secureId", null, true); - string html = string.Format("<html><head><meta http-equiv='X-XRDS-Location' content='{0}'/></head><body></body></html>", - insecureXrdsSource); + string html = string.Format("<html><head><meta http-equiv='X-XRDS-Location' content='{0}'/></head><body></body></html>", insecureXrdsSource); this.mockResponder.RegisterMockResponse(secureClaimedUri, "text/html", html); Identifier userSuppliedIdentifier = new UriIdentifier(secureClaimedUri, true); @@ -406,5 +345,77 @@ namespace DotNetOpenAuth.Test.OpenId { this.mockResponder.RegisterMockXrdsResponse(secureClaimedId, new ServiceEndpoint[] { insecureEndpoint, secureEndpoint }); Assert.AreEqual(secureEndpoint.ProviderLocalIdentifier, secureClaimedId.Discover(this.requestHandler).Single().ProviderLocalIdentifier); } + + private void Discover(string url, ProtocolVersion version, Identifier expectedLocalId, bool expectSreg, bool useRedirect) { + this.Discover(url, version, expectedLocalId, expectSreg, useRedirect, null); + } + + private void Discover(string url, ProtocolVersion version, Identifier expectedLocalId, bool expectSreg, bool useRedirect, WebHeaderCollection headers) { + Protocol protocol = Protocol.Lookup(version); + UriIdentifier claimedId = TestSupport.GetFullUrl(url); + UriIdentifier userSuppliedIdentifier = TestSupport.GetFullUrl( + "Discovery/htmldiscovery/redirect.aspx?target=" + url); + if (expectedLocalId == null) { + expectedLocalId = claimedId; + } + Identifier idToDiscover = useRedirect ? userSuppliedIdentifier : claimedId; + + string contentType; + if (url.EndsWith("html")) { + contentType = "text/html"; + } else if (url.EndsWith("xml")) { + contentType = "application/xrds+xml"; + } else { + throw new InvalidOperationException(); + } + this.mockResponder.RegisterMockResponse(new Uri(idToDiscover), claimedId, contentType, headers ?? new WebHeaderCollection(), TestSupport.LoadEmbeddedFile(url)); + + ServiceEndpoint se = idToDiscover.Discover(this.requestHandler).FirstOrDefault(); + 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(expectSreg ? 2 : 1, se.ProviderSupportedServiceTypeUris.Length); + Assert.IsTrue(Array.IndexOf(se.ProviderSupportedServiceTypeUris, protocol.ClaimedIdentifierServiceTypeURI) >= 0); + + // TODO: re-enable this line once extensions support is added back in. + ////Assert.AreEqual(expectSreg, se.IsExtensionSupported(new ClaimsRequest())); + } + + private void DiscoverXrds(string page, ProtocolVersion version, Identifier expectedLocalId) { + this.DiscoverXrds(page, version, expectedLocalId, null); + } + + private void DiscoverXrds(string page, ProtocolVersion version, Identifier expectedLocalId, WebHeaderCollection headers) { + if (!page.Contains(".")) page += ".xml"; + this.Discover("/Discovery/xrdsdiscovery/" + page, version, expectedLocalId, true, false, headers); + this.Discover("/Discovery/xrdsdiscovery/" + page, version, expectedLocalId, true, true, headers); + } + + private void DiscoverHtml(string page, ProtocolVersion version, Identifier expectedLocalId, bool useRedirect) { + this.Discover("/Discovery/htmldiscovery/" + page, version, expectedLocalId, false, useRedirect); + } + + private void DiscoverHtml(string scenario, ProtocolVersion version, Identifier expectedLocalId) { + string page = scenario + ".html"; + this.DiscoverHtml(page, version, expectedLocalId, false); + this.DiscoverHtml(page, version, expectedLocalId, true); + } + + private void FailDiscover(string url) { + UriIdentifier userSuppliedId = TestSupport.GetFullUrl(url); + + this.mockResponder.RegisterMockResponse(new Uri(userSuppliedId), userSuppliedId, "text/html", TestSupport.LoadEmbeddedFile(url)); + + Assert.AreEqual(0, userSuppliedId.Discover(this.requestHandler).Count()); // ... but that no endpoint info is discoverable + } + + private void FailDiscoverHtml(string scenario) { + this.FailDiscover("/Discovery/htmldiscovery/" + scenario + ".html"); + } + + private void FailDiscoverXrds(string scenario) { + this.FailDiscover("/Discovery/xrdsdiscovery/" + scenario + ".xml"); + } } } diff --git a/src/DotNetOpenAuth.Test/OpenId/XriIdentifierTests.cs b/src/DotNetOpenAuth.Test/OpenId/XriIdentifierTests.cs index 5f85f28..4d349ff 100644 --- a/src/DotNetOpenAuth.Test/OpenId/XriIdentifierTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/XriIdentifierTests.cs @@ -1,17 +1,21 @@ -namespace DotNetOpenAuth.Test.OpenId { +//----------------------------------------------------------------------- +// <copyright file="XriIdentifierTests.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.Test.OpenId { using System; using System.Collections.Generic; using System.Linq; + using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.RelyingParty; - using DotNetOpenAuth.Test.Mocks; using Microsoft.VisualStudio.TestTools.UnitTesting; - using DotNetOpenAuth.OpenId; - using DotNetOpenAuth.Messaging; [TestClass] public class XriIdentifierTests : OpenIdTestBase { - string goodXri = "=Andrew*Arnott"; - string badXri = "some\\wacky%^&*()non-XRI"; + private string goodXri = "=Andrew*Arnott"; + private string badXri = "some\\wacky%^&*()non-XRI"; [TestInitialize] public override void SetUp() { @@ -30,29 +34,29 @@ [TestMethod, ExpectedException(typeof(FormatException))] public void CtorBadXri() { - new XriIdentifier(badXri); + new XriIdentifier(this.badXri); } [TestMethod] public void CtorGoodXri() { - var xri = new XriIdentifier(goodXri); - Assert.AreEqual(goodXri, xri.OriginalXri); - Assert.AreEqual(goodXri, xri.CanonicalXri); // assumes 'goodXri' is canonical already + var xri = new XriIdentifier(this.goodXri); + Assert.AreEqual(this.goodXri, xri.OriginalXri); + Assert.AreEqual(this.goodXri, xri.CanonicalXri); // assumes 'goodXri' is canonical already Assert.IsFalse(xri.IsDiscoverySecureEndToEnd); } [TestMethod] public void CtorGoodXriSecure() { - var xri = new XriIdentifier(goodXri, true); - Assert.AreEqual(goodXri, xri.OriginalXri); - Assert.AreEqual(goodXri, xri.CanonicalXri); // assumes 'goodXri' is canonical already + var xri = new XriIdentifier(this.goodXri, true); + Assert.AreEqual(this.goodXri, xri.OriginalXri); + Assert.AreEqual(this.goodXri, xri.CanonicalXri); // assumes 'goodXri' is canonical already Assert.IsTrue(xri.IsDiscoverySecureEndToEnd); } [TestMethod] public void IsValid() { - Assert.IsTrue(XriIdentifier.IsValidXri(goodXri)); - Assert.IsFalse(XriIdentifier.IsValidXri(badXri)); + Assert.IsTrue(XriIdentifier.IsValidXri(this.goodXri)); + Assert.IsFalse(XriIdentifier.IsValidXri(this.badXri)); } /// <summary> @@ -60,40 +64,28 @@ /// </summary> [TestMethod] public void StripXriScheme() { - var xri = new XriIdentifier("xri://" + goodXri); - Assert.AreEqual("xri://" + goodXri, xri.OriginalXri); - Assert.AreEqual(goodXri, xri.CanonicalXri); + var xri = new XriIdentifier("xri://" + this.goodXri); + Assert.AreEqual("xri://" + this.goodXri, xri.OriginalXri); + Assert.AreEqual(this.goodXri, xri.CanonicalXri); } [TestMethod] public void TrimFragment() { - Identifier xri = new XriIdentifier(goodXri); + Identifier xri = new XriIdentifier(this.goodXri); Assert.AreSame(xri, xri.TrimFragment()); } [TestMethod] public void ToStringTest() { - Assert.AreEqual(goodXri, new XriIdentifier(goodXri).ToString()); + Assert.AreEqual(this.goodXri, new XriIdentifier(this.goodXri).ToString()); } [TestMethod] public void EqualsTest() { - Assert.AreEqual(new XriIdentifier(goodXri), new XriIdentifier(goodXri)); - Assert.AreNotEqual(new XriIdentifier(goodXri), new XriIdentifier(goodXri + "a")); - Assert.AreNotEqual(null, new XriIdentifier(goodXri)); - Assert.AreEqual(goodXri, new XriIdentifier(goodXri)); - } - - private ServiceEndpoint verifyCanonicalId(Identifier iname, string expectedClaimedIdentifier) { - ServiceEndpoint se = iname.Discover(this.requestHandler).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.ProviderSupportedServiceTypeUris.Length > 0); - } else { - Assert.IsNull(se); - } - return se; + Assert.AreEqual(new XriIdentifier(this.goodXri), new XriIdentifier(this.goodXri)); + Assert.AreNotEqual(new XriIdentifier(this.goodXri), new XriIdentifier(this.goodXri + "a")); + Assert.AreNotEqual(null, new XriIdentifier(this.goodXri)); + Assert.AreEqual(this.goodXri, new XriIdentifier(this.goodXri)); } [TestMethod] @@ -136,7 +128,7 @@ this.mockResponder.RegisterMockXrdsResponses(mocks); string expectedCanonicalId = "=!9B72.7DD1.50A9.5CCD"; - ServiceEndpoint se = verifyCanonicalId("=Arnott", expectedCanonicalId); + ServiceEndpoint se = this.VerifyCanonicalId("=Arnott", expectedCanonicalId); Assert.AreEqual(Protocol.V10, se.Protocol); Assert.AreEqual("http://1id.com/sso", se.ProviderEndpoint.ToString()); Assert.AreEqual(se.ClaimedIdentifier, se.ProviderLocalIdentifier); @@ -366,11 +358,11 @@ uEyb50RJ7DWmXctSC0b3eymZ2lSXxAWNOsNy { "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 }, }); - 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"); + this.VerifyCanonicalId("@llli", "@!72CD.A072.157E.A9C6"); + this.VerifyCanonicalId("@llli*area", "@!72CD.A072.157E.A9C6!0000.0000.3B9A.CA0C"); + this.VerifyCanonicalId("@llli*area*canada.unattached", "@!72CD.A072.157E.A9C6!0000.0000.3B9A.CA0C!0000.0000.3B9A.CA41"); + this.VerifyCanonicalId("@llli*area*canada.unattached*ada", "@!72CD.A072.157E.A9C6!0000.0000.3B9A.CA0C!0000.0000.3B9A.CA41!0000.0000.3B9A.CA01"); + this.VerifyCanonicalId("=Web", "=!91F2.8153.F600.AE24"); } [TestMethod] @@ -456,8 +448,8 @@ uEyb50RJ7DWmXctSC0b3eymZ2lSXxAWNOsNy }); // 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); + this.VerifyCanonicalId("=Web*andrew.arnott", null); + this.VerifyCanonicalId("@id*andrewarnott", null); } ////[TestMethod, Ignore("XRI parsing and normalization is not implemented (yet).")] @@ -465,5 +457,17 @@ uEyb50RJ7DWmXctSC0b3eymZ2lSXxAWNOsNy Identifier id = "=!9B72.7dd1.50a9.5ccd"; Assert.AreEqual("=!9B72.7DD1.50A9.5CCD", id.ToString()); } + + private ServiceEndpoint VerifyCanonicalId(Identifier iname, string expectedClaimedIdentifier) { + ServiceEndpoint se = iname.Discover(this.requestHandler).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.ProviderSupportedServiceTypeUris.Length > 0); + } else { + Assert.IsNull(se); + } + return se; + } } } |