Quellcode durchsuchen

Adding a unique error when no authentication method has been passed in
yet.

Since ServerAuthError returns all errors collected during the
userAuthLoop, it will always include the generic error "no auth passed
yet" (assuming the connection fails).

Change-Id: I5f6c67f3f0762b023618178d4028600d2b6c9253
Reviewed-on: https://go-review.googlesource.com/92737
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

Spencer Tung vor 7 Jahren
Ursprung
Commit
432090b8f5
2 geänderte Dateien mit 11 neuen und 3 gelöschten Zeilen
  1. 2 2
      ssh/client_auth_test.go
  2. 9 1
      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 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:
 		case 1:
 			if e != publicKeyErr {
 			if e != publicKeyErr {

+ 9 - 1
ssh/server.go

@@ -309,6 +309,14 @@ 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"
+}
+
 func (s *connection) serverAuthenticate(config *ServerConfig) (*Permissions, error) {
 func (s *connection) serverAuthenticate(config *ServerConfig) (*Permissions, error) {
 	sessionID := s.transport.getSessionID()
 	sessionID := s.transport.getSessionID()
 	var cache pubKeyCache
 	var cache pubKeyCache
@@ -363,7 +371,7 @@ userAuthLoop:
 		}
 		}
 
 
 		perms = nil
 		perms = nil
-		authErr := errors.New("no auth passed yet")
+		authErr := error(&NoAuthError{})
 
 
 		switch userAuthReq.Method {
 		switch userAuthReq.Method {
 		case "none":
 		case "none":