func TestDownloadTargetChecksumMismatch(t *testing.T) { repo, _, err := testutils.EmptyRepo("docker.com/notary") assert.NoError(t, err) localStorage := store.NewMemoryStore(nil) remoteStorage := testutils.NewCorruptingMemoryStore(nil) client := NewClient(repo, remoteStorage, localStorage) // create and "upload" sample targets signedOrig, err := repo.SignTargets("targets", data.DefaultExpires("targets")) assert.NoError(t, err) orig, err := json.Marshal(signedOrig) assert.NoError(t, err) origSha256 := sha256.Sum256(orig) err = remoteStorage.SetMeta("targets", orig) assert.NoError(t, err) // create local snapshot with targets file snap := data.SignedSnapshot{ Signed: data.Snapshot{ Meta: data.Files{ "targets": data.FileMeta{ Length: int64(len(orig)), Hashes: data.Hashes{ "sha256": origSha256[:], }, }, }, }, } repo.Snapshot = &snap err = client.downloadTargets("targets") assert.IsType(t, ErrChecksumMismatch{}, err) }
func TestChecksumMismatch(t *testing.T) { repo := tuf.NewRepo(nil) localStorage := store.NewMemoryStore(nil) remoteStorage := testutils.NewCorruptingMemoryStore(nil) client := NewClient(repo, remoteStorage, localStorage) sampleTargets := data.NewTargets() orig, err := json.Marshal(sampleTargets) origSha256 := sha256.Sum256(orig) assert.NoError(t, err) remoteStorage.SetMeta("targets", orig) _, _, err = client.downloadSigned("targets", int64(len(orig)), origSha256[:]) assert.IsType(t, ErrChecksumMismatch{}, err) }
func TestUpdateDownloadRootBadChecksum(t *testing.T) { remoteStore := testutils.NewCorruptingMemoryStore(nil) repo, _, err := testutils.EmptyRepo("docker.com/notary") assert.NoError(t, err) localStorage := store.NewMemoryStore(nil) client := NewClient(repo, remoteStore, localStorage) // sign and "upload" sample root signedOrig, err := repo.SignRoot(data.DefaultExpires("root")) assert.NoError(t, err) orig, err := json.Marshal(signedOrig) assert.NoError(t, err) err = remoteStore.SetMeta("root", orig) assert.NoError(t, err) // sign snapshot to make sure we have current checksum for root _, err = repo.SignSnapshot(data.DefaultExpires("snapshot")) assert.NoError(t, err) err = client.downloadRoot() assert.IsType(t, ErrChecksumMismatch{}, err) }