@@ -115,6 +115,28 @@ def connect *args
115115 expect ( Mysql2 ::Client ) . to respond_to ( :default_query_options )
116116 end
117117
118+ it "should be able to connect via SSL defaults" do
119+ ssl = @client . query "SHOW VARIABLES LIKE 'have_ssl'"
120+ ssl_uncompiled = ssl . any? { |x | x [ 'Value' ] == 'OFF' }
121+ pending ( "DON'T WORRY, THIS TEST PASSES - but SSL is not compiled into your MySQL daemon." ) if ssl_uncompiled
122+ ssl_disabled = ssl . any? { |x | x [ 'Value' ] == 'DISABLED' }
123+ pending ( "DON'T WORRY, THIS TEST PASSES - but SSL is not enabled in your MySQL daemon." ) if ssl_disabled
124+
125+ ssl_client = nil
126+ expect {
127+ ssl_client = Mysql2 ::Client . new (
128+ DatabaseCredentials [ 'root' ] . merge (
129+ :ssl => true
130+ )
131+ )
132+ } . not_to raise_error
133+
134+ results = Hash [ ssl_client . query ( 'SHOW STATUS WHERE Variable_name LIKE "Ssl_%"' ) . map { |x | x . values_at ( 'Variable_name' , 'Value' ) } ]
135+ expect ( results [ 'Ssl_cipher' ] ) . not_to be_empty
136+ expect ( results [ 'Ssl_version' ] ) . not_to be_empty
137+ ssl_client . close
138+ end
139+
118140 it "should be able to connect via SSL options" do
119141 ssl = @client . query "SHOW VARIABLES LIKE 'have_ssl'"
120142 ssl_uncompiled = ssl . any? { |x | x [ 'Value' ] == 'OFF' }
@@ -137,17 +159,9 @@ def connect *args
137159 )
138160 } . not_to raise_error
139161
140- results = ssl_client . query ( "SHOW STATUS WHERE Variable_name = \" Ssl_version\" OR Variable_name = \" Ssl_cipher\" " ) . to_a
141- expect ( results [ 0 ] [ 'Variable_name' ] ) . to eql ( 'Ssl_cipher' )
142- expect ( results [ 0 ] [ 'Value' ] ) . not_to be_nil
143- expect ( results [ 0 ] [ 'Value' ] ) . to be_kind_of ( String )
144- expect ( results [ 0 ] [ 'Value' ] ) . not_to be_empty
145-
146- expect ( results [ 1 ] [ 'Variable_name' ] ) . to eql ( 'Ssl_version' )
147- expect ( results [ 1 ] [ 'Value' ] ) . not_to be_nil
148- expect ( results [ 1 ] [ 'Value' ] ) . to be_kind_of ( String )
149- expect ( results [ 1 ] [ 'Value' ] ) . not_to be_empty
150-
162+ results = Hash [ ssl_client . query ( 'SHOW STATUS WHERE Variable_name LIKE "Ssl_%"' ) . map { |x | x . values_at ( 'Variable_name' , 'Value' ) } ]
163+ expect ( results [ 'Ssl_cipher' ] ) . not_to be_empty
164+ expect ( results [ 'Ssl_version' ] ) . not_to be_empty
151165 ssl_client . close
152166 end
153167
0 commit comments