From 6aa79472bf2a26ecc566d18c3df7a6991414115d Mon Sep 17 00:00:00 2001 From: Abhinav Adduri Date: Mon, 10 Jul 2017 12:45:20 -0700 Subject: [PATCH] fixing small issues --- frontend/src/fileReceiver.js | 3 +-- frontend/src/fileSender.js | 5 ++--- server/portal_server.js | 2 +- server/storage.js | 10 ++++------ test/aws.storage.test.js | 2 +- test/local.storage.test.js | 2 +- 6 files changed, 10 insertions(+), 14 deletions(-) diff --git a/frontend/src/fileReceiver.js b/frontend/src/fileReceiver.js index d6b8cc00..37924038 100644 --- a/frontend/src/fileReceiver.js +++ b/frontend/src/fileReceiver.js @@ -4,7 +4,6 @@ const { hexToArray } = require('./utils'); class FileReceiver extends EventEmitter { constructor() { super(); - this.salt = hexToArray(location.pathname.slice(10, -1)); } download() { @@ -37,7 +36,7 @@ class FileReceiver extends EventEmitter { data: this.result, aad: meta.aad, filename: meta.filename, - iv: meta.iv + iv: meta.id }); }; diff --git a/frontend/src/fileSender.js b/frontend/src/fileSender.js index f2ed169d..5be5f490 100644 --- a/frontend/src/fileSender.js +++ b/frontend/src/fileSender.js @@ -72,8 +72,7 @@ class FileSender extends EventEmitter { }, secretKey, file.plaintext - ) - .catch(err => console.log('Error with encrypting.')), + ), window.crypto.subtle.exportKey('jwk', secretKey), new Promise((resolve, reject) => { resolve(file.hash) }) ]); @@ -114,7 +113,7 @@ class FileSender extends EventEmitter { 'X-File-Metadata', JSON.stringify({ aad: arrayToHex(hash), - iv: fileId, + id: fileId, filename: file.name }) ); diff --git a/server/portal_server.js b/server/portal_server.js index 7bdebc1d..c6ed936d 100644 --- a/server/portal_server.js +++ b/server/portal_server.js @@ -147,7 +147,7 @@ app.post('/upload', (req, res, next) => { req.busboy.on('file', (fieldname, file, filename) => { log.info('Uploading:', newId); - storage.set(meta.iv, newId, file, filename, meta).then(() => { + storage.set(newId, file, filename, meta).then(() => { const protocol = conf.env === 'production' ? 'https' : req.protocol; const url = `${protocol}://${req.get('host')}/download/${newId}/`; res.json({ diff --git a/server/storage.js b/server/storage.js index e765b0c7..38559ba3 100644 --- a/server/storage.js +++ b/server/storage.js @@ -115,14 +115,13 @@ function localGet(id) { return fs.createReadStream(path.join(__dirname, '../static', id)); } -function localSet(id, newId, file, filename, meta) { +function localSet(newId, file, filename, meta) { return new Promise((resolve, reject) => { const fstream = fs.createWriteStream(path.join(__dirname, '../static', newId)); file.pipe(fstream); fstream.on('close', () => { - meta.id = id; redis_client.hmset(newId, meta); - redis_client.expire(id, 86400000); + redis_client.expire(newId, 86400000); log.info('localSet:', 'Upload Finished of ' + newId); resolve(meta.delete); }); @@ -192,7 +191,7 @@ function awsGet(id) { } } -function awsSet(id, newId, file, filename, meta) { +function awsSet(newId, file, filename, meta) { const params = { Bucket: conf.s3_bucket, Key: newId, @@ -205,10 +204,9 @@ function awsSet(id, newId, file, filename, meta) { log.info('awsUploadError:', err.stack); // an error occurred reject(); } else { - meta.id = id; redis_client.hmset(newId, meta); - redis_client.expire(id, 86400000); + redis_client.expire(newId, 86400000); log.info('awsUploadFinish', 'Upload Finished of ' + filename); resolve(meta.delete); } diff --git a/test/aws.storage.test.js b/test/aws.storage.test.js index 867c2009..eef1f2a7 100644 --- a/test/aws.storage.test.js +++ b/test/aws.storage.test.js @@ -112,7 +112,7 @@ describe('Testing Set using aws', function() { sinon.stub(crypto, 'randomBytes').returns(buf); s3Stub.upload.callsArgWith(1, null, {}); return storage - .set('123', '123', {}, 'Filename.moz', {}) + .set('123', {}, 'Filename.moz', {}) .then(() => { assert(expire.calledOnce); assert(expire.calledWith('123', 86400000)); diff --git a/test/local.storage.test.js b/test/local.storage.test.js index 022cf613..3a9993b2 100644 --- a/test/local.storage.test.js +++ b/test/local.storage.test.js @@ -122,7 +122,7 @@ describe('Testing Set to local filesystem', function() { fsStub.createWriteStream.returns({ on: stub }); return storage - .set('test', 'test', { pipe: sinon.stub() }, 'Filename.moz', {}) + .set('test', { pipe: sinon.stub() }, 'Filename.moz', {}) .then(() => { assert(1); })