Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gbfs-validator-java-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<junit.version>6.0.0</junit.version>
<mockito.version>5.11.0</mockito.version>
<junit-platform.version>6.0.0</junit-platform.version>
<openapi-generator-maven-plugin>6.0.0</openapi-generator-maven-plugin>
<openapi-generator-maven-plugin>7.16.0</openapi-generator-maven-plugin>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@
import org.entur.gbfs.validation.model.ValidationResult;
import org.entur.gbfs.validation.model.ValidatorError;
import org.entur.gbfs.validator.api.gen.ValidateApiDelegate;
import org.entur.gbfs.validator.api.model.BasicAuth;
import org.entur.gbfs.validator.api.model.BearerTokenAuth;
import org.entur.gbfs.validator.api.model.FileError;
import org.entur.gbfs.validator.api.model.GbfsFile;
import org.entur.gbfs.validator.api.model.OAuthClientCredentialsGrantAuth;
import org.entur.gbfs.validator.api.model.SystemError;
import org.entur.gbfs.validator.api.model.ValidatePostRequest;
import org.entur.gbfs.validator.api.model.ValidatePostRequestAuth;
Expand Down Expand Up @@ -113,40 +110,7 @@ public ResponseEntity<org.entur.gbfs.validator.api.model.ValidationResult> valid
validatePostRequest.getFeedUrl()
);
try {
Authentication loaderAuth = null;
ValidatePostRequestAuth apiAuth = validatePostRequest.getAuth();

if (apiAuth != null) {
if (apiAuth instanceof BasicAuth basic) {
if (basic.getUsername() != null && basic.getPassword() != null) {
loaderAuth =
new org.entur.gbfs.validator.loader.auth.BasicAuth(
basic.getUsername(),
basic.getPassword()
);
}
} else if (apiAuth instanceof BearerTokenAuth bearer) {
if (bearer.getToken() != null) {
loaderAuth =
new org.entur.gbfs.validator.loader.auth.BearerTokenAuth(
bearer.getToken()
);
}
} else if (apiAuth instanceof OAuthClientCredentialsGrantAuth oauth) {
if (
oauth.getClientId() != null &&
oauth.getClientSecret() != null &&
oauth.getTokenUrl() != null
) {
loaderAuth =
new org.entur.gbfs.validator.loader.auth.OAuthClientCredentialsGrantAuth(
oauth.getClientId(),
oauth.getClientSecret(),
oauth.getTokenUrl().toString()
);
}
}
}
Authentication loaderAuth = getAuthentication(validatePostRequest);

List<LoadedFile> allLoadedFiles = loader.load(
validatePostRequest.getFeedUrl(),
Expand Down Expand Up @@ -210,6 +174,47 @@ public ResponseEntity<org.entur.gbfs.validator.api.model.ValidationResult> valid
}
}

private static Authentication getAuthentication(
ValidatePostRequest validatePostRequest
) {
Authentication loaderAuth = null;
ValidatePostRequestAuth apiAuth = validatePostRequest.getAuth();

if (apiAuth != null) {
String authType = apiAuth.getAuthType();
if ("basicAuth".equals(authType)) {
if (apiAuth.getUsername() != null && apiAuth.getPassword() != null) {
loaderAuth =
new org.entur.gbfs.validator.loader.auth.BasicAuth(
apiAuth.getUsername(),
apiAuth.getPassword()
);
}
} else if ("bearerToken".equals(authType)) {
if (apiAuth.getToken() != null) {
loaderAuth =
new org.entur.gbfs.validator.loader.auth.BearerTokenAuth(
apiAuth.getToken()
);
}
} else if ("oauthClientCredentialsGrant".equals(authType)) {
if (
apiAuth.getClientId() != null &&
apiAuth.getClientSecret() != null &&
apiAuth.getTokenUrl() != null
) {
loaderAuth =
new org.entur.gbfs.validator.loader.auth.OAuthClientCredentialsGrantAuth(
apiAuth.getClientId(),
apiAuth.getClientSecret(),
apiAuth.getTokenUrl()
);
}
}
}
return loaderAuth;
}

private org.entur.gbfs.validator.api.model.ValidationResult mergeValidationResults(
List<org.entur.gbfs.validator.api.model.ValidationResult> results
) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.entur.gbfs.validator.api.handler.OpenApiGeneratorApplication;
import org.entur.gbfs.validator.api.model.*;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -13,7 +14,7 @@
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;

@SpringBootTest(classes = TestApplication.class)
@SpringBootTest(classes = OpenApiGeneratorApplication.class)
@AutoConfigureMockMvc
public class ValidateIntegrationTest {

Expand Down Expand Up @@ -46,8 +47,8 @@ void testValidate_BasicAuth_Success() throws Exception {
ValidatePostRequest request = new ValidatePostRequest();
request.setFeedUrl("http://example.com/gbfs.json");

BasicAuth basicAuth = new BasicAuth();
basicAuth.setAuthType("basic");
ValidatePostRequestAuth basicAuth = new ValidatePostRequestAuth();
basicAuth.setAuthType("basicAuth");
basicAuth.setUsername("user");
basicAuth.setPassword("pass");
request.setAuth(basicAuth);
Expand All @@ -69,8 +70,8 @@ void testValidate_BearerTokenAuth_Success() throws Exception {
ValidatePostRequest request = new ValidatePostRequest();
request.setFeedUrl("http://example.com/gbfs.json");

BearerTokenAuth bearerAuth = new BearerTokenAuth();
bearerAuth.setAuthType("bearer");
ValidatePostRequestAuth bearerAuth = new ValidatePostRequestAuth();
bearerAuth.setAuthType("bearerToken");
bearerAuth.setToken("token123");
request.setAuth(bearerAuth);

Expand All @@ -91,9 +92,8 @@ void testValidate_OAuthClientCredentials_Success() throws Exception {
ValidatePostRequest request = new ValidatePostRequest();
request.setFeedUrl("http://example.com/gbfs.json");

OAuthClientCredentialsGrantAuth oauthAuth =
new OAuthClientCredentialsGrantAuth();
oauthAuth.setAuthType("oauth");
ValidatePostRequestAuth oauthAuth = new ValidatePostRequestAuth();
oauthAuth.setAuthType("oauthClientCredentialsGrant");
oauthAuth.setTokenUrl("https://auth.example.com/token");
oauthAuth.setClientId("client_id");
oauthAuth.setClientSecret("client_secret");
Expand All @@ -116,8 +116,8 @@ void testValidate_AuthFailure() throws Exception {
ValidatePostRequest request = new ValidatePostRequest();
request.setFeedUrl("http://example.com/gbfs.json");

BasicAuth basicAuth = new BasicAuth();
basicAuth.setAuthType("basic");
ValidatePostRequestAuth basicAuth = new ValidatePostRequestAuth();
basicAuth.setAuthType("basicAuth");
basicAuth.setUsername("wrong_user");
basicAuth.setPassword("wrong_password");
request.setAuth(basicAuth);
Expand Down