Fixed tests

This commit is contained in:
Marc Ole Bulling
2026-03-20 10:26:53 +01:00
parent 87e6208db4
commit 6bd2803a82
2 changed files with 30 additions and 8 deletions

View File

@@ -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"}},
})
}

View File

@@ -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) {