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

Count items crashes if a bucket has a website configuration #322

Merged
merged 2 commits into from
Jul 8, 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
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 is 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
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.14.11",
"version": "1.14.12",
"engines": {
"node": ">= 16"
},
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();
});
});
});