Commit 2853ac71 authored by bobbyrullo's avatar bobbyrullo

Merge pull request #215 from ericchiang/fix_panic

cmd, db: verify at least one secret is passed to --key-secrets
parents dddc4c12 49389c9b
...@@ -72,6 +72,10 @@ func main() { ...@@ -72,6 +72,10 @@ func main() {
log.Fatalf("Unable to use --admin-listen flag: %v", err) log.Fatalf("Unable to use --admin-listen flag: %v", err)
} }
if len(keySecrets.BytesSlice()) == 0 {
log.Fatalf("Must specify at least one key secret")
}
dbCfg := db.Config{ dbCfg := db.Config{
DSN: *dbURL, DSN: *dbURL,
MaxIdleConnections: 1, MaxIdleConnections: 1,
......
...@@ -135,6 +135,9 @@ func main() { ...@@ -135,6 +135,9 @@ func main() {
UsersFile: *users, UsersFile: *users,
} }
} else { } else {
if len(keySecrets.BytesSlice()) == 0 {
log.Fatalf("Must specify at least one key secret")
}
if *dbMaxIdleConns == 0 { if *dbMaxIdleConns == 0 {
log.Warning("Running with no limit on: database idle connections") log.Warning("Running with no limit on: database idle connections")
} }
......
...@@ -90,6 +90,9 @@ type privateKeySetBlob struct { ...@@ -90,6 +90,9 @@ type privateKeySetBlob struct {
} }
func NewPrivateKeySetRepo(dbm *gorp.DbMap, useOldFormat bool, secrets ...[]byte) (*PrivateKeySetRepo, error) { func NewPrivateKeySetRepo(dbm *gorp.DbMap, useOldFormat bool, secrets ...[]byte) (*PrivateKeySetRepo, error) {
if len(secrets) == 0 {
return nil, errors.New("must provide at least one key secret")
}
for i, secret := range secrets { for i, secret := range secrets {
if len(secret) != 32 { if len(secret) != 32 {
return nil, fmt.Errorf("key secret %d: expected 32-byte secret", i) return nil, fmt.Errorf("key secret %d: expected 32-byte secret", i)
......
...@@ -7,6 +7,10 @@ import ( ...@@ -7,6 +7,10 @@ import (
func TestNewPrivateKeySetRepoInvalidKey(t *testing.T) { func TestNewPrivateKeySetRepoInvalidKey(t *testing.T) {
_, err := NewPrivateKeySetRepo(nil, false, []byte("sharks")) _, err := NewPrivateKeySetRepo(nil, false, []byte("sharks"))
if err == nil { if err == nil {
t.Fatalf("Expected non-nil error") t.Errorf("Expected non-nil error for key secret that was not 32 bytes")
}
_, err = NewPrivateKeySetRepo(nil, false)
if err == nil {
t.Fatalf("Expected non-nil error when creating repo with no key secrets")
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment