Skip to content

Commit a27433e

Browse files
author
Aaron
committed
Create motd test for regular user w/ no parameters
1 parent 2182105 commit a27433e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

host_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,54 @@ func TestHostNameCollision(t *testing.T) {
132132
<-done
133133
}
134134

135+
func TestMotdCommand(t *testing.T) {
136+
key, err := sshd.NewRandomSigner(512)
137+
if err != nil {
138+
t.Fatal(err)
139+
}
140+
141+
auth := NewAuth()
142+
config := sshd.MakeAuth(auth)
143+
config.AddHostKey(key)
144+
145+
s, err := sshd.ListenSSH("localhost:0", config)
146+
if err != nil {
147+
t.Fatal(err)
148+
}
149+
defer s.Close()
150+
host := NewHost(s, auth)
151+
go host.Serve()
152+
153+
err = sshd.ConnectShell(s.Addr().String(), "baz", func(r io.Reader, w io.WriteCloser) error {
154+
if err != nil {
155+
t.Error(err)
156+
}
157+
member, _ := host.Room.MemberById("baz")
158+
if member == nil {
159+
return errors.New("failed to load MemberById")
160+
}
161+
162+
scanner := bufio.NewScanner(r)
163+
testMotd := "foobar"
164+
host.motd = testMotd
165+
166+
// Test as regular user with no parameters - expected behaviour: should print the MOTD
167+
w.Write([]byte("/motd\r\n"))
168+
169+
// Consuming buffer
170+
nextScanToken(scanner, 3)
171+
172+
actual := scanner.Text()
173+
actual = stripPrompt(actual)[3:]
174+
expected := "foobar"
175+
if strings.Compare(actual, expected) != 0 {
176+
t.Error("failed to print MOTD using /motd with no parameters", "actual:", actual, "expected:", expected)
177+
}
178+
179+
return nil
180+
})
181+
}
182+
135183
func TestHostWhitelist(t *testing.T) {
136184
key, err := sshd.NewRandomSigner(512)
137185
if err != nil {

0 commit comments

Comments
 (0)