@@ -4,13 +4,16 @@ import { app, mock } from 'egg-mock/bootstrap';
4
4
import { TestUtil } from '../../../../test/TestUtil' ;
5
5
import { NFSClientAdapter } from '../../../../app/infra/NFSClientAdapter' ;
6
6
import { SyncMode } from '../../../../app/common/constants' ;
7
+ import { PackageManagerService } from '../../../../app/core/service/PackageManagerService' ;
7
8
8
9
describe ( 'test/port/controller/package/DownloadPackageVersionTarController.test.ts' , ( ) => {
9
10
let publisher : any ;
10
11
let nfsClientAdapter : NFSClientAdapter ;
12
+ let packageManagerService : PackageManagerService ;
11
13
beforeEach ( async ( ) => {
12
14
publisher = await TestUtil . createUser ( ) ;
13
15
nfsClientAdapter = await app . getEggObject ( NFSClientAdapter ) ;
16
+ packageManagerService = await app . getEggObject ( PackageManagerService ) ;
14
17
} ) ;
15
18
16
19
const scope = '@cnpm' ;
@@ -38,6 +41,8 @@ describe('test/port/controller/package/DownloadPackageVersionTarController.test.
38
41
assert ( res . status === 201 ) ;
39
42
assert ( res . body . ok === true ) ;
40
43
assert . match ( res . body . rev , / ^ \d + \- \w { 24 } $ / ) ;
44
+
45
+ await packageManagerService . unblockPackageByFullname ( scopedName ) ;
41
46
} ) ;
42
47
43
48
describe ( '[GET /:fullname/-/:name-:version.tgz] download()' , ( ) => {
@@ -56,6 +61,14 @@ describe('test/port/controller/package/DownloadPackageVersionTarController.test.
56
61
assert ( res . headers . location === `https://cdn.mock.com/packages/${ scopedName } /1.0.0/${ name } -1.0.0.tgz` ) ;
57
62
} ) ;
58
63
64
+ it ( 'should block tgz' , async ( ) => {
65
+ await packageManagerService . blockPackageByFullname ( scopedName , 'test' ) ;
66
+ const res = await app . httpRequest ( )
67
+ . get ( `/${ scopedName } /-/testmodule-download-version-tar-1.0.0.tgz` )
68
+ . expect ( 451 ) ;
69
+ assert . equal ( res . body . error , '[UNAVAILABLE_FOR_LEGAL_REASONS] @cnpm/[email protected] was blocked, reason: test' ) ;
70
+ } ) ;
71
+
59
72
it ( 'should support cors OPTIONS Request' , async ( ) => {
60
73
mock ( nfsClientAdapter , 'url' , async ( storeKey : string ) => {
61
74
return `https://cdn.mock.com${ storeKey } ` ;
@@ -337,6 +350,14 @@ describe('test/port/controller/package/DownloadPackageVersionTarController.test.
337
350
assert ( res . headers . location === `https://cdn.mock.com/packages/${ scopedName } /1.0.0/${ name } -1.0.0.tgz` ) ;
338
351
} ) ;
339
352
353
+ it ( 'should block tgz' , async ( ) => {
354
+ await packageManagerService . blockPackageByFullname ( scopedName , 'test' ) ;
355
+ const res = await app . httpRequest ( )
356
+ . get ( `/${ scopedName } /download/${ scopedName } -1.0.0.tgz` )
357
+ . expect ( 451 ) ;
358
+ assert . equal ( res . body . error , '[UNAVAILABLE_FOR_LEGAL_REASONS] @cnpm/[email protected] was blocked, reason: test' ) ;
359
+ } ) ;
360
+
340
361
it ( 'should download a version tar with streaming success' , async ( ) => {
341
362
mock ( nfsClientAdapter , 'url' , 'not-function' ) ;
342
363
const res = await app . httpRequest ( )
@@ -385,6 +406,15 @@ describe('test/port/controller/package/DownloadPackageVersionTarController.test.
385
406
assert ( res . headers . location === `https://cdn.mock.com/packages/${ scopedName } /1.0.0/${ name } -1.0.0.tgz` ) ;
386
407
} ) ;
387
408
409
+ it ( 'should block tgz' , async ( ) => {
410
+ await packageManagerService . blockPackageByFullname ( scopedName , 'test' ) ;
411
+ const res = await app . httpRequest ( )
412
+ . get ( `/${ scopedName } /-/${ scope } /${ name } -1.0.0.tgz` )
413
+ . expect ( 451 ) ;
414
+ assert . equal ( res . body . error , '[UNAVAILABLE_FOR_LEGAL_REASONS] @cnpm/[email protected] was blocked, reason: test' ) ;
415
+ } ) ;
416
+
417
+
388
418
it ( 'should download a version tar with streaming success' , async ( ) => {
389
419
mock ( nfsClientAdapter , 'url' , 'not-function' ) ;
390
420
const res = await app . httpRequest ( )
0 commit comments