ssh-chat/sshd/client_test.go
Andrey Petrov 903d6c9420
/ban query support (#286)
For #285 

Turns out there were some bugs in Set, and I was using it incorrectly too.

The query syntax is a little awkward but couldn't find a nicer easy to parse format that worked with quoted string values.
2018-12-25 14:29:19 -05:00

44 lines
753 B
Go

package sshd
import (
"errors"
"net"
"testing"
"golang.org/x/crypto/ssh"
)
var errRejectAuth = errors.New("not welcome here")
type RejectAuth struct{}
func (a RejectAuth) AllowAnonymous() bool {
return false
}
func (a RejectAuth) Check(net.Addr, ssh.PublicKey, string) error {
return errRejectAuth
}
func TestClientReject(t *testing.T) {
signer, err := NewRandomSigner(512)
if err != nil {
t.Fatal(err)
}
config := MakeAuth(RejectAuth{})
config.AddHostKey(signer)
s, err := ListenSSH("localhost:0", config)
if err != nil {
t.Fatal(err)
}
defer s.Close()
go s.Serve()
conn, err := ssh.Dial("tcp", s.Addr().String(), NewClientConfig("foo"))
if err == nil {
defer conn.Close()
t.Error("Failed to reject conncetion")
}
}