diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index af57ef136..d53c78d2f 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -16,7 +16,7 @@ jobs: # Fedora latest stable version - {distro: fedora, image: 'fedora:latest'} # Fedora development version - - {distro: fedora, image: 'fedora:rawhide', ssl_cert_dir: '/tmp/mysql2'} + - {distro: fedora, image: 'fedora:rawhide', ssl_cert_dir: '/tmp/mysql2', ssl_cert_host: 'localhost'} # On the fail-fast: true, it cancels all in-progress jobs # if any matrix job fails unlike Travis fast_finish. fail-fast: false @@ -29,8 +29,9 @@ jobs: # https://bugzilla.redhat.com/show_bug.cgi?id=1900021 - run: | docker run \ - --add-host=mysql2gem.example.com:127.0.0.1 \ + --add-host=${{ matrix.ssl_cert_host || 'mysql2gem.example.com' }}:127.0.0.1 \ -t \ -e TEST_RUBY_MYSQL2_SSL_CERT_DIR="${{ matrix.ssl_cert_dir || '' }}" \ + -e TEST_RUBY_MYSQL2_SSL_CERT_HOST="${{ matrix.ssl_cert_host || '' }}" \ --cap-add=SYS_PTRACE --security-opt seccomp=unconfined \ mysql2 diff --git a/ci/Dockerfile_fedora b/ci/Dockerfile_fedora index 644b5974f..f709b42cb 100644 --- a/ci/Dockerfile_fedora +++ b/ci/Dockerfile_fedora @@ -17,6 +17,7 @@ RUN dnf -yq install \ make \ mariadb-connector-c-devel \ mariadb-server \ + openssl \ redhat-rpm-config \ ruby-devel \ rubygem-bigdecimal \ diff --git a/ci/container.sh b/ci/container.sh index 90552a919..88764a389 100644 --- a/ci/container.sh +++ b/ci/container.sh @@ -5,6 +5,13 @@ set -eux ruby -v bundle install --path vendor/bundle --without development +# Regenerate the SSL certification files from the specified host. +if [ -n "${TEST_RUBY_MYSQL2_SSL_CERT_HOST}" ]; then + pushd spec/ssl + bash gen_certs.sh + popd +fi + # Start mysqld service. bash ci/setup_container.sh diff --git a/spec/mysql2/client_spec.rb b/spec/mysql2/client_spec.rb index db7c4b88b..639ed01a1 100644 --- a/spec/mysql2/client_spec.rb +++ b/spec/mysql2/client_spec.rb @@ -153,7 +153,7 @@ def connect(*args) let(:option_overrides) do { - 'host' => 'mysql2gem.example.com', # must match the certificates + 'host' => ssl_cert_host, # must match the certificates :sslkey => "#{ssl_cert_dir}/client-key.pem", :sslcert => "#{ssl_cert_dir}/client-cert.pem", :sslca => "#{ssl_cert_dir}/ca-cert.pem", diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2e924eb42..1441d60f1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -73,6 +73,19 @@ def ssl_cert_dir @ssl_cert_dir end + # A host used to create the certificates pem files. + def ssl_cert_host + return @ssl_cert_host if @ssl_cert_host + + host = ENV['TEST_RUBY_MYSQL2_SSL_CERT_HOST'] + @ssl_cert_host = if host && !host.empty? + host + else + 'mysql2gem.example.com' + end + @ssl_cert_host + end + config.before(:suite) do begin new_client diff --git a/spec/ssl/gen_certs.sh b/spec/ssl/gen_certs.sh index 3d48da014..2f1f6a6df 100644 --- a/spec/ssl/gen_certs.sh +++ b/spec/ssl/gen_certs.sh @@ -2,6 +2,10 @@ set -eux +# TEST_RUBY_MYSQL2_SSL_CERT_HOST: custom host for the SSL certificates. +SSL_CERT_HOST=${TEST_RUBY_MYSQL2_SSL_CERT_HOST:-mysql2gem.example.com} +echo "Generating the SSL certifications from the host ${SSL_CERT_HOST}.." + echo " [ ca ] # January 1, 2015 @@ -30,7 +34,7 @@ commonName_default = ca_mysql2gem " >> ca.cnf echo " -commonName_default = mysql2gem.example.com +commonName_default = ${SSL_CERT_HOST} " >> cert.cnf # Generate a set of certificates