Debian Codegraph @

t/t-credentials-protect.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 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 cpscip-shell system . . 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 gitscip-shell system . . git. lfs track "*.dat"
26 printfscip-shell system . . printf. "%s" "$contents" >a.dat
27 gitscip-shell system . . git. add .gitattributes a.dat
28 gitscip-shell system . . 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="$(echoscip-shell system . . echo. "$GITSERVER" | sedscip-shell system . . sed. 's/127\.0\.0\.1/localhost/')"
34 testreponame="test%0a$reponame"
35 gitscip-shell system . . 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 gitscip-shell system . . git. lfs push origin main 2>&1 | teescip-shell system . . tee. push.log
44 if [scip-shell system . . `[`. "0" -eq "${PIPESTATUS[0]}" ]; then
45 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs push' to fail ..."
46 exit 1
47 fi
48 grepscip-shell system . . grep. "batch response: Git credentials for $gitserver.* not found" push.log
49 grepscip-shell system . . grep. "credential value for path contains newline" push.log
50 refute_server_object "$testreponame" "$contents_oid"
51
52 gitscip-shell system . . git. config credential.protectProtocol false
53
54 GIT_TRACE=1 gitscip-shell system . . git. lfs push origin main 2>&1 | teescip-shell system . . tee. push.log
55 if [scip-shell system . . `[`. "0" -eq "${PIPESTATUS[0]}" ]; then
56 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs push' to fail ..."
57 exit 1
58 fi
59 grepscip-shell system . . grep. "batch response: Git credentials for $gitserver.* not found" push.log
60 grepscip-shell system . . 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 gitscip-shell system . . git. lfs track "*.dat"
77 printfscip-shell system . . printf. "%s" "$contents" >a.dat
78 gitscip-shell system . . git. add .gitattributes a.dat
79 gitscip-shell system . . 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="$(echoscip-shell system . . echo. "$GITSERVER" | sedscip-shell system . . sed. 's/127\.0\.0\.1/localhost/')"
85 testreponame="test%0d$reponame"
86 gitscip-shell system . . 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 gitscip-shell system . . git. lfs push origin main 2>&1 | teescip-shell system . . tee. push.log
95 if [scip-shell system . . `[`. "0" -eq "${PIPESTATUS[0]}" ]; then
96 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs push' to fail ..."
97 exit 1
98 fi
99 grepscip-shell system . . grep. "batch response: Git credentials for $gitserver.* not found" push.log
100 grepscip-shell system . . grep. "credential value for path contains carriage return" push.log
101 refute_server_object "$testreponame" "$contents_oid"
102
103 gitscip-shell system . . git. config credential.protectProtocol false
104
105 gitscip-shell system . . git. lfs push origin main 2>&1 | teescip-shell system . . tee. push.log
106 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
107 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs push' to succeed ..."
108 exit 1
109 fi
110 [scip-shell system . . `[`. $(grepscip-shell system . . 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 gitscip-shell system . . git. lfs track "*.dat"
127 printfscip-shell system . . printf. "%s" "$contents" >a.dat
128 gitscip-shell system . . git. add .gitattributes a.dat
129 gitscip-shell system . . 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="$(echoscip-shell system . . echo. "$GITSERVER" | sedscip-shell system . . sed. 's/127\.0\.0\.1/localhost/')"
135 testreponame="test%00$reponame"
136 gitscip-shell system . . 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 gitscip-shell system . . git. lfs push origin main 2>&1 | teescip-shell system . . tee. push.log
145 if [scip-shell system . . `[`. "0" -eq "${PIPESTATUS[0]}" ]; then
146 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs push' to fail ..."
147 exit 1
148 fi
149 grepscip-shell system . . grep. "batch response: Git credentials for $gitserver.* not found" push.log
150 grepscip-shell system . . grep. "credential value for path contains null byte" push.log
151 refute_server_object "$testreponame" "$contents_oid"
152
153 gitscip-shell system . . git. config credential.protectProtocol false
154
155 GIT_TRACE=1 gitscip-shell system . . git. lfs push origin main 2>&1 | teescip-shell system . . tee. push.log
156 if [scip-shell system . . `[`. "0" -eq "${PIPESTATUS[0]}" ]; then
157 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs push' to fail ..."
158 exit 1
159 fi
160 grepscip-shell system . . grep. "batch response: Git credentials for $gitserver.* not found" push.log
161 grepscip-shell system . . grep. "credential value for path contains null byte" push.log
162 refute_server_object "$testreponame" "$contents_oid"
163 )
164 end_test