diff --git a/tests/functional/aws-node-sdk/test/support/config.js b/tests/functional/aws-node-sdk/test/support/config.js index 2c66fec471..ae4df173a2 100644 --- a/tests/functional/aws-node-sdk/test/support/config.js +++ b/tests/functional/aws-node-sdk/test/support/config.js @@ -1,7 +1,7 @@ const https = require('https'); const AWS = require('aws-sdk'); -const memCredentials = require('../../lib/json/mem_credentials.json'); +const { getCredentials } = require('./credentials'); const { getAwsCredentials } = require('./awsConfig'); const conf = require('../../../../../lib/Config').config; @@ -29,16 +29,8 @@ const DEFAULT_MEM_OPTIONS = { }; const DEFAULT_AWS_OPTIONS = {}; -if (!memCredentials || Object.is(memCredentials, {})) { - throw new Error('Credential info is missing in mem_credentials.json'); -} - function _getMemCredentials(profile) { - const credentials = memCredentials[profile] || memCredentials.default; - - const accessKeyId = credentials.accessKey; - const secretAccessKey = credentials.secretKey; - + const { accessKeyId, secretAccessKey } = getCredentials(profile); return new AWS.Credentials(accessKeyId, secretAccessKey); } diff --git a/tests/functional/aws-node-sdk/test/support/credentials.js b/tests/functional/aws-node-sdk/test/support/credentials.js new file mode 100644 index 0000000000..4aa6a176c0 --- /dev/null +++ b/tests/functional/aws-node-sdk/test/support/credentials.js @@ -0,0 +1,21 @@ +const memCredentials = require('../../lib/json/mem_credentials.json'); + +if (!memCredentials || Object.is(memCredentials, {})) { + throw new Error('Credential info is missing in mem_credentials.json'); +} + +function getCredentials(profile = 'default') { + const credentials = memCredentials[profile] || memCredentials.default; + + const accessKeyId = credentials.accessKey; + const secretAccessKey = credentials.secretKey; + + return { + accessKeyId, + secretAccessKey, + }; +} + +module.exports = { + getCredentials, +}; diff --git a/tests/functional/raw-node/test/routes/routeMetadata.js b/tests/functional/raw-node/test/routes/routeMetadata.js index 7af418d36d..9a916ada5a 100644 --- a/tests/functional/raw-node/test/routes/routeMetadata.js +++ b/tests/functional/raw-node/test/routes/routeMetadata.js @@ -3,13 +3,17 @@ const http = require('http'); const { makeRequest } = require('../../utils/makeRequest'); const MetadataMock = require('../../utils/MetadataMock'); +const { getCredentials } = require('../../../aws-node-sdk/test/support/credentials'); +const BucketUtility = require('../../../aws-node-sdk/lib/utility/bucket-util'); +const metadataMock = new MetadataMock(); const ipAddress = process.env.IP ? process.env.IP : 'localhost'; -const metadataMock = new MetadataMock(); + +const { accessKeyId, secretAccessKey } = getCredentials(); const metadataAuthCredentials = { - accessKey: 'accessKey1', - secretKey: 'verySecretKey1', + accessKey: accessKeyId, + secretKey: secretAccessKey, }; function makeMetadataRequest(params, callback) { @@ -29,15 +33,39 @@ function makeMetadataRequest(params, callback) { makeRequest(options, callback); } -describe('metadata routes with metadata mock backend', () => { - let httpServer; +describe('metadata routes with metadata', () => { + const bucketUtil = new BucketUtility( + 'default', { signatureVersion: 'v4' }); + const s3 = bucketUtil.s3; - before(done => { - httpServer = http.createServer( - (req, res) => metadataMock.onRequest(req, res)).listen(9000, done); - }); + const bucket1 = 'bucket1'; + const bucket2 = 'bucket2'; + const keyName = 'testobject1'; + + // E2E tests use S3C metadata, whereas functional tests use mocked metadata. + if (process.env.S3_END_TO_END) { + before(done => s3.createBucket({ Bucket: bucket1 }).promise() + .then(() => s3.putObject({ Bucket: bucket1, Key: keyName, Body: '' }).promise()) + .then(() => s3.createBucket({ Bucket: bucket2 }).promise()) + .then(() => done(), err => done(err)) + ); - after(() => httpServer.close()); + after(done => bucketUtil.empty(bucket1) + .then(() => s3.deleteBucket({ Bucket: bucket1 }).promise()) + .then(() => bucketUtil.empty(bucket2)) + .then(() => s3.deleteBucket({ Bucket: bucket2 }).promise()) + .then(() => done(), err => done(err)) + ); + } else { + let httpServer; + + before(done => { + httpServer = http.createServer( + (req, res) => metadataMock.onRequest(req, res)).listen(9000, done); + }); + + after(() => httpServer.close()); + } it('should retrieve list of buckets', done => { makeMetadataRequest({ @@ -48,7 +76,13 @@ describe('metadata routes with metadata mock backend', () => { assert.ifError(err); assert.strictEqual(res.statusCode, 200); assert(res.body); - assert.strictEqual(res.body, '["bucket1","bucket2"]'); + const expectedArray = [bucket1, 'users..bucket', bucket2]; + const responseArray = JSON.parse(res.body); + + expectedArray.sort(); + responseArray.sort(); + + assert.deepStrictEqual(responseArray, expectedArray); return done(); }); }); @@ -57,7 +91,7 @@ describe('metadata routes with metadata mock backend', () => { makeMetadataRequest({ method: 'GET', authCredentials: metadataAuthCredentials, - path: '/_/metadata/default/bucket/bucket1', + path: `/_/metadata/default/bucket/${bucket1}`, queryObj: { listingType: 'Delimiter' }, }, (err, res) => { assert.ifError(err); @@ -72,7 +106,7 @@ describe('metadata routes with metadata mock backend', () => { makeMetadataRequest({ method: 'GET', authCredentials: metadataAuthCredentials, - path: '/_/metadata/default/attributes/bucket1', + path: `/_/metadata/default/attributes/${bucket1}`, }, (err, res) => { assert.ifError(err); assert.strictEqual(res.statusCode, 200); @@ -85,13 +119,13 @@ describe('metadata routes with metadata mock backend', () => { makeMetadataRequest({ method: 'GET', authCredentials: metadataAuthCredentials, - path: '/_/metadata/default/bucket/bucket1/testobject1', + path: `/_/metadata/default/bucket/${bucket1}/${keyName}`, }, (err, res) => { assert.ifError(err); assert(res.body); assert.strictEqual(res.statusCode, 200); const body = JSON.parse(res.body); - assert.strictEqual(body.metadata, 'dogsAreGood'); + assert(body['owner-id']); return done(); }); }); diff --git a/tests/functional/raw-node/utils/MetadataMock.js b/tests/functional/raw-node/utils/MetadataMock.js index 639a22758f..008a284b41 100644 --- a/tests/functional/raw-node/utils/MetadataMock.js +++ b/tests/functional/raw-node/utils/MetadataMock.js @@ -208,7 +208,7 @@ class MetadataMock { })); } if (/\/_\/raft_sessions\/[1-8]\/bucket/.test(req.url)) { - const value = ['bucket1', 'bucket2']; + const value = ['bucket1', 'bucket2', 'users..bucket']; res.writeHead(200, { 'content-type': 'application/json' }); return res.end(JSON.stringify(value)); } else if (/\/default\/attributes\/[a-z0-9]/.test(req.url)) { @@ -228,7 +228,8 @@ class MetadataMock { return res.end(JSON.stringify(objectList)); } else if (/\/default\/bucket\/.*\/.*?/.test(req.url)) { return res.end(JSON.stringify({ - metadata: 'dogsAreGood', + 'owner-id': '123', + 'metadata': 'dogsAreGood', })); } else if (mockLogURLRegex.test(req.url)) { return res.end(JSON.stringify(mockLogs)); diff --git a/tests/multipleBackend/routes/routeBackbeat.js b/tests/multipleBackend/routes/routeBackbeat.js index a9a08655fb..1f307c27c3 100644 --- a/tests/multipleBackend/routes/routeBackbeat.js +++ b/tests/multipleBackend/routes/routeBackbeat.js @@ -19,6 +19,7 @@ const { } = require('../../functional/aws-node-sdk/test/multipleBackend/utils'); const { getRealAwsConfig } = require('../../functional/aws-node-sdk/test/support/awsConfig'); +const { getCredentials } = require('../../functional/aws-node-sdk/test/support/credentials'); const { config } = require('../../../lib/Config'); const awsConfig = getRealAwsConfig(awsLocation); @@ -29,11 +30,12 @@ const containerName = getAzureContainerName(azureLocation); const ipAddress = process.env.IP ? process.env.IP : '127.0.0.1'; +const { accessKeyId, secretAccessKey } = getCredentials(); + const backbeatAuthCredentials = { - accessKey: 'accessKey1', - secretKey: 'verySecretKey1', + accessKey: accessKeyId, + secretKey: secretAccessKey, }; - const TEST_BUCKET = 'backbeatbucket'; const TEST_ENCRYPTED_BUCKET = 'backbeatbucket-encrypted'; const TEST_KEY = 'fookey'; diff --git a/tests/multipleBackend/routes/routeBackbeatForReplication.js b/tests/multipleBackend/routes/routeBackbeatForReplication.js index 6cd64efc60..adde8ed1a6 100644 --- a/tests/multipleBackend/routes/routeBackbeatForReplication.js +++ b/tests/multipleBackend/routes/routeBackbeatForReplication.js @@ -5,10 +5,13 @@ const { ObjectMD } = models; const { makeBackbeatRequest } = require('../../functional/raw-node/utils/makeRequest'); const BucketUtility = require('../../functional/aws-node-sdk/lib/utility/bucket-util'); +const { getCredentials } = require('../../functional/aws-node-sdk/test/support/credentials'); + +const { accessKeyId, secretAccessKey } = getCredentials(); const backbeatAuthCredentials = { - accessKey: 'accessKey1', - secretKey: 'verySecretKey1', + accessKey: accessKeyId, + secretKey: secretAccessKey, }; const testData = 'testkey data';