summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj1
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/AssociationsTests.cs79
3 files changed, 81 insertions, 1 deletions
diff --git a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
index 0ea0f5e..9c18ac1 100644
--- a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
+++ b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
@@ -101,6 +101,7 @@
<Compile Include="OAuth\ConsumerDescription.cs" />
<Compile Include="OAuth\ProtocolTests.cs" />
<Compile Include="OAuth\ServiceProviderDescriptionTests.cs" />
+ <Compile Include="OpenId\AssociationsTests.cs" />
<Compile Include="OpenId\ChannelElements\KeyValueFormEncodingTests.cs" />
<Compile Include="OpenId\IdentifierTests.cs" />
<Compile Include="OpenId\Messages\AssociateDiffieHellmanRequestTests.cs" />
diff --git a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
index 7743ccc..8637cfd 100644
--- a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
@@ -24,7 +24,7 @@ namespace DotNetOpenAuth.Test.OpenId {
}
[TestMethod]
- public void AssociateDiffieHellman() {
+ public void AssociateDiffieHellmanOverHttp() {
this.ParameterizedAssociationTest(new Uri("http://host"));
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/AssociationsTests.cs b/src/DotNetOpenAuth.Test/OpenId/AssociationsTests.cs
new file mode 100644
index 0000000..65de3e0
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/OpenId/AssociationsTests.cs
@@ -0,0 +1,79 @@
+//-----------------------------------------------------------------------
+// <copyright file="AssociationsTests.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 System.Security.Cryptography;
+ using System.Text;
+ using DotNetOpenAuth.OpenId;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class AssociationsTests : OpenIdTestBase {
+ private static readonly HashAlgorithm sha1 = DiffieHellmanUtilities.Lookup(Protocol.Default, Protocol.Default.Args.SessionType.DH_SHA1);
+ private byte[] sha1Secret;
+ private Associations assocs;
+
+ [TestInitialize]
+ public override void SetUp() {
+ this.sha1Secret = new byte[sha1.HashSize / 8];
+ this.assocs = new Associations();
+ }
+
+ [TestMethod]
+ public void GetNonexistentHandle() {
+ Assert.IsNull(this.assocs.Get("someinvalidhandle"));
+ }
+
+ [TestMethod]
+ public void RemoveNonexistentHandle() {
+ Assert.IsFalse(this.assocs.Remove("someinvalidhandle"));
+ }
+
+ [TestMethod]
+ public void HandleLifecycle() {
+ Association a = HmacShaAssociation.Create(
+ Protocol.Default,
+ Protocol.Default.Args.SignatureAlgorithm.HMAC_SHA1,
+ "somehandle",
+ this.sha1Secret,
+ TimeSpan.FromDays(1));
+ this.assocs.Set(a);
+ Assert.AreSame(a, this.assocs.Get(a.Handle));
+ Assert.IsTrue(this.assocs.Remove(a.Handle));
+ Assert.IsNull(this.assocs.Get(a.Handle));
+ Assert.IsFalse(this.assocs.Remove(a.Handle));
+ }
+
+ [TestMethod]
+ public void Best() {
+ Association a = HmacShaAssociation.Create(
+ Protocol.Default,
+ Protocol.Default.Args.SignatureAlgorithm.HMAC_SHA1,
+ "h1",
+ this.sha1Secret,
+ TimeSpan.FromHours(1));
+ Association b = HmacShaAssociation.Create(
+ Protocol.Default,
+ Protocol.Default.Args.SignatureAlgorithm.HMAC_SHA1,
+ "h2",
+ this.sha1Secret,
+ TimeSpan.FromHours(1));
+
+ this.assocs.Set(a);
+ this.assocs.Set(b);
+
+ // make b the best by making a older
+ a.Issued -= TimeSpan.FromHours(1);
+ Assert.AreSame(b, this.assocs.Best);
+ // now make a the best
+ b.Issued -= TimeSpan.FromHours(2);
+ Assert.AreSame(a, this.assocs.Best);
+ }
+ }
+}