Skip to content

Commit

Permalink
test: add IAM integration test (#151)
Browse files Browse the repository at this point in the history
Signed-off-by: Phil Adams <phil_adams@us.ibm.com>
  • Loading branch information
padamstx authored Feb 9, 2023
1 parent 5cb2d95 commit a348122
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test_integration/test_cp4d_authenticator_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# In order to test with a live CP4D server, rename "ibm-credentials-cp4dtest.env.example" to
# "ibm-credentials-cp4dtest.env" in the resources folder and populate the fields.
# Then run this command:
# pytest test_integration
# pytest test_integration/test_cp4d_authenticator_integration.py

IBM_CREDENTIALS_FILE = '../resources/ibm-credentials-cp4dtest.env'

Expand Down
28 changes: 28 additions & 0 deletions test_integration/test_iam_authenticator_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# pylint: disable=missing-docstring
import os

from ibm_cloud_sdk_core import get_authenticator_from_environment

# Note: Only the unit tests are run by default.
#
# In order to test with a live IAM server, create file "iamtest.env" in the project root.
# It should look like this:
#
# IAMTEST1_AUTH_URL=<url> e.g. https://iam.cloud.ibm.com
# IAMTEST1_AUTH_TYPE=iam
# IAMTEST1_APIKEY=<apikey>
#
# Then run this command:
# pytest test_integration/test_iam_authenticator_integration.py


def test_iam_authenticator():
os.environ['IBM_CREDENTIALS_FILE'] = 'iamtest.env'

authenticator = get_authenticator_from_environment('iamtest1')
assert authenticator is not None

request = {'headers': {}}
authenticator.authenticate(request)
assert request['headers']['Authorization'] is not None
assert 'Bearer' in request['headers']['Authorization']

0 comments on commit a348122

Please sign in to comment.