chore: add retoor attribution and expand source file list in Makefile
- Add author comment with retoor <retoor@molodetz.nl> at top of Makefile - Include 12 new source files (config_parser, http_response, client_handler, upstream, forwarding, base64, socket_utils, epoll_utils, time_utils, histogram, deque, rate_tracker, stats_collector) to SOURCES and TEST_LIB_SOURCES - Add corresponding backup copies of auth.c, config.c, connection.c, and monitor.c to src/backup/ directory
This commit is contained in:
+94
-15
@@ -2303,8 +2303,8 @@ void test_connection_buffered_data_after_upstream_close(void) {
|
||||
TEST_SUITE_END();
|
||||
}
|
||||
|
||||
void test_connection_pipelined_request_rejected(void) {
|
||||
TEST_SUITE_BEGIN("Pipelined Request Rejected");
|
||||
void test_connection_pipelined_request_forwarded(void) {
|
||||
TEST_SUITE_BEGIN("Pipelined Request Forwarded");
|
||||
|
||||
connection_init_all();
|
||||
int old_epoll = epoll_fd;
|
||||
@@ -2345,10 +2345,10 @@ void test_connection_pipelined_request_rejected(void) {
|
||||
struct epoll_event event = { .events = EPOLLIN, .data.fd = sockfd[0] };
|
||||
connection_handle_event(&event);
|
||||
|
||||
TEST_ASSERT(client->state == CLIENT_STATE_CLOSING || client->type == CONN_TYPE_UNUSED,
|
||||
"Connection closed on pipelined request");
|
||||
TEST_ASSERT(strstr((char*)client->write_buf.data, "400") != NULL,
|
||||
"400 error sent to client");
|
||||
TEST_ASSERT(client->state == CLIENT_STATE_FORWARDING,
|
||||
"Client still in forwarding state");
|
||||
TEST_ASSERT(client->type == CONN_TYPE_CLIENT,
|
||||
"Client connection still active");
|
||||
|
||||
if (client->type != CONN_TYPE_UNUSED) {
|
||||
buffer_free(&client->read_buf);
|
||||
@@ -2364,8 +2364,8 @@ void test_connection_pipelined_request_rejected(void) {
|
||||
TEST_SUITE_END();
|
||||
}
|
||||
|
||||
void test_connection_pipelined_dashboard_rejected(void) {
|
||||
TEST_SUITE_BEGIN("Pipelined Dashboard Request Rejected");
|
||||
void test_connection_pipelined_request_allowed(void) {
|
||||
TEST_SUITE_BEGIN("Pipelined Request Allowed");
|
||||
|
||||
connection_init_all();
|
||||
int old_epoll = epoll_fd;
|
||||
@@ -2400,15 +2400,16 @@ void test_connection_pipelined_dashboard_rejected(void) {
|
||||
epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sockfd[0], &ev);
|
||||
client->epoll_events = EPOLLIN;
|
||||
|
||||
const char *pipelined_dashboard = "GET /rproxy/dashboard HTTP/1.1\r\nHost: test.com\r\n\r\n";
|
||||
IGNORE_RESULT(write(sockfd[1], pipelined_dashboard, strlen(pipelined_dashboard)));
|
||||
const char *pipelined_req = "GET /api/data HTTP/1.1\r\nHost: test.com\r\n\r\n";
|
||||
IGNORE_RESULT(write(sockfd[1], pipelined_req, strlen(pipelined_req)));
|
||||
|
||||
struct epoll_event event = { .events = EPOLLIN, .data.fd = sockfd[0] };
|
||||
connection_handle_event(&event);
|
||||
|
||||
TEST_ASSERT(upstream->write_buf.tail == 0, "Dashboard request NOT forwarded to upstream");
|
||||
TEST_ASSERT(client->state == CLIENT_STATE_CLOSING || client->type == CONN_TYPE_UNUSED,
|
||||
"Client connection closed");
|
||||
TEST_ASSERT(client->state == CLIENT_STATE_FORWARDING,
|
||||
"Client remains in forwarding state");
|
||||
TEST_ASSERT(client->type == CONN_TYPE_CLIENT,
|
||||
"Client connection not closed");
|
||||
|
||||
if (client->type != CONN_TYPE_UNUSED) {
|
||||
buffer_free(&client->read_buf);
|
||||
@@ -2485,6 +2486,83 @@ void test_connection_single_request_not_rejected(void) {
|
||||
TEST_SUITE_END();
|
||||
}
|
||||
|
||||
void test_connection_pipelined_host_rewrite(void) {
|
||||
TEST_SUITE_BEGIN("Pipelined Host Rewrite");
|
||||
|
||||
connection_init_all();
|
||||
int old_epoll = epoll_fd;
|
||||
epoll_fd = epoll_create1(0);
|
||||
TEST_ASSERT(epoll_fd >= 0, "Epoll created");
|
||||
|
||||
static route_config_t test_route;
|
||||
memset(&test_route, 0, sizeof(test_route));
|
||||
strncpy(test_route.hostname, "test.com", sizeof(test_route.hostname) - 1);
|
||||
strncpy(test_route.upstream_host, "backend.internal", sizeof(test_route.upstream_host) - 1);
|
||||
test_route.upstream_port = 8080;
|
||||
test_route.rewrite_host = 1;
|
||||
|
||||
int sockfd[2];
|
||||
socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd);
|
||||
connection_set_non_blocking(sockfd[0]);
|
||||
connection_set_non_blocking(sockfd[1]);
|
||||
|
||||
connection_t *client = &connections[sockfd[0]];
|
||||
memset(client, 0, sizeof(connection_t));
|
||||
client->fd = sockfd[0];
|
||||
client->type = CONN_TYPE_CLIENT;
|
||||
client->state = CLIENT_STATE_FORWARDING;
|
||||
buffer_init(&client->read_buf, 4096);
|
||||
buffer_init(&client->write_buf, 4096);
|
||||
|
||||
connection_t *upstream = &connections[sockfd[1]];
|
||||
memset(upstream, 0, sizeof(connection_t));
|
||||
upstream->fd = sockfd[1];
|
||||
upstream->type = CONN_TYPE_UPSTREAM;
|
||||
upstream->state = CLIENT_STATE_FORWARDING;
|
||||
upstream->route = &test_route;
|
||||
buffer_init(&upstream->read_buf, 4096);
|
||||
buffer_init(&upstream->write_buf, 4096);
|
||||
|
||||
client->pair = upstream;
|
||||
upstream->pair = client;
|
||||
|
||||
struct epoll_event ev = { .events = EPOLLIN, .data.fd = sockfd[0] };
|
||||
epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sockfd[0], &ev);
|
||||
client->epoll_events = EPOLLIN;
|
||||
|
||||
const char *pipelined_req = "GET /api HTTP/1.1\r\nHost: test.com\r\n\r\n";
|
||||
IGNORE_RESULT(write(sockfd[1], pipelined_req, strlen(pipelined_req)));
|
||||
|
||||
struct epoll_event event = { .events = EPOLLIN, .data.fd = sockfd[0] };
|
||||
connection_handle_event(&event);
|
||||
|
||||
TEST_ASSERT(client->state == CLIENT_STATE_FORWARDING,
|
||||
"Client still in forwarding state");
|
||||
|
||||
char recv_buf[4096];
|
||||
ssize_t n = read(sockfd[1], recv_buf, sizeof(recv_buf) - 1);
|
||||
if (n > 0) {
|
||||
recv_buf[n] = '\0';
|
||||
TEST_ASSERT(strstr(recv_buf, "Host: backend.internal:8080") != NULL,
|
||||
"Host header rewritten to upstream");
|
||||
TEST_ASSERT(strstr(recv_buf, "Host: test.com") == NULL,
|
||||
"Original Host header removed");
|
||||
}
|
||||
|
||||
if (client->type != CONN_TYPE_UNUSED) {
|
||||
buffer_free(&client->read_buf);
|
||||
buffer_free(&client->write_buf);
|
||||
}
|
||||
buffer_free(&upstream->read_buf);
|
||||
buffer_free(&upstream->write_buf);
|
||||
close(sockfd[0]);
|
||||
close(sockfd[1]);
|
||||
close(epoll_fd);
|
||||
epoll_fd = old_epoll;
|
||||
|
||||
TEST_SUITE_END();
|
||||
}
|
||||
|
||||
void run_connection_tests(void) {
|
||||
test_connection_init_all();
|
||||
test_connection_set_non_blocking();
|
||||
@@ -2549,6 +2627,7 @@ void run_connection_tests(void) {
|
||||
test_connection_cleanup_active_conn();
|
||||
test_connection_keep_alive_internal_route_second_request();
|
||||
test_connection_buffered_data_after_upstream_close();
|
||||
test_connection_pipelined_request_rejected();
|
||||
test_connection_pipelined_dashboard_rejected();
|
||||
test_connection_pipelined_request_forwarded();
|
||||
test_connection_pipelined_request_allowed();
|
||||
test_connection_pipelined_host_rewrite();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user