Commit 4bd30414 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '40668-pages-domain-api-returns-404-when-using-a-specific-domain' into 'master'

Resolve "Pages Domain API returns 404 when using a specific domain"

Closes #40668

See merge request gitlab-org/gitlab-ce!17206
parents b5372d82 15ca2d5f
---
title: Fix get a single pages domain when project path contains a period
merge_request: 17206
author: Travis Miller
type: fixed
......@@ -2,6 +2,8 @@ module API
class PagesDomains < Grape::API
include PaginationParams
PAGES_DOMAINS_ENDPOINT_REQUIREMENTS = API::PROJECT_ENDPOINT_REQUIREMENTS.merge(domain: API::NO_SLASH_URL_PART_REGEX)
before do
authenticate!
end
......@@ -48,7 +50,7 @@ module API
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: { id: %r{[^/]+} } do
resource :projects, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do
before do
require_pages_enabled!
end
......@@ -71,7 +73,7 @@ module API
params do
requires :domain, type: String, desc: 'The domain'
end
get ":id/pages/domains/:domain", requirements: { domain: %r{[^/]+} } do
get ":id/pages/domains/:domain", requirements: PAGES_DOMAINS_ENDPOINT_REQUIREMENTS do
authorize! :read_pages, user_project
present pages_domain, with: Entities::PagesDomain
......@@ -105,7 +107,7 @@ module API
optional :certificate, allow_blank: false, types: [File, String], desc: 'The certificate'
optional :key, allow_blank: false, types: [File, String], desc: 'The key'
end
put ":id/pages/domains/:domain", requirements: { domain: %r{[^/]+} } do
put ":id/pages/domains/:domain", requirements: PAGES_DOMAINS_ENDPOINT_REQUIREMENTS do
authorize! :update_pages, user_project
pages_domain_params = declared(params, include_parent_namespaces: false)
......@@ -126,7 +128,7 @@ module API
params do
requires :domain, type: String, desc: 'The domain'
end
delete ":id/pages/domains/:domain", requirements: { domain: %r{[^/]+} } do
delete ":id/pages/domains/:domain", requirements: PAGES_DOMAINS_ENDPOINT_REQUIREMENTS do
authorize! :update_pages, user_project
status 204
......
require 'rails_helper'
describe API::PagesDomains do
set(:project) { create(:project) }
set(:project) { create(:project, path: 'my.project') }
set(:user) { create(:user) }
set(:admin) { create(:admin) }
......@@ -16,6 +16,7 @@ describe API::PagesDomains do
let(:route) { "/projects/#{project.id}/pages/domains" }
let(:route_domain) { "/projects/#{project.id}/pages/domains/#{pages_domain.domain}" }
let(:route_domain_path) { "/projects/#{project.path_with_namespace.gsub('/', '%2F')}/pages/domains/#{pages_domain.domain}" }
let(:route_secure_domain) { "/projects/#{project.id}/pages/domains/#{pages_domain_secure.domain}" }
let(:route_expired_domain) { "/projects/#{project.id}/pages/domains/#{pages_domain_expired.domain}" }
let(:route_vacant_domain) { "/projects/#{project.id}/pages/domains/www.vacant-domain.test" }
......@@ -144,6 +145,16 @@ describe API::PagesDomains do
expect(json_response['certificate']).to be_nil
end
it 'returns pages domain with project path' do
get api(route_domain_path, user)
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/pages_domain/detail')
expect(json_response['domain']).to eq(pages_domain.domain)
expect(json_response['url']).to eq(pages_domain.url)
expect(json_response['certificate']).to be_nil
end
it 'returns pages domain with a certificate' do
get api(route_secure_domain, user)
......
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