summaryrefslogtreecommitdiffstats
path: root/src/tests/keywords/if-regex-match-named
blob: 2aa665fbeb116053d0087c43b0247b99f9ecfcce (plain)
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
# PRE: if
#
if ('${feature.regex-pcre}' == 'yes') {
update request {
	Tmp-Integer-0 := '123456789'
	Tmp-Integer-1 := 1
}

# Check failures when no previous capture
if ("%{regex:}" != "") {
	update reply {
		Filter-Id += 'Fail 0.1'
	}
}

if ("%{regex:foo}" != "") {
	update reply {
		Filter-Id += 'Fail 0.2'
	}
}

if ("%{regex:%{Tmp-Integer-1}}" != "") {
	update reply {
		Filter-Id += 'Fail 0.3'
	}
}

if ("%{regex:1}" != "") {
	update reply {
		Filter-Id += 'Fail 0.4'
	}
}

# uncompiled - ref - named capture groups
if (User-Name =~ /^(?<one>[0-9])_(?<two>[0-9])?_(?<three>[0-9]*)_(?<four>[0-9]+)_(?<five>[^_])_(?<six>6)_(?<seven>[7-8])%{Tmp-String-0}/) {
	if ("%{regex:seven}_%{regex:six}_%{regex:five}_%{regex:four}_%{regex:three}_%{regex:two}_%{regex:one}_%{0}" != '7_6_5_4_3_2_1_1_2_3_4_5_6_7') {
		update reply {
			Filter-Id += 'Fail 1'
		}
	}
}
else {
	update reply {
		Filter-Id += 'Fail 1.5'
	}
}

# Checking capture groups are cleared out correctly
if (User-Name =~ /^(?<one>[0-9])_%{Tmp-String-0}/) {
	if ("%{0}%{regex:one}%{regex:two}%{regex:three}%{regex:four}%{regex:five}%{regex:six}%{regex:seven}" != '1_1') {
		update reply {
			Filter-Id += 'Fail 2'
		}
	}
}
else {
	update reply {
		Filter-Id += 'Fail 2.5'
	}
}

# Checking capture groups are cleared out correctly when there are no matches
if (User-Name =~ /^.%{Tmp-String-0}/) {
	if ("%{0}%{regex:one}%{regex:two}%{regex:three}%{regex:four}%{regex:five}%{regex:six}%{regex:seven}" != '1') {
		update reply {
			Filter-Id += 'Fail 3'
		}
	}
}
else {
	update reply {
		Filter-Id += 'Fail 3.5'
	}
}

# compiled - ref - named capture groups
if (User-Name =~ /^(?<one>[0-9])_(?<two>[0-9])?_(?<three>[0-9]*)_(?<four>[0-9]+)_(?<five>[^_])_(?<six>6)_(?<seven>[7-8])/) {
	if ("%{regex:seven}_%{regex:six}_%{regex:five}_%{regex:four}_%{regex:three}_%{regex:two}_%{regex:one}_%{0}" != '7_6_5_4_3_2_1_1_2_3_4_5_6_7') {
		update reply {
			Filter-Id += 'Fail 4'
		}
	}
}
else {
	update reply {
		Filter-Id += 'Fail 4.5'
	}
}

# compiled - xlat - named capture groups
if ('1_2_3_4_5_6_7' =~ /^(?<one>[0-9])_(?<two>[0-9])?_(?<three>[0-9]*)_(?<four>[0-9]+)_(?<five>[^_])_(?<six>6)_(?<seven>[7-8])/) {
	if ("%{regex:seven}_%{regex:six}_%{regex:five}_%{regex:four}_%{regex:three}_%{regex:two}_%{regex:one}_%{0}" != '7_6_5_4_3_2_1_1_2_3_4_5_6_7') {
		update reply {
			Filter-Id += 'Fail 5'
		}
	}
}
else {
	update reply {
		Filter-Id += 'Fail 5.5'
	}
}

# compiled - ref - named capture groups (numeric indexes)
if (User-Name =~ /^(?<one>[0-9])_(?<two>[0-9])?_(?<three>[0-9]*)_(?<four>[0-9]+)_(?<five>[^_])_(?<six>6)_(?<seven>[7-8])/) {
	if ("%{7}_%{6}_%{5}_%{4}_%{3}_%{2}_%{1}_%{0}" != '7_6_5_4_3_2_1_1_2_3_4_5_6_7') {
		update reply {
			Filter-Id += 'Fail 4'
		}
	}
}
else {
	update reply {
		Filter-Id += 'Fail 4.5'
	}
}
}