Skip to main content
Glama
test_github_oauth.pyโ€ข12.2 kB
#!/usr/bin/env python3 """ GitHub OAuth Integration Test This script tests the GitHub OAuth provider configuration and functionality for the Kafka Schema Registry MCP Server. """ import asyncio import os import sys # Add parent directory to path to import modules sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) def test_github_provider_config(): """Test GitHub provider configuration in the new generic structure.""" print("๐Ÿ”ง Testing GitHub Provider Configuration...") try: from oauth_provider import get_oauth_provider_configs configs = get_oauth_provider_configs() # Check GitHub is in the examples section if "examples" not in configs or "github" not in configs["examples"]: print(" โŒ GitHub provider not found in configuration examples") return False github_config = configs["examples"]["github"] # Test GitHub-specific configuration in new structure assert github_config["name"] == "GitHub OAuth (Limited Support)" assert github_config["issuer_url_pattern"] == "https://github.com" # Check example setup example_setup = github_config["example_setup"] assert "AUTH_ISSUER_URL" in example_setup assert example_setup["AUTH_ISSUER_URL"] == "https://github.com" assert "AUTH_AUDIENCE" in example_setup assert example_setup["AUTH_AUDIENCE"] == "your-github-client-id" # Check OAuth 2.1 compliance status (should be False for GitHub) assert github_config["oauth_2_1_compliant"] == False # Check GitHub limitations are documented if "notes" in github_config: notes = github_config["notes"] assert any("limited OAuth 2.1 support" in note for note in notes) assert any("No PKCE support" in note for note in notes) print(" โœ… GitHub provider configuration is valid in new structure") return True except Exception as e: print(f" โŒ Error testing GitHub provider config: {e}") return False def test_github_environment_variables(): """Test GitHub environment variable support with OAuth 2.1 generic approach.""" print("๐ŸŒ Testing GitHub OAuth 2.1 Configuration...") try: # Test the generic OAuth 2.1 approach for GitHub import os # Set up GitHub OAuth 2.1 configuration os.environ["AUTH_ISSUER_URL"] = "https://github.com" os.environ["AUTH_AUDIENCE"] = "test-github-client-id" from oauth_provider import AUTH_AUDIENCE, AUTH_ISSUER_URL # Test generic OAuth 2.1 variables work for GitHub assert AUTH_ISSUER_URL is not None, "AUTH_ISSUER_URL not available" assert AUTH_AUDIENCE is not None, "AUTH_AUDIENCE not available" # Test values print(f" ๐Ÿ“‹ AUTH_ISSUER_URL: {AUTH_ISSUER_URL}") print(f" ๐Ÿ“‹ AUTH_AUDIENCE: {AUTH_AUDIENCE}") print(" โœ… GitHub OAuth 2.1 generic configuration working") print(" โ„น๏ธ Note: GitHub uses fallback configuration (not fully OAuth 2.1 compliant)") return True except Exception as e: print(f" โŒ Error testing GitHub OAuth 2.1 configuration: {e}") return False async def test_github_fallback_configuration(): """Test GitHub fallback configuration logic.""" print("๐ŸŽฏ Testing GitHub Fallback Configuration...") try: import oauth_provider # Check if token validator is available if not hasattr(oauth_provider, "token_validator") or oauth_provider.token_validator is None: print(" โš ๏ธ Token validator not available (JWT dependencies missing)") print(" โ„น๏ธ GitHub fallback configuration is implemented but cannot be tested") return True validator = oauth_provider.token_validator # Test GitHub fallback configuration github_issuer = "https://github.com" fallback_config = await validator.get_fallback_configuration(github_issuer) # Check GitHub-specific fallback values assert fallback_config["issuer"] == "https://github.com" assert fallback_config["authorization_endpoint"] == "https://github.com/login/oauth/authorize" assert fallback_config["token_endpoint"] == "https://github.com/login/oauth/access_token" assert fallback_config["oauth_2_1_compliant"] == False assert "limited OAuth 2.1 support" in fallback_config["note"] print(f" ๐Ÿ“‹ Fallback config issuer: {fallback_config['issuer']}") print(f" ๐Ÿ“‹ OAuth 2.1 compliant: {fallback_config['oauth_2_1_compliant']}") print(f" ๐Ÿ“‹ Note: {fallback_config['note']}") print(" โœ… GitHub fallback configuration is working") return True except Exception as e: print(f" โŒ Error testing GitHub fallback configuration: {e}") return False async def test_github_discovery_fallback(): """Test GitHub discovery fallback when standard endpoints fail.""" print("๐Ÿ” Testing GitHub Discovery Fallback...") try: import oauth_provider # Check if token validator is available if not hasattr(oauth_provider, "token_validator") or oauth_provider.token_validator is None: print(" โš ๏ธ Token validator not available (JWT dependencies missing)") print(" โ„น๏ธ GitHub discovery fallback is implemented but cannot be tested") return True validator = oauth_provider.token_validator # Test discovery for GitHub URLs (should trigger fallback) github_urls = ["https://github.com", "https://api.github.com"] for github_url in github_urls: print(f" ๐Ÿงช Testing discovery fallback for: {github_url}") # This should trigger the fallback configuration config = await validator.discover_oauth_configuration(github_url) # Verify fallback was used (GitHub doesn't support standard discovery) assert config is not None, f"Failed to get fallback config for {github_url}" assert config.get("oauth_2_1_compliant") == False, "GitHub should not be marked as OAuth 2.1 compliant" assert "limited OAuth 2.1 support" in config.get("note", ""), "Should have limitation note" print(f" โœ… Fallback config generated for {github_url}") print(" โœ… GitHub discovery fallback is working correctly") return True except Exception as e: print(f" โŒ Error testing GitHub discovery fallback: {e}") return False async def test_github_generic_oauth_validation(): """Test GitHub with generic OAuth 2.1 validation approach.""" print("๐Ÿ” Testing GitHub with Generic OAuth 2.1 Validation...") try: import oauth_provider # Check if token validator is available if not hasattr(oauth_provider, "token_validator") or oauth_provider.token_validator is None: print(" โš ๏ธ Token validator not available (JWT dependencies missing)") print(" โ„น๏ธ GitHub OAuth validation is implemented but cannot be tested") return True validator = oauth_provider.token_validator # Test with mock GitHub development token (should be handled generically) github_dev_token = "dev-token-read,write" if validator.is_dev_token(github_dev_token): print(" โœ… GitHub development token format recognized") # Check if dev tokens are allowed in current environment from oauth_provider import ALLOW_DEV_TOKENS if ALLOW_DEV_TOKENS: # Test token validation with GitHub issuer # This tests the generic approach working with GitHub try: result = await validator.validate_token(github_dev_token, required_scopes={"read"}) # Should succeed for development tokens regardless of issuer if result.get("valid"): print(" โœ… GitHub development token validation succeeded") else: print(f" โ„น๏ธ Development token validation: {result}") except Exception as e: print(f" โ„น๏ธ Token validation (expected in test env): {e}") else: print(" โ„น๏ธ Development tokens not allowed in production environment (security feature)") else: print(" โš ๏ธ Development token format not recognized") print(" โœ… GitHub generic OAuth validation logic is available") return True except Exception as e: print(f" โŒ Error testing GitHub OAuth validation: {e}") return False def test_github_oauth_exports(): """Test that GitHub OAuth components are properly exported.""" print("๐Ÿ“ฆ Testing GitHub OAuth Exports...") try: import oauth_provider # Check GitHub-specific exports assert hasattr(oauth_provider, "AUTH_GITHUB_CLIENT_ID"), "AUTH_GITHUB_CLIENT_ID not exported" assert hasattr(oauth_provider, "AUTH_GITHUB_ORG"), "AUTH_GITHUB_ORG not exported" # Check GitHub is in __all__ assert "AUTH_GITHUB_CLIENT_ID" in oauth_provider.__all__, "AUTH_GITHUB_CLIENT_ID not in __all__" assert "AUTH_GITHUB_ORG" in oauth_provider.__all__, "AUTH_GITHUB_ORG not in __all__" print(" โœ… GitHub OAuth components are properly exported") return True except Exception as e: print(f" โŒ Error testing GitHub OAuth exports: {e}") return False async def main(): """Run all GitHub OAuth tests.""" print("๐Ÿ”“ GitHub OAuth Integration Test Suite") print("=" * 50) tests = [ ("Provider Configuration", test_github_provider_config), ("Environment Variables (Legacy)", test_github_environment_variables), ("Fallback Configuration", test_github_fallback_configuration), ("Discovery Fallback", test_github_discovery_fallback), ("Generic OAuth Validation", test_github_generic_oauth_validation), ("OAuth Exports", test_github_oauth_exports), ] passed = 0 total = len(tests) # Cleanup any existing sessions import oauth_provider if hasattr(oauth_provider, "token_validator") and oauth_provider.token_validator: try: await oauth_provider.token_validator.close() except Exception: pass for test_name, test_func in tests: print(f"\n๐Ÿงช Running: {test_name}") try: if asyncio.iscoroutinefunction(test_func): result = await test_func() else: result = test_func() if result: passed += 1 except Exception as e: print(f" โŒ Test failed with exception: {e}") # Final cleanup if hasattr(oauth_provider, "token_validator") and oauth_provider.token_validator: try: await oauth_provider.token_validator.close() except Exception: pass print("\n" + "=" * 50) print(f"๐Ÿ“Š Test Results: {passed}/{total} tests passed") if passed == total: print("๐ŸŽ‰ ALL GITHUB OAUTH TESTS PASSED!") print("โœ… GitHub OAuth integration is ready for use with generic OAuth 2.1 approach") print("\n๐Ÿ“‹ GitHub OAuth Configuration Summary:") print("โ€ข Configuration: Generic OAuth 2.1 with GitHub fallback") print("โ€ข OAuth 2.1 Compliance: Limited (no PKCE, no resource indicators)") print("โ€ข Discovery: Uses fallback configuration (no standard endpoints)") print("โ€ข Setup: AUTH_ISSUER_URL=https://github.com, AUTH_AUDIENCE=your-client-id") print("โ€ข Legacy Support: Environment variables maintained for backward compatibility") print("โ€ข Validation: Works with generic OAuth 2.1 validation approach") return True else: print(f"โš ๏ธ {total - passed} test(s) failed") return False if __name__ == "__main__": success = asyncio.run(main()) sys.exit(0 if success else 1)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aywengo/kafka-schema-reg-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server