From 6bd2803a8230da94b3da8270c8af94dabf43fa9a Mon Sep 17 00:00:00 2001 From: Marc Ole Bulling Date: Fri, 20 Mar 2026 10:26:53 +0100 Subject: [PATCH] Fixed tests --- internal/webserver/Webserver_test.go | 19 +++++++++++++++++-- .../authentication/Authentication_test.go | 19 +++++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/internal/webserver/Webserver_test.go b/internal/webserver/Webserver_test.go index 3e91dfc..6a1e08e 100644 --- a/internal/webserver/Webserver_test.go +++ b/internal/webserver/Webserver_test.go @@ -122,6 +122,7 @@ func TestLogin(t *testing.T) { // POST with correct credentials but invalid CSRF token shows error postConfig.PostValues = postValues("test", "adminadmin", "invalid") + postConfig.RequiredContent = []string{"id=\"uname_hidden\"", "The login page was open too long and expired. Please try again."} test.HttpPostRequest(t, postConfig) // GET /login with OAuth2 enabled redirects to oauth-login @@ -283,7 +284,14 @@ func TestLoginIncorrectPassword(t *testing.T) { RequiredContent: []string{"Incorrect username or password"}, IsHtml: true, Method: "POST", - PostValues: []test.PostBody{{"username", "test"}, {"password", "incorrect"}}, + PostValues: []test.PostBody{{"username", "test"}, {"password", "incorrect"}, {"csrf-token", csrftoken.Generate()}}, + }) + test.HttpPageResult(t, test.HttpTestConfig{ + Url: "http://localhost:53843/login", + RequiredContent: []string{"The login page was open too long and expired. Please try again."}, + IsHtml: true, + Method: "POST", + PostValues: []test.PostBody{{"username", "test"}, {"password", "incorrect"}, {"csrf-token", "incorrect"}}, }) } func TestLoginIncorrectUsername(t *testing.T) { @@ -293,7 +301,14 @@ func TestLoginIncorrectUsername(t *testing.T) { RequiredContent: []string{"Incorrect username or password"}, IsHtml: true, Method: "POST", - PostValues: []test.PostBody{{"username", "incorrect"}, {"password", "incorrect"}}, + PostValues: []test.PostBody{{"username", "incorrect"}, {"password", "incorrect"}, {"csrf-token", csrftoken.Generate()}}, + }) + test.HttpPageResult(t, test.HttpTestConfig{ + Url: "http://localhost:53843/login", + RequiredContent: []string{"The login page was open too long and expired. Please try again."}, + IsHtml: true, + Method: "POST", + PostValues: []test.PostBody{{"username", "incorrect"}, {"password", "incorrect"}, {"csrf-token", "incorrect"}}, }) } diff --git a/internal/webserver/authentication/Authentication_test.go b/internal/webserver/authentication/Authentication_test.go index 96e57a0..128830e 100644 --- a/internal/webserver/authentication/Authentication_test.go +++ b/internal/webserver/authentication/Authentication_test.go @@ -75,20 +75,27 @@ func TestIsValid(t *testing.T) { } func TestIsCorrectUsernameAndPassword(t *testing.T) { - user, ok := IsCorrectUsernameAndPassword("test", "adminadmin", csrftoken.Generate()) + user, ok, csfrOk := IsCorrectUsernameAndPassword("test", "adminadmin", csrftoken.Generate()) test.IsEqualBool(t, ok, true) - user, ok = IsCorrectUsernameAndPassword("Test", "adminadmin", csrftoken.Generate()) + test.IsEqualBool(t, csfrOk, true) + + user, ok, csfrOk = IsCorrectUsernameAndPassword("Test", "adminadmin", csrftoken.Generate()) test.IsEqualBool(t, ok, true) + test.IsEqualBool(t, csfrOk, true) test.IsEqualInt(t, user.Id, 5) - user, ok = IsCorrectUsernameAndPassword("user", "useruser", csrftoken.Generate()) + user, ok, csfrOk = IsCorrectUsernameAndPassword("user", "useruser", csrftoken.Generate()) test.IsEqualBool(t, ok, true) + test.IsEqualBool(t, csfrOk, true) test.IsEqualInt(t, user.Id, 7) - _, ok = IsCorrectUsernameAndPassword("test", "wrong", csrftoken.Generate()) + _, ok, csfrOk = IsCorrectUsernameAndPassword("test", "wrong", csrftoken.Generate()) test.IsEqualBool(t, ok, false) - _, ok = IsCorrectUsernameAndPassword("invalid", "adminadmin", csrftoken.Generate()) + test.IsEqualBool(t, csfrOk, true) + _, ok, csfrOk = IsCorrectUsernameAndPassword("invalid", "adminadmin", csrftoken.Generate()) test.IsEqualBool(t, ok, false) - _, ok = IsCorrectUsernameAndPassword("test", "adminadmin", "invalidToken") + test.IsEqualBool(t, csfrOk, true) + _, ok, csfrOk = IsCorrectUsernameAndPassword("test", "adminadmin", "invalidToken") test.IsEqualBool(t, ok, false) + test.IsEqualBool(t, csfrOk, false) } func TestIsAuthenticated(t *testing.T) {