1
1
/* Copyright (C) 2020 NooBaa */
2
2
/* eslint-disable max-lines-per-function */
3
- /*eslint max-lines: ["error",3200 ]*/
3
+ /*eslint max-lines: ["error",3300 ]*/
4
4
'use strict' ;
5
5
6
6
const fs = require ( 'fs' ) ;
@@ -804,38 +804,72 @@ mocha.describe('bucketspace namespace_fs - versioning', function() {
804
804
const tagging_key = "key_tagging" ;
805
805
const tag_set1 = { TagSet : [ { Key : "key1" , Value : "Value1" } ] } ;
806
806
const tag_set2 = { TagSet : [ { Key : "key2" , Value : "Value2" } ] } ;
807
+ const tag_set3 = { TagSet : [ { "Key" : "designation" , "Value" : "confidential" } ,
808
+ { "Key" : "department" , "Value" : "finance" } ,
809
+ { "Key" : "team" , "Value" : "payroll" } ]
810
+ } ;
807
811
let version_id ;
808
812
809
813
mocha . before ( async function ( ) {
810
- await s3_uid6 . putBucketVersioning ( { Bucket : suspended_bucket_name , VersioningConfiguration : { MFADelete : 'Disabled' , Status : 'Enabled' } } ) ;
811
- const res_put = await s3_uid6 . putObject ( { Bucket : suspended_bucket_name , Key : tagging_key , Body : body1 } ) ;
812
- await s3_uid6 . putObject ( { Bucket : suspended_bucket_name , Key : tagging_key , Body : body1 } ) ;
814
+ await s3_uid6 . putBucketVersioning ( { Bucket : bucket_name , VersioningConfiguration : { MFADelete : 'Disabled' , Status : 'Enabled' } } ) ;
815
+ const res_put = await s3_uid6 . putObject ( { Bucket : bucket_name , Key : tagging_key , Body : body1 } ) ;
816
+ await s3_uid6 . putObject ( { Bucket : bucket_name , Key : tagging_key , Body : body1 } ) ;
813
817
version_id = res_put . VersionId ;
814
818
} ) ;
815
819
816
820
mocha . it ( "put object tagging - no versionId" , async function ( ) {
817
- await s3_uid6 . putObjectTagging ( { Bucket : suspended_bucket_name , Key : tagging_key , Tagging : tag_set1 } ) ;
818
- const res = await s3_uid6 . getObjectTagging ( { Bucket : suspended_bucket_name , Key : tagging_key } ) ;
821
+ await s3_uid6 . putObjectTagging ( { Bucket : bucket_name , Key : tagging_key , Tagging : tag_set1 } ) ;
822
+ const res = await s3_uid6 . getObjectTagging ( { Bucket : bucket_name , Key : tagging_key } ) ;
819
823
assert . deepEqual ( res . TagSet , tag_set1 . TagSet ) ;
820
824
} ) ;
821
825
822
826
mocha . it ( "put object tagging - specific versionId" , async function ( ) {
823
- await s3_uid6 . putObjectTagging ( { Bucket : suspended_bucket_name , Key : tagging_key , Tagging : tag_set2 , versionId : version_id } ) ;
824
- const res = await s3_uid6 . getObjectTagging ( { Bucket : suspended_bucket_name , Key : tagging_key } ) ;
827
+ await s3_uid6 . putObjectTagging ( { Bucket : bucket_name , Key : tagging_key , Tagging : tag_set2 , versionId : version_id } ) ;
828
+ const res = await s3_uid6 . getObjectTagging ( { Bucket : bucket_name , Key : tagging_key } ) ;
825
829
assert . notDeepEqual ( res . TagSet , tag_set2 ) ;
826
- const version_res = await s3_uid6 . getObjectTagging ( { Bucket : suspended_bucket_name , Key : tagging_key } ) ;
830
+ const version_res = await s3_uid6 . getObjectTagging ( { Bucket : bucket_name , Key : tagging_key } ) ;
827
831
assert . deepEqual ( version_res . TagSet , tag_set2 . TagSet ) ;
828
832
} ) ;
829
833
834
+ mocha . it ( "head object with tagging - test header x-amz-tagging-count (1 tag)" , async function ( ) {
835
+ await s3_uid6 . putBucketVersioning ( { Bucket : bucket_name , VersioningConfiguration : { MFADelete : 'Disabled' , Status : 'Enabled' } } ) ;
836
+ await s3_uid6 . putObjectTagging ( { Bucket : bucket_name , Key : tagging_key , Tagging : tag_set2 , versionId : version_id } ) ;
837
+ s3_uid6 . middlewareStack . add (
838
+ next => async args => {
839
+ const result = await next ( args ) ;
840
+ result . output . $metadata . headers = result . response . headers ;
841
+ return result ;
842
+ }
843
+ ) ;
844
+
845
+ const res = await s3_uid6 . headObject ( { Bucket : bucket_name , Key : tagging_key , versionId : version_id } ) ;
846
+ assert . equal ( res . $metadata . headers [ 'x-amz-tagging-count' ] , tag_set2 . TagSet . length ) ;
847
+ } ) ;
848
+
849
+ mocha . it ( "head object with tagging - test header x-amz-tagging-count (3 tags)" , async function ( ) {
850
+ await s3_uid6 . putBucketVersioning ( { Bucket : bucket_name , VersioningConfiguration : { MFADelete : 'Disabled' , Status : 'Enabled' } } ) ;
851
+ await s3_uid6 . putObjectTagging ( { Bucket : bucket_name , Key : tagging_key , Tagging : tag_set3 , versionId : version_id } ) ;
852
+ s3_uid6 . middlewareStack . add (
853
+ next => async args => {
854
+ const result = await next ( args ) ;
855
+ result . output . $metadata . headers = result . response . headers ;
856
+ return result ;
857
+ }
858
+ ) ;
859
+
860
+ const res = await s3_uid6 . headObject ( { Bucket : bucket_name , Key : tagging_key , versionId : version_id } ) ;
861
+ assert . equal ( res . $metadata . headers [ 'x-amz-tagging-count' ] , tag_set3 . TagSet . length ) ;
862
+ } ) ;
863
+
830
864
mocha . it ( "delete object tagging - no versionId" , async function ( ) {
831
- await s3_uid6 . deleteObjectTagging ( { Bucket : suspended_bucket_name , Key : tagging_key } ) ;
832
- const res = await s3_uid6 . getObjectTagging ( { Bucket : suspended_bucket_name , Key : tagging_key } ) ;
865
+ await s3_uid6 . deleteObjectTagging ( { Bucket : bucket_name , Key : tagging_key } ) ;
866
+ const res = await s3_uid6 . getObjectTagging ( { Bucket : bucket_name , Key : tagging_key } ) ;
833
867
assert . equal ( res . TagSet . length , 0 ) ;
834
868
} ) ;
835
869
836
870
mocha . it ( "delete object tagging - specific versionId" , async function ( ) {
837
- await s3_uid6 . deleteObjectTagging ( { Bucket : suspended_bucket_name , Key : tagging_key , versionId : version_id } ) ;
838
- const res = await s3_uid6 . getObjectTagging ( { Bucket : suspended_bucket_name , Key : tagging_key , versionId : version_id } ) ;
871
+ await s3_uid6 . deleteObjectTagging ( { Bucket : bucket_name , Key : tagging_key , versionId : version_id } ) ;
872
+ const res = await s3_uid6 . getObjectTagging ( { Bucket : bucket_name , Key : tagging_key , versionId : version_id } ) ;
839
873
assert . equal ( res . TagSet . length , 0 ) ;
840
874
} ) ;
841
875
} ) ;
@@ -2665,6 +2699,8 @@ mocha.describe('bucketspace namespace_fs - versioning', function() {
2665
2699
assert . fail ( 'Should fail' ) ;
2666
2700
} catch ( err ) {
2667
2701
assert . strictEqual ( err . $metadata . httpStatusCode , 405 ) ;
2702
+ assert . ok ( err . $response . headers [ 'last-modified' ] !== undefined , 'Should have last-modified header' ) ;
2703
+ assert . ok ( err . $response . headers [ 'x-amz-delete-marker' ] === 'true' , 'Should have x-amz-delete-marker header with value true' ) ;
2668
2704
// In headObject the AWS SDK doesn't return the err.Code
2669
2705
// In AWS CLI it looks:
2670
2706
// An error occurred (405) when calling the HeadObject operation: Method Not Allowed
@@ -2681,6 +2717,8 @@ mocha.describe('bucketspace namespace_fs - versioning', function() {
2681
2717
} catch ( err ) {
2682
2718
assert . strictEqual ( err . $metadata . httpStatusCode , 405 ) ;
2683
2719
assert . strictEqual ( err . Code , 'MethodNotAllowed' ) ;
2720
+ assert . ok ( err . $response . headers [ 'last-modified' ] !== undefined , 'Should have last-modified header' ) ;
2721
+ assert . ok ( err . $response . headers [ 'x-amz-delete-marker' ] === 'true' , 'Should have x-amz-delete-marker header with value true' ) ;
2684
2722
// In AWS CLI it looks:
2685
2723
// An error occurred (MethodNotAllowed) when calling the GetObject operation: The specified method is not allowed against this resource.
2686
2724
}
0 commit comments