Skip to content

Commit 0c58474

Browse files
Add assertion that server-side should have successfully written part of the response message.
1 parent 7dc180f commit 0c58474

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

ssh/agent/client_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"os/exec"
1414
"path/filepath"
1515
"strconv"
16+
"sync"
1617
"testing"
1718
"time"
1819

@@ -232,14 +233,26 @@ func TestServerResponseTooLarge(t *testing.T) {
232233
response.Keys = make([]byte, maxAgentResponseBytes+1)
233234

234235
agent := NewClient(a)
235-
go b.Write(ssh.Marshal(response))
236+
var wg sync.WaitGroup
237+
wg.Add(1)
238+
go func() {
239+
defer wg.Done()
240+
n, _ := b.Write(ssh.Marshal(response))
241+
if n < 4 {
242+
t.Fatalf("At least 4 bytes (the response size) should have been successfully written: %d < 4", n)
243+
}
244+
}()
236245
_, err = agent.List()
237246
if err == nil {
238247
t.Fatal("Did not get error result")
239248
}
240249
if err.Error() != "agent: client error: response too large" {
241250
t.Fatal("Did not get expected error result")
242251
}
252+
// We need to explicitly close the client connection or else the server-side write call might block waiting for
253+
// the client to consume the entire message (which it shouldn't)
254+
a.Close()
255+
wg.Wait()
243256
}
244257

245258
func TestAuth(t *testing.T) {

0 commit comments

Comments
 (0)