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

Issue-3769 : fix update component external references #3805

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 @@ -418,6 +418,7 @@ public Component updateComponent(Component transientComponent, boolean commitInd
component.setInternal(transientComponent.isInternal());
component.setAuthor(transientComponent.getAuthor());
component.setSupplier(transientComponent.getSupplier());
component.setExternalReferences(transientComponent.getExternalReferences());
final Component result = persist(component);
Event.dispatch(new IndexEvent(IndexEvent.Action.UPDATE, result));
commitSearchIndex(commitIndex, Component.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ public Response updateComponent(Component jsonComponent) {
component.setSha3_256(StringUtils.trimToNull(jsonComponent.getSha3_256()));
component.setSha3_384(StringUtils.trimToNull(jsonComponent.getSha3_384()));
component.setSha3_512(StringUtils.trimToNull(jsonComponent.getSha3_512()));
component.setExternalReferences(jsonComponent.getExternalReferences());

final License resolvedLicense = qm.getLicense(jsonComponent.getLicense());
if (resolvedLicense != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.dependencytrack.ResourceTest;
import org.dependencytrack.model.Component;
import org.dependencytrack.model.ConfigPropertyConstants;
import org.dependencytrack.model.ExternalReference;
import org.dependencytrack.model.Project;
import org.dependencytrack.model.RepositoryMetaComponent;
import org.dependencytrack.model.RepositoryType;
Expand Down Expand Up @@ -557,17 +558,29 @@ public void updateComponentTest() {
component.setProject(project);
component.setName("My Component");
component.setVersion("1.0");
component = qm.createComponent(component, false);
component.setDescription("Test component");
qm.createComponent(component, false);

var jsonComponent = new Component();
jsonComponent.setUuid(component.getUuid());
jsonComponent.setPurl("pkg:maven/org.acme/abc");
jsonComponent.setName("My Component");
jsonComponent.setVersion("1.0");
jsonComponent.setDescription("Test component");
var externalReference = new ExternalReference();
externalReference.setType(org.cyclonedx.model.ExternalReference.Type.WEBSITE);
externalReference.setUrl("test.com");
jsonComponent.setExternalReferences(List.of(externalReference));

Response response = jersey.target(V1_COMPONENT).request()
.header(X_API_KEY, apiKey)
.post(Entity.entity(component, MediaType.APPLICATION_JSON));
.post(Entity.entity(jsonComponent, MediaType.APPLICATION_JSON));
Assert.assertEquals(200, response.getStatus(), 0);
JsonObject json = parseJsonObject(response);
Assert.assertNotNull(json);
Assert.assertEquals("My Component", json.getString("name"));
Assert.assertEquals("1.0", json.getString("version"));
Assert.assertEquals("Test component", json.getString("description"));
Assert.assertEquals(1, json.getJsonArray("externalReferences").size());
}

@Test
Expand Down