Fix integration test while running with MySQL
- Add SQL configuration options - Increase the width of the authz and pending_authz tables' challenges field - Make it configurable whether CREATE TABLE commands should run
This commit is contained in:
parent
f15da06af7
commit
343920cfe3
|
@ -39,16 +39,14 @@ func NewCertificateAuthorityDatabaseImpl(driver string, name string) (cadb core.
|
|||
db: db,
|
||||
log: logger,
|
||||
}
|
||||
|
||||
err = createTablesIfNotExist(db)
|
||||
return
|
||||
}
|
||||
|
||||
// createTablesIfNotExist builds the database tables and inserts the initial
|
||||
// state, if the tables do not already exist. It is not an error for the tables
|
||||
// to already exist.
|
||||
func createTablesIfNotExist(db *sql.DB) (err error) {
|
||||
tx, err := db.Begin()
|
||||
func (cadb *CertificateAuthorityDatabaseImpl) CreateTablesIfNotExists() (err error) {
|
||||
tx, err := cadb.db.Begin()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -35,6 +35,9 @@ func TestBeginCommit(t *testing.T) {
|
|||
cadb, err := NewCertificateAuthorityDatabaseImpl(sqliteDriver, sqliteName)
|
||||
test.AssertNotError(t, err, "Could not construct CA DB")
|
||||
|
||||
err = cadb.CreateTablesIfNotExists()
|
||||
test.AssertNotError(t, err, "Could not construct tables")
|
||||
|
||||
err = cadb.Begin()
|
||||
test.AssertNotError(t, err, "Could not begin")
|
||||
|
||||
|
@ -53,6 +56,9 @@ func TestGetSetSequenceOutsideTx(t *testing.T) {
|
|||
cadb, err := NewCertificateAuthorityDatabaseImpl(sqliteDriver, sqliteName)
|
||||
test.AssertNotError(t, err, "Could not construct CA DB")
|
||||
|
||||
err = cadb.CreateTablesIfNotExists()
|
||||
test.AssertNotError(t, err, "Could not construct tables")
|
||||
|
||||
_, err = cadb.IncrementAndGetSerial()
|
||||
test.AssertError(t, err, "Not permitted")
|
||||
}
|
||||
|
@ -61,6 +67,9 @@ func TestGetSetSequenceNumber(t *testing.T) {
|
|||
cadb, err := NewCertificateAuthorityDatabaseImpl(sqliteDriver, sqliteName)
|
||||
test.AssertNotError(t, err, "Could not construct CA DB")
|
||||
|
||||
err = cadb.CreateTablesIfNotExists()
|
||||
test.AssertNotError(t, err, "Could not construct tables")
|
||||
|
||||
err = cadb.Begin()
|
||||
test.AssertNotError(t, err, "Could not begin")
|
||||
|
||||
|
|
|
@ -322,11 +322,15 @@ func (cadb *MockCADatabase) IncrementAndGetSerial() (int, error) {
|
|||
return 1, nil
|
||||
}
|
||||
|
||||
func (cadb *MockCADatabase) CreateTablesIfNotExists() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func setup(t *testing.T) (cadb core.CertificateAuthorityDatabase, storageAuthority core.StorageAuthority, caConfig Config) {
|
||||
// Create an SA
|
||||
ssa, err := sa.NewSQLStorageAuthority("sqlite3", ":memory:")
|
||||
test.AssertNotError(t, err, "Failed to create SA")
|
||||
ssa.InitTables()
|
||||
ssa.CreateTablesIfNotExists()
|
||||
storageAuthority = ssa
|
||||
|
||||
cadb, _ = NewMockCertificateAuthorityDatabase()
|
||||
|
|
|
@ -36,6 +36,11 @@ func main() {
|
|||
cadb, err := ca.NewCertificateAuthorityDatabaseImpl(c.CA.DBDriver, c.CA.DBName)
|
||||
cmd.FailOnError(err, "Failed to create CA database")
|
||||
|
||||
if c.SQL.CreateTables {
|
||||
err = cadb.CreateTablesIfNotExists()
|
||||
cmd.FailOnError(err, "Failed to create CA tables")
|
||||
}
|
||||
|
||||
cai, err := ca.NewCertificateAuthorityImpl(cadb, c.CA)
|
||||
cmd.FailOnError(err, "Failed to create CA impl")
|
||||
|
||||
|
|
|
@ -35,7 +35,12 @@ func main() {
|
|||
|
||||
sai, err := sa.NewSQLStorageAuthority(c.SA.DBDriver, c.SA.DBName)
|
||||
cmd.FailOnError(err, "Failed to create SA impl")
|
||||
sai.SetSQLDebug(c.SA.SQLDebug)
|
||||
sai.SetSQLDebug(c.SQL.SQLDebug)
|
||||
|
||||
if c.SQL.CreateTables {
|
||||
err = sai.CreateTablesIfNotExists()
|
||||
cmd.FailOnError(err, "Failed to create tables")
|
||||
}
|
||||
|
||||
go cmd.ProfileCmd("SA", stats)
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ func main() {
|
|||
wfe := wfe.NewWebFrontEndImpl()
|
||||
sa, err := sa.NewSQLStorageAuthority(c.SA.DBDriver, c.SA.DBName)
|
||||
cmd.FailOnError(err, "Unable to create SA")
|
||||
sa.SetSQLDebug(c.SA.SQLDebug)
|
||||
sa.SetSQLDebug(c.SQL.SQLDebug)
|
||||
|
||||
ra := ra.NewRegistrationAuthorityImpl()
|
||||
va := va.NewValidationAuthorityImpl(c.CA.TestMode)
|
||||
|
@ -88,6 +88,14 @@ func main() {
|
|||
ca, err := ca.NewCertificateAuthorityImpl(cadb, c.CA)
|
||||
cmd.FailOnError(err, "Unable to create CA")
|
||||
|
||||
if c.SQL.CreateTables {
|
||||
err = sa.CreateTablesIfNotExists()
|
||||
cmd.FailOnError(err, "Failed to create SA tables")
|
||||
|
||||
err = cadb.CreateTablesIfNotExists()
|
||||
cmd.FailOnError(err, "Failed to create CA tables")
|
||||
}
|
||||
|
||||
// Wire them up
|
||||
wfe.RA = &ra
|
||||
wfe.SA = sa
|
||||
|
|
|
@ -67,7 +67,11 @@ type Config struct {
|
|||
SA struct {
|
||||
DBDriver string
|
||||
DBName string
|
||||
SQLDebug bool
|
||||
}
|
||||
|
||||
SQL struct {
|
||||
CreateTables bool
|
||||
SQLDebug bool
|
||||
}
|
||||
|
||||
Statsd struct {
|
||||
|
|
|
@ -119,9 +119,9 @@ type StorageAuthority interface {
|
|||
|
||||
// CertificateAuthorityDatabase represents an atomic sequence source
|
||||
type CertificateAuthorityDatabase interface {
|
||||
CreateTablesIfNotExists() error
|
||||
Begin() error
|
||||
Commit() error
|
||||
Rollback() error
|
||||
|
||||
IncrementAndGetSerial() (int, error)
|
||||
}
|
||||
|
|
|
@ -62,6 +62,10 @@ func (cadb *MockCADatabase) IncrementAndGetSerial() (int, error) {
|
|||
return 1, nil
|
||||
}
|
||||
|
||||
func (cadb *MockCADatabase) CreateTablesIfNotExists() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
// These values we simulate from the client
|
||||
AccountKeyJSON = []byte(`{
|
||||
|
@ -116,7 +120,7 @@ func initAuthorities(t *testing.T) (core.CertificateAuthority, *DummyValidationA
|
|||
|
||||
sa, err := sa.NewSQLStorageAuthority("sqlite3", ":memory:")
|
||||
test.AssertNotError(t, err, "Failed to create SA")
|
||||
sa.InitTables()
|
||||
sa.CreateTablesIfNotExists()
|
||||
|
||||
va := &DummyValidationAuthority{}
|
||||
|
||||
|
|
|
@ -185,11 +185,7 @@ func NewSQLStorageAuthority(driver string, name string) (ssa *SQLStorageAuthorit
|
|||
bucket: make(map[string]interface{}),
|
||||
}
|
||||
|
||||
err = ssa.InitTables()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
ssa.initTables()
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -203,19 +199,29 @@ func (ssa *SQLStorageAuthority) SetSQLDebug(state bool) {
|
|||
}
|
||||
}
|
||||
|
||||
func (ssa *SQLStorageAuthority) InitTables() (err error) {
|
||||
// initTables constructs the table map for the ORM. If you want to also create
|
||||
// the tables, call CreateTablesIfNotExists.
|
||||
func (ssa *SQLStorageAuthority) initTables() {
|
||||
regTable := ssa.dbMap.AddTableWithName(core.Registration{}, "registrations").SetKeys(true, "ID")
|
||||
regTable.SetVersionCol("LockCol")
|
||||
regTable.ColMap("Key").SetMaxSize(512).SetNotNull(true)
|
||||
|
||||
ssa.dbMap.AddTableWithName(pendingauthzModel{}, "pending_authz").SetKeys(false, "ID").SetVersionCol("LockCol")
|
||||
ssa.dbMap.AddTableWithName(authzModel{}, "authz").SetKeys(false, "ID")
|
||||
pendingAuthzTable := ssa.dbMap.AddTableWithName(pendingauthzModel{}, "pending_authz").SetKeys(false, "ID")
|
||||
pendingAuthzTable.SetVersionCol("LockCol")
|
||||
pendingAuthzTable.ColMap("Challenges").SetMaxSize(1536)
|
||||
|
||||
authzTable := ssa.dbMap.AddTableWithName(authzModel{}, "authz").SetKeys(false, "ID")
|
||||
authzTable.ColMap("Challenges").SetMaxSize(1536)
|
||||
|
||||
ssa.dbMap.AddTableWithName(core.Certificate{}, "certificates").SetKeys(false, "Serial")
|
||||
ssa.dbMap.AddTableWithName(core.CertificateStatus{}, "certificateStatus").SetKeys(false, "Serial").SetVersionCol("LockCol")
|
||||
ssa.dbMap.AddTableWithName(core.OcspResponse{}, "ocspResponses").SetKeys(true, "ID")
|
||||
ssa.dbMap.AddTableWithName(core.Crl{}, "crls").SetKeys(false, "Serial")
|
||||
ssa.dbMap.AddTableWithName(core.DeniedCsr{}, "deniedCsrs").SetKeys(true, "ID")
|
||||
}
|
||||
|
||||
// CreateTablesIfNotExists instructs the ORM to create any missing tables.
|
||||
func (ssa *SQLStorageAuthority) CreateTablesIfNotExists() (err error) {
|
||||
err = ssa.dbMap.CreateTablesIfNotExists()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ func initSA(t *testing.T) *SQLStorageAuthority {
|
|||
if err != nil {
|
||||
t.Fatalf("Failed to create SA")
|
||||
}
|
||||
if err = sa.InitTables(); err != nil {
|
||||
if err = sa.CreateTablesIfNotExists(); err != nil {
|
||||
t.Fatalf("Failed to create SA")
|
||||
}
|
||||
return sa
|
||||
|
|
|
@ -51,8 +51,12 @@
|
|||
|
||||
"sa": {
|
||||
"dbDriver": "sqlite3",
|
||||
"dbName": ":memory:",
|
||||
"SQLDebug": false
|
||||
"dbName": ":memory:"
|
||||
},
|
||||
|
||||
"sql": {
|
||||
"SQLDebug": true,
|
||||
"CreateTables": false
|
||||
},
|
||||
|
||||
"revoker": {
|
||||
|
|
|
@ -51,8 +51,12 @@
|
|||
|
||||
"sa": {
|
||||
"dbDriver": "sqlite3",
|
||||
"dbName": ":memory:",
|
||||
"SQLDebug": false
|
||||
"dbName": ":memory:"
|
||||
},
|
||||
|
||||
"sql": {
|
||||
"SQLDebug": false,
|
||||
"CreateTables": true
|
||||
},
|
||||
|
||||
"mail": {
|
||||
|
|
Loading…
Reference in New Issue