From patchwork Mon Oct 12 12:37:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1380889 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=itYfxYwr; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C8ytM329lz9sTf for ; Mon, 12 Oct 2020 23:39:39 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=3pMQumgJaxB3zUTpkwV4g4lmBGstbB0hgICYjc6dTwk=; b=itYfxYwroyKJwWxtwf+pMJsGj u35N0twGhECx2poURTnI/1RH0gqOUZgp1keYa0mRAPbVVv1GN8QTxdXBpz7J/TRMXa3f0fl8A0+pc bauFZl+Y7ShM3gVTLtXDUA+tNMy7rpGSNviNiMwwswf+h8n3H4U2sWns3MfEGiW0vSV3nRRennmSK e+NrHBcwYSh4xjmHa2yR3BNSuI4OHaUVgKBYwpp3KLug6FnniQGE54ZtvcQOrkbGc+pheyNVpmxZJ BDajc0c/HHACJWe7iDJTh/hX3tqSXm4GdCZFrSqLnwu6v62uNEnGefm6i7Ul24RDojAiQAIZ1fBYo vIwrJYM3g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kRx5U-0002vr-58; Mon, 12 Oct 2020 12:38:00 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kRx52-0002oX-Ss for openwrt-devel@lists.openwrt.org; Mon, 12 Oct 2020 12:37:37 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id E67AC35EC; Mon, 12 Oct 2020 14:37:29 +0200 (CEST) Received: by meh.true.cz (OpenSMTPD) with ESMTP id fd155949; Mon, 12 Oct 2020 14:37:12 +0200 (CEST) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH cgi-io 12/12] tests: add cram based unit tests Date: Mon, 12 Oct 2020 14:37:18 +0200 Message-Id: <20201012123718.25623-13-ynezz@true.cz> In-Reply-To: <20201012123718.25623-1-ynezz@true.cz> References: <20201012123718.25623-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201012_083733_184636_F811E012 X-CRM114-Status: GOOD ( 20.87 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org For the start with cgi-exec testing. Signed-off-by: Petr Štetiar --- tests/CMakeLists.txt | 2 ++ tests/cram/CMakeLists.txt | 25 ++++++++++++++++++++++ tests/cram/test-cases/cgi-exec-01.txt | 1 + tests/cram/test-cases/cgi-exec-02.txt | 1 + tests/cram/test-cases/cgi-exec-03.txt | 1 + tests/cram/test-san_cgi-exec.t | 30 +++++++++++++++++++++++++++ tests/cram/test_cgi-exec.t | 30 +++++++++++++++++++++++++++ 7 files changed, 90 insertions(+) create mode 100644 tests/cram/CMakeLists.txt create mode 100644 tests/cram/test-cases/cgi-exec-01.txt create mode 100644 tests/cram/test-cases/cgi-exec-02.txt create mode 100644 tests/cram/test-cases/cgi-exec-03.txt create mode 100644 tests/cram/test-san_cgi-exec.t create mode 100644 tests/cram/test_cgi-exec.t diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index efad20642dd6..5306b913c0d9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,3 +1,5 @@ +ADD_SUBDIRECTORY(cram) + IF(CMAKE_C_COMPILER_ID STREQUAL "Clang") ADD_SUBDIRECTORY(fuzz) ADD_SUBDIRECTORY(fuzz-multipart-parser) diff --git a/tests/cram/CMakeLists.txt b/tests/cram/CMakeLists.txt new file mode 100644 index 000000000000..d8b317c40b47 --- /dev/null +++ b/tests/cram/CMakeLists.txt @@ -0,0 +1,25 @@ +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=$") diff --git a/tests/cram/test-cases/cgi-exec-01.txt b/tests/cram/test-cases/cgi-exec-01.txt new file mode 100644 index 000000000000..0b03e8b008a1 --- /dev/null +++ b/tests/cram/test-cases/cgi-exec-01.txt @@ -0,0 +1 @@ +sessionid=0& diff --git a/tests/cram/test-cases/cgi-exec-02.txt b/tests/cram/test-cases/cgi-exec-02.txt new file mode 100644 index 000000000000..a4969b8148e0 --- /dev/null +++ b/tests/cram/test-cases/cgi-exec-02.txt @@ -0,0 +1 @@ +sessionid=0&command=basename /tmp/foo& diff --git a/tests/cram/test-cases/cgi-exec-03.txt b/tests/cram/test-cases/cgi-exec-03.txt new file mode 100644 index 000000000000..3561f1099a45 --- /dev/null +++ b/tests/cram/test-cases/cgi-exec-03.txt @@ -0,0 +1 @@ +sessionid=0&command=basename /king/banik/1922&filename=output.txt&mimetype=0& diff --git a/tests/cram/test-san_cgi-exec.t b/tests/cram/test-san_cgi-exec.t new file mode 100644 index 000000000000..e4a33565f84a --- /dev/null +++ b/tests/cram/test-san_cgi-exec.t @@ -0,0 +1,30 @@ +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 diff --git a/tests/cram/test_cgi-exec.t b/tests/cram/test_cgi-exec.t new file mode 100644 index 000000000000..d5cffb45e871 --- /dev/null +++ b/tests/cram/test_cgi-exec.t @@ -0,0 +1,30 @@ +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