Merge branch 'master' into add-license

This commit is contained in:
Peter deHaan 2017-06-23 11:57:44 -07:00 committed by GitHub
commit b972e707ed
6 changed files with 60 additions and 8 deletions

32
package-lock.json generated
View File

@ -2539,6 +2539,11 @@
"integrity": "sha1-YRwj6BTbN1Un34URk9tZ3Sryf0U=",
"dev": true
},
"json-stringify-safe": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz",
"integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus="
},
"json3": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/json3/-/json3-3.3.2.tgz",
@ -2771,6 +2776,11 @@
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.1.tgz",
"integrity": "sha512-q4spe4KTfsAS1SUHLO0wz8Qiyf1+vMIAgpRYioFYDMNqKfHQbg+AVDH3i4fvpl71/P1L0dBl+fQi+P37UYf0ew=="
},
"lsmod": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/lsmod/-/lsmod-1.0.0.tgz",
"integrity": "sha1-mgD3bco26yP6BTUK/htYXUKZ5ks="
},
"map-obj": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/map-obj/-/map-obj-1.0.1.tgz",
@ -3475,6 +3485,23 @@
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz",
"integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4="
},
"raven": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/raven/-/raven-2.1.0.tgz",
"integrity": "sha1-G2JOVjdNnJ2Tx0RIRhoqNWzjdSc=",
"dependencies": {
"stack-trace": {
"version": "0.0.9",
"resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.9.tgz",
"integrity": "sha1-qPbq7KkGdMMz58Q5U/J1tFFRBpU="
},
"uuid": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.0.0.tgz",
"integrity": "sha1-Zyj8BFnEUNeWqZwxg3VpvfZy1yg="
}
}
},
"raven-js": {
"version": "3.16.0",
"resolved": "https://registry.npmjs.org/raven-js/-/raven-js-3.16.0.tgz",
@ -4232,6 +4259,11 @@
}
}
},
"timed-out": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/timed-out/-/timed-out-4.0.1.tgz",
"integrity": "sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8="
},
"timers-browserify": {
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/timers-browserify/-/timers-browserify-1.4.2.tgz",

View File

@ -15,6 +15,7 @@
"helmet": "^3.6.1",
"jquery": "^3.2.1",
"mozlog": "^2.1.1",
"raven": "^2.1.0",
"raven-js": "^3.16.0",
"redis": "^2.7.1",
"uglify-es": "3.0.19"

View File

@ -25,6 +25,11 @@ const conf = convict({
sentry_id: {
format: String,
default: 'https://cdf9a4f43a584f759586af8ceb2194f2@sentry.prod.mozaws.net/238',
env: 'P2P_SENTRY_CLIENT'
},
sentry_dsn: {
format: String,
default: 'localhost',
env: 'P2P_SENTRY_DSN'
},
env: {
@ -42,4 +47,5 @@ module.exports = props;
module.exports.notLocalHost =
props.env === 'production' &&
props.s3_bucket !== 'localhost';
props.s3_bucket !== 'localhost' &&
props.sentry_dsn !== 'localhost';

View File

@ -7,9 +7,14 @@ const helmet = require('helmet');
const bytes = require('bytes');
const conf = require('./config.js');
const storage = require('./storage.js');
const Raven = require('raven');
const notLocalHost = conf.notLocalHost;
if (notLocalHost) {
Raven.config(conf.sentry_dsn).install();
}
const mozlog = require('./log.js');
const log = mozlog('portal.server');
@ -38,9 +43,9 @@ app.get('/', (req, res) => {
app.get('/exists/:id', (req, res) => {
const id = req.params.id;
storage.exists(id).then(doesExist => {
res.sendStatus(doesExist ? 200 : 404);
});
storage.exists(id).then(() => {
res.sendStatus(200);
}).catch(err => res.sendStatus(404));
});
app.get('/download/:id', (req, res) => {

View File

@ -49,7 +49,7 @@ function filename(id) {
if (!err) {
resolve(reply);
} else {
reject();
reject(err);
}
});
});
@ -58,7 +58,11 @@ function filename(id) {
function exists(id) {
return new Promise((resolve, reject) => {
redis_client.exists(id, (rediserr, reply) => {
resolve(reply === 1);
if (reply === 1 && !rediserr) {
resolve();
} else {
reject(rediserr);
}
});
});
}

View File

@ -44,12 +44,16 @@ const storage = proxyquire('../server/storage', {
describe('Testing Exists from local filesystem', function() {
it('Exists returns true when file exists', function() {
exists.callsArgWith(1, null, 1);
return storage.exists('test').then(reply => assert(reply));
return storage.exists('test')
.then(() => assert(1))
.catch(err => assert.fail())
});
it('Exists returns false when file does not exist', function() {
exists.callsArgWith(1, null, 0);
return storage.exists('test').then(reply => assert(!reply));
return storage.exists('test')
.then(() => assert.fail())
.catch(err => assert(1))
});
});