Commit a331e749 authored by Vladimir Shushlin's avatar Vladimir Shushlin

Refactor pages feature spec

* no need to run settings tests with letsencrypt enabled/disabled
  they don't depend on it
* there is already a separate file for LE specs, so no need to check
  in general domain tests
* move everything to a subdirectory
parent 1371e8d5
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'User adds pages domain', :js do
include LetsEncryptHelpers
let_it_be(:project) { create(:project, pages_https_only: false) }
let(:user) { create(:user) }
before do
allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
project.add_maintainer(user)
sign_in(user)
end
context 'when pages are exposed on external HTTP address', :http_pages_enabled do
let(:project) { create(:project, pages_https_only: false) }
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 }
let(:project) { create(:project, namespace: group, pages_https_only: false) }
end
end
context 'when pages domain is added' do
before do
create(:pages_domain, project: project, domain: 'my.test.domain.com')
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
context 'when pages are exposed on external HTTPS address', :https_pages_enabled, :js do
let(:certificate_pem) do
attributes_for(:pages_domain)[:certificate]
end
let(:certificate_key) do
attributes_for(:pages_domain)[:key]
end
it 'adds new domain with certificate' do
visit new_project_pages_domain_path(project)
fill_in 'Domain', with: 'my.test.domain.com'
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
it "adds new domain with certificate if Let's Encrypt is enabled" do
stub_lets_encrypt_settings
visit new_project_pages_domain_path(project)
fill_in 'Domain', with: 'my.test.domain.com'
find('.js-auto-ssl-toggle-container .project-feature-toggle').click
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
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
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
describe 'updating the certificate for an existing domain' do
let!(:domain) do
create(:pages_domain, project: project, auto_ssl_enabled: false)
end
it 'allows the certificate to be updated' do
visit project_pages_path(project)
within('#content-body') { click_link 'Edit' }
click_button 'Save Changes'
expect(page).to have_content('Domain was updated')
end
context 'when the certificate is invalid' do
let!(:domain) do
create(:pages_domain, :without_certificate, :without_key, project: project)
end
it 'tells the user what the problem is' do
visit project_pages_path(project)
within('#content-body') { click_link 'Edit' }
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
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
end
end
end
...@@ -17,7 +17,7 @@ RSpec.describe "Pages with Let's Encrypt", :https_pages_enabled do ...@@ -17,7 +17,7 @@ RSpec.describe "Pages with Let's Encrypt", :https_pages_enabled do
project.add_role(user, role) project.add_role(user, role)
sign_in(user) sign_in(user)
project.namespace.update(owner: user) project.namespace.update!(owner: user)
allow_next_instance_of(Project) do |instance| allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:pages_deployed?) { true } allow(instance).to receive(:pages_deployed?) { true }
end end
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
RSpec.shared_examples 'pages settings editing' do RSpec.describe 'Pages edits pages settings', :js do
let_it_be(:project) { create(:project, pages_https_only: false) } let(:project) { create(:project, pages_https_only: false) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:role) { :maintainer }
before do before do
allow(Gitlab.config.pages).to receive(:enabled).and_return(true) allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
project.add_role(user, role) project.add_maintainer(user)
sign_in(user) sign_in(user)
end end
context 'when user is the owner' do context 'when user is the owner' do
before do before do
project.namespace.update(owner: user) project.namespace.update!(owner: user)
end end
context 'when pages deployed' do context 'when pages deployed' do
before do before do
allow_any_instance_of(Project).to receive(:pages_deployed?) { true } project.mark_pages_as_deployed
end end
it 'renders Access pages' do it 'renders Access pages' do
...@@ -83,166 +82,6 @@ RSpec.shared_examples 'pages settings editing' do ...@@ -83,166 +82,6 @@ RSpec.shared_examples 'pages settings editing' do
expect(page).to have_content('Support for domains and certificates is disabled') expect(page).to have_content('Support for domains and certificates is disabled')
end end
end end
context 'when pages are exposed on external HTTP address', :http_pages_enabled do
let(:project) { create(:project, pages_https_only: false) }
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 }
let(:project) { create(:project, namespace: group, pages_https_only: false) }
end
end
context 'when pages domain is added' do
before do
create(:pages_domain, project: project, domain: 'my.test.domain.com')
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
context 'when pages are exposed on external HTTPS address', :https_pages_enabled, :js do
let(:certificate_pem) do
attributes_for(:pages_domain)[:certificate]
end
let(:certificate_key) do
attributes_for(:pages_domain)[:key]
end
it 'adds new domain with certificate' do
visit new_project_pages_domain_path(project)
fill_in 'Domain', with: 'my.test.domain.com'
if ::Gitlab::LetsEncrypt.enabled?
find('.js-auto-ssl-toggle-container .project-feature-toggle').click
end
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
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
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
describe 'updating the certificate for an existing domain' do
let!(:domain) do
create(:pages_domain, project: project, auto_ssl_enabled: false)
end
it 'allows the certificate to be updated' do
visit project_pages_path(project)
within('#content-body') { click_link 'Edit' }
click_button 'Save Changes'
expect(page).to have_content('Domain was updated')
end
context 'when the certificate is invalid' do
let!(:domain) do
create(:pages_domain, :without_certificate, :without_key, project: project)
end
it 'tells the user what the problem is' do
visit project_pages_path(project)
within('#content-body') { click_link 'Edit' }
if ::Gitlab::LetsEncrypt.enabled?
find('.js-auto-ssl-toggle-container .project-feature-toggle').click
end
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
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
end
end
end end
it 'does not see anything to destroy' do it 'does not see anything to destroy' do
...@@ -279,9 +118,9 @@ RSpec.shared_examples 'pages settings editing' do ...@@ -279,9 +118,9 @@ RSpec.shared_examples 'pages settings editing' do
describe 'HTTPS settings', :https_pages_enabled do describe 'HTTPS settings', :https_pages_enabled do
before do before do
project.namespace.update(owner: user) project.namespace.update!(owner: user)
allow_any_instance_of(Project).to receive(:pages_deployed?) { true } project.mark_pages_as_deployed
end end
it 'tries to change the setting' do it 'tries to change the setting' do
...@@ -342,42 +181,9 @@ RSpec.shared_examples 'pages settings editing' do ...@@ -342,42 +181,9 @@ RSpec.shared_examples 'pages settings editing' do
end end
describe 'Remove page' do describe 'Remove page' do
let(:project) { create :project, :repository }
context 'when pages are deployed' do 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
)
end
let(:ci_build) do
create(
:ci_build,
project: project,
pipeline: pipeline,
ref: 'HEAD')
end
let!(:artifact) do
create(:ci_job_artifact, :archive, :correct_checksum,
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)
end
before do before do
result = Projects::UpdatePagesService.new(project, ci_build).execute project.mark_pages_as_deployed
expect(result[:status]).to eq(:success)
expect(project).to be_pages_deployed
end end
it 'removes the pages', :sidekiq_inline do it 'removes the pages', :sidekiq_inline do
...@@ -393,19 +199,3 @@ RSpec.shared_examples 'pages settings editing' do ...@@ -393,19 +199,3 @@ RSpec.shared_examples 'pages settings editing' do
end end
end end
end end
RSpec.describe 'Pages', :js do
include LetsEncryptHelpers
context 'when editing normally' do
include_examples 'pages settings editing'
end
context 'when letsencrypt support is enabled' do
before do
stub_lets_encrypt_settings
end
include_examples 'pages settings editing'
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