Compare commits
10 Commits
channel_pr
...
v1.6.5
Author | SHA1 | Date | |
---|---|---|---|
![]() |
04d907d1e9 | ||
![]() |
d74a6780fe | ||
![]() |
d7e9ef230a | ||
![]() |
75f224a7c0 | ||
![]() |
caab002d51 | ||
![]() |
7ff892bba9 | ||
![]() |
233238b709 | ||
![]() |
59e0792db1 | ||
![]() |
962b6645c1 | ||
![]() |
cee8bf9957 |
@@ -6,9 +6,15 @@ pipeline:
|
||||
build:
|
||||
image: golang
|
||||
commands:
|
||||
- go get -d
|
||||
- go get -d ./...
|
||||
- go build .
|
||||
|
||||
test:
|
||||
image: golang
|
||||
commands:
|
||||
- go get -d ./...
|
||||
- go test ./...
|
||||
|
||||
docker:
|
||||
image: plugins/docker
|
||||
repo: r.mills.io/prologic/eris
|
||||
|
18
.gitmodules
vendored
18
.gitmodules
vendored
@@ -43,9 +43,15 @@
|
||||
[submodule "vendor/github.com/prometheus/procfs"]
|
||||
path = vendor/github.com/prometheus/procfs
|
||||
url = https://github.com/prometheus/procfs
|
||||
[submodule "vendor/github.com/sasha-s/go-deadlock"]
|
||||
path = vendor/github.com/sasha-s/go-deadlock
|
||||
url = https://github.com/sasha-s/go-deadlock
|
||||
[submodule "vendor/github.com/petermattis/goid"]
|
||||
path = vendor/github.com/petermattis/goid
|
||||
url = https://github.com/petermattis/goid
|
||||
[submodule "vendor/github.com/thoj/go-ircevent"]
|
||||
path = vendor/github.com/thoj/go-ircevent
|
||||
url = https://github.com/thoj/go-ircevent
|
||||
[submodule "vendor/github.com/stretchr/testify"]
|
||||
path = vendor/github.com/stretchr/testify
|
||||
url = https://github.com/stretchr/testify
|
||||
[submodule "vendor/github.com/renstrom/shortuuid"]
|
||||
path = vendor/github.com/renstrom/shortuuid
|
||||
url = https://github.com/renstrom/shortuuid
|
||||
[submodule "vendor/github.com/satori/go.uuid"]
|
||||
path = vendor/github.com/satori/go.uuid
|
||||
url = https://github.com/satori/go.uuid
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# eris - IRC Server / Daemon written in Go
|
||||
:set spell eris - IRC Server / Daemon written in Go
|
||||
|
||||
[](https://travis-ci.org/prologic/eris)
|
||||
[](https://goreportcard.com/report/github.com/prologic/eris)
|
||||
@@ -25,7 +25,7 @@ The connotation here is that IRC (*Internet Relay Chat*) is a place of chaos,
|
||||
strife and discord. IRC is a place where you argue and get into arguments for
|
||||
the sake of argument.
|
||||
|
||||
So `eris` is an IRC daemon written from scratch in Go to factiliate discord
|
||||
So `eris` is an IRC daemon written from scratch in Go to facilitate discord
|
||||
and have arguments for the sake of argument!
|
||||
|
||||
Pull requests and issues are welcome.
|
||||
@@ -35,9 +35,9 @@ Discussion at:
|
||||
* /server irc.mills.io +6697 (*use TLS/SSL*)
|
||||
* /join #lobby
|
||||
|
||||
Or (*not recommended*)P
|
||||
Or (**not recommended**):
|
||||
|
||||
* /server irc.mills.io (*default port 6667, non-TLS)
|
||||
* /server irc.mills.io (*default port 6667, non-TLS*)
|
||||
* /join #lobby
|
||||
|
||||
## Features
|
||||
@@ -54,6 +54,7 @@ Or (*not recommended*)P
|
||||
* Simple IRC operator privileges (*overrides most things*)
|
||||
* Secure connection tracking (+z) and SecureOnly user mode (+Z)
|
||||
* Secure channels (+Z)
|
||||
* Three layers of channel privacy, Public, Private (+p) and Secret (s)
|
||||
|
||||
## Quick Start
|
||||
|
||||
|
@@ -374,7 +374,7 @@ func (channel *Channel) applyMode(client *Client, change *ChannelModeChange) boo
|
||||
return channel.applyModeMask(client, change.mode, change.op,
|
||||
NewName(change.arg))
|
||||
|
||||
case InviteOnly, Moderated, NoOutside, OpOnlyTopic, Private, SecureChan:
|
||||
case InviteOnly, Moderated, NoOutside, OpOnlyTopic, Private, Secret, SecureChan:
|
||||
return channel.applyModeFlag(client, change.mode, change.op)
|
||||
|
||||
case Key:
|
||||
|
@@ -72,8 +72,17 @@ func NewClient(server *Server, conn net.Conn) *Client {
|
||||
//
|
||||
|
||||
func (client *Client) writeloop() {
|
||||
for reply := range client.replies {
|
||||
client.socket.Write(reply)
|
||||
for {
|
||||
select {
|
||||
case reply, ok := <-client.replies:
|
||||
if !ok || reply == "" || client.socket == nil {
|
||||
return
|
||||
}
|
||||
client.socket.Write(reply)
|
||||
}
|
||||
if client.replies == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,13 +128,6 @@ func (client *Client) readloop() {
|
||||
}
|
||||
|
||||
func (client *Client) processCommand(cmd Command) {
|
||||
client.server.metrics.Counter("client", "commands").Inc()
|
||||
|
||||
defer func(t time.Time) {
|
||||
v := client.server.metrics.SummaryVec("client", "command_duration_seconds")
|
||||
v.WithLabelValues(cmd.Code().String()).Observe(time.Now().Sub(t).Seconds())
|
||||
}(time.Now())
|
||||
|
||||
cmd.SetClient(client)
|
||||
|
||||
if !client.registered {
|
||||
@@ -144,6 +146,13 @@ func (client *Client) processCommand(cmd Command) {
|
||||
return
|
||||
}
|
||||
|
||||
client.server.metrics.Counter("client", "commands").Inc()
|
||||
|
||||
defer func(t time.Time) {
|
||||
v := client.server.metrics.SummaryVec("client", "command_duration_seconds")
|
||||
v.WithLabelValues(cmd.Code().String()).Observe(time.Now().Sub(t).Seconds())
|
||||
}(time.Now())
|
||||
|
||||
switch srvCmd.(type) {
|
||||
case *PingCommand, *PongCommand:
|
||||
client.Touch()
|
||||
|
@@ -4,9 +4,7 @@ import (
|
||||
"errors"
|
||||
"regexp"
|
||||
"strings"
|
||||
//"sync"
|
||||
|
||||
sync "github.com/sasha-s/go-deadlock"
|
||||
"sync"
|
||||
|
||||
"github.com/DanielOaks/girc-go/ircmatch"
|
||||
)
|
||||
|
@@ -4,9 +4,7 @@ import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
//"sync"
|
||||
|
||||
sync "github.com/sasha-s/go-deadlock"
|
||||
"sync"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
@@ -70,7 +70,6 @@ var (
|
||||
)
|
||||
|
||||
const (
|
||||
Anonymous ChannelMode = 'a' // flag
|
||||
BanMask ChannelMode = 'b' // arg
|
||||
ChannelCreator ChannelMode = 'O' // flag
|
||||
ChannelOperator ChannelMode = 'o' // arg
|
||||
@@ -82,8 +81,6 @@ const (
|
||||
NoOutside ChannelMode = 'n' // flag
|
||||
OpOnlyTopic ChannelMode = 't' // flag
|
||||
Private ChannelMode = 'p' // flag
|
||||
Quiet ChannelMode = 'q' // flag
|
||||
ReOp ChannelMode = 'r' // flag
|
||||
Secret ChannelMode = 's' // flag, deprecated
|
||||
UserLimit ChannelMode = 'l' // flag arg
|
||||
Voice ChannelMode = 'v' // arg
|
||||
@@ -93,7 +90,7 @@ const (
|
||||
var (
|
||||
SupportedChannelModes = ChannelModes{
|
||||
BanMask, ExceptMask, InviteMask, InviteOnly, Key, NoOutside,
|
||||
OpOnlyTopic, Private, UserLimit, SecureChan,
|
||||
OpOnlyTopic, Private, UserLimit, Secret, SecureChan,
|
||||
}
|
||||
)
|
||||
|
||||
|
@@ -4,9 +4,8 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
//"sync"
|
||||
"sync"
|
||||
|
||||
sync "github.com/sasha-s/go-deadlock"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
22
irc/privacy.go
Normal file
22
irc/privacy.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package irc
|
||||
|
||||
func CanSeeChannel(client *Client, channel *Channel) bool {
|
||||
isPrivate := channel.flags.Has(Private)
|
||||
isSecret := channel.flags.Has(Secret)
|
||||
|
||||
isMember := channel.members.Has(client)
|
||||
isOperator := client.flags[Operator]
|
||||
isRegistered := client.flags[Registered]
|
||||
isSecure := client.flags[SecureConn]
|
||||
|
||||
if !(isSecret || isPrivate) {
|
||||
return true
|
||||
}
|
||||
if isSecret && (isMember || isOperator) {
|
||||
return true
|
||||
}
|
||||
if isPrivate && (isMember || isOperator || (isRegistered && isSecure)) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
17
irc/reply.go
17
irc/reply.go
@@ -489,8 +489,13 @@ func (target *Client) RplMOTDEnd() {
|
||||
}
|
||||
|
||||
func (target *Client) RplList(channel *Channel) {
|
||||
target.NumericReply(RPL_LIST,
|
||||
"%s %d :%s", channel, channel.members.Count(), channel.topic)
|
||||
target.NumericReply(
|
||||
RPL_LIST,
|
||||
"%s %d :%s",
|
||||
channel,
|
||||
channel.members.Count(),
|
||||
channel.topic,
|
||||
)
|
||||
}
|
||||
|
||||
func (target *Client) RplListEnd(server *Server) {
|
||||
@@ -504,8 +509,12 @@ func (target *Client) RplNamReply(channel *Channel) {
|
||||
}
|
||||
|
||||
func (target *Client) RplWhoisChannels(client *Client) {
|
||||
target.MultilineReply(client.WhoisChannelsNames(), RPL_WHOISCHANNELS,
|
||||
"%s :%s", client.Nick())
|
||||
target.MultilineReply(
|
||||
client.WhoisChannelsNames(target),
|
||||
RPL_WHOISCHANNELS,
|
||||
"%s :%s",
|
||||
client.Nick(),
|
||||
)
|
||||
}
|
||||
|
||||
func (target *Client) RplVersion() {
|
||||
|
@@ -2,9 +2,7 @@ package irc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
//"sync"
|
||||
|
||||
sync "github.com/sasha-s/go-deadlock"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type SaslState struct {
|
||||
|
@@ -202,6 +202,10 @@ func (server *Server) Shutdown() {
|
||||
server.Global("shutting down...")
|
||||
}
|
||||
|
||||
func (server *Server) Stop() {
|
||||
server.done <- true
|
||||
}
|
||||
|
||||
func (server *Server) Run() {
|
||||
for {
|
||||
select {
|
||||
@@ -212,7 +216,7 @@ func (server *Server) Run() {
|
||||
// Give at least 1s for clients to see the shutdown
|
||||
go func() {
|
||||
time.Sleep(1 * time.Second)
|
||||
server.done <- true
|
||||
server.Stop()
|
||||
}()
|
||||
|
||||
case conn := <-server.newConns:
|
||||
@@ -625,10 +629,14 @@ func (msg *PrivMsgCommand) HandleServer(server *Server) {
|
||||
}
|
||||
}
|
||||
|
||||
func (client *Client) WhoisChannelsNames() []string {
|
||||
func (client *Client) WhoisChannelsNames(target *Client) []string {
|
||||
chstrs := make([]string, client.channels.Count())
|
||||
index := 0
|
||||
client.channels.Range(func(channel *Channel) bool {
|
||||
if !CanSeeChannel(target, channel) {
|
||||
return true
|
||||
}
|
||||
|
||||
switch {
|
||||
case channel.members.Get(client).Has(ChannelOperator):
|
||||
chstrs[index] = "@" + channel.name.String()
|
||||
@@ -835,7 +843,7 @@ func (msg *ListCommand) HandleServer(server *Server) {
|
||||
|
||||
if len(msg.channels) == 0 {
|
||||
server.channels.Range(func(name Name, channel *Channel) bool {
|
||||
if !client.flags[Operator] && channel.flags.Has(Private) {
|
||||
if !CanSeeChannel(client, channel) {
|
||||
return true
|
||||
}
|
||||
client.RplList(channel)
|
||||
@@ -844,7 +852,7 @@ func (msg *ListCommand) HandleServer(server *Server) {
|
||||
} else {
|
||||
for _, chname := range msg.channels {
|
||||
channel := server.channels.Get(chname)
|
||||
if channel == nil || (!client.flags[Operator] && channel.flags.Has(Private)) {
|
||||
if channel == nil || !CanSeeChannel(client, channel) {
|
||||
client.ErrNoSuchChannel(chname)
|
||||
continue
|
||||
}
|
||||
|
@@ -3,9 +3,7 @@ package irc
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
//"sync"
|
||||
|
||||
sync "github.com/sasha-s/go-deadlock"
|
||||
"sync"
|
||||
)
|
||||
|
||||
//
|
||||
|
@@ -9,7 +9,7 @@ var (
|
||||
Package = "eris"
|
||||
|
||||
// Version release version
|
||||
Version = "1.6.2"
|
||||
Version = "1.6.4"
|
||||
|
||||
// Build will be overwritten automatically by the build system
|
||||
Build = "dev"
|
||||
|
@@ -1,9 +1,7 @@
|
||||
package irc
|
||||
|
||||
import (
|
||||
//"sync"
|
||||
|
||||
sync "github.com/sasha-s/go-deadlock"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type WhoWasList struct {
|
||||
|
498
main_test.go
Normal file
498
main_test.go
Normal file
@@ -0,0 +1,498 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/renstrom/shortuuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/thoj/go-ircevent"
|
||||
|
||||
eris "github.com/prologic/eris/irc"
|
||||
)
|
||||
|
||||
const (
|
||||
TIMEOUT = 3 * time.Second
|
||||
)
|
||||
|
||||
var (
|
||||
server *eris.Server
|
||||
|
||||
debug = flag.Bool("d", false, "enable debug logging")
|
||||
)
|
||||
|
||||
func setupServer() *eris.Server {
|
||||
config := &eris.Config{}
|
||||
|
||||
config.Network.Name = "Test"
|
||||
config.Server.Name = "test"
|
||||
config.Server.Description = "Test"
|
||||
config.Server.Listen = []string{":6667"}
|
||||
|
||||
// SASL
|
||||
config.Account = map[string]*eris.PassConfig{
|
||||
"admin": &eris.PassConfig{"JDJhJDA0JGtUU1JVc1JOUy9DbEh1WEdvYVlMdGVnclp6YnA3NDBOZGY1WUZhdTZtRzVmb1VKdXQ5ckZD"},
|
||||
}
|
||||
|
||||
server := eris.NewServer(config)
|
||||
|
||||
go server.Run()
|
||||
|
||||
return server
|
||||
}
|
||||
|
||||
func randomValidName() string {
|
||||
var name eris.Name
|
||||
for {
|
||||
name = eris.NewName(shortuuid.New())
|
||||
if name.IsNickname() {
|
||||
break
|
||||
}
|
||||
}
|
||||
return name.String()
|
||||
}
|
||||
|
||||
func newClient(start bool) *irc.Connection {
|
||||
name := randomValidName()
|
||||
client := irc.IRC(name, name)
|
||||
client.RealName = fmt.Sprintf("Test Client: %s", name)
|
||||
|
||||
err := client.Connect("localhost:6667")
|
||||
if err != nil {
|
||||
log.Fatalf("error setting up test client: %s", err)
|
||||
}
|
||||
|
||||
if start {
|
||||
go client.Loop()
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
flag.Parse()
|
||||
|
||||
if *debug {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
} else {
|
||||
log.SetLevel(log.WarnLevel)
|
||||
}
|
||||
|
||||
server = setupServer()
|
||||
|
||||
result := m.Run()
|
||||
|
||||
server.Stop()
|
||||
|
||||
os.Exit(result)
|
||||
}
|
||||
|
||||
func TestConnection(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
expected := true
|
||||
actual := make(chan bool)
|
||||
|
||||
client := newClient(false)
|
||||
|
||||
client.AddCallback("001", func(e *irc.Event) {
|
||||
actual <- true
|
||||
})
|
||||
|
||||
defer client.Quit()
|
||||
go client.Loop()
|
||||
|
||||
select {
|
||||
case res := <-actual:
|
||||
assert.Equal(expected, res)
|
||||
case <-time.After(TIMEOUT):
|
||||
assert.Fail("timeout")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSASL(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
expected := true
|
||||
actual := make(chan bool)
|
||||
|
||||
client := newClient(false)
|
||||
client.SASLLogin = "admin"
|
||||
client.SASLPassword = "admin"
|
||||
|
||||
client.AddCallback("001", func(e *irc.Event) {
|
||||
actual <- true
|
||||
})
|
||||
|
||||
defer client.Quit()
|
||||
go client.Loop()
|
||||
|
||||
select {
|
||||
case res := <-actual:
|
||||
assert.Equal(expected, res)
|
||||
case <-time.After(TIMEOUT):
|
||||
assert.Fail("timeout")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRplWelcome(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
expected := "Welcome to the .* Internet Relay Network .*!.*@.*"
|
||||
actual := make(chan string)
|
||||
|
||||
client := newClient(false)
|
||||
|
||||
client.AddCallback("001", func(e *irc.Event) {
|
||||
actual <- e.Message()
|
||||
})
|
||||
|
||||
defer client.Quit()
|
||||
go client.Loop()
|
||||
|
||||
select {
|
||||
case res := <-actual:
|
||||
assert.Regexp(expected, res)
|
||||
case <-time.After(TIMEOUT):
|
||||
assert.Fail("timeout")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUser_JOIN(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
client := newClient(false)
|
||||
|
||||
expected := []string{client.GetNick(), "=", "#join", fmt.Sprintf("@%s", client.GetNick())}
|
||||
actual := make(chan string)
|
||||
|
||||
client.AddCallback("353", func(e *irc.Event) {
|
||||
for i := range e.Arguments {
|
||||
actual <- e.Arguments[i]
|
||||
}
|
||||
})
|
||||
|
||||
defer client.Quit()
|
||||
go client.Loop()
|
||||
|
||||
client.Join("#join")
|
||||
client.SendRaw("NAMES #join")
|
||||
|
||||
for i := range expected {
|
||||
select {
|
||||
case res := <-actual:
|
||||
assert.Equal(expected[i], res)
|
||||
case <-time.After(TIMEOUT):
|
||||
assert.Fail("timeout")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestChannel_InviteOnly(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
expected := true
|
||||
actual := make(chan bool)
|
||||
|
||||
client1 := newClient(false)
|
||||
client2 := newClient(false)
|
||||
|
||||
client1.AddCallback("324", func(e *irc.Event) {
|
||||
if strings.Contains(e.Arguments[2], "i") {
|
||||
client2.Join("#inviteonly")
|
||||
} else {
|
||||
client1.Mode("#inviteonly")
|
||||
}
|
||||
})
|
||||
|
||||
client2.AddCallback("473", func(e *irc.Event) {
|
||||
actual <- true
|
||||
})
|
||||
client2.AddCallback("JOIN", func(e *irc.Event) {
|
||||
actual <- false
|
||||
})
|
||||
|
||||
defer client1.Quit()
|
||||
defer client2.Quit()
|
||||
go client1.Loop()
|
||||
go client2.Loop()
|
||||
|
||||
client1.Join("#inviteonly")
|
||||
client1.Mode("#inviteonly", "+i")
|
||||
client1.Mode("#inviteonly")
|
||||
|
||||
select {
|
||||
case res := <-actual:
|
||||
assert.Equal(expected, res)
|
||||
case <-time.After(TIMEOUT):
|
||||
assert.Fail("timeout")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUser_PRIVMSG(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
expected := "Hello World!"
|
||||
actual := make(chan string)
|
||||
|
||||
client1 := newClient(false)
|
||||
client2 := newClient(false)
|
||||
|
||||
client1.AddCallback("001", func(e *irc.Event) {
|
||||
client1.Privmsg(client2.GetNick(), expected)
|
||||
|
||||
})
|
||||
client1.AddCallback("PRIVMSG", func(e *irc.Event) {
|
||||
actual <- e.Message()
|
||||
})
|
||||
|
||||
client2.AddCallback("001", func(e *irc.Event) {
|
||||
client2.Privmsg(client1.GetNick(), expected)
|
||||
})
|
||||
client2.AddCallback("PRIVMSG", func(e *irc.Event) {
|
||||
actual <- e.Message()
|
||||
})
|
||||
|
||||
defer client1.Quit()
|
||||
defer client2.Quit()
|
||||
go client1.Loop()
|
||||
go client2.Loop()
|
||||
|
||||
select {
|
||||
case res := <-actual:
|
||||
assert.Equal(expected, res)
|
||||
case <-time.After(TIMEOUT):
|
||||
assert.Fail("timeout")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChannel_PRIVMSG(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
expected := "Hello World!"
|
||||
actual := make(chan string)
|
||||
|
||||
client1 := newClient(false)
|
||||
client2 := newClient(false)
|
||||
|
||||
client1.AddCallback("JOIN", func(e *irc.Event) {
|
||||
client1.Privmsg(e.Arguments[0], expected)
|
||||
})
|
||||
client2.AddCallback("JOIN", func(e *irc.Event) {
|
||||
client2.Privmsg(e.Arguments[0], expected)
|
||||
})
|
||||
|
||||
client1.AddCallback("PRIVMSG", func(e *irc.Event) {
|
||||
actual <- e.Message()
|
||||
})
|
||||
client2.AddCallback("PRIVMSG", func(e *irc.Event) {
|
||||
actual <- e.Message()
|
||||
})
|
||||
|
||||
defer client1.Quit()
|
||||
defer client2.Quit()
|
||||
go client1.Loop()
|
||||
go client2.Loop()
|
||||
|
||||
client1.Join("#channelprivmsg")
|
||||
client2.Join("#channelprivmsg")
|
||||
|
||||
select {
|
||||
case res := <-actual:
|
||||
assert.Equal(expected, res)
|
||||
case <-time.After(TIMEOUT):
|
||||
assert.Fail("timeout")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChannel_NoExternal(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
expected := true
|
||||
actual := make(chan bool)
|
||||
|
||||
client1 := newClient(true)
|
||||
client2 := newClient(true)
|
||||
|
||||
client1.AddCallback("JOIN", func(e *irc.Event) {
|
||||
channel := e.Arguments[0]
|
||||
if channel == "#noexternal" {
|
||||
if e.Nick == client1.GetNick() {
|
||||
client2.Privmsg("#noexternal", "FooBar!")
|
||||
} else {
|
||||
assert.Fail(fmt.Sprintf("unexpected user %s joined %s", e.Nick, channel))
|
||||
}
|
||||
} else {
|
||||
assert.Fail(fmt.Sprintf("unexpected channel %s", channel))
|
||||
}
|
||||
})
|
||||
|
||||
client2.AddCallback("PRIVMSG", func(e *irc.Event) {
|
||||
if e.Arguments[0] == "#noexternal" {
|
||||
actual <- false
|
||||
}
|
||||
})
|
||||
client2.AddCallback("404", func(e *irc.Event) {
|
||||
actual <- true
|
||||
})
|
||||
|
||||
defer client1.Quit()
|
||||
defer client2.Quit()
|
||||
go client1.Loop()
|
||||
go client2.Loop()
|
||||
|
||||
client1.Join("#noexternal")
|
||||
|
||||
select {
|
||||
case res := <-actual:
|
||||
assert.Equal(expected, res)
|
||||
case <-time.After(TIMEOUT):
|
||||
assert.Fail("timeout")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChannel_SetTopic_InvalidChannel(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
expected := true
|
||||
actual := make(chan bool)
|
||||
|
||||
client1 := newClient(false)
|
||||
|
||||
client1.AddCallback("403", func(e *irc.Event) {
|
||||
actual <- true
|
||||
})
|
||||
|
||||
defer client1.Quit()
|
||||
go client1.Loop()
|
||||
|
||||
client1.SendRaw("TOPIC #invalidchannel :FooBar")
|
||||
|
||||
select {
|
||||
case res := <-actual:
|
||||
assert.Equal(expected, res)
|
||||
case <-time.After(TIMEOUT):
|
||||
assert.Fail("timeout")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChannel_SetTopic_NotOnChannel(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
expected := true
|
||||
actual := make(chan bool)
|
||||
|
||||
client1 := newClient(false)
|
||||
client2 := newClient(false)
|
||||
|
||||
client1.AddCallback("442", func(e *irc.Event) {
|
||||
actual <- true
|
||||
})
|
||||
client2.AddCallback("JOIN", func(e *irc.Event) {
|
||||
client1.SendRaw("TOPIC #notonchannel :FooBar")
|
||||
})
|
||||
|
||||
defer client1.Quit()
|
||||
go client1.Loop()
|
||||
|
||||
client2.Join("#notonchannel")
|
||||
|
||||
select {
|
||||
case res := <-actual:
|
||||
assert.Equal(expected, res)
|
||||
case <-time.After(TIMEOUT):
|
||||
assert.Fail("timeout")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChannel_BadChannelKey(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
expected := true
|
||||
actual := make(chan bool)
|
||||
|
||||
client1 := newClient(false)
|
||||
client2 := newClient(false)
|
||||
|
||||
client1.AddCallback("324", func(e *irc.Event) {
|
||||
if strings.Contains(e.Arguments[2], "k") {
|
||||
client2.Join(e.Arguments[1])
|
||||
} else {
|
||||
client1.Mode("#badchannelkey")
|
||||
}
|
||||
})
|
||||
|
||||
client2.AddCallback("JOIN", func(e *irc.Event) {
|
||||
if e.Nick == client2.GetNick() && e.Arguments[0] == "#badchannelkey" {
|
||||
actual <- false
|
||||
}
|
||||
})
|
||||
client2.AddCallback("475", func(e *irc.Event) {
|
||||
actual <- true
|
||||
})
|
||||
|
||||
defer client1.Quit()
|
||||
defer client2.Quit()
|
||||
go client1.Loop()
|
||||
go client2.Loop()
|
||||
|
||||
client1.Join("#badchannelkey")
|
||||
client1.Mode("#badchannelkey", "+k", "opensesame")
|
||||
client1.Mode("#badchannelkey")
|
||||
|
||||
select {
|
||||
case res := <-actual:
|
||||
assert.Equal(expected, res)
|
||||
case <-time.After(TIMEOUT):
|
||||
assert.Fail("timeout")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChannel_GoodChannelKey(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
expected := true
|
||||
actual := make(chan bool)
|
||||
|
||||
client1 := newClient(true)
|
||||
client2 := newClient(true)
|
||||
|
||||
client1.AddCallback("324", func(e *irc.Event) {
|
||||
if strings.Contains(e.Arguments[2], "k") {
|
||||
client2.SendRawf("JOIN %s :opensesame", e.Arguments[1])
|
||||
} else {
|
||||
client1.Mode("#goodchannelkey")
|
||||
}
|
||||
})
|
||||
|
||||
client2.AddCallback("JOIN", func(e *irc.Event) {
|
||||
if e.Nick == client2.GetNick() && e.Arguments[0] == "#goodchannelkey" {
|
||||
actual <- true
|
||||
}
|
||||
})
|
||||
client2.AddCallback("475", func(e *irc.Event) {
|
||||
actual <- false
|
||||
})
|
||||
|
||||
defer client1.Quit()
|
||||
defer client2.Quit()
|
||||
go client1.Loop()
|
||||
go client2.Loop()
|
||||
|
||||
client1.Join("#goodchannelkey")
|
||||
client1.Mode("#goodchannelkey", "+k", "opensesame")
|
||||
client1.Mode("#goodchannelkey")
|
||||
|
||||
select {
|
||||
case res := <-actual:
|
||||
assert.Equal(expected, res)
|
||||
case <-time.After(TIMEOUT):
|
||||
assert.Fail("timeout")
|
||||
}
|
||||
}
|
1
vendor/github.com/petermattis/goid
generated
vendored
1
vendor/github.com/petermattis/goid
generated
vendored
Submodule vendor/github.com/petermattis/goid deleted from 3db12ebb2a
2
vendor/github.com/prometheus/client_golang
generated
vendored
2
vendor/github.com/prometheus/client_golang
generated
vendored
Submodule vendor/github.com/prometheus/client_golang updated: 1cdba8fdde...661e31bf84
1
vendor/github.com/renstrom/shortuuid
generated
vendored
Submodule
1
vendor/github.com/renstrom/shortuuid
generated
vendored
Submodule
Submodule vendor/github.com/renstrom/shortuuid added at d728e00b72
1
vendor/github.com/sasha-s/go-deadlock
generated
vendored
1
vendor/github.com/sasha-s/go-deadlock
generated
vendored
Submodule vendor/github.com/sasha-s/go-deadlock deleted from 565eb44395
1
vendor/github.com/satori/go.uuid
generated
vendored
Submodule
1
vendor/github.com/satori/go.uuid
generated
vendored
Submodule
Submodule vendor/github.com/satori/go.uuid added at 5bf94b69c6
1
vendor/github.com/stretchr/testify
generated
vendored
Submodule
1
vendor/github.com/stretchr/testify
generated
vendored
Submodule
Submodule vendor/github.com/stretchr/testify added at 2aa2c176b9
1
vendor/github.com/thoj/go-ircevent
generated
vendored
Submodule
1
vendor/github.com/thoj/go-ircevent
generated
vendored
Submodule
Submodule vendor/github.com/thoj/go-ircevent added at db5bd176f7
2
vendor/golang.org/x/crypto
generated
vendored
2
vendor/golang.org/x/crypto
generated
vendored
Submodule vendor/golang.org/x/crypto updated: b080dc9a8c...94eea52f7b
2
vendor/golang.org/x/sys
generated
vendored
2
vendor/golang.org/x/sys
generated
vendored
Submodule vendor/golang.org/x/sys updated: 4ff8c001ce...8b4580aae2
2
vendor/golang.org/x/text
generated
vendored
2
vendor/golang.org/x/text
generated
vendored
Submodule vendor/golang.org/x/text updated: 88f656faf3...556d234e9c
Reference in New Issue
Block a user