1
0
mirror of https://github.com/docker/docs.git synced 2026-10-31 10:34:26 +03:00

make notary-signer tests work and add test for signer bootstrap

Signed-off-by: David Lawrence <david.lawrence@docker.com> (github: endophage)
This commit is contained in:
David Lawrence
2016-04-11 13:19:06 -07:00
committed by Riyaz Faizullabhoy
parent 5d8bcee97b
commit 92c17b754c
8 changed files with 62 additions and 17 deletions

View File

@@ -0,0 +1,24 @@
package main
import (
"testing"
"github.com/docker/notary/tuf/testutils"
"github.com/stretchr/testify/require"
"golang.org/x/net/context"
)
func TestBootstrap(t *testing.T) {
ctx := context.Background()
err := bootstrap(ctx)
require.Error(t, err)
ctx = context.WithValue(ctx, "metaStore", 1)
err = bootstrap(ctx)
require.Error(t, err)
require.Contains(t, err.Error(), "does not support bootstrapping")
bs := &testutils.TestBootstrapper{}
ctx = context.WithValue(ctx, "metaStore", bs)
err = bootstrap(ctx)
require.NoError(t, err)
require.True(t, bs.Booted)
}

View File

@@ -80,9 +80,8 @@ func getStore(configuration *viper.Viper, hRegister healthRegister) (
if err != nil {
return nil, err
}
var s *storage.SQLStorage
s, err = storage.NewSQLStorage(storeConfig.Backend, storeConfig.Source)
store = *storage.NewTufMetaStorage(s)
s, err := storage.NewSQLStorage(storeConfig.Backend, storeConfig.Source)
store = *storage.NewTUFMetaStorage(s)
hRegister("DB operational", s.CheckHealth, time.Second*60)
case notary.RethinkDBBackend:
var sess *gorethink.Session
@@ -93,7 +92,7 @@ func getStore(configuration *viper.Viper, hRegister healthRegister) (
sess, err = rethinkdb.Connection(storeConfig.CA, storeConfig.Source)
if err == nil {
s := storage.NewRethinkDBStorage(storeConfig.DBName, sess)
store = *storage.NewTufMetaStorage(s)
store = *storage.NewTUFMetaStorage(s)
hRegister("DB operational", s.CheckHealth, time.Second*60)
}
default:

View File

@@ -330,7 +330,7 @@ func TestGetStoreDBStore(t *testing.T) {
store, err := getStore(configure(config), fakeRegister)
require.NoError(t, err)
_, ok := store.(storage.TufMetaStorage)
_, ok := store.(storage.TUFMetaStorage)
require.True(t, ok)
// health function registered

View File

@@ -284,7 +284,7 @@ func debugServer(addr string) {
}
}
func bootstrap(s trustmanager.KeyStore) error {
func bootstrap(s interface{}) error {
store, ok := s.(storage.Bootstrapper)
if !ok {
return fmt.Errorf("Store does not support bootstrapping.")

View File

@@ -11,7 +11,9 @@ import (
"github.com/docker/notary"
"github.com/docker/notary/signer"
"github.com/docker/notary/signer/keydbstore"
"github.com/docker/notary/trustmanager"
"github.com/docker/notary/tuf/data"
"github.com/docker/notary/tuf/testutils"
"github.com/jinzhu/gorm"
_ "github.com/mattn/go-sqlite3"
"github.com/spf13/viper"
@@ -168,7 +170,7 @@ func TestSetupCryptoServicesMemoryStore(t *testing.T) {
cryptoServices, err := setUpCryptoservices(config,
[]string{notary.SQLiteBackend, notary.MemoryBackend})
require.NoError(t, err)
assert.Len(t, cryptoServices, 2)
require.Len(t, cryptoServices, 2)
edService, ok := cryptoServices[data.ED25519Key]
require.True(t, ok)
@@ -209,3 +211,13 @@ func TestSetupGRPCServerSuccess(t *testing.T) {
require.Equal(t, "tcp", lis.Addr().Network())
require.NotNil(t, grpcServer)
}
func TestBootstrap(t *testing.T) {
var ks trustmanager.KeyStore
err := bootstrap(ks)
require.Error(t, err)
tb := &testutils.TestBootstrapper{}
err = bootstrap(tb)
require.NoError(t, err)
require.True(t, tb.Booted)
}

View File

@@ -11,17 +11,17 @@ import (
"github.com/docker/notary/tuf/data"
)
// TufMetaStorage wraps a MetaStore in order to walk the TUF tree for GetCurrent in a consistent manner,
// TUFMetaStorage wraps a MetaStore in order to walk the TUF tree for GetCurrent in a consistent manner,
// by always starting from a current timestamp and then looking up other data by hash
type TufMetaStorage struct {
type TUFMetaStorage struct {
MetaStore
// cached metadata by checksum
cachedMeta map[string]*storedMeta
}
// NewTufMetaStorage instantiates a TufMetaStorage instance
func NewTufMetaStorage(m MetaStore) *TufMetaStorage {
return &TufMetaStorage{
// NewTUFMetaStorage instantiates a TUFMetaStorage instance
func NewTUFMetaStorage(m MetaStore) *TUFMetaStorage {
return &TUFMetaStorage{
MetaStore: m,
cachedMeta: make(map[string]*storedMeta),
}
@@ -33,7 +33,7 @@ type storedMeta struct {
}
// GetCurrent gets a specific TUF record, by walking from the current Timestamp to other metadata by checksum
func (tms TufMetaStorage) GetCurrent(gun, tufRole string) (*time.Time, []byte, error) {
func (tms TUFMetaStorage) GetCurrent(gun, tufRole string) (*time.Time, []byte, error) {
timestampTime, timestampJSON, err := tms.MetaStore.GetCurrent(gun, data.CanonicalTimestampRole)
if err != nil {
return nil, nil, err
@@ -107,7 +107,7 @@ func (tms TufMetaStorage) GetCurrent(gun, tufRole string) (*time.Time, []byte, e
}
// Bootstrap the store with tables if possible
func (tms TufMetaStorage) Bootstrap() error {
func (tms TUFMetaStorage) Bootstrap() error {
if s, ok := tms.MetaStore.(storage.Bootstrapper); ok {
return s.Bootstrap()
}

View File

@@ -13,12 +13,12 @@ import (
"github.com/stretchr/testify/require"
)
// SetupTUFSQLite creates a sqlite database for testing, wrapped by a TufMetaStorage
func SetupTUFSQLite(t *testing.T, dbDir string) (*gorm.DB, *TufMetaStorage) {
// SetupTUFSQLite creates a sqlite database for testing, wrapped by a TUFMetaStorage
func SetupTUFSQLite(t *testing.T, dbDir string) (*gorm.DB, *TUFMetaStorage) {
dbStore, err := NewSQLStorage("sqlite3", dbDir+"test_db")
require.NoError(t, err)
consistentDBStore := NewTufMetaStorage(dbStore)
consistentDBStore := NewTUFMetaStorage(dbStore)
embeddedDB := dbStore.DB
// Create the DB tables

View File

@@ -0,0 +1,10 @@
package testutils
type TestBootstrapper struct {
Booted bool
}
func (tb *TestBootstrapper) Bootstrap() error {
tb.Booted = true
return nil
}