Commit 607aaa77 authored by Jaime Martinez's avatar Jaime Martinez Committed by Bob Van Landuyt

Add enabled endpoint to Pages Internal API

Add this new simple endpoint to allow GitLab Pages to verify that
the internal API is enabled and ready to be used. Details on the issue
https://gitlab.com/gitlab-org/gitlab/-/issues/210010
parent 63e8820c
---
title: Add status endpoint to Pages Internal API
merge_request: 28743
author:
type: added
...@@ -16,6 +16,13 @@ module API ...@@ -16,6 +16,13 @@ module API
namespace 'internal' do namespace 'internal' do
namespace 'pages' do namespace 'pages' do
desc 'Indicates that pages API is enabled and auth token is valid' do
detail 'This feature was introduced in GitLab 12.10.'
end
get "status" do
no_content!
end
desc 'Get GitLab Pages domain configuration by hostname' do desc 'Get GitLab Pages domain configuration by hostname' do
detail 'This feature was introduced in GitLab 12.3.' detail 'This feature was introduced in GitLab 12.3.'
end end
......
...@@ -3,13 +3,36 @@ ...@@ -3,13 +3,36 @@
require 'spec_helper' require 'spec_helper'
describe API::Internal::Pages do describe API::Internal::Pages do
describe "GET /internal/pages" do let(:auth_headers) do
let(:pages_secret) { SecureRandom.random_bytes(Gitlab::Pages::SECRET_LENGTH) } jwt_token = JWT.encode({ 'iss' => 'gitlab-pages' }, Gitlab::Pages.secret, 'HS256')
{ Gitlab::Pages::INTERNAL_API_REQUEST_HEADER => jwt_token }
end
let(:pages_secret) { SecureRandom.random_bytes(Gitlab::Pages::SECRET_LENGTH) }
before do
allow(Gitlab::Pages).to receive(:secret).and_return(pages_secret)
end
describe "GET /internal/pages/status" do
def query_enabled(headers = {})
get api("/internal/pages/status"), headers: headers
end
before do it 'responds with 401 Unauthorized' do
allow(Gitlab::Pages).to receive(:secret).and_return(pages_secret) query_enabled
expect(response).to have_gitlab_http_status(:unauthorized)
end
it 'responds with 204 no content' do
query_enabled(auth_headers)
expect(response).to have_gitlab_http_status(:no_content)
expect(response.body).to be_empty
end end
end
describe "GET /internal/pages" do
def query_host(host, headers = {}) def query_host(host, headers = {})
get api("/internal/pages"), headers: headers, params: { host: host } get api("/internal/pages"), headers: headers, params: { host: host }
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment