Skip to content

Commit

Permalink
t7599: create corrupt blob test
Browse files Browse the repository at this point in the history
Teach helper/test-gvfs-protocol to be able to send corrupted
loose blobs.

Add unit test for gvfs-helper to detect receipt of a corrupted loose blob.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
  • Loading branch information
jeffhostetler authored and dscho committed Dec 24, 2020
1 parent 66aa561 commit fcb9b4f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
17 changes: 17 additions & 0 deletions t/helper/test-gvfs-protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ static enum worker_result send_loose_object(const struct object_id *oid,
unsigned long size;
enum object_type type;
struct object_info oi = OBJECT_INFO_INIT;
int mayhem__corrupt_loose = string_list_has_string(&mayhem_list,
"corrupt_loose");

/*
* Since `test-gvfs-protocol` is mocking a real GVFS server (cache or
Expand Down Expand Up @@ -623,7 +625,22 @@ static enum worker_result send_loose_object(const struct object_id *oid,
do {
enum worker_result wr;
unsigned char *in0 = stream.next_in;

/*
* Corrupt a byte in the buffer we compress, but undo it
* before we compute the SHA on the portion of the raw
* buffer included in the chunk we compressed.
*/
if (mayhem__corrupt_loose) {
logmayhem("corrupt_loose");
*in0 = *in0 ^ 0xff;
}

ret = git_deflate(&stream, Z_FINISH);

if (mayhem__corrupt_loose)
*in0 = *in0 ^ 0xff;

the_hash_algo->update_fn(&c, in0, stream.next_in - in0);

/* [5] */
Expand Down
32 changes: 32 additions & 0 deletions t/t5799-gvfs-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1288,4 +1288,36 @@ test_expect_success 'duplicate and busy: vfs- packfile' '
stop_gvfs_protocol_server
'

#################################################################
# Ensure that the SHA of the blob we received matches the SHA of
# the blob we requested.
#################################################################

# Request a loose blob from the server. Verify that we received
# content matches the requested SHA.
#
test_expect_success 'catch corrupted loose object' '
# test_when_finished "per_test_cleanup" &&
start_gvfs_protocol_server_with_mayhem corrupt_loose &&
test_must_fail \
git -C "$REPO_T1" gvfs-helper \
--cache-server=trust \
--remote=origin \
get \
<"$OID_ONE_BLOB_FILE" >OUT.output 2>OUT.stderr &&
stop_gvfs_protocol_server &&
# Verify corruption detected.
# Verify valid blob not included in response to client.
grep "hash failed for received loose object" OUT.stderr &&
# Verify that we did not write the corrupted blob to the ODB.
! verify_objects_in_shared_cache "$OID_ONE_BLOB_FILE" &&
git -C "$REPO_T1" fsck
'

test_done

0 comments on commit fcb9b4f

Please sign in to comment.