Skip to content

Commit

Permalink
ARSN-22 - Fix bug in onPutOgjectTaggig and getObjectTagging
Browse files Browse the repository at this point in the history
Use actual string instead of object when building object key
(for the bucket part).
  • Loading branch information
Alexandre Lavigne committed Oct 5, 2021
1 parent 0a33d4b commit 6a250fe
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/storage/data/external/AwsClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ class AwsClient {

objectPutTagging(key, bucket, objectMD, log, callback) {
const awsBucket = this._awsBucketName;
const awsKey = this._createAwsKey(bucket, key, this._bucketMatch);
const awsKey = this._createAwsKey(bucket.getName(), key, this._bucketMatch);
const dataStoreVersionId = objectMD.location[0].dataStoreVersionId;
const tagParams = {
Bucket: awsBucket,
Expand Down Expand Up @@ -514,7 +514,7 @@ class AwsClient {

objectDeleteTagging(key, bucket, objectMD, log, callback) {
const awsBucket = this._awsBucketName;
const awsKey = this._createAwsKey(bucket, key, this._bucketMatch);
const awsKey = this._createAwsKey(bucket.getName(), key, this._bucketMatch);
const dataStoreVersionId = objectMD.location[0].dataStoreVersionId;
const tagParams = {
Bucket: awsBucket,
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/storage/data/DummyService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const { EventEmitter } = require('events');

const DummyObjectStream = require('./DummyObjectStream');
const { parseRange } = require('../../../../lib/network/http/utils');
const assert = require('assert');
const errors = require('../../../../lib/errors');

const OBJECT_SIZE = 1024 * 1024 * 1024;

Expand Down Expand Up @@ -133,6 +135,38 @@ class DummyService {
objStream.pipe(writeStream);
return callback();
}
putObjectTagging(tagParams, callback) {
if (tagParams.Key === 'externalBackendTestBucket/externalBackendMissingKey') {
const err = errors.NoSuchKey;
return callback(err);
}

const keys = Object.keys(tagParams);
assert(keys.length > 0);
assert(tagParams.Tagging.TagSet.length > 0);
tagParams.Tagging.TagSet.forEach(tag => {
assert(tag.Key.length > 0);
assert(tag.Value.length > 0);
});

if (tagParams.VersionId) {
assert.strictEqual(tagParams.VersionId, 'latestversion');
}

return callback();
}
deleteObjectTagging(tagParams, callback) {
if (tagParams.Key === 'externalBackendTestBucket/externalBackendMissingKey') {
const err = errors.NoSuchKey;
return callback(err);
}

if (tagParams.VersionId) {
assert.strictEqual(tagParams.VersionId, 'latestversion');
}

return callback();
}
// To-Do: add tests for other methods
}

Expand Down
64 changes: 64 additions & 0 deletions tests/unit/storage/data/external/ExternalClients.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const assert = require('assert');
const async = require('async');
const stream = require('stream');

const AwsClient = require('../../../../../lib/storage/data/external/AwsClient');
Expand All @@ -7,6 +8,7 @@ const AzureClient =
require('../../../../../lib/storage/data/external/AzureClient');
const DummyService = require('../DummyService');
const { DummyRequestLogger } = require('../../../helpers');
const BucketInfo = require('../../../../../lib/models/BucketInfo');

const backendClients = [
{
Expand Down Expand Up @@ -154,6 +156,68 @@ describe('external backend clients', () => {
});
});
});

if (backend.config.type !== 'azure') {
it(`${backend.name} should set tags and then delete it`, done => {
const key = 'externalBackendTestKey';
const bucketData = {
_name: 'externalBackendTestBucket',
_owner: 'abcdef0123456789',
_ownerDisplayName: 'UnitTestOwner',
_creationDate: '2021-10-05T08:59:12.546Z',
};
const bucket = BucketInfo.fromObj(bucketData);
const objectMd = {
tags: {
Key1: 'value_1',
Key2: 'value_2',
},
location: [
{
dataStoreVersionId: 'latestversion',
},
],
};
async.series([
next => testClient.objectPutTagging(key.key, bucket, objectMd, log, next),
next => testClient.objectDeleteTagging(key.Key, bucket, objectMd, log, next),
], done);
});

it(`${backend.name} should fail to set tag on missing key`, done => {
const key = 'externalBackendMissingKey';
const bucketData = {
_name: 'externalBackendTestBucket',
_owner: 'abcdef0123456789',
_ownerDisplayName: 'UnitTestOwner',
_creationDate: '2021-10-05T08:59:12.546Z',
};
const bucket = BucketInfo.fromObj(bucketData);
const objectMD = {
tags: {
Key1: 'value_1',
},
location: [
{
dataStoreVersionId: 'latestversion',
},
],
};
async.series(
[
next => testClient.objectPutTagging(key, bucket, objectMD, log, (err) => {
assert(err.ServiceUnavailable);
next();
}),
next => testClient.objectDeleteTagging(key, bucket, objectMD, log, (err) => {
assert(err.ServiceUnavailable);
next();
}),
],
done,
);
});
}
// To-Do: test the other external client methods (delete, createMPU ...)
});
});

0 comments on commit 6a250fe

Please sign in to comment.