check names directly on the User objects in TestHostNameCollision

This commit is contained in:
mik2k2 2022-01-04 16:15:05 +01:00
parent be6a0f69da
commit bd91a245a0

View File

@ -124,51 +124,23 @@ func TestHostNameCollision(t *testing.T) {
// First client // First client
g.Go(func() error { g.Go(func() error {
return sshd.ConnectShell(s.Addr().String(), "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) // second client
name := (<-newUsers).Name()
// Consume the initial buffer if name != "Guest1" {
scanner.Scan() t.Errorf("Second client did not get Guest1 name: %q", name)
actual := stripPrompt(scanner.Text())
expected := " * foo joined. (Connected: 1)\r"
if actual != expected {
t.Errorf("Got %q; expected %q", actual, expected)
} }
// wait for the second client
<-newUsers
scanner.Scan()
actual = scanner.Text()
// This check has to happen second because prompt doesn't always
// get set before the first message.
if !strings.HasPrefix(actual, "[foo] ") {
t.Errorf("First client failed to get 'foo' name: %q", actual)
}
actual = stripPrompt(actual)
expected = " * Guest1 joined. (Connected: 2)\r"
if actual != expected {
t.Errorf("Got %q; expected %q", actual, expected)
}
return nil return nil
}) })
}) })
// Second client // Second client
g.Go(func() error { g.Go(func() error {
// wait for the first client // first client
<-newUsers name := (<-newUsers).Name()
return sshd.ConnectShell(s.Addr().String(), "foo", func(r io.Reader, w io.WriteCloser) error { if name != "foo" {
scanner := bufio.NewScanner(r) t.Errorf("First client did not get foo name: %q", name)
// Consume the initial buffer
scanner.Scan()
scanner.Scan()
scanner.Scan()
actual := scanner.Text()
if !strings.HasPrefix(actual, "[Guest1] ") {
t.Errorf("Second client did not get Guest1 name: %q", actual)
} }
return sshd.ConnectShell(s.Addr().String(), "foo", func(r io.Reader, w io.WriteCloser) error {
return nil return nil
}) })
}) })