Skip to content

Commit d9b9f8a

Browse files
derrickstoleegitster
authored andcommitted
commit-graph: verify catches corrupt signature
This is the first of several commits that add a test to check that 'git commit-graph verify' catches corruption in the commit-graph file. The first test checks that the command catches an error in the file signature. This is a check that exists in the existing commit-graph reading code. Add a helper method 'corrupt_graph_and_verify' to the test script t5318-commit-graph.sh. This helper corrupts the commit-graph file at a certain location, runs 'git commit-graph verify', and reports the output to the 'err' file. This data is filtered to remove the lines added by 'test_must_fail' when the test is run verbosely. Then, the output is checked to contain a specific error message. Most messages from 'git commit-graph verify' will not be marked for translation. There will be one exception: the message that reports an invalid checksum will be marked for translation, as that is the only message that is intended for a typical user. Helped-by: Szeder Gábor <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 283e68c commit d9b9f8a

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

t/t5318-commit-graph.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,52 @@ test_expect_success 'perform fast-forward merge in full repo' '
235235
test_cmp expect output
236236
'
237237

238+
# the verify tests below expect the commit-graph to contain
239+
# exactly the commits reachable from the commits/8 branch.
240+
# If the file changes the set of commits in the list, then the
241+
# offsets into the binary file will result in different edits
242+
# and the tests will likely break.
243+
238244
test_expect_success 'git commit-graph verify' '
239245
cd "$TRASH_DIRECTORY/full" &&
246+
git rev-parse commits/8 | git commit-graph write --stdin-commits &&
240247
git commit-graph verify >output
241248
'
242249

250+
GRAPH_BYTE_VERSION=4
251+
GRAPH_BYTE_HASH=5
252+
253+
# usage: corrupt_graph_and_verify <position> <data> <string>
254+
# Manipulates the commit-graph file at the position
255+
# by inserting the data, then runs 'git commit-graph verify'
256+
# and places the output in the file 'err'. Test 'err' for
257+
# the given string.
258+
corrupt_graph_and_verify() {
259+
pos=$1
260+
data="${2:-\0}"
261+
grepstr=$3
262+
cd "$TRASH_DIRECTORY/full" &&
263+
test_when_finished mv commit-graph-backup $objdir/info/commit-graph &&
264+
cp $objdir/info/commit-graph commit-graph-backup &&
265+
printf "$data" | dd of="$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc &&
266+
test_must_fail git commit-graph verify 2>test_err &&
267+
grep -v "^+" test_err >err
268+
test_i18ngrep "$grepstr" err
269+
}
270+
271+
test_expect_success 'detect bad signature' '
272+
corrupt_graph_and_verify 0 "\0" \
273+
"graph signature"
274+
'
275+
276+
test_expect_success 'detect bad version' '
277+
corrupt_graph_and_verify $GRAPH_BYTE_VERSION "\02" \
278+
"graph version"
279+
'
280+
281+
test_expect_success 'detect bad hash version' '
282+
corrupt_graph_and_verify $GRAPH_BYTE_HASH "\02" \
283+
"hash version"
284+
'
285+
243286
test_done

0 commit comments

Comments
 (0)