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.csproj17
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/EnumerableCacheTests.cs130
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs1
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs2
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs2
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs2
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/InMemoryTokenManager.cs75
-rw-r--r--src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs18
-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
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs4
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionsInteropHelperOPTests.cs147
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionsInteropHelperRPRequestTests.cs128
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionsInteropHelperRPResponseTests.cs83
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs11
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Provider/AuthenticationRequestTest.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/Provider/PerformanceTests.cs149
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/ProviderEndpointDescriptionTests.cs62
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/RelyingParty/PositiveAnonymousResponseTests.cs14
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/RelyingParty/RelyingPartySecuritySettingsTests.cs24
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/RelyingParty/ServiceEndpointTests.cs40
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs2
27 files changed, 963 insertions, 83 deletions
diff --git a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
index 49e9b9e..680a9ef 100644
--- a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
+++ b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
@@ -80,9 +80,10 @@
<CodeContractsRunInBackground>True</CodeContractsRunInBackground>
<CodeContractsShowSquigglies>False</CodeContractsShowSquigglies>
</PropertyGroup>
- <PropertyGroup Condition=" '$(Sign)' == 'true' ">
+ <PropertyGroup>
<SignAssembly>true</SignAssembly>
- <AssemblyOriginatorKeyFile>..\official-build-key.pfx</AssemblyOriginatorKeyFile>
+ <DelaySign>true</DelaySign>
+ <AssemblyOriginatorKeyFile>..\official-build-key.pub</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'CodeAnalysis|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -129,6 +130,10 @@
<HintPath>..\..\lib\Microsoft.Contracts.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
+ <Reference Include="Moq, Version=3.1.416.3, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\Moq.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core">
@@ -159,6 +164,7 @@
<Compile Include="Hosting\HttpHost.cs" />
<Compile Include="Hosting\TestingWorkerRequest.cs" />
<Compile Include="Messaging\CollectionAssert.cs" />
+ <Compile Include="Messaging\EnumerableCacheTests.cs" />
<Compile Include="Messaging\ErrorUtilitiesTests.cs" />
<Compile Include="Messaging\MessageSerializerTests.cs" />
<Compile Include="Messaging\Reflection\MessageDescriptionTests.cs" />
@@ -198,9 +204,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" />
@@ -216,6 +224,8 @@
<Compile Include="OpenId\Extensions\AttributeExchange\AttributeValuesTests.cs" />
<Compile Include="OpenId\Extensions\AttributeExchange\StoreRequestTests.cs" />
<Compile Include="OpenId\Extensions\AttributeExchange\StoreResponseTests.cs" />
+ <Compile Include="OpenId\Extensions\ExtensionsInteropHelperOPTests.cs" />
+ <Compile Include="OpenId\Extensions\ExtensionsInteropHelperRPResponseTests.cs" />
<Compile Include="OpenId\Extensions\ProviderAuthenticationPolicy\PapeRoundTripTests.cs" />
<Compile Include="OpenId\Extensions\ProviderAuthenticationPolicy\PolicyRequestTests.cs" />
<Compile Include="OpenId\Extensions\ProviderAuthenticationPolicy\PolicyResponseTests.cs" />
@@ -224,6 +234,7 @@
<Compile Include="OpenId\Extensions\SimpleRegistration\ClaimsRequestTests.cs" />
<Compile Include="OpenId\Extensions\UI\UIRequestTests.cs" />
<Compile Include="OpenId\IdentifierTests.cs" />
+ <Compile Include="OpenId\Extensions\ExtensionsInteropHelperRPRequestTests.cs" />
<Compile Include="OpenId\Messages\AssociateDiffieHellmanRequestTests.cs" />
<Compile Include="OpenId\Messages\AssociateRequestTests.cs" />
<Compile Include="OpenId\Messages\AssociateUnsuccessfulResponseTests.cs" />
@@ -242,6 +253,8 @@
<Compile Include="OpenId\OpenIdCoordinator.cs" />
<Compile Include="OpenId\AssociationHandshakeTests.cs" />
<Compile Include="OpenId\OpenIdTestBase.cs" />
+ <Compile Include="OpenId\Provider\PerformanceTests.cs" />
+ <Compile Include="OpenId\ProviderEndpointDescriptionTests.cs" />
<Compile Include="OpenId\Provider\AnonymousRequestTests.cs" />
<Compile Include="OpenId\Provider\AuthenticationRequestTest.cs" />
<Compile Include="OpenId\Provider\HostProcessedRequestTests.cs" />
diff --git a/src/DotNetOpenAuth.Test/Messaging/EnumerableCacheTests.cs b/src/DotNetOpenAuth.Test/Messaging/EnumerableCacheTests.cs
new file mode 100644
index 0000000..55f4394
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/Messaging/EnumerableCacheTests.cs
@@ -0,0 +1,130 @@
+//-----------------------------------------------------------------------
+// <copyright file="EnumerableCacheTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// This code is released under the Microsoft Public License (Ms-PL).
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.Messaging {
+ using System;
+ using System.Collections.Generic;
+ using System.Collections.ObjectModel;
+ using System.Linq;
+ using DotNetOpenAuth.Messaging;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ /// <summary>
+ /// Tests for cached enumeration.
+ /// </summary>
+ [TestClass]
+ public class EnumerableCacheTests {
+ /// <summary>
+ /// The number of times the generator method's implementation is started.
+ /// </summary>
+ private int generatorInvocations;
+
+ /// <summary>
+ /// The number of times the end of the generator method's implementation is reached.
+ /// </summary>
+ private int generatorCompleted;
+
+ /// <summary>
+ /// Gets or sets the test context.
+ /// </summary>
+ public TestContext TestContext { get; set; }
+
+ /// <summary>
+ /// Sets up a test.
+ /// </summary>
+ [TestInitialize]
+ public void Setup() {
+ this.generatorInvocations = 0;
+ this.generatorCompleted = 0;
+ }
+
+ [TestMethod]
+ public void EnumerableCache() {
+ // Baseline
+ var generator = this.NumberGenerator();
+ var list1 = generator.ToList();
+ var list2 = generator.ToList();
+ Assert.AreEqual(2, this.generatorInvocations);
+ CollectionAssert.AreEqual(list1, list2);
+
+ // Cache behavior
+ this.generatorInvocations = 0;
+ this.generatorCompleted = 0;
+ generator = this.NumberGenerator().CacheGeneratedResults();
+ var list3 = generator.ToList();
+ var list4 = generator.ToList();
+ Assert.AreEqual(1, this.generatorInvocations);
+ Assert.AreEqual(1, this.generatorCompleted);
+ CollectionAssert.AreEqual(list1, list3);
+ CollectionAssert.AreEqual(list1, list4);
+ }
+
+ [TestMethod]
+ public void GeneratesOnlyRequiredElements() {
+ var generator = this.NumberGenerator().CacheGeneratedResults();
+ Assert.AreEqual(0, this.generatorInvocations);
+ generator.Take(2).ToList();
+ Assert.AreEqual(1, this.generatorInvocations);
+ Assert.AreEqual(0, this.generatorCompleted, "Only taking part of the list should not have completed the generator.");
+ }
+
+ [TestMethod]
+ public void PassThruDoubleCache() {
+ var cache1 = this.NumberGenerator().CacheGeneratedResults();
+ var cache2 = cache1.CacheGeneratedResults();
+ Assert.AreSame(cache1, cache2, "Two caches were set up rather than just sharing the first one.");
+ }
+
+ [TestMethod]
+ public void PassThruList() {
+ var list = this.NumberGenerator().ToList();
+ var cache = list.CacheGeneratedResults();
+ Assert.AreSame(list, cache);
+ }
+
+ [TestMethod]
+ public void PassThruArray() {
+ var array = this.NumberGenerator().ToArray();
+ var cache = array.CacheGeneratedResults();
+ Assert.AreSame(array, cache);
+ }
+
+ [TestMethod]
+ public void PassThruCollection() {
+ var collection = new Collection<int>();
+ var cache = collection.CacheGeneratedResults();
+ Assert.AreSame(collection, cache);
+ }
+
+ /// <summary>
+ /// Tests calling IEnumerator.Current before first call to MoveNext.
+ /// </summary>
+ [TestMethod, ExpectedException(typeof(InvalidOperationException))]
+ public void EnumerableCacheCurrentThrowsBefore() {
+ var foo = this.NumberGenerator().CacheGeneratedResults().GetEnumerator().Current;
+ }
+
+ /// <summary>
+ /// Tests calling IEnumerator.Current after MoveNext returns false.
+ /// </summary>
+ [TestMethod, ExpectedException(typeof(InvalidOperationException))]
+ public void EnumerableCacheCurrentThrowsAfter() {
+ var enumerator = this.NumberGenerator().CacheGeneratedResults().GetEnumerator();
+ while (enumerator.MoveNext()) {
+ }
+ var foo = enumerator.Current;
+ }
+
+ private IEnumerable<int> NumberGenerator() {
+ this.generatorInvocations++;
+ for (int i = 10; i < 15; i++) {
+ yield return i;
+ }
+ this.generatorCompleted++;
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs b/src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs
index dd59bae..4cdaa39 100644
--- a/src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs
@@ -26,6 +26,7 @@ namespace DotNetOpenAuth.Test.Messaging {
Assert.AreEqual(request.Url.Query, info.Query);
Assert.AreEqual(request.QueryString["a"], info.QueryString["a"]);
Assert.AreEqual(request.Url, info.Url);
+ Assert.AreEqual(request.Url, info.UrlBeforeRewriting);
Assert.AreEqual(request.HttpMethod, info.HttpMethod);
}
diff --git a/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs b/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs
index 0a11a75..accb182 100644
--- a/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs
@@ -70,7 +70,7 @@ namespace DotNetOpenAuth.Test {
}
HttpRequestInfo request = new HttpRequestInfo {
HttpMethod = method,
- Url = requestUri.Uri,
+ UrlBeforeRewriting = requestUri.Uri,
Headers = headers,
InputStream = ms,
};
diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs
index 2e5a9ce..46e3373 100644
--- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingHttpRequestInfo.cs
@@ -41,7 +41,7 @@ namespace DotNetOpenAuth.Test.Mocks {
internal CoordinatingHttpRequestInfo(MessageReceivingEndpoint recipient) {
this.recipient = recipient;
if (recipient != null) {
- this.Url = recipient.Location;
+ this.UrlBeforeRewriting = recipient.Location;
}
if (recipient == null || (recipient.AllowedMethods & HttpDeliveryMethods.GetRequest) != 0) {
diff --git a/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs b/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs
index 2e4ccad..7dc369b 100644
--- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs
@@ -111,7 +111,7 @@ namespace DotNetOpenAuth.Test.Mocks {
if (signedMessage != null) {
string httpMethod = this.GetHttpMethod(signedMessage.HttpMethods);
requestInfo.HttpMethod = httpMethod;
- requestInfo.Url = message.Recipient;
+ requestInfo.UrlBeforeRewriting = message.Recipient;
signedMessage.HttpMethod = httpMethod;
}
diff --git a/src/DotNetOpenAuth.Test/Mocks/InMemoryTokenManager.cs b/src/DotNetOpenAuth.Test/Mocks/InMemoryTokenManager.cs
index be3c563..48547b7 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,16 @@ 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];
+ }
+
+ public IServiceProviderAccessToken GetAccessToken(string token) {
+ return this.tokens[token];
}
#endregion
@@ -105,7 +114,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 +128,49 @@ namespace DotNetOpenAuth.Test.Mocks {
this.requestTokens[requestToken] = true;
}
+
+ private class TokenInfo : IServiceProviderRequestToken, IServiceProviderAccessToken {
+ internal TokenInfo() {
+ this.CreatedOn = DateTime.Now;
+ }
+
+ public string ConsumerKey { get; set; }
+
+ public DateTime CreatedOn { get; set; }
+
+ public string Token { get; set; }
+
+ public string VerificationCode { get; set; }
+
+ public Uri Callback { get; set; }
+
+ public Version ConsumerVersion { get; set; }
+
+ public string Username { get; set; }
+
+ public string[] Roles { get; set; }
+
+ public DateTime? ExpirationDate { 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 923e6c1..d19d908 100644
--- a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
+++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
@@ -34,7 +34,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);
@@ -48,22 +48,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]
@@ -84,9 +84,9 @@ namespace DotNetOpenAuth.Test.ChannelElements {
HttpRequestInfo requestInfo = CreateHttpRequestInfo(HttpDeliveryMethods.PostRequest, fields);
// Now add another field to the request URL
- UriBuilder builder = new UriBuilder(requestInfo.Url);
+ UriBuilder builder = new UriBuilder(requestInfo.UrlBeforeRewriting);
builder.Query = "Name=Andrew";
- requestInfo.Url = builder.Uri;
+ requestInfo.UrlBeforeRewriting = builder.Uri;
requestInfo.RawUrl = builder.Path + builder.Query + builder.Fragment;
// Finally, add an Authorization header
@@ -289,7 +289,7 @@ namespace DotNetOpenAuth.Test.ChannelElements {
}
HttpRequestInfo request = new HttpRequestInfo {
HttpMethod = method,
- Url = requestUri.Uri,
+ UrlBeforeRewriting = requestUri.Uri,
RawUrl = requestUri.Path + requestUri.Query + requestUri.Fragment,
Headers = headers,
InputStream = ms,
@@ -301,7 +301,7 @@ namespace DotNetOpenAuth.Test.ChannelElements {
private static HttpRequestInfo ConvertToRequestInfo(HttpWebRequest request, Stream postEntity) {
HttpRequestInfo info = new HttpRequestInfo {
HttpMethod = request.Method,
- Url = request.RequestUri,
+ UrlBeforeRewriting = request.RequestUri,
RawUrl = request.RequestUri.AbsolutePath + request.RequestUri.Query + request.RequestUri.Fragment,
Headers = request.Headers,
InputStream = postEntity,
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));
+ }
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
index f88af0d..af3b1b1 100644
--- a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
@@ -375,8 +375,8 @@ namespace DotNetOpenAuth.Test.OpenId {
var unencryptedResponse = (AssociateUnencryptedResponse)associateSuccessfulResponse;
}
} else {
- Assert.IsNull(associationManagerAccessor.associationStore.GetAssociation(opDescription.Endpoint, new SecuritySettings(false)));
- Assert.IsNull(coordinator.Provider.AssociationStore.GetAssociation(AssociationRelyingPartyType.Smart, new SecuritySettings(true)));
+ Assert.IsNull(associationManagerAccessor.associationStore.GetAssociation(opDescription.Endpoint, new RelyingPartySecuritySettings()));
+ Assert.IsNull(coordinator.Provider.AssociationStore.GetAssociation(AssociationRelyingPartyType.Smart, new ProviderSecuritySettings()));
}
}
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs
index 08432ff..29797dc 100644
--- a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs
@@ -32,7 +32,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements {
this.factory = new StandardOpenIdExtensionFactory();
this.factory.RegisterExtension(MockOpenIdExtension.Factory);
- this.rpElement = new ExtensionsBindingElement(this.factory);
+ this.rpElement = new ExtensionsBindingElement(this.factory, new RelyingPartySecuritySettings());
this.rpElement.Channel = new TestChannel(this.MessageDescriptions);
this.request = new SignedResponseRequest(Protocol.Default.Version, OpenIdTestBase.OPUri, AuthenticationRequestMode.Immediate);
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionsInteropHelperOPTests.cs b/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionsInteropHelperOPTests.cs
new file mode 100644
index 0000000..9f849ea
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionsInteropHelperOPTests.cs
@@ -0,0 +1,147 @@
+//-----------------------------------------------------------------------
+// <copyright file="ExtensionsInteropHelperOPTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.OpenId.Extensions {
+ using System.Collections.Generic;
+ using System.Linq;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OpenId;
+ using DotNetOpenAuth.OpenId.Extensions;
+ using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
+ using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
+ using DotNetOpenAuth.OpenId.Messages;
+ using DotNetOpenAuth.OpenId.Provider;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class ExtensionsInteropHelperOPTests : OpenIdTestBase {
+ private AuthenticationRequest request;
+ private IList<IExtensionMessage> extensions;
+
+ [TestInitialize]
+ public override void SetUp() {
+ base.SetUp();
+
+ var op = this.CreateProvider();
+ var rpRequest = new CheckIdRequest(Protocol.Default.Version, OPUri, DotNetOpenAuth.OpenId.RelyingParty.AuthenticationRequestMode.Setup);
+ rpRequest.ReturnTo = RPUri;
+ this.extensions = rpRequest.Extensions;
+ this.request = new AuthenticationRequest(op, rpRequest);
+ this.request.IsAuthenticated = true;
+ }
+
+ /// <summary>
+ /// Verifies no extensions appear as no extensions
+ /// </summary>
+ [TestMethod]
+ public void NoRequestedExtensions() {
+ var sreg = ExtensionsInteropHelper.UnifyExtensionsAsSreg(this.request);
+ Assert.IsNull(sreg);
+
+ // Make sure we're still able to send an sreg response.
+ var sregResponse = new ClaimsResponse();
+ this.request.AddResponseExtension(sregResponse);
+ ExtensionsInteropHelper.ConvertSregToMatchRequest(this.request);
+ var extensions = this.GetResponseExtensions();
+ Assert.AreSame(sregResponse, extensions.Single());
+ }
+
+ /// <summary>
+ /// Verifies sreg coming in is seen as sreg.
+ /// </summary>
+ [TestMethod]
+ public void UnifyExtensionsAsSregWithSreg() {
+ var sregInjected = new ClaimsRequest {
+ Nickname = DemandLevel.Request,
+ };
+ this.extensions.Add(sregInjected);
+ var sreg = ExtensionsInteropHelper.UnifyExtensionsAsSreg(this.request);
+ Assert.AreSame(sregInjected, sreg);
+ Assert.AreEqual(DemandLevel.Request, sreg.Nickname);
+ Assert.AreEqual(DemandLevel.NoRequest, sreg.FullName);
+
+ var sregResponse = new ClaimsResponse();
+ this.request.AddResponseExtension(sregResponse);
+ ExtensionsInteropHelper.ConvertSregToMatchRequest(this.request);
+ var extensions = this.GetResponseExtensions();
+ Assert.AreSame(sregResponse, extensions.Single());
+ }
+
+ /// <summary>
+ /// Verifies AX coming in looks like sreg.
+ /// </summary>
+ [TestMethod]
+ public void UnifyExtensionsAsSregWithAX() {
+ this.ParameterizedAXTest(AXAttributeFormats.AXSchemaOrg);
+ }
+
+ /// <summary>
+ /// Verifies AX coming in looks like sreg.
+ /// </summary>
+ [TestMethod]
+ public void UnifyExtensionsAsSregWithAXSchemaOpenIdNet() {
+ this.ParameterizedAXTest(AXAttributeFormats.SchemaOpenIdNet);
+ }
+
+ /// <summary>
+ /// Verifies sreg and AX in one request has a preserved sreg request.
+ /// </summary>
+ [TestMethod]
+ public void UnifyExtensionsAsSregWithBothSregAndAX() {
+ var sregInjected = new ClaimsRequest {
+ Nickname = DemandLevel.Request,
+ };
+ this.extensions.Add(sregInjected);
+ var axInjected = new FetchRequest();
+ axInjected.Attributes.AddOptional(WellKnownAttributes.Contact.Email);
+ this.extensions.Add(axInjected);
+ var sreg = ExtensionsInteropHelper.UnifyExtensionsAsSreg(this.request);
+ Assert.AreSame(sregInjected, sreg);
+ Assert.AreEqual(DemandLevel.Request, sreg.Nickname);
+ Assert.AreEqual(DemandLevel.NoRequest, sreg.Email);
+
+ var sregResponseInjected = new ClaimsResponse {
+ Nickname = "andy",
+ };
+ this.request.AddResponseExtension(sregResponseInjected);
+ var axResponseInjected = new FetchResponse();
+ axResponseInjected.Attributes.Add(WellKnownAttributes.Contact.Email, "a@b.com");
+ this.request.AddResponseExtension(axResponseInjected);
+ ExtensionsInteropHelper.ConvertSregToMatchRequest(this.request);
+ var extensions = this.GetResponseExtensions();
+ var sregResponse = extensions.OfType<ClaimsResponse>().Single();
+ Assert.AreEqual("andy", sregResponse.Nickname);
+ var axResponse = extensions.OfType<FetchResponse>().Single();
+ Assert.AreEqual("a@b.com", axResponse.GetAttributeValue(WellKnownAttributes.Contact.Email));
+ }
+
+ private IList<IExtensionMessage> GetResponseExtensions() {
+ IProtocolMessageWithExtensions response = (IProtocolMessageWithExtensions)this.request.Response;
+ return response.Extensions;
+ }
+
+ private void ParameterizedAXTest(AXAttributeFormats format) {
+ var axInjected = new FetchRequest();
+ axInjected.Attributes.AddOptional(ExtensionsInteropHelper_Accessor.TransformAXFormat(WellKnownAttributes.Name.Alias, format));
+ axInjected.Attributes.AddRequired(ExtensionsInteropHelper_Accessor.TransformAXFormat(WellKnownAttributes.Name.FullName, format));
+ this.extensions.Add(axInjected);
+ var sreg = ExtensionsInteropHelper.UnifyExtensionsAsSreg(this.request);
+ Assert.AreSame(sreg, this.request.GetExtension<ClaimsRequest>());
+ Assert.AreEqual(DemandLevel.Request, sreg.Nickname);
+ Assert.AreEqual(DemandLevel.Require, sreg.FullName);
+ Assert.AreEqual(DemandLevel.NoRequest, sreg.Language);
+
+ var sregResponse = new ClaimsResponse {
+ Nickname = "andy",
+ };
+ this.request.AddResponseExtension(sregResponse);
+ ExtensionsInteropHelper.ConvertSregToMatchRequest(this.request);
+ var extensions = this.GetResponseExtensions();
+ var axResponse = extensions.OfType<FetchResponse>().Single();
+ Assert.AreEqual("andy", axResponse.GetAttributeValue(ExtensionsInteropHelper_Accessor.TransformAXFormat(WellKnownAttributes.Name.Alias, format)));
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionsInteropHelperRPRequestTests.cs b/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionsInteropHelperRPRequestTests.cs
new file mode 100644
index 0000000..ba5e335
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionsInteropHelperRPRequestTests.cs
@@ -0,0 +1,128 @@
+//-----------------------------------------------------------------------
+// <copyright file="ExtensionsInteropHelperRPRequestTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.OpenId {
+ using System.Linq;
+ using DotNetOpenAuth.OpenId;
+ using DotNetOpenAuth.OpenId.Extensions;
+ using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
+ using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
+ using DotNetOpenAuth.OpenId.RelyingParty;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class ExtensionsInteropHelperRPRequestTests : OpenIdTestBase {
+ private AuthenticationRequest authReq;
+ private ClaimsRequest sreg;
+
+ [TestInitialize]
+ public override void SetUp() {
+ base.SetUp();
+
+ var rp = CreateRelyingParty(true);
+ Identifier identifier = this.GetMockIdentifier(ProtocolVersion.V20);
+ this.authReq = (AuthenticationRequest)rp.CreateRequest(identifier, RPRealmUri, RPUri);
+ this.sreg = new ClaimsRequest {
+ Nickname = DemandLevel.Request,
+ FullName = DemandLevel.Request,
+ BirthDate = DemandLevel.Request,
+ Email = DemandLevel.Require,
+ Country = DemandLevel.Request,
+ PostalCode = DemandLevel.Request,
+ Gender = DemandLevel.Request,
+ Language = DemandLevel.Request,
+ TimeZone = DemandLevel.Request,
+ };
+ }
+
+ /// <summary>
+ /// Verifies that without an Sreg extension to copy from, no AX extension request is added.
+ /// </summary>
+ [TestMethod]
+ public void SpreadSregToAXNoExtensions() {
+ ExtensionsInteropHelper.SpreadSregToAX(this.authReq, AXAttributeFormats.AXSchemaOrg);
+ Assert.AreEqual(0, this.authReq.AppliedExtensions.Count());
+ }
+
+ /// <summary>
+ /// Verifies that Sreg requests are correctly copied to axschema.org AX requests.
+ /// </summary>
+ [TestMethod]
+ public void SpreadSregToAXBasic() {
+ this.authReq.AddExtension(this.sreg);
+ ExtensionsInteropHelper.SpreadSregToAX(this.authReq, AXAttributeFormats.AXSchemaOrg);
+ var ax = this.authReq.AppliedExtensions.OfType<FetchRequest>().Single();
+ Assert.IsFalse(ax.Attributes[WellKnownAttributes.Name.Alias].IsRequired);
+ Assert.IsFalse(ax.Attributes[WellKnownAttributes.Name.FullName].IsRequired);
+ Assert.IsFalse(ax.Attributes[WellKnownAttributes.BirthDate.WholeBirthDate].IsRequired);
+ Assert.IsTrue(ax.Attributes[WellKnownAttributes.Contact.Email].IsRequired);
+ Assert.IsFalse(ax.Attributes[WellKnownAttributes.Contact.HomeAddress.Country].IsRequired);
+ Assert.IsFalse(ax.Attributes[WellKnownAttributes.Contact.HomeAddress.PostalCode].IsRequired);
+ Assert.IsFalse(ax.Attributes[WellKnownAttributes.Person.Gender].IsRequired);
+ Assert.IsFalse(ax.Attributes[WellKnownAttributes.Preferences.Language].IsRequired);
+ Assert.IsFalse(ax.Attributes[WellKnownAttributes.Preferences.TimeZone].IsRequired);
+ }
+
+ /// <summary>
+ /// Verifies that sreg can spread to multiple AX schemas.
+ /// </summary>
+ [TestMethod]
+ public void SpreadSregToAxMultipleSchemas() {
+ this.authReq.AddExtension(this.sreg);
+ ExtensionsInteropHelper.SpreadSregToAX(this.authReq, AXAttributeFormats.AXSchemaOrg | AXAttributeFormats.SchemaOpenIdNet);
+ var ax = this.authReq.AppliedExtensions.OfType<FetchRequest>().Single();
+ Assert.IsTrue(ax.Attributes.Contains(WellKnownAttributes.Name.Alias));
+ Assert.IsTrue(ax.Attributes.Contains(ExtensionsInteropHelper_Accessor.TransformAXFormat(WellKnownAttributes.Name.Alias, AXAttributeFormats.SchemaOpenIdNet)));
+ Assert.IsFalse(ax.Attributes.Contains(ExtensionsInteropHelper_Accessor.TransformAXFormat(WellKnownAttributes.Name.Alias, AXAttributeFormats.OpenIdNetSchema)));
+ }
+
+ /// <summary>
+ /// Verifies no spread if the OP advertises sreg support.
+ /// </summary>
+ [TestMethod]
+ public void SpreadSregToAxNoOpIfOPSupportsSreg() {
+ this.authReq.AddExtension(this.sreg);
+ this.InjectAdvertisedTypeUri(DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.Constants.sreg_ns);
+ ExtensionsInteropHelper.SpreadSregToAX(this.authReq, AXAttributeFormats.All);
+ Assert.IsFalse(this.authReq.AppliedExtensions.OfType<FetchRequest>().Any());
+ }
+
+ /// <summary>
+ /// Verifies a targeted AX request if the OP advertises a recognized type URI format.
+ /// </summary>
+ [TestMethod]
+ public void SpreadSregToAxTargetedAtOPFormat() {
+ this.authReq.AddExtension(this.sreg);
+ this.InjectAdvertisedTypeUri(WellKnownAttributes.Name.FullName);
+ ExtensionsInteropHelper.SpreadSregToAX(this.authReq, AXAttributeFormats.OpenIdNetSchema);
+ var ax = this.authReq.AppliedExtensions.OfType<FetchRequest>().Single();
+ Assert.IsFalse(ax.Attributes.Contains(ExtensionsInteropHelper_Accessor.TransformAXFormat(WellKnownAttributes.Contact.Email, AXAttributeFormats.OpenIdNetSchema)));
+ Assert.IsTrue(ax.Attributes.Contains(WellKnownAttributes.Contact.Email));
+ }
+
+ /// <summary>
+ /// Verifies that TransformAXFormat correctly translates AX schema Type URIs.
+ /// </summary>
+ [TestMethod]
+ public void TransformAXFormatTest() {
+ Assert.AreEqual(WellKnownAttributes.Name.Alias, ExtensionsInteropHelper_Accessor.TransformAXFormat(WellKnownAttributes.Name.Alias, AXAttributeFormats.AXSchemaOrg));
+ Assert.AreEqual("http://schema.openid.net/namePerson/friendly", ExtensionsInteropHelper_Accessor.TransformAXFormat(WellKnownAttributes.Name.Alias, AXAttributeFormats.SchemaOpenIdNet));
+ Assert.AreEqual("http://openid.net/schema/namePerson/friendly", ExtensionsInteropHelper_Accessor.TransformAXFormat(WellKnownAttributes.Name.Alias, AXAttributeFormats.OpenIdNetSchema));
+ }
+
+ /// <summary>
+ /// Injects the advertised type URI into the list of advertised services for the authentication request.
+ /// </summary>
+ /// <param name="typeUri">The type URI.</param>
+ private void InjectAdvertisedTypeUri(string typeUri) {
+ var serviceEndpoint = ServiceEndpoint_Accessor.AttachShadow(((ServiceEndpoint)this.authReq.Provider));
+ serviceEndpoint.ProviderDescription = ProviderEndpointDescription_Accessor.AttachShadow(
+ new ProviderEndpointDescription(
+ serviceEndpoint.ProviderDescription.Endpoint,
+ serviceEndpoint.ProviderDescription.Capabilities.Concat(new[] { typeUri })));
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionsInteropHelperRPResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionsInteropHelperRPResponseTests.cs
new file mode 100644
index 0000000..5fe05c1
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionsInteropHelperRPResponseTests.cs
@@ -0,0 +1,83 @@
+//-----------------------------------------------------------------------
+// <copyright file="ExtensionsInteropHelperRPResponseTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.OpenId {
+ using System.Collections.Generic;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OpenId;
+ using DotNetOpenAuth.OpenId.Extensions;
+ using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
+ using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
+ using DotNetOpenAuth.OpenId.Messages;
+ using DotNetOpenAuth.OpenId.RelyingParty;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class ExtensionsInteropHelperRPResponseTests : OpenIdTestBase {
+ private IAuthenticationResponse response;
+ private IList<IExtensionMessage> extensions;
+
+ [TestInitialize]
+ public override void SetUp() {
+ base.SetUp();
+
+ IndirectSignedResponse responseMessage = new IndirectSignedResponse(Protocol.Default.Version, RPUri);
+ this.extensions = responseMessage.Extensions;
+ this.response = new DotNetOpenAuth.OpenId.RelyingParty.PositiveAnonymousResponse(responseMessage);
+ }
+
+ /// <summary>
+ /// Verifies that with no extensions present, UnifyExtensionsAsSreg returns an empty ClaimsResponse.
+ /// </summary>
+ [TestMethod]
+ public void UnifyExtensionsAsSregNoExtensions() {
+ var sreg = ExtensionsInteropHelper.UnifyExtensionsAsSreg(this.response, true);
+ Assert.IsNotNull(sreg);
+ Assert.IsNull(sreg.Nickname);
+ }
+
+ /// <summary>
+ /// Verifies that with sreg and AX extensions present, the sreg extension is returned.
+ /// </summary>
+ [TestMethod]
+ public void UnifyExtensionsAsSregWithSreg() {
+ var sregInjected = new ClaimsResponse {
+ Nickname = "andy",
+ };
+ var axInjected = new FetchResponse();
+ axInjected.Attributes.Add(WellKnownAttributes.Name.Alias, "nate");
+ this.extensions.Add(sregInjected);
+ this.extensions.Add(axInjected);
+ var sreg = ExtensionsInteropHelper.UnifyExtensionsAsSreg(this.response, true);
+ Assert.AreSame(sregInjected, sreg);
+ Assert.AreEqual("andy", sreg.Nickname);
+ }
+
+ /// <summary>
+ /// Verifies UnifyExtensionsAsSreg correctly converts AX to sreg.
+ /// </summary>
+ [TestMethod]
+ public void UnifyExtensionsAsSregFromAXSchemaOrg() {
+ var axInjected = new FetchResponse();
+ axInjected.Attributes.Add(WellKnownAttributes.Name.Alias, "nate");
+ this.extensions.Add(axInjected);
+ var sreg = ExtensionsInteropHelper.UnifyExtensionsAsSreg(this.response, true);
+ Assert.AreEqual("nate", sreg.Nickname);
+ }
+
+ /// <summary>
+ /// Verifies UnifyExtensionsAsSreg correctly converts AX in a non-standard format to sreg.
+ /// </summary>
+ [TestMethod]
+ public void UnifyExtensionsasSregFromSchemaOpenIdNet() {
+ var axInjected = new FetchResponse();
+ axInjected.Attributes.Add(ExtensionsInteropHelper_Accessor.TransformAXFormat(WellKnownAttributes.Name.Alias, AXAttributeFormats.SchemaOpenIdNet), "nate");
+ this.extensions.Add(axInjected);
+ var sreg = ExtensionsInteropHelper.UnifyExtensionsAsSreg(this.response, true);
+ Assert.AreEqual("nate", sreg.Nickname);
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs b/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs
index 8fa5580..59c818c 100644
--- a/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs
@@ -187,7 +187,16 @@ namespace DotNetOpenAuth.Test.OpenId {
/// </summary>
/// <returns>The new instance.</returns>
protected OpenIdRelyingParty CreateRelyingParty() {
- var rp = new OpenIdRelyingParty(new StandardRelyingPartyApplicationStore());
+ return this.CreateRelyingParty(false);
+ }
+
+ /// <summary>
+ /// Creates a standard <see cref="OpenIdRelyingParty"/> instance for general testing.
+ /// </summary>
+ /// <param name="stateless">if set to <c>true</c> a stateless RP is created.</param>
+ /// <returns>The new instance.</returns>
+ protected OpenIdRelyingParty CreateRelyingParty(bool stateless) {
+ var rp = new OpenIdRelyingParty(stateless ? null : new StandardRelyingPartyApplicationStore());
rp.Channel.WebRequestHandler = this.MockResponder.MockWebRequestHandler;
return rp;
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/Provider/AuthenticationRequestTest.cs b/src/DotNetOpenAuth.Test/OpenId/Provider/AuthenticationRequestTest.cs
index e2a173b..accbd97 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Provider/AuthenticationRequestTest.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Provider/AuthenticationRequestTest.cs
@@ -34,7 +34,7 @@ namespace DotNetOpenAuth.Test.OpenId.Provider {
Assert.IsNotNull(userSetupUrl);
// Now construct a new request as if it had just come in.
- HttpRequestInfo httpRequest = new HttpRequestInfo { Url = userSetupUrl };
+ HttpRequestInfo httpRequest = new HttpRequestInfo { UrlBeforeRewriting = userSetupUrl };
var setupRequest = AuthenticationRequest_Accessor.AttachShadow(provider.GetRequest(httpRequest));
CheckIdRequest_Accessor setupRequestMessage = setupRequest.RequestMessage;
diff --git a/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs b/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs
index 76a46d0..28b2b55 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs
@@ -90,7 +90,7 @@ namespace DotNetOpenAuth.Test.OpenId.Provider {
[TestMethod]
public void GetRequest() {
HttpRequestInfo httpInfo = new HttpRequestInfo();
- httpInfo.Url = new Uri("http://someUri");
+ httpInfo.UrlBeforeRewriting = new Uri("http://someUri");
Assert.IsNull(this.provider.GetRequest(httpInfo), "An irrelevant request should return null.");
var providerDescription = new ProviderEndpointDescription(OpenIdTestBase.OPUri, Protocol.Default.Version);
diff --git a/src/DotNetOpenAuth.Test/OpenId/Provider/PerformanceTests.cs b/src/DotNetOpenAuth.Test/OpenId/Provider/PerformanceTests.cs
new file mode 100644
index 0000000..82384f8
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/OpenId/Provider/PerformanceTests.cs
@@ -0,0 +1,149 @@
+//-----------------------------------------------------------------------
+// <copyright file="PerformanceTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.OpenId.Provider {
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.IO;
+ using System.Linq;
+ using System.Net;
+ using System.Text;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.Messaging.Reflection;
+ using DotNetOpenAuth.OpenId;
+ using DotNetOpenAuth.OpenId.ChannelElements;
+ using DotNetOpenAuth.OpenId.Messages;
+ using DotNetOpenAuth.OpenId.Provider;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class PerformanceTests : OpenIdTestBase {
+ private const string SharedAssociationHandle = "handle";
+ private static readonly TimeSpan TestRunTime = TimeSpan.FromSeconds(3);
+ private OpenIdProvider provider;
+
+ [TestInitialize]
+ public override void SetUp() {
+ base.SetUp();
+
+ this.provider = CreateProvider();
+ }
+
+ [TestMethod]
+ public void AssociateDH() {
+ var associateRequest = this.CreateAssociateRequest(OPUri);
+ Stopwatch timer = new Stopwatch();
+ timer.Start();
+ int iterations;
+ for (iterations = 0; timer.ElapsedMilliseconds < TestRunTime.TotalMilliseconds; iterations++) {
+ IRequest request = this.provider.GetRequest(associateRequest);
+ var response = this.provider.PrepareResponse(request);
+ Assert.IsInstanceOfType(response.OriginalMessage, typeof(AssociateSuccessfulResponse));
+ }
+ timer.Stop();
+ double executionsPerSecond = GetExecutionsPerSecond(iterations, timer);
+ TestContext.WriteLine("Created {0} associations in {1}, or {2} per second.", iterations, timer.Elapsed, executionsPerSecond);
+ Assert.IsTrue(executionsPerSecond >= 2, "Too slow");
+ }
+
+ [TestMethod]
+ public void AssociateClearText() {
+ var associateRequest = this.CreateAssociateRequest(OPUriSsl); // SSL will cause a plaintext association
+ Stopwatch timer = new Stopwatch();
+ timer.Start();
+ int iterations;
+ for (iterations = 0; timer.ElapsedMilliseconds < TestRunTime.TotalMilliseconds; iterations++) {
+ IRequest request = this.provider.GetRequest(associateRequest);
+ var response = this.provider.PrepareResponse(request);
+ Assert.IsInstanceOfType(response.OriginalMessage, typeof(AssociateSuccessfulResponse));
+ }
+ timer.Stop();
+ double executionsPerSecond = GetExecutionsPerSecond(iterations, timer);
+ TestContext.WriteLine("Created {0} associations in {1}, or {2} per second.", iterations, timer.Elapsed, executionsPerSecond);
+ Assert.IsTrue(executionsPerSecond > 1000, "Too slow.");
+ }
+
+ [TestMethod]
+ public void CheckIdSharedHmacSha1Association() {
+ Protocol protocol = Protocol.Default;
+ string assocType = protocol.Args.SignatureAlgorithm.HMAC_SHA1;
+ double executionsPerSecond = this.ParameterizedCheckIdTest(protocol, assocType);
+ Assert.IsTrue(executionsPerSecond > 500, "Too slow");
+ }
+
+ [TestMethod]
+ public void CheckIdSharedHmacSha256Association() {
+ Protocol protocol = Protocol.Default;
+ string assocType = protocol.Args.SignatureAlgorithm.HMAC_SHA256;
+ double executionsPerSecond = this.ParameterizedCheckIdTest(protocol, assocType);
+ Assert.IsTrue(executionsPerSecond > 400, "Too slow");
+ }
+
+ private static double GetExecutionsPerSecond(int iterations, Stopwatch timer) {
+ return (double)iterations / (timer.ElapsedMilliseconds / 1000);
+ }
+
+ private double ParameterizedCheckIdTest(Protocol protocol, string assocType) {
+ Association assoc = HmacShaAssociation.Create(
+ protocol,
+ assocType,
+ AssociationRelyingPartyType.Smart,
+ this.provider.SecuritySettings);
+ this.provider.AssociationStore.StoreAssociation(AssociationRelyingPartyType.Smart, assoc);
+ var checkidRequest = this.CreateCheckIdRequest(true);
+ Stopwatch timer = new Stopwatch();
+ timer.Start();
+ int iterations;
+ for (iterations = 0; timer.ElapsedMilliseconds < TestRunTime.TotalMilliseconds; iterations++) {
+ var request = (IAuthenticationRequest)this.provider.GetRequest(checkidRequest);
+ request.IsAuthenticated = true;
+ var response = this.provider.PrepareResponse(request);
+ Assert.IsInstanceOfType(response.OriginalMessage, typeof(PositiveAssertionResponse));
+ }
+ timer.Stop();
+ double executionsPerSecond = GetExecutionsPerSecond(iterations, timer);
+ TestContext.WriteLine("Responded to {0} checkid messages in {1}; or {2} authentications per second.", iterations, timer.Elapsed, executionsPerSecond);
+ return executionsPerSecond;
+ }
+
+ private HttpRequestInfo CreateAssociateRequest(Uri opEndpoint) {
+ var rp = CreateRelyingParty(true);
+ AssociateRequest associateMessage = AssociateRequest.Create(rp.SecuritySettings, new ProviderEndpointDescription(opEndpoint, Protocol.Default.Version));
+ Channel rpChannel = rp.Channel;
+ MemoryStream ms = new MemoryStream();
+ StreamWriter mswriter = new StreamWriter(ms);
+ mswriter.Write(MessagingUtilities.CreateQueryString(rpChannel.MessageDescriptions.GetAccessor(associateMessage)));
+ mswriter.Flush();
+ ms.Position = 0;
+ var headers = new WebHeaderCollection();
+ headers.Add(HttpRequestHeader.ContentType, Channel.HttpFormUrlEncoded);
+ var httpRequest = new HttpRequestInfo("POST", opEndpoint, opEndpoint.PathAndQuery, headers, ms);
+ return httpRequest;
+ }
+
+ private HttpRequestInfo CreateCheckIdRequest(bool sharedAssociation) {
+ var rp = CreateRelyingParty(true);
+ CheckIdRequest checkidMessage = new CheckIdRequest(
+ Protocol.Default.Version,
+ OPUri,
+ DotNetOpenAuth.OpenId.RelyingParty.AuthenticationRequestMode.Setup);
+ if (sharedAssociation) {
+ checkidMessage.AssociationHandle = SharedAssociationHandle;
+ }
+ checkidMessage.ClaimedIdentifier = OPLocalIdentifiers[0];
+ checkidMessage.LocalIdentifier = OPLocalIdentifiers[0];
+ checkidMessage.Realm = RPRealmUri;
+ checkidMessage.ReturnTo = RPUri;
+ Channel rpChannel = rp.Channel;
+ UriBuilder receiver = new UriBuilder(OPUri);
+ receiver.Query = MessagingUtilities.CreateQueryString(rpChannel.MessageDescriptions.GetAccessor(checkidMessage));
+ var headers = new WebHeaderCollection();
+ var httpRequest = new HttpRequestInfo("GET", receiver.Uri, receiver.Uri.PathAndQuery, headers, null);
+ return httpRequest;
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.Test/OpenId/ProviderEndpointDescriptionTests.cs b/src/DotNetOpenAuth.Test/OpenId/ProviderEndpointDescriptionTests.cs
new file mode 100644
index 0000000..005b8a0
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/OpenId/ProviderEndpointDescriptionTests.cs
@@ -0,0 +1,62 @@
+//-----------------------------------------------------------------------
+// <copyright file="ProviderEndpointDescriptionTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.OpenId {
+ using System;
+ using DotNetOpenAuth.OpenId;
+ using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
+ using DotNetOpenAuth.OpenId.Messages;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class ProviderEndpointDescriptionTests : OpenIdTestBase {
+ private ProviderEndpointDescription se;
+
+ private string[] v20TypeUris = { Protocol.V20.ClaimedIdentifierServiceTypeURI };
+
+ [TestInitialize]
+ public override void SetUp() {
+ base.SetUp();
+
+ this.se = new ProviderEndpointDescription(OPUri, Protocol.V20.Version);
+ }
+
+ [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ public void IsExtensionSupportedNullType() {
+ this.se.IsExtensionSupported((Type)null);
+ }
+
+ [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ public void IsExtensionSupportedNullString() {
+ this.se.IsExtensionSupported((string)null);
+ }
+
+ [TestMethod, ExpectedException(typeof(ArgumentException))]
+ public void IsExtensionSupportedEmptyString() {
+ this.se.IsExtensionSupported(string.Empty);
+ }
+
+ [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ public void IsExtensionSupportedNullExtension() {
+ this.se.IsExtensionSupported((IOpenIdMessageExtension)null);
+ }
+
+ [TestMethod]
+ public void IsExtensionSupported() {
+ this.se = new ProviderEndpointDescription(OPUri, this.v20TypeUris);
+ Assert.IsFalse(this.se.IsExtensionSupported<ClaimsRequest>());
+ Assert.IsFalse(this.se.IsExtensionSupported(new ClaimsRequest()));
+ Assert.IsFalse(this.se.IsExtensionSupported("http://someextension/typeuri"));
+
+ this.se = new ProviderEndpointDescription(
+ OPUri,
+ new[] { Protocol.V20.ClaimedIdentifierServiceTypeURI, "http://someextension", Constants.sreg_ns });
+ Assert.IsTrue(this.se.IsExtensionSupported<ClaimsRequest>());
+ Assert.IsTrue(this.se.IsExtensionSupported(new ClaimsRequest()));
+ Assert.IsTrue(this.se.IsExtensionSupported("http://someextension"));
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/PositiveAnonymousResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/PositiveAnonymousResponseTests.cs
index 6452420..1418513 100644
--- a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/PositiveAnonymousResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/PositiveAnonymousResponseTests.cs
@@ -36,7 +36,21 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
Assert.IsNull(response.ClaimedIdentifier);
Assert.IsNull(response.FriendlyIdentifierForDisplay);
Assert.IsNull(response.Exception);
+ Assert.IsNull(response.Provider);
Assert.AreSame(ext, response.GetUntrustedExtension<ClaimsResponse>());
}
+
+ /// <summary>
+ /// Verifies the Provider property.
+ /// </summary>
+ [TestMethod]
+ public void ProviderTest() {
+ var responseMessage = new IndirectSignedResponse(Protocol.V20.Version, this.returnTo);
+ responseMessage.ProviderEndpoint = OPUri;
+ var response = new PositiveAnonymousResponse(responseMessage);
+ Assert.IsNotNull(response.Provider);
+ Assert.AreEqual(OPUri, response.Provider.Uri);
+ Assert.AreEqual(responseMessage.Version, response.Provider.Version);
+ }
}
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/RelyingPartySecuritySettingsTests.cs b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/RelyingPartySecuritySettingsTests.cs
index 3f1cea0..851939e 100644
--- a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/RelyingPartySecuritySettingsTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/RelyingPartySecuritySettingsTests.cs
@@ -40,5 +40,29 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
this.settings.RequireSsl = false;
Assert.IsFalse(this.settings.RequireSsl);
}
+
+ /// <summary>
+ /// Verifies that the <see cref="RelyingPartySecuritySettings.RequireDirectedIdentity"/>
+ /// property getter/setter are implemented correctly.
+ /// </summary>
+ [TestMethod]
+ public void RequireDirectedIdentity() {
+ this.settings.RequireDirectedIdentity = true;
+ Assert.IsTrue(this.settings.RequireDirectedIdentity);
+ this.settings.RequireDirectedIdentity = false;
+ Assert.IsFalse(this.settings.RequireDirectedIdentity);
+ }
+
+ /// <summary>
+ /// Verifies that the <see cref="RelyingPartySecuritySettings.RequireAssociation"/>
+ /// property getter/setter are implemented correctly.
+ /// </summary>
+ [TestMethod]
+ public void RequireAssociation() {
+ this.settings.RequireAssociation = true;
+ Assert.IsTrue(this.settings.RequireAssociation);
+ this.settings.RequireAssociation = false;
+ Assert.IsFalse(this.settings.RequireAssociation);
+ }
}
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/ServiceEndpointTests.cs b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/ServiceEndpointTests.cs
index 7b71eef..bd09bc9 100644
--- a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/ServiceEndpointTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/ServiceEndpointTests.cs
@@ -173,46 +173,6 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
Assert.AreEqual("=!9B72.7DD1.50A9.5CCD", se.FriendlyIdentifierForDisplay);
}
- [TestMethod, ExpectedException(typeof(ArgumentNullException))]
- public void IsExtensionSupportedNullType() {
- ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedXri, this.userSuppliedXri, this.localId, new ProviderEndpointDescription(this.providerEndpoint, this.v20TypeUris), this.servicePriority, this.uriPriority);
- se.IsExtensionSupported((Type)null);
- }
-
- [TestMethod, ExpectedException(typeof(ArgumentNullException))]
- public void IsExtensionSupportedNullString() {
- ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedXri, this.userSuppliedXri, this.localId, new ProviderEndpointDescription(this.providerEndpoint, this.v20TypeUris), this.servicePriority, this.uriPriority);
- se.IsExtensionSupported((string)null);
- }
-
- [TestMethod, ExpectedException(typeof(ArgumentException))]
- public void IsExtensionSupportedEmptyString() {
- ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedXri, this.userSuppliedXri, this.localId, new ProviderEndpointDescription(this.providerEndpoint, this.v20TypeUris), this.servicePriority, this.uriPriority);
- se.IsExtensionSupported(string.Empty);
- }
-
- [TestMethod, ExpectedException(typeof(ArgumentNullException))]
- public void IsExtensionSupportedNullExtension() {
- ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedXri, this.userSuppliedXri, this.localId, new ProviderEndpointDescription(this.providerEndpoint, this.v20TypeUris), this.servicePriority, this.uriPriority);
- se.IsExtensionSupported((IOpenIdMessageExtension)null);
- }
-
- [TestMethod]
- public void IsExtensionSupported() {
- ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedXri, this.userSuppliedXri, this.localId, new ProviderEndpointDescription(this.providerEndpoint, this.v20TypeUris), this.servicePriority, this.uriPriority);
- Assert.IsFalse(se.IsExtensionSupported<ClaimsRequest>());
- Assert.IsFalse(se.IsExtensionSupported(new ClaimsRequest()));
- Assert.IsFalse(se.IsExtensionSupported("http://someextension/typeuri"));
-
- ProviderEndpointDescription ped = new ProviderEndpointDescription(
- OPUri,
- new[] { Protocol.V20.ClaimedIdentifierServiceTypeURI, "http://someextension", Constants.sreg_ns });
- se = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedXri, this.userSuppliedXri, this.localId, ped, this.servicePriority, this.uriPriority);
- Assert.IsTrue(se.IsExtensionSupported<ClaimsRequest>());
- Assert.IsTrue(se.IsExtensionSupported(new ClaimsRequest()));
- Assert.IsTrue(se.IsExtensionSupported("http://someextension"));
- }
-
[TestMethod]
public void IsTypeUriPresent() {
ServiceEndpoint se = ServiceEndpoint.CreateForClaimedIdentifier(this.claimedXri, this.userSuppliedXri, this.localId, new ProviderEndpointDescription(this.providerEndpoint, this.v20TypeUris), this.servicePriority, this.uriPriority);
diff --git a/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs b/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs
index 92379da..5a5182f 100644
--- a/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/UriIdentifierTests.cs
@@ -391,7 +391,7 @@ namespace DotNetOpenAuth.Test.OpenId {
// the ServiceEndpoint.Equals method.
Assert.AreEqual(expectSreg ? 2 : 1, se.ProviderSupportedServiceTypeUris.Count);
Assert.IsTrue(se.ProviderSupportedServiceTypeUris.Contains(protocol.ClaimedIdentifierServiceTypeURI));
- Assert.AreEqual(expectSreg, se.IsExtensionSupported(new ClaimsRequest()));
+ Assert.AreEqual(expectSreg, se.IsExtensionSupported<ClaimsRequest>());
}
private void DiscoverXrds(string page, ProtocolVersion version, Identifier expectedLocalId, string providerEndpoint) {