For the start with cgi-exec testing.
Signed-off-by: Petr Štetiar <ynezz@true.cz>
+ADD_SUBDIRECTORY(cram)
+
IF(CMAKE_C_COMPILER_ID STREQUAL "Clang")
ADD_SUBDIRECTORY(fuzz)
ADD_SUBDIRECTORY(fuzz-multipart-parser)
--- /dev/null
+FIND_PACKAGE(PythonInterp 3 REQUIRED)
+FILE(GLOB test_cases "test_*.t")
+
+IF(CMAKE_C_COMPILER_ID STREQUAL "Clang")
+ FILE(GLOB test_cases_san "test-san_*.t")
+ENDIF()
+
+SET(PYTHON_VENV_DIR "${CMAKE_CURRENT_BINARY_DIR}/.venv")
+SET(PYTHON_VENV_PIP "${PYTHON_VENV_DIR}/bin/pip")
+SET(PYTHON_VENV_CRAM "${PYTHON_VENV_DIR}/bin/cram")
+
+ADD_CUSTOM_COMMAND(
+ OUTPUT ${PYTHON_VENV_CRAM}
+ COMMAND ${PYTHON_EXECUTABLE} -m venv ${PYTHON_VENV_DIR}
+ COMMAND ${PYTHON_VENV_PIP} install cram
+)
+ADD_CUSTOM_TARGET(prepare-cram-venv ALL DEPENDS ${PYTHON_VENV_CRAM})
+
+ADD_TEST(
+ NAME cram
+ COMMAND ${PYTHON_VENV_CRAM} ${test_cases} ${test_cases_san}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+SET_PROPERTY(TEST cram APPEND PROPERTY ENVIRONMENT "BUILD_BIN_DIR=$<TARGET_FILE_DIR:cgi-io>")
--- /dev/null
+sessionid=0&
--- /dev/null
+sessionid=0&command=basename /tmp/foo&
--- /dev/null
+sessionid=0&command=basename /king/banik/1922&filename=output.txt&mimetype=0&
--- /dev/null
+check that cgi-exec is producing expected results:
+
+ $ [ -n "$BUILD_BIN_DIR" ] && export PATH="$BUILD_BIN_DIR:$PATH"
+ $ ln -sf $BUILD_BIN_DIR/cgi-io-san $BUILD_BIN_DIR/cgi-exec
+
+ $ for file in $(LC_ALL=C find "$TESTDIR/test-cases" -type f | sort); do
+ > export CONTENT_TYPE="application/x-www-form-urlencoded"; \
+ > export CONTENT_LENGTH="$(wc -c < $file)"; \
+ > printf "\n[-] testing: $(basename $file)\n"; \
+ > cgi-exec < $file; \
+ > done
+
+ [-] testing: cgi-exec-01.txt
+ Status: 400 Invalid command parameter\r (esc)
+ Content-Type: text/plain\r (esc)
+ \r (esc)
+ Invalid command parameter
+
+ [-] testing: cgi-exec-02.txt
+ Status: 200 OK\r (esc)
+ Content-Type: application/octet-stream\r (esc)
+ \r (esc)
+ foo
+
+ [-] testing: cgi-exec-03.txt
+ Status: 200 OK\r (esc)
+ Content-Type: 0\r (esc)
+ Content-Disposition: attachment; filename="output.txt"\r (esc)
+ \r (esc)
+ 1922
--- /dev/null
+check that cgi-exec is producing expected results:
+
+ $ [ -n "$BUILD_BIN_DIR" ] && export PATH="$BUILD_BIN_DIR:$PATH"
+ $ ln -sf $BUILD_BIN_DIR/cgi-io $BUILD_BIN_DIR/cgi-exec
+
+ $ for file in $(LC_ALL=C find "$TESTDIR/test-cases" -type f | sort); do
+ > export CONTENT_TYPE="application/x-www-form-urlencoded"; \
+ > export CONTENT_LENGTH="$(wc -c < $file)"; \
+ > printf "\n[-] testing: $(basename $file)\n"; \
+ > valgrind --quiet --leak-check=full cgi-exec < $file; \
+ > done
+
+ [-] testing: cgi-exec-01.txt
+ Status: 400 Invalid command parameter\r (esc)
+ Content-Type: text/plain\r (esc)
+ \r (esc)
+ Invalid command parameter
+
+ [-] testing: cgi-exec-02.txt
+ Status: 200 OK\r (esc)
+ Content-Type: application/octet-stream\r (esc)
+ \r (esc)
+ foo
+
+ [-] testing: cgi-exec-03.txt
+ Status: 200 OK\r (esc)
+ Content-Type: 0\r (esc)
+ Content-Disposition: attachment; filename="output.txt"\r (esc)
+ \r (esc)
+ 1922