From 1baabfd82b14b2677f9e6213699000a0e3e41e99 Mon Sep 17 00:00:00 2001 From: Nicolas Humbert Date: Thu, 18 Jul 2024 14:57:31 +0200 Subject: [PATCH] CLDSRV-554 fix route metadata API tests --- .../raw-node/test/routes/routeBackbeat.js | 3 +- .../raw-node/test/routes/routeMetadata.js | 56 ++++++++++++++----- .../functional/raw-node/utils/MetadataMock.js | 5 +- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/tests/functional/raw-node/test/routes/routeBackbeat.js b/tests/functional/raw-node/test/routes/routeBackbeat.js index 98d0af3925..77360931bf 100644 --- a/tests/functional/raw-node/test/routes/routeBackbeat.js +++ b/tests/functional/raw-node/test/routes/routeBackbeat.js @@ -11,6 +11,7 @@ const { getCredentials } = require('../../../aws-node-sdk/test/support/credentia const ipAddress = process.env.IP ? process.env.IP : '127.0.0.1'; const describeSkipIfAWS = process.env.AWS_ON_AIR ? describe.skip : describe; const isNullVersionCompatMode = process.env.ENABLE_NULL_VERSION_COMPAT_MODE === 'true'; +const itSkipIfE2E = process.env.S3_END_TO_END ? it.skip : it; const { accessKeyId, secretAccessKey } = getCredentials(); @@ -2123,7 +2124,7 @@ describeSkipIfAWS('backbeat routes', () => { }); // TODO: unskip test when S3C-9123 is fixed - it.skip('should skip batch delete of a non-existent location', done => { + itSkipIfE2E('should skip batch delete of a non-existent location', done => { async.series([ done => { const options = { diff --git a/tests/functional/raw-node/test/routes/routeMetadata.js b/tests/functional/raw-node/test/routes/routeMetadata.js index d453df95ea..8a6b93bd53 100644 --- a/tests/functional/raw-node/test/routes/routeMetadata.js +++ b/tests/functional/raw-node/test/routes/routeMetadata.js @@ -4,9 +4,10 @@ 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(); @@ -32,15 +33,38 @@ 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(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; - after(() => httpServer.close()); + 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({ @@ -51,7 +75,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(); }); }); @@ -60,7 +90,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); @@ -75,7 +105,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); @@ -88,13 +118,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));