mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-13 07:37:17 +03:00
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.
44 lines
753 B
Go
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")
|
|
}
|
|
}
|