Navigation Menu

Skip to content

Commit

Permalink
Add full set of MySQL CLI options to support SSL authentication when …
Browse files Browse the repository at this point in the history
…using db:structure dump and load
  • Loading branch information
drcapulet committed Jan 27, 2016
1 parent 878e429 commit 7f5be7e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
6 changes: 6 additions & 0 deletions activerecord/CHANGELOG.md
@@ -1,3 +1,9 @@
* Correctly pass MySQL options when using structure_dump or structure_load

Specifically, it fixes an issue when using SSL authentication.

*Alex Coomans*

* Fix regression when loading fixture files with symbol keys.

Closes #22584.
Expand Down
22 changes: 13 additions & 9 deletions activerecord/lib/active_record/tasks/mysql_database_tasks.rb
Expand Up @@ -129,15 +129,19 @@ def root_password
end

def prepare_command_options
args = []
args.concat(['--user', configuration['username']]) if configuration['username']
args << "--password=#{configuration['password']}" if configuration['password']
args.concat(['--default-character-set', configuration['encoding']]) if configuration['encoding']
configuration.slice('host', 'port', 'socket').each do |k, v|
args.concat([ "--#{k}", v.to_s ]) if v
end

args
{
'host' => '--host',
'port' => '--port',
'socket' => '--socket',
'username' => '--user',
'password' => '--password',
'encoding' => '--default-character-set',
'sslca' => '--ssl-ca',
'sslcert' => '--ssl-cert',
'sslcapath' => '--ssl-capath',
'sslcipher' => '--ssh-cipher',
'sslkey' => '--ssl-key'
}.map { |opt, arg| "#{arg}=#{configuration[opt]}" if configuration[opt] }.compact
end

def run_cmd(cmd, args, action)
Expand Down
11 changes: 10 additions & 1 deletion activerecord/test/cases/tasks/mysql_rake_test.rb
Expand Up @@ -295,12 +295,21 @@ def test_warn_when_external_structure_dump_command_execution_fails

def test_structure_dump_with_port_number
filename = "awesome-file.sql"
Kernel.expects(:system).with("mysqldump", "--port", "10000", "--result-file", filename, "--no-data", "test-db").returns(true)
Kernel.expects(:system).with("mysqldump", "--port=10000", "--result-file", filename, "--no-data", "test-db").returns(true)

ActiveRecord::Tasks::DatabaseTasks.structure_dump(
@configuration.merge('port' => 10000),
filename)
end

def test_structure_dump_with_ssl
filename = "awesome-file.sql"
Kernel.expects(:system).with("mysqldump", "--ssl-ca=ca.crt", "--result-file", filename, "--no-data", "test-db").returns(true)

ActiveRecord::Tasks::DatabaseTasks.structure_dump(
@configuration.merge("sslca" => "ca.crt"),
filename)
end
end

class MySQLStructureLoadTest < ActiveRecord::TestCase
Expand Down

0 comments on commit 7f5be7e

Please sign in to comment.