-
Notifications
You must be signed in to change notification settings - Fork 3
/
testing_script.sh
78 lines (67 loc) · 1.97 KB
/
testing_script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
TEST_LOGFILE="/tmp/precommit_test.log"
TEST_GIT_REPO="https://github.com/security-deriv/pre-commit-testing-creds"
#1. Create 1 new file and commit. - commit should succed due to zero secrets in commit
invoke_test_1(){
touch newcreds
git add .
git commit -m "test1"
if [ $? -ne 0 ]; then
echo "Test 1 failed" | tee $TEST_LOGFILE
else
echo "Test 1 succeded" | tee $TEST_LOGFILE
fi
}
#2. cp creds to newfile and commit - commit should fail due to secrets in newcreds
invoke_test_2(){
cp creds newcreds
git add .
git commit -m "test2"
if [ $? -ne 0 ]; then
echo "Test 2 succeded" | tee -a $TEST_LOGFILE
else
echo "Test 2 failed" | tee -a $TEST_LOGFILE
fi
}
#3. cp creds to newfile and commit with —no-verify flag - commit should succed as precommit hook is bypassed
invoke_test_3(){
git commit -m "test3" --no-verify
if [ $? -ne 0 ]; then
echo "Test 3 failed" | tee -a $TEST_LOGFILE
else
echo "Test 3 succeded" | tee -a $TEST_LOGFILE
fi
}
#4. append newfile content to creds, delete newfile and commit - commit should fail due to secrets in newcreds
invoke_test_4(){
cat newcreds >> creds
rm newcreds
git add .
git commit -m "Test4"
if [ $? -ne 0 ]; then
echo "Test 4 succeded" | tee -a $TEST_LOGFILE
else
echo "Test 4 failed" | tee -a $TEST_LOGFILE
fi
}
#5. append newfile content to creds, delete newfile and commit with —no-verify flag - success
invoke_test_5(){
git commit -m "Test5" --no-verify
if [ $? -ne 0 ]; then
echo "Test 5 failed" | tee -a $TEST_LOGFILE
else
echo "Test 5 succeded" | tee -a $TEST_LOGFILE
fi
}
cd /tmp
rm -rf /tmp/pre-commit-testing-creds
git clone $TEST_GIT_REPO
cd pre-commit-testing-creds/
invoke_test_1
invoke_test_2
invoke_test_3
invoke_test_4
invoke_test_5
rm -rf /tmp/pre-commit-testing-creds
echo "___________________TESTING RESULTS___________________"
cat $TEST_LOGFILE