1package sshstdio
2
3import (
4 "testing"
5
6 "github.com/stretchr/testify/require"
7
8 "github.com/bnema/vev/internal/domain"
9)
10
11func TestClassifyStderr(t *testing.T) {
12 tests := []struct {
13 name string
14 stderr string
15 want domain.RemoteFailureKind
16 }{
17 {name: "openssh key refused", stderr: "user@example.test: Permission denied (publickey).", want: domain.RemoteFailureAuthentication},
18 {name: "go ssh no methods", stderr: "ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain", want: domain.RemoteFailureAuthentication},
19 {name: "browser login required", stderr: "SSH authentication required.\nPlease do the SSO login in your browser.", want: domain.RemoteFailureAuthentication},
20 {name: "unknown host key", stderr: "Host key verification failed.", want: domain.RemoteFailureTrust},
21 {name: "changed host key", stderr: "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!", want: domain.RemoteFailureTrust},
22 {name: "timeout", stderr: "ssh: connect to host example.test port 22: Connection timed out", want: domain.RemoteFailureTimeout},
23 {name: "remote shell permission stays generic", stderr: "bash: /usr/local/bin/vev: Permission denied", want: domain.RemoteFailureNone},
24 {name: "refused stays generic", stderr: "connect: connection refused", want: domain.RemoteFailureNone},
25 {name: "empty", stderr: "", want: domain.RemoteFailureNone},
26 }
27 for _, tt := range tests {
28 t.Run(tt.name, func(t *testing.T) {
29 require.Equal(t, tt.want, ClassifyStderr(tt.stderr))
30 })
31 }
32}