Calling .auth after class is loaded does not apply auth to top-level endpoints

Open
#1,331 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
ruby
Domain
api, authorization

Research direction

Start with the failing tests in the linked auth-after-load comparison and trace the top-level get endpoint through SomeAPI.http_basic and .auth after the class is loaded. Done means the top-level endpoint passes through the authorization middleware and the regression tests no longer return an unauthorized request as 200.

Written by the indexing model from the issue text.

Description

bug?

I've stumbled on an issue where requests to endpoints which are not nested inside resources or namespace blocks don't go through the authorization middleware.

I have added failing tests to demonstrate this: https://github.com/ruby-grape/grape/compare/master...jeromegn:auth-after-load

Concise example:

class SomeAPI < Grape::API
  get { "hello" }
end
SomeAPI.http_basic { |u, p| false } # .http_basic calls .auth

GETting this endpoint ^ will return a 200 with "hello" as its body.

Dominant language
Ruby
Stars
10k
Forks
1.2k
Avg merge
14h 38m
Merged PRs (30d)
92

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby-grape/grape

All issues in ruby-grape/grape

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.