-
Notifications
You must be signed in to change notification settings - Fork 260
Allow partialFilterExpression in backbeat index add payload #6274
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
base: development/9.4
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1540,3 +1540,101 @@ describe('routeBackbeat authorization', () => { | |
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('routeBackbeat index add payload validation', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing a test : should reject if the field is not well formatted ? |
||
| const bucketName = 'bucketname'; | ||
| let endPromise; | ||
| let resolveEnd; | ||
| let response; | ||
|
|
||
| function makeIndexRequest(payload) { | ||
| const body = JSON.stringify(payload); | ||
| return new DummyRequest( | ||
| { | ||
| method: 'POST', | ||
| headers: { 'content-length': body.length }, | ||
| url: `/_/backbeat/index/${bucketName}?operation=add`, | ||
| }, | ||
| body, | ||
| ); | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| endPromise = new Promise(resolve => { | ||
| resolveEnd = resolve; | ||
| }); | ||
| response = { | ||
| setHeader: sinon.stub(), | ||
| writeHead: sinon.stub(), | ||
| end: sinon.stub().callsFake((body, encoding, callback) => { | ||
| resolveEnd(); | ||
| if (callback) { | ||
| callback(); | ||
| } | ||
| }), | ||
| }; | ||
| sinon.stub(auth.server, 'doAuth').yields( | ||
| null, | ||
| new AuthInfo({ | ||
| canonicalID: 'abcdef/lifecycle', | ||
| accountDisplayName: 'Lifecycle Service Account', | ||
| }), | ||
| undefined, | ||
| undefined, | ||
| {}, | ||
| ); | ||
| sinon.stub(metadata, 'putBucketIndexes').yields(null); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| sinon.restore(); | ||
| }); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing test where the request fails if backend is not mongo? or is it in some integration tests? |
||
| it('should accept indexes with a partialFilterExpression', async () => { | ||
| const payload = [ | ||
| { | ||
| keys: [ | ||
| { key: 'value.last-modified', order: 1 }, | ||
| { key: '_id', order: 1 }, | ||
| ], | ||
| name: 'partialIndex', | ||
| partialFilterExpression: { _id: { $gte: 'a', $lt: 'b' } }, | ||
| }, | ||
| ]; | ||
| routeBackbeat('127.0.0.1', makeIndexRequest(payload), response, log); | ||
| void (await endPromise); | ||
|
|
||
| assert.strictEqual(response.writeHead.getCall(0).args[0], 200); | ||
| assert.deepStrictEqual(metadata.putBucketIndexes.getCall(0).args[1], payload); | ||
| }); | ||
|
|
||
| it('should accept indexes without a partialFilterExpression', async () => { | ||
| const payload = [ | ||
| { | ||
| keys: [{ key: '_id', order: 1 }], | ||
| name: 'plainIndex', | ||
| }, | ||
| ]; | ||
| routeBackbeat('127.0.0.1', makeIndexRequest(payload), response, log); | ||
| void (await endPromise); | ||
|
|
||
| assert.strictEqual(response.writeHead.getCall(0).args[0], 200); | ||
| assert.deepStrictEqual(metadata.putBucketIndexes.getCall(0).args[1], payload); | ||
| }); | ||
|
|
||
| it('should reject indexes with unknown fields', async () => { | ||
| const payload = [ | ||
| { | ||
| keys: [{ key: '_id', order: 1 }], | ||
| name: 'badIndex', | ||
| unknownField: true, | ||
| }, | ||
| ]; | ||
| routeBackbeat('127.0.0.1', makeIndexRequest(payload), response, log); | ||
| void (await endPromise); | ||
|
|
||
| const err = JSON.parse(response.end.getCall(0).args[0]); | ||
| assert.strictEqual(err.code, 'BadRequest'); | ||
| assert.strictEqual(metadata.putBucketIndexes.called, false); | ||
| }); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we have "integration" test, where we actually call mongo? |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we validate it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean declare the schema ? Can be hard as it's mongo but pretty sure we can find some joi lib to validate mongo ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is validated by mongo during the call, so is it worth duplicating the validation?
(the alternative would be to define our own "index definition format", and map it to mongo format in cloudserver : in that case we should indeed do validation)