initial repo - geomyidae-tests - geomyidae tests | |
git clone git://bitreich.org/geomyidae-tests/ git://enlrupgkhuxnvlhsf6lc3fziv5h… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
LICENSE | |
--- | |
commit 77772ad44967239799ef0fa93ab220d8d133b15e | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Fri, 21 Jul 2023 13:58:55 +0200 | |
initial repo | |
Diffstat: | |
A Makefile | 13 +++++++++++++ | |
A README | 7 +++++++ | |
A env.c | 14 ++++++++++++++ | |
A run.sh | 35 +++++++++++++++++++++++++++++… | |
A test.c | 97 ++++++++++++++++++++++++++++++ | |
A tests | 7 +++++++ | |
6 files changed, 173 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/Makefile b/Makefile | |
@@ -0,0 +1,13 @@ | |
+build: clean | |
+ ${CC} -o test.cgi test.c -static | |
+ | |
+setup: | |
+ mkdir -p results | |
+ rm -f test_counter.txt | |
+ | |
+clean-results: | |
+ rm -rf results | |
+ rm -f test_counter.txt | |
+ | |
+clean: | |
+ rm -f test.cgi | |
diff --git a/README b/README | |
@@ -0,0 +1,7 @@ | |
+geomyidae testsuite initial prototype | |
+ | |
+steps to run: | |
+ | |
+as root: ./run.sh | |
+ | |
+make sure geomyidae is not running | |
diff --git a/env.c b/env.c | |
@@ -0,0 +1,14 @@ | |
+#include <stdio.h> | |
+ | |
+extern char **environ; | |
+ | |
+int | |
+main(void) | |
+{ | |
+ char **p; | |
+ | |
+ for (p = environ; p && *p; p++) | |
+ puts(*p); | |
+ | |
+ return 0; | |
+} | |
diff --git a/run.sh b/run.sh | |
@@ -0,0 +1,35 @@ | |
+#!/bin/sh | |
+bin="/home/hiltjo/p/geomyidae/geomyidae" | |
+host="127.0.0.1" | |
+port="7070" | |
+base="$(pwd)" | |
+user="hiltjo" | |
+group="hiltjo" | |
+ | |
+run_tests() { | |
+ while read -r line; do | |
+ printf '%s\r\n' "$line" | nc "$host" "$port" | |
+ done < tests | |
+} | |
+ | |
+uid=$(id -u) | |
+if test "$uid" != "0"; then | |
+ echo "needs to be run as root to be able to chroot the daemon, etc" >&2 | |
+ exit 1 | |
+fi | |
+ | |
+# clean previous tests | |
+rm -rf results | |
+mkdir -p results | |
+chown "$user:$group" results | |
+rm -f test_counter.txt | |
+ | |
+"$bin" -4 -d -b "$base" -p "$port" -o "$port" -h "$host" -u "$user" -g "$group… | |
+run_tests | |
+pkill geomyidae | |
+ | |
+"$bin" -4 -c -d -b "$base" -p "$port" -o "$port" -h "$host" -u "$user" -g "$gr… | |
+run_tests | |
+pkill geomyidae | |
+ | |
+# TOOD: test TLS | |
diff --git a/test.c b/test.c | |
@@ -0,0 +1,97 @@ | |
+#include <errno.h> | |
+#include <limits.h> | |
+#include <stdio.h> | |
+#include <stdlib.h> | |
+#include <string.h> | |
+ | |
+const char *counter_path = "test_counter.txt"; | |
+ | |
+/* read counter */ | |
+long | |
+get_test_counter(void) | |
+{ | |
+ FILE *fp; | |
+ char buf[32]; | |
+ size_t n; | |
+ long counter; | |
+ | |
+ fp = fopen(counter_path, "rb+"); | |
+ if (!fp) | |
+ return 0; | |
+ | |
+ n = fread(buf, 1, sizeof(buf), fp); | |
+ if (n < 0 || ferror(fp)) | |
+ return 0; | |
+ buf[n] = '\0'; | |
+ counter = strtol(buf, NULL, 10); | |
+ | |
+ return counter; | |
+} | |
+ | |
+/* write new counter */ | |
+int | |
+write_test_counter(long counter) | |
+{ | |
+ FILE *fp; | |
+ char buf[32]; | |
+ size_t n; | |
+ int ret; | |
+ | |
+ fp = fopen(counter_path, "wb+"); | |
+ if (!fp) { | |
+ fprintf(stderr, "error opening path for writing counter: %s", | |
+ strerror(errno)); | |
+ return -1; | |
+ } | |
+ | |
+ snprintf(buf, sizeof(buf), "%ld", counter); | |
+ fwrite(buf, 1, strlen(buf), fp); | |
+ ret = (fflush(fp) || ferror(fp)) ? -1 : 0; | |
+ fclose(fp); | |
+ | |
+ return ret; | |
+} | |
+ | |
+int | |
+main(void) | |
+{ | |
+ FILE *fp; | |
+ char path[PATH_MAX]; | |
+ const char *envs[] = { | |
+ "PATH_INFO", | |
+ "PATH_TRANSLATED", | |
+ "QUERY_STRING", | |
+ "SCRIPT_NAME", | |
+ /* TLS */ | |
+ "SERVER_PROTOCOL", | |
+ "HTTPS", | |
+ /* gopher-specific: */ | |
+ "SEARCHREQUEST", | |
+ "X_GOPHER_SEARCH" | |
+ }; | |
+ char *p; | |
+ int i; | |
+ long counter; | |
+ | |
+ counter = get_test_counter(); | |
+ | |
+ snprintf(path, sizeof(path), "results/%lld.txt", counter); | |
+ fp = fopen(path, "wb+"); | |
+ if (!fp) { | |
+ fprintf(stderr, "error writing result to path: %s: %s\n", | |
+ path, strerror(errno)); | |
+ return 1; | |
+ } | |
+ | |
+ for (i = 0; i < sizeof(envs) / sizeof(envs[0]); i++) { | |
+ p = getenv(envs[i]); | |
+ if (!p) | |
+ p = "(null)"; | |
+ fprintf(fp, "%s = %s\n", envs[i], p); | |
+ } | |
+ fclose(fp); | |
+ | |
+ write_test_counter(counter + 1); | |
+ | |
+ return 0; | |
+} | |
diff --git a/tests b/tests | |
@@ -0,0 +1,7 @@ | |
+test.cgi | |
+/test.cgi | |
+//test.cgi | |
+/?query | |
+/test.cgi?query | |
+/test.cgi?query=test | |
+/test.cgi?query=/test |