feat: Add auth_tools support and fix test infrastructure

Merged
PE
5mo ago
+557-60

Key Features Added

🔐 Auth_tools Support

• HTTP Plugin: Added auth_tools field to HttpCallTemplate for tool-specific authentication
• Text Plugin: Added auth_tools support for local OpenAPI specs
• Smart Authentication: Compatible auth schemes use real credentials, incompatible ones use placeholders
• Public Endpoints: Remain accessible without authentication requirements

🤖 Auto-Discovery of Authentication Requirements

• AuthToolsConfig: New wrapper class with auto_discover and verify_auth options
• Endpoint Testing: Automatically tests endpoints with unauthenticated requests
• Smart Classification:
• 200/2xx → Public endpoint (no auth needed)
• 401/403 → Requires authentication
• Other → Assumes public for safety
• Credential Verification: Optional validation that provided auth actually works
• Override Specs: Ignores potentially incorrect OpenAPI security definitions

🧪 Test Infrastructure Fixes

• Pytest Fixtures: Resolved aiohttp_client dependency issues in HTTP tests
• Test Coverage: All 163 tests now pass without conflicts
• Comprehensive Testing: Added auth_tools integration tests and auto-discovery test suite

Technical Implementation

Authentication Logic

• Analyzes OpenAPI security schemes vs provided auth_tools
• convert_async() method with auto-discovery support
• Applies authentication only to compatible/required endpoints
• Maintains backward compatibility (auth_tools is optional)
• Preserves existing behavior for public APIs

Auto-Discovery Process

  1. Test Endpoints: Makes unauthenticated requests to each endpoint
  2. Classify Responses: Determines actual auth requirements vs spec
  3. Apply Authentication: Only adds auth to endpoints returning 401/403
  4. Verify Credentials: Tests that provided auth actually works (optional)
  5. Log Issues: Reports when auth doesn't work for specific endpoints

Plugin Support

• HTTP Plugin: Full auth_tools support with auto-discovery for remote OpenAPI specs
• Text Plugin: Auth_tools support with auto-discovery for local OpenAPI files
• Consistent API: Same auth_tools interface across both plugins

Configuration Examples

Basic Auth_tools

{
  "auth_tools": {
    "auth_type": "api_key",
    "api_key": "Bearer ${API_TOKEN}",
    "var_name": "Authorization",
    "location": "header"
  }
}

Auto-Discovery Configuration

{
  "auth_tools": {
    "auth": {
      "auth_type": "api_key", 
      "api_key": "Bearer ${GITHUB_TOKEN}",
      "var_name": "Authorization",
      "location": "header"
    },
    "auto_discover": true,
    "verify_auth": true
  }
}

Documentation Updates

• Updated README.md with auth_tools and auto-discovery configuration examples
• Enhanced plugin-specific documentation
• Added usage examples for both HTTP and text plugins
• Complete auto-discovery guide and benefits

Backward Compatibility

✅ All existing functionality preserved
✅ Optional auth_tools field maintains compatibility
✅ AuthToolsConfig supports both dict and Auth object formats
✅ No breaking changes to existing APIs

Testing

• 163/163 tests passing
• New integration tests for auth_tools functionality
• Comprehensive auto-discovery test suite
• AuthToolsConfig serialization/validation tests
• Comprehensive coverage of authentication scenarios