Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/s3middleware/tagging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const _validator = {
validateTagObjectStructure: (tag: BucketTag) => tag
&& Object.keys(tag).length === 2
&& typeof tag.Key === 'string' && typeof tag.Value === 'string'
&& tag.Key.length >= 1 && tag.Value.length >= 1,
&& tag.Key.length >= 1,

validateXMLStructure: (result: any) =>
result && Object.keys(result).length === 1 &&
Expand Down
24 changes: 23 additions & 1 deletion tests/unit/s3middleware/tagging.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const assert = require('assert');
const { areTagsValid, _validator } = require('../../../lib/s3middleware/tagging');
const werelogs = require('werelogs');
const { areTagsValid, _validator, parseTagXml } = require('../../../lib/s3middleware/tagging');

describe('tagging validator', () => {
it('validates keys and values are less than 128 and 256', () => {
Expand Down Expand Up @@ -68,6 +69,14 @@ describe('areTagsValid', () => {
assert.strictEqual(result, false);
});

it('should return true for tags with empty Value', () => {
const validTags = [
{ Key: 'key1', Value: '' }
];
const result = areTagsValid(validTags);
assert.strictEqual(result, true);
});

it('should return false for tags with duplicate keys', () => {
const invalidTags = [
{ Key: 'key1', Value: 'value1' },
Expand All @@ -93,3 +102,16 @@ describe('areTagsValid', () => {
assert.strictEqual(result, false);
});
});

describe('parseTagXml', () => {
const log = new werelogs.Logger('test');

it('should parse tags with empty values from XML', (done) => {
const xml = '<Tagging><TagSet><Tag><Key>key1</Key><Value></Value></Tag></TagSet></Tagging>';
parseTagXml(xml, log, (err, result) => {
assert.ifError(err);
assert.deepStrictEqual(result, { key1: '' });
done();
});
});
});
Loading