Skip to content

Commit 6891333

Browse files
committed
Merge branch 'w/9.0/bugfix/CLDSRV-729-rm-md5-requirement-backport-7.70' into tmp/octopus/w/9.1/bugfix/CLDSRV-729-rm-md5-requirement-backport-7.70
2 parents 37b699d + 0c31285 commit 6891333

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

tests/unit/api/multiObjectDelete.js

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,3 +492,122 @@ describe('multiObjectDelete function', () => {
492492
});
493493
});
494494
});
495+
496+
describe('multiObjectDelete function', () => {
497+
afterEach(() => {
498+
sinon.restore();
499+
});
500+
501+
it('should not authorize the bucket and initial IAM authorization results', done => {
502+
const post = '<Delete><Object><Key>objectname</Key></Object></Delete>';
503+
const request = new DummyRequest({
504+
bucketName: 'bucketname',
505+
objectKey: 'objectname',
506+
parsedHost: 'localhost',
507+
headers: {
508+
'content-md5': crypto.createHash('md5').update(post, 'utf8').digest('base64'),
509+
},
510+
post,
511+
socket: {
512+
remoteAddress: '127.0.0.1',
513+
},
514+
url: '/bucketname',
515+
});
516+
const authInfo = makeAuthInfo('123456');
517+
518+
sinon.stub(metadataWrapper, 'getBucket').callsFake((bucketName, log, cb) =>
519+
cb(null, new BucketInfo(
520+
'bucketname',
521+
'123456',
522+
'accountA',
523+
new Date().toISOString(),
524+
15,
525+
)));
526+
527+
multiObjectDelete.multiObjectDelete(authInfo, request, log, (err, res) => {
528+
// Expected result is an access denied on the object, and no error, as the API was authorized
529+
assert.strictEqual(err, null);
530+
assert.strictEqual(
531+
res.includes('<Error><Key>objectname</Key><Code>AccessDenied</Code>'),
532+
true
533+
);
534+
done();
535+
});
536+
});
537+
538+
it('should accept request when content-md5 header is missing', done => {
539+
const post = '<Delete><Object><Key>objectname</Key></Object></Delete>';
540+
const testObjectKey = 'objectname';
541+
const testBucketName = 'test-bucket';
542+
const request = new DummyRequest({
543+
bucketName: testBucketName,
544+
objectKey: testObjectKey,
545+
parsedHost: 'localhost',
546+
headers: {
547+
// No content-md5 header
548+
},
549+
post,
550+
socket: {
551+
remoteAddress: '127.0.0.1',
552+
},
553+
url: `/${testBucketName}`,
554+
});
555+
// Use the same canonicalID for both authInfo and bucket owner to avoid AccessDenied
556+
const testAuthInfo = makeAuthInfo(canonicalID);
557+
558+
// Create bucket with proper ownership
559+
const testBucketRequest = new DummyRequest({
560+
bucketName: testBucketName,
561+
namespace,
562+
headers: {},
563+
url: `/${testBucketName}`,
564+
});
565+
// Create object to delete
566+
const testObjectRequest = new DummyRequest({
567+
bucketName: testBucketName,
568+
namespace,
569+
objectKey: testObjectKey,
570+
headers: {},
571+
url: `/${testBucketName}/${testObjectKey}`,
572+
}, postBody);
573+
574+
bucketPut(testAuthInfo, testBucketRequest, log, () => {
575+
objectPut(testAuthInfo, testObjectRequest, undefined, log, () => {
576+
multiObjectDelete.multiObjectDelete(testAuthInfo, request, log, (err, res) => {
577+
// Request should succeed even without content-md5 header
578+
assert.strictEqual(err, null);
579+
assert.strictEqual(typeof res, 'string');
580+
// Should contain successful deletion response
581+
assert.strictEqual(res.includes('<Deleted><Key>objectname</Key></Deleted>'), true);
582+
done();
583+
});
584+
});
585+
});
586+
});
587+
588+
it('should reject request with BadDigest error when content-md5 header mismatches', done => {
589+
const post = '<Delete><Object><Key>objectname</Key></Object></Delete>';
590+
const incorrectMd5 = 'incorrectMd5Hash';
591+
const request = new DummyRequest({
592+
bucketName: 'bucketname',
593+
objectKey: 'objectname',
594+
parsedHost: 'localhost',
595+
headers: {
596+
'content-md5': incorrectMd5,
597+
},
598+
post,
599+
socket: {
600+
remoteAddress: '127.0.0.1',
601+
},
602+
url: '/bucketname',
603+
});
604+
const authInfo = makeAuthInfo('123456');
605+
606+
multiObjectDelete.multiObjectDelete(authInfo, request, log, (err, res) => {
607+
// Should return BadDigest error for mismatched content-md5
608+
assert.strictEqual(err.is.BadDigest, true);
609+
assert.strictEqual(res, undefined);
610+
done();
611+
});
612+
});
613+
});

0 commit comments

Comments
 (0)