diff --git a/.fixtures.yml b/.fixtures.yml index f9191787c..7a27d173f 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -2,5 +2,6 @@ fixtures: repositories: "stdlib": "https://github.com/puppetlabs/puppetlabs-stdlib" "staging": "https://github.com/voxpupuli/puppet-staging" + "translate": "https://github.com/puppetlabs/puppetlabs-translate" symlinks: "mysql": "#{source_dir}" diff --git a/.rubocop.yml b/.rubocop.yml index 2b51cf922..b28fcc8ff 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -14,6 +14,7 @@ AllCops: - pkg/**/* - spec/fixtures/**/* - vendor/**/* +inherit_from: .rubocop_todo.yml Metrics/LineLength: Description: People have wide screens, use them. Max: 200 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 000000000..0e36ae041 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,123 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2017-09-04 11:31:12 +0100 using RuboCop version 0.49.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent +Layout/IndentHeredoc: + Exclude: + - 'spec/unit/puppet/provider/mysql_database/mysql_spec.rb' + - 'spec/unit/puppet/provider/mysql_user/mysql_spec.rb' + +# Offense count: 1 +Lint/AmbiguousRegexpLiteral: + Exclude: + - 'spec/unit/puppet/type/mysql_grant_spec.rb' + +# Offense count: 1 +Lint/DuplicatedKey: + Exclude: + - 'spec/classes/mysql_server_backup_spec.rb' + +# Offense count: 1 +Lint/HandleExceptions: + Exclude: + - 'spec/spec_helper.rb' + +# Offense count: 1 +Lint/ScriptPermission: + Exclude: + - 'spec/unit/puppet/functions/mysql_deepmerge_spec.rb' + +# Offense count: 1 +Lint/UselessAssignment: + Exclude: + - 'spec/unit/puppet/functions/mysql_deepmerge_spec.rb' + +# Offense count: 11 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 351 + +# Offense count: 1 +RSpec/BeforeAfterAll: + Exclude: + - 'spec/acceptance/**/*.rb' + - 'spec/unit/puppet/functions/mysql_password_spec.rb' + +# Offense count: 56 +# Configuration parameters: Max. +RSpec/ExampleLength: + Exclude: + - 'spec/acceptance/mysql_backup_spec.rb' + - 'spec/acceptance/types/mysql_database_spec.rb' + - 'spec/acceptance/types/mysql_grant_spec.rb' + - 'spec/acceptance/types/mysql_plugin_spec.rb' + - 'spec/acceptance/types/mysql_user_spec.rb' + - 'spec/classes/mysql_server_backup_spec.rb' + - 'spec/classes/mysql_server_monitor_spec.rb' + - 'spec/classes/mysql_server_spec.rb' + - 'spec/unit/puppet/provider/mysql_database/mysql_spec.rb' + - 'spec/unit/puppet/provider/mysql_user/mysql_spec.rb' + - 'spec/unit/puppet/type/mysql_grant_spec.rb' + +# Offense count: 3 +# Configuration parameters: CustomTransform, IgnoreMethods. +RSpec/FilePath: + Exclude: + - 'spec/unit/facter/mysql_server_id_spec.rb' + - 'spec/unit/facter/mysql_version_spec.rb' + - 'spec/unit/facter/mysqld_version_spec.rb' + +# Offense count: 41 +# Configuration parameters: AssignmentOnly. +RSpec/InstanceVariable: + Exclude: + - 'spec/acceptance/mysql_server_spec.rb' + - 'spec/unit/puppet/type/mysql_database_spec.rb' + - 'spec/unit/puppet/type/mysql_grant_spec.rb' + - 'spec/unit/puppet/type/mysql_plugin_spec.rb' + - 'spec/unit/puppet/type/mysql_user_spec.rb' + +# Offense count: 38 +RSpec/MultipleExpectations: + Max: 4 + +# Offense count: 42 +# Configuration parameters: Max. +RSpec/NestedGroups: + Exclude: + - 'spec/acceptance/mysql_backup_spec.rb' + - 'spec/classes/mycnf_template_spec.rb' + - 'spec/classes/mysql_server_backup_spec.rb' + - 'spec/classes/mysql_server_spec.rb' + +# Offense count: 2 +RSpec/RepeatedExample: + Exclude: + - 'spec/classes/mysql_server_account_security_spec.rb' + +# Offense count: 3 +RSpec/ScatteredLet: + Exclude: + - 'spec/unit/puppet/provider/mysql_database/mysql_spec.rb' + - 'spec/unit/puppet/provider/mysql_plugin/mysql_spec.rb' + - 'spec/unit/puppet/provider/mysql_user/mysql_spec.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. +# SupportedStyles: slashes, percent_r, mixed +Style/RegexpLiteral: + Exclude: + - 'spec/acceptance/types/mysql_grant_spec.rb' + - 'spec/classes/mycnf_template_spec.rb' + - 'spec/classes/mysql_server_backup_spec.rb' + - 'spec/unit/puppet/type/mysql_grant_spec.rb' diff --git a/.sync.yml b/.sync.yml index e31be44e9..d50a282cd 100644 --- a/.sync.yml +++ b/.sync.yml @@ -7,4 +7,4 @@ spec/spec_helper.rb: extras: - rvm: 2.1.9 bundler_args: --without system_tests - script: bundle exec rubocop lib + script: bundle exec rake rubocop diff --git a/.travis.yml b/.travis.yml index 67294f4de..a38caa335 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,6 @@ matrix: env: PUPPET_GEM_VERSION="~> 4.0" - rvm: 2.1.9 bundler_args: --without system_tests - script: bundle exec rubocop lib + script: bundle exec rake rubocop notifications: email: false diff --git a/lib/puppet/parser/functions/mysql_deepmerge.rb b/lib/puppet/parser/functions/mysql_deepmerge.rb index 68aae8f3a..5959a0fde 100644 --- a/lib/puppet/parser/functions/mysql_deepmerge.rb +++ b/lib/puppet/parser/functions/mysql_deepmerge.rb @@ -19,7 +19,7 @@ module Puppet::Parser::Functions ENDHEREDOC if args.length < 2 - raise Puppet::ParseError, "mysql_deepmerge(): wrong number of arguments (#{args.length}; must be at least 2)" + raise Puppet::ParseError, _('mysql_deepmerge(): wrong number of arguments (%{args_length}; must be at least 2)') % { args_length: args.length } end result = {} @@ -27,7 +27,7 @@ module Puppet::Parser::Functions next if arg.is_a?(String) && arg.empty? # empty string is synonym for puppet's undef # If the argument was not a hash, skip it. unless arg.is_a?(Hash) - raise Puppet::ParseError, "mysql_deepmerge: unexpected argument type #{arg.class}, only expects hash arguments" + raise Puppet::ParseError, _('mysql_deepmerge: unexpected argument type %{arg_class}, only expects hash arguments') % { args_class: args.class } end # Now we have to traverse our hash assigning our non-hash values diff --git a/lib/puppet/parser/functions/mysql_dirname.rb b/lib/puppet/parser/functions/mysql_dirname.rb index 33680a7dd..e1a21202d 100644 --- a/lib/puppet/parser/functions/mysql_dirname.rb +++ b/lib/puppet/parser/functions/mysql_dirname.rb @@ -6,13 +6,10 @@ module Puppet::Parser::Functions ) do |arguments| if arguments.empty? - raise(Puppet::ParseError, 'mysql_dirname(): Wrong number of arguments ' \ - "given (#{arguments.size} for 1)") + raise Puppet::ParseError, _('mysql_dirname(): Wrong number of arguments given (%{args_length} for 1)') % { args_length: args.length } end path = arguments[0] return File.dirname(path) end end - -# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/mysql_password.rb b/lib/puppet/parser/functions/mysql_password.rb index 3d3f4f841..4169bf433 100644 --- a/lib/puppet/parser/functions/mysql_password.rb +++ b/lib/puppet/parser/functions/mysql_password.rb @@ -8,8 +8,7 @@ module Puppet::Parser::Functions ) do |args| if args.size != 1 - raise(Puppet::ParseError, 'mysql_password(): Wrong number of arguments ' \ - "given (#{args.size} for 1)") + raise Puppet::ParseError, _('mysql_password(): Wrong number of arguments given (%{args_length} for 1)') % { args_length: args.length } end return '' if args[0].empty? diff --git a/lib/puppet/provider/mysql_datadir/mysql.rb b/lib/puppet/provider/mysql_datadir/mysql.rb index 64ac460ae..55740c30f 100644 --- a/lib/puppet/provider/mysql_datadir/mysql.rb +++ b/lib/puppet/provider/mysql_datadir/mysql.rb @@ -21,7 +21,7 @@ def create # rubocop:enable Lint/UselessAssignment unless defaults_extra_file.nil? unless File.exist?(defaults_extra_file) - raise ArgumentError, "Defaults-extra-file #{defaults_extra_file} is missing" + raise ArgumentError, _('Defaults-extra-file %{file} is missing') % { file: defaults_extra_file } end defaults_extra_file = "--defaults-extra-file=#{defaults_extra_file}" end diff --git a/lib/puppet/provider/mysql_grant/mysql.rb b/lib/puppet/provider/mysql_grant/mysql.rb index c54d2b6f5..b32404fca 100644 --- a/lib/puppet/provider/mysql_grant/mysql.rb +++ b/lib/puppet/provider/mysql_grant/mysql.rb @@ -16,16 +16,14 @@ def self.instances # of myhost.mydomain.my: root@myhost.mydomain.my, when MySQL is started # with --skip-name-resolve. next if e.inspect =~ %r{There is no such grant defined for user} - raise Puppet::Error, "#mysql had an error -> #{e.inspect}" + raise Puppet::Error, _('#mysql had an error -> %{inspect}') % { inspect: e.inspect } end # Once we have the list of grants generate entries for each. grants.each_line do |grant| # Match the munges we do in the type. munged_grant = grant.delete("'").delete('`').delete('"') # Matching: GRANT (SELECT, UPDATE) PRIVILEGES ON (*.*) TO ('root')@('127.0.0.1') (WITH GRANT OPTION) - # rubocop:disable Lint/AssignmentInCondition - next unless match = munged_grant.match(%r{^GRANT\s(.+)\sON\s(.+)\sTO\s(.*)@(.*?)(\s.*)?$}) - # rubocop:enable Lint/AssignmentInCondition + next unless match = munged_grant.match(%r{^GRANT\s(.+)\sON\s(.+)\sTO\s(.*)@(.*?)(\s.*)?$}) # rubocop:disable Lint/AssignmentInCondition privileges, table, user, host, rest = match.captures table.gsub!('\\\\', '\\') diff --git a/lib/puppet/type/mysql_grant.rb b/lib/puppet/type/mysql_grant.rb index b544b24d9..587db5ac1 100644 --- a/lib/puppet/type/mysql_grant.rb +++ b/lib/puppet/type/mysql_grant.rb @@ -54,7 +54,7 @@ def initialize(*args) validate do |value| mysql_version = Facter.value(:mysql_version) if value =~ %r{proxy}i && Puppet::Util::Package.versioncmp(mysql_version, '5.5.0') < 0 - raise(ArgumentError, "PROXY user not supported on mysql versions < 5.5.0. Current version #{mysql_version}") + raise(ArgumentError, _('PROXY user not supported on mysql versions < 5.5.0. Current version %{version}') % { version: mysql_version }) end end end @@ -93,7 +93,7 @@ def initialize(*args) user_part = matches[1] host_part = matches[2] else - raise(ArgumentError, "Invalid database user #{value}") + raise(ArgumentError, _('Invalid database user %{user}') % { user: value }) end # rubocop:enable Lint/AssignmentInCondition # rubocop:enable Lint/UselessAssignment diff --git a/lib/puppet/type/mysql_user.rb b/lib/puppet/type/mysql_user.rb index 075a144e2..ae38c383f 100644 --- a/lib/puppet/type/mysql_user.rb +++ b/lib/puppet/type/mysql_user.rb @@ -26,7 +26,7 @@ user_part = matches[1] host_part = matches[2] else - raise(ArgumentError, "Invalid database user #{value}") + raise ArgumentError, _('Invalid database user %{user}') % { user: value } end # rubocop:enable Lint/AssignmentInCondition # rubocop:enable Lint/UselessAssignment @@ -84,7 +84,7 @@ else value.each do |opt| o = opt.match(%r{^(CIPHER|ISSUER|SUBJECT)}i) - raise(ArgumentError, "Invalid tls option #{o}") unless o + raise(ArgumentError, _('Invalid tls option %{option}') % { option: o }) unless o end end end diff --git a/manifests/bindings.pp b/manifests/bindings.pp index fa7b870ff..755a1a246 100644 --- a/manifests/bindings.pp +++ b/manifests/bindings.pp @@ -35,11 +35,11 @@ case $::osfamily { 'Archlinux': { - if $java_enable { fail("::mysql::bindings::java cannot be managed by puppet on ${::osfamily} as it is not in official repositories. Please disable java mysql binding.") } + if $java_enable { fail(translate("::mysql::bindings::java cannot be managed by puppet on ${::osfamily} as it is not in official repositories. Please disable java mysql binding.")) } if $perl_enable { include '::mysql::bindings::perl' } - if $php_enable { warning("::mysql::bindings::php does not need to be managed by puppet on ${::osfamily} as it is included in mysql package by default.") } + if $php_enable { warning(translate("::mysql::bindings::php does not need to be managed by puppet on ${::osfamily} as it is included in mysql package by default.")) } if $python_enable { include '::mysql::bindings::python' } - if $ruby_enable { fail("::mysql::bindings::ruby cannot be managed by puppet on ${::osfamily} as it is not in official repositories. Please disable ruby mysql binding.") } + if $ruby_enable { fail(translate("::mysql::bindings::ruby cannot be managed by puppet on ${::osfamily} as it is not in official repositories. Please disable ruby mysql binding.")) } } default: { diff --git a/manifests/bindings/client_dev.pp b/manifests/bindings/client_dev.pp index ee3c2fedd..ac5bb5eff 100644 --- a/manifests/bindings/client_dev.pp +++ b/manifests/bindings/client_dev.pp @@ -9,7 +9,7 @@ provider => $mysql::bindings::client_dev_package_provider, } } else { - warning("No MySQL client development package configured for ${::operatingsystem}.") + warning(translate("No MySQL client development package configured for ${::operatingsystem}.")) } } diff --git a/manifests/bindings/daemon_dev.pp b/manifests/bindings/daemon_dev.pp index 051535893..85766c037 100644 --- a/manifests/bindings/daemon_dev.pp +++ b/manifests/bindings/daemon_dev.pp @@ -9,7 +9,7 @@ provider => $mysql::bindings::daemon_dev_package_provider, } } else { - warning("No MySQL daemon development package configured for ${::operatingsystem}.") + warning(translate("No MySQL daemon development package configured for ${::operatingsystem}.")) } } diff --git a/manifests/params.pp b/manifests/params.pp index bcd923ec4..ce8f4e36b 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -121,7 +121,7 @@ } } default: { - fail("Unsupported platform: puppetlabs-${module_name} currently doesn't support ${::operatingsystem}") + fail(translate("Unsupported platform: puppetlabs-${module_name} currently doesn't support ${::operatingsystem}")) } } $config_file = '/etc/my.cnf' @@ -378,7 +378,7 @@ } default: { - fail("Unsupported platform: puppetlabs-${module_name} currently doesn't support ${::osfamily} or ${::operatingsystem}") + fail(translate("Unsupported platform: puppetlabs-${module_name} currently doesn't support ${::osfamily} or ${::operatingsystem}")) } } } @@ -462,6 +462,6 @@ ## Additional graceful failures if $::osfamily == 'RedHat' and $::operatingsystemmajrelease == '4' and $::operatingsystem != 'Amazon' { - fail("Unsupported platform: puppetlabs-${module_name} only supports RedHat 5.0 and beyond") + fail(translate("Unsupported platform: puppetlabs-${module_name} only supports RedHat 5.0 and beyond")) } } diff --git a/manifests/server/backup.pp b/manifests/server/backup.pp index 092360383..d2c8f3efa 100644 --- a/manifests/server/backup.pp +++ b/manifests/server/backup.pp @@ -25,7 +25,7 @@ ) { if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ { - warning("The \$prescript option is not currently implemented for the ${provider} backup provider.") + warning(translate("The \$prescript option is not currently implemented for the ${provider} backup provider.")) } create_resources('class', { diff --git a/spec/acceptance/locales_spec.rb b/spec/acceptance/locales_spec.rb index 50db50865..ef6f97ce9 100644 --- a/spec/acceptance/locales_spec.rb +++ b/spec/acceptance/locales_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper_acceptance' require 'beaker/i18n_helper' -describe 'mysql localization', unless: fact('operatingsystem') == 'Debian' do +describe 'mysql localization', if: fact('osfamily') == 'Debian' do before :all do hosts.each do |host| on(host, "sed -i \"96i FastGettext.locale='ja'\" /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet.rb") @@ -30,14 +30,13 @@ class { 'mysql::server': end it 'displays Japanese error' do - pending('waiting on japanese translation in the po file') apply_manifest(pp, catch_error: true) do |r| - expect(r.stderr).not_to match(%r{The `old_root_password` attribute is no longer used and will be removed}i) + expect(r.stderr).to match(%r{`old_root_password`属性は廃止予定であり、今後のリリースで廃止されます。}i) end end end - context 'when triggering ruby string warning' do + context 'when triggering ruby simple string warning' do let(:pp) do <<-EOS mysql::db { 'mydb': @@ -50,9 +49,23 @@ class { 'mysql::server': end it 'displays Japanese error' do - pending('waiting on japanese translation in the po file') apply_manifest(pp, expect_failures: true) do |r| - expect(r.stderr).not_to match(%r{MySQL usernames are limited to a maximum of 16 characters.}i) + expect(r.stderr).to match(%r{MySQLユーザ名は最大16文字に制限されています。}i) + end + end + end + + context 'when triggering ruby interpolated string warning' do + let(:pp) do + <<-EOS + $password_hash = mysql_password('new_password', 'should not have second parameter') + EOS + end + + it 'displays Japanese error' do + pending 'waiting on japanese translation in the po file' + apply_manifest(pp, catch_error: true) do |r| + expect(r.stderr).not_to match(%r{mysql_password(): Wrong number of arguments given (2 for 1)}i) end end end diff --git a/spec/classes/graceful_failures_spec.rb b/spec/classes/graceful_failures_spec.rb index 04ab6e1c6..22a677b2f 100644 --- a/spec/classes/graceful_failures_spec.rb +++ b/spec/classes/graceful_failures_spec.rb @@ -9,7 +9,7 @@ } end - it 'gracefullies fail' do + it 'gracefully fails' do is_expected.to compile.and_raise_error(%r{Unsupported platform:}) end end diff --git a/spec/unit/puppet/functions/mysql_password_spec.rb b/spec/unit/puppet/functions/mysql_password_spec.rb index 566e0760b..b1794f8b1 100644 --- a/spec/unit/puppet/functions/mysql_password_spec.rb +++ b/spec/unit/puppet/functions/mysql_password_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'the mysql_password function' do - before :all do + before :all do # rubocop:disable RSpec/BeforeAfterAll Puppet::Parser::Functions.autoloader.loadall end diff --git a/spec/unit/puppet/provider/mysql_database/mysql_spec.rb b/spec/unit/puppet/provider/mysql_database/mysql_spec.rb index 77cb245fa..56213a7ba 100644 --- a/spec/unit/puppet/provider/mysql_database/mysql_spec.rb +++ b/spec/unit/puppet/provider/mysql_database/mysql_spec.rb @@ -31,7 +31,7 @@ Puppet::Util.stubs(:which).with('mysql').returns('/usr/bin/mysql') File.stubs(:file?).with('/root/.my.cnf').returns(true) provider.class.stubs(:mysql).with([defaults_file, '-NBe', 'show databases']).returns('new_database') - provider.class.stubs(:mysql).with([defaults_file, '-NBe', "show variables like '%_database'", 'new_database']).returns("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF") + provider.class.stubs(:mysql).with([defaults_file, '-NBe', "show variables like '%_database'", 'new_database']).returns("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF") # rubocop:disable Metrics/LineLength end let(:instance) { provider.class.instances.first } @@ -40,7 +40,7 @@ it 'returns an array of databases' do provider.class.stubs(:mysql).with([defaults_file, '-NBe', 'show databases']).returns(raw_databases) raw_databases.each_line do |db| - provider.class.stubs(:mysql).with([defaults_file, '-NBe', "show variables like '%_database'", db.chomp]).returns("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF") + provider.class.stubs(:mysql).with([defaults_file, '-NBe', "show variables like '%_database'", db.chomp]).returns("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF") # rubocop:disable Metrics/LineLength end databases = provider.class.instances.map { |x| x.name } expect(parsed_databases).to match_array(databases) diff --git a/spec/unit/puppet/provider/mysql_user/mysql_spec.rb b/spec/unit/puppet/provider/mysql_user/mysql_spec.rb index 2a2bec876..080381366 100644 --- a/spec/unit/puppet/provider/mysql_user/mysql_spec.rb +++ b/spec/unit/puppet/provider/mysql_user/mysql_spec.rb @@ -88,7 +88,7 @@ Puppet::Util.stubs(:which).with('mysqld').returns('/usr/sbin/mysqld') File.stubs(:file?).with('/root/.my.cnf').returns(true) provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns('joe@localhost') - provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = 'joe@localhost'"]).returns('10 10 10 10 *6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4') + provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = 'joe@localhost'"]).returns('10 10 10 10 *6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4') # rubocop:disable Metrics/LineLength end let(:instance) { provider.class.instances.first } @@ -98,7 +98,7 @@ provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.5'][:string]) provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users) parsed_users.each do |user| - provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') + provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') # rubocop:disable Metrics/LineLength end usernames = provider.class.instances.map { |x| x.name } @@ -108,7 +108,7 @@ provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.6'][:string]) provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users) parsed_users.each do |user| - provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') + provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') # rubocop:disable Metrics/LineLength end usernames = provider.class.instances.map { |x| x.name } @@ -118,7 +118,7 @@ provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.1'][:string]) provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users) parsed_users.each do |user| - provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') + provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') # rubocop:disable Metrics/LineLength end usernames = provider.class.instances.map { |x| x.name } @@ -128,7 +128,7 @@ provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.6'][:string]) provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users) parsed_users.each do |user| - provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, AUTHENTICATION_STRING, PLUGIN FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') + provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, AUTHENTICATION_STRING, PLUGIN FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') # rubocop:disable Metrics/LineLength end usernames = provider.class.instances.map { |x| x.name } @@ -138,7 +138,7 @@ provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mariadb-10.0'][:string]) provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users) parsed_users.each do |user| - provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') + provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') # rubocop:disable Metrics/LineLength end usernames = provider.class.instances.map { |x| x.name } @@ -148,7 +148,7 @@ provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['percona-5.5'][:string]) provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users) parsed_users.each do |user| - provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') + provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') # rubocop:disable Metrics/LineLength end usernames = provider.class.instances.map { |x| x.name } @@ -179,7 +179,7 @@ describe 'create' do it 'makes a user' do provider.expects(:mysql).with([defaults_file, system_database, '-e', "CREATE USER 'joe'@'localhost' IDENTIFIED BY PASSWORD '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'"]) - provider.expects(:mysql).with([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' WITH MAX_USER_CONNECTIONS 10 MAX_CONNECTIONS_PER_HOUR 10 MAX_QUERIES_PER_HOUR 10 MAX_UPDATES_PER_HOUR 10"]) + provider.expects(:mysql).with([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' WITH MAX_USER_CONNECTIONS 10 MAX_CONNECTIONS_PER_HOUR 10 MAX_QUERIES_PER_HOUR 10 MAX_UPDATES_PER_HOUR 10"]) # rubocop:disable Metrics/LineLength provider.expects(:mysql).with([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' REQUIRE NONE"]) provider.expects(:exists?).returns(true) expect(provider.create).to be_truthy @@ -265,7 +265,7 @@ end it 'changes the hash MySQL >= 5.7.6' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.6'][:string]) - provider.expects(:mysql).with([defaults_file, system_database, '-e', "ALTER USER 'joe'@'localhost' IDENTIFIED WITH mysql_native_password AS '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5'"]).returns('0') + provider.expects(:mysql).with([defaults_file, system_database, '-e', "ALTER USER 'joe'@'localhost' IDENTIFIED WITH mysql_native_password AS '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5'"]).returns('0') # rubocop:disable Metrics/LineLength provider.expects(:password_hash).returns('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5') provider.password_hash = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5'