| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | ensure_git_version_isnt $VERSION_LOWER "2.3.0" |
| 6 | |
| 7 | export CREDSDIR="$REMOTEDIR/creds-credentials" |
| 8 | setup_creds |
| 9 | |
| 10 | begin_test "credentials with url-specific helper skips askpass" |
| 11 | ( |
| 12 | set -e |
| 13 | |
| 14 | reponame="url-specific-helper" |
| 15 | setup_remote_repo "$reponame" |
| 16 | |
| 17 | clone_repo "$reponame" "$reponame" |
| 18 | git config credential.useHttpPath false |
| 19 | git config credential.helper "" |
| 20 | git config credential.$GITSERVER.helper "lfstest" |
| 21 | |
| 22 | git lfs track "*.dat" |
| 23 | echo "hello" > a.dat |
| 24 | |
| 25 | git add .gitattributes a.dat |
| 26 | git commit -m "initial commit" |
| 27 | |
| 28 | # askpass is skipped |
| 29 | GIT_ASKPASS="lfs-bad-cmd" GIT_TRACE=1 git push origin main 2>&1 | tee push.log |
| 30 | |
| 31 | [ 0 -eq "$(grep -c "filling with GIT_ASKPASS" push.log)" ] |
| 32 | ) |
| 33 | end_test |
| 34 | |
| 35 | begin_test "credentials without useHttpPath, with bad path password" |
| 36 | ( |
| 37 | set -e |
| 38 | |
| 39 | reponame="no-httppath-bad-password" |
| 40 | setup_remote_repo "$reponame" |
| 41 | |
| 42 | printf ":path:wrong" > "$CREDSDIR/127.0.0.1--$reponame" |
| 43 | |
| 44 | clone_repo "$reponame" without-path |
| 45 | git config credential.useHttpPath false |
| 46 | git checkout -b without-path |
| 47 | |
| 48 | git lfs track "*.dat" 2>&1 | tee track.log |
| 49 | grep "Tracking \"\*.dat\"" track.log |
| 50 | |
| 51 | printf "a" > a.dat |
| 52 | git add a.dat |
| 53 | git add .gitattributes |
| 54 | git commit -m "add a.dat" |
| 55 | |
| 56 | GIT_TRACE=1 git push origin without-path 2>&1 | tee push.log |
| 57 | grep "Uploading LFS objects: 100% (1/1), 1 B" push.log |
| 58 | |
| 59 | echo "approvals:" |
| 60 | [ 1 -eq "$(grep -c "creds: git credential approve" push.log)" ] |
| 61 | echo "fills:" |
| 62 | [ 1 -eq "$(grep -c "creds: git credential fill" push.log)" ] |
| 63 | |
| 64 | echo "credential calls have no path:" |
| 65 | credcalls="$(grep "creds: git credential" push.log)" |
| 66 | [ 0 -eq "$(echo "$credcalls" | grep -c "no-httppath-bad-password")" ] |
| 67 | expected="$(echo "$credcalls" | wc -l)" |
| 68 | [ "$expected" -eq "$(printf "%s" "$credcalls" | grep -c '", "")')" ] |
| 69 | ) |
| 70 | end_test |
| 71 | |
| 72 | begin_test "credentials with url-specific useHttpPath, with bad path password" |
| 73 | ( |
| 74 | set -e |
| 75 | |
| 76 | reponame="url-specific-httppath-bad-password" |
| 77 | setup_remote_repo "$reponame" |
| 78 | |
| 79 | printf ":path:wrong" > "$CREDSDIR/127.0.0.1--$reponame" |
| 80 | |
| 81 | clone_repo "$reponame" with-url-specific-path |
| 82 | git config credential.$GITSERVER.useHttpPath false |
| 83 | git config lfs.locksverify false |
| 84 | git checkout -b without-path |
| 85 | |
| 86 | git lfs track "*.dat" 2>&1 | tee track.log |
| 87 | grep "Tracking \"\*.dat\"" track.log |
| 88 | |
| 89 | printf "a" > a.dat |
| 90 | git add a.dat |
| 91 | git add .gitattributes |
| 92 | git commit -m "add a.dat" |
| 93 | |
| 94 | GIT_TRACE=1 git push origin without-path 2>&1 | tee push.log |
| 95 | grep "Uploading LFS objects: 100% (1/1), 1 B" push.log |
| 96 | |
| 97 | echo "approvals:" |
| 98 | [ 1 -eq "$(grep -c "creds: git credential approve" push.log)" ] |
| 99 | echo "fills:" |
| 100 | [ 1 -eq "$(grep -c "creds: git credential fill" push.log)" ] |
| 101 | ) |
| 102 | end_test |
| 103 | |
| 104 | begin_test "credentials with useHttpPath, with wrong password" |
| 105 | ( |
| 106 | set -e |
| 107 | |
| 108 | reponame="httppath-bad-password" |
| 109 | setup_remote_repo "$reponame" |
| 110 | |
| 111 | printf ":path:wrong" > "$CREDSDIR/127.0.0.1--$reponame" |
| 112 | |
| 113 | clone_repo "$reponame" with-path-wrong-pass |
| 114 | git checkout -b with-path-wrong-pass |
| 115 | |
| 116 | git lfs track "*.dat" 2>&1 | tee track.log |
| 117 | grep "Tracking \"\*.dat\"" track.log |
| 118 | |
| 119 | contents="a" |
| 120 | contents_oid=$(calc_oid "$contents") |
| 121 | |
| 122 | printf "%s" "$contents" > a.dat |
| 123 | git add a.dat |
| 124 | git add .gitattributes |
| 125 | git commit -m "add a.dat" |
| 126 | |
| 127 | GIT_TRACE=1 git push origin with-path-wrong-pass 2>&1 | tee push.log |
| 128 | [ 0 -eq "$(grep -c "Uploading LFS objects: 100% (1/1)" push.log)" ] |
| 129 | |
| 130 | # Requests to both the Locking API and the Batch API should receive 403s. |
| 131 | [ 1 -eq "$(grep -c "Authorization error: $GITSERVER/$reponame.*/locks/verify" push.log)" ] |
| 132 | [ 1 -eq "$(grep -c "batch response: Authorization error: $GITSERVER/$reponame" push.log)" ] |
| 133 | |
| 134 | [ 0 -eq "$(grep -c "creds: git credential approve" push.log)" ] |
| 135 | [ 2 -eq "$(grep -c "creds: git credential fill" push.log)" ] |
| 136 | |
| 137 | refute_server_object "$reponame" "$contents_oid" |
| 138 | ) |
| 139 | end_test |
| 140 | |
| 141 | begin_test "credentials with useHttpPath, with wrong password and 401 response" |
| 142 | ( |
| 143 | set -e |
| 144 | |
| 145 | reponame="httppath-bad-password-401-unauth" |
| 146 | setup_remote_repo "$reponame" |
| 147 | |
| 148 | printf ":path:wrong" > "$CREDSDIR/127.0.0.1--$reponame" |
| 149 | |
| 150 | clone_repo "$reponame" with-path-wrong-pass-401-unauth |
| 151 | git checkout -b with-path-wrong-pass-401-unauth |
| 152 | |
| 153 | git lfs track "*.dat" |
| 154 | |
| 155 | contents="a" |
| 156 | contents_oid="$(calc_oid "$contents")" |
| 157 | printf "%s" "$contents" >a.dat |
| 158 | |
| 159 | git add .gitattributes a.dat |
| 160 | git commit -m "initial commit" |
| 161 | |
| 162 | GIT_TRACE=1 git push origin with-path-wrong-pass-401-unauth 2>&1 | tee push.log |
| 163 | [ 0 -eq "$(grep -c "Uploading LFS objects: 100% (1/1), 1 B" push.log)" ] |
| 164 | |
| 165 | # Requests to both the Locking API and the Batch API should receive 401s |
| 166 | # until the maximum number of authentication attempts is reached for both. |
| 167 | [ 2 -eq "$(grep -c "api: too many authentication attempts" push.log)" ] |
| 168 | [ 1 -eq "$(grep -c "batch response: too many authentication attempts" push.log)" ] |
| 169 | |
| 170 | # Note that the first request to the Locking API is made without an |
| 171 | # Authorization header, so no credentials are retrieved for that request |
| 172 | # and it is not counted toward the authentication attempt limit. |
| 173 | [ 0 -eq "$(grep -c "creds: git credential approve" push.log)" ] |
| 174 | [ 6 -eq "$(grep -c "creds: git credential fill" push.log)" ] |
| 175 | |
| 176 | refute_server_object "$reponame" "$contents_oid" |
| 177 | ) |
| 178 | end_test |
| 179 | |
| 180 | begin_test "credentials with useHttpPath, with correct password" |
| 181 | ( |
| 182 | set -e |
| 183 | |
| 184 | reponame="$(basename "$0" ".sh")" |
| 185 | setup_remote_repo "$reponame" |
| 186 | |
| 187 | printf ":path:$reponame" > "$CREDSDIR/127.0.0.1--$reponame" |
| 188 | |
| 189 | clone_repo "$reponame" with-path-correct-pass |
| 190 | git checkout -b with-path-correct-pass |
| 191 | |
| 192 | git lfs track "*.dat" 2>&1 | tee track.log |
| 193 | grep "Tracking \"\*.dat\"" track.log |
| 194 | |
| 195 | # creating new branch does not re-send any objects existing on other |
| 196 | # remote branches anymore, generate new object, different from prev tests |
| 197 | contents="b" |
| 198 | contents_oid=$(calc_oid "$contents") |
| 199 | |
| 200 | printf "%s" "$contents" > b.dat |
| 201 | git add b.dat |
| 202 | git add .gitattributes |
| 203 | git commit -m "add b.dat" |
| 204 | |
| 205 | GIT_TRACE=1 git push origin with-path-correct-pass 2>&1 | tee push.log |
| 206 | grep "Uploading LFS objects: 100% (1/1), 1 B" push.log |
| 207 | echo "approvals:" |
| 208 | [ 1 -eq "$(grep -c "creds: git credential approve" push.log)" ] |
| 209 | echo "fills:" |
| 210 | [ 1 -eq "$(grep -c "creds: git credential fill" push.log)" ] |
| 211 | echo "credential calls have path:" |
| 212 | credcalls="$(grep "creds: git credential" push.log)" |
| 213 | [ 0 -eq "$(echo "$credcalls" | grep -c '", "")')" ] |
| 214 | expected="$(echo "$credcalls" | wc -l)" |
| 215 | [ "$expected" -eq "$(printf "%s" "$credcalls" | grep -c "t-credentials")" ] |
| 216 | ) |
| 217 | end_test |
| 218 | |
| 219 | begin_test "credentials send wwwauth[] by default" |
| 220 | ( |
| 221 | set -e |
| 222 | ensure_git_version_isnt $VERSION_LOWER "2.41.0" |
| 223 | export LFS_TEST_CREDS_WWWAUTH=required |
| 224 | |
| 225 | reponame="$(basename "$0" ".sh")-wwwauth-required" |
| 226 | setup_remote_repo "$reponame" |
| 227 | |
| 228 | printf ":path:$reponame" > "$CREDSDIR/127.0.0.1--$reponame" |
| 229 | |
| 230 | clone_repo "$reponame" "$reponame" |
| 231 | git checkout -b new-branch |
| 232 | |
| 233 | git lfs track "*.dat" 2>&1 | tee track.log |
| 234 | grep "Tracking \"\*.dat\"" track.log |
| 235 | |
| 236 | # creating new branch does not re-send any objects existing on other |
| 237 | # remote branches anymore, generate new object, different from prev tests |
| 238 | contents="b" |
| 239 | contents_oid=$(calc_oid "$contents") |
| 240 | |
| 241 | printf "%s" "$contents" > b.dat |
| 242 | git add b.dat |
| 243 | git add .gitattributes |
| 244 | git commit -m "add b.dat" |
| 245 | |
| 246 | GIT_TERMINAL_PROMPT=0 GIT_TRACE=1 git push origin new-branch 2>&1 | tee push.log |
| 247 | grep "Uploading LFS objects: 100% (1/1), 1 B" push.log |
| 248 | echo "approvals:" |
| 249 | [ 1 -eq "$(grep -c "creds: git credential approve" push.log)" ] |
| 250 | echo "fills:" |
| 251 | [ 1 -eq "$(grep -c "creds: git credential fill" push.log)" ] |
| 252 | echo "credential calls have path:" |
| 253 | credcalls="$(grep "creds: git credential" push.log)" |
| 254 | [ 0 -eq "$(echo "$credcalls" | grep -c '", "")')" ] |
| 255 | expected="$(echo "$credcalls" | wc -l)" |
| 256 | [ "$expected" -eq "$(printf "%s" "$credcalls" | grep -c "t-credentials")" ] |
| 257 | ) |
| 258 | end_test |
| 259 | |
| 260 | begin_test "credentials sends wwwauth[] and fails with finicky helper" |
| 261 | ( |
| 262 | set -e |
| 263 | ensure_git_version_isnt $VERSION_LOWER "2.41.0" |
| 264 | export LFS_TEST_CREDS_WWWAUTH=forbidden |
| 265 | |
| 266 | reponame="$(basename "$0" ".sh")-wwwauth-forbidden-finicky" |
| 267 | setup_remote_repo "$reponame" |
| 268 | |
| 269 | printf ":path:$reponame" > "$CREDSDIR/127.0.0.1--$reponame" |
| 270 | |
| 271 | clone_repo "$reponame" "$reponame" |
| 272 | git checkout -b new-branch |
| 273 | |
| 274 | git lfs track "*.dat" 2>&1 | tee track.log |
| 275 | grep "Tracking \"\*.dat\"" track.log |
| 276 | |
| 277 | # creating new branch does not re-send any objects existing on other |
| 278 | # remote branches anymore, generate new object, different from prev tests |
| 279 | contents="b" |
| 280 | contents_oid=$(calc_oid "$contents") |
| 281 | |
| 282 | printf "%s" "$contents" > b.dat |
| 283 | git add b.dat |
| 284 | git add .gitattributes |
| 285 | git commit -m "add b.dat" |
| 286 | |
| 287 | GIT_TERMINAL_PROMPT=0 GIT_TRACE=1 git push origin new-branch 2>&1 | tee push.log |
| 288 | echo "approvals:" |
| 289 | [ 0 -eq "$(grep -c "creds: git credential approve" push.log)" ] |
| 290 | echo "fills:" |
| 291 | [ 2 -eq "$(grep -c "creds: git credential fill" push.log)" ] |
| 292 | ) |
| 293 | end_test |
| 294 | |
| 295 | begin_test "credentials skips wwwauth[] with option" |
| 296 | ( |
| 297 | set -e |
| 298 | ensure_git_version_isnt $VERSION_LOWER "2.41.0" |
| 299 | export LFS_TEST_CREDS_WWWAUTH=forbidden |
| 300 | |
| 301 | reponame="$(basename "$0" ".sh")-wwwauth-skip" |
| 302 | setup_remote_repo "$reponame" |
| 303 | git config --global credential.$GITSERVER.skipwwwauth true |
| 304 | |
| 305 | printf ":path:$reponame" > "$CREDSDIR/127.0.0.1--$reponame" |
| 306 | |
| 307 | clone_repo "$reponame" "$reponame" |
| 308 | git checkout -b new-branch |
| 309 | |
| 310 | git lfs track "*.dat" 2>&1 | tee track.log |
| 311 | grep "Tracking \"\*.dat\"" track.log |
| 312 | |
| 313 | # creating new branch does not re-send any objects existing on other |
| 314 | # remote branches anymore, generate new object, different from prev tests |
| 315 | contents="b" |
| 316 | contents_oid=$(calc_oid "$contents") |
| 317 | |
| 318 | printf "%s" "$contents" > b.dat |
| 319 | git add b.dat |
| 320 | git add .gitattributes |
| 321 | git commit -m "add b.dat" |
| 322 | |
| 323 | GIT_TERMINAL_PROMPT=0 GIT_TRACE=1 git push origin new-branch 2>&1 | tee push.log |
| 324 | grep "Uploading LFS objects: 100% (1/1), 1 B" push.log |
| 325 | echo "approvals:" |
| 326 | [ 1 -eq "$(grep -c "creds: git credential approve" push.log)" ] |
| 327 | echo "fills:" |
| 328 | [ 1 -eq "$(grep -c "creds: git credential fill" push.log)" ] |
| 329 | echo "credential calls have path:" |
| 330 | credcalls="$(grep "creds: git credential" push.log)" |
| 331 | [ 0 -eq "$(echo "$credcalls" | grep -c '", "")')" ] |
| 332 | expected="$(echo "$credcalls" | wc -l)" |
| 333 | [ "$expected" -eq "$(printf "%s" "$credcalls" | grep -c "t-credentials")" ] |
| 334 | ) |
| 335 | end_test |
| 336 | |
| 337 | begin_test "credentials can authenticate with Bearer auth" |
| 338 | ( |
| 339 | set -e |
| 340 | git credential capability </dev/null | grep "capability authtype" || exit 0 |
| 341 | |
| 342 | reponame="auth-bearer-token" |
| 343 | setup_remote_repo "$reponame" |
| 344 | |
| 345 | printf "Bearer::token" > "$CREDSDIR/127.0.0.1--$reponame" |
| 346 | |
| 347 | clone_repo "$reponame" "$reponame" |
| 348 | git checkout -b new-branch |
| 349 | |
| 350 | git lfs track "*.dat" 2>&1 | tee track.log |
| 351 | grep "Tracking \"\*.dat\"" track.log |
| 352 | |
| 353 | contents="b" |
| 354 | |
| 355 | printf "%s" "$contents" > b.dat |
| 356 | git add b.dat |
| 357 | git add .gitattributes |
| 358 | git commit -m "add b.dat" |
| 359 | |
| 360 | GIT_TERMINAL_PROMPT=0 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 GIT_CURL_VERBOSE=1 git push origin new-branch 2>&1 | tee push.log |
| 361 | grep "Uploading LFS objects: 100% (1/1), 1 B" push.log |
| 362 | [ 1 -eq "$(grep -c "creds: git credential approve" push.log)" ] |
| 363 | [ 1 -eq "$(grep -c "creds: git credential fill" push.log)" ] |
| 364 | ) |
| 365 | end_test |
| 366 | |
| 367 | begin_test "credentials can authenticate with multistage auth" |
| 368 | ( |
| 369 | set -e |
| 370 | [ $(git credential capability </dev/null | grep -c -E "capability (authtype|state)") -eq 2 ] || exit 0 |
| 371 | |
| 372 | reponame="auth-multistage-token" |
| 373 | setup_remote_repo "$reponame" |
| 374 | |
| 375 | printf 'Multistage::cred2of2:state1:state2:\n' >"$CREDSDIR/127.0.0.1--$reponame" |
| 376 | # Note that the entry with the empty, generic "match state" value in the |
| 377 | # fourth field must be ordered after all other entries so that it does not |
| 378 | # always match the current request. |
| 379 | printf 'Multistage::cred1of2::state1:true\n' >>"$CREDSDIR/127.0.0.1--$reponame" |
| 380 | |
| 381 | clone_repo "$reponame" "$reponame" |
| 382 | git checkout -b new-branch |
| 383 | |
| 384 | git lfs track "*.dat" 2>&1 | tee track.log |
| 385 | grep "Tracking \"\*.dat\"" track.log |
| 386 | |
| 387 | contents="b" |
| 388 | |
| 389 | printf "%s" "$contents" > b.dat |
| 390 | git add b.dat |
| 391 | git add .gitattributes |
| 392 | git commit -m "add b.dat" |
| 393 | |
| 394 | GIT_TERMINAL_PROMPT=0 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 GIT_CURL_VERBOSE=1 git push origin new-branch 2>&1 | tee push.log |
| 395 | grep "Uploading LFS objects: 100% (1/1), 1 B" push.log |
| 396 | |
| 397 | [ 1 -eq "$(grep -c "creds: git credential approve" push.log)" ] |
| 398 | [ 2 -eq "$(grep -c "creds: git credential fill" push.log)" ] |
| 399 | ) |
| 400 | end_test |
| 401 | |
| 402 | begin_test "credentials with multistage auth loop fails" |
| 403 | ( |
| 404 | set -e |
| 405 | [ $(git credential capability </dev/null | grep -c -E "capability (authtype|state)") -eq 2 ] || exit 0 |
| 406 | |
| 407 | reponame="auth-multistage-loop" |
| 408 | setup_remote_repo "$reponame" |
| 409 | |
| 410 | # Note that we define an endless transition from "state1" to "state1" |
| 411 | # so our git-credential-lfstest utility will simulate an invalid |
| 412 | # credential helper. |
| 413 | printf 'Multistage::cred1of2:state1:state1:true\n' >"$CREDSDIR/127.0.0.1--$reponame" |
| 414 | # Note that the entry with the empty, generic "match state" value in the |
| 415 | # fourth field must be ordered after all other entries so that it does not |
| 416 | # always match the current request. |
| 417 | printf 'Multistage::cred1of2::state1:true\n' >>"$CREDSDIR/127.0.0.1--$reponame" |
| 418 | |
| 419 | clone_repo "$reponame" "$reponame" |
| 420 | git checkout -b new-branch |
| 421 | |
| 422 | git lfs track "*.dat" |
| 423 | |
| 424 | contents="b" |
| 425 | contents_oid="$(calc_oid "$contents")" |
| 426 | printf "%s" "$contents" >b.dat |
| 427 | |
| 428 | git add .gitattributes b.dat |
| 429 | git commit -m "initial commit" |
| 430 | |
| 431 | GIT_TERMINAL_PROMPT=0 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 GIT_CURL_VERBOSE=1 git push origin new-branch 2>&1 | tee push.log |
| 432 | [ 0 -eq "$(grep -c "Uploading LFS objects: 100% (1/1)" push.log)" ] |
| 433 | |
| 434 | # Requests to both the Locking API and the Batch API should receive 401s |
| 435 | # until the maximum number of authentication attempts is reached for both. |
| 436 | [ 2 -eq "$(grep -c "api: too many authentication attempts" push.log)" ] |
| 437 | [ 1 -eq "$(grep -c "batch response: too many authentication attempts" push.log)" ] |
| 438 | |
| 439 | # Note that the first request to the Locking API is made without an |
| 440 | # Authorization header, so no credentials are retrieved for that request |
| 441 | # and it is not counted toward the authentication attempt limit. |
| 442 | [ 6 -eq "$(grep -c "Authorization: Multistage cred1" push.log)" ] |
| 443 | |
| 444 | [ 0 -eq "$(grep -c "creds: git credential approve" push.log)" ] |
| 445 | [ 6 -eq "$(grep -c "creds: git credential fill" push.log)" ] |
| 446 | |
| 447 | refute_server_object "$reponame" "$contents_oid" |
| 448 | ) |
| 449 | end_test |
| 450 | |
| 451 | begin_test "credentials with multistage auth above limit fails and resets" |
| 452 | ( |
| 453 | set -e |
| 454 | [ $(git credential capability </dev/null | grep -c -E "capability (authtype|state)") -eq 2 ] || exit 0 |
| 455 | |
| 456 | reponame="auth-multistage-limit-reset" |
| 457 | setup_remote_repo "$reponame" |
| 458 | |
| 459 | printf 'Multistage::cred4of4:state3:state4:true\n' >>"$CREDSDIR/127.0.0.1--$reponame" |
| 460 | printf 'Multistage::cred3of4:state2:state3:true\n' >>"$CREDSDIR/127.0.0.1--$reponame" |
| 461 | printf 'Multistage::cred2of4:state1:state2:true\n' >>"$CREDSDIR/127.0.0.1--$reponame" |
| 462 | # Note that the entry with the empty, generic "match state" value in the |
| 463 | # fourth field must be ordered after all other entries so that it does not |
| 464 | # always match the current request. |
| 465 | printf 'Multistage::cred1of4::state1:true\n' >>"$CREDSDIR/127.0.0.1--$reponame" |
| 466 | |
| 467 | clone_repo "$reponame" "$reponame" |
| 468 | git checkout -b new-branch |
| 469 | |
| 470 | git lfs track "*.dat" |
| 471 | |
| 472 | contents="b" |
| 473 | contents_oid="$(calc_oid "$contents")" |
| 474 | printf "%s" "$contents" >b.dat |
| 475 | |
| 476 | git add .gitattributes b.dat |
| 477 | git commit -m "initial commit" |
| 478 | |
| 479 | GIT_TERMINAL_PROMPT=0 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 GIT_CURL_VERBOSE=1 git push origin new-branch 2>&1 | tee push.log |
| 480 | [ 0 -eq "$(grep -c "Uploading LFS objects: 100% (1/1)" push.log)" ] |
| 481 | |
| 482 | # Requests to both the Locking API and the Batch API should receive 401s |
| 483 | # until the maximum number of authentication attempts is reached for both. |
| 484 | [ 2 -eq "$(grep -c "api: too many authentication attempts" push.log)" ] |
| 485 | [ 1 -eq "$(grep -c "batch response: too many authentication attempts" push.log)" ] |
| 486 | |
| 487 | # Note that the first request to the Locking API is made without an |
| 488 | # Authorization header, so no credentials are retrieved for that request |
| 489 | # and it is not counted toward the authentication attempt limit. |
| 490 | [ 2 -eq "$(grep -c "Authorization: Multistage cred1of4" push.log)" ] |
| 491 | [ 2 -eq "$(grep -c "Authorization: Multistage cred2of4" push.log)" ] |
| 492 | [ 2 -eq "$(grep -c "Authorization: Multistage cred3of4" push.log)" ] |
| 493 | [ 0 -eq "$(grep -c "Authorization: Multistage cred4of4" push.log)" ] |
| 494 | |
| 495 | [ 0 -eq "$(grep -c "creds: git credential approve" push.log)" ] |
| 496 | [ 6 -eq "$(grep -c "creds: git credential fill" push.log)" ] |
| 497 | |
| 498 | refute_server_object "$reponame" "$contents_oid" |
| 499 | ) |
| 500 | end_test |
| 501 | |
| 502 | begin_test "git credential" |
| 503 | ( |
| 504 | set -e |
| 505 | |
| 506 | printf ":git:server" > "$CREDSDIR/credential-test.com" |
| 507 | printf ":git:path" > "$CREDSDIR/credential-test.com--some-path" |
| 508 | # Note that the entry with the empty, generic "match state" value in the |
| 509 | # fourth field must be ordered after all other entries so that it does not |
| 510 | # always match the current request. |
| 511 | printf 'Multistage::bazquux:state1:state2:\nMultistage::foobar::state1:true' > "$CREDSDIR/example.com" |
| 512 | |
| 513 | mkdir empty |
| 514 | cd empty |
| 515 | git init |
| 516 | |
| 517 | echo "protocol=http |
| 518 | host=credential-test.com |
| 519 | path=some/path" | GIT_TERMINAL_PROMPT=0 git credential fill > cred.log |
| 520 | cat cred.log |
| 521 | |
| 522 | expected="protocol=http |
| 523 | host=credential-test.com |
| 524 | path=some/path |
| 525 | username=git |
| 526 | password=path" |
| 527 | |
| 528 | [ "$expected" = "$(cat cred.log)" ] |
| 529 | |
| 530 | git config credential.useHttpPath false |
| 531 | |
| 532 | echo "protocol=http |
| 533 | host=credential-test.com" | GIT_TERMINAL_PROMPT=0 git credential fill > cred.log |
| 534 | cat cred.log |
| 535 | |
| 536 | expected="protocol=http |
| 537 | host=credential-test.com |
| 538 | username=git |
| 539 | password=server" |
| 540 | [ "$expected" = "$(cat cred.log)" ] |
| 541 | |
| 542 | echo "protocol=http |
| 543 | host=credential-test.com |
| 544 | path=some/path" | GIT_TERMINAL_PROMPT=0 git credential fill > cred.log |
| 545 | cat cred.log |
| 546 | |
| 547 | expected="protocol=http |
| 548 | host=credential-test.com |
| 549 | username=git |
| 550 | password=server" |
| 551 | |
| 552 | [ "$expected" = "$(cat cred.log)" ] |
| 553 | |
| 554 | [ $(git credential capability </dev/null | grep -c -E "capability (authtype|state)") -eq 2 ] || exit 0 |
| 555 | |
| 556 | echo "capability[]=authtype |
| 557 | capability[]=state |
| 558 | protocol=http |
| 559 | host=example.com" | GIT_TERMINAL_PROMPT=0 git credential fill > cred.log |
| 560 | cat cred.log |
| 561 | |
| 562 | expected="capability[]=authtype |
| 563 | capability[]=state |
| 564 | authtype=Multistage |
| 565 | credential=foobar |
| 566 | protocol=http |
| 567 | host=example.com |
| 568 | continue=1 |
| 569 | state[]=lfstest:state1" |
| 570 | |
| 571 | [ "$expected" = "$(cat cred.log)" ] |
| 572 | |
| 573 | echo "capability[]=authtype |
| 574 | capability[]=state |
| 575 | protocol=http |
| 576 | host=example.com |
| 577 | state[]=lfstest:state1" | GIT_TERMINAL_PROMPT=0 git credential fill > cred.log |
| 578 | cat cred.log |
| 579 | |
| 580 | expected="capability[]=authtype |
| 581 | capability[]=state |
| 582 | authtype=Multistage |
| 583 | credential=bazquux |
| 584 | protocol=http |
| 585 | host=example.com |
| 586 | state[]=lfstest:state2" |
| 587 | |
| 588 | [ "$expected" = "$(cat cred.log)" ] |
| 589 | ) |
| 590 | end_test |
| 591 | |
| 592 | NETRCFILES=".netrc" |
| 593 | if [ "$IS_WINDOWS" -eq 1 ]; then |
| 594 | NETRCFILES+=" _netrc" |
| 595 | fi |
| 596 | |
| 597 | for netrcfile in $NETRCFILES; do |
| 598 | begin_test "credentials from netrc ($netrcfile)" |
| 599 | ( |
| 600 | set -e |
| 601 | |
| 602 | printf "machine localhost\nlogin netrcuser\npassword netrcpass\n" >"$HOME/$netrcfile" |
| 603 | echo $HOME |
| 604 | echo "GITSERVER $GITSERVER" |
| 605 | cat "$HOME/$netrcfile" |
| 606 | |
| 607 | # prevent prompts on Windows particularly |
| 608 | export SSH_ASKPASS= |
| 609 | |
| 610 | reponame="netrctest-$netrcfile" |
| 611 | setup_remote_repo "$reponame" |
| 612 | |
| 613 | clone_repo "$reponame" "${reponame}-assert" |
| 614 | |
| 615 | # Need a remote named "localhost" or 127.0.0.1 in netrc will interfere with the other auth |
| 616 | git remote add "netrc" "$(echo $GITSERVER | sed s/127.0.0.1/localhost/)/netrctest" |
| 617 | git lfs env |
| 618 | |
| 619 | git lfs track "*.dat" |
| 620 | echo "push a" > a.dat |
| 621 | git add .gitattributes a.dat |
| 622 | git commit -m "add a.dat" |
| 623 | |
| 624 | GIT_TRACE=1 git lfs push netrc main 2>&1 | tee push.log |
| 625 | grep "Uploading LFS objects: 100% (1/1), 7 B" push.log |
| 626 | echo "any netrc credential calls:" |
| 627 | [ 4 -eq "$(grep -c "netrc: git credential" push.log)" ] |
| 628 | |
| 629 | echo "any netrc credential fills:" |
| 630 | [ 2 -eq "$(grep -c "netrc: git credential fill" push.log)" ] |
| 631 | |
| 632 | echo "any netrc credential approvals:" |
| 633 | [ 2 -eq "$(grep -c "netrc: git credential approve" push.log)" ] |
| 634 | ) |
| 635 | end_test |
| 636 | done |
| 637 | |
| 638 | begin_test "credentials from netrc with unknown keyword" |
| 639 | ( |
| 640 | set -e |
| 641 | |
| 642 | printf "machine localhost\nlogin netrcuser\nnot-a-key something\npassword netrcpass\n" >"$HOME/.netrc" |
| 643 | echo $HOME |
| 644 | echo "GITSERVER $GITSERVER" |
| 645 | cat "$HOME/.netrc" |
| 646 | |
| 647 | # prevent prompts on Windows particularly |
| 648 | export SSH_ASKPASS= |
| 649 | |
| 650 | reponame="netrctest" |
| 651 | setup_remote_repo "$reponame" |
| 652 | |
| 653 | clone_repo "$reponame" repo2 |
| 654 | |
| 655 | # Need a remote named "localhost" or 127.0.0.1 in netrc will interfere with the other auth |
| 656 | git remote add "netrc" "$(echo $GITSERVER | sed s/127.0.0.1/localhost/)/netrctest" |
| 657 | git lfs env |
| 658 | |
| 659 | git lfs track "*.dat" |
| 660 | echo "push a" > a.dat |
| 661 | git add .gitattributes a.dat |
| 662 | git commit -m "add a.dat" |
| 663 | |
| 664 | GIT_TRACE=1 git lfs push netrc main 2>&1 | tee push.log |
| 665 | grep "Uploading LFS objects: 100% (1/1), 7 B" push.log |
| 666 | echo "any netrc credential calls:" |
| 667 | [ 4 -eq "$(grep -c "netrc: git credential" push.log)" ] |
| 668 | |
| 669 | echo "any netrc credential fills:" |
| 670 | [ 2 -eq "$(grep -c "netrc: git credential fill" push.log)" ] |
| 671 | |
| 672 | echo "any netrc credential approvals:" |
| 673 | [ 2 -eq "$(grep -c "netrc: git credential approve" push.log)" ] |
| 674 | ) |
| 675 | end_test |
| 676 | |
| 677 | begin_test "credentials from netrc with bad password" |
| 678 | ( |
| 679 | set -e |
| 680 | |
| 681 | printf "machine localhost\nlogin netrcuser\npassword badpass\n" >"$HOME/.netrc" |
| 682 | echo $HOME |
| 683 | echo "GITSERVER $GITSERVER" |
| 684 | cat "$HOME/.netrc" |
| 685 | |
| 686 | # prevent prompts on Windows particularly |
| 687 | export SSH_ASKPASS= |
| 688 | |
| 689 | reponame="netrctest" |
| 690 | setup_remote_repo "$reponame" |
| 691 | |
| 692 | clone_repo "$reponame" repo3 |
| 693 | |
| 694 | # Need a remote named "localhost" or 127.0.0.1 in netrc will interfere with the other auth |
| 695 | git remote add "netrc" "$(echo $GITSERVER | sed s/127.0.0.1/localhost/)/netrctest" |
| 696 | git lfs env |
| 697 | |
| 698 | git lfs track "*.dat" |
| 699 | echo "push a" > a.dat |
| 700 | git add .gitattributes a.dat |
| 701 | git commit -m "add a.dat" |
| 702 | |
| 703 | git push netrc main 2>&1 | tee push.log |
| 704 | [ 0 -eq "$(grep -c "Uploading LFS objects: 100% (1/1), 7 B" push.log)" ] |
| 705 | ) |
| 706 | end_test |
| 707 | |
| 708 | begin_test "credentials with bad netrc creds will retry" |
| 709 | ( |
| 710 | set -e |
| 711 | |
| 712 | printf "machine localhost\nlogin netrcuser\npassword badpassretry\n" >"$HOME/.netrc" |
| 713 | echo $HOME |
| 714 | echo "GITSERVER $GITSERVER" |
| 715 | cat "$HOME/.netrc" |
| 716 | |
| 717 | # prevent prompts on Windows particularly |
| 718 | export SSH_ASKPASS= |
| 719 | |
| 720 | # ensure we provide the correct creds through ASKPASS so we can fall back |
| 721 | # when .netrc fails |
| 722 | export LFS_ASKPASS_USERNAME="netrcuser" |
| 723 | export LFS_ASKPASS_PASSWORD="netrcpass" |
| 724 | |
| 725 | reponame="netrctest" |
| 726 | setup_remote_repo "$reponame" |
| 727 | |
| 728 | clone_repo "$reponame" repo4 |
| 729 | |
| 730 | # Need a remote named "localhost" or 127.0.0.1 in netrc will interfere with the other auth |
| 731 | git remote add "netrc" "$(echo $GITSERVER | sed s/127.0.0.1/localhost/)/netrctest" |
| 732 | git lfs env |
| 733 | |
| 734 | git lfs track "*.dat" |
| 735 | echo "push a" > a.dat |
| 736 | git add .gitattributes a.dat |
| 737 | git commit -m "add a.dat" |
| 738 | |
| 739 | GIT_TRACE=1 GIT_ASKPASS="lfs-askpass" git push netrc main 2>&1 | tee push.log |
| 740 | grep -c "Uploading LFS objects: 100% (1/1), 7 B" push.log |
| 741 | |
| 742 | # netrc credentials should be attempted then rejected for the lock request |
| 743 | echo "netrc credentials attempted:" |
| 744 | [ 1 -eq "$(grep -c "netrc: git credential fill" push.log)" ] |
| 745 | |
| 746 | echo "netrc credentials rejected:" |
| 747 | [ 1 -eq "$(grep -c "netrc: git credential reject" push.log)" ] |
| 748 | |
| 749 | # credhelper should then use askpass to find the proper credentials, which |
| 750 | # should be successful |
| 751 | echo "askpass credentials attempted:" |
| 752 | [ 1 -eq "$(grep -c "creds: git credential fill" push.log)" ] |
| 753 | |
| 754 | echo "askpass credentials approved:" |
| 755 | [ 1 -eq "$(grep -c "creds: git credential approve" push.log)" ] |
| 756 | |
| 757 | # askpass creds should be cached and used for the batch request |
| 758 | echo "cached credentials used:" |
| 759 | [ 1 -eq "$(grep -c "creds: git credential cache" push.log)" ] |
| 760 | ) |
| 761 | end_test |
| 762 | |
| 763 | begin_test "credentials from lfs.url" |
| 764 | ( |
| 765 | set -e |
| 766 | |
| 767 | reponame="requirecreds-lfsurl" |
| 768 | setup_remote_repo "$reponame" |
| 769 | clone_repo "$reponame" "$reponame" |
| 770 | |
| 771 | git lfs track "*.dat" |
| 772 | echo "push a" > a.dat |
| 773 | git add .gitattributes a.dat |
| 774 | git commit -m "add a.dat" |
| 775 | |
| 776 | echo "bad push" |
| 777 | git lfs env |
| 778 | git lfs push origin main 2>&1 | tee push.log |
| 779 | grep "Uploading LFS objects: 0% (0/1), 0 B" push.log |
| 780 | |
| 781 | echo "good push" |
| 782 | gitserverhost=$(echo "$GITSERVER" | cut -d'/' -f3) |
| 783 | git config lfs.url http://requirecreds:pass@$gitserverhost/$reponame.git/info/lfs |
| 784 | git lfs env |
| 785 | GIT_TRACE=1 git lfs push origin main 2>&1 | tee push.log |
| 786 | # A 401 indicates URL access mode for the /storage endpoint |
| 787 | # was used instead of for the lfsapi endpoint |
| 788 | grep "HTTP: 401" push.log |
| 789 | # Ensure we didn't make a second batch request, which means the request |
| 790 | # was successfully retried internally |
| 791 | grep "tq: retrying object" push.log && exit 1 |
| 792 | grep "Uploading LFS objects: 0% (0/1), 0 B" push.log |
| 793 | |
| 794 | echo "bad fetch" |
| 795 | rm -rf .git/lfs/objects |
| 796 | git config lfs.url http://$gitserverhost/$reponame.git/info/lfs |
| 797 | git lfs env |
| 798 | git lfs fetch --all 2>&1 | tee fetch.log |
| 799 | grep "Downloading LFS objects: 0% (0/1), 0 B" fetch.log |
| 800 | |
| 801 | echo "good fetch" |
| 802 | rm -rf .git/lfs/objects |
| 803 | git config lfs.url http://requirecreds:pass@$gitserverhost/$reponame.git/info/lfs |
| 804 | git lfs env |
| 805 | GIT_TRACE=1 git lfs fetch --all 2>&1 | tee fetch.log |
| 806 | # No 401 should occur as we've already set an access mode for the |
| 807 | # storage endpoint during the push |
| 808 | grep "HTTP: 401" fetch.log && exit 1 |
| 809 | git lfs fsck |
| 810 | |
| 811 | echo "good fetch, setting access mode" |
| 812 | rm -rf .git/lfs/objects |
| 813 | git config lfs.url http://requirecreds:pass@$gitserverhost/$reponame.git/info/lfs |
| 814 | git config lfs.http://$gitserverhost/storage/.access "None" |
| 815 | git lfs env |
| 816 | GIT_TRACE=1 git lfs fetch --all 2>&1 | tee fetch.log |
| 817 | # A 401 indicates URL access mode for the /storage endpoint |
| 818 | # was used instead of for the lfsapi endpoint |
| 819 | grep "HTTP: 401" fetch.log |
| 820 | # Ensure we didn't make a second batch request, which means the request |
| 821 | # was successfully retried internally |
| 822 | grep "tq: retrying object" fetch.log && exit 1 |
| 823 | |
| 824 | git lfs fsck |
| 825 | ) |
| 826 | end_test |
| 827 | |
| 828 | begin_test "credentials from remote.origin.url" |
| 829 | ( |
| 830 | set -e |
| 831 | |
| 832 | reponame="requirecreds-remoteurl" |
| 833 | setup_remote_repo "$reponame" |
| 834 | clone_repo "$reponame" "$reponame" |
| 835 | |
| 836 | git lfs track "*.dat" |
| 837 | echo "push b" > b.dat |
| 838 | git add .gitattributes b.dat |
| 839 | git commit -m "add b.dat" |
| 840 | |
| 841 | echo "bad push" |
| 842 | git lfs env |
| 843 | git lfs push origin main 2>&1 | tee push.log |
| 844 | grep "Uploading LFS objects: 0% (0/1), 0 B" push.log |
| 845 | |
| 846 | echo "good push" |
| 847 | gitserverhost=$(echo "$GITSERVER" | cut -d'/' -f3) |
| 848 | git config remote.origin.url http://requirecreds:pass@$gitserverhost/$reponame.git |
| 849 | git lfs env |
| 850 | GIT_TRACE=1 git lfs push origin main 2>&1 | tee push.log |
| 851 | # A 401 indicates URL access mode for the /storage endpoint |
| 852 | # was used instead of for the lfsapi endpoint |
| 853 | grep "HTTP: 401" push.log |
| 854 | # Ensure we didn't make a second batch request, which means the request |
| 855 | # was successfully retried internally |
| 856 | grep "tq: retrying object" push.log && exit 1 |
| 857 | grep "Uploading LFS objects: 100% (1/1), 7 B" push.log |
| 858 | |
| 859 | echo "bad fetch" |
| 860 | rm -rf .git/lfs/objects |
| 861 | git config remote.origin.url http://$gitserverhost/$reponame.git |
| 862 | git lfs env |
| 863 | git lfs fetch --all 2>&1 | tee fetch.log |
| 864 | # Missing authentication causes `git lfs fetch` to fail before the progress |
| 865 | # meter is printed to the TTY. |
| 866 | |
| 867 | echo "good fetch" |
| 868 | rm -rf .git/lfs/objects |
| 869 | git config remote.origin.url http://requirecreds:pass@$gitserverhost/$reponame.git |
| 870 | git lfs env |
| 871 | GIT_TRACE=1 git lfs fetch --all 2>&1 | tee fetch.log |
| 872 | # No 401 should occur as we've already set an access mode for the |
| 873 | # storage endpoint during the push |
| 874 | grep "HTTP: 401" fetch.log && exit 1 |
| 875 | git lfs fsck |
| 876 | |
| 877 | echo "good fetch, setting access mode" |
| 878 | rm -rf .git/lfs/objects |
| 879 | git config remote.origin.url http://requirecreds:pass@$gitserverhost/$reponame.git |
| 880 | git config lfs.http://$gitserverhost/storage/.access "None" |
| 881 | git lfs env |
| 882 | GIT_TRACE=1 git lfs fetch --all 2>&1 | tee fetch.log |
| 883 | # A 401 indicates URL access mode for the /storage endpoint |
| 884 | # was used instead of for the lfsapi endpoint |
| 885 | grep "HTTP: 401" fetch.log |
| 886 | # Ensure we didn't make a second batch request, which means the request |
| 887 | # was successfully retried internally |
| 888 | grep "tq: retrying object" fetch.log && exit 1 |
| 889 | |
| 890 | git lfs fsck |
| 891 | ) |
| 892 | end_test |