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

changed 404 to 401 for unknown client #1707

Merged
merged 1 commit into from Feb 1, 2020

Conversation

obasajujoshua31
Copy link
Contributor

Related issue

#1617

Proposed changes

Checklist

  • [ x] I have read the contributing guidelines
  • [ x] I have read the security policy
  • [ x] I confirm that this pull request does not address a security vulnerability. If this pull request addresses a security
    vulnerability, I confirm that I got green light (please contact security@ory.sh) from the maintainers to push the changes.
  • [ x] I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation within the code base (if appropriate)
  • I have documented my changes in the developer guide (if appropriate)

Further comments

Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

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

Looks good so far, but there are pieces missing:

This also needs to be done in the memory manager and we should also add a test!

I also think that it would be a better idea to handle this 404->401 conversion in the handler, because we use the manager also in other areas of hydra, and it might break functionality there.

Handler: https://github.com/ory/hydra/blob/master/client/handler.go#L243

@@ -253,6 +258,13 @@ func (m *SQLManager) CreateSchemas(dbName string) (int, error) {
func (m *SQLManager) GetConcreteClient(ctx context.Context, id string) (*Client, error) {
var d sqlData
if err := m.DB.GetContext(ctx, &d, m.DB.Rebind("SELECT * FROM hydra_client WHERE id=?"), id); err != nil {
if errorsx.Cause(err) == sql.ErrNoRows {
return nil, errors.WithStack(&herodot.DefaultError{
Copy link
Member

Choose a reason for hiding this comment

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

You can use herodot.ErrUnauthorized.WithReason("The requested OAuth 2.0 client does not exist or you did not provide the necessary credentials.")

@obasajujoshua31 obasajujoshua31 force-pushed the fix-get-client-404 branch 2 times, most recently from 2ac9ff2 to 6d78337 Compare January 23, 2020 16:43
@@ -230,13 +233,17 @@ func (h *Handler) List(w http.ResponseWriter, r *http.Request, ps httprouter.Par
//
// Responses:
// 200: oAuth2Client
// 401: genericError
Copy link
Member

Choose a reason for hiding this comment

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

Please fix the indentation

Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

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

As discussed, please add some tests!

// 404: genericError
// 500: genericError
func (h *Handler) Get(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var id = ps.ByName("id")

c, err := h.r.ClientManager().GetConcreteClient(r.Context(), id)
if err != nil {
if errors.Cause(err).Error() == sqlcon.ErrNoRows.ErrorField {
Copy link
Member

Choose a reason for hiding this comment

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

I believe this should be enough:

Suggested change
if errors.Cause(err).Error() == sqlcon.ErrNoRows.ErrorField {
if errorsx.Cause(err) == sqlcon.ErrNoRows {

@obasajujoshua31 obasajujoshua31 force-pushed the fix-get-client-404 branch 3 times, most recently from 1518568 to 815c500 Compare January 27, 2020 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants