Exemplo n.º 1
0
// NewFileCachedNotaryRepository is a wrapper for NewNotaryRepository that initializes
// a file cache from the provided repository and local config information
func NewFileCachedNotaryRepository(baseDir, gun, baseURL string, rt http.RoundTripper,
	retriever notary.PassRetriever, trustPinning trustpinning.TrustPinConfig) (
	*NotaryRepository, error) {

	cache, err := store.NewFileStore(
		filepath.Join(baseDir, tufDir, filepath.FromSlash(gun), "metadata"),
		"json",
	)
	if err != nil {
		return nil, err
	}
	return NewNotaryRepository(baseDir, gun, baseURL, rt, cache, retriever, trustPinning)
}
// Ensures that the current client can download metadata that is published from notary 0.3 repos
func TestDownloading0Dot3RepoFormat(t *testing.T) {
	gun := "docker.com/notary0.3/tst"
	passwd := "randompass"

	metaCache, err := store.NewFileStore(
		filepath.Join("../fixtures/compatibility/notary0.3/tuf", filepath.FromSlash(gun), "metadata"),
		"json")
	require.NoError(t, err)

	ts := readOnlyServer(t, metaCache, http.StatusNotFound, gun)
	defer ts.Close()

	repoDir, err := ioutil.TempDir("", "notary-backwards-compat-test")
	require.NoError(t, err)
	defer os.RemoveAll(repoDir)

	repo, err := NewFileCachedNotaryRepository(repoDir, gun, ts.URL, http.DefaultTransport,
		passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{})
	require.NoError(t, err, "error creating repo: %s", err)

	err = repo.Update(true)
	require.NoError(t, err, "error updating repo: %s", err)
}