mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 13:05:46 +00:00
ssh/tailssh: handle output matching better in tests (#7799)
This commit is contained in:
parent
2c0bda6e2e
commit
d42d570066
@ -365,6 +365,8 @@ func TestSSHRecordingCancelsSessionsOnUploadFailure(t *testing.T) {
|
|||||||
handler func(w http.ResponseWriter, r *http.Request)
|
handler func(w http.ResponseWriter, r *http.Request)
|
||||||
sshCommand string
|
sshCommand string
|
||||||
wantClientOutput string
|
wantClientOutput string
|
||||||
|
|
||||||
|
clientOutputMustNotContain []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "upload-denied",
|
name: "upload-denied",
|
||||||
@ -373,6 +375,8 @@ func TestSSHRecordingCancelsSessionsOnUploadFailure(t *testing.T) {
|
|||||||
},
|
},
|
||||||
sshCommand: "echo hello",
|
sshCommand: "echo hello",
|
||||||
wantClientOutput: "recording: server responded with 403 Forbidden\r\n",
|
wantClientOutput: "recording: server responded with 403 Forbidden\r\n",
|
||||||
|
|
||||||
|
clientOutputMustNotContain: []string{"hello"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "upload-fails-after-starting",
|
name: "upload-fails-after-starting",
|
||||||
@ -382,7 +386,9 @@ func TestSSHRecordingCancelsSessionsOnUploadFailure(t *testing.T) {
|
|||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
},
|
},
|
||||||
sshCommand: "echo hello && sleep 1 && echo world",
|
sshCommand: "echo hello && sleep 1 && echo world",
|
||||||
wantClientOutput: "hello\n\r\n\r\nrecording server responded with: 500 Internal Server Error\r\n\r\n",
|
wantClientOutput: "\r\n\r\nrecording server responded with: 500 Internal Server Error\r\n\r\n",
|
||||||
|
|
||||||
|
clientOutputMustNotContain: []string{"world"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,9 +422,15 @@ func TestSSHRecordingCancelsSessionsOnUploadFailure(t *testing.T) {
|
|||||||
} else {
|
} else {
|
||||||
t.Errorf("client did not get kicked out: %q", got)
|
t.Errorf("client did not get kicked out: %q", got)
|
||||||
}
|
}
|
||||||
if string(got) != tt.wantClientOutput {
|
gotStr := string(got)
|
||||||
|
if !strings.HasSuffix(gotStr, tt.wantClientOutput) {
|
||||||
t.Errorf("client got %q, want %q", got, tt.wantClientOutput)
|
t.Errorf("client got %q, want %q", got, tt.wantClientOutput)
|
||||||
}
|
}
|
||||||
|
for _, x := range tt.clientOutputMustNotContain {
|
||||||
|
if strings.Contains(gotStr, x) {
|
||||||
|
t.Errorf("client output must not contain %q", x)
|
||||||
|
}
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
if err := s.HandleSSHConn(dc); err != nil {
|
if err := s.HandleSSHConn(dc); err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user