Fix IRC listener relay of bodies and modes, and JOIN names (closes #127)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
The IRC listener relayed only the first line of a PRIVMSG or NOTICE body; it now sends one line per body line. A relayed MODE change now carries its key, limit or mask, each value its own parameter, also in the echo to the user who made it. CR, LF and NUL are removed from each parameter and from each whole line sent to an IRC listener connection, so no stored value can start a line of its own. The channel name check moved into service.JoinChannel, so the IRC listener's JOIN refuses the same names with 403. Model: opus-5-5
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"log/slog"
|
||||
"net"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -100,3 +101,48 @@ func TestDisconnectNotifiesAndClosesVictim(t *testing.T) {
|
||||
t.Errorf("missing ERROR line, got: %q", joined)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDisconnectReasonCannotStartLine checks that CR, LF and
|
||||
// NUL in a KILL reason are removed from both the KILL line
|
||||
// and the ERROR line, so the victim gets exactly those two
|
||||
// lines. The ERROR line is not built with FormatMessage, so
|
||||
// only the removal in sendWithin protects it.
|
||||
func TestDisconnectReasonCannotStartLine(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
victim, clientSide := newKillVictim(t)
|
||||
received := make(chan []string, 1)
|
||||
|
||||
go func() {
|
||||
var lines []string
|
||||
|
||||
scanner := bufio.NewScanner(clientSide)
|
||||
for scanner.Scan() {
|
||||
lines = append(lines, scanner.Text())
|
||||
}
|
||||
|
||||
received <- lines
|
||||
}()
|
||||
|
||||
victim.Disconnect("bye\r\nPRIVMSG victim :forged\x00")
|
||||
|
||||
var lines []string
|
||||
|
||||
select {
|
||||
case lines = <-received:
|
||||
case <-time.After(testTimeout):
|
||||
t.Fatal("the victim's connection was not closed")
|
||||
}
|
||||
|
||||
// The test connection has no host name, hence the two
|
||||
// spaces after "Closing Link:".
|
||||
want := []string{
|
||||
":" + testServerName +
|
||||
" KILL victim :byePRIVMSG victim :forged",
|
||||
"ERROR :Closing Link: (byePRIVMSG victim :forged)",
|
||||
}
|
||||
|
||||
if !slices.Equal(lines, want) {
|
||||
t.Errorf("got lines %q, want %q", lines, want)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user