Skip to content

Commit

Permalink
Merge branch 'master' into cluster_subscription_gql
Browse files Browse the repository at this point in the history
  • Loading branch information
dalehille authored Jun 8, 2020
2 parents 5d89fa1 + fd48203 commit 4587931
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 20 deletions.
20 changes: 0 additions & 20 deletions app/s3/s3Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,3 @@ module.exports = class S3Client {
}
};

// ;((async()=>{
// var s3Client = new module.exports(require('../conf.js').conf);
// var bucketName = 'razee--k4tty77xnpmgjppfw';
// var path = 'blah';
// var content = 'this is teh content';
// var encryptionKey = 'orgApiKey-21fd8bfa-cc1d-43dd-988f-ddec98d72db7';
// var ivText = 'oRAApY8YmWQx5a98rUVkhg==';
// var iv = Buffer.from(ivText, 'base64');
//
// console.log(11111, bucketName, path, content, encryptionKey, ivText, iv);
//
// var out = await s3Client.encryptAndUploadFile(bucketName, path, content, encryptionKey, iv);
//
// console.log('uploaded', out);
//
// var out = await s3Client.getAndDecryptFile(bucketName, path, encryptionKey, iv);
//
// console.log('downloaded', out);
// })());

68 changes: 68 additions & 0 deletions app/s3/s3Client.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* eslint-env node, mocha */
/**
* Copyright 2019 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const assert = require('assert');
const rewire = require('rewire');
const AwsS3Mock = require('mock-aws-s3');
var stream = require('stream');

const S3Client = rewire('./s3Client');

AwsS3Mock.config.basePath = '/tmp/buckets';
S3Client.__set__({
AWS: AwsS3Mock,
bucketExists: ()=>{return true;}, //mock library doesnt have this function
});

describe('s3', () => {
describe('s3Client', () => {
it('encrypt, upload, download, and decrypt', async () => {
//assert.equal(responseCodeMapper(500), 'error');
var s3Client = new S3Client({
s3: {
endpoint: 'http://someS3/',
accessKeyId: 'accessKey',
secretAccessKey: 'secretKey',
locationConstraint: 'us-standard',
bucketPrefix: 'razee',
s3ForcePathStyle: true,
signatureVersion: 'v4',
sslEnabled: false,
},
});

var bucketName = 'razee--k4tty77xnpmgjppfw';
var path = 'blah';
var inContent = 'this is teh content';
var fileStream = stream.Readable.from([ inContent ]);
var encryptionKey = 'orgApiKey-21fd8bfa-cc1d-43dd-988f-ddec98d72db7';
var ivText = 'oRAApY8YmWQx5a98rUVkhg==';
var iv = Buffer.from(ivText, 'base64');

await s3Client.createBucket(bucketName);
s3Client.bucketExists = ()=>{return true;};

// encrypts and uploads
await s3Client.encryptAndUploadFile(bucketName, path, fileStream, encryptionKey, iv);

// downloads and decrypts
var outContent = await s3Client.getAndDecryptFile(bucketName, path, encryptionKey, iv);

// makes sure we got the right content back
assert.equal(inContent, outContent);
});
});
});
38 changes: 38 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"express-mongo-sanitize": "^2.0.0",
"express-query-boolean": "^2.0.0",
"express-request-id": "^1.4.1",
"form-data": "^3.0.0",
"fs-readfile-promise": "^3.0.1",
"glob": "^7.1.6",
"glob-promise": "^3.4.0",
Expand All @@ -60,6 +61,7 @@
"json-key-validate": "^1.0.2",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.14",
"mock-aws-s3": "^4.0.1",
"moment": "^2.24.0",
"mongodb": "^3.5.5",
"mongoose": "^5.9.7",
Expand Down

0 comments on commit 4587931

Please sign in to comment.