Mercurial
comparison seobeo/tests/seobeo_request_context_test.c @ 264:04fee26ecce0
add authenticated JRPG conversation platform
Add reusable auth/session storage, owned conversation recovery, guest quotas, admin workflows, URL-routed conversation UI, mobile frame support, and parallel browser acceptance.
Co-authored-by: Copilot <[email protected]>
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Fri, 07 Aug 2026 07:34:12 -0700 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 263:ee04e4e69fed | 264:04fee26ecce0 |
|---|---|
| 1 #include "seobeo/seobeo.h" | |
| 2 #include "seobeo/seobeo_internal.h" | |
| 3 | |
| 4 #include <stdio.h> | |
| 5 #include <stdlib.h> | |
| 6 #include <string.h> | |
| 7 #include <sys/socket.h> | |
| 8 #include <unistd.h> | |
| 9 | |
| 10 static const char *request_value( | |
| 11 Seobeo_Request_Entry *request, | |
| 12 const char *key) | |
| 13 { | |
| 14 void *entry = Dowa_HashMap_Get_Ptr(request, key); | |
| 15 return entry ? ((Seobeo_Request_Entry *)entry)->value : NULL; | |
| 16 } | |
| 17 | |
| 18 int main(void) | |
| 19 { | |
| 20 int sockets[2]; | |
| 21 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) != 0) | |
| 22 return 1; | |
| 23 | |
| 24 const char raw_request[] = | |
| 25 "GET / HTTP/1.1\r\n" | |
| 26 "Host: example.test\r\n" | |
| 27 "cookie: mjj_session=session-token\r\n" | |
| 28 "origin: https://example.test\r\n" | |
| 29 "x-csrf-token: csrf-token\r\n" | |
| 30 "Remote-Addr: 198.51.100.99\r\n" | |
| 31 "X-Real-IP: 203.0.113.45\r\n" | |
| 32 "\r\n"; | |
| 33 if (write(sockets[1], raw_request, sizeof(raw_request) - 1) < 0) | |
| 34 return 1; | |
| 35 | |
| 36 Seobeo_Handle handle = {0}; | |
| 37 handle.socket = sockets[0]; | |
| 38 handle.host = strdup("2001:db8::1234"); | |
| 39 handle.read_buffer_capacity = 4096; | |
| 40 handle.read_buffer = malloc(handle.read_buffer_capacity); | |
| 41 | |
| 42 Dowa_Arena *arena = Dowa_Arena_Create(16 * 1024); | |
| 43 Seobeo_Request_Entry *request = NULL; | |
| 44 int failed = Seobeo_Web_Header_Parse(&handle, &request, arena) != 0; | |
| 45 | |
| 46 const char *remote_addr = request_value(request, "Remote-Addr"); | |
| 47 const char *forwarded_addr = request_value(request, "X-Real-IP"); | |
| 48 const char *cookie = request_value(request, "Cookie"); | |
| 49 const char *origin = request_value(request, "Origin"); | |
| 50 const char *csrf = request_value(request, "X-CSRF-Token"); | |
| 51 if (!remote_addr || strcmp(remote_addr, "2001:db8::1234") != 0) | |
| 52 failed = 1; | |
| 53 if (!forwarded_addr || strcmp(forwarded_addr, "203.0.113.45") != 0) | |
| 54 failed = 1; | |
| 55 if (!cookie || strcmp(cookie, "mjj_session=session-token") != 0) | |
| 56 failed = 1; | |
| 57 if (!origin || strcmp(origin, "https://example.test") != 0) | |
| 58 failed = 1; | |
| 59 if (!csrf || strcmp(csrf, "csrf-token") != 0) | |
| 60 failed = 1; | |
| 61 if (remote_addr == handle.host) | |
| 62 failed = 1; | |
| 63 | |
| 64 if (failed) | |
| 65 fprintf(stderr, "Request context did not preserve peer identity or canonical headers\n"); | |
| 66 | |
| 67 close(sockets[0]); | |
| 68 close(sockets[1]); | |
| 69 free(handle.host); | |
| 70 free(handle.read_buffer); | |
| 71 Dowa_Arena_Free(arena); | |
| 72 return failed; | |
| 73 } |