Skip to content

Commit

Permalink
fix unit test for cookie.Store
Browse files Browse the repository at this point in the history
  • Loading branch information
equinox0815 committed Dec 1, 2023
1 parent c708e19 commit cf9438b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion auth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (b *NullBackend) Authenticate(username, password string) error {
return fmt.Errorf("invalid username/password")
}

func NewBackend(conf *Config, prom *prometheus.Registry, infoLog, dbgLog *log.Logger) (Backend, error) {
func NewBackend(conf *Config, prom prometheus.Registerer, infoLog, dbgLog *log.Logger) (Backend, error) {
if infoLog == nil {
infoLog = log.New(io.Discard, "", 0)
}
Expand Down
4 changes: 2 additions & 2 deletions auth/backend_ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type LDAPBackend struct {
dbgLog *log.Logger
}

func NewLDAPBackend(conf *LDAPConfig, prom *prometheus.Registry, infoLog, dbgLog *log.Logger) (Backend, error) {
func NewLDAPBackend(conf *LDAPConfig, prom prometheus.Registerer, infoLog, dbgLog *log.Logger) (Backend, error) {
if conf.UserSearchBase == "" {
conf.UserSearchBase = conf.RootDN
}
Expand Down Expand Up @@ -88,7 +88,7 @@ func NewLDAPBackend(conf *LDAPConfig, prom *prometheus.Registry, infoLog, dbgLog
return b, nil
}

func (b *LDAPBackend) initPrometheus(prom *prometheus.Registry) error {
func (b *LDAPBackend) initPrometheus(prom prometheus.Registerer) error {
// TODO: implement this!
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions auth/backend_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type StaticBackend struct {
dbgLog *log.Logger
}

func NewStaticBackend(conf *StaticConfig, prom *prometheus.Registry, infoLog, dbgLog *log.Logger) (Backend, error) {
func NewStaticBackend(conf *StaticConfig, prom prometheus.Registerer, infoLog, dbgLog *log.Logger) (Backend, error) {
file, err := htpasswd.New(conf.HTPasswd, htpasswd.DefaultSystems, func(err error) {
dbgLog.Printf("static: found invalid line: %v", err)
})
Expand Down Expand Up @@ -88,7 +88,7 @@ func (b *StaticBackend) watchFileEventCB(event fsnotify.Event) {
b.dbgLog.Printf("static: htpasswd file successfully reloaded")
}

func (b *StaticBackend) initPrometheus(prom *prometheus.Registry) error {
func (b *StaticBackend) initPrometheus(prom prometheus.Registerer) error {
// TODO: implement this!
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions auth/backend_whawty.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type WhawtyAuthBackend struct {
dbgLog *log.Logger
}

func NewWhawtyAuthBackend(conf *WhawtyAuthConfig, prom *prometheus.Registry, infoLog, dbgLog *log.Logger) (Backend, error) {
func NewWhawtyAuthBackend(conf *WhawtyAuthConfig, prom prometheus.Registerer, infoLog, dbgLog *log.Logger) (Backend, error) {
s, err := store.NewDirFromConfig(conf.ConfigFile)
if err != nil {
infoLog.Printf("whawty-auth: failed to intialize store: %v", err)
Expand Down Expand Up @@ -198,7 +198,7 @@ func (b *WhawtyAuthBackend) watchFileEventCB(event fsnotify.Event) {
b.infoLog.Printf("whawty-auth: successfully reloaded from: %s (%d parameter-sets loaded)", event.Name, len(b.store.Params))
}

func (b *WhawtyAuthBackend) initPrometheus(prom *prometheus.Registry) error {
func (b *WhawtyAuthBackend) initPrometheus(prom prometheus.Registerer) error {
// TODO: implement this!
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions cookie/backend_bolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type BoltBackend struct {
db *bolt.DB
}

func NewBoltBackend(conf *BoltBackendConfig, prom *prometheus.Registry) (*BoltBackend, error) {
func NewBoltBackend(conf *BoltBackendConfig, prom prometheus.Registerer) (*BoltBackend, error) {
db, err := bolt.Open(conf.Path, 0600, &bolt.Options{Timeout: time.Second})
if err != nil {
if err == bolt.ErrTimeout {
Expand Down Expand Up @@ -86,7 +86,7 @@ func NewBoltBackend(conf *BoltBackendConfig, prom *prometheus.Registry) (*BoltBa
return b, nil
}

func (b *BoltBackend) initPrometheus(prom *prometheus.Registry) error {
func (b *BoltBackend) initPrometheus(prom prometheus.Registerer) error {
// TODO: implement this!
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions cookie/backend_in-memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type InMemoryBackend struct {
revoked map[ulid.ULID]SessionBase
}

func NewInMemoryBackend(conf *InMemoryBackendConfig, prom *prometheus.Registry) (*InMemoryBackend, error) {
func NewInMemoryBackend(conf *InMemoryBackendConfig, prom prometheus.Registerer) (*InMemoryBackend, error) {
m := &InMemoryBackend{}
m.sessions = make(map[string]InMemorySessionMap)
m.revoked = make(map[ulid.ULID]SessionBase)
Expand All @@ -66,7 +66,7 @@ func NewInMemoryBackend(conf *InMemoryBackendConfig, prom *prometheus.Registry)
return m, nil
}

func (b *InMemoryBackend) initPrometheus(prom *prometheus.Registry) error {
func (b *InMemoryBackend) initPrometheus(prom prometheus.Registerer) error {
// TODO: implement this!
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions cookie/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ type Store struct {
dbgLog *log.Logger
}

func NewStore(conf *Config, prom *prometheus.Registry, infoLog, dbgLog *log.Logger) (*Store, error) {
func NewStore(conf *Config, prom prometheus.Registerer, infoLog, dbgLog *log.Logger) (*Store, error) {
if infoLog == nil {
infoLog = log.New(io.Discard, "", 0)
}
Expand Down Expand Up @@ -336,7 +336,7 @@ func (st *Store) runSync(interval time.Duration, baseURL *url.URL, host string,
}
}

func (st *Store) initBackend(conf *Config, prom *prometheus.Registry) (err error) {
func (st *Store) initBackend(conf *Config, prom prometheus.Registerer) (err error) {
if conf.Backend.GCInterval <= time.Second {
st.infoLog.Printf("cookie-store: overriding invalid/unset GC interval to 5 minutes")
conf.Backend.GCInterval = 5 * time.Minute
Expand Down Expand Up @@ -386,7 +386,7 @@ func (st *Store) initBackend(conf *Config, prom *prometheus.Registry) (err error
return
}

func (st *Store) initPrometheus(prom *prometheus.Registry) error {
func (st *Store) initPrometheus(prom prometheus.Registerer) error {
// TODO: implement this!
return nil
}
Expand Down
32 changes: 16 additions & 16 deletions cookie/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestSessionListEmptyJson(t *testing.T) {

func TestNewStore(t *testing.T) {
conf := &Config{}
_, err := NewStore(conf, nil, nil)
_, err := NewStore(conf, nil, nil, nil)
if err == nil {
t.Fatal("initializing store from empty config should fail")
}
Expand All @@ -71,7 +71,7 @@ func TestNewStore(t *testing.T) {
conf.Keys = []SignerVerifierConfig{
SignerVerifierConfig{Name: "empty"},
}
_, err = NewStore(conf, nil, nil)
_, err = NewStore(conf, nil, nil, nil)
if err == nil {
t.Fatal("initializing store with bogus keys config should fail")
}
Expand All @@ -81,7 +81,7 @@ func TestNewStore(t *testing.T) {
conf.Keys = []SignerVerifierConfig{
SignerVerifierConfig{Name: "test", Ed25519: ed25519Conf},
}
_, err = NewStore(conf, nil, nil)
_, err = NewStore(conf, nil, nil, nil)
if err == nil {
t.Fatal("initializing store with corrupt keys config entries should fail")
}
Expand All @@ -90,7 +90,7 @@ func TestNewStore(t *testing.T) {
conf.Keys = []SignerVerifierConfig{
SignerVerifierConfig{Name: "test", Ed25519: ed25519Conf},
}
st, err := NewStore(conf, nil, nil)
st, err := NewStore(conf, nil, nil, nil)
if err != nil {
t.Fatal("unexpected error:", err)
}
Expand All @@ -109,7 +109,7 @@ func TestNewStore(t *testing.T) {
conf.Keys = []SignerVerifierConfig{
SignerVerifierConfig{Name: "test", Ed25519: ed25519Conf},
}
st, err = NewStore(conf, nil, nil)
st, err = NewStore(conf, nil, nil, nil)
if err != nil {
t.Fatal("unexpected error:", err)
}
Expand All @@ -118,7 +118,7 @@ func TestNewStore(t *testing.T) {
}

conf.Backend = StoreBackendConfig{}
_, err = NewStore(conf, nil, nil)
_, err = NewStore(conf, nil, nil, nil)
if err == nil {
t.Fatal("initializing store with empty backend config should fail")
}
Expand All @@ -135,7 +135,7 @@ func TestMultipleKeys(t *testing.T) {
SignerVerifierConfig{Name: "sign-and-verify", Ed25519: ed25519ConfSignAndVerify},
}
conf.Backend = StoreBackendConfig{InMemory: &InMemoryBackendConfig{}}
st, err := NewStore(conf, nil, nil)
st, err := NewStore(conf, nil, nil, nil)
if err != nil {
t.Fatal("unexpected error:", err)
}
Expand Down Expand Up @@ -163,17 +163,17 @@ func TestBackendSync(t *testing.T) {
}
conf.Backend = StoreBackendConfig{InMemory: &InMemoryBackendConfig{}}
conf.Backend.Sync = &StoreSyncConfig{BaseURL: ""}
_, err := NewStore(conf, nil, nil)
_, err := NewStore(conf, nil, nil, nil)
if err == nil {
t.Fatal("initializing store with empty sync base-url shoud fail")
}
conf.Backend.Sync = &StoreSyncConfig{BaseURL: "file:///not/a/http/url"}
_, err = NewStore(conf, nil, nil)
_, err = NewStore(conf, nil, nil, nil)
if err == nil {
t.Fatal("initializing store with non-http(s) sync base-url shoud fail")
}
conf.Backend.Sync = &StoreSyncConfig{BaseURL: "http://192.0.2.1"}
_, err = NewStore(conf, nil, nil)
_, err = NewStore(conf, nil, nil, nil)
if err != nil {
t.Fatal("unexpected error:", err)
}
Expand All @@ -185,7 +185,7 @@ func TestNew(t *testing.T) {
SignerVerifierConfig{Name: "verify-only", Ed25519: &Ed25519Config{PubKeyData: &testPubKeyEd25519Pem}},
}
conf.Backend = StoreBackendConfig{InMemory: &InMemoryBackendConfig{}}
st, err := NewStore(conf, nil, nil)
st, err := NewStore(conf, nil, nil, nil)
if err != nil {
t.Fatal("unexpected error:", err)
}
Expand All @@ -200,7 +200,7 @@ func TestNew(t *testing.T) {
conf.Keys = []SignerVerifierConfig{
SignerVerifierConfig{Name: "sign-and-verify", Ed25519: &Ed25519Config{PrivKeyData: &testPrivKeyEd25519Pem}},
}
st, err = NewStore(conf, nil, nil)
st, err = NewStore(conf, nil, nil, nil)
if err != nil {
t.Fatal("unexpected error:", err)
}
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestVerify(t *testing.T) {
SignerVerifierConfig{Name: "sign-and-verify", Ed25519: &Ed25519Config{PrivKeyData: &testPrivKeyEd25519Pem}},
}
conf.Backend = StoreBackendConfig{InMemory: &InMemoryBackendConfig{}}
st, err := NewStore(conf, nil, nil)
st, err := NewStore(conf, nil, nil, nil)
if err != nil {
t.Fatal("unexpected error:", err)
}
Expand Down Expand Up @@ -336,7 +336,7 @@ func TestNewThenVerifyMultipleKeys(t *testing.T) {
SignerVerifierConfig{Name: "sign-and-verify", Ed25519: &Ed25519Config{PrivKeyData: &testPrivKeyEd25519Pem}},
}
conf.Backend = StoreBackendConfig{InMemory: &InMemoryBackendConfig{}}
st, err := NewStore(conf, nil, nil)
st, err := NewStore(conf, nil, nil, nil)
if err != nil {
t.Fatal("unexpected error:", err)
}
Expand Down Expand Up @@ -390,7 +390,7 @@ func TestListUser(t *testing.T) {
SignerVerifierConfig{Name: "sign-and-verify", Ed25519: &Ed25519Config{PrivKeyData: &testPrivKeyEd25519Pem}},
}
conf.Backend = StoreBackendConfig{InMemory: &InMemoryBackendConfig{}}
st, err := NewStore(conf, nil, nil)
st, err := NewStore(conf, nil, nil, nil)
if err != nil {
t.Fatal("unexpected error:", err)
}
Expand Down Expand Up @@ -509,7 +509,7 @@ func TestListRevoked(t *testing.T) {
SignerVerifierConfig{Name: "sign-and-verify", Ed25519: &Ed25519Config{PrivKeyData: &testPrivKeyEd25519Pem}},
}
conf.Backend = StoreBackendConfig{InMemory: &InMemoryBackendConfig{}}
st, err := NewStore(conf, nil, nil)
st, err := NewStore(conf, nil, nil, nil)
if err != nil {
t.Fatal("unexpected error:", err)
}
Expand Down

0 comments on commit cf9438b

Please sign in to comment.