diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-01-09 21:03:29 -0800 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2009-01-09 21:03:29 -0800 |
commit | d8abcbe507383d3510ee45ed19f6503c60d7d63b (patch) | |
tree | 64d656b165aed099ef68881c98082d552f5af2e4 /src/DotNetOpenAuth.Test/OpenId/ChannelElements | |
parent | 588d1384431e23827921124bd438569231cbdfa7 (diff) | |
download | DotNetOpenAuth-d8abcbe507383d3510ee45ed19f6503c60d7d63b.zip DotNetOpenAuth-d8abcbe507383d3510ee45ed19f6503c60d7d63b.tar.gz DotNetOpenAuth-d8abcbe507383d3510ee45ed19f6503c60d7d63b.tar.bz2 |
CRLF -> LF line endings change to all .cs files.
Diffstat (limited to 'src/DotNetOpenAuth.Test/OpenId/ChannelElements')
-rw-r--r-- | src/DotNetOpenAuth.Test/OpenId/ChannelElements/OpenIdChannelTests.cs | 204 |
1 files changed, 102 insertions, 102 deletions
diff --git a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/OpenIdChannelTests.cs b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/OpenIdChannelTests.cs index a548969..60cbe3e 100644 --- a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/OpenIdChannelTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/OpenIdChannelTests.cs @@ -1,102 +1,102 @@ -//-----------------------------------------------------------------------
-// <copyright file="OpenIdChannelTests.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.Test.OpenId.ChannelElements {
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.Messaging.Bindings;
- using DotNetOpenAuth.Messaging.Reflection;
- using DotNetOpenAuth.OpenId;
- using DotNetOpenAuth.OpenId.ChannelElements;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
-
- [TestClass]
- public class OpenIdChannelTests : TestBase {
- private static readonly TimeSpan maximumMessageAge = TimeSpan.FromHours(3); // good for tests, too long for production
- private OpenIdChannel channel;
- private OpenIdChannel_Accessor accessor;
- private Mocks.TestWebRequestHandler webHandler;
-
- [TestInitialize]
- public void Setup() {
- this.webHandler = new Mocks.TestWebRequestHandler();
- this.channel = new OpenIdChannel(new AssociationMemoryStore<Uri>(), new NonceMemoryStore(maximumMessageAge), new PrivateSecretMemoryStore());
- this.accessor = OpenIdChannel_Accessor.AttachShadow(this.channel);
- this.channel.WebRequestHandler = this.webHandler;
- }
-
- [TestMethod]
- public void Ctor() {
- // Verify that the channel stack includes the expected types.
- // While other binding elements may be substituted for these, we'd then have
- // to test them. Since we're not testing them in the OpenID battery of tests,
- // we make sure they are the standard ones so that we trust they are tested
- // elsewhere by the testing library.
- var replayElement = (StandardReplayProtectionBindingElement)this.channel.BindingElements.SingleOrDefault(el => el is StandardReplayProtectionBindingElement);
- Assert.IsTrue(this.channel.BindingElements.Any(el => el is StandardExpirationBindingElement));
- Assert.IsNotNull(replayElement);
-
- // Verify that empty nonces are allowed, since OpenID 2.0 allows this.
- Assert.IsTrue(replayElement.AllowZeroLengthNonce);
- }
-
- /// <summary>
- /// Verifies that the channel sends direct message requests as HTTP POST requests.
- /// </summary>
- [TestMethod]
- public void DirectRequestsUsePost() {
- IDirectedProtocolMessage requestMessage = new Mocks.TestDirectedMessage(MessageTransport.Direct) {
- Recipient = new Uri("http://host"),
- Name = "Andrew",
- };
- HttpWebRequest httpRequest = this.accessor.CreateHttpRequest(requestMessage);
- Assert.AreEqual("POST", httpRequest.Method);
- StringAssert.Contains(this.webHandler.RequestEntityAsString, "Name=Andrew");
- }
-
- /// <summary>
- /// Verifies that direct response messages are encoded using Key Value Form.
- /// </summary>
- /// <remarks>
- /// The validity of the actual KVF encoding is not checked here. We assume that the KVF encoding
- /// class is verified elsewhere. We're only checking that the KVF class is being used by the
- /// <see cref="OpenIdChannel.SendDirectMessageResponse"/> method.
- /// </remarks>
- [TestMethod]
- public void DirectResponsesSentUsingKeyValueForm() {
- IProtocolMessage message = MessagingTestBase.GetStandardTestMessage(MessagingTestBase.FieldFill.AllRequired);
- MessageDictionary messageFields = new MessageDictionary(message);
- byte[] expectedBytes = KeyValueFormEncoding.GetBytes(messageFields);
- string expectedContentType = OpenIdChannel_Accessor.KeyValueFormContentType;
-
- UserAgentResponse directResponse = this.accessor.SendDirectMessageResponse(message);
- Assert.AreEqual(expectedContentType, directResponse.Headers[HttpResponseHeader.ContentType]);
- byte[] actualBytes = new byte[directResponse.ResponseStream.Length];
- directResponse.ResponseStream.Read(actualBytes, 0, actualBytes.Length);
- Assert.IsTrue(MessagingUtilities.AreEquivalent(expectedBytes, actualBytes));
- }
-
- /// <summary>
- /// Verifies that direct message responses are read in using the Key Value Form decoder.
- /// </summary>
- [TestMethod]
- public void DirectResponsesReceivedAsKeyValueForm() {
- var fields = new Dictionary<string, string> {
- { "var1", "value1" },
- { "var2", "value2" },
- };
- var response = new DirectWebResponse {
- ResponseStream = new MemoryStream(KeyValueFormEncoding.GetBytes(fields)),
- };
- Assert.IsTrue(MessagingUtilities.AreEquivalent(fields, this.accessor.ReadFromResponseInternal(response)));
- }
- }
-}
+//----------------------------------------------------------------------- +// <copyright file="OpenIdChannelTests.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.Test.OpenId.ChannelElements { + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Net; + using System.Text; + using DotNetOpenAuth.Messaging; + using DotNetOpenAuth.Messaging.Bindings; + using DotNetOpenAuth.Messaging.Reflection; + using DotNetOpenAuth.OpenId; + using DotNetOpenAuth.OpenId.ChannelElements; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class OpenIdChannelTests : TestBase { + private static readonly TimeSpan maximumMessageAge = TimeSpan.FromHours(3); // good for tests, too long for production + private OpenIdChannel channel; + private OpenIdChannel_Accessor accessor; + private Mocks.TestWebRequestHandler webHandler; + + [TestInitialize] + public void Setup() { + this.webHandler = new Mocks.TestWebRequestHandler(); + this.channel = new OpenIdChannel(new AssociationMemoryStore<Uri>(), new NonceMemoryStore(maximumMessageAge), new PrivateSecretMemoryStore()); + this.accessor = OpenIdChannel_Accessor.AttachShadow(this.channel); + this.channel.WebRequestHandler = this.webHandler; + } + + [TestMethod] + public void Ctor() { + // Verify that the channel stack includes the expected types. + // While other binding elements may be substituted for these, we'd then have + // to test them. Since we're not testing them in the OpenID battery of tests, + // we make sure they are the standard ones so that we trust they are tested + // elsewhere by the testing library. + var replayElement = (StandardReplayProtectionBindingElement)this.channel.BindingElements.SingleOrDefault(el => el is StandardReplayProtectionBindingElement); + Assert.IsTrue(this.channel.BindingElements.Any(el => el is StandardExpirationBindingElement)); + Assert.IsNotNull(replayElement); + + // Verify that empty nonces are allowed, since OpenID 2.0 allows this. + Assert.IsTrue(replayElement.AllowZeroLengthNonce); + } + + /// <summary> + /// Verifies that the channel sends direct message requests as HTTP POST requests. + /// </summary> + [TestMethod] + public void DirectRequestsUsePost() { + IDirectedProtocolMessage requestMessage = new Mocks.TestDirectedMessage(MessageTransport.Direct) { + Recipient = new Uri("http://host"), + Name = "Andrew", + }; + HttpWebRequest httpRequest = this.accessor.CreateHttpRequest(requestMessage); + Assert.AreEqual("POST", httpRequest.Method); + StringAssert.Contains(this.webHandler.RequestEntityAsString, "Name=Andrew"); + } + + /// <summary> + /// Verifies that direct response messages are encoded using Key Value Form. + /// </summary> + /// <remarks> + /// The validity of the actual KVF encoding is not checked here. We assume that the KVF encoding + /// class is verified elsewhere. We're only checking that the KVF class is being used by the + /// <see cref="OpenIdChannel.SendDirectMessageResponse"/> method. + /// </remarks> + [TestMethod] + public void DirectResponsesSentUsingKeyValueForm() { + IProtocolMessage message = MessagingTestBase.GetStandardTestMessage(MessagingTestBase.FieldFill.AllRequired); + MessageDictionary messageFields = new MessageDictionary(message); + byte[] expectedBytes = KeyValueFormEncoding.GetBytes(messageFields); + string expectedContentType = OpenIdChannel_Accessor.KeyValueFormContentType; + + UserAgentResponse directResponse = this.accessor.SendDirectMessageResponse(message); + Assert.AreEqual(expectedContentType, directResponse.Headers[HttpResponseHeader.ContentType]); + byte[] actualBytes = new byte[directResponse.ResponseStream.Length]; + directResponse.ResponseStream.Read(actualBytes, 0, actualBytes.Length); + Assert.IsTrue(MessagingUtilities.AreEquivalent(expectedBytes, actualBytes)); + } + + /// <summary> + /// Verifies that direct message responses are read in using the Key Value Form decoder. + /// </summary> + [TestMethod] + public void DirectResponsesReceivedAsKeyValueForm() { + var fields = new Dictionary<string, string> { + { "var1", "value1" }, + { "var2", "value2" }, + }; + var response = new DirectWebResponse { + ResponseStream = new MemoryStream(KeyValueFormEncoding.GetBytes(fields)), + }; + Assert.IsTrue(MessagingUtilities.AreEquivalent(fields, this.accessor.ReadFromResponseInternal(response))); + } + } +} |