summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2018-10-02 21:10:15 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2018-10-02 23:27:35 -0400
commitd110b58ca14705db49919963624c7cfda045c998 (patch)
tree65c7849ca76b2d052c7d0660de56f2f1ec1b205d
parentb8b344d1ba86c30c4fd452b40a3ae326634e8082 (diff)
test: librerelease: Add tests for the actual run
https://labs.parabola.nu/issues/1411 https://labs.parabola.nu/issues/1412 I have verified that the test fails with commit 0b8606e0cd0e1aedfe222d4d6603c4986aacb7b5 ("librerelease: Fix rmdir failing") reverted.
-rw-r--r--test/cases/librerelease.bats90
-rwxr-xr-xtest/testenv18
2 files changed, 104 insertions, 4 deletions
diff --git a/test/cases/librerelease.bats b/test/cases/librerelease.bats
index eb73d35..4e75cf9 100644
--- a/test/cases/librerelease.bats
+++ b/test/cases/librerelease.bats
@@ -3,14 +3,44 @@ load ../lib/common
setup() {
common_setup
- cat >> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot
- REPODEST=ssh://repo@repo.parabola.nu:1863/~/staging/$LIBREUSER/staging/
+ local ssh_port
+
+ # Configure and start the SSH server
+ install -Dm644 /dev/stdin "$tmpdir/etc/ssh/sshd_config" <<-eot
+ AuthorizedKeysFile ${HOME}/.ssh/id_rsa.pub
+ PasswordAuthentication no
+ AcceptEnv TMPDIR
+ AcceptEnv _HOME GNUPGHOME XDG_CACHE_HOME XDG_CONFIG_HOME
+ AcceptEnv _PATH LIBRETOOLS_LIBDIR _librelib_conf_sh_sysconfdir _librelib_conf_sh_pkgconfdir
+ AcceptEnv GPGKEY
+ ForceCommand HOME=\$_HOME; PATH=\$_PATH; eval "\$SSH_ORIGINAL_COMMAND"
eot
- cat >> "$XDG_CONFIG_HOME/pacman/makepkg.conf" <<-eot
- PKGEXT=.pkg.tar.gz
+ ssh-keygen -A -f "$tmpdir"
+ ssh_port=$(./lib/runserver "$tmpdir/sshd.pid" \
+ sshd -i \
+ -f "$tmpdir/etc/ssh/sshd_config" \
+ -h "$tmpdir/etc/ssh/ssh_host_ecdsa_key")
+
+ # Configure the SSH client
+ mkdir -p -- "$HOME/.ssh"
+ ssh-keygen -N '' -f "$HOME/.ssh/id_rsa"
+ ssh-keyscan -p "$ssh_port" 127.0.0.1 > "$HOME/.ssh/known_hosts"
+ touch -- "$HOME/.ssh/config"
+
+ # Configure libretools
+ cat >> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot
+ REPODEST=ssh://${USER@Q}@127.0.0.1:${ssh_port@Q}/${tmpdir@Q}/srv-staging/
+ HOOKPRERELEASE=:
+ HOOKPOSTRELEASE=:
eot
}
+teardown() {
+ xargs -a "$tmpdir/sshd.pid" kill --
+
+ common_teardown
+}
+
@test "librerelease displays usage text" {
rm -rf "$XDG_CONFIG_HOME"
LC_ALL=C librerelease -h >"$tmpdir/stdout" 2>"$tmpdir/stderr"
@@ -59,3 +89,55 @@ setup() {
empty "$tmpdir/stdout"
grep GPGKEY "$tmpdir/stderr"
}
+
+@test "librerelease runs" {
+ # Add a stub db-update so that when we ssh to localhost it has
+ # something to run.
+ install -Dm755 /dev/stdin "$tmpdir/bin/db-update" <<-eot
+ #!/bin/bash
+ {
+ readlink -f -- "\$STAGING"
+ find "\$STAGING" -printf '%P\n' | LC_COLLATE=C sort
+ } > ${tmpdir@Q}/log.txt
+ eot
+ PATH=$tmpdir/bin:$PATH
+
+ # Log which directories the hooks are run in.
+ cat >> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot
+ HOOKPRERELEASE='pwd > ${tmpdir@Q}/prerelease.txt'
+ HOOKPOSTRELEASE='pwd > ${tmpdir@Q}/postrelease.txt'
+ eot
+
+ # Make some files to stage
+ local workdir="$tmpdir/workdir"
+ mkdir -p "$workdir/staging/repo1" "$workdir/staging/repo2/sub"
+ touch \
+ "$workdir/staging/repo1/file1" \
+ "$workdir/staging/repo1/file2" \
+ "$workdir/staging/repo2/file with spaces" \
+ "$workdir/staging/repo2/sub/subfolder"
+
+ # Run
+ librerelease
+
+ # Make sure everything went OK
+ pwd > "$tmpdir/pwd.txt"
+ cat > "$tmpdir/log-correct.txt" <<-eot
+ $(readlink -f -- "$tmpdir/srv-staging")
+
+ repo1
+ repo1/file1
+ repo1/file1.sig
+ repo1/file2
+ repo1/file2.sig
+ repo2
+ repo2/file with spaces
+ repo2/file with spaces.sig
+ repo2/sub
+ repo2/sub/subfolder
+ repo2/sub/subfolder.sig
+ eot
+ diff -u "$tmpdir/log-correct.txt" "$tmpdir/log.txt"
+ diff -u "$tmpdir/pwd.txt" "$tmpdir/prerelease.txt"
+ diff -u "$tmpdir/pwd.txt" "$tmpdir/postrelease.txt"
+}
diff --git a/test/testenv b/test/testenv
index ca61225..11a46ee 100755
--- a/test/testenv
+++ b/test/testenv
@@ -92,6 +92,24 @@
fi
exec /usr/bin/gpg-connect-agent "$@"
eot
+ # Hack to work around ssh ignoring HOME and instead looking the homedir in NSS
+ install -Dm755 /dev/stdin "$destdir/usr/bin/ssh" <<-'eot'
+ #!/bin/bash
+ vars=(
+ TMPDIR
+ _HOME GNUPGHOME XDG_CACHE_HOME XDG_CONFIG_HOME
+ _PATH LIBRETOOLS_LIBDIR _librelib_conf_sh_sysconfdir _librelib_conf_sh_pkgconfdir
+ GPGKEY
+ )
+ export _HOME="$HOME"
+ export _PATH="$PATH"
+ exec /usr/bin/ssh \
+ -o SendEnv="${vars[*]}" \
+ -o IdentityFile="$HOME/.ssh/id_rsa" \
+ -o UserKnownHostsFile="$HOME/.ssh/known_hosts" \
+ -F "$HOME/.ssh/config" \
+ "$@"
+ eot
# Run the tests
command -- "$@"