test_boto_cognitoidentity.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. # -*- coding: utf-8 -*-
  2. # Import Python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import logging
  5. import random
  6. import string
  7. import pytest
  8. # Import Salt libs
  9. import salt.config
  10. import salt.loader
  11. import salt.states.boto_cognitoidentity as boto_cognitoidentity
  12. from salt.ext.six.moves import range
  13. from salt.utils.versions import LooseVersion
  14. # Import Salt Testing libs
  15. from tests.support.mixins import LoaderModuleMockMixin
  16. from tests.support.mock import MagicMock, patch
  17. from tests.support.unit import TestCase, skipIf
  18. # pylint: disable=import-error,no-name-in-module
  19. from tests.unit.modules.test_boto_cognitoidentity import (
  20. BotoCognitoIdentityTestCaseMixin,
  21. )
  22. # Import 3rd-party libs
  23. try:
  24. import boto3
  25. from botocore.exceptions import ClientError
  26. HAS_BOTO = True
  27. except ImportError:
  28. HAS_BOTO = False
  29. # pylint: enable=import-error,no-name-in-module
  30. # the boto_cognitoidentity module relies on the connect_to_region() method
  31. # which was added in boto 2.8.0
  32. # https://github.com/boto/boto/commit/33ac26b416fbb48a60602542b4ce15dcc7029f12
  33. required_boto3_version = "1.2.1"
  34. region = "us-east-1"
  35. access_key = "GKTADJGHEIQSXMKKRBJ08H"
  36. secret_key = "askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs"
  37. conn_parameters = {
  38. "region": region,
  39. "key": access_key,
  40. "keyid": secret_key,
  41. "profile": {},
  42. }
  43. error_message = (
  44. "An error occurred (101) when calling the {0} operation: Test-defined error"
  45. )
  46. error_content = {"Error": {"Code": 101, "Message": "Test-defined error"}}
  47. first_pool_id = "first_pool_id"
  48. first_pool_name = "first_pool"
  49. second_pool_id = "second_pool_id"
  50. second_pool_name = "second_pool"
  51. second_pool_name_updated = "second_pool_updated"
  52. third_pool_id = "third_pool_id"
  53. third_pool_name = first_pool_name
  54. default_pool_name = "default_pool_name"
  55. default_pool_id = "default_pool_id"
  56. default_dev_provider = "test_provider_default"
  57. identity_pools_ret = dict(
  58. IdentityPools=[
  59. dict(IdentityPoolId=first_pool_id, IdentityPoolName=first_pool_name),
  60. dict(IdentityPoolId=second_pool_id, IdentityPoolName=second_pool_name),
  61. dict(IdentityPoolId=third_pool_id, IdentityPoolName=third_pool_name),
  62. ]
  63. )
  64. first_pool_ret = dict(
  65. IdentityPoolId=first_pool_id,
  66. IdentityPoolName=first_pool_name,
  67. AllowUnauthenticatedIdentities=False,
  68. SupportedLoginProviders={
  69. "accounts.google.com": "testing123",
  70. "api.twitter.com": "testing123",
  71. "graph.facebook.com": "testing123",
  72. "www.amazon.com": "testing123",
  73. },
  74. DeveloperProviderName="test_provider",
  75. OpenIdConnectProviderARNs=["some_provider_arn", "another_provider_arn"],
  76. )
  77. first_pool_role_ret = dict(
  78. IdentityPoolId=first_pool_id,
  79. Roles=dict(
  80. authenticated="first_pool_auth_role", unauthenticated="first_pool_unauth_role"
  81. ),
  82. )
  83. second_pool_ret = dict(
  84. IdentityPoolId=second_pool_id,
  85. IdentityPoolName=second_pool_name,
  86. AllowUnauthenticatedIdentities=False,
  87. )
  88. second_pool_role_ret = dict(
  89. IdentityPoolId=second_pool_id, Roles=dict(authenticated="second_pool_auth_role")
  90. )
  91. second_pool_update_ret = dict(
  92. IdentityPoolId=second_pool_id,
  93. IdentityPoolName=second_pool_name,
  94. AllowUnauthenticatedIdentities=True,
  95. )
  96. third_pool_ret = dict(
  97. IdentityPoolId=third_pool_id,
  98. IdentityPoolName=third_pool_name,
  99. AllowUnauthenticatedIdentities=False,
  100. DeveloperProviderName="test_provider2",
  101. )
  102. third_pool_role_ret = dict(IdentityPoolId=third_pool_id)
  103. default_pool_ret = dict(
  104. IdentityPoolId=default_pool_id,
  105. IdentityPoolName=default_pool_name,
  106. AllowUnauthenticatedIdentities=False,
  107. DeveloperProviderName=default_dev_provider,
  108. )
  109. default_pool_role_ret = dict(IdentityPoolId=default_pool_id)
  110. log = logging.getLogger(__name__)
  111. def _has_required_boto():
  112. """
  113. Returns True/False boolean depending on if Boto is installed and correct
  114. version.
  115. """
  116. if not HAS_BOTO:
  117. return False
  118. elif LooseVersion(boto3.__version__) < LooseVersion(required_boto3_version):
  119. return False
  120. else:
  121. return True
  122. class BotoCognitoIdentityStateTestCaseBase(TestCase, LoaderModuleMockMixin):
  123. conn = None
  124. def setup_loader_modules(self):
  125. ctx = {}
  126. utils = salt.loader.utils(
  127. self.opts,
  128. whitelist=["boto", "boto3", "args", "systemd", "path", "platform", "reg"],
  129. context=ctx,
  130. )
  131. serializers = salt.loader.serializers(self.opts)
  132. self.funcs = funcs = salt.loader.minion_mods(
  133. self.opts, context=ctx, utils=utils, whitelist=["boto_cognitoidentity"]
  134. )
  135. self.salt_states = salt.loader.states(
  136. opts=self.opts,
  137. functions=funcs,
  138. utils=utils,
  139. whitelist=["boto_cognitoidentity"],
  140. serializers=serializers,
  141. )
  142. return {
  143. boto_cognitoidentity: {
  144. "__opts__": self.opts,
  145. "__salt__": funcs,
  146. "__utils__": utils,
  147. "__states__": self.salt_states,
  148. "__serializers__": serializers,
  149. }
  150. }
  151. @classmethod
  152. def setUpClass(cls):
  153. cls.opts = salt.config.DEFAULT_MINION_OPTS.copy()
  154. cls.opts["grains"] = salt.loader.grains(cls.opts)
  155. @classmethod
  156. def tearDownClass(cls):
  157. del cls.opts
  158. def setUp(self):
  159. self.addCleanup(delattr, self, "funcs")
  160. self.addCleanup(delattr, self, "salt_states")
  161. # Set up MagicMock to replace the boto3 session
  162. # connections keep getting cached from prior tests, can't find the
  163. # correct context object to clear it. So randomize the cache key, to prevent any
  164. # cache hits
  165. conn_parameters["key"] = "".join(
  166. random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
  167. )
  168. self.patcher = patch("boto3.session.Session")
  169. self.addCleanup(self.patcher.stop)
  170. self.addCleanup(delattr, self, "patcher")
  171. mock_session = self.patcher.start()
  172. session_instance = mock_session.return_value
  173. self.conn = MagicMock()
  174. self.addCleanup(delattr, self, "conn")
  175. session_instance.client.return_value = self.conn
  176. @skipIf(HAS_BOTO is False, "The boto module must be installed.")
  177. @skipIf(
  178. _has_required_boto() is False,
  179. "The boto3 module must be greater than"
  180. " or equal to version {0}".format(required_boto3_version),
  181. )
  182. class BotoCognitoIdentityTestCase(
  183. BotoCognitoIdentityStateTestCaseBase, BotoCognitoIdentityTestCaseMixin
  184. ):
  185. """
  186. TestCase for salt.states.boto_cognitoidentity state.module
  187. """
  188. def _describe_identity_pool_side_effect(self, *args, **kwargs):
  189. if kwargs.get("IdentityPoolId") == first_pool_id:
  190. return first_pool_ret
  191. elif kwargs.get("IdentityPoolId") == second_pool_id:
  192. return second_pool_ret
  193. elif kwargs.get("IdentityPoolId") == third_pool_id:
  194. return third_pool_ret
  195. else:
  196. return default_pool_ret
  197. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  198. def test_present_when_failing_to_describe_identity_pools(self):
  199. """
  200. Tests exceptions when describing identity pools
  201. """
  202. self.conn.list_identity_pools.return_value = identity_pools_ret
  203. self.conn.describe_identity_pool.side_effect = ClientError(
  204. error_content, "error on describe identity pool"
  205. )
  206. result = self.salt_states["boto_cognitoidentity.pool_present"](
  207. name="test pool present",
  208. IdentityPoolName=first_pool_name,
  209. AuthenticatedRole="my_auth_role",
  210. **conn_parameters
  211. )
  212. self.assertEqual(result.get("result"), False)
  213. self.assertTrue("error on describe identity pool" in result.get("comment", {}))
  214. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  215. def test_present_when_multiple_pools_with_same_name_exist(self):
  216. """
  217. Tests present on an identity pool name where it matched
  218. multiple pools. The result should fail.
  219. """
  220. self.conn.list_identity_pools.return_value = identity_pools_ret
  221. self.conn.describe_identity_pool.side_effect = (
  222. self._describe_identity_pool_side_effect
  223. )
  224. result = self.salt_states["boto_cognitoidentity.pool_present"](
  225. name="test pool present",
  226. IdentityPoolName=first_pool_name,
  227. AuthenticatedRole="my_auth_role",
  228. **conn_parameters
  229. )
  230. self.assertEqual(result.get("result"), False)
  231. self.assertIn(
  232. "{0}".format([first_pool_ret, third_pool_ret]), result.get("comment", "")
  233. )
  234. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  235. def test_present_when_failing_to_create_a_new_identity_pool(self):
  236. """
  237. Tests present on an identity pool name that doesn't exist and
  238. an error is thrown on creation.
  239. """
  240. self.conn.list_identity_pools.return_value = identity_pools_ret
  241. self.conn.describe_identity_pool.side_effect = (
  242. self._describe_identity_pool_side_effect
  243. )
  244. self.conn.create_identity_pool.side_effect = ClientError(
  245. error_content, "error on create_identity_pool"
  246. )
  247. result = self.salt_states["boto_cognitoidentity.pool_present"](
  248. name="test pool present",
  249. IdentityPoolName=default_pool_name,
  250. AuthenticatedRole="my_auth_role",
  251. **conn_parameters
  252. )
  253. self.assertEqual(result.get("result"), False)
  254. self.assertTrue("error on create_identity_pool" in result.get("comment", ""))
  255. self.assertTrue(self.conn.update_identity_pool.call_count == 0)
  256. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  257. def test_present_when_failing_to_update_an_existing_identity_pool(self):
  258. """
  259. Tests present on a unique instance of identity pool having the matching
  260. IdentityPoolName, and an error is thrown on updating the pool properties.
  261. """
  262. self.conn.list_identity_pools.return_value = identity_pools_ret
  263. self.conn.describe_identity_pool.side_effect = (
  264. self._describe_identity_pool_side_effect
  265. )
  266. self.conn.update_identity_pool.side_effect = ClientError(
  267. error_content, "error on update_identity_pool"
  268. )
  269. result = self.salt_states["boto_cognitoidentity.pool_present"](
  270. name="test pool present",
  271. IdentityPoolName=second_pool_name,
  272. AuthenticatedRole="my_auth_role",
  273. AllowUnauthenticatedIdentities=True,
  274. **conn_parameters
  275. )
  276. self.assertEqual(result.get("result"), False)
  277. self.assertTrue("error on update_identity_pool" in result.get("comment", ""))
  278. self.assertTrue(self.conn.create_identity_pool.call_count == 0)
  279. def _get_identity_pool_roles_side_effect(self, *args, **kwargs):
  280. if kwargs.get("IdentityPoolId") == first_pool_id:
  281. return first_pool_role_ret
  282. elif kwargs.get("IdentityPoolId") == second_pool_id:
  283. return second_pool_role_ret
  284. elif kwargs.get("IdentityPoolId") == third_pool_id:
  285. return third_pool_role_ret
  286. else:
  287. return default_pool_role_ret
  288. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  289. def test_present_when_failing_to_get_identity_pool_roles(self):
  290. """
  291. Tests present on a unique instance of identity pool having the matching
  292. IdentityPoolName, where update_identity_pool succeeded, but an error
  293. is thrown on getting the identity pool role prior to setting the roles.
  294. """
  295. self.conn.list_identity_pools.return_value = identity_pools_ret
  296. self.conn.describe_identity_pool.side_effect = (
  297. self._describe_identity_pool_side_effect
  298. )
  299. self.conn.update_identity_pool.return_value = second_pool_update_ret
  300. self.conn.get_identity_pool_roles.side_effect = ClientError(
  301. error_content, "error on get_identity_pool_roles"
  302. )
  303. result = self.salt_states["boto_cognitoidentity.pool_present"](
  304. name="test pool present",
  305. IdentityPoolName=second_pool_name,
  306. AuthenticatedRole="my_auth_role",
  307. AllowUnauthenticatedIdentities=True,
  308. **conn_parameters
  309. )
  310. self.assertEqual(result.get("result"), False)
  311. self.assertTrue("error on get_identity_pool_roles" in result.get("comment", ""))
  312. self.assertTrue(self.conn.create_identity_pool.call_count == 0)
  313. self.assertTrue(self.conn.set_identity_pool_roles.call_count == 0)
  314. @pytest.mark.slow_test(seconds=60) # Test takes >30 and <=60 seconds
  315. def test_present_when_failing_to_set_identity_pool_roles(self):
  316. """
  317. Tests present on a unique instance of identity pool having the matching
  318. IdentityPoolName, where update_identity_pool succeeded, but an error
  319. is thrown on setting the identity pool role.
  320. """
  321. self.conn.list_identity_pools.return_value = identity_pools_ret
  322. self.conn.describe_identity_pool.side_effect = (
  323. self._describe_identity_pool_side_effect
  324. )
  325. self.conn.update_identity_pool.return_value = second_pool_update_ret
  326. self.conn.get_identity_pool_roles.return_value = second_pool_role_ret
  327. self.conn.set_identity_pool_roles.side_effect = ClientError(
  328. error_content, "error on set_identity_pool_roles"
  329. )
  330. with patch.dict(
  331. self.funcs,
  332. {
  333. "boto_iam.describe_role": MagicMock(
  334. return_value={"arn": "my_auth_role_arn"}
  335. )
  336. },
  337. ):
  338. result = self.salt_states["boto_cognitoidentity.pool_present"](
  339. name="test pool present",
  340. IdentityPoolName=second_pool_name,
  341. AuthenticatedRole="my_auth_role",
  342. AllowUnauthenticatedIdentities=True,
  343. **conn_parameters
  344. )
  345. self.assertEqual(result.get("result"), False)
  346. self.assertTrue(
  347. "error on set_identity_pool_roles" in result.get("comment", "")
  348. )
  349. expected_call_args = (
  350. dict(
  351. IdentityPoolId=second_pool_id,
  352. Roles={"authenticated": "my_auth_role_arn"},
  353. ),
  354. )
  355. self.assertTrue(
  356. self.conn.set_identity_pool_roles.call_args == expected_call_args
  357. )
  358. @pytest.mark.slow_test(seconds=60) # Test takes >30 and <=60 seconds
  359. def test_present_when_pool_name_does_not_exist(self):
  360. """
  361. Tests the successful case of creating a new instance, and updating its
  362. roles
  363. """
  364. self.conn.list_identity_pools.return_value = identity_pools_ret
  365. self.conn.create_identity_pool.side_effect = (
  366. self._describe_identity_pool_side_effect
  367. )
  368. self.conn.get_identity_pool_roles.return_value = default_pool_role_ret
  369. self.conn.set_identity_pool_roles.return_value = None
  370. with patch.dict(
  371. self.funcs,
  372. {
  373. "boto_iam.describe_role": MagicMock(
  374. return_value={"arn": "my_auth_role_arn"}
  375. )
  376. },
  377. ):
  378. result = self.salt_states["boto_cognitoidentity.pool_present"](
  379. name="test pool present",
  380. IdentityPoolName=default_pool_name,
  381. AuthenticatedRole="my_auth_role",
  382. AllowUnauthenticatedIdentities=True,
  383. DeveloperProviderName=default_dev_provider,
  384. **conn_parameters
  385. )
  386. self.assertEqual(result.get("result"), True)
  387. expected_call_args = (
  388. dict(
  389. AllowUnauthenticatedIdentities=True,
  390. IdentityPoolName=default_pool_name,
  391. DeveloperProviderName=default_dev_provider,
  392. SupportedLoginProviders={},
  393. OpenIdConnectProviderARNs=[],
  394. ),
  395. )
  396. self.assertTrue(
  397. self.conn.create_identity_pool.call_args == expected_call_args
  398. )
  399. expected_call_args = (
  400. dict(
  401. IdentityPoolId=default_pool_id,
  402. Roles={"authenticated": "my_auth_role_arn"},
  403. ),
  404. )
  405. self.assertTrue(
  406. self.conn.set_identity_pool_roles.call_args == expected_call_args
  407. )
  408. self.assertTrue(self.conn.update_identity_pool.call_count == 0)
  409. @pytest.mark.slow_test(seconds=60) # Test takes >30 and <=60 seconds
  410. def test_present_when_pool_name_exists(self):
  411. """
  412. Tests the successful case of updating a single instance with matching
  413. IdentityPoolName and its roles.
  414. """
  415. self.conn.list_identity_pools.return_value = identity_pools_ret
  416. self.conn.describe_identity_pool.side_effect = (
  417. self._describe_identity_pool_side_effect
  418. )
  419. self.conn.update_identity_pool.return_value = second_pool_update_ret
  420. self.conn.get_identity_pool_roles.return_value = second_pool_role_ret
  421. self.conn.set_identity_pool_roles.return_value = None
  422. with patch.dict(
  423. self.funcs,
  424. {
  425. "boto_iam.describe_role": MagicMock(
  426. return_value={"arn": "my_auth_role_arn"}
  427. )
  428. },
  429. ):
  430. result = self.salt_states["boto_cognitoidentity.pool_present"](
  431. name="test pool present",
  432. IdentityPoolName=second_pool_name,
  433. AuthenticatedRole="my_auth_role",
  434. AllowUnauthenticatedIdentities=True,
  435. **conn_parameters
  436. )
  437. self.assertEqual(result.get("result"), True)
  438. expected_call_args = (
  439. dict(
  440. AllowUnauthenticatedIdentities=True,
  441. IdentityPoolId=second_pool_id,
  442. IdentityPoolName=second_pool_name,
  443. ),
  444. )
  445. self.assertTrue(
  446. self.conn.update_identity_pool.call_args == expected_call_args
  447. )
  448. expected_call_args = (
  449. dict(
  450. IdentityPoolId=second_pool_id,
  451. Roles={"authenticated": "my_auth_role_arn"},
  452. ),
  453. )
  454. self.assertTrue(
  455. self.conn.set_identity_pool_roles.call_args == expected_call_args
  456. )
  457. self.assertTrue(self.conn.create_identity_pool.call_count == 0)
  458. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  459. def test_absent_when_pool_does_not_exist(self):
  460. """
  461. Tests absent on an identity pool that does not exist.
  462. """
  463. self.conn.list_identity_pools.return_value = identity_pools_ret
  464. result = self.salt_states["boto_cognitoidentity.pool_absent"](
  465. name="test pool absent",
  466. IdentityPoolName="no_such_pool_name",
  467. RemoveAllMatched=False,
  468. **conn_parameters
  469. )
  470. self.assertEqual(result.get("result"), True)
  471. self.assertEqual(result["changes"], {})
  472. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  473. def test_absent_when_removeallmatched_is_false_and_multiple_pools_matched(self):
  474. """
  475. Tests absent on when RemoveAllMatched flag is false and there are multiple matches
  476. for the given pool name
  477. first_pool_name is matched to first and third pool with different id's
  478. """
  479. self.conn.list_identity_pools.return_value = identity_pools_ret
  480. self.conn.describe_identity_pool.side_effect = (
  481. self._describe_identity_pool_side_effect
  482. )
  483. result = self.salt_states["boto_cognitoidentity.pool_absent"](
  484. name="test pool absent",
  485. IdentityPoolName=first_pool_name,
  486. RemoveAllMatched=False,
  487. **conn_parameters
  488. )
  489. self.assertEqual(result.get("result"), False)
  490. self.assertEqual(result["changes"], {})
  491. self.assertTrue(
  492. "{0}".format([first_pool_ret, third_pool_ret]) in result.get("comment", "")
  493. )
  494. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  495. def test_absent_when_failing_to_describe_identity_pools(self):
  496. """
  497. Tests exceptions when describing identity pools
  498. """
  499. self.conn.list_identity_pools.return_value = identity_pools_ret
  500. self.conn.describe_identity_pool.side_effect = ClientError(
  501. error_content, "error on describe identity pool"
  502. )
  503. result = self.salt_states["boto_cognitoidentity.pool_absent"](
  504. name="test pool absent",
  505. IdentityPoolName=first_pool_name,
  506. RemoveAllMatched=False,
  507. **conn_parameters
  508. )
  509. self.assertEqual(result.get("result"), False)
  510. self.assertTrue("error on describe identity pool" in result.get("comment", {}))
  511. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  512. def test_absent_when_erroring_on_delete_identity_pool(self):
  513. """
  514. Tests error due to delete_identity_pools
  515. """
  516. self.conn.list_identity_pools.return_value = identity_pools_ret
  517. self.conn.describe_identity_pool.side_effect = (
  518. self._describe_identity_pool_side_effect
  519. )
  520. self.conn.delete_identity_pool.side_effect = ClientError(
  521. error_content, "error on delete identity pool"
  522. )
  523. result = self.salt_states["boto_cognitoidentity.pool_absent"](
  524. name="test pool absent",
  525. IdentityPoolName=first_pool_name,
  526. RemoveAllMatched=True,
  527. **conn_parameters
  528. )
  529. self.assertEqual(result.get("result"), False)
  530. self.assertEqual(result["changes"], {})
  531. self.assertTrue("error on delete identity pool" in result.get("comment", ""))
  532. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  533. def test_absent_when_a_single_pool_exists(self):
  534. """
  535. Tests absent succeeds on delete when a single pool matched and
  536. RemoveAllMatched is False
  537. """
  538. self.conn.list_identity_pools.return_value = identity_pools_ret
  539. self.conn.describe_identity_pool.return_value = second_pool_ret
  540. self.conn.delete_identity_pool.return_value = None
  541. result = self.salt_states["boto_cognitoidentity.pool_absent"](
  542. name="test pool absent",
  543. IdentityPoolName=second_pool_name,
  544. RemoveAllMatched=False,
  545. **conn_parameters
  546. )
  547. self.assertEqual(result.get("result"), True)
  548. expected_changes = {
  549. "new": {"Identity Pool Id {0}".format(second_pool_id): None},
  550. "old": {"Identity Pool Id {0}".format(second_pool_id): second_pool_name},
  551. }
  552. self.assertEqual(result["changes"], expected_changes)
  553. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  554. def test_absent_when_multiple_pool_exists_and_removeallmatched_flag_is_true(self):
  555. """
  556. Tests absent succeeds on delete when a multiple pools matched and
  557. RemoveAllMatched is True
  558. first_pool_name should match to first_pool_id and third_pool_id
  559. """
  560. self.conn.list_identity_pools.return_value = identity_pools_ret
  561. self.conn.describe_identity_pool.side_effect = (
  562. self._describe_identity_pool_side_effect
  563. )
  564. self.conn.delete_identity_pool.return_value = None
  565. result = self.salt_states["boto_cognitoidentity.pool_absent"](
  566. name="test pool absent",
  567. IdentityPoolName=first_pool_name,
  568. RemoveAllMatched=True,
  569. **conn_parameters
  570. )
  571. self.assertEqual(result.get("result"), True)
  572. expected_changes = {
  573. "new": {
  574. "Identity Pool Id {0}".format(first_pool_id): None,
  575. "Identity Pool Id {0}".format(third_pool_id): None,
  576. },
  577. "old": {
  578. "Identity Pool Id {0}".format(first_pool_id): first_pool_name,
  579. "Identity Pool Id {0}".format(third_pool_id): third_pool_name,
  580. },
  581. }
  582. self.assertEqual(result["changes"], expected_changes)