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

168 lines
5.8 KiB
Ruby
Raw Normal View History

2019-09-04 21:01:54 +05:30
# frozen_string_literal: true
require 'spec_helper'
describe "Pages with Let's Encrypt", :https_pages_enabled do
2019-09-30 21:07:59 +05:30
include LetsEncryptHelpers
2019-12-26 22:10:19 +05:30
let(:project) { create(:project, pages_https_only: false) }
2019-09-04 21:01:54 +05:30
let(:user) { create(:user) }
let(:role) { :maintainer }
2019-09-30 21:07:59 +05:30
let(:certificate_pem) { attributes_for(:pages_domain)[:certificate] }
2019-09-04 21:01:54 +05:30
2019-09-30 21:07:59 +05:30
let(:certificate_key) { attributes_for(:pages_domain)[:key] }
2019-09-04 21:01:54 +05:30
before do
allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
2019-09-30 21:07:59 +05:30
stub_lets_encrypt_settings
2019-09-04 21:01:54 +05:30
project.add_role(user, role)
sign_in(user)
project.namespace.update(owner: user)
2019-12-26 22:10:19 +05:30
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:pages_deployed?) { true }
end
end
it "creates new domain with Let's Encrypt enabled by default" do
visit new_project_pages_domain_path(project)
fill_in 'Domain', with: 'my.test.domain.com'
expect(find("#pages_domain_auto_ssl_enabled", visible: false).value).to eq 'true'
click_button 'Create New Domain'
expect(page).to have_content('my.test.domain.com')
expect(PagesDomain.find_by_domain('my.test.domain.com').auto_ssl_enabled).to eq(true)
2019-09-04 21:01:54 +05:30
end
2019-09-30 21:07:59 +05:30
context 'when the auto SSL management is initially disabled' do
let(:domain) do
create(:pages_domain, auto_ssl_enabled: false, project: project)
2019-09-04 21:01:54 +05:30
end
2019-09-30 21:07:59 +05:30
it 'enables auto SSL and dynamically updates the form accordingly', :js do
2020-01-01 13:55:28 +05:30
visit project_pages_domain_path(project, domain)
2019-09-04 21:01:54 +05:30
2019-09-30 21:07:59 +05:30
expect(domain.auto_ssl_enabled).to eq false
2019-09-04 21:01:54 +05:30
2019-09-30 21:07:59 +05:30
expect(find("#pages_domain_auto_ssl_enabled", visible: false).value).to eq 'false'
2019-12-26 22:10:19 +05:30
expect(page).to have_selector '.card-header', text: 'Certificate'
expect(page).to have_text domain.subject
2019-09-04 21:01:54 +05:30
2019-09-30 21:07:59 +05:30
find('.js-auto-ssl-toggle-container .project-feature-toggle').click
2019-09-04 21:01:54 +05:30
2019-09-30 21:07:59 +05:30
expect(find("#pages_domain_auto_ssl_enabled", visible: false).value).to eq 'true'
2019-12-26 22:10:19 +05:30
expect(page).not_to have_selector '.card-header', text: 'Certificate'
expect(page).not_to have_text domain.subject
2019-09-04 21:01:54 +05:30
2019-09-30 21:07:59 +05:30
click_on 'Save Changes'
2019-09-04 21:01:54 +05:30
2019-09-30 21:07:59 +05:30
expect(domain.reload.auto_ssl_enabled).to eq true
end
end
2019-09-04 21:01:54 +05:30
2019-09-30 21:07:59 +05:30
context 'when the auto SSL management is initially enabled' do
let(:domain) do
create(:pages_domain, :letsencrypt, auto_ssl_enabled: true, project: project)
2019-09-04 21:01:54 +05:30
end
2019-09-30 21:07:59 +05:30
it 'disables auto SSL and dynamically updates the form accordingly', :js do
2020-01-01 13:55:28 +05:30
visit project_pages_domain_path(project, domain)
2019-09-04 21:01:54 +05:30
2019-09-30 21:07:59 +05:30
expect(find("#pages_domain_auto_ssl_enabled", visible: false).value).to eq 'true'
expect(page).not_to have_field 'Certificate (PEM)', type: 'textarea'
expect(page).not_to have_field 'Key (PEM)', type: 'textarea'
2019-09-04 21:01:54 +05:30
2019-09-30 21:07:59 +05:30
find('.js-auto-ssl-toggle-container .project-feature-toggle').click
2019-09-04 21:01:54 +05:30
2019-09-30 21:07:59 +05:30
expect(find("#pages_domain_auto_ssl_enabled", visible: false).value).to eq 'false'
expect(page).to have_field 'Certificate (PEM)', type: 'textarea'
expect(page).to have_field 'Key (PEM)', type: 'textarea'
2019-09-04 21:01:54 +05:30
2019-09-30 21:07:59 +05:30
click_on 'Save Changes'
2019-09-04 21:01:54 +05:30
2019-09-30 21:07:59 +05:30
expect(domain.reload.auto_ssl_enabled).to eq false
end
end
2019-09-04 21:01:54 +05:30
2020-04-22 19:07:51 +05:30
context "when we failed to obtain Let's Encrypt certificate", :js do
let(:domain) do
create(:pages_domain, auto_ssl_enabled: true, auto_ssl_failed: true, project: project)
end
it 'user can retry obtaining certificate' do
visit project_pages_domain_path(project, domain)
expect(page).to have_text("Something went wrong while obtaining the Let's Encrypt certificate.")
click_on('Retry')
expect(page).to have_text("GitLab is obtaining a Let's Encrypt SSL certificate for this domain. This process can take some time. Please try again later.")
end
end
2019-09-30 21:07:59 +05:30
shared_examples 'user sees private keys only for user provided certificate' do
shared_examples 'user do not see private key' do
it 'user do not see private key' do
2020-01-01 13:55:28 +05:30
visit project_pages_domain_path(project, domain)
2019-12-04 20:38:33 +05:30
2019-12-26 22:10:19 +05:30
expect(page).not_to have_selector '.card-header', text: 'Certificate'
expect(page).not_to have_text domain.subject
2019-09-30 21:07:59 +05:30
end
end
context 'when auto_ssl is enabled for domain' do
let(:domain) { create(:pages_domain, :letsencrypt, project: project, auto_ssl_enabled: true) }
include_examples 'user do not see private key'
end
context 'when auto_ssl is disabled for domain' do
let(:domain) { create(:pages_domain, :letsencrypt, project: project) }
include_examples 'user do not see private key'
end
context 'when certificate is provided by user' do
2019-12-26 22:10:19 +05:30
let(:domain) { create(:pages_domain, project: project, auto_ssl_enabled: false) }
it 'user sees certificate subject' do
2020-01-01 13:55:28 +05:30
visit project_pages_domain_path(project, domain)
2019-12-26 22:10:19 +05:30
expect(page).to have_selector '.card-header', text: 'Certificate'
expect(page).to have_text domain.subject
end
2019-09-30 21:07:59 +05:30
2019-12-26 22:10:19 +05:30
it 'user can delete the certificate', :js do
2020-01-01 13:55:28 +05:30
visit project_pages_domain_path(project, domain)
2019-12-04 20:38:33 +05:30
2019-12-26 22:10:19 +05:30
expect(page).to have_selector '.card-header', text: 'Certificate'
expect(page).to have_text domain.subject
within('.card') { accept_confirm { click_on 'Remove' } }
expect(page).to have_field 'Certificate (PEM)', with: ''
expect(page).to have_field 'Key (PEM)', with: ''
2019-09-04 21:01:54 +05:30
end
end
end
2019-09-30 21:07:59 +05:30
include_examples 'user sees private keys only for user provided certificate'
context 'when letsencrypt is disabled' do
2019-09-04 21:01:54 +05:30
let(:domain) do
create(:pages_domain, auto_ssl_enabled: false, project: project)
end
before do
2019-09-30 21:07:59 +05:30
stub_application_setting(lets_encrypt_terms_of_service_accepted: false)
2019-09-04 21:01:54 +05:30
2020-01-01 13:55:28 +05:30
visit project_pages_domain_path(project, domain)
2019-09-04 21:01:54 +05:30
end
it "does not render the Let's Encrypt field", :js do
expect(page).not_to have_selector '.js-auto-ssl-toggle-container'
end
2019-09-30 21:07:59 +05:30
include_examples 'user sees private keys only for user provided certificate'
2019-09-04 21:01:54 +05:30
end
end