debian-mirror-gitlab/spec/features/projects/pages_spec.rb

412 lines
12 KiB
Ruby
Raw Normal View History

2019-09-04 21:01:54 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2019-09-30 21:07:59 +05:30
shared_examples 'pages settings editing' do
2019-12-26 22:10:19 +05:30
let_it_be(:project) { create(:project, pages_https_only: false) }
2018-11-08 19:23:39 +05:30
let(:user) { create(:user) }
2018-11-18 11:00:15 +05:30
let(:role) { :maintainer }
2017-08-17 22:00:37 +05:30
2018-11-08 19:23:39 +05:30
before do
2017-08-17 22:00:37 +05:30
allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
2018-03-17 18:26:18 +05:30
project.add_role(user, role)
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
sign_in(user)
2017-08-17 22:00:37 +05:30
end
context 'when user is the owner' do
2018-11-08 19:23:39 +05:30
before do
2017-08-17 22:00:37 +05:30
project.namespace.update(owner: user)
end
context 'when pages deployed' do
2018-11-08 19:23:39 +05:30
before do
2017-08-17 22:00:37 +05:30
allow_any_instance_of(Project).to receive(:pages_deployed?) { true }
end
2018-11-08 19:23:39 +05:30
it 'renders Access pages' do
2017-09-10 17:25:29 +05:30
visit project_pages_path(project)
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
expect(page).to have_content('Access pages')
end
2019-12-26 22:10:19 +05:30
context 'when pages are disabled in the project settings' do
it 'renders disabled warning' do
project.project_feature.update!(pages_access_level: ProjectFeature::DISABLED)
visit project_pages_path(project)
expect(page).to have_content('GitLab Pages are disabled for this project')
end
end
2019-12-04 20:38:33 +05:30
it 'renders first deployment warning' do
visit project_pages_path(project)
expect(page).to have_content('It may take up to 30 minutes before the site is available after the first deployment.')
end
2019-12-26 22:10:19 +05:30
shared_examples 'does not render access control warning' do
it 'does not render access control warning' do
visit project_pages_path(project)
expect(page).not_to have_content('Access Control is enabled for this Pages website')
end
end
include_examples 'does not render access control warning'
context 'when access control is enabled in gitlab settings' do
before do
stub_pages_setting(access_control: true)
end
it 'renders access control warning' do
visit project_pages_path(project)
expect(page).to have_content('Access Control is enabled for this Pages website')
end
context 'when pages are public' do
before do
project.project_feature.update!(pages_access_level: ProjectFeature::PUBLIC)
end
include_examples 'does not render access control warning'
end
end
2018-03-27 19:54:05 +05:30
context 'when support for external domains is disabled' do
it 'renders message that support is disabled' do
visit project_pages_path(project)
expect(page).to have_content('Support for domains and certificates is disabled')
end
end
2018-05-09 12:01:36 +05:30
context 'when pages are exposed on external HTTP address', :http_pages_enabled do
2018-11-08 19:23:39 +05:30
let(:project) { create(:project, pages_https_only: false) }
2018-05-09 12:01:36 +05:30
2018-03-27 19:54:05 +05:30
shared_examples 'adds new domain' do
it 'adds new domain' do
visit new_project_pages_domain_path(project)
fill_in 'Domain', with: 'my.test.domain.com'
click_button 'Create New Domain'
expect(page).to have_content('my.test.domain.com')
end
end
it 'allows to add new domain' do
visit project_pages_path(project)
expect(page).to have_content('New Domain')
end
it_behaves_like 'adds new domain'
context 'when project in group namespace' do
it_behaves_like 'adds new domain' do
let(:group) { create :group }
2018-05-09 12:01:36 +05:30
let(:project) { create(:project, namespace: group, pages_https_only: false) }
2018-03-27 19:54:05 +05:30
end
end
context 'when pages domain is added' do
before do
2018-05-09 12:01:36 +05:30
create(:pages_domain, project: project, domain: 'my.test.domain.com')
2018-03-27 19:54:05 +05:30
visit new_project_pages_domain_path(project)
end
it 'renders certificates is disabled' do
expect(page).to have_content('Support for custom certificates is disabled')
end
it 'does not adds new domain and renders error message' do
fill_in 'Domain', with: 'my.test.domain.com'
click_button 'Create New Domain'
expect(page).to have_content('Domain has already been taken')
end
end
end
2019-12-26 22:10:19 +05:30
context 'when pages are exposed on external HTTPS address', :https_pages_enabled, :js do
2018-03-27 19:54:05 +05:30
let(:certificate_pem) do
2020-03-28 13:19:24 +05:30
attributes_for(:pages_domain)[:certificate]
2018-03-27 19:54:05 +05:30
end
let(:certificate_key) do
2020-03-28 13:19:24 +05:30
attributes_for(:pages_domain)[:key]
2018-03-27 19:54:05 +05:30
end
it 'adds new domain with certificate' do
visit new_project_pages_domain_path(project)
fill_in 'Domain', with: 'my.test.domain.com'
2019-12-26 22:10:19 +05:30
if ::Gitlab::LetsEncrypt.enabled?
find('.js-auto-ssl-toggle-container .project-feature-toggle').click
end
2018-03-27 19:54:05 +05:30
fill_in 'Certificate (PEM)', with: certificate_pem
fill_in 'Key (PEM)', with: certificate_key
click_button 'Create New Domain'
expect(page).to have_content('my.test.domain.com')
end
2020-05-24 23:13:21 +05:30
it 'shows validation error if domain is duplicated' do
project.pages_domains.create!(domain: 'my.test.domain.com')
visit new_project_pages_domain_path(project)
fill_in 'Domain', with: 'my.test.domain.com'
click_button 'Create New Domain'
expect(page).to have_content('Domain has already been taken')
end
2019-12-26 22:10:19 +05:30
describe 'with dns verification enabled' do
before do
stub_application_setting(pages_domain_verification_enabled: true)
end
it 'shows the DNS verification record' do
domain = create(:pages_domain, project: project)
visit project_pages_path(project)
within('#content-body') { click_link 'Edit' }
expect(page).to have_field :domain_verification, with: "#{domain.verification_domain} TXT #{domain.keyed_verification_code}"
end
end
2018-03-27 19:54:05 +05:30
describe 'updating the certificate for an existing domain' do
let!(:domain) do
2019-12-26 22:10:19 +05:30
create(:pages_domain, project: project, auto_ssl_enabled: false)
2018-03-27 19:54:05 +05:30
end
it 'allows the certificate to be updated' do
visit project_pages_path(project)
2019-12-26 22:10:19 +05:30
within('#content-body') { click_link 'Edit' }
2018-03-27 19:54:05 +05:30
click_button 'Save Changes'
expect(page).to have_content('Domain was updated')
end
context 'when the certificate is invalid' do
2019-12-26 22:10:19 +05:30
let!(:domain) do
create(:pages_domain, :without_certificate, :without_key, project: project)
end
2018-03-27 19:54:05 +05:30
it 'tells the user what the problem is' do
visit project_pages_path(project)
2019-12-26 22:10:19 +05:30
within('#content-body') { click_link 'Edit' }
if ::Gitlab::LetsEncrypt.enabled?
find('.js-auto-ssl-toggle-container .project-feature-toggle').click
end
2018-03-27 19:54:05 +05:30
fill_in 'Certificate (PEM)', with: 'invalid data'
click_button 'Save Changes'
expect(page).to have_content('Certificate must be a valid PEM certificate')
expect(page).to have_content('Certificate misses intermediates')
expect(page).to have_content("Key doesn't match the certificate")
end
end
2019-12-26 22:10:19 +05:30
it 'allows the certificate to be removed', :js do
visit project_pages_path(project)
within('#content-body') { click_link 'Edit' }
accept_confirm { click_link 'Remove' }
expect(page).to have_field('Certificate (PEM)', with: '')
expect(page).to have_field('Key (PEM)', with: '')
domain.reload
expect(domain.certificate).to be_nil
expect(domain.key).to be_nil
end
it 'shows the DNS CNAME record' do
visit project_pages_path(project)
within('#content-body') { click_link 'Edit' }
expect(page).to have_field :domain_dns, with: "#{domain.domain} CNAME #{domain.project.pages_subdomain}.#{Settings.pages.host}."
end
2018-03-27 19:54:05 +05:30
end
2017-08-17 22:00:37 +05:30
end
end
2019-07-07 11:18:12 +05:30
it 'does not see anything to destroy' do
visit project_pages_path(project)
expect(page).to have_content('Configure pages')
expect(page).not_to have_link('Remove pages')
end
2018-03-27 19:54:05 +05:30
describe 'project settings page' do
it 'renders "Pages" tab' do
visit edit_project_path(project)
page.within '.nav-sidebar' do
expect(page).to have_link('Pages')
end
end
context 'when pages are disabled' do
before do
allow(Gitlab.config.pages).to receive(:enabled).and_return(false)
end
it 'does not render "Pages" tab' do
visit edit_project_path(project)
page.within '.nav-sidebar' do
expect(page).not_to have_link('Pages')
end
end
end
end
2017-08-17 22:00:37 +05:30
end
2019-12-26 22:10:19 +05:30
describe 'HTTPS settings', :https_pages_enabled do
2018-11-08 19:23:39 +05:30
before do
2018-05-09 12:01:36 +05:30
project.namespace.update(owner: user)
allow_any_instance_of(Project).to receive(:pages_deployed?) { true }
end
2018-11-08 19:23:39 +05:30
it 'tries to change the setting' do
2018-05-09 12:01:36 +05:30
visit project_pages_path(project)
2019-07-07 11:18:12 +05:30
expect(page).to have_content("Force HTTPS (requires valid certificates)")
2018-05-09 12:01:36 +05:30
uncheck :project_pages_https_only
click_button 'Save'
expect(page).to have_text('Your changes have been saved')
expect(page).not_to have_checked_field('project_pages_https_only')
end
context 'setting could not be updated' do
let(:service) { instance_double('Projects::UpdateService') }
before do
allow(Projects::UpdateService).to receive(:new).and_return(service)
2020-03-13 15:44:24 +05:30
allow(service).to receive(:execute).and_return(status: :error, message: 'Some error has occured')
2018-05-09 12:01:36 +05:30
end
2018-11-08 19:23:39 +05:30
it 'tries to change the setting' do
2018-05-09 12:01:36 +05:30
visit project_pages_path(project)
uncheck :project_pages_https_only
click_button 'Save'
2020-03-13 15:44:24 +05:30
expect(page).to have_text('Some error has occured')
2018-05-09 12:01:36 +05:30
end
end
context 'non-HTTPS domain exists' do
2018-11-08 19:23:39 +05:30
let(:project) { create(:project, pages_https_only: false) }
2018-05-09 12:01:36 +05:30
before do
create(:pages_domain, :without_key, :without_certificate, project: project)
end
2018-11-08 19:23:39 +05:30
it 'the setting is disabled' do
2018-05-09 12:01:36 +05:30
visit project_pages_path(project)
expect(page).to have_field(:project_pages_https_only, disabled: true)
2020-03-13 15:44:24 +05:30
expect(page).to have_button('Save')
2018-05-09 12:01:36 +05:30
end
end
context 'HTTPS pages are disabled', :https_pages_disabled do
2018-11-08 19:23:39 +05:30
it 'the setting is unavailable' do
2018-05-09 12:01:36 +05:30
visit project_pages_path(project)
expect(page).not_to have_field(:project_pages_https_only)
2019-07-07 11:18:12 +05:30
expect(page).not_to have_content('Force HTTPS (requires valid certificates)')
2018-05-09 12:01:36 +05:30
expect(page).not_to have_button('Save')
end
end
end
2018-03-27 19:54:05 +05:30
describe 'Remove page' do
2019-07-07 11:18:12 +05:30
let(:project) { create :project, :repository }
context 'when pages are deployed' do
let(:pipeline) do
commit_sha = project.commit('HEAD').sha
project.ci_pipelines.create(
ref: 'HEAD',
sha: commit_sha,
source: :push,
protected: false
)
2019-05-18 00:54:41 +05:30
end
2018-03-27 19:54:05 +05:30
2019-07-07 11:18:12 +05:30
let(:ci_build) do
create(
:ci_build,
project: project,
pipeline: pipeline,
2019-09-04 21:01:54 +05:30
ref: 'HEAD')
end
let!(:artifact) do
create(:ci_job_artifact, :archive,
file: fixture_file_upload(File.join('spec/fixtures/pages.zip')), job: ci_build)
end
let!(:metadata) do
create(:ci_job_artifact, :metadata,
file: fixture_file_upload(File.join('spec/fixtures/pages.zip.meta')), job: ci_build)
2019-07-07 11:18:12 +05:30
end
2019-05-30 16:15:17 +05:30
2019-07-07 11:18:12 +05:30
before do
result = Projects::UpdatePagesService.new(project, ci_build).execute
expect(result[:status]).to eq(:success)
expect(project).to be_pages_deployed
end
2019-05-30 16:15:17 +05:30
2019-07-07 11:18:12 +05:30
it 'removes the pages' do
visit project_pages_path(project)
2018-03-27 19:54:05 +05:30
2019-07-07 11:18:12 +05:30
expect(page).to have_link('Remove pages')
2018-03-27 19:54:05 +05:30
2019-12-26 22:10:19 +05:30
accept_confirm { click_link 'Remove pages' }
2019-05-30 16:15:17 +05:30
2019-12-26 22:10:19 +05:30
expect(page).to have_content('Pages were removed')
expect(project.reload.pages_deployed?).to be_falsey
2018-03-27 19:54:05 +05:30
end
end
end
2017-08-17 22:00:37 +05:30
end
2019-09-04 21:01:54 +05:30
2019-12-26 22:10:19 +05:30
describe 'Pages', :js do
2019-09-30 21:07:59 +05:30
include LetsEncryptHelpers
2019-09-04 21:01:54 +05:30
2019-12-26 22:10:19 +05:30
context 'when editing normally' do
include_examples 'pages settings editing'
end
2019-09-04 21:01:54 +05:30
2019-09-30 21:07:59 +05:30
context 'when letsencrypt support is enabled' do
2019-09-04 21:01:54 +05:30
before do
2019-09-30 21:07:59 +05:30
stub_lets_encrypt_settings
2019-09-04 21:01:54 +05:30
end
2019-09-30 21:07:59 +05:30
include_examples 'pages settings editing'
2019-09-04 21:01:54 +05:30
end
end