Fix facebook tests.
This commit is contained in:
parent
e6376a89a6
commit
2ce9fcc233
|
|
@ -21,6 +21,55 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MusicStore", "src\MusicStor
|
|||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MusicStore.Test", "test\MusicStore.Test\MusicStore.Test.xproj", "{CA663205-77DE-4E55-B300-85594181B5A9}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Mocks", "Mocks", "{D7CB3341-F932-4AC6-8F4E-EDC62F03C064}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
shared\Mocks\Readme.md = shared\Mocks\Readme.md
|
||||
shared\Mocks\StartupOpenIdConnectTesting.cs = shared\Mocks\StartupOpenIdConnectTesting.cs
|
||||
shared\Mocks\StartupSocialTesting.cs = shared\Mocks\StartupSocialTesting.cs
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Facebook", "Facebook", "{B53E1D6D-4A18-4AA2-BE59-146D6B7F310D}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
shared\Mocks\Facebook\FacebookMockBackChannelHttpHandler.cs = shared\Mocks\Facebook\FacebookMockBackChannelHttpHandler.cs
|
||||
shared\Mocks\Facebook\TestFacebookEvents.cs = shared\Mocks\Facebook\TestFacebookEvents.cs
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{E839AEB0-7926-4FEE-B22C-11AF7EF5D4BF}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{78715843-B625-414E-9074-56908C48EF28}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
shared\Mocks\Common\CustomStateDataFormat.cs = shared\Mocks\Common\CustomStateDataFormat.cs
|
||||
shared\Mocks\Common\Helpers.cs = shared\Mocks\Common\Helpers.cs
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Google", "Google", "{A6D34706-33E8-45D4-9E3D-8EB8C9EAD9B2}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
shared\Mocks\Google\GoogleMockBackChannelHttpHandler.cs = shared\Mocks\Google\GoogleMockBackChannelHttpHandler.cs
|
||||
shared\Mocks\Google\TestGoogleEvents.cs = shared\Mocks\Google\TestGoogleEvents.cs
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MicrosoftAccount", "MicrosoftAccount", "{86DDEB7E-F29D-41BD-9866-65EB01A8CFED}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
shared\Mocks\MicrosoftAccount\MicrosoftAccountMockBackChannelHandler.cs = shared\Mocks\MicrosoftAccount\MicrosoftAccountMockBackChannelHandler.cs
|
||||
shared\Mocks\MicrosoftAccount\TestMicrosoftAccountEvents.cs = shared\Mocks\MicrosoftAccount\TestMicrosoftAccountEvents.cs
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OpenIdConnect", "OpenIdConnect", "{B76F2C95-C066-4CAB-AA2B-287FA039C786}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
shared\Mocks\OpenIdConnect\CustomStringDataFormat.cs = shared\Mocks\OpenIdConnect\CustomStringDataFormat.cs
|
||||
shared\Mocks\OpenIdConnect\keys.json = shared\Mocks\OpenIdConnect\keys.json
|
||||
shared\Mocks\OpenIdConnect\openid-configuration.json = shared\Mocks\OpenIdConnect\openid-configuration.json
|
||||
shared\Mocks\OpenIdConnect\OpenIdConnectBackChannelHttpHandler.cs = shared\Mocks\OpenIdConnect\OpenIdConnectBackChannelHttpHandler.cs
|
||||
shared\Mocks\OpenIdConnect\TestOpenIdConnectEvents.cs = shared\Mocks\OpenIdConnect\TestOpenIdConnectEvents.cs
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Twitter", "Twitter", "{6CA9AC03-039E-4993-8164-C27E418683C5}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
shared\Mocks\Twitter\CustomTwitterStateDataFormat.cs = shared\Mocks\Twitter\CustomTwitterStateDataFormat.cs
|
||||
shared\Mocks\Twitter\TestTwitterEvents.cs = shared\Mocks\Twitter\TestTwitterEvents.cs
|
||||
shared\Mocks\Twitter\TwitterMockBackChannelHttpHandler.cs = shared\Mocks\Twitter\TwitterMockBackChannelHttpHandler.cs
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -71,5 +120,12 @@ Global
|
|||
{A319ACCE-060B-4385-9534-9F2202F6180E} = {363D2681-31A6-48C9-90BB-9ACFF4A41F06}
|
||||
{3CFBED5D-2ED8-49DB-96FB-BDAA748DC5A0} = {B7B176B6-8D4D-4EF1-BBD2-DDA650C78FFF}
|
||||
{CA663205-77DE-4E55-B300-85594181B5A9} = {363D2681-31A6-48C9-90BB-9ACFF4A41F06}
|
||||
{D7CB3341-F932-4AC6-8F4E-EDC62F03C064} = {E839AEB0-7926-4FEE-B22C-11AF7EF5D4BF}
|
||||
{B53E1D6D-4A18-4AA2-BE59-146D6B7F310D} = {D7CB3341-F932-4AC6-8F4E-EDC62F03C064}
|
||||
{78715843-B625-414E-9074-56908C48EF28} = {D7CB3341-F932-4AC6-8F4E-EDC62F03C064}
|
||||
{A6D34706-33E8-45D4-9E3D-8EB8C9EAD9B2} = {D7CB3341-F932-4AC6-8F4E-EDC62F03C064}
|
||||
{86DDEB7E-F29D-41BD-9866-65EB01A8CFED} = {D7CB3341-F932-4AC6-8F4E-EDC62F03C064}
|
||||
{B76F2C95-C066-4CAB-AA2B-287FA039C786} = {D7CB3341-F932-4AC6-8F4E-EDC62F03C064}
|
||||
{6CA9AC03-039E-4993-8164-C27E418683C5} = {D7CB3341-F932-4AC6-8F4E-EDC62F03C064}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
|||
|
|
@ -3,6 +3,5 @@
|
|||
<packageSources>
|
||||
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" />
|
||||
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
|
||||
<add key="AzureAD" value="http://www.myget.org/F/azureadwebstacknightly/api/v3/index.json" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
#if TESTING
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -16,23 +18,29 @@ namespace MusicStore.Mocks.Facebook
|
|||
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new HttpResponseMessage();
|
||||
var queryParameters = new QueryCollection(QueryHelpers.ParseQuery(request.RequestUri.Query));
|
||||
|
||||
if (request.RequestUri.AbsoluteUri.StartsWith("https://graph.facebook.com/v2.2/oauth/access_token"))
|
||||
if (request.RequestUri.AbsoluteUri.StartsWith("https://graph.facebook.com/v2.5/oauth/access_token"))
|
||||
{
|
||||
if (queryParameters["grant_type"] == "authorization_code")
|
||||
var formData = new FormCollection(await FormReader.ReadFormAsync(await request.Content.ReadAsStreamAsync()));
|
||||
if (formData["grant_type"] == "authorization_code")
|
||||
{
|
||||
if (queryParameters["code"] == "ValidCode")
|
||||
if (formData["code"] == "ValidCode")
|
||||
{
|
||||
Helpers.ThrowIfConditionFailed(() => ((string)queryParameters["redirect_uri"]).EndsWith("signin-facebook"), "Redirect URI is not ending with /signin-facebook");
|
||||
Helpers.ThrowIfConditionFailed(() => queryParameters["client_id"] == "[AppId]", "Invalid client Id received");
|
||||
Helpers.ThrowIfConditionFailed(() => queryParameters["client_secret"] == "[AppSecret]", "Invalid client secret received");
|
||||
response.Content = new StringContent("access_token=ValidAccessToken&expires=100");
|
||||
Helpers.ThrowIfConditionFailed(() => ((string)formData["redirect_uri"]).EndsWith("signin-facebook"), "Redirect URI is not ending with /signin-facebook");
|
||||
Helpers.ThrowIfConditionFailed(() => formData["client_id"] == "[AppId]", "Invalid client Id received");
|
||||
Helpers.ThrowIfConditionFailed(() => formData["client_secret"] == "[AppSecret]", "Invalid client secret received");
|
||||
response.Content = new StringContent("{ \"access_token\": \"ValidAccessToken\", \"expires_in\": \"100\" }");
|
||||
}
|
||||
else
|
||||
{
|
||||
response.StatusCode = (HttpStatusCode)400;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
else if (request.RequestUri.AbsoluteUri.StartsWith("https://graph.facebook.com/v2.2/me"))
|
||||
else if (request.RequestUri.AbsoluteUri.StartsWith("https://graph.facebook.com/v2.5/me"))
|
||||
{
|
||||
var queryParameters = new QueryCollection(QueryHelpers.ParseQuery(request.RequestUri.Query));
|
||||
Helpers.ThrowIfConditionFailed(() => queryParameters["appsecret_proof"].Count > 0, "appsecret_proof is empty");
|
||||
if (queryParameters["access_token"] == "ValidAccessToken")
|
||||
{
|
||||
|
|
@ -42,9 +50,10 @@ namespace MusicStore.Mocks.Facebook
|
|||
{
|
||||
response.Content = new StringContent("{\"error\":{\"message\":\"Invalid OAuth access token.\",\"type\":\"OAuthException\",\"code\":190}}");
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
return await Task.FromResult(response);
|
||||
throw new NotImplementedException(request.RequestUri.AbsoluteUri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,19 @@
|
|||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
|
||||
<system.web>
|
||||
<compilation debug="true" targetFramework="4.5" />
|
||||
<httpRuntime targetFramework="4.5" />
|
||||
</system.web>
|
||||
|
||||
<appSettings>
|
||||
<!-- This will turn on detailed errors when deployed to remote servers -->
|
||||
<!-- This setting is not recommended for production -->
|
||||
<add key="ASPNET_DETAILED_ERRORS" value="true" />
|
||||
<add key="dnx-app-base" value=".." />
|
||||
</appSettings>
|
||||
|
||||
<system.web>
|
||||
<compilation debug="true" targetFramework="4.5" />
|
||||
<httpRuntime targetFramework="4.5" />
|
||||
</system.web>
|
||||
<appSettings>
|
||||
<!-- This will turn on detailed errors when deployed to remote servers -->
|
||||
<!-- This setting is not recommended for production -->
|
||||
<add key="ASPNET_DETAILED_ERRORS" value="true" />
|
||||
<add key="dnx-app-base" value=".." />
|
||||
</appSettings>
|
||||
<system.webServer>
|
||||
<handlers>
|
||||
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
|
||||
</handlers>
|
||||
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" forwardWindowsAuthToken="false" startupTimeLimit="3600" />
|
||||
</system.webServer>
|
||||
</configuration>
|
||||
|
|
@ -30,7 +30,7 @@ namespace E2ETests
|
|||
|
||||
var content = new FormUrlEncodedContent(formParameters.ToArray());
|
||||
response = await _httpClient.PostAsync("Account/ExternalLogin", content);
|
||||
Assert.Equal<string>("https://www.facebook.com/v2.2/dialog/oauth", response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty));
|
||||
Assert.Equal<string>("https://www.facebook.com/v2.5/dialog/oauth", response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty));
|
||||
var queryItems = new QueryCollection(QueryHelpers.ParseQuery(response.Headers.Location.Query));
|
||||
Assert.Equal<string>("code", queryItems["response_type"]);
|
||||
Assert.Equal<string>("[AppId]", queryItems["client_id"]);
|
||||
|
|
|
|||
Loading…
Reference in New Issue