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
15 changes: 10 additions & 5 deletions CountItems/CountWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const monitoring = require('../utils/monitoring');
const { deserializeBigInts, serializeBigInts } = require('./utils/utils');

const PENSIEVE = 'PENSIEVE';

class CountWorker {
constructor(params) {
this.log = params.log;
Expand Down Expand Up @@ -66,12 +67,16 @@ class CountWorker {
if (!this.client.client) {
return callback(new Error('NotConnected'));
}
// 'fromObj' expects that the website configuration is an instance of
// WebsiteConfiguration as it is not used in CountItems, we nullify it.
if (bucketInfoObj._websiteConfiguration) {
Object.assign(bucketInfoObj, { _websiteConfiguration: null });
const bucketInfoData = bucketInfoObj.bucketInfo || bucketInfoObj;
// 'fromObj' expects class-backed fields to already be instances.
// They are not used in CountItems, so we nullify unsupported serialized fields.
if (bucketInfoData._websiteConfiguration) {
bucketInfoData._websiteConfiguration = null;
}
if (bucketInfoData._bucketLoggingStatus) {
bucketInfoData._bucketLoggingStatus = null;
}
const bucketInfo = BucketInfo.fromObj(bucketInfoObj.bucketInfo || bucketInfoObj);
const bucketInfo = BucketInfo.fromObj(bucketInfoData);
const bucketName = bucketInfo.getName();
this.log.info(`${process.pid} handling ${bucketName}`);
return async.waterfall([
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "s3utils",
"version": "1.17.11",
"version": "1.17.12",
"engines": {
"node": ">= 22"
},
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/CountItems/CountWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,42 @@ describe('CountItems::CountWorker', () => {
});
});

test('should nullify unsupported serialized bucket info fields', done => {
const testSendFn = jest.fn();
const w = new CountWorker({
log: new DummyLogger(),
sendFn: testSendFn,
client: mongoMock,
});
const bucketInfo = {
_name: 'test-bucket',
_owner: 'any',
_ownerDisplayName: 'any',
_creationDate: Date.now().toString(),
_websiteConfiguration: {
_indexDocument: 'index.html',
},
_bucketLoggingStatus: {
_loggingEnabled: {
TargetBucket: 'target-bucket',
TargetPrefix: 'logs/',
},
},
};
w.getIsTransient = jest.fn((bucketInfo, cb) => cb(null, true));
mongoMock.setup.mockImplementationOnce(cb => cb());
mongoMock.close.mockImplementationOnce(cb => cb());
mongoMock.client.isConnected.mockImplementationOnce(() => false);
mongoMock.getObjectMDStats.mockImplementationOnce((_a, _b, _c, _d, cb) => cb(null, { value: 42 }));
w.countItems(bucketInfo, (err, results) => {
expect(err).toBeNull();
expect(results).toEqual({ value: 42 });
expect(bucketInfo._websiteConfiguration).toBeNull();
expect(bucketInfo._bucketLoggingStatus).toBeNull();
done();
});
});

describe('CountWorker.getIsTransient method', () => {
let worker;
let mockBucketInfo;
Expand Down
Loading