@@ -104,6 +104,18 @@ const cleanup = async (): Promise<void> => {
104
104
const mockGetArtifactSuccess = jest . fn ( ( ) => {
105
105
const message = new http . IncomingMessage ( new net . Socket ( ) )
106
106
message . statusCode = 200
107
+ message . headers [ 'content-type' ] = 'zip'
108
+ message . push ( fs . readFileSync ( fixtures . exampleArtifact . path ) )
109
+ message . push ( null )
110
+ return {
111
+ message
112
+ }
113
+ } )
114
+
115
+ const mockGetArtifactGzip = jest . fn ( ( ) => {
116
+ const message = new http . IncomingMessage ( new net . Socket ( ) )
117
+ message . statusCode = 200
118
+ message . headers [ 'content-type' ] = 'application/gzip'
107
119
message . push ( fs . readFileSync ( fixtures . exampleArtifact . path ) )
108
120
message . push ( null )
109
121
return {
@@ -124,6 +136,7 @@ const mockGetArtifactFailure = jest.fn(() => {
124
136
const mockGetArtifactMalicious = jest . fn ( ( ) => {
125
137
const message = new http . IncomingMessage ( new net . Socket ( ) )
126
138
message . statusCode = 200
139
+ message . headers [ 'content-type' ] = 'zip'
127
140
message . push ( fs . readFileSync ( path . join ( __dirname , 'fixtures' , 'evil.zip' ) ) ) // evil.zip contains files that are formatted x/../../etc/hosts
128
141
message . push ( null )
129
142
return {
@@ -178,6 +191,7 @@ describe('download-artifact', () => {
178
191
)
179
192
expectExtractedArchive ( fixtures . workspaceDir )
180
193
expect ( response . downloadPath ) . toBe ( fixtures . workspaceDir )
194
+ expect ( response . skipped ) . toBe ( false )
181
195
} )
182
196
183
197
it ( 'should not allow path traversal from malicious artifacts' , async ( ) => {
@@ -231,6 +245,7 @@ describe('download-artifact', () => {
231
245
) . toBe ( true )
232
246
233
247
expect ( response . downloadPath ) . toBe ( fixtures . workspaceDir )
248
+ expect ( response . skipped ) . toBe ( false )
234
249
} )
235
250
236
251
it ( 'should successfully download an artifact to user defined path' , async ( ) => {
@@ -280,6 +295,7 @@ describe('download-artifact', () => {
280
295
)
281
296
expectExtractedArchive ( customPath )
282
297
expect ( response . downloadPath ) . toBe ( customPath )
298
+ expect ( response . skipped ) . toBe ( false )
283
299
} )
284
300
285
301
it ( 'should fail if download artifact API does not respond with location' , async ( ) => {
@@ -316,6 +332,7 @@ describe('download-artifact', () => {
316
332
// mock http client to delay response data by 30s
317
333
const msg = new http . IncomingMessage ( new net . Socket ( ) )
318
334
msg . statusCode = 200
335
+ msg . headers [ 'content-type' ] = 'zip'
319
336
320
337
const mockGet = jest . fn ( async ( ) => {
321
338
return new Promise ( ( resolve , reject ) => {
@@ -444,7 +461,39 @@ describe('download-artifact', () => {
444
461
)
445
462
expect ( mockGetArtifactSuccess ) . toHaveBeenCalledTimes ( 1 )
446
463
expect ( response . downloadPath ) . toBe ( fixtures . workspaceDir )
464
+ expect ( response . skipped ) . toBe ( false )
447
465
} , 28000 )
466
+
467
+ it ( 'should skip if artifact does not have the right content type' , async ( ) => {
468
+ const downloadArtifactMock = github . getOctokit ( fixtures . token ) . rest
469
+ . actions . downloadArtifact as MockedDownloadArtifact
470
+ downloadArtifactMock . mockResolvedValueOnce ( {
471
+ headers : {
472
+ location : fixtures . blobStorageUrl
473
+ } ,
474
+ status : 302 ,
475
+ url : '' ,
476
+ data : Buffer . from ( '' )
477
+ } )
478
+
479
+ const mockHttpClient = ( HttpClient as jest . Mock ) . mockImplementation (
480
+ ( ) => {
481
+ return {
482
+ get : mockGetArtifactGzip
483
+ }
484
+ }
485
+ )
486
+
487
+ const response = await downloadArtifactPublic (
488
+ fixtures . artifactID ,
489
+ fixtures . repositoryOwner ,
490
+ fixtures . repositoryName ,
491
+ fixtures . token
492
+ )
493
+
494
+ expect ( mockHttpClient ) . toHaveBeenCalledWith ( getUserAgentString ( ) )
495
+ expect ( response . skipped ) . toBe ( true )
496
+ } )
448
497
} )
449
498
450
499
describe ( 'internal' , ( ) => {
@@ -499,6 +548,7 @@ describe('download-artifact', () => {
499
548
500
549
expectExtractedArchive ( fixtures . workspaceDir )
501
550
expect ( response . downloadPath ) . toBe ( fixtures . workspaceDir )
551
+ expect ( response . skipped ) . toBe ( false )
502
552
expect ( mockHttpClient ) . toHaveBeenCalledWith ( getUserAgentString ( ) )
503
553
expect ( mockListArtifacts ) . toHaveBeenCalledWith ( {
504
554
idFilter : {
@@ -550,6 +600,7 @@ describe('download-artifact', () => {
550
600
551
601
expectExtractedArchive ( customPath )
552
602
expect ( response . downloadPath ) . toBe ( customPath )
603
+ expect ( response . skipped ) . toBe ( false )
553
604
expect ( mockHttpClient ) . toHaveBeenCalledWith ( getUserAgentString ( ) )
554
605
expect ( mockListArtifacts ) . toHaveBeenCalledWith ( {
555
606
idFilter : {
0 commit comments