Skip to content

Commit

Permalink
S3UTILS-168: remove any website configuration
Browse files Browse the repository at this point in the history
The website configuration object, when calling "fromObj" must be
of type WebsiteConfiguration, otherwise, an assert will fail, and
this will cause a crash of count items.
  • Loading branch information
williamlardier committed Jun 26, 2024
1 parent 832863c commit 2bb4dab
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CountItems/CountWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class CountWorker {
if (!this.client.client) {
return callback(new Error('NotConnected'));
}
// 'fromObj' expects that the website configuration is an instance of
// WebsiteConfiguration As it it not used in CountItems, we nullify it.
if (bucketInfoObj._websiteConfiguration) {
Object.assign(bucketInfoObj, { _websiteConfiguration: null });
}
const bucketInfo = BucketInfo.fromObj(bucketInfoObj);
const bucketName = bucketInfo.getName();
this.log.info(`${process.pid} handling ${bucketName}`);
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/CountItems/CountWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,32 @@ describe('CountItems::CountWorker', () => {
done();
}, 100);
});

// test that the countworker's "countItems" method properly handles
// buckets with website
test('should correctly handle buckets with website', 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(),
website: { indexDocument: 'index.html' },
};
mongoMock.setup.mockImplementationOnce(cb => cb());
mongoMock.close.mockImplementationOnce(cb => cb());
mongoMock.client.isConnected.mockImplementationOnce(() => false);
mongoMock._getIsTransient.mockImplementationOnce((_a, _b, cb) => cb(null, true));
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 });
done();
});
});
});

0 comments on commit 2bb4dab

Please sign in to comment.