tAdd test units. - git-restrict - simple utility for git repo permission management
HTML git clone https://git.parazyd.org/git-restrict
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 0484d2a0c353a4a3d7d78cda9ed9fab9f184d1eb
DIR parent db4a0581a15ff4e9489bdf81eb6caed1aa565433
HTML Author: parazyd <parazyd@dyne.org>
Date: Thu, 1 Apr 2021 15:09:44 +0200
Add test units.
Could use more work, but w/e.
Diffstat:
M Makefile | 5 ++++-
A test.sh | 39 +++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 1 deletion(-)
---
DIR diff --git a/Makefile b/Makefile
t@@ -35,4 +35,7 @@ uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/$(BIN)
rm -f $(DESTDIR)$(MANPREFIX)/man1/$(MAN)
-.PHONY: all clean install uninstall
+test: all
+ @./test.sh
+
+.PHONY: all clean install uninstall test
DIR diff --git a/test.sh b/test.sh
t@@ -0,0 +1,39 @@
+#!/bin/sh
+
+export failed=0
+fail() { echo "Test $1 failed"; failed=1 ; }
+pass() { echo "Test $1 passed" ; }
+
+# Test 0
+./git-restrict 2>/dev/null && fail 0 || pass 0
+
+# Test 1
+./git-restrict foo 2>/dev/null && fail 1 || pass 1
+
+# Test 2
+SSH_ORIGINAL_COMMAND="cat /etc/passwd" \
+ ./git-restrict foo 2>/dev/null && fail 2 || pass 2
+
+# Test 3
+SSH_ORIGINAL_COMMAND="git-upload-pack bar" \
+ ./git-restrict foo bar baz 2>/dev/null && fail 3 || pass 3
+
+# Test 4
+SSH_ORIGINAL_COMMAND="git-upload-pack 'bar' ; cat /etc/passwd" \
+ ./git-restrict bar 2>/dev/null && fail 4 || pass 4
+
+# Test 5 (code 128 given by git-shell when repository isn't available)
+SSH_ORIGINAL_COMMAND="git-upload-pack 'bar'" \
+ ./git-restrict foo bar baz 2>/dev/null
+[ $? = 128 ] || fail 5 && pass 5
+
+# Test 6
+SSH_ORIGINAL_COMMAND="git-upload-pack 'bar.git'" \
+ ./git-restrict foo bar baz 2>/dev/null
+[ $? = 128 ] || fail 6 && pass 6
+
+# Test 7
+SSH_ORIGINAL_COMMAND="git-upload-pack 'foo'" \
+ ./git-restrict bar 2>/dev/null && fail 7 || pass 7
+
+exit "$failed"