@@ -400,6 +400,85 @@ void flb_test_cloudwatch_error_put_retention_policy(void)
400400 flb_destroy (ctx );
401401}
402402
403+ void flb_test_cloudwatch_create_stream_escapes_json (void )
404+ {
405+ struct log_stream stream ;
406+ flb_sds_t body ;
407+ char * expected ;
408+ int ret ;
409+
410+ memset (& stream , 0 , sizeof (struct log_stream ));
411+ stream .group = flb_sds_create ("fluent" );
412+ stream .name = flb_sds_create ("systemd-fsck@dev-disk-by\\x2dlabel-BOOT.service" );
413+ TEST_CHECK (stream .group != NULL );
414+ TEST_CHECK (stream .name != NULL );
415+
416+ if (stream .group && stream .name ) {
417+ body = flb_cloudwatch_create_log_stream_body (& stream );
418+ TEST_CHECK (body != NULL );
419+
420+ if (body ) {
421+ expected = "{\"logGroupName\":\"fluent\","
422+ "\"logStreamName\":\"systemd-fsck@dev-disk-by\\\\x2dlabel-BOOT.service\"}" ;
423+ ret = strcmp (body , expected );
424+ TEST_CHECK (ret == 0 );
425+ flb_sds_destroy (body );
426+ }
427+ }
428+
429+ flb_sds_destroy (stream .group );
430+ flb_sds_destroy (stream .name );
431+ }
432+
433+ void flb_test_cloudwatch_put_events_escapes_stream_name (void )
434+ {
435+ struct flb_cloudwatch ctx ;
436+ struct log_stream stream ;
437+ struct cw_flush buf ;
438+ char out_buf [512 ];
439+ char * expected_stream_name ;
440+ char * expected ;
441+ int offset ;
442+ int ret ;
443+
444+ memset (& ctx , 0 , sizeof (struct flb_cloudwatch ));
445+ memset (& stream , 0 , sizeof (struct log_stream ));
446+ memset (& buf , 0 , sizeof (struct cw_flush ));
447+
448+ stream .group = flb_sds_create ("fluent" );
449+ stream .name = flb_sds_create ("systemd-fsck@dev-disk-by\\x2dlabel-BOOT.service" );
450+ TEST_CHECK (stream .group != NULL );
451+ TEST_CHECK (stream .name != NULL );
452+
453+ if (stream .group && stream .name ) {
454+ offset = 0 ;
455+ buf .out_buf = out_buf ;
456+ buf .out_buf_size = sizeof (out_buf );
457+ buf .current_stream = & stream ;
458+
459+ ret = flb_cloudwatch_init_put_payload (& ctx , & buf , & stream , & offset );
460+ TEST_CHECK (ret == 0 );
461+
462+ if (ret == 0 ) {
463+ expected = "{\"logGroupName\":\"fluent\","
464+ "\"logStreamName\":\"systemd-fsck@dev-disk-by\\\\x2dlabel-BOOT.service\","
465+ "\"logEvents\":[" ;
466+ TEST_CHECK (offset == strlen (expected ));
467+ TEST_CHECK (strncmp (out_buf , expected , offset ) == 0 );
468+ }
469+
470+ expected_stream_name = "systemd-fsck@dev-disk-by\\\\x2dlabel-BOOT.service" ;
471+ reset_flush_buf (& ctx , & buf );
472+ TEST_CHECK (buf .data_size == PUT_LOG_EVENTS_HEADER_LEN +
473+ PUT_LOG_EVENTS_FOOTER_LEN +
474+ strlen ("fluent" ) +
475+ strlen (expected_stream_name ));
476+ }
477+
478+ flb_sds_destroy (stream .group );
479+ flb_sds_destroy (stream .name );
480+ }
481+
403482/* Helper function to create a large JSON message of specified size */
404483static char * create_large_json_message (size_t target_size )
405484{
@@ -551,6 +630,8 @@ TEST_LIST = {
551630 {"put_retention_policy_success" , flb_test_cloudwatch_put_retention_policy_success },
552631 {"already_exists_create_group_put_retention_policy" , flb_test_cloudwatch_already_exists_create_group_put_retention_policy },
553632 {"error_put_retention_policy" , flb_test_cloudwatch_error_put_retention_policy },
633+ {"create_stream_escapes_json" , flb_test_cloudwatch_create_stream_escapes_json },
634+ {"put_events_escapes_stream_name" , flb_test_cloudwatch_put_events_escapes_stream_name },
554635 {"event_size_at_limit" , flb_test_cloudwatch_event_size_at_limit },
555636 {"event_size_over_limit" , flb_test_cloudwatch_event_size_over_limit },
556637 {"event_truncation_with_backslash" , flb_test_cloudwatch_event_truncation_with_backslash },
0 commit comments