Skip to content

Commit

Permalink
Merge pull request #274 from getbraincloud/BCLOUD-6698_logout
Browse files Browse the repository at this point in the history
Bcloud 6698 logout
  • Loading branch information
jo-codegirl authored Feb 15, 2024
2 parents 37501da + e147b44 commit f27003c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 33 deletions.
2 changes: 2 additions & 0 deletions include/braincloud/BrainCloudWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ namespace BrainCloud {
*/
bool getAlwaysAllowProfileSwitch();

void logout(bool forgetUser, IServerCallback * in_callback);

virtual void serverCallback(BrainCloud::ServiceName serviceName, BrainCloud::ServiceOperation serviceOperation, std::string const & jsonData);
virtual void serverError(BrainCloud::ServiceName serviceName,
BrainCloud::ServiceOperation serviceOperation,
Expand Down
8 changes: 8 additions & 0 deletions src/BrainCloudWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,14 @@ namespace BrainCloud {
}
}

void BrainCloudWrapper::logout(bool forgetUser, IServerCallback * in_callback)
{
if (forgetUser) {
resetStoredProfileId();
}
client->getPlayerStateService()->logout(in_callback);
}

void BrainCloudWrapper::resetEmailPassword(const char * in_externalId, IServerCallback * in_callback)
{
client->getAuthenticationService()->resetEmailPassword(in_externalId, in_callback);
Expand Down
91 changes: 58 additions & 33 deletions tests/src/TestBCWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,26 +158,45 @@ TEST_F(TestBCWrapper, Reconnect)
Logout();
}

TEST_F(TestBCWrapper, LogoutRememberUser)
{
m_bcWrapper->initialize(m_serverUrl.c_str(), m_secret.c_str(), m_appId.c_str(), m_version.c_str(), "wrapper", "unittest");

TestResult tr;
std::string uid = GetUser(UserA)->m_id;
uid.append("_wrapper");
m_bcWrapper->authenticateUniversal(uid.c_str(), GetUser(UserA)->m_password, true, &tr);
tr.run(m_bc);

m_bcWrapper->logout(false, &tr);
tr.run(m_bc);

EXPECT_FALSE(m_bcWrapper->getStoredProfileId()=="");
}

TEST_F(TestBCWrapper, LogoutForgetUser)
{
m_bcWrapper->initialize(m_serverUrl.c_str(), m_secret.c_str(), m_appId.c_str(), m_version.c_str(), "wrapper", "unittest");

TestResult tr;
std::string uid = GetUser(UserA)->m_id;
uid.append("_wrapper");
m_bcWrapper->authenticateUniversal(uid.c_str(), GetUser(UserA)->m_password, true, &tr);
tr.run(m_bc);

m_bcWrapper->logout(true, &tr);
tr.run(m_bc);

EXPECT_TRUE(m_bcWrapper->getStoredProfileId()=="");
}

TEST_F(TestBCWrapper, SmartSwitchAnonToUniversal)
{
//need to separate these tests for windows and linux for the time being.
#if defined(_WIN32)

std::string uid = GetUser(UserA)->m_id;
#if defined(UNIX)
std::string uid = GetUser(UserA)->m_id;
uid.append("_wrapper");

/*
std::string anonIdtest = "\n STORED ID: " + m_bcWrapper->getStoredAnonymousId() + "\n";
std::cout<< anonIdtest;
//after testing and test cases it's noticeable that this fucntion does not work for linux.
m_bcWrapper->setStoredAnonymousId(m_bcWrapper->client->getAuthenticationService()->generateAnonymousId().c_str());
std::string anonIdtest1 = "\n STORED ID: " + m_bcWrapper->getStoredAnonymousId() + "\n";
std::cout<< anonIdtest1;
*/
//CONFIRMED : setStoredAnonymousId uses a pure virtual method save data helper, which is only implemented for Windows. Due to this it will not work on linux.

m_bcWrapper->setStoredAnonymousId(m_bcWrapper->client->getAuthenticationService()->generateAnonymousId().c_str());
m_bcWrapper->resetStoredProfileId();

Expand All @@ -191,13 +210,24 @@ TEST_F(TestBCWrapper, SmartSwitchAnonToUniversal)
m_bcWrapper->smartSwitchAuthenticateUniversal(uid.c_str(), GetUser(UserA)->m_password, true, &tr);
tr.run(m_bc);

EXPECT_TRUE(profileId.compare(m_bcWrapper->getStoredAnonymousId()) != 0);

#elif defined (UNIX)

//WE WILL NOT HAVE A SAVED ANON ID, <<BUT>> the switchauthentication call works.
EXPECT_FALSE(profileId.compare(m_bcWrapper->getStoredAnonymousId()) != 0);
#else
std::string uid = GetUser(UserA)->m_id;
uid.append("_wrapper");

/*
std::string anonIdtest = "\n STORED ID: " + m_bcWrapper->getStoredAnonymousId() + "\n";
std::cout<< anonIdtest;
//after testing and test cases it's noticeable that this fucntion does not work for linux.
m_bcWrapper->setStoredAnonymousId(m_bcWrapper->client->getAuthenticationService()->generateAnonymousId().c_str());
std::string anonIdtest1 = "\n STORED ID: " + m_bcWrapper->getStoredAnonymousId() + "\n";
std::cout<< anonIdtest1;
*/
//CONFIRMED : setStoredAnonymousId uses a pure virtual method save data helper, which is only implemented for Windows. Due to this it will not work on linux.

m_bcWrapper->setStoredAnonymousId(m_bcWrapper->client->getAuthenticationService()->generateAnonymousId().c_str());
m_bcWrapper->resetStoredProfileId();

Expand All @@ -211,22 +241,20 @@ TEST_F(TestBCWrapper, SmartSwitchAnonToUniversal)
m_bcWrapper->smartSwitchAuthenticateUniversal(uid.c_str(), GetUser(UserA)->m_password, true, &tr);
tr.run(m_bc);

//WE WILL NOT HAVE A SAVED ANON ID, <<BUT>> the switchauthentication call works.
EXPECT_FALSE(profileId.compare(m_bcWrapper->getStoredAnonymousId()) != 0);
EXPECT_TRUE(profileId.compare(m_bcWrapper->getStoredAnonymousId()) != 0);

#endif
}

TEST_F(TestBCWrapper, SmartSwitchUniversalToEmail)
{
//same reason, we have no way to properly store an anon id in linux yet
#if defined(_WIN32)

std::string email = GetUser(UserA)->m_email;
#if defined(UNIX)
std::string email = GetUser(UserA)->m_email;
size_t pos = email.find('@');
if(pos > 0)
email.insert(pos, "_wrapper");
m_bcWrapper->setStoredAnonymousId(m_bcWrapper->client->getAuthenticationService()->generateAnonymousId().c_str());
m_bcWrapper->setStoredAnonymousId(m_bcWrapper->client->getAuthenticationService()->generateAnonymousId().c_str());
m_bcWrapper->resetStoredProfileId();

TestResult tr;
Expand All @@ -240,15 +268,14 @@ TEST_F(TestBCWrapper, SmartSwitchUniversalToEmail)
m_bcWrapper->smartSwitchAuthenticateEmailPassword(email.c_str(), GetUser(UserA)->m_password, true, &tr);
tr.run(m_bc);

EXPECT_TRUE(profileId.compare(m_bcWrapper->getStoredProfileId()) != 0);

#elif defined(UNIX)

//makes it through until failure here.
EXPECT_FALSE(profileId.compare(m_bcWrapper->getStoredProfileId()) != 0);
#else
std::string email = GetUser(UserA)->m_email;
size_t pos = email.find('@');
if(pos > 0)
email.insert(pos, "_wrapper");
m_bcWrapper->setStoredAnonymousId(m_bcWrapper->client->getAuthenticationService()->generateAnonymousId().c_str());
m_bcWrapper->setStoredAnonymousId(m_bcWrapper->client->getAuthenticationService()->generateAnonymousId().c_str());
m_bcWrapper->resetStoredProfileId();

TestResult tr;
Expand All @@ -262,8 +289,7 @@ TEST_F(TestBCWrapper, SmartSwitchUniversalToEmail)
m_bcWrapper->smartSwitchAuthenticateEmailPassword(email.c_str(), GetUser(UserA)->m_password, true, &tr);
tr.run(m_bc);

//makes it through until failure here.
EXPECT_FAIL(profileId.compare(m_bcWrapper->getStoredProfileId()) != 0);
EXPECT_TRUE(profileId.compare(m_bcWrapper->getStoredProfileId()) != 0);

#endif
}
Expand Down Expand Up @@ -305,6 +331,5 @@ TEST_F(TestBCWrapper, ReInit)
tr3.runExpectFail(m_bc, HTTP_FORBIDDEN, NO_SESSION);
}


#endif

0 comments on commit f27003c

Please sign in to comment.