@@ -12,6 +12,7 @@ const {
1212const { GetObjectAttributesExtendedCommand } = require ( '@scality/cloudserverclient' ) ;
1313const withV4 = require ( '../support/withV4' ) ;
1414const BucketUtility = require ( '../../lib/utility/bucket-util' ) ;
15+ const { algorithms } = require ( '../../../../../lib/api/apiUtils/integrity/validateChecksums' ) ;
1516
1617const bucket = 'testbucket' ;
1718const key = 'testobject' ;
@@ -30,7 +31,9 @@ describe('objectGetAttributes', () => {
3031
3132 beforeEach ( async ( ) => {
3233 await s3 . send ( new CreateBucketCommand ( { Bucket : bucket } ) ) ;
33- await s3 . send ( new PutObjectCommand ( { Bucket : bucket , Key : key , Body : body } ) ) ;
34+ await s3 . send ( new PutObjectCommand ( {
35+ Bucket : bucket , Key : key , Body : body , ChecksumAlgorithm : 'CRC64NVME' ,
36+ } ) ) ;
3437 } ) ;
3538
3639 afterEach ( async ( ) => {
@@ -119,18 +122,28 @@ describe('objectGetAttributes', () => {
119122 assert . strictEqual ( data . ETag , expectedMD5 ) ;
120123 } ) ;
121124
122- it ( 'should fail with NotImplemented when Checksum is requested' , async ( ) => {
123- try {
124- await s3 . send ( new GetObjectAttributesCommand ( {
125- Bucket : bucket ,
126- Key : key ,
127- ObjectAttributes : [ 'Checksum' ] ,
128- } ) ) ;
129- assert . fail ( 'Expected NotImplemented error' ) ;
130- } catch ( err ) {
131- assert . strictEqual ( err . name , 'NotImplemented' ) ;
132- assert . strictEqual ( err . message , 'Checksum attribute is not implemented' ) ;
133- }
125+ it ( 'should return ChecksumCRC64NVME for object' , async ( ) => {
126+ const data = await s3 . send ( new GetObjectAttributesCommand ( {
127+ Bucket : bucket ,
128+ Key : key ,
129+ ObjectAttributes : [ 'Checksum' ] ,
130+ } ) ) ;
131+
132+ assert ( data . Checksum , 'Checksum should be present' ) ;
133+ assert ( data . Checksum . ChecksumCRC64NVME , 'ChecksumCRC64NVME should be present' ) ;
134+ assert . strictEqual ( data . Checksum . ChecksumType , 'FULL_OBJECT' ) ;
135+ } ) ;
136+
137+ it ( 'should not return Checksum when not requested' , async ( ) => {
138+ const data = await s3 . send ( new GetObjectAttributesCommand ( {
139+ Bucket : bucket ,
140+ Key : key ,
141+ ObjectAttributes : [ 'ETag' , 'ObjectSize' ] ,
142+ } ) ) ;
143+
144+ assert ( data . ETag , 'ETag should be present' ) ;
145+ assert ( data . ObjectSize , 'ObjectSize should be present' ) ;
146+ assert . strictEqual ( data . Checksum , undefined , 'Checksum should not be present' ) ;
134147 } ) ;
135148
136149 it ( "shouldn't return ObjectParts for non-MPU objects" , async ( ) => {
@@ -480,3 +493,93 @@ describe('objectGetAttributes with user metadata', () => {
480493 } ) ;
481494 } ) ;
482495} ) ;
496+
497+ describe ( 'objectGetAttributes with checksum' , ( ) => {
498+ withV4 ( sigCfg => {
499+ let bucketUtil ;
500+ let s3 ;
501+ const checksumBucket = 'checksum-getattr-test' ;
502+ const checksumKey = 'checksum-test-object' ;
503+ const checksumBody = Buffer . from ( 'checksum test body' ) ;
504+
505+ const expectedDigests = { } ;
506+
507+ before ( async ( ) => {
508+ bucketUtil = new BucketUtility ( 'default' , sigCfg ) ;
509+ s3 = bucketUtil . s3 ;
510+ await s3 . send ( new CreateBucketCommand ( { Bucket : checksumBucket } ) ) ;
511+
512+ for ( const [ name , algo ] of Object . entries ( algorithms ) ) {
513+ expectedDigests [ name ] = await algo . digest ( checksumBody ) ;
514+ }
515+ } ) ;
516+
517+ after ( async ( ) => {
518+ await bucketUtil . empty ( checksumBucket ) ;
519+ await s3 . send ( new DeleteBucketCommand ( { Bucket : checksumBucket } ) ) ;
520+ } ) ;
521+
522+ Object . entries ( algorithms ) . forEach ( ( [ name , { getObjectAttributesXMLTag } ] ) => {
523+ const sdkAlgorithm = name . toUpperCase ( ) ;
524+
525+ it ( `should return ${ getObjectAttributesXMLTag } when object has ${ name } checksum` , async ( ) => {
526+ await s3 . send ( new PutObjectCommand ( {
527+ Bucket : checksumBucket ,
528+ Key : checksumKey ,
529+ Body : checksumBody ,
530+ ChecksumAlgorithm : sdkAlgorithm ,
531+ } ) ) ;
532+
533+ const data = await s3 . send ( new GetObjectAttributesCommand ( {
534+ Bucket : checksumBucket ,
535+ Key : checksumKey ,
536+ ObjectAttributes : [ 'Checksum' ] ,
537+ } ) ) ;
538+
539+ assert ( data . Checksum , 'Checksum should be present' ) ;
540+ assert . strictEqual ( data . Checksum [ getObjectAttributesXMLTag ] , expectedDigests [ name ] ) ;
541+ assert . strictEqual ( data . Checksum . ChecksumType , 'FULL_OBJECT' ) ;
542+ } ) ;
543+
544+ it ( `should return ${ getObjectAttributesXMLTag } along with other attributes` , async ( ) => {
545+ await s3 . send ( new PutObjectCommand ( {
546+ Bucket : checksumBucket ,
547+ Key : checksumKey ,
548+ Body : checksumBody ,
549+ ChecksumAlgorithm : sdkAlgorithm ,
550+ } ) ) ;
551+
552+ const data = await s3 . send ( new GetObjectAttributesCommand ( {
553+ Bucket : checksumBucket ,
554+ Key : checksumKey ,
555+ ObjectAttributes : [ 'ETag' , 'Checksum' , 'ObjectSize' ] ,
556+ } ) ) ;
557+
558+ assert ( data . ETag , 'ETag should be present' ) ;
559+ assert ( data . ObjectSize , 'ObjectSize should be present' ) ;
560+ assert ( data . Checksum , 'Checksum should be present' ) ;
561+ assert . strictEqual ( data . Checksum [ getObjectAttributesXMLTag ] , expectedDigests [ name ] ) ;
562+ assert . strictEqual ( data . Checksum . ChecksumType , 'FULL_OBJECT' ) ;
563+ } ) ;
564+ } ) ;
565+
566+ it ( 'should not return Checksum when not requested' , async ( ) => {
567+ await s3 . send ( new PutObjectCommand ( {
568+ Bucket : checksumBucket ,
569+ Key : checksumKey ,
570+ Body : checksumBody ,
571+ ChecksumAlgorithm : 'CRC64NVME' ,
572+ } ) ) ;
573+
574+ const data = await s3 . send ( new GetObjectAttributesCommand ( {
575+ Bucket : checksumBucket ,
576+ Key : checksumKey ,
577+ ObjectAttributes : [ 'ETag' , 'ObjectSize' ] ,
578+ } ) ) ;
579+
580+ assert ( data . ETag , 'ETag should be present' ) ;
581+ assert ( data . ObjectSize , 'ObjectSize should be present' ) ;
582+ assert . strictEqual ( data . Checksum , undefined , 'Checksum should not be present' ) ;
583+ } ) ;
584+ } ) ;
585+ } ) ;
0 commit comments