From bbfc32e67e6d0b10f77539fb318b727d9cb297d0 Mon Sep 17 00:00:00 2001 From: Jonathan Gramain Date: Tue, 21 Apr 2020 14:23:45 -0700 Subject: [PATCH] bugfix: S3C-2726 remove some default attributes from ObjectMD Remove "nullVersionId", "isNull" and "isDeleteMarker" default values from ObjectMD model, instead of the previous '' (empty string) default value that was incorrect and could cause an issue by misinterpreting the empty "nullVersionId" as an actual null version ID. --- lib/models/ObjectMD.js | 20 +++++++++++--------- tests/unit/models/object.js | 6 +++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/models/ObjectMD.js b/lib/models/ObjectMD.js index b11a392af..e611d91bc 100644 --- a/lib/models/ObjectMD.js +++ b/lib/models/ObjectMD.js @@ -106,10 +106,12 @@ class ObjectMD { }, 'key': '', 'location': null, - 'isNull': '', - 'nullVersionId': '', - 'isDeleteMarker': '', - 'versionId': undefined, // If no versionId, it should be undefined + // versionId, isNull, nullVersionId and isDeleteMarker + // should be undefined when not set explicitly + 'isNull': undefined, + 'nullVersionId': undefined, + 'isDeleteMarker': undefined, + 'versionId': undefined, 'tags': {}, 'replicationInfo': { status: '', @@ -605,7 +607,7 @@ class ObjectMD { * @return {boolean} Whether new version is null or not */ getIsNull() { - return this._data.isNull; + return this._data.isNull || false; } /** @@ -622,7 +624,7 @@ class ObjectMD { /** * Get metadata nullVersionId value * - * @return {string} The version id of the null version + * @return {string|undefined} The version id of the null version */ getNullVersionId() { return this._data.nullVersionId; @@ -645,7 +647,7 @@ class ObjectMD { * @return {boolean} Whether object is a delete marker */ getIsDeleteMarker() { - return this._data.isDeleteMarker; + return this._data.isDeleteMarker || false; } /** @@ -662,7 +664,7 @@ class ObjectMD { /** * Get metadata versionId value * - * @return {string} The object versionId + * @return {string|undefined} The object versionId */ getVersionId() { return this._data.versionId; @@ -672,7 +674,7 @@ class ObjectMD { * Get metadata versionId value in encoded form (the one visible * to the S3 API user) * - * @return {string} The encoded object versionId + * @return {string|undefined} The encoded object versionId */ getEncodedVersionId() { return VersionIDUtils.encode(this.getVersionId()); diff --git a/tests/unit/models/object.js b/tests/unit/models/object.js index 9644b6b5e..ab49842d8 100644 --- a/tests/unit/models/object.js +++ b/tests/unit/models/object.js @@ -60,11 +60,11 @@ describe('ObjectMD class setters/getters', () => { ['Key', 'key'], ['Location', null, []], ['Location', ['location1']], - ['IsNull', null, ''], + ['IsNull', null, false], ['IsNull', true], - ['NullVersionId', null, ''], + ['NullVersionId', null, undefined], ['NullVersionId', '111111'], - ['IsDeleteMarker', null, ''], + ['IsDeleteMarker', null, false], ['IsDeleteMarker', true], ['VersionId', null, undefined], ['VersionId', '111111'],