Fix Google & Twitter, harden the tests.
This commit is contained in:
parent
2ce9fcc233
commit
b3e5e7c178
|
|
@ -30,11 +30,9 @@ namespace MusicStore.Mocks.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\" }");
|
||||
return response;
|
||||
}
|
||||
else
|
||||
{
|
||||
response.StatusCode = (HttpStatusCode)400;
|
||||
}
|
||||
response.StatusCode = (HttpStatusCode)400;
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
#if TESTING
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
|
@ -17,7 +19,7 @@ namespace MusicStore.Mocks.Google
|
|||
{
|
||||
var response = new HttpResponseMessage();
|
||||
|
||||
if (request.RequestUri.AbsoluteUri.StartsWith("https://accounts.google.com/o/oauth2/token"))
|
||||
if (request.RequestUri.AbsoluteUri.StartsWith("https://www.googleapis.com/oauth2/v3/token"))
|
||||
{
|
||||
var formData = new FormCollection(await FormReader.ReadFormAsync(await request.Content.ReadAsStreamAsync()));
|
||||
if (formData["grant_type"] == "authorization_code")
|
||||
|
|
@ -28,9 +30,12 @@ namespace MusicStore.Mocks.Google
|
|||
formData["client_id"] == "[ClientId]" && formData["client_secret"] == "[ClientSecret]")
|
||||
{
|
||||
response.Content = new StringContent("{\"access_token\":\"ValidAccessToken\",\"refresh_token\":\"ValidRefreshToken\",\"token_type\":\"Bearer\",\"expires_in\":\"1200\",\"id_token\":\"Token\"}", Encoding.UTF8, "application/json");
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
response.StatusCode = (HttpStatusCode)400;
|
||||
return response;
|
||||
}
|
||||
else if (request.RequestUri.AbsoluteUri.StartsWith("https://www.googleapis.com/plus/v1/people/me"))
|
||||
{
|
||||
|
|
@ -42,9 +47,10 @@ namespace MusicStore.Mocks.Google
|
|||
{
|
||||
response.Content = new StringContent("{\"error\":{\"message\":\"Invalid OAuth access token.\",\"type\":\"OAuthException\",\"code\":190}}");
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
return response;
|
||||
throw new NotImplementedException(request.RequestUri.AbsoluteUri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
#if TESTING
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
|
@ -28,9 +30,13 @@ namespace MusicStore.Mocks.MicrosoftAccount
|
|||
formData["client_id"] == "[ClientId]" && formData["client_secret"] == "[ClientSecret]")
|
||||
{
|
||||
response.Content = new StringContent("{\"token_type\":\"bearer\",\"expires_in\":3600,\"scope\":\"wl.basic\",\"access_token\":\"ValidAccessToken\",\"refresh_token\":\"ValidRefreshToken\",\"authentication_token\":\"ValidAuthenticationToken\"}");
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response.StatusCode = (HttpStatusCode)400;
|
||||
return response;
|
||||
}
|
||||
else if (request.RequestUri.AbsoluteUri.StartsWith("https://apis.live.net/v5.0/me"))
|
||||
{
|
||||
|
|
@ -42,9 +48,10 @@ namespace MusicStore.Mocks.MicrosoftAccount
|
|||
{
|
||||
response.Content = new StringContent("{\r \"error\": {\r \"code\": \"request_token_invalid\", \r \"message\": \"The access token isn't valid.\"\r }\r}", Encoding.UTF8, "text/javascript");
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
return response;
|
||||
throw new NotImplementedException(request.RequestUri.AbsoluteUri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#if TESTING
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
|
|
@ -42,7 +43,10 @@ namespace MusicStore.Mocks.Twitter
|
|||
response.StatusCode = HttpStatusCode.InternalServerError;
|
||||
response.Content = new StringContent("RequestTokenEndpoint is not invoked");
|
||||
}
|
||||
return response;
|
||||
}
|
||||
response.StatusCode = (HttpStatusCode)400;
|
||||
return response;
|
||||
}
|
||||
else if (request.RequestUri.AbsoluteUri.StartsWith("https://api.twitter.com/oauth/request_token"))
|
||||
{
|
||||
|
|
@ -55,9 +59,10 @@ namespace MusicStore.Mocks.Twitter
|
|||
|
||||
_requestTokenEndpointInvoked = true;
|
||||
response.Content = new FormUrlEncodedContent(response_Form_data);
|
||||
return response;
|
||||
}
|
||||
|
||||
return response;
|
||||
throw new NotImplementedException(request.RequestUri.AbsoluteUri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ namespace E2ETests
|
|||
|
||||
var content = new FormUrlEncodedContent(formParameters.ToArray());
|
||||
response = await _httpClient.PostAsync("Account/ExternalLogin", content);
|
||||
Assert.Equal<string>("https://twitter.com/oauth/authenticate", response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty));
|
||||
Assert.Equal<string>("https://api.twitter.com/oauth/authenticate", response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty));
|
||||
var queryItems = new QueryCollection(QueryHelpers.ParseQuery(response.Headers.Location.Query));
|
||||
Assert.Equal<string>("custom", queryItems["custom_redirect_uri"]);
|
||||
Assert.Equal<string>("valid_oauth_token", queryItems["oauth_token"]);
|
||||
|
|
|
|||
Loading…
Reference in New Issue