diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-01-21 07:43:10 -0800 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2009-01-21 07:43:10 -0800 |
commit | f2c098cf7c700e3e9dc87316608a50de48222e19 (patch) | |
tree | d63e202a08a94faf1f557a3cd46efd3111b6d3ed /src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs | |
parent | 2d67dfd17c7222d16ac620ec667b32bb52b28a72 (diff) | |
download | DotNetOpenAuth-f2c098cf7c700e3e9dc87316608a50de48222e19.zip DotNetOpenAuth-f2c098cf7c700e3e9dc87316608a50de48222e19.tar.gz DotNetOpenAuth-f2c098cf7c700e3e9dc87316608a50de48222e19.tar.bz2 |
Lots of little bug fixes, and added a (finally!) passing test for unsigned extensions being ignored.
Diffstat (limited to 'src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs')
-rw-r--r-- | src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs index 7a719ec..a9217eb 100644 --- a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs @@ -93,11 +93,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements { public void ExtensionResponsesAreSigned() { Protocol protocol = Protocol.Default; var op = this.CreateProvider(); - IndirectSignedResponse response = new IndirectSignedResponse(protocol.Version, RPUri); - response.ReturnTo = RPUri; - response.ProviderEndpoint = ProviderUri; - var ext = new MockOpenIdExtension("pv", "ev"); - response.Extensions.Add(ext); + IndirectSignedResponse response = CreateResponseWithExtensions(protocol); op.Channel.Send(response); ITamperResistantOpenIdMessage signedResponse = (ITamperResistantOpenIdMessage)response; string extensionAliasKey = signedResponse.ExtraData.Single(kv => kv.Value == MockOpenIdExtension.MockTypeUri).Key; @@ -115,9 +111,47 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements { /// <summary> /// Verifies that unsigned extension responses (where any or all fields are unsigned) are ignored. /// </summary> - [TestMethod, Ignore] + [TestMethod] public void UnsignedExtensionsAreIgnored() { - Assert.Inconclusive("Not yet implemented."); + Protocol protocol = Protocol.Default; + OpenIdCoordinator coordinator = new OpenIdCoordinator( + rp => { + RegisterMockExtension(rp.Channel); + var response = rp.Channel.ReadFromRequest<IndirectSignedResponse>(); + Assert.AreEqual(1, response.Extensions.Count, "Signed extension should have been received."); + response = rp.Channel.ReadFromRequest<IndirectSignedResponse>(); + Assert.AreEqual(0, response.Extensions.Count, "Unsigned extension should have been ignored."); + }, + op => { + RegisterMockExtension(op.Channel); + op.Channel.Send(CreateResponseWithExtensions(protocol)).Send(); + op.GetRequest().Response.Send(); // check_auth + op.SecuritySettings.SignOutgoingExtensions = false; + op.Channel.Send(CreateResponseWithExtensions(protocol)).Send(); + op.GetRequest().Response.Send(); // check_auth + } + ); + coordinator.Run(); + } + + private static void RegisterMockExtension(Channel channel) { + ErrorUtilities.VerifyArgumentNotNull(channel, "channel"); + + ((OpenIdExtensionFactory)channel.BindingElements.OfType<ExtensionsBindingElement>().Single().ExtensionFactory).RegisterExtension(MockOpenIdExtension.Factory); + } + + /// <summary> + /// Creates a response message with one extensions. + /// </summary> + /// <param name="protocol">The protocol to construct the message with.</param> + /// <returns>The message ready to send from OP to RP.</returns> + private IndirectSignedResponse CreateResponseWithExtensions(Protocol protocol) { + ErrorUtilities.VerifyArgumentNotNull(protocol, "protocol"); + + IndirectSignedResponse response = new IndirectSignedResponse(protocol.Version, RPUri); + response.ProviderEndpoint = ProviderUri; + response.Extensions.Add(new MockOpenIdExtension("pv", "ev")); + return response; } /// <summary> |