mirror of https://github.com/docker/docs.git
Add test function to ensure that fixture expiry dates are all far far in the future.
Signed-off-by: Ying Li <ying.li@docker.com>
This commit is contained in:
parent
85c2fbea6a
commit
aaef008706
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue