MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / TestAuthFailed

Function TestAuthFailed

internal/sshserver/Server_test.go:57–99  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

55}
56
57func TestAuthFailed(t *testing.T) {
58 //t.Parallel()()
59 port := test.GetNextPort(t, "SSH")
60 server := newServerHelper(
61 t,
62 fmt.Sprintf("127.0.0.1:%d", port),
63 map[string][]byte{
64 "foo": []byte("bar"),
65 },
66 map[string]string{},
67 )
68 hostKey, err := server.start(t)
69 if err != nil {
70 assert.Fail(t, "failed to start ssh server", err)
71 return
72 }
73 defer func() {
74 server.stop()
75 <-server.shutdownChannel
76 }()
77
78 sshConfig := &ssh.ClientConfig{
79 User: "foo",
80 Auth: []ssh.AuthMethod{ssh.Password("invalid")},
81 }
82 sshConfig.HostKeyCallback = func(hostname string, remote net.Addr, key ssh.PublicKey) error {
83 marshaledKey := key.Marshal()
84 if bytes.Equal(marshaledKey, hostKey) {
85 return nil
86 }
87 return fmt.Errorf("invalid host")
88 }
89
90 sshConnection, err := ssh.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", port), sshConfig)
91 if err != nil {
92 if !strings.Contains(err.Error(), "unable to authenticate") {
93 assert.Fail(t, "handshake failed for non-auth reasons", err)
94 }
95 } else {
96 _ = sshConnection.Close()
97 assert.Fail(t, "authentication succeeded", err)
98 }
99}
100
101func TestAuthKeyboardInteractive(t *testing.T) {
102 //t.Parallel()()

Callers

nothing calls this directly

Calls 10

GetNextPortFunction · 0.92
newServerHelperFunction · 0.85
FailMethod · 0.80
stopMethod · 0.80
startMethod · 0.65
PasswordMethod · 0.65
MarshalMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected