mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-06-06 18:33:05 +03:00
refactor: fixed failing tests
This commit is contained in:
parent
01b989cab2
commit
a22d9380e4
@ -143,7 +143,7 @@ func (r *Room) Join(m Member) (*roomMember, error) {
|
|||||||
Member: m,
|
Member: m,
|
||||||
Ignored: set.New(),
|
Ignored: set.New(),
|
||||||
}
|
}
|
||||||
err := r.Members.Add(set.Itemize(m.ID(), member))
|
err := r.Members.AddNew(set.Itemize(m.ID(), member))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
3
host.go
3
host.go
@ -187,6 +187,9 @@ func (h *Host) addClient(user *message.User, conn sshd.Connection) *Client {
|
|||||||
timestamp: time.Now(),
|
timestamp: time.Now(),
|
||||||
}
|
}
|
||||||
h.mu.Lock()
|
h.mu.Lock()
|
||||||
|
if _, ok := h.clients[user]; ok {
|
||||||
|
logger.Warningf("user collision: %q", user)
|
||||||
|
}
|
||||||
h.clients[user] = append(h.clients[user], client)
|
h.clients[user] = append(h.clients[user], client)
|
||||||
h.mu.Unlock()
|
h.mu.Unlock()
|
||||||
return &client
|
return &client
|
||||||
|
24
host_test.go
24
host_test.go
@ -5,6 +5,7 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
@ -63,6 +64,8 @@ func TestHostNameCollision(t *testing.T) {
|
|||||||
|
|
||||||
done := make(chan struct{}, 1)
|
done := make(chan struct{}, 1)
|
||||||
|
|
||||||
|
canary := "canarystring"
|
||||||
|
|
||||||
// First client
|
// First client
|
||||||
go func() {
|
go func() {
|
||||||
err := sshd.ConnectShell(s.Addr().String(), "foo", func(r io.Reader, w io.WriteCloser) error {
|
err := sshd.ConnectShell(s.Addr().String(), "foo", func(r io.Reader, w io.WriteCloser) error {
|
||||||
@ -92,8 +95,10 @@ func TestHostNameCollision(t *testing.T) {
|
|||||||
t.Errorf("Got %q; expected %q", actual, expected)
|
t.Errorf("Got %q; expected %q", actual, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(w, canary+message.Newline)
|
||||||
|
|
||||||
|
<-done
|
||||||
// Wrap it up.
|
// Wrap it up.
|
||||||
close(done)
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -108,16 +113,23 @@ func TestHostNameCollision(t *testing.T) {
|
|||||||
err = sshd.ConnectShell(s.Addr().String(), "foo", func(r io.Reader, w io.WriteCloser) error {
|
err = 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
|
// Scan until we see our canarystring
|
||||||
scanner.Scan()
|
for scanner.Scan() {
|
||||||
scanner.Scan()
|
s := scanner.Text()
|
||||||
scanner.Scan()
|
if strings.HasSuffix(s, canary) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send an empty prompt to allow for a full line scan with EOL.
|
||||||
|
fmt.Fprintf(w, message.Newline)
|
||||||
|
|
||||||
|
scanner.Scan()
|
||||||
actual := scanner.Text()
|
actual := scanner.Text()
|
||||||
if !strings.HasPrefix(actual, "[Guest1] ") {
|
if !strings.HasPrefix(actual, "[Guest1] ") {
|
||||||
// FIXME: Flaky?
|
|
||||||
t.Errorf("Second client did not get Guest1 name: %q", actual)
|
t.Errorf("Second client did not get Guest1 name: %q", actual)
|
||||||
}
|
}
|
||||||
|
close(done)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user