diff --git a/.changelog/10163.txt b/.changelog/10163.txt new file mode 100644 index 0000000000..45f594680b --- /dev/null +++ b/.changelog/10163.txt @@ -0,0 +1,3 @@ +```release-note:improvement +acl: Give more descriptive error if auth method not found. +``` diff --git a/agent/consul/acl_endpoint.go b/agent/consul/acl_endpoint.go index b8ba08e0b2..64141f5cd1 100644 --- a/agent/consul/acl_endpoint.go +++ b/agent/consul/acl_endpoint.go @@ -2422,7 +2422,7 @@ func (a *ACL) Login(args *structs.ACLLoginRequest, reply *structs.ACLToken) erro if err != nil { return err } else if method == nil { - return acl.ErrNotFound + return fmt.Errorf("%w: auth method %q not found", acl.ErrNotFound, auth.AuthMethod) } if err := a.enterpriseAuthMethodTypeValidation(method.Type); err != nil { diff --git a/agent/consul/acl_endpoint_test.go b/agent/consul/acl_endpoint_test.go index a265f79f47..213d540d9a 100644 --- a/agent/consul/acl_endpoint_test.go +++ b/agent/consul/acl_endpoint_test.go @@ -4428,7 +4428,7 @@ func TestACLEndpoint_Login(t *testing.T) { } resp := structs.ACLToken{} - testutil.RequireErrorContains(t, acl.Login(&req, &resp), "ACL not found") + testutil.RequireErrorContains(t, acl.Login(&req, &resp), fmt.Sprintf("auth method %q not found", method.Name+"-notexist")) }) t.Run("invalid method token", func(t *testing.T) { diff --git a/command/login/login_test.go b/command/login/login_test.go index e821eddb02..25a46dda5e 100644 --- a/command/login/login_test.go +++ b/command/login/login_test.go @@ -139,7 +139,7 @@ func TestLoginCommand(t *testing.T) { code := cmd.Run(args) require.Equal(t, code, 1, "err: %s", ui.ErrorWriter.String()) - require.Contains(t, ui.ErrorWriter.String(), "403 (ACL not found)") + require.Contains(t, ui.ErrorWriter.String(), "403 (ACL not found: auth method \"test\" not found") }) testSessionID := testauth.StartSession()