Debian Codegraph @

test_integration/test_iam_assume_authenticator_integration.py

raw
1 # pylint: disable=missing-docstring
2 import os
3
4 import logging
5
6 from test.utils.logger_utils import setup_test_logger
7 from ibm_cloud_sdk_core import get_authenticator_from_environment
8
9 # Note: Only the unit tests are run by default.
10 #
11 # In order to test with a live IAM server, create file "iamassumetest.env" in the project root.
12 # It should look like this:
13 #
14 # IAMASSUMETEST_AUTH_URL=<url> e.g. https://iam.cloud.ibm.com
15 # IAMASSUMETEST_AUTH_TYPE=iam
16 # IAMASSUMETEST_APIKEY=<apikey>
17 # IAMASSUMETEST_PROFILE_ID=<profile-id>
18 #
19 # Then run this command:
20 # pytest test_integration/test_iam_assume_authenticator_integration.py
21
22 # To enable debug logging as well as HTTP message logging,
23 # change WARNING to DEBUG:
24 setup_test_logger(logging.WARNING)
25
26
27 def test_iam_authenticator():
28 os.environ['IBM_CREDENTIALS_FILE'] = 'iamassumetest.env'
29
30 authenticator = get_authenticator_from_environment('iamassumetest')
31 assert authenticator is not None
32
33 request = {'headers': {}}
34 authenticator.authenticate(request)
35 assert request['headers']['Authorization'] is not None
36 assert 'Bearer' in request['headers']['Authorization']