Debian Codegraph @

test_integration/test_iam_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 "iamtest.env" in the project root.
12 # It should look like this:
13 #
14 # IAMTEST1_AUTH_URL=<url> e.g. https://iam.cloud.ibm.com
15 # IAMTEST1_AUTH_TYPE=iam
16 # IAMTEST1_APIKEY=<apikey>
17 #
18 # Then run this command:
19 # pytest test_integration/test_iam_authenticator_integration.py
20
21 # To enable debug logging as well as HTTP message logging,
22 # change WARNING to DEBUG:
23 setup_test_logger(logging.WARNING)
24
25
26 def test_iam_authenticator():
27 os.environ['IBM_CREDENTIALS_FILE'] = 'iamtest.env'
28
29 authenticator = get_authenticator_from_environment('iamtest1')
30 assert authenticator is not None
31
32 request = {'headers': {}}
33 authenticator.authenticate(request)
34 assert request['headers']['Authorization'] is not None
35 assert 'Bearer' in request['headers']['Authorization']