2019-05-31 08:58:23 -04:00
# frozen_string_literal: true
require 'spec_helper'
2020-06-16 14:09:01 -04:00
RSpec . describe " Pages with Let's Encrypt " , :https_pages_enabled do
2019-06-21 08:06:12 -04:00
include LetsEncryptHelpers
2019-11-15 13:06:24 -05:00
let ( :project ) { create ( :project , pages_https_only : false ) }
2019-05-31 08:58:23 -04:00
let ( :user ) { create ( :user ) }
let ( :role ) { :maintainer }
2019-06-21 08:06:12 -04:00
let ( :certificate_pem ) { attributes_for ( :pages_domain ) [ :certificate ] }
2019-05-31 08:58:23 -04:00
2019-06-21 08:06:12 -04:00
let ( :certificate_key ) { attributes_for ( :pages_domain ) [ :key ] }
2019-05-31 08:58:23 -04:00
before do
allow ( Gitlab . config . pages ) . to receive ( :enabled ) . and_return ( true )
2019-06-21 08:06:12 -04:00
stub_lets_encrypt_settings
2019-05-31 08:58:23 -04:00
project . add_role ( user , role )
sign_in ( user )
project . namespace . update ( owner : user )
2019-11-13 22:06:25 -05:00
allow_next_instance_of ( Project ) do | instance |
allow ( instance ) . to receive ( :pages_deployed? ) { true }
end
2019-05-31 08:58:23 -04:00
end
2019-11-15 16:06:14 -05:00
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 )
end
2019-06-21 08:06:12 -04:00
context 'when the auto SSL management is initially disabled' do
let ( :domain ) do
create ( :pages_domain , auto_ssl_enabled : false , project : project )
2019-05-31 08:58:23 -04:00
end
2019-06-21 08:06:12 -04:00
it 'enables auto SSL and dynamically updates the form accordingly' , :js do
2019-12-10 02:53:40 -05:00
visit project_pages_domain_path ( project , domain )
2019-05-31 08:58:23 -04:00
2019-06-21 08:06:12 -04:00
expect ( domain . auto_ssl_enabled ) . to eq false
2019-05-31 08:58:23 -04:00
2019-06-21 08:06:12 -04:00
expect ( find ( " # pages_domain_auto_ssl_enabled " , visible : false ) . value ) . to eq 'false'
2019-11-15 13:06:24 -05:00
expect ( page ) . to have_selector '.card-header' , text : 'Certificate'
expect ( page ) . to have_text domain . subject
2019-05-31 08:58:23 -04:00
2019-06-21 08:06:12 -04:00
find ( '.js-auto-ssl-toggle-container .project-feature-toggle' ) . click
2019-05-31 08:58:23 -04:00
2019-06-21 08:06:12 -04:00
expect ( find ( " # pages_domain_auto_ssl_enabled " , visible : false ) . value ) . to eq 'true'
2019-11-15 13:06:24 -05:00
expect ( page ) . not_to have_selector '.card-header' , text : 'Certificate'
expect ( page ) . not_to have_text domain . subject
2019-05-31 08:58:23 -04:00
2019-06-21 08:06:12 -04:00
click_on 'Save Changes'
2019-05-31 08:58:23 -04:00
2019-06-21 08:06:12 -04:00
expect ( domain . reload . auto_ssl_enabled ) . to eq true
end
end
2019-05-31 08:58:23 -04:00
2019-06-21 08:06:12 -04:00
context 'when the auto SSL management is initially enabled' do
let ( :domain ) do
create ( :pages_domain , :letsencrypt , auto_ssl_enabled : true , project : project )
2019-05-31 08:58:23 -04:00
end
2019-06-21 08:06:12 -04:00
it 'disables auto SSL and dynamically updates the form accordingly' , :js do
2019-12-10 02:53:40 -05:00
visit project_pages_domain_path ( project , domain )
2019-05-31 08:58:23 -04:00
2019-06-21 08:06:12 -04:00
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-05-31 08:58:23 -04:00
2019-06-21 08:06:12 -04:00
find ( '.js-auto-ssl-toggle-container .project-feature-toggle' ) . click
2019-05-31 08:58:23 -04:00
2019-06-21 08:06:12 -04:00
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-05-31 08:58:23 -04:00
2019-06-21 08:06:12 -04:00
click_on 'Save Changes'
2019-05-31 08:58:23 -04:00
2019-06-21 08:06:12 -04:00
expect ( domain . reload . auto_ssl_enabled ) . to eq false
end
end
2019-05-31 08:58:23 -04:00
2020-04-14 17:09:52 -04:00
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-06-21 08:06:12 -04:00
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
2019-12-10 02:53:40 -05:00
visit project_pages_domain_path ( project , domain )
2019-08-13 13:14:13 -04:00
2019-11-15 13:06:24 -05:00
expect ( page ) . not_to have_selector '.card-header' , text : 'Certificate'
expect ( page ) . not_to have_text domain . subject
2019-06-21 08:06:12 -04:00
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-11-15 16:06:14 -05:00
let ( :domain ) { create ( :pages_domain , project : project , auto_ssl_enabled : false ) }
2019-06-21 08:06:12 -04:00
2019-11-15 13:06:24 -05:00
it 'user sees certificate subject' do
2019-12-10 02:53:40 -05:00
visit project_pages_domain_path ( project , domain )
2019-11-15 13:06:24 -05:00
expect ( page ) . to have_selector '.card-header' , text : 'Certificate'
expect ( page ) . to have_text domain . subject
end
it 'user can delete the certificate' , :js do
2019-12-10 02:53:40 -05:00
visit project_pages_domain_path ( project , domain )
2019-08-13 13:14:13 -04:00
2019-11-15 13:06:24 -05:00
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-05-31 08:58:23 -04:00
end
end
end
2019-06-21 08:06:12 -04:00
include_examples 'user sees private keys only for user provided certificate'
context 'when letsencrypt is disabled' do
2019-05-31 08:58:23 -04:00
let ( :domain ) do
create ( :pages_domain , auto_ssl_enabled : false , project : project )
end
before do
2019-06-21 08:06:12 -04:00
stub_application_setting ( lets_encrypt_terms_of_service_accepted : false )
2019-05-31 08:58:23 -04:00
2019-12-10 02:53:40 -05:00
visit project_pages_domain_path ( project , domain )
2019-05-31 08:58:23 -04:00
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-06-21 08:06:12 -04:00
include_examples 'user sees private keys only for user provided certificate'
2019-05-31 08:58:23 -04:00
end
end