Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2bfb597342 |
@@ -23,7 +23,6 @@ import (
|
|||||||
|
|
||||||
"go.uber.org/fx"
|
"go.uber.org/fx"
|
||||||
"go.uber.org/fx/fxtest"
|
"go.uber.org/fx/fxtest"
|
||||||
"golang.org/x/crypto/bcrypt"
|
|
||||||
"modernc.org/sqlite"
|
"modernc.org/sqlite"
|
||||||
"sneak.berlin/go/neoirc/internal/broker"
|
"sneak.berlin/go/neoirc/internal/broker"
|
||||||
api "sneak.berlin/go/neoirc/internal/cli/api"
|
api "sneak.berlin/go/neoirc/internal/cli/api"
|
||||||
@@ -863,7 +862,10 @@ func TestRequestBodyLimit(t *testing.T) {
|
|||||||
tserver := newTestServer(t)
|
tserver := newTestServer(t)
|
||||||
token := tserver.createSession(nick)
|
token := tserver.createSession(nick)
|
||||||
|
|
||||||
tserver.setPassword(nick)
|
tserver.sendCommand(token, map[string]any{
|
||||||
|
commandKey: irc.CmdPass,
|
||||||
|
bodyKey: []string{testPassword},
|
||||||
|
})
|
||||||
|
|
||||||
bytesToLimit := maxMessageSize - len(endpoint.value)
|
bytesToLimit := maxMessageSize - len(endpoint.value)
|
||||||
|
|
||||||
@@ -1765,7 +1767,9 @@ func checkQuitRace(
|
|||||||
firstToken := tserver.createSession(nick)
|
firstToken := tserver.createSession(nick)
|
||||||
observerToken := tserver.createSession("raceobserver")
|
observerToken := tserver.createSession("raceobserver")
|
||||||
|
|
||||||
tserver.setPassword(nick)
|
tserver.sendCommand(firstToken, map[string]any{
|
||||||
|
commandKey: irc.CmdPass, bodyKey: []string{testPassword},
|
||||||
|
})
|
||||||
|
|
||||||
tokens := []string{firstToken, tserver.login(nick)}
|
tokens := []string{firstToken, tserver.login(nick)}
|
||||||
|
|
||||||
@@ -1815,7 +1819,9 @@ func TestLogoutOfOneClientKeepsSession(t *testing.T) {
|
|||||||
firstToken := tserver.createSession(nick)
|
firstToken := tserver.createSession(nick)
|
||||||
observerToken := tserver.createSession("logoutobserver")
|
observerToken := tserver.createSession("logoutobserver")
|
||||||
|
|
||||||
tserver.setPassword(nick)
|
tserver.sendCommand(firstToken, map[string]any{
|
||||||
|
commandKey: irc.CmdPass, bodyKey: []string{testPassword},
|
||||||
|
})
|
||||||
|
|
||||||
secondToken := tserver.login(nick)
|
secondToken := tserver.login(nick)
|
||||||
|
|
||||||
@@ -2124,24 +2130,6 @@ func (tserver *testServer) longPoll(
|
|||||||
return result.Messages, nil
|
return result.Messages, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// setPassword gives the session nick the password testPassword
|
|
||||||
// without sending PASS. It hashes at bcrypt.MinCost, and a login
|
|
||||||
// compares at the cost stored in the hash, so both are fast.
|
|
||||||
func (tserver *testServer) setPassword(nick string) {
|
|
||||||
tserver.t.Helper()
|
|
||||||
|
|
||||||
hash, err := bcrypt.GenerateFromPassword(
|
|
||||||
[]byte(testPassword), bcrypt.MinCost,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
tserver.t.Fatalf("hash password: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
dbtest.Exec(tserver.t, tserver.dbURL,
|
|
||||||
"UPDATE sessions SET password_hash = '"+string(hash)+
|
|
||||||
"' WHERE nick = '"+nick+"'")
|
|
||||||
}
|
|
||||||
|
|
||||||
// login logs in to the session nick with testPassword and
|
// login logs in to the session nick with testPassword and
|
||||||
// returns the new client's token.
|
// returns the new client's token.
|
||||||
func (tserver *testServer) login(nick string) string {
|
func (tserver *testServer) login(nick string) string {
|
||||||
@@ -3749,8 +3737,13 @@ func TestLoginValid(t *testing.T) {
|
|||||||
|
|
||||||
tserver := newTestServer(t)
|
tserver := newTestServer(t)
|
||||||
|
|
||||||
tserver.createSession("loginuser")
|
// Create session and set password via PASS command.
|
||||||
tserver.setPassword("loginuser")
|
token := tserver.createSession("loginuser")
|
||||||
|
|
||||||
|
tserver.sendCommand(token, map[string]any{
|
||||||
|
commandKey: irc.CmdPass,
|
||||||
|
bodyKey: []string{testPassword},
|
||||||
|
})
|
||||||
|
|
||||||
// Login with nick + password.
|
// Login with nick + password.
|
||||||
loginBody, err := json.Marshal(map[string]string{
|
loginBody, err := json.Marshal(map[string]string{
|
||||||
@@ -3814,8 +3807,13 @@ func TestLoginWrongPassword(t *testing.T) {
|
|||||||
|
|
||||||
tserver := newTestServer(t)
|
tserver := newTestServer(t)
|
||||||
|
|
||||||
tserver.createSession("wrongpwuser")
|
// Create session and set password via PASS command.
|
||||||
tserver.setPassword("wrongpwuser")
|
token := tserver.createSession("wrongpwuser")
|
||||||
|
|
||||||
|
tserver.sendCommand(token, map[string]any{
|
||||||
|
commandKey: irc.CmdPass,
|
||||||
|
bodyKey: []string{"correctpass1"},
|
||||||
|
})
|
||||||
|
|
||||||
postJSONExpectStatus(
|
postJSONExpectStatus(
|
||||||
t, tserver, "/api/v1/login",
|
t, tserver, "/api/v1/login",
|
||||||
@@ -4286,8 +4284,13 @@ func TestLoginRateLimitAllowsNormalUse(t *testing.T) {
|
|||||||
|
|
||||||
tserver := newTestServer(t)
|
tserver := newTestServer(t)
|
||||||
|
|
||||||
tserver.createSession("normaluser")
|
// Create session and set password via PASS command.
|
||||||
tserver.setPassword("normaluser")
|
token := tserver.createSession("normaluser")
|
||||||
|
|
||||||
|
tserver.sendCommand(token, map[string]any{
|
||||||
|
commandKey: irc.CmdPass,
|
||||||
|
bodyKey: []string{testPassword},
|
||||||
|
})
|
||||||
|
|
||||||
// A single login should succeed without rate limiting.
|
// A single login should succeed without rate limiting.
|
||||||
loginBody, err := json.Marshal(map[string]string{
|
loginBody, err := json.Marshal(map[string]string{
|
||||||
|
|||||||
Reference in new issue
Block a user