@@ -290,3 +290,74 @@ describe('NotificationConfiguration.restrictSupportedNotificationBasedOnLifecycl
290290 expect ( supportedNotificationEvents . has ( 's3:ObjectCreated:*' ) ) . toBeTruthy ( ) ;
291291 } ) ;
292292} ) ;
293+
294+ describe ( 'NotificationConfiguration.getConfigXML - XML escaping for special characters' , ( ) => {
295+ const specialCharacters = [ '&' , '<' , '>' , '"' , "'" ] ;
296+
297+ specialCharacters . forEach ( char => {
298+ it ( `should escape \`${ char } \` in notification ID and generate valid XML` , done => {
299+ const config = {
300+ queueConfig : [ {
301+ id : `test-id${ char } value` ,
302+ queueArn : 'arn:scality:bucketnotif:::target' ,
303+ events : [ 's3:ObjectCreated:*' ] ,
304+ filterRules : [ ] ,
305+ } ] ,
306+ } ;
307+
308+ const xml = NotificationConfiguration . getConfigXML ( config ) ;
309+
310+ parseString ( xml , ( err , result ) => {
311+ assert . ifError ( err ) ;
312+ const queueConfig = result . NotificationConfiguration . QueueConfiguration [ 0 ] ;
313+ assert . strictEqual ( queueConfig . Id [ 0 ] , `test-id${ char } value` ) ;
314+ done ( ) ;
315+ } ) ;
316+ } ) ;
317+
318+ it ( `should escape \`${ char } \` in queue ARN` , done => {
319+ const config = {
320+ queueConfig : [ {
321+ id : 'test-id' ,
322+ queueArn : `arn:scality:bucketnotif:::queue${ char } name` ,
323+ events : [ 's3:ObjectCreated:*' ] ,
324+ filterRules : [ ] ,
325+ } ] ,
326+ } ;
327+
328+ const xml = NotificationConfiguration . getConfigXML ( config ) ;
329+
330+ parseString ( xml , ( err , result ) => {
331+ assert . ifError ( err ) ;
332+ const queueConfig = result . NotificationConfiguration . QueueConfiguration [ 0 ] ;
333+ assert . strictEqual ( queueConfig . Queue [ 0 ] , `arn:scality:bucketnotif:::queue${ char } name` ) ;
334+ done ( ) ;
335+ } ) ;
336+ } ) ;
337+
338+ it ( `should escape \`${ char } \` in filter rule name and value` , done => {
339+ const config = {
340+ queueConfig : [ {
341+ id : 'test-id' ,
342+ queueArn : 'arn:scality:bucketnotif:::target' ,
343+ events : [ 's3:ObjectCreated:*' ] ,
344+ filterRules : [ {
345+ name : `Prefix${ char } Name` ,
346+ value : `logs/${ char } path` ,
347+ } ] ,
348+ } ] ,
349+ } ;
350+
351+ const xml = NotificationConfiguration . getConfigXML ( config ) ;
352+
353+ parseString ( xml , ( err , result ) => {
354+ assert . ifError ( err ) ;
355+ const queueConfig = result . NotificationConfiguration . QueueConfiguration [ 0 ] ;
356+ const filterRule = queueConfig . Filter [ 0 ] . S3Key [ 0 ] . FilterRule [ 0 ] ;
357+ assert . strictEqual ( filterRule . Name [ 0 ] , `Prefix${ char } Name` ) ;
358+ assert . strictEqual ( filterRule . Value [ 0 ] , `logs/${ char } path` ) ;
359+ done ( ) ;
360+ } ) ;
361+ } ) ;
362+ } ) ;
363+ } ) ;
0 commit comments