Skip to content

Commit

Permalink
Merge pull request #3888 from nscuro/relax-tag-lowercase-validation
Browse files Browse the repository at this point in the history
Relax lowercase requirement for `/api/v1/tag/{name}/project` and `/api/v1/tag/{name}/policy`
  • Loading branch information
nscuro authored Jun 26, 2024
2 parents 7ef0470 + 5fbf0d9 commit 6def612
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 110 deletions.
44 changes: 0 additions & 44 deletions src/main/java/org/dependencytrack/model/validation/LowerCase.java

This file was deleted.

This file was deleted.

17 changes: 12 additions & 5 deletions src/main/java/org/dependencytrack/resources/v1/TagResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirements;
import org.dependencytrack.auth.Permissions;
import org.dependencytrack.model.Tag;
import org.dependencytrack.model.validation.LowerCase;
import org.dependencytrack.model.validation.ValidUuid;
import org.dependencytrack.persistence.QueryManager;
import org.dependencytrack.persistence.TagQueryManager.TagListRow;
Expand Down Expand Up @@ -108,9 +107,13 @@ public Response getAllTags() {
@PaginatedApi
@PermissionRequired(Permissions.Constants.VIEW_PORTFOLIO)
public Response getTaggedProjects(
@Parameter(description = "Name of the tag to get projects for. Must be lowercase.", required = true)
@PathParam("name") @LowerCase final String tagName
@Parameter(description = "Name of the tag to get projects for", required = true)
@PathParam("name") final String tagName
) {
// TODO: Should enforce lowercase for tagName once we are sure that
// users don't have any mixed-case tags in their system anymore.
// Will likely need a migration to cleanup existing tags for this.

final List<TaggedProjectRow> taggedProjectListRows;
try (final var qm = new QueryManager(getAlpineRequest())) {
taggedProjectListRows = qm.getTaggedProjects(tagName);
Expand Down Expand Up @@ -141,9 +144,13 @@ public Response getTaggedProjects(
@PaginatedApi
@PermissionRequired(Permissions.Constants.VIEW_PORTFOLIO)
public Response getTaggedPolicies(
@Parameter(description = "Name of the tag to get policies for. Must be lowercase.", required = true)
@PathParam("name") @LowerCase final String tagName
@Parameter(description = "Name of the tag to get policies for", required = true)
@PathParam("name") final String tagName
) {
// TODO: Should enforce lowercase for tagName once we are sure that
// users don't have any mixed-case tags in their system anymore.
// Will likely need a migration to cleanup existing tags for this.

final List<TaggedPolicyRow> taggedPolicyListRows;
try (final var qm = new QueryManager(getAlpineRequest())) {
taggedPolicyListRows = qm.getTaggedPolicies(tagName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,17 +346,9 @@ public void getTaggedProjectsWithNonLowerCaseTagNameTest() {
.request()
.header(X_API_KEY, apiKey)
.get();
assertThat(response.getStatus()).isEqualTo(400);
assertThatJson(getPlainTextBody(response)).isEqualTo("""
[
{
"message": "Value must only contain lowercase letters.",
"messageTemplate": "Value must only contain lowercase letters.",
"path": "getTaggedProjects.arg0",
"invalidValue": "Foo"
}
]
""");
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getHeaderString(TOTAL_COUNT_HEADER)).isEqualTo("0");
assertThat(getPlainTextBody(response)).isEqualTo("[]");
}

@Test
Expand Down Expand Up @@ -473,17 +465,9 @@ public void getTaggedPoliciesWithNonLowerCaseTagNameTest() {
.request()
.header(X_API_KEY, apiKey)
.get();
assertThat(response.getStatus()).isEqualTo(400);
assertThatJson(getPlainTextBody(response)).isEqualTo("""
[
{
"message": "Value must only contain lowercase letters.",
"messageTemplate": "Value must only contain lowercase letters.",
"path": "getTaggedPolicies.arg0",
"invalidValue": "Foo"
}
]
""");
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getHeaderString(TOTAL_COUNT_HEADER)).isEqualTo("0");
assertThat(getPlainTextBody(response)).isEqualTo("[]");
}

@Test
Expand Down

0 comments on commit 6def612

Please sign in to comment.