summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-12-26 14:24:47 -0800
committerAndrew <andrewarnott@gmail.com>2008-12-26 14:24:47 -0800
commitc4557a7ff40920582e60cc75ebdcb24a7c05ae9e (patch)
tree1d2650da4cdadd5195cae39bc663d349b4f320dd
parent095f0d7bb1625c0710701d64d55fc631e66f5220 (diff)
downloadDotNetOpenAuth-c4557a7ff40920582e60cc75ebdcb24a7c05ae9e.zip
DotNetOpenAuth-c4557a7ff40920582e60cc75ebdcb24a7c05ae9e.tar.gz
DotNetOpenAuth-c4557a7ff40920582e60cc75ebdcb24a7c05ae9e.tar.bz2
Ported ServiceEndpointTests and fixed but in ProviderEndpointDescription class.
-rw-r--r--src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj1
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/RelyingParty/ServiceEndpointTests.cs174
-rw-r--r--src/DotNetOpenAuth.Test/Settings.StyleCop93
-rw-r--r--src/DotNetOpenAuth/DotNetOpenAuth.csproj2
-rw-r--r--src/DotNetOpenAuth/OpenId/ProviderEndpointDescription.cs (renamed from src/DotNetOpenAuth/OpenId/ProviderDescription.cs)8
5 files changed, 227 insertions, 51 deletions
diff --git a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
index 9d181c5..b680db2 100644
--- a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
+++ b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
@@ -133,6 +133,7 @@
<Compile Include="OpenId\RealmTests.cs" />
<Compile Include="OpenId\RelyingParty\OpenIdRelyingPartyTests.cs" />
<Compile Include="OpenId\RelyingParty\RelyingPartySecuritySettingsTests.cs" />
+ <Compile Include="OpenId\RelyingParty\ServiceEndpointTests.cs" />
<Compile Include="OpenId\TestSupport.cs" />
<Compile Include="OpenId\UI\UITestSupport.cs" />
<Compile Include="OpenId\UriIdentifierTests.cs" />
diff --git a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/ServiceEndpointTests.cs b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/ServiceEndpointTests.cs
new file mode 100644
index 0000000..897904c
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/ServiceEndpointTests.cs
@@ -0,0 +1,174 @@
+//-----------------------------------------------------------------------
+// <copyright file="ServiceEndpointTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.IO;
+ using System.Text;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OpenId;
+ using DotNetOpenAuth.OpenId.RelyingParty;
+ using DotNetOpenAuth.Test.Messaging;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class ServiceEndpointTests : OpenIdTestBase {
+ private UriIdentifier claimedId = new UriIdentifier("http://claimedid.justatest.com");
+ private XriIdentifier claimedXri = new XriIdentifier("=!9B72.7DD1.50A9.5CCD");
+ private XriIdentifier userSuppliedXri = new XriIdentifier("=Arnot");
+ private Uri providerEndpoint = new Uri("http://someprovider.com");
+ private Identifier localId = "http://localid.someprovider.com";
+ private string[] v20TypeUris = { Protocol.V20.ClaimedIdentifierServiceTypeURI };
+ private string[] v11TypeUris = { Protocol.V11.ClaimedIdentifierServiceTypeURI };
+ private int servicePriority = 10;
+ private int uriPriority = 10;
+
+ [TestMethod]
+ public void Ctor() {
+ ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedId, this.localId, new ProviderEndpointDescription(this.providerEndpoint, this.v20TypeUris), this.servicePriority, this.uriPriority);
+ Assert.AreSame(this.claimedId, se.ClaimedIdentifier);
+ Assert.AreSame(this.providerEndpoint, se.ProviderEndpoint);
+ Assert.AreSame(this.localId, se.ProviderLocalIdentifier);
+ CollectionAssert<string>.AreEquivalent(this.v20TypeUris, se.ProviderSupportedServiceTypeUris);
+ Assert.AreEqual(this.servicePriority, ((IXrdsProviderEndpoint)se).ServicePriority);
+ }
+
+ [TestMethod]
+ public void CtorImpliedLocalIdentifier() {
+ ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedId, null, new ProviderEndpointDescription(this.providerEndpoint, this.v20TypeUris), this.servicePriority, this.uriPriority);
+ Assert.AreSame(this.claimedId, se.ClaimedIdentifier);
+ Assert.AreSame(this.providerEndpoint, se.ProviderEndpoint);
+ Assert.AreSame(this.claimedId, se.ProviderLocalIdentifier);
+ CollectionAssert<string>.AreEquivalent(this.v20TypeUris, se.ProviderSupportedServiceTypeUris);
+ }
+
+ [TestMethod]
+ public void ProtocolDetection() {
+ ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedId, this.localId, new ProviderEndpointDescription(this.providerEndpoint, this.v20TypeUris), this.servicePriority, this.uriPriority);
+ Assert.AreSame(Protocol.V20, se.Protocol);
+ se = ServiceEndpoint.CreateForClaimedIdentifier(
+ this.claimedId,
+ this.localId,
+ new ProviderEndpointDescription(this.providerEndpoint, new[] { Protocol.V20.OPIdentifierServiceTypeURI }),
+ this.servicePriority,
+ this.uriPriority);
+ Assert.AreSame(Protocol.V20, se.Protocol);
+ se = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedId, this.localId, new ProviderEndpointDescription(this.providerEndpoint, this.v11TypeUris), this.servicePriority, this.uriPriority);
+ Assert.AreSame(Protocol.V11, se.Protocol);
+ }
+
+ [TestMethod, ExpectedException(typeof(ProtocolException))]
+ public void ProtocolDetectionWithoutClues() {
+ ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(
+ this.claimedId,
+ this.localId,
+ new ProviderEndpointDescription(this.providerEndpoint, new[] { Protocol.V20.HtmlDiscoveryLocalIdKey }), // random type URI irrelevant to detection
+ this.servicePriority,
+ this.uriPriority);
+ }
+
+ [TestMethod]
+ public void SerializationWithUri() {
+ ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedId, this.localId, new ProviderEndpointDescription(this.providerEndpoint, this.v20TypeUris), this.servicePriority, this.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);
+ }
+ }
+
+ [TestMethod]
+ public void SerializationWithXri() {
+ ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedXri, this.userSuppliedXri, this.localId, new ProviderEndpointDescription(this.providerEndpoint, this.v20TypeUris), this.servicePriority, this.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);
+ }
+ }
+
+ [TestMethod]
+ public void EqualsTests() {
+ ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedId, this.localId, new ProviderEndpointDescription(this.providerEndpoint, this.v20TypeUris), this.servicePriority, this.uriPriority);
+ ServiceEndpoint se2 = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedId, this.localId, new ProviderEndpointDescription(this.providerEndpoint, this.v20TypeUris), (int?)null, (int?)null);
+ Assert.AreEqual(se2, se);
+ Assert.AreNotEqual(se, null);
+ Assert.AreNotEqual(null, se);
+
+ ServiceEndpoint se3 = ServiceEndpoint.CreateForClaimedIdentifier(new UriIdentifier(this.claimedId + "a"), this.localId, new ProviderEndpointDescription(this.providerEndpoint, this.v20TypeUris), this.servicePriority, this.uriPriority);
+ Assert.AreNotEqual(se, se3);
+ se3 = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedId, this.localId, new ProviderEndpointDescription(new Uri(this.providerEndpoint.AbsoluteUri + "a"), this.v20TypeUris), this.servicePriority, this.uriPriority);
+ Assert.AreNotEqual(se, se3);
+ se3 = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedId, this.localId + "a", new ProviderEndpointDescription(this.providerEndpoint, this.v20TypeUris), this.servicePriority, this.uriPriority);
+ Assert.AreNotEqual(se, se3);
+ se3 = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedId, this.localId, new ProviderEndpointDescription(this.providerEndpoint, this.v11TypeUris), this.servicePriority, this.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));
+ }
+
+ [TestMethod]
+ public void FriendlyIdentifierForDisplay() {
+ Uri providerEndpoint = new Uri("http://someprovider");
+ Identifier localId = "someuser";
+ string[] serviceTypeUris = new string[] {
+ Protocol.V20.ClaimedIdentifierServiceTypeURI,
+ };
+ ServiceEndpoint se;
+
+ // strip of protocol and fragment
+ se = ServiceEndpoint.CreateForClaimedIdentifier(
+ "http://someprovider.somedomain.com:79/someuser#frag",
+ localId,
+ new ProviderEndpointDescription(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, new ProviderEndpointDescription(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,
+ new ProviderEndpointDescription(providerEndpoint, serviceTypeUris),
+ null,
+ null);
+ Assert.AreEqual("=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,
+ new ProviderEndpointDescription(providerEndpoint, serviceTypeUris),
+ null,
+ null);
+ Assert.AreEqual("=!9B72.7DD1.50A9.5CCD", se.FriendlyIdentifierForDisplay);
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.Test/Settings.StyleCop b/src/DotNetOpenAuth.Test/Settings.StyleCop
index d8cb897..551e87c 100644
--- a/src/DotNetOpenAuth.Test/Settings.StyleCop
+++ b/src/DotNetOpenAuth.Test/Settings.StyleCop
@@ -1,47 +1,48 @@
-<StyleCopSettings Version="4.3">
- <Analyzers>
- <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.DocumentationRules">
- <Rules>
- <Rule Name="ElementsMustBeDocumented">
- <RuleSettings>
- <BooleanProperty Name="Enabled">False</BooleanProperty>
- </RuleSettings>
- </Rule>
- <Rule Name="EnumerationItemsMustBeDocumented">
- <RuleSettings>
- <BooleanProperty Name="Enabled">False</BooleanProperty>
- </RuleSettings>
- </Rule>
- </Rules>
- <AnalyzerSettings />
- </Analyzer>
- <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.LayoutRules">
- <Rules>
- <Rule Name="SingleLineCommentMustBePrecededByBlankLine">
- <RuleSettings>
- <BooleanProperty Name="Enabled">False</BooleanProperty>
- </RuleSettings>
- </Rule>
- </Rules>
- <AnalyzerSettings />
- </Analyzer>
- <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.NamingRules">
- <AnalyzerSettings>
- <CollectionProperty Name="Hungarian">
- <Value>op</Value>
- <Value>rp</Value>
- </CollectionProperty>
- </AnalyzerSettings>
- </Analyzer>
- <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.MaintainabilityRules">
- <Rules>
- <Rule Name="FieldsMustBePrivate">
- <RuleSettings>
- <BooleanProperty Name="Enabled">False</BooleanProperty>
- </RuleSettings>
- </Rule>
- </Rules>
- <AnalyzerSettings />
- </Analyzer>
- </Analyzers>
+<StyleCopSettings Version="4.3">
+ <Analyzers>
+ <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.DocumentationRules">
+ <Rules>
+ <Rule Name="ElementsMustBeDocumented">
+ <RuleSettings>
+ <BooleanProperty Name="Enabled">False</BooleanProperty>
+ </RuleSettings>
+ </Rule>
+ <Rule Name="EnumerationItemsMustBeDocumented">
+ <RuleSettings>
+ <BooleanProperty Name="Enabled">False</BooleanProperty>
+ </RuleSettings>
+ </Rule>
+ </Rules>
+ <AnalyzerSettings />
+ </Analyzer>
+ <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.LayoutRules">
+ <Rules>
+ <Rule Name="SingleLineCommentMustBePrecededByBlankLine">
+ <RuleSettings>
+ <BooleanProperty Name="Enabled">False</BooleanProperty>
+ </RuleSettings>
+ </Rule>
+ </Rules>
+ <AnalyzerSettings />
+ </Analyzer>
+ <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.NamingRules">
+ <AnalyzerSettings>
+ <CollectionProperty Name="Hungarian">
+ <Value>op</Value>
+ <Value>rp</Value>
+ <Value>v</Value>
+ </CollectionProperty>
+ </AnalyzerSettings>
+ </Analyzer>
+ <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.MaintainabilityRules">
+ <Rules>
+ <Rule Name="FieldsMustBePrivate">
+ <RuleSettings>
+ <BooleanProperty Name="Enabled">False</BooleanProperty>
+ </RuleSettings>
+ </Rule>
+ </Rules>
+ <AnalyzerSettings />
+ </Analyzer>
+ </Analyzers>
</StyleCopSettings> \ No newline at end of file
diff --git a/src/DotNetOpenAuth/DotNetOpenAuth.csproj b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
index ecf4e77..6a0ce33 100644
--- a/src/DotNetOpenAuth/DotNetOpenAuth.csproj
+++ b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
@@ -233,7 +233,7 @@
<AutoGen>True</AutoGen>
</Compile>
<Compile Include="OpenId\Protocol.cs" />
- <Compile Include="OpenId\ProviderDescription.cs" />
+ <Compile Include="OpenId\ProviderEndpointDescription.cs" />
<Compile Include="OpenId\Provider\ProviderSecuritySettings.cs" />
<Compile Include="OpenId\RelyingParty\RelyingPartySecuritySettings.cs" />
<Compile Include="OpenId\RelyingParty\ServiceEndpoint.cs" />
diff --git a/src/DotNetOpenAuth/OpenId/ProviderDescription.cs b/src/DotNetOpenAuth/OpenId/ProviderEndpointDescription.cs
index 6a72e06..15ba2e9 100644
--- a/src/DotNetOpenAuth/OpenId/ProviderDescription.cs
+++ b/src/DotNetOpenAuth/OpenId/ProviderEndpointDescription.cs
@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------
-// <copyright file="ProviderDescription.cs" company="Andrew Arnott">
+// <copyright file="ProviderEndpointDescription.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
@@ -41,9 +41,9 @@ namespace DotNetOpenAuth.OpenId {
ErrorUtilities.VerifyArgumentNotNull(serviceTypeURIs, "serviceTypeURIs");
this.Endpoint = providerEndpoint;
- this.Capabilities = new ReadOnlyCollection<string>(serviceTypeURIs.ToList());
-
- Protocol opIdentifierProtocol = Protocol.FindBestVersion(p => p.ClaimedIdentifierForOPIdentifier, serviceTypeURIs);
+ this.Capabilities = new ReadOnlyCollection<string>(serviceTypeURIs.ToList());
+
+ Protocol opIdentifierProtocol = Protocol.FindBestVersion(p => p.OPIdentifierServiceTypeURI, serviceTypeURIs);
Protocol claimedIdentifierProviderVersion = Protocol.FindBestVersion(p => p.ClaimedIdentifierServiceTypeURI, serviceTypeURIs);
if (opIdentifierProtocol != null) {
this.ProtocolVersion = opIdentifierProtocol.Version;