summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-08-30 13:48:44 -0700
committerAndrew <andrewarnott@gmail.com>2008-09-01 11:02:44 -0700
commitd385d8d38fc971e75d841b7a55591a67828caf17 (patch)
tree24d674abfb6dfcb71f5a79de9f86af225162880d
parent5b33ddfca4d707afdd0a616940b7062d6d6e6276 (diff)
downloadDotNetOpenAuth-d385d8d38fc971e75d841b7a55591a67828caf17.zip
DotNetOpenAuth-d385d8d38fc971e75d841b7a55591a67828caf17.tar.gz
DotNetOpenAuth-d385d8d38fc971e75d841b7a55591a67828caf17.tar.bz2
Added test for and accomodated required message parts.
-rw-r--r--src/DotNetOAuth.Test/MessageSerializerTest.cs13
-rw-r--r--src/DotNetOAuth.Test/Mocks/TestMessage.cs2
-rw-r--r--src/DotNetOAuth/MessageScheme.cs6
-rw-r--r--src/DotNetOAuth/ProtocolMessageSerializer.cs10
-rw-r--r--src/DotNetOAuth/Strings.Designer.cs11
-rw-r--r--src/DotNetOAuth/Strings.resx3
6 files changed, 33 insertions, 12 deletions
diff --git a/src/DotNetOAuth.Test/MessageSerializerTest.cs b/src/DotNetOAuth.Test/MessageSerializerTest.cs
index e0ef39e..9faebfe 100644
--- a/src/DotNetOAuth.Test/MessageSerializerTest.cs
+++ b/src/DotNetOAuth.Test/MessageSerializerTest.cs
@@ -98,22 +98,19 @@ namespace DotNetOAuth.Test {
Assert.IsNull(actual.EmptyMember);
}
- [TestMethod()]
+ [TestMethod, ExpectedException(typeof(ProtocolException))]
public void DeserializeEmpty() {
var serializer = new ProtocolMessageSerializer<Mocks.TestMessage>();
- Dictionary<string, string> fields = new Dictionary<string, string>(StringComparer.Ordinal);
- var actual = serializer.Deserialize(fields);
- Assert.AreEqual(0, actual.Age);
- Assert.IsNull(actual.Name);
- Assert.IsNull(actual.EmptyMember);
+ var fields = new Dictionary<string, string>(StringComparer.Ordinal);
+ serializer.Deserialize(fields);
}
[TestMethod, ExpectedException(typeof(ProtocolException))]
public void DeserializeInvalidMessage() {
var serializer = new ProtocolMessageSerializer<Mocks.TestMessage>();
Dictionary<string, string> fields = new Dictionary<string, string>(StringComparer.Ordinal);
- // Put in a value where the field should be empty.
- fields["EmptyMember"] = "15";
+ // Set an disallowed value.
+ fields["age"] = "-1";
serializer.Deserialize(fields);
}
}
diff --git a/src/DotNetOAuth.Test/Mocks/TestMessage.cs b/src/DotNetOAuth.Test/Mocks/TestMessage.cs
index 4f27b5b..fb9a30c 100644
--- a/src/DotNetOAuth.Test/Mocks/TestMessage.cs
+++ b/src/DotNetOAuth.Test/Mocks/TestMessage.cs
@@ -4,7 +4,7 @@ using System;
namespace DotNetOAuth.Test.Mocks {
[DataContract(Namespace = Protocol.DataContractNamespace)]
class TestMessage : IProtocolMessage {
- [DataMember(Name = "age")]
+ [DataMember(Name = "age", IsRequired = true)]
public int Age { get; set; }
[DataMember]
public string Name { get; set; }
diff --git a/src/DotNetOAuth/MessageScheme.cs b/src/DotNetOAuth/MessageScheme.cs
index 8878f40..ab42f28 100644
--- a/src/DotNetOAuth/MessageScheme.cs
+++ b/src/DotNetOAuth/MessageScheme.cs
@@ -3,6 +3,12 @@ using System.Collections.Generic;
using System.Text;
namespace DotNetOAuth {
+ /// <summary>
+ /// The methods available for the Consumer to send messages to the Service Provider.
+ /// </summary>
+ /// <remarks>
+ /// See 1.0 spec section 5.2.
+ /// </remarks>
internal enum MessageScheme {
/// <summary>
/// In the HTTP Authorization header as defined in OAuth HTTP Authorization Scheme (OAuth HTTP Authorization Scheme).
diff --git a/src/DotNetOAuth/ProtocolMessageSerializer.cs b/src/DotNetOAuth/ProtocolMessageSerializer.cs
index a9c92bc..b44aec6 100644
--- a/src/DotNetOAuth/ProtocolMessageSerializer.cs
+++ b/src/DotNetOAuth/ProtocolMessageSerializer.cs
@@ -23,7 +23,7 @@ namespace DotNetOAuth {
internal IDictionary<string, string> Serialize(T message) {
if (message == null) throw new ArgumentNullException("message");
- var fields = new Dictionary<string, string>();
+ var fields = new Dictionary<string, string>(StringComparer.Ordinal);
Serialize(fields, message);
return fields;
}
@@ -46,7 +46,13 @@ namespace DotNetOAuth {
if (fields == null) throw new ArgumentNullException("fields");
var reader = DictionaryXmlReader.Create(rootElement, fields);
- T result = (T)serializer.ReadObject(reader, false);
+ T result;
+ try {
+ result = (T)serializer.ReadObject(reader, false);
+ } catch (SerializationException ex) {
+ // Missing required fields is one cause of this exception.
+ throw new ProtocolException(Strings.InvalidIncomingMessage, ex);
+ }
result.EnsureValidMessage();
return result;
}
diff --git a/src/DotNetOAuth/Strings.Designer.cs b/src/DotNetOAuth/Strings.Designer.cs
index 4679c2c..05bbbc8 100644
--- a/src/DotNetOAuth/Strings.Designer.cs
+++ b/src/DotNetOAuth/Strings.Designer.cs
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
-// Runtime Version:2.0.50727.1434
+// Runtime Version:2.0.50727.3053
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -61,6 +61,15 @@ namespace DotNetOAuth {
}
/// <summary>
+ /// Looks up a localized string similar to An invalid OAuth message received and discarded..
+ /// </summary>
+ internal static string InvalidIncomingMessage {
+ get {
+ return ResourceManager.GetString("InvalidIncomingMessage", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to The request URL query MUST NOT contain any OAuth Protocol Parameters..
/// </summary>
internal static string RequestUrlMustNotHaveOAuthParameters {
diff --git a/src/DotNetOAuth/Strings.resx b/src/DotNetOAuth/Strings.resx
index 52b5577..6c687d9 100644
--- a/src/DotNetOAuth/Strings.resx
+++ b/src/DotNetOAuth/Strings.resx
@@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
+ <data name="InvalidIncomingMessage" xml:space="preserve">
+ <value>An invalid OAuth message received and discarded.</value>
+ </data>
<data name="RequestUrlMustNotHaveOAuthParameters" xml:space="preserve">
<value>The request URL query MUST NOT contain any OAuth Protocol Parameters.</value>
</data>