AWSResourceMappingManagerTest.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/Settings/SettingsRegistry.h>
  9. #include <AzFramework/StringFunc/StringFunc.h>
  10. #include <Configuration/AWSCoreConfiguration.h>
  11. #include <ResourceMapping/AWSResourceMappingConstants.h>
  12. #include <ResourceMapping/AWSResourceMappingManager.h>
  13. #include <TestFramework/AWSCoreFixture.h>
  14. using namespace AWSCore;
  15. static constexpr const char TEST_EXPECTED_GLOBAL_ACCOUNTID[] = "123456789012";
  16. static constexpr const char TEST_EXPECTED_GLOBAL_REGION[] = "us-west-2";
  17. static constexpr const char TEST_EXPECTED_RESOURCE_ACCOUNTID[] = "012345678912";
  18. static constexpr const char TEST_EXPECTED_RESOURCE_REGION[] = "us-east-1";
  19. static constexpr const char TEST_EXPECTED_LAMBDA_KEYNAME[] = "TestLambda";
  20. static constexpr const char TEST_EXPECTED_LAMBDA_TYPE[] = "AWS::Lambda::Function";
  21. static constexpr const char TEST_EXPECTED_LAMBDA_NAMEID[] = "MyTestLambda";
  22. static constexpr const char TEST_EXPECTED_BUCKET_KEYNAME[] = "TestS3Bucket";
  23. static constexpr const char TEST_EXPECTED_BUCKET_TYPE[] = "AWS::S3::Bucket";
  24. static constexpr const char TEST_EXPECTED_BUCKET_NAMEID[] = "MyTestS3Bucket";
  25. static constexpr const char TEST_EXPECTED_SERVICE_KEYNAME[] = "TestService";
  26. static constexpr const char TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE[] =
  27. R"({
  28. "AWSResourceMappings": {
  29. "TestLambda": {
  30. "Type": "AWS::Lambda::Function",
  31. "Name/ID": "MyTestLambda",
  32. "Region": "us-east-1",
  33. "AccountId": "012345678912"
  34. },
  35. "TestS3Bucket": {
  36. "Type": "AWS::S3::Bucket",
  37. "Name/ID": "MyTestS3Bucket"
  38. },
  39. "TestService.RESTApiId": {
  40. "Type": "AWS::ApiGateway::RestApi",
  41. "Name/ID": "1234567890"
  42. },
  43. "TestService.RESTApiStage": {
  44. "Type": "AWS::ApiGateway::Stage",
  45. "Name/ID": "prod",
  46. "Region": "us-east-1"
  47. }
  48. },
  49. "AccountId": "123456789012",
  50. "Region": "us-west-2",
  51. "Version": "1.0.0"
  52. })";
  53. static constexpr const char TEST_VALID_EMPTY_ACCOUNTID_RESOURCE_MAPPING_CONFIG_FILE[] =
  54. R"({
  55. "AWSResourceMappings": {
  56. "TestLambda": {
  57. "Type": "AWS::Lambda::Function",
  58. "Name/ID": "MyTestLambda",
  59. "Region": "us-east-1",
  60. "AccountId": "012345678912"
  61. },
  62. "TestS3Bucket": {
  63. "Type": "AWS::S3::Bucket",
  64. "Name/ID": "MyTestS3Bucket"
  65. },
  66. "TestService.RESTApiId": {
  67. "Type": "AWS::ApiGateway::RestApi",
  68. "Name/ID": "1234567890"
  69. },
  70. "TestService.RESTApiStage": {
  71. "Type": "AWS::ApiGateway::Stage",
  72. "Name/ID": "prod",
  73. "Region": "us-east-1"
  74. }
  75. },
  76. "AccountId": "",
  77. "Region": "us-west-2",
  78. "Version": "1.1.0"
  79. })";
  80. static constexpr const char TEST_INVALID_RESOURCE_MAPPING_CONFIG_FILE[] =
  81. R"({
  82. "AWSResourceMappings": {},
  83. "AccountId": "123",
  84. "Region": "123",
  85. "Version": "123"
  86. })";
  87. static constexpr const char TEST_TEMPLATE_RESOURCE_MAPPING_CONFIG_FILE[] =
  88. R"({
  89. "AWSResourceMappings": {},
  90. "AccountId": "EMPTY",
  91. "Region": "us-west-2",
  92. "Version": "1.0.0"
  93. })";
  94. class AWSResourceMappingManagerTest
  95. : public AWSCoreFixture
  96. , AWSCoreInternalRequestBus::Handler
  97. {
  98. public:
  99. AWSResourceMappingManagerTest(): m_reloadConfigurationCounter(0)
  100. {
  101. m_resourceMappingManager = AZStd::make_unique<AWSCore::AWSResourceMappingManager>();
  102. }
  103. void SetUp() override
  104. {
  105. AWSCoreFixture::SetUpFixture(false);
  106. m_configFilePath = (GetTestTempDirectoryPath() /
  107. AWSCore::AWSCoreConfiguration::AWSCoreResourceMappingConfigFolderName /
  108. "test_aws_resource_mappings.json").LexicallyNormal();
  109. AWSCoreInternalRequestBus::Handler::BusConnect();
  110. }
  111. void TearDown() override
  112. {
  113. AWSCoreInternalRequestBus::Handler::BusDisconnect();
  114. RemoveFile(m_configFilePath.Native());
  115. m_configFilePath.clear();
  116. m_reloadConfigurationCounter = 0;
  117. m_resourceMappingManager->DeactivateManager();
  118. m_resourceMappingManager.reset();
  119. AWSCoreFixture::TearDownFixture(false);
  120. }
  121. // AWSCoreInternalRequestBus interface implementation
  122. AZStd::string GetProfileName() const override { return ""; }
  123. AZStd::string GetResourceMappingConfigFilePath() const override { return m_configFilePath.Native(); }
  124. bool IsAllowedAWSMetadataCredentials() const override { return false; }
  125. void ReloadConfiguration() override { m_reloadConfigurationCounter++; }
  126. AZStd::unique_ptr<AWSCore::AWSResourceMappingManager> m_resourceMappingManager;
  127. AZ::u8 m_reloadConfigurationCounter;
  128. AZ::IO::Path m_configFilePath;
  129. };
  130. TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseInvalidConfigFile_ConfigDataIsEmpty)
  131. {
  132. CreateFile(m_configFilePath.Native(), TEST_INVALID_RESOURCE_MAPPING_CONFIG_FILE);
  133. m_resourceMappingManager->ActivateManager();
  134. AZStd::string actualAccountId;
  135. AZStd::string actualRegion;
  136. AWSResourceMappingRequestBus::BroadcastResult(actualAccountId, &AWSResourceMappingRequests::GetDefaultAccountId);
  137. AWSResourceMappingRequestBus::BroadcastResult(actualRegion, &AWSResourceMappingRequests::GetDefaultRegion);
  138. EXPECT_EQ(m_reloadConfigurationCounter, 0);
  139. EXPECT_TRUE(actualAccountId.empty());
  140. EXPECT_TRUE(actualRegion.empty());
  141. EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::Error);
  142. }
  143. TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseValidConfigFile_ConfigDataIsNotEmpty)
  144. {
  145. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  146. m_resourceMappingManager->ActivateManager();
  147. AZStd::string actualAccountId;
  148. AZStd::string actualRegion;
  149. AWSResourceMappingRequestBus::BroadcastResult(actualAccountId, &AWSResourceMappingRequests::GetDefaultAccountId);
  150. AWSResourceMappingRequestBus::BroadcastResult(actualRegion, &AWSResourceMappingRequests::GetDefaultRegion);
  151. EXPECT_EQ(m_reloadConfigurationCounter, 0);
  152. EXPECT_FALSE(actualAccountId.empty());
  153. EXPECT_FALSE(actualRegion.empty());
  154. EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::Ready);
  155. }
  156. TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseTemplateConfigFile_ConfigDataIsNotEmpty)
  157. {
  158. CreateFile(m_configFilePath.Native(), TEST_TEMPLATE_RESOURCE_MAPPING_CONFIG_FILE);
  159. m_resourceMappingManager->ActivateManager();
  160. AZStd::string actualAccountId;
  161. AZStd::string actualRegion;
  162. AWSResourceMappingRequestBus::BroadcastResult(actualAccountId, &AWSResourceMappingRequests::GetDefaultAccountId);
  163. AWSResourceMappingRequestBus::BroadcastResult(actualRegion, &AWSResourceMappingRequests::GetDefaultRegion);
  164. EXPECT_EQ(m_reloadConfigurationCounter, 0);
  165. EXPECT_FALSE(actualAccountId.empty());
  166. EXPECT_FALSE(actualRegion.empty());
  167. EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::Ready);
  168. }
  169. TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseValidConfigFile_ConfigDataIsNotEmptyWithMultithreadCalls)
  170. {
  171. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  172. m_resourceMappingManager->ActivateManager();
  173. constexpr int testThreadNumber = 10;
  174. AZStd::atomic<int> actualEbusCalls = 0;
  175. AZStd::vector<AZStd::thread> testThreadPool;
  176. for (int index = 0; index < testThreadNumber; index++)
  177. {
  178. testThreadPool.emplace_back(AZStd::thread([&]() {
  179. AZStd::string actualAccountId;
  180. AWSResourceMappingRequestBus::BroadcastResult(actualAccountId, &AWSResourceMappingRequests::GetDefaultAccountId);
  181. EXPECT_FALSE(actualAccountId.empty());
  182. ++actualEbusCalls;
  183. }));
  184. }
  185. for (auto& testThread : testThreadPool)
  186. {
  187. testThread.join();
  188. }
  189. EXPECT_TRUE(actualEbusCalls == testThreadNumber);
  190. }
  191. TEST_F(AWSResourceMappingManagerTest, ActivateManager_ParseValidConfigFile_GlobalAccountIdEmpty)
  192. {
  193. CreateFile(m_configFilePath.Native(), TEST_VALID_EMPTY_ACCOUNTID_RESOURCE_MAPPING_CONFIG_FILE);
  194. m_resourceMappingManager->ActivateManager();
  195. AZStd::string actualAccountId;
  196. AZStd::string actualRegion;
  197. AWSResourceMappingRequestBus::BroadcastResult(actualAccountId, &AWSResourceMappingRequests::GetDefaultAccountId);
  198. AWSResourceMappingRequestBus::BroadcastResult(actualRegion, &AWSResourceMappingRequests::GetDefaultRegion);
  199. EXPECT_EQ(m_reloadConfigurationCounter, 0);
  200. EXPECT_TRUE(actualAccountId.empty());
  201. EXPECT_FALSE(actualRegion.empty());
  202. EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::Ready);
  203. }
  204. TEST_F(AWSResourceMappingManagerTest, DeactivateManager_AfterActivatingWithValidConfigFile_ConfigDataGetCleanedUp)
  205. {
  206. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  207. m_resourceMappingManager->ActivateManager();
  208. AZStd::string actualAccountId;
  209. AZStd::string actualRegion;
  210. AWSResourceMappingRequestBus::BroadcastResult(actualAccountId, &AWSResourceMappingRequests::GetDefaultAccountId);
  211. AWSResourceMappingRequestBus::BroadcastResult(actualRegion, &AWSResourceMappingRequests::GetDefaultRegion);
  212. EXPECT_FALSE(actualAccountId.empty());
  213. EXPECT_FALSE(actualRegion.empty());
  214. EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::Ready);
  215. m_resourceMappingManager->DeactivateManager();
  216. EXPECT_TRUE(m_resourceMappingManager->GetDefaultAccountId().empty());
  217. EXPECT_TRUE(m_resourceMappingManager->GetDefaultRegion().empty());
  218. EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::NotLoaded);
  219. }
  220. TEST_F(AWSResourceMappingManagerTest, GetDefaultAccountId_AfterParsingValidConfigFile_GetExpectedDefaultAccountId)
  221. {
  222. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  223. m_resourceMappingManager->ActivateManager();
  224. AZStd::string actualAccountId;
  225. AWSResourceMappingRequestBus::BroadcastResult(actualAccountId, &AWSResourceMappingRequests::GetDefaultAccountId);
  226. EXPECT_FALSE(actualAccountId.empty());
  227. EXPECT_EQ(TEST_EXPECTED_GLOBAL_ACCOUNTID, actualAccountId);
  228. }
  229. TEST_F(AWSResourceMappingManagerTest, GetDefaultRegion_AfterParsingValidConfigFile_GetExpectedDefaultRegion)
  230. {
  231. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  232. m_resourceMappingManager->ActivateManager();
  233. AZStd::string actualRegion;
  234. AWSResourceMappingRequestBus::BroadcastResult(actualRegion, &AWSResourceMappingRequests::GetDefaultRegion);
  235. EXPECT_FALSE(actualRegion.empty());
  236. EXPECT_EQ(TEST_EXPECTED_GLOBAL_REGION, actualRegion);
  237. }
  238. TEST_F(AWSResourceMappingManagerTest, GetResourceAccountId_AfterParsingValidConfigFile_GetExpectedAccountId)
  239. {
  240. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  241. m_resourceMappingManager->ActivateManager();
  242. AZStd::string actualAccountId;
  243. AWSResourceMappingRequestBus::BroadcastResult(
  244. actualAccountId, &AWSResourceMappingRequests::GetResourceAccountId, TEST_EXPECTED_LAMBDA_KEYNAME);
  245. EXPECT_FALSE(actualAccountId.empty());
  246. EXPECT_EQ(TEST_EXPECTED_RESOURCE_ACCOUNTID, actualAccountId);
  247. AWSResourceMappingRequestBus::BroadcastResult(
  248. actualAccountId, &AWSResourceMappingRequests::GetResourceAccountId, TEST_EXPECTED_BUCKET_KEYNAME);
  249. EXPECT_FALSE(actualAccountId.empty());
  250. EXPECT_EQ(TEST_EXPECTED_GLOBAL_ACCOUNTID, actualAccountId);
  251. }
  252. TEST_F(AWSResourceMappingManagerTest, GetResourceAccountId_QueryNonexistResourceMappingKeyName_GetEmptyAccountId)
  253. {
  254. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  255. m_resourceMappingManager->ActivateManager();
  256. AZStd::string actualAccountId;
  257. AWSResourceMappingRequestBus::BroadcastResult(
  258. actualAccountId, &AWSResourceMappingRequests::GetResourceAccountId, "dummyKeyName");
  259. EXPECT_TRUE(actualAccountId.empty());
  260. }
  261. TEST_F(AWSResourceMappingManagerTest, GetResourceNameId_AfterParsingValidConfigFile_GetExpectedNameId)
  262. {
  263. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  264. m_resourceMappingManager->ActivateManager();
  265. AZStd::string actualNameId;
  266. AWSResourceMappingRequestBus::BroadcastResult(
  267. actualNameId, &AWSResourceMappingRequests::GetResourceNameId, TEST_EXPECTED_LAMBDA_KEYNAME);
  268. EXPECT_FALSE(actualNameId.empty());
  269. EXPECT_EQ(TEST_EXPECTED_LAMBDA_NAMEID, actualNameId);
  270. AWSResourceMappingRequestBus::BroadcastResult(
  271. actualNameId, &AWSResourceMappingRequests::GetResourceNameId, TEST_EXPECTED_BUCKET_KEYNAME);
  272. EXPECT_FALSE(actualNameId.empty());
  273. EXPECT_EQ(TEST_EXPECTED_BUCKET_NAMEID, actualNameId);
  274. }
  275. TEST_F(AWSResourceMappingManagerTest, GetResourceNameId_QueryNonexistResourceMappingKeyName_GetEmptyNameId)
  276. {
  277. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  278. m_resourceMappingManager->ActivateManager();
  279. AZStd::string actualNameId;
  280. AWSResourceMappingRequestBus::BroadcastResult(
  281. actualNameId, &AWSResourceMappingRequests::GetResourceNameId, "dummyKeyName");
  282. EXPECT_TRUE(actualNameId.empty());
  283. }
  284. TEST_F(AWSResourceMappingManagerTest, GetResourceRegion_AfterParsingValidConfigFile_GetExpectedRegion)
  285. {
  286. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  287. m_resourceMappingManager->ActivateManager();
  288. AZStd::string actualRegion;
  289. AWSResourceMappingRequestBus::BroadcastResult(
  290. actualRegion, &AWSResourceMappingRequests::GetResourceRegion, TEST_EXPECTED_LAMBDA_KEYNAME);
  291. EXPECT_FALSE(actualRegion.empty());
  292. EXPECT_EQ(TEST_EXPECTED_RESOURCE_REGION, actualRegion);
  293. AWSResourceMappingRequestBus::BroadcastResult(
  294. actualRegion, &AWSResourceMappingRequests::GetResourceRegion, TEST_EXPECTED_BUCKET_KEYNAME);
  295. EXPECT_FALSE(actualRegion.empty());
  296. EXPECT_EQ(TEST_EXPECTED_GLOBAL_REGION, actualRegion);
  297. }
  298. TEST_F(AWSResourceMappingManagerTest, GetResourceRegion_QueryNonexistResourceMappingKeyName_GetEmptyRegion)
  299. {
  300. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  301. m_resourceMappingManager->ActivateManager();
  302. AZStd::string actualRegion;
  303. AWSResourceMappingRequestBus::BroadcastResult(
  304. actualRegion, &AWSResourceMappingRequests::GetResourceRegion, "dummyKeyName");
  305. EXPECT_TRUE(actualRegion.empty());
  306. }
  307. TEST_F(AWSResourceMappingManagerTest, GetResourceType_AfterParsingValidConfigFile_GetExpectedType)
  308. {
  309. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  310. m_resourceMappingManager->ActivateManager();
  311. AZStd::string actualType;
  312. AWSResourceMappingRequestBus::BroadcastResult(
  313. actualType, &AWSResourceMappingRequests::GetResourceType, TEST_EXPECTED_LAMBDA_KEYNAME);
  314. EXPECT_FALSE(actualType.empty());
  315. EXPECT_EQ(TEST_EXPECTED_LAMBDA_TYPE, actualType);
  316. AWSResourceMappingRequestBus::BroadcastResult(
  317. actualType, &AWSResourceMappingRequests::GetResourceType, TEST_EXPECTED_BUCKET_KEYNAME);
  318. EXPECT_FALSE(actualType.empty());
  319. EXPECT_EQ(TEST_EXPECTED_BUCKET_TYPE, actualType);
  320. }
  321. TEST_F(AWSResourceMappingManagerTest, GetResourceType_QueryNonexistResourceMappingKeyName_GetEmptyType)
  322. {
  323. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  324. m_resourceMappingManager->ActivateManager();
  325. AZStd::string actualType;
  326. AWSResourceMappingRequestBus::BroadcastResult(
  327. actualType, &AWSResourceMappingRequests::GetResourceType, "dummyKeyName");
  328. EXPECT_TRUE(actualType.empty());
  329. }
  330. TEST_F(AWSResourceMappingManagerTest, GetServiceUrl_PassingEmptyServiceName_GetEmptyUrl)
  331. {
  332. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  333. m_resourceMappingManager->ActivateManager();
  334. AZStd::string actualServiceUrl;
  335. AWSResourceMappingRequestBus::BroadcastResult(
  336. actualServiceUrl, &AWSResourceMappingRequests::GetServiceUrlByServiceName, "");
  337. EXPECT_TRUE(actualServiceUrl.empty());
  338. }
  339. TEST_F(AWSResourceMappingManagerTest, GetServiceUrl_PassingEmptyRESTApiIdAndStage_GetEmptyUrl)
  340. {
  341. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  342. m_resourceMappingManager->ActivateManager();
  343. AZStd::string actualServiceUrl;
  344. AWSResourceMappingRequestBus::BroadcastResult(
  345. actualServiceUrl, &AWSResourceMappingRequests::GetServiceUrlByRESTApiIdAndStage, "", "");
  346. EXPECT_TRUE(actualServiceUrl.empty());
  347. }
  348. TEST_F(AWSResourceMappingManagerTest, GetServiceUrl_RESTApiIdAndStageHaveInconsistentRegion_GetEmptyUrl)
  349. {
  350. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  351. m_resourceMappingManager->ActivateManager();
  352. AZStd::string actualServiceUrl;
  353. AWSResourceMappingRequestBus::BroadcastResult(
  354. actualServiceUrl, &AWSResourceMappingRequests::GetServiceUrlByServiceName, TEST_EXPECTED_SERVICE_KEYNAME);
  355. EXPECT_TRUE(actualServiceUrl.empty());
  356. }
  357. TEST_F(AWSResourceMappingManagerTest, ReloadConfigFile_ParseValidConfigFileAfterParsingInvalid_ConfigDataGetParsed)
  358. {
  359. CreateFile(m_configFilePath.Native(), TEST_INVALID_RESOURCE_MAPPING_CONFIG_FILE);
  360. m_resourceMappingManager->ActivateManager();
  361. AZStd::string actualAccountId;
  362. AZStd::string actualRegion;
  363. AWSResourceMappingRequestBus::BroadcastResult(actualAccountId, &AWSResourceMappingRequests::GetDefaultAccountId);
  364. AWSResourceMappingRequestBus::BroadcastResult(actualRegion, &AWSResourceMappingRequests::GetDefaultRegion);
  365. EXPECT_EQ(m_reloadConfigurationCounter, 0);
  366. EXPECT_TRUE(actualAccountId.empty());
  367. EXPECT_TRUE(actualRegion.empty());
  368. EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::Error);
  369. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  370. m_resourceMappingManager->ReloadConfigFile();
  371. AWSResourceMappingRequestBus::BroadcastResult(actualAccountId, &AWSResourceMappingRequests::GetDefaultAccountId);
  372. AWSResourceMappingRequestBus::BroadcastResult(actualRegion, &AWSResourceMappingRequests::GetDefaultRegion);
  373. EXPECT_EQ(m_reloadConfigurationCounter, 0);
  374. EXPECT_FALSE(actualAccountId.empty());
  375. EXPECT_FALSE(actualRegion.empty());
  376. EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::Ready);
  377. }
  378. TEST_F(AWSResourceMappingManagerTest, ReloadConfigFile_ReloadConfigFileNameAndParseValidConfigFile_ConfigDataGetParsed)
  379. {
  380. CreateFile(m_configFilePath.Native(), TEST_VALID_RESOURCE_MAPPING_CONFIG_FILE);
  381. m_resourceMappingManager->ReloadConfigFile(true);
  382. EXPECT_EQ(m_reloadConfigurationCounter, 1);
  383. EXPECT_FALSE(m_resourceMappingManager->GetDefaultAccountId().empty());
  384. EXPECT_FALSE(m_resourceMappingManager->GetDefaultRegion().empty());
  385. EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::Ready);
  386. }
  387. TEST_F(AWSResourceMappingManagerTest, ReloadConfigFile_MissingSetRegFile_ConfigDataIsNotParsed)
  388. {
  389. m_configFilePath.clear();
  390. m_resourceMappingManager->ReloadConfigFile(true);
  391. EXPECT_EQ(m_reloadConfigurationCounter, 1);
  392. EXPECT_TRUE(m_resourceMappingManager->GetDefaultAccountId().empty());
  393. EXPECT_TRUE(m_resourceMappingManager->GetDefaultRegion().empty());
  394. EXPECT_TRUE(m_resourceMappingManager->GetStatus() == AWSResourceMappingManager::Status::NotLoaded);
  395. }