adjust test for key store
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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{},
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user