Browse Source

AWSClientAuth: Remove confusing long spam when cognito is not configured (#8971)

* Avoid initializing cognito controllers when config is missing to avoid log spam
* Adds unit test, event call and clean up some overrides

Signed-off-by: Pip Potter <[email protected]>
Pip Potter 3 years ago
parent
commit
ef0f6c01bf

+ 7 - 1
Gems/AWSClientAuth/Code/Source/AWSClientAuthBus.h

@@ -39,9 +39,15 @@ namespace AWSClientAuth
         //! std shared_ptr as the ownership has to be shared with AWS Native SDK.
         //! @return AWS Native SDK Cognito Identity client
         virtual std::shared_ptr<Aws::CognitoIdentity::CognitoIdentityClient> GetCognitoIdentityClient() = 0;
+
+        //! Sanity check for Cognito identity and user controllers to see if they have been configured. Gem will skip set up of controllers
+        //! when configuration is missing to avoid making calls to Cognito that are guaranteed to fail.
+        //! @return True, the controllers configured to support user and identify management have been initialized.
+        //! If False, then either user pool or identity pool configuration is missing. Refer to the Gem documentation about how to provide this configuration.
+        virtual bool HasCognitoControllers() const = 0;
     };
 
-    //! Responsible for fetching AWS Cognito IDP and Identity service client objetcs.
+    //! Responsible for fetching AWS Cognito IDP and Identity service client objects.
     class AWSClientAuthRequests
         : public AZ::EBusTraits
     {

+ 30 - 6
Gems/AWSClientAuth/Code/Source/AWSClientAuthSystemComponent.cpp

@@ -12,10 +12,10 @@
 #include <UserManagement/UserManagementNotificationBusBehaviorHandler.h>
 #include <Authorization/AWSCognitoAuthorizationNotificationBusBehaviorHandler.h>
 #include <Authorization/AWSCognitoAuthorizationController.h>
-#include <AzCore/std/smart_ptr/make_shared.h>
+#include <AWSClientAuthResourceMappingConstants.h>
 #include <ResourceMapping/AWSResourceMappingBus.h>
 #include <Framework/AWSApiJobConfig.h>
-
+#include <ResourceMapping/AWSResourceMappingBus.h>
 #include <aws/cognito-identity/CognitoIdentityClient.h>
 #include <aws/cognito-idp/CognitoIdentityProviderClient.h>
 
@@ -169,10 +169,29 @@ namespace AWSClientAuth
         AZ::Interface<IAWSClientAuthRequests>::Register(this);
         AWSClientAuthRequestBus::Handler::BusConnect();
 
-        // Objects below depend on bus above.
         m_authenticationProviderManager = AZStd::make_unique<AuthenticationProviderManager>();
-        m_awsCognitoUserManagementController = AZStd::make_unique<AWSCognitoUserManagementController>();
-        m_awsCognitoAuthorizationController = AZStd::make_unique<AWSCognitoAuthorizationController>();
+
+        // Sanity check if code should setup Cognito user and autorization controllers.
+        // Only set up if Cognito settings appear to be provided in resource mapping file.
+        AZStd::string userPoolId;
+        AWSCore::AWSResourceMappingRequestBus::BroadcastResult(
+            userPoolId, &AWSCore::AWSResourceMappingRequests::GetResourceNameId, CognitoUserPoolIdResourceMappingKey);
+
+        AZStd::string cognitoIdentityPoolId;
+         AWSCore::AWSResourceMappingRequestBus::BroadcastResult(
+            cognitoIdentityPoolId, &AWSCore::AWSResourceMappingRequests::GetResourceNameId, CognitoIdentityPoolIdResourceMappingKey);
+
+        if (userPoolId.empty() && cognitoIdentityPoolId.empty())
+        {
+            AZ_Warning("AWSClientAuthSystemComponent",  false,
+                "Missing Cognito settings in resource mappings. Skipping set up of Cognito controllers.");
+        }
+        else
+        {
+            // Objects below depend on bus above.
+            m_awsCognitoUserManagementController = AZStd::make_unique<AWSCognitoUserManagementController>();
+            m_awsCognitoAuthorizationController = AZStd::make_unique<AWSCognitoAuthorizationController>();
+        }
 
         AWSCore::AWSCoreEditorRequestBus::Broadcast(&AWSCore::AWSCoreEditorRequests::SetAWSClientAuthEnabled);
     }
@@ -182,7 +201,7 @@ namespace AWSClientAuth
         m_authenticationProviderManager.reset();
         m_awsCognitoUserManagementController.reset();
         m_awsCognitoAuthorizationController.reset();
-
+        
         AWSClientAuthRequestBus::Handler::BusDisconnect();
         AWSCore::AWSCoreNotificationsBus::Handler::BusDisconnect();
         AZ::Interface<IAWSClientAuthRequests>::Unregister(this);
@@ -222,4 +241,9 @@ namespace AWSClientAuth
         return m_cognitoIdentityClient;
     }
 
+    bool AWSClientAuthSystemComponent::HasCognitoControllers() const
+    {
+        return (m_awsCognitoUserManagementController != nullptr) || (m_awsCognitoAuthorizationController != nullptr);
+    }
+
 } // namespace AWSClientAuth

+ 3 - 3
Gems/AWSClientAuth/Code/Source/AWSClientAuthSystemComponent.h

@@ -17,15 +17,14 @@
 
 namespace AWSClientAuth
 {
-    //! Gem System Component. Responsible for instantiating and managing Authentication and Authroziation Controller
+    //! Gem System Component. Responsible for instantiating and managing Authentication and Authorization Controller
     class AWSClientAuthSystemComponent
         : public AZ::Component
         , public AWSCore::AWSCoreNotificationsBus::Handler
         , public AWSClientAuthRequestBus::Handler
     {
     public:
-
-        virtual ~AWSClientAuthSystemComponent() = default;
+        ~AWSClientAuthSystemComponent() override = default;
 
         AZ_COMPONENT(AWSClientAuthSystemComponent, "{0C2660C8-1B4A-4474-BE65-B487E2DE8649}");
 
@@ -49,6 +48,7 @@ namespace AWSClientAuth
         // AWSClientAuthRequests interface
         std::shared_ptr<Aws::CognitoIdentityProvider::CognitoIdentityProviderClient> GetCognitoIDPClient() override;
         std::shared_ptr<Aws::CognitoIdentity::CognitoIdentityClient> GetCognitoIdentityClient() override;
+        bool HasCognitoControllers() const override;
 
         AZStd::vector<ProviderNameEnum> m_enabledProviderNames;
         AZStd::unique_ptr<AuthenticationProviderManager> m_authenticationProviderManager;

+ 1 - 1
Gems/AWSClientAuth/Code/Source/UserManagement/AWSCognitoUserManagementController.h

@@ -19,7 +19,7 @@ namespace AWSClientAuth
     public:
         AZ_RTTI(AWSCognitoUserManagementController, "{2645D1CC-EB55-4A8D-8F45-5DFE94032813}", IAWSCognitoUserManagementRequests);
         AWSCognitoUserManagementController();
-        virtual ~AWSCognitoUserManagementController();
+        ~AWSCognitoUserManagementController() override;
 
         // AWSCognitoUserManagementRequestsBus interface methods
         bool Initialize() override;

+ 138 - 69
Gems/AWSClientAuth/Code/Tests/AWSClientAuthGemMock.h

@@ -96,7 +96,8 @@ namespace AWSClientAuthUnitTest
             ON_CALL(*this, GetResourceNameId).WillByDefault(testing::Return(TEST_RESOURCE_NAME_ID));
             ON_CALL(*this, GetDefaultRegion).WillByDefault(testing::Return(TEST_REGION));
         }
-        ~AWSResourceMappingRequestBusMock()
+
+        ~AWSResourceMappingRequestBusMock() override
         {
             AWSCore::AWSResourceMappingRequestBus::Handler::BusDisconnect();
         }
@@ -126,7 +127,7 @@ namespace AWSClientAuthUnitTest
             ON_CALL(*this, GetDefaultConfig).WillByDefault(testing::Return(nullptr));
         }
 
-        ~AWSCoreRequestBusMock()
+        ~AWSCoreRequestBusMock() override
         {
             AWSCore::AWSCoreRequestBus::Handler::BusDisconnect();
         }
@@ -141,11 +142,12 @@ namespace AWSClientAuthUnitTest
     public:
         HttpRequestorRequestBusMock()
         {
-            ON_CALL(*this, AddRequestWithHeadersAndBody(testing::_, testing::_, testing::_, testing::_, testing::_)).WillByDefault(testing::Invoke(this, &HttpRequestorRequestBusMock::AddRequestWithHeadersAndBodyMock));
+            ON_CALL(*this, AddRequestWithHeadersAndBody(testing::_, testing::_, testing::_, testing::_, testing::_))
+                .WillByDefault(testing::Invoke(this, &HttpRequestorRequestBusMock::AddRequestWithHeadersAndBodyMock));
             HttpRequestor::HttpRequestorRequestBus::Handler::BusConnect();
         }
 
-        virtual ~HttpRequestorRequestBusMock()
+        ~HttpRequestorRequestBusMock() override
         {
             HttpRequestor::HttpRequestorRequestBus::Handler::BusDisconnect();
         }
@@ -180,6 +182,7 @@ namespace AWSClientAuthUnitTest
             AZ_UNUSED(headers);
             AZ_UNUSED(callback);
         }
+
         void AddRequestWithHeadersAndBodyMock(const AZStd::string& URI, Aws::Http::HttpMethod method, const HttpRequestor::Headers& headers, const AZStd::string& body, const HttpRequestor::Callback& callback)
         {
             AZ_UNUSED(URI);
@@ -206,6 +209,7 @@ namespace AWSClientAuthUnitTest
             AZ_UNUSED(method);
             AZ_UNUSED(callback);
         }
+
         void AddTextRequestWithHeaders(const AZStd::string& URI, Aws::Http::HttpMethod method, const HttpRequestor::Headers& headers, const HttpRequestor::TextCallback& callback) override
         {
             AZ_UNUSED(URI);
@@ -213,6 +217,7 @@ namespace AWSClientAuthUnitTest
             AZ_UNUSED(headers);
             AZ_UNUSED(callback);
         }
+
         void AddTextRequestWithHeadersAndBody(const AZStd::string& URI, Aws::Http::HttpMethod method, const HttpRequestor::Headers& headers, const AZStd::string& body, const HttpRequestor::TextCallback& callback) override
         {
             AZ_UNUSED(URI);
@@ -227,8 +232,8 @@ namespace AWSClientAuthUnitTest
         : public Aws::CognitoIdentityProvider::CognitoIdentityProviderClient
     {
     public:
-
-        CognitoIdentityProviderClientMock() : Aws::CognitoIdentityProvider::CognitoIdentityProviderClient(Aws::Auth::AWSCredentials())
+        CognitoIdentityProviderClientMock()
+            : Aws::CognitoIdentityProvider::CognitoIdentityProviderClient(Aws::Auth::AWSCredentials())
         {
             ON_CALL(*this, InitiateAuth(testing::_)).WillByDefault(testing::Invoke(this, &CognitoIdentityProviderClientMock::InitiateAuthMock));
             ON_CALL(*this, SignUp(testing::_)).WillByDefault(testing::Invoke(this, &CognitoIdentityProviderClientMock::SignUpMock));
@@ -239,21 +244,27 @@ namespace AWSClientAuthUnitTest
             ON_CALL(*this, SetUserMFAPreference(testing::_)).WillByDefault(testing::Invoke(this, &CognitoIdentityProviderClientMock::SetUserMFAPreferenceMock));
         }
 
-        MOCK_CONST_METHOD1(InitiateAuth
-            , Aws::CognitoIdentityProvider::Model::InitiateAuthOutcome(const Aws::CognitoIdentityProvider::Model::InitiateAuthRequest& request));
-        MOCK_CONST_METHOD1(RespondToAuthChallenge
-            , Aws::CognitoIdentityProvider::Model::RespondToAuthChallengeOutcome(const Aws::CognitoIdentityProvider::Model::RespondToAuthChallengeRequest& request));
-        MOCK_CONST_METHOD1(SignUp
-            , Aws::CognitoIdentityProvider::Model::SignUpOutcome(const Aws::CognitoIdentityProvider::Model::SignUpRequest& request));
-        MOCK_CONST_METHOD1(ConfirmSignUp
-            , Aws::CognitoIdentityProvider::Model::ConfirmSignUpOutcome(const Aws::CognitoIdentityProvider::Model::ConfirmSignUpRequest& request));
-        MOCK_CONST_METHOD1(ForgotPassword
-            , Aws::CognitoIdentityProvider::Model::ForgotPasswordOutcome(const Aws::CognitoIdentityProvider::Model::ForgotPasswordRequest& request));
-        MOCK_CONST_METHOD1(ConfirmForgotPassword
-            , Aws::CognitoIdentityProvider::Model::ConfirmForgotPasswordOutcome(const Aws::CognitoIdentityProvider::Model::ConfirmForgotPasswordRequest& request));
-        MOCK_CONST_METHOD1(SetUserMFAPreference
-            , Aws::CognitoIdentityProvider::Model::SetUserMFAPreferenceOutcome(const Aws::CognitoIdentityProvider::Model::SetUserMFAPreferenceRequest& request));
-
+        MOCK_CONST_METHOD1(
+            InitiateAuth,
+            Aws::CognitoIdentityProvider::Model::InitiateAuthOutcome(const Aws::CognitoIdentityProvider::Model::InitiateAuthRequest& request));
+        MOCK_CONST_METHOD1(
+            RespondToAuthChallenge,
+            Aws::CognitoIdentityProvider::Model::RespondToAuthChallengeOutcome(const Aws::CognitoIdentityProvider::Model::RespondToAuthChallengeRequest& request));
+        MOCK_CONST_METHOD1(
+            SignUp,
+            Aws::CognitoIdentityProvider::Model::SignUpOutcome(const Aws::CognitoIdentityProvider::Model::SignUpRequest& request));
+        MOCK_CONST_METHOD1(
+            ConfirmSignUp,
+            Aws::CognitoIdentityProvider::Model::ConfirmSignUpOutcome(const Aws::CognitoIdentityProvider::Model::ConfirmSignUpRequest& request));
+        MOCK_CONST_METHOD1(
+            ForgotPassword,
+            Aws::CognitoIdentityProvider::Model::ForgotPasswordOutcome(const Aws::CognitoIdentityProvider::Model::ForgotPasswordRequest& request));
+        MOCK_CONST_METHOD1(
+            ConfirmForgotPassword,
+            Aws::CognitoIdentityProvider::Model::ConfirmForgotPasswordOutcome(const Aws::CognitoIdentityProvider::Model::ConfirmForgotPasswordRequest& request));
+        MOCK_CONST_METHOD1(
+            SetUserMFAPreference,
+            Aws::CognitoIdentityProvider::Model::SetUserMFAPreferenceOutcome(const Aws::CognitoIdentityProvider::Model::SetUserMFAPreferenceRequest& request));
 
         Aws::CognitoIdentityProvider::Model::InitiateAuthOutcome InitiateAuthMock(const Aws::CognitoIdentityProvider::Model::InitiateAuthRequest& request)
         {
@@ -316,7 +327,7 @@ namespace AWSClientAuthUnitTest
             Aws::CognitoIdentityProvider::Model::ConfirmForgotPasswordOutcome outcome(result);
             return outcome;
         }
-        
+
         Aws::CognitoIdentityProvider::Model::SetUserMFAPreferenceOutcome SetUserMFAPreferenceMock(const Aws::CognitoIdentityProvider::Model::SetUserMFAPreferenceRequest& request)
         {
             AZ_UNUSED(request);
@@ -330,17 +341,17 @@ namespace AWSClientAuthUnitTest
         : public Aws::CognitoIdentity::CognitoIdentityClient
     {
     public:
-        CognitoIdentityClientMock() : Aws::CognitoIdentity::CognitoIdentityClient(Aws::Auth::AWSCredentials())
+        CognitoIdentityClientMock()
+            : Aws::CognitoIdentity::CognitoIdentityClient(Aws::Auth::AWSCredentials())
         {
             ON_CALL(*this, GetId(testing::_)).WillByDefault(testing::Invoke(this, &CognitoIdentityClientMock::GetIdMock));
             ON_CALL(*this, GetCredentialsForIdentity(testing::_)).WillByDefault(testing::Invoke(this, &CognitoIdentityClientMock::GetCredentialsForIdentityMock));
         }
 
-        MOCK_CONST_METHOD1(GetId
-            , Aws::CognitoIdentity::Model::GetIdOutcome(const Aws::CognitoIdentity::Model::GetIdRequest& request));
-        MOCK_CONST_METHOD1(GetCredentialsForIdentity
-            , Aws::CognitoIdentity::Model::GetCredentialsForIdentityOutcome(const Aws::CognitoIdentity::Model::GetCredentialsForIdentityRequest& request));
-
+        MOCK_CONST_METHOD1(GetId, Aws::CognitoIdentity::Model::GetIdOutcome(const Aws::CognitoIdentity::Model::GetIdRequest& request));
+        MOCK_CONST_METHOD1(
+            GetCredentialsForIdentity,
+            Aws::CognitoIdentity::Model::GetCredentialsForIdentityOutcome(const Aws::CognitoIdentity::Model::GetCredentialsForIdentityRequest& request));
 
         Aws::CognitoIdentity::Model::GetIdOutcome GetIdMock(const Aws::CognitoIdentity::Model::GetIdRequest& request)
         {
@@ -370,13 +381,12 @@ namespace AWSClientAuthUnitTest
         : public AWSClientAuth::AuthenticationProviderInterface
     {
     public:
-
         AuthenticationProviderMock()
         {
             ON_CALL(*this, Initialize()).WillByDefault(testing::Return(true));
         }
 
-        virtual ~AuthenticationProviderMock() = default;
+        ~AuthenticationProviderMock() override = default;
 
         MOCK_METHOD0(Initialize, bool());
         MOCK_METHOD2(PasswordGrantSingleFactorSignInAsync, void(const AZStd::string& username, const AZStd::string& password));
@@ -403,7 +413,7 @@ namespace AWSClientAuthUnitTest
             AWSClientAuth::AuthenticationProviderNotificationBus::Handler::BusConnect();
         }
 
-        virtual ~AuthenticationProviderNotificationsBusMock()
+        ~AuthenticationProviderNotificationsBusMock() override
         {
             AWSClientAuth::AuthenticationProviderNotificationBus::Handler::BusDisconnect();
         }
@@ -425,19 +435,14 @@ namespace AWSClientAuthUnitTest
     private:
         void AssertAuthenticationTokensPopulated([[maybe_unused]] const AWSClientAuth::AuthenticationTokens& authenticationToken)
         {
+            AZ_Assert(authenticationToken.GetAccessToken() == TEST_ACCESS_TOKEN, "Access token expected to match");
             AZ_Assert(
-                authenticationToken.GetAccessToken() == TEST_ACCESS_TOKEN,
-                "Access token expected to match");
-            AZ_Assert(
-                authenticationToken.GetProviderName() == AWSClientAuth::ProviderNameEnum::LoginWithAmazon ?
-                    authenticationToken.GetOpenIdToken() == TEST_ACCESS_TOKEN : authenticationToken.GetOpenIdToken() == TEST_ID_TOKEN,
+                authenticationToken.GetProviderName() == AWSClientAuth::ProviderNameEnum::LoginWithAmazon
+                    ? authenticationToken.GetOpenIdToken() == TEST_ACCESS_TOKEN
+                    : authenticationToken.GetOpenIdToken() == TEST_ID_TOKEN,
                 "Id token expected to match");
-            AZ_Assert(
-                authenticationToken.GetRefreshToken() == TEST_REFRESH_TOKEN,
-                "Refresh token expected match");
-            AZ_Assert(
-                authenticationToken.GetTokensExpireTimeSeconds() != 0,
-                "Access token expiry expected to be set");
+            AZ_Assert(authenticationToken.GetRefreshToken() == TEST_REFRESH_TOKEN, "Refresh token expected match");
+            AZ_Assert(authenticationToken.GetTokensExpireTimeSeconds() != 0, "Access token expiry expected to be set");
             AZ_Assert(authenticationToken.AreTokensValid(), "Tokens expected to be valid");
         }
     };
@@ -451,7 +456,7 @@ namespace AWSClientAuthUnitTest
             AWSClientAuth::AWSCognitoAuthorizationNotificationBus::Handler::BusConnect();
         }
 
-        virtual ~AWSCognitoAuthorizationNotificationsBusMock()
+        ~AWSCognitoAuthorizationNotificationsBusMock() override
         {
             AWSClientAuth::AWSCognitoAuthorizationNotificationBus::Handler::BusDisconnect();
         }
@@ -469,7 +474,7 @@ namespace AWSClientAuthUnitTest
             AWSClientAuth::AWSCognitoUserManagementNotificationBus::Handler::BusConnect();
         }
 
-        virtual ~AWSCognitoUserManagementNotificationsBusMock()
+        ~AWSCognitoUserManagementNotificationsBusMock() override
         {
             AWSClientAuth::AWSCognitoUserManagementNotificationBus::Handler::BusDisconnect();
         }
@@ -494,10 +499,8 @@ namespace AWSClientAuthUnitTest
         , public AWSClientAuth::AWSClientAuthRequestBus::Handler
     {
     public:
-
         AWSClientAuthGemAllocatorFixture()
         {
-
         }
 
         AWSClientAuthGemAllocatorFixture(bool connectClientAuthBus)
@@ -505,7 +508,7 @@ namespace AWSClientAuthUnitTest
             m_connectClientAuthBus = connectClientAuthBus;
         }
 
-        virtual ~AWSClientAuthGemAllocatorFixture() = default;
+        ~AWSClientAuthGemAllocatorFixture() override = default;
 
     protected:
         AZStd::shared_ptr<AZ::SerializeContext> m_serializeContext;
@@ -524,6 +527,7 @@ namespace AWSClientAuthUnitTest
         AuthenticationProviderNotificationsBusMock m_authenticationProviderNotificationsBusMock;
         AWSCognitoAuthorizationNotificationsBusMock m_awsCognitoAuthorizationNotificationsBusMock;
         AWSCognitoUserManagementNotificationsBusMock m_awsCognitoUserManagementNotificationsBusMock;
+        bool m_hasCognitoControllers = true;
 
         void SetUp() override
         {
@@ -609,31 +613,91 @@ namespace AWSClientAuthUnitTest
             m_serializeContext.reset();
             m_registrationContext.reset();
 
-
             delete AZ::IO::FileIOBase::GetInstance();
             AZ::IO::FileIOBase::SetInstance(nullptr);
-
         }
 
         // ComponentApplicationBus overrides. Required by settings registry for json serialization context.
-        AZ::ComponentApplication* GetApplication() override { return nullptr; }
-        void RegisterComponentDescriptor(const AZ::ComponentDescriptor*) override { }
-        void UnregisterComponentDescriptor(const AZ::ComponentDescriptor*) override { }
-        void RegisterEntityAddedEventHandler(AZ::EntityAddedEvent::Handler&) override { }
-        void RegisterEntityRemovedEventHandler(AZ::EntityRemovedEvent::Handler&) override { }
-        void RegisterEntityActivatedEventHandler(AZ::EntityActivatedEvent::Handler&) override { }
-        void RegisterEntityDeactivatedEventHandler(AZ::EntityDeactivatedEvent::Handler&) override { }
-        void SignalEntityActivated(AZ::Entity*) override { }
-        void SignalEntityDeactivated(AZ::Entity*) override { }
-        bool AddEntity(AZ::Entity*) override { return true; }
-        bool RemoveEntity(AZ::Entity*) override { return true; }
-        bool DeleteEntity(const AZ::EntityId&) override { return true; }
-        AZ::Entity* FindEntity(const AZ::EntityId&) override { return nullptr; }
-        AZ::BehaviorContext* GetBehaviorContext() override { return nullptr; }
-        const char* GetExecutableFolder() const override { return nullptr; }
-        const char* GetEngineRoot() const override { return nullptr; }
-        void EnumerateEntities(const EntityCallback& /*callback*/) override {}
-        void QueryApplicationType(AZ::ApplicationTypeQuery& /*appType*/) const override {}
+        AZ::ComponentApplication* GetApplication() override
+        {
+            return nullptr;
+        }
+
+        void RegisterComponentDescriptor(const AZ::ComponentDescriptor*) override
+        {
+        }
+
+        void UnregisterComponentDescriptor(const AZ::ComponentDescriptor*) override
+        {
+        }
+
+        void RegisterEntityAddedEventHandler(AZ::EntityAddedEvent::Handler&) override
+        {
+        }
+
+        void RegisterEntityRemovedEventHandler(AZ::EntityRemovedEvent::Handler&) override
+        {
+        }
+
+        void RegisterEntityActivatedEventHandler(AZ::EntityActivatedEvent::Handler&) override
+        {
+        }
+
+        void RegisterEntityDeactivatedEventHandler(AZ::EntityDeactivatedEvent::Handler&) override
+        {
+        }
+
+        void SignalEntityActivated(AZ::Entity*) override
+        {
+        }
+
+        void SignalEntityDeactivated(AZ::Entity*) override
+        {
+        }
+
+        bool AddEntity(AZ::Entity*) override
+        {
+            return true;
+        }
+
+        bool RemoveEntity(AZ::Entity*) override
+        {
+            return true;
+        }
+
+        bool DeleteEntity(const AZ::EntityId&) override
+        {
+            return true;
+        }
+
+        AZ::Entity* FindEntity(const AZ::EntityId&) override
+        {
+            return nullptr;
+        }
+
+        AZ::BehaviorContext* GetBehaviorContext() override
+        {
+            return nullptr;
+        }
+
+        const char* GetExecutableFolder() const override
+        {
+            return nullptr;
+        }
+
+        const char* GetEngineRoot() const override
+        {
+            return nullptr;
+        }
+
+        void EnumerateEntities(const EntityCallback& /*callback*/) override
+        {
+        }
+
+        void QueryApplicationType(AZ::ApplicationTypeQuery& /*appType*/) const override
+        {
+        }
+
         AZ::SerializeContext* GetSerializeContext() override
         {
             return m_serializeContext.get();
@@ -655,6 +719,11 @@ namespace AWSClientAuthUnitTest
             return m_cognitoIdentityClientMock;
         }
 
+        bool HasCognitoControllers() const override
+        {
+            return m_hasCognitoControllers;
+        }
+
         // TODO Add safety check. Also use pattern to create and remove one file.
         static void DeleteFolderRecursive(const AZStd::string& path)
         {
@@ -707,5 +776,5 @@ namespace AWSClientAuthUnitTest
             m_testFolderCreated = true;
             return path;
         }
-    };  
-}
+    };
+} // namespace AWSClientAuthUnitTest

+ 33 - 3
Gems/AWSClientAuth/Code/Tests/AWSClientAuthSystemComponentTest.cpp

@@ -13,6 +13,7 @@
 #include <AzCore/Component/Entity.h>
 #include <AzFramework/IO/LocalFileIO.h>
 #include <AWSClientAuthGemMock.h>
+#include <AWSClientAuthResourceMappingConstants.h>
 
 namespace AWSClientAuthUnitTest
 {
@@ -49,7 +50,7 @@ namespace AWSClientAuthUnitTest
         MOCK_METHOD0(Activate, void());
         MOCK_METHOD0(Deactivate, void());
 
-        AZStd::vector<AWSClientAuth::ProviderNameEnum> m_enabledProviderNames;        
+        using AWSClientAuth::AWSClientAuthSystemComponent::m_enabledProviderNames;        
     };
 
     class AWSCoreSystemComponentMock
@@ -87,10 +88,12 @@ namespace AWSClientAuthUnitTest
         {
             AZ_UNUSED(incompatible);
         }
+
         static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
         {
             AZ_UNUSED(required);
         }
+
         static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
         {
             AZ_UNUSED(dependent);
@@ -119,10 +122,11 @@ class AWSClientAuthSystemComponentTest
 {
 public:
     AWSClientAuthSystemComponentTest()
-        : AWSClientAuthUnitTest::AWSClientAuthGemAllocatorFixture(false)
+        : AWSClientAuthUnitTest::AWSClientAuthGemAllocatorFixture(false), m_awsClientAuthSystemsComponent(nullptr),
+          m_awsCoreSystemsComponent(nullptr)
     {
-
     }
+
 protected:
     AZStd::unique_ptr<AZ::ComponentDescriptor> m_componentDescriptor;
     AZStd::unique_ptr<AZ::ComponentDescriptor> m_awsCoreComponentDescriptor;
@@ -202,6 +206,32 @@ TEST_F(AWSClientAuthSystemComponentTest, GetCognitoClients_Success)
     m_entity->Init();
     m_entity->Activate();
 
+    EXPECT_TRUE(AZ::Interface<IAWSClientAuthRequests>::Get()->HasCognitoControllers());
+    EXPECT_TRUE(AZ::Interface<IAWSClientAuthRequests>::Get()->GetCognitoIdentityClient() != nullptr);
+    EXPECT_TRUE(AZ::Interface<IAWSClientAuthRequests>::Get()->GetCognitoIDPClient() != nullptr);
+
+    // deactivate component
+    m_entity->Deactivate();
+}
+
+TEST_F(AWSClientAuthSystemComponentTest, SkipCognitoControllers_Success)
+{
+    EXPECT_CALL(m_awsResourceMappingRequestBusMock, GetResourceNameId(AZStd::string(CognitoUserPoolIdResourceMappingKey)))
+        .Times(1)
+        .WillOnce(testing::Return(""));
+
+    EXPECT_CALL(m_awsResourceMappingRequestBusMock, GetResourceNameId(AZStd::string(CognitoIdentityPoolIdResourceMappingKey)))
+        .Times(1)
+        .WillOnce(testing::Return(""));
+
+    // activate component
+    m_entity->Init();
+    m_entity->Activate();
+
+    // Expect controllers are not configured
+    EXPECT_FALSE(AZ::Interface<IAWSClientAuthRequests>::Get()->HasCognitoControllers());
+
+    // These should still be available
     EXPECT_TRUE(AZ::Interface<IAWSClientAuthRequests>::Get()->GetCognitoIdentityClient() != nullptr);
     EXPECT_TRUE(AZ::Interface<IAWSClientAuthRequests>::Get()->GetCognitoIDPClient() != nullptr);