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

129 lines
4.2 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-09-04 21:01:54 +05:30
let(:project) { create(:project) }
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)
allow_any_instance_of(Project).to receive(:pages_deployed?) { true }
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
visit edit_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'
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
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'
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
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
visit edit_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
fill_in 'Certificate (PEM)', with: certificate_pem
fill_in 'Key (PEM)', with: certificate_key
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
2019-09-30 21:07:59 +05:30
shared_examples 'user sees private keys only for user provided certificate' do
before do
visit edit_project_pages_domain_path(project, domain)
end
shared_examples 'user do not see private key' do
it 'user do not see private key' do
expect(find_field('Key (PEM)', visible: :all, disabled: :all).value).to be_blank
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
let(:domain) { create(:pages_domain, project: project) }
it 'user sees private key' do
expect(find_field('Key (PEM)').value).not_to be_blank
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
visit edit_project_pages_domain_path(project, domain)
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