Repository: CycloneDX/cyclonedx-core-java
Pull request #493 (2024-09-02 01:33:58)

Fix Issue 462
Fixes https://github.com/CycloneDX/cyclonedx-core-java/issues/462 


Patch:
diff --git a/src/main/java/org/cyclonedx/model/Service.java b/src/main/java/org/cyclonedx/model/Service.java
index d52bc0043..69f1fe8c7 100644
--- a/src/main/java/org/cyclonedx/model/Service.java
+++ b/src/main/java/org/cyclonedx/model/Service.java
@@ -50,6 +50,7 @@ import java.util.Objects;
         "endpoints",
         "authenticated",
         "xTrustBoundary",
+        "trustZone",
         "data",
         "licenses",
         "externalReferences",
@@ -74,6 +75,8 @@ public class Service extends ExtensibleElement {
     @JacksonXmlProperty(localName = "x-trust-boundary")
     @JsonProperty("x-trust-boundary")
     private Boolean xTrustBoundary;
+    @VersionFilter(Version.VERSION_15)
+    private String trustZone;
     private List<ServiceData> data;
     private LicenseChoice licenses;
     private List<ExternalReference> externalReferences;
@@ -269,6 +272,14 @@ public class Service extends ExtensibleElement {
         this.tags = tags;
     }
 
+    public String getTrustZone() {
+        return trustZone;
+    }
+
+    public void setTrustZone(final String trustZone) {
+        this.trustZone = trustZone;
+    }
+
     @Override
     public boolean equals(final Object object) {
         if (this == object) {
@@ -290,13 +301,13 @@ public class Service extends ExtensibleElement {
             Objects.equals(properties, service.properties) && Objects.equals(tags, service.tags) &&
             Objects.equals(services, service.services) &&
             Objects.equals(releaseNotes, service.releaseNotes) &&
+            Objects.equals(trustZone, service.trustZone) &&
             Objects.equals(signature, service.signature);
     }
 
     @Override
     public int hashCode() {
-        return Objects.hash(bomRef, provider, group, name, version, description, endpoints, authenticated,
-            xTrustBoundary,
-            data, licenses, externalReferences, properties, tags, services, releaseNotes, signature);
+        return Objects.hash(bomRef, provider, group, name, version, description, endpoints, authenticated, signature,
+            xTrustBoundary, trustZone, data, licenses, externalReferences, properties, tags, services, releaseNotes);
     }
 }


Test patch:
diff --git a/src/test/java/org/cyclonedx/parsers/AbstractParserTest.java b/src/test/java/org/cyclonedx/parsers/AbstractParserTest.java
index 7cd651877..bba38d28e 100644
--- a/src/test/java/org/cyclonedx/parsers/AbstractParserTest.java
+++ b/src/test/java/org/cyclonedx/parsers/AbstractParserTest.java
@@ -583,7 +583,7 @@ public class AbstractParserTest
     assertEquals(Status.AFFECTED, vuln.getAffects().get(0).getVersions().get(1).getStatus());
   }
 
-  void assertServices(final Bom bom) {
+  void assertServices(final Bom bom, final Version version) {
     //Services
     List<Service> services = bom.getServices();
     assertEquals(1, services.size());
@@ -595,6 +595,13 @@ public class AbstractParserTest
     assertEquals(1, urls.size());
     assertEquals("https://partner.org", urls.get(0));
 
+    if (Version.VERSION_15.getVersion() <= version.getVersion()) {
+      assertEquals("value", s.getTrustZone());
+    }
+    else {
+      assertNull(s.getTrustZone());
+    }
+
     List<OrganizationalContact> contacts = provider.getContacts();
     assertEquals(1, contacts.size());
     OrganizationalContact contact = contacts.get(0);
diff --git a/src/test/java/org/cyclonedx/parsers/JsonParserTest.java b/src/test/java/org/cyclonedx/parsers/JsonParserTest.java
index cab699622..b10d06f87 100644
--- a/src/test/java/org/cyclonedx/parsers/JsonParserTest.java
+++ b/src/test/java/org/cyclonedx/parsers/JsonParserTest.java
@@ -107,7 +107,7 @@ public class JsonParserTest
         assertEquals("(CDDL-1.0 OR GPL-2.0-with-classpath-exception)",
             c3.getLicenseChoice().getExpression().getValue());
 
-        assertServices(bom);
+        assertServices(bom, Version.VERSION_12);
 
         // Assertions for bom.dependencies
         assertEquals(2, bom.getDependencies().size());
@@ -126,7 +126,7 @@ public class JsonParserTest
 
         assertMetadata(bom, Version.VERSION_13);
 
-        assertServices(bom);
+        assertServices(bom, Version.VERSION_13);
 
         final List<Component> components = bom.getComponents();
         assertEquals(3, components.size());
@@ -171,7 +171,7 @@ public class JsonParserTest
 
         assertMetadata(bom.getMetadata(), Version.VERSION_14);
         assertComponent(bom, Version.VERSION_14);
-        assertServices(bom);
+        assertServices(bom, Version.VERSION_14);
         assertCompositions(bom, Version.VERSION_14);
         assertVulnerabilities(bom, Version.VERSION_14);
 
@@ -199,7 +199,7 @@ public class JsonParserTest
 
         assertMetadata(bom.getMetadata(), Version.VERSION_15);
         assertComponent(bom, Version.VERSION_15);
-        assertServices(bom);
+        assertServices(bom, Version.VERSION_15);
         assertCompositions(bom, Version.VERSION_15);
         assertVulnerabilities(bom, Version.VERSION_15);
 
diff --git a/src/test/java/org/cyclonedx/parsers/XmlParserTest.java b/src/test/java/org/cyclonedx/parsers/XmlParserTest.java
index 471bb317a..0e7bf8ecb 100644
--- a/src/test/java/org/cyclonedx/parsers/XmlParserTest.java
+++ b/src/test/java/org/cyclonedx/parsers/XmlParserTest.java
@@ -289,7 +289,7 @@ public class XmlParserTest
         // Assertions for bom.components
         assertComponent(components.get(0), Component.Type.APPLICATION, "pkg:maven/com.acme/tomcat-catalina@9.0.14?packaging=jar");
 
-        assertServices(bom);
+        assertServices(bom, Version.VERSION_12);
 
         // Assertions for bom.dependencies
         assertEquals(1, bom.getDependencies().size());
@@ -313,7 +313,7 @@ public class XmlParserTest
 
         assertComponent(components.get(0), Component.Type.APPLICATION, "pkg:maven/com.acme/tomcat-catalina@9.0.14?packaging=jar");
 
-        assertServices(bom);
+        assertServices(bom, Version.VERSION_13);
 
         // Assertions for bom.dependencies
         assertEquals(1, bom.getDependencies().size());
@@ -334,7 +334,7 @@ public class XmlParserTest
 
         assertMetadata(bom.getMetadata(), Version.VERSION_14);
         assertComponent(bom, Version.VERSION_14);
-        assertServices(bom);
+        assertServices(bom, Version.VERSION_14);
         assertCompositions(bom, Version.VERSION_14);
         assertVulnerabilities(bom, Version.VERSION_14);
 
@@ -361,7 +361,7 @@ public class XmlParserTest
 
         assertMetadata(bom.getMetadata(), Version.VERSION_15);
         assertComponent(bom, Version.VERSION_15);
-        assertServices(bom);
+        assertServices(bom, Version.VERSION_15);
         assertCompositions(bom, Version.VERSION_15);
         assertVulnerabilities(bom, Version.VERSION_15);
 
diff --git a/src/test/resources/bom-1.5.json b/src/test/resources/bom-1.5.json
index f91b59113..c8166df6b 100644
--- a/src/test/resources/bom-1.5.json
+++ b/src/test/resources/bom-1.5.json
@@ -403,6 +403,7 @@
       ],
       "authenticated": true,
       "x-trust-boundary": true,
+      "trustZone": "value",
       "data": [
         {
           "flow": "inbound",
diff --git a/src/test/resources/bom-1.5.xml b/src/test/resources/bom-1.5.xml
index c0c9f517e..6dcf2e2c3 100644
--- a/src/test/resources/bom-1.5.xml
+++ b/src/test/resources/bom-1.5.xml
@@ -311,6 +311,7 @@
             </endpoints>
             <authenticated>true</authenticated>
             <x-trust-boundary>true</x-trust-boundary>
+            <trustZone>value</trustZone>
             <data>
                 <classification flow="inbound">PII</classification>
                 <classification flow="outbound">PIFI</classification>