summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-04-08 16:22:58 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2009-04-08 16:22:58 -0700
commitd9c0ee017807cc17132e9c760d274afffc9b981c (patch)
tree28a79463a760a10c4d67cbac48f9a6af5cd25b32 /src/DotNetOpenAuth.Test
parent1c3247abc8fb37405d0602e5037b3cebbe8e944a (diff)
downloadDotNetOpenAuth-d9c0ee017807cc17132e9c760d274afffc9b981c.zip
DotNetOpenAuth-d9c0ee017807cc17132e9c760d274afffc9b981c.tar.gz
DotNetOpenAuth-d9c0ee017807cc17132e9c760d274afffc9b981c.tar.bz2
Split up ITokenManager into two derived interfaces to better fit Consumer and Service Provider scenarios.
Diffstat (limited to 'src/DotNetOpenAuth.Test')
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs20
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/InMemoryTokenManager.cs25
-rw-r--r--src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs4
-rw-r--r--src/DotNetOpenAuth.Test/OAuth/OAuthCoordinator.cs6
4 files changed, 42 insertions, 13 deletions
diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs
index 88ada15..2d14bc8 100644
--- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs
@@ -26,14 +26,26 @@ namespace DotNetOpenAuth.Test.Mocks {
/// <param name="signingBindingElement">
/// The signing element for the Consumer to use. Null for the Service Provider.
/// </param>
- /// <param name="isConsumer">True if this channel is constructed for a Consumer.</param>
/// <param name="tokenManager">The token manager to use.</param>
- internal CoordinatingOAuthChannel(ITamperProtectionChannelBindingElement signingBindingElement, bool isConsumer, ITokenManager tokenManager)
+ internal CoordinatingOAuthChannel(ITamperProtectionChannelBindingElement signingBindingElement, IConsumerTokenManager tokenManager)
: base(
signingBindingElement,
new NonceMemoryStore(StandardExpirationBindingElement.DefaultMaximumMessageAge),
- tokenManager,
- isConsumer ? (IMessageFactory)new OAuthConsumerMessageFactory() : new OAuthServiceProviderMessageFactory(tokenManager)) {
+ tokenManager) {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="CoordinatingOAuthChannel"/> class for Consumers.
+ /// </summary>
+ /// <param name="signingBindingElement">
+ /// The signing element for the Consumer to use. Null for the Service Provider.
+ /// </param>
+ /// <param name="tokenManager">The token manager to use.</param>
+ internal CoordinatingOAuthChannel(ITamperProtectionChannelBindingElement signingBindingElement, IServiceProviderTokenManager tokenManager)
+ : base(
+ signingBindingElement,
+ new NonceMemoryStore(StandardExpirationBindingElement.DefaultMaximumMessageAge),
+ tokenManager) {
}
/// <summary>
diff --git a/src/DotNetOpenAuth.Test/Mocks/InMemoryTokenManager.cs b/src/DotNetOpenAuth.Test/Mocks/InMemoryTokenManager.cs
index 571bba7..be3c563 100644
--- a/src/DotNetOpenAuth.Test/Mocks/InMemoryTokenManager.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/InMemoryTokenManager.cs
@@ -8,10 +8,11 @@ namespace DotNetOpenAuth.Test.Mocks {
using System;
using System.Collections.Generic;
using System.Diagnostics;
+ using System.Linq;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages;
- internal class InMemoryTokenManager : ITokenManager {
+ internal class InMemoryTokenManager : IConsumerTokenManager, IServiceProviderTokenManager {
private Dictionary<string, string> consumersAndSecrets = new Dictionary<string, string>();
private Dictionary<string, string> tokensAndSecrets = new Dictionary<string, string>();
@@ -25,12 +26,20 @@ namespace DotNetOpenAuth.Test.Mocks {
/// </summary>
private List<string> accessTokens = new List<string>();
- #region ITokenManager Members
+ #region IConsumerTokenManager Members
- public string GetConsumerSecret(string consumerKey) {
- return this.consumersAndSecrets[consumerKey];
+ public string ConsumerKey {
+ get { return this.consumersAndSecrets.Keys.Single(); }
+ }
+
+ public string ConsumerSecret {
+ get { return this.consumersAndSecrets.Values.Single(); }
}
+ #endregion
+
+ #region ITokenManager Members
+
public string GetTokenSecret(string token) {
return this.tokensAndSecrets[token];
}
@@ -82,6 +91,14 @@ namespace DotNetOpenAuth.Test.Mocks {
#endregion
+ #region IServiceProviderTokenManager Members
+
+ public string GetConsumerSecret(string consumerKey) {
+ return this.consumersAndSecrets[consumerKey];
+ }
+
+ #endregion
+
/// <summary>
/// Tells a Service Provider's token manager about a consumer and its secret
/// so that the SP can verify the Consumer's signed messages.
diff --git a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
index fd8c15a..401153d 100644
--- a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
+++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
@@ -56,12 +56,12 @@ namespace DotNetOpenAuth.Test.ChannelElements {
[TestMethod]
public void CtorSimpleConsumer() {
- new OAuthChannel(new RsaSha1SigningBindingElement(), this.nonceStore, new InMemoryTokenManager(), true);
+ new OAuthChannel(new RsaSha1SigningBindingElement(), this.nonceStore, (IConsumerTokenManager)new InMemoryTokenManager());
}
[TestMethod]
public void CtorSimpleServiceProvider() {
- new OAuthChannel(new RsaSha1SigningBindingElement(), this.nonceStore, new InMemoryTokenManager(), false);
+ new OAuthChannel(new RsaSha1SigningBindingElement(), this.nonceStore, (IServiceProviderTokenManager)new InMemoryTokenManager());
}
[TestMethod]
diff --git a/src/DotNetOpenAuth.Test/OAuth/OAuthCoordinator.cs b/src/DotNetOpenAuth.Test/OAuth/OAuthCoordinator.cs
index e8b1f79..e04edeb 100644
--- a/src/DotNetOpenAuth.Test/OAuth/OAuthCoordinator.cs
+++ b/src/DotNetOpenAuth.Test/OAuth/OAuthCoordinator.cs
@@ -8,6 +8,7 @@ namespace DotNetOpenAuth.Test {
using System;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth;
+ using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.Test.Mocks;
/// <summary>
@@ -47,15 +48,14 @@ namespace DotNetOpenAuth.Test {
serviceTokenManager.AddConsumer(this.consumerDescription);
// Prepare channels that will pass messages directly back and forth.
- CoordinatingOAuthChannel consumerChannel = new CoordinatingOAuthChannel(consumerSigningElement, true, consumerTokenManager);
- CoordinatingOAuthChannel serviceProviderChannel = new CoordinatingOAuthChannel(spSigningElement, false, serviceTokenManager);
+ CoordinatingOAuthChannel consumerChannel = new CoordinatingOAuthChannel(consumerSigningElement, (IConsumerTokenManager)consumerTokenManager);
+ CoordinatingOAuthChannel serviceProviderChannel = new CoordinatingOAuthChannel(spSigningElement, (IServiceProviderTokenManager)serviceTokenManager);
consumerChannel.RemoteChannel = serviceProviderChannel;
serviceProviderChannel.RemoteChannel = consumerChannel;
// Prepare the Consumer and Service Provider objects
WebConsumer consumer = new WebConsumer(this.serviceDescription, consumerTokenManager) {
OAuthChannel = consumerChannel,
- ConsumerKey = this.consumerDescription.ConsumerKey,
};
ServiceProvider serviceProvider = new ServiceProvider(this.serviceDescription, serviceTokenManager) {
OAuthChannel = serviceProviderChannel,