1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
package irc
import (
"crypto/tls"
"os"
"testing"
"time"
)
// set SASLLogin and SASLPassword environment variables before testing
func TestConnectionSASL(t *testing.T) {
SASLServer := "irc.freenode.net:7000"
SASLLogin := os.Getenv("SASLLogin")
SASLPassword := os.Getenv("SASLPassword")
if SASLLogin == "" {
t.Skip("Define SASLLogin and SASLPasword environment varables to test SASL")
}
if testing.Short() {
t.Skip("skipping test in short mode.")
}
irccon := IRC("go-eventirc", "go-eventirc")
irccon.VerboseCallbackHandler = true
irccon.Debug = true
irccon.UseTLS = true
irccon.UseSASL = true
irccon.SASLLogin = SASLLogin
irccon.SASLPassword = SASLPassword
irccon.TLSConfig = &tls.Config{InsecureSkipVerify: true}
irccon.AddCallback("001", func(e *Event) { irccon.Join("#go-eventirc") })
irccon.AddCallback("366", func(e *Event) {
irccon.Privmsg("#go-eventirc", "Test Message SASL\n")
time.Sleep(2 * time.Second)
irccon.Quit()
})
err := irccon.Connect(SASLServer)
if err != nil {
t.Fatalf("SASL failed: %s", err)
}
irccon.Loop()
}
// 1. Register fingerprint with IRC network
// 2. Add SASLKeyPem="-----BEGIN PRIVATE KEY-----..."
// and SASLCertPem="-----BEGIN CERTIFICATE-----..."
// to CI environment as masked variables
func TestConnectionSASLExternal(t *testing.T) {
SASLServer := "irc.freenode.net:7000"
keyPem := os.Getenv("SASLKeyPem")
certPem := os.Getenv("SASLCertPem")
if certPem == "" || keyPem == "" {
t.Skip("Env vars SASLKeyPem SASLCertPem not present, skipping")
}
if testing.Short() {
t.Skip("skipping test in short mode.")
}
cert, err := tls.X509KeyPair([]byte(certPem), []byte(keyPem))
if err != nil {
t.Fatalf("SASL EXTERNAL cert creation failed: %s", err)
}
irccon := IRC("go-eventirc", "go-eventirc")
irccon.VerboseCallbackHandler = true
irccon.Debug = true
irccon.UseTLS = true
irccon.UseSASL = true
irccon.SASLMech = "EXTERNAL"
irccon.TLSConfig = &tls.Config{
InsecureSkipVerify: true,
Certificates: []tls.Certificate{cert},
}
irccon.AddCallback("001", func(e *Event) { irccon.Join("#go-eventirc") })
irccon.AddCallback("366", func(e *Event) {
irccon.Privmsg("#go-eventirc", "Test Message SASL EXTERNAL\n")
time.Sleep(2 * time.Second)
irccon.Quit()
})
err = irccon.Connect(SASLServer)
if err != nil {
t.Fatalf("SASL EXTERNAL failed: %s", err)
}
irccon.Loop()
}
|