From 7d19d91fb068e189d451ddb61b1c255ee97626b3 Mon Sep 17 00:00:00 2001 From: Tomasz Janiszewski Date: Thu, 16 Mar 2023 17:46:19 +0100 Subject: [PATCH] Update schema to include names in image added in 3.74 (#231) --- stackrox-container-image-scanner/api.yaml | 4 ++++ .../jenkins/plugins/services/ImageServiceTest.java | 9 ++++++--- .../__files/v1/images/scan/minimal-with-names.json | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 stackrox-container-image-scanner/src/test/resources/__files/v1/images/scan/minimal-with-names.json diff --git a/stackrox-container-image-scanner/api.yaml b/stackrox-container-image-scanner/api.yaml index 9f70f584..08945a77 100644 --- a/stackrox-container-image-scanner/api.yaml +++ b/stackrox-container-image-scanner/api.yaml @@ -11665,6 +11665,10 @@ components: type: string name: $ref: '#/components/schemas/storageImageName' + names: + type: array + items: + $ref: '#/components/schemas/storageImageName' metadata: $ref: '#/components/schemas/storageImageMetadata' scan: diff --git a/stackrox-container-image-scanner/src/test/java/com/stackrox/jenkins/plugins/services/ImageServiceTest.java b/stackrox-container-image-scanner/src/test/java/com/stackrox/jenkins/plugins/services/ImageServiceTest.java index 021291f6..bfd4cbe2 100644 --- a/stackrox-container-image-scanner/src/test/java/com/stackrox/jenkins/plugins/services/ImageServiceTest.java +++ b/stackrox-container-image-scanner/src/test/java/com/stackrox/jenkins/plugins/services/ImageServiceTest.java @@ -24,6 +24,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; class ImageServiceTest extends AbstractServiceTest { @@ -60,10 +62,11 @@ public void shouldThrowWhenNoDataFor200() throws IOException { assertEquals("Did not get scan results from StackRox", exception.getMessage()); } - @Test - public void shouldNotFailOnMissingData() throws IOException { + @ParameterizedTest + @ValueSource(strings = {"minimal.json", "minimal-with-names.json"}) + public void shouldNotFailOnMissingData(String file) throws IOException { MOCK_SERVER.stubFor(postImagesScan().willReturn( - ok().withBodyFile("v1/images/scan/minimal.json"))); + ok().withBodyFile("v1/images/scan/" + file))); List actual = imageService.getImageScanResults("nginx:latest"); ImmutableList expected = ImmutableList.of( new CVE(null, null, new StorageEmbeddedVulnerability() diff --git a/stackrox-container-image-scanner/src/test/resources/__files/v1/images/scan/minimal-with-names.json b/stackrox-container-image-scanner/src/test/resources/__files/v1/images/scan/minimal-with-names.json new file mode 100644 index 00000000..c3153433 --- /dev/null +++ b/stackrox-container-image-scanner/src/test/resources/__files/v1/images/scan/minimal-with-names.json @@ -0,0 +1,14 @@ +{ + "names": [{}], + "scan": { + "components": [ + { + "vulns": [ + { + "cve": "CVE-MISSING-DATA" + } + ] + } + ] + } +}