Skip to content

Commit 42a01d0

Browse files
authored
Fix/2.12.1 (#1) (#172)
* upd: 新增单测 * upd: 新增单测 * upd: 新增单测 * upd: 补充单测 * upd: 补充单测 * upd: 补充单测 * upd: 补充单测 * upd: 补充单测 * fix: 更新XMLParser配置 * fix: 更新XMLParser配置 * fix: 优化d.ts
1 parent 675016a commit 42a01d0

File tree

4 files changed

+144
-4
lines changed

4 files changed

+144
-4
lines changed

index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,8 +2326,8 @@ declare class COS {
23262326
appendObject(params: COS.AppendObjectParams): Promise<COS.GeneralResult>;
23272327

23282328
/** 分块下载 @see https://cloud.tencent.com/document/product/436/64981#.E5.88.86.E5.9D.97.E4.B8.8B.E8.BD.BD.E5.AF.B9.E8.B1.A1 */
2329-
downloadFile(params: COS.DownloadFileParams, callback: (err: COS.CosError, data: COS.GeneralResult) => void): void;
2330-
downloadFile(params: COS.DownloadFileParams): Promise<COS.GeneralResult>;
2329+
downloadFile(params: COS.DownloadFileParams, callback: (err: COS.CosError, data: COS.GetObjectResult) => void): void;
2330+
downloadFile(params: COS.DownloadFileParams): Promise<COS.GetObjectResult>;
23312331

23322332
/** 获取 COS JSON API (v4) 签名 @see https://cloud.tencent.com/document/product/436/6054 */
23332333
getV4Auth(params: COS.GetV4AuthParams): COS.Authorization;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cos-nodejs-sdk-v5",
3-
"version": "2.12.0",
3+
"version": "2.12.1",
44
"description": "cos nodejs sdk v5",
55
"main": "index.js",
66
"types": "index.d.ts",

sdk/util.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
var fs = require('fs');
44
var crypto = require('crypto');
55
var { XMLParser, XMLBuilder } = require('fast-xml-parser');
6-
var xmlParser = new XMLParser({ ignoreAttributes: true });
6+
var xmlParser = new XMLParser({
7+
ignoreDeclaration: true, // 忽略 XML 声明
8+
ignoreAttributes: true, // 忽略属性
9+
parseTagValue: false, // 关闭自动解析
10+
});
711
var xmlBuilder = new XMLBuilder();
812

913
function camSafeUrlEncode(str) {

test/test.js

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

394484
group('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

Comments
 (0)