diff options
Diffstat (limited to 'tests/blogc-git-receiver')
-rwxr-xr-x | tests/blogc-git-receiver/check_post_receive.sh.in | 116 | ||||
-rwxr-xr-x | tests/blogc-git-receiver/check_pre_receive.sh.in | 304 | ||||
-rw-r--r-- | tests/blogc-git-receiver/check_pre_receive_parser.c | 134 | ||||
-rw-r--r-- | tests/blogc-git-receiver/check_settings.c | 91 | ||||
-rwxr-xr-x | tests/blogc-git-receiver/check_shell.sh.in | 95 | ||||
-rw-r--r-- | tests/blogc-git-receiver/check_shell_command_parser.c | 215 |
6 files changed, 0 insertions, 955 deletions
diff --git a/tests/blogc-git-receiver/check_post_receive.sh.in b/tests/blogc-git-receiver/check_post_receive.sh.in deleted file mode 100755 index 74d4df2..0000000 --- a/tests/blogc-git-receiver/check_post_receive.sh.in +++ /dev/null @@ -1,116 +0,0 @@ -#!@BASH@ - -set -xe -o pipefail - -export LC_ALL=C - -TEMP="$(mktemp -d)" -[[ -n "${TEMP}" ]] - -trap_func() { - [[ -e "${TEMP}/output.txt" ]] && cat "${TEMP}/output.txt" - [[ -n "${TEMP}" ]] && rm -rf "${TEMP}" -} - -trap trap_func EXIT - -mkdir -p "${TEMP}/repos" -git init --bare "${TEMP}/repos/foo.git" &> /dev/null - -ln -s "@abs_top_builddir@/blogc-git-receiver" "${TEMP}/repos/foo.git/hooks/post-receive" - -cat > "${TEMP}/tmp.txt" <<EOF -blob -mark :1 -data 4 -bar - -reset refs/heads/master -commit refs/heads/master -mark :2 -author Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476033730 +0200 -committer Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476033888 +0200 -data 11 -testing... -M 100644 :1 foo - -EOF - -cd "${TEMP}/repos/foo.git" -git fast-import < "${TEMP}/tmp.txt" &> /dev/null - -git init --bare "${TEMP}/repos/bar.git" &> /dev/null - -HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./hooks/post-receive 2>&1 | tee "${TEMP}/output.txt" -grep "warning: repository mirroring disabled" "${TEMP}/output.txt" &> /dev/null - -git config --local remote.mirror.pushurl "${TEMP}/repos/bar.git" -HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./hooks/post-receive 2>&1 | tee "${TEMP}/output.txt" -grep "[new branch] *master" "${TEMP}/output.txt" &> /dev/null - -git config --local --unset remote.mirror.pushurl -git init --bare "${TEMP}/repos/bar2.git" &> /dev/null -git config --local remote.mirror.url "${TEMP}/repos/bar2.git" -HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./hooks/post-receive 2>&1 | tee "${TEMP}/output.txt" -grep "[new branch] *master" "${TEMP}/output.txt" &> /dev/null - -git config --local --unset remote.mirror.url -cat > "${TEMP}/blogc-git-receiver.ini" <<EOF -[repo:boo.git] -mirror = 123 - -[repo:foo.git] -mirror = ${TEMP}/repos/bar3.git - -[repo:bar.git] -mirror = lol -EOF -git init --bare "${TEMP}/repos/bar3.git" &> /dev/null -HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./hooks/post-receive 2>&1 | tee "${TEMP}/output.txt" -grep "[new branch] *master" "${TEMP}/output.txt" &> /dev/null - -cat > "${TEMP}/blogc-git-receiver.ini" <<EOF -asd[repo:boo.git] -mirror = 123 - -[repo:foo.git] -mirror = ${TEMP}/repos/bar4.git - -[repo:bar.git] -mirror = lol -EOF -git init --bare "${TEMP}/repos/bar4.git" &> /dev/null -HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./hooks/post-receive 2>&1 | tee "${TEMP}/output.txt" -grep "warning: failed to parse configuration file " "${TEMP}/output.txt" &> /dev/null - -cd .. -cat > "${TEMP}/blogc-git-receiver.ini" <<EOF -[repo:boo.git] -mirror = 123 - -[repo:foo.git] -mirror = ${TEMP}/repos/bar5.git - -[repo:bar.git] -mirror = lol -EOF -git init --bare "${TEMP}/repos/bar5.git" &> /dev/null -HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./foo.git/hooks/post-receive 2>&1 | tee "${TEMP}/output.txt" -grep "[new branch] *master" "${TEMP}/output.txt" &> /dev/null - -cd .. -cat > "${TEMP}/blogc-git-receiver.ini" <<EOF -[repo:boo.git] -mirror = 123 - -[repo:foo.git] -mirror = ${TEMP}/repos/bar6.git - -[repo:bar.git] -mirror = lol -EOF -git init --bare "${TEMP}/repos/bar6.git" &> /dev/null -BLOGC_GIT_RECEIVER_BASE_DIR="${TEMP}" ${TESTS_ENVIRONMENT} ./repos/foo.git/hooks/post-receive 2>&1 | tee "${TEMP}/output.txt" -grep "[new branch] *master" "${TEMP}/output.txt" &> /dev/null - -rm "${TEMP}/output.txt" diff --git a/tests/blogc-git-receiver/check_pre_receive.sh.in b/tests/blogc-git-receiver/check_pre_receive.sh.in deleted file mode 100755 index 2cf3c89..0000000 --- a/tests/blogc-git-receiver/check_pre_receive.sh.in +++ /dev/null @@ -1,304 +0,0 @@ -#!@BASH@ - -set -xe -o pipefail - -export LC_ALL=C - -TEMP="$(mktemp -d)" -[[ -n "${TEMP}" ]] - -trap_func() { - [[ -e "${TEMP}/output.txt" ]] && cat "${TEMP}/output.txt" - [[ -n "${TEMP}" ]] && rm -rf "${TEMP}" -} - -trap trap_func EXIT - -mkdir -p "${TEMP}/repos" -git init --bare "${TEMP}/repos/foo.git" &> /dev/null - -SELF="@abs_top_builddir@/blogc-git-receiver" - -ln -s "${SELF}" "${TEMP}/repos/foo.git/hooks/pre-receive" - -cat > "${TEMP}/payload.txt" <<EOF -0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/foo -0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/bar -EOF - -cd "${TEMP}/repos/foo.git" - -SHELL="${SELF}" HOME="${TEMP}" GIT_DIR=. ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt" -grep "warning: no suitable branch found. nothing to deploy." "${TEMP}/output.txt" &> /dev/null - -cat > "${TEMP}/tmp.txt" <<EOF -blob -mark :1 -data 63 -all: - mkdir -p \$(OUTPUT_DIR) - echo lol > \$(OUTPUT_DIR)/foo.txt - -reset refs/heads/master -commit refs/heads/master -mark :2 -author Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476139736 +0200 -committer Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476139736 +0200 -data 11 -testing... -M 100644 :1 Makefil - -EOF - -git fast-import < "${TEMP}/tmp.txt" &> /dev/null - -cat > "${TEMP}/payload.txt" <<EOF -0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/foo -0000000000000000000000000000000000000000 $(git rev-parse master) refs/heads/master -0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/main -EOF - -SHELL="${SELF}" HOME="${TEMP}" GIT_DIR=. ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt" -grep "warning: no blogcfile or Makefile found. skipping ..." "${TEMP}/output.txt" &> /dev/null - -cd "${TEMP}" -git init --bare "${TEMP}/repos/foo2.git" &> /dev/null -ln -s "${SELF}" "${TEMP}/repos/foo2.git/hooks/pre-receive" - -cat > "${TEMP}/tmp.txt" <<EOF -blob -mark :1 -data 63 -all: - mkdir -p \$(OUTPUT_DIR) - echo lol > \$(OUTPUT_DIR)/foo.txt - -reset refs/heads/main -commit refs/heads/main -mark :2 -author Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476139736 +0200 -committer Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476139736 +0200 -data 11 -testing... -M 100644 :1 Makefile - -EOF - -cd "${TEMP}/repos/foo2.git" -git fast-import < "${TEMP}/tmp.txt" &> /dev/null - -cat > "${TEMP}/payload.txt" <<EOF -0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/foo -0000000000000000000000000000000000000000 $(git rev-parse main) refs/heads/main -0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/bar -EOF - -cat > "${TEMP}/blogc-git-receiver.ini" <<EOF -[repo:foo2a.git] -symlink = ${TEMP}/guda -EOF - -SHELL="${SELF}" HOME="${TEMP}" GIT_DIR=. BLOGC_GIT_RECEIVER_BUILDS_DIR="${TEMP}/foooo" ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt" -grep "echo lol" "${TEMP}/output.txt" &> /dev/null - -[[ -h htdocs ]] -[[ "$(cat htdocs/foo.txt)" == "lol" ]] - -cat >> "${TEMP}/blogc-git-receiver.ini" <<EOF -[repo:foo2.git] -EOF - -SHELL="${SELF}" HOME="${TEMP}" GIT_DIR=. BLOGC_GIT_RECEIVER_BUILDS_DIR="${TEMP}/foooo" ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt" -grep "echo lol" "${TEMP}/output.txt" &> /dev/null - -[[ -h htdocs ]] -[[ "$(cat htdocs/foo.txt)" == "lol" ]] - -cat >> "${TEMP}/blogc-git-receiver.ini" <<EOF -symlink = ${TEMP}/chunda -EOF - -SHELL="${SELF}" HOME="${TEMP}" GIT_DIR=. BLOGC_GIT_RECEIVER_BUILDS_DIR="${TEMP}/foooo" ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt" -grep "echo lol" "${TEMP}/output.txt" &> /dev/null - -[[ -h "${TEMP}/chunda" ]] -[[ "$(cat "${TEMP}/chunda/foo.txt")" == "lol" ]] - -DEST="$(readlink "${TEMP}/chunda")" -[[ -e "${DEST}" ]] -[[ "${DEST}" == "${TEMP}/foooo/"* ]] - -cd "${TEMP}" -git init --bare "${TEMP}/repos/foo2a.git" &> /dev/null -ln -s "${SELF}" "${TEMP}/repos/foo2a.git/hooks/pre-receive" - -cat > "${TEMP}/tmp.txt" <<EOF -blob -mark :1 -data 64 -all: - mkdir -p \$(OUTPUT_DIR) - echo lol > \$(OUTPUT_DIR)/foo.txt - - -commit refs/heads/master -mark :2 -author Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476142917 +0200 -committer Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476142917 +0200 -data 12 -testing2... -M 100644 :1 Makefile - -EOF - -cd "${TEMP}/repos/foo2a.git" -ln -s "${DEST}" "${TEMP}/guda" -git fast-import < "${TEMP}/tmp.txt" &> /dev/null - -cat > "${TEMP}/payload.txt" <<EOF -0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/foo -0000000000000000000000000000000000000000 $(git rev-parse master) refs/heads/master -0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/bar -EOF - -SHELL="${SELF}" HOME="${TEMP}" GIT_DIR=. ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt" -grep "echo lol" "${TEMP}/output.txt" &> /dev/null - -[[ -h "${TEMP}/guda" ]] -[[ "$(cat "${TEMP}/guda/foo.txt")" == "lol" ]] -[[ "${DEST}" != "$(readlink "${TEMP}/guda")" ]] -[[ ! -e "${DEST}" ]] - -DEST="$(readlink "${TEMP}/guda")" -HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./hooks/pre-receive 2>&1 | tee "${TEMP}/output.txt" - -[[ -h "${TEMP}/guda" ]] -[[ "$(cat "${TEMP}/guda/foo.txt")" == "lol" ]] -[[ "${DEST}" != "$(readlink "${TEMP}/guda")" ]] -[[ ! -e "${DEST}" ]] - -cd .. - -DEST="$(readlink "${TEMP}/guda")" -HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./foo2a.git/hooks/pre-receive 2>&1 | tee "${TEMP}/output.txt" - -[[ -h "${TEMP}/guda" ]] -[[ "$(cat "${TEMP}/guda/foo.txt")" == "lol" ]] -[[ "${DEST}" != "$(readlink "${TEMP}/guda")" ]] -[[ ! -e "${DEST}" ]] - -cd .. - -DEST="$(readlink "${TEMP}/guda")" -HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./repos/foo2a.git/hooks/pre-receive 2>&1 | tee "${TEMP}/output.txt" - -[[ -h "${TEMP}/guda" ]] -[[ "$(cat "${TEMP}/guda/foo.txt")" == "lol" ]] -[[ "${DEST}" != "$(readlink "${TEMP}/guda")" ]] -[[ ! -e "${DEST}" ]] - -DEST="$(readlink "${TEMP}/guda")" -[[ -e "${DEST}" ]] - -cd "${TEMP}" -git init --bare "${TEMP}/repos/foo3.git" &> /dev/null -ln -s "${SELF}" "${TEMP}/repos/foo3.git/hooks/pre-receive" - -cat > "${TEMP}/tmp.txt" <<EOF -blob -mark :1 -data 64 -all: - mkdir -p \$(OUTPUT_DIR) - echo lol > \$(OUTPUT_DIR)/foo.txt - - -commit refs/heads/master -mark :2 -author Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476142917 +0200 -committer Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476142917 +0200 -data 12 -testing2... -M 100644 :1 Makefile - -EOF - -cd "${TEMP}/repos/foo3.git" -ln -s "${DEST}" htdocs -git fast-import < "${TEMP}/tmp.txt" &> /dev/null - -cat > "${TEMP}/payload.txt" <<EOF -0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/foo -0000000000000000000000000000000000000000 $(git rev-parse master) refs/heads/master -0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 refs/heads/bar -EOF - -SHELL="${SELF}" HOME="${TEMP}" GIT_DIR=. ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt" -grep "echo lol" "${TEMP}/output.txt" &> /dev/null - -[[ -h htdocs ]] -[[ "$(cat htdocs/foo.txt)" == "lol" ]] -[[ "${DEST}" != "$(readlink htdocs)" ]] -[[ ! -e "${DEST}" ]] - -DEST="$(readlink htdocs)" -HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./hooks/pre-receive 2>&1 | tee "${TEMP}/output.txt" - -[[ -h htdocs ]] -[[ "$(cat htdocs/foo.txt)" == "lol" ]] -[[ "${DEST}" != "$(readlink htdocs)" ]] -[[ ! -e "${DEST}" ]] - -cd .. - -DEST="$(readlink foo3.git/htdocs)" -HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./foo3.git/hooks/pre-receive 2>&1 | tee "${TEMP}/output.txt" - -[[ -h foo3.git/htdocs ]] -[[ "$(cat foo3.git/htdocs/foo.txt)" == "lol" ]] -[[ "${DEST}" != "$(readlink foo3.git/htdocs)" ]] -[[ ! -e "${DEST}" ]] - -cd .. - -DEST="$(readlink repos/foo3.git/htdocs)" -HOME="${TEMP}" ${TESTS_ENVIRONMENT} ./repos/foo3.git/hooks/pre-receive 2>&1 | tee "${TEMP}/output.txt" - -[[ -h repos/foo3.git/htdocs ]] -[[ "$(cat repos/foo3.git/htdocs/foo.txt)" == "lol" ]] -[[ "${DEST}" != "$(readlink repos/foo3.git/htdocs)" ]] -[[ ! -e "${DEST}" ]] - -if [[ "x@MAKE_@" == "xenabled" ]]; then - cd "${TEMP}" - git init --bare "${TEMP}/repos/foo4.git" &> /dev/null - ln -s "${SELF}" "${TEMP}/repos/foo4.git/hooks/pre-receive" - - cat > "${TEMP}/tmp.txt" <<EOF -blob -mark :1 -data 0 - -reset refs/heads/master -commit refs/heads/master -mark :2 -author Rafael G. Martins <rafael@rafaelmartins.eng.br> 1483558736 +0100 -committer Rafael G. Martins <rafael@rafaelmartins.eng.br> 1483558736 +0100 -data 12 -testing3... -M 100644 :1 blogcfile - -EOF - - cd "${TEMP}/repos/foo4.git" - git fast-import < "${TEMP}/tmp.txt" &> /dev/null - - cat > "${TEMP}/payload.txt" <<EOF -0000000000000000000000000000000000000000 $(git rev-parse master) refs/heads/master -EOF - - SHELL="${SELF}" BLOGC_GIT_RECEIVER_BASE_DIR="${TEMP}" PATH="@abs_top_builddir@:${PATH}" GIT_DIR=. ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt" || true - grep "blogc-make: error: settings: " "${TEMP}/output.txt" &> /dev/null -fi - -rm "${TEMP}/output.txt" diff --git a/tests/blogc-git-receiver/check_pre_receive_parser.c b/tests/blogc-git-receiver/check_pre_receive_parser.c deleted file mode 100644 index cad1421..0000000 --- a/tests/blogc-git-receiver/check_pre_receive_parser.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * blogc: A blog compiler. - * Copyright (C) 2014-2020 Rafael G. Martins <rafael@rafaelmartins.eng.br> - * - * This program can be distributed under the terms of the BSD License. - * See the file LICENSE. - */ - -#include <stdarg.h> -#include <stddef.h> -#include <setjmp.h> -#include <cmocka.h> -#include <stdlib.h> -#include <string.h> -#include "../../src/blogc-git-receiver/pre-receive-parser.h" - -#define _bgr_pre_receive_parse(a) bgr_pre_receive_parse(a, strlen(a)) - - -static void -test_pre_receive_parse(void **state) -{ - assert_null(_bgr_pre_receive_parse("")); - assert_null(_bgr_pre_receive_parse( - "4f1f932f6ef6d6c9770266775c2db072964d7a62")); - assert_null(_bgr_pre_receive_parse( - "4f1f932f6ef6d6c9770266775c2db072964d7a62 ")); - assert_null(_bgr_pre_receive_parse( - "4f1f932f6ef6d6c9770266775c2db072964d7a62 " - "3fff4bb3172f77b292b0c913749e81bedd3545f3")); - assert_null(_bgr_pre_receive_parse( - "4f1f932f6ef6d6c9770266775c2db072964d7a62 " - "3fff4bb3172f77b292b0c913749e81bedd3545f3 ")); - assert_null(_bgr_pre_receive_parse( - "4f1f932f6ef6d6c9770266775c2db072964d7a62 " - "3fff4bb3172f77b292b0c913749e81bedd3545f3 " - "refs/heads/lol")); - assert_null(_bgr_pre_receive_parse( - "4f1f932f6ef6d6c9770266775c2db072964d7a62 " - "3fff4bb3172f77b292b0c913749e81bedd3545f3 " - "refs/heads/lol")); - assert_null(_bgr_pre_receive_parse( - "4f1f932f6ef6d6c9770266775c2db072964d7a62 " - "3fff4bb3172f77b292b0c913749e81bedd3545f3 " - "refs/heads/master")); - assert_null(_bgr_pre_receive_parse( - "4f1f932f6ef6d6c9770266775c2db072964d7a62 " - "3fff4bb3172f77b292b0c913749e81bedd3545f3 " - "adgfdgdfgfdgdfgdfgdfgdfgdfg\n")); - - bc_trie_t *t; - t = _bgr_pre_receive_parse( - "4f1f932f6ef6d6c9770266775c2db072964d7a62 " - "3fff4bb3172f77b292b0c913749e81bedd3545f3 " - "refs/heads/master asd\n"); - assert_non_null(t); - assert_int_equal(bc_trie_size(t), 1); - assert_string_equal(bc_trie_lookup(t, "master asd"), - "3fff4bb3172f77b292b0c913749e81bedd3545f3"); - bc_trie_free(t); - - t = _bgr_pre_receive_parse( - "4f1f932f6ef6d6c9770266775c2db072964d7a62 " - "3fff4bb3172f77b292b0c913749e81bedd3545f3 " - "refs/heads/master\n"); - assert_non_null(t); - assert_int_equal(bc_trie_size(t), 1); - assert_string_equal(bc_trie_lookup(t, "master"), - "3fff4bb3172f77b292b0c913749e81bedd3545f3"); - bc_trie_free(t); - - t = _bgr_pre_receive_parse( - "4f1f932f6ef6d6c9770266775c2db072964d7a62 " - "3fff4bb3172f77b292b0c913749e81bedd3545fa " - "refs/heads/master\n" - "4f1f932f6ef6d6c9770266775c2db072964d7a63 " - "3fff4bb3172f77b292b0c913749e81bedd3545f4 " - "refs/heads/bola\n" - ); - assert_non_null(t); - assert_int_equal(bc_trie_size(t), 2); - assert_string_equal(bc_trie_lookup(t, "master"), - "3fff4bb3172f77b292b0c913749e81bedd3545fa"); - assert_string_equal(bc_trie_lookup(t, "bola"), - "3fff4bb3172f77b292b0c913749e81bedd3545f4"); - bc_trie_free(t); - - t = _bgr_pre_receive_parse( - "4f1f932f6ef6d6c9770266775c2db072964d7a63 " - "3fff4bb3172f77b292b0c913749e81bedd3545f4 " - "refs/heads/bola\n" - "4f1f932f6ef6d6c9770266775c2db072964d7a62 " - "3fff4bb3172f77b292b0c913749e81bedd3545fb " - "refs/heads/master\n" - ); - assert_non_null(t); - assert_int_equal(bc_trie_size(t), 2); - assert_string_equal(bc_trie_lookup(t, "bola"), - "3fff4bb3172f77b292b0c913749e81bedd3545f4"); - assert_string_equal(bc_trie_lookup(t, "master"), - "3fff4bb3172f77b292b0c913749e81bedd3545fb"); - bc_trie_free(t); - - t = _bgr_pre_receive_parse( - "4f1f932f6ef6d6c9770266775c2db072964d7a63 " - "3fff4bb3172f77b292b0c913749e81bedd3545f4 " - "refs/heads/bola\n" - "4f1f932f6ef6d6c9770266775c2db072964d7a62 " - "3fff4bb3172f77b292b0c913749e81bedd3545fc " - "refs/heads/master\n" - "4f1f932f6ef6d6c9770266775c2db072964d7a64 " - "3fff4bb3172f77b292b0c913749e81bedd3545f5 " - "refs/heads/bolao\n" - ); - assert_non_null(t); - assert_int_equal(bc_trie_size(t), 3); - assert_string_equal(bc_trie_lookup(t, "bola"), - "3fff4bb3172f77b292b0c913749e81bedd3545f4"); - assert_string_equal(bc_trie_lookup(t, "master"), - "3fff4bb3172f77b292b0c913749e81bedd3545fc"); - assert_string_equal(bc_trie_lookup(t, "bolao"), - "3fff4bb3172f77b292b0c913749e81bedd3545f5"); - bc_trie_free(t); -} - - -int -main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_pre_receive_parse), - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/tests/blogc-git-receiver/check_settings.c b/tests/blogc-git-receiver/check_settings.c deleted file mode 100644 index 61cd469..0000000 --- a/tests/blogc-git-receiver/check_settings.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * blogc: A blog compiler. - * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br> - * - * This program can be distributed under the terms of the BSD License. - * See the file LICENSE. - */ - -#include <stdarg.h> -#include <stddef.h> -#include <setjmp.h> -#include <cmocka.h> -#include <string.h> -#include <stdlib.h> -#include "../../src/common/config-parser.h" -#include "../../src/common/utils.h" -#include "../../src/blogc-git-receiver/settings.h" - - -char* -__wrap_realpath(const char *path, char *resolved_path) -{ - const char *real_path = mock_type(const char*); - if (real_path == NULL) - return NULL; - assert_string_equal(path, real_path); - return bc_strdup(real_path); -} - - -static void -test_settings_get_section(void **state) -{ - bc_error_t *err = NULL; - - setenv("HOME", "/home/blogc", 1); - - bc_config_t *config = bc_config_parse("", 0, NULL, &err); - assert_null(err); - assert_null(bgr_settings_get_section(config, "/home/blogc/repos/foo.git")); - bc_config_free(config); - - will_return(__wrap_realpath, NULL); - will_return(__wrap_realpath, "/home/blogc/repos/bar.git"); - const char *conf = - "[repo:foo.git]\n" - "mirror = foo\n" - "\n" - "[repo:bar.git]\n" - "mirror = bar\n" - "\n" - "[repo:baz.git]\n" - "mirror = baz\n" - "\n"; - config = bc_config_parse(conf, strlen(conf), NULL, &err); - assert_null(err); - char *s = bgr_settings_get_section(config, "/home/blogc/repos/bar.git"); - assert_string_equal(s, "repo:bar.git"); - free(s); - bc_config_free(config); - - setenv("BLOGC_GIT_RECEIVER_BASE_DIR", "/home/bola", 1); - will_return(__wrap_realpath, NULL); - will_return(__wrap_realpath, "/home/bola/repos/asd/bar.git"); - conf = - "[repo:asd/foo.git]\n" - "mirror = foo\n" - "\n" - "[repo:asd/bar.git]\n" - "mirror = bar\n" - "\n" - "[repo:asd/baz.git]\n" - "mirror = baz\n" - "\n"; - config = bc_config_parse(conf, strlen(conf), NULL, &err); - assert_null(err); - s = bgr_settings_get_section(config, "/home/bola/repos/asd/bar.git"); - assert_string_equal(s, "repo:asd/bar.git"); - free(s); - bc_config_free(config); -} - - -int -main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_settings_get_section), - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/tests/blogc-git-receiver/check_shell.sh.in b/tests/blogc-git-receiver/check_shell.sh.in deleted file mode 100755 index f70fc50..0000000 --- a/tests/blogc-git-receiver/check_shell.sh.in +++ /dev/null @@ -1,95 +0,0 @@ -#!@BASH@ - -set -xe -o pipefail - -export LC_ALL=C - -TEMP="$(mktemp -d)" -[[ -n "${TEMP}" ]] - -trap_func() { - [[ -e "${TEMP}/output.txt" ]] && cat "${TEMP}/output.txt" - [[ -n "${TEMP}" ]] && rm -rf "${TEMP}" -} - -trap trap_func EXIT - -SELF="@abs_top_builddir@/blogc-git-receiver" - -call_bgr() { - [[ -n "${VALGRIND}" ]] && export __VALGRIND_ENABLED=1 - SHELL="${SELF}" HOME="${TEMP}" ${TESTS_ENVIRONMENT} "${SELF}" "$@" -} - -call_bgr -c "bola 'lol.git'" 2>&1 | tee "${TEMP}/output.txt" || true -grep "error: invalid git-shell command: bola 'lol\.git'" "${TEMP}/output.txt" &> /dev/null - -echo 0000 | call_bgr -c "git-receive-pack 'lol.git'" 2>&1 > "${TEMP}/output.txt" -if [[ -n "${VALGRIND}" ]]; then - grep "git-shell -c \"git-receive-pack '.*repos/lol.git'\"" "${TEMP}/output.txt" &> /dev/null -else - grep "agent=" "${TEMP}/output.txt" &> /dev/null -fi -[[ -d "${TEMP}/repos/lol.git" ]] -[[ -h "${TEMP}/repos/lol.git/hooks/pre-receive" ]] -[[ "$(readlink "${TEMP}/repos/lol.git/hooks/pre-receive")" == "${SELF}" ]] -[[ -h "${TEMP}/repos/lol.git/hooks/post-receive" ]] -[[ "$(readlink "${TEMP}/repos/lol.git/hooks/post-receive")" == "${SELF}" ]] - -rm "${TEMP}/repos/lol.git/hooks/pre-receive" -ln -s /lolheheasdxd "${TEMP}/repos/lol.git/hooks/pre-receive" - -echo 0000 | call_bgr -c "git-receive-pack 'lol.git'" 2>&1 > "${TEMP}/output.txt" -if [[ -n "${VALGRIND}" ]]; then - grep "git-shell -c \"git-receive-pack '.*repos/lol.git'\"" "${TEMP}/output.txt" &> /dev/null -else - grep "agent=" "${TEMP}/output.txt" &> /dev/null -fi -[[ -d "${TEMP}/repos/lol.git" ]] -[[ -h "${TEMP}/repos/lol.git/hooks/pre-receive" ]] -[[ "$(readlink "${TEMP}/repos/lol.git/hooks/pre-receive")" == "${SELF}" ]] -[[ -h "${TEMP}/repos/lol.git/hooks/post-receive" ]] -[[ "$(readlink "${TEMP}/repos/lol.git/hooks/post-receive")" == "${SELF}" ]] - -cat > "${TEMP}/tmp.txt" <<EOF -blob -mark :1 -data 4 -bar - -reset refs/heads/master -commit refs/heads/master -mark :2 -author Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476033730 +0200 -committer Rafael G. Martins <rafael@rafaelmartins.eng.br> 1476033888 +0200 -data 11 -testing... -M 100644 :1 foo - -EOF -cd "${TEMP}/repos/lol.git" -git fast-import < "${TEMP}/tmp.txt" &> /dev/null -cd - > /dev/null - -echo 0000 | call_bgr -c "git-upload-pack 'lol.git'" 2>&1 > "${TEMP}/output.txt" -if [[ -n "${VALGRIND}" ]]; then - grep "git-shell -c \"git-upload-pack '.*repos/lol.git'\"" "${TEMP}/output.txt" &> /dev/null -else - grep "agent=" "${TEMP}/output.txt" &> /dev/null -fi - -echo 0000 | SSH_ORIGINAL_COMMAND="git-upload-pack 'lol.git'" call_bgr 2>&1 > "${TEMP}/output.txt" -if [[ -n "${VALGRIND}" ]]; then - grep "git-shell -c \"git-upload-pack '.*repos/lol.git'\"" "${TEMP}/output.txt" &> /dev/null -else - grep "agent=" "${TEMP}/output.txt" &> /dev/null -fi - -echo 0000 | call_bgr -c "git-upload-archive 'lol.git'" 2>&1 > "${TEMP}/output.txt" || true -if [[ -n "${VALGRIND}" ]]; then - grep "git-shell -c \"git-upload-archive '.*repos/lol.git'\"" "${TEMP}/output.txt" &> /dev/null -else - grep "ACK" "${TEMP}/output.txt" &> /dev/null -fi - -rm "${TEMP}/output.txt" diff --git a/tests/blogc-git-receiver/check_shell_command_parser.c b/tests/blogc-git-receiver/check_shell_command_parser.c deleted file mode 100644 index eafeabb..0000000 --- a/tests/blogc-git-receiver/check_shell_command_parser.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - * blogc: A blog compiler. - * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br> - * - * This program can be distributed under the terms of the BSD License. - * See the file LICENSE. - */ - -#include <stdarg.h> -#include <stddef.h> -#include <setjmp.h> -#include <cmocka.h> -#include <stdlib.h> -#include "../../src/blogc-git-receiver/shell-command-parser.h" - - -static void -test_shell_command_parse(void **state) -{ - char *t; - assert_null(bgr_shell_command_parse("")); - assert_null(bgr_shell_command_parse("bola")); - assert_null(bgr_shell_command_parse("bola guda")); - assert_null(bgr_shell_command_parse("bola 'guda'")); - t = bgr_shell_command_parse("git-receive-pack 'bola.git'"); - assert_string_equal(t, "bola.git"); - free(t); - t = bgr_shell_command_parse("git-upload-pack 'bolaa.git'"); - assert_string_equal(t, "bolaa.git"); - free(t); - t = bgr_shell_command_parse("git-upload-archive 'bolab.git'"); - assert_string_equal(t, "bolab.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/bola1.git'"); - assert_string_equal(t, "bola1.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/bola2.git/'"); - assert_string_equal(t, "bola2.git/"); - free(t); - t = bgr_shell_command_parse("git-receive-pack 'bola3.git/'"); - assert_string_equal(t, "bola3.git/"); - free(t); - t = bgr_shell_command_parse("git-receive-pack 'foo/bola.git'"); - assert_string_equal(t, "foo/bola.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/foo/bola1.git'"); - assert_string_equal(t, "foo/bola1.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/foo/bola2.git/'"); - assert_string_equal(t, "foo/bola2.git/"); - free(t); - t = bgr_shell_command_parse("git-receive-pack 'foo/bola3.git/'"); - assert_string_equal(t, "foo/bola3.git/"); - free(t); - - t = bgr_shell_command_parse("git-receive-pack ''\\''bola.git'"); - assert_string_equal(t, "'bola.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack ''\\''/bola1.git'"); - assert_string_equal(t, "'/bola1.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack ''\\''/bola2.git/'"); - assert_string_equal(t, "'/bola2.git/"); - free(t); - t = bgr_shell_command_parse("git-receive-pack ''\\''bola3.git/'"); - assert_string_equal(t, "'bola3.git/"); - free(t); - t = bgr_shell_command_parse("git-receive-pack ''\\''foo/bola.git'"); - assert_string_equal(t, "'foo/bola.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack ''\\''/foo/bola1.git'"); - assert_string_equal(t, "'/foo/bola1.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack ''\\''/foo/bola2.git/'"); - assert_string_equal(t, "'/foo/bola2.git/"); - free(t); - t = bgr_shell_command_parse("git-receive-pack ''\\''foo/bola3.git/'"); - assert_string_equal(t, "'foo/bola3.git/"); - free(t); - - t = bgr_shell_command_parse("git-receive-pack 'bola.git'\\'''"); - assert_string_equal(t, "bola.git'"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/bola1.git'\\'''"); - assert_string_equal(t, "bola1.git'"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/bola2.git/'\\'''"); - assert_string_equal(t, "bola2.git/'"); - free(t); - t = bgr_shell_command_parse("git-receive-pack 'bola3.git/'\\'''"); - assert_string_equal(t, "bola3.git/'"); - free(t); - t = bgr_shell_command_parse("git-receive-pack 'foo/bola.git'\\'''"); - assert_string_equal(t, "foo/bola.git'"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/foo/bola1.git'\\'''"); - assert_string_equal(t, "foo/bola1.git'"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/foo/bola2.git/'\\'''"); - assert_string_equal(t, "foo/bola2.git/'"); - free(t); - t = bgr_shell_command_parse("git-receive-pack 'foo/bola3.git/'\\'''"); - assert_string_equal(t, "foo/bola3.git/'"); - free(t); - - t = bgr_shell_command_parse("git-receive-pack 'bo'\\''la.git'"); - assert_string_equal(t, "bo'la.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/bo'\\''la1.git'"); - assert_string_equal(t, "bo'la1.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/bo'\\''la2.git/'"); - assert_string_equal(t, "bo'la2.git/"); - free(t); - t = bgr_shell_command_parse("git-receive-pack 'bo'\\''la3.git/'"); - assert_string_equal(t, "bo'la3.git/"); - free(t); - t = bgr_shell_command_parse("git-receive-pack 'foo/bo'\\''la.git'"); - assert_string_equal(t, "foo/bo'la.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/foo/bo'\\''la1.git'"); - assert_string_equal(t, "foo/bo'la1.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/foo/bo'\\''la2.git/'"); - assert_string_equal(t, "foo/bo'la2.git/"); - free(t); - t = bgr_shell_command_parse("git-receive-pack 'foo/bo'\\''la3.git/'"); - assert_string_equal(t, "foo/bo'la3.git/"); - free(t); - - t = bgr_shell_command_parse("git-receive-pack ''\\!'bola.git'"); - assert_string_equal(t, "!bola.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack ''\\!'/bola1.git'"); - assert_string_equal(t, "!/bola1.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack ''\\!'/bola2.git/'"); - assert_string_equal(t, "!/bola2.git/"); - free(t); - t = bgr_shell_command_parse("git-receive-pack ''\\!'bola3.git/'"); - assert_string_equal(t, "!bola3.git/"); - free(t); - t = bgr_shell_command_parse("git-receive-pack ''\\!'foo/bola.git'"); - assert_string_equal(t, "!foo/bola.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack ''\\!'/foo/bola1.git'"); - assert_string_equal(t, "!/foo/bola1.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack ''\\!'/foo/bola2.git/'"); - assert_string_equal(t, "!/foo/bola2.git/"); - free(t); - t = bgr_shell_command_parse("git-receive-pack ''\\!'foo/bola3.git/'"); - assert_string_equal(t, "!foo/bola3.git/"); - free(t); - - t = bgr_shell_command_parse("git-receive-pack 'bola.git'\\!''"); - assert_string_equal(t, "bola.git!"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/bola1.git'\\!''"); - assert_string_equal(t, "bola1.git!"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/bola2.git/'\\!''"); - assert_string_equal(t, "bola2.git/!"); - free(t); - t = bgr_shell_command_parse("git-receive-pack 'bola3.git/'\\!''"); - assert_string_equal(t, "bola3.git/!"); - free(t); - t = bgr_shell_command_parse("git-receive-pack 'foo/bola.git'\\!''"); - assert_string_equal(t, "foo/bola.git!"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/foo/bola1.git'\\!''"); - assert_string_equal(t, "foo/bola1.git!"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/foo/bola2.git/'\\!''"); - assert_string_equal(t, "foo/bola2.git/!"); - free(t); - t = bgr_shell_command_parse("git-receive-pack 'foo/bola3.git/'\\!''"); - assert_string_equal(t, "foo/bola3.git/!"); - free(t); - - t = bgr_shell_command_parse("git-receive-pack 'bo'\\!'la.git'"); - assert_string_equal(t, "bo!la.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/bo'\\!'la1.git'"); - assert_string_equal(t, "bo!la1.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/bo'\\!'la2.git/'"); - assert_string_equal(t, "bo!la2.git/"); - free(t); - t = bgr_shell_command_parse("git-receive-pack 'bo'\\!'la3.git/'"); - assert_string_equal(t, "bo!la3.git/"); - free(t); - t = bgr_shell_command_parse("git-receive-pack 'foo/bo'\\!'la.git'"); - assert_string_equal(t, "foo/bo!la.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/foo/bo'\\!'la1.git'"); - assert_string_equal(t, "foo/bo!la1.git"); - free(t); - t = bgr_shell_command_parse("git-receive-pack '/foo/bo'\\!'la2.git/'"); - assert_string_equal(t, "foo/bo!la2.git/"); - free(t); - t = bgr_shell_command_parse("git-receive-pack 'foo/bo'\\!'la3.git/'"); - assert_string_equal(t, "foo/bo!la3.git/"); - free(t); -} - - -int -main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_shell_command_parse), - }; - return cmocka_run_group_tests(tests, NULL, NULL); -} |