Skip to content

Commit a32659c

Browse files
committed
Add an option to set a custom SSL pem files directory in test.
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 pem files required to run SSL tests in the `/etc/mysql`. This custom SSL directory option gives an option to run the SSL tests executed in the environment. How to use: ``` $ TEST_RUBY_MYSQL2_SSL_DIR=/tmp/mysql2 \ bundle exec rake spec ```
1 parent 7f6f33a commit a32659c

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

.github/workflows/container.yml

Lines changed: 8 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'}
19+
- {distro: fedora, image: 'fedora:rawhide', ssl_dir: '/tmp/mysql2'}
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
@@ -27,4 +27,10 @@ jobs:
2727
# as a temporary workaround to avoid the following issue
2828
# in the Fedora >= 34 containers.
2929
# https://bugzilla.redhat.com/show_bug.cgi?id=1900021
30-
- run: docker run --add-host=mysql2gem.example.com:127.0.0.1 -t --cap-add=SYS_PTRACE --security-opt seccomp=unconfined mysql2
30+
- run: |
31+
docker run \
32+
--add-host=mysql2gem.example.com:127.0.0.1 \
33+
-t \
34+
-e TEST_RUBY_MYSQL2_SSL_DIR="${{ matrix.ssl_dir || '' }}" \
35+
--cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
36+
mysql2

ci/ssl.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22

33
set -eux
44

5+
# TEST_RUBY_MYSQL2_SSL_DIR: custom SSL directory.
6+
SSL_DIR=${TEST_RUBY_MYSQL2_SSL_DIR:-/etc/mysql}
7+
58
# Make sure there is an /etc/mysql
6-
mkdir -p /etc/mysql
9+
mkdir -p "${SSL_DIR}"
710

811
# Copy the local certs to /etc/mysql
9-
cp spec/ssl/*pem /etc/mysql/
12+
cp spec/ssl/*pem "${SSL_DIR}"
1013

1114
# Wherever MySQL configs live, go there (this is for cross-platform)
1215
cd $(my_print_defaults --help | grep my.cnf | xargs find 2>/dev/null | xargs dirname)
1316

1417
# Put the configs into the server
1518
echo "
1619
[mysqld]
17-
ssl-ca=/etc/mysql/ca-cert.pem
18-
ssl-cert=/etc/mysql/server-cert.pem
19-
ssl-key=/etc/mysql/server-key.pem
20+
ssl-ca=${SSL_DIR}/ca-cert.pem
21+
ssl-cert=${SSL_DIR}/server-cert.pem
22+
ssl-key=${SSL_DIR}/server-key.pem
2023
" >> my.cnf

spec/mysql2/client_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ def connect(*args)
154154
let(:option_overrides) do
155155
{
156156
'host' => 'mysql2gem.example.com', # must match the certificates
157-
:sslkey => '/etc/mysql/client-key.pem',
158-
:sslcert => '/etc/mysql/client-cert.pem',
159-
:sslca => '/etc/mysql/ca-cert.pem',
157+
:sslkey => "#{ssl_dir}/client-key.pem",
158+
:sslcert => "#{ssl_dir}/client-cert.pem",
159+
:sslca => "#{ssl_dir}/ca-cert.pem",
160160
:sslcipher => 'DHE-RSA-AES256-SHA',
161161
:sslverify => true,
162162
}

spec/spec_helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ def clock_time
6060
end
6161
end
6262

63+
# A directory where SSL pem files exist.
64+
def ssl_dir
65+
return @ssl_dir if @ssl_dir
66+
67+
@ssl_dir = ENV['TEST_RUBY_MYSQL2_SSL_DIR'] || '/etc/mysql'
68+
@ssl_dir
69+
end
70+
6371
config.before(:suite) do
6472
begin
6573
new_client

0 commit comments

Comments
 (0)