From aaef0087061e080f3608e7dd543f7263126d2e12 Mon Sep 17 00:00:00 2001 From: Ying Li Date: Thu, 4 Feb 2016 17:14:00 -0800 Subject: [PATCH] Add test function to ensure that fixture expiry dates are all far far in the future. Signed-off-by: Ying Li --- client/backwards_compatibility_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/client/backwards_compatibility_test.go b/client/backwards_compatibility_test.go index c340bd811d..d78f313f96 100644 --- a/client/backwards_compatibility_test.go +++ b/client/backwards_compatibility_test.go @@ -10,6 +10,7 @@ import ( "path/filepath" "strings" "testing" + "time" "github.com/docker/notary/client/changelist" "github.com/docker/notary/passphrase" @@ -18,6 +19,22 @@ import ( "github.com/stretchr/testify/require" ) +// Once a fixture is read in, ensure that it's valid by making sure the expiry +// times of all the metadata and certificates is > 10 years ahead +func requireValidFixture(t *testing.T, notaryRepo *NotaryRepository) { + tenYearsInFuture := time.Now().AddDate(10, 0, 0) + require.True(t, notaryRepo.tufRepo.Root.Signed.Expires.After(tenYearsInFuture)) + require.True(t, notaryRepo.tufRepo.Snapshot.Signed.Expires.After(tenYearsInFuture)) + require.True(t, notaryRepo.tufRepo.Timestamp.Signed.Expires.After(tenYearsInFuture)) + for _, targetObj := range notaryRepo.tufRepo.Targets { + require.True(t, targetObj.Signed.Expires.After(tenYearsInFuture)) + } + + for _, cert := range notaryRepo.CertStore.GetCertificates() { + require.True(t, cert.NotAfter.After(tenYearsInFuture)) + } +} + // recursively copies the contents of one directory into another - ignores // symlinks func recursiveCopy(sourceDir, targetDir string) error { @@ -83,6 +100,9 @@ func Test0Dot1RepoFormat(t *testing.T) { require.Len(t, targets, 1) require.Equal(t, "LICENSE", targets[0].Name) + // ok, now that everything has been loaded, verify that the fixture is valid + requireValidFixture(t, repo) + // delete the timestamp metadata, since the server will ignore the uploaded // one and try to create a new one from scratch, which will be the wrong version require.NoError(t, repo.fileStore.RemoveMeta(data.CanonicalTimestampRole))