view seobeo/tests/seobeo_response_test.c @ 279:b3b547563ec7

Add Google connector service and agent wiki Implement the C/Seobeo Google Drive and Gmail connector with encrypted OAuth storage, Zenbu authentication, browser testing, AI tool discovery, chunked HTTP decoding, and Bazel coverage. Consolidate repository guidance into progressive wiki documentation and enforce arena-first allocation for new first-party C code. Co-authored-by: Copilot <[email protected]> Copilot-Session: 84c338fd-0939-4bb3-b7f3-1062eb213e5d
author MrJuneJune <me@mrjunejune.com>
date Mon, 17 Aug 2026 22:22:36 -0700
parents 0e7b9464248d
children
line wrap: on
line source

#include "seobeo/seobeo.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>

int main(void)
{
  int sockets[2];
  if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) != 0)
    return 1;

  Seobeo_Handle handle = {0};
  handle.socket = sockets[0];
  handle.write_buffer_capacity = 4096;
  handle.write_buffer = malloc(handle.write_buffer_capacity);

  Dowa_Arena *arena = Dowa_Arena_Create(4096);
  Seobeo_Request_Entry *response = NULL;
  Dowa_HashMap_Push_Arena(response, "status", "200", arena);
  Dowa_HashMap_Push_Arena(response, "content-type", "text/plain", arena);
  Dowa_HashMap_Push_Arena(response, "body", "hello", arena);
  Dowa_HashMap_Push_Arena(response, "X-Test", "present", arena);
  Dowa_HashMap_Push_Arena(response, "X-Unsafe", "bad\r\nInjected: yes", arena);

  Seobeo_Router_Send_Response(&handle, response, arena);

  char received[4096] = {0};
  ssize_t length = read(sockets[1], received, sizeof(received) - 1);
  int failed = 0;
  if (length <= 0)
    failed = 1;
  if (!strstr(received, "Content-Length: 5\r\n"))
    failed = 1;
  if (!strstr(received, "X-Test: present\r\n\r\nhello"))
    failed = 1;
  if (strstr(received, "Injected: yes"))
    failed = 1;

  if (failed)
    fprintf(stderr, "Unexpected response:\n%s\n", received);

  close(sockets[0]);
  close(sockets[1]);
  free(handle.write_buffer);
  Dowa_Arena_Free(arena);

  if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) != 0)
    return 1;

  memset(&handle, 0, sizeof(handle));
  handle.socket = sockets[0];
  handle.write_buffer_capacity = 4096;
  handle.write_buffer = malloc(handle.write_buffer_capacity);
  arena = Dowa_Arena_Create(4096);
  response = NULL;
  Dowa_HashMap_Push_Arena(response, "status", "204", arena);
  Dowa_HashMap_Push_Arena(response, "content-type", "text/plain", arena);
  Dowa_HashMap_Push_Arena(response, "body", "", arena);
  Seobeo_Router_Send_Response(&handle, response, arena);

  memset(received, 0, sizeof(received));
  length = read(sockets[1], received, sizeof(received) - 1);
  if (length <= 0 ||
      !strstr(received, "HTTP/1.1 204 No Content\r\n") ||
      !strstr(received, "Content-Length: 0\r\n") ||
      !strstr(received, "\r\n\r\n"))
    failed = 1;

  if (failed)
    fprintf(stderr, "Unexpected no-content response:\n%s\n", received);

  close(sockets[0]);
  close(sockets[1]);
  free(handle.write_buffer);
  Dowa_Arena_Free(arena);
  return failed;
}