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

Relax lowercase requirement for /api/v1/tag/{name}/project and /api/v1/tag/{name}/policy #3888

Merged
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
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