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

Fix Owner Validation #3593

Merged
merged 1 commit into from
Aug 29, 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 @@ -258,6 +258,11 @@ public ArtifactOwner getArtifactOwner(String groupId, String artifactId) {
public void updateArtifactOwner(String groupId, String artifactId, ArtifactOwner data) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("data", data);

if (data.getOwner().isEmpty()) {
throw new MissingRequiredParameterException("Missing required owner");
}

ArtifactOwnerDto dto = new ArtifactOwnerDto(data.getOwner());
storage.updateArtifactOwner(defaultGroupIdToNull(groupId), artifactId, dto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

import io.apicurio.registry.AbstractResourceTestBase;
import io.apicurio.registry.rest.client.exception.RuleViolationException;
import io.apicurio.registry.rest.v2.beans.ArtifactOwner;
import io.apicurio.registry.rest.v2.beans.ArtifactMetaData;
import io.apicurio.registry.rest.v2.beans.ArtifactReference;
import io.apicurio.registry.rest.v2.beans.Comment;
Expand Down Expand Up @@ -178,6 +179,41 @@ public void testDefaultGroup() throws Exception {
.body("info.title", equalTo("Empty API"));
}

@Test
public void testUpdateArtifactOwner() throws Exception {
String oaiArtifactContent = resourceToString("openapi-empty.json");
createArtifact("testUpdateArtifactOwner", "testUpdateArtifactOwner/EmptyAPI/1",ArtifactType.OPENAPI, oaiArtifactContent);

ArtifactOwner artifactOwner = new ArtifactOwner("newOwner");

given()
.when()
.contentType(CT_JSON)
.pathParam("groupId", "testUpdateArtifactOwner")
.pathParam("artifactId", "testUpdateArtifactOwner/EmptyAPI/1")
.body(artifactOwner)
.put("/registry/v2/groups/{groupId}/artifacts/{artifactId}/owner")
.then()
.statusCode(204);
}

@Test
public void testUpdateEmptyArtifactOwner() throws Exception {
String oaiArtifactContent = resourceToString("openapi-empty.json");
createArtifact("testUpdateEmptyArtifactOwner", "testUpdateEmptyArtifactOwner/EmptyAPI/1",ArtifactType.OPENAPI, oaiArtifactContent);

ArtifactOwner artifactOwner = new ArtifactOwner("");

given()
.when()
.contentType(CT_JSON)
.pathParam("groupId", "testUpdateEmptyArtifactOwner")
.pathParam("artifactId", "testUpdateEmptyArtifactOwner/EmptyAPI/1")
.body(artifactOwner)
.put("/registry/v2/groups/{groupId}/artifacts/{artifactId}/owner")
.then()
.statusCode(400);
}

@Test
public void testMultipleGroups() throws Exception {
Expand Down