From e2524224631fa032414dfa5abb547f882a7ffb10 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 7 Dec 2021 17:01:43 -0800 Subject: [PATCH] Test Invalid Chunk Store --- protocol/files/manifest_test.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/protocol/files/manifest_test.go b/protocol/files/manifest_test.go index 697073d..cb0608b 100644 --- a/protocol/files/manifest_test.go +++ b/protocol/files/manifest_test.go @@ -28,7 +28,7 @@ func TestManifest(t *testing.T) { t.Logf("%v", manifest) - // Try to tread the chunk + // Try to read the chunk _, err = manifest.GetChunkBytes(1) if err == nil { t.Fatalf("chunk fetch should have thrown an error") @@ -43,6 +43,11 @@ func TestManifest(t *testing.T) { t.Fatalf("chunk fetch error: %v", err) } + _, err = manifest.GetChunkBytes(0) + if err != nil { + t.Fatalf("chunk fetch error: %v", err) + } + json, _ := json.Marshal(manifest) t.Logf("%s", json) @@ -112,7 +117,21 @@ func TestManifestLarge(t *testing.T) { t.Fatalf("could not store chunk %v %v", i, err) } + + // Attempt to store the chunk in an invalid position... + _, err = cwtchPngOutManifest.StoreChunk(uint64(i+1), contents) + if err == nil { + t.Fatalf("incorrect chunk store") + } + } + + // Attempt to store an invalid chunk...should trigger an error + _, err = cwtchPngOutManifest.StoreChunk(uint64(len(cwtchPngManifest.Chunks)), []byte{0xff}) + if err == nil { + t.Fatalf("incorrect chunk store") + } + err = cwtchPngOutManifest.VerifyFile() if err != nil { t.Fatalf("could not verify file %v", err)