mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-07-17 06:54:34 +00:00
Improvements to enforce middleware, linting, returning 404 properly
This commit is contained in:
@ -17,34 +17,19 @@ func TestEnforceSetup(t *testing.T) {
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
shouldBeSetup bool
|
||||
isSetup bool
|
||||
expectedCode int
|
||||
name string
|
||||
isSetup bool
|
||||
expectedCode int
|
||||
}{
|
||||
{
|
||||
name: "should allow request when setup is expected and is setup",
|
||||
shouldBeSetup: true,
|
||||
isSetup: true,
|
||||
expectedCode: http.StatusOK,
|
||||
name: "should allow request when setup is expected and is setup",
|
||||
isSetup: true,
|
||||
expectedCode: http.StatusOK,
|
||||
},
|
||||
{
|
||||
name: "should error when setup is expected but not setup",
|
||||
shouldBeSetup: true,
|
||||
isSetup: false,
|
||||
expectedCode: http.StatusForbidden,
|
||||
},
|
||||
{
|
||||
name: "should allow request when setup is not expected and not setup",
|
||||
shouldBeSetup: false,
|
||||
isSetup: false,
|
||||
expectedCode: http.StatusOK,
|
||||
},
|
||||
{
|
||||
name: "should error when setup is not expected but is setup",
|
||||
shouldBeSetup: false,
|
||||
isSetup: true,
|
||||
expectedCode: http.StatusForbidden,
|
||||
name: "should error when setup is expected but not setup",
|
||||
isSetup: false,
|
||||
expectedCode: http.StatusForbidden,
|
||||
},
|
||||
}
|
||||
|
||||
@ -52,7 +37,7 @@ func TestEnforceSetup(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
config.IsSetup = tt.isSetup
|
||||
|
||||
handler := middleware.EnforceSetup(tt.shouldBeSetup)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
handler := middleware.EnforceSetup()(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
|
||||
|
Reference in New Issue
Block a user