Skip to content

Commit 0abf83f

Browse files
Fix for crash in define-text-block.
1 parent ebc8b14 commit 0abf83f

9 files changed

Lines changed: 183 additions & 21 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ include/tscpp
6060
/_vcs
6161
/_sdk
6262
/_unit_tests
63+
/test/autest/_sandbox/
6364
Pipfile.lock

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The automated end to end tests are written using the
2424
[AuTest](https://bitbucket.org/autestsuite/reusable-gold-testing-system/src/master/)
2525
test framework. To run the tests, build the following required dependencies:
2626

27+
1. The package "python3-devel" - `sudo dnf install python3-devel`
2728
1. Build the `txn_box` Sconstruct target.
2829
1. Build [traffic_server](https://github.com/apache/trafficserver)
2930
1. Build [Proxy Verifier](https://github.com/yahoo/proxy-verifier)

Sconstruct

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ AddOption("--with-ssl",
2929

3030
# the depends
3131
Part("code/libswoc.part"
32-
,vcs_type=VcsGit(server="github.com", repository="SolidWallOfCode/libswoc", tag="dev-1-2-3")
32+
,vcs_type=VcsGit(server="github.com", repository="SolidWallOfCode/libswoc", tag="1.2.3")
3333
)
3434
Part("#lib/libyaml-cpp.part", vcs_type=VcsGit(server="github.com", repository="jbeder/yaml-cpp.git", protocol="https", tag="yaml-cpp-0.6.3"))
3535
#Part("#lib/libyaml-cpp.part")

plugin/src/text_block.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Do_text_block_define : public Directive {
6363
*/
6464
static Rv<Handle> load(Config& cfg, YAML::Node drtv_node, swoc::TextView const& name, swoc::TextView const& arg, YAML::Node key_value);
6565

66-
static Errata type_init(Config& cfg);
66+
static Errata cfg_init(Config& cfg);
6767

6868
protected:
6969
using Map = std::unordered_map<TextView, self_type *, std::hash<std::string_view>>;
@@ -228,7 +228,7 @@ Rv<Directive::Handle> Do_text_block_define::load(Config& cfg, YAML::Node drtv_no
228228
return std::move(handle);
229229
}
230230

231-
Errata Do_text_block_define::type_init(Config &cfg) {
231+
Errata Do_text_block_define::cfg_init(Config &cfg) {
232232
// Note - @a h gets a pointer to the Handle.
233233
auto h = cfg.allocate_cfg_storage(sizeof(MapHandle)).rebind<MapHandle>().data();
234234
new (h) MapHandle(std::make_unique<Map>());

test/autest/gold_tests/ct-header/replay_files/ct_header/ct_header.yaml renamed to test/autest/gold_tests/ct_header/ct_header.replay.yaml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,52 @@ meta:
44
txn_box:
55

66
# Set the ct-policy variable for later use in the transaction.
7-
- when: creq
7+
- when: ua-req
88
do:
9-
- with: cssn-proto<tls>
9+
- with: inbound-protocol<tls>
1010
select:
1111
- prefix: "tls"
1212
do:
1313
- var<ct-policy>:
14-
- creq-host
14+
- ua-req-host
1515
- filter:
1616
- match: "u.protected.com"
1717
replace: "enforce"
1818
- replace: "report-uri=\"http://cane.example.com/path/cane?src=examplecom-expect-ct-report-only\""
1919

2020
# Remove all Cookies going to protected.com
21-
- when: creq
21+
- when: proxy-req
2222
do:
23-
- with: creq-host
23+
- with: proxy-req-host
2424
select:
2525
- tld: "protected.com" # protected.com or any subdomain
2626
do:
27-
- creq-field<Cookie>: NULL
27+
- proxy-req-field<Cookie>: NULL
2828

2929
# Filter out set-cookie fields concerning protected.com
30-
- when: ursp
30+
- when: upstream-rsp
3131
do:
32-
- ursp-field<Set-Cookie>: # filter set-cookie fields
33-
- ursp-field<Set-Cookie> # get the current list
32+
- upstream-rsp-field<Set-Cookie>: # filter set-cookie fields
33+
- upstream-rsp-field<Set-Cookie> # get the current list
3434
- filter: # keep the ones
3535
- none-of: # that do *not* match
3636
- rxp<nc>: "domain=(?:[^=]*[.])?protected[.]com" # this regex
3737

38-
- when: prsp
38+
- when: proxy-rsp
3939
do:
4040
# set a referrer policy if not already present.
41-
- prsp-field<Referrer-Policy>: [ prsp-field<Referrer-Policy>, { else: "no-referrer-when-downgrade" } ]
41+
- proxy-rsp-field<Referrer-Policy>:
42+
- proxy-rsp-field<Referrer-Policy>
43+
- else: "no-referrer-when-downgrade"
4244

4345
# For proxy response, fix up (add) the cross site fields if it's TLS.
44-
- with: cssn-proto<tls>
46+
- with: inbound-protocol<tls>
4547
select:
4648
- prefix: "tls"
4749
do:
48-
- prsp-field<Expect-CT>: "max-age=31536000, {var<ct-policy>}"
49-
- prsp-field<X-XSS-Protection>: "1; mode=block"
50-
- prsp-field<X-Content-Type-Options>: "nosniff"
50+
- proxy-rsp-field<Expect-CT>: "max-age=31536000, {var<ct-policy>}"
51+
- proxy-rsp-field<X-XSS-Protection>: "1; mode=block"
52+
- proxy-rsp-field<X-Content-Type-Options>: "nosniff"
5153

5254
sessions:
5355

test/autest/gold_tests/ct-header/ct_header.test.py renamed to test/autest/gold_tests/ct_header/ct_header.test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919
r = Test.AddTestRun("Verify txn_box can filter fields as expected.")
2020
client = r.AddVerifierClientProcess(
21-
"client1", ts, "replay_files/ct_header",
21+
"client1", ts, "ct_header.replay.yaml",
2222
http_ports=[ts.Variables.port])
23-
server = r.AddVerifierServerProcess("server1", "replay_files/ct_header")
24-
r.ConfigureTsForTxnBox(ts, server, "replay_files/ct_header/ct_header.yaml")
23+
server = r.AddVerifierServerProcess("server1", "ct_header.replay.yaml")
24+
r.ConfigureTsForTxnBox(ts, server, "ct_header.replay.yaml")
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Text block testing.
2+
3+
meta:
4+
version: "1.0"
5+
6+
txn_box:
7+
- when: post-load
8+
do:
9+
- text-block-define:
10+
name: "SWOC"
11+
path: "../../static_file.txt"
12+
duration: seconds<20>
13+
14+
- when: upstream-rsp
15+
do:
16+
- with: [ upstream-rsp-status , proxy-req-path ]
17+
select:
18+
- as-tuple:
19+
- eq: 404
20+
- match: "security.txt"
21+
do:
22+
- upstream-rsp-status: [ 200 , "OK" ]
23+
- proxy-rsp-body: "Contents of security.txt"
24+
25+
txn-box-remap:
26+
- when: proxy-rsp
27+
do:
28+
- proxy-rsp-field<SWOC>: [ proxy-rsp-field<SWOC>, { else: text-block<SWOC> }]
29+
30+
31+
sessions:
32+
- protocol: [ ipv4, tcp ]
33+
transactions:
34+
- all: { headers: { fields: [[ uuid, 1 ]]}}
35+
client-request:
36+
version: "1.1"
37+
scheme: "http"
38+
method: "GET"
39+
url: "/1"
40+
headers:
41+
fields:
42+
- [ Host, example.one ]
43+
proxy-request:
44+
version: "1.1"
45+
scheme: "http"
46+
method: "GET"
47+
url: "/1"
48+
headers:
49+
fields:
50+
- [ Host, example.one ]
51+
server-response:
52+
status: 200
53+
reason: OK
54+
content:
55+
size: 110
56+
headers:
57+
fields:
58+
- [ Content-Type, text/html ]
59+
- [ Content-Length, 110 ]
60+
- [ SWOC, upstream ]
61+
proxy-response:
62+
status: 200
63+
64+
- all: { headers: { fields: [[ uuid, 2 ]]}}
65+
client-request:
66+
version: "1.1"
67+
scheme: "http"
68+
method: "GET"
69+
url: "/2"
70+
headers:
71+
fields:
72+
- [ Host, example.one ]
73+
proxy-request:
74+
version: "1.1"
75+
scheme: "http"
76+
method: "GET"
77+
url: "/2"
78+
headers:
79+
fields:
80+
- [ Host, example.one ]
81+
server-response:
82+
status: 200
83+
reason: OK
84+
content:
85+
size: 120
86+
headers:
87+
fields:
88+
- [ Content-Type, text/html ]
89+
- [ Content-Length, 120 ]
90+
proxy-response:
91+
status: 200
92+
headers:
93+
fields:
94+
- [ SWOC, Winning ]
95+
96+
- all: { headers: { fields: [[ uuid, 3 ]]}}
97+
client-request:
98+
version: "1.1"
99+
scheme: "http"
100+
method: "GET"
101+
url: "/security.txt"
102+
headers:
103+
fields:
104+
- [ Host, example.one ]
105+
proxy-request:
106+
version: "1.1"
107+
scheme: "http"
108+
method: "GET"
109+
url: "/security.txt"
110+
headers:
111+
fields:
112+
- [ Host, example.one ]
113+
server-response:
114+
status: 404
115+
reason: Not Found
116+
content:
117+
size: 130
118+
headers:
119+
fields:
120+
- [ Content-Type, text/html ]
121+
- [ Content-Length, 130 ]
122+
proxy-response:
123+
status: 200
124+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'''
2+
Static file serving and handling.
3+
'''
4+
# @file
5+
#
6+
# Copyright 2020, Verizon Media
7+
# SPDX-License-Identifier: Apache-2.0
8+
#
9+
10+
import os
11+
12+
Test.Summary = '''
13+
Server static file as response body.
14+
'''
15+
16+
ts = Test.MakeATSProcess("ts")
17+
18+
#
19+
# Test 1: Verify that a field can be changed in both upstream and downstream
20+
#
21+
r = Test.AddTestRun("Serve static file content.")
22+
client = r.AddVerifierClientProcess(
23+
"client1", ts, "static_file.replay.yaml",
24+
http_ports=[ts.Variables.port])
25+
server = r.AddVerifierServerProcess("server1", "static_file.replay.yaml")
26+
r.ConfigureTsForTxnBox(ts, server, "static_file.replay.yaml")
27+
r.Setup.Copy("static_file.txt", Test.RunDirectory)
28+
ts.Disk.remap_config.AddLine(
29+
'map http://example.one http://exmaple.one @plugin=txn_box.so @pparam=static_file.replay.yaml @pparam=meta.txn-box-remap'
30+
)
31+
ts.Disk.records_config.update({
32+
'proxy.config.plugin.dynamic_reload_mode': 0,
33+
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Delain Concert.

0 commit comments

Comments
 (0)