mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-06-07 19:03:17 +03:00
use the same auth (the tests don't seem to care, but htis is more right)
This commit is contained in:
parent
93a8d19281
commit
18a00b66c8
19
host_test.go
19
host_test.go
@ -84,22 +84,28 @@ func TestHostGetPrompt(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHost(t *testing.T, config *ssh.ServerConfig) (*sshd.SSHListener, *Host) {
|
func getHost(t *testing.T, auth *Auth) (*sshd.SSHListener, *Host) {
|
||||||
key, err := sshd.NewRandomSigner(512)
|
key, err := sshd.NewRandomSigner(512)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
var config *ssh.ServerConfig
|
||||||
|
if auth == nil {
|
||||||
|
config = sshd.MakeNoAuth()
|
||||||
|
} else {
|
||||||
|
config = sshd.MakeAuth(auth)
|
||||||
|
}
|
||||||
config.AddHostKey(key)
|
config.AddHostKey(key)
|
||||||
|
|
||||||
s, err := sshd.ListenSSH("localhost:0", config)
|
s, err := sshd.ListenSSH("localhost:0", config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
return s, NewHost(s, NewAuth())
|
return s, NewHost(s, auth)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHostNameCollision(t *testing.T) {
|
func TestHostNameCollision(t *testing.T) {
|
||||||
s, host := getHost(t, sshd.MakeNoAuth())
|
s, host := getHost(t, nil)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
newUsers := make(chan *message.User)
|
newUsers := make(chan *message.User)
|
||||||
@ -169,7 +175,7 @@ func TestHostNameCollision(t *testing.T) {
|
|||||||
|
|
||||||
func TestHostWhitelist(t *testing.T) {
|
func TestHostWhitelist(t *testing.T) {
|
||||||
auth := NewAuth()
|
auth := NewAuth()
|
||||||
s, host := getHost(t, sshd.MakeAuth(auth))
|
s, host := getHost(t, auth)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
go host.Serve()
|
go host.Serve()
|
||||||
|
|
||||||
@ -196,7 +202,7 @@ func TestHostWhitelist(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHostWhitelistCommand(t *testing.T) {
|
func TestHostWhitelistCommand(t *testing.T) {
|
||||||
s, host := getHost(t, sshd.MakeNoAuth())
|
s, host := getHost(t, NewAuth())
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
go host.Serve()
|
go host.Serve()
|
||||||
|
|
||||||
@ -214,7 +220,6 @@ func TestHostWhitelistCommand(t *testing.T) {
|
|||||||
|
|
||||||
scanner := bufio.NewScanner(r)
|
scanner := bufio.NewScanner(r)
|
||||||
scanner.Scan() // Joined
|
scanner.Scan() // Joined
|
||||||
// <- messages
|
|
||||||
|
|
||||||
assertLineEq := func(expected string) {
|
assertLineEq := func(expected string) {
|
||||||
if !scanner.Scan() {
|
if !scanner.Scan() {
|
||||||
@ -245,7 +250,7 @@ func TestHostWhitelistCommand(t *testing.T) {
|
|||||||
if !host.auth.WhitelistMode {
|
if !host.auth.WhitelistMode {
|
||||||
t.Error("whitelist not enabled after /whitelist on")
|
t.Error("whitelist not enabled after /whitelist on")
|
||||||
}
|
}
|
||||||
host.HandleMsg(message.ParseInput("/whitelist off", m.User))
|
sendCmd("/whitelist off")
|
||||||
if host.auth.WhitelistMode {
|
if host.auth.WhitelistMode {
|
||||||
t.Error("whitelist not disabled after /whitelist off")
|
t.Error("whitelist not disabled after /whitelist off")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user