Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions plugins/header_rewrite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,15 @@ if(BUILD_TESTING)
endif()
endif()

# This test has linker issue when cripts is enabled, so its commented for now
# add_executable(test_matcher matcher_tests.cc matcher.cc lulu.cc regex_helper.cc resources.cc)
# add_catch2_test(NAME test_matcher COMMAND $<TARGET_FILE:test_matcher>)
# add_executable(test_matcher matcher_tests.cc matcher.cc lulu.cc regex_helper.cc)
# add_catch2_test(NAME test_matcher COMMAND $<TARGET_FILE:test_matcher>)
#
# target_link_libraries(test_matcher PRIVATE Catch2::Catch2WithMain ts::tscore libswoc::libswoc PkgConfig::PCRE2)
# target_link_libraries(test_matcher PRIVATE Catch2::Catch2WithMain ts::tscore libswoc::libswoc PkgConfig::PCRE2)
#
# if(ENABLE_CRIPTS)
# target_link_libraries(test_matcher PRIVATE ts::cripts)
# target_compile_definitions(test_matcher PRIVATE TS_HAS_CRIPTS=1)
# endif()

endif()
verify_global_plugin(header_rewrite)
Expand Down
2 changes: 1 addition & 1 deletion plugins/header_rewrite/matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ template <class T> class Matchers : public Matcher

field.ltrim_if(&isspace).rtrim_if(&isspace);
values.insert(convert(std::string(field)));
start = ++cur + skip_quotes;
start = ++cur;
skip_quotes = 0;
} else {
++cur;
Expand Down
24 changes: 24 additions & 0 deletions plugins/header_rewrite/matcher_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ TSHttpTxnServerRespGet(TSHttpTxn, TSMBuffer *, TSMLoc *)
return TS_SUCCESS;
}

TSHttpSsn
TSHttpTxnSsnGet(TSHttpTxn)
{
return nullptr;
}

void
Resources::destroy()
{
}

ClassAllocator<ProxyMutex, false> mutexAllocator("mutexAllocator");

TEST_CASE("Matcher", "[plugins][header_rewrite]")
Expand All @@ -106,3 +117,16 @@ TEST_CASE("MatcherSet", "[plugins][header_rewrite]")
foo.set("foo, bar, baz", CondModifiers::MOD_NOCASE);
REQUIRE(foo.test("FOO", res) == true);
}

TEST_CASE("MatcherSetQuoted", "[plugins][header_rewrite]")
{
Matchers<std::string> foo(MATCH_SET);
TSHttpTxn txn = nullptr;
TSCont c = nullptr;
Resources res(txn, c);

foo.set("\"foo\",\"bar\"", CondModifiers::MOD_NOCASE);
REQUIRE(foo.test("FOO", res) == true);
REQUIRE(foo.test("BAR", res) == true);
REQUIRE(foo.test("BAZ", res) == false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,57 @@ sessions:
- [ X-Testing, { value: "elif", as: equal } ]
- [ X-Pre-Else, { as: absent } ]

# Test 6: cond method GET
# Test 6: quoted set matching - second item "bar" should match
- transactions:
- client-request:
method: "GET"
version: "1.1"
url: /from_1/hrw-sets.png
headers:
fields:
- [ Host, www.example.com ]
- [ X-Quoted-Set, "bar" ]
- [ uuid, quoted-set-match ]

server-response:
status: 200
reason: OK
headers:
fields:
- [ Connection, close ]

proxy-response:
status: 200
headers:
fields:
- [ X-Quoted-Set, { value: "Yes", as: equal } ]

# Test 7: quoted set matching - non-member should not match
- transactions:
- client-request:
method: "GET"
version: "1.1"
url: /from_1/hrw-sets.png
headers:
fields:
- [ Host, www.example.com ]
- [ X-Quoted-Set, "baz" ]
- [ uuid, quoted-set-nomatch ]

server-response:
status: 200
reason: OK
headers:
fields:
- [ Connection, close ]

proxy-response:
status: 200
headers:
fields:
- [ X-Quoted-Set, { value: "No", as: equal } ]

# Test 8: cond method GET
- transactions:
- client-request:
method: "GET"
Expand All @@ -338,7 +388,7 @@ sessions:
fields:
- [ Via, { as: present } ]

# Test 7: cond method DELETE
# Test 9: cond method DELETE
- transactions:
- client-request:
method: "DELETE"
Expand All @@ -362,7 +412,7 @@ sessions:
fields:
- [ Via, { as: present } ]

# Test 8: End [L] #5423
# Test 10: End [L] #5423
- transactions:
- client-request:
method: "GET"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ elif
set-header X-Testing "elif"
else
set-header X-Testing "No"

cond %{SEND_RESPONSE_HDR_HOOK}
cond %{CLIENT-HEADER:X-Quoted-Set} ("foo","bar")
set-header X-Quoted-Set "Yes"
else
set-header X-Quoted-Set "No"