예제 #1
0
 def test_from_file_missing_env_args(self):
     with tempfile.TemporaryDirectory() as tmp_dir:
         access_config_path = Path(tmp_dir, "access_config.json")
         with open(access_config_path, "w") as fp:
             fp.write(json.dumps(TEST_ACCESSOR_FILE_CONTENT))
         with self.assertRaises(jinja2.exceptions.UndefinedError):
             Accessor.from_file(filepath=access_config_path)
예제 #2
0
 def test_from_file_without_cred_caching(self):
     with tempfile.TemporaryDirectory() as tmp_dir:
         access_config_path = Path(tmp_dir, "access_config.json")
         with open(access_config_path, "w") as fp:
             fp.write(json.dumps(TEST_ACCESSOR_FILE_CONTENT))
         accessor = Accessor.from_file(filepath=access_config_path,
                                       cache_creds=False)
     self.assertDictEqual(
         accessor.dict(),
         {
             "multi_hop_accessors": [
                 {
                     "role_session_name":
                     "altimeter-mb-a",
                     "access_steps": [
                         {
                             "role_name": "OrganizationAccountAccessRole",
                             "account_id": "123456789012",
                             "external_id": "foo",
                         },
                         {
                             "role_name": "OrganizationAccountAccessRole",
                             "account_id": None,
                             "external_id": None,
                         },
                     ],
                 },
                 {
                     "role_session_name":
                     "altimeter-mb-b",
                     "access_steps": [
                         {
                             "role_name": "OrganizationAccountAccessRole",
                             "account_id": "123456789012",
                             "external_id": "foo",
                         },
                         {
                             "role_name": "OrganizationAccountAccessRole",
                             "account_id": "123456789012",
                             "external_id": "foo",
                         },
                         {
                             "role_name": "OrganizationAccountAccessRole",
                             "account_id": None,
                             "external_id": None,
                         },
                     ],
                 },
             ],
             "credentials_cache": {
                 "cache": {}
             },
             "cache_creds":
             False,
         },
     )
예제 #3
0
 def test_get_session(self):
     with tempfile.TemporaryDirectory() as tmp_dir:
         access_config_path = Path(tmp_dir, "access_config.json")
         with open(access_config_path, "w") as fp:
             fp.write(json.dumps(TEST_ACCESSOR_FILE_CONTENT))
         accessor = Accessor.from_file(filepath=access_config_path)
         session = accessor.get_session(account_id="123456789012")
         sts_client = session.client("sts")
         sts_account_id = sts_client.get_caller_identity()["Account"]
         self.assertEqual(sts_account_id, "123456789012")
예제 #4
0
 def test_get_session_fall_through_failure(self):
     with tempfile.TemporaryDirectory() as tmp_dir:
         access_config_path = Path(tmp_dir, "access_config.json")
         with open(access_config_path, "w") as fp:
             fp.write(json.dumps(TEST_ACCESSOR_FILE_CONTENT))
         accessor = Accessor.from_file(filepath=access_config_path)
         with mock.patch(
                 "altimeter.aws.auth.multi_hop_accessor.MultiHopAccessor.get_session"
         ) as mock_get_session:
             mock_get_session.side_effect = Exception("MockAuthFailure")
             with self.assertRaises(AccountAuthException):
                 accessor.get_session(account_id="123456789012")