@@ -7,25 +7,22 @@ const {
77 listVersionsRes,
88 listVersionWithMarkerRes,
99 getMetadataRes,
10+ objectMd,
1011} = require ( '../../utils/crr' ) ;
1112
1213const logger = new werelogs . Logger ( 'ReplicationStatusUpdater::tests' , 'debug' , 'debug' ) ;
1314
1415describe ( 'ReplicationStatusUpdater' , ( ) => {
15- let crr ;
16-
17- beforeEach ( ( ) => {
18- crr = initializeCrrWithMocks ( {
16+ it ( 'should process bucket for CRR' , done => {
17+ const crr = initializeCrrWithMocks ( {
1918 buckets : [ 'bucket0' ] ,
2019 workers : 10 ,
2120 replicationStatusToProcess : [ 'NEW' ] ,
2221 targetPrefix : 'toto' ,
2322 listingLimit : 10 ,
2423 siteName : 'aws-location' ,
2524 } , logger ) ;
26- } ) ;
2725
28- it ( 'should process bucket for CRR' , done => {
2926 crr . run ( err => {
3027 assert . ifError ( err ) ;
3128
@@ -66,7 +63,7 @@ describe('ReplicationStatusUpdater', () => {
6663 } ,
6764 ] ,
6865 content : [ 'METADATA' , 'DATA' ] ,
69- destination : 'arn:aws:s3:::sourcebucket ' ,
66+ destination : 'arn:aws:s3:::destination ' ,
7067 storageClass : 'aws-location' ,
7168 role : 'arn:aws:iam::root:role/s3-replication-role' ,
7269 storageType : '' ,
@@ -88,7 +85,7 @@ describe('ReplicationStatusUpdater', () => {
8885 } ) ;
8986
9087 it ( 'should process bucket for CRR with multiple objects' , done => {
91- crr = initializeCrrWithMocks ( {
88+ const crr = initializeCrrWithMocks ( {
9289 buckets : [ 'bucket0' ] ,
9390 workers : 10 ,
9491 replicationStatusToProcess : [ 'NEW' ] ,
@@ -159,7 +156,7 @@ describe('ReplicationStatusUpdater', () => {
159156 } ,
160157 ] ,
161158 content : [ 'METADATA' , 'DATA' ] ,
162- destination : 'arn:aws:s3:::sourcebucket ' ,
159+ destination : 'arn:aws:s3:::destination ' ,
163160 storageClass : 'aws-location' ,
164161 role : 'arn:aws:iam::root:role/s3-replication-role' ,
165162 storageType : 'aws_s3' ,
@@ -188,7 +185,7 @@ describe('ReplicationStatusUpdater', () => {
188185 } ,
189186 ] ,
190187 content : [ 'METADATA' , 'DATA' ] ,
191- destination : 'arn:aws:s3:::sourcebucket ' ,
188+ destination : 'arn:aws:s3:::destination ' ,
192189 storageClass : 'aws-location' ,
193190 role : 'arn:aws:iam::root:role/s3-replication-role' ,
194191 storageType : 'aws_s3' ,
@@ -206,7 +203,7 @@ describe('ReplicationStatusUpdater', () => {
206203 } ,
207204 ] ,
208205 content : [ 'METADATA' , 'DATA' ] ,
209- destination : 'arn:aws:s3:::sourcebucket ' ,
206+ destination : 'arn:aws:s3:::destination ' ,
210207 storageClass : 'aws-location' ,
211208 role : 'arn:aws:iam::root:role/s3-replication-role' ,
212209 storageType : 'aws_s3' ,
@@ -223,7 +220,7 @@ describe('ReplicationStatusUpdater', () => {
223220 } ,
224221 ] ,
225222 content : [ 'METADATA' , 'DATA' ] ,
226- destination : 'arn:aws:s3:::sourcebucket ' ,
223+ destination : 'arn:aws:s3:::destination ' ,
227224 storageClass : 'aws-location' ,
228225 role : 'arn:aws:iam::root:role/s3-replication-role' ,
229226 storageType : 'aws_s3' ,
@@ -241,7 +238,7 @@ describe('ReplicationStatusUpdater', () => {
241238 } ,
242239 ] ,
243240 content : [ 'METADATA' , 'DATA' ] ,
244- destination : 'arn:aws:s3:::sourcebucket ' ,
241+ destination : 'arn:aws:s3:::destination ' ,
245242 storageClass : 'aws-location' ,
246243 role : 'arn:aws:iam::root:role/s3-replication-role' ,
247244 storageType : 'aws_s3' ,
@@ -258,7 +255,7 @@ describe('ReplicationStatusUpdater', () => {
258255 } ,
259256 ] ,
260257 content : [ 'METADATA' , 'DATA' ] ,
261- destination : 'arn:aws:s3:::sourcebucket ' ,
258+ destination : 'arn:aws:s3:::destination ' ,
262259 storageClass : 'aws-location' ,
263260 role : 'arn:aws:iam::root:role/s3-replication-role' ,
264261 storageType : 'aws_s3' ,
@@ -281,7 +278,7 @@ describe('ReplicationStatusUpdater', () => {
281278 } ,
282279 ] ,
283280 content : [ 'METADATA' , 'DATA' ] ,
284- destination : 'arn:aws:s3:::sourcebucket ' ,
281+ destination : 'arn:aws:s3:::destination ' ,
285282 storageClass : 'azure-location,aws-location' ,
286283 role : 'arn:aws:iam::root:role/s3-replication-role' ,
287284 storageType : 'azure,aws_s3' ,
@@ -302,7 +299,7 @@ describe('ReplicationStatusUpdater', () => {
302299 } ,
303300 ] ,
304301 content : [ 'METADATA' , 'DATA' ] ,
305- destination : 'arn:aws:s3:::sourcebucket ' ,
302+ destination : 'arn:aws:s3:::destination ' ,
306303 storageClass : 'azure-location,aws-location' ,
307304 role : 'arn:aws:iam::root:role/s3-replication-role' ,
308305 storageType : 'azure,aws_s3' ,
@@ -325,7 +322,7 @@ describe('ReplicationStatusUpdater', () => {
325322 } ,
326323 ] ,
327324 content : [ 'METADATA' , 'DATA' ] ,
328- destination : 'arn:aws:s3:::sourcebucket ' ,
325+ destination : 'arn:aws:s3:::destination ' ,
329326 storageClass : 'azure-location,azure-location-2' ,
330327 role : 'arn:aws:iam::root:role/s3-replication-role' ,
331328 storageType : 'azure,azure' ,
@@ -350,7 +347,7 @@ describe('ReplicationStatusUpdater', () => {
350347 } ,
351348 ] ,
352349 content : [ 'METADATA' , 'DATA' ] ,
353- destination : 'arn:aws:s3:::sourcebucket ' ,
350+ destination : 'arn:aws:s3:::destination ' ,
354351 storageClass : 'azure-location,azure-location-2,aws-location' ,
355352 role : 'arn:aws:iam::root:role/s3-replication-role' ,
356353 storageType : 'azure,azure,aws_s3' ,
@@ -359,6 +356,14 @@ describe('ReplicationStatusUpdater', () => {
359356 } ,
360357 ] . forEach ( params => {
361358 it ( `should trigger replication ${ params . description } ` , done => {
359+ const crr = initializeCrrWithMocks ( {
360+ buckets : [ 'bucket0' ] ,
361+ workers : 10 ,
362+ replicationStatusToProcess : [ 'NEW' ] ,
363+ targetPrefix : 'toto' ,
364+ listingLimit : 10 ,
365+ siteName : 'aws-location' ,
366+ } , logger ) ;
362367 crr . bb . getMetadata = jest . fn ( ( p , cb ) => {
363368 const objectMd = JSON . parse ( getMetadataRes . Body ) ;
364369 objectMd . replicationInfo = params . replicationInfo ;
@@ -578,6 +583,63 @@ describe('ReplicationStatusUpdater with specifics', () => {
578583 } ) ;
579584} ) ;
580585
586+ describe ( 'ReplicationStatusUpdater with forceUsingConfiguration' , ( ) => {
587+ it ( 'should overwrite replication destination and role when forceUsingConfiguration is true' , done => {
588+ // Deep copy objectMd from utils to avoid affecting the original
589+ const objectMdWithOldReplication = JSON . parse ( JSON . stringify ( objectMd ) ) ;
590+
591+ // Only modify the replicationInfo part
592+ objectMdWithOldReplication . replicationInfo = {
593+ status : 'COMPLETED' ,
594+ backends : [
595+ {
596+ site : 'sf' ,
597+ status : 'COMPLETED' ,
598+ dataStoreVersionId : '' ,
599+ } ,
600+ ] ,
601+ content : [ 'DATA' , 'METADATA' ] ,
602+ destination : 'arn:aws:s3:::destination2' ,
603+ storageClass : 'sf' ,
604+ role : 'arn:aws:iam::123456789012:role/src-resource,arn:aws:iam::123456789012:role/dest-resource' ,
605+ storageType : '' ,
606+ dataStoreVersionId : '' ,
607+ } ;
608+
609+ const crr = initializeCrrWithMocks ( {
610+ buckets : [ 'bucket0' ] ,
611+ workers : 10 ,
612+ replicationStatusToProcess : [ 'NEW' ] ,
613+ forceUsingConfiguration : true ,
614+ } , logger ) ;
615+
616+ // Override getMetadata to return object with old replication info
617+ crr . bb . getMetadata = jest . fn ( ( params , cb ) => cb ( null , {
618+ Body : JSON . stringify ( objectMdWithOldReplication ) ,
619+ } ) ) ;
620+
621+ crr . run ( err => {
622+ assert . ifError ( err ) ;
623+
624+ expect ( crr . bb . putMetadata ) . toHaveBeenCalledTimes ( 1 ) ;
625+
626+ // Verify that putMetadata was called with updated destination and role from bucket config
627+ const putMetadataCall = crr . bb . putMetadata . mock . calls [ 0 ] [ 0 ] ;
628+ const updatedMetadata = JSON . parse ( putMetadataCall . Body ) ;
629+
630+ // Check that replicationInfo contains the bucket configuration values
631+ expect ( updatedMetadata . replicationInfo . destination ) . toBe ( 'arn:aws:s3:::destination' ) ;
632+ expect ( updatedMetadata . replicationInfo . role ) . toBe ( 'arn:aws:iam::root:role/s3-replication-role' ) ;
633+
634+ assert . strictEqual ( crr . _nProcessed , 1 ) ;
635+ assert . strictEqual ( crr . _nSkipped , 0 ) ;
636+ assert . strictEqual ( crr . _nUpdated , 1 ) ;
637+ assert . strictEqual ( crr . _nErrors , 0 ) ;
638+ done ( ) ;
639+ } ) ;
640+ } ) ;
641+ } ) ;
642+
581643describe ( 'ReplicationStatusUpdater with currentVersionOnly' , ( ) => {
582644 it ( 'should process only latest versions when currentVersionOnly is true' , done => {
583645 const listVersionsWithMixedLatest = {
0 commit comments