Debian Codegraph @

t/t-batch-storage-corrupt.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 "batch storage HTTP download of corrupt object"
6 (
7 set -e
8
9 reponame="batch-storage-download-corrupt-http"
10 setup_remote_repo "$reponame"
11 clone_repo "$reponame" "$reponame"
12
13 gitscip-shell system . . git. lfs track "*.dat"
14 gitscip-shell system . . git. add .gitattributes
15 gitscip-shell system . . git. commit -m "initial commit"
16
17 initial_sha="$(gitscip-shell system . . git. rev-parse HEAD)"
18
19 # This content announces to the server that it should corrupt the
20 # contents of the object before returning it.
21 contents="storage-download-corrupt"
22 contents_oid="$(calc_oid "$contents")"
23 printfscip-shell system . . printf. "%s" "$contents" > a.dat
24
25 gitscip-shell system . . git. add a.dat
26 gitscip-shell system . . git. commit -m "add a.dat"
27
28 gitscip-shell system . . git. push origin main
29
30 assert_server_object "$reponame" "$contents_oid"
31
32 rmscip-shell system . . rm. -f a.dat
33 rmscip-shell system . . rm. -rf .git/lfs/objects
34
35 # We expect the server to corrupt the object's contents by inverting
36 # the case of each character.
37 inverted_contents_oid="$(calc_oid "$(invert_case "$contents")")"
38
39 GIT_TRACE=1 gitscip-shell system . . git. lfs pull 2>&1 | teescip-shell system . . tee. pull.log
40 [scip-shell system . . `[`. 0 -ne "${PIPESTATUS[0]}" ]
41
42 grepscip-shell system . . grep. "expected OID $contents_oid, got $inverted_contents_oid after ${#contents} bytes written" pull.log
43 grepscip-shell system . . grep. "Failed to fetch some objects" pull.log
44
45 refute_local_object "$contents_oid"
46 refute_local_object "$inverted_contents_oid"
47
48 expected="${contents_oid:0:10} - a.dat"
49 [scip-shell system . . `[`. "$expected" = "$(gitscip-shell system . . git. lfs ls-files)" ]
50
51 gitscip-shell system . . git. lfs fsck --objects 2>&1 | teescip-shell system . . tee. fsck.log
52 [scip-shell system . . `[`. 1 -eq "${PIPESTATUS[0]}" ]
53
54 grepscip-shell system . . grep. "objects: openError: a.dat ($contents_oid) could not be checked: .*" fsck.log
55
56 # Test again using "git pull", which should not advance HEAD after the
57 # smudge filter reports an error.
58 gitscip-shell system . . git. reset --hard HEAD^
59
60 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 gitscip-shell system . . git. pull origin main 2>&1 | teescip-shell system . . tee. pull.log
61 [scip-shell system . . `[`. 0 -ne "${PIPESTATUS[0]}" ]
62
63 grepscip-shell system . . grep. "expected OID $contents_oid, got $inverted_contents_oid after ${#contents} bytes written" pull.log
64 grepscip-shell system . . grep. "Smudge error: Error downloading a.dat ($contents_oid)" pull.log
65
66 refute_local_object "$contents_oid"
67 refute_local_object "$inverted_contents_oid"
68
69 [scip-shell system . . `[`. "$initial_sha" = "$(gitscip-shell system . . git. rev-parse HEAD)" ]
70
71 [scip-shell system . . `[`. -z "$(gitscip-shell system . . git. lfs ls-files)" ]
72
73 gitscip-shell system . . git. lfs fsck --objects 2>&1 | teescip-shell system . . tee. fsck.log
74 [scip-shell system . . `[`. 0 -eq "${PIPESTATUS[0]}" ]
75
76 grepscip-shell system . . grep. "Git LFS fsck OK" fsck.log
77 )
78 end_test
79
80 begin_test "batch storage SSH download of corrupt object"
81 (
82 set -e
83
84 setup_pure_ssh
85
86 reponame="batch-storage-download-corrupt-ssh"
87 setup_remote_repo "$reponame"
88 clone_repo "$reponame" "$reponame"
89
90 sshurl=$(ssh_remote "$reponame")
91 gitscip-shell system . . git. config lfs.url "$sshurl"
92
93 gitscip-shell system . . git. lfs track "*.dat"
94 gitscip-shell system . . git. add .gitattributes
95 gitscip-shell system . . git. commit -m "initial commit"
96
97 initial_sha="$(gitscip-shell system . . git. rev-parse HEAD)"
98
99 contents="storage-download-corrupt"
100 contents_oid="$(calc_oid "$contents")"
101 printfscip-shell system . . printf. "%s" "$contents" > a.dat
102
103 gitscip-shell system . . git. add a.dat
104 gitscip-shell system . . git. commit -m "add a.dat"
105
106 gitscip-shell system . . git. push origin main
107
108 assert_remote_object "$reponame" "$contents_oid" "${#contents}"
109
110 rmscip-shell system . . rm. -f a.dat
111 rmscip-shell system . . rm. -rf .git/lfs/objects
112
113 # We corrupt the object's contents in the remote repository by inverting
114 # the case of each character.
115 inverted_contents="$(invert_case "$contents")"
116 inverted_contents_oid="$(calc_oid "$inverted_contents")"
117
118 remote_path="$(canonical_path "$REMOTEDIR/$reponame.git")"
119 pushd "$remote_path"
120 printfscip-shell system . . printf. "%s" "$inverted_contents" >"$(local_object_path "$contents_oid")"
121 popd
122
123 GIT_TRACE=1 gitscip-shell system . . git. lfs pull 2>&1 | teescip-shell system . . tee. pull.log
124 [scip-shell system . . `[`. 0 -ne "${PIPESTATUS[0]}" ]
125
126 grepscip-shell system . . grep. "expected OID $contents_oid, got $inverted_contents_oid after ${#contents} bytes written" pull.log
127 grepscip-shell system . . grep. "Failed to fetch some objects" pull.log
128
129 refute_local_object "$contents_oid"
130 refute_local_object "$inverted_contents_oid"
131
132 expected="${contents_oid:0:10} - a.dat"
133 [scip-shell system . . `[`. "$expected" = "$(gitscip-shell system . . git. lfs ls-files)" ]
134
135 gitscip-shell system . . git. lfs fsck --objects 2>&1 | teescip-shell system . . tee. fsck.log
136 [scip-shell system . . `[`. 1 -eq "${PIPESTATUS[0]}" ]
137
138 grepscip-shell system . . grep. "objects: openError: a.dat ($contents_oid) could not be checked: .*" fsck.log
139
140 # Test again using "git pull", which should not advance HEAD after the
141 # smudge filter reports an error.
142 gitscip-shell system . . git. reset --hard HEAD^
143
144 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 gitscip-shell system . . git. pull origin main 2>&1 | teescip-shell system . . tee. pull.log
145 [scip-shell system . . `[`. 0 -ne "${PIPESTATUS[0]}" ]
146
147 grepscip-shell system . . grep. "expected OID $contents_oid, got $inverted_contents_oid after ${#contents} bytes written" pull.log
148 grepscip-shell system . . grep. "Smudge error: Error downloading a.dat ($contents_oid)" pull.log
149
150 refute_local_object "$contents_oid"
151 refute_local_object "$inverted_contents_oid"
152
153 [scip-shell system . . `[`. "$initial_sha" = "$(gitscip-shell system . . git. rev-parse HEAD)" ]
154
155 [scip-shell system . . `[`. -z "$(gitscip-shell system . . git. lfs ls-files)" ]
156
157 gitscip-shell system . . git. lfs fsck --objects 2>&1 | teescip-shell system . . tee. fsck.log
158 [scip-shell system . . `[`. 0 -eq "${PIPESTATUS[0]}" ]
159
160 grepscip-shell system . . grep. "Git LFS fsck OK" fsck.log
161 )
162 end_test
163
164 begin_test "batch storage custom adapter download of corrupt object"
165 (
166 set -e
167
168 # The "custom-transfer-" prefix indicates to the server to advertise
169 # support for custom transfers.
170 reponame="custom-transfer-batch-storage-download-corrupt"
171 setup_remote_repo "$reponame"
172 clone_repo "$reponame" "$reponame"
173
174 gitscip-shell system . . git. lfs track "*.dat"
175 gitscip-shell system . . git. add .gitattributes
176 gitscip-shell system . . git. commit -m "initial commit"
177
178 initial_sha="$(gitscip-shell system . . git. rev-parse HEAD)"
179
180 # This content announces to the server that it should corrupt the
181 # contents of the object before returning it.
182 contents="storage-download-corrupt"
183 contents_oid="$(calc_oid "$contents")"
184 printfscip-shell system . . printf. "%s" "$contents" > a.dat
185
186 gitscip-shell system . . git. add a.dat
187 gitscip-shell system . . git. commit -m "add a.dat"
188
189 gitscip-shell system . . git. config lfs.customTransfer.testcustom.path lfstest-customadapter
190
191 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
192 [scip-shell system . . `[`. 0 -eq "${PIPESTATUS[0]}" ]
193
194 grepscip-shell system . . grep. "tq: starting transfer adapter" push.log
195 grepscip-shell system . . grep. "xfer: started custom adapter process" push.log
196
197 assert_server_object "$reponame" "$contents_oid"
198
199 rmscip-shell system . . rm. -f a.dat
200 rmscip-shell system . . rm. -rf .git/lfs/objects
201
202 # We expect the server to corrupt the object's contents by inverting
203 # the case of each character.
204 inverted_contents_oid="$(calc_oid "$(invert_case "$contents")")"
205
206 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 gitscip-shell system . . git. lfs pull 2>&1 | teescip-shell system . . tee. pull.log
207 [scip-shell system . . `[`. 0 -ne "${PIPESTATUS[0]}" ]
208
209 grepscip-shell system . . grep. "tq: starting transfer adapter" pull.log
210 grepscip-shell system . . grep. "xfer: started custom adapter process" pull.log
211
212 grepscip-shell system . . grep. "downloaded file failed checks" pull.log
213 grepscip-shell system . . grep. "has an invalid hash $inverted_contents_oid, expected $contents_oid" pull.log
214 grepscip-shell system . . grep. "Failed to fetch some objects" pull.log
215
216 refute_local_object "$contents_oid"
217 refute_local_object "$inverted_contents_oid"
218
219 expected="${contents_oid:0:10} - a.dat"
220 [scip-shell system . . `[`. "$expected" = "$(gitscip-shell system . . git. lfs ls-files)" ]
221
222 gitscip-shell system . . git. lfs fsck --objects 2>&1 | teescip-shell system . . tee. fsck.log
223 [scip-shell system . . `[`. 1 -eq "${PIPESTATUS[0]}" ]
224
225 grepscip-shell system . . grep. "objects: openError: a.dat ($contents_oid) could not be checked: .*" fsck.log
226
227 # Test again using "git pull", which should not advance HEAD after the
228 # smudge filter reports an error.
229 gitscip-shell system . . git. reset --hard HEAD^
230
231 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 gitscip-shell system . . git. pull origin main 2>&1 | teescip-shell system . . tee. pull.log
232 [scip-shell system . . `[`. 0 -ne "${PIPESTATUS[0]}" ]
233
234 grepscip-shell system . . grep. "tq: starting transfer adapter" pull.log
235 grepscip-shell system . . grep. "xfer: started custom adapter process" pull.log
236
237 grepscip-shell system . . grep. "downloaded file failed checks" pull.log
238 grepscip-shell system . . grep. "has an invalid hash $inverted_contents_oid, expected $contents_oid" pull.log
239 grepscip-shell system . . grep. "Smudge error: Error downloading a.dat ($contents_oid)" pull.log
240
241 refute_local_object "$contents_oid"
242 refute_local_object "$inverted_contents_oid"
243
244 [scip-shell system . . `[`. "$initial_sha" = "$(gitscip-shell system . . git. rev-parse HEAD)" ]
245
246 [scip-shell system . . `[`. -z "$(gitscip-shell system . . git. lfs ls-files)" ]
247
248 gitscip-shell system . . git. lfs fsck --objects 2>&1 | teescip-shell system . . tee. fsck.log
249 [scip-shell system . . `[`. 0 -eq "${PIPESTATUS[0]}" ]
250
251 grepscip-shell system . . grep. "Git LFS fsck OK" fsck.log
252 )
253 end_test