@@ -439,6 +439,85 @@ void flb_test_cloudwatch_error_put_retention_policy(void)
439439 flb_destroy (ctx );
440440}
441441
442+ void flb_test_cloudwatch_create_stream_escapes_json (void )
443+ {
444+ struct log_stream stream ;
445+ flb_sds_t body ;
446+ char * expected ;
447+ int ret ;
448+
449+ memset (& stream , 0 , sizeof (struct log_stream ));
450+ stream .group = flb_sds_create ("fluent" );
451+ stream .name = flb_sds_create ("systemd-fsck@dev-disk-by\\x2dlabel-BOOT.service" );
452+ TEST_CHECK (stream .group != NULL );
453+ TEST_CHECK (stream .name != NULL );
454+
455+ if (stream .group && stream .name ) {
456+ body = flb_cloudwatch_create_log_stream_body (& stream );
457+ TEST_CHECK (body != NULL );
458+
459+ if (body ) {
460+ expected = "{\"logGroupName\":\"fluent\","
461+ "\"logStreamName\":\"systemd-fsck@dev-disk-by\\\\x2dlabel-BOOT.service\"}" ;
462+ ret = strcmp (body , expected );
463+ TEST_CHECK (ret == 0 );
464+ flb_sds_destroy (body );
465+ }
466+ }
467+
468+ flb_sds_destroy (stream .group );
469+ flb_sds_destroy (stream .name );
470+ }
471+
472+ void flb_test_cloudwatch_put_events_escapes_stream_name (void )
473+ {
474+ struct flb_cloudwatch ctx ;
475+ struct log_stream stream ;
476+ struct cw_flush buf ;
477+ char out_buf [512 ];
478+ char * expected_stream_name ;
479+ char * expected ;
480+ int offset ;
481+ int ret ;
482+
483+ memset (& ctx , 0 , sizeof (struct flb_cloudwatch ));
484+ memset (& stream , 0 , sizeof (struct log_stream ));
485+ memset (& buf , 0 , sizeof (struct cw_flush ));
486+
487+ stream .group = flb_sds_create ("fluent" );
488+ stream .name = flb_sds_create ("systemd-fsck@dev-disk-by\\x2dlabel-BOOT.service" );
489+ TEST_CHECK (stream .group != NULL );
490+ TEST_CHECK (stream .name != NULL );
491+
492+ if (stream .group && stream .name ) {
493+ offset = 0 ;
494+ buf .out_buf = out_buf ;
495+ buf .out_buf_size = sizeof (out_buf );
496+ buf .current_stream = & stream ;
497+
498+ ret = flb_cloudwatch_init_put_payload (& ctx , & buf , & stream , & offset );
499+ TEST_CHECK (ret == 0 );
500+
501+ if (ret == 0 ) {
502+ expected = "{\"logGroupName\":\"fluent\","
503+ "\"logStreamName\":\"systemd-fsck@dev-disk-by\\\\x2dlabel-BOOT.service\","
504+ "\"logEvents\":[" ;
505+ TEST_CHECK (offset == strlen (expected ));
506+ TEST_CHECK (strncmp (out_buf , expected , offset ) == 0 );
507+ }
508+
509+ expected_stream_name = "systemd-fsck@dev-disk-by\\\\x2dlabel-BOOT.service" ;
510+ reset_flush_buf (& ctx , & buf );
511+ TEST_CHECK (buf .data_size == PUT_LOG_EVENTS_HEADER_LEN +
512+ PUT_LOG_EVENTS_FOOTER_LEN +
513+ strlen ("fluent" ) +
514+ strlen (expected_stream_name ));
515+ }
516+
517+ flb_sds_destroy (stream .group );
518+ flb_sds_destroy (stream .name );
519+ }
520+
442521/* Helper function to create a large JSON message of specified size */
443522static char * create_large_json_message (size_t target_size )
444523{
@@ -591,6 +670,8 @@ TEST_LIST = {
591670 {"put_retention_policy_success" , flb_test_cloudwatch_put_retention_policy_success },
592671 {"already_exists_create_group_put_retention_policy" , flb_test_cloudwatch_already_exists_create_group_put_retention_policy },
593672 {"error_put_retention_policy" , flb_test_cloudwatch_error_put_retention_policy },
673+ {"create_stream_escapes_json" , flb_test_cloudwatch_create_stream_escapes_json },
674+ {"put_events_escapes_stream_name" , flb_test_cloudwatch_put_events_escapes_stream_name },
594675 {"event_size_at_limit" , flb_test_cloudwatch_event_size_at_limit },
595676 {"event_size_over_limit" , flb_test_cloudwatch_event_size_over_limit },
596677 {"event_truncation_with_backslash" , flb_test_cloudwatch_event_truncation_with_backslash },
0 commit comments