Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling and validation for Maven resources #184

Merged
merged 1 commit into from
Mar 31, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Response provide(ArtifactCoords artifact, UriInfo uriInfo) throws Excepti
platformCatalog = registryClient.resolveCurrentPlatformsCatalog(quarkusVersion);
}
if (platformCatalog == null || platformCatalog.getPlatforms().isEmpty()) {
return Response.status(Response.Status.NO_CONTENT)
return Response.status(Response.Status.NOT_FOUND)
.header("X-Reason", "No platforms found")
.build();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/quarkus/registry/app/util/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Version {
*/
public static void validateVersion(String version) {
DefaultArtifactVersion dav = new DefaultArtifactVersion(version);
if (dav.getMajorVersion() == 0) {
if (dav.getMajorVersion() == 0 && dav.getMinorVersion() == 0 && dav.getIncrementalVersion() == 0) {
throw new IllegalArgumentException("Invalid Version: " + version);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,6 @@ void should_return_only_matching_platforms() {
"platforms.streams[0].releases[0].quarkus-core-version[0]", is("2.1.0.CR1"));
}

@Test
void should_return_204_on_inexistent_platforms() {
given()
.get("/maven/io/quarkus/registry/quarkus-platforms/1.0-SNAPSHOT/quarkus-platforms-1.0-SNAPSHOT-10.1.0.CR1.json")
.then()
.statusCode(204)
.header("X-Reason", "No platforms found");
}

@Test
void non_platform_descriptor_should_contain_quarkus_core() {
given()
Expand All @@ -152,10 +143,34 @@ void non_platform_descriptor_should_contain_quarkus_core() {
}

@Test
void should_return_bad_request_if_version_is_invalid() {
void should_return_not_found_if_version_is_invalid() {
given()
.get("/maven/io/quarkus/registry/quarkus-platforms/1.0-SNAPSHOT/quarkus-platforms-1.0-SNAPSHOT-0.23.2.json")
.then()
.statusCode(HttpURLConnection.HTTP_BAD_REQUEST);
.statusCode(HttpURLConnection.HTTP_NOT_FOUND);
}

@Test
void should_return_not_found_if_snapshot_version_is_invalid() {
given()
.get("/maven/io/quarkus/registry/quarkus-platforms/1.0-SNAPSHOT/quarkus-platforms-1.0-SNAPSHOT-999-SNAPSHOT.json")
.then()
.statusCode(HttpURLConnection.HTTP_NOT_FOUND);
}

@Test
void should_return_not_found_to_sha1_if_version_is_invalid() {
given()
.get("/maven/io/quarkus/registry/quarkus-platforms/1.0-SNAPSHOT/quarkus-platforms-1.0-SNAPSHOT-0.23.2.json.sha1")
.then()
.statusCode(HttpURLConnection.HTTP_NOT_FOUND);
}

@Test
void should_return_not_found_to_sha1_if_snapshot_version_is_invalid() {
given()
.get("/maven/io/quarkus/registry/quarkus-platforms/1.0-SNAPSHOT/quarkus-platforms-1.0-SNAPSHOT-999-SNAPSHOT.sha1")
.then()
.statusCode(HttpURLConnection.HTTP_NOT_FOUND);
}
}
}