src: Add tests
This commit is contained in:
parent
b8fda6808b
commit
be5c39a1cf
|
@ -117,6 +117,8 @@ int main(int argc, char *argv[]) {
|
|||
shrpx::test_downstream_rewrite_location_response_header) ||
|
||||
!CU_add_test(pSuite, "downstream_supports_non_final_response",
|
||||
shrpx::test_downstream_supports_non_final_response) ||
|
||||
!CU_add_test(pSuite, "downstream_find_affinity_cookie",
|
||||
shrpx::test_downstream_find_affinity_cookie) ||
|
||||
!CU_add_test(pSuite, "config_parse_header",
|
||||
shrpx::test_shrpx_config_parse_header) ||
|
||||
!CU_add_test(pSuite, "config_parse_log_format",
|
||||
|
@ -131,6 +133,8 @@ int main(int argc, char *argv[]) {
|
|||
shrpx::test_shrpx_http_create_forwarded) ||
|
||||
!CU_add_test(pSuite, "http_create_via_header_value",
|
||||
shrpx::test_shrpx_http_create_via_header_value) ||
|
||||
!CU_add_test(pSuite, "http_create_affinity_cookie",
|
||||
shrpx::test_shrpx_http_create_affinity_cookie) ||
|
||||
!CU_add_test(pSuite, "router_match", shrpx::test_shrpx_router_match) ||
|
||||
!CU_add_test(pSuite, "router_match_wildcard",
|
||||
shrpx::test_shrpx_router_match_wildcard) ||
|
||||
|
|
|
@ -189,4 +189,38 @@ void test_downstream_supports_non_final_response(void) {
|
|||
CU_ASSERT(!d.supports_non_final_response());
|
||||
}
|
||||
|
||||
void test_downstream_find_affinity_cookie(void) {
|
||||
Downstream d(nullptr, nullptr, 0);
|
||||
|
||||
auto &req = d.request();
|
||||
req.fs.add_header_token(StringRef::from_lit("cookie"), StringRef{}, false,
|
||||
http2::HD_COOKIE);
|
||||
req.fs.add_header_token(StringRef::from_lit("cookie"),
|
||||
StringRef::from_lit("a=b;;c=d"), false,
|
||||
http2::HD_COOKIE);
|
||||
req.fs.add_header_token(StringRef::from_lit("content-length"),
|
||||
StringRef::from_lit("599"), false,
|
||||
http2::HD_CONTENT_LENGTH);
|
||||
req.fs.add_header_token(StringRef::from_lit("cookie"),
|
||||
StringRef::from_lit("lb=deadbeef;LB=f1f2f3f4"), false,
|
||||
http2::HD_COOKIE);
|
||||
req.fs.add_header_token(StringRef::from_lit("cookie"),
|
||||
StringRef::from_lit("short=e1e2e3e"), false,
|
||||
http2::HD_COOKIE);
|
||||
|
||||
uint32_t aff;
|
||||
|
||||
aff = d.find_affinity_cookie(StringRef::from_lit("lb"));
|
||||
|
||||
CU_ASSERT(0xdeadbeef == aff);
|
||||
|
||||
aff = d.find_affinity_cookie(StringRef::from_lit("LB"));
|
||||
|
||||
CU_ASSERT(0xf1f2f3f4 == aff);
|
||||
|
||||
aff = d.find_affinity_cookie(StringRef::from_lit("short"));
|
||||
|
||||
CU_ASSERT(0 == aff);
|
||||
}
|
||||
|
||||
} // namespace shrpx
|
||||
|
|
|
@ -37,6 +37,7 @@ void test_downstream_crumble_request_cookie(void);
|
|||
void test_downstream_assemble_request_cookie(void);
|
||||
void test_downstream_rewrite_location_response_header(void);
|
||||
void test_downstream_supports_non_final_response(void);
|
||||
void test_downstream_find_affinity_cookie(void);
|
||||
|
||||
} // namespace shrpx
|
||||
|
||||
|
|
|
@ -91,4 +91,31 @@ void test_shrpx_http_create_via_header_value(void) {
|
|||
CU_ASSERT(("2 nghttpx" == StringRef{std::begin(buf), end}));
|
||||
}
|
||||
|
||||
void test_shrpx_http_create_affinity_cookie(void) {
|
||||
BlockAllocator balloc(1024, 1024);
|
||||
StringRef c;
|
||||
|
||||
c = http::create_affinity_cookie(balloc, StringRef::from_lit("cookie-val"),
|
||||
0xf1e2d3c4u, StringRef{}, false);
|
||||
|
||||
CU_ASSERT("cookie-val=f1e2d3c4" == c);
|
||||
|
||||
c = http::create_affinity_cookie(balloc, StringRef::from_lit("alpha"),
|
||||
0x00000000u, StringRef{}, true);
|
||||
|
||||
CU_ASSERT("alpha=00000000; Secure" == c);
|
||||
|
||||
c = http::create_affinity_cookie(balloc, StringRef::from_lit("bravo"),
|
||||
0x01111111u, StringRef::from_lit("bar"),
|
||||
false);
|
||||
|
||||
CU_ASSERT("bravo=01111111; Path=bar" == c);
|
||||
|
||||
c = http::create_affinity_cookie(balloc, StringRef::from_lit("charlie"),
|
||||
0x01111111u, StringRef::from_lit("bar"),
|
||||
true);
|
||||
|
||||
CU_ASSERT("charlie=01111111; Path=bar; Secure" == c);
|
||||
}
|
||||
|
||||
} // namespace shrpx
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace shrpx {
|
|||
|
||||
void test_shrpx_http_create_forwarded(void);
|
||||
void test_shrpx_http_create_via_header_value(void);
|
||||
void test_shrpx_http_create_affinity_cookie(void);
|
||||
|
||||
} // namespace shrpx
|
||||
|
||||
|
|
Loading…
Reference in New Issue