-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·173 lines (126 loc) · 4.25 KB
/
test.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
HASHWORD=src/hashword
TESTDB1=test.db
TESTDB2=test_copy.db
TESTUSER=testuser
MASTERPW1=test1234
MASTERPW2='m0RES3CUrE?'
DOMAIN1_NAME=example.com
DOMAIN1_PW1=3xampl3
DOMAIN1_PW2=Ch4ng3d
DOMAIN1_PW3=lo7sofchang3s
DOMAIN1_USER1=anotherUser
DOMAIN1_USER1_PW1=Another
DOMAIN2_NAME=thing.co.uk
DOMAIN2_PW1='! !'
DOMAIN3_NAME=generate.example.com
DOMAIN4_NAME=synctest.example.com
DOMAIN5_NAME=syncnewtest.example.com
function savepassword()
{
domain=$1
domainuser=$2
password=$3
echo -e "${MASTERPW}\n${password}" | ${HASHWORD} --database ${TESTDB} --user ${TESTUSER} -s save "${domain}" "${domainuser}"
}
function generatepassword()
{
domain=$1
domainuser=$2
#results=`echo "${MASTERPW}" | ${HASHWORD} --database ${TESTDB} --user ${TESTUSER} -s gen $domain ${domainuser}|tr '\n' ':'|cut -d':'`
results=`echo "${MASTERPW}" | ${HASHWORD} --database ${TESTDB} --user ${TESTUSER} -s gen $domain ${domainuser}`
echo $results
}
function getpassword()
{
domain=$1
user=$2
results=`echo "${MASTERPW}" | ${HASHWORD} --database ${TESTDB} --user ${TESTUSER} -s get $domain ${user}|tr '\n' ':'`
results_pw=`echo $results|cut -f2 -d':'`
echo $results_pw
}
function verifypassword()
{
domain=$1
user=$2
expected=$3
if [ -z "${user}" ]
then
formatted=${domain}
else
formatted=${user}@${domain}
fi
got=`getpassword $domain $user`
if [[ "${got}" != "${expected}" ]]
then
echo "FAIL: ${formatted}: Password is incorrect: Got=$got Expected=$expected"
exit 255
else
echo "PASS: ${formatted}: Password is correct"
fi
}
function changemasterpassword()
{
original=$1
new=$2
echo -e "${original}\n${new}" | ${HASHWORD} --database ${TESTDB} --user ${TESTUSER} -s change
}
function syncdbs()
{
target=$1
echo -e "${MASTERPW}" | ${HASHWORD} --database ${TESTDB} --user ${TESTUSER} -s sync ${target}
}
rm -f $TESTDB1 $TESTDB2
export TESTDB=$TESTDB1
export MASTERPW=$MASTERPW1
echo $MASTERPW | ${HASHWORD} --database ${TESTDB} --user ${TESTUSER} -s init
echo "Test: Domain 1: Set entry password"
savepassword $DOMAIN1_NAME '' $DOMAIN1_PW1
verifypassword $DOMAIN1_NAME '' $DOMAIN1_PW1
echo "Test: Domain 1: Change entry password"
savepassword $DOMAIN1_NAME '' $DOMAIN1_PW2
verifypassword $DOMAIN1_NAME '' $DOMAIN1_PW2
echo "Test: Domain 1: Set entry password, another user"
savepassword "$DOMAIN1_NAME" ${DOMAIN1_USER} ${DOMAIN1_USER1_PW1}
verifypassword "$DOMAIN1_NAME" ${DOMAIN1_USER} ${DOMAIN1_USER1_PW1}
echo "Test: Domain 2: Set another password"
savepassword $DOMAIN2_NAME '' ${DOMAIN2_PW1}
verifypassword $DOMAIN2_NAME '' ${DOMAIN2_PW1}
echo "Test: Domain 1: Verify original password"
verifypassword $DOMAIN1_NAME '' $DOMAIN1_PW2
echo "Test: Domain 3: Generate new password"
newpassword=`generatepassword $DOMAIN3_NAME`
verifypassword "$DOMAIN3_NAME" '' ${newpassword}
echo "Test: Change master password"
changemasterpassword $MASTERPW1 $MASTERPW2
export MASTERPW=$MASTERPW2
echo "Test: Domain 1 Verify original password"
verifypassword $DOMAIN1_NAME '' $DOMAIN1_PW2
# Sync tests
cp $TESTDB1 $TESTDB2
echo "Test: Sync Test: Domain 1: Change entry password"
savepassword $DOMAIN1_NAME '' $DOMAIN1_PW3
verifypassword $DOMAIN1_NAME '' $DOMAIN1_PW3
echo "Test: Sync Test: Generate new password"
synctestpassword=`generatepassword $DOMAIN4_NAME`
verifypassword "$DOMAIN4_NAME" '' ${synctestpassword}
syncdbs $TESTDB2
export TESTDB=$TESTDB2
echo "Test: Verify synced password"
verifypassword $DOMAIN4_NAME '' $synctestpassword
echo "Test: Sync Test: Change password in other DB"
synctestpassword2=`generatepassword $DOMAIN4_NAME`
verifypassword "$DOMAIN4_NAME" '' ${synctestpassword2}
echo "Test: Sync Test: Add entry in other DB"
synctestpassword3=`generatepassword $DOMAIN5_NAME`
verifypassword "$DOMAIN5_NAME" '' ${synctestpassword3}
export TESTDB=$TESTDB1
syncdbs $TESTDB2
echo "Test: Sync Test: Verifying changes in other DB have been syncd back"
verifypassword "$DOMAIN4_NAME" '' ${synctestpassword2}
verifypassword "$DOMAIN5_NAME" '' ${synctestpassword3}
# And finally triple check we haven't lost our first entry!
echo "Test: Verify original passwords"
verifypassword $DOMAIN1_NAME '' $DOMAIN1_PW3
verifypassword $DOMAIN2_NAME '' ${DOMAIN2_PW1}
echo "PASS!"