forked from newrelic/newrelic-php-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_rules.c
626 lines (554 loc) · 20.6 KB
/
test_rules.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include "nr_axiom.h"
#include <stddef.h>
#include "nr_rules.h"
#include "nr_rules_private.h"
#include "util_memory.h"
#include "util_strings.h"
#include "util_text.h"
#include "tlib_main.h"
#define rules_apply_testcase(...) \
rules_apply_testcase_fn(__VA_ARGS__, __FILE__, __LINE__)
static void rules_apply_testcase_fn(const char* testname,
const nrrules_t* rules,
const char* input,
const char* expected,
const char* file,
int line) {
nr_rules_result_t rv;
char* output = 0;
rv = nr_rules_apply(rules, input, &output);
if (0 == nr_strcmp(input, expected)) {
if (NR_RULES_RESULT_CHANGED == (int)rv) {
/*
* NR_RULES_RESULT_CHANGED expected and rule makes input and output the
* same.
*/
test_pass_if_true(testname, NR_RULES_RESULT_CHANGED == rv, "rv=%d",
(int)rv);
test_pass_if_true(testname, 0 == nr_strcmp(output, expected),
"output=%s expected=%s", NRSAFESTR(output),
NRSAFESTR(expected));
} else {
/*
* NR_RULES_RESULT_UNCHANGED expected.
*/
test_pass_if_true(testname, NR_RULES_RESULT_UNCHANGED == rv, "rv=%d",
(int)rv);
test_pass_if_true(testname, 0 == output, "output=%p", output);
}
} else if (0 == expected) {
/*
* NR_RULES_RESULT_IGNORE expected.
*/
test_pass_if_true(testname, NR_RULES_RESULT_IGNORE == rv, "rv=%d", (int)rv);
test_pass_if_true(testname, 0 == output, "output=%p", output);
} else {
/*
* NR_RULES_RESULT_CHANGED expected.
*/
test_pass_if_true(testname, NR_RULES_RESULT_CHANGED == rv, "rv=%d",
(int)rv);
test_pass_if_true(testname, 0 == nr_strcmp(output, expected),
"output=%s expected=%s", NRSAFESTR(output),
NRSAFESTR(expected));
}
nr_free(output);
}
#define rule_parsing_testcase(N, R, M, P, O, F) \
rule_parsing_testcase_fn((N), (R), (M), (P), (O), (F), __FILE__, __LINE__)
static void rule_parsing_testcase_fn(const char* testname,
const nrrules_t* rules,
const char* match,
const char* replacement,
int order,
int rflags,
const char* file,
int line) {
test_pass_if_true(testname, rules && rules->rules && (1 == rules->nrules),
"rules=%p", rules);
if (rules && rules->rules && (1 == rules->nrules)) {
nrrule_t* r = rules->rules;
test_pass_if_true(testname, 0 == nr_strcmp(match, r->match),
"match=%s r->match=%s", match, r->match);
test_pass_if_true(testname, 0 == nr_strcmp(replacement, r->replacement),
"replacement=%s r->replacement=%s", replacement,
r->replacement);
test_pass_if_true(testname, order == r->order, "order=%d r->order=%d",
order, r->order);
test_pass_if_true(testname, rflags == r->rflags, "rflags=%d r->rflags=%d",
rflags, r->rflags);
test_pass_if_true(testname, NULL != r->regex, "r->regex=%p", r->regex);
}
}
static nrrules_t* build_rules(const char* str) {
nrobj_t* ob = nro_create_from_json(str);
nrrules_t* rs = nr_rules_create_from_obj(ob);
nro_delete(ob);
return rs;
}
static void test_rule_parsing(void) {
nrrules_t* ur;
/*
* Test : Rule parsing and creation.
*
* These are the default url_rules as sent by the collector.
*
* One escape '\' is needed to create the string in the test source and a
* second '\' is needed for the JSON parsing. Hence the \\\\1.
*/
ur = build_rules(
"["
"{\"match_expression\":\"^(test_match_nothing)$\","
"\"replacement\":\"\\\\1\","
"\"each_segment\":false, "
"\"eval_order\":0, "
"\"ignore\":false, "
"\"replace_all\":false, "
"\"terminate_chain\":true}]");
rule_parsing_testcase("default rule", ur, "^(test_match_nothing)$", "\\1", 0,
NR_RULE_TERMINATE | NR_RULE_HAS_CAPTURES);
nr_rules_destroy(&ur);
ur = build_rules(
"["
"{\"match_expression\":\"^(test_match_nothing)$\","
"\"replacement\":\"\\\\1\","
"\"each_segment\":false, "
"\"eval_order\":0, "
"\"ignore\":false, "
"\"replace_all\":false, "
"\"terminate_chain\":true}]");
rule_parsing_testcase("default rule", ur, "^(test_match_nothing)$", "\\1", 0,
NR_RULE_TERMINATE | NR_RULE_HAS_CAPTURES);
nr_rules_destroy(&ur);
ur = build_rules(
"["
"{\"match_expression\":\".*\\\\.(css|gif|ico|jpe?g|js|png|swf)$\","
"\"replacement\":\"\\/*.\\\\1\","
"\"each_segment\":false, "
"\"eval_order\":0, "
"\"ignore\":false, "
"\"replace_all\":false, "
"\"terminate_chain\":true}]");
rule_parsing_testcase(
"default rule", ur, ".*\\.(css|gif|ico|jpe?g|js|png|swf)$", "/*.\\1", 0,
NR_RULE_TERMINATE | NR_RULE_HAS_CAPTURES | NR_RULE_HAS_ALTS);
nr_rules_destroy(&ur);
ur = build_rules(
"["
"{\"match_expression\":\".*\\\\.(css|gif|ico|jpe?g|js|png|swf)$\","
"\"replacement\":\"\\/*.\\\\1\","
"\"each_segment\":false, "
"\"eval_order\":0, "
"\"ignore\":false, "
"\"replace_all\":false, "
"\"terminate_chain\":true}]");
rule_parsing_testcase(
"default rule", ur, ".*\\.(css|gif|ico|jpe?g|js|png|swf)$", "/*.\\1", 0,
NR_RULE_TERMINATE | NR_RULE_HAS_CAPTURES | NR_RULE_HAS_ALTS);
nr_rules_destroy(&ur);
ur = build_rules(
"["
"{\"match_expression\":\"^(test_match_nothing)$\","
"\"replacement\":\"\\\\1\","
"\"each_segment\":false, "
"\"eval_order\":0, "
"\"ignore\":false, "
"\"replace_all\":false, "
"\"terminate_chain\":true}]");
rule_parsing_testcase("default rule", ur, "^(test_match_nothing)$", "\\1", 0,
NR_RULE_TERMINATE | NR_RULE_HAS_CAPTURES);
nr_rules_destroy(&ur);
ur = build_rules(
"["
"{\"match_expression\":\".*\\\\.(css|gif|ico|jpe?g|js|png|swf)$\","
"\"replacement\":\"\\/*.\\\\1\","
"\"each_segment\":false, "
"\"eval_order\":0, "
"\"ignore\":false, "
"\"replace_all\":false, "
"\"terminate_chain\":true}]");
rule_parsing_testcase(
"default rule", ur, ".*\\.(css|gif|ico|jpe?g|js|png|swf)$", "/*.\\1", 0,
NR_RULE_TERMINATE | NR_RULE_HAS_CAPTURES | NR_RULE_HAS_ALTS);
nr_rules_destroy(&ur);
ur = build_rules(
"["
"{\"match_expression\":\"^(test_match_nothing)$\","
"\"replacement\":\"\\\\1\","
"\"each_segment\":false, "
"\"eval_order\":0, "
"\"ignore\":false, "
"\"replace_all\":false, "
"\"terminate_chain\":true}]");
rule_parsing_testcase("default rule", ur, "^(test_match_nothing)$", "\\1", 0,
NR_RULE_TERMINATE | NR_RULE_HAS_CAPTURES);
nr_rules_destroy(&ur);
ur = build_rules(
"["
"{\"match_expression\":\".*\\\\.(css|gif|ico|jpe?g|js|png|swf)$\","
"\"replacement\":\"\\/*.\\\\1\","
"\"each_segment\":false, "
"\"eval_order\":0, "
"\"ignore\":false, "
"\"replace_all\":false, "
"\"terminate_chain\":true}]");
rule_parsing_testcase(
"default rule", ur, ".*\\.(css|gif|ico|jpe?g|js|png|swf)$", "/*.\\1", 0,
NR_RULE_TERMINATE | NR_RULE_HAS_CAPTURES | NR_RULE_HAS_ALTS);
nr_rules_destroy(&ur);
ur = build_rules(
"["
"{\"match_expression\":\"^[0-9][0-9a-f_,.-]*$\","
"\"replacement\":\"*\","
"\"each_segment\":true, "
"\"eval_order\":1, "
"\"ignore\":false, "
"\"replace_all\":false, "
"\"terminate_chain\":false}]");
rule_parsing_testcase("default rule", ur, "^[0-9][0-9a-f_,.-]*$", "*", 1,
NR_RULE_EACH_SEGMENT);
nr_rules_destroy(&ur);
ur = build_rules(
"["
"{\"match_expression\":\"^[0-9][0-9a-f_,.-]*$\","
"\"replacement\":\"*\","
"\"each_segment\":true, "
"\"eval_order\":1, "
"\"ignore\":false, "
"\"replace_all\":false, "
"\"terminate_chain\":false}]");
rule_parsing_testcase("default rule", ur, "^[0-9][0-9a-f_,.-]*$", "*", 1,
NR_RULE_EACH_SEGMENT);
nr_rules_destroy(&ur);
ur = build_rules(
"["
"{\"match_expression\":\"^[0-9][0-9a-f_,.-]*$\","
"\"replacement\":\"*\","
"\"each_segment\":true, "
"\"eval_order\":1, "
"\"ignore\":false, "
"\"replace_all\":false, "
"\"terminate_chain\":false}]");
rule_parsing_testcase("default rule", ur, "^[0-9][0-9a-f_,.-]*$", "*", 1,
NR_RULE_EACH_SEGMENT);
nr_rules_destroy(&ur);
ur = build_rules(
"["
"{\"match_expression\":\"^[0-9][0-9a-f_,.-]*$\","
"\"replacement\":\"*\","
"\"each_segment\":true, "
"\"eval_order\":1, "
"\"ignore\":false, "
"\"replace_all\":false, "
"\"terminate_chain\":false}]");
rule_parsing_testcase("default rule", ur, "^[0-9][0-9a-f_,.-]*$", "*", 1,
NR_RULE_EACH_SEGMENT);
nr_rules_destroy(&ur);
ur = build_rules(
"["
"{\"match_expression\":\"^(.*)\\/"
"[0-9][0-9a-f_,-]*\\\\.([0-9a-z][0-9a-z]*)$\","
"\"replacement\":\"\\\\1\\/.*\\\\2\","
"\"each_segment\":false, "
"\"eval_order\":2, "
"\"ignore\":false, "
"\"replace_all\":false, "
"\"terminate_chain\":false}]");
rule_parsing_testcase("default rule", ur,
"^(.*)/[0-9][0-9a-f_,-]*\\.([0-9a-z][0-9a-z]*)$",
"\\1/.*\\2", 2, NR_RULE_HAS_CAPTURES);
nr_rules_destroy(&ur);
ur = build_rules(
"["
"{\"match_expression\":\"^(.*)\\/"
"[0-9][0-9a-f_,-]*\\\\.([0-9a-z][0-9a-z]*)$\","
"\"replacement\":\"\\\\1\\/.*\\\\2\","
"\"each_segment\":false, "
"\"eval_order\":2, "
"\"ignore\":false, "
"\"replace_all\":false, "
"\"terminate_chain\":false}]");
rule_parsing_testcase("default rule", ur,
"^(.*)/[0-9][0-9a-f_,-]*\\.([0-9a-z][0-9a-z]*)$",
"\\1/.*\\2", 2, NR_RULE_HAS_CAPTURES);
nr_rules_destroy(&ur);
ur = build_rules(
"["
"{\"match_expression\":\"^(.*)\\/"
"[0-9][0-9a-f_,-]*\\\\.([0-9a-z][0-9a-z]*)$\","
"\"replacement\":\"\\\\1\\/.*\\\\2\","
"\"each_segment\":false, "
"\"eval_order\":2, "
"\"ignore\":false, "
"\"replace_all\":false, "
"\"terminate_chain\":false}]");
rule_parsing_testcase("default rule", ur,
"^(.*)/[0-9][0-9a-f_,-]*\\.([0-9a-z][0-9a-z]*)$",
"\\1/.*\\2", 2, NR_RULE_HAS_CAPTURES);
nr_rules_destroy(&ur);
ur = build_rules(
"["
"{\"match_expression\":\"^(.*)\\/"
"[0-9][0-9a-f_,-]*\\\\.([0-9a-z][0-9a-z]*)$\","
"\"replacement\":\"\\\\1\\/.*\\\\2\","
"\"each_segment\":false, "
"\"eval_order\":2, "
"\"ignore\":false, "
"\"replace_all\":false, "
"\"terminate_chain\":false}]");
rule_parsing_testcase("default rule", ur,
"^(.*)/[0-9][0-9a-f_,-]*\\.([0-9a-z][0-9a-z]*)$",
"\\1/.*\\2", 2, NR_RULE_HAS_CAPTURES);
nr_rules_destroy(&ur);
}
static void test_cross_agent_rule_tests(void) {
char* json = 0;
nrobj_t* array = 0;
nrotype_t otype;
int i;
#define RULES_TESTS_FILE CROSS_AGENT_TESTS_DIR "/rules.json"
json = nr_read_file_contents(RULES_TESTS_FILE, 10 * 1000 * 1000);
tlib_pass_if_true("tests valid", 0 != json, "json=%p", json);
if (0 == json) {
return;
}
array = nro_create_from_json(json);
tlib_pass_if_true("tests valid", 0 != array, "array=%p", array);
otype = nro_type(array);
tlib_pass_if_true("tests valid", NR_OBJECT_ARRAY == otype, "otype=%d",
(int)otype);
if (array && (NR_OBJECT_ARRAY == nro_type(array))) {
for (i = 1; i <= nro_getsize(array); i++) {
int j;
const nrobj_t* hash = nro_get_array_hash(array, i, 0);
const char* testname = nro_get_hash_string(hash, "testname", 0);
const nrobj_t* rules_obj = nro_get_hash_array(hash, "rules", 0);
const nrobj_t* test_cases = nro_get_hash_array(hash, "tests", 0);
nrrules_t* rules;
rules = nr_rules_create_from_obj(rules_obj);
tlib_pass_if_true("tests valid", 0 != rules, "rules=%p", rules);
tlib_pass_if_true("tests valid", 0 != test_cases, "test_cases=%p",
test_cases);
if (test_cases && (NR_OBJECT_ARRAY == nro_type(test_cases))) {
for (j = 1; j <= nro_getsize(test_cases); j++) {
const nrobj_t* h = nro_get_array_hash(test_cases, j, 0);
const char* input = nro_get_hash_string(h, "input", 0);
const char* expected = nro_get_hash_string(h, "expected", 0);
tlib_pass_if_true("tests valid", 0 != h, "h=%p", h);
tlib_pass_if_true("tests valid", 0 != input, "input=%p", input);
rules_apply_testcase(testname ? testname : input, rules, input,
expected);
}
}
nr_rules_destroy(&rules);
}
}
nro_delete(array);
nr_free(json);
}
#define process_rule_testcase(...) \
process_rule_testcase_fn(__VA_ARGS__, __FILE__, __LINE__)
static void process_rule_testcase_fn(const char* json,
int flags,
int order,
const char* match,
const char* replacement,
const char* file,
int line) {
nrobj_t* rule_obj = nro_create_from_json(json);
nrrules_t* rules = nr_rules_create(100);
nr_rules_process_rule(rules, rule_obj);
test_pass_if_true("test valid", 0 != rule_obj, "rule_obj=%p", rule_obj);
if (0 == match) {
/*
* If 0 == match then it is expected that adding the rule should fail.
*/
test_pass_if_true("no rule added", 0 == rules->nrules, "json=%s nrules=%d",
json, rules->nrules);
} else {
nrrule_t* rule = &rules->rules[0];
test_pass_if_true("number rules increased", 1 == rules->nrules,
"json=%s nrules=%d", json, rules->nrules);
test_pass_if_true("rule added", 0 != rule, "json=%s rule=%p", json, rule);
if (rule) {
test_pass_if_true("correct flags", flags == rule->rflags,
"json=%s flags=%d rule->rflags=%d", json, flags,
rule->rflags);
test_pass_if_true("correct order", order == rule->order,
"json=%s order=%d rule->order=%d", json, order,
rule->order);
test_pass_if_true("correct match", 0 == nr_strcmp(match, rule->match),
"json=%s match=%s rule->match=%s", json,
NRSAFESTR(match), NRSAFESTR(rule->match));
test_pass_if_true("correct replacement",
0 == nr_strcmp(replacement, rule->replacement),
"json=%s replacement=%s rule->replacement=%s", json,
NRSAFESTR(replacement), NRSAFESTR(rule->replacement));
}
}
nr_rules_destroy(&rules);
nro_delete(rule_obj);
}
static void test_process_rule(void) {
/*
* Test : Bad Parameters
*/
/* Don't blow up! */
nr_rules_process_rule(0, 0);
/* Wrong type */
process_rule_testcase("[1,2,3]", 0, 0, 0, 0);
/* Missing match_expression */
process_rule_testcase(
"{\"replace_all\":false,"
"\"terminate_chain\":true,"
"\"eval_order\":0,"
"\"replacement\":\"\\1\","
"\"each_segment\":false,"
"\"ignore\":false}",
0, 0, 0, 0);
/* Missing replacement */
process_rule_testcase(
"{\"match_expression\":\"^(test_match_nothing)$\","
"\"replace_all\":false,"
"\"terminate_chain\":true,"
"\"eval_order\":0,"
"\"each_segment\":false,"
"\"ignore\":false}",
0, 0, 0, 0);
/*
* Test : Success
*/
/* Basic */
process_rule_testcase(
"{\"match_expression\":\"alpha\","
"\"replacement\":\"beta\"}",
0, NR_RULE_DEFAULT_ORDER, "alpha", "beta");
/* Each Segment */
process_rule_testcase(
"{\"match_expression\":\"alpha\","
"\"replacement\":\"beta\","
"\"each_segment\":true}",
NR_RULE_EACH_SEGMENT, NR_RULE_DEFAULT_ORDER, "alpha", "beta");
/* Replace All */
process_rule_testcase(
"{\"match_expression\":\"alpha\","
"\"replacement\":\"beta\","
"\"replace_all\":true}",
NR_RULE_REPLACE_ALL, NR_RULE_DEFAULT_ORDER, "alpha", "beta");
/* Each Segment */
process_rule_testcase(
"{\"match_expression\":\"alpha\","
"\"replacement\":\"beta\","
"\"each_segment\":true}",
NR_RULE_EACH_SEGMENT, NR_RULE_DEFAULT_ORDER, "alpha", "beta");
/* Ignore (no replacement) */
process_rule_testcase(
"{\"match_expression\":\"alpha\","
"\"ignore\":true}",
NR_RULE_IGNORE, NR_RULE_DEFAULT_ORDER, "alpha", 0);
/* Terminate Chain */
process_rule_testcase(
"{\"match_expression\":\"alpha\","
"\"replacement\":\"beta\","
"\"terminate_chain\":true}",
NR_RULE_TERMINATE, NR_RULE_DEFAULT_ORDER, "alpha", "beta");
/* Eval Order */
process_rule_testcase(
"{\"match_expression\":\"alpha\","
"\"replacement\":\"beta\","
"\"eval_order\":55}",
0, 55, "alpha", "beta");
/* Has Alts */
process_rule_testcase(
"{\"match_expression\":\"alpha|gamma\","
"\"replacement\":\"beta\"}",
NR_RULE_HAS_ALTS, NR_RULE_DEFAULT_ORDER, "alpha|gamma", "beta");
/* Has Captures */
process_rule_testcase(
"{\"match_expression\":\"alpha\","
"\"replacement\":\"\\\\0\"}",
NR_RULE_HAS_CAPTURES, NR_RULE_DEFAULT_ORDER, "alpha", "\\0");
}
static void test_create_from_obj_bad_params(void) {
nrrules_t* rules;
nrobj_t* not_hash = nro_new(NR_OBJECT_INT);
rules = nr_rules_create_from_obj(0);
tlib_pass_if_true("null param", 0 == rules, "rules=%p", rules);
rules = nr_rules_create_from_obj(not_hash);
tlib_pass_if_true("wrong type", 0 == rules, "rules=%p", rules);
nro_delete(not_hash);
}
static void test_replace_string(void) {
int study = 1;
char dest[64];
const char* pattern = "^.*(abc).*(stu)";
nr_regex_t* regex = nr_regex_create(
pattern, NR_REGEX_CASELESS | NR_REGEX_DOLLAR_ENDONLY | NR_REGEX_DOTALL,
study);
const char* subject;
int slen;
nr_regex_substrings_t* ss = 0;
subject = "rrabcbqrstuas111";
slen = nr_strlen(subject);
ss = nr_regex_match_capture(regex, subject, slen);
nr_regex_destroy(®ex);
nr_rule_replace_string("QQ\\2RRR\\1STUV", dest, sizeof(dest), ss);
tlib_pass_if_str_equal("basic", "QQstuRRRabcSTUV", dest);
nr_rule_replace_string("\\2\\1", dest, sizeof(dest), ss);
tlib_pass_if_str_equal("basic", "stuabc", dest);
nr_rule_replace_string("\\1\\1\\1", dest, sizeof(dest), ss);
tlib_pass_if_str_equal("basic", "abcabcabc", dest);
nr_rule_replace_string("", dest, sizeof(dest), ss);
tlib_pass_if_str_equal("basic", "", dest);
/*
* Back substitute everything that matched
*/
nr_rule_replace_string("\\0", dest, sizeof(dest), ss);
tlib_pass_if_str_equal("basic", "rrabcbqrstu", dest);
/*
* Dest is too small to receive the value
*/
nr_rule_replace_string("\\1\\1\\1", dest, 2, ss);
tlib_pass_if_str_equal("basic", "a", dest);
/*
* dest is null
*/
dest[0] = 0;
nr_rule_replace_string("\\1\\1\\1", 0, sizeof(dest), ss);
tlib_pass_if_str_equal("basic", "", dest);
dest[0] = 0;
nr_rule_replace_string("\\1\\1\\1", dest, 0, ss);
tlib_pass_if_str_equal("basic", "", dest);
/*
* Out of range selector number
*/
nr_rule_replace_string("\\3", dest, sizeof(dest), ss);
tlib_pass_if_str_equal("basic", "\\3", dest);
/*
* Out of range selector number
*/
nr_rule_replace_string("\\13", dest, sizeof(dest), ss);
tlib_pass_if_str_equal("basic", "\\13", dest);
nr_regex_substrings_destroy(&ss);
/*
* 0-length subject
*/
subject = "";
slen = nr_strlen(subject);
ss = nr_regex_match_capture(regex, subject, slen);
nr_rule_replace_string("\\0", dest, sizeof(dest), ss);
tlib_pass_if_str_equal("0-length subject", "\\0", dest);
nr_regex_substrings_destroy(&ss);
}
tlib_parallel_info_t parallel_info = {.suggested_nthreads = 2, .state_size = 0};
void test_main(void* p NRUNUSED) {
test_rule_parsing();
test_process_rule();
test_create_from_obj_bad_params();
test_cross_agent_rule_tests();
test_replace_string();
}