mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-09-10 12:50:03 -04:00
managed to reproduce the timeout after updating, hopefully it's the same one
This commit is contained in:
parent
89ee27d930
commit
efe894e021
53
host_test.go
53
host_test.go
@ -85,7 +85,7 @@ func TestHostGetPrompt(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getHost(t *testing.T, auth *Auth) (*sshd.SSHListener, *Host) {
|
func getHost(t *testing.T, auth *Auth) (*sshd.SSHListener, *Host) {
|
||||||
key, err := sshd.NewRandomSigner(512)
|
key, err := sshd.NewRandomSigner(1024)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -312,22 +312,8 @@ func TestHostAllowlistCommand(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHostKick(t *testing.T) {
|
func TestHostKick(t *testing.T) {
|
||||||
key, err := sshd.NewRandomSigner(512)
|
s, host := getHost(t, NewAuth())
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
auth := NewAuth()
|
|
||||||
config := sshd.MakeAuth(auth)
|
|
||||||
config.AddHostKey(key)
|
|
||||||
|
|
||||||
s, err := sshd.ListenSSH("localhost:0", config)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
addr := s.Addr().String()
|
|
||||||
host := NewHost(s, nil)
|
|
||||||
go host.Serve()
|
go host.Serve()
|
||||||
|
|
||||||
g := errgroup.Group{}
|
g := errgroup.Group{}
|
||||||
@ -336,7 +322,7 @@ func TestHostKick(t *testing.T) {
|
|||||||
|
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
// First client
|
// First client
|
||||||
return sshd.ConnectShell(addr, "foo", func(r io.Reader, w io.WriteCloser) error {
|
return sshd.ConnectShell(s.Addr().String(), "foo", func(r io.Reader, w io.WriteCloser) error {
|
||||||
scanner := bufio.NewScanner(r)
|
scanner := bufio.NewScanner(r)
|
||||||
|
|
||||||
// Consume the initial buffer
|
// Consume the initial buffer
|
||||||
@ -373,7 +359,7 @@ func TestHostKick(t *testing.T) {
|
|||||||
|
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
// Second client
|
// Second client
|
||||||
return sshd.ConnectShell(addr, "bar", func(r io.Reader, w io.WriteCloser) error {
|
return sshd.ConnectShell(s.Addr().String(), "bar", func(r io.Reader, w io.WriteCloser) error {
|
||||||
scanner := bufio.NewScanner(r)
|
scanner := bufio.NewScanner(r)
|
||||||
<-connected
|
<-connected
|
||||||
scanner.Scan()
|
scanner.Scan()
|
||||||
@ -411,12 +397,9 @@ func TestTimestampEnvConfig(t *testing.T) {
|
|||||||
{"datetime +8h", strptr("2006-01-02 15:04:05")},
|
{"datetime +8h", strptr("2006-01-02 15:04:05")},
|
||||||
}
|
}
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
u, err := connectUserWithConfig("dingus", map[string]string{
|
u := connectUserWithConfig(t, "dingus", map[string]string{
|
||||||
"SSHCHAT_TIMESTAMP": tc.input,
|
"SSHCHAT_TIMESTAMP": tc.input,
|
||||||
})
|
})
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
userConfig := u.Config()
|
userConfig := u.Config()
|
||||||
if userConfig.Timeformat != nil && tc.timeformat != nil {
|
if userConfig.Timeformat != nil && tc.timeformat != nil {
|
||||||
if *userConfig.Timeformat != *tc.timeformat {
|
if *userConfig.Timeformat != *tc.timeformat {
|
||||||
@ -430,20 +413,9 @@ func strptr(s string) *string {
|
|||||||
return &s
|
return &s
|
||||||
}
|
}
|
||||||
|
|
||||||
func connectUserWithConfig(name string, envConfig map[string]string) (*message.User, error) {
|
func connectUserWithConfig(t *testing.T, name string, envConfig map[string]string) *message.User {
|
||||||
key, err := sshd.NewRandomSigner(512)
|
s, host := getHost(t, nil)
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("unable to create signer: %w", err)
|
|
||||||
}
|
|
||||||
config := sshd.MakeNoAuth()
|
|
||||||
config.AddHostKey(key)
|
|
||||||
|
|
||||||
s, err := sshd.ListenSSH("localhost:0", config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("unable to create a test server: %w", err)
|
|
||||||
}
|
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
host := NewHost(s, nil)
|
|
||||||
|
|
||||||
newUsers := make(chan *message.User)
|
newUsers := make(chan *message.User)
|
||||||
host.OnUserJoined = func(u *message.User) {
|
host.OnUserJoined = func(u *message.User) {
|
||||||
@ -454,13 +426,13 @@ func connectUserWithConfig(name string, envConfig map[string]string) (*message.U
|
|||||||
clientConfig := sshd.NewClientConfig(name)
|
clientConfig := sshd.NewClientConfig(name)
|
||||||
conn, err := ssh.Dial("tcp", s.Addr().String(), clientConfig)
|
conn, err := ssh.Dial("tcp", s.Addr().String(), clientConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to connect to test ssh-chat server: %w", err)
|
t.Fatal("unable to connect to test ssh-chat server:", err)
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
session, err := conn.NewSession()
|
session, err := conn.NewSession()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to open session: %w", err)
|
t.Fatal("unable to open session:", err)
|
||||||
}
|
}
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
|
|
||||||
@ -470,13 +442,14 @@ func connectUserWithConfig(name string, envConfig map[string]string) (*message.U
|
|||||||
|
|
||||||
err = session.Shell()
|
err = session.Shell()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to open shell: %w", err)
|
t.Fatal("unable to open shell:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for u := range newUsers {
|
for u := range newUsers {
|
||||||
if u.Name() == name {
|
if u.Name() == name {
|
||||||
return u, nil
|
return u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("user %s not found in the host", name)
|
t.Fatalf("user %s not found in the host", name)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ func TestServerInit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestServeTerminals(t *testing.T) {
|
func TestServeTerminals(t *testing.T) {
|
||||||
signer, err := NewRandomSigner(512)
|
signer, err := NewRandomSigner(1024)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user