2011-08-22 22:24:05 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2013-02-16 00:17:31 +00:00
|
|
|
"time"
|
2019-10-17 19:27:52 +00:00
|
|
|
|
|
|
|
"github.com/fluffle/goirc/state"
|
|
|
|
"github.com/golang/mock/gomock"
|
2011-08-22 22:24:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// This test performs a simple end-to-end verification of correct line parsing
|
|
|
|
// and event dispatch as well as testing the PING handler. All the other tests
|
|
|
|
// in this file will call their respective handlers synchronously, otherwise
|
|
|
|
// testing becomes more difficult.
|
|
|
|
func TestPING(t *testing.T) {
|
2013-02-16 00:17:31 +00:00
|
|
|
_, s := setUp(t)
|
2011-11-06 04:56:46 +00:00
|
|
|
defer s.tearDown()
|
|
|
|
s.nc.Send("PING :1234567890")
|
|
|
|
s.nc.Expect("PONG :1234567890")
|
2011-08-22 22:24:05 +00:00
|
|
|
}
|
|
|
|
|
2013-02-18 01:36:17 +00:00
|
|
|
// Test the REGISTER handler matches section 3.1 of rfc2812
|
|
|
|
func TestREGISTER(t *testing.T) {
|
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
|
|
|
|
|
|
|
c.h_REGISTER(&Line{Cmd: REGISTER})
|
|
|
|
s.nc.Expect("NICK test")
|
|
|
|
s.nc.Expect("USER test 12 * :Testing IRC")
|
|
|
|
s.nc.ExpectNothing()
|
|
|
|
|
|
|
|
c.cfg.Pass = "12345"
|
|
|
|
c.cfg.Me.Ident = "idiot"
|
|
|
|
c.cfg.Me.Name = "I've got the same combination on my luggage!"
|
|
|
|
c.h_REGISTER(&Line{Cmd: REGISTER})
|
|
|
|
s.nc.Expect("PASS 12345")
|
|
|
|
s.nc.Expect("NICK test")
|
|
|
|
s.nc.Expect("USER idiot 12 * :I've got the same combination on my luggage!")
|
|
|
|
s.nc.ExpectNothing()
|
|
|
|
}
|
|
|
|
|
2011-08-22 22:24:05 +00:00
|
|
|
// Test the handler for 001 / RPL_WELCOME
|
|
|
|
func Test001(t *testing.T) {
|
2011-11-06 04:56:46 +00:00
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
2011-08-22 22:24:05 +00:00
|
|
|
|
2021-03-26 11:20:00 +00:00
|
|
|
l := ParseLine(":irc.server.org 001 newnick :Welcome to IRC newnick!ident@somehost.com")
|
2013-02-16 00:17:31 +00:00
|
|
|
// Set up a handler to detect whether connected handler is called from 001
|
|
|
|
hcon := false
|
2013-02-16 10:33:15 +00:00
|
|
|
c.HandleFunc("connected", func(conn *Conn, line *Line) {
|
2013-02-16 00:17:31 +00:00
|
|
|
hcon = true
|
|
|
|
})
|
|
|
|
|
2015-01-02 12:58:50 +00:00
|
|
|
// Test state tracking first.
|
|
|
|
gomock.InOrder(
|
|
|
|
s.st.EXPECT().Me().Return(c.cfg.Me),
|
2021-03-26 11:20:00 +00:00
|
|
|
s.st.EXPECT().NickInfo("test", "ident", "somehost.com", "Testing IRC"),
|
|
|
|
s.st.EXPECT().ReNick("test", "newnick").Return(&state.Nick{
|
|
|
|
Nick: "newnick",
|
|
|
|
Ident: c.cfg.Me.Ident,
|
|
|
|
Name: c.cfg.Me.Name,
|
|
|
|
}),
|
2015-01-02 12:58:50 +00:00
|
|
|
)
|
2011-08-22 22:24:05 +00:00
|
|
|
// Call handler with a valid 001 line
|
2011-11-07 14:50:23 +00:00
|
|
|
c.h_001(l)
|
2013-02-16 00:17:31 +00:00
|
|
|
<-time.After(time.Millisecond)
|
|
|
|
if !hcon {
|
|
|
|
t.Errorf("001 handler did not dispatch connected event.")
|
|
|
|
}
|
2011-08-22 22:24:05 +00:00
|
|
|
|
2015-01-02 12:58:50 +00:00
|
|
|
// Now without state tracking.
|
|
|
|
c.st = nil
|
|
|
|
c.h_001(l)
|
2011-08-22 22:24:05 +00:00
|
|
|
// Check host parsed correctly
|
2013-02-18 01:36:17 +00:00
|
|
|
if c.cfg.Me.Host != "somehost.com" {
|
|
|
|
t.Errorf("Host parsing failed, host is '%s'.", c.cfg.Me.Host)
|
2011-08-22 22:24:05 +00:00
|
|
|
}
|
2015-01-02 12:58:50 +00:00
|
|
|
c.st = s.st
|
2011-08-22 22:24:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test the handler for 433 / ERR_NICKNAMEINUSE
|
|
|
|
func Test433(t *testing.T) {
|
2011-11-06 04:56:46 +00:00
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
2011-09-09 22:04:27 +00:00
|
|
|
|
2013-02-18 01:36:17 +00:00
|
|
|
// Call handler with a 433 line, not triggering c.cfg.Me.Renick()
|
2015-01-02 12:58:50 +00:00
|
|
|
s.st.EXPECT().Me().Return(c.cfg.Me)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_433(ParseLine(":irc.server.org 433 test new :Nickname is already in use."))
|
2019-10-17 19:27:52 +00:00
|
|
|
s.nc.Expect("NICK " + DefaultNewNick("new"))
|
2011-08-22 22:24:05 +00:00
|
|
|
|
2011-09-12 22:25:09 +00:00
|
|
|
// Send a line that will trigger a renick. This happens when our wanted
|
2011-08-22 22:24:05 +00:00
|
|
|
// nick is unavailable during initial negotiation, so we must choose a
|
|
|
|
// different one before the connection can proceed. No NICK line will be
|
|
|
|
// sent by the server to confirm nick change in this case.
|
2019-10-17 19:27:52 +00:00
|
|
|
want := DefaultNewNick(c.cfg.Me.Nick)
|
2015-01-02 12:58:50 +00:00
|
|
|
gomock.InOrder(
|
|
|
|
s.st.EXPECT().Me().Return(c.cfg.Me),
|
2019-10-17 19:27:52 +00:00
|
|
|
s.st.EXPECT().ReNick("test", want).Return(c.cfg.Me),
|
2015-01-02 12:58:50 +00:00
|
|
|
)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_433(ParseLine(":irc.server.org 433 test test :Nickname is already in use."))
|
2019-10-17 19:27:52 +00:00
|
|
|
s.nc.Expect("NICK " + want)
|
2011-11-06 04:56:46 +00:00
|
|
|
|
|
|
|
// Test the code path that *doesn't* involve state tracking.
|
2013-02-16 11:29:56 +00:00
|
|
|
c.st = nil
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_433(ParseLine(":irc.server.org 433 test test :Nickname is already in use."))
|
2019-10-17 19:27:52 +00:00
|
|
|
s.nc.Expect("NICK " + want)
|
2011-08-22 22:24:05 +00:00
|
|
|
|
2019-10-17 19:27:52 +00:00
|
|
|
if c.cfg.Me.Nick != want {
|
2013-02-18 01:36:17 +00:00
|
|
|
t.Errorf("My nick not updated from '%s'.", c.cfg.Me.Nick)
|
2011-08-22 22:24:05 +00:00
|
|
|
}
|
2013-02-16 11:29:56 +00:00
|
|
|
c.st = s.st
|
2011-08-22 22:24:05 +00:00
|
|
|
}
|
|
|
|
|
2011-11-06 04:56:46 +00:00
|
|
|
// Test the handler for NICK messages when state tracking is disabled
|
2011-08-22 22:24:05 +00:00
|
|
|
func TestNICK(t *testing.T) {
|
2011-11-06 04:56:46 +00:00
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
|
|
|
|
|
|
|
// State tracking is enabled by default in setUp
|
2013-02-16 11:29:56 +00:00
|
|
|
c.st = nil
|
2011-08-22 22:24:05 +00:00
|
|
|
|
|
|
|
// Call handler with a NICK line changing "our" nick to test1.
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_NICK(ParseLine(":test!test@somehost.com NICK :test1"))
|
2011-08-23 09:52:16 +00:00
|
|
|
|
|
|
|
// Verify that our Nick has changed
|
2013-02-18 01:36:17 +00:00
|
|
|
if c.cfg.Me.Nick != "test1" {
|
2011-08-22 22:24:05 +00:00
|
|
|
t.Errorf("NICK did not result in changing our nick.")
|
|
|
|
}
|
|
|
|
|
2011-11-06 04:56:46 +00:00
|
|
|
// Send a NICK line for something that isn't us.
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_NICK(ParseLine(":blah!moo@cows.com NICK :milk"))
|
2011-08-24 12:53:28 +00:00
|
|
|
|
2011-11-06 04:56:46 +00:00
|
|
|
// Verify that our Nick hasn't changed
|
2013-02-18 01:36:17 +00:00
|
|
|
if c.cfg.Me.Nick != "test1" {
|
2011-11-06 04:56:46 +00:00
|
|
|
t.Errorf("NICK did not result in changing our nick.")
|
2011-08-22 22:24:05 +00:00
|
|
|
}
|
|
|
|
|
2011-11-06 04:56:46 +00:00
|
|
|
// Re-enable state tracking and send a line that *should* change nick.
|
2013-02-16 11:29:56 +00:00
|
|
|
c.st = s.st
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_NICK(ParseLine(":test1!test@somehost.com NICK :test2"))
|
2011-11-06 04:56:46 +00:00
|
|
|
|
|
|
|
// Verify that our Nick hasn't changed (should be handled by h_STNICK).
|
2013-02-18 01:36:17 +00:00
|
|
|
if c.cfg.Me.Nick != "test1" {
|
2011-11-06 04:56:46 +00:00
|
|
|
t.Errorf("NICK changed our nick when state tracking enabled.")
|
|
|
|
}
|
2011-08-22 22:24:05 +00:00
|
|
|
}
|
2011-08-23 10:03:59 +00:00
|
|
|
|
2011-08-24 11:46:21 +00:00
|
|
|
// Test the handler for CTCP messages
|
2011-08-23 10:03:59 +00:00
|
|
|
func TestCTCP(t *testing.T) {
|
2011-11-06 04:56:46 +00:00
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
2011-08-23 10:03:59 +00:00
|
|
|
|
|
|
|
// Call handler with CTCP VERSION
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_CTCP(ParseLine(":blah!moo@cows.com PRIVMSG test :\001VERSION\001"))
|
2011-08-23 10:03:59 +00:00
|
|
|
|
|
|
|
// Expect a version reply
|
2013-02-19 01:02:58 +00:00
|
|
|
s.nc.Expect("NOTICE blah :\001VERSION Powered by GoIRC\001")
|
2011-08-23 10:03:59 +00:00
|
|
|
|
|
|
|
// Call handler with CTCP PING
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_CTCP(ParseLine(":blah!moo@cows.com PRIVMSG test :\001PING 1234567890\001"))
|
2011-08-23 10:03:59 +00:00
|
|
|
|
|
|
|
// Expect a ping reply
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("NOTICE blah :\001PING 1234567890\001")
|
2011-08-23 10:03:59 +00:00
|
|
|
|
|
|
|
// Call handler with CTCP UNKNOWN
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_CTCP(ParseLine(":blah!moo@cows.com PRIVMSG test :\001UNKNOWN ctcp\001"))
|
2011-08-23 10:03:59 +00:00
|
|
|
}
|
2011-08-24 11:46:21 +00:00
|
|
|
|
|
|
|
// Test the handler for JOIN messages
|
|
|
|
func TestJOIN(t *testing.T) {
|
2011-11-06 04:56:46 +00:00
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
|
|
|
|
|
|
|
// The state tracker should be creating a new channel in this first test
|
2015-01-02 12:58:50 +00:00
|
|
|
chan1 := &state.Channel{Name: "#test1"}
|
2011-08-24 11:46:21 +00:00
|
|
|
|
2011-11-06 04:56:46 +00:00
|
|
|
gomock.InOrder(
|
|
|
|
s.st.EXPECT().GetChannel("#test1").Return(nil),
|
2013-02-18 01:36:17 +00:00
|
|
|
s.st.EXPECT().GetNick("test").Return(c.cfg.Me),
|
2015-01-02 12:58:50 +00:00
|
|
|
s.st.EXPECT().Me().Return(c.cfg.Me),
|
2011-11-06 04:56:46 +00:00
|
|
|
s.st.EXPECT().NewChannel("#test1").Return(chan1),
|
2015-01-02 12:58:50 +00:00
|
|
|
s.st.EXPECT().Associate("#test1", "test"),
|
2011-11-06 04:56:46 +00:00
|
|
|
)
|
2011-08-24 11:46:21 +00:00
|
|
|
|
|
|
|
// Use #test1 to test expected behaviour
|
|
|
|
// Call handler with JOIN by test to #test1
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_JOIN(ParseLine(":test!test@somehost.com JOIN :#test1"))
|
2011-08-24 11:46:21 +00:00
|
|
|
|
|
|
|
// Verify that the MODE and WHO commands are sent correctly
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("MODE #test1")
|
|
|
|
s.nc.Expect("WHO #test1")
|
2011-08-24 11:46:21 +00:00
|
|
|
|
2011-11-06 04:56:46 +00:00
|
|
|
// In this second test, we should be creating a new nick
|
2015-01-02 12:58:50 +00:00
|
|
|
nick1 := &state.Nick{Nick: "user1"}
|
2011-11-06 04:56:46 +00:00
|
|
|
|
|
|
|
gomock.InOrder(
|
|
|
|
s.st.EXPECT().GetChannel("#test1").Return(chan1),
|
|
|
|
s.st.EXPECT().GetNick("user1").Return(nil),
|
|
|
|
s.st.EXPECT().NewNick("user1").Return(nick1),
|
2015-01-02 12:58:50 +00:00
|
|
|
s.st.EXPECT().NickInfo("user1", "ident1", "host1.com", "").Return(nick1),
|
|
|
|
s.st.EXPECT().Associate("#test1", "user1"),
|
2011-11-06 04:56:46 +00:00
|
|
|
)
|
2011-08-24 11:46:21 +00:00
|
|
|
|
2011-08-24 12:57:06 +00:00
|
|
|
// OK, now #test1 exists, JOIN another user we don't know about
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_JOIN(ParseLine(":user1!ident1@host1.com JOIN :#test1"))
|
2011-08-24 11:46:21 +00:00
|
|
|
|
|
|
|
// Verify that the WHO command is sent correctly
|
2011-11-06 04:56:46 +00:00
|
|
|
s.nc.Expect("WHO user1")
|
|
|
|
|
|
|
|
// In this third test, we'll be pretending we know about the nick already.
|
2015-01-02 12:58:50 +00:00
|
|
|
nick2 := &state.Nick{Nick: "user2"}
|
2011-11-06 04:56:46 +00:00
|
|
|
gomock.InOrder(
|
|
|
|
s.st.EXPECT().GetChannel("#test1").Return(chan1),
|
|
|
|
s.st.EXPECT().GetNick("user2").Return(nick2),
|
2015-01-02 12:58:50 +00:00
|
|
|
s.st.EXPECT().Associate("#test1", "user2"),
|
2011-11-06 04:56:46 +00:00
|
|
|
)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_JOIN(ParseLine(":user2!ident2@host2.com JOIN :#test1"))
|
2011-08-24 11:46:21 +00:00
|
|
|
|
2011-11-06 04:56:46 +00:00
|
|
|
// Test error paths
|
|
|
|
gomock.InOrder(
|
|
|
|
// unknown channel, unknown nick
|
|
|
|
s.st.EXPECT().GetChannel("#test2").Return(nil),
|
|
|
|
s.st.EXPECT().GetNick("blah").Return(nil),
|
2015-01-02 12:58:50 +00:00
|
|
|
s.st.EXPECT().Me().Return(c.cfg.Me),
|
2011-11-06 04:56:46 +00:00
|
|
|
// unknown channel, known nick that isn't Me.
|
|
|
|
s.st.EXPECT().GetChannel("#test2").Return(nil),
|
|
|
|
s.st.EXPECT().GetNick("user2").Return(nick2),
|
2015-01-02 12:58:50 +00:00
|
|
|
s.st.EXPECT().Me().Return(c.cfg.Me),
|
2011-11-06 04:56:46 +00:00
|
|
|
)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_JOIN(ParseLine(":blah!moo@cows.com JOIN :#test2"))
|
|
|
|
c.h_JOIN(ParseLine(":user2!ident2@host2.com JOIN :#test2"))
|
2011-08-24 11:46:21 +00:00
|
|
|
}
|
2011-08-24 13:34:11 +00:00
|
|
|
|
|
|
|
// Test the handler for PART messages
|
|
|
|
func TestPART(t *testing.T) {
|
2011-11-06 04:56:46 +00:00
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
|
|
|
|
|
|
|
// PART should dissociate a nick from a channel.
|
2015-01-02 12:58:50 +00:00
|
|
|
s.st.EXPECT().Dissociate("#test1", "user1")
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_PART(ParseLine(":user1!ident1@host1.com PART #test1 :Bye!"))
|
2011-08-24 13:34:11 +00:00
|
|
|
}
|
2011-08-30 22:15:54 +00:00
|
|
|
|
|
|
|
// Test the handler for KICK messages
|
|
|
|
// (this is very similar to the PART message test)
|
|
|
|
func TestKICK(t *testing.T) {
|
2011-11-06 04:56:46 +00:00
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
|
|
|
|
|
|
|
// KICK should dissociate a nick from a channel.
|
2015-01-02 12:58:50 +00:00
|
|
|
s.st.EXPECT().Dissociate("#test1", "user1")
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_KICK(ParseLine(":test!test@somehost.com KICK #test1 user1 :Bye!"))
|
2011-08-30 22:15:54 +00:00
|
|
|
}
|
2011-08-31 21:55:56 +00:00
|
|
|
|
|
|
|
// Test the handler for QUIT messages
|
|
|
|
func TestQUIT(t *testing.T) {
|
2011-11-06 04:56:46 +00:00
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
2011-08-31 21:55:56 +00:00
|
|
|
|
2011-11-06 04:56:46 +00:00
|
|
|
// Have user1 QUIT. All possible errors handled by state tracker \o/
|
|
|
|
s.st.EXPECT().DelNick("user1")
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_QUIT(ParseLine(":user1!ident1@host1.com QUIT :Bye!"))
|
2011-08-31 21:55:56 +00:00
|
|
|
}
|
2011-09-09 21:32:55 +00:00
|
|
|
|
|
|
|
// Test the handler for MODE messages
|
|
|
|
func TestMODE(t *testing.T) {
|
2011-11-06 04:56:46 +00:00
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
|
|
|
|
2015-01-02 12:58:50 +00:00
|
|
|
// Channel modes
|
|
|
|
gomock.InOrder(
|
|
|
|
s.st.EXPECT().GetChannel("#test1").Return(&state.Channel{Name: "#test1"}),
|
|
|
|
s.st.EXPECT().ChannelModes("#test1", "+sk", "somekey"),
|
|
|
|
)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_MODE(ParseLine(":user1!ident1@host1.com MODE #test1 +sk somekey"))
|
2011-11-06 04:56:46 +00:00
|
|
|
|
2015-01-02 12:58:50 +00:00
|
|
|
// Nick modes for Me.
|
2011-11-06 04:56:46 +00:00
|
|
|
gomock.InOrder(
|
|
|
|
s.st.EXPECT().GetChannel("test").Return(nil),
|
2013-02-18 01:36:17 +00:00
|
|
|
s.st.EXPECT().GetNick("test").Return(c.cfg.Me),
|
2015-01-02 12:58:50 +00:00
|
|
|
s.st.EXPECT().Me().Return(c.cfg.Me),
|
|
|
|
s.st.EXPECT().NickModes("test", "+i"),
|
2011-11-06 04:56:46 +00:00
|
|
|
)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_MODE(ParseLine(":test!test@somehost.com MODE test +i"))
|
2011-11-06 04:56:46 +00:00
|
|
|
|
|
|
|
// Check error paths
|
|
|
|
gomock.InOrder(
|
|
|
|
// send a valid user mode that's not us
|
|
|
|
s.st.EXPECT().GetChannel("user1").Return(nil),
|
2015-01-02 12:58:50 +00:00
|
|
|
s.st.EXPECT().GetNick("user1").Return(&state.Nick{Nick: "user1"}),
|
|
|
|
s.st.EXPECT().Me().Return(c.cfg.Me),
|
2011-11-06 04:56:46 +00:00
|
|
|
// Send a random mode for an unknown channel
|
|
|
|
s.st.EXPECT().GetChannel("#test2").Return(nil),
|
|
|
|
s.st.EXPECT().GetNick("#test2").Return(nil),
|
|
|
|
)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_MODE(ParseLine(":user1!ident1@host1.com MODE user1 +w"))
|
|
|
|
c.h_MODE(ParseLine(":user1!ident1@host1.com MODE #test2 +is"))
|
2011-09-09 21:32:55 +00:00
|
|
|
}
|
2011-09-09 22:02:33 +00:00
|
|
|
|
|
|
|
// Test the handler for TOPIC messages
|
|
|
|
func TestTOPIC(t *testing.T) {
|
2011-11-06 04:56:46 +00:00
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
2011-09-09 22:02:33 +00:00
|
|
|
|
2015-01-02 12:58:50 +00:00
|
|
|
// Ensure TOPIC reply calls Topic
|
|
|
|
gomock.InOrder(
|
|
|
|
s.st.EXPECT().GetChannel("#test1").Return(&state.Channel{Name: "#test1"}),
|
|
|
|
s.st.EXPECT().Topic("#test1", "something something"),
|
|
|
|
)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_TOPIC(ParseLine(":user1!ident1@host1.com TOPIC #test1 :something something"))
|
2011-09-09 22:02:33 +00:00
|
|
|
|
|
|
|
// Check error paths -- send a topic for an unknown channel
|
2013-02-16 00:11:39 +00:00
|
|
|
s.st.EXPECT().GetChannel("#test2").Return(nil)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_TOPIC(ParseLine(":user1!ident1@host1.com TOPIC #test2 :dark side"))
|
2011-09-09 22:02:33 +00:00
|
|
|
}
|
2011-09-09 22:03:44 +00:00
|
|
|
|
|
|
|
// Test the handler for 311 / RPL_WHOISUSER
|
|
|
|
func Test311(t *testing.T) {
|
2011-11-06 04:56:46 +00:00
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
2011-09-09 22:03:44 +00:00
|
|
|
|
2015-01-02 12:58:50 +00:00
|
|
|
// Ensure 311 reply calls NickInfo
|
|
|
|
gomock.InOrder(
|
|
|
|
s.st.EXPECT().GetNick("user1").Return(&state.Nick{Nick: "user1"}),
|
|
|
|
s.st.EXPECT().Me().Return(c.cfg.Me),
|
|
|
|
s.st.EXPECT().NickInfo("user1", "ident1", "host1.com", "name"),
|
|
|
|
)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_311(ParseLine(":irc.server.org 311 test user1 ident1 host1.com * :name"))
|
2011-09-09 22:03:44 +00:00
|
|
|
|
|
|
|
// Check error paths -- send a 311 for an unknown nick
|
2013-02-16 00:11:39 +00:00
|
|
|
s.st.EXPECT().GetNick("user2").Return(nil)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_311(ParseLine(":irc.server.org 311 test user2 ident2 host2.com * :dongs"))
|
2011-09-09 22:03:44 +00:00
|
|
|
}
|
2011-09-09 22:24:08 +00:00
|
|
|
|
|
|
|
// Test the handler for 324 / RPL_CHANNELMODEIS
|
|
|
|
func Test324(t *testing.T) {
|
2011-11-06 04:56:46 +00:00
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
2011-09-09 22:24:08 +00:00
|
|
|
|
2015-01-02 12:58:50 +00:00
|
|
|
// Ensure 324 reply calls ChannelModes
|
|
|
|
gomock.InOrder(
|
|
|
|
s.st.EXPECT().GetChannel("#test1").Return(&state.Channel{Name: "#test1"}),
|
|
|
|
s.st.EXPECT().ChannelModes("#test1", "+sk", "somekey"),
|
|
|
|
)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_324(ParseLine(":irc.server.org 324 test #test1 +sk somekey"))
|
2011-09-09 22:24:08 +00:00
|
|
|
|
2013-02-16 00:11:39 +00:00
|
|
|
// Check error paths -- send 324 for an unknown channel
|
|
|
|
s.st.EXPECT().GetChannel("#test2").Return(nil)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_324(ParseLine(":irc.server.org 324 test #test2 +pmt"))
|
2011-09-09 22:24:08 +00:00
|
|
|
}
|
2011-09-09 22:27:45 +00:00
|
|
|
|
|
|
|
// Test the handler for 332 / RPL_TOPIC
|
|
|
|
func Test332(t *testing.T) {
|
2011-11-06 04:56:46 +00:00
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
2011-09-09 22:27:45 +00:00
|
|
|
|
2015-01-02 12:58:50 +00:00
|
|
|
// Ensure 332 reply calls Topic
|
|
|
|
gomock.InOrder(
|
|
|
|
s.st.EXPECT().GetChannel("#test1").Return(&state.Channel{Name: "#test1"}),
|
|
|
|
s.st.EXPECT().Topic("#test1", "something something"),
|
|
|
|
)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_332(ParseLine(":irc.server.org 332 test #test1 :something something"))
|
2011-09-09 22:27:45 +00:00
|
|
|
|
2013-02-16 00:11:39 +00:00
|
|
|
// Check error paths -- send 332 for an unknown channel
|
|
|
|
s.st.EXPECT().GetChannel("#test2").Return(nil)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_332(ParseLine(":irc.server.org 332 test #test2 :dark side"))
|
2011-09-09 22:27:45 +00:00
|
|
|
}
|
2011-09-11 10:01:28 +00:00
|
|
|
|
|
|
|
// Test the handler for 352 / RPL_WHOREPLY
|
|
|
|
func Test352(t *testing.T) {
|
2011-11-06 04:56:46 +00:00
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
2011-09-11 10:01:28 +00:00
|
|
|
|
2015-01-02 12:58:50 +00:00
|
|
|
// Ensure 352 reply calls NickInfo and NickModes
|
|
|
|
gomock.InOrder(
|
|
|
|
s.st.EXPECT().GetNick("user1").Return(&state.Nick{Nick: "user1"}),
|
|
|
|
s.st.EXPECT().Me().Return(c.cfg.Me),
|
|
|
|
s.st.EXPECT().NickInfo("user1", "ident1", "host1.com", "name"),
|
|
|
|
)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_352(ParseLine(":irc.server.org 352 test #test1 ident1 host1.com irc.server.org user1 G :0 name"))
|
2011-09-11 10:01:28 +00:00
|
|
|
|
|
|
|
// Check that modes are set correctly from WHOREPLY
|
2015-01-02 12:58:50 +00:00
|
|
|
gomock.InOrder(
|
|
|
|
s.st.EXPECT().GetNick("user1").Return(&state.Nick{Nick: "user1"}),
|
|
|
|
s.st.EXPECT().Me().Return(c.cfg.Me),
|
|
|
|
s.st.EXPECT().NickInfo("user1", "ident1", "host1.com", "name"),
|
|
|
|
s.st.EXPECT().NickModes("user1", "+o"),
|
|
|
|
s.st.EXPECT().NickModes("user1", "+i"),
|
|
|
|
)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_352(ParseLine(":irc.server.org 352 test #test1 ident1 host1.com irc.server.org user1 H* :0 name"))
|
2011-09-11 10:01:28 +00:00
|
|
|
|
|
|
|
// Check error paths -- send a 352 for an unknown nick
|
2013-02-16 00:11:39 +00:00
|
|
|
s.st.EXPECT().GetNick("user2").Return(nil)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_352(ParseLine(":irc.server.org 352 test #test2 ident2 host2.com irc.server.org user2 G :0 fooo"))
|
2011-09-11 10:01:28 +00:00
|
|
|
}
|
2011-09-12 22:14:08 +00:00
|
|
|
|
|
|
|
// Test the handler for 353 / RPL_NAMREPLY
|
|
|
|
func Test353(t *testing.T) {
|
2011-11-06 04:56:46 +00:00
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
2011-09-12 22:14:08 +00:00
|
|
|
|
2011-11-06 04:56:46 +00:00
|
|
|
// 353 handler is called twice, so GetChannel will be called twice
|
2015-01-02 12:58:50 +00:00
|
|
|
s.st.EXPECT().GetChannel("#test1").Return(&state.Channel{Name: "#test1"}).Times(2)
|
2011-11-06 04:56:46 +00:00
|
|
|
gomock.InOrder(
|
|
|
|
// "test" is Me, i am known, and already on the channel
|
2013-02-18 01:36:17 +00:00
|
|
|
s.st.EXPECT().GetNick("test").Return(c.cfg.Me),
|
2015-01-02 12:58:50 +00:00
|
|
|
s.st.EXPECT().IsOn("#test1", "test").Return(&state.ChanPrivs{}, true),
|
2011-11-06 04:56:46 +00:00
|
|
|
// user1 is known, but not on the channel, so should be associated
|
2015-01-02 12:58:50 +00:00
|
|
|
s.st.EXPECT().GetNick("user1").Return(&state.Nick{Nick: "user1"}),
|
2011-11-06 04:56:46 +00:00
|
|
|
s.st.EXPECT().IsOn("#test1", "user1").Return(nil, false),
|
2015-01-02 12:58:50 +00:00
|
|
|
s.st.EXPECT().Associate("#test1", "user1").Return(&state.ChanPrivs{}),
|
|
|
|
s.st.EXPECT().ChannelModes("#test1", "+o", "user1"),
|
2011-11-06 04:56:46 +00:00
|
|
|
)
|
2015-01-02 12:58:50 +00:00
|
|
|
for n, m := range map[string]string{
|
2015-11-02 21:41:41 +00:00
|
|
|
"user2": "",
|
|
|
|
"voice": "+v",
|
2015-01-02 12:58:50 +00:00
|
|
|
"halfop": "+h",
|
2015-11-02 21:41:41 +00:00
|
|
|
"op": "+o",
|
|
|
|
"admin": "+a",
|
|
|
|
"owner": "+q",
|
2015-01-02 12:58:50 +00:00
|
|
|
} {
|
|
|
|
calls := []*gomock.Call{
|
2011-11-06 04:56:46 +00:00
|
|
|
s.st.EXPECT().GetNick(n).Return(nil),
|
2015-01-02 12:58:50 +00:00
|
|
|
s.st.EXPECT().NewNick(n).Return(&state.Nick{Nick: n}),
|
2011-11-06 04:56:46 +00:00
|
|
|
s.st.EXPECT().IsOn("#test1", n).Return(nil, false),
|
2015-01-02 12:58:50 +00:00
|
|
|
s.st.EXPECT().Associate("#test1", n).Return(&state.ChanPrivs{}),
|
|
|
|
}
|
|
|
|
if m != "" {
|
|
|
|
calls = append(calls, s.st.EXPECT().ChannelModes("#test1", m, n))
|
|
|
|
}
|
|
|
|
gomock.InOrder(calls...)
|
2011-11-06 04:56:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Send a couple of names replies (complete with trailing space)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_353(ParseLine(":irc.server.org 353 test = #test1 :test @user1 user2 +voice "))
|
|
|
|
c.h_353(ParseLine(":irc.server.org 353 test = #test1 :%halfop @op &admin ~owner "))
|
2011-09-12 22:14:08 +00:00
|
|
|
|
2013-02-16 00:11:39 +00:00
|
|
|
// Check error paths -- send 353 for an unknown channel
|
|
|
|
s.st.EXPECT().GetChannel("#test2").Return(nil)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_353(ParseLine(":irc.server.org 353 test = #test2 :test ~user3"))
|
2011-09-12 22:14:08 +00:00
|
|
|
}
|
2011-09-12 22:21:40 +00:00
|
|
|
|
|
|
|
// Test the handler for 671 (unreal specific)
|
|
|
|
func Test671(t *testing.T) {
|
2011-11-06 04:56:46 +00:00
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
2011-09-12 22:21:40 +00:00
|
|
|
|
2015-01-02 12:58:50 +00:00
|
|
|
// Ensure 671 reply calls NickModes
|
|
|
|
gomock.InOrder(
|
|
|
|
s.st.EXPECT().GetNick("user1").Return(&state.Nick{Nick: "user1"}),
|
|
|
|
s.st.EXPECT().NickModes("user1", "+z"),
|
|
|
|
)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_671(ParseLine(":irc.server.org 671 test user1 :some ignored text"))
|
2011-09-12 22:21:40 +00:00
|
|
|
|
|
|
|
// Check error paths -- send a 671 for an unknown nick
|
2013-02-16 00:11:39 +00:00
|
|
|
s.st.EXPECT().GetNick("user2").Return(nil)
|
2014-07-06 18:26:34 +00:00
|
|
|
c.h_671(ParseLine(":irc.server.org 671 test user2 :some ignored text"))
|
2011-09-12 22:21:40 +00:00
|
|
|
}
|
2022-03-06 22:20:06 +00:00
|
|
|
|
|
|
|
func TestCap(t *testing.T) {
|
|
|
|
c, s := setUp(t)
|
|
|
|
defer s.tearDown()
|
|
|
|
|
|
|
|
c.Config().EnableCapabilityNegotiation = true
|
|
|
|
c.Config().Capabilites = []string{"cap1", "cap2", "cap3", "cap4"}
|
|
|
|
|
|
|
|
c.h_REGISTER(&Line{Cmd: REGISTER})
|
|
|
|
s.nc.Expect("CAP LS")
|
|
|
|
s.nc.Expect("NICK test")
|
|
|
|
s.nc.Expect("USER test 12 * :Testing IRC")
|
|
|
|
|
|
|
|
// Ensure that capabilities not supported by the server are not requested
|
|
|
|
s.nc.Send("CAP * LS :cap2 cap4")
|
|
|
|
s.nc.Expect("CAP REQ :cap2 cap4")
|
|
|
|
|
|
|
|
s.nc.Send("CAP * ACK :cap2 cap4")
|
|
|
|
s.nc.Expect("CAP END")
|
|
|
|
|
|
|
|
for _, cap := range []string{"cap2", "cap4"} {
|
|
|
|
if !c.SupportsCapability(cap) {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
|
|
|
if !c.HasCapability(cap) {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, cap := range []string{"cap1", "cap3"} {
|
|
|
|
if c.HasCapability(cap) {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// test disable capability after registration
|
|
|
|
s.c.Cap("REQ", "-cap4")
|
|
|
|
s.nc.Expect("CAP REQ :-cap4")
|
|
|
|
|
|
|
|
s.nc.Send("CAP * ACK :-cap4")
|
|
|
|
s.nc.Expect("CAP END")
|
|
|
|
|
|
|
|
if !c.HasCapability("cap2") {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.HasCapability("cap4") {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|