diff options
6 files changed, 69 insertions, 17 deletions
diff --git a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj index 0e460bd..d16b6c4 100644 --- a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj +++ b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj @@ -41,6 +41,7 @@ </Reference> <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> <Reference Include="System" /> + <Reference Include="System.configuration" /> <Reference Include="System.Core"> <RequiredTargetFramework>3.5</RequiredTargetFramework> </Reference> @@ -105,6 +106,7 @@ <Compile Include="OpenId\Messages\IndirectErrorResponseTests.cs" /> <Compile Include="OpenId\OpenIdCoordinator.cs" /> <Compile Include="OpenId\AssociationHandshakeTests.cs" /> + <Compile Include="OpenId\OpenIdTestBase.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Messaging\ResponseTests.cs" /> <Compile Include="OAuth\AppendixScenarios.cs" /> diff --git a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs index 103a252..e411ecb 100644 --- a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs @@ -6,26 +6,43 @@ namespace DotNetOpenAuth.Test.OpenId { using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.Messages; using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] - public class AssociationHandshakeTests { + public class AssociationHandshakeTests : OpenIdTestBase { [TestMethod] - public void AssociateDiffieHellmanMessages() { + public void DHv2() { var opDescription = new ProviderEndpointDescription(new Uri("http://host"), Protocol.V20); - ParameterizedAssociationTest(opDescription, true, Protocol.V20.Args.SignatureAlgorithm.HMAC_SHA1); + this.ParameterizedAssociationTest( + opDescription, + Protocol.V20.Args.SignatureAlgorithm.HMAC_SHA256); } [TestMethod] - public void AssociateUnencryptedMessages() { + public void DHv1() { + var opDescription = new ProviderEndpointDescription(new Uri("http://host"), Protocol.V10); + this.ParameterizedAssociationTest( + opDescription, + Protocol.V20.Args.SignatureAlgorithm.HMAC_SHA1); + } + + [TestMethod] + public void PTv2() { var opDescription = new ProviderEndpointDescription(new Uri("https://host"), Protocol.V20); - ParameterizedAssociationTest(opDescription, false, Protocol.V20.Args.SignatureAlgorithm.HMAC_SHA1); + this.ParameterizedAssociationTest( + opDescription, + Protocol.V20.Args.SignatureAlgorithm.HMAC_SHA256); + } + + [TestMethod] + public void PTv1() { + var opDescription = new ProviderEndpointDescription(new Uri("https://host"), Protocol.V11); + this.ParameterizedAssociationTest( + opDescription, + Protocol.V20.Args.SignatureAlgorithm.HMAC_SHA1); } /// <summary> @@ -35,24 +52,25 @@ namespace DotNetOpenAuth.Test.OpenId { /// The description of the Provider that the relying party uses to formulate the request. /// The specific host is not used, but the scheme is significant. /// </param> - /// <param name="expectDiffieHellman">True if a DH session is expected to be used.</param> /// <param name="expectedAssociationType"> /// The value of the openid.assoc_type parameter expected, /// or null if a failure is anticipated. /// </param> private void ParameterizedAssociationTest( ProviderEndpointDescription opDescription, - bool expectDiffieHellman, string expectedAssociationType) { bool expectSuccess = expectedAssociationType != null; + bool expectDiffieHellman = !opDescription.Endpoint.IsTransportSecure(); Association rpAssociation = null, opAssociation; AssociateSuccessfulResponse associateSuccessfulResponse = null; AssociateUnsuccessfulResponse associateUnsuccessfulResponse = null; OpenIdCoordinator coordinator = new OpenIdCoordinator( rp => { + rp.SecuritySettings = this.RelyingPartySecuritySettings; rpAssociation = rp.GetAssociation(opDescription); }, op => { + op.SecuritySettings = this.ProviderSecuritySettings; op.AutoRespond(); }); coordinator.IncomingMessageFilter = (message) => { diff --git a/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs b/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs new file mode 100644 index 0000000..4b52634 --- /dev/null +++ b/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs @@ -0,0 +1,24 @@ +//----------------------------------------------------------------------- +// <copyright file="OpenIdTestBase.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.Test.OpenId { + using DotNetOpenAuth.Configuration; + using DotNetOpenAuth.OpenId.Provider; + using DotNetOpenAuth.OpenId.RelyingParty; + + public class OpenIdTestBase : TestBase { + protected RelyingPartySecuritySettings RelyingPartySecuritySettings { get; private set; } + + protected ProviderSecuritySettings ProviderSecuritySettings { get; private set; } + + public override void SetUp() { + base.SetUp(); + + RelyingPartySecuritySettings = RelyingPartySection.Configuration.SecuritySettings.CreateSecuritySettings(); + ProviderSecuritySettings = ProviderSection.Configuration.SecuritySettings.CreateSecuritySettings(); + } + } +} diff --git a/src/DotNetOpenAuth/OpenId/OpenIdProvider.cs b/src/DotNetOpenAuth/OpenId/OpenIdProvider.cs index d1c48e7..ed095ae 100644 --- a/src/DotNetOpenAuth/OpenId/OpenIdProvider.cs +++ b/src/DotNetOpenAuth/OpenId/OpenIdProvider.cs @@ -6,9 +6,7 @@ namespace DotNetOpenAuth.OpenId { using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; + using DotNetOpenAuth.Configuration; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.ChannelElements; using DotNetOpenAuth.OpenId.Messages; @@ -26,6 +24,7 @@ namespace DotNetOpenAuth.OpenId { this.Channel = new OpenIdChannel(); this.AssociationStore = associationStore; + this.SecuritySettings = ProviderSection.Configuration.SecuritySettings.CreateSecuritySettings(); } /// <summary> @@ -34,6 +33,11 @@ namespace DotNetOpenAuth.OpenId { public Channel Channel { get; internal set; } /// <summary> + /// Gets the security settings used by this Provider. + /// </summary> + public Provider.ProviderSecuritySettings SecuritySettings { get; internal set; } + + /// <summary> /// Gets the association store. /// </summary> internal IAssociationStore<AssociationRelyingPartyType> AssociationStore { get; private set; } diff --git a/src/DotNetOpenAuth/OpenId/OpenIdRelyingParty.cs b/src/DotNetOpenAuth/OpenId/OpenIdRelyingParty.cs index cc7c5f5..a67b223 100644 --- a/src/DotNetOpenAuth/OpenId/OpenIdRelyingParty.cs +++ b/src/DotNetOpenAuth/OpenId/OpenIdRelyingParty.cs @@ -6,9 +6,7 @@ namespace DotNetOpenAuth.OpenId { using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; + using DotNetOpenAuth.Configuration; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.ChannelElements; using DotNetOpenAuth.OpenId.Messages; @@ -26,6 +24,7 @@ namespace DotNetOpenAuth.OpenId { this.Channel = new OpenIdChannel(); this.AssociationStore = associationStore; + this.SecuritySettings = RelyingPartySection.Configuration.SecuritySettings.CreateSecuritySettings(); } /// <summary> @@ -34,6 +33,11 @@ namespace DotNetOpenAuth.OpenId { public Channel Channel { get; internal set; } /// <summary> + /// Gets the security settings used by this Relying Party. + /// </summary> + public RelyingParty.RelyingPartySecuritySettings SecuritySettings { get; internal set; } + + /// <summary> /// Gets the association store. /// </summary> internal IAssociationStore<Uri> AssociationStore { get; private set; } diff --git a/src/DotNetOpenAuth/OpenId/Provider/ProviderSecuritySettings.cs b/src/DotNetOpenAuth/OpenId/Provider/ProviderSecuritySettings.cs index 3ae299e..b025142 100644 --- a/src/DotNetOpenAuth/OpenId/Provider/ProviderSecuritySettings.cs +++ b/src/DotNetOpenAuth/OpenId/Provider/ProviderSecuritySettings.cs @@ -8,7 +8,7 @@ namespace DotNetOpenAuth.OpenId.Provider { /// <summary> /// Security settings that are applicable to providers. /// </summary> - internal sealed class ProviderSecuritySettings : SecuritySettings { + public sealed class ProviderSecuritySettings : SecuritySettings { /// <summary> /// Initializes a new instance of the <see cref="ProviderSecuritySettings"/> class. /// </summary> |