diff options
Diffstat (limited to 'swarm/api/manifest_test.go')
-rw-r--r-- | swarm/api/manifest_test.go | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/swarm/api/manifest_test.go b/swarm/api/manifest_test.go index 7098ca16f..d65f023f8 100644 --- a/swarm/api/manifest_test.go +++ b/swarm/api/manifest_test.go @@ -42,7 +42,9 @@ func manifest(paths ...string) (manifestReader storage.LazySectionReader) { func testGetEntry(t *testing.T, path, match string, multiple bool, paths ...string) *manifestTrie { quitC := make(chan bool) - trie, err := readManifest(manifest(paths...), nil, nil, quitC) + fileStore := storage.NewFileStore(nil, storage.NewFileStoreParams()) + ref := make([]byte, fileStore.HashSize()) + trie, err := readManifest(manifest(paths...), ref, fileStore, false, quitC) if err != nil { t.Errorf("unexpected error making manifest: %v", err) } @@ -97,7 +99,9 @@ func TestGetEntry(t *testing.T) { func TestExactMatch(t *testing.T) { quitC := make(chan bool) mf := manifest("shouldBeExactMatch.css", "shouldBeExactMatch.css.map") - trie, err := readManifest(mf, nil, nil, quitC) + fileStore := storage.NewFileStore(nil, storage.NewFileStoreParams()) + ref := make([]byte, fileStore.HashSize()) + trie, err := readManifest(mf, ref, fileStore, false, quitC) if err != nil { t.Errorf("unexpected error making manifest: %v", err) } @@ -128,7 +132,9 @@ func TestAddFileWithManifestPath(t *testing.T) { reader := &storage.LazyTestSectionReader{ SectionReader: io.NewSectionReader(bytes.NewReader(manifest), 0, int64(len(manifest))), } - trie, err := readManifest(reader, nil, nil, nil) + fileStore := storage.NewFileStore(nil, storage.NewFileStoreParams()) + ref := make([]byte, fileStore.HashSize()) + trie, err := readManifest(reader, ref, fileStore, false, nil) if err != nil { t.Fatal(err) } @@ -144,3 +150,26 @@ func TestAddFileWithManifestPath(t *testing.T) { checkEntry(t, "ac", "ac", false, trie) checkEntry(t, "a", "a", false, trie) } + +// TestReadManifestOverSizeLimit creates a manifest reader with data longer then +// manifestSizeLimit and checks if readManifest function will return the exact error +// message. +// The manifest data is not in json-encoded format, preventing possbile +// successful parsing attempts if limit check fails. +func TestReadManifestOverSizeLimit(t *testing.T) { + manifest := make([]byte, manifestSizeLimit+1) + reader := &storage.LazyTestSectionReader{ + SectionReader: io.NewSectionReader(bytes.NewReader(manifest), 0, int64(len(manifest))), + } + _, err := readManifest(reader, storage.Address{}, nil, false, nil) + if err == nil { + t.Fatal("got no error from readManifest") + } + // Error message is part of the http response body + // which justifies exact string validation. + got := err.Error() + want := fmt.Sprintf("Manifest size of %v bytes exceeds the %v byte limit", len(manifest), manifestSizeLimit) + if got != want { + t.Fatalf("got error mesage %q, expected %q", got, want) + } +} |