Fix empty basic auth
Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
parent
e3ab4e4d63
commit
eaedc1b924
2 changed files with 45 additions and 7 deletions
|
@ -655,7 +655,7 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
|
||||||
log.Errorf("Skipping frontend %s...", frontendName)
|
log.Errorf("Skipping frontend %s...", frontendName)
|
||||||
continue frontend
|
continue frontend
|
||||||
}
|
}
|
||||||
hcOpts := parseHealthCheckOptions(rebalancer, frontend.Backend, configuration.Backends[frontend.Backend].HealthCheck, *globalConfiguration.HealthCheck)
|
hcOpts := parseHealthCheckOptions(rebalancer, frontend.Backend, configuration.Backends[frontend.Backend].HealthCheck, globalConfiguration.HealthCheck)
|
||||||
if hcOpts != nil {
|
if hcOpts != nil {
|
||||||
log.Debugf("Setting up backend health check %s", *hcOpts)
|
log.Debugf("Setting up backend health check %s", *hcOpts)
|
||||||
backendsHealthcheck[frontend.Backend] = healthcheck.NewBackendHealthCheck(*hcOpts)
|
backendsHealthcheck[frontend.Backend] = healthcheck.NewBackendHealthCheck(*hcOpts)
|
||||||
|
@ -683,7 +683,7 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
|
||||||
continue frontend
|
continue frontend
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hcOpts := parseHealthCheckOptions(rr, frontend.Backend, configuration.Backends[frontend.Backend].HealthCheck, *globalConfiguration.HealthCheck)
|
hcOpts := parseHealthCheckOptions(rr, frontend.Backend, configuration.Backends[frontend.Backend].HealthCheck, globalConfiguration.HealthCheck)
|
||||||
if hcOpts != nil {
|
if hcOpts != nil {
|
||||||
log.Debugf("Setting up backend health check %s", *hcOpts)
|
log.Debugf("Setting up backend health check %s", *hcOpts)
|
||||||
backendsHealthcheck[frontend.Backend] = healthcheck.NewBackendHealthCheck(*hcOpts)
|
backendsHealthcheck[frontend.Backend] = healthcheck.NewBackendHealthCheck(*hcOpts)
|
||||||
|
@ -733,10 +733,11 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
|
||||||
}
|
}
|
||||||
authMiddleware, err := middlewares.NewAuthenticator(auth)
|
authMiddleware, err := middlewares.NewAuthenticator(auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error creating Auth: ", err)
|
log.Errorf("Error creating Auth: %s", err)
|
||||||
}
|
} else {
|
||||||
negroni.Use(authMiddleware)
|
negroni.Use(authMiddleware)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if configuration.Backends[frontend.Backend].CircuitBreaker != nil {
|
if configuration.Backends[frontend.Backend].CircuitBreaker != nil {
|
||||||
log.Debugf("Creating circuit breaker %s", configuration.Backends[frontend.Backend].CircuitBreaker.Expression)
|
log.Debugf("Creating circuit breaker %s", configuration.Backends[frontend.Backend].CircuitBreaker.Expression)
|
||||||
cbreaker, err := middlewares.NewCircuitBreaker(lb, configuration.Backends[frontend.Backend].CircuitBreaker.Expression, cbreaker.Logger(oxyLogger))
|
cbreaker, err := middlewares.NewCircuitBreaker(lb, configuration.Backends[frontend.Backend].CircuitBreaker.Expression, cbreaker.Logger(oxyLogger))
|
||||||
|
@ -843,8 +844,8 @@ func (server *Server) buildDefaultHTTPRouter() *mux.Router {
|
||||||
return router
|
return router
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseHealthCheckOptions(lb healthcheck.LoadBalancer, backend string, hc *types.HealthCheck, hcConfig HealthCheckConfig) *healthcheck.Options {
|
func parseHealthCheckOptions(lb healthcheck.LoadBalancer, backend string, hc *types.HealthCheck, hcConfig *HealthCheckConfig) *healthcheck.Options {
|
||||||
if hc == nil || hc.Path == "" {
|
if hc == nil || hc.Path == "" || hcConfig == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,10 +151,47 @@ func TestServerParseHealthCheckOptions(t *testing.T) {
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
gotOpts := parseHealthCheckOptions(lb, "backend", test.hc, HealthCheckConfig{Interval: flaeg.Duration(globalInterval)})
|
gotOpts := parseHealthCheckOptions(lb, "backend", test.hc, &HealthCheckConfig{Interval: flaeg.Duration(globalInterval)})
|
||||||
if !reflect.DeepEqual(gotOpts, test.wantOpts) {
|
if !reflect.DeepEqual(gotOpts, test.wantOpts) {
|
||||||
t.Errorf("got health check options %+v, want %+v", gotOpts, test.wantOpts)
|
t.Errorf("got health check options %+v, want %+v", gotOpts, test.wantOpts)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestServerLoadConfigEmptyBasicAuth(t *testing.T) {
|
||||||
|
globalConfig := GlobalConfiguration{
|
||||||
|
EntryPoints: EntryPoints{
|
||||||
|
"http": &EntryPoint{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
dynamicConfigs := configs{
|
||||||
|
"config": &types.Configuration{
|
||||||
|
Frontends: map[string]*types.Frontend{
|
||||||
|
"frontend": {
|
||||||
|
EntryPoints: []string{"http"},
|
||||||
|
Backend: "backend",
|
||||||
|
BasicAuth: []string{""},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Backends: map[string]*types.Backend{
|
||||||
|
"backend": {
|
||||||
|
Servers: map[string]types.Server{
|
||||||
|
"server": {
|
||||||
|
URL: "http://localhost",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
LoadBalancer: &types.LoadBalancer{
|
||||||
|
Method: "Wrr",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
srv := NewServer(globalConfig)
|
||||||
|
if _, err := srv.loadConfig(dynamicConfigs, globalConfig); err != nil {
|
||||||
|
t.Fatalf("got error: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue