Debian Codegraph @

t/t-askpass.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 . "$(dirname "$0")/testlib.sh"
4
5 begin_test "askpass: push with GIT_ASKPASS"
6 (
7 set -e
8
9 reponame="askpass-with-git-environ"
10 setup_remote_repo "$reponame"
11 clone_repo "$reponame" "$reponame"
12
13 git lfs track "*.dat"
14 echo "hello" > a.dat
15
16 git add .gitattributes a.dat
17 git commit -m "initial commit"
18
19 # $password is defined from test/cmd/lfstest-gitserver.go (see: skipIfBadAuth)
20 export LFS_ASKPASS_USERNAME="user"
21 export LFS_ASKPASS_PASSWORD="pass"
22 git config "credential.helper" ""
23 GIT_ASKPASS="lfs-askpass" SSH_ASKPASS="dont-call-me" GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push origin main 2>&1 | tee push.log
24
25 GITSERVER_USER="$(printf $GITSERVER | sed -e 's/http:\/\//http:\/\/user@/')"
26
27 grep "filling with GIT_ASKPASS: lfs-askpass Username for \"$GITSERVER/$reponame\"" push.log
28 grep "filling with GIT_ASKPASS: lfs-askpass Password for \"$GITSERVER_USER/$reponame\"" push.log
29 grep "main -> main" push.log
30 )
31 end_test
32
33 begin_test "askpass: push with core.askPass"
34 (
35 set -e
36
37 reponame="askpass-with-config"
38 setup_remote_repo "$reponame"
39 clone_repo "$reponame" "$reponame"
40
41 git lfs track "*.dat"
42 echo "hello" > a.dat
43
44 git add .gitattributes a.dat
45 git commit -m "initial commit"
46
47 # $password is defined from test/cmd/lfstest-gitserver.go (see: skipIfBadAuth)
48 export LFS_ASKPASS_PASSWORD="pass"
49 git config "credential.helper" ""
50 git config "core.askPass" "lfs-askpass"
51 cat .git/config
52 SSH_ASKPASS="dont-call-me" GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push origin main 2>&1 | tee push.log
53
54 GITSERVER_USER="$(printf $GITSERVER | sed -e 's/http:\/\//http:\/\/user@/')"
55
56 grep "filling with GIT_ASKPASS: lfs-askpass Username for \"$GITSERVER/$reponame\"" push.log
57 grep "filling with GIT_ASKPASS: lfs-askpass Password for \"$GITSERVER_USER/$reponame\"" push.log
58 grep "main -> main" push.log
59 )
60 end_test
61
62 begin_test "askpass: push with core.askPass and wrong password"
63 (
64 set -e
65
66 reponame="askpass-with-config-bad-password"
67 setup_remote_repo "$reponame"
68 clone_repo "$reponame" "$reponame"
69
70 git lfs track "*.dat"
71
72 contents="a"
73 contents_oid="$(calc_oid "$contents")"
74 printf "%s" "$contents" >a.dat
75
76 git add .gitattributes a.dat
77 git commit -m "initial commit"
78
79 export LFS_ASKPASS_PASSWORD="wrong"
80 git config "credential.helper" ""
81 git config "core.askPass" "lfs-askpass"
82
83 SSH_ASKPASS="dont-call-me" GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push origin main 2>&1 | tee push.log
84 [ 0 -eq "$(grep -c "Uploading LFS objects: 100% (1/1)" push.log)" ]
85
86 # Requests to both the Locking API and the Batch API should receive 403s.
87 [ 1 -eq "$(grep -c "Authorization error: $GITSERVER/$reponame.*/locks/verify" push.log)" ]
88 [ 1 -eq "$(grep -c "batch response: Authorization error: $GITSERVER/$reponame" push.log)" ]
89
90 GITSERVER_USER="$(printf $GITSERVER | sed -e 's/http:\/\//http:\/\/user@/')"
91 [ 2 -eq "$(grep -c "filling with GIT_ASKPASS: lfs-askpass Username for \"$GITSERVER/$reponame\"" push.log)" ]
92 [ 2 -eq "$(grep -c "filling with GIT_ASKPASS: lfs-askpass Password for \"$GITSERVER_USER/$reponame\"" push.log)" ]
93
94 refute_server_object "$reponame" "$contents_oid"
95 )
96 end_test
97
98 begin_test "askpass: push with core.askPass and wrong password and 401 response"
99 (
100 set -e
101
102 reponame="askpass-with-config-bad-password-401-unauth"
103 setup_remote_repo "$reponame"
104 clone_repo "$reponame" "$reponame"
105
106 git lfs track "*.dat"
107
108 contents="a"
109 contents_oid="$(calc_oid "$contents")"
110 printf "%s" "$contents" >a.dat
111
112 git add .gitattributes a.dat
113 git commit -m "initial commit"
114
115 export LFS_ASKPASS_PASSWORD="wrong"
116 git config "credential.helper" ""
117 git config "core.askPass" "lfs-askpass"
118
119 SSH_ASKPASS="dont-call-me" GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push origin main 2>&1 | tee push.log
120 [ 0 -eq "$(grep -c "Uploading LFS objects: 100% (1/1)" push.log)" ]
121
122 # Requests to both the Locking API and the Batch API should receive 401s
123 # until the maximum number of authentication attempts is reached for both.
124 [ 2 -eq "$(grep -c "api: too many authentication attempts" push.log)" ]
125 [ 1 -eq "$(grep -c "batch response: too many authentication attempts" push.log)" ]
126
127 # Note that the first request to the Locking API is made without an
128 # Authorization header, so no credentials are retrieved for that request
129 # and it is not counted toward the authentication attempt limit.
130 GITSERVER_USER="$(printf $GITSERVER | sed -e 's/http:\/\//http:\/\/user@/')"
131 [ 6 -eq "$(grep -c "filling with GIT_ASKPASS: lfs-askpass Username for \"$GITSERVER/$reponame\"" push.log)" ]
132 [ 6 -eq "$(grep -c "filling with GIT_ASKPASS: lfs-askpass Password for \"$GITSERVER_USER/$reponame\"" push.log)" ]
133
134 refute_server_object "$reponame" "$contents_oid"
135 )
136 end_test
137
138 begin_test "askpass: push with SSH_ASKPASS"
139 (
140 set -e
141
142 reponame="askpass-with-ssh-environ"
143 setup_remote_repo "$reponame"
144 clone_repo "$reponame" "$reponame"
145
146 git lfs track "*.dat"
147 echo "hello" > a.dat
148
149 git add .gitattributes a.dat
150 git commit -m "initial commit"
151
152 # $password is defined from test/cmd/lfstest-gitserver.go (see: skipIfBadAuth)
153 export LFS_ASKPASS_USERNAME="user"
154 export LFS_ASKPASS_PASSWORD="pass"
155 git config "credential.helper" ""
156 SSH_ASKPASS="lfs-askpass" GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push origin main 2>&1 | tee push.log
157
158 GITSERVER_USER="$(printf $GITSERVER | sed -e 's/http:\/\//http:\/\/user@/')"
159
160 grep "filling with GIT_ASKPASS: lfs-askpass Username for \"$GITSERVER/$reponame\"" push.log
161 grep "filling with GIT_ASKPASS: lfs-askpass Password for \"$GITSERVER_USER/$reponame\"" push.log
162 grep "main -> main" push.log
163 )
164 end_test
165
166 begin_test "askpass: defaults to provided credentials"
167 (
168 set -e
169
170 reponame="askpass-provided-creds"
171 setup_remote_repo "$reponame"
172 clone_repo "$reponame" "$reponame"
173
174 git lfs track "*.dat"
175 echo "hello" > a.dat
176
177 git add .gitattributes a.dat
178 git commit -m "initial commit"
179
180 # $password is defined from test/cmd/lfstest-gitserver.go (see: skipIfBadAuth)
181 export LFS_ASKPASS_USERNAME="fakeuser"
182 export LFS_ASKPASS_PASSWORD="fakepass"
183 git config --local "credential.helper" ""
184
185 url=$(git config --get remote.origin.url)
186 newurl=${url/http:\/\//http:\/\/user\:pass@}
187 git remote set-url origin "$newurl"
188
189 GIT_ASKPASS="lfs-askpass" GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push origin main 2>&1 | tee push.log
190
191 grep "filling with GIT_ASKPASS" push.log && exit 1
192 grep "main -> main" push.log
193 )
194 end_test