145 lines
6.1 KiB
C++
145 lines
6.1 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
#include "tests/config.h"
|
|
#include "tests/fixture/authenticationFixture.h"
|
|
#include "tests/fixture/loginMockFixture.h"
|
|
#include "tests/mock/mockResultHelper.h"
|
|
#include <ubiservices/facade.h>
|
|
#if !defined(US_SDK_S2S)
|
|
#include <ubiservices/services/authentication/playerCredentials.h>
|
|
#endif
|
|
#include <ubiservices/services/friend/friendClient.h>
|
|
#include <ubiservices/services/http/request/httpGet.h>
|
|
#include <ubiservices/services/http/request/httpPost.h>
|
|
#include <usCommon/authenticationHelper.h>
|
|
#include <usSharedIntegration/usInitialization.h>
|
|
|
|
namespace US_NS {;
|
|
US_DEFINE_TEST(TestUbiServices);
|
|
|
|
typedef AuthenticationFixture<1, false> UBISERVICES_NOLOGIN;
|
|
typedef LeakCheckerNoInit UBISERVICES_NO_INIT;
|
|
typedef LeakChecker CORE_UBISERVICES;
|
|
typedef LoginMockFixture<false> UBISERVICES_MOCK_NOLOGIN;
|
|
|
|
#if defined(US_SDK_S2S)
|
|
/// @test Creates and deletes a game server session.
|
|
TEST_F(UBISERVICES_NOLOGIN, US_AuthenticationS2S)
|
|
#else
|
|
/// @test Logs in and out providing players credentials.
|
|
TEST_F(UBISERVICES_NOLOGIN, US_AuthenticationWithCredentials)
|
|
#endif
|
|
{
|
|
ASSERT_TRUE(AsyncHelper::waitSuccess(getFacade().createSession(GET_CREDENTIALS(), {}, {})));
|
|
ASSERT_TRUE(AsyncHelper::waitSuccess(getFacade().deleteSession()));
|
|
}
|
|
|
|
#if !defined(US_SDK_S2S)
|
|
/// @test Logs in and out providing players credentials with a modified response for forward compatibility
|
|
TEST_F(UBISERVICES_MOCK_NOLOGIN, USNOT_AuthenticationWithCredentialsWithModifiedResponseForForwardCompatibility)
|
|
{
|
|
const char* JSON =
|
|
"{"
|
|
" \"platformType\": \"uplay\","
|
|
" \"ticket\" : \"dummy-ticket\","
|
|
" \"twoFactorAuthenticationTicket\" : null,"
|
|
" \"profileId\" : \"4d9061de-7c20-4cc9-9f55-b8d6228da6ae\","
|
|
" \"userId\" : \"4d9061de-7c20-4cc9-9f55-b8d6228da6ae\","
|
|
" \"nameOnPlatform\" : \"ussdk001\","
|
|
" \"environment\" : \"UAT\","
|
|
" \"expiration\" : \"2018-02-27T19:19:53.7344891Z\","
|
|
" \"spaceId\" : \"d0b38ea5-d884-4444-895d-fa99ec47a76a\","
|
|
" \"clientIp\" : \"216.98.60.148\","
|
|
" \"clientIpCountry\" : \"BS\","
|
|
" \"serverTime\" : \"2018-02-27T16:19:53.7354619Z\","
|
|
" \"sessionId\" : \"e64976f5-40ee-46fb-a9e8-647a4fdd8387\","
|
|
" \"rememberMeTicket\": null"
|
|
"}";
|
|
|
|
HttpPost request(StringUrl(""), "");
|
|
{
|
|
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(JSON);
|
|
|
|
US_EXPECT_CALL_HTTP(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "parameters")
|
|
.Times(2)
|
|
.WillOnce(testing::Return(getMockedParametersApplication()))
|
|
.WillOnce(testing::Return(getMockedParametersSpace()))
|
|
.RetiresOnSaturation();
|
|
|
|
US_EXPECT_CALL_HTTP(getMockHttpClientImpl(), HttpMethod::HTTP_PUT, "/profiles/me/mock-populations/data")
|
|
.WillRepeatedly(testing::Return(getMockedPopulationsResponse()));
|
|
|
|
US_EXPECT_CALL_HTTP(getMockHttpClientImpl(), HttpMethod::HTTP_POST, "/sessions")
|
|
.WillOnce(testing::DoAll(testing::SaveArg<0>(static_cast<HttpRequest*>(&request)), testing::Return(mockResult)));
|
|
#if !defined(US_SDK_S2S)
|
|
mockPrimaryStoreCalls();
|
|
#endif
|
|
mockPostLogin();
|
|
#if !defined(US_SDK_S2S) && !defined(US_DLL)
|
|
setupWebsocketMock();
|
|
#endif
|
|
}
|
|
|
|
ASSERT_TRUE(AsyncHelper::waitSuccess(getFacade().createSession(GET_CREDENTIALS(), {}, {})));
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_SDK_FULL)
|
|
/// @test Ensures logging out works seamlessly while another call is progressing.
|
|
TEST_F(UBISERVICES_NOLOGIN, US_DeleteSessionWhileCallProcessing)
|
|
{
|
|
ASSERT_TRUE(AsyncHelper::waitSuccess(getFacade().createSession(GET_CREDENTIALS(), {}, {})));
|
|
|
|
const AsyncResult<Vector<FriendInfo> > result = getFacade().getFriendClient().requestFriends(FriendClient::ClubWithConsoleInfo);
|
|
EXPECT_TRUE(result.isProcessing());
|
|
|
|
ASSERT_TRUE(AsyncHelper::waitSuccess(getFacade().deleteSession()));
|
|
|
|
// At this point the test verified that logging out works while
|
|
// the request friends is processing. However, the fixture requires
|
|
// that no job remains in process to succeed (unless explicitly enabled).
|
|
// So, the test must at least ensure that the request completes.
|
|
EXPECT_TRUE(result.wait(NS_COMMON::DEFAULT_WAIT_TIME));
|
|
}
|
|
#endif // defined(US_SDK_FULL)
|
|
|
|
/// @test Ensures deleting the facade works seamlessly while a delete session is in progress.
|
|
TEST_F(UBISERVICES_NOLOGIN, US_DeleteFacadeWhileDeleteSessionProcessing)
|
|
{
|
|
const AsyncResult<Empty> loginResult = getFacade().createSession(GET_CREDENTIALS(), {}, {});
|
|
EXPECT_TRUE(loginResult.wait());
|
|
ASSERT_TRUE(US_TEST_NS::Helper::waitForWebsocketInit(getFacade()));
|
|
|
|
const AsyncResult<Empty> resultDeleteSession = getFacade().deleteSession();
|
|
// Intentionally avoiding the wait call on the AsyncResult
|
|
}
|
|
|
|
#if defined(US_SDK_FULL)
|
|
/// @test Ensures the facade tears down seamlessly while another call is progressing.
|
|
TEST_F(UBISERVICES_NOLOGIN, US_DeleteFacadeWhileCallProcessing)
|
|
{
|
|
const AsyncResult<Empty> loginResult = getFacade().createSession(GET_CREDENTIALS(), {}, {});
|
|
EXPECT_TRUE(loginResult.wait());
|
|
ASSERT_TRUE(US_TEST_NS::Helper::waitForWebsocketInit(getFacade()));
|
|
const AsyncResult<Vector<FriendInfo> > result = getFacade().getFriendClient().requestFriends(FriendClient::ClubWithConsoleInfo);
|
|
// Intentionally avoiding the wait call on the AsyncResult
|
|
}
|
|
#endif // defined(US_SDK_FULL)
|
|
|
|
#if defined(US_DLL) && !defined(US_DLL_SWIG) && !defined(US_UNITY3D)
|
|
///@test Tries to initialize and run UbiServices from a shared module that doesn't link against EAL.
|
|
TEST_F(UBISERVICES_NO_INIT, LOCAL_IntegrationInSharedEngineWithoutEAL)
|
|
{
|
|
eal_log_dll_interface logInterface;
|
|
EalLogDllPopulateInterface(logInterface);
|
|
|
|
eal_mem_dll_interface memInterface;
|
|
EalMemDllPopulateInterface(memInterface);
|
|
|
|
usSharedIntegration::initializeSdkFromSharedModule(memInterface, logInterface);
|
|
usSharedIntegration::uninitializeSdkFromSharedModule();
|
|
}
|
|
#endif
|
|
|
|
};
|