From f9e99940140f94493cb451f7973c3580db5c16c1 Mon Sep 17 00:00:00 2001 From: ikbear Date: Wed, 16 Jan 2013 16:12:27 +0800 Subject: [PATCH 01/17] Add download token --- .gitignore | 1 + lib/auth.js | 70 ++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 57 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index c5e5df08..d4dc9fe5 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ node_modules npm-debug.log demo/test.jpg test/config.js +demo/config.js diff --git a/lib/auth.js b/lib/auth.js index b6961762..51f0f031 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -2,17 +2,53 @@ var crypto = require('crypto'); var config = require("./conf.js"); var util = require('./util.js'); +exports.UploadToken = UploadToken; +exports.DownloadToken = DownloadToken; + +// ------------------------------------------------------------------------------------------ +// func generateSignature + +function generateSignature(params) { + var paramsString = JSON.stringify(params); + return util.encode(paramsString); +} + +// ------------------------------------------------------------------------------------------ +// func generateEncodedDigest + +function generateEncodedDigest(signature) { + var hmac = crypto.createHmac('sha1', config.SECRET_KEY); + hmac.update(signature); + var digest = hmac.digest('base64'); + return util.base64ToUrlsafe(digest); +} + +// ------------------------------------------------------------------------------------------ +// func generateToken + +function generateToken(params) { + var signature = generateSignature(params); + var encodedDigest = generateEncodedDigest(signature); + return config.ACCESS_KEY + ":" + encodedDigest + ":" + signature; +} + +// ------------------------------------------------------------------------------------------ +// type UploadToken + function UploadToken(opts) { this.scope = opts.scope || null; this.expires = opts.expires || 3600; this.callbackUrl = opts.callbackUrl || null; this.callbackBodyType = opts.callbackBodyType || null; this.customer = opts.customer || null; + this.escape = opts.escape || 0; + this.asyncOps = opts.asyncOps || null; } -UploadToken.prototype.generateSignature = function() { +UploadToken.prototype.generateToken = function() { var params = { "deadline": this.expires + Math.floor(Date.now() / 1000), + "escape": this.excape, }; if (this.scope !== null) { params["scope"] = this.scope; @@ -26,21 +62,27 @@ UploadToken.prototype.generateSignature = function() { if (this.customer !== null) { params["customer"] = this.customer; } - var paramsString = JSON.stringify(params) - return util.encode(paramsString); + if (this.asyncOps !== null) { + params["asyncOps"] = this.asyncOps; + } + console.log(params) + return generateToken(params); }; -UploadToken.prototype.generateEncodedDigest = function(signature) { - var hmac = crypto.createHmac('sha1', config.SECRET_KEY); - hmac.update(signature); - var digest = hmac.digest('base64'); - return util.base64ToUrlsafe(digest); -}; +// ------------------------------------------------------------------------------------------ +// type DownloadToken -UploadToken.prototype.generateToken = function() { - var signature = this.generateSignature(); - var encoded_digest = this.generateEncodedDigest(signature); - return config.ACCESS_KEY + ":" + encoded_digest + ":" + signature; +function DownloadToken(opts) { + this.expires = opts.expires || 3600; + this.pattern = opts.pattern || "*/*"; +} + +DownloadToken.prototype.generateToken = function() { + var params = { + S: this.pattern, + E: this.expires + Math.floor(Date.now() / 1000), + }; + return generateToken(params); }; -exports.UploadToken = UploadToken; +// ------------------------------------------------------------------------------------------ From a533d1cbf4de0a85ec15a30581851709272a2784 Mon Sep 17 00:00:00 2001 From: ikbear Date: Fri, 18 Jan 2013 13:45:55 +0800 Subject: [PATCH 02/17] Add copy and move API and travis-ci test --- .gitignore | 6 ++- lib/auth.js | 1 - lib/rs.js | 96 +++++++++++++++++++++++++++++++++++++++ package.json | 2 +- test/rs.test.js | 116 +++++++++++++++++++++++++++++++++++++++--------- 5 files changed, 197 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index d4dc9fe5..5af95536 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,8 @@ results node_modules npm-debug.log -demo/test.jpg +demo/*.jpg test/config.js -demo/config.js +demo/rtest.js +demo/itest.js +demo/put.sh diff --git a/lib/auth.js b/lib/auth.js index 51f0f031..78d642c6 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -65,7 +65,6 @@ UploadToken.prototype.generateToken = function() { if (this.asyncOps !== null) { params["asyncOps"] = this.asyncOps; } - console.log(params) return generateToken(params); }; diff --git a/lib/rs.js b/lib/rs.js index bb4756ce..2e12d51e 100644 --- a/lib/rs.js +++ b/lib/rs.js @@ -250,6 +250,64 @@ Service.prototype.drop = function(onret) { this.conn.callWith(url, null, onret); }; +Service.prototype.copy = function(sourceBucket, sourceKey, targetBucket, targetKey, onret) { + /* + * func Copy(sourceBucket, sourceKey, targetBucket, targetKey, onret) => Bool + * 拷贝某个资源表中的文件到另一个资源表中的某个文件 + */ + var url = config.RS_HOST + generateMoveOrCopyOpString('copy', sourceBucket, sourceKey, targetBucket, targetKey); + this.conn.callWith(url, null, onret); +}; + +Service.prototype.move = function(sourceBucket, sourceKey, targetBucket, targetKey, onret) { + /* + * func Move(sourceBucket, sourceKey, targetBucket, targetKey, onret) => Bool + * 移动某个资源表中的文件到另一个资源表中的某个文件 + */ + var url = config.RS_HOST + generateMoveOrCopyOpString('move', sourceBucket, sourceKey, targetBucket, targetKey); + this.conn.callWith(url, null, onret); +}; + +Service.prototype.batchGet = function(bucket, keys, onret) { + /* + * func BatchGet(bucket, keys, onret) => GetRet[] + * 为每个key生成一个短期有效的下载地址 + */ + batch(this, "get", bucket, keys, onret); +}; + +Service.prototype.batchStat = function(bucket, keys, onret) { + /* + * func BatchStat(bucket, keys, onret) => Entry[] + * 查看每个key所对应文件的属性 + */ + batch(this, "stat", bucket, keys, onret); +}; + +Service.prototype.batchDelete = function(bucket, keys, onret) { + /* + * func BatchDelete(bucket, keys, onret) => Bool[] + * 批量删除每个key所对应的资源 + */ + batch(this, "delete", bucket, keys, onret); +}; + +Service.prototype.batchCopy = function(entries, onret) { + /* + * func BatchCopy(entries, onret) => Bool[] + * 批量拷贝文件 + */ + batchMoveOrCopy(this, 'copy', entries, onret); +}; + +Service.prototype.batchMove = function(entries, onret) { + /* + * func BatchMove(entries, onret) => Bool[] + * 批量移动文件 + */ + batchMoveOrCopy(this, 'move', entries, onret); +}; + /* * 持久化存储一个经过云端服务处理过后的资源 */ @@ -310,4 +368,42 @@ Service.prototype.unsetStyle = function(name, onret){ this.conn.callWith(url, null, onret); }; + +// ------------------------------------------------------------------------------------------ +// private functions + +function generateMoveOrCopyOpString(command, sourceBucket, sourceKey, targetBucket, targetKey) { + var sourceEntryURI = sourceBucket + ":" + sourceKey; + var targetEntryURI = targetBucket + ":" + targetKey; + var url = '/' + command + '/' + util.encode(sourceEntryURI) + '/' + util.encode(targetEntryURI); + return url; +}; + +function batch(rs, command, bucket, keys, onret) { + var ops = [] + , length = keys.length + , url = config.RS_HOST + '/batch?'; + + for(var i = 0; i < length; i++) { + console.log("Entry URI is: ", bucket + ":" + keys[i]); + var encodedEntryURI = util.encode(bucket + ":" + keys[i]); + ops.push("op=/" + command + "/" + encodedEntryURI); + } + url += ops.join("&"); + console.log("Batch URL: ", url); + rs.conn.callWith(url, null, onret); +} + +function batchMoveOrCopy(rs, command, entries, onret) { + var ops = [] + , length = ops.length + , url = config.RS_HOST + '/batch?'; + + for(var i = 0; i < length; i++) { + ops.push('op=' + moveOrCopy(command, entries[i][0], entries[i][1], entries[i][2], entries[i][3])); + } + url += ops.join("&"); + rs.conn.callWith(url, null, onret); +} + // ------------------------------------------------------------------------------------------ diff --git a/package.json b/package.json index 2bf4a595..f3bc62bd 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test": "test" }, "scripts": { - "test": "echo \"Error => no test specified\" && exit 1\"" + "test": "make test" }, "repository": { "type": "git", diff --git a/test/rs.test.js b/test/rs.test.js index 04224d51..f0d1aea9 100644 --- a/test/rs.test.js +++ b/test/rs.test.js @@ -23,35 +23,29 @@ var urlparse = require('url').parse; qiniu.conf.ACCESS_KEY = config.ACCESS_KEY; qiniu.conf.SECRET_KEY = config.SECRET_KEY; -var conn = new qiniu.digestauth.Client(); +var bucket = config.bucket, + DEMO_DOMAIN = bucket + '.qiniudn.com', + imagefile = path.join(__dirname, 'logo.png'); -var bucket = config.bucket; -var DEMO_DOMAIN = 'iovip.qbox.me/' + bucket; -var imagefile = path.join(__dirname, 'logo.png'); - -var rs = new qiniu.rs.Service(conn, bucket); - -function drop(done) { - rs.drop(function (res) { - res.should.have.property('code', 200); - done(); - }); -} +var conn = new qiniu.digestauth.Client(), + rs = new qiniu.rs.Service(conn, bucket); describe('rs.test.js', function () { var lastHash = null; before(function (done) { - drop(function () { - rs.putFile('rs.test.js.get', null, __filename, function (res) { - res.code.should.equal(200); - lastHash = res.data.hash; - done(); - }); + qiniu.rs.mkbucket(conn, bucket, function(res){ + res.should.have.property('code', 200); + done(); }); }); - after(drop); + after(function (done){ + rs.drop(function (res) { + res.should.have.property('code', 200); + done(); + }); + }); describe('putAuth()', function () { @@ -252,8 +246,90 @@ describe('rs.test.js', function () { }); + describe('uploadWithToken() && uploadFileWithToken()', function () { + var upToken = null; + beforeEach(function (done) { + var opts = { + scope: bucket, + expires: 3600, + callbackUrl: null, + callbackBodyType: null, + customer: null + }; + var token = new qiniu.auth.UploadToken(opts); + upToken = token.generateToken(); + done(); + }); + + it('should upload a stream with key using upToken and form-date format', function (done) { + + var s = new Stream(); + var count = 0; + var size = 0; + var timer = setInterval(function () { + var text = 'I come from timer stream ' + count + '\n'; + size += text.length; + count++; + if (count >= 5) { + clearInterval(timer); + process.nextTick(function () { + s.emit('end'); + }); + } + s.emit('data', text); + }, 100); + + rs.uploadWithToken(upToken, s, "stream.txt", null, null, null, null, function (res) { + res.should.have.keys('code', 'data'); + res.code.should.equal(200); + res.data.should.have.property('hash').with.match(/^[\w\-=]{28}$/); + var lastHash = res.data.hash; + rs.get('stream.txt', 'stream.txt', function (res) { + res.code.should.equal(200); + res.data.hash.should.equal(lastHash); + res.data.should.have.keys('expires', 'fsize', 'hash', 'mimeType', 'url'); + res.data.fsize.should.equal(size); + done(); + }); + }); + }); + + it('should upload a file with key using upToken and form-date format', function (done) { + var fstat = fs.statSync(__filename) + , size = fstat.size; + + rs.uploadFileWithToken(upToken, __filename, "uploadfilewithtoken.txt", null, null, {}, false, function(res){ + res.should.have.keys('code', 'data'); + res.code.should.equal(200); + res.data.should.have.property('hash').with.match(/^[\w\-=]{28}$/); + var lastHash = res.data.hash; + rs.get('uploadfilewithtoken.txt', 'uploadfilewithtoken.txt', function (res) { + res.code.should.equal(200); + res.data.hash.should.equal(lastHash); + res.data.should.have.keys('expires', 'fsize', 'hash', 'mimeType', 'url'); + res.data.fsize.should.equal(size); + done(); + }); + }); + + }); + + }); + describe('get()', function () { + var lastHash = null; + + beforeEach(function (done) { + rs.putFile('rs.test.js.get', null, __filename, function (res) { + res.should.have.keys('code', 'data'); + res.code.should.equal(200); + res.data.should.have.property('hash').with.match(/^[\w\-=]{28}$/); + lastHash = res.data.hash; + done(); + }); + }); + it('should return a file download url', function (done) { rs.get('rs.test.js.get', 'download.js', function (res) { res.code.should.equal(200); From 4f9570d2b4013c83af159641b0d024550f40b545 Mon Sep 17 00:00:00 2001 From: ikbear Date: Fri, 18 Jan 2013 13:50:24 +0800 Subject: [PATCH 03/17] Update test config file --- test/rs.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/rs.test.js b/test/rs.test.js index f0d1aea9..b0d84613 100644 --- a/test/rs.test.js +++ b/test/rs.test.js @@ -15,7 +15,7 @@ var http = require('http'); var fs = require('fs'); var should = require('should'); var qiniu = require('../'); -var config = require('./config'); +var config = require('./config.js'); var path = require('path'); var pedding = require('pedding'); var urlparse = require('url').parse; From 8bf44767db12a4b7fac40be89b5e2c365ddf0ad1 Mon Sep 17 00:00:00 2001 From: ikbear Date: Fri, 18 Jan 2013 14:08:27 +0800 Subject: [PATCH 04/17] Add config.js to travis-ci test --- .gitignore | 1 - test/config.js | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 test/config.js diff --git a/.gitignore b/.gitignore index 5af95536..217f1b38 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,6 @@ results node_modules npm-debug.log demo/*.jpg -test/config.js demo/rtest.js demo/itest.js demo/put.sh diff --git a/test/config.js b/test/config.js new file mode 100644 index 00000000..2ef8aca3 --- /dev/null +++ b/test/config.js @@ -0,0 +1,5 @@ +module.exports = { + ACCESS_KEY: 'ZXNF7bDoBmq-Qms9wPNPBAPtMMhOIe9UgL6hr9H_', + SECRET_KEY: 'O9yirPRXghIwEdQuf0XGt16uIDp4s-8DmTRcAxCq', + bucket: 'qiniutest', +}; From e01b96d494a8a41b9aba79d67fc85b14a89603e0 Mon Sep 17 00:00:00 2001 From: ikbear Date: Fri, 18 Jan 2013 16:19:55 +0800 Subject: [PATCH 05/17] Update test file --- test/rs.test.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/rs.test.js b/test/rs.test.js index b0d84613..a5af0d32 100644 --- a/test/rs.test.js +++ b/test/rs.test.js @@ -192,8 +192,7 @@ describe('rs.test.js', function () { s.emit('data', text); }, 100); - rs.upload(upToken, 'test/rs.test.js.upload.timer.stream', null, 'stream.txt', s, - function (res) { + rs.upload(upToken, 'test/rs.test.js.upload.timer.stream', null, 'stream.txt', s, function (res) { res.should.have.keys('code', 'data'); res.code.should.equal(200); res.data.should.have.property('hash').with.match(/^[\w\-=]{28}$/); @@ -225,8 +224,7 @@ describe('rs.test.js', function () { s.emit('data', text); }, 1000); - var req = rs.upload(upToken, 'test/rs.test.js.upload.timer.stream.abort', null, 'stream.txt', s, - function (res) { + var req = rs.upload(upToken, 'test/rs.test.js.upload.timer.stream.abort', null, 'stream.txt', s, function (res) { res.should.have.keys('code', 'detail', 'error'); res.code.should.equal(-1); res.error.should.equal('socket hang up'); From 1ce48f96a72f6dd80cfa502837a82b98687af9a7 Mon Sep 17 00:00:00 2001 From: ikbear Date: Fri, 18 Jan 2013 16:29:16 +0800 Subject: [PATCH 06/17] Do not delete bucket after unit test --- test/rs.test.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/rs.test.js b/test/rs.test.js index a5af0d32..5e885058 100644 --- a/test/rs.test.js +++ b/test/rs.test.js @@ -40,13 +40,6 @@ describe('rs.test.js', function () { }); }); - after(function (done){ - rs.drop(function (res) { - res.should.have.property('code', 200); - done(); - }); - }); - describe('putAuth()', function () { it('should return the auth upload url with default expires time 3600 seconds', function (done) { From 1009655162b74e4571279f06069fd6db153ed1da Mon Sep 17 00:00:00 2001 From: He Lishi Date: Tue, 22 Jan 2013 16:23:53 +0800 Subject: [PATCH 07/17] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add build status image --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e3ccd26e..ad847a44 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Node wrapper for Qiniu Resource (Cloud) Storage API +[![Build Status](https://travis-ci.org/qiniu/nodejs-sdk.png?branch=master)](undefined) + ![logo](http://qiniutek.com/images/logo-2.png) 该 SDK 适用于 NodeJS 0.4.7 及其以上版本,基于 [七牛云存储官方API](/v3/api/) 构建。若您的服务端是一个基于 NodeJS 编写的网络程序,使用此 SDK ,能让您以非常便捷地方式将数据安全地存储到七牛云存储上。以便让您应用的终端用户进行高速上传和下载,同时也使得您的服务端更加轻盈。 From 40218f9683e832ab3f2df2c41c9acee26c0c89fd Mon Sep 17 00:00:00 2001 From: ikbear Date: Tue, 22 Jan 2013 16:50:54 +0800 Subject: [PATCH 08/17] Update Access Key, Secret Key and bucket name --- test/config.js | 5 ++--- test/rs.test.js | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/test/config.js b/test/config.js index 2ef8aca3..80cb6fad 100644 --- a/test/config.js +++ b/test/config.js @@ -1,5 +1,4 @@ module.exports = { - ACCESS_KEY: 'ZXNF7bDoBmq-Qms9wPNPBAPtMMhOIe9UgL6hr9H_', - SECRET_KEY: 'O9yirPRXghIwEdQuf0XGt16uIDp4s-8DmTRcAxCq', - bucket: 'qiniutest', + ACCESS_KEY: '2FRuiVGEsA511NS9pNd2uvuSB3k5ozXE_DHCH8Ov', + SECRET_KEY: 'CIRtcmymB3VeIfXebFvYxmMmH9u2oLKW6rffVvoK', }; diff --git a/test/rs.test.js b/test/rs.test.js index 5e885058..54e96e12 100644 --- a/test/rs.test.js +++ b/test/rs.test.js @@ -23,7 +23,7 @@ var urlparse = require('url').parse; qiniu.conf.ACCESS_KEY = config.ACCESS_KEY; qiniu.conf.SECRET_KEY = config.SECRET_KEY; -var bucket = config.bucket, +var bucket = "qiniutest" + Math.round(new Date().getTime() / 1000), DEMO_DOMAIN = bucket + '.qiniudn.com', imagefile = path.join(__dirname, 'logo.png'); From 4bcb62729057db70e578df88c805d513383a4c18 Mon Sep 17 00:00:00 2001 From: He Lishi Date: Tue, 22 Jan 2013 16:56:56 +0800 Subject: [PATCH 09/17] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ad847a44..5542d240 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Node wrapper for Qiniu Resource (Cloud) Storage API -[![Build Status](https://travis-ci.org/qiniu/nodejs-sdk.png?branch=master)](undefined) +[![Build Status](https://travis-ci.org/qiniu/nodejs-sdk.png?branch=master)](https://travis-ci.org/qiniu/nodejs-sdk) ![logo](http://qiniutek.com/images/logo-2.png) From 2a2a189b2861a5896eeca2e8cceed205adbd6000 Mon Sep 17 00:00:00 2001 From: ikbear Date: Tue, 22 Jan 2013 17:31:25 +0800 Subject: [PATCH 10/17] Delete config.js --- test/config.js | 4 ---- test/config.js.default | 5 ----- test/rs.test.js | 5 ++--- 3 files changed, 2 insertions(+), 12 deletions(-) delete mode 100644 test/config.js delete mode 100644 test/config.js.default diff --git a/test/config.js b/test/config.js deleted file mode 100644 index 80cb6fad..00000000 --- a/test/config.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - ACCESS_KEY: '2FRuiVGEsA511NS9pNd2uvuSB3k5ozXE_DHCH8Ov', - SECRET_KEY: 'CIRtcmymB3VeIfXebFvYxmMmH9u2oLKW6rffVvoK', -}; diff --git a/test/config.js.default b/test/config.js.default deleted file mode 100644 index 097128b4..00000000 --- a/test/config.js.default +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - ACCESS_KEY: 'your key', - SECRET_KEY: 'your secret', - bucket: 'testqiniu', -}; \ No newline at end of file diff --git a/test/rs.test.js b/test/rs.test.js index 54e96e12..aed5761f 100644 --- a/test/rs.test.js +++ b/test/rs.test.js @@ -15,13 +15,12 @@ var http = require('http'); var fs = require('fs'); var should = require('should'); var qiniu = require('../'); -var config = require('./config.js'); var path = require('path'); var pedding = require('pedding'); var urlparse = require('url').parse; -qiniu.conf.ACCESS_KEY = config.ACCESS_KEY; -qiniu.conf.SECRET_KEY = config.SECRET_KEY; +qiniu.conf.ACCESS_KEY = "2FRuiVGEsA511NS9pNd2uvuSB3k5ozXE_DHCH8Ov"; +qiniu.conf.SECRET_KEY = "CIRtcmymB3VeIfXebFvYxmMmH9u2oLKW6rffVvoK"; var bucket = "qiniutest" + Math.round(new Date().getTime() / 1000), DEMO_DOMAIN = bucket + '.qiniudn.com', From b856acc0855da9226fdacf7cad061ef2604c3da1 Mon Sep 17 00:00:00 2001 From: ikbear Date: Wed, 23 Jan 2013 14:14:34 +0800 Subject: [PATCH 11/17] Revert "Delete config.js" This reverts commit 2a2a189b2861a5896eeca2e8cceed205adbd6000. --- test/config.js | 4 ++++ test/config.js.default | 5 +++++ test/rs.test.js | 5 +++-- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 test/config.js create mode 100644 test/config.js.default diff --git a/test/config.js b/test/config.js new file mode 100644 index 00000000..80cb6fad --- /dev/null +++ b/test/config.js @@ -0,0 +1,4 @@ +module.exports = { + ACCESS_KEY: '2FRuiVGEsA511NS9pNd2uvuSB3k5ozXE_DHCH8Ov', + SECRET_KEY: 'CIRtcmymB3VeIfXebFvYxmMmH9u2oLKW6rffVvoK', +}; diff --git a/test/config.js.default b/test/config.js.default new file mode 100644 index 00000000..097128b4 --- /dev/null +++ b/test/config.js.default @@ -0,0 +1,5 @@ +module.exports = { + ACCESS_KEY: 'your key', + SECRET_KEY: 'your secret', + bucket: 'testqiniu', +}; \ No newline at end of file diff --git a/test/rs.test.js b/test/rs.test.js index aed5761f..54e96e12 100644 --- a/test/rs.test.js +++ b/test/rs.test.js @@ -15,12 +15,13 @@ var http = require('http'); var fs = require('fs'); var should = require('should'); var qiniu = require('../'); +var config = require('./config.js'); var path = require('path'); var pedding = require('pedding'); var urlparse = require('url').parse; -qiniu.conf.ACCESS_KEY = "2FRuiVGEsA511NS9pNd2uvuSB3k5ozXE_DHCH8Ov"; -qiniu.conf.SECRET_KEY = "CIRtcmymB3VeIfXebFvYxmMmH9u2oLKW6rffVvoK"; +qiniu.conf.ACCESS_KEY = config.ACCESS_KEY; +qiniu.conf.SECRET_KEY = config.SECRET_KEY; var bucket = "qiniutest" + Math.round(new Date().getTime() / 1000), DEMO_DOMAIN = bucket + '.qiniudn.com', From 46a44cfdba62efa0809a2804ff23dc023cc6aecb Mon Sep 17 00:00:00 2001 From: ikbear Date: Wed, 23 Jan 2013 14:15:49 +0800 Subject: [PATCH 12/17] Revert "Revert "Delete config.js"" This reverts commit b856acc0855da9226fdacf7cad061ef2604c3da1. --- test/config.js | 4 ---- test/config.js.default | 5 ----- test/rs.test.js | 5 ++--- 3 files changed, 2 insertions(+), 12 deletions(-) delete mode 100644 test/config.js delete mode 100644 test/config.js.default diff --git a/test/config.js b/test/config.js deleted file mode 100644 index 80cb6fad..00000000 --- a/test/config.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - ACCESS_KEY: '2FRuiVGEsA511NS9pNd2uvuSB3k5ozXE_DHCH8Ov', - SECRET_KEY: 'CIRtcmymB3VeIfXebFvYxmMmH9u2oLKW6rffVvoK', -}; diff --git a/test/config.js.default b/test/config.js.default deleted file mode 100644 index 097128b4..00000000 --- a/test/config.js.default +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - ACCESS_KEY: 'your key', - SECRET_KEY: 'your secret', - bucket: 'testqiniu', -}; \ No newline at end of file diff --git a/test/rs.test.js b/test/rs.test.js index 54e96e12..aed5761f 100644 --- a/test/rs.test.js +++ b/test/rs.test.js @@ -15,13 +15,12 @@ var http = require('http'); var fs = require('fs'); var should = require('should'); var qiniu = require('../'); -var config = require('./config.js'); var path = require('path'); var pedding = require('pedding'); var urlparse = require('url').parse; -qiniu.conf.ACCESS_KEY = config.ACCESS_KEY; -qiniu.conf.SECRET_KEY = config.SECRET_KEY; +qiniu.conf.ACCESS_KEY = "2FRuiVGEsA511NS9pNd2uvuSB3k5ozXE_DHCH8Ov"; +qiniu.conf.SECRET_KEY = "CIRtcmymB3VeIfXebFvYxmMmH9u2oLKW6rffVvoK"; var bucket = "qiniutest" + Math.round(new Date().getTime() / 1000), DEMO_DOMAIN = bucket + '.qiniudn.com', From 018bb69b67c49e3ab5f2c717e21224353461c2f6 Mon Sep 17 00:00:00 2001 From: ikbear Date: Wed, 23 Jan 2013 16:35:27 +0800 Subject: [PATCH 13/17] Update travis test env parameters --- .travis.yml | 3 ++- test/rs.test.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b31a50be..f80b3986 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,5 @@ language: node_js node_js: - 0.8 - 0.6 - - 0.4 \ No newline at end of file +before_script: + export QINIU_ACCESS_KEY="2FRuiVGEsA511NS9pNd2uvuSB3k5ozXE_DHCH8Ov" QINIU_SECRET_KEY="CIRtcmymB3VeIfXebFvYxmMmH9u2oLKW6rffVvoK" diff --git a/test/rs.test.js b/test/rs.test.js index aed5761f..d2104f7b 100644 --- a/test/rs.test.js +++ b/test/rs.test.js @@ -19,8 +19,8 @@ var path = require('path'); var pedding = require('pedding'); var urlparse = require('url').parse; -qiniu.conf.ACCESS_KEY = "2FRuiVGEsA511NS9pNd2uvuSB3k5ozXE_DHCH8Ov"; -qiniu.conf.SECRET_KEY = "CIRtcmymB3VeIfXebFvYxmMmH9u2oLKW6rffVvoK"; +qiniu.conf.ACCESS_KEY = QINIU_ACCESS_KEY; +qiniu.conf.SECRET_KEY = QINIU_SECRET_KEY; var bucket = "qiniutest" + Math.round(new Date().getTime() / 1000), DEMO_DOMAIN = bucket + '.qiniudn.com', From e90595446b7e302d6e3adedc447722b4efb25400 Mon Sep 17 00:00:00 2001 From: ikbear Date: Wed, 23 Jan 2013 16:44:58 +0800 Subject: [PATCH 14/17] Update env parameters bug --- test/rs.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/rs.test.js b/test/rs.test.js index d2104f7b..72b88f20 100644 --- a/test/rs.test.js +++ b/test/rs.test.js @@ -19,8 +19,8 @@ var path = require('path'); var pedding = require('pedding'); var urlparse = require('url').parse; -qiniu.conf.ACCESS_KEY = QINIU_ACCESS_KEY; -qiniu.conf.SECRET_KEY = QINIU_SECRET_KEY; +qiniu.conf.ACCESS_KEY = process.env.QINIU_ACCESS_KEY; +qiniu.conf.SECRET_KEY = process.env.QINIU_SECRET_KEY; var bucket = "qiniutest" + Math.round(new Date().getTime() / 1000), DEMO_DOMAIN = bucket + '.qiniudn.com', From d430b190c5a0540be9e5ce973d433c0972923cab Mon Sep 17 00:00:00 2001 From: ikbear Date: Wed, 23 Jan 2013 16:59:56 +0800 Subject: [PATCH 15/17] Update export script --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f80b3986..c7bfd1c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,5 @@ node_js: - 0.8 - 0.6 before_script: - export QINIU_ACCESS_KEY="2FRuiVGEsA511NS9pNd2uvuSB3k5ozXE_DHCH8Ov" QINIU_SECRET_KEY="CIRtcmymB3VeIfXebFvYxmMmH9u2oLKW6rffVvoK" + - export QINIU_ACCESS_KEY="2FRuiVGEsA511NS9pNd2uvuSB3k5ozXE_DHCH8Ov" + - export QINIU_SECRET_KEY="CIRtcmymB3VeIfXebFvYxmMmH9u2oLKW6rffVvoK" From 0ec0dbe071edd14629e522021c33a6a7d9167767 Mon Sep 17 00:00:00 2001 From: ikbear Date: Wed, 23 Jan 2013 17:01:07 +0800 Subject: [PATCH 16/17] Update access key and secret key --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c7bfd1c0..f207622f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,5 +3,5 @@ node_js: - 0.8 - 0.6 before_script: - - export QINIU_ACCESS_KEY="2FRuiVGEsA511NS9pNd2uvuSB3k5ozXE_DHCH8Ov" - - export QINIU_SECRET_KEY="CIRtcmymB3VeIfXebFvYxmMmH9u2oLKW6rffVvoK" + - export QINIU_ACCESS_KEY="iN7NgwM31j4-BZacMjPrOQBs34UG1maYCAQmhdCV" + - export QINIU_SECRET_KEY="6QTOr2Jg1gcZEWDQXKOGZh5PziC2MCV5KsntT70j" From ac6fd5795bf6e3c1917942fd31e2dae68d779d9a Mon Sep 17 00:00:00 2001 From: ikbear Date: Wed, 23 Jan 2013 18:02:55 +0800 Subject: [PATCH 17/17] Drop bucket after test. --- test/rs.test.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/rs.test.js b/test/rs.test.js index 72b88f20..5a199694 100644 --- a/test/rs.test.js +++ b/test/rs.test.js @@ -22,7 +22,8 @@ var urlparse = require('url').parse; qiniu.conf.ACCESS_KEY = process.env.QINIU_ACCESS_KEY; qiniu.conf.SECRET_KEY = process.env.QINIU_SECRET_KEY; -var bucket = "qiniutest" + Math.round(new Date().getTime() / 1000), +var currentTime = new Date().getTime(); +var bucket = "qiniutest" + currentTime, DEMO_DOMAIN = bucket + '.qiniudn.com', imagefile = path.join(__dirname, 'logo.png'); @@ -39,6 +40,13 @@ describe('rs.test.js', function () { }); }); + after(function (done) { + rs.drop(function (res) { + res.should.have.property('code', 200); + done(); + }); + }); + describe('putAuth()', function () { it('should return the auth upload url with default expires time 3600 seconds', function (done) {