Enable tests for CoreCLR.

This commit is contained in:
Chris R 2015-10-16 12:40:39 -07:00
parent f588677bb4
commit 42cba79e01
9 changed files with 58 additions and 58 deletions

View File

@ -1020,14 +1020,8 @@ namespace Microsoft.AspNet.Authentication.Cookies
{ {
xml.Add(result.Properties.Select(extra => new XElement("extra", new XAttribute("type", extra.Key), new XAttribute("value", extra.Value)))); xml.Add(result.Properties.Select(extra => new XElement("extra", new XAttribute("type", extra.Key), new XAttribute("value", extra.Value))));
} }
using (var memory = new MemoryStream()) var xmlBytes = Encoding.UTF8.GetBytes(xml.ToString());
{ res.Body.Write(xmlBytes, 0, xmlBytes.Length);
using (var writer = new XmlTextWriter(memory, Encoding.UTF8))
{
xml.WriteTo(writer);
}
res.Body.Write(memory.ToArray(), 0, memory.ToArray().Length);
}
} }
private static async Task<Transaction> SendAsync(TestServer server, string uri, string cookieHeader = null) private static async Task<Transaction> SendAsync(TestServer server, string uri, string cookieHeader = null)

View File

@ -176,7 +176,7 @@ namespace Microsoft.AspNet.Authentication.Facebook
{ {
Sender = req => Sender = req =>
{ {
if (req.RequestUri.GetLeftPart(UriPartial.Path) == FacebookDefaults.TokenEndpoint) if (req.RequestUri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped) == FacebookDefaults.TokenEndpoint)
{ {
var res = new HttpResponseMessage(HttpStatusCode.OK); var res = new HttpResponseMessage(HttpStatusCode.OK);
var tokenResponse = new Dictionary<string, string> var tokenResponse = new Dictionary<string, string>
@ -186,8 +186,8 @@ namespace Microsoft.AspNet.Authentication.Facebook
res.Content = new FormUrlEncodedContent(tokenResponse); res.Content = new FormUrlEncodedContent(tokenResponse);
return res; return res;
} }
if (req.RequestUri.GetLeftPart(UriPartial.Path) == if (req.RequestUri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped) ==
new Uri(customUserInfoEndpoint).GetLeftPart(UriPartial.Path)) new Uri(customUserInfoEndpoint).GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped))
{ {
finalUserInfoEndpoint = req.RequestUri.ToString(); finalUserInfoEndpoint = req.RequestUri.ToString();
var res = new HttpResponseMessage(HttpStatusCode.OK); var res = new HttpResponseMessage(HttpStatusCode.OK);

View File

@ -307,7 +307,7 @@ namespace Microsoft.AspNet.Authentication.Google
token_type = "Bearer" token_type = "Bearer"
}); });
} }
else if (req.RequestUri.GetLeftPart(UriPartial.Path) == "https://www.googleapis.com/plus/v1/people/me") else if (req.RequestUri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped) == "https://www.googleapis.com/plus/v1/people/me")
{ {
return ReturnJsonResponse(new return ReturnJsonResponse(new
{ {
@ -497,7 +497,7 @@ namespace Microsoft.AspNet.Authentication.Google
refresh_token = "Test Refresh Token" refresh_token = "Test Refresh Token"
}); });
} }
else if (req.RequestUri.GetLeftPart(UriPartial.Path) == "https://www.googleapis.com/plus/v1/people/me") else if (req.RequestUri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped) == "https://www.googleapis.com/plus/v1/people/me")
{ {
return ReturnJsonResponse(new return ReturnJsonResponse(new
{ {
@ -577,7 +577,7 @@ namespace Microsoft.AspNet.Authentication.Google
refresh_token = "Test Refresh Token" refresh_token = "Test Refresh Token"
}); });
} }
else if (req.RequestUri.GetLeftPart(UriPartial.Path) == "https://www.googleapis.com/plus/v1/people/me") else if (req.RequestUri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped) == "https://www.googleapis.com/plus/v1/people/me")
{ {
return ReturnJsonResponse(new return ReturnJsonResponse(new
{ {
@ -667,7 +667,7 @@ namespace Microsoft.AspNet.Authentication.Google
refresh_token = "Test Refresh Token" refresh_token = "Test Refresh Token"
}); });
} }
else if (req.RequestUri.GetLeftPart(UriPartial.Path) == "https://www.googleapis.com/plus/v1/people/me") else if (req.RequestUri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped) == "https://www.googleapis.com/plus/v1/people/me")
{ {
return ReturnJsonResponse(new return ReturnJsonResponse(new
{ {

View File

@ -126,7 +126,7 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount
refresh_token = "Test Refresh Token" refresh_token = "Test Refresh Token"
}); });
} }
else if (req.RequestUri.GetLeftPart(UriPartial.Path) == "https://apis.live.net/v5.0/me") else if (req.RequestUri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped) == "https://apis.live.net/v5.0/me")
{ {
return ReturnJsonResponse(new return ReturnJsonResponse(new
{ {

View File

@ -19,7 +19,6 @@ using Microsoft.AspNet.TestHost;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.WebEncoders; using Microsoft.Extensions.WebEncoders;
using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Moq;
using Xunit; using Xunit;
namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
@ -151,24 +150,43 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
private static void SetProtocolMessageOptions(OpenIdConnectOptions options) private static void SetProtocolMessageOptions(OpenIdConnectOptions options)
{ {
var mockOpenIdConnectMessage = new Mock<OpenIdConnectMessage>(); var fakeOpenIdRequestMessage = new FakeOpenIdConnectMessage(ExpectedAuthorizeRequest, ExpectedLogoutRequest);
mockOpenIdConnectMessage.Setup(m => m.CreateAuthenticationRequestUrl()).Returns(ExpectedAuthorizeRequest);
mockOpenIdConnectMessage.Setup(m => m.CreateLogoutRequestUrl()).Returns(ExpectedLogoutRequest);
options.AutomaticChallenge = true; options.AutomaticChallenge = true;
options.Events = new OpenIdConnectEvents() options.Events = new OpenIdConnectEvents()
{ {
OnRedirectToAuthenticationEndpoint = (context) => OnRedirectToAuthenticationEndpoint = (context) =>
{ {
context.ProtocolMessage = mockOpenIdConnectMessage.Object; context.ProtocolMessage = fakeOpenIdRequestMessage;
return Task.FromResult<object>(null); return Task.FromResult(0);
}, },
OnRedirectToEndSessionEndpoint = (context) => OnRedirectToEndSessionEndpoint = (context) =>
{ {
context.ProtocolMessage = mockOpenIdConnectMessage.Object; context.ProtocolMessage = fakeOpenIdRequestMessage;
return Task.FromResult<object>(null); return Task.FromResult(0);
} }
}; };
} }
private class FakeOpenIdConnectMessage : OpenIdConnectMessage
{
private readonly string _authorizeRequest;
private readonly string _logoutRequest;
public FakeOpenIdConnectMessage(string authorizeRequest, string logoutRequest)
{
_authorizeRequest = authorizeRequest;
_logoutRequest = logoutRequest;
}
public override string CreateAuthenticationRequestUrl()
{
return _authorizeRequest;
}
public override string CreateLogoutRequestUrl()
{
return _logoutRequest;
}
}
/// <summary> /// <summary>
/// Tests for users who want to add 'state'. There are two ways to do it. /// Tests for users who want to add 'state'. There are two ways to do it.

View File

@ -60,14 +60,8 @@ namespace Microsoft.AspNet.Authentication
new XAttribute("issuer", claim.Issuer)))); new XAttribute("issuer", claim.Issuer))));
} }
} }
using (var memory = new MemoryStream()) var xmlBytes = Encoding.UTF8.GetBytes(xml.ToString());
{ res.Body.Write(xmlBytes, 0, xmlBytes.Length);
using (var writer = new XmlTextWriter(memory, Encoding.UTF8))
{
xml.WriteTo(writer);
}
res.Body.Write(memory.ToArray(), 0, memory.ToArray().Length);
}
} }
} }
} }

View File

@ -13,14 +13,13 @@
"Microsoft.AspNet.DataProtection": "1.0.0-*", "Microsoft.AspNet.DataProtection": "1.0.0-*",
"Microsoft.AspNet.TestHost": "1.0.0-*", "Microsoft.AspNet.TestHost": "1.0.0-*",
"Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*",
"Moq": "4.2.1312.1622",
"xunit.runner.aspnet": "2.0.0-aspnet-*" "xunit.runner.aspnet": "2.0.0-aspnet-*"
}, },
"commands": { "commands": {
"test": "xunit.runner.aspnet" "test": "xunit.runner.aspnet"
}, },
"frameworks": { "frameworks": {
"dnx451": { "dnx451": { },
} "dnxcore50": { }
} }
} }

View File

@ -61,14 +61,8 @@ namespace Microsoft.AspNet.CookiePolicy
new XAttribute("issuer", claim.Issuer)))); new XAttribute("issuer", claim.Issuer))));
} }
} }
using (var memory = new MemoryStream()) var xmlBytes = Encoding.UTF8.GetBytes(xml.ToString());
{ res.Body.Write(xmlBytes, 0, xmlBytes.Length);
using (var writer = new XmlTextWriter(memory, Encoding.UTF8))
{
xml.WriteTo(writer);
}
res.Body.Write(memory.ToArray(), 0, memory.ToArray().Length);
}
} }
} }
} }

View File

@ -1,17 +1,18 @@
{ {
"compilationOptions": { "compilationOptions": {
"warningsAsErrors": true "warningsAsErrors": true
}, },
"dependencies": { "dependencies": {
"Microsoft.AspNet.CookiePolicy": "1.0.0-*", "Microsoft.AspNet.CookiePolicy": "1.0.0-*",
"Microsoft.AspNet.TestHost": "1.0.0-*", "Microsoft.AspNet.TestHost": "1.0.0-*",
"Microsoft.Extensions.DependencyInjection": "1.0.0-*", "Microsoft.Extensions.DependencyInjection": "1.0.0-*",
"xunit.runner.aspnet": "2.0.0-aspnet-*" "xunit.runner.aspnet": "2.0.0-aspnet-*"
}, },
"commands": { "commands": {
"test": "xunit.runner.aspnet" "test": "xunit.runner.aspnet"
}, },
"frameworks": { "frameworks": {
"dnx451": { } "dnx451": { },
} "dnxcore50": { }
}
} }