@@ -141,16 +141,94 @@ describe("analyzeStatically", () => {
141141 } ,
142142 } ) ;
143143
144- // Should not crash
145- await expect (
146- analyzeStatically (
147- "test-image" ,
148- undefined ,
149- "docker-archive" ,
150- "test-path" ,
151- { include : [ ] , exclude : [ ] } ,
152- { } ,
153- ) ,
154- ) . resolves . toBeDefined ( ) ;
144+ await analyzeStatically (
145+ "test-image" ,
146+ undefined ,
147+ "docker-archive" ,
148+ "test-path" ,
149+ { include : [ ] , exclude : [ ] } ,
150+ { } ,
151+ ) ;
152+
153+ const buildResponseCall = (
154+ responseBuilder . buildResponse as jest . Mock
155+ ) . mock . calls [ 0 ] ;
156+ // Second argument is dockerfileAnalysis
157+ expect ( buildResponseCall [ 1 ] ) . toMatchObject ( { baseImage : "alpine:latest" } ) ;
158+ } ) ;
159+
160+ it ( "creates synthetic dockerfileAnalysis when dockerfileAnalysis is undefined and OCI labels present" , async ( ) => {
161+ ( analyzer . analyzeStatically as jest . Mock ) . mockResolvedValue ( {
162+ osRelease : { name : "test" , version : "1" } ,
163+ imageLabels : {
164+ "org.opencontainers.image.base.name" : "alpine:latest" ,
165+ } ,
166+ } ) ;
167+
168+ await analyzeStatically (
169+ "test-image" ,
170+ undefined ,
171+ "docker-archive" ,
172+ "test-path" ,
173+ { include : [ ] , exclude : [ ] } ,
174+ { } ,
175+ ) ;
176+
177+ const buildResponseCall = (
178+ responseBuilder . buildResponse as jest . Mock
179+ ) . mock . calls [ 0 ] ;
180+ expect ( buildResponseCall [ 1 ] ) . toEqual ( {
181+ baseImage : "alpine:latest" ,
182+ dockerfilePackages : { } ,
183+ dockerfileLayers : { } ,
184+ } ) ;
185+ } ) ;
186+
187+ it ( "passes excludeBaseImageVulns as false when dockerfileAnalysis is synthetic" , async ( ) => {
188+ ( analyzer . analyzeStatically as jest . Mock ) . mockResolvedValue ( {
189+ osRelease : { name : "test" , version : "1" } ,
190+ imageLabels : {
191+ "org.opencontainers.image.base.name" : "alpine:latest" ,
192+ } ,
193+ } ) ;
194+
195+ await analyzeStatically (
196+ "test-image" ,
197+ undefined ,
198+ "docker-archive" ,
199+ "test-path" ,
200+ { include : [ ] , exclude : [ ] } ,
201+ { "exclude-base-image-vulns" : "true" } ,
202+ ) ;
203+
204+ const buildResponseCall = (
205+ responseBuilder . buildResponse as jest . Mock
206+ ) . mock . calls [ 0 ] ;
207+ // Third argument is excludeBaseImageVulns
208+ expect ( buildResponseCall [ 2 ] ) . toBe ( false ) ;
209+ } ) ;
210+
211+ it ( "passes excludeBaseImageVulns as true when dockerfileAnalysis is real" , async ( ) => {
212+ ( analyzer . analyzeStatically as jest . Mock ) . mockResolvedValue ( {
213+ osRelease : { name : "test" , version : "1" } ,
214+ imageLabels : {
215+ "org.opencontainers.image.base.name" : "alpine:latest" ,
216+ } ,
217+ } ) ;
218+
219+ await analyzeStatically (
220+ "test-image" ,
221+ { dockerfilePackages : { } , dockerfileLayers : { } , baseImage : undefined } ,
222+ "docker-archive" ,
223+ "test-path" ,
224+ { include : [ ] , exclude : [ ] } ,
225+ { "exclude-base-image-vulns" : "true" } ,
226+ ) ;
227+
228+ const buildResponseCall = (
229+ responseBuilder . buildResponse as jest . Mock
230+ ) . mock . calls [ 0 ] ;
231+ // Third argument is excludeBaseImageVulns
232+ expect ( buildResponseCall [ 2 ] ) . toBe ( true ) ;
155233 } ) ;
156234} ) ;
0 commit comments