my_obfuscate 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +1 -0
- data/lib/my_obfuscate/postgres.rb +1 -1
- data/lib/my_obfuscate/version.rb +1 -1
- data/spec/my_obfuscate/config_applicator_spec.rb +92 -92
- data/spec/my_obfuscate/mysql_spec.rb +13 -13
- data/spec/my_obfuscate/postgres_spec.rb +16 -11
- data/spec/my_obfuscate/sql_server_spec.rb +10 -10
- data/spec/my_obfuscate_spec.rb +63 -63
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e7f50293f88ff7eea7bdce3905110af4602229c
|
4
|
+
data.tar.gz: 4008d4d1bb153fde2125dabcf2afdcbef334fbdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77a9e4325cabd6434e89928d6c1939f914cad6bfe0289618c4a91f67a4c6d237c27a81e98ae43a5b4913b75b1504a1723cebd0f9f1829a938bcea249dd36270c
|
7
|
+
data.tar.gz: b55e7c9b10453a22b77c8231a2f9665393aff73bc1fbcda9bf48959ad3a1846042943dc27d7d4a96cf8c9cb991589139d5caa4323ae753a44cc1163b0b47ed3e
|
data/CHANGES
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
+
10/24/2014 - Postgres handles empty trailing fields.
|
1
2
|
7/17/2013 - Switch Postgres to use COPY statements and refactor internals. Thanks @samuelreh!
|
2
3
|
3/4/2013 - Switch to the ffaker gem for speed. Add WalkerMethod and an English language frequency dictionary for generating random texts.
|
@@ -10,7 +10,7 @@ class MyObfuscate
|
|
10
10
|
# We wrap it in an array to keep it consistent with MySql bulk
|
11
11
|
# obfuscation (multiple rows per insert statement)
|
12
12
|
def rows_to_be_inserted(line)
|
13
|
-
row = line.split(/\t
|
13
|
+
row = line.split(/\t/, -1)
|
14
14
|
row.last && row.last.strip!
|
15
15
|
|
16
16
|
row.collect! do |value|
|
data/lib/my_obfuscate/version.rb
CHANGED
@@ -6,101 +6,101 @@ describe MyObfuscate::ConfigApplicator do
|
|
6
6
|
it "should work on email addresses" do
|
7
7
|
100.times do
|
8
8
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else"], {:a => {:type => :email}}, [:a, :b])
|
9
|
-
new_row.length.
|
10
|
-
new_row.first.
|
9
|
+
expect(new_row.length).to eq(2)
|
10
|
+
expect(new_row.first).to match(/^[\w\.]+\@(\w+\.){2,3}[a-f0-9]{5}\.example\.com$/)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should work on strings" do
|
15
15
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "something crazy"], {:b => {:type => :string, :length => 7}}, [:a, :b, :c])
|
16
|
-
new_row.length.
|
17
|
-
new_row[1].length.
|
18
|
-
new_row[1].
|
16
|
+
expect(new_row.length).to eq(3)
|
17
|
+
expect(new_row[1].length).to eq(7)
|
18
|
+
expect(new_row[1]).not_to eq("something_else")
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "conditional directives" do
|
22
22
|
it "should honor :unless conditionals" do
|
23
23
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:a=> {:type => :fixed, :string => "123", :unless => lambda { |row| row[:a] == "blah" }}}, [:a, :b, :c])
|
24
|
-
new_row[0].
|
25
|
-
new_row[0].
|
24
|
+
expect(new_row[0]).not_to eq("123")
|
25
|
+
expect(new_row[0]).to eq("blah")
|
26
26
|
|
27
27
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:a=> {:type => :fixed, :string => "123", :unless => lambda { |row| row[:a] == "not blah" }}}, [:a, :b, :c])
|
28
|
-
new_row[0].
|
28
|
+
expect(new_row[0]).to eq("123")
|
29
29
|
|
30
30
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config([nil, "something_else", "5"], {:a=> {:type => :fixed, :string => "123", :unless => :nil}, :b=> {:type => :fixed, :string => "123", :unless => :nil}}, [:a, :b, :c])
|
31
|
-
new_row[0].
|
32
|
-
new_row[1].
|
31
|
+
expect(new_row[0]).to eq(nil)
|
32
|
+
expect(new_row[1]).to eq("123")
|
33
33
|
|
34
34
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(['', "something_else", "5"], {:a=> {:type => :fixed, :string => "123", :unless => :blank}, :b=> {:type => :fixed, :string => "123", :unless => :blank}}, [:a, :b, :c])
|
35
|
-
new_row[0].
|
36
|
-
new_row[1].
|
35
|
+
expect(new_row[0]).to eq('')
|
36
|
+
expect(new_row[1]).to eq("123")
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should honor :if conditionals" do
|
40
40
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:a=> {:type => :fixed, :string => "123", :if => lambda { |row| row[:a] == "blah" }}}, [:a, :b, :c])
|
41
|
-
new_row[0].
|
41
|
+
expect(new_row[0]).to eq("123")
|
42
42
|
|
43
43
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:a=> {:type => :fixed, :string => "123", :if=> lambda { |row| row[:a] == "not blah" }}}, [:a, :b, :c])
|
44
|
-
new_row[0].
|
45
|
-
new_row[0].
|
44
|
+
expect(new_row[0]).not_to eq("123")
|
45
|
+
expect(new_row[0]).to eq("blah")
|
46
46
|
|
47
47
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config([nil, "something_else", "5"], {:a=> {:type => :fixed, :string => "123", :if => :nil}, :b=> {:type => :fixed, :string => "123", :if => :nil}}, [:a, :b, :c])
|
48
|
-
new_row[0].
|
49
|
-
new_row[1].
|
48
|
+
expect(new_row[0]).to eq("123")
|
49
|
+
expect(new_row[1]).to eq("something_else")
|
50
50
|
|
51
51
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(['', "something_else", "5"], {:a=> {:type => :fixed, :string => "123", :if => :blank}, :b=> {:type => :fixed, :string => "123", :if => :blank}}, [:a, :b, :c])
|
52
|
-
new_row[0].
|
53
|
-
new_row[1].
|
52
|
+
expect(new_row[0]).to eq("123")
|
53
|
+
expect(new_row[1]).to eq("something_else")
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should supply the original row values to the conditional" do
|
57
57
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else"], {:a => {:type => :fixed, :string => "123"}, :b => {:type => :fixed, :string => "yup", :if => lambda { |row| row[:a] == "blah" }}}, [:a, :b])
|
58
|
-
new_row[0].
|
59
|
-
new_row[1].
|
58
|
+
expect(new_row[0]).to eq("123")
|
59
|
+
expect(new_row[1]).to eq("yup")
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should honor combined :unless and :if conditionals" do
|
63
63
|
#both true
|
64
64
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:a=> {:type => :fixed, :string => "123", :if => lambda { |row| row[:a] == "blah" }, :unless => lambda { |row| row[:b] == "something_else" }}}, [:a, :b, :c])
|
65
|
-
new_row[0].
|
65
|
+
expect(new_row[0]).to eq("blah")
|
66
66
|
|
67
67
|
#both false
|
68
68
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:a=> {:type => :fixed, :string => "123", :if => lambda { |row| row[:a] == "not blah" }, :unless => lambda { |row| row[:b] == "not something_else" }}}, [:a, :b, :c])
|
69
|
-
new_row[0].
|
69
|
+
expect(new_row[0]).to eq("blah")
|
70
70
|
|
71
71
|
#if true, #unless false
|
72
72
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:a=> {:type => :fixed, :string => "123", :if => lambda { |row| row[:a] == "blah" }, :unless => lambda { |row| row[:b] == "not something_else" }}}, [:a, :b, :c])
|
73
|
-
new_row[0].
|
73
|
+
expect(new_row[0]).to eq("123")
|
74
74
|
|
75
75
|
#if false, #unless true
|
76
76
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:a=> {:type => :fixed, :string => "123", :if => lambda { |row| row[:a] == "not blah" }, :unless => lambda { |row| row[:b] == "something_else" }}}, [:a, :b, :c])
|
77
|
-
new_row[0].
|
77
|
+
expect(new_row[0]).to eq("blah")
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should be able to generate random integers in ranges" do
|
82
82
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:c => {:type => :integer, :between => 10..100}}, [:a, :b, :c])
|
83
|
-
new_row.length.
|
84
|
-
new_row[2].to_i.to_s.
|
85
|
-
new_row[2].
|
83
|
+
expect(new_row.length).to eq(3)
|
84
|
+
expect(new_row[2].to_i.to_s).to eq(new_row[2]) # It should be an integer.
|
85
|
+
expect(new_row[2]).not_to eq("5")
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should be able to substitute fixed strings" do
|
89
89
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:b => {:type => :fixed, :string => "hello"}}, [:a, :b, :c])
|
90
|
-
new_row.length.
|
91
|
-
new_row[1].
|
90
|
+
expect(new_row.length).to eq(3)
|
91
|
+
expect(new_row[1]).to eq("hello")
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should be able to substitute a proc that returns a string" do
|
95
95
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:b => {:type => :fixed, :string => proc { "Hello World" }}}, [:a, :b, :c])
|
96
|
-
new_row.length.
|
97
|
-
new_row[1].
|
96
|
+
expect(new_row.length).to eq(3)
|
97
|
+
expect(new_row[1]).to eq("Hello World")
|
98
98
|
end
|
99
99
|
|
100
100
|
it "should provide the row to the proc" do
|
101
101
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:b => {:type => :fixed, :string => proc { |a| a[:b] }}}, [:a, :b, :c])
|
102
|
-
new_row.length.
|
103
|
-
new_row[1].
|
102
|
+
expect(new_row.length).to eq(3)
|
103
|
+
expect(new_row[1]).to eq("something_else")
|
104
104
|
end
|
105
105
|
|
106
106
|
it "should be able to substitute fixed strings from a random set" do
|
@@ -109,154 +109,154 @@ describe MyObfuscate::ConfigApplicator do
|
|
109
109
|
guard = 0
|
110
110
|
while !looking_for.empty? && guard < 1000
|
111
111
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:a => {:type => :fixed, :one_of => ["hello", "world"]}}, [:a, :b, :c])
|
112
|
-
new_row.length.
|
113
|
-
original_looking_for.
|
112
|
+
expect(new_row.length).to eq(3)
|
113
|
+
expect(original_looking_for).to include(new_row[0])
|
114
114
|
looking_for.delete new_row[0]
|
115
115
|
guard += 1
|
116
116
|
end
|
117
|
-
looking_for.
|
117
|
+
expect(looking_for).to be_empty
|
118
118
|
end
|
119
119
|
|
120
120
|
it "should treat a symbol in the column definition as an implicit { :type => symbol }" do
|
121
121
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:b => :null, :a => :keep}, [:a, :b, :c])
|
122
|
-
new_row.length.
|
123
|
-
new_row[0].
|
124
|
-
new_row[1].
|
122
|
+
expect(new_row.length).to eq(3)
|
123
|
+
expect(new_row[0]).to eq("blah")
|
124
|
+
expect(new_row[1]).to eq(nil)
|
125
125
|
end
|
126
126
|
|
127
127
|
it "should be able to set things NULL" do
|
128
128
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:b => {:type => :null}}, [:a, :b, :c])
|
129
|
-
new_row.length.
|
130
|
-
new_row[1].
|
129
|
+
expect(new_row.length).to eq(3)
|
130
|
+
expect(new_row[1]).to eq(nil)
|
131
131
|
end
|
132
132
|
|
133
133
|
it "should be able to :keep the value the same" do
|
134
134
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:b => {:type => :keep}}, [:a, :b, :c])
|
135
|
-
new_row.length.
|
136
|
-
new_row[1].
|
135
|
+
expect(new_row.length).to eq(3)
|
136
|
+
expect(new_row[1]).to eq("something_else")
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should keep the value when given an unknown type, but should display a warning" do
|
140
140
|
$stderr = error_output = StringIO.new
|
141
141
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:b => {:type => :unknown_type}}, [:a, :b, :c])
|
142
142
|
$stderr = STDERR
|
143
|
-
new_row.length.
|
144
|
-
new_row[1].
|
143
|
+
expect(new_row.length).to eq(3)
|
144
|
+
expect(new_row[1]).to eq("something_else")
|
145
145
|
error_output.rewind
|
146
|
-
error_output.read.
|
146
|
+
expect(error_output.read).to match(/Keeping a column value by.*?unknown_type/)
|
147
147
|
end
|
148
148
|
|
149
149
|
it "should be able to substitute lorem ipsum text" do
|
150
150
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:a => :lorem, :b => {:type => :lorem, :number => 2}}, [:a, :b, :c])
|
151
|
-
new_row.length.
|
152
|
-
new_row[0].
|
153
|
-
new_row[0].
|
154
|
-
new_row[1].
|
155
|
-
new_row[1].
|
151
|
+
expect(new_row.length).to eq(3)
|
152
|
+
expect(new_row[0]).not_to eq("blah")
|
153
|
+
expect(new_row[0]).not_to match(/\w\.(?!\Z)/)
|
154
|
+
expect(new_row[1]).not_to eq("something_else")
|
155
|
+
expect(new_row[1]).to match(/\w\.(?!\Z)/)
|
156
156
|
end
|
157
157
|
|
158
158
|
it "should be able to generate an :company" do
|
159
159
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["Smith and Sons", "something_else", "5"], {:a => :company}, [:a, :b, :c])
|
160
|
-
new_row.length.
|
161
|
-
new_row[0].
|
162
|
-
new_row[0].
|
160
|
+
expect(new_row.length).to eq(3)
|
161
|
+
expect(new_row[0]).not_to eq("Smith and Sons")
|
162
|
+
expect(new_row[0]).to match(/\w+/)
|
163
163
|
end
|
164
164
|
|
165
165
|
it "should be able to generate an :url" do
|
166
166
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["http://mystuff.blogger.com", "something_else", "5"], {:a => :url}, [:a, :b, :c])
|
167
|
-
new_row.length.
|
168
|
-
new_row[0].
|
169
|
-
new_row[0].
|
167
|
+
expect(new_row.length).to eq(3)
|
168
|
+
expect(new_row[0]).not_to eq("http://mystuff.blogger.com")
|
169
|
+
expect(new_row[0]).to match(/http:\/\/\w+/)
|
170
170
|
end
|
171
171
|
|
172
172
|
it "should be able to generate an :ipv4" do
|
173
173
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["1.2.3.4", "something_else", "5"], {:a => :ipv4}, [:a, :b, :c])
|
174
|
-
new_row.length.
|
175
|
-
new_row[0].
|
176
|
-
new_row[0].
|
174
|
+
expect(new_row.length).to eq(3)
|
175
|
+
expect(new_row[0]).not_to eq("1.2.3.4")
|
176
|
+
expect(new_row[0]).to match(/\d+\.\d+\.\d+\.\d+/)
|
177
177
|
end
|
178
178
|
|
179
179
|
it "should be able to generate an :ipv6" do
|
180
180
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["fe80:0000:0000:0000:0202:b3ff:fe1e:8329", "something_else", "5"], {:a => :ipv6}, [:a, :b, :c])
|
181
|
-
new_row.length.
|
182
|
-
new_row[0].
|
183
|
-
new_row[0].
|
181
|
+
expect(new_row.length).to eq(3)
|
182
|
+
expect(new_row[0]).not_to eq("fe80:0000:0000:0000:0202:b3ff:fe1e:8329")
|
183
|
+
expect(new_row[0]).to match(/[0-9a-f:]+/)
|
184
184
|
end
|
185
185
|
|
186
186
|
it "should be able to generate an :address" do
|
187
187
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:a => :address}, [:a, :b, :c])
|
188
|
-
new_row.length.
|
189
|
-
new_row[0].
|
190
|
-
new_row[0].
|
188
|
+
expect(new_row.length).to eq(3)
|
189
|
+
expect(new_row[0]).not_to eq("blah")
|
190
|
+
expect(new_row[0]).to match(/\d+ \w/)
|
191
191
|
end
|
192
192
|
|
193
193
|
it "should be able to generate a :name" do
|
194
194
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:a => :name}, [:a, :b, :c])
|
195
|
-
new_row.length.
|
196
|
-
new_row[0].
|
197
|
-
new_row[0].
|
195
|
+
expect(new_row.length).to eq(3)
|
196
|
+
expect(new_row[0]).not_to eq("blah")
|
197
|
+
expect(new_row[0]).to match(/ /)
|
198
198
|
end
|
199
199
|
|
200
200
|
it "should be able to generate just a street address" do
|
201
201
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:a => :street_address}, [:a, :b, :c])
|
202
|
-
new_row.length.
|
203
|
-
new_row[0].
|
204
|
-
new_row[0].
|
202
|
+
expect(new_row.length).to eq(3)
|
203
|
+
expect(new_row[0]).not_to eq("blah")
|
204
|
+
expect(new_row[0]).to match(/\d+ \w/)
|
205
205
|
end
|
206
206
|
|
207
207
|
it "should be able to generate a city" do
|
208
208
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:a => :city}, [:a, :b, :c])
|
209
|
-
new_row.length.
|
210
|
-
new_row[0].
|
209
|
+
expect(new_row.length).to eq(3)
|
210
|
+
expect(new_row[0]).not_to eq("blah")
|
211
211
|
end
|
212
212
|
|
213
213
|
it "should be able to generate a state" do
|
214
214
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:a => :state}, [:a, :b, :c])
|
215
|
-
new_row.length.
|
216
|
-
new_row[0].
|
215
|
+
expect(new_row.length).to eq(3)
|
216
|
+
expect(new_row[0]).not_to eq("blah")
|
217
217
|
end
|
218
218
|
|
219
219
|
it "should be able to generate a zip code" do
|
220
220
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:a => :zip_code}, [:a, :b, :c])
|
221
|
-
new_row.length.
|
222
|
-
new_row[0].
|
223
|
-
new_row[0].
|
221
|
+
expect(new_row.length).to eq(3)
|
222
|
+
expect(new_row[0]).not_to eq("blah")
|
223
|
+
expect(new_row[0]).to match(/\d+/)
|
224
224
|
end
|
225
225
|
|
226
226
|
it "should be able to generate a phone number" do
|
227
227
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["blah", "something_else", "5"], {:a => :phone}, [:a, :b, :c])
|
228
|
-
new_row.length.
|
229
|
-
new_row[0].
|
230
|
-
new_row[0].
|
228
|
+
expect(new_row.length).to eq(3)
|
229
|
+
expect(new_row[0]).not_to eq("blah")
|
230
|
+
expect(new_row[0]).to match(/\d+/)
|
231
231
|
end
|
232
232
|
|
233
233
|
describe "when faker generates values with quotes in them" do
|
234
234
|
before do
|
235
|
-
Faker::Address.
|
236
|
-
Faker::Name.
|
237
|
-
Faker::Name.
|
238
|
-
Faker::Name.
|
239
|
-
Faker::Lorem.
|
235
|
+
allow(Faker::Address).to receive(:city).and_return("O'ReillyTown")
|
236
|
+
allow(Faker::Name).to receive(:name).and_return("Foo O'Reilly")
|
237
|
+
allow(Faker::Name).to receive(:first_name).and_return("O'Foo")
|
238
|
+
allow(Faker::Name).to receive(:last_name).and_return("O'Reilly")
|
239
|
+
allow(Faker::Lorem).to receive(:sentences).with(any_args).and_return(["Foo bar O'Thingy"])
|
240
240
|
end
|
241
241
|
|
242
242
|
it "should remove single quotes from the value" do
|
243
243
|
new_row = MyObfuscate::ConfigApplicator.apply_table_config(["address", "city", "first", "last", "fullname", "some text"],
|
244
244
|
{:a => :address, :b => :city, :c => :first_name, :d => :last_name, :e => :name, :f => :lorem},
|
245
245
|
[:a, :b, :c, :d, :e, :f])
|
246
|
-
new_row.each {|value| value.
|
246
|
+
new_row.each {|value| expect(value).not_to include("'")}
|
247
247
|
end
|
248
248
|
end
|
249
249
|
end
|
250
250
|
|
251
251
|
describe ".row_as_hash" do
|
252
252
|
it "will map row values into a hash with column names as keys" do
|
253
|
-
MyObfuscate::ConfigApplicator.row_as_hash([1, 2, 3, 4], [:a, :b, :c, :d]).
|
253
|
+
expect(MyObfuscate::ConfigApplicator.row_as_hash([1, 2, 3, 4], [:a, :b, :c, :d])).to eq({:a => 1, :b => 2, :c => 3, :d => 4})
|
254
254
|
end
|
255
255
|
end
|
256
256
|
|
257
257
|
describe ".random_english_sentences" do
|
258
258
|
before do
|
259
|
-
File.
|
259
|
+
expect(File).to receive(:read).once.and_return("hello 2")
|
260
260
|
end
|
261
261
|
|
262
262
|
after do
|
@@ -269,7 +269,7 @@ describe MyObfuscate::ConfigApplicator do
|
|
269
269
|
end
|
270
270
|
|
271
271
|
it "should make random sentences" do
|
272
|
-
MyObfuscate::ConfigApplicator.random_english_sentences(2).
|
272
|
+
expect(MyObfuscate::ConfigApplicator.random_english_sentences(2)).to match(/^(Hello( hello)+\.\s*){2}$/)
|
273
273
|
end
|
274
274
|
end
|
275
275
|
|
@@ -6,74 +6,74 @@ describe MyObfuscate::Mysql do
|
|
6
6
|
it "should split a mysql string into fields" do
|
7
7
|
string = "INSERT INTO `some_table` (thing1,thing2) VALUES ('bob@bob.com','bob', 'somethingelse1', 25, '2', 10, 'hi') ; "
|
8
8
|
fields = [['bob@bob.com', 'bob', 'somethingelse1', '25', '2', '10', "hi"]]
|
9
|
-
subject.rows_to_be_inserted(string).
|
9
|
+
expect(subject.rows_to_be_inserted(string)).to eq(fields)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should work ok with escaped characters" do
|
13
13
|
string = "INSERT INTO `some_table` (thing1,thing2) VALUES ('bob,@bob.c , om', 'bo\\', b', 'some\"thin\\gel\\\\\\'se1', 25, '2', 10, 'hi', 5) ; "
|
14
14
|
fields = [['bob,@bob.c , om', 'bo\\\', b', 'some"thin\\gel\\\\\\\'se1', '25', '2', '10', "hi", "5"]]
|
15
|
-
subject.rows_to_be_inserted(string).
|
15
|
+
expect(subject.rows_to_be_inserted(string)).to eq(fields)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should work with multiple subinserts" do
|
19
19
|
string = "INSERT INTO `some_table` (thing1,thing2) VALUES (1,2,3, '((m))(oo()s,e'), ('bob,@bob.c , om', 'bo\\', b', 'some\"thin\\gel\\\\\\'se1', 25, '2', 10, 'hi', 5) ;"
|
20
20
|
fields = [["1", "2", "3", "((m))(oo()s,e"], ['bob,@bob.c , om', 'bo\\\', b', 'some"thin\\gel\\\\\\\'se1', '25', '2', '10', "hi", "5"]]
|
21
|
-
subject.rows_to_be_inserted(string).
|
21
|
+
expect(subject.rows_to_be_inserted(string)).to eq(fields)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should work ok with NULL values" do
|
25
25
|
string = "INSERT INTO `some_table` (thing1,thing2) VALUES (NULL , 'bob@bob.com','bob', NULL, 25, '2', NULL, 'hi', NULL ); "
|
26
26
|
fields = [[nil, 'bob@bob.com', 'bob', nil, '25', '2', nil, "hi", nil]]
|
27
|
-
subject.rows_to_be_inserted(string).
|
27
|
+
expect(subject.rows_to_be_inserted(string)).to eq(fields)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should work with empty strings" do
|
31
31
|
string = "INSERT INTO `some_table` (thing1,thing2) VALUES (NULL , '', '' , '', 25, '2','', 'hi','') ;"
|
32
32
|
fields = [[nil, '', '', '', '25', '2', '', "hi", '']]
|
33
|
-
subject.rows_to_be_inserted(string).
|
33
|
+
expect(subject.rows_to_be_inserted(string)).to eq(fields)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should work with hex encoded blobs" do
|
37
37
|
string = "INSERT INTO `some_table` (thing1,thing2) VALUES ('bla' , 'blobdata', 'blubb' , 0xACED00057372001F6A6176612E7574696C2E436F6C6C656) ;"
|
38
38
|
fields = [['bla', 'blobdata', 'blubb', '0xACED00057372001F6A6176612E7574696C2E436F6C6C656']]
|
39
|
-
subject.rows_to_be_inserted(string).
|
39
|
+
expect(subject.rows_to_be_inserted(string)).to eq(fields)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
describe "#make_valid_value_string" do
|
44
44
|
it "should work with nil values" do
|
45
45
|
value = nil
|
46
|
-
subject.make_valid_value_string(value).
|
46
|
+
expect(subject.make_valid_value_string(value)).to eq('NULL')
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should work with hex-encoded blob data" do
|
50
50
|
value = "0xACED00057372001F6A6176612E7574696C2E436F6C6C656"
|
51
|
-
subject.make_valid_value_string(value).
|
51
|
+
expect(subject.make_valid_value_string(value)).to eq('0xACED00057372001F6A6176612E7574696C2E436F6C6C656')
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should quote hex-encoded ALIKE data" do
|
55
55
|
value = "40x17x7"
|
56
|
-
subject.make_valid_value_string(value).
|
56
|
+
expect(subject.make_valid_value_string(value)).to eq("'40x17x7'")
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should quote all other values" do
|
60
60
|
value = "hello world"
|
61
|
-
subject.make_valid_value_string(value).
|
61
|
+
expect(subject.make_valid_value_string(value)).to eq("'hello world'")
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
describe "#parse_insert_statement" do
|
66
66
|
it "should return nil for other SQL syntaxes (MS SQL Server)" do
|
67
|
-
subject.parse_insert_statement("INSERT [dbo].[TASKS] ([TaskID], [TaskName]) VALUES (61, N'Report Thing')").
|
67
|
+
expect(subject.parse_insert_statement("INSERT [dbo].[TASKS] ([TaskID], [TaskName]) VALUES (61, N'Report Thing')")).to be_nil
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should return nil for MySQL non-insert statements" do
|
71
|
-
subject.parse_insert_statement("CREATE TABLE `some_table`;").
|
71
|
+
expect(subject.parse_insert_statement("CREATE TABLE `some_table`;")).to be_nil
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should return a hash of table name, column names for MySQL insert statements" do
|
75
75
|
hash = subject.parse_insert_statement("INSERT INTO `some_table` (`email`, `name`, `something`, `age`) VALUES ('bob@honk.com','bob', 'some\\'thin,ge())lse1', 25),('joe@joe.com','joe', 'somethingelse2', 54);")
|
76
|
-
hash.
|
76
|
+
expect(hash).to eq({:table_name => :some_table, :column_names => [:email, :name, :something, :age]})
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -7,42 +7,47 @@ describe MyObfuscate::Postgres do
|
|
7
7
|
describe "#rows_to_be_inserted" do
|
8
8
|
it 'splits tab seperated values' do
|
9
9
|
line = "1 2 3 4"
|
10
|
-
helper.rows_to_be_inserted(line).
|
10
|
+
expect(helper.rows_to_be_inserted(line)).to eq([["1","2","3","4"]])
|
11
|
+
end
|
12
|
+
|
13
|
+
it "preserves empty strings at the end of a line" do
|
14
|
+
line = "1 2 3 4 "
|
15
|
+
expect(helper.rows_to_be_inserted(line)).to eq([["1","2","3","4",""]])
|
11
16
|
end
|
12
17
|
|
13
18
|
it 'ignores the newline character at the end of string' do
|
14
19
|
line = "1 2 3 4\n"
|
15
|
-
helper.rows_to_be_inserted(line).
|
20
|
+
expect(helper.rows_to_be_inserted(line)).to eq([["1","2","3","4"]])
|
16
21
|
end
|
17
22
|
|
18
23
|
it "doesn't ignore newlines due to empty strings" do
|
19
24
|
line = "1 2 3 \n"
|
20
|
-
helper.rows_to_be_inserted(line).
|
25
|
+
expect(helper.rows_to_be_inserted(line)).to eq([["1","2","3",""]])
|
21
26
|
end
|
22
27
|
|
23
28
|
it "doesn't ignore newline characters in the string" do
|
24
29
|
line = "1 2 3\n4 5"
|
25
|
-
helper.rows_to_be_inserted(line).
|
30
|
+
expect(helper.rows_to_be_inserted(line)).to eq([["1","2","3\n4","5"]])
|
26
31
|
end
|
27
32
|
|
28
33
|
it "preserves empty strings in the middle of the string" do
|
29
34
|
line = "1 2 4"
|
30
|
-
helper.rows_to_be_inserted(line).
|
35
|
+
expect(helper.rows_to_be_inserted(line)).to eq([["1","2","","4"]])
|
31
36
|
end
|
32
37
|
|
33
38
|
it "preserves newline characters in the middle of the string" do
|
34
39
|
line = "1 2 \n 4"
|
35
|
-
helper.rows_to_be_inserted(line).
|
40
|
+
expect(helper.rows_to_be_inserted(line)).to eq([["1","2","\n","4"]])
|
36
41
|
end
|
37
42
|
|
38
43
|
it "replaces \\N with nil" do
|
39
44
|
line = "1 2 \\N 4"
|
40
|
-
helper.rows_to_be_inserted(line).
|
45
|
+
expect(helper.rows_to_be_inserted(line)).to eq([["1","2",nil,"4"]])
|
41
46
|
end
|
42
47
|
|
43
48
|
it "replaces \\N\n with nil" do
|
44
49
|
line = "1 2 3 \\N\n"
|
45
|
-
helper.rows_to_be_inserted(line).
|
50
|
+
expect(helper.rows_to_be_inserted(line)).to eq([["1","2","3",nil]])
|
46
51
|
end
|
47
52
|
end
|
48
53
|
|
@@ -50,14 +55,14 @@ describe MyObfuscate::Postgres do
|
|
50
55
|
it 'parses table name and column names' do
|
51
56
|
line = "COPY some_table (id, email, name, something) FROM stdin;"
|
52
57
|
hash = helper.parse_copy_statement(line)
|
53
|
-
hash[:table_name].
|
54
|
-
hash[:column_names].
|
58
|
+
expect(hash[:table_name]).to eq(:some_table)
|
59
|
+
expect(hash[:column_names]).to eq([:id, :email, :name, :something])
|
55
60
|
end
|
56
61
|
end
|
57
62
|
|
58
63
|
describe "#make_insert_statement" do
|
59
64
|
it 'creates a string with tab delminted' do
|
60
|
-
helper.make_insert_statement(:some_table, [:id, :name], ['1', '2']).
|
65
|
+
expect(helper.make_insert_statement(:some_table, [:id, :name], ['1', '2'])).to eq("1 2")
|
61
66
|
end
|
62
67
|
end
|
63
68
|
end
|
@@ -4,15 +4,15 @@ describe MyObfuscate::SqlServer do
|
|
4
4
|
describe "#parse_insert_statement" do
|
5
5
|
it "should return a hash of table_name, column_names for SQL Server input statements" do
|
6
6
|
hash = subject.parse_insert_statement("INSERT [dbo].[TASKS] ([TaskID], [TaskName]) VALUES (61, N'Report Thing')")
|
7
|
-
hash.
|
7
|
+
expect(hash).to eq({ :table_name => :TASKS, :column_names => [:TaskID, :TaskName] })
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should return nil for SQL Server non-insert statements" do
|
11
|
-
subject.parse_insert_statement("CREATE TABLE [dbo].[WORKFLOW](").
|
11
|
+
expect(subject.parse_insert_statement("CREATE TABLE [dbo].[WORKFLOW](")).to be_nil
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should return nil for non-SQL Server insert statements (MySQL)" do
|
15
|
-
subject.parse_insert_statement("INSERT INTO `some_table` (`email`, `name`, `something`, `age`) VALUES ('bob@honk.com','bob', 'some\\'thin,ge())lse1', 25),('joe@joe.com','joe', 'somethingelse2', 54);").
|
15
|
+
expect(subject.parse_insert_statement("INSERT INTO `some_table` (`email`, `name`, `something`, `age`) VALUES ('bob@honk.com','bob', 'some\\'thin,ge())lse1', 25),('joe@joe.com','joe', 'somethingelse2', 54);")).to be_nil
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -20,39 +20,39 @@ describe MyObfuscate::SqlServer do
|
|
20
20
|
it "should split a SQL Server string into fields" do
|
21
21
|
string = "INSERT [dbo].[some_table] ([thing1],[thing2]) VALUES (N'bob@bob.com',N'bob', N'somethingelse1',25, '2', 10, 'hi', CAST(0x00009E1A00000000 AS DATETIME)) ; "
|
22
22
|
fields = [['bob@bob.com', 'bob', 'somethingelse1', '25', '2', '10', "hi", "CAST(0x00009E1A00000000 AS DATETIME)"]]
|
23
|
-
subject.rows_to_be_inserted(string).
|
23
|
+
expect(subject.rows_to_be_inserted(string)).to eq(fields)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should work ok with single quote escape" do
|
27
27
|
string = "INSERT [dbo].[some_table] ([thing1],[thing2]) VALUES (N'bob,@bob.c , om', 'bo'', b', N'some\"thingel''se1', 25, '2', 10, 'hi', 5) ; "
|
28
28
|
fields = [['bob,@bob.c , om', "bo'', b", "some\"thingel''se1", '25', '2', '10', "hi", "5"]]
|
29
|
-
subject.rows_to_be_inserted(string).
|
29
|
+
expect(subject.rows_to_be_inserted(string)).to eq(fields)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should work ok with NULL values" do
|
33
33
|
string = "INSERT [dbo].[some_table] ([thing1],[thing2]) VALUES (NULL , N'bob@bob.com','bob', NULL, 25, N'2', NULL, 'hi', NULL ); "
|
34
34
|
fields = [[nil, 'bob@bob.com', 'bob', nil, '25', '2', nil, "hi", nil]]
|
35
|
-
subject.rows_to_be_inserted(string).
|
35
|
+
expect(subject.rows_to_be_inserted(string)).to eq(fields)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should work with empty strings" do
|
39
39
|
string = "INSERT [dbo].[some_table] ([thing1],[thing2]) VALUES (NULL , N'', '' , '', 25, '2','', N'hi','') ;"
|
40
40
|
fields = [[nil, '', '','', '25', '2', '', "hi", '']]
|
41
|
-
subject.rows_to_be_inserted(string).
|
41
|
+
expect(subject.rows_to_be_inserted(string)).to eq(fields)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
describe "#make_valid_value_string" do
|
46
46
|
it "should output 'NULL' when the value is nil" do
|
47
|
-
subject.make_valid_value_string(nil).
|
47
|
+
expect(subject.make_valid_value_string(nil)).to eq("NULL")
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should enclose the value in quotes if it's a string" do
|
51
|
-
subject.make_valid_value_string("something").
|
51
|
+
expect(subject.make_valid_value_string("something")).to eq("N'something'")
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should not enclose the value in quotes if it is a method call" do
|
55
|
-
subject.make_valid_value_string("CAST(0x00009E1A00000000 AS DATETIME)").
|
55
|
+
expect(subject.make_valid_value_string("CAST(0x00009E1A00000000 AS DATETIME)")).to eq("CAST(0x00009E1A00000000 AS DATETIME)")
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
data/spec/my_obfuscate_spec.rb
CHANGED
@@ -14,12 +14,12 @@ describe MyObfuscate do
|
|
14
14
|
it "should yield each subinsert and reassemble the result" do
|
15
15
|
count = 0
|
16
16
|
reassembled = MyObfuscate.new.reassembling_each_insert(@test_insert, "some_table", @column_names) do |sub_insert|
|
17
|
-
sub_insert.
|
17
|
+
expect(sub_insert).to eq(@test_insert_passes.shift)
|
18
18
|
count += 1
|
19
19
|
sub_insert
|
20
20
|
end
|
21
|
-
count.
|
22
|
-
reassembled.
|
21
|
+
expect(count).to eq(2)
|
22
|
+
expect(reassembled).to eq(@test_insert)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -74,25 +74,25 @@ COPY some_table_to_keep (a, b) FROM stdin;
|
|
74
74
|
end
|
75
75
|
|
76
76
|
it "is able to obfuscate single column tables" do
|
77
|
-
output_string.
|
78
|
-
output_string.
|
77
|
+
expect(output_string).not_to include("1\n2\n")
|
78
|
+
expect(output_string).to match(/\d\n\d\n/)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "is able to truncate tables" do
|
82
|
-
output_string.
|
82
|
+
expect(output_string).not_to include("1\t2\t3\t4")
|
83
83
|
end
|
84
84
|
|
85
85
|
it "can obfuscate the tables" do
|
86
|
-
output_string.
|
87
|
-
output_string.
|
86
|
+
expect(output_string).to include("COPY some_table (id, email, name, something, age) FROM stdin;\n")
|
87
|
+
expect(output_string).to match(/1\t.*\t\S{8}\tmoose\t\d{2}\n/)
|
88
88
|
end
|
89
89
|
|
90
90
|
it "can skip nils" do
|
91
|
-
output_string.
|
91
|
+
expect(output_string).to match(/\d\n\d\n\\N/)
|
92
92
|
end
|
93
93
|
|
94
94
|
it "is able to keep tables" do
|
95
|
-
output_string.
|
95
|
+
expect(output_string).to include("5\t6")
|
96
96
|
end
|
97
97
|
|
98
98
|
context "when dump contains INSERT statement" do
|
@@ -118,7 +118,7 @@ COPY some_table_to_keep (a, b) FROM stdin;
|
|
118
118
|
ddo.obfuscate(input, output)
|
119
119
|
input.rewind
|
120
120
|
output.rewind
|
121
|
-
output.read.
|
121
|
+
expect(output.read).to eq(string)
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
@@ -137,9 +137,9 @@ COPY some_table_to_keep (a, b) FROM stdin;
|
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should raise an error if a column name can't be found" do
|
140
|
-
|
140
|
+
expect {
|
141
141
|
@ddo.obfuscate(@database_dump, @output)
|
142
|
-
}.
|
142
|
+
}.to raise_error
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
@@ -176,35 +176,35 @@ COPY some_table_to_keep (a, b) FROM stdin;
|
|
176
176
|
end
|
177
177
|
|
178
178
|
it "should be able to truncate tables" do
|
179
|
-
@output_string.
|
180
|
-
@output_string.
|
179
|
+
expect(@output_string).not_to include("INSERT INTO `another_table`")
|
180
|
+
expect(@output_string).to include("INSERT INTO `one_more_table`")
|
181
181
|
end
|
182
182
|
|
183
183
|
it "should be able to declare tables to keep" do
|
184
|
-
@output_string.
|
184
|
+
expect(@output_string).to include("INSERT INTO `some_table_to_keep` (`a`, `b`, `c`, `d`) VALUES (1,2,3,4), (5,6,7,8);")
|
185
185
|
end
|
186
186
|
|
187
187
|
it "should ignore tables that it doesn't know about, but should warn" do
|
188
|
-
@output_string.
|
188
|
+
expect(@output_string).to include("INSERT INTO `an_ignored_table` (`col`, `col2`) VALUES ('hello','kjhjd^&dkjh'), ('hello1','kjhj!'), ('hello2','moose!!');")
|
189
189
|
@error_output.rewind
|
190
|
-
@error_output.read.
|
190
|
+
expect(@error_output.read).to match(/an_ignored_table was not specified in the config/)
|
191
191
|
end
|
192
192
|
|
193
193
|
it "should obfuscate the tables" do
|
194
|
-
@output_string.
|
195
|
-
@output_string.
|
196
|
-
@output_string.
|
197
|
-
@output_string.
|
198
|
-
@output_string.
|
199
|
-
@output_string.
|
200
|
-
@output_string.
|
194
|
+
expect(@output_string).to include("INSERT INTO `some_table` (`email`, `name`, `something`, `age`) VALUES (")
|
195
|
+
expect(@output_string).to include("INSERT INTO `one_more_table` (`a`, `password`, `c`, `d,d`) VALUES (")
|
196
|
+
expect(@output_string).to include("'some\\'thin,ge())lse1'")
|
197
|
+
expect(@output_string).to include("INSERT INTO `one_more_table` (`a`, `password`, `c`, `d,d`) VALUES ('hello','monkey',NULL),('hello1','monkey',NULL),('hello2','monkey',NULL);")
|
198
|
+
expect(@output_string).not_to include("INSERT INTO `one_more_table` (`a`, `password`, `c`, `d,d`) VALUES ('hello','kjhjd^&dkjh', 'aawefjkafe'), ('hello1','kjhj!', 892938), ('hello2','moose!!', NULL);")
|
199
|
+
expect(@output_string).not_to include("INSERT INTO `one_more_table` (`a`, `password`, `c`, `d,d`) VALUES ('hello','kjhjd^&dkjh','aawefjkafe'),('hello1','kjhj!',892938),('hello2','moose!!',NULL);")
|
200
|
+
expect(@output_string).not_to include("INSERT INTO `some_table` (`email`, `name`, `something`, `age`) VALUES ('bob@honk.com','bob', 'some\\'thin,ge())lse1', 25),('joe@joe.com','joe', 'somethingelse2', 54);")
|
201
201
|
end
|
202
202
|
|
203
203
|
it "honors a special case: on the people table, rows with skip_regexes that match are skipped" do
|
204
|
-
@output_string.
|
205
|
-
@output_string.
|
206
|
-
@output_string.
|
207
|
-
@output_string.
|
204
|
+
expect(@output_string).to include("('bob@honk.com',")
|
205
|
+
expect(@output_string).to include("('dontmurderme@direwolf.com',")
|
206
|
+
expect(@output_string).not_to include("joe@joe.com")
|
207
|
+
expect(@output_string).to include("example.com")
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
@@ -225,16 +225,16 @@ COPY some_table_to_keep (a, b) FROM stdin;
|
|
225
225
|
end
|
226
226
|
|
227
227
|
it "should raise an exception when an unspecified column is found" do
|
228
|
-
|
228
|
+
expect {
|
229
229
|
@ddo.obfuscate(@database_dump, StringIO.new)
|
230
|
-
}.
|
230
|
+
}.to raise_error(/column 'something' defined/i)
|
231
231
|
end
|
232
232
|
|
233
233
|
it "should accept columns defined in globally_kept_columns" do
|
234
234
|
@ddo.globally_kept_columns = %w[something]
|
235
|
-
|
235
|
+
expect {
|
236
236
|
@ddo.obfuscate(@database_dump, StringIO.new)
|
237
|
-
}.
|
237
|
+
}.not_to raise_error
|
238
238
|
end
|
239
239
|
end
|
240
240
|
end
|
@@ -250,7 +250,7 @@ COPY some_table_to_keep (a, b) FROM stdin;
|
|
250
250
|
ddo.obfuscate(input, output)
|
251
251
|
input.rewind
|
252
252
|
output.rewind
|
253
|
-
output.read.
|
253
|
+
expect(output.read).to eq(string)
|
254
254
|
end
|
255
255
|
end
|
256
256
|
|
@@ -270,9 +270,9 @@ COPY some_table_to_keep (a, b) FROM stdin;
|
|
270
270
|
end
|
271
271
|
|
272
272
|
it "should raise an error if a column name can't be found" do
|
273
|
-
|
273
|
+
expect {
|
274
274
|
@ddo.obfuscate(@database_dump, @output)
|
275
|
-
}.
|
275
|
+
}.to raise_error
|
276
276
|
end
|
277
277
|
end
|
278
278
|
|
@@ -320,42 +320,42 @@ COPY some_table_to_keep (a, b) FROM stdin;
|
|
320
320
|
end
|
321
321
|
|
322
322
|
it "should be able to truncate tables" do
|
323
|
-
@output_string.
|
324
|
-
@output_string.
|
323
|
+
expect(@output_string).not_to include("INSERT [dbo].[another_table]")
|
324
|
+
expect(@output_string).to include("INSERT [dbo].[one_more_table]")
|
325
325
|
end
|
326
326
|
|
327
327
|
it "should be able to declare tables to keep" do
|
328
|
-
@output_string.
|
329
|
-
@output_string.
|
328
|
+
expect(@output_string).to include("INSERT [dbo].[some_table_to_keep] ([a], [b], [c], [d]) VALUES (1,2,3,4);")
|
329
|
+
expect(@output_string).to include("INSERT [dbo].[some_table_to_keep] ([a], [b], [c], [d]) VALUES (5,6,7,8);")
|
330
330
|
end
|
331
331
|
|
332
332
|
it "should ignore tables that it doesn't know about, but should warn" do
|
333
|
-
@output_string.
|
334
|
-
@output_string.
|
335
|
-
@output_string.
|
333
|
+
expect(@output_string).to include("INSERT [dbo].[an_ignored_table] ([col], [col2]) VALUES (N'hello',N'kjhjd^&dkjh');")
|
334
|
+
expect(@output_string).to include("INSERT [dbo].[an_ignored_table] ([col], [col2]) VALUES (N'hello1',N'kjhj!');")
|
335
|
+
expect(@output_string).to include("INSERT [dbo].[an_ignored_table] ([col], [col2]) VALUES (N'hello2',N'moose!!');")
|
336
336
|
@error_output.rewind
|
337
|
-
@error_output.read.
|
337
|
+
expect(@error_output.read).to match(/an_ignored_table was not specified in the config/)
|
338
338
|
end
|
339
339
|
|
340
340
|
it "should obfuscate the tables" do
|
341
|
-
@output_string.
|
342
|
-
@output_string.
|
343
|
-
@output_string.
|
344
|
-
@output_string.
|
345
|
-
@output_string.
|
346
|
-
@output_string.
|
347
|
-
@output_string.
|
348
|
-
@output_string.
|
349
|
-
@output_string.
|
350
|
-
@output_string.
|
351
|
-
@output_string.
|
352
|
-
@output_string.
|
341
|
+
expect(@output_string).to include("INSERT [dbo].[some_table] ([email], [name], [something], [age], [bday]) VALUES (")
|
342
|
+
expect(@output_string).to include("CAST(0x00009E1A00000000 AS DATETIME)")
|
343
|
+
expect(@output_string).to include("INSERT [dbo].[one_more_table] ([a], [password], [c], [d,d]) VALUES (")
|
344
|
+
expect(@output_string).to include("'some''thin,ge())lse1'")
|
345
|
+
expect(@output_string).to include("INSERT [dbo].[one_more_table] ([a], [password], [c], [d,d]) VALUES (N'hello',N'monkey',NULL);")
|
346
|
+
expect(@output_string).to include("INSERT [dbo].[one_more_table] ([a], [password], [c], [d,d]) VALUES (N'hello1',N'monkey',NULL);")
|
347
|
+
expect(@output_string).to include("INSERT [dbo].[one_more_table] ([a], [password], [c], [d,d]) VALUES (N'hello2',N'monkey',NULL);")
|
348
|
+
expect(@output_string).not_to include("INSERT [dbo].[one_more_table] ([a], [password], [c], [d,d]) VALUES (N'hello',N'kjhjd^&dkjh', N'aawefjkafe');")
|
349
|
+
expect(@output_string).not_to include("INSERT [dbo].[one_more_table] ([a], [password], [c], [d,d]) VALUES (N'hello1',N'kjhj!', 892938);")
|
350
|
+
expect(@output_string).not_to include("INSERT [dbo].[one_more_table] ([a], [password], [c], [d,d]) VALUES (N'hello2',N'moose!!', NULL);")
|
351
|
+
expect(@output_string).not_to include("INSERT [dbo].[some_table] ([email], [name], [something], [age]) VALUES (N'bob@honk.com',N'bob', N'some''thin,ge())lse1', 25, CAST(0x00009E1A00000000 AS DATETIME));")
|
352
|
+
expect(@output_string).not_to include("INSERT [dbo].[some_table] ([email], [name], [something], [age]) VALUES (N'joe@joe.com',N'joe', N'somethingelse2', 54, CAST(0x00009E1A00000000 AS DATETIME));")
|
353
353
|
end
|
354
354
|
|
355
355
|
it "honors a special case: on the people table, rows with anything@honk.com in a slot marked with :honk_email_skip do not change this slot" do
|
356
|
-
@output_string.
|
357
|
-
@output_string.
|
358
|
-
@output_string.
|
356
|
+
expect(@output_string).to include("(N'bob@honk.com',")
|
357
|
+
expect(@output_string).to include("(N'dontmurderme@direwolf.com',")
|
358
|
+
expect(@output_string).not_to include("joe@joe.com")
|
359
359
|
end
|
360
360
|
end
|
361
361
|
|
@@ -377,16 +377,16 @@ COPY some_table_to_keep (a, b) FROM stdin;
|
|
377
377
|
end
|
378
378
|
|
379
379
|
it "should raise an exception when an unspecified column is found" do
|
380
|
-
|
380
|
+
expect {
|
381
381
|
@ddo.obfuscate(@database_dump, StringIO.new)
|
382
|
-
}.
|
382
|
+
}.to raise_error(/column 'something' defined/i)
|
383
383
|
end
|
384
384
|
|
385
385
|
it "should accept columns defined in globally_kept_columns" do
|
386
386
|
@ddo.globally_kept_columns = %w[something]
|
387
|
-
|
387
|
+
expect {
|
388
388
|
@ddo.obfuscate(@database_dump, StringIO.new)
|
389
|
-
}.
|
389
|
+
}.not_to raise_error
|
390
390
|
end
|
391
391
|
end
|
392
392
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: my_obfuscate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Cantino
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2014-
|
16
|
+
date: 2014-10-24 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: ffaker
|