Skip to content

Commit

Permalink
Merge pull request #8534 from tangledbytes/utkarsh/fix/amz-restore-he…
Browse files Browse the repository at this point in the history
…ader
  • Loading branch information
tangledbytes authored Nov 18, 2024
2 parents aaeeb19 + 888259b commit e22503b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/endpoint/s3/s3_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ function set_response_object_md(res, object_md) {
if (storage_class !== STORAGE_CLASS_STANDARD) {
res.setHeader('x-amz-storage-class', storage_class);
}
if (object_md.restore_status) {
if (object_md.restore_status?.ongoing || object_md.restore_status?.expiry_time) {
const restore = [`ongoing-request="${object_md.restore_status.ongoing}"`];
if (!object_md.restore_status.ongoing && object_md.restore_status.expiry_time) {
// Expiry time is in UTC format
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/nsfs_glacier_backend/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class GlacierBackend {
static get_restore_status(xattr, now, file_path) {
if (xattr[GlacierBackend.STORAGE_CLASS_XATTR] !== s3_utils.STORAGE_CLASS_GLACIER) return;

// Total 6 states (2x restore_request, 3x restore_expiry)
// Total 8 states (2x restore_request, 4x restore_expiry)
let restore_request;
let restore_expiry;

Expand Down
58 changes: 58 additions & 0 deletions src/test/unit_tests/jest_tests/test_s3_utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ const s3_utils = require('../../../endpoint/s3/s3_utils');
const { S3Error } = require('../../../endpoint/s3/s3_errors');
const config = require('../../../../config');

function create_dummy_nb_response() {
return {
headers: {},
setHeader: function(k, v) {
if (Array.isArray(v)) {
v = v.join(',');
}

this.headers[k] = v;
}
};
}

describe('s3_utils', () => {
describe('parse_restrore_request_days', () => {
it('should parse correctly when 0 < days < max days', () => {
Expand Down Expand Up @@ -57,4 +70,49 @@ describe('s3_utils', () => {
config.S3_RESTORE_REQUEST_MAX_DAYS_BEHAVIOUR = initial;
});
});

describe('set_response_object_md', () => {
it('should return no restore status when restore_status is absent', () => {
const object_md = {
xattr: {}
};
const res = create_dummy_nb_response();

// @ts-ignore
s3_utils.set_response_object_md(res, object_md);

expect(res.headers['x-amz-restore']).toBeUndefined();
});

it('should return restore status when restore is requested and ongoing', () => {
const object_md = {
xattr: {},
restore_status: {
ongoing: true,
},
};
const res = create_dummy_nb_response();

// @ts-ignore
s3_utils.set_response_object_md(res, object_md);

expect(res.headers['x-amz-restore']).toBeDefined();
});

it('should return restore status when restore is completed', () => {
const object_md = {
xattr: {},
restore_status: {
ongoing: false,
expiry_time: new Date(),
},
};
const res = create_dummy_nb_response();

// @ts-ignore
s3_utils.set_response_object_md(res, object_md);

expect(res.headers['x-amz-restore']).toBeDefined();
});
});
});

0 comments on commit e22503b

Please sign in to comment.