Coverage for libs/sdc_etl_libs/tests/aws_helpers_tests/aws_secrets_test.py : 29%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import os
2import sys
4import boto3
5import pytest
7sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../../../")
10@pytest.mark.skip(reason="It is an integration test, it expect .aws set")
11def test_get_credentials__expired_token(mocker):
12 """
13 This will use an expired token to cause the ExpiredTokenException to be raised
14 """
15 secret_id_ = 'snowflake/service_account/airflow'
16 access_key_ = None
17 secret_key_ = None
18 aws_session_token_ = None
20 # get your current valid key values
21 # We will need to access key and secret key to create an expired token connection
22 mysession = boto3.session.Session(
23 aws_access_key_id=access_key_,
24 aws_secret_access_key=secret_key_,
25 aws_session_token=aws_session_token_,
26 region_name='us-east-2')
28 credentials = mysession.get_credentials()
29 credentials = credentials.get_frozen_credentials()
30 access_key_ = credentials.access_key
31 secret_key_ = credentials.secret_key
33 # Set our session to an expired token
34 # This actually has to be a legit expired token or you will receive a different error
35 aws_session_token_ = """FwoGZXIvYXdzEGIaDHgIMISXbLjMZ9OetyKCAp+1cu5hd2sSQkBQ6ZO/3hlgQQ85GUy21WR/BNGVkXBW/qYCjYmFC1CegPuX6O/upNVZeDNXK+uMa3CsfKZKY/3B4M3Dno4gp+cq4PhK9jLB78lCEBBfkART7PEzOZEZmk6bhkctSag0ZZbY2fv5lFpshcADwSYBGpudJn3Sv+HumdY+SucE25OP04lsNueym4NbUEC/O5ew5JObayviFLUr1WESWTeRVXnacfsSvwSpIGCmwhFTC1qGGZcrFcaviZUKEw6Z9nreQ82mrFlJj6ZLWQE8ISpm6PlaVrfwCA1861p9UlkzATdBG1n7w39rS32/wFykhZN+2NNOoJo5kNE3ZSjN6oD9BTIrlEKgJlWWmr8E4TDezmNj+FaLmYMjhmjH/XMfteIrrtPHxUNXrhgtOeiCdg=="""
37 # this few lines of code mimics aws_helpers.get_secrets()
38 # Create the session with the expired token
39 mysession = boto3.session.Session(
40 aws_access_key_id=access_key_,
41 aws_secret_access_key=secret_key_,
42 aws_session_token=aws_session_token_,
43 region_name='us-east-2')
45 with pytest.raises(Exception) as excep_info:
46 secrets = mysession.client('secretsmanager')
47 # this line will trigger the error
48 response = secrets.get_secret_value(SecretId=secret_id_)
49 assert 'ExpiredTokenException' in str(excep_info.value)