diff --git a/README.md b/README.md index 33680ea..84cf01a 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,6 @@ middlewares: kuzzle: url: "http://localhost:7512" # required routes: # optional - ping: /_publicApi login: /_login/local getCurrentUser: /_me # With Kuzzle v1 you must use '/users/_me' allowedUsers: # optional @@ -127,7 +126,6 @@ middlewares: allowedUsers = ["admin", "developer"] # optional [middlewares.your-well-named-middleware.plugin.traefik-kuzzle-auth.kuzzle.routes] # optional - ping = "/_publicApi" login = "/_login/local" getCurrentUser = "/_me" # With Kuzzle v1 you must use '/users/_me' @@ -138,7 +136,6 @@ middlewares: labels: - "traefik.http.middlewares.your-well-named-middleware.plugin.traefik-kuzzle-auth.customRealm=Use a valid Kuzzle user to authenticate" # optional - "traefik.http.middlewares.your-well-named-middleware.plugin.traefik-kuzzle-auth.kuzzle.url=http://kuzzle:7512" # required - - "traefik.http.middlewares.your-well-named-middleware.plugin.traefik-kuzzle-auth.kuzzle.routes.ping=/_publicApi" # optional - "traefik.http.middlewares.your-well-named-middleware.plugin.traefik-kuzzle-auth.kuzzle.routes.login=/_login/local" # optional - "traefik.http.middlewares.your-well-named-middleware.plugin.traefik-kuzzle-auth.kuzzle.routes.getCurrentUser=/_me" # With Kuzzle v1 you must use '/users/_me' (optional) - "traefik.http.middlewares.kuzzle-auth.plugin.traefik-kuzzle-auth.kuzzle.allowedUsers=admin,developer" # optional diff --git a/config.go b/config.go index d8d1024..1e711c6 100644 --- a/config.go +++ b/config.go @@ -17,10 +17,6 @@ func (c *Config) addMissingFields() *Config { c.CustomRealm = "Use a valid Kuzzle user to authenticate" } - if c.Kuzzle.Routes.Ping == "" { - c.Kuzzle.Routes.Ping = "/_publicApi" - } - if c.Kuzzle.Routes.Login == "" { c.Kuzzle.Routes.Login = "/_login/local" } diff --git a/config_test.go b/config_test.go index 64979d0..ad4252b 100644 --- a/config_test.go +++ b/config_test.go @@ -21,7 +21,6 @@ func TestConfig_addMissingFields(t *testing.T) { Kuzzle: Kuzzle{ URL: "http://kuzzle:7512", Routes: Routes{ - Ping: "/_publicApi", Login: "/_login/local", GetCurrentUser: "/_me", }, @@ -33,7 +32,6 @@ func TestConfig_addMissingFields(t *testing.T) { Kuzzle: Kuzzle{ URL: "http://kuzzle:7512", Routes: Routes{ - Ping: "/_publicApi", Login: "/_login/local", GetCurrentUser: "/_me", }, @@ -54,7 +52,6 @@ func TestConfig_addMissingFields(t *testing.T) { Kuzzle: Kuzzle{ URL: "http://kuzzle:7512", Routes: Routes{ - Ping: "/_publicApi", Login: "/_login/local", GetCurrentUser: "/_me", }, diff --git a/kuzzle.go b/kuzzle.go index e9ea132..a09c533 100644 --- a/kuzzle.go +++ b/kuzzle.go @@ -10,11 +10,6 @@ import ( // Routes used to request Kuzzle, can be customized type Routes struct { - // Ping route used to test configured Kuzzle server reachability. - // The specified route must return 200 HTTP status code when called by anonymous user. - // Default is '/_publicApi' (see: https://docs.kuzzle.io/core/2/api/controllers/server/public-api/). - // You would like to modify this route if you performed security adjustement on your Kuzzle Server - Ping string `yaml:"ping,omitempty"` // Login route used to log in to Kuzzle using Auth Basic user/pass. // The specified route must return 200 HTTP status code and a valid JWT when called by anonymous user. // Default is '/_login/local' (see: https://docs.kuzzle.io/core/2/api/controllers/auth/login/) @@ -49,17 +44,6 @@ type Kuzzle struct { JWT string } -func (k *Kuzzle) ping() error { - url := fmt.Sprintf("%s%s", k.URL, k.Routes.Ping) - _, err := http.Get(url) - - if err != nil { - return fmt.Errorf("Ping request send to %s failed: %v", url, err) - } - - return nil -} - func (k *Kuzzle) login(user string, password string) error { reqBody, _ := json.Marshal(map[string]string{ "username": user, diff --git a/kuzzle_test.go b/kuzzle_test.go index e9cbd12..aa08e17 100644 --- a/kuzzle_test.go +++ b/kuzzle_test.go @@ -7,101 +7,6 @@ import ( "gopkg.in/h2non/gock.v1" ) -func TestKuzzle_ping(t *testing.T) { - type fields struct { - URL string - Routes Routes - AllowedUsers []string - JWT string - } - tests := []struct { - name string - fields fields - wantErr bool - mock Mock - }{ - { - name: "Success", - fields: fields{ - URL: "http://kuzzle:7512", - Routes: Routes{ - Ping: "/_publicApi", - }, - }, - wantErr: false, - mock: Mock{ - enabled: true, - statusCode: 200, - url: "http://kuzzle:7512", - route: "/_publicApi", - }, - }, - { - name: "Unreachable Kuzzle server", - fields: fields{ - URL: "http://kuzzle:7512", - Routes: Routes{ - Ping: "/_publicApi", - }, - }, - wantErr: true, - }, - { - name: "Bad URL format", - fields: fields{ - URL: "Bad", - Routes: Routes{ - Ping: "/_publicApi", - }, - }, - wantErr: true, - mock: Mock{ - enabled: true, - statusCode: 200, - url: "Bad", - route: "/_publicApi", - }, - }, - { - name: "Anonymous Unauthorized route", - fields: fields{ - URL: "http://kuzzle:7512", - Routes: Routes{ - Ping: "/_publicApi", - }, - }, - wantErr: true, - mock: Mock{ - enabled: true, - statusCode: 401, - url: "http://localhost:7512", - route: "/_publicApi", - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if tt.mock.enabled { - defer gock.Off() - gock. - New(tt.mock.url). - Get(tt.mock.route). - Reply(tt.mock.statusCode) - } - - k := &Kuzzle{ - URL: tt.fields.URL, - Routes: tt.fields.Routes, - AllowedUsers: tt.fields.AllowedUsers, - JWT: tt.fields.JWT, - } - if err := k.ping(); (err != nil) != tt.wantErr { - t.Errorf("Kuzzle.ping() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - func TestKuzzle_login(t *testing.T) { type fields struct { URL string diff --git a/main.go b/main.go index b266ad5..f5f8cb8 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package traefik_kuzzle_auth import ( "context" - "fmt" "net/http" ) @@ -15,10 +14,6 @@ type KuzzleAuth struct { // New created a new KuzzleBasicAuth plugin. func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error) { - if err := config.Kuzzle.ping(); err != nil { - return nil, fmt.Errorf("Unable to reach Kuzzle server at %s: %v", config.Kuzzle.URL, err) - } - return &KuzzleAuth{ next: next, name: name, diff --git a/main_test.go b/main_test.go index 0ed5d10..5b07a91 100644 --- a/main_test.go +++ b/main_test.go @@ -28,45 +28,20 @@ func TestNew(t *testing.T) { args: args{ config: &Config{ Kuzzle: Kuzzle{ - URL: "http://kuzzle:7512", - Routes: Routes{ - Ping: "/_publicApi", - }, + URL: "http://kuzzle:7512", + Routes: Routes{}, }, }, }, want: &KuzzleAuth{ config: &Config{ Kuzzle: Kuzzle{ - URL: "http://kuzzle:7512", - Routes: Routes{ - Ping: "/_publicApi", - }, + URL: "http://kuzzle:7512", + Routes: Routes{}, }, }, }, wantErr: false, - mock: Mock{ - enabled: true, - statusCode: 200, - url: "http://kuzzle:7512", - route: "/_publicApi", - }, - }, - { - name: "Kuzzle server ping failure", - args: args{ - config: &Config{ - Kuzzle: Kuzzle{ - URL: "http://kuzzle:7512", - Routes: Routes{ - Ping: "/_publicApi", - }, - }, - }, - }, - want: nil, - wantErr: true, }, } for _, tt := range tests {