summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.Test')
-rw-r--r--src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj2
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/InMemoryTokenManager.cs59
-rw-r--r--src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs10
-rw-r--r--src/DotNetOpenAuth.Test/OAuth/ChannelElements/PlaintextSigningBindingElementTest.cs14
-rw-r--r--src/DotNetOpenAuth.Test/OAuth/ChannelElements/SigningBindingElementBaseTests.cs3
-rw-r--r--src/DotNetOpenAuth.Test/OAuth/ChannelElements/UriOrOobEncodingTests.cs68
-rw-r--r--src/DotNetOpenAuth.Test/OAuth/ProtocolTests.cs6
-rw-r--r--src/DotNetOpenAuth.Test/OAuth/ServiceProviderTests.cs38
8 files changed, 173 insertions, 27 deletions
diff --git a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
index 591c442..231d92d 100644
--- a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
+++ b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
@@ -167,9 +167,11 @@
<Compile Include="OAuth\ChannelElements\OAuthChannelTests.cs" />
<Compile Include="OAuth\ChannelElements\PlaintextSigningBindingElementTest.cs" />
<Compile Include="OAuth\ChannelElements\SigningBindingElementBaseTests.cs" />
+ <Compile Include="OAuth\ChannelElements\UriOrOobEncodingTests.cs" />
<Compile Include="OAuth\ConsumerDescription.cs" />
<Compile Include="OAuth\ProtocolTests.cs" />
<Compile Include="OAuth\ServiceProviderDescriptionTests.cs" />
+ <Compile Include="OAuth\ServiceProviderTests.cs" />
<Compile Include="OpenId\AssociationsTests.cs" />
<Compile Include="OpenId\AssociationTests.cs" />
<Compile Include="OpenId\AuthenticationTests.cs" />
diff --git a/src/DotNetOpenAuth.Test/Mocks/InMemoryTokenManager.cs b/src/DotNetOpenAuth.Test/Mocks/InMemoryTokenManager.cs
index be3c563..5585107 100644
--- a/src/DotNetOpenAuth.Test/Mocks/InMemoryTokenManager.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/InMemoryTokenManager.cs
@@ -9,12 +9,13 @@ namespace DotNetOpenAuth.Test.Mocks {
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
+ using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages;
internal class InMemoryTokenManager : IConsumerTokenManager, IServiceProviderTokenManager {
- private Dictionary<string, string> consumersAndSecrets = new Dictionary<string, string>();
- private Dictionary<string, string> tokensAndSecrets = new Dictionary<string, string>();
+ private KeyedCollectionDelegate<string, ConsumerInfo> consumers = new KeyedCollectionDelegate<string, ConsumerInfo>(c => c.Key);
+ private KeyedCollectionDelegate<string, TokenInfo> tokens = new KeyedCollectionDelegate<string, TokenInfo>(t => t.Token);
/// <summary>
/// Request tokens that have been issued, and whether they have been authorized yet.
@@ -29,11 +30,11 @@ namespace DotNetOpenAuth.Test.Mocks {
#region IConsumerTokenManager Members
public string ConsumerKey {
- get { return this.consumersAndSecrets.Keys.Single(); }
+ get { return this.consumers.Single().Key; }
}
public string ConsumerSecret {
- get { return this.consumersAndSecrets.Values.Single(); }
+ get { return this.consumers.Single().Secret; }
}
#endregion
@@ -41,11 +42,11 @@ namespace DotNetOpenAuth.Test.Mocks {
#region ITokenManager Members
public string GetTokenSecret(string token) {
- return this.tokensAndSecrets[token];
+ return this.tokens[token].Secret;
}
public void StoreNewRequestToken(UnauthorizedTokenRequest request, ITokenSecretContainingMessage response) {
- this.tokensAndSecrets[response.Token] = response.TokenSecret;
+ this.tokens.Add(new TokenInfo { ConsumerKey = request.ConsumerKey, Token = response.Token, Secret = response.TokenSecret });
this.requestTokens.Add(response.Token, false);
}
@@ -70,8 +71,8 @@ namespace DotNetOpenAuth.Test.Mocks {
////Debug.Assert(this.requestTokens[requestToken], "Unauthorized token should not be exchanged for access token.");
this.requestTokens.Remove(requestToken);
this.accessTokens.Add(accessToken);
- this.tokensAndSecrets.Remove(requestToken);
- this.tokensAndSecrets[accessToken] = accessTokenSecret;
+ this.tokens.Remove(requestToken);
+ this.tokens.Add(new TokenInfo { Token = accessToken, Secret = accessTokenSecret });
}
/// <summary>
@@ -93,8 +94,12 @@ namespace DotNetOpenAuth.Test.Mocks {
#region IServiceProviderTokenManager Members
- public string GetConsumerSecret(string consumerKey) {
- return this.consumersAndSecrets[consumerKey];
+ public IConsumerDescription GetConsumer(string consumerKey) {
+ return this.consumers[consumerKey];
+ }
+
+ public IServiceProviderRequestToken GetRequestToken(string token) {
+ return this.tokens[token];
}
#endregion
@@ -105,7 +110,7 @@ namespace DotNetOpenAuth.Test.Mocks {
/// </summary>
/// <param name="consumerDescription">The consumer description.</param>
internal void AddConsumer(ConsumerDescription consumerDescription) {
- this.consumersAndSecrets.Add(consumerDescription.ConsumerKey, consumerDescription.ConsumerSecret);
+ this.consumers.Add(new ConsumerInfo { Key = consumerDescription.ConsumerKey, Secret = consumerDescription.ConsumerSecret });
}
/// <summary>
@@ -119,5 +124,37 @@ namespace DotNetOpenAuth.Test.Mocks {
this.requestTokens[requestToken] = true;
}
+
+ private class TokenInfo : IServiceProviderRequestToken {
+ public string ConsumerKey { get; set; }
+
+ public string Token { get; set; }
+
+ public string VerificationCode { get; set; }
+
+ public Uri Callback { get; set; }
+
+ public Version ConsumerVersion { get; set; }
+
+ internal string Secret { get; set; }
+ }
+
+ private class ConsumerInfo : IConsumerDescription {
+ #region IConsumerDescription Members
+
+ public string Key { get; set; }
+
+ public string Secret { get; set; }
+
+ public System.Security.Cryptography.X509Certificates.X509Certificate2 Certificate { get; set; }
+
+ public Uri Callback { get; set; }
+
+ public DotNetOpenAuth.OAuth.VerificationCodeFormat VerificationCodeFormat { get; set; }
+
+ public int VerificationCodeLength { get; set; }
+
+ #endregion
+ }
}
}
diff --git a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
index 449a033..82d211a 100644
--- a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
+++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
@@ -33,7 +33,7 @@ namespace DotNetOpenAuth.Test.ChannelElements {
base.SetUp();
this.webRequestHandler = new TestWebRequestHandler();
- this.signingElement = new RsaSha1SigningBindingElement();
+ this.signingElement = new RsaSha1SigningBindingElement(new InMemoryTokenManager());
this.nonceStore = new NonceMemoryStore(StandardExpirationBindingElement.DefaultMaximumMessageAge);
this.channel = new OAuthChannel(this.signingElement, this.nonceStore, new InMemoryTokenManager(), new TestMessageFactory());
this.accessor = OAuthChannel_Accessor.AttachShadow(this.channel);
@@ -47,22 +47,22 @@ namespace DotNetOpenAuth.Test.ChannelElements {
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
public void CtorNullStore() {
- new OAuthChannel(new RsaSha1SigningBindingElement(), null, new InMemoryTokenManager(), new TestMessageFactory());
+ new OAuthChannel(new RsaSha1SigningBindingElement(new InMemoryTokenManager()), null, new InMemoryTokenManager(), new TestMessageFactory());
}
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
public void CtorNullTokenManager() {
- new OAuthChannel(new RsaSha1SigningBindingElement(), this.nonceStore, null, new TestMessageFactory());
+ new OAuthChannel(new RsaSha1SigningBindingElement(new InMemoryTokenManager()), this.nonceStore, null, new TestMessageFactory());
}
[TestMethod]
public void CtorSimpleConsumer() {
- new OAuthChannel(new RsaSha1SigningBindingElement(), this.nonceStore, (IConsumerTokenManager)new InMemoryTokenManager());
+ new OAuthChannel(new RsaSha1SigningBindingElement(new InMemoryTokenManager()), this.nonceStore, (IConsumerTokenManager)new InMemoryTokenManager());
}
[TestMethod]
public void CtorSimpleServiceProvider() {
- new OAuthChannel(new RsaSha1SigningBindingElement(), this.nonceStore, (IServiceProviderTokenManager)new InMemoryTokenManager());
+ new OAuthChannel(new RsaSha1SigningBindingElement(new InMemoryTokenManager()), this.nonceStore, (IServiceProviderTokenManager)new InMemoryTokenManager());
}
[TestMethod]
diff --git a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/PlaintextSigningBindingElementTest.cs b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/PlaintextSigningBindingElementTest.cs
index ca63b50..627db8f 100644
--- a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/PlaintextSigningBindingElementTest.cs
+++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/PlaintextSigningBindingElementTest.cs
@@ -4,9 +4,9 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace DotNetOpenAuth.Test.ChannelElements
-{
+namespace DotNetOpenAuth.Test.ChannelElements {
using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OAuth;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -17,7 +17,7 @@ namespace DotNetOpenAuth.Test.ChannelElements
public void HttpsSignatureGeneration() {
SigningBindingElementBase target = new PlaintextSigningBindingElement();
MessageReceivingEndpoint endpoint = new MessageReceivingEndpoint("https://localtest", HttpDeliveryMethods.GetRequest);
- ITamperResistantOAuthMessage message = new UnauthorizedTokenRequest(endpoint);
+ ITamperResistantOAuthMessage message = new UnauthorizedTokenRequest(endpoint, Protocol.Default.Version);
message.ConsumerSecret = "cs";
message.TokenSecret = "ts";
Assert.IsNotNull(target.ProcessOutgoingMessage(message));
@@ -29,7 +29,7 @@ namespace DotNetOpenAuth.Test.ChannelElements
public void HttpsSignatureVerification() {
MessageReceivingEndpoint endpoint = new MessageReceivingEndpoint("https://localtest", HttpDeliveryMethods.GetRequest);
ITamperProtectionChannelBindingElement target = new PlaintextSigningBindingElement();
- ITamperResistantOAuthMessage message = new UnauthorizedTokenRequest(endpoint);
+ ITamperResistantOAuthMessage message = new UnauthorizedTokenRequest(endpoint, Protocol.Default.Version);
message.ConsumerSecret = "cs";
message.TokenSecret = "ts";
message.SignatureMethod = "PLAINTEXT";
@@ -41,7 +41,7 @@ namespace DotNetOpenAuth.Test.ChannelElements
public void HttpsSignatureVerificationNotApplicable() {
SigningBindingElementBase target = new PlaintextSigningBindingElement();
MessageReceivingEndpoint endpoint = new MessageReceivingEndpoint("https://localtest", HttpDeliveryMethods.GetRequest);
- ITamperResistantOAuthMessage message = new UnauthorizedTokenRequest(endpoint);
+ ITamperResistantOAuthMessage message = new UnauthorizedTokenRequest(endpoint, Protocol.Default.Version);
message.ConsumerSecret = "cs";
message.TokenSecret = "ts";
message.SignatureMethod = "ANOTHERALGORITHM";
@@ -53,7 +53,7 @@ namespace DotNetOpenAuth.Test.ChannelElements
public void HttpSignatureGeneration() {
SigningBindingElementBase target = new PlaintextSigningBindingElement();
MessageReceivingEndpoint endpoint = new MessageReceivingEndpoint("http://localtest", HttpDeliveryMethods.GetRequest);
- ITamperResistantOAuthMessage message = new UnauthorizedTokenRequest(endpoint);
+ ITamperResistantOAuthMessage message = new UnauthorizedTokenRequest(endpoint, Protocol.Default.Version);
message.ConsumerSecret = "cs";
message.TokenSecret = "ts";
@@ -67,7 +67,7 @@ namespace DotNetOpenAuth.Test.ChannelElements
public void HttpSignatureVerification() {
SigningBindingElementBase target = new PlaintextSigningBindingElement();
MessageReceivingEndpoint endpoint = new MessageReceivingEndpoint("http://localtest", HttpDeliveryMethods.GetRequest);
- ITamperResistantOAuthMessage message = new UnauthorizedTokenRequest(endpoint);
+ ITamperResistantOAuthMessage message = new UnauthorizedTokenRequest(endpoint, Protocol.Default.Version);
message.ConsumerSecret = "cs";
message.TokenSecret = "ts";
message.SignatureMethod = "PLAINTEXT";
diff --git a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/SigningBindingElementBaseTests.cs b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/SigningBindingElementBaseTests.cs
index 93c0b3f..6e566c8 100644
--- a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/SigningBindingElementBaseTests.cs
+++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/SigningBindingElementBaseTests.cs
@@ -7,6 +7,7 @@
namespace DotNetOpenAuth.Test.ChannelElements {
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Reflection;
+ using DotNetOpenAuth.OAuth;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -63,7 +64,7 @@ namespace DotNetOpenAuth.Test.ChannelElements {
internal static UnauthorizedTokenRequest CreateTestRequestTokenMessage(MessageDescriptionCollection messageDescriptions, MessageReceivingEndpoint endpoint) {
endpoint = endpoint ?? new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthGetRequestToken", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest);
- UnauthorizedTokenRequest message = new UnauthorizedTokenRequest(endpoint);
+ UnauthorizedTokenRequest message = new UnauthorizedTokenRequest(endpoint, Protocol.V10.Version);
message.ConsumerKey = "nerdbank.org";
((ITamperResistantOAuthMessage)message).ConsumerSecret = "nerdbanksecret";
var signedMessage = (ITamperResistantOAuthMessage)message;
diff --git a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/UriOrOobEncodingTests.cs b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/UriOrOobEncodingTests.cs
new file mode 100644
index 0000000..40fc93e
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/UriOrOobEncodingTests.cs
@@ -0,0 +1,68 @@
+//-----------------------------------------------------------------------
+// <copyright file="UriOrOobEncodingTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.OAuth.ChannelElements {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using DotNetOpenAuth.OAuth.ChannelElements;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class UriOrOobEncodingTests : TestBase {
+ private UriOrOobEncoding encoding;
+
+ [TestInitialize]
+ public void Setup() {
+ this.encoding = new UriOrOobEncoding();
+ }
+
+ /// <summary>
+ /// Verifies null value encoding
+ /// </summary>
+ [TestMethod]
+ public void NullValueEncoding() {
+ Assert.AreEqual("oob", this.encoding.EncodedNullValue);
+ }
+
+ /// <summary>
+ /// Verifies decoding "oob" results in a null uri.
+ /// </summary>
+ [TestMethod]
+ public void DecodeOobToNullUri() {
+ Assert.IsNull(this.encoding.Decode("oob"));
+ }
+
+ /// <summary>
+ /// Verifies that decoding an empty string generates an exception.
+ /// </summary>
+ [TestMethod, ExpectedException(typeof(UriFormatException))]
+ public void DecodeEmptyStringFails() {
+ this.encoding.Decode(string.Empty);
+ }
+
+ /// <summary>
+ /// Verifies proper decoding/encoding of a Uri
+ /// </summary>
+ [TestMethod]
+ public void UriEncodeDecode() {
+ Uri original = new Uri("http://somehost/p?q=a#frag");
+ string encodedValue = this.encoding.Encode(original);
+ Assert.AreEqual(original.AbsoluteUri, encodedValue);
+ Uri decoded = (Uri)this.encoding.Decode(encodedValue);
+ Assert.AreEqual(original, decoded);
+ }
+
+ /// <summary>
+ /// Verifies failure to decode a relative Uri
+ /// </summary>
+ [TestMethod, ExpectedException(typeof(UriFormatException))]
+ public void RelativeUriDecodeFails() {
+ this.encoding.Decode("../a/b");
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.Test/OAuth/ProtocolTests.cs b/src/DotNetOpenAuth.Test/OAuth/ProtocolTests.cs
index 6a2551a..ce8070b 100644
--- a/src/DotNetOpenAuth.Test/OAuth/ProtocolTests.cs
+++ b/src/DotNetOpenAuth.Test/OAuth/ProtocolTests.cs
@@ -12,7 +12,7 @@ namespace DotNetOpenAuth.Test {
public class ProtocolTests {
[TestMethod]
public void Default() {
- Assert.AreSame(Protocol.V10, Protocol.Default);
+ Assert.AreSame(Protocol.V10a, Protocol.Default);
}
[TestMethod]
@@ -23,12 +23,12 @@ namespace DotNetOpenAuth.Test {
[TestMethod]
public void AuthorizationHeaderScheme() {
- Assert.AreEqual("OAuth", Protocol.V10.AuthorizationHeaderScheme);
+ Assert.AreEqual("OAuth", Protocol.AuthorizationHeaderScheme);
}
[TestMethod]
public void ParameterPrefix() {
- Assert.AreEqual("oauth_", Protocol.V10.ParameterPrefix);
+ Assert.AreEqual("oauth_", Protocol.ParameterPrefix);
}
}
}
diff --git a/src/DotNetOpenAuth.Test/OAuth/ServiceProviderTests.cs b/src/DotNetOpenAuth.Test/OAuth/ServiceProviderTests.cs
new file mode 100644
index 0000000..2a443ce
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/OAuth/ServiceProviderTests.cs
@@ -0,0 +1,38 @@
+//-----------------------------------------------------------------------
+// <copyright file="ServiceProviderTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.OAuth {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OAuth;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class ServiceProviderTests : TestBase {
+ /// <summary>
+ /// Verifies the CreateVerificationCode method.
+ /// </summary>
+ [TestMethod]
+ public void CreateVerificationCode() {
+ this.TestCode(VerificationCodeFormat.Numeric, 3, MessagingUtilities.Digits);
+ this.TestCode(VerificationCodeFormat.AlphaLower, 5, MessagingUtilities.LowercaseLetters);
+ this.TestCode(VerificationCodeFormat.AlphaUpper, 5, MessagingUtilities.UppercaseLetters);
+ this.TestCode(VerificationCodeFormat.AlphaNumericNoLookAlikes, 8, MessagingUtilities.AlphaNumericNoLookAlikes);
+ }
+
+ private void TestCode(VerificationCodeFormat format, int length, string allowableCharacters) {
+ string code = ServiceProvider.CreateVerificationCode(format, length);
+ TestContext.WriteLine("{0} of length {2}: {1}", format, code, length);
+ Assert.AreEqual(length, code.Length);
+ foreach (char ch in code) {
+ Assert.IsTrue(allowableCharacters.Contains(ch));
+ }
+ }
+ }
+}