Skip to content

Conversation

@testower
Copy link
Collaborator

@testower testower commented Jun 2, 2025

No description provided.

This change adds support for specifying authentication details when fetching GBFS files, as defined in the OpenAPI specification. The loader can now handle Basic Authentication, Bearer Token Authentication, and OAuth 2.0 Client Credentials Grant.

Key changes:

- Added authentication models (`BasicAuth`, `BearerTokenAuth`, `OAuthClientCredentialsGrantAuth`) to the `gbfs-validator-java-loader` module.
- Modified `Loader.java` to accept an `Authentication` object and include appropriate `Authorization` headers in HTTP requests. For OAuth2, it handles fetching the token from the specified token URL.
- Integrated these changes into the `gbfs-validator-java-api` module by updating `ValidateApiDelegateHandler.java` to map API authentication models to the loader's authentication models.
- Ensured backward compatibility by providing an overloaded `load` method in `Loader.java` that defaults to no authentication.

Testing:

- I added comprehensive unit tests for `Loader.java` in `gbfs-validator-java-loader` using WireMock. These tests cover successful authentication for all supported methods, as well as error scenarios like incorrect credentials and token fetch failures.
- I added integration tests in `gbfs-validator-java-api` using `MockMvc` and WireMock. These tests verify the end-to-end authentication flow, from the API request to the `Loader` making authenticated HTTP calls. They ensure that the `/validate` endpoint correctly processes authentication details and that the system behaves as expected under various authentication scenarios.

The tests verify that:
- Files are fetched successfully with valid authentication credentials for each supported method.
- Appropriate `Authorization` headers are added to requests.
- OAuth2 token acquisition works correctly.
- System errors are reported for authentication failures (e.g., HTTP 401 errors due to bad credentials or token issues) rather than causing the validation process to crash.
@testower testower merged commit cec34fb into MobilityData:feature/api-module Jun 2, 2025
@testower testower deleted the feat/gbfs-auth branch June 2, 2025 20:28
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.

1 participant