Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARSN-418 Cherry-pick change to fix CRR null version in Backbeat #2244

Merged
merged 2 commits into from
Jun 20, 2024
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
11 changes: 9 additions & 2 deletions lib/models/ObjectMD.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as constants from '../constants';
import * as VersionIDUtils from '../versioning/VersionID';
import { VersioningConstants } from '../versioning/constants';
import ObjectMDLocation, {
ObjectMDLocationData,
Location,
Expand Down Expand Up @@ -797,20 +798,26 @@ export default class ObjectMD {
* @return The object versionId
*/
getVersionId() {
if (this.getIsNull()) {
return VersioningConstants.ExternalNullVersionId;
}
return this._data.versionId;
}

/**
* Get metadata versionId value in encoded form (the one visible
* to the S3 API user)
*
* @return The encoded object versionId
* @return {undefined|string} The encoded object versionId
*/
getEncodedVersionId() {
const versionId = this.getVersionId();
if (versionId) {
if (versionId === VersioningConstants.ExternalNullVersionId) {
return versionId;
} else if (versionId) {
return VersionIDUtils.encode(versionId);
}
return undefined;
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/versioning/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export const VersioningConstants = {
v1mig: 'v1mig',
v1: 'v1',
},
ExternalNullVersionId: 'null',
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"engines": {
"node": ">=16"
},
"version": "7.70.14",
"version": "7.70.14-1",
"description": "Common utilities for the S3 project components",
"main": "build/index.js",
"repository": {
Expand Down
43 changes: 43 additions & 0 deletions tests/unit/models/ObjectMD.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const assert = require('assert');
const ObjectMD = require('../../../lib/models/ObjectMD').default;
const constants = require('../../../lib/constants');
const ExternalNullVersionId = require('../../../lib/versioning/constants')
.VersioningConstants.ExternalNullVersionId;

const retainDate = new Date();
retainDate.setDate(retainDate.getDate() + 1);
Expand Down Expand Up @@ -583,3 +585,44 @@ describe('ObjectMD::getReducedLocations', () => {
]);
});
});

describe('ObjectMD::getVersionId', () => {
let objMd = null;
const versionId = '98451712418844999999RG001 22019.0';
beforeEach(() => {
objMd = new ObjectMD();
});
it('should return undefined when object is non versioned', () => {
assert.strictEqual(objMd.getVersionId(), undefined);
});
it('should return versionId when object versioned', () => {
objMd.setVersionId(versionId);
assert.strictEqual(objMd.getVersionId(), versionId);
});
it('should return "null" when object is in versioning suspended mode', () => {
objMd.setVersionId(versionId);
objMd.setIsNull(true);
assert.strictEqual(objMd.getVersionId(), ExternalNullVersionId);
});
});

describe('ObjectMD::getEncodedVersionId', () => {
let objMd = null;
const versionId = '98451712418844999999RG001 22019.0';
const encodedVersionId = '39383435313731323431383834343939393939395247303031202032323031392e30';
beforeEach(() => {
objMd = new ObjectMD();
});
it('should return undefined when object is non versioned', () => {
assert.strictEqual(objMd.getEncodedVersionId(), undefined);
});
it('should return versionId when object versioned', () => {
objMd.setVersionId(versionId);
assert.strictEqual(objMd.getEncodedVersionId(), encodedVersionId);
});
it('should return "null" when object is in versioning suspended mode', () => {
objMd.setVersionId(versionId);
objMd.setIsNull(true);
assert.strictEqual(objMd.getEncodedVersionId(), ExternalNullVersionId);
});
});
Loading