pr changes
This commit is contained in:
parent
f3fe56e3d5
commit
e8280df647
|
@ -2,6 +2,7 @@ env:
|
||||||
browser: true
|
browser: true
|
||||||
es6: true
|
es6: true
|
||||||
jquery: true
|
jquery: true
|
||||||
|
mocha: true
|
||||||
node: true
|
node: true
|
||||||
|
|
||||||
extends:
|
extends:
|
||||||
|
|
|
@ -18,9 +18,7 @@
|
||||||
"mozlog": "^2.1.1",
|
"mozlog": "^2.1.1",
|
||||||
"node-fetch": "^1.7.1",
|
"node-fetch": "^1.7.1",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
"proxyquire": "^1.8.0",
|
"redis": "^2.7.1"
|
||||||
"redis": "^2.7.1",
|
|
||||||
"sinon": "^2.3.2"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"browserify": "^14.4.0",
|
"browserify": "^14.4.0",
|
||||||
|
@ -30,11 +28,13 @@
|
||||||
"eslint-plugin-node": "5.0.0",
|
"eslint-plugin-node": "5.0.0",
|
||||||
"eslint-plugin-security": "1.3.0",
|
"eslint-plugin-security": "1.3.0",
|
||||||
"htmllint-cli": "0.0.6",
|
"htmllint-cli": "0.0.6",
|
||||||
|
"mocha": "^3.4.2",
|
||||||
"npm-run-all": "4.0.2",
|
"npm-run-all": "4.0.2",
|
||||||
"prettier": "1.4.4",
|
"prettier": "1.4.4",
|
||||||
|
"proxyquire": "^1.8.0",
|
||||||
|
"sinon": "^2.3.5",
|
||||||
"stylelint": "7.11.0",
|
"stylelint": "7.11.0",
|
||||||
"stylelint-config-standard": "16.0.0",
|
"stylelint-config-standard": "16.0.0",
|
||||||
"mocha": "^3.4.2",
|
|
||||||
"watchify": "^3.9.0"
|
"watchify": "^3.9.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|
|
@ -143,7 +143,12 @@ function awsGet(id) {
|
||||||
Key: id
|
Key: id
|
||||||
};
|
};
|
||||||
|
|
||||||
return s3.getObject(params).createReadStream();
|
try {
|
||||||
|
return s3.getObject(params).createReadStream();
|
||||||
|
} catch(err) {
|
||||||
|
log.info('GetFailed', 'Get Object from s3 failed.');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function awsSet(id, file, filename, url) {
|
function awsSet(id, file, filename, url) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const proxyquire = require('proxyquire');
|
const proxyquire = require('proxyquire');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
|
||||||
const conf = require('../server/config.js');
|
const conf = require('../server/config.js');
|
||||||
conf.notLocalHost = true;
|
conf.notLocalHost = true;
|
||||||
|
@ -9,7 +10,7 @@ let redisStub = {};
|
||||||
let exists = sinon.stub();
|
let exists = sinon.stub();
|
||||||
let hget = sinon.stub();
|
let hget = sinon.stub();
|
||||||
let hmset = sinon.stub();
|
let hmset = sinon.stub();
|
||||||
let expire = sinon.stub();
|
let expire = sinon.spy();
|
||||||
let del = sinon.stub();
|
let del = sinon.stub();
|
||||||
|
|
||||||
redisStub.createClient = function() {
|
redisStub.createClient = function() {
|
||||||
|
@ -56,7 +57,7 @@ describe('Testing Length using aws', function() {
|
||||||
it('Filesize returns properly if id exists', function() {
|
it('Filesize returns properly if id exists', function() {
|
||||||
s3Stub.headObject.callsArgWith(1, null, {ContentLength: 1});
|
s3Stub.headObject.callsArgWith(1, null, {ContentLength: 1});
|
||||||
return storage.length('123')
|
return storage.length('123')
|
||||||
.then(reply => assert(reply === 1))
|
.then(reply => assert.equal(reply, 1))
|
||||||
.catch(err => assert.fail())
|
.catch(err => assert.fail())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -69,35 +70,59 @@ describe('Testing Length using aws', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Testing Get using aws', function() {
|
describe('Testing Get using aws', function() {
|
||||||
|
|
||||||
it('Should not error out when the file exists', function() {
|
it('Should not error out when the file exists', function() {
|
||||||
|
let spy = sinon.spy();
|
||||||
s3Stub.getObject.returns({
|
s3Stub.getObject.returns({
|
||||||
createReadStream: function() { return 1; }
|
createReadStream: spy
|
||||||
});
|
});
|
||||||
assert(storage.get('123') === 1);
|
|
||||||
|
storage.get('123');
|
||||||
|
assert(spy.calledOnce);
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should error when the file does not exist', function() {
|
it('Should error when the file does not exist', function() {
|
||||||
|
let err = function() { throw new Error(); }
|
||||||
|
let spy = sinon.spy(err);
|
||||||
s3Stub.getObject.returns({
|
s3Stub.getObject.returns({
|
||||||
createReadStream: function() { return null; }
|
createReadStream: spy
|
||||||
});
|
});
|
||||||
assert(storage.get('123') === null);
|
|
||||||
|
assert.equal(storage.get('123'), null);
|
||||||
|
assert(spy.threw());
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Testing Set using aws', function() {
|
describe('Testing Set using aws', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
expire.reset();
|
||||||
|
})
|
||||||
|
|
||||||
|
after(function() {
|
||||||
|
crypto.randomBytes.restore();
|
||||||
|
})
|
||||||
|
|
||||||
it('Should pass when the file is successfully uploaded and no bitly key', function() {
|
it('Should pass when the file is successfully uploaded and no bitly key', function() {
|
||||||
conf.bitly_key = null;
|
conf.bitly_key = null;
|
||||||
|
const buf = new Buffer(10);
|
||||||
|
sinon.stub(crypto, 'randomBytes').returns(buf);
|
||||||
s3Stub.upload.callsArgWith(1, null, {});
|
s3Stub.upload.callsArgWith(1, null, {});
|
||||||
return storage.set('123', {}, 'Filename.moz', 'url.com')
|
return storage.set('123', {}, 'Filename.moz', 'url.com')
|
||||||
.then(reply => assert(reply.url === 'url.com' && reply.uuid !== null))
|
.then(reply => {
|
||||||
.catch(err => assert.fail());
|
assert.equal(reply.uuid, buf.toString('hex'));
|
||||||
|
assert.equal(reply.url, 'url.com');
|
||||||
|
assert.notEqual(reply.uuid, null);
|
||||||
|
assert(expire.calledOnce);
|
||||||
|
assert(expire.calledWith('123', 86400000));
|
||||||
|
})
|
||||||
|
.catch(err => assert.fail());
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail if there was an error during uploading', function() {
|
it('Should fail if there was an error during uploading', function() {
|
||||||
s3Stub.upload.callsArgWith(1, new Error(), null);
|
s3Stub.upload.callsArgWith(1, new Error(), null);
|
||||||
return storage.set('123', {}, 'Filename.moz', 'url.com')
|
return storage.set('123', {}, 'Filename.moz', 'url.com')
|
||||||
.then(reply => assert.fail())
|
.then(reply => assert.fail())
|
||||||
.catch(err => assert(1));
|
.catch(err => assert(1));
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue