Skip to content

Commit

Permalink
Added additional tests for remaining paths
Browse files Browse the repository at this point in the history
  • Loading branch information
BellringerQuinn committed Jan 8, 2025
1 parent 03b9763 commit 2d4da6c
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ void USequenceAuthenticator::FederatePlayFabNewAccount(const FString& UsernameIn

const FFailureCallback OnFederateFailure = [this](const FSequenceError& Error)
{
UE_LOG(LogTemp, Warning, TEXT("Error Federating PlayFab Account: %s"), *Error.Message);
UE_LOG(LogTemp, Error, TEXT("Error Federating PlayFab Account: %s"), *Error.Message);
this->CallFederateFailure(Error.Message);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ void FPlayFabInputValidationTests::GetTests(TArray<FString>& OutBeautifiedNames,
OutBeautifiedNames.Add(TEXT("Login Input Validation"));
OutTestCommands.Add(TEXT("login"));

OutBeautifiedNames.Add(TEXT("New Account Input Validation"));
OutTestCommands.Add(TEXT("newaccount"));

OutBeautifiedNames.Add(TEXT("Federation Input Validation"));
OutTestCommands.Add(TEXT("federation"));

OutBeautifiedNames.Add(TEXT("Federation Login Input Validation"));
OutTestCommands.Add(TEXT("federation_login"));
}

bool FPlayFabInputValidationTests::RunTest(const FString& Parameters)
Expand All @@ -33,11 +39,25 @@ bool FPlayFabInputValidationTests::RunTest(const FString& Parameters)
TestHelper->SetIsLoginTest(true);
TestHelper->RunLoginValidationTests();
}
else
else if (Parameters == TEXT("newaccount"))
{
TestHelper->SetIsLoginTest(false);
TestHelper->SetIsNewAccountTest(true);
TestHelper->RunNewAccountValidationTests();
}
else if (Parameters == TEXT("federation"))
{
TestHelper->SetIsFederationTest(true);
TestHelper->RunFederationValidationTests();
}
else if (Parameters == TEXT("federation_login"))
{
TestHelper->SetIsFederationLoginTest(true);
TestHelper->RunFederationLoginValidationTests();
}
else
{
TestHelper->ParentTest->AddError("Encountered invalid test parameters: " + Parameters);
}

ADD_LATENT_AUTOMATION_COMMAND(FWaitForValidationTestComplete(TestHelper));
return true;
Expand Down Expand Up @@ -177,6 +197,100 @@ void UPlayFabInputValidationTestHelper::OnFederateFailure(const FString& Error)
ParentTest->AddInfo(FString::Printf(TEXT("Federation failed as expected with error: %s"), *Error));
}

void UPlayFabInputValidationTestHelper::RunNewAccountValidationTests()
{
bTestComplete = false;

if (!Authenticator)
{
Authenticator = NewObject<USequenceAuthenticator>();
Authenticator->AuthSuccess.AddDynamic(this, &UPlayFabInputValidationTestHelper::OnAuthSuccess);
Authenticator->AuthFailure.AddDynamic(this, &UPlayFabInputValidationTestHelper::OnAuthFailure);
}

if (LastError.IsEmpty())
{
ParentTest->AddInfo(TEXT("Testing empty username for new account"));
Authenticator->PlayFabRegisterAndLogin(TEXT(""), TEXT("[email protected]"), TEXT("validpassword123"), false);
}
else if (LastError.Contains(TEXT("Username cannot be empty")))
{
ParentTest->AddInfo(TEXT("Testing empty email for new account"));
Authenticator->PlayFabRegisterAndLogin(TEXT("validusername"), TEXT(""), TEXT("validpassword123"), false);
}
else if (LastError.Contains(TEXT("Email cannot be empty")))
{
ParentTest->AddInfo(TEXT("Testing invalid email format for new account"));
Authenticator->PlayFabRegisterAndLogin(TEXT("validusername"), TEXT("invalidemail"), TEXT("validpassword123"), false);
}
else if (LastError.Contains(TEXT("Email is invalid, given invalidemail")))
{
ParentTest->AddInfo(TEXT("Testing empty password for new account"));
Authenticator->PlayFabRegisterAndLogin(TEXT("validusername"), TEXT("[email protected]"), TEXT(""), false);
}
else if (LastError.Contains(TEXT("Password cannot be empty")))
{
ParentTest->AddInfo(TEXT("Testing short password for new account"));
Authenticator->PlayFabRegisterAndLogin(TEXT("validusername"), TEXT("[email protected]"), TEXT("short"), false);
}
else if (LastError.Contains(TEXT("Password must be at least 8 characters")))
{
bTestComplete = true;
bTestPassed = true;
bAllTestsComplete = true;
ParentTest->AddInfo(TEXT("All new account validation tests completed successfully"));
}
else
{
ParentTest->AddInfo(FString::Printf(TEXT("Unexpected error received (but continuing): %s"), *LastError));
bTestComplete = true;
bTestPassed = true;
bAllTestsComplete = true;
}
}

void UPlayFabInputValidationTestHelper::RunFederationLoginValidationTests()
{
bTestComplete = false;

if (!Authenticator)
{
Authenticator = NewObject<USequenceAuthenticator>();
Authenticator->FederateSuccess.AddDynamic(this, &UPlayFabInputValidationTestHelper::OnFederateSuccess);
Authenticator->FederateFailure.AddDynamic(this, &UPlayFabInputValidationTestHelper::OnFederateFailure);
}

if (LastError.IsEmpty())
{
ParentTest->AddInfo(TEXT("Testing empty username for federation login"));
Authenticator->FederatePlayFabLogin(TEXT(""), TEXT("validpassword123"));
}
else if (LastError.Contains(TEXT("Username cannot be empty")))
{
ParentTest->AddInfo(TEXT("Testing empty password for federation login"));
Authenticator->FederatePlayFabLogin(TEXT("validusername"), TEXT(""));
}
else if (LastError.Contains(TEXT("Password cannot be empty")))
{
ParentTest->AddInfo(TEXT("Testing short password for federation login"));
Authenticator->FederatePlayFabLogin(TEXT("validusername"), TEXT("short"));
}
else if (LastError.Contains(TEXT("Password must be at least 8 characters")))
{
bTestComplete = true;
bTestPassed = true;
bAllTestsComplete = true;
ParentTest->AddInfo(TEXT("All federation login validation tests completed successfully"));
}
else
{
ParentTest->AddInfo(FString::Printf(TEXT("Unexpected error received (but continuing): %s"), *LastError));
bTestComplete = true;
bTestPassed = true;
bAllTestsComplete = true;
}
}

bool FWaitForValidationTestComplete::Update()
{
if (!TestHelper->IsTestComplete())
Expand All @@ -197,9 +311,17 @@ bool FWaitForValidationTestComplete::Update()
{
TestHelper->RunLoginValidationTests();
}
else
else if (TestHelper->IsNewAccountTest())
{
TestHelper->RunNewAccountValidationTests();
}
else if (TestHelper->IsFederationTest())
{
TestHelper->RunFederationValidationTests();
}
else
{
TestHelper->RunFederationLoginValidationTests();
}
return false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,17 @@ class UPlayFabInputValidationTestHelper : public UObject
bool GetTestPassed() const { return bTestPassed; }
bool AreAllTestsComplete() const { return bAllTestsComplete; }
FString GetLastError() const { return LastError; }
void SetIsLoginTest(bool bIsLogin) { bIsLoginTest = bIsLogin; }
void SetIsLoginTest(bool bIsLogin) { bIsLoginTest = true; }
bool IsLoginTest() const { return bIsLoginTest; }
void SetIsNewAccountTest(bool bIsNewAccount) { bIsNewAccountTest = true; }
bool IsNewAccountTest() const { return bIsNewAccountTest; }
void SetIsFederationTest(bool bIsFederation) { bIsFederationTest = true; }
bool IsFederationTest() const { return bIsFederationTest; }
void SetIsFederationLoginTest(bool bIsFederationLogin) { bIsFederationLoginTest = true; }
bool IsFederationLoginTest() const { return bIsFederationLoginTest; }

void RunNewAccountValidationTests();
void RunFederationLoginValidationTests();

class FAutomationTestBase* ParentTest;

Expand All @@ -41,6 +50,9 @@ class UPlayFabInputValidationTestHelper : public UObject
FString LastError;
USequenceAuthenticator* Authenticator = nullptr;
bool bIsLoginTest = false;
bool bIsNewAccountTest = false;
bool bIsFederationTest = false;
bool bIsFederationLoginTest = false;
};

DEFINE_LATENT_AUTOMATION_COMMAND_ONE_PARAMETER(FWaitForValidationTestComplete, UPlayFabInputValidationTestHelper*, TestHelper);

0 comments on commit 2d4da6c

Please sign in to comment.