@@ -393,3 +393,111 @@ def test_file_uploads_complete(client, part_uploaded_file_upload_id):
393393 assert response ["content_type" ] == "text/plain"
394394 assert response ["number_of_parts" ]["total" ] == 3
395395 assert response ["number_of_parts" ]["sent" ] == 3
396+
397+
398+ def test_oauth_introspect (client , mocker ):
399+ """Test OAuth token introspection with mock - tests Basic auth encoding"""
400+ mock_response = {"active" : False , "request_id" : "test-request-id" }
401+
402+ # Mock at HTTP level to test Basic auth header encoding
403+ mock_send = mocker .patch .object (
404+ client .client ,
405+ "send" ,
406+ return_value = mocker .Mock (
407+ json = lambda : mock_response , raise_for_status = lambda : None
408+ ),
409+ )
410+
411+ response = client .oauth .introspect (
412+ client_id = "test_client_id" ,
413+ client_secret = "test_client_secret" ,
414+ token = "test_token" ,
415+ )
416+
417+ assert "active" in response
418+ assert isinstance (response ["active" ], bool )
419+
420+ # Verify the Basic auth header was properly encoded
421+ mock_send .assert_called_once ()
422+ request = mock_send .call_args [0 ][0 ]
423+ assert "Authorization" in request .headers
424+ assert request .headers ["Authorization" ].startswith ("Basic " )
425+ # The base64 of "test_client_id:test_client_secret" is "dGVzdF9jbGllbnRfaWQ6dGVzdF9jbGllbnRfc2VjcmV0"
426+ assert (
427+ request .headers ["Authorization" ]
428+ == "Basic dGVzdF9jbGllbnRfaWQ6dGVzdF9jbGllbnRfc2VjcmV0"
429+ )
430+
431+
432+ def test_oauth_revoke (client , mocker ):
433+ """Test OAuth token revocation with mock (can't use cassette - token becomes invalid)"""
434+ mock_response = {}
435+ mock_request = mocker .patch .object (client , "request" , return_value = mock_response )
436+
437+ response = client .oauth .revoke (
438+ client_id = "test_client_id" ,
439+ client_secret = "test_client_secret" ,
440+ token = "test_token" ,
441+ )
442+
443+ assert response == {}
444+ mock_request .assert_called_once_with (
445+ path = "oauth/revoke" ,
446+ method = "POST" ,
447+ body = {"token" : "test_token" },
448+ auth = {"client_id" : "test_client_id" , "client_secret" : "test_client_secret" },
449+ )
450+
451+
452+ def test_oauth_token_authorization_code (client , mocker ):
453+ mock_response = {
454+ "access_token" : "secret_test_token" ,
455+ "token_type" : "bearer" ,
456+ "bot_id" : "bot_123" ,
457+ "workspace_id" : "ws_456" ,
458+ "workspace_name" : "Test Workspace" ,
459+ "owner" : {"type" : "user" , "user" : {"object" : "user" , "id" : "user_789" }},
460+ }
461+
462+ mock_request = mocker .patch .object (client , "request" , return_value = mock_response )
463+
464+ response = client .oauth .token (
465+ client_id = "test_client_id" ,
466+ client_secret = "test_client_secret" ,
467+ grant_type = "authorization_code" ,
468+ code = "test_code" ,
469+ redirect_uri = "http://localhost:3000/callback" ,
470+ )
471+
472+ assert response ["access_token" ] == "secret_test_token"
473+ assert response ["bot_id" ] == "bot_123"
474+ mock_request .assert_called_once ()
475+ call_kwargs = mock_request .call_args [1 ]
476+ assert call_kwargs ["path" ] == "oauth/token"
477+ assert call_kwargs ["method" ] == "POST"
478+ assert call_kwargs ["auth" ] == {
479+ "client_id" : "test_client_id" ,
480+ "client_secret" : "test_client_secret" ,
481+ }
482+
483+
484+ def test_oauth_token_refresh_token (client , mocker ):
485+ mock_response = {
486+ "access_token" : "secret_refreshed_token" ,
487+ "token_type" : "bearer" ,
488+ "bot_id" : "bot_123" ,
489+ }
490+
491+ mock_request = mocker .patch .object (client , "request" , return_value = mock_response )
492+
493+ response = client .oauth .token (
494+ client_id = "test_client_id" ,
495+ client_secret = "test_client_secret" ,
496+ grant_type = "refresh_token" ,
497+ refresh_token = "test_refresh_token" ,
498+ )
499+
500+ assert response ["access_token" ] == "secret_refreshed_token"
501+ mock_request .assert_called_once ()
502+ call_kwargs = mock_request .call_args [1 ]
503+ assert call_kwargs ["path" ] == "oauth/token"
0 commit comments