From ae9c54064091e63ae64594310f7fe3b96f8aab27 Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Sat, 25 Sep 2021 14:50:08 +0200 Subject: [PATCH] web client login: redirect to setup page if no admin is found --- httpd/httpd_test.go | 5 +++++ httpd/webclient.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/httpd/httpd_test.go b/httpd/httpd_test.go index 8cf53541..30252c26 100644 --- a/httpd/httpd_test.go +++ b/httpd/httpd_test.go @@ -5944,6 +5944,11 @@ func TestWebAdminSetupMock(t *testing.T) { rr = executeRequest(req) checkResponseCode(t, http.StatusFound, rr) assert.Equal(t, webAdminSetupPath, rr.Header().Get("Location")) + req, err = http.NewRequest(http.MethodGet, webClientLoginPath, nil) + assert.NoError(t, err) + rr = executeRequest(req) + checkResponseCode(t, http.StatusFound, rr) + assert.Equal(t, webAdminSetupPath, rr.Header().Get("Location")) csrfToken, err := getCSRFToken(httpBaseURL + webAdminSetupPath) assert.NoError(t, err) diff --git a/httpd/webclient.go b/httpd/webclient.go index 0b6693c4..d4886a78 100644 --- a/httpd/webclient.go +++ b/httpd/webclient.go @@ -253,6 +253,10 @@ func renderCredentialsPage(w http.ResponseWriter, r *http.Request, pwdError stri } func handleClientWebLogin(w http.ResponseWriter, r *http.Request) { + if !dataprovider.HasAdmin() { + http.Redirect(w, r, webAdminSetupPath, http.StatusFound) + return + } renderClientLoginPage(w, "") }