@@ -86,6 +86,76 @@ Test(syslog_format, cisco_sequence_id_non_zero_termination)
86
86
log_msg_unref (msg );
87
87
}
88
88
89
+ Test (syslog_format , rfc3164_error_invalid_pri )
90
+ {
91
+ /* incorrect pri value */
92
+ const gchar * data = "<189 Feb 3 12:34:56 host program[pid]: message" ;
93
+ gsize data_length = strlen (data );
94
+
95
+ LogMessage * msg = log_msg_new_empty ();
96
+
97
+ gsize problem_position ;
98
+ cr_assert (syslog_format_handler (& parse_options , msg , (const guchar * ) data , data_length , & problem_position ));
99
+ assert_log_message_value_by_name (msg , "MSG" , "<189 Feb 3 12:34:56 host program[pid]: message" );
100
+ assert_log_message_has_tag (msg , "syslog.invalid_pri" );
101
+
102
+ log_msg_unref (msg );
103
+ }
104
+
105
+ Test (syslog_format , rfc3164_error_missing_timestamp )
106
+ {
107
+ /* incorrect pri value */
108
+ const gchar * data = "<189> program[pid]: message" ;
109
+ gsize data_length = strlen (data );
110
+
111
+ LogMessage * msg = log_msg_new_empty ();
112
+
113
+ gsize problem_position ;
114
+ cr_assert (syslog_format_handler (& parse_options , msg , (const guchar * ) data , data_length , & problem_position ));
115
+ /* without timestamp, host is not expected */
116
+ assert_log_message_value_by_name (msg , "HOST" , "" );
117
+ assert_log_message_value_by_name (msg , "PROGRAM" , "program" );
118
+ assert_log_message_value_by_name (msg , "PID" , "pid" );
119
+ assert_log_message_value_by_name (msg , "MSG" , "message" );
120
+ assert_log_message_value_by_name (msg , "MSGFORMAT" , "rfc3164" );
121
+ assert_log_message_has_tag (msg , "syslog.missing_timestamp" );
122
+ assert_log_message_has_tag (msg , "syslog.rfc3164_missing_header" );
123
+
124
+ log_msg_unref (msg );
125
+ }
126
+
127
+ Test (syslog_format , rfc5424_error_invalid_timestamp )
128
+ {
129
+ const gchar * data = "<189>1 2024-09-16Q11:22:33+02:00 host program pid msgid [foo bar=baz] message" ;
130
+ gsize data_length = strlen (data );
131
+
132
+ parse_options .flags |= LP_SYSLOG_PROTOCOL ;
133
+ LogMessage * msg = log_msg_new_empty ();
134
+
135
+ gsize problem_position ;
136
+ cr_assert_not (syslog_format_handler (& parse_options , msg , (const guchar * ) data , data_length , & problem_position ));
137
+ assert_log_message_value_by_name (msg , "MSGFORMAT" , "" );
138
+ assert_log_message_has_tag (msg , "syslog.missing_timestamp" );
139
+
140
+ log_msg_unref (msg );
141
+ }
142
+
143
+ Test (syslog_format , rfc5424_error_invalid_sdata )
144
+ {
145
+ const gchar * data = "<189>1 2024-09-16T11:22:33+02:00 host program pid msgid [foo bar=baz message" ;
146
+ gsize data_length = strlen (data );
147
+
148
+ parse_options .flags |= LP_SYSLOG_PROTOCOL ;
149
+ LogMessage * msg = log_msg_new_empty ();
150
+
151
+ gsize problem_position ;
152
+ cr_assert_not (syslog_format_handler (& parse_options , msg , (const guchar * ) data , data_length , & problem_position ));
153
+ assert_log_message_value_by_name (msg , "MSGFORMAT" , "" );
154
+ assert_log_message_has_tag (msg , "syslog.rfc5424_invalid_sdata" );
155
+
156
+ log_msg_unref (msg );
157
+ }
158
+
89
159
Test (syslog_format , rfc3164_style_message_when_parsed_as_rfc5424_is_marked_as_such_in_msgformat )
90
160
{
91
161
const gchar * data = "<189>Feb 3 12:34:56 host program[pid]: message" ;
0 commit comments