Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51b151aa26 |
@@ -23,6 +23,7 @@ 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"
|
||||||
@@ -862,10 +863,7 @@ func TestRequestBodyLimit(t *testing.T) {
|
|||||||
tserver := newTestServer(t)
|
tserver := newTestServer(t)
|
||||||
token := tserver.createSession(nick)
|
token := tserver.createSession(nick)
|
||||||
|
|
||||||
tserver.sendCommand(token, map[string]any{
|
tserver.setPassword(nick)
|
||||||
commandKey: irc.CmdPass,
|
|
||||||
bodyKey: []string{testPassword},
|
|
||||||
})
|
|
||||||
|
|
||||||
bytesToLimit := maxMessageSize - len(endpoint.value)
|
bytesToLimit := maxMessageSize - len(endpoint.value)
|
||||||
|
|
||||||
@@ -1767,9 +1765,7 @@ func checkQuitRace(
|
|||||||
firstToken := tserver.createSession(nick)
|
firstToken := tserver.createSession(nick)
|
||||||
observerToken := tserver.createSession("raceobserver")
|
observerToken := tserver.createSession("raceobserver")
|
||||||
|
|
||||||
tserver.sendCommand(firstToken, map[string]any{
|
tserver.setPassword(nick)
|
||||||
commandKey: irc.CmdPass, bodyKey: []string{testPassword},
|
|
||||||
})
|
|
||||||
|
|
||||||
tokens := []string{firstToken, tserver.login(nick)}
|
tokens := []string{firstToken, tserver.login(nick)}
|
||||||
|
|
||||||
@@ -1819,9 +1815,7 @@ func TestLogoutOfOneClientKeepsSession(t *testing.T) {
|
|||||||
firstToken := tserver.createSession(nick)
|
firstToken := tserver.createSession(nick)
|
||||||
observerToken := tserver.createSession("logoutobserver")
|
observerToken := tserver.createSession("logoutobserver")
|
||||||
|
|
||||||
tserver.sendCommand(firstToken, map[string]any{
|
tserver.setPassword(nick)
|
||||||
commandKey: irc.CmdPass, bodyKey: []string{testPassword},
|
|
||||||
})
|
|
||||||
|
|
||||||
secondToken := tserver.login(nick)
|
secondToken := tserver.login(nick)
|
||||||
|
|
||||||
@@ -2130,6 +2124,24 @@ 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 {
|
||||||
@@ -3737,13 +3749,8 @@ func TestLoginValid(t *testing.T) {
|
|||||||
|
|
||||||
tserver := newTestServer(t)
|
tserver := newTestServer(t)
|
||||||
|
|
||||||
// Create session and set password via PASS command.
|
tserver.createSession("loginuser")
|
||||||
token := tserver.createSession("loginuser")
|
tserver.setPassword("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{
|
||||||
@@ -3807,13 +3814,8 @@ func TestLoginWrongPassword(t *testing.T) {
|
|||||||
|
|
||||||
tserver := newTestServer(t)
|
tserver := newTestServer(t)
|
||||||
|
|
||||||
// Create session and set password via PASS command.
|
tserver.createSession("wrongpwuser")
|
||||||
token := tserver.createSession("wrongpwuser")
|
tserver.setPassword("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",
|
||||||
@@ -4284,13 +4286,8 @@ func TestLoginRateLimitAllowsNormalUse(t *testing.T) {
|
|||||||
|
|
||||||
tserver := newTestServer(t)
|
tserver := newTestServer(t)
|
||||||
|
|
||||||
// Create session and set password via PASS command.
|
tserver.createSession("normaluser")
|
||||||
token := tserver.createSession("normaluser")
|
tserver.setPassword("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