Authentication Testing
Relevant source files
The following files were used as context for generating this wiki page:
Authentication testing within the flext-tap-oracle-oic project ensures the robust implementation of the OAuth2 Client Credentials flow required to interact with Oracle Integration Cloud (OIC) APIs. The testing framework validates configuration integrity, token retrieval logic, error handling for various HTTP status codes, and the base64 encoding of credentials. Sources: tests/unit/test_auth.py:1-15
The scope of these tests covers the interaction between the FlextOracleOicAuthenticator, the OIC identity endpoints, and the underlying API client. By utilizing mocked dependencies, the test suite verifies that the authenticator correctly processes successful token responses, handles expired or invalid credentials, and manages unexpected network or protocol failures. Sources: tests/unit/test_auth.py:17-25, src/flext_tap_oracle_oic/tap.py:38-42
Authentication Architecture and Logic
The authentication system is centered around the FlextOracleOicAuthenticator class. This component is responsible for negotiating access tokens from the Oracle Identity Cloud Service (IDCS) using provided client credentials. The testing suite focuses on the get_access_token method, which executes the POST request to the oauth_token_url. Sources: src/flext_tap_oracle_oic/tap.py:44-55, tests/unit/test_auth.py:72-88
Key Components
| Component | Description |
|---|---|
FlextOracleOicAuthenticator | Main class responsible for OAuth2 token management and caching. |
OicAuthenticationConfig | Pydantic model defining required fields like oauth_client_id and oauth_token_url. |
FlextTapOracleOicSettings | Centralized settings management that provides token request data. |
get_access_token() | Core logic for obtaining and validating the bearer token. |
Sources: src/flext_tap_oracle_oic/tap.py:44-46, src/flext_tap_oracle_oic/_models/_auth_config.py:14-16, src/flext_tap_oracle_oic/settings.py:19-21
Token Retrieval Flow
The following diagram illustrates the flow validated during authentication testing, from configuration loading to token storage.
The authenticator builds the request body using client_credentials grant type and the specified audience. The testing suite ensures that even if the body is returned as a JSON string rather than a dictionary, the system correctly parses it. Sources: src/flext_tap_oracle_oic/tap.py:53-75, tests/unit/test_auth.py:129-145
Unit Test Scenarios
The test suite in test_auth.py utilizes a mock_config fixture to simulate OIC settings without requiring a live environment. This allow for isolated testing of logic branches. Sources: tests/unit/test_auth.py:28-48
Success and Failure Modes
Tests verify the following behaviors of the FlextOracleOicAuthenticator:
- Success Path: Verifies that a
200 OKstatus with a validaccess_tokenin the body results in a successfulResultobject and populates the internal cache. Sources: tests/unit/test_auth.py:72-88 - HTTP Failures: Simulates connection refusals and ensures the authenticator returns a failure result with appropriate error messaging. Sources: tests/unit/test_auth.py:90-100
- Status Code Validation: Checks that status codes above the error threshold (e.g., 401 Unauthorized) are caught and reported as failures. Sources: tests/unit/test_auth.py:102-115
- Payload Validation: Ensures that empty bodies or responses missing the
access_tokenfield trigger failure states. Sources: tests/unit/test_auth.py:117-145
Configuration Constraints
The OicAuthenticationConfig model enforces specific validation rules that are exercised during initialization testing. Sources: src/flext_tap_oracle_oic/_models/_auth_config.py:105-115
| Rule | Constraint | Source |
|---|---|---|
| HTTPS Enforcement | Both oauth_token_url and base_url must start with https://. | src/flext_tap_oracle_oic/_models/_auth_config.py:107-111 |
| Token Expiry Buffer | token_expiry_buffer must be at least 60 seconds. | src/flext_tap_oracle_oic/_models/_auth_config.py:112-114 |
| Required Fields | oauth_client_id, oauth_client_secret, and oauth_token_url are mandatory. | src/flext_tap_oracle_oic/tap.py:168-173 |
Interaction Sequence
The authentication test demonstrates how the Authenticator interacts with the FlextApi client to perform the OAuth2 handshake.
Implementation Details
Testing also covers the FlextTapOracleOicSettings.get_token_request_data() method, which prepares the credentials for the HTTP request. This method retrieves the secret value from Pydantic SecretStr types to ensure sensitive data is handled correctly during the request phase. Sources: src/flext_tap_oracle_oic/settings.py:59-66, tests/unit/test_auth.py:159-165
def get_token_request_data(self) -> t.StrMapping:
"""Return OAuth2 client credentials payload."""
return {
"grant_type": "client_credentials",
"client_id": self.oauth_client_id,
"client_secret": self.oauth_client_secret.get_secret_value(),
"audience": self.oauth_audience,
}
Sources: src/flext_tap_oracle_oic/settings.py:59-66
Summary
Authentication Testing verifies that the flext-tap-oracle-oic can securely and reliably obtain access tokens. By strictly validating configuration (enforcing HTTPS and required fields) and testing the lifecycle of a token request (including numerous error conditions and body parsing edge cases), the project maintains a secure connection to Oracle Integration Cloud. The use of result-oriented programming (p.Result) ensures that authentication failures are surfaced clearly to the tap's execution engine. Sources: src/flext_tap_oracle_oic/tap.py:270-285, tests/unit/test_auth.py:147-157