From dc59fc9f7bc9cae4721201519363b5784bed8f3c Mon Sep 17 00:00:00 2001 From: Umputun Date: Wed, 12 Sep 2018 00:34:36 -0500 Subject: [PATCH] adjust test for key store --- backend/app/cmd/server.go | 2 +- backend/app/cmd/server_test.go | 2 +- backend/app/rest/api/migrator_test.go | 2 +- backend/app/rest/api/rest_test.go | 2 +- backend/app/rest/auth/auth.go | 6 +++--- backend/app/rest/auth/auth_test.go | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/app/cmd/server.go b/backend/app/cmd/server.go index bc1a34ac..4f868e8d 100644 --- a/backend/app/cmd/server.go +++ b/backend/app/cmd/server.go @@ -225,7 +225,7 @@ func (s *ServerCommand) newServerApp() (*serverApp, error) { SharedSecret: s.SharedSecret, Authenticator: auth.Authenticator{ JWTService: jwtService, - AdminStore: adminStore, + KeyStore: adminStore, Providers: authProviders, DevPasswd: s.DevPasswd, PermissionChecker: dataService, diff --git a/backend/app/cmd/server_test.go b/backend/app/cmd/server_test.go index 67eddf62..dacaf21f 100644 --- a/backend/app/cmd/server_test.go +++ b/backend/app/cmd/server_test.go @@ -45,7 +45,7 @@ func TestServerApp(t *testing.T) { body, _ = ioutil.ReadAll(resp.Body) t.Log(string(body)) - assert.Equal(t, "admin@demo.remark42.com", app.restSrv.Authenticator.AdminStore.Email(""), "default admin email") + assert.Equal(t, "admin@demo.remark42.com", app.dataService.AdminStore.Email(""), "default admin email") app.Wait() } diff --git a/backend/app/rest/api/migrator_test.go b/backend/app/rest/api/migrator_test.go index 6771d37a..c192bd94 100644 --- a/backend/app/rest/api/migrator_test.go +++ b/backend/app/rest/api/migrator_test.go @@ -165,7 +165,7 @@ func prepImportSrv(t *testing.T) (svc *Migrator, ds *service.DataStore, ts *http a := auth.Authenticator{ DevPasswd: "password", Providers: nil, - AdminStore: adminStore, + KeyStore: adminStore, JWTService: auth.NewJWT(adminStore, false, time.Minute, time.Hour), } routes := svc.withRoutes(chi.NewRouter().With(a.Auth(true)).With(a.AdminOnly)) diff --git a/backend/app/rest/api/rest_test.go b/backend/app/rest/api/rest_test.go index 666caed5..8717b50e 100644 --- a/backend/app/rest/api/rest_test.go +++ b/backend/app/rest/api/rest_test.go @@ -104,7 +104,7 @@ func prep(t *testing.T) (srv *Rest, ts *httptest.Server) { Authenticator: auth.Authenticator{ DevPasswd: "password", Providers: nil, - AdminStore: adminStore, + KeyStore: adminStore, JWTService: auth.NewJWT(adminStore, false, time.Minute, time.Hour), }, Cache: &cache.Nop{}, diff --git a/backend/app/rest/auth/auth.go b/backend/app/rest/auth/auth.go index 98cbc72f..61b0e35c 100644 --- a/backend/app/rest/auth/auth.go +++ b/backend/app/rest/auth/auth.go @@ -15,7 +15,7 @@ import ( type Authenticator struct { JWTService *JWT Providers []Provider - KeysStore KeyStore + KeyStore KeyStore DevPasswd string PermissionChecker PermissionChecker } @@ -116,14 +116,14 @@ func (a *Authenticator) Auth(reqAuth bool) func(http.Handler) http.Handler { } func (a *Authenticator) checkSecretKey(r *http.Request) bool { - if a.KeysStore == nil { + if a.KeyStore == nil { return false } siteID := r.URL.Query().Get("site") secret := r.URL.Query().Get("secret") - skey, err := a.KeysStore.Key(siteID) + skey, err := a.KeyStore.Key(siteID) if err != nil { return false } diff --git a/backend/app/rest/auth/auth_test.go b/backend/app/rest/auth/auth_test.go index 5350bc10..7b901835 100644 --- a/backend/app/rest/auth/auth_test.go +++ b/backend/app/rest/auth/auth_test.go @@ -223,7 +223,7 @@ func TestAdminRequired(t *testing.T) { } func TestAuthWithSecret(t *testing.T) { - a := Authenticator{DevPasswd: "123456", KeysStore: admin.NewStaticKeyStore("secretkey")} + a := Authenticator{DevPasswd: "123456", KeyStore: admin.NewStaticKeyStore("secretkey")} router := chi.NewRouter() router.With(a.Auth(true), a.AdminOnly).Get("/auth", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(201)