Commit 3611d142 authored by Vladimir Shushlin's avatar Vladimir Shushlin

Remove pages_internal_api feature flag

This API is used only internally, and we don't use this
feature flag inside pages daemon itself
parent d4083f52
...@@ -5,7 +5,6 @@ module API ...@@ -5,7 +5,6 @@ module API
module Internal module Internal
class Pages < Grape::API class Pages < Grape::API
before do before do
not_found! unless Feature.enabled?(:pages_internal_api)
authenticate_gitlab_pages_request! authenticate_gitlab_pages_request!
end end
......
...@@ -14,241 +14,227 @@ describe API::Internal::Pages do ...@@ -14,241 +14,227 @@ describe API::Internal::Pages do
get api("/internal/pages"), headers: headers, params: { host: host } get api("/internal/pages"), headers: headers, params: { host: host }
end end
context 'feature flag disabled' do context 'not authenticated' do
before do it 'responds with 401 Unauthorized' do
stub_feature_flags(pages_internal_api: false)
end
it 'responds with 404 Not Found' do
query_host('pages.gitlab.io') query_host('pages.gitlab.io')
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
context 'feature flag enabled' do context 'authenticated' do
context 'not authenticated' do def query_host(host)
it 'responds with 401 Unauthorized' do jwt_token = JWT.encode({ 'iss' => 'gitlab-pages' }, Gitlab::Pages.secret, 'HS256')
query_host('pages.gitlab.io') headers = { Gitlab::Pages::INTERNAL_API_REQUEST_HEADER => jwt_token }
expect(response).to have_gitlab_http_status(:unauthorized) super(host, headers)
end
end end
context 'authenticated' do def deploy_pages(project)
def query_host(host) project.mark_pages_as_deployed
jwt_token = JWT.encode({ 'iss' => 'gitlab-pages' }, Gitlab::Pages.secret, 'HS256') end
headers = { Gitlab::Pages::INTERNAL_API_REQUEST_HEADER => jwt_token }
super(host, headers) context 'domain does not exist' do
end it 'responds with 204 no content' do
query_host('pages.gitlab.io')
def deploy_pages(project) expect(response).to have_gitlab_http_status(:no_content)
project.mark_pages_as_deployed expect(response.body).to be_empty
end end
end
context 'serverless domain' do
let(:namespace) { create(:namespace, name: 'gitlab-org') }
let(:project) { create(:project, namespace: namespace, name: 'gitlab-ce') }
let(:environment) { create(:environment, project: project) }
let(:pages_domain) { create(:pages_domain, domain: 'serverless.gitlab.io') }
let(:knative_without_ingress) { create(:clusters_applications_knative) }
let(:knative_with_ingress) { create(:clusters_applications_knative, external_ip: '10.0.0.1') }
context 'without a knative ingress gateway IP' do
let!(:serverless_domain_cluster) do
create(
:serverless_domain_cluster,
uuid: 'abcdef12345678',
pages_domain: pages_domain,
knative: knative_without_ingress
)
end
let(:serverless_domain) do
create(
:serverless_domain,
serverless_domain_cluster: serverless_domain_cluster,
environment: environment
)
end
context 'domain does not exist' do
it 'responds with 204 no content' do it 'responds with 204 no content' do
query_host('pages.gitlab.io') query_host(serverless_domain.uri.host)
expect(response).to have_gitlab_http_status(:no_content) expect(response).to have_gitlab_http_status(:no_content)
expect(response.body).to be_empty expect(response.body).to be_empty
end end
end end
context 'serverless domain' do context 'with a knative ingress gateway IP' do
let(:namespace) { create(:namespace, name: 'gitlab-org') } let!(:serverless_domain_cluster) do
let(:project) { create(:project, namespace: namespace, name: 'gitlab-ce') } create(
let(:environment) { create(:environment, project: project) } :serverless_domain_cluster,
let(:pages_domain) { create(:pages_domain, domain: 'serverless.gitlab.io') } uuid: 'abcdef12345678',
let(:knative_without_ingress) { create(:clusters_applications_knative) } pages_domain: pages_domain,
let(:knative_with_ingress) { create(:clusters_applications_knative, external_ip: '10.0.0.1') } knative: knative_with_ingress
)
context 'without a knative ingress gateway IP' do
let!(:serverless_domain_cluster) do
create(
:serverless_domain_cluster,
uuid: 'abcdef12345678',
pages_domain: pages_domain,
knative: knative_without_ingress
)
end
let(:serverless_domain) do
create(
:serverless_domain,
serverless_domain_cluster: serverless_domain_cluster,
environment: environment
)
end
it 'responds with 204 no content' do
query_host(serverless_domain.uri.host)
expect(response).to have_gitlab_http_status(:no_content)
expect(response.body).to be_empty
end
end end
context 'with a knative ingress gateway IP' do let(:serverless_domain) do
let!(:serverless_domain_cluster) do create(
create( :serverless_domain,
:serverless_domain_cluster, serverless_domain_cluster: serverless_domain_cluster,
uuid: 'abcdef12345678', environment: environment
pages_domain: pages_domain, )
knative: knative_with_ingress end
)
end it 'responds with proxy configuration' do
query_host(serverless_domain.uri.host)
let(:serverless_domain) do
create( expect(response).to have_gitlab_http_status(:ok)
:serverless_domain, expect(response).to match_response_schema('internal/serverless/virtual_domain')
serverless_domain_cluster: serverless_domain_cluster,
environment: environment expect(json_response['certificate']).to eq(pages_domain.certificate)
) expect(json_response['key']).to eq(pages_domain.key)
end
expect(json_response['lookup_paths']).to eq(
it 'responds with proxy configuration' do [
query_host(serverless_domain.uri.host) {
'source' => {
expect(response).to have_gitlab_http_status(:ok) 'type' => 'serverless',
expect(response).to match_response_schema('internal/serverless/virtual_domain') 'service' => "test-function.#{project.name}-#{project.id}-#{environment.slug}.#{serverless_domain_cluster.knative.hostname}",
'cluster' => {
expect(json_response['certificate']).to eq(pages_domain.certificate) 'hostname' => serverless_domain_cluster.knative.hostname,
expect(json_response['key']).to eq(pages_domain.key) 'address' => serverless_domain_cluster.knative.external_ip,
'port' => 443,
expect(json_response['lookup_paths']).to eq( 'cert' => serverless_domain_cluster.certificate,
[ 'key' => serverless_domain_cluster.key
{
'source' => {
'type' => 'serverless',
'service' => "test-function.#{project.name}-#{project.id}-#{environment.slug}.#{serverless_domain_cluster.knative.hostname}",
'cluster' => {
'hostname' => serverless_domain_cluster.knative.hostname,
'address' => serverless_domain_cluster.knative.external_ip,
'port' => 443,
'cert' => serverless_domain_cluster.certificate,
'key' => serverless_domain_cluster.key
}
} }
} }
] }
) ]
end )
end end
end end
end
context 'custom domain' do context 'custom domain' do
let(:namespace) { create(:namespace, name: 'gitlab-org') } let(:namespace) { create(:namespace, name: 'gitlab-org') }
let(:project) { create(:project, namespace: namespace, name: 'gitlab-ce') } let(:project) { create(:project, namespace: namespace, name: 'gitlab-ce') }
let!(:pages_domain) { create(:pages_domain, domain: 'pages.io', project: project) } let!(:pages_domain) { create(:pages_domain, domain: 'pages.io', project: project) }
context 'when there are no pages deployed for the related project' do context 'when there are no pages deployed for the related project' do
it 'responds with 204 No Content' do it 'responds with 204 No Content' do
query_host('pages.io') query_host('pages.io')
expect(response).to have_gitlab_http_status(:no_content) expect(response).to have_gitlab_http_status(:no_content)
end
end end
end
context 'when there are pages deployed for the related project' do context 'when there are pages deployed for the related project' do
it 'domain lookup is case insensitive' do it 'domain lookup is case insensitive' do
deploy_pages(project) deploy_pages(project)
query_host('Pages.IO') query_host('Pages.IO')
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
end end
it 'responds with the correct domain configuration' do it 'responds with the correct domain configuration' do
deploy_pages(project) deploy_pages(project)
query_host('pages.io') query_host('pages.io')
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('internal/pages/virtual_domain') expect(response).to match_response_schema('internal/pages/virtual_domain')
expect(json_response['certificate']).to eq(pages_domain.certificate) expect(json_response['certificate']).to eq(pages_domain.certificate)
expect(json_response['key']).to eq(pages_domain.key) expect(json_response['key']).to eq(pages_domain.key)
expect(json_response['lookup_paths']).to eq( expect(json_response['lookup_paths']).to eq(
[ [
{ {
'project_id' => project.id, 'project_id' => project.id,
'access_control' => false, 'access_control' => false,
'https_only' => false, 'https_only' => false,
'prefix' => '/', 'prefix' => '/',
'source' => { 'source' => {
'type' => 'file', 'type' => 'file',
'path' => 'gitlab-org/gitlab-ce/public/' 'path' => 'gitlab-org/gitlab-ce/public/'
}
} }
] }
) ]
end )
end end
end end
end
context 'namespaced domain' do context 'namespaced domain' do
let(:group) { create(:group, name: 'mygroup') } let(:group) { create(:group, name: 'mygroup') }
before do before do
allow(Settings.pages).to receive(:host).and_return('gitlab-pages.io') allow(Settings.pages).to receive(:host).and_return('gitlab-pages.io')
allow(Gitlab.config.pages).to receive(:url).and_return("http://gitlab-pages.io") allow(Gitlab.config.pages).to receive(:url).and_return("http://gitlab-pages.io")
end end
context 'regular project' do context 'regular project' do
it 'responds with the correct domain configuration' do it 'responds with the correct domain configuration' do
project = create(:project, group: group, name: 'myproject') project = create(:project, group: group, name: 'myproject')
deploy_pages(project) deploy_pages(project)
query_host('mygroup.gitlab-pages.io') query_host('mygroup.gitlab-pages.io')
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('internal/pages/virtual_domain') expect(response).to match_response_schema('internal/pages/virtual_domain')
expect(json_response['lookup_paths']).to eq( expect(json_response['lookup_paths']).to eq(
[ [
{ {
'project_id' => project.id, 'project_id' => project.id,
'access_control' => false, 'access_control' => false,
'https_only' => false, 'https_only' => false,
'prefix' => '/myproject/', 'prefix' => '/myproject/',
'source' => { 'source' => {
'type' => 'file', 'type' => 'file',
'path' => 'mygroup/myproject/public/' 'path' => 'mygroup/myproject/public/'
}
} }
] }
) ]
end )
end end
end
context 'group root project' do context 'group root project' do
it 'responds with the correct domain configuration' do it 'responds with the correct domain configuration' do
project = create(:project, group: group, name: 'mygroup.gitlab-pages.io') project = create(:project, group: group, name: 'mygroup.gitlab-pages.io')
deploy_pages(project) deploy_pages(project)
query_host('mygroup.gitlab-pages.io') query_host('mygroup.gitlab-pages.io')
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('internal/pages/virtual_domain') expect(response).to match_response_schema('internal/pages/virtual_domain')
expect(json_response['lookup_paths']).to eq( expect(json_response['lookup_paths']).to eq(
[ [
{ {
'project_id' => project.id, 'project_id' => project.id,
'access_control' => false, 'access_control' => false,
'https_only' => false, 'https_only' => false,
'prefix' => '/', 'prefix' => '/',
'source' => { 'source' => {
'type' => 'file', 'type' => 'file',
'path' => 'mygroup/mygroup.gitlab-pages.io/public/' 'path' => 'mygroup/mygroup.gitlab-pages.io/public/'
}
} }
] }
) ]
end )
end end
end end
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