Skip to content
Open
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 @@ -112,6 +112,10 @@ private void createMetadataInfo(
}
}

if (metadata.getDistributionConstraints() != null && shouldSerializeField(metadata, version, "distributionConstraints")) {
jsonGenerator.writeObjectField("distributionConstraints", metadata.getDistributionConstraints());
}

jsonGenerator.writeEndObject();
}

Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/cyclonedx/BomJsonGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ public void schema12MultipleDependenciesJsonTest() throws Exception {
assertTrue(jsonParser.isValid(file, Version.VERSION_12));
}

@Test
public void schema17MetadataDistributionConstraintsJsonTest() throws Exception {
final byte[] bomBytes = Objects.requireNonNull(this.getClass().getResourceAsStream("/1.7/valid-metadata-distribution-1.7.json")).readAllBytes();
final Bom bom = new JsonParser().parse(bomBytes);

BomJsonGenerator generator = BomGeneratorFactory.createJson(Version.VERSION_17, bom);
JsonNode metadata = generator.toJsonNode().get("metadata");
assertEquals("RED", metadata.get("distributionConstraints").get("tlp").asText());

generator = BomGeneratorFactory.createJson(Version.VERSION_16, bom);
assertNull(generator.toJsonNode().get("metadata").get("distributionConstraints"));
}

@Test
public void schema13EmptyComponentsJsonTest() throws Exception {
final Bom bom = new Bom();
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/cyclonedx/BomXmlGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,16 @@ private File writeToFile(String xmlString) throws Exception {
return tempFile;
}

@Test
public void schema17MetadataDistributionConstraintsGenerationTest() throws Exception {
BomXmlGenerator generator = BomGeneratorFactory.createXml(Version.VERSION_17, createCommonBomXml("/1.7/valid-metadata-distribution-1.7.xml"));
String xml = generator.toXmlString();
assertTrue(xml.contains("<tlp>RED</tlp>"), xml);
File file = writeToFile(xml);
XmlParser parser = new XmlParser();
assertTrue(parser.isValid(file, Version.VERSION_17));
}

private Bom createCommonBomXml(String resource) throws Exception {
final byte[] bomBytes = Objects.requireNonNull(this.getClass().getResourceAsStream(resource)).readAllBytes();
XmlParser parser = new XmlParser();
Expand Down