diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/DotNetOAuth.Test/DotNetOAuth.Test.csproj | 1 | ||||
-rw-r--r-- | src/DotNetOAuth.Test/Messaging/ChannelTests.cs | 123 | ||||
-rw-r--r-- | src/DotNetOAuth.Test/Messaging/HttpRequestInfoTests.cs | 36 | ||||
-rw-r--r-- | src/DotNetOAuth.Test/Messaging/ResponseTest.cs | 22 | ||||
-rw-r--r-- | src/DotNetOAuth.Test/Mocks/TestBadChannel.cs | 28 | ||||
-rw-r--r-- | src/DotNetOAuth.Test/Mocks/TestMessage.cs | 11 | ||||
-rw-r--r-- | src/DotNetOAuth/Messaging/Channel.cs | 30 | ||||
-rw-r--r-- | src/DotNetOAuth/Messaging/DictionaryXmlReader.cs | 17 | ||||
-rw-r--r-- | src/DotNetOAuth/Messaging/HttpRequestInfo.cs | 5 | ||||
-rw-r--r-- | src/DotNetOAuth/Messaging/MessageSerializer.cs | 6 | ||||
-rw-r--r-- | src/DotNetOAuth/Messaging/MessagingStrings.Designer.cs | 18 | ||||
-rw-r--r-- | src/DotNetOAuth/Messaging/MessagingStrings.resx | 6 | ||||
-rw-r--r-- | src/DotNetOAuth/Messaging/Response.cs | 16 | ||||
-rw-r--r-- | src/DotNetOAuth/OAuthChannel.cs | 2 |
14 files changed, 277 insertions, 44 deletions
diff --git a/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj b/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj index 8f28791..e7e334c 100644 --- a/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj +++ b/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj @@ -61,6 +61,7 @@ <Compile Include="MessagingUtilitiesTest.cs" />
<Compile Include="Messaging\ChannelTests.cs" />
<Compile Include="Messaging\DictionaryXmlReaderTests.cs" />
+ <Compile Include="Messaging\HttpRequestInfoTests.cs" />
<Compile Include="Mocks\TestDirectedMessage.cs" />
<Compile Include="Mocks\TestBadChannel.cs" />
<Compile Include="OAuthChannelTests.cs" />
diff --git a/src/DotNetOAuth.Test/Messaging/ChannelTests.cs b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs index 26155cb..dc433cf 100644 --- a/src/DotNetOAuth.Test/Messaging/ChannelTests.cs +++ b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs @@ -30,7 +30,7 @@ namespace DotNetOAuth.Test.Messaging { public void CtorNull() {
// This bad channel is deliberately constructed to pass null to
// its protected base class' constructor.
- new TestBadChannel();
+ new TestBadChannel(true);
}
[TestMethod]
@@ -53,6 +53,24 @@ namespace DotNetOAuth.Test.Messaging { this.channel.Send(null);
}
+ [TestMethod, ExpectedException(typeof(ArgumentException))]
+ public void SendIndirectedUndirectedMessage() {
+ IProtocolMessage message = new TestMessage(MessageTransport.Indirect);
+ this.channel.Send(message);
+ }
+
+ [TestMethod, ExpectedException(typeof(ArgumentException))]
+ public void SendDirectedNoRecipientMessage() {
+ IProtocolMessage message = new TestDirectedMessage(MessageTransport.Indirect);
+ this.channel.Send(message);
+ }
+
+ [TestMethod, ExpectedException(typeof(ArgumentException))]
+ public void SendInvalidMessageTransport() {
+ IProtocolMessage message = new TestDirectedMessage((MessageTransport)100);
+ this.channel.Send(message);
+ }
+
[TestMethod]
public void SendIndirectMessage301Get() {
IProtocolMessage message = new TestDirectedMessage(MessageTransport.Indirect) {
@@ -70,6 +88,27 @@ namespace DotNetOAuth.Test.Messaging { StringAssert.Contains(response.Headers[HttpResponseHeader.Location], "Location=http%3a%2f%2fhost%2fpath");
}
+ [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ public void SendIndirectMessage301GetNullMessage() {
+ TestBadChannel badChannel = new TestBadChannel(false);
+ badChannel.Create301RedirectResponse(null, new Dictionary<string, string>());
+ }
+
+ [TestMethod, ExpectedException(typeof(ArgumentException))]
+ public void SendIndirectMessage301GetEmptyRecipient() {
+ TestBadChannel badChannel = new TestBadChannel(false);
+ var message = new TestDirectedMessage(MessageTransport.Indirect);
+ badChannel.Create301RedirectResponse(message, new Dictionary<string, string>());
+ }
+
+ [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ public void SendIndirectMessage301GetNullFields() {
+ TestBadChannel badChannel = new TestBadChannel(false);
+ var message = new TestDirectedMessage(MessageTransport.Indirect);
+ message.Recipient = new Uri("http://someserver");
+ badChannel.Create301RedirectResponse(message, null);
+ }
+
[TestMethod]
public void SendIndirectMessageFormPost() {
// We craft a very large message to force fallback to form POST.
@@ -85,7 +124,7 @@ namespace DotNetOAuth.Test.Messaging { Response response = this.channel.DequeueIndirectOrResponseMessage();
Assert.AreEqual(HttpStatusCode.OK, response.Status, "A form redirect should be an HTTP successful response.");
Assert.IsNull(response.Headers[HttpResponseHeader.Location], "There should not be a redirection header in the response.");
- string body = Encoding.UTF8.GetString(response.Body);
+ string body = response.Body;
StringAssert.Contains(body, "<form ");
StringAssert.Contains(body, "action=\"http://provider/path\"");
StringAssert.Contains(body, "method=\"post\"");
@@ -95,6 +134,27 @@ namespace DotNetOAuth.Test.Messaging { StringAssert.Contains(body, ".submit()", "There should be some javascript to automate form submission.");
}
+ [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ public void SendIndirectMessageFormPostNullMessage() {
+ TestBadChannel badChannel = new TestBadChannel(false);
+ badChannel.CreateFormPostResponse(null, new Dictionary<string, string>());
+ }
+
+ [TestMethod, ExpectedException(typeof(ArgumentException))]
+ public void SendIndirectMessageFormPostEmptyRecipient() {
+ TestBadChannel badChannel = new TestBadChannel(false);
+ var message = new TestDirectedMessage(MessageTransport.Indirect);
+ badChannel.CreateFormPostResponse(message, new Dictionary<string, string>());
+ }
+
+ [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ public void SendIndirectMessageFormPostNullFields() {
+ TestBadChannel badChannel = new TestBadChannel(false);
+ var message = new TestDirectedMessage(MessageTransport.Indirect);
+ message.Recipient = new Uri("http://someserver");
+ badChannel.CreateFormPostResponse(message, null);
+ }
+
/// <summary>
/// Tests that a direct message is sent when the appropriate message type is provided.
/// </summary>
@@ -112,7 +172,62 @@ namespace DotNetOAuth.Test.Messaging { this.channel.Send(message);
}
- private static HttpRequestInfo CreateHttpRequest(string method, IDictionary<string, string> fields) {
+ [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ public void QueueIndirectOrResponseMessageNull() {
+ TestBadChannel badChannel = new TestBadChannel(false);
+ badChannel.QueueIndirectOrResponseMessage(null);
+ }
+
+ [TestMethod, ExpectedException(typeof(InvalidOperationException))]
+ public void QueueIndirectOrResponseMessageTwice() {
+ TestBadChannel badChannel = new TestBadChannel(false);
+ Response response = new Response();
+ badChannel.QueueIndirectOrResponseMessage(new Response());
+ badChannel.QueueIndirectOrResponseMessage(new Response());
+ }
+
+ [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ public void SendIndirectMessageNull() {
+ TestBadChannel badChannel = new TestBadChannel(false);
+ badChannel.SendIndirectMessage(null);
+ }
+
+ [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ public void ReceiveNull() {
+ TestBadChannel badChannel = new TestBadChannel(false);
+ badChannel.Receive(null);
+ }
+
+ [TestMethod]
+ public void ReceiveUnrecognizedMessage() {
+ TestBadChannel badChannel = new TestBadChannel(false);
+ Assert.IsNull(badChannel.Receive(new Dictionary<string, string>()));
+ }
+
+ [TestMethod]
+ public void ReadFromRequestWithContext() {
+ // TODO: make this a request with a message in it.
+ HttpRequest request = new HttpRequest("somefile", "http://someurl", "age=15");
+ HttpContext.Current = new HttpContext(request, new HttpResponse(new StringWriter()));
+ IProtocolMessage message = this.channel.ReadFromRequest();
+ Assert.IsNotNull(message);
+ Assert.IsInstanceOfType(message, typeof(TestMessage));
+ Assert.AreEqual(15, ((TestMessage)message).Age);
+ }
+
+ [TestMethod, ExpectedException(typeof(InvalidOperationException))]
+ public void ReadFromRequestNoContext() {
+ TestBadChannel badChannel = new TestBadChannel(false);
+ badChannel.ReadFromRequest();
+ }
+
+ [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ public void ReadFromRequestNull() {
+ TestBadChannel badChannel = new TestBadChannel(false);
+ badChannel.ReadFromRequest(null);
+ }
+
+ private static HttpRequestInfo CreateHttpRequestInfo(string method, IDictionary<string, string> fields) {
string query = MessagingUtilities.CreateQueryString(fields);
UriBuilder requestUri = new UriBuilder("http://localhost/path");
WebHeaderCollection headers = new WebHeaderCollection();
@@ -144,7 +259,7 @@ namespace DotNetOAuth.Test.Messaging { { "Name", "Andrew" },
{ "Location", "http://hostb/pathB" },
};
- IProtocolMessage requestMessage = this.channel.ReadFromRequest(CreateHttpRequest(method, fields));
+ IProtocolMessage requestMessage = this.channel.ReadFromRequest(CreateHttpRequestInfo(method, fields));
Assert.IsNotNull(requestMessage);
Assert.IsInstanceOfType(requestMessage, typeof(TestMessage));
TestMessage testMessage = (TestMessage)requestMessage;
diff --git a/src/DotNetOAuth.Test/Messaging/HttpRequestInfoTests.cs b/src/DotNetOAuth.Test/Messaging/HttpRequestInfoTests.cs new file mode 100644 index 0000000..108a147 --- /dev/null +++ b/src/DotNetOAuth.Test/Messaging/HttpRequestInfoTests.cs @@ -0,0 +1,36 @@ +//-----------------------------------------------------------------------
+// <copyright file="HttpRequestInfoTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+using System.Web;
+using DotNetOAuth.Messaging;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace DotNetOAuth.Test.Messaging {
+ [TestClass]
+ public class HttpRequestInfoTests : TestBase {
+ [TestMethod]
+ public void CtorRequest() {
+ HttpRequest request = new HttpRequest("file", "http://someserver?a=b", "a=b");
+ //request.Headers["headername"] = "headervalue"; // PlatformNotSupportedException prevents us mocking this up
+ HttpRequestInfo info = new HttpRequestInfo(request);
+ Assert.AreEqual(request.Headers["headername"], info.Headers["headername"]);
+ Assert.AreEqual(request.Url.Query, info.Query);
+ Assert.AreEqual(request.QueryString["a"], info.QueryString["a"]);
+ Assert.AreEqual(request.Url, info.Url);
+ Assert.AreEqual(request.HttpMethod, info.HttpMethod);
+ }
+
+ /// <summary>
+ /// Checks that a property dependent on another null property
+ /// doesn't generate a NullReferenceException.
+ /// </summary>
+ [TestMethod]
+ public void QueryBeforeSettingUrl() {
+ HttpRequestInfo info = new HttpRequestInfo();
+ Assert.IsNull(info.Query);
+ }
+ }
+}
diff --git a/src/DotNetOAuth.Test/Messaging/ResponseTest.cs b/src/DotNetOAuth.Test/Messaging/ResponseTest.cs index c1c7dff..6b49e62 100644 --- a/src/DotNetOAuth.Test/Messaging/ResponseTest.cs +++ b/src/DotNetOAuth.Test/Messaging/ResponseTest.cs @@ -8,6 +8,10 @@ namespace DotNetOAuth.Test.Messaging { using System;
using DotNetOAuth.Messaging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
+ using System.Web;
+ using System.IO;
+ using System.Threading;
+ using System.Text;
[TestClass]
public class ResponseTest : TestBase {
@@ -15,5 +19,23 @@ namespace DotNetOAuth.Test.Messaging { public void SendWithoutAspNetContext() {
new Response().Send();
}
+
+ [TestMethod]
+ public void Send() {
+ StringWriter writer = new StringWriter();
+ HttpRequest httpRequest = new HttpRequest("file", "http://server", "");
+ HttpResponse httpResponse = new HttpResponse(writer);
+ HttpContext context = new HttpContext(httpRequest, httpResponse);
+ HttpContext.Current = context;
+
+ Response response = new Response();
+ response.Status = System.Net.HttpStatusCode.OK;
+ response.Headers["someHeaderName"] = "someHeaderValue";
+ response.Body = "some body";
+ response.Send();
+ string results = writer.ToString();
+ // For some reason the only output in test is the body... the headers require a web host
+ Assert.AreEqual(response.Body, results);
+ }
}
}
diff --git a/src/DotNetOAuth.Test/Mocks/TestBadChannel.cs b/src/DotNetOAuth.Test/Mocks/TestBadChannel.cs index 4c06980..5d6802f 100644 --- a/src/DotNetOAuth.Test/Mocks/TestBadChannel.cs +++ b/src/DotNetOAuth.Test/Mocks/TestBadChannel.cs @@ -15,8 +15,32 @@ namespace DotNetOAuth.Test.Mocks { /// A Channel derived type that passes null to the protected constructor.
/// </summary>
internal class TestBadChannel : Channel {
- internal TestBadChannel()
- : base(null) {
+ internal TestBadChannel(bool badConstructorParam)
+ : base(badConstructorParam ? null : new TestMessageTypeProvider()) {
+ }
+
+ internal new void Create301RedirectResponse(IDirectedProtocolMessage message, IDictionary<string, string> fields) {
+ base.Create301RedirectResponse(message, fields);
+ }
+
+ internal new void CreateFormPostResponse(IDirectedProtocolMessage message, IDictionary<string, string> fields) {
+ base.CreateFormPostResponse(message, fields);
+ }
+
+ internal new void QueueIndirectOrResponseMessage(Response response) {
+ base.QueueIndirectOrResponseMessage(response);
+ }
+
+ internal new void SendIndirectMessage(IDirectedProtocolMessage message) {
+ base.SendIndirectMessage(message);
+ }
+
+ internal new IProtocolMessage Receive(Dictionary<string, string> fields) {
+ return base.Receive(fields);
+ }
+
+ internal new IProtocolMessage ReadFromRequest(HttpRequestInfo request) {
+ return base.ReadFromRequest(request);
}
protected internal override IProtocolMessage Request(IDirectedProtocolMessage request) {
diff --git a/src/DotNetOAuth.Test/Mocks/TestMessage.cs b/src/DotNetOAuth.Test/Mocks/TestMessage.cs index 8c47717..6f654ea 100644 --- a/src/DotNetOAuth.Test/Mocks/TestMessage.cs +++ b/src/DotNetOAuth.Test/Mocks/TestMessage.cs @@ -11,6 +11,15 @@ namespace DotNetOAuth.Test.Mocks { [DataContract(Namespace = Protocol.DataContractNamespaceV10)]
internal class TestMessage : IProtocolMessage {
+ private MessageTransport transport;
+
+ internal TestMessage() : this(MessageTransport.Direct) {
+ }
+
+ internal TestMessage(MessageTransport transport) {
+ this.transport = transport;
+ }
+
[DataMember(Name = "age", IsRequired = true)]
public int Age { get; set; }
[DataMember]
@@ -27,7 +36,7 @@ namespace DotNetOAuth.Test.Mocks { }
MessageTransport IProtocolMessage.Transport {
- get { return MessageTransport.Direct; }
+ get { return transport; }
}
void IProtocolMessage.EnsureValidMessage() {
diff --git a/src/DotNetOAuth/Messaging/Channel.cs b/src/DotNetOAuth/Messaging/Channel.cs index 2ab3636..f674f12 100644 --- a/src/DotNetOAuth/Messaging/Channel.cs +++ b/src/DotNetOAuth/Messaging/Channel.cs @@ -120,8 +120,9 @@ namespace DotNetOAuth.Messaging { this.SendIndirectMessage(directedMessage);
break;
default:
- Debug.Fail("Unrecogized MessageTransport value.");
- throw new ArgumentException();
+ throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
+ MessagingStrings.UnrecognizedEnumValue, "Transport", message.Transport),
+ "message");
}
}
@@ -132,7 +133,12 @@ namespace DotNetOAuth.Messaging { /// <remarks>
/// Requires an HttpContext.Current context.
/// </remarks>
+ /// <exception cref="InvalidOperationException">Thrown when <see cref="HttpContext.Current"/> is null.</exception>
internal IProtocolMessage ReadFromRequest() {
+ if (HttpContext.Current == null) {
+ throw new InvalidOperationException(MessagingStrings.HttpContextRequired);
+ }
+
return this.ReadFromRequest(new HttpRequestInfo(HttpContext.Current.Request));
}
@@ -173,13 +179,14 @@ namespace DotNetOAuth.Messaging { /// Deserializes a dictionary of values into a message.
/// </summary>
/// <param name="fields">The dictionary of values that were read from an HTTP request or response.</param>
- /// <returns>The deserialized message.</returns>
+ /// <returns>The deserialized message, or null if no message could be recognized in the provided data.</returns>
protected virtual IProtocolMessage Receive(Dictionary<string, string> fields) {
- Type messageType = null;
- if (fields != null) {
- messageType = this.MessageTypeProvider.GetRequestMessageType(fields);
+ if (fields == null) {
+ throw new ArgumentNullException("fields");
}
+ Type messageType = this.MessageTypeProvider.GetRequestMessageType(fields);
+
// If there was no data, or we couldn't recognize it as a message, abort.
if (messageType == null) {
return null;
@@ -255,7 +262,7 @@ namespace DotNetOAuth.Messaging { Response response = new Response {
Status = HttpStatusCode.Redirect,
Headers = headers,
- Body = new byte[0],
+ Body = null,
OriginalMessage = message
};
@@ -281,8 +288,7 @@ namespace DotNetOAuth.Messaging { }
WebHeaderCollection headers = new WebHeaderCollection();
- MemoryStream body = new MemoryStream();
- StreamWriter bodyWriter = new StreamWriter(body);
+ StringWriter bodyWriter = new StringWriter();
StringBuilder hiddenFields = new StringBuilder();
foreach (var field in fields) {
hiddenFields.AppendFormat(
@@ -298,7 +304,7 @@ namespace DotNetOAuth.Messaging { Response response = new Response {
Status = HttpStatusCode.OK,
Headers = headers,
- Body = body.ToArray(),
+ Body = bodyWriter.ToString(),
OriginalMessage = message
};
@@ -322,9 +328,7 @@ namespace DotNetOAuth.Messaging { /// <param name="fields">The fields that would be included in a message.</param>
/// <returns>The size (in bytes) of the message payload.</returns>
private static int CalculateSizeOfPayload(IDictionary<string, string> fields) {
- if (fields == null) {
- throw new ArgumentNullException("fields");
- }
+ Debug.Assert(fields != null, "fields == null");
int size = 0;
foreach (var field in fields) {
diff --git a/src/DotNetOAuth/Messaging/DictionaryXmlReader.cs b/src/DotNetOAuth/Messaging/DictionaryXmlReader.cs index 7a5dc21..6ecc41e 100644 --- a/src/DotNetOAuth/Messaging/DictionaryXmlReader.cs +++ b/src/DotNetOAuth/Messaging/DictionaryXmlReader.cs @@ -41,9 +41,8 @@ namespace DotNetOAuth.Messaging { /// <param name="fields">The dictionary to list values from.</param>
/// <returns>The generated <see cref="XmlReader"/>.</returns>
private static XmlReader CreateRoundtripReader(XName rootElement, IDictionary<string, string> fields) {
- if (rootElement == null) {
- throw new ArgumentNullException("rootElement");
- }
+ Debug.Assert(rootElement != null, "rootElement == null");
+ Debug.Assert(fields != null, "fields == null");
MemoryStream stream = new MemoryStream();
XmlWriter writer = XmlWriter.Create(stream);
@@ -66,15 +65,9 @@ namespace DotNetOAuth.Messaging { /// <param name="rootElement">The name of the root element to use to surround the dictionary values.</param>
/// <param name="fields">The dictionary with values to serialize.</param>
private static void SerializeDictionaryToXml(XmlWriter writer, XName rootElement, IDictionary<string, string> fields) {
- if (writer == null) {
- throw new ArgumentNullException("writer");
- }
- if (rootElement == null) {
- throw new ArgumentNullException("rootElement");
- }
- if (fields == null) {
- throw new ArgumentNullException("fields");
- }
+ Debug.Assert(writer != null, "writer == null");
+ Debug.Assert(rootElement != null, "rootElement == null");
+ Debug.Assert(fields != null, "fields == null");
writer.WriteStartElement(rootElement.LocalName, rootElement.NamespaceName);
diff --git a/src/DotNetOAuth/Messaging/HttpRequestInfo.cs b/src/DotNetOAuth/Messaging/HttpRequestInfo.cs index 3654367..e4aabb8 100644 --- a/src/DotNetOAuth/Messaging/HttpRequestInfo.cs +++ b/src/DotNetOAuth/Messaging/HttpRequestInfo.cs @@ -10,6 +10,7 @@ namespace DotNetOAuth.Messaging { using System.IO;
using System.Net;
using System.Web;
+ using System.Diagnostics;
/// <summary>
/// A property store of details of an incoming HTTP request.
@@ -122,9 +123,7 @@ namespace DotNetOAuth.Messaging { /// <param name="pairs">The collection a HTTP headers.</param>
/// <returns>A new collection of the given headers.</returns>
private static WebHeaderCollection GetHeaderCollection(NameValueCollection pairs) {
- if (pairs == null) {
- throw new ArgumentNullException("pairs");
- }
+ Debug.Assert(pairs != null, "pairs == null");
WebHeaderCollection headers = new WebHeaderCollection();
foreach (string key in pairs) {
diff --git a/src/DotNetOAuth/Messaging/MessageSerializer.cs b/src/DotNetOAuth/Messaging/MessageSerializer.cs index ac40232..5a39a61 100644 --- a/src/DotNetOAuth/Messaging/MessageSerializer.cs +++ b/src/DotNetOAuth/Messaging/MessageSerializer.cs @@ -12,6 +12,7 @@ namespace DotNetOAuth.Messaging { using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Linq;
+ using System.Diagnostics;
/// <summary>
/// Serializes/deserializes OAuth messages for/from transit.
@@ -46,9 +47,8 @@ namespace DotNetOAuth.Messaging { /// <param name="messageType">The specific <see cref="IProtocolMessage"/>-derived type
/// that will be serialized and deserialized using this class.</param>
private MessageSerializer(Type messageType) {
- if (messageType == null) {
- throw new ArgumentNullException("messageType");
- }
+ Debug.Assert(messageType != null, "messageType == null");
+
if (!typeof(IProtocolMessage).IsAssignableFrom(messageType)) {
throw new ArgumentException(
string.Format(
diff --git a/src/DotNetOAuth/Messaging/MessagingStrings.Designer.cs b/src/DotNetOAuth/Messaging/MessagingStrings.Designer.cs index cf722bd..0de92f6 100644 --- a/src/DotNetOAuth/Messaging/MessagingStrings.Designer.cs +++ b/src/DotNetOAuth/Messaging/MessagingStrings.Designer.cs @@ -97,6 +97,15 @@ namespace DotNetOAuth.Messaging { }
/// <summary>
+ /// Looks up a localized string similar to This method requires a current HttpContext. Alternatively, use an overload of this method that allows you to pass in information without an HttpContext..
+ /// </summary>
+ internal static string HttpContextRequired {
+ get {
+ return ResourceManager.GetString("HttpContextRequired", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Messages that indicate indirect transport must implement the {0} interface..
/// </summary>
internal static string IndirectMessagesMustImplementIDirectedProtocolMessage {
@@ -122,5 +131,14 @@ namespace DotNetOAuth.Messaging { return ResourceManager.GetString("UnexpectedType", resourceCulture);
}
}
+
+ /// <summary>
+ /// Looks up a localized string similar to {0} property has unrecognized value {1}..
+ /// </summary>
+ internal static string UnrecognizedEnumValue {
+ get {
+ return ResourceManager.GetString("UnrecognizedEnumValue", resourceCulture);
+ }
+ }
}
}
diff --git a/src/DotNetOAuth/Messaging/MessagingStrings.resx b/src/DotNetOAuth/Messaging/MessagingStrings.resx index abc913b..2ac776a 100644 --- a/src/DotNetOAuth/Messaging/MessagingStrings.resx +++ b/src/DotNetOAuth/Messaging/MessagingStrings.resx @@ -129,6 +129,9 @@ <data name="ExceptionNotConstructedForTransit" xml:space="preserve">
<value>This exception was not constructed with a root request message that caused it.</value>
</data>
+ <data name="HttpContextRequired" xml:space="preserve">
+ <value>This method requires a current HttpContext. Alternatively, use an overload of this method that allows you to pass in information without an HttpContext.</value>
+ </data>
<data name="IndirectMessagesMustImplementIDirectedProtocolMessage" xml:space="preserve">
<value>Messages that indicate indirect transport must implement the {0} interface.</value>
</data>
@@ -138,4 +141,7 @@ <data name="UnexpectedType" xml:space="preserve">
<value>The type {0} or a derived type was expected, but {1} was given.</value>
</data>
+ <data name="UnrecognizedEnumValue" xml:space="preserve">
+ <value>{0} property has unrecognized value {1}.</value>
+ </data>
</root>
\ No newline at end of file diff --git a/src/DotNetOAuth/Messaging/Response.cs b/src/DotNetOAuth/Messaging/Response.cs index 68950ff..6413e68 100644 --- a/src/DotNetOAuth/Messaging/Response.cs +++ b/src/DotNetOAuth/Messaging/Response.cs @@ -25,6 +25,14 @@ namespace DotNetOAuth.Messaging { /// </remarks>
public class Response {
/// <summary>
+ /// Initializes an instance of the <see cref="Response"/> class.
+ /// </summary>
+ internal Response() {
+ Status = HttpStatusCode.OK;
+ Headers = new WebHeaderCollection();
+ }
+
+ /// <summary>
/// Gets the headers that must be included in the response to the user agent.
/// </summary>
/// <remarks>
@@ -37,7 +45,7 @@ namespace DotNetOAuth.Messaging { /// <summary>
/// Gets the body of the HTTP response.
/// </summary>
- public byte[] Body { get; internal set; }
+ public string Body { get; internal set; }
/// <summary>
/// Gets the HTTP status code to use in the HTTP response.
@@ -62,11 +70,9 @@ namespace DotNetOAuth.Messaging { HttpContext.Current.Response.Clear();
HttpContext.Current.Response.StatusCode = (int)this.Status;
MessagingUtilities.ApplyHeadersToResponse(this.Headers, HttpContext.Current.Response);
- if (this.Body != null && this.Body.Length > 0) {
- HttpContext.Current.Response.OutputStream.Write(this.Body, 0, this.Body.Length);
- HttpContext.Current.Response.OutputStream.Flush();
+ if (this.Body != null) {
+ HttpContext.Current.Response.Output.Write(Body);
}
- HttpContext.Current.Response.OutputStream.Close();
HttpContext.Current.Response.End();
}
}
diff --git a/src/DotNetOAuth/OAuthChannel.cs b/src/DotNetOAuth/OAuthChannel.cs index 4014ecf..aceaa42 100644 --- a/src/DotNetOAuth/OAuthChannel.cs +++ b/src/DotNetOAuth/OAuthChannel.cs @@ -143,7 +143,7 @@ namespace DotNetOAuth { string responseBody = MessagingUtilities.CreateQueryString(fields);
Response encodedResponse = new Response {
- Body = Encoding.UTF8.GetBytes(responseBody),
+ Body = responseBody,
OriginalMessage = response,
Status = System.Net.HttpStatusCode.OK,
Headers = new System.Net.WebHeaderCollection(),
|