Debian Codegraph @

t/t-askpass.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 . "$(dirnamescip-shell system . . 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 gitscip-shell system . . git. lfs track "*.dat"
14 echoscip-shell system . . echo. "hello" > a.dat
15
16 gitscip-shell system . . git. add .gitattributes a.dat
17 gitscip-shell system . . 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 gitscip-shell system . . git. config "credential.helper" ""
23 GIT_ASKPASS="lfs-askpass" SSH_ASKPASS="dont-call-me" GIT_TRACE=1 GIT_CURL_VERBOSE=1 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
24
25 GITSERVER_USER="$(printfscip-shell system . . printf. $GITSERVER | sedscip-shell system . . sed. -e 's/http:\/\//http:\/\/user@/')"
26
27 grepscip-shell system . . grep. "filling with GIT_ASKPASS: lfs-askpass Username for \"$GITSERVER/$reponame\"" push.log
28 grepscip-shell system . . grep. "filling with GIT_ASKPASS: lfs-askpass Password for \"$GITSERVER_USER/$reponame\"" push.log
29 grepscip-shell system . . 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 gitscip-shell system . . git. lfs track "*.dat"
42 echoscip-shell system . . echo. "hello" > a.dat
43
44 gitscip-shell system . . git. add .gitattributes a.dat
45 gitscip-shell system . . 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 gitscip-shell system . . git. config "credential.helper" ""
50 gitscip-shell system . . git. config "core.askPass" "lfs-askpass"
51 catscip-shell system . . cat. .git/config
52 SSH_ASKPASS="dont-call-me" GIT_TRACE=1 GIT_CURL_VERBOSE=1 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
53
54 GITSERVER_USER="$(printfscip-shell system . . printf. $GITSERVER | sedscip-shell system . . sed. -e 's/http:\/\//http:\/\/user@/')"
55
56 grepscip-shell system . . grep. "filling with GIT_ASKPASS: lfs-askpass Username for \"$GITSERVER/$reponame\"" push.log
57 grepscip-shell system . . grep. "filling with GIT_ASKPASS: lfs-askpass Password for \"$GITSERVER_USER/$reponame\"" push.log
58 grepscip-shell system . . 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 gitscip-shell system . . git. lfs track "*.dat"
71
72 contents="a"
73 contents_oid="$(calc_oid "$contents")"
74 printfscip-shell system . . printf. "%s" "$contents" >a.dat
75
76 gitscip-shell system . . git. add .gitattributes a.dat
77 gitscip-shell system . . git. commit -m "initial commit"
78
79 export LFS_ASKPASS_PASSWORD="wrong"
80 gitscip-shell system . . git. config "credential.helper" ""
81 gitscip-shell system . . git. config "core.askPass" "lfs-askpass"
82
83 SSH_ASKPASS="dont-call-me" GIT_TRACE=1 GIT_CURL_VERBOSE=1 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
84 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . 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 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "Authorization error: $GITSERVER/$reponame.*/locks/verify" push.log)" ]
88 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "batch response: Authorization error: $GITSERVER/$reponame" push.log)" ]
89
90 GITSERVER_USER="$(printfscip-shell system . . printf. $GITSERVER | sedscip-shell system . . sed. -e 's/http:\/\//http:\/\/user@/')"
91 [scip-shell system . . `[`. 2 -eq "$(grepscip-shell system . . grep. -c "filling with GIT_ASKPASS: lfs-askpass Username for \"$GITSERVER/$reponame\"" push.log)" ]
92 [scip-shell system . . `[`. 2 -eq "$(grepscip-shell system . . 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 gitscip-shell system . . git. lfs track "*.dat"
107
108 contents="a"
109 contents_oid="$(calc_oid "$contents")"
110 printfscip-shell system . . printf. "%s" "$contents" >a.dat
111
112 gitscip-shell system . . git. add .gitattributes a.dat
113 gitscip-shell system . . git. commit -m "initial commit"
114
115 export LFS_ASKPASS_PASSWORD="wrong"
116 gitscip-shell system . . git. config "credential.helper" ""
117 gitscip-shell system . . git. config "core.askPass" "lfs-askpass"
118
119 SSH_ASKPASS="dont-call-me" GIT_TRACE=1 GIT_CURL_VERBOSE=1 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
120 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . 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 [scip-shell system . . `[`. 2 -eq "$(grepscip-shell system . . grep. -c "api: too many authentication attempts" push.log)" ]
125 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . 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="$(printfscip-shell system . . printf. $GITSERVER | sedscip-shell system . . sed. -e 's/http:\/\//http:\/\/user@/')"
131 [scip-shell system . . `[`. 6 -eq "$(grepscip-shell system . . grep. -c "filling with GIT_ASKPASS: lfs-askpass Username for \"$GITSERVER/$reponame\"" push.log)" ]
132 [scip-shell system . . `[`. 6 -eq "$(grepscip-shell system . . 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 gitscip-shell system . . git. lfs track "*.dat"
147 echoscip-shell system . . echo. "hello" > a.dat
148
149 gitscip-shell system . . git. add .gitattributes a.dat
150 gitscip-shell system . . 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 gitscip-shell system . . git. config "credential.helper" ""
156 SSH_ASKPASS="lfs-askpass" GIT_TRACE=1 GIT_CURL_VERBOSE=1 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
157
158 GITSERVER_USER="$(printfscip-shell system . . printf. $GITSERVER | sedscip-shell system . . sed. -e 's/http:\/\//http:\/\/user@/')"
159
160 grepscip-shell system . . grep. "filling with GIT_ASKPASS: lfs-askpass Username for \"$GITSERVER/$reponame\"" push.log
161 grepscip-shell system . . grep. "filling with GIT_ASKPASS: lfs-askpass Password for \"$GITSERVER_USER/$reponame\"" push.log
162 grepscip-shell system . . 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 gitscip-shell system . . git. lfs track "*.dat"
175 echoscip-shell system . . echo. "hello" > a.dat
176
177 gitscip-shell system . . git. add .gitattributes a.dat
178 gitscip-shell system . . 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 gitscip-shell system . . git. config --local "credential.helper" ""
184
185 url=$(gitscip-shell system . . git. config --get remote.origin.url)
186 newurl=${url/http:\/\//http:\/\/user\:pass@}
187 gitscip-shell system . . git. remote set-url origin "$newurl"
188
189 GIT_ASKPASS="lfs-askpass" GIT_TRACE=1 GIT_CURL_VERBOSE=1 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
190
191 grepscip-shell system . . grep. "filling with GIT_ASKPASS" push.log && exit 1
192 grepscip-shell system . . grep. "main -> main" push.log
193 )
194 end_test