-
Notifications
You must be signed in to change notification settings - Fork 257
Enforce microVersionId conflicts at the metadata write level #6235
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 |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ | |
| "@opentelemetry/instrumentation-ioredis": "~0.64.0", | ||
| "@opentelemetry/instrumentation-mongodb": "~0.69.0", | ||
| "@smithy/node-http-handler": "^3.0.0", | ||
| "arsenal": "git+https://github.com/scality/arsenal#8.5.6", | ||
| "arsenal": "git+https://github.com/scality/arsenal#fa9abec316dc0a48b9511eec5b41f7b9a626d5f4", | ||
|
maeldonn marked this conversation as resolved.
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. reminder to point to the released arsenal tag containing ARSN-619 before merging ( |
||
| "async": "2.6.4", | ||
| "aws-crt": "^1.24.0", | ||
| "bucketclient": "scality/bucketclient#8.2.7", | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -255,12 +255,19 @@ describe('routeBackbeat', () => { | |||||||
| mockRequest = preparePutMetadataRequest(); | ||||||||
| dataDeleteSpy = sandbox.stub(dataWrapper.data, 'delete').callsFake((loc, log, cb) => cb(null)); | ||||||||
|
|
||||||||
| // fake the capability (mem backend has none) to exercise the condition path | ||||||||
| metadata.supportsConditionalPutObjectMD = () => true; | ||||||||
|
|
||||||||
| // Setup default version enabled bucket and empty object metadata | ||||||||
| metadataUtils.standardMetadataValidateBucketAndObj.callsFake((params, denies, log, callback) => { | ||||||||
| callback(null, bucketInfo, {}); | ||||||||
| }); | ||||||||
| }); | ||||||||
|
|
||||||||
| afterEach(() => { | ||||||||
| delete metadata.supportsConditionalPutObjectMD; | ||||||||
| }); | ||||||||
|
|
||||||||
| it('should allow CRR destination requests (putMetadata) when versioning is enabled', async () => { | ||||||||
| sandbox.stub(metadata, 'putObjectMD').callsFake((bucketName, objectKey, omVal, options, logParam, cb) => { | ||||||||
| cb(null, {}); | ||||||||
|
|
@@ -358,6 +365,136 @@ describe('routeBackbeat', () => { | |||||||
| assert.deepStrictEqual(mockResponse.body, {}); | ||||||||
| }); | ||||||||
|
|
||||||||
| it('should set an atomic microVersionId condition when updating an existing version', async () => { | ||||||||
| // reverse-chronological ordering: sorted ascending, the newer revision (incoming) sorts first | ||||||||
| const [incomingRaw, storedRaw] = [ | ||||||||
| versioning.VersionID.generateVersionId('test', 'RG001'), | ||||||||
| versioning.VersionID.generateVersionId('test', 'RG001'), | ||||||||
| ].sort(); | ||||||||
|
|
||||||||
| mockRequest = preparePutMetadataRequest({ microVersionId: incomingRaw }); | ||||||||
| mockRequest.headers['x-scal-micro-version-id'] = versioning.VersionID.encode(incomingRaw); | ||||||||
| mockRequest.url = '/_/backbeat/metadata/bucket0/key0' + '?versionId=aIXVkw5Tw2Pd00000000001I4j3QKsvf'; | ||||||||
|
|
||||||||
| metadataUtils.standardMetadataValidateBucketAndObj.callsFake((_params, _denies, _log, callback) => { | ||||||||
| callback(null, bucketInfo, { microVersionId: storedRaw }); | ||||||||
| }); | ||||||||
|
|
||||||||
| const putObjectMDStub = sandbox | ||||||||
| .stub(metadata, 'putObjectMD') | ||||||||
| .callsFake((_bucketName, _objectKey, _omVal, options, _logParam, cb) => { | ||||||||
| assert.deepStrictEqual(options.conditions, { microVersionId: { $gt: incomingRaw } }); | ||||||||
| cb(null, {}); | ||||||||
| }); | ||||||||
|
|
||||||||
| routeBackbeat('127.0.0.1', mockRequest, mockResponse, log); | ||||||||
| void (await endPromise); | ||||||||
|
|
||||||||
| sinon.assert.called(putObjectMDStub); | ||||||||
| assert.strictEqual(mockResponse.statusCode, 200); | ||||||||
| }); | ||||||||
|
|
||||||||
| it('should return 409 without writing when the incoming microVersionId is already stored', async () => { | ||||||||
| const incomingRaw = versioning.VersionID.generateVersionId('test', 'RG001'); | ||||||||
|
|
||||||||
| mockRequest = preparePutMetadataRequest({ microVersionId: incomingRaw }); | ||||||||
| mockRequest.headers['x-scal-micro-version-id'] = versioning.VersionID.encode(incomingRaw); | ||||||||
| mockRequest.url = '/_/backbeat/metadata/bucket0/key0' + '?versionId=aIXVkw5Tw2Pd00000000001I4j3QKsvf'; | ||||||||
|
|
||||||||
| metadataUtils.standardMetadataValidateBucketAndObj.callsFake((_params, _denies, _log, callback) => { | ||||||||
| callback(null, bucketInfo, { microVersionId: incomingRaw }); | ||||||||
| }); | ||||||||
|
|
||||||||
| const putObjectMDStub = sandbox.stub(metadata, 'putObjectMD'); | ||||||||
|
|
||||||||
| routeBackbeat('127.0.0.1', mockRequest, mockResponse, log); | ||||||||
| void (await endPromise); | ||||||||
|
|
||||||||
| sinon.assert.notCalled(putObjectMDStub); | ||||||||
| assert.strictEqual(mockResponse.statusCode, 409); | ||||||||
|
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. Only asserting
Suggested change
|
||||||||
| }); | ||||||||
|
|
||||||||
| it('should not set a microVersionId condition when the stored revision has none', async () => { | ||||||||
| const incomingRaw = versioning.VersionID.generateVersionId('test', 'RG001'); | ||||||||
|
|
||||||||
| mockRequest = preparePutMetadataRequest({ microVersionId: incomingRaw }); | ||||||||
| mockRequest.headers['x-scal-micro-version-id'] = versioning.VersionID.encode(incomingRaw); | ||||||||
| mockRequest.url = '/_/backbeat/metadata/bucket0/key0' + '?versionId=aIXVkw5Tw2Pd00000000001I4j3QKsvf'; | ||||||||
|
|
||||||||
| metadataUtils.standardMetadataValidateBucketAndObj.callsFake((_params, _denies, _log, callback) => { | ||||||||
| callback(null, bucketInfo, {}); | ||||||||
| }); | ||||||||
|
|
||||||||
| const putObjectMDStub = sandbox | ||||||||
| .stub(metadata, 'putObjectMD') | ||||||||
| .callsFake((_bucketName, _objectKey, _omVal, options, _logParam, cb) => { | ||||||||
| assert.strictEqual(options.conditions, undefined); | ||||||||
| cb(null, {}); | ||||||||
| }); | ||||||||
|
|
||||||||
| routeBackbeat('127.0.0.1', mockRequest, mockResponse, log); | ||||||||
| void (await endPromise); | ||||||||
|
|
||||||||
| sinon.assert.called(putObjectMDStub); | ||||||||
| assert.strictEqual(mockResponse.statusCode, 200); | ||||||||
| }); | ||||||||
|
|
||||||||
| it('should not set a microVersionId condition when the backend does not support it', async () => { | ||||||||
| const [incomingRaw, storedRaw] = [ | ||||||||
| versioning.VersionID.generateVersionId('test', 'RG001'), | ||||||||
| versioning.VersionID.generateVersionId('test', 'RG001'), | ||||||||
| ].sort(); | ||||||||
|
|
||||||||
| delete metadata.supportsConditionalPutObjectMD; | ||||||||
|
|
||||||||
| mockRequest = preparePutMetadataRequest({ microVersionId: incomingRaw }); | ||||||||
| mockRequest.headers['x-scal-micro-version-id'] = versioning.VersionID.encode(incomingRaw); | ||||||||
| mockRequest.url = '/_/backbeat/metadata/bucket0/key0' + '?versionId=aIXVkw5Tw2Pd00000000001I4j3QKsvf'; | ||||||||
|
|
||||||||
| metadataUtils.standardMetadataValidateBucketAndObj.callsFake((_params, _denies, _log, callback) => { | ||||||||
| callback(null, bucketInfo, { microVersionId: storedRaw }); | ||||||||
| }); | ||||||||
|
|
||||||||
| const putObjectMDStub = sandbox | ||||||||
| .stub(metadata, 'putObjectMD') | ||||||||
| .callsFake((_bucketName, _objectKey, _omVal, options, _logParam, cb) => { | ||||||||
| assert.strictEqual(options.conditions, undefined); | ||||||||
| cb(null, {}); | ||||||||
| }); | ||||||||
|
|
||||||||
| routeBackbeat('127.0.0.1', mockRequest, mockResponse, log); | ||||||||
| void (await endPromise); | ||||||||
|
|
||||||||
| sinon.assert.called(putObjectMDStub); | ||||||||
| assert.strictEqual(mockResponse.statusCode, 200); | ||||||||
| }); | ||||||||
|
|
||||||||
| it('should return 409 when the metadata write rejects a stale microVersionId', async () => { | ||||||||
| const [incomingRaw, storedRaw] = [ | ||||||||
| versioning.VersionID.generateVersionId('test', 'RG001'), | ||||||||
| versioning.VersionID.generateVersionId('test', 'RG001'), | ||||||||
| ].sort(); | ||||||||
|
|
||||||||
| mockRequest = preparePutMetadataRequest({ microVersionId: incomingRaw }); | ||||||||
| mockRequest.headers['x-scal-micro-version-id'] = versioning.VersionID.encode(incomingRaw); | ||||||||
| mockRequest.url = '/_/backbeat/metadata/bucket0/key0' + '?versionId=aIXVkw5Tw2Pd00000000001I4j3QKsvf'; | ||||||||
|
|
||||||||
| metadataUtils.standardMetadataValidateBucketAndObj.callsFake((_params, _denies, _log, callback) => { | ||||||||
| callback(null, bucketInfo, { microVersionId: storedRaw }); | ||||||||
| }); | ||||||||
|
|
||||||||
| sandbox | ||||||||
| .stub(metadata, 'putObjectMD') | ||||||||
| .callsFake((_bucketName, _objectKey, _omVal, _options, _logParam, cb) => { | ||||||||
| cb(errors.PreconditionFailed); | ||||||||
| }); | ||||||||
|
|
||||||||
| routeBackbeat('127.0.0.1', mockRequest, mockResponse, log); | ||||||||
| void (await endPromise); | ||||||||
|
|
||||||||
| assert.strictEqual(mockResponse.statusCode, 409); | ||||||||
|
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. Same here — assert the body code so this test doesn't pass if a different 409 path fires.
Suggested change
|
||||||||
| }); | ||||||||
|
|
||||||||
| it('should handle error when putting metadata', async () => { | ||||||||
| const putObjectMDStub = sandbox.stub(metadata, 'putObjectMD'); | ||||||||
| putObjectMDStub.onCall(0).callsFake((bucketName, objectKey, omVal, options, logParam, cb) => { | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.
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.
could the condition also cover the missing-field case, e.g.
$or: [{ microVersionId: { $exists: false } }, { microVersionId: { $gt: … } }]? otherwise this window stays unprotected , iftranslateConditionscannot express it, worth mentionning in the comment.