gratan 0.1.0
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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +86 -0
- data/Rakefile +5 -0
- data/bin/gratan +132 -0
- data/gratan.gemspec +28 -0
- data/lib/gratan/client.rb +211 -0
- data/lib/gratan/driver.rb +166 -0
- data/lib/gratan/dsl/context/on.rb +19 -0
- data/lib/gratan/dsl/context/user.rb +25 -0
- data/lib/gratan/dsl/context.rb +57 -0
- data/lib/gratan/dsl/converter.rb +74 -0
- data/lib/gratan/dsl/validator.rb +13 -0
- data/lib/gratan/dsl.rb +9 -0
- data/lib/gratan/exporter.rb +49 -0
- data/lib/gratan/ext/string_ext.rb +25 -0
- data/lib/gratan/grant_parser.rb +68 -0
- data/lib/gratan/identifier/auto.rb +28 -0
- data/lib/gratan/identifier/csv.rb +25 -0
- data/lib/gratan/identifier/null.rb +5 -0
- data/lib/gratan/identifier.rb +2 -0
- data/lib/gratan/logger.rb +28 -0
- data/lib/gratan/version.rb +3 -0
- data/lib/gratan.rb +24 -0
- data/spec/change/change_grants_2_spec.rb +154 -0
- data/spec/change/change_grants_3_spec.rb +164 -0
- data/spec/change/change_grants_4_spec.rb +37 -0
- data/spec/change/change_grants_spec.rb +209 -0
- data/spec/create/create_user_2_spec.rb +139 -0
- data/spec/create/create_user_3_spec.rb +115 -0
- data/spec/create/create_user_spec.rb +194 -0
- data/spec/drop/drop_user_2_spec.rb +77 -0
- data/spec/drop/drop_user_spec.rb +67 -0
- data/spec/drop/expire_user_spec.rb +179 -0
- data/spec/export/export_spec.rb +119 -0
- data/spec/misc/misc_spec.rb +74 -0
- data/spec/misc/require_spec.rb +77 -0
- data/spec/spec_helper.rb +118 -0
- metadata +198 -0
@@ -0,0 +1,194 @@
|
|
1
|
+
describe 'Gratan::Client#apply' do
|
2
|
+
context 'when user does not exist' do
|
3
|
+
subject { client }
|
4
|
+
|
5
|
+
it do
|
6
|
+
result = apply(subject) { '' }
|
7
|
+
expect(result).to be_falsey
|
8
|
+
expect(show_grants).to match_array []
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'when create user' do
|
13
|
+
subject { client }
|
14
|
+
|
15
|
+
it do
|
16
|
+
result = apply(subject) {
|
17
|
+
<<-RUBY
|
18
|
+
user 'scott', 'localhost', identified: 'tiger' do
|
19
|
+
on '*.*' do
|
20
|
+
grant 'SELECT'
|
21
|
+
grant 'INSERT'
|
22
|
+
grant 'UPDATE'
|
23
|
+
grant 'DELETE'
|
24
|
+
end
|
25
|
+
|
26
|
+
on 'test.*' do
|
27
|
+
grant 'SELECT'
|
28
|
+
grant 'INSERT'
|
29
|
+
grant 'UPDATE'
|
30
|
+
grant 'DELETE'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
RUBY
|
34
|
+
}
|
35
|
+
|
36
|
+
expect(result).to be_truthy
|
37
|
+
|
38
|
+
expect(show_grants).to match_array [
|
39
|
+
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
40
|
+
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
41
|
+
]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when add user' do
|
46
|
+
before do
|
47
|
+
apply {
|
48
|
+
<<-RUBY
|
49
|
+
user 'bob', '%', required: 'SSL' do
|
50
|
+
on '*.*' do
|
51
|
+
grant 'ALL PRIVILEGES'
|
52
|
+
end
|
53
|
+
|
54
|
+
on 'test.*' do
|
55
|
+
grant 'SELECT'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
RUBY
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
subject { client }
|
63
|
+
|
64
|
+
it do
|
65
|
+
apply(subject) {
|
66
|
+
<<-RUBY
|
67
|
+
user 'bob', '%', required: 'SSL' do
|
68
|
+
on '*.*' do
|
69
|
+
grant 'ALL PRIVILEGES'
|
70
|
+
end
|
71
|
+
|
72
|
+
on 'test.*' do
|
73
|
+
grant 'SELECT'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
user 'scott', 'localhost', identified: 'tiger' do
|
78
|
+
on '*.*' do
|
79
|
+
grant 'SELECT'
|
80
|
+
grant 'INSERT'
|
81
|
+
grant 'UPDATE'
|
82
|
+
grant 'DELETE'
|
83
|
+
end
|
84
|
+
|
85
|
+
on 'test.*' do
|
86
|
+
grant 'SELECT'
|
87
|
+
grant 'INSERT'
|
88
|
+
grant 'UPDATE'
|
89
|
+
grant 'DELETE'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
RUBY
|
93
|
+
}
|
94
|
+
|
95
|
+
expect(show_grants).to match_array [
|
96
|
+
"GRANT ALL PRIVILEGES ON *.* TO 'bob'@'%' REQUIRE SSL",
|
97
|
+
"GRANT SELECT ON `test`.* TO 'bob'@'%'",
|
98
|
+
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
99
|
+
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
100
|
+
]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when create user with grant option' do
|
105
|
+
subject { client }
|
106
|
+
|
107
|
+
it do
|
108
|
+
apply(subject) {
|
109
|
+
<<-RUBY
|
110
|
+
user 'scott', 'localhost', identified: 'tiger' do
|
111
|
+
on '*.*', with: 'grant option' do
|
112
|
+
grant 'SELECT'
|
113
|
+
grant 'INSERT'
|
114
|
+
grant 'UPDATE'
|
115
|
+
grant 'DELETE'
|
116
|
+
end
|
117
|
+
|
118
|
+
on 'test.*' do
|
119
|
+
grant 'SELECT'
|
120
|
+
grant 'INSERT'
|
121
|
+
grant 'UPDATE'
|
122
|
+
grant 'DELETE'
|
123
|
+
end
|
124
|
+
end
|
125
|
+
RUBY
|
126
|
+
}
|
127
|
+
|
128
|
+
expect(show_grants).to match_array [
|
129
|
+
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' WITH GRANT OPTION",
|
130
|
+
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
131
|
+
]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'when duplicata user' do
|
136
|
+
subject { client }
|
137
|
+
|
138
|
+
it do
|
139
|
+
dsl = <<-RUBY
|
140
|
+
user 'scott', 'localhost', required: 'SSL' do
|
141
|
+
on '*.*' do
|
142
|
+
grant 'ALL PRIVILEGES'
|
143
|
+
end
|
144
|
+
|
145
|
+
on 'test.*' do
|
146
|
+
grant 'SELECT'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
user 'scott', 'localhost', identified: 'tiger' do
|
151
|
+
on '*.*' do
|
152
|
+
grant 'SELECT'
|
153
|
+
grant 'INSERT'
|
154
|
+
grant 'UPDATE'
|
155
|
+
grant 'DELETE'
|
156
|
+
end
|
157
|
+
|
158
|
+
on 'test.*' do
|
159
|
+
grant 'SELECT'
|
160
|
+
grant 'INSERT'
|
161
|
+
grant 'UPDATE'
|
162
|
+
grant 'DELETE'
|
163
|
+
end
|
164
|
+
end
|
165
|
+
RUBY
|
166
|
+
|
167
|
+
expect {
|
168
|
+
apply(subject) { dsl }
|
169
|
+
}.to raise_error('User `scott@localhost` is already defined')
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
context 'when duplicata object' do
|
174
|
+
subject { client }
|
175
|
+
|
176
|
+
it do
|
177
|
+
dsl = <<-RUBY
|
178
|
+
user 'scott', 'localhost', required: 'SSL' do
|
179
|
+
on '*.*' do
|
180
|
+
grant 'ALL PRIVILEGES'
|
181
|
+
end
|
182
|
+
|
183
|
+
on '*.*' do
|
184
|
+
grant 'SELECT'
|
185
|
+
end
|
186
|
+
end
|
187
|
+
RUBY
|
188
|
+
|
189
|
+
expect {
|
190
|
+
apply(subject) { dsl }
|
191
|
+
}.to raise_error('User `scott@localhost`: Object `*.*` is already defined')
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
describe 'Gratan::Client#apply' do
|
2
|
+
before(:each) do
|
3
|
+
apply {
|
4
|
+
<<-RUBY
|
5
|
+
user 'scott', 'localhost', identified: 'tiger', required: 'SSL' do
|
6
|
+
on '*.*' do
|
7
|
+
grant 'SELECT'
|
8
|
+
grant 'INSERT'
|
9
|
+
end
|
10
|
+
|
11
|
+
on 'test.*' do
|
12
|
+
grant 'UPDATE'
|
13
|
+
grant 'DELETE'
|
14
|
+
end
|
15
|
+
|
16
|
+
on 'mysql.user' do
|
17
|
+
grant 'SELECT (user)'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
user 'bob', 'localhost' do
|
22
|
+
on '*.*' do
|
23
|
+
grant 'USAGE'
|
24
|
+
end
|
25
|
+
|
26
|
+
on 'test.*' do
|
27
|
+
grant 'ALL PRIVILEGES'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
RUBY
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when drop user' do
|
35
|
+
subject { client(dry_run: true) }
|
36
|
+
|
37
|
+
it do
|
38
|
+
apply(subject) {
|
39
|
+
<<-RUBY
|
40
|
+
user 'bob', 'localhost' do
|
41
|
+
on '*.*' do
|
42
|
+
grant 'USAGE'
|
43
|
+
end
|
44
|
+
|
45
|
+
on 'test.*' do
|
46
|
+
grant 'ALL PRIVILEGES'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
RUBY
|
50
|
+
}
|
51
|
+
|
52
|
+
expect(show_grants).to match_array [
|
53
|
+
"GRANT ALL PRIVILEGES ON `test`.* TO 'bob'@'localhost'",
|
54
|
+
"GRANT SELECT (user) ON `mysql`.`user` TO 'scott'@'localhost'",
|
55
|
+
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
56
|
+
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
57
|
+
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
58
|
+
]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when drop all users' do
|
63
|
+
subject { client(dry_run: true) }
|
64
|
+
|
65
|
+
it do
|
66
|
+
apply(subject) { '' }
|
67
|
+
|
68
|
+
expect(show_grants).to match_array [
|
69
|
+
"GRANT ALL PRIVILEGES ON `test`.* TO 'bob'@'localhost'",
|
70
|
+
"GRANT SELECT (user) ON `mysql`.`user` TO 'scott'@'localhost'",
|
71
|
+
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
72
|
+
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
73
|
+
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
74
|
+
]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
describe 'Gratan::Client#apply' do
|
2
|
+
before(:each) do
|
3
|
+
apply {
|
4
|
+
<<-RUBY
|
5
|
+
user 'scott', 'localhost', identified: 'tiger', required: 'SSL' do
|
6
|
+
on '*.*' do
|
7
|
+
grant 'SELECT'
|
8
|
+
grant 'INSERT'
|
9
|
+
end
|
10
|
+
|
11
|
+
on 'test.*' do
|
12
|
+
grant 'UPDATE'
|
13
|
+
grant 'DELETE'
|
14
|
+
end
|
15
|
+
|
16
|
+
on 'mysql.user' do
|
17
|
+
grant 'SELECT (user)'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
user 'bob', 'localhost' do
|
22
|
+
on '*.*' do
|
23
|
+
grant 'USAGE'
|
24
|
+
end
|
25
|
+
|
26
|
+
on 'test.*' do
|
27
|
+
grant 'ALL PRIVILEGES'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
RUBY
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when drop user' do
|
35
|
+
subject { client }
|
36
|
+
|
37
|
+
it do
|
38
|
+
apply(subject) {
|
39
|
+
<<-RUBY
|
40
|
+
user 'bob', 'localhost' do
|
41
|
+
on '*.*' do
|
42
|
+
grant 'USAGE'
|
43
|
+
end
|
44
|
+
|
45
|
+
on 'test.*' do
|
46
|
+
grant 'ALL PRIVILEGES'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
RUBY
|
50
|
+
}
|
51
|
+
|
52
|
+
expect(show_grants).to match_array [
|
53
|
+
"GRANT ALL PRIVILEGES ON `test`.* TO 'bob'@'localhost'",
|
54
|
+
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
55
|
+
]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when drop all users' do
|
60
|
+
subject { client }
|
61
|
+
|
62
|
+
it do
|
63
|
+
apply(subject) { '' }
|
64
|
+
expect(show_grants).to match_array []
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
describe 'Gratan::Client#apply' do
|
2
|
+
before(:each) do
|
3
|
+
apply {
|
4
|
+
<<-RUBY
|
5
|
+
user 'scott', 'localhost', identified: 'tiger', required: 'SSL' do
|
6
|
+
on '*.*' do
|
7
|
+
grant 'SELECT'
|
8
|
+
grant 'INSERT'
|
9
|
+
end
|
10
|
+
|
11
|
+
on 'test.*' do
|
12
|
+
grant 'UPDATE'
|
13
|
+
grant 'DELETE'
|
14
|
+
end
|
15
|
+
|
16
|
+
on 'mysql.user' do
|
17
|
+
grant 'SELECT (user)'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
user 'bob', 'localhost' do
|
22
|
+
on '*.*' do
|
23
|
+
grant 'USAGE'
|
24
|
+
end
|
25
|
+
|
26
|
+
on 'test.*' do
|
27
|
+
grant 'ALL PRIVILEGES'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
RUBY
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when has expired' do
|
35
|
+
let(:logger) do
|
36
|
+
logger = Logger.new('/dev/null')
|
37
|
+
expect(logger).to receive(:warn).with('[WARN] User `scott@localhost` has expired')
|
38
|
+
logger
|
39
|
+
end
|
40
|
+
|
41
|
+
subject do
|
42
|
+
client(
|
43
|
+
enable_expired: true,
|
44
|
+
logger: logger
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
it do
|
49
|
+
dsl = <<-RUBY
|
50
|
+
user 'scott', 'localhost', identified: 'tiger', required: 'SSL', expired: '2014/10/06' do
|
51
|
+
on '*.*' do
|
52
|
+
grant 'SELECT'
|
53
|
+
grant 'INSERT'
|
54
|
+
end
|
55
|
+
|
56
|
+
on 'test.*' do
|
57
|
+
grant 'UPDATE'
|
58
|
+
grant 'DELETE'
|
59
|
+
end
|
60
|
+
|
61
|
+
on 'mysql.user' do
|
62
|
+
grant 'SELECT (user)'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
user 'bob', 'localhost' do
|
67
|
+
on '*.*' do
|
68
|
+
grant 'USAGE'
|
69
|
+
end
|
70
|
+
|
71
|
+
on 'test.*' do
|
72
|
+
grant 'ALL PRIVILEGES'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
RUBY
|
76
|
+
|
77
|
+
Timecop.freeze(Time.parse('2014/10/06')) do
|
78
|
+
apply(subject) { dsl }
|
79
|
+
end
|
80
|
+
|
81
|
+
expect(show_grants).to match_array [
|
82
|
+
"GRANT ALL PRIVILEGES ON `test`.* TO 'bob'@'localhost'",
|
83
|
+
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
84
|
+
]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'when has not expired' do
|
89
|
+
subject { client(enable_expired: true) }
|
90
|
+
|
91
|
+
it do
|
92
|
+
dsl = <<-RUBY
|
93
|
+
user 'scott', 'localhost', identified: 'tiger', required: 'SSL', expired: '2014/10/06' do
|
94
|
+
on '*.*' do
|
95
|
+
grant 'SELECT'
|
96
|
+
grant 'INSERT'
|
97
|
+
end
|
98
|
+
|
99
|
+
on 'test.*' do
|
100
|
+
grant 'UPDATE'
|
101
|
+
grant 'DELETE'
|
102
|
+
end
|
103
|
+
|
104
|
+
on 'mysql.user' do
|
105
|
+
grant 'SELECT (user)'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
user 'bob', 'localhost' do
|
110
|
+
on '*.*' do
|
111
|
+
grant 'USAGE'
|
112
|
+
end
|
113
|
+
|
114
|
+
on 'test.*' do
|
115
|
+
grant 'ALL PRIVILEGES'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
RUBY
|
119
|
+
|
120
|
+
Timecop.freeze(Time.parse('2014/10/05 23:59:59')) do
|
121
|
+
apply(subject) { dsl }
|
122
|
+
end
|
123
|
+
|
124
|
+
expect(show_grants).to match_array [
|
125
|
+
"GRANT ALL PRIVILEGES ON `test`.* TO 'bob'@'localhost'",
|
126
|
+
"GRANT SELECT (user) ON `mysql`.`user` TO 'scott'@'localhost'",
|
127
|
+
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
128
|
+
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
129
|
+
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
130
|
+
]
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'when enable_expired is false' do
|
135
|
+
subject { client(enable_expired: false) }
|
136
|
+
|
137
|
+
it do
|
138
|
+
dsl = <<-RUBY
|
139
|
+
user 'scott', 'localhost', identified: 'tiger', required: 'SSL', expired: '2014/10/06' do
|
140
|
+
on '*.*' do
|
141
|
+
grant 'SELECT'
|
142
|
+
grant 'INSERT'
|
143
|
+
end
|
144
|
+
|
145
|
+
on 'test.*' do
|
146
|
+
grant 'UPDATE'
|
147
|
+
grant 'DELETE'
|
148
|
+
end
|
149
|
+
|
150
|
+
on 'mysql.user' do
|
151
|
+
grant 'SELECT (user)'
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
user 'bob', 'localhost' do
|
156
|
+
on '*.*' do
|
157
|
+
grant 'USAGE'
|
158
|
+
end
|
159
|
+
|
160
|
+
on 'test.*' do
|
161
|
+
grant 'ALL PRIVILEGES'
|
162
|
+
end
|
163
|
+
end
|
164
|
+
RUBY
|
165
|
+
|
166
|
+
Timecop.freeze(Time.parse('2014/10/10')) do
|
167
|
+
apply(subject) { dsl }
|
168
|
+
end
|
169
|
+
|
170
|
+
expect(show_grants).to match_array [
|
171
|
+
"GRANT ALL PRIVILEGES ON `test`.* TO 'bob'@'localhost'",
|
172
|
+
"GRANT SELECT (user) ON `mysql`.`user` TO 'scott'@'localhost'",
|
173
|
+
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
|
174
|
+
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
175
|
+
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
|
176
|
+
]
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
describe 'Gratan::Client#export' do
|
2
|
+
context 'when user does not exist' do
|
3
|
+
subject { client }
|
4
|
+
|
5
|
+
it do
|
6
|
+
expect(subject.export.strip).to eq ''
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'when user exists' do
|
11
|
+
let(:grantfile) {
|
12
|
+
<<-RUBY
|
13
|
+
user "scott", "%" do
|
14
|
+
on "*.*" do
|
15
|
+
grant "USAGE"
|
16
|
+
end
|
17
|
+
|
18
|
+
on "test.*" do
|
19
|
+
grant "SELECT"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
user "scott", "localhost" do
|
24
|
+
on "*.*" do
|
25
|
+
grant "USAGE"
|
26
|
+
end
|
27
|
+
|
28
|
+
on "test.*" do
|
29
|
+
grant "SELECT"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
RUBY
|
33
|
+
}
|
34
|
+
|
35
|
+
subject { client }
|
36
|
+
|
37
|
+
before do
|
38
|
+
apply(subject) do
|
39
|
+
grantfile
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it do
|
44
|
+
expect(subject.export.strip).to eq grantfile.strip
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when ignore user exists' do
|
49
|
+
let(:grantfile) {
|
50
|
+
<<-RUBY
|
51
|
+
user "scott", "%" do
|
52
|
+
on "*.*" do
|
53
|
+
grant "USAGE"
|
54
|
+
end
|
55
|
+
|
56
|
+
on "test.*" do
|
57
|
+
grant "SELECT"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
user "bob", "localhost" do
|
62
|
+
on "*.*" do
|
63
|
+
grant "USAGE"
|
64
|
+
end
|
65
|
+
|
66
|
+
on "test.*" do
|
67
|
+
grant "SELECT"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
RUBY
|
71
|
+
}
|
72
|
+
|
73
|
+
subject { client(ignore_user: /\Abob\z/) }
|
74
|
+
|
75
|
+
before do
|
76
|
+
apply(subject) do
|
77
|
+
grantfile
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it do
|
82
|
+
expect(subject.export.strip).to eq <<-RUBY.strip
|
83
|
+
user "scott", "%" do
|
84
|
+
on "*.*" do
|
85
|
+
grant "USAGE"
|
86
|
+
end
|
87
|
+
|
88
|
+
on "test.*" do
|
89
|
+
grant "SELECT"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
RUBY
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when with option exists' do
|
97
|
+
let(:grantfile) {
|
98
|
+
<<-RUBY
|
99
|
+
user "scott", "%" do
|
100
|
+
on "*.*", :with=>"GRANT OPTION" do
|
101
|
+
grant "USAGE"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
RUBY
|
105
|
+
}
|
106
|
+
|
107
|
+
subject { client(ignore_user: /\Abob\z/) }
|
108
|
+
|
109
|
+
before do
|
110
|
+
apply(subject) do
|
111
|
+
grantfile
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it do
|
116
|
+
expect(subject.export.strip).to eq grantfile.strip
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
describe 'Gratan::Client#apply' do
|
2
|
+
context 'when colorize is true' do
|
3
|
+
subject { client }
|
4
|
+
|
5
|
+
it do
|
6
|
+
dsl = <<-RUBY
|
7
|
+
user 'scott', 'localhost', identified: 'tiger' do
|
8
|
+
on '*.*' do
|
9
|
+
grant 'SELECT'
|
10
|
+
grant 'INSERT'
|
11
|
+
grant 'UPDATE'
|
12
|
+
grant 'DELETE'
|
13
|
+
end
|
14
|
+
|
15
|
+
on 'test.*' do
|
16
|
+
grant 'SELECT'
|
17
|
+
grant 'INSERT'
|
18
|
+
grant 'UPDATE'
|
19
|
+
grant 'DELETE'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
RUBY
|
23
|
+
|
24
|
+
begin
|
25
|
+
String.colorize = true
|
26
|
+
apply(subject) { dsl }
|
27
|
+
ensure
|
28
|
+
String.colorize = false
|
29
|
+
end
|
30
|
+
|
31
|
+
expect(show_grants).to match_array [
|
32
|
+
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
33
|
+
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
34
|
+
]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when set debug' do
|
39
|
+
let(:logger) do
|
40
|
+
logger = Gratan::Logger.instance
|
41
|
+
logger.set_debug(true)
|
42
|
+
logger
|
43
|
+
end
|
44
|
+
|
45
|
+
subject { client(logger: logger) }
|
46
|
+
|
47
|
+
it do
|
48
|
+
apply(subject) {
|
49
|
+
<<-RUBY
|
50
|
+
user 'scott', 'localhost', identified: 'tiger' do
|
51
|
+
on '*.*' do
|
52
|
+
grant 'SELECT'
|
53
|
+
grant 'INSERT'
|
54
|
+
grant 'UPDATE'
|
55
|
+
grant 'DELETE'
|
56
|
+
end
|
57
|
+
|
58
|
+
on 'test.*' do
|
59
|
+
grant 'SELECT'
|
60
|
+
grant 'INSERT'
|
61
|
+
grant 'UPDATE'
|
62
|
+
grant 'DELETE'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
RUBY
|
66
|
+
}
|
67
|
+
|
68
|
+
expect(show_grants).to match_array [
|
69
|
+
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
|
70
|
+
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
|
71
|
+
]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|