123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include <AzCore/Settings/SettingsRegistry.h>
- #include <AzFramework/StringFunc/StringFunc.h>
- #include <Configuration/AWSCoreConfiguration.h>
- #include <TestFramework/AWSCoreFixture.h>
- using namespace AWSCore;
- static constexpr const char TEST_VALID_RESOURCE_MAPPING_SETREG[] =
- R"({
- "Amazon":
- {
- "AWSCore": {
- "ProfileName": "testprofile",
- "ResourceMappingConfigFileName": "test_aws_resource_mappings.json",
- "AllowAWSMetadataCredentials": true,
- }
- }
- })";
- static constexpr const char TEST_INVALID_RESOURCE_MAPPING_SETREG[] =
- R"({
- "Amazon":
- {
- "AWSCore": {
- }
- }
- })";
- class AWSCoreConfigurationTest
- : public AWSCoreFixture
- {
- public:
- AWSCoreConfigurationTest()
- {
- m_setRegFilePath = (GetTestTempDirectoryPath() /
- AZ::SettingsRegistryInterface::RegistryFolder /
- AWSCore::AWSCoreConfiguration::AWSCoreConfigurationFileName).LexicallyNormal();
- }
- void SetUp() override
- {
- AWSCoreFixture::SetUp();
- m_awsCoreConfiguration = AZStd::make_unique<AWSCore::AWSCoreConfiguration>();
- CreateFile(m_setRegFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_SETREG);
- m_localFileIO->SetAlias("@projectroot@", GetTestTempDirectoryPath().Native().c_str());
- }
- void TearDown() override
- {
- RemoveFile(m_setRegFilePath.Native());
- m_awsCoreConfiguration.reset();
- AWSCoreFixture::TearDown();
- }
- AZStd::unique_ptr<AWSCore::AWSCoreConfiguration> m_awsCoreConfiguration;
- AZ::IO::Path m_setRegFilePath;
- };
- TEST_F(AWSCoreConfigurationTest, InitConfig_NoSourceProjectFolderFound_ReturnEmptyConfigFilePath)
- {
- m_settingsRegistry->MergeSettingsFile(m_setRegFilePath.Native(), AZ::SettingsRegistryInterface::Format::JsonMergePatch, {});
- m_localFileIO->ClearAlias("@projectroot@");
- AZ_TEST_START_TRACE_SUPPRESSION;
- m_awsCoreConfiguration->InitConfig();
- AZ_TEST_STOP_TRACE_SUPPRESSION(1); // expect the above have thrown an AZ_Error
- auto actualConfigFilePath = m_awsCoreConfiguration->GetResourceMappingConfigFilePath();
- EXPECT_TRUE(actualConfigFilePath.empty());
- }
- TEST_F(AWSCoreConfigurationTest, InitConfig_SettingsRegistryIsEmpty_ReturnEmptyConfigFilePath)
- {
- CreateFile(m_setRegFilePath.Native(), TEST_INVALID_RESOURCE_MAPPING_SETREG);
- m_settingsRegistry->MergeSettingsFile(m_setRegFilePath.Native(), AZ::SettingsRegistryInterface::Format::JsonMergePatch, {});
- m_awsCoreConfiguration->InitConfig();
- auto actualConfigFilePath = m_awsCoreConfiguration->GetResourceMappingConfigFilePath();
- EXPECT_TRUE(actualConfigFilePath.empty());
- }
- TEST_F(AWSCoreConfigurationTest, InitConfig_LoadValidSettingsRegistry_ReturnNonEmptyConfigFilePath)
- {
- m_settingsRegistry->MergeSettingsFile(m_setRegFilePath.Native(), AZ::SettingsRegistryInterface::Format::JsonMergePatch, {});
- m_awsCoreConfiguration->InitConfig();
- auto actualConfigFilePath = m_awsCoreConfiguration->GetResourceMappingConfigFilePath();
- EXPECT_FALSE(actualConfigFilePath.empty());
- }
- TEST_F(AWSCoreConfigurationTest, ReloadConfiguration_NoSourceProjectFolderFound_ReturnEmptyConfigFilePath)
- {
- m_settingsRegistry->MergeSettingsFile(m_setRegFilePath.Native(), AZ::SettingsRegistryInterface::Format::JsonMergePatch, {});
- m_localFileIO->ClearAlias("@projectroot@");
- m_awsCoreConfiguration->ReloadConfiguration();
- auto actualConfigFilePath = m_awsCoreConfiguration->GetResourceMappingConfigFilePath();
- EXPECT_TRUE(actualConfigFilePath.empty());
- }
- TEST_F(AWSCoreConfigurationTest, ReloadConfiguration_LoadValidSettingsRegistryAfterInvalidOne_ReturnNonEmptyConfigFilePath)
- {
- CreateFile(m_setRegFilePath.Native(), TEST_INVALID_RESOURCE_MAPPING_SETREG);
- m_settingsRegistry->MergeSettingsFile(m_setRegFilePath.Native(), AZ::SettingsRegistryInterface::Format::JsonMergePatch, {});
- m_awsCoreConfiguration->InitConfig();
- auto actualConfigFilePath = m_awsCoreConfiguration->GetResourceMappingConfigFilePath();
- auto actualProfileName = m_awsCoreConfiguration->GetProfileName();
- auto actualAllowAWSMetadataCredentials = m_awsCoreConfiguration->IsAllowedAWSMetadataCredentials();
- EXPECT_TRUE(actualConfigFilePath.empty());
- EXPECT_TRUE(actualProfileName == AWSCoreConfiguration::AWSCoreDefaultProfileName);
- EXPECT_FALSE(actualAllowAWSMetadataCredentials);
- CreateFile(m_setRegFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_SETREG);
- m_awsCoreConfiguration->ReloadConfiguration();
- actualConfigFilePath = m_awsCoreConfiguration->GetResourceMappingConfigFilePath();
- actualProfileName = m_awsCoreConfiguration->GetProfileName();
- actualAllowAWSMetadataCredentials = m_awsCoreConfiguration->IsAllowedAWSMetadataCredentials();
- EXPECT_FALSE(actualConfigFilePath.empty());
- EXPECT_TRUE(actualProfileName != AWSCoreConfiguration::AWSCoreDefaultProfileName);
- EXPECT_TRUE(actualAllowAWSMetadataCredentials);
- }
- TEST_F(AWSCoreConfigurationTest, ReloadConfiguration_LoadInvalidSettingsRegistryAfterValidOne_ReturnEmptyConfigFilePath)
- {
- m_settingsRegistry->MergeSettingsFile(m_setRegFilePath.Native(), AZ::SettingsRegistryInterface::Format::JsonMergePatch, {});
- m_awsCoreConfiguration->InitConfig();
- auto actualConfigFilePath = m_awsCoreConfiguration->GetResourceMappingConfigFilePath();
- auto actualProfileName = m_awsCoreConfiguration->GetProfileName();
- auto actualAllowAWSMetadataCredentials = m_awsCoreConfiguration->IsAllowedAWSMetadataCredentials();
- EXPECT_FALSE(actualConfigFilePath.empty());
- EXPECT_TRUE(actualProfileName != AWSCoreConfiguration::AWSCoreDefaultProfileName);
- EXPECT_TRUE(actualAllowAWSMetadataCredentials);
- CreateFile(m_setRegFilePath.Native(), TEST_INVALID_RESOURCE_MAPPING_SETREG);
- m_awsCoreConfiguration->ReloadConfiguration();
- actualConfigFilePath = m_awsCoreConfiguration->GetResourceMappingConfigFilePath();
- actualProfileName = m_awsCoreConfiguration->GetProfileName();
- actualAllowAWSMetadataCredentials = m_awsCoreConfiguration->IsAllowedAWSMetadataCredentials();
- EXPECT_TRUE(actualConfigFilePath.empty());
- EXPECT_TRUE(actualProfileName == AWSCoreConfiguration::AWSCoreDefaultProfileName);
- EXPECT_FALSE(actualAllowAWSMetadataCredentials);
- }
|