diff --git a/ssh/client_auth_test.go b/ssh/client_auth_test.go index a6b8b99..e457ca5 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 _, ok := e.(*NoAuthError); !ok { - t.Fatalf("errors: got error type %T, want NoAuthError", e) + if e != NoAuthError { + t.Fatalf("errors: got error %v, want NoAuthError", e) } case 1: if e != publicKeyErr { diff --git a/ssh/server.go b/ssh/server.go index f40657d..6262f34 100644 --- a/ssh/server.go +++ b/ssh/server.go @@ -297,7 +297,7 @@ func checkSourceAddress(addr net.Addr, sourceAddrs string) error { // provided by the user failed to authenticate. type ServerAuthError struct { // Errors contains authentication errors returned by the authentication - // callback methods. + // callback methods. The first entry typically is NoAuthError. Errors []error } @@ -309,13 +309,11 @@ 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" -} +// NoAuthError is the unique error that is returned if no +// authentication method has been passed yet. This happens as a normal +// part of the authentication loop, since the client first tries +// 'none' authentication to discover available methods. +var NoAuthError = errors.New("ssh: no auth passed yet") func (s *connection) serverAuthenticate(config *ServerConfig) (*Permissions, error) { sessionID := s.transport.getSessionID() @@ -371,7 +369,7 @@ userAuthLoop: } perms = nil - authErr := error(&NoAuthError{}) + authErr := NoAuthError switch userAuthReq.Method { case "none":