From d62afec285253371c975f95366e5bf110ff2a3ff Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sat, 23 Oct 2021 12:45:43 -0400 Subject: move more files out of / --- Makefile | 6 ++++-- src/tests.sh | 66 ---------------------------------------------------------- test/Makefile | 38 +++++++++++++++++++++++++++++++++ test/tests.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests.makefile | 34 ------------------------------ 5 files changed, 108 insertions(+), 102 deletions(-) delete mode 100644 src/tests.sh create mode 100644 test/Makefile create mode 100644 test/tests.sh delete mode 100644 tests.makefile diff --git a/Makefile b/Makefile index 785c4ac..d3346ed 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ SSHD_CONFIG_DIR = $(SSH_CONFIG_DIR)/sshd_config.d SSH_LIB_DIR = /usr/lib/ssh USER_SSH_CONFIG_DIR = ~$(USER)/.ssh -.PHONY: install shared doc +.PHONY: install shared doc test shared: install git config core.self-forge true @@ -29,7 +29,9 @@ install: [ -e "$(SSH_LIB_DIR)"/AuthorizedKeysCommand ] || $(SUDO) ln -s -t /etc/ssh "$(SSH_LIB_DIR)"/AuthorizedKeysCommand doc: README.html + README.html: README.md pandoc -t html $< > $@ -include tests.makefile +test: + make -C test diff --git a/src/tests.sh b/src/tests.sh deleted file mode 100644 index 5d221b6..0000000 --- a/src/tests.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/sh -set -ex -USER=u -DIR=src/anonymous-ssh -HOST=localhost -SSH_ID=~/.ssh/id_ed25519 - -get_sshfp() -{ - ( - key="$1" - r="${2:-.}" - dns=$(mktemp) || exit - trap 'rm -rf "$dns"' EXIT - - ssh-keygen -r "$r" -f "$key" > "$dns" - exec < "$dns" - while read line - do - set -- $line - if [ "$3 $5" = "SSHFP 2" ] - then - echo "$line" - break - fi - done - ) -} - -make_test_commit() -{ - newfile=newfile.$(date -Ins|tr -d :) - touch "$newfile" - git add "$newfile" - git commit -m "$newfile" -} - -[ -e "$SSH_ID" ] || ssh-keygen -t ed25519 -f "$SSH_ID" -P '' - -git_namespace=$(set -- $(get_sshfp "$SSH_ID") && echo $6) - -ssh -o NoHostAuthenticationForLocalhost=yes $USER@$HOST -- test || true -[ ! -e anonymous-ssh ] || rm -rf anonymous-ssh -export GIT_SSH_COMMAND="ssh -o NoHostAuthenticationForLocalhost=yes -i $SSH_ID" -git clone -v ${USER}@${HOST}:${DIR} -cd anonymous-ssh - -make - -git pull --ff-only -make_test_commit -git push -f -make_test_commit -git push -git log -n4 -git pull --ff-only -git log -n4 -git push - -# branch=$(git branch -q --show-current) -# forkname=origin-myfork -# ns_branch=refs/namespaces/$git_namespace/refs/heads/$branch -# git remote add -m "$ns_branch" "$forkname" $(git remote get-url origin) -# git push "$forkname" -# git pull "$forkname" --ff-only "$branch" -exit diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..3bc1a66 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,38 @@ +.DEFAULT_GOAL = test + +include ../Makefile + +testuser = testuser + +SU = $(SUDO) su + +.PHONY: test useradd cleanuser + +useradd: + $(SUDO) useradd $(testuser) --shell /bin/bash --create-home + $(SU) - $(testuser) -c 'ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ""' + $(SU) - $(testuser) -c 'git config --global user.name $(testuser)' + $(SU) - $(testuser) -c 'git config --global user.email $(testuser)' + +test: $(shell getent passwd $(testuser) >/dev/null || echo useradd) + $(ROOT_INSTALL) -t ~$(testuser) tests.sh + $(SU) - $(testuser) -c ./tests.sh + +ifeq ($(testuser),) +$(error testuser not defined) +endif +cleanuser_command = $(SUDO) rm -I -r ~$(testuser) + +cleanuser: + : Preparing to run destructive command: + : + : + : $(cleanuser_command) + : + : + : Press ctrl-c to abort. + : + @for n in 5 4 3 2 1; do printf ' %d\r' "$$n"; sleep 1; done + $(cleanuser_command) || true + $(SUDO) userdel testuser || true + diff --git a/test/tests.sh b/test/tests.sh new file mode 100644 index 0000000..5d221b6 --- /dev/null +++ b/test/tests.sh @@ -0,0 +1,66 @@ +#!/bin/sh +set -ex +USER=u +DIR=src/anonymous-ssh +HOST=localhost +SSH_ID=~/.ssh/id_ed25519 + +get_sshfp() +{ + ( + key="$1" + r="${2:-.}" + dns=$(mktemp) || exit + trap 'rm -rf "$dns"' EXIT + + ssh-keygen -r "$r" -f "$key" > "$dns" + exec < "$dns" + while read line + do + set -- $line + if [ "$3 $5" = "SSHFP 2" ] + then + echo "$line" + break + fi + done + ) +} + +make_test_commit() +{ + newfile=newfile.$(date -Ins|tr -d :) + touch "$newfile" + git add "$newfile" + git commit -m "$newfile" +} + +[ -e "$SSH_ID" ] || ssh-keygen -t ed25519 -f "$SSH_ID" -P '' + +git_namespace=$(set -- $(get_sshfp "$SSH_ID") && echo $6) + +ssh -o NoHostAuthenticationForLocalhost=yes $USER@$HOST -- test || true +[ ! -e anonymous-ssh ] || rm -rf anonymous-ssh +export GIT_SSH_COMMAND="ssh -o NoHostAuthenticationForLocalhost=yes -i $SSH_ID" +git clone -v ${USER}@${HOST}:${DIR} +cd anonymous-ssh + +make + +git pull --ff-only +make_test_commit +git push -f +make_test_commit +git push +git log -n4 +git pull --ff-only +git log -n4 +git push + +# branch=$(git branch -q --show-current) +# forkname=origin-myfork +# ns_branch=refs/namespaces/$git_namespace/refs/heads/$branch +# git remote add -m "$ns_branch" "$forkname" $(git remote get-url origin) +# git push "$forkname" +# git pull "$forkname" --ff-only "$branch" +exit diff --git a/tests.makefile b/tests.makefile deleted file mode 100644 index 81c9312..0000000 --- a/tests.makefile +++ /dev/null @@ -1,34 +0,0 @@ -testuser = testuser - -SU = $(SUDO) su - -.PHONY: test useradd cleanuser - -useradd: - $(SUDO) useradd $(testuser) --shell /bin/bash --create-home - $(SU) - $(testuser) -c 'ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ""' - $(SU) - $(testuser) -c 'git config --global user.name $(testuser)' - $(SU) - $(testuser) -c 'git config --global user.email $(testuser)' - -test: install $(shell getent passwd $(testuser) >/dev/null || echo useradd) - $(ROOT_INSTALL) -t ~$(testuser) $(SRC)/tests.sh - $(SU) - $(testuser) -c ./tests.sh - -ifeq ($(testuser),) -$(error testuser not defined) -endif -cleanuser_command = $(SUDO) rm -I -r ~$(testuser) - -cleanuser: - : Preparing to run destructive command: - : - : - : $(cleanuser_command) - : - : - : Press ctrl-c to abort. - : - @for n in 5 4 3 2 1; do printf ' %d\r' "$$n"; sleep 1; done - $(cleanuser_command) || true - $(SUDO) userdel testuser || true - -- cgit v1.2.3