Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give descriptive error if auth method not found #10163

Merged
merged 2 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/10163.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
acl: Give more descriptive error if auth method not found.
```
2 changes: 1 addition & 1 deletion agent/consul/acl_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2380,7 +2380,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("auth method %q not found", auth.AuthMethod)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, forgot to submit this comment:

I think we'll need something like this:

Suggested change
return fmt.Errorf("auth method %q not found", auth.AuthMethod)
return fmt.Errorf("auth method %q: %w", auth.AuthMethod, acl.ErrNotFound)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I swapped it around so it reads ACL not found: auth method <blah> not found

}

if err := a.enterpriseAuthMethodTypeValidation(method.Type); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion agent/consul/acl_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4628,7 +4628,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) {
Expand Down
2 changes: 1 addition & 1 deletion command/login/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,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(), "500 (auth method \"test\" not found)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want a 500 response code for this. Either a 404 or 403 seems appropriate.

There's some related context in #8520 (comment) (and the associated issue).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agreed, didn't know how to do that but your suggestion works like a charm!

})

testSessionID := testauth.StartSession()
Expand Down