Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/improvement/CLDSRV-554/tests' in…
Browse files Browse the repository at this point in the history
…to w/8.6/improvement/CLDSRV-554/tests
  • Loading branch information
nicolas2bert committed Jul 24, 2024
2 parents 0cd10a7 + 9fe2d31 commit 1b25718
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 32 deletions.
12 changes: 2 additions & 10 deletions tests/functional/aws-node-sdk/test/support/config.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down
21 changes: 21 additions & 0 deletions tests/functional/aws-node-sdk/test/support/credentials.js
Original file line number Diff line number Diff line change
@@ -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,
};
64 changes: 49 additions & 15 deletions tests/functional/raw-node/test/routes/routeMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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({
Expand All @@ -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();
});
});
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();
});
});
Expand Down
5 changes: 3 additions & 2 deletions tests/functional/raw-node/utils/MetadataMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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));
Expand Down
8 changes: 5 additions & 3 deletions tests/multipleBackend/routes/routeBackbeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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';
Expand Down
7 changes: 5 additions & 2 deletions tests/multipleBackend/routes/routeBackbeatForReplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 1b25718

Please sign in to comment.