Debian Codegraph @

t/t-credentials-protect.sh

raw symbols SCIP
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-protect"
8 setup_creds
9
10 # Copy the default record file for the test credential helper to match the
11 # hostname used in the Git LFS configurations of the tests.
12 cp "$CREDSDIR/127.0.0.1" "$CREDSDIR/localhost"
13
14 begin_test "credentials rejected with line feed"
15 (
16 set -e
17
18 reponame="protect-linefeed"
19 setup_remote_repo "$reponame"
20 clone_repo "$reponame" "$reponame"
21
22 contents="a"
23 contents_oid=$(calc_oid "$contents")
24
25 git lfs track "*.dat"
26 printf "%s" "$contents" >a.dat
27 git add .gitattributes a.dat
28 git commit -m "add a.dat"
29
30 # Using localhost instead of 127.0.0.1 in the LFS API URL ensures this URL
31 # is used when filling credentials rather than the Git remote URL, which
32 # would otherwise be used since it would have the same scheme and hostname.
33 gitserver="$(echo "$GITSERVER" | sed 's/127\.0\.0\.1/localhost/')"
34 testreponame="test%0a$reponame"
35 git config lfs.url "$gitserver/$testreponame.git/info/lfs"
36
37 # The refute_server_object() assertion below will fail unless its
38 # repository name parameter matches an extant "remote" directory.
39 pushd .
40 setup_remote_repo "$testreponame"
41 popd
42
43 GIT_TRACE=1 git lfs push origin main 2>&1 | tee push.log
44 if [ "0" -eq "${PIPESTATUS[0]}" ]; then
45 echo >&2 "fatal: expected 'git lfs push' to fail ..."
46 exit 1
47 fi
48 grep "batch response: Git credentials for $gitserver.* not found" push.log
49 grep "credential value for path contains newline" push.log
50 refute_server_object "$testreponame" "$contents_oid"
51
52 git config credential.protectProtocol false
53
54 GIT_TRACE=1 git lfs push origin main 2>&1 | tee push.log
55 if [ "0" -eq "${PIPESTATUS[0]}" ]; then
56 echo >&2 "fatal: expected 'git lfs push' to fail ..."
57 exit 1
58 fi
59 grep "batch response: Git credentials for $gitserver.* not found" push.log
60 grep "credential value for path contains newline" push.log
61 refute_server_object "$testreponame" "$contents_oid"
62 )
63 end_test
64
65 begin_test "credentials rejected with carriage return"
66 (
67 set -e
68
69 reponame="protect-return"
70 setup_remote_repo "$reponame"
71 clone_repo "$reponame" "$reponame"
72
73 contents="a"
74 contents_oid=$(calc_oid "$contents")
75
76 git lfs track "*.dat"
77 printf "%s" "$contents" >a.dat
78 git add .gitattributes a.dat
79 git commit -m "add a.dat"
80
81 # Using localhost instead of 127.0.0.1 in the LFS API URL ensures this URL
82 # is used when filling credentials rather than the Git remote URL, which
83 # would otherwise be used since it would have the same scheme and hostname.
84 gitserver="$(echo "$GITSERVER" | sed 's/127\.0\.0\.1/localhost/')"
85 testreponame="test%0d$reponame"
86 git config lfs.url "$gitserver/$testreponame.git/info/lfs"
87
88 # The refute_server_object() assertion below will fail unless its
89 # repository name parameter matches an extant "remote" directory.
90 pushd .
91 setup_remote_repo "$testreponame"
92 popd
93
94 GIT_TRACE=1 git lfs push origin main 2>&1 | tee push.log
95 if [ "0" -eq "${PIPESTATUS[0]}" ]; then
96 echo >&2 "fatal: expected 'git lfs push' to fail ..."
97 exit 1
98 fi
99 grep "batch response: Git credentials for $gitserver.* not found" push.log
100 grep "credential value for path contains carriage return" push.log
101 refute_server_object "$testreponame" "$contents_oid"
102
103 git config credential.protectProtocol false
104
105 git lfs push origin main 2>&1 | tee push.log
106 if [ "0" -ne "${PIPESTATUS[0]}" ]; then
107 echo >&2 "fatal: expected 'git lfs push' to succeed ..."
108 exit 1
109 fi
110 [ $(grep -c "Uploading LFS objects: 100% (1/1)" push.log) -eq 1 ]
111 assert_server_object "$testreponame" "$contents_oid"
112 )
113 end_test
114
115 begin_test "credentials rejected with null byte"
116 (
117 set -e
118
119 reponame="protect-null"
120 setup_remote_repo "$reponame"
121 clone_repo "$reponame" "$reponame"
122
123 contents="a"
124 contents_oid=$(calc_oid "$contents")
125
126 git lfs track "*.dat"
127 printf "%s" "$contents" >a.dat
128 git add .gitattributes a.dat
129 git commit -m "add a.dat"
130
131 # Using localhost instead of 127.0.0.1 in the LFS API URL ensures this URL
132 # is used when filling credentials rather than the Git remote URL, which
133 # would otherwise be used since it would have the same scheme and hostname.
134 gitserver="$(echo "$GITSERVER" | sed 's/127\.0\.0\.1/localhost/')"
135 testreponame="test%00$reponame"
136 git config lfs.url "$gitserver/$testreponame.git/info/lfs"
137
138 # The refute_server_object() assertion below will fail unless its
139 # repository name parameter matches an extant "remote" directory.
140 pushd .
141 setup_remote_repo "$testreponame"
142 popd
143
144 GIT_TRACE=1 git lfs push origin main 2>&1 | tee push.log
145 if [ "0" -eq "${PIPESTATUS[0]}" ]; then
146 echo >&2 "fatal: expected 'git lfs push' to fail ..."
147 exit 1
148 fi
149 grep "batch response: Git credentials for $gitserver.* not found" push.log
150 grep "credential value for path contains null byte" push.log
151 refute_server_object "$testreponame" "$contents_oid"
152
153 git config credential.protectProtocol false
154
155 GIT_TRACE=1 git lfs push origin main 2>&1 | tee push.log
156 if [ "0" -eq "${PIPESTATUS[0]}" ]; then
157 echo >&2 "fatal: expected 'git lfs push' to fail ..."
158 exit 1
159 fi
160 grep "batch response: Git credentials for $gitserver.* not found" push.log
161 grep "credential value for path contains null byte" push.log
162 refute_server_object "$testreponame" "$contents_oid"
163 )
164 end_test