@@ -389,6 +389,96 @@ group('init cos', function() {
389389 } ) ;
390390 putFile ( initCos , done , assert ) ;
391391 } ) ;
392+ test ( 'SecretKey格式错误' , function ( done , assert ) {
393+ var initCos = new COS ( {
394+ SecretId : config . SecretId ,
395+ SecretKey : config . SecretKey + ' ' ,
396+ } ) ;
397+ putFile ( initCos , done , assert , false ) ;
398+ } ) ;
399+ test ( 'StrictSsl=false' , function ( done , assert ) {
400+ var initCos = new COS ( {
401+ SecretId : config . SecretId ,
402+ SecretKey : config . SecretKey ,
403+ StrictSsl : false ,
404+ } ) ;
405+ putFile ( initCos , done , assert , true ) ;
406+ } ) ;
407+ test ( 'Tunnel=false' , function ( done , assert ) {
408+ var initCos = new COS ( {
409+ SecretId : config . SecretId ,
410+ SecretKey : config . SecretKey ,
411+ Tunnel : false ,
412+ } ) ;
413+ putFile ( initCos , done , assert , true ) ;
414+ } ) ;
415+ test ( 'Timeout=6000' , function ( done , assert ) {
416+ var initCos = new COS ( {
417+ SecretId : config . SecretId ,
418+ SecretKey : config . SecretKey ,
419+ Timeout : 6000 ,
420+ } ) ;
421+ putFile ( initCos , done , assert , true ) ;
422+ } ) ;
423+ test ( '模拟sms init' , function ( done , assert ) {
424+ var Credentials = {
425+ secretId : config . SecretId ,
426+ secretKey : config . SecretKey ,
427+ } ;
428+ var initCos = new COS ( { Credentials } ) ;
429+ setTimeout ( ( ) => {
430+ Credentials . secretId = '123456' ;
431+ Credentials . secretKey = 'abcdefg' ;
432+ } , 1000 ) ;
433+ putFile ( initCos , done , assert , true ) ;
434+ } ) ;
435+ test ( 'getAuthorization error tmpSecretId' , function ( done , assert ) {
436+ var initCos = new COS ( {
437+ getAuthorization : function ( options , callback ) {
438+ callback ( {
439+ tmpSecretId : config . SecretId ,
440+ TmpSecretKey : config . SecretKey ,
441+ } ) ;
442+ }
443+ } ) ;
444+ putFile ( initCos , done , assert , false ) ;
445+ } ) ;
446+ test ( 'getAuthorization error tmpSecretKey' , function ( done , assert ) {
447+ var initCos = new COS ( {
448+ getAuthorization : function ( options , callback ) {
449+ callback ( {
450+ TmpSecretId : config . SecretId ,
451+ tmpSecretKey : config . SecretKey ,
452+ } ) ;
453+ }
454+ } ) ;
455+ putFile ( initCos , done , assert , false ) ;
456+ } ) ;
457+ test ( 'getAuthorization error' , function ( done , assert ) {
458+ var initCos = new COS ( {
459+ getAuthorization : function ( options , callback ) {
460+ callback ( {
461+ TmpSecretId : config . SecretId ,
462+ TmpSecretKey : config . SecretKey ,
463+ } ) ;
464+ }
465+ } ) ;
466+ putFile ( initCos , done , assert , false ) ;
467+ } ) ;
468+ test ( 'getAuthorization' , function ( done , assert ) {
469+ var initCos = new COS ( {
470+ getAuthorization : function ( options , callback ) {
471+ var AuthData = cos . getAuth ( {
472+ Method : 'put' ,
473+ Key : '1.txt'
474+ } ) ;
475+ callback ( {
476+ Authorization : AuthData
477+ } ) ;
478+ }
479+ } ) ;
480+ putFile ( initCos , done , assert ) ;
481+ } ) ;
392482} ) ;
393483
394484group ( 'getService()' , function ( ) {
@@ -4870,6 +4960,22 @@ group('downloadFile', function () {
48704960 done ( ) ;
48714961 } ) ;
48724962 } ) ;
4963+ test ( 'downloadFile() fileSize=0' , function ( done , assert ) {
4964+ var Key = '0b.zip' ;
4965+ cos . downloadFile ( {
4966+ Bucket : config . Bucket , // Bucket 格式:test-1250000000
4967+ Region : config . Region ,
4968+ Key : Key ,
4969+ FilePath : './' + Key , // 本地保存路径
4970+ ChunkSize : 1024 * 1024 * 8 , // 分块大小
4971+ ParallelLimit : 5 , // 分块并发数
4972+ RetryTimes : 3 , // 分块失败重试次数
4973+ TaskId : '123' , // 可以自己生成TaskId,用于取消下载
4974+ } , function ( err , data ) {
4975+ assert . ok ( err ) ;
4976+ done ( ) ;
4977+ } ) ;
4978+ } ) ;
48734979 test ( 'downloadFile() 小文件简单下载' , function ( done , assert ) {
48744980 var Key = '1mb.zip' ;
48754981 var fileSize = 1024 * 1024 * 3 ;
@@ -4992,6 +5098,36 @@ group('downloadFile', function () {
49925098 }
49935099 } ) ;
49945100 } ) ;
5101+ test ( 'downloadFile() 文件续传时远端文件已修改' , function ( done , assert ) {
5102+ var Key = '50mb.zip' ;
5103+ var fileSize = 1024 * 1024 * 50 ;
5104+ var filePath = createFileSync ( path . resolve ( __dirname , Key ) , fileSize ) ;
5105+ cos . sliceUploadFile ( {
5106+ Bucket : config . Bucket ,
5107+ Region : config . Region ,
5108+ Key : Key ,
5109+ FilePath : filePath ,
5110+ TrafficLimit : 819200 ,
5111+ } , function ( err , data ) {
5112+ if ( err ) {
5113+ done ( ) ;
5114+ } else {
5115+ cos . downloadFile ( {
5116+ Bucket : config . Bucket , // Bucket 格式:test-1250000000
5117+ Region : config . Region ,
5118+ Key : Key ,
5119+ FilePath : './' + Key , // 本地保存路径
5120+ ChunkSize : 1024 * 1024 * 8 , // 分块大小
5121+ ParallelLimit : 5 , // 分块并发数
5122+ RetryTimes : 3 , // 分块失败重试次数
5123+ TaskId : '123' , // 可以自己生成TaskId,用于取消下载
5124+ } , function ( err , data ) {
5125+ assert . ok ( ! err ) ;
5126+ done ( ) ;
5127+ } ) ;
5128+ }
5129+ } ) ;
5130+ } ) ;
49955131 test ( 'downloadFile() 下载归档文件' , function ( done , assert ) {
49965132 var Key = '10mb.zip' ;
49975133 var fileSize = 1024 * 1024 * 10 ;
0 commit comments