mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-01 13:10:43 +00:00
move Makefile to test/
This commit is contained in:
1 parent
601af780c9
commit
89aaf1c30c
14 files changed
+792
-139
No files matched your search
+208
@@ -0,0 +1,208 @@
|
||||
SRCS = mongoose.c unit_test.c packed_fs.c
|
||||
HDRS = $(wildcard ../src/*.h) $(wildcard ../src/drivers/*.h)
|
||||
DEFS ?= -DMG_MAX_HTTP_HEADERS=7 -DMG_ENABLE_LINES -DMG_ENABLE_PACKED_FS=1 -DMG_ENABLE_SSI=1 -DMG_ENABLE_ASSERT=1
|
||||
WARN ?= -pedantic -W -Wall -Werror -Wshadow -Wdouble-promotion -fno-common -Wconversion -Wundef
|
||||
OPTS ?= -O3 -g3
|
||||
INCS ?= -Isrc -I.
|
||||
SSL ?=
|
||||
CWD ?= $(realpath $(CURDIR))
|
||||
ENV ?= -e Tmp=. -e WINEDEBUG=-all
|
||||
DOCKER_BIN ?= docker
|
||||
DOCKER ?= $(DOCKER_BIN) run --platform linux/amd64 --rm $(ENV) -v $(CWD)/..:$(CWD)/.. -w $(CWD)
|
||||
VCFLAGS = /nologo /W3 /O2 /MD /I. $(DEFS) $(TFLAGS)
|
||||
IPV6 ?= 1
|
||||
ASAN ?= -fsanitize=address,undefined,alignment -fno-sanitize-recover=all -fno-omit-frame-pointer -fno-common
|
||||
ASAN_OPTIONS ?= detect_leaks=1
|
||||
EXAMPLES := $(dir $(wildcard ../examples/*/Makefile))
|
||||
EXAMPLES_QUICK := $(filter-out ../examples/mip-pcap/ ../examples/micropython/, $(EXAMPLES))
|
||||
EXAMPLES_MAC := $(filter-out ../examples/mip-pcap/ ../examples/mip-tap/ ../examples/micropython/, $(EXAMPLES))
|
||||
EXAMPLES_WIN := $(dir $(wildcard ../examples/device-dashboard/Makefile) $(wildcard ../examples/file-*/Makefile) $(wildcard ../examples/http-*/Makefile) $(wildcard ../examples/mqtt-*/Makefile) $(wildcard ../examples/websocket-*/Makefile) $(wildcard ../examples/webui-*/Makefile))
|
||||
EXAMPLES_EMBEDDED := $(filter-out $(wildcard ../examples/zephyr/*/), $(dir $(wildcard ../examples/*/*/Makefile)))
|
||||
PREFIX ?= /usr/local
|
||||
LIBDIR ?= $(PREFIX)/lib
|
||||
INCLUDEDIR ?= $(PREFIX)/include
|
||||
VERSION ?= $(shell cut -d'"' -f2 ../src/version.h)
|
||||
COMMON_CFLAGS ?= $(C_WARN) $(WARN) $(INCS) $(DEFS) -DMG_ENABLE_IPV6=$(IPV6) $(TFLAGS) -pthread
|
||||
CFLAGS ?= $(OPTS) $(ASAN) $(COMMON_CFLAGS)
|
||||
VALGRIND_CFLAGS ?= $(OPTS) $(COMMON_CFLAGS)
|
||||
VALGRIND_RUN ?= valgrind --tool=memcheck --gen-suppressions=all --leak-check=full --show-leak-kinds=all --leak-resolution=high --track-origins=yes --error-exitcode=1 --exit-on-first-error=yes --fair-sched=yes
|
||||
.PHONY: clean_examples examples mip_test test valgrind
|
||||
|
||||
ifeq "$(findstring ++,$(CC))" ""
|
||||
# $(CC) does not end with ++, i.e. we're using C. Apply C flags
|
||||
C_WARN ?= -Wmissing-prototypes -Wstrict-prototypes
|
||||
else
|
||||
# $(CC) ends with ++, i.e. we're using C++. Apply C++ flags
|
||||
C_WARN ?= -Wno-deprecated
|
||||
endif
|
||||
|
||||
ifeq "$(SSL)" "MBEDTLS"
|
||||
MBEDTLS ?= /usr/local
|
||||
CFLAGS += -DMG_TLS=MG_TLS_MBED -I$(MBEDTLS)/include -I/usr/include
|
||||
LDFLAGS += -L$(MBEDTLS)/lib -lmbedtls -lmbedcrypto -lmbedx509
|
||||
endif
|
||||
|
||||
ifeq "$(SSL)" "OPENSSL"
|
||||
OPENSSL ?= /usr/local
|
||||
CFLAGS += -DMG_TLS=MG_TLS_OPENSSL -I$(OPENSSL)/include
|
||||
LDFLAGS += -L$(OPENSSL)/lib -lssl -lcrypto
|
||||
endif
|
||||
|
||||
ifeq "$(SSL)" "BUILTIN"
|
||||
CFLAGS += -DMG_TLS=MG_TLS_BUILTIN
|
||||
endif
|
||||
|
||||
all:
|
||||
$(MAKE) -C ../examples/http-server
|
||||
|
||||
tall: mg_prefix unamalgamated test mip_test arm examples vc98 vc17 vc22 mingw mingw++ fuzz
|
||||
|
||||
mip_test: mip_test.c mongoose.c mongoose.h Makefile mip_tap_test
|
||||
$(CC) mip_test.c $(INCS) $(WARN) $(OPTS) $(C_WARN) $(ASAN) -o $@
|
||||
ASAN_OPTIONS=$(ASAN_OPTIONS) $(RUN) ./$@
|
||||
|
||||
mip_tap_test: mip_tap_test.c mongoose.c mongoose.h Makefile
|
||||
$(CC) mip_tap_test.c $(INCS) $(WARN) $(OPTS) $(C_WARN) $(ASAN) -o $@
|
||||
ASAN_OPTIONS=$(ASAN_OPTIONS) $(RUN) ./$@
|
||||
|
||||
examples:
|
||||
@for X in $(EXAMPLES); do test -f $$X/Makefile || continue; $(MAKE) -C $$X example || exit 1; done
|
||||
clean_examples:
|
||||
for X in $(EXAMPLES); do test -f $$X/Makefile || continue; $(MAKE) -C $$X clean || exit 1; done
|
||||
|
||||
examples_essential:
|
||||
@for X in $(EXAMPLES_QUICK); do test -f $$X/Makefile || continue; $(MAKE) -C $$X example || exit 1; done
|
||||
clean_examples_essential:
|
||||
for X in $(EXAMPLES_QUICK); do test -f $$X/Makefile || continue; $(MAKE) -C $$X clean || exit 1; done
|
||||
|
||||
examples_mac:
|
||||
for X in $(EXAMPLES_MAC); do test -f $$X/Makefile || continue; $(MAKE) -C $$X example || exit 1; done
|
||||
clean_examples_mac:
|
||||
for X in $(EXAMPLES_MAC); do test -f $$X/Makefile || continue; $(MAKE) -C $$X clean || exit 1; done
|
||||
|
||||
examples_win:
|
||||
$(foreach X, $(EXAMPLES_WIN), $(MAKE) -C $(X) example &)
|
||||
clean_examples_win:
|
||||
$(foreach X, $(EXAMPLES_WIN), $(MAKE) -C $(X) clean &)
|
||||
|
||||
packed_fs.c: Makefile data/ssi.h fuzz.c data/a.txt data/ca.pem certs/ca.crt certs/server.crt certs/server.key
|
||||
$(CC) $(CFLAGS) pack.c -o pack
|
||||
$(RUN) ./pack Makefile data/ssi.h fuzz.c data/a.txt data/range.txt data/ca.pem certs/ca.crt certs/server.crt certs/server.key certs/client.key certs/client.crt > $@
|
||||
|
||||
# Check that all external (exported) symbols have "mg_" prefix
|
||||
mg_prefix: mongoose.c mongoose.h
|
||||
$(CC) mongoose.c $(CFLAGS) -c -o /tmp/x.o && nm /tmp/x.o | grep ' T ' | grep -v 'mg_' ; test $$? = 1
|
||||
|
||||
musl: test
|
||||
musl: ASAN =
|
||||
musl: WARN += -Wno-sign-conversion
|
||||
musl: CC = $(DOCKER) mdashnet/cc1 gcc
|
||||
musl: RUN = $(DOCKER) mdashnet/cc1
|
||||
|
||||
# Make sure we can build from unamalgamated sources.
|
||||
unamalgamated: CFLAGS += -DMG_ENABLE_MD5=1
|
||||
unamalgamated: $(HDRS) Makefile packed_fs.c
|
||||
$(CC) ../src/*.c packed_fs.c unit_test.c $(CFLAGS) $(LDFLAGS) -g -o unit_test
|
||||
|
||||
fuzz: ASAN = -fsanitize=fuzzer,signed-integer-overflow,address,undefined
|
||||
fuzz: mongoose.c mongoose.h Makefile fuzz.c
|
||||
$(CC) fuzz.c $(OPTS) $(WARN) $(INCS) $(TFLAGS) $(ASAN) -o fuzzer
|
||||
$(RUN) ./fuzzer
|
||||
|
||||
FUZZDATA ?= /tmp/fuzzdata
|
||||
fuzz2: mongoose.c mongoose.h Makefile fuzz.c
|
||||
$(CC) fuzz.c -DMAIN $(OPTS) $(WARN) $(ASAN) $(INCS) -o fuzzer
|
||||
$(RUN) ./fuzzer $(FUZZDATA)
|
||||
|
||||
test: Makefile mongoose.h $(SRCS)
|
||||
$(CC) $(SRCS) $(CFLAGS) $(LDFLAGS) -o unit_test
|
||||
ASAN_OPTIONS=$(ASAN_OPTIONS) $(RUN) ./unit_test
|
||||
|
||||
coverage: CFLAGS += -coverage
|
||||
coverage: test
|
||||
gcov -l -n *.gcno | sed '/^$$/d' | sed 'N;s/\n/ /'
|
||||
gcov -t mongoose.c > mongoose.gcov
|
||||
|
||||
upload-coverage: coverage
|
||||
curl -s https://codecov.io/bash | /bin/bash
|
||||
|
||||
valgrind: Makefile mongoose.h $(SRCS)
|
||||
$(CC) $(SRCS) $(VALGRIND_CFLAGS) $(LDFLAGS) -g -o unit_test
|
||||
$(VALGRIND_RUN) ./unit_test
|
||||
|
||||
misra:
|
||||
cppcheck --addon=misra -DMG_ARCH=MG_ARCH_UNIX -DMG_ENABLE_PACKED_FS=1 -DMG_ENABLE_SSI=1 mongoose.c >/tmp/x 2>&1
|
||||
cppcheck --addon=misra -DMG_ARCH=MG_ARCH_CUSTOM -DMG_ENABLE_LINES=1 -DTLS=MG_TLS_BUILTIN -DMG_ENABLE_TCPIP=1 mongoose.c >>/tmp/x 2>&1
|
||||
cppcheck --addon=misra --clang -DMG_ENABLE_LINES=1 -DTLS=MG_TLS_BUILTIN -DMG_ENABLE_TCPIP=1 mongoose.c >>/tmp/x 2>&1
|
||||
cppcheck --addon=misra --clang -DMG_ENABLE_LINES=1 -DMG_ENABLE_SSI=1 mongoose.c >>/tmp/x 2>&1
|
||||
less /tmp/x
|
||||
|
||||
armhf: ASAN=
|
||||
armhf: IPV6=0
|
||||
armhf: CC = $(DOCKER) mdashnet/armhf cc
|
||||
armhf: RUN = $(DOCKER) mdashnet/armhf
|
||||
armhf: test
|
||||
|
||||
s390: ASAN=
|
||||
s390: IPV6=0
|
||||
s390: CC = $(DOCKER) mdashnet/s390 cc
|
||||
s390: RUN = $(DOCKER) mdashnet/s390
|
||||
s390: test
|
||||
|
||||
arm: DEFS += -DMG_ENABLE_POSIX_FS=0 -DMG_ENABLE_TCPIP=1 -DMG_ENABLE_TCPIP_DRIVER_INIT=0 -DMG_ARCH=MG_ARCH_NEWLIB
|
||||
arm: mongoose.h $(SRCS)
|
||||
$(DOCKER) mdashnet/armgcc arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb $(SRCS) $(OPTS) $(WARN) $(INCS) $(DEFS) $(TFLAGS) -o unit_test -nostartfiles --specs nosys.specs -e 0
|
||||
|
||||
riscv: DEFS += -DMG_ENABLE_POSIX_FS=0 -DMG_ENABLE_TCPIP=1 -DMG_ENABLE_TCPIP_DRIVER_INIT=0 -DMG_ARCH=MG_ARCH_NEWLIB
|
||||
riscv: mongoose.h $(SRCS)
|
||||
$(DOCKER) mdashnet/riscv riscv-none-elf-gcc -march=rv32imc -mabi=ilp32 $(SRCS) $(OPTS) $(WARN) $(INCS) $(DEFS) $(TFLAGS) -o unit_test
|
||||
|
||||
vc98: Makefile mongoose.h $(SRCS)
|
||||
$(DOCKER) mdashnet/vc98 wine cl $(SRCS) $(VCFLAGS) ws2_32.lib /Fe$@.exe
|
||||
$(DOCKER) mdashnet/vc98 wine $@.exe
|
||||
|
||||
vc17: Makefile mongoose.h $(SRCS)
|
||||
$(DOCKER) mdashnet/vc17 wine64 cl $(SRCS) $(VCFLAGS) ws2_32.lib /Fe$@.exe
|
||||
$(DOCKER) mdashnet/vc17 wine64 $@.exe
|
||||
|
||||
vc22: Makefile mongoose.h $(SRCS)
|
||||
$(DOCKER) mdashnet/vc22 wine64 cl $(SRCS) $(VCFLAGS) ws2_32.lib /Fe$@.exe
|
||||
$(DOCKER) mdashnet/vc22 wine64 $@.exe
|
||||
|
||||
mingw: Makefile mongoose.h $(SRCS)
|
||||
$(DOCKER) mdashnet/mingw x86_64-w64-mingw32-gcc $(SRCS) -W -Wall -Werror -I. $(DEFS) -lwsock32 -o $@.exe
|
||||
$(DOCKER) mdashnet/mingw wine64 $@.exe
|
||||
|
||||
mingw++: Makefile mongoose.h $(SRCS)
|
||||
$(DOCKER) mdashnet/mingw x86_64-w64-mingw32-g++ $(SRCS) -W -Wall -Werror -I. $(DEFS) -lwsock32 -o $@.exe
|
||||
|
||||
linux-libs: CFLAGS += -fPIC
|
||||
linux-libs: LDFLAGS += -Wl,-soname,libmongoose.so.$(VERSION)
|
||||
linux-libs: mongoose.o
|
||||
$(CC) mongoose.o $(LDFLAGS) -shared -o libmongoose.so.$(VERSION)
|
||||
$(AR) rcs libmongoose.a mongoose.o
|
||||
|
||||
install: linux-libs
|
||||
install -Dm644 libmongoose.a libmongoose.so.$(VERSION) $(DESTDIR)$(LIBDIR)
|
||||
ln -s libmongoose.so.$(VERSION) $(DESTDIR)$(LIBDIR)/libmongoose.so
|
||||
install -Dm644 mongoose.h $(DESTDIR)$(INCLUDEDIR)/mongoose.h
|
||||
|
||||
uninstall:
|
||||
rm -rf $(DESTDIR)$(LIBDIR)/libmongoose.a $(DESTDIR)$(LIBDIR)/libmongoose.so.$(VERSION) $(DESTDIR)$(INCLUDEDIR)/mongoose.h $(DESTDIR)$(LIBDIR)/libmongoose.so
|
||||
|
||||
mongoose.c: Makefile $(wildcard src/*.c) $(wildcard src/drivers/*.c)
|
||||
cd .. && (export LC_ALL=C ; cat src/license.h; echo; echo '#include "mongoose.h"' ; (for F in src/*.c src/drivers/*.c ; do echo; echo '#ifdef MG_ENABLE_LINES'; echo "#line 1 \"$$F\""; echo '#endif'; cat $$F | sed -e 's,#include ".*,,'; done))> $@
|
||||
|
||||
mongoose.h: $(HDRS) Makefile
|
||||
cd .. && (cat src/license.h; echo; echo '#ifndef MONGOOSE_H'; echo '#define MONGOOSE_H'; echo; cat src/version.h ; echo; echo '#ifdef __cplusplus'; echo 'extern "C" {'; echo '#endif'; cat src/arch.h src/arch_*.h src/net_ft.h src/net_lwip.h src/net_rl.h src/config.h src/str.h src/queue.h src/fmt.h src/printf.h src/log.h src/timer.h src/fs.h src/util.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/sha256.h src/tls_x25519.h src/tls_aes128.h src/tls_uecc.h src/event.h src/net.h src/http.h src/ssi.h src/tls.h src/tls_mbed.h src/tls_openssl.h src/ws.h src/sntp.h src/mqtt.h src/dns.h src/json.h src/rpc.h src/ota.h src/device.h src/net_builtin.h src/profile.h src/drivers/*.h | sed -e '/keep/! s,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@
|
||||
|
||||
|
||||
clean: clean_examples clean_examples_embedded
|
||||
rm -rf $(PROG) *.exe *.o *.dSYM *_test* ut fuzzer *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb slow-unit* _CL_* infer-out data.txt crash-* packed_fs.c pack
|
||||
#find examples -maxdepth 3 -name zephyr -prune -o -name Makefile -print | xargs dirname | xargs -n1 make clean -C
|
||||
|
||||
examples_embedded:
|
||||
@for X in $(EXAMPLES_EMBEDDED); do test -f $$X/Makefile || continue; $(MAKE) -C $$X build || exit 1; done
|
||||
clean_examples_embedded:
|
||||
for X in $(EXAMPLES_EMBEDDED); do test -f $$X/Makefile || continue; $(MAKE) -C $$X clean || exit 1; done
|
||||
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../src/ssi.h
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../fuzz.c
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../src/version.h
|
||||
+4
-5
@@ -123,13 +123,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
int main(int argc, char *argv[]) {
|
||||
int res = EXIT_FAILURE;
|
||||
if (argc > 1) {
|
||||
size_t len = 0;
|
||||
char *buf = mg_file_read(&mg_fs_posix, argv[1], &len);
|
||||
if (buf != NULL) {
|
||||
LLVMFuzzerTestOneInput((uint8_t *) buf, len);
|
||||
struct mg_str data = mg_file_read(&mg_fs_posix, argv[1]);
|
||||
if (data.buf != NULL) {
|
||||
LLVMFuzzerTestOneInput((uint8_t *) data.buf, data.len);
|
||||
res = EXIT_SUCCESS;
|
||||
}
|
||||
free(buf);
|
||||
free(data.buf);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../mongoose.c
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../mongoose.h
|
||||
+30
-26
@@ -652,21 +652,21 @@ static void eh1(struct mg_connection *c, int ev, void *ev_data) {
|
||||
} else if (mg_match(hm->uri, mg_str("/upload"), NULL)) {
|
||||
mg_http_upload(c, hm, &mg_fs_posix, ".", 99999);
|
||||
c->is_hexdumping = 1;
|
||||
} else if (mg_match(hm->uri, mg_str("/test/"), NULL)) {
|
||||
} else if (mg_match(hm->uri, mg_str("/dirtest/"), NULL)) {
|
||||
struct mg_http_serve_opts sopts;
|
||||
memset(&sopts, 0, sizeof(sopts));
|
||||
sopts.root_dir = ".";
|
||||
sopts.extra_headers = "A: B\r\nC: D\r\n";
|
||||
sopts.extra_headers = "A: B\r\nE: F\r\n";
|
||||
mg_http_serve_dir(c, hm, &sopts);
|
||||
} else if (mg_match(hm->uri, mg_str("/servefile"), NULL)) {
|
||||
struct mg_http_serve_opts sopts;
|
||||
memset(&sopts, 0, sizeof(sopts));
|
||||
sopts.mime_types = "foo=a/b,txt=c/d";
|
||||
mg_http_serve_file(c, hm, "test/data/a.txt", &sopts);
|
||||
mg_http_serve_file(c, hm, "data/a.txt", &sopts);
|
||||
} else {
|
||||
struct mg_http_serve_opts sopts;
|
||||
memset(&sopts, 0, sizeof(sopts));
|
||||
sopts.root_dir = "./test/data";
|
||||
sopts.root_dir = "./data";
|
||||
sopts.ssi_pattern = "#.shtml";
|
||||
sopts.extra_headers = "C: D\r\n";
|
||||
mg_http_serve_dir(c, hm, &sopts);
|
||||
@@ -713,10 +713,10 @@ static int fetch(struct mg_mgr *mgr, char *buf, const char *url,
|
||||
struct mg_tls_opts opts;
|
||||
memset(&opts, 0, sizeof(opts)); // read CA from packed_fs
|
||||
opts.name = mg_url_host(url);
|
||||
opts.ca = mg_unpacked("/test/data/ca.pem");
|
||||
opts.ca = mg_unpacked("/data/ca.pem");
|
||||
if (strstr(url, "localhost") != NULL) {
|
||||
// Local connection, use self-signed certificates
|
||||
opts.ca = mg_unpacked("/test/certs/ca.crt");
|
||||
opts.ca = mg_unpacked("/certs/ca.crt");
|
||||
// opts.cert = mg_str(s_tls_cert);
|
||||
// opts.key = mg_str(s_tls_key);
|
||||
}
|
||||
@@ -843,6 +843,7 @@ static void test_http_server(void) {
|
||||
|
||||
ASSERT(fetch(&mgr, buf, url, "GET /a.txt HTTP/1.0\n\n") == 200);
|
||||
ASSERT(cmpbody(buf, "hello\n") == 0);
|
||||
ASSERT(cmpheader(buf, "C", "D"));
|
||||
|
||||
// Invalid header: failure
|
||||
ASSERT(fetch(&mgr, buf, url, "GET /a.txt HTTP/1.0\nA B\n\n") == 0);
|
||||
@@ -914,7 +915,7 @@ static void test_http_server(void) {
|
||||
char etag[100];
|
||||
size_t size = 0;
|
||||
time_t mtime = 0;
|
||||
ASSERT(mg_fs_posix.st("./test/data/a.txt", &size, &mtime) != 0);
|
||||
ASSERT(mg_fs_posix.st("./data/a.txt", &size, &mtime) != 0);
|
||||
ASSERT(mg_http_etag(etag, sizeof(etag), size, mtime) == etag);
|
||||
ASSERT(fetch(&mgr, buf, url, "GET /a.txt HTTP/1.0\nIf-None-Match: %s\n\n",
|
||||
etag) == 304);
|
||||
@@ -968,7 +969,7 @@ static void test_http_server(void) {
|
||||
// ASSERT(cmpbody(buf, "Invalid web root [/BAAADDD!]\n") == 0);
|
||||
|
||||
{
|
||||
struct mg_str data = mg_file_read(&mg_fs_posix, "./test/data/ca.pem");
|
||||
struct mg_str data = mg_file_read(&mg_fs_posix, "./data/ca.pem");
|
||||
ASSERT(fetch(&mgr, buf, url, "GET /ca.pem HTTP/1.0\r\n\n") == 200);
|
||||
ASSERT(cmpbody(buf, data.buf) == 0);
|
||||
free((void *) data.buf);
|
||||
@@ -995,10 +996,13 @@ static void test_http_server(void) {
|
||||
}
|
||||
|
||||
// Directory listing
|
||||
fetch(&mgr, buf, url, "GET /test/ HTTP/1.0\n\n");
|
||||
ASSERT(fetch(&mgr, buf, url, "GET /test/ HTTP/1.0\n\n") == 200);
|
||||
ASSERT(mg_strstr(mg_str(buf), mg_str(">Index of /test/<")) != NULL);
|
||||
fetch(&mgr, buf, url, "GET /dirtest/ HTTP/1.0\n\n");
|
||||
ASSERT(fetch(&mgr, buf, url, "GET /dirtest/ HTTP/1.0\n\n") == 200);
|
||||
ASSERT(mg_strstr(mg_str(buf), mg_str(">Index of /dirtest/<")) != NULL);
|
||||
ASSERT(mg_strstr(mg_str(buf), mg_str(">fuzz.c<")) != NULL);
|
||||
ASSERT(cmpheader(buf, "A", "B"));
|
||||
ASSERT(!cmpheader(buf, "C", "D"));
|
||||
ASSERT(cmpheader(buf, "E", "F"));
|
||||
|
||||
{
|
||||
// Credentials
|
||||
@@ -1119,19 +1123,19 @@ static void h4(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (mg_match(hm->uri, mg_str("/a/#"), NULL)) {
|
||||
struct mg_http_serve_opts opts;
|
||||
memset(&opts, 0, sizeof(opts));
|
||||
opts.root_dir = "/a=./test/data";
|
||||
opts.page404 = "./test/data/404.html"; // existing 404 page
|
||||
opts.root_dir = "/a=./data";
|
||||
opts.page404 = "./data/404.html"; // existing 404 page
|
||||
mg_http_serve_dir(c, hm, &opts);
|
||||
} else if (mg_match(hm->uri, mg_str("/b/#"), NULL)) {
|
||||
struct mg_http_serve_opts opts;
|
||||
memset(&opts, 0, sizeof(opts));
|
||||
opts.root_dir = "/b=./test/data";
|
||||
opts.page404 = "./test/data/nooooo.html"; // non-existing 404 page
|
||||
opts.root_dir = "/b=./data";
|
||||
opts.page404 = "./data/nooooo.html"; // non-existing 404 page
|
||||
mg_http_serve_dir(c, hm, &opts);
|
||||
} else { // null 404 page
|
||||
struct mg_http_serve_opts opts;
|
||||
memset(&opts, 0, sizeof(opts));
|
||||
opts.root_dir = "./test/data";
|
||||
opts.root_dir = "./data";
|
||||
mg_http_serve_dir(c, hm, &opts);
|
||||
}
|
||||
}
|
||||
@@ -1183,8 +1187,8 @@ static void test_tls(void) {
|
||||
struct mg_str data = mg_unpacked("/Makefile");
|
||||
memset(&opts, 0, sizeof(opts));
|
||||
// opts.ca = mg_str(s_tls_ca);
|
||||
opts.cert = mg_unpacked("/test/certs/server.crt");
|
||||
opts.key = mg_unpacked("/test/certs/server.key");
|
||||
opts.cert = mg_unpacked("/certs/server.crt");
|
||||
opts.key = mg_unpacked("/certs/server.key");
|
||||
mg_mgr_init(&mgr);
|
||||
c = mg_http_listen(&mgr, url, eh1, &opts);
|
||||
ASSERT(c != NULL);
|
||||
@@ -1231,7 +1235,7 @@ static void test_http_client(void) {
|
||||
int i, ok = 0;
|
||||
struct mg_tls_opts opts;
|
||||
memset(&opts, 0, sizeof(opts));
|
||||
opts.ca = mg_unpacked("/test/data/ca.pem");
|
||||
opts.ca = mg_unpacked("/data/ca.pem");
|
||||
opts.name = mg_url_host(url);
|
||||
ASSERT(opts.ca.len > 0);
|
||||
ASSERT(opts.name.len > 0);
|
||||
@@ -1303,7 +1307,7 @@ static void test_host_validation(void) {
|
||||
ok = 0;
|
||||
c = mg_http_connect(&mgr, url, f3, &ok);
|
||||
ASSERT(c != NULL);
|
||||
opts.ca = mg_unpacked("/test/data/ca.pem");
|
||||
opts.ca = mg_unpacked("/data/ca.pem");
|
||||
opts.name = mg_url_host(url);
|
||||
mg_tls_init(c, &opts);
|
||||
for (i = 0; i < 1500 && ok <= 0; i++) mg_mgr_poll(&mgr, 10);
|
||||
@@ -1617,7 +1621,7 @@ static void ehr(struct mg_connection *c, int ev, void *ev_data) {
|
||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||
struct mg_http_serve_opts opts;
|
||||
memset(&opts, 0, sizeof(opts));
|
||||
opts.root_dir = "./test/data";
|
||||
opts.root_dir = "./data";
|
||||
mg_http_serve_dir(c, hm, &opts);
|
||||
}
|
||||
}
|
||||
@@ -2635,8 +2639,8 @@ static void test_packed(void) {
|
||||
free((void *) data.buf);
|
||||
|
||||
// Load file deeper in the FS tree directly
|
||||
data = mg_file_read(&mg_fs_posix, "src/ssi.h");
|
||||
ASSERT(fetch(&mgr, buf, url, "GET /src/ssi.h HTTP/1.0\n\n") == 200);
|
||||
data = mg_file_read(&mg_fs_posix, "data/ssi.h");
|
||||
ASSERT(fetch(&mgr, buf, url, "GET /data/ssi.h HTTP/1.0\n\n") == 200);
|
||||
ASSERT(cmpbody(buf, data.buf) == 0);
|
||||
free((void *) data.buf);
|
||||
|
||||
@@ -2645,8 +2649,8 @@ static void test_packed(void) {
|
||||
// printf("--------\n%s\n", buf);
|
||||
|
||||
// List nested dir
|
||||
ASSERT(fetch(&mgr, buf, url, "GET /test HTTP/1.0\n\n") == 301);
|
||||
ASSERT(fetch(&mgr, buf, url, "GET /test/ HTTP/1.0\n\n") == 200);
|
||||
ASSERT(fetch(&mgr, buf, url, "GET /data HTTP/1.0\n\n") == 301);
|
||||
ASSERT(fetch(&mgr, buf, url, "GET /data/ HTTP/1.0\n\n") == 200);
|
||||
// printf("--------\n%s\n", buf);
|
||||
|
||||
mg_mgr_free(&mgr);
|
||||
@@ -2782,7 +2786,7 @@ static void h7(struct mg_connection *c, int ev, void *ev_data) {
|
||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||
struct mg_http_serve_opts opts;
|
||||
memset(&opts, 0, sizeof(opts));
|
||||
opts.root_dir = "./test/data,/foo=./src";
|
||||
opts.root_dir = "./data,/foo=./dirtest";
|
||||
mg_http_serve_dir(c, hm, &opts);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user