Skip to content

Commit 02bf971

Browse files
committed
Added integration tests for authenticators endpoints
1 parent 187b2e4 commit 02bf971

File tree

3 files changed

+67
-11
lines changed

3 files changed

+67
-11
lines changed

test/python/api_config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
CONJUR_AUTHN_LOGIN = 'CONJUR_AUTHN_LOGIN'
1616
CONJUR_ACCOUNT = 'CONJUR_ACCOUNT'
1717

18+
WEBSERVICE_POLICY = pathlib.Path('test/config/webservice.yml')
19+
20+
def get_webservice_policy():
21+
"""Gets the text for the webservice testing policy"""
22+
with open(WEBSERVICE_POLICY, 'r') as policy:
23+
return policy.read()
24+
25+
1826
def get_default_policy():
1927
"""Gets the default testing policy"""
2028
with open(pathlib.Path('.').resolve() / 'test/config/policy.yaml', 'r') as default_policy:

test/python/test_authn_api.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class TestAuthnApi(api_config.ConfiguredTest):
1616
def setUpClass(cls):
1717
super().setUpClass()
1818
cls.api_key = os.environ[CONJUR_AUTHN_API_KEY]
19-
cls.account = os.environ[CONJUR_ACCOUNT]
2019

2120
@classmethod
2221
def tearDownClass(cls):
@@ -32,6 +31,10 @@ def setUp(self):
3231
self.client = openapi_client.ApiClient(self.config)
3332
self.api = openapi_client.api.authn_api.AuthnApi(self.client)
3433

34+
self.bad_auth_api = openapi_client.api.authn_api.AuthnApi(
35+
self.bad_auth_client
36+
)
37+
3538
def tearDown(self):
3639
self.client.close()
3740

@@ -66,6 +69,28 @@ def test_login(self):
6669
with self.assertRaises(openapi_client.exceptions.ApiException):
6770
self.api.login('authn', self.account)
6871

72+
# We dont have this authenticator setup so we cant authenticate with it
73+
@unittest.expectedFailure
74+
def test_service_login_200(self):
75+
"""Test case for service_login 200 response
76+
77+
Login with the given authenticator
78+
"""
79+
_, status, _ = self.api.service_login_with_http_info(
80+
'iam',
81+
'aws',
82+
self.account
83+
)
84+
85+
self.assertEqual(status, 200)
86+
87+
def test_service_login_401(self):
88+
"""Test case for service_login 401 response"""
89+
with self.assertRaises(openapi_client.exceptions.ApiException) as context:
90+
self.bad_auth_api.service_login('iam', 'aws', self.account)
91+
92+
self.assertEqual(context.exception.status, 401)
93+
6994
def test_rotate_api_key(self):
7095
"""Test case for rotate_api_key
7196
@@ -108,5 +133,33 @@ def test_set_password(self):
108133
with self.assertRaises(openapi_client.exceptions.ApiException):
109134
self.api.set_password(self.account, body=invalid_pass)
110135

136+
# We dont have this setup so we cant change the config
137+
@unittest.expectedFailure
138+
def test_update_authenticator_config_204(self):
139+
"""Test case for update_authenticator_config 204 response
140+
141+
Updates the authenticators configuration
142+
"""
143+
_, status, _ = self.api.update_authenticator_config_with_http_info(
144+
'oidc',
145+
'okta',
146+
self.account,
147+
body='enabled=false'
148+
)
149+
150+
self.assertEqual(status, 204)
151+
152+
def test_update_authenticator_config_401(self):
153+
"""Test case for update_authenticator_config 401 response"""
154+
with self.assertRaises(openapi_client.exceptions.ApiException) as context:
155+
self.bad_auth_api.update_authenticator_config(
156+
'oidc',
157+
'okta',
158+
self.account,
159+
body='enabled=false'
160+
)
161+
162+
self.assertEqual(context.exception.status, 401)
163+
111164
if __name__ == '__main__':
112165
unittest.main()

test/python/test_status_api.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import absolute_import
22

33
import unittest
4-
import pathlib
54

65
import openapi_client
76

@@ -21,21 +20,14 @@
2120
"token_issued_at",
2221
]
2322

24-
WEBSERVICE_POLICY = pathlib.Path('test/config/webservice.yml')
25-
26-
def get_webservice_policy():
27-
"""Gets the text for the webservice testing policy"""
28-
with open(WEBSERVICE_POLICY, 'r') as policy:
29-
return policy.read()
30-
3123
class TestStatusApi(api_config.ConfiguredTest):
3224
"""StatusApi unit test stubs"""
3325
@classmethod
3426
def setup_webservice(cls):
3527
"""loads the webservice policy into conjur and gets it setup"""
3628
policies_api = openapi_client.api.policies_api.PoliciesApi(cls.client)
3729
secrets_api = openapi_client.api.secrets_api.SecretsApi(cls.client)
38-
policies_api.modify_policy(cls.account, 'root', get_webservice_policy())
30+
policies_api.modify_policy(cls.account, 'root', api_config.get_webservice_policy())
3931
secrets_api.create_variable(
4032
cls.account,
4133
"variable",
@@ -161,7 +153,10 @@ def test_authenticators_index_200(self):
161153
authenticators, status, _ = self.api.authenticators_index_with_http_info()
162154

163155
self.assertEqual(status, 200)
164-
self.assertIsInstance(authenticators, openapi_client.models.authenticators_response.AuthenticatorsResponse)
156+
self.assertIsInstance(
157+
authenticators,
158+
openapi_client.models.authenticators_response.AuthenticatorsResponse
159+
)
165160

166161
for i in AUTHENTICATOR_FIELDS:
167162
lst = getattr(authenticators, i)

0 commit comments

Comments
 (0)