mirror of
https://github.com/Forceu/Gokapi.git
synced 2026-04-03 20:22:22 -05:00
Fixed tests
This commit is contained in:
@@ -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"}},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user