@@ -194,16 +194,17 @@ def check_device_code_table(client_id, user_code, device_code, verification_url,
194194 retrieved = models .DeviceCode .query .filter_by (user_code = user_code ).first ()
195195 print (f'DEBUG: got device code object:: { retrieved } ' )
196196 if negative :
197- assert retrieved == None
197+ assert retrieved is None
198198 return
199199 assert retrieved .code == device_code
200200 assert retrieved .user_code == user_code
201201 assert retrieved .tenant_id == TEST_TENANT_ID
202202 assert retrieved .client_id == client_id
203- assert retrieved .client_key == TEST_CLIENT_KEY
203+ assert retrieved .client_key == TEST_CLIENT_KEY
204204 assert retrieved .status == status
205205 assert retrieved .verification_uri == verification_url
206206
207+
207208def validate_refresh_token (response ):
208209 """
209210 Validate that a response has a refresh token and it is properly formatted.
@@ -221,6 +222,7 @@ def validate_refresh_token(response):
221222 assert claims ['tapis/access_token' ]['sub' ] == f'{ TEST_USERNAME } @{ TEST_TENANT_ID } '
222223 return claims
223224
225+
224226def get_jwt (client ):
225227 # TODO: add assertions for failing to get a token -- this should fail the current test somehow
226228 # auth_header = {'Authorization': get_basic_auth_header(TEST_CLIENT_ID, TEST_CLIENT_KEY)}
@@ -241,17 +243,20 @@ def get_jwt(client):
241243 access_token_str = response .json ['result' ]['access_token' ]['access_token' ]
242244 return access_token_str
243245
246+
244247def gen_mfa_token (username , tokencode = None ):
245248 """
246249 Generate a OTP mfa code using pyotp given a username and token code.
247250 If a token code is not provided, a random one will be used.
248251 """
249252 pass
250253
254+
251255# =====================
252256# Actual test functions
253257# =====================
254258
259+
255260## utility tests
256261# get jwt
257262def test_get_jwt (client ):
@@ -262,6 +267,7 @@ def test_get_jwt(client):
262267 result = get_jwt (client )
263268 print (f'got result = { result } ' )
264269
270+
265271# get mfa config
266272def test_get_mfa_config (client ):
267273 print ('top of get mfa config' )
@@ -289,6 +295,7 @@ def test_get_mfa_config(client):
289295 print (f'got { e } while trying to get mfa config for tenant { TEST_TENANT_ID } ' )
290296 raise Exception ()
291297
298+
292299## Health Check
293300# hello
294301def test_authenticator_hello (client ):
@@ -301,23 +308,27 @@ def test_authenticator_ready(client):
301308 result = client .get ('http://localhost:5000/v3/oauth2/ready' )
302309 assert result .status_code == 200
303310
311+
304312## Metadata
305313# get_server_metadata
306314def test_get_metadata (client ):
307315 result = client .get ("http://localhost:5000/v3/oauth2/.well-known/oauth-authorization-server" )
308316 assert result .status_code == 200
309317
318+
310319## Admin
311320# get_config
312321# update_config
313322
314323## Clients
315324
325+
316326def test_invalid_post (client ):
317327 with client :
318328 response = client .post ("http://localhost:5000/v3/oauth2/clients" )
319329 assert response .status_code == 400
320330
331+
321332# list_clients
322333def test_authenticator_list_clients (client , capsys ):
323334 # result = client.authenticator.list_clients()
@@ -326,6 +337,7 @@ def test_authenticator_list_clients(client, capsys):
326337 result = client .get ('http://localhost:5000/v3/oauth2/clients' , headers = header )
327338 assert result .status_code == 200
328339
340+
329341# create_client
330342def test_authenticator_create_clients (client , capsys ): ## TODO: this works, but doing it twice violates uniqueness constraint. Need to find a way to reliably erase it without using another endpoint
331343 # result = client.authenticator.create_client(client_id=TEST_CLIENT_ID, callback_url='https://foo.example.com/oauth2/callback')
@@ -522,7 +534,7 @@ def test_password_grant_no_client(client, init_db):
522534 assert 'access_token' in response .json ['result' ]
523535 # validate access_token:
524536 claims = validate_access_token (response )
525- assert claims ['tapis/client_id' ] == None
537+ assert claims ['tapis/client_id' ] is None
526538 assert claims ['tapis/grant_type' ] == 'password'
527539 # when not using an oauth client, refresh tokens are not returned:
528540 assert 'refresh_token' not in response .json ['result' ]
@@ -565,7 +577,7 @@ def test_revoke_token(client, init_db):
565577 data = json .dumps (payload ),
566578 content_type = 'application/json'
567579 )
568- assert response .status_code == 200
580+ assert response .status_code == 200
569581 check_access_token_table (access_token_claims , "password" , True , TEST_CLIENT_ID )
570582
571583 # then the refresh token
@@ -575,7 +587,7 @@ def test_revoke_token(client, init_db):
575587 data = json .dumps (payload ),
576588 content_type = 'application/json'
577589 )
578- assert response .status_code == 200
590+ assert response .status_code == 200
579591
580592 check_refresh_token_table (refresh_token_claims , "password" , True , TEST_CLIENT_ID )
581593
@@ -799,12 +811,12 @@ def test_exchange_device_code(client):
799811 access_token_ttl = models .DeviceCode .set_ttl ())
800812 except Exception as e :
801813 print (f'ERROR: exception while generating device code object:: { e } ' )
802- assert device_code != None
814+ assert device_code is not None
803815 print (f'DEBUG: have device code object: { device_code } ' )
804816 try :
805817 models .db .session .add (device_code )
806818 models .db .session .commit ()
807- print (f 'DEBUG: committed device code object to DB' )
819+ print ('DEBUG: committed device code object to DB' )
808820 except Exception as e :
809821 print (f"Got exception trying to add and commit the device code. e: { e } ; type(e): { type (e )} " )
810822 raise Exception ("Internal error saving device code. Please try again later." )
0 commit comments