Skip to content

Commit

Permalink
add ping endpoint
Browse files Browse the repository at this point in the history
- this signals compact index support
  • Loading branch information
ezekg committed Oct 22, 2024
1 parent 7315b3e commit 6bd2130
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ class Rubygems::CompactIndexController < Api::V1::BaseController
before_action :set_packages, only: %i[versions names]
before_action :set_package, only: %i[info]

def ping
skip_verify_authorized!

head :ok
end

def versions
authorize! packages,
to: :index?
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
get 'versions', to: 'compact_index#versions', as: :rubygems_compact_versions
get 'info/:package', to: 'compact_index#info', as: :rubygems_compact_info
get 'names', to: 'compact_index#names', as: :rubygems_compact_names
root via: :head, to: 'compact_index#ping', as: :rubygems_compact_ping
end
end

Expand Down
10 changes: 7 additions & 3 deletions features/api/v1/engines/rubygems/compact_index.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Feature: Rubygems simple package index
| Test 2 | test2 |
And the current account is "test1"
And the current account has the following "product" rows:
| id | name |
| 6198261a-48b5-4445-a045-9fed4afc7735 | Test 1 |
| cad3c65c-b6a5-4b3d-bce6-c2280953b8b8 | Test 2 |
| id | name | distribution_strategy |
| 6198261a-48b5-4445-a045-9fed4afc7735 | Test 1 | LICENSED |
| cad3c65c-b6a5-4b3d-bce6-c2280953b8b8 | Test 2 | LICENSED |
And the current account has the following "package" rows:
| id | product_id | engine | key |
| 46e034fe-2312-40f8-bbeb-7d9957fb6fcf | 6198261a-48b5-4445-a045-9fed4afc7735 | rubygems | foo |
Expand Down Expand Up @@ -87,6 +87,10 @@ Feature: Rubygems simple package index
When I send a GET request to "/accounts/test1/engines/rubygems/versions"
Then the response status should be "400"

Scenario: Endpoint should respond to ping
When I send a HEAD request to "/accounts/test1/engines/rubygems"
Then the response status should be "200"

Scenario: Endpoint should return all gems
Given I am an admin of account "test1"
And I use an authentication token
Expand Down
18 changes: 18 additions & 0 deletions features/step_definitions/request_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@
travel_back
end

When /^I send a HEAD request to "([^\"]*)"$/ do |path|
path = parse_path_placeholders(path, account: @account, bearer: @bearer, crypt: @crypt)

case %r{/accounts/(?<account>[^?#/]+)}.match(path)
in account: id if Keygen.singleplayer?
account = FindByAliasService.call(Account, id:, aliases: :slug) rescue nil

stub_env 'KEYGEN_ACCOUNT_ID', account&.id
else
end

unless path.starts_with?('//')
head "//api.keygen.sh/#{@api_version}/#{path.sub(/^\//, '')}"
else
head path
end
end

When /^I send a GET request to "([^\"]*)"$/ do |path|
path = parse_path_placeholders(path, account: @account, bearer: @bearer, crypt: @crypt)

Expand Down

0 comments on commit 6bd2130

Please sign in to comment.