Skip to content

Commit 99a6cc3

Browse files
authored
CI: Add an option to use SSL certifications generated from specific host. (#1310)
In the Fedora project, we are running the mysql2 tests on the build environment with a user permission, without root permission and without `sudo`. In this case, we couldn't set up the custom domain "mysql2gem.example.com" to run SSL tests. The feature to create a set of the SSL certifications from the localhost gives an option to run the SSL tests executed in the environment. How to generate the certificaton files: ``` $ cd spec/ssl/ $ TEST_RUBY_MYSQL2_SSL_CERT_HOST=localhost bash gen_certs.sh ``` The files are generated in the `spec/ssl` directory. How to use: ``` $ TEST_RUBY_MYSQL2_SSL_CERT_HOST=localhost \ bundle exec rake spec ```
1 parent 3adb531 commit 99a6cc3

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

.github/workflows/container.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
# Fedora latest stable version
1717
- {distro: fedora, image: 'fedora:latest'}
1818
# Fedora development version
19-
- {distro: fedora, image: 'fedora:rawhide', ssl_cert_dir: '/tmp/mysql2'}
19+
- {distro: fedora, image: 'fedora:rawhide', ssl_cert_dir: '/tmp/mysql2', ssl_cert_host: 'localhost'}
2020
# On the fail-fast: true, it cancels all in-progress jobs
2121
# if any matrix job fails unlike Travis fast_finish.
2222
fail-fast: false
@@ -29,8 +29,9 @@ jobs:
2929
# https://bugzilla.redhat.com/show_bug.cgi?id=1900021
3030
- run: |
3131
docker run \
32-
--add-host=mysql2gem.example.com:127.0.0.1 \
32+
--add-host=${{ matrix.ssl_cert_host || 'mysql2gem.example.com' }}:127.0.0.1 \
3333
-t \
3434
-e TEST_RUBY_MYSQL2_SSL_CERT_DIR="${{ matrix.ssl_cert_dir || '' }}" \
35+
-e TEST_RUBY_MYSQL2_SSL_CERT_HOST="${{ matrix.ssl_cert_host || '' }}" \
3536
--cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
3637
mysql2

ci/Dockerfile_fedora

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ RUN dnf -yq install \
1818
make \
1919
mariadb-connector-c-devel \
2020
mariadb-server \
21+
openssl \
2122
redhat-rpm-config \
2223
ruby-devel \
2324
rubygem-bigdecimal \

ci/container.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ set -eux
55
ruby -v
66
bundle install --path vendor/bundle --without development
77

8+
# Regenerate the SSL certification files from the specified host.
9+
if [ -n "${TEST_RUBY_MYSQL2_SSL_CERT_HOST}" ]; then
10+
pushd spec/ssl
11+
bash gen_certs.sh
12+
popd
13+
fi
14+
815
# Start mysqld service.
916
bash ci/setup_container.sh
1017

spec/mysql2/client_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def connect(*args)
153153

154154
let(:option_overrides) do
155155
{
156-
'host' => 'mysql2gem.example.com', # must match the certificates
156+
'host' => ssl_cert_host, # must match the certificates
157157
:sslkey => "#{ssl_cert_dir}/client-key.pem",
158158
:sslcert => "#{ssl_cert_dir}/client-cert.pem",
159159
:sslca => "#{ssl_cert_dir}/ca-cert.pem",

spec/spec_helper.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ def ssl_cert_dir
8181
@ssl_cert_dir
8282
end
8383

84+
# A host used to create the certificates pem files.
85+
def ssl_cert_host
86+
return @ssl_cert_host if @ssl_cert_host
87+
88+
host = ENV['TEST_RUBY_MYSQL2_SSL_CERT_HOST']
89+
@ssl_cert_host = if host && !host.empty?
90+
host
91+
else
92+
'mysql2gem.example.com'
93+
end
94+
@ssl_cert_host
95+
end
96+
8497
config.before(:suite) do
8598
begin
8699
new_client

spec/ssl/gen_certs.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
set -eux
44

5+
# TEST_RUBY_MYSQL2_SSL_CERT_HOST: custom host for the SSL certificates.
6+
SSL_CERT_HOST=${TEST_RUBY_MYSQL2_SSL_CERT_HOST:-mysql2gem.example.com}
7+
echo "Generating the SSL certifications from the host ${SSL_CERT_HOST}.."
8+
59
echo "
610
[ ca ]
711
# January 1, 2015
@@ -34,7 +38,7 @@ commonName_default = ca_mysql2gem
3438
" >> ca.cnf
3539

3640
echo "
37-
commonName_default = mysql2gem.example.com
41+
commonName_default = ${SSL_CERT_HOST}
3842
" >> cert.cnf
3943

4044
# Generate a set of certificates

0 commit comments

Comments
 (0)