Mercurial
comparison seobeo/tests/seobeo_response_test.c @ 221:ce7f4400c2de hg-web
[hg-web] Harden forge and add changeset UI
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Sun, 02 Aug 2026 09:01:24 -0700 |
| parents | |
| children | 0e7b9464248d |
comparison
equal
deleted
inserted
replaced
| 219:8c9bb0b0759e | 221:ce7f4400c2de |
|---|---|
| 1 #include "seobeo/seobeo.h" | |
| 2 | |
| 3 #include <stdio.h> | |
| 4 #include <stdlib.h> | |
| 5 #include <string.h> | |
| 6 #include <sys/socket.h> | |
| 7 | |
| 8 int main(void) | |
| 9 { | |
| 10 int sockets[2]; | |
| 11 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) != 0) | |
| 12 return 1; | |
| 13 | |
| 14 Seobeo_Handle handle = {0}; | |
| 15 handle.socket = sockets[0]; | |
| 16 handle.write_buffer_capacity = 4096; | |
| 17 handle.write_buffer = malloc(handle.write_buffer_capacity); | |
| 18 | |
| 19 Dowa_Arena *arena = Dowa_Arena_Create(4096); | |
| 20 Seobeo_Request_Entry *response = NULL; | |
| 21 Dowa_HashMap_Push_Arena(response, "status", "200", arena); | |
| 22 Dowa_HashMap_Push_Arena(response, "content-type", "text/plain", arena); | |
| 23 Dowa_HashMap_Push_Arena(response, "body", "hello", arena); | |
| 24 Dowa_HashMap_Push_Arena(response, "X-Test", "present", arena); | |
| 25 Dowa_HashMap_Push_Arena(response, "X-Unsafe", "bad\r\nInjected: yes", arena); | |
| 26 | |
| 27 Seobeo_Router_Send_Response(&handle, response, arena); | |
| 28 | |
| 29 char received[4096] = {0}; | |
| 30 ssize_t length = read(sockets[1], received, sizeof(received) - 1); | |
| 31 int failed = 0; | |
| 32 if (length <= 0) | |
| 33 failed = 1; | |
| 34 if (!strstr(received, "Content-Length: 5\r\n")) | |
| 35 failed = 1; | |
| 36 if (!strstr(received, "X-Test: present\r\n\r\nhello")) | |
| 37 failed = 1; | |
| 38 if (strstr(received, "Injected: yes")) | |
| 39 failed = 1; | |
| 40 | |
| 41 if (failed) | |
| 42 fprintf(stderr, "Unexpected response:\n%s\n", received); | |
| 43 | |
| 44 close(sockets[0]); | |
| 45 close(sockets[1]); | |
| 46 free(handle.write_buffer); | |
| 47 Dowa_Arena_Free(arena); | |
| 48 return failed; | |
| 49 } |