116 lines
5 KiB
C++
116 lines
5 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
#include "tests/config.h"
|
|
#include "testsIntegration/facebookTestHelper.h"
|
|
#include "tests/common/helpers.h"
|
|
#include <ubiservices/core/JSON/json.h>
|
|
#include <ubiservices/core/types/string.h>
|
|
#include <ubiservices/core/errors/errorDetails.h>
|
|
#include <ubiservices/core/tasks/asyncResult.h>
|
|
#include <ubiservices/services/http/httpClient.h>
|
|
#include <ubiservices/services/http/httpResponse.h>
|
|
#include <ubiservices/services/http/request/httpGet.h>
|
|
#include <ubiservices/facade.h>
|
|
|
|
namespace US_TEST_NS {;
|
|
|
|
namespace FacebookTestHelper
|
|
{
|
|
::testing::AssertionResult getFacebookAccessTokenFromAccountList(
|
|
const US_NS::String& accountListJson, const char* facebookAccountId, US_NS::String& facebookAccessToken);
|
|
|
|
/// To get a valid Facebook access token, check the following page:
|
|
/// https://mdc-web-tomcat17.ubisoft.org/confluence/display/online/How+to+get+a+Facebook+Test+Access+Token
|
|
/// ****** WARNING: Hardcoded values in url shall ONLY be used for internal tests *****
|
|
/// Parameters correspond to the TG-Uplay-SocialTest Facebook application.
|
|
/// Access to the application administration interface is explained in
|
|
/// https://mdc-web-tomcat17.ubisoft.org/confluence/display/ubiservices/Prototyping+Consoles+Facebook+Integration
|
|
US_NS::String getFacebookAccountListJson(US_NS::HttpClient& httpClient);
|
|
}
|
|
|
|
::testing::AssertionResult FacebookTestHelper::getFacebookAccessTokenFromAccountList(
|
|
US_NS::HttpClient& httpClient, const char* facebookAccountId, US_NS::String& facebookAccessToken)
|
|
{
|
|
return getFacebookAccessTokenFromAccountList(FacebookTestHelper::getFacebookAccountListJson(httpClient), facebookAccountId, facebookAccessToken);
|
|
}
|
|
|
|
::testing::AssertionResult FacebookTestHelper::getFacebookAccessTokenFromAccountList(
|
|
const US_NS::String& accountListJson, const char* facebookAccountId, US_NS::String& facebookAccessToken)
|
|
{
|
|
using US_NS::Json;
|
|
const Json bodyReader(accountListJson);
|
|
const Json dataReader = bodyReader["data"];
|
|
const bool isDataValid = (dataReader.isValid() && dataReader.isTypeArray());
|
|
if (!isDataValid)
|
|
{
|
|
return ::testing::AssertionFailure() << "Invalid JSON for Facebook account list";
|
|
}
|
|
|
|
for (const auto& dataItem : dataReader.getValueArray())
|
|
{
|
|
const Json idReader = dataItem["id"];
|
|
const bool isIdValid = idReader.isValid() && idReader.isTypeString();
|
|
if (isIdValid)
|
|
{
|
|
const char* idInJson(idReader.getValueStringFast());
|
|
if (strcmp(facebookAccountId, idInJson) == 0)
|
|
{
|
|
const Json accessTokenReader = dataItem["access_token"];
|
|
const bool isAccessTokenValid = (accessTokenReader.isValid() && accessTokenReader.isTypeString());
|
|
if (isAccessTokenValid)
|
|
{
|
|
facebookAccessToken = accessTokenReader.getValueString();
|
|
return ::testing::AssertionSuccess();
|
|
}
|
|
else
|
|
{
|
|
return ::testing::AssertionFailure() << "Invalid JSON for Facebook account list (access_token is missing?)";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return ::testing::AssertionFailure() << "The specified Facebook id '" << facebookAccountId << "' could not be found in the JSON";
|
|
}
|
|
|
|
// Note: The list of users is shared between UbiServices teams
|
|
// The SDK uses the following accounts:
|
|
// - 108223022854753
|
|
// - 114296632243965
|
|
// - 132054560461515
|
|
// Do not use other accounts in the list, they are reserved for other teams.
|
|
US_NS::String FacebookTestHelper::getFacebookAccountListJson(US_NS::HttpClient& httpClient)
|
|
{
|
|
// https://developers.facebook.com/docs/graph-api/reference/user/accounts/
|
|
// /{user-id}/accounts
|
|
|
|
// Where...
|
|
// https://graph.facebook.com/111521402337975
|
|
// {
|
|
// "category": "Games",
|
|
// "link" : "http://validation.ubi.com/webservices/uplay/en-GB/",
|
|
// "name" : "Uplay Account - UAT",
|
|
// "namespace" : "uplay-account-uat",
|
|
// "id" : "111521402337975"
|
|
// }
|
|
|
|
using namespace US_NS;
|
|
const char* url = "https://graph.facebook.com/111521402337975/accounts/test-users?access_token=111521402337975%7Ca913251748b947122a0caf00d96557f4";
|
|
HttpGet request(url);
|
|
#if defined(US_TARGET_WINDOWS) || defined(US_TARGET_LINUX)
|
|
HttpProxyConfig proxyConfig = HttpProxyConfig(US_TEST_NS::PROXY_NAME, US_TEST_NS::PROXY_PORT);
|
|
proxyConfig.m_proxyType = HttpProxyConfig::Type::Enabled;
|
|
request.setProxyInfo(proxyConfig);
|
|
#endif
|
|
|
|
const US_NS::AsyncResult<US_NS::HttpResponse> result = httpClient.sendRequest(request);
|
|
EXPECT_TRUE(result.wait());
|
|
US_EXPECT_SUCCESS(result);
|
|
|
|
PRINT_LINE("Account List JSON: %s", Json(result.getResult().getBodyAsString()).renderContent(Json::Formatted).getUtf8());
|
|
|
|
return result.getResult().getBodyAsString();
|
|
}
|
|
|
|
};
|