Skip to content

Comments

test: add missing oauth providers test#2687

Merged
asvishnyakov merged 1 commit intoChainlit:mainfrom
codomposer:fix/test_oauth_providers
Nov 24, 2025
Merged

test: add missing oauth providers test#2687
asvishnyakov merged 1 commit intoChainlit:mainfrom
codomposer:fix/test_oauth_providers

Conversation

@codomposer
Copy link
Contributor

@codomposer codomposer commented Nov 22, 2025

Add Tests for Missing OAuth Providers

Description

This PR adds comprehensive unit tests for OAuth providers that were previously missing test coverage in the Chainlit authentication system. The initial OAuth provider tests (PR #XXX) covered 7 out of 11 providers. This PR completes the test suite by adding tests for the remaining 5 providers.

Changes

New Test Classes Added

Added comprehensive test coverage for the following OAuth providers:

  1. AzureADHybridOAuthProvider (TestAzureADHybridOAuthProvider)

    • Initialization with tenant configuration
    • Token retrieval with refresh token storage
    • User info fetching with photo support
    • Hybrid flow specific parameters (nonce, response_mode, response_type)
  2. DescopeOAuthProvider (TestDescopeOAuthProvider)

    • Provider initialization
    • Token retrieval
    • User info parsing
  3. AWSCognitoOAuthProvider (TestAWSCognitoOAuthProvider)

    • Provider initialization with Cognito domain
    • Custom scope configuration
    • Token retrieval
    • User info with picture metadata
  4. GitlabOAuthProvider (TestGitlabOAuthProvider)

    • Provider initialization with custom domain
    • Domain trailing slash normalization
    • Token retrieval
    • User info with avatar support
  5. KeycloakOAuthProvider (TestKeycloakOAuthProvider)

    • Provider initialization with realm and base URL
    • Custom provider name support
    • Token retrieval with refresh token
    • User info parsing

Test Coverage Summary

Before this PR:

  • ✅ OAuthProvider (base class)
  • ✅ GithubOAuthProvider
  • ✅ GoogleOAuthProvider
  • ✅ AzureADOAuthProvider
  • ✅ OktaOAuthProvider
  • ✅ Auth0OAuthProvider
  • ✅ GenericOAuthProvider
  • ❌ AzureADHybridOAuthProvider
  • ❌ DescopeOAuthProvider
  • ❌ AWSCognitoOAuthProvider
  • ❌ GitlabOAuthProvider
  • ❌ KeycloakOAuthProvider

After this PR:

  • ✅ All 11 OAuth providers have comprehensive test coverage

Test Statistics

  • New test classes: 5
  • New test methods: 15
  • Total test file size: ~1,200 lines
  • Coverage areas: Initialization, token retrieval, user info, error handling, custom configurations

Testing Approach

Each provider test suite includes:

  1. Initialization Tests

    • Environment variable configuration
    • Client ID/secret validation
    • Provider-specific parameters (domains, realms, scopes)
    • Custom configuration options
  2. Token Retrieval Tests

    • Successful token exchange
    • Access token extraction
    • Refresh token storage (where applicable)
    • HTTP request mocking with httpx.AsyncClient
  3. User Info Tests

    • User data parsing
    • Email/identifier extraction
    • Metadata handling (images, provider names)
    • User object creation
  4. Provider-Specific Features

    • Azure AD Hybrid: nonce generation, form_post response mode
    • AWS Cognito: custom scope configuration
    • Gitlab: domain trailing slash normalization
    • Keycloak: custom provider naming, realm configuration

Implementation Details

  • Uses pytest with @pytest.mark.asyncio for async tests
  • Mocks HTTP requests with unittest.mock.AsyncMock and httpx.AsyncClient
  • Uses patch.dict for environment variable isolation
  • Follows existing test patterns from initial OAuth provider tests
  • Module reloading for class-level attribute testing (Keycloak custom name)

Contribution by Gittensor, learn more at https://gittensor.io/

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. auth Pertaining to authentication. backend Pertains to the Python backend. labels Nov 22, 2025
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@asvishnyakov asvishnyakov changed the title add missing oauth providers test test: add missing oauth providers test Nov 24, 2025
@asvishnyakov asvishnyakov added this pull request to the merge queue Nov 24, 2025
Merged via the queue into Chainlit:main with commit c213f9b Nov 24, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth Pertaining to authentication. backend Pertains to the Python backend. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants