瀏覽代碼

Test Version. Generate certificate once.

Steve Thielemann 2 年之前
父節點
當前提交
e2eb9ac2a7
共有 2 個文件被更改,包括 15 次插入2 次删除
  1. 3 1
      client_test.go
  2. 12 1
      ircd_test.go

+ 3 - 1
client_test.go

@@ -1,6 +1,7 @@
 package ircclient
 
 import (
+	"fmt"
 	"net"
 	"strconv"
 	"strings"
@@ -179,6 +180,7 @@ func TestConnectAutojoin(t *testing.T) {
 		AutoJoin:    []string{"#chat", "#test"},
 		Flood_Num:   2,
 		Flood_Delay: 10,
+		Version:     "Test",
 	}
 	var listen net.Listener
 	var address string
@@ -206,7 +208,7 @@ func TestConnectAutojoin(t *testing.T) {
 		"PING 12345",
 	}
 	var noticeExpect []string = []string{"Testing",
-		"VERSION red-green.com/irc-client",
+		fmt.Sprintf("VERSION %s red-green.com/irc-client", config.Version),
 		"TIME ",
 		"PING 12345",
 	}

+ 12 - 1
ircd_test.go

@@ -37,6 +37,17 @@ func setupSocket() (listen net.Listener, addr string) {
 	return listener, address
 }
 
+var KeyPair tls.Certificate
+var HasKeyPair bool
+
+func GenerateKeyPair() (keypair tls.Certificate) {
+	if !HasKeyPair {
+		KeyPair = generateKeyPair()
+		HasKeyPair = true
+	}
+	return KeyPair
+}
+
 func generateKeyPair() (keypair tls.Certificate) {
 	// generate test certificate
 	priv, _ := ecdsa.GenerateKey(elliptic.P521(), rand.Reader)
@@ -78,7 +89,7 @@ func setupTLSSocket() (listen net.Listener, addr string) {
 	var listener net.Listener
 	var address string
 	var tlsconfig tls.Config
-	var keypair tls.Certificate = generateKeyPair()
+	var keypair tls.Certificate = GenerateKeyPair()
 
 	tlsconfig.Certificates = make([]tls.Certificate, 0)
 	tlsconfig.Certificates = append(tlsconfig.Certificates, keypair)