summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.Test')
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs101
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs2
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs15
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/Reflection/MessagePartTests.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/MockOpenIdExtension.cs9
-rw-r--r--src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs8
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs10
-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/RelyingParty/PositiveAuthenticationResponseTests.cs4
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/RelyingParty/RelyingPartySecuritySettingsTests.cs8
13 files changed, 140 insertions, 27 deletions
diff --git a/src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs b/src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs
index dd59bae..fd77746 100644
--- a/src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs
@@ -5,6 +5,8 @@
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Test.Messaging {
+ using System;
+ using System.Collections.Specialized;
using System.Web;
using DotNetOpenAuth.Messaging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -26,9 +28,54 @@ 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);
}
+ // All these tests are ineffective because ServerVariables[] cannot be set.
+ ////[TestMethod]
+ ////public void CtorRequestWithDifferentPublicHttpHost() {
+ //// HttpRequest request = new HttpRequest("file", "http://someserver?a=b", "a=b");
+ //// request.ServerVariables["HTTP_HOST"] = "publichost";
+ //// HttpRequestInfo info = new HttpRequestInfo(request);
+ //// Assert.AreEqual("publichost", info.UrlBeforeRewriting.Host);
+ //// Assert.AreEqual(80, info.UrlBeforeRewriting.Port);
+ //// Assert.AreEqual(request.Url.Query, info.Query);
+ //// Assert.AreEqual(request.QueryString["a"], info.QueryString["a"]);
+ ////}
+
+ ////[TestMethod]
+ ////public void CtorRequestWithDifferentPublicHttpsHost() {
+ //// HttpRequest request = new HttpRequest("file", "https://someserver?a=b", "a=b");
+ //// request.ServerVariables["HTTP_HOST"] = "publichost";
+ //// HttpRequestInfo info = new HttpRequestInfo(request);
+ //// Assert.AreEqual("publichost", info.UrlBeforeRewriting.Host);
+ //// Assert.AreEqual(443, info.UrlBeforeRewriting.Port);
+ //// Assert.AreEqual(request.Url.Query, info.Query);
+ //// Assert.AreEqual(request.QueryString["a"], info.QueryString["a"]);
+ ////}
+
+ ////[TestMethod]
+ ////public void CtorRequestWithDifferentPublicHostNonstandardPort() {
+ //// HttpRequest request = new HttpRequest("file", "http://someserver?a=b", "a=b");
+ //// request.ServerVariables["HTTP_HOST"] = "publichost:550";
+ //// HttpRequestInfo info = new HttpRequestInfo(request);
+ //// Assert.AreEqual("publichost", info.UrlBeforeRewriting.Host);
+ //// Assert.AreEqual(550, info.UrlBeforeRewriting.Port);
+ //// Assert.AreEqual(request.Url.Query, info.Query);
+ //// Assert.AreEqual(request.QueryString["a"], info.QueryString["a"]);
+ ////}
+
+ ////[TestMethod]
+ ////public void CtorRequestWithDifferentPublicIPv6Host() {
+ //// HttpRequest request = new HttpRequest("file", "http://[fe80::587e:c6e5:d3aa:657a]:8089/v3.1/", "");
+ //// request.ServerVariables["HTTP_HOST"] = "[fe80::587e:c6e5:d3aa:657b]:8089";
+ //// HttpRequestInfo info = new HttpRequestInfo(request);
+ //// Assert.AreEqual("[fe80::587e:c6e5:d3aa:657b]", info.UrlBeforeRewriting.Host);
+ //// Assert.AreEqual(8089, info.UrlBeforeRewriting.Port);
+ //// Assert.AreEqual(request.Url.Query, info.Query);
+ ////}
+
/// <summary>
/// Checks that a property dependent on another null property
/// doesn't generate a NullReferenceException.
@@ -47,5 +94,59 @@ namespace DotNetOpenAuth.Test.Messaging {
HttpRequestInfo info = new HttpRequestInfo();
Assert.IsNull(info.QueryString["hi"]);
}
+
+ /// <summary>
+ /// Verifies SSL forwarders are correctly handled when they supply X_FORWARDED_PROTO and HOST
+ /// </summary>
+ [TestMethod]
+ public void GetPublicFacingUrlSSLForwarder1() {
+ HttpRequest req = new HttpRequest("a.aspx", "http://someinternalhost/a.aspx?a=b", "a=b");
+ var serverVariables = new NameValueCollection();
+ serverVariables["HTTP_X_FORWARDED_PROTO"] = "https";
+ serverVariables["HTTP_HOST"] = "somehost";
+ Uri actual = HttpRequestInfo.GetPublicFacingUrl(req, serverVariables);
+ Uri expected = new Uri("https://somehost/a.aspx?a=b");
+ Assert.AreEqual(expected, actual);
+ }
+
+ /// <summary>
+ /// Verifies SSL forwarders are correctly handled when they supply X_FORWARDED_PROTO and HOST:port
+ /// </summary>
+ [TestMethod]
+ public void GetPublicFacingUrlSSLForwarder2() {
+ HttpRequest req = new HttpRequest("a.aspx", "http://someinternalhost/a.aspx?a=b", "a=b");
+ var serverVariables = new NameValueCollection();
+ serverVariables["HTTP_X_FORWARDED_PROTO"] = "https";
+ serverVariables["HTTP_HOST"] = "somehost:999";
+ Uri actual = HttpRequestInfo.GetPublicFacingUrl(req, serverVariables);
+ Uri expected = new Uri("https://somehost:999/a.aspx?a=b");
+ Assert.AreEqual(expected, actual);
+ }
+
+ /// <summary>
+ /// Verifies SSL forwarders are correctly handled when they supply just HOST
+ /// </summary>
+ [TestMethod]
+ public void GetPublicFacingUrlSSLForwarder3() {
+ HttpRequest req = new HttpRequest("a.aspx", "http://someinternalhost/a.aspx?a=b", "a=b");
+ var serverVariables = new NameValueCollection();
+ serverVariables["HTTP_HOST"] = "somehost";
+ Uri actual = HttpRequestInfo.GetPublicFacingUrl(req, serverVariables);
+ Uri expected = new Uri("http://somehost/a.aspx?a=b");
+ Assert.AreEqual(expected, actual);
+ }
+
+ /// <summary>
+ /// Verifies SSL forwarders are correctly handled when they supply just HOST:port
+ /// </summary>
+ [TestMethod]
+ public void GetPublicFacingUrlSSLForwarder4() {
+ HttpRequest req = new HttpRequest("a.aspx", "http://someinternalhost/a.aspx?a=b", "a=b");
+ var serverVariables = new NameValueCollection();
+ serverVariables["HTTP_HOST"] = "somehost:79";
+ Uri actual = HttpRequestInfo.GetPublicFacingUrl(req, serverVariables);
+ Uri expected = new Uri("http://somehost:79/a.aspx?a=b");
+ Assert.AreEqual(expected, actual);
+ }
}
}
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/Messaging/Reflection/MessageDictionaryTests.cs b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs
index 679e761..b9e7436 100644
--- a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs
@@ -331,17 +331,26 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
/// A test for System.Collections.Generic.ICollection&lt;System.Collections.Generic.KeyValuePair&lt;System.String,System.String&lt;&lt;.Clear
/// </summary>
[TestMethod]
- public void Clear() {
- ICollection<KeyValuePair<string, string>> target = this.MessageDescriptions.GetAccessor(this.message);
+ public void ClearValues() {
+ MessageDictionary target = this.MessageDescriptions.GetAccessor(this.message);
IDictionary<string, string> targetAsDictionary = (IDictionary<string, string>)target;
this.message.Name = "Andrew";
this.message.Age = 15;
targetAsDictionary["extra"] = "value";
- target.Clear();
+ target.ClearValues();
Assert.AreEqual(2, target.Count, "Clearing should remove all keys except for declared non-nullable structs.");
Assert.IsFalse(targetAsDictionary.ContainsKey("extra"));
Assert.IsNull(this.message.Name);
Assert.AreEqual(0, this.message.Age);
}
+
+ /// <summary>
+ /// Verifies that the Clear method throws the expected exception.
+ /// </summary>
+ [TestMethod, ExpectedException(typeof(NotSupportedException))]
+ public void Clear() {
+ MessageDictionary target = this.MessageDescriptions.GetAccessor(this.message);
+ target.Clear();
+ }
}
}
diff --git a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessagePartTests.cs b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessagePartTests.cs
index 0215801..19e6a82 100644
--- a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessagePartTests.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessagePartTests.cs
@@ -82,7 +82,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection {
Assert.AreEqual("abc", part.GetValue(message));
}
- [TestMethod, ExpectedException(typeof(ArgumentException))]
+ [TestMethod, ExpectedException(typeof(ProtocolException))]
public void ConstantFieldMemberInvalidValues() {
var message = new MessageWithConstantField();
MessagePart part = GetMessagePart(message.GetType(), "ConstantField");
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 2d14bc8..10b0261 100644
--- a/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/CoordinatingOAuthChannel.cs
@@ -110,7 +110,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/MockOpenIdExtension.cs b/src/DotNetOpenAuth.Test/Mocks/MockOpenIdExtension.cs
index 0010bb9..f9d418f 100644
--- a/src/DotNetOpenAuth.Test/Mocks/MockOpenIdExtension.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/MockOpenIdExtension.cs
@@ -48,6 +48,15 @@ namespace DotNetOpenAuth.Test.Mocks {
get { return Enumerable.Empty<string>(); }
}
+ /// <summary>
+ /// Gets or sets a value indicating whether this extension was
+ /// signed by the OpenID Provider.
+ /// </summary>
+ /// <value>
+ /// <c>true</c> if this instance is signed by the provider; otherwise, <c>false</c>.
+ /// </value>
+ public bool IsSignedByRemoteParty { get; set; }
+
#endregion
#region IMessage Properties
diff --git a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
index 82d211a..856f164 100644
--- a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
+++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
@@ -83,9 +83,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
@@ -288,7 +288,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,
@@ -300,7 +300,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/OpenId/ChannelElements/ExtensionsBindingElementTests.cs b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs
index 28fe2cc..12f6e7a 100644
--- a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs
@@ -31,7 +31,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements {
this.factory = new StandardOpenIdExtensionFactory();
this.factory.RegisterExtension(MockOpenIdExtension.Factory);
- this.rpElement = new ExtensionsBindingElement(this.factory, new RelyingPartySecuritySettings());
+ this.rpElement = new ExtensionsBindingElement(this.factory);
this.rpElement.Channel = new TestChannel(this.MessageDescriptions);
this.request = new SignedResponseRequest(Protocol.Default.Version, OpenIdTestBase.OPUri, AuthenticationRequestMode.Immediate);
}
@@ -113,15 +113,17 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements {
/// Verifies that unsigned extension responses (where any or all fields are unsigned) are ignored.
/// </summary>
[TestMethod]
- public void UnsignedExtensionsAreIgnored() {
+ public void ExtensionsAreIdentifiedAsSignedOrUnsigned() {
Protocol protocol = Protocol.Default;
OpenIdCoordinator coordinator = new OpenIdCoordinator(
rp => {
RegisterMockExtension(rp.Channel);
var response = rp.Channel.ReadFromRequest<IndirectSignedResponse>();
- Assert.AreEqual(1, response.Extensions.Count, "Signed extension should have been received.");
+ Assert.AreEqual(1, response.SignedExtensions.Count(), "Signed extension should have been received.");
+ Assert.AreEqual(0, response.UnsignedExtensions.Count(), "No unsigned extension should be present.");
response = rp.Channel.ReadFromRequest<IndirectSignedResponse>();
- Assert.AreEqual(0, response.Extensions.Count, "Unsigned extension should have been ignored.");
+ Assert.AreEqual(0, response.SignedExtensions.Count(), "No signed extension should have been received.");
+ Assert.AreEqual(1, response.UnsignedExtensions.Count(), "Unsigned extension should have been received.");
},
op => {
RegisterMockExtension(op.Channel);
diff --git a/src/DotNetOpenAuth.Test/OpenId/Provider/AuthenticationRequestTest.cs b/src/DotNetOpenAuth.Test/OpenId/Provider/AuthenticationRequestTest.cs
index cb898be..9803095 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 82f9ecc..0a6cdcc 100644
--- a/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs
@@ -91,7 +91,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/RelyingParty/PositiveAuthenticationResponseTests.cs b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/PositiveAuthenticationResponseTests.cs
index c5257a6..083b988 100644
--- a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/PositiveAuthenticationResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/PositiveAuthenticationResponseTests.cs
@@ -39,8 +39,8 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
Assert.IsNull(authResponse.Exception);
Assert.AreEqual<string>(assertion.ClaimedIdentifier, authResponse.ClaimedIdentifier);
Assert.AreEqual<string>(authResponseAccessor.endpoint.FriendlyIdentifierForDisplay, authResponse.FriendlyIdentifierForDisplay);
- Assert.AreSame(extension, authResponse.GetExtension(typeof(ClaimsResponse)));
- Assert.AreSame(extension, authResponse.GetExtension<ClaimsResponse>());
+ Assert.AreSame(extension, authResponse.GetUntrustedExtension(typeof(ClaimsResponse)));
+ Assert.AreSame(extension, authResponse.GetUntrustedExtension<ClaimsResponse>());
Assert.IsNull(authResponse.GetCallbackArgument("a"));
Assert.AreEqual(0, authResponse.GetCallbackArguments().Count);
}
diff --git a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/RelyingPartySecuritySettingsTests.cs b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/RelyingPartySecuritySettingsTests.cs
index 8c5dc6a..cb5fbb5 100644
--- a/src/DotNetOpenAuth.Test/OpenId/RelyingParty/RelyingPartySecuritySettingsTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/RelyingParty/RelyingPartySecuritySettingsTests.cs
@@ -53,13 +53,5 @@ namespace DotNetOpenAuth.Test.OpenId.RelyingParty {
this.settings.RequireSsl = !this.settings.RequireSsl;
Assert.IsTrue(requireSslChanged);
}
-
- /// <summary>
- /// Verifies default value for AllowUnsignedIncomingExtensions.
- /// </summary>
- [TestMethod]
- public void AllowUnsignedIncomingExtensionsDefault() {
- Assert.IsFalse(this.settings.AllowUnsignedIncomingExtensions);
- }
}
}