From 2d4da6c62a48d4cb8ae163d8e48bb8343806baa4 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 8 Jan 2025 14:54:18 -0500 Subject: [PATCH] Added additional tests for remaining paths --- .../Private/SequenceAuthenticator.cpp | 2 +- .../PlayfabInputValidationTest.cpp | 128 +++++++++++++++++- .../PlayfabInputValidationTest.h | 14 +- 3 files changed, 139 insertions(+), 5 deletions(-) diff --git a/Plugins/SequencePlugin/Source/SequencePlugin/Private/SequenceAuthenticator.cpp b/Plugins/SequencePlugin/Source/SequencePlugin/Private/SequenceAuthenticator.cpp index 424c461b..5a08d5ea 100644 --- a/Plugins/SequencePlugin/Source/SequencePlugin/Private/SequenceAuthenticator.cpp +++ b/Plugins/SequencePlugin/Source/SequencePlugin/Private/SequenceAuthenticator.cpp @@ -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); }; diff --git a/Plugins/SequenceTests/Source/SequenceTests/Private/SessionManagementEndToEndTests/PlayfabInputValidationTest.cpp b/Plugins/SequenceTests/Source/SequenceTests/Private/SessionManagementEndToEndTests/PlayfabInputValidationTest.cpp index c4255b69..0487c0fd 100644 --- a/Plugins/SequenceTests/Source/SequenceTests/Private/SessionManagementEndToEndTests/PlayfabInputValidationTest.cpp +++ b/Plugins/SequenceTests/Source/SequenceTests/Private/SessionManagementEndToEndTests/PlayfabInputValidationTest.cpp @@ -12,8 +12,14 @@ void FPlayFabInputValidationTests::GetTests(TArray& 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) @@ -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; @@ -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(); + 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("valid@email.com"), 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("valid@email.com"), 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("valid@email.com"), 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(); + 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()) @@ -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; } diff --git a/Plugins/SequenceTests/Source/SequenceTests/Private/SessionManagementEndToEndTests/PlayfabInputValidationTest.h b/Plugins/SequenceTests/Source/SequenceTests/Private/SessionManagementEndToEndTests/PlayfabInputValidationTest.h index bee58791..ef0e0dc9 100644 --- a/Plugins/SequenceTests/Source/SequenceTests/Private/SessionManagementEndToEndTests/PlayfabInputValidationTest.h +++ b/Plugins/SequenceTests/Source/SequenceTests/Private/SessionManagementEndToEndTests/PlayfabInputValidationTest.h @@ -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; @@ -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);