TEST(PersistentCognitoIdentityProvider_JsonImpl_Test, TestPersistance) { JsonValue someOtherIdentityPool; someOtherIdentityPool.WithString("IdentityId", "SomeOtherIdentity"); JsonValue identityDoc; identityDoc.WithObject("SomeOtherIdentityPool", someOtherIdentityPool); Aws::String filePath = ComputeIdentityFilePath(); FileSystemUtils::RemoveFileIfExists(filePath.c_str()); std::ofstream identityFile(filePath.c_str()); identityFile << identityDoc.WriteReadable(); identityFile.close(); Aws::Map<Aws::String, LoginAccessTokens> loginsMap; LoginAccessTokens loginAccessTokens; loginAccessTokens.accessToken = "LoginValue"; loginAccessTokens.longTermTokenExpiry = 1001; loginAccessTokens.longTermToken = "LongTermToken"; loginsMap["LoginName"] = loginAccessTokens; //scope it to kill the cache and force it to reload from file. { PersistentCognitoIdentityProvider_JsonFileImpl identityProvider("IdentityPoolWeWant", "accountId", filePath.c_str()); EXPECT_FALSE(identityProvider.HasIdentityId()); EXPECT_FALSE(identityProvider.HasLogins()); identityProvider.PersistIdentityId("IdentityWeWant"); identityProvider.PersistLogins(loginsMap); } PersistentCognitoIdentityProvider_JsonFileImpl identityProvider("IdentityPoolWeWant", "accountId", filePath.c_str()); EXPECT_EQ("IdentityWeWant", identityProvider.GetIdentityId()); EXPECT_EQ("LoginName", identityProvider.GetLogins().begin()->first); EXPECT_EQ(loginAccessTokens.accessToken, identityProvider.GetLogins().begin()->second.accessToken); EXPECT_EQ(loginAccessTokens.longTermToken, identityProvider.GetLogins().begin()->second.longTermToken); EXPECT_EQ(loginAccessTokens.longTermTokenExpiry, identityProvider.GetLogins().begin()->second.longTermTokenExpiry); std::ifstream identityFileInput(filePath.c_str()); JsonValue finalIdentityDoc(identityFileInput); identityFileInput.close(); FileSystemUtils::RemoveFileIfExists(filePath.c_str()); ASSERT_TRUE(finalIdentityDoc.ValueExists("SomeOtherIdentityPool")); ASSERT_TRUE(finalIdentityDoc.ValueExists("IdentityPoolWeWant")); JsonValue ourIdentityPool = finalIdentityDoc.GetObject("IdentityPoolWeWant"); ASSERT_EQ("IdentityWeWant", ourIdentityPool.GetString("IdentityId")); ASSERT_EQ("LoginName", ourIdentityPool.GetObject("Logins").GetAllObjects().begin()->first); ASSERT_EQ(loginAccessTokens.accessToken, ourIdentityPool.GetObject("Logins").GetAllObjects().begin()->second.GetString("AccessToken")); ASSERT_EQ(loginAccessTokens.longTermToken, ourIdentityPool.GetObject("Logins").GetAllObjects().begin()->second.GetString("LongTermToken")); ASSERT_EQ(loginAccessTokens.longTermTokenExpiry, ourIdentityPool.GetObject("Logins").GetAllObjects().begin()->second.GetInt64("Expiry")); }
AttributeValueMap::AttributeValueMap(const JsonValue& jsonValue) { const Aws::Map<Aws::String, JsonValue> map = jsonValue.GetObject("M").GetAllObjects(); for (auto& item : map) { std::shared_ptr<AttributeValue> attributeValue = Aws::MakeShared<AttributeValue>("AttributeValue"); JsonValue itemValue = item.second; *attributeValue = itemValue; m_m.insert(m_m.begin(), std::pair<Aws::String, const std::shared_ptr<AttributeValue>>(item.first, attributeValue)); } }