diff --git a/ssh/client_auth_test.go b/ssh/client_auth_test.go index 145b57a..a6b8b99 100644 --- a/ssh/client_auth_test.go +++ b/ssh/client_auth_test.go @@ -614,8 +614,8 @@ func TestClientAuthErrorList(t *testing.T) { for i, e := range authErrs.Errors { switch i { case 0: - if e.Error() != "no auth passed yet" { - t.Fatalf("errors: got %v, want no auth passed yet", e.Error()) + if _, ok := e.(*NoAuthError); !ok { + t.Fatalf("errors: got error type %T, want NoAuthError", e) } case 1: if e != publicKeyErr { diff --git a/ssh/server.go b/ssh/server.go index b83d473..f40657d 100644 --- a/ssh/server.go +++ b/ssh/server.go @@ -309,6 +309,14 @@ func (l ServerAuthError) Error() string { return "[" + strings.Join(errs, ", ") + "]" } +// NoAuthError is the unique error that is returned if no authentication method +// has been passed yet +type NoAuthError struct{} + +func (e *NoAuthError) Error() string { + return "no auth passed yet" +} + func (s *connection) serverAuthenticate(config *ServerConfig) (*Permissions, error) { sessionID := s.transport.getSessionID() var cache pubKeyCache @@ -363,7 +371,7 @@ userAuthLoop: } perms = nil - authErr := errors.New("no auth passed yet") + authErr := error(&NoAuthError{}) switch userAuthReq.Method { case "none":