Skip to content

Conversation

@tomerqodo
Copy link

Benchmark PR langgenius#29950

Type: Corrupted (contains bugs)

Original PR Title: fix: validate API key is not empty in HTTPRequest node
Original PR Description: # Fix: HTTPRequest Node fails when API key is empty

Description

Fixes issue langgenius#21830 where the HTTPRequest node fails to execute when the API key used for authorization is empty, resulting in invalid headers like "Basic " (with no credentials) and causing "Illegal header value" errors.

Changes

Core Fix

  • Added validation in Executor.__init__ to check if API key is empty or whitespace-only after template conversion
  • Raises AuthorizationConfigError with a clear error message when API key is empty
  • Prevents invalid authorization headers from being created

Files Modified

  1. api/core/workflow/nodes/http_request/executor.py

    • Added validation after template conversion (lines 89-93)
    • Validates both empty strings and whitespace-only strings
  2. api/tests/unit_tests/core/workflow/nodes/http_request/test_http_request_executor.py

    • Added 5 new unit tests:
      • test_empty_api_key_raises_error_bearer - Tests bearer auth with empty key
      • test_empty_api_key_raises_error_basic - Tests basic auth with empty key
      • test_empty_api_key_raises_error_custom - Tests custom auth with empty key
      • test_whitespace_only_api_key_raises_error - Tests whitespace-only key
      • test_valid_api_key_works - Ensures valid keys still work
  3. api/tests/integration_tests/workflow/nodes/test_http.py

    • Updated test_custom_auth_with_empty_api_key_raises_error to expect AuthorizationConfigError
    • Updated test_custom_authorization_with_empty_api_key to verify proper error handling in node execution

Testing

Unit Tests

All new unit tests pass:

  • ✅ Empty API key validation for bearer, basic, and custom auth types
  • ✅ Whitespace-only API key validation
  • ✅ Valid API key still works correctly

Integration Tests

  • ✅ Updated integration tests to verify error handling in full node execution

Manual Testing

To test manually:

  1. Create a workflow with an HTTPRequest node
  2. Set authorization type to "api-key" (bearer, basic, or custom)
  3. Leave the API key field empty
  4. Execute the workflow
  5. Should receive a clear error: "API key is required for authorization but was empty. Please provide a valid API key."

Impact

  • Before: Empty API keys caused cryptic errors like "Illegal header value b'Basic '" during HTTP request execution
  • After: Empty API keys are caught early with a clear, actionable error message before any HTTP request is made

Related Issues

Fixes langgenius#21830

Checklist

  • Code follows project style guidelines
  • Tests added/updated
  • All tests pass
  • No linter errors
  • Error messages are clear and actionable
  • Backward compatibility maintained (valid API keys still work)

Original PR URL: langgenius#29950

AziizBg and others added 3 commits December 19, 2025 18:56
- Add validation after template conversion to check for empty/whitespace API keys
- Raise AuthorizationConfigError with clear message when API key is empty
- Prevents invalid headers like 'Basic ' from being created
- Add comprehensive unit tests for all auth types (bearer, basic, custom)
- Update integration tests to verify proper error handling

Fixes langgenius#21830
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants