Example #1
0
 def test_read_secret_different_versions_from_secret_manager(self):
     hook = SecretsManagerHook()
     secret = hook.get_secret(secret_id=TEST_SECRET_ID)
     assert TEST_SECRET_VALUE_UPDATED == secret
     secret = hook.get_secret(secret_id=TEST_SECRET_ID, secret_version='1')
     assert TEST_SECRET_VALUE == secret
     secret = hook.get_secret(secret_id=TEST_SECRET_ID, secret_version='2')
     assert TEST_SECRET_VALUE_UPDATED == secret
Example #2
0
 def test_get_missing_key(self, mock_get_credentials, mock_client):
     mock_client.secret_version_path.return_value = "full-path"
     mock_client.access_secret_version.side_effect = NotFound('test-msg')
     secrets_manager_hook = SecretsManagerHook(gcp_conn_id='test')
     mock_get_credentials.assert_called_once_with()
     secret = secrets_manager_hook.get_secret(secret_id="secret")
     mock_client.secret_version_path.assert_called_once_with('example-project', 'secret', 'latest')
     mock_client.access_secret_version.assert_called_once_with("full-path")
     self.assertIsNone(secret)
Example #3
0
 def test_get_existing_key(self, mock_get_credentials, mock_client):
     mock_client.secret_version_path.return_value = "full-path"
     test_response = AccessSecretVersionResponse()
     test_response.payload.data = "result".encode("UTF-8")
     mock_client.access_secret_version.return_value = test_response
     secrets_manager_hook = SecretsManagerHook(gcp_conn_id='test')
     mock_get_credentials.assert_called_once_with()
     secret = secrets_manager_hook.get_secret(secret_id="secret")
     mock_client.secret_version_path.assert_called_once_with('example-project', 'secret', 'latest')
     mock_client.access_secret_version.assert_called_once_with("full-path")
     self.assertEqual("result", secret)
Example #4
0
 def test_read_missing_secret_from_secret_manager(self):
     hook = SecretsManagerHook()
     secret = hook.get_secret(secret_id=TEST_MISSING_SECRET_ID)
     assert secret is None
Example #5
0
 def test_read_secret_from_secret_manager(self):
     hook = SecretsManagerHook()
     secret = hook.get_secret(secret_id=TEST_SECRET_ID)
     assert TEST_SECRET_VALUE == secret
Example #6
0
 def test_read_secret_from_secret_manager(self):
     hook = SecretsManagerHook()
     secret = hook.get_secret(secret_id=TEST_SECRET_ID)
     self.assertEqual(TEST_SECRET_VALUE, secret)