ソースを参照

ssh: use a variable rather than type for NoAuthError

Change-Id: Ib61e0bc7d953cefde0436f77fe6a610201043c85
Reviewed-on: https://go-review.googlesource.com/96336
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Spencer Tung <spencertung@google.com>
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
Han-Wen Nienhuys 7 年 前
コミット
49796115aa
2 ファイル変更9 行追加11 行削除
  1. 2 2
      ssh/client_auth_test.go
  2. 7 9
      ssh/server.go

+ 2 - 2
ssh/client_auth_test.go

@@ -614,8 +614,8 @@ func TestClientAuthErrorList(t *testing.T) {
 	for i, e := range authErrs.Errors {
 	for i, e := range authErrs.Errors {
 		switch i {
 		switch i {
 		case 0:
 		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:
 		case 1:
 			if e != publicKeyErr {
 			if e != publicKeyErr {

+ 7 - 9
ssh/server.go

@@ -297,7 +297,7 @@ func checkSourceAddress(addr net.Addr, sourceAddrs string) error {
 // provided by the user failed to authenticate.
 // provided by the user failed to authenticate.
 type ServerAuthError struct {
 type ServerAuthError struct {
 	// Errors contains authentication errors returned by the authentication
 	// Errors contains authentication errors returned by the authentication
-	// callback methods.
+	// callback methods. The first entry typically is NoAuthError.
 	Errors []error
 	Errors []error
 }
 }
 
 
@@ -309,13 +309,11 @@ func (l ServerAuthError) Error() string {
 	return "[" + strings.Join(errs, ", ") + "]"
 	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) {
 func (s *connection) serverAuthenticate(config *ServerConfig) (*Permissions, error) {
 	sessionID := s.transport.getSessionID()
 	sessionID := s.transport.getSessionID()
@@ -371,7 +369,7 @@ userAuthLoop:
 		}
 		}
 
 
 		perms = nil
 		perms = nil
-		authErr := error(&NoAuthError{})
+		authErr := NoAuthError
 
 
 		switch userAuthReq.Method {
 		switch userAuthReq.Method {
 		case "none":
 		case "none":