Skip to content

Commit 4f785f2

Browse files
committed
hrw4u: Normalize autest .conf rules for u4wrh roundtrip
Regenerate .conf files from .hrw4u so both converters produce identical output. Split merged sections in 3 .hrw4u files to match u4wrh --no-merge-sections output. Add roundtrip tests that verify hrw4u->conf and conf->hrw4u exact match.
1 parent a1034e3 commit 4f785f2

26 files changed

Lines changed: 276 additions & 224 deletions

tests/gold_tests/pluginTest/header_rewrite/rules/complex_logics.conf

Lines changed: 67 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
17-
1817
# All rules use SEND_RESPONSE_HDR_HOOK so set-header operates on the
1918
# response that the client sees. CLIENT-HEADER and CLIENT-URL:PATH
2019
# conditions always refer to the original client request regardless of hook.
21-
2220
# ---- Test: GROUP with [OR] on GROUP:END ----
2321
# hrw4u: if (inbound.req.X-Group-A) || inbound.req.X-Group-B
2422
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
@@ -28,128 +26,128 @@ cond %{GROUP}
2826
cond %{GROUP:END} [OR]
2927
cond %{CLIENT-HEADER:X-Group-B} ="" [NOT]
3028
set-header X-Group-Or-Result "matched"
29+
# ---- Test: GROUP with [AND] on GROUP:END (explicit) ----
30+
# hrw4u: if (inbound.req.X-And-A) && inbound.req.X-And-B
3131

32-
# ---- Test: GROUP with [AND] on GROUP:END (explicit) ----
33-
# hrw4u: if (inbound.req.X-And-A) && inbound.req.X-And-B
3432
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
3533
cond %{CLIENT-URL:PATH} /\/logic\/group-and$/ [AND]
3634
cond %{GROUP}
3735
cond %{CLIENT-HEADER:X-And-A} ="" [NOT]
3836
cond %{GROUP:END} [AND]
3937
cond %{CLIENT-HEADER:X-And-B} ="" [NOT]
4038
set-header X-Group-And-Result "matched"
39+
# ---- Test: GROUP with [NOT] on GROUP:END ----
40+
# hrw4u: if !(inbound.req.X-Not-A && inbound.req.X-Not-B)
4141

42-
# ---- Test: GROUP with [NOT] on GROUP:END ----
43-
# hrw4u: if !(inbound.req.X-Not-A && inbound.req.X-Not-B)
4442
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
4543
cond %{CLIENT-URL:PATH} /\/logic\/group-not$/ [AND]
4644
cond %{GROUP}
47-
cond %{CLIENT-HEADER:X-Not-A} ="" [NOT]
45+
cond %{CLIENT-HEADER:X-Not-A} ="" [AND,NOT]
4846
cond %{CLIENT-HEADER:X-Not-B} ="" [NOT]
4947
cond %{GROUP:END} [NOT]
5048
set-header X-Group-Not-Result "matched"
49+
# ---- Test: Nested GROUPs with mixed OR/AND ----
50+
# hrw4u: if inbound.req.X-Outer-A && (inbound.req.X-Inner-A || inbound.req.X-Inner-B)
5151

52-
# ---- Test: Nested GROUPs with mixed OR/AND ----
53-
# hrw4u: if inbound.req.X-Outer-A && (inbound.req.X-Inner-A || inbound.req.X-Inner-B)
5452
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
5553
cond %{CLIENT-URL:PATH} /\/logic\/nested-group$/ [AND]
56-
cond %{CLIENT-HEADER:X-Outer-A} ="" [NOT]
54+
cond %{CLIENT-HEADER:X-Outer-A} ="" [AND,NOT]
5755
cond %{GROUP}
58-
cond %{CLIENT-HEADER:X-Inner-A} ="" [NOT,OR]
56+
cond %{CLIENT-HEADER:X-Inner-A} ="" [OR,NOT]
5957
cond %{CLIENT-HEADER:X-Inner-B} ="" [NOT]
6058
cond %{GROUP:END}
6159
set-header X-Nested-Group-Result "matched"
60+
# ---- Test: Two GROUPs with OR between them ----
61+
# hrw4u: if (inbound.req.X-Left-A && inbound.req.X-Left-B) || (inbound.req.X-Right-A && inbound.req.X-Right-B)
6262

63-
# ---- Test: Two GROUPs with OR between them ----
64-
# hrw4u: if (inbound.req.X-Left-A && inbound.req.X-Left-B) || (inbound.req.X-Right-A && inbound.req.X-Right-B)
6563
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
6664
cond %{CLIENT-URL:PATH} /\/logic\/two-groups$/ [AND]
6765
cond %{GROUP}
68-
cond %{CLIENT-HEADER:X-Left-A} ="" [NOT]
66+
cond %{CLIENT-HEADER:X-Left-A} ="" [AND,NOT]
6967
cond %{CLIENT-HEADER:X-Left-B} ="" [NOT]
7068
cond %{GROUP:END} [OR]
7169
cond %{GROUP}
72-
cond %{CLIENT-HEADER:X-Right-A} ="" [NOT]
70+
cond %{CLIENT-HEADER:X-Right-A} ="" [AND,NOT]
7371
cond %{CLIENT-HEADER:X-Right-B} ="" [NOT]
7472
cond %{GROUP:END}
7573
set-header X-Two-Groups-Result "matched"
74+
# ---- Test: GROUP inside if/elif/else ----
75+
# hrw4u:
76+
# if inbound.req.X-Branch == "alpha" && (inbound.req.X-Sub-A || inbound.req.X-Sub-B)
77+
# -> "alpha"
78+
# elif inbound.req.X-Branch == "beta"
79+
# -> "beta"
80+
# else
81+
# -> "other"
7682

77-
# ---- Test: GROUP inside if/elif/else ----
78-
# hrw4u:
79-
# if inbound.req.X-Branch == "alpha" && (inbound.req.X-Sub-A || inbound.req.X-Sub-B)
80-
# -> "alpha"
81-
# elif inbound.req.X-Branch == "beta"
82-
# -> "beta"
83-
# else
84-
# -> "other"
85-
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
86-
cond %{CLIENT-URL:PATH} /\/logic\/if-group$/ [AND]
87-
if
88-
cond %{CLIENT-HEADER:X-Branch} ="alpha"
89-
cond %{GROUP}
90-
cond %{CLIENT-HEADER:X-Sub-A} ="" [NOT,OR]
91-
cond %{CLIENT-HEADER:X-Sub-B} ="" [NOT]
92-
cond %{GROUP:END}
93-
set-header X-If-Group-Result "alpha"
94-
elif
95-
cond %{CLIENT-HEADER:X-Branch} ="beta"
96-
set-header X-If-Group-Result "beta"
97-
else
98-
set-header X-If-Group-Result "other"
99-
endif
100-
101-
# ---- Test: GROUP with OR inside nested if ----
102-
# hrw4u:
103-
# if inbound.req.X-Outer == "yes"
104-
# if (inbound.req.X-Case-A || inbound.req.X-Case-B)
105-
# -> "inner-match"
106-
# else
107-
# -> "inner-miss"
108-
# else
109-
# -> "outer-miss"
11083
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
111-
cond %{CLIENT-URL:PATH} /\/logic\/nested-if-group$/ [AND]
112-
if
113-
cond %{CLIENT-HEADER:X-Outer} ="yes"
114-
if
84+
cond %{CLIENT-URL:PATH} /\/logic\/if-group$/
85+
if
86+
cond %{CLIENT-HEADER:X-Branch} ="alpha" [AND]
11587
cond %{GROUP}
116-
cond %{CLIENT-HEADER:X-Case-A} ="" [NOT,OR]
117-
cond %{CLIENT-HEADER:X-Case-B} ="" [NOT]
88+
cond %{CLIENT-HEADER:X-Sub-A} ="" [OR,NOT]
89+
cond %{CLIENT-HEADER:X-Sub-B} ="" [NOT]
11890
cond %{GROUP:END}
119-
set-header X-Nested-If-Result "inner-match"
120-
else
121-
set-header X-Nested-If-Result "inner-miss"
122-
endif
123-
else
124-
set-header X-Nested-If-Result "outer-miss"
125-
endif
91+
set-header X-If-Group-Result "alpha"
92+
elif
93+
cond %{CLIENT-HEADER:X-Branch} ="beta"
94+
set-header X-If-Group-Result "beta"
95+
else
96+
set-header X-If-Group-Result "other"
97+
endif
98+
# ---- Test: GROUP with OR inside nested if ----
99+
# hrw4u:
100+
# if inbound.req.X-Outer == "yes"
101+
# if (inbound.req.X-Case-A || inbound.req.X-Case-B)
102+
# -> "inner-match"
103+
# else
104+
# -> "inner-miss"
105+
# else
106+
# -> "outer-miss"
107+
108+
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
109+
cond %{CLIENT-URL:PATH} /\/logic\/nested-if-group$/
110+
if
111+
cond %{CLIENT-HEADER:X-Outer} ="yes"
112+
if
113+
cond %{GROUP}
114+
cond %{CLIENT-HEADER:X-Case-A} ="" [OR,NOT]
115+
cond %{CLIENT-HEADER:X-Case-B} ="" [NOT]
116+
cond %{GROUP:END}
117+
set-header X-Nested-If-Result "inner-match"
118+
else
119+
set-header X-Nested-If-Result "inner-miss"
120+
endif
121+
else
122+
set-header X-Nested-If-Result "outer-miss"
123+
endif
124+
# ---- Test: Complex expression: (A OR B) AND (C OR D) ----
125+
# hrw4u: if (inbound.req.X-P || inbound.req.X-Q) && (inbound.req.X-R || inbound.req.X-S)
126126

127-
# ---- Test: Complex expression: (A OR B) AND (C OR D) ----
128-
# hrw4u: if (inbound.req.X-P || inbound.req.X-Q) && (inbound.req.X-R || inbound.req.X-S)
129127
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
130128
cond %{CLIENT-URL:PATH} /\/logic\/complex-and-or$/ [AND]
131129
cond %{GROUP}
132-
cond %{CLIENT-HEADER:X-P} ="" [NOT,OR]
130+
cond %{CLIENT-HEADER:X-P} ="" [OR,NOT]
133131
cond %{CLIENT-HEADER:X-Q} ="" [NOT]
134132
cond %{GROUP:END} [AND]
135133
cond %{GROUP}
136-
cond %{CLIENT-HEADER:X-R} ="" [NOT,OR]
134+
cond %{CLIENT-HEADER:X-R} ="" [OR,NOT]
137135
cond %{CLIENT-HEADER:X-S} ="" [NOT]
138136
cond %{GROUP:END}
139137
set-header X-Complex-Result "matched"
138+
# ---- Test: IP:CLIENT in GROUP with [OR]
139+
# hrw4u: if (inbound.ip in {127.0.0.0/8}) || inbound.req.X-Outer == "true"
140140

141-
# ---- Test: IP:CLIENT in GROUP with [OR]
142-
# hrw4u: if (inbound.ip in {127.0.0.0/8}) || inbound.req.X-Outer == "true"
143141
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
144142
cond %{CLIENT-URL:PATH} /\/logic\/ip-group-or$/ [AND]
145143
cond %{GROUP}
146144
cond %{IP:CLIENT} {127.0.0.0/8}
147145
cond %{GROUP:END} [OR]
148146
cond %{CLIENT-HEADER:X-Outer} ="true"
149147
set-header X-Ip-Group-Or-Result "matched"
148+
# ---- Test: GROUP as first condition after hook ----
149+
# hrw4u: if (inbound.url.path ~ /\/logic\/group-first$/) && inbound.req.X-First-A
150150

151-
# ---- Test: GROUP as first condition after hook ----
152-
# hrw4u: if (inbound.url.path ~ /\/logic\/group-first$/) && inbound.req.X-First-A
153151
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
154152
cond %{GROUP}
155153
cond %{CLIENT-URL:PATH} /\/logic\/group-first$/

tests/gold_tests/pluginTest/header_rewrite/rules/complex_logics.hrw4u

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,33 @@ SEND_RESPONSE {
2525
# ---- Test: GROUP with [AND] on GROUP:END (explicit) ----
2626
# hrw4u: if (inbound.req.X-And-A) && inbound.req.X-And-B
2727
}
28+
}
2829

30+
SEND_RESPONSE {
2931
if inbound.url.path ~ /\/logic\/group-and$/ && (inbound.req.X-And-A) && inbound.req.X-And-B {
3032
inbound.resp.X-Group-And-Result = "matched";
3133
# ---- Test: GROUP with [NOT] on GROUP:END ----
3234
# hrw4u: if !(inbound.req.X-Not-A && inbound.req.X-Not-B)
3335
}
36+
}
3437

38+
SEND_RESPONSE {
3539
if inbound.url.path ~ /\/logic\/group-not$/ && !(inbound.req.X-Not-A && inbound.req.X-Not-B) {
3640
inbound.resp.X-Group-Not-Result = "matched";
3741
# ---- Test: Nested GROUPs with mixed OR/AND ----
3842
# hrw4u: if inbound.req.X-Outer-A && (inbound.req.X-Inner-A || inbound.req.X-Inner-B)
3943
}
44+
}
4045

46+
SEND_RESPONSE {
4147
if inbound.url.path ~ /\/logic\/nested-group$/ && inbound.req.X-Outer-A && (inbound.req.X-Inner-A || inbound.req.X-Inner-B) {
4248
inbound.resp.X-Nested-Group-Result = "matched";
4349
# ---- Test: Two GROUPs with OR between them ----
4450
# hrw4u: if (inbound.req.X-Left-A && inbound.req.X-Left-B) || (inbound.req.X-Right-A && inbound.req.X-Right-B)
4551
}
52+
}
4653

54+
SEND_RESPONSE {
4755
if inbound.url.path ~ /\/logic\/two-groups$/ && (inbound.req.X-Left-A && inbound.req.X-Left-B) || (inbound.req.X-Right-A && inbound.req.X-Right-B) {
4856
inbound.resp.X-Two-Groups-Result = "matched";
4957
# ---- Test: GROUP inside if/elif/else ----
@@ -55,7 +63,9 @@ SEND_RESPONSE {
5563
# else
5664
# -> "other"
5765
}
66+
}
5867

68+
SEND_RESPONSE {
5969
if inbound.url.path ~ /\/logic\/if-group$/ {
6070
if inbound.req.X-Branch == "alpha" && (inbound.req.X-Sub-A || inbound.req.X-Sub-B) {
6171
inbound.resp.X-If-Group-Result = "alpha";
@@ -74,7 +84,9 @@ SEND_RESPONSE {
7484
# else
7585
# -> "outer-miss"
7686
}
87+
}
7788

89+
SEND_RESPONSE {
7890
if inbound.url.path ~ /\/logic\/nested-if-group$/ {
7991
if inbound.req.X-Outer == "yes" {
8092
if (inbound.req.X-Case-A || inbound.req.X-Case-B) {
@@ -88,19 +100,25 @@ SEND_RESPONSE {
88100
# ---- Test: Complex expression: (A OR B) AND (C OR D) ----
89101
# hrw4u: if (inbound.req.X-P || inbound.req.X-Q) && (inbound.req.X-R || inbound.req.X-S)
90102
}
103+
}
91104

105+
SEND_RESPONSE {
92106
if inbound.url.path ~ /\/logic\/complex-and-or$/ && (inbound.req.X-P || inbound.req.X-Q) && (inbound.req.X-R || inbound.req.X-S) {
93107
inbound.resp.X-Complex-Result = "matched";
94108
# ---- Test: IP:CLIENT in GROUP with [OR]
95109
# hrw4u: if (inbound.ip in {127.0.0.0/8}) || inbound.req.X-Outer == "true"
96110
}
111+
}
97112

113+
SEND_RESPONSE {
98114
if inbound.url.path ~ /\/logic\/ip-group-or$/ && (inbound.ip in {127.0.0.0/8}) || inbound.req.X-Outer == "true" {
99115
inbound.resp.X-Ip-Group-Or-Result = "matched";
100116
# ---- Test: GROUP as first condition after hook ----
101117
# hrw4u: if (inbound.url.path ~ /\/logic\/group-first$/) && inbound.req.X-First-A
102118
}
119+
}
103120

121+
SEND_RESPONSE {
104122
if (inbound.url.path ~ /\/logic\/group-first$/) && inbound.req.X-First-A {
105123
inbound.resp.X-Group-First-Result = "matched";
106124
}

tests/gold_tests/pluginTest/header_rewrite/rules/glob_set_redirect.conf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
17-
1817
cond %{READ_RESPONSE_HDR_HOOK} [AND]
1918
cond %{ID:REQUEST} =0
20-
set-redirect 301 http://redirect.com/here
19+
set-redirect 301 "http://redirect.com/here"
2120

2221
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
2322
cond %{ID:REQUEST} =1
24-
set-redirect 301 http://redirect.com/here
23+
set-redirect 301 "http://redirect.com/here"

tests/gold_tests/pluginTest/header_rewrite/rules/implicit_hook.conf

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@
1414
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
17-
1817
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
1918
cond %{CLIENT-HEADER:X-Client-Foo} ="foo" [NOCASE,PRE]
20-
set-header X-Response-Foo "Prefix"
19+
set-header X-Response-Foo "Prefix"
2120
elif
22-
cond %{CLIENT-HEADER:X-Client-Foo} ="bar"
23-
set-header X-Response-Foo "Never"
21+
cond %{CLIENT-HEADER:X-Client-Foo} ="bar"
22+
set-header X-Response-Foo "Never"
2423
elif
25-
cond %{CLIENT-HEADER:X-Client-Foo} ="" [NOT]
26-
set-header X-Response-Foo "Yes"
24+
cond %{CLIENT-HEADER:X-Client-Foo} ="" [NOT]
25+
set-header X-Response-Foo "Yes"
2726
else
28-
set-header X-Response-Foo "No"
27+
set-header X-Response-Foo "No"
2928

29+
cond %{REMAP_PSEUDO_HOOK} [AND]
3030
cond %{CLIENT-HEADER:X-Fie} ="fie" [NOCASE]
31-
add-header X-Client-Foo "Yes"
31+
add-header X-Client-Foo "Yes"
3232
elif
33-
cond %{CLIENT-HEADER:X-Fie} ="nope"
34-
add-header X-client-Foo "Yes"
33+
cond %{CLIENT-HEADER:X-Fie} ="nope"
34+
add-header X-client-Foo "Yes"

tests/gold_tests/pluginTest/header_rewrite/rules/nested_ifs.conf

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@
1717
#
1818
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
1919
cond %{STATUS} =200
20-
set-header X-When-200-Before "Yes"
21-
if
22-
cond %{CLIENT-HEADER:X-Foo} ="foo"
23-
set-header X-Foo "Yes"
24-
if
25-
cond %{CLIENT-HEADER:X-Bar} ="bar" [NOCASE]
26-
set-header X-Foo-And-Bar "Yes"
27-
elif
20+
set-header X-When-200-Before "Yes"
21+
if
22+
cond %{CLIENT-HEADER:X-Foo} ="foo"
23+
set-header X-Foo "Yes"
24+
if
25+
cond %{CLIENT-HEADER:X-Bar} ="bar" [NOCASE]
26+
set-header X-Foo-And-Bar "Yes"
27+
elif
28+
cond %{CLIENT-HEADER:X-Fie} ="fie" [NOCASE]
29+
set-header X-Foo-And-Fie "Yes"
30+
endif
31+
elif
32+
cond %{CLIENT-HEADER:X-Foo} ="maybe"
33+
set-header X-Foo "Maybe"
34+
elif
35+
cond %{CLIENT-HEADER:X-Foo} ="definitely"
36+
set-header X-Foo "Definitely"
37+
else
38+
set-header X-Foo "Nothing"
39+
endif
40+
if
2841
cond %{CLIENT-HEADER:X-Fie} ="fie" [NOCASE]
29-
set-header X-Foo-And-Fie "Yes"
30-
endif
31-
elif
32-
cond %{CLIENT-HEADER:X-Foo} ="maybe"
33-
set-header X-Foo "Maybe"
34-
elif
35-
cond %{CLIENT-HEADER:X-Foo} ="definitely"
36-
set-header X-Foo "Definitely"
37-
else
38-
set-header X-Foo "Nothing"
39-
endif
40-
if
41-
cond %{CLIENT-HEADER:X-Fie} ="fie" [NOCASE]
42-
set-header X-Fie-Anywhere "Yes"
43-
endif
44-
set-header X-When-200-After "Yes"
42+
set-header X-Fie-Anywhere "Yes"
43+
endif
44+
set-header X-When-200-After "Yes"

tests/gold_tests/pluginTest/header_rewrite/rules/query_sub_key.conf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
17-
1817
# Test query parameter sub-key extraction
1918
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
2019
cond %{CLIENT-URL:QUERY:sub} ="" [NOT]
21-
set-header X-Query-Sub "%{CLIENT-URL:QUERY:sub}"
20+
set-header X-Query-Sub "%{CLIENT-URL:QUERY:sub}"

0 commit comments

Comments
 (0)