Skip to content

Commit 7f4e844

Browse files
authored
Merge pull request #1183 from vakuum/master
Can't enable SSL with MariaDB driver library. (#1182)
2 parents ca883e1 + 7dcd371 commit 7f4e844

File tree

4 files changed

+62
-33
lines changed

4 files changed

+62
-33
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- {os: ubuntu-16.04, ruby: 2.4, db: mariadb10.0, allow-failure: true}
3232
# Comment out due to ci/setup.sh stucking.
3333
# - {os: ubuntu-18.04, ruby: 2.4, db: mariadb10.1}
34-
# `service mysql restart` fails.
34+
# Allow failure due to the issue #965, #1165.
3535
- {os: ubuntu-20.04, ruby: 2.4, db: mariadb10.3, allow-failure: true}
3636
- {os: ubuntu-18.04, ruby: 2.4, db: mysql57}
3737
# Allow failure due to the issue #1165.

ci/setup.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ fi
7272

7373
# Install MariaDB 10.3 if DB=mariadb10.3
7474
if [[ -n ${GITHUB_ACTIONS-} && -n ${DB-} && x$DB =~ ^xmariadb10.3 ]]; then
75+
sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
76+
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld
77+
sudo apt-get purge -y 'mysql-common*' 'mysql-client*' 'mysql-server*'
78+
sudo mv /etc/mysql "/etc/mysql-$(date +%Y%m%d-%H%M%S)"
79+
sudo mv /var/lib/mysql "/var/lib/mysql-$(date +%Y%m%d-%H%M%S)"
7580
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' mariadb-server mariadb-server-10.3 libmariadb-dev
76-
CHANGED_PASSWORD=true
81+
CHANGED_PASSWORD_BY_RECREATE=true
7782
fi
7883

7984
# Install MySQL/MariaDB if OS=darwin

ext/mysql2/client.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ static VALUE rb_set_ssl_mode_option(VALUE self, VALUE setting) {
124124
#ifdef HAVE_CONST_MYSQL_OPT_SSL_ENFORCE
125125
GET_CLIENT(self);
126126
int val = NUM2INT( setting );
127-
// Either MySQL 5.7.3 - 5.7.10, or Connector/C 6.1.3 - 6.1.x
128-
if ((version >= 50703 && version < 50711) || (version >= 60103 && version < 60200)) {
127+
// Either MySQL 5.7.3 - 5.7.10, or Connector/C 6.1.3 - 6.1.x, or MariaDB 10.x
128+
if ((version >= 50703 && version < 50711) || (version >= 60103 && version < 60200) || (version >= 100000 && version < 110000)) {
129129
if (val == SSL_MODE_DISABLED || val == SSL_MODE_REQUIRED) {
130130
my_bool b = ( val == SSL_MODE_REQUIRED );
131131
int result = mysql_options( wrapper->client, MYSQL_OPT_SSL_ENFORCE, &b );

spec/mysql2/client_spec.rb

+53-29
Original file line numberDiff line numberDiff line change
@@ -131,39 +131,63 @@ def connect(*args)
131131
expect(Mysql2::Client).to respond_to(:default_query_options)
132132
end
133133

134-
it "should be able to connect via SSL options" do
135-
ssl = @client.query "SHOW VARIABLES LIKE 'have_ssl'"
136-
ssl_uncompiled = ssl.any? { |x| x['Value'] == 'OFF' }
137-
pending("DON'T WORRY, THIS TEST PASSES - but SSL is not compiled into your MySQL daemon.") if ssl_uncompiled
138-
ssl_disabled = ssl.any? { |x| x['Value'] == 'DISABLED' }
139-
pending("DON'T WORRY, THIS TEST PASSES - but SSL is not enabled in your MySQL daemon.") if ssl_disabled
140-
141-
# You may need to adjust the lines below to match your SSL certificate paths
142-
ssl_client = nil
143-
option_overrides = {
144-
'host' => 'mysql2gem.example.com', # must match the certificates
145-
:sslkey => '/etc/mysql/client-key.pem',
146-
:sslcert => '/etc/mysql/client-cert.pem',
147-
:sslca => '/etc/mysql/ca-cert.pem',
148-
:sslcipher => 'DHE-RSA-AES256-SHA',
149-
:sslverify => true,
150-
}
151-
%i[sslkey sslcert sslca].each do |item|
152-
unless File.exist?(option_overrides[item])
153-
pending("DON'T WORRY, THIS TEST PASSES - but #{option_overrides[item]} does not exist.")
154-
break
134+
context "SSL" do
135+
before(:example) do
136+
ssl = @client.query "SHOW VARIABLES LIKE 'have_ssl'"
137+
ssl_uncompiled = ssl.any? { |x| x['Value'] == 'OFF' }
138+
ssl_disabled = ssl.any? { |x| x['Value'] == 'DISABLED' }
139+
if ssl_uncompiled
140+
skip("DON'T WORRY, THIS TEST PASSES - but SSL is not compiled into your MySQL daemon.")
141+
elsif ssl_disabled
142+
skip("DON'T WORRY, THIS TEST PASSES - but SSL is not enabled in your MySQL daemon.")
143+
else
144+
%i[sslkey sslcert sslca].each do |item|
145+
unless File.exist?(option_overrides[item])
146+
skip("DON'T WORRY, THIS TEST PASSES - but #{option_overrides[item]} does not exist.")
147+
break
148+
end
149+
end
155150
end
156151
end
157-
expect do
158-
ssl_client = new_client(option_overrides)
159-
end.not_to raise_error
160152

161-
results = Hash[ssl_client.query('SHOW STATUS WHERE Variable_name LIKE "Ssl_%"').map { |x| x.values_at('Variable_name', 'Value') }]
162-
expect(results['Ssl_cipher']).not_to be_empty
163-
expect(results['Ssl_version']).not_to be_empty
153+
let(:option_overrides) do
154+
{
155+
'host' => 'mysql2gem.example.com', # must match the certificates
156+
:sslkey => '/etc/mysql/client-key.pem',
157+
:sslcert => '/etc/mysql/client-cert.pem',
158+
:sslca => '/etc/mysql/ca-cert.pem',
159+
:sslcipher => 'DHE-RSA-AES256-SHA',
160+
:sslverify => true,
161+
}
162+
end
163+
164+
let(:ssl_client) do
165+
new_client(option_overrides)
166+
end
167+
168+
%i[disabled preferred required verify_ca verify_identity].each do |ssl_mode|
169+
it "should set ssl_mode option #{ssl_mode}" do
170+
options = {
171+
ssl_mode: ssl_mode,
172+
}
173+
options.merge!(option_overrides)
174+
# Relax the matching condition by checking if an error is not raised.
175+
# TODO: Verify warnings by checking stderr.
176+
expect do
177+
new_client(options)
178+
end.not_to raise_error
179+
end
180+
end
164181

165-
expect(ssl_client.ssl_cipher).not_to be_empty
166-
expect(results['Ssl_cipher']).to eql(ssl_client.ssl_cipher)
182+
it "should be able to connect via SSL options" do
183+
# You may need to adjust the lines below to match your SSL certificate paths
184+
results = Hash[ssl_client.query('SHOW STATUS WHERE Variable_name LIKE "Ssl_%"').map { |x| x.values_at('Variable_name', 'Value') }]
185+
expect(results['Ssl_cipher']).not_to be_empty
186+
expect(results['Ssl_version']).not_to be_empty
187+
188+
expect(ssl_client.ssl_cipher).not_to be_empty
189+
expect(results['Ssl_cipher']).to eql(ssl_client.ssl_cipher)
190+
end
167191
end
168192

169193
def run_gc

0 commit comments

Comments
 (0)