flydata 0.3.14 → 0.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/flydata.gemspec +2 -2
- data/lib/flydata/compatibility_check.rb +5 -5
- data/spec/flydata/compatibility_check_spec.rb +60 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2092338e5191e9b77804e78ba3aef0a667d2fba2
|
4
|
+
data.tar.gz: f2f65e5850da6e1e77be386d8b1fdcf4ab3a6a00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 693815184571882684724fdf9e0eab6f9f16142c335ddc0e47c2cdcd59adf0d8789ac7113f0796f64cbbd7aad3d2939ac325d13ba1a3bdb565f0b5d82b597df0
|
7
|
+
data.tar.gz: a2b9def6f55162b7098d34daa2b881b2919594ab642d772797caa6229d482a2b416fc976ec504010d0f59bd473ed5c2596eecff14112d9f9b072ffe1c0d2b1dc
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.15
|
data/flydata.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: flydata 0.3.
|
5
|
+
# stub: flydata 0.3.15 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "flydata"
|
9
|
-
s.version = "0.3.
|
9
|
+
s.version = "0.3.15"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
@@ -102,24 +102,24 @@ module Flydata
|
|
102
102
|
def check_mysql_user_compat
|
103
103
|
client = Mysql2::Client.new(@db_opts)
|
104
104
|
grants_sql = "SHOW GRANTS"
|
105
|
-
correct_db = ["ON (
|
105
|
+
correct_db = ["ON (\\*|(`)?#{@db_opts[:database]}(`)?).","TO '#{@db_opts[:username]}"]
|
106
106
|
necessary_permission_fields= ["SELECT","RELOAD","LOCK TABLES","REPLICATION SLAVE","REPLICATION CLIENT"]
|
107
107
|
all_privileges_field= ["ALL PRIVILEGES"]
|
108
108
|
result = client.query(grants_sql)
|
109
109
|
# Do not catch MySQL connection problem because check should stop if no MySQL connection can be made.
|
110
110
|
client.close
|
111
|
-
|
111
|
+
found_priv = []
|
112
112
|
result.each do |res|
|
113
113
|
# SHOW GRANTS should only return one column
|
114
114
|
res_value = res.values.first
|
115
115
|
if correct_db.all? {|perm| res_value.match(perm)}
|
116
116
|
necessary_permission_fields.each do |priv|
|
117
|
-
|
117
|
+
found_priv << priv if res_value.match(priv)
|
118
118
|
end
|
119
|
-
return true if
|
119
|
+
return true if (necessary_permission_fields-found_priv).empty? or all_privileges_field.all? {|d| res_value.match(d)}
|
120
120
|
end
|
121
121
|
end
|
122
|
-
raise MysqlCompatibilityError, "The user '#{@db_opts[:username]}' does not have the correct permissions to run FlyData Sync\n * These privileges are missing: #{
|
122
|
+
raise MysqlCompatibilityError, "The user '#{@db_opts[:username]}' does not have the correct permissions to run FlyData Sync\n * These privileges are missing: #{(necessary_permission_fields-found_priv).join(", ")}"
|
123
123
|
end
|
124
124
|
|
125
125
|
def check_mysql_protocol_tcp_compat
|
@@ -44,6 +44,66 @@ module Flydata
|
|
44
44
|
"database" => "test_db"
|
45
45
|
}
|
46
46
|
end
|
47
|
+
describe "#check_mysql_user_compat" do
|
48
|
+
let(:client) { double('client') }
|
49
|
+
subject { MysqlCompatibilityCheck.new({},:default_mysql_cred) }
|
50
|
+
before do
|
51
|
+
allow(Mysql2::Client).to receive(:new).and_return(client)
|
52
|
+
allow(client).to receive(:close)
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with all privileges for privileges all in one database" do
|
56
|
+
before do
|
57
|
+
allow(client).to receive(:query).and_return([{"Grants for test"=>"GRANT SELECT, LOCK TABLES, RELOAD, REPLICATION SLAVE, REPLICATION CLIENT ON `test_db`.* TO 'test'@'host"}])
|
58
|
+
end
|
59
|
+
it do
|
60
|
+
expect{subject.check_mysql_user_compat}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
context "with missing privileges for privileges all in one database" do
|
64
|
+
before do
|
65
|
+
allow(client).to receive(:query).and_return([{"Grants for test"=>"GRANT SELECT, RELOAD, REPLICATION CLIENT ON `test_db`.* TO 'test'@'host"}])
|
66
|
+
end
|
67
|
+
it do
|
68
|
+
expect{subject.check_mysql_user_compat}.to raise_error(Flydata::MysqlCompatibilityCheck::MysqlCompatibilityError, /LOCK TABLES, REPLICATION SLAVE/)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
context "with all privileges for privileges in between all and specific databases" do
|
72
|
+
before do
|
73
|
+
allow(client).to receive(:query).and_return([{"Grants for test"=>"GRANT RELOAD, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'test'@'host"},
|
74
|
+
{"Grants for test"=>"GRANT SELECT, LOCK TABLES ON `test_db`.* TO 'test'@'host"}])
|
75
|
+
end
|
76
|
+
it do
|
77
|
+
expect{subject.check_mysql_user_compat}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
context "with missing privileges for privileges in between all and specific databases" do
|
81
|
+
before do
|
82
|
+
allow(client).to receive(:query).and_return([{"Grants for test"=>"GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'test'@'host"},
|
83
|
+
{"Grants for test"=>"GRANT SELECT, LOCK TABLES ON `test_db`.* TO 'test'@'host"}])
|
84
|
+
end
|
85
|
+
it do
|
86
|
+
expect{subject.check_mysql_user_compat}.to raise_error(Flydata::MysqlCompatibilityCheck::MysqlCompatibilityError, /RELOAD/)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
context "with all privileges for privileges in all databases" do
|
90
|
+
before do
|
91
|
+
allow(client).to receive(:query).and_return([{"Grants for test"=>"GRANT SELECT, LOCK TABLES, RELOAD, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'test'@'host"}])
|
92
|
+
end
|
93
|
+
it do
|
94
|
+
expect{subject.check_mysql_user_compat}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
context "with missing privileges for privileges in all databases" do
|
98
|
+
before do
|
99
|
+
allow(client).to receive(:query).and_return([{"Grants for test"=>"GRANT RELOAD, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'test'@'host"}])
|
100
|
+
end
|
101
|
+
it do
|
102
|
+
expect{subject.check_mysql_user_compat}.to raise_error(Flydata::MysqlCompatibilityCheck::MysqlCompatibilityError, /SELECT, LOCK TABLES/)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
47
107
|
describe "#check_mysql_binlog_retention" do
|
48
108
|
context "on on-premise mysql server" do
|
49
109
|
subject { MysqlCompatibilityCheck.new({},:default_mysql_cred) }
|