1+ import * as crypto from "crypto" ;
12import * as fs from "fs" ;
3+ import * as os from "os" ;
24import * as path from "path" ;
3- import * as tmp from "tmp" ;
4- import { v4 as uuidv4 } from "uuid" ;
55
66import { DockerPullResult } from "@snyk/snyk-docker-pull" ;
77import * as plugin from "../../lib" ;
@@ -114,7 +114,7 @@ describe("getImageArchive", () => {
114114 } ) ;
115115
116116 it ( "should produce the expected state" , async ( ) => {
117- const imageSavePath = path . join ( customPath , uuidv4 ( ) ) ;
117+ const imageSavePath = path . join ( customPath , crypto . randomUUID ( ) ) ;
118118 const dockerPullSpy = jest . spyOn ( Docker . prototype , "pull" ) ;
119119 const loadImage = path . join (
120120 __dirname ,
@@ -152,8 +152,8 @@ describe("getImageArchive", () => {
152152
153153 describe ( "from remote registry with binary" , ( ) => {
154154 it ( "should produce the expected state" , async ( ) => {
155- const customPath = tmp . dirSync ( ) . name ;
156- const imageSavePath = path . join ( customPath , uuidv4 ( ) ) ;
155+ const customPath = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "snyk-" ) ) ;
156+ const imageSavePath = path . join ( customPath , crypto . randomUUID ( ) ) ;
157157 const registryPullSpy = jest . spyOn ( Docker . prototype , "pull" ) ;
158158
159159 const archiveLocation : ArchiveResult =
@@ -180,11 +180,12 @@ describe("getImageArchive", () => {
180180 expect ( customPathExistsOnDisk ) . toBe ( true ) ;
181181
182182 await subProcess . execute ( "docker" , [ "image" , "rm" , targetImage ] ) ;
183+ fs . rmSync ( customPath , { recursive : true , force : true } ) ;
183184 } ) ;
184185
185186 it ( "should fail correctly when manifest is not found for given tag" , async ( ) => {
186- const customPath = tmp . dirSync ( ) . name ;
187- const imageSavePath = path . join ( customPath , uuidv4 ( ) ) ;
187+ const customPath = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "snyk-" ) ) ;
188+ const imageSavePath = path . join ( customPath , crypto . randomUUID ( ) ) ;
188189 const dockerPullCliSpy = jest
189190 . spyOn ( Docker . prototype , "pullCli" )
190191 . mockImplementation ( ( ) => {
@@ -209,6 +210,8 @@ describe("getImageArchive", () => {
209210
210211 expect ( dockerPullCliSpy ) . toHaveBeenCalled ( ) ;
211212 expect ( dockerPullSpy ) . not . toHaveBeenCalled ( ) ;
213+
214+ fs . rmSync ( customPath , { recursive : true , force : true } ) ;
212215 } ) ;
213216 } ) ;
214217
@@ -220,7 +223,7 @@ describe("getImageArchive", () => {
220223 } ) ;
221224
222225 it ( "should produce the expected state" , async ( ) => {
223- const imageSavePath = path . join ( customPath , uuidv4 ( ) ) ;
226+ const imageSavePath = path . join ( customPath , crypto . randomUUID ( ) ) ;
224227 // we simulate the Docker CLI being so old that the `--platform` flag is not supported at all.
225228 const dockerPullCliSpy = jest
226229 . spyOn ( Docker . prototype , "pullCli" )
@@ -258,7 +261,7 @@ describe("getImageArchive", () => {
258261 } ) ;
259262
260263 it ( "should produce the expected state" , async ( ) => {
261- const imageSavePath = path . join ( customPath , uuidv4 ( ) ) ;
264+ const imageSavePath = path . join ( customPath , crypto . randomUUID ( ) ) ;
262265 const dockerPullCliSpy = jest
263266 . spyOn ( Docker . prototype , "pullCli" )
264267 . mockImplementation ( ( ) => {
@@ -296,7 +299,7 @@ describe("getImageArchive", () => {
296299 } ) ;
297300
298301 it ( "should produce the expected state" , async ( ) => {
299- const imageSavePath = path . join ( customPath , uuidv4 ( ) ) ;
302+ const imageSavePath = path . join ( customPath , crypto . randomUUID ( ) ) ;
300303 const dockerPullSpy = jest . spyOn ( Docker . prototype , "pull" ) ;
301304 jest . spyOn ( subProcess , "execute" ) . mockImplementation ( ( ) => {
302305 throw new Error ( ) ;
@@ -334,7 +337,7 @@ describe("getImageArchive", () => {
334337 } ) ;
335338
336339 it ( "should produce the expected state" , async ( ) => {
337- const imageSavePath = path . join ( customPath , uuidv4 ( ) ) ;
340+ const imageSavePath = path . join ( customPath , crypto . randomUUID ( ) ) ;
338341 const dockerPullSpy = jest
339342 . spyOn ( Docker . prototype , "pull" )
340343 . mockImplementation ( ( _1 , _2 , _3 , imageSavePath ) => {
0 commit comments