| 1 |
# pylint: disable=missing-docstring |
| 2 |
import logging |
| 3 |
import os |
| 4 |
|
| 5 |
from test.utils.logger_utils import setup_test_logger |
| 6 |
from ibm_cloud_sdk_core import get_authenticator_from_environment |
| 7 |
|
| 8 |
setup_test_logger(logging.WARNING) |
| 9 |
|
| 10 |
|
| 11 |
# Note: Only the unit tests are run by default. |
| 12 |
# |
| 13 |
# In order to test with a live MCSP token server, create file "mcspv2test.env" in the project root. |
| 14 |
# It should look like this: |
| 15 |
# |
| 16 |
# required properties: |
| 17 |
# |
| 18 |
# MCSPV2TEST1_AUTH_URL=<url> e.g. https://account-iam.platform.dev.saas.ibm.com |
| 19 |
# MCSPV2TEST1_AUTH_TYPE=mcspv2 |
| 20 |
# MCSPV2TEST1_APIKEY=<apikey> |
| 21 |
# MCSPV2TEST1_SCOPE_COLLECTION_TYPE=accounts (use any valid collection type value) |
| 22 |
# MCSPV2TEST1_SCOPE_ID=global_account (use any valid scope id) |
| 23 |
# |
| 24 |
# optional properties: |
| 25 |
# |
| 26 |
# MCSPV2TEST1_INCLUDE_BUILTIN_ACTIONS=true|false |
| 27 |
# MCSPV2TEST1_INCLUDE_CUSTOM_ACTIONS=true|false |
| 28 |
# MCSPV2TEST1_INCLUDE_ROLES=true|false |
| 29 |
# MCSPV2TEST1_PREFIX_ROLES=true|false |
| 30 |
# MCSPV2TEST1_CALLER_EXT_CLAIM={"productID":"prod123"} |
| 31 |
# |
| 32 |
# Then run this command: |
| 33 |
# pytest test_integration/test_mcspv2_authenticator_integration.py |
| 34 |
def test_mcspv2_authenticator(): |
| 35 |
os.environ['IBM_CREDENTIALS_FILE'] = 'mcspv2test.env' |
| 36 |
|
| 37 |
authenticator = get_authenticator_from_environment('mcspv2test1') |
| 38 |
assert authenticator is not None |
| 39 |
|
| 40 |
request = {'headers': {}} |
| 41 |
authenticator.authenticate(request) |
| 42 |
assert request['headers']['Authorization'] is not None |
| 43 |
|
| 44 |
auth_header = request['headers']['Authorization'] |
| 45 |
assert 'Bearer' in auth_header |
| 46 |
print("Authorization: ", auth_header) |