my_obfuscate 0.3.7 → 0.4.2
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.
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/CHANGES +1 -0
- data/LICENSE +1 -1
- data/README.rdoc +11 -7
- data/lib/my_obfuscate/data/en_50K.txt +50000 -0
- data/lib/my_obfuscate/database_helper_shared.rb +76 -0
- data/lib/my_obfuscate/mysql.rb +5 -73
- data/lib/my_obfuscate/postgres.rb +23 -0
- data/lib/my_obfuscate/sql_server.rb +7 -4
- data/lib/my_obfuscate/version.rb +1 -1
- data/lib/my_obfuscate.rb +47 -14
- data/my_obfuscate.gemspec +4 -3
- data/spec/{mysql_spec.rb → my_obfuscate/database_helper_shared_examples.rb} +2 -17
- data/spec/my_obfuscate/mysql_spec.rb +23 -0
- data/spec/my_obfuscate/postgres_spec.rb +23 -0
- data/spec/{sql_server_spec.rb → my_obfuscate/sql_server_spec.rb} +0 -0
- data/spec/my_obfuscate_spec.rb +28 -6
- metadata +44 -13
@@ -0,0 +1,76 @@
|
|
1
|
+
class MyObfuscate
|
2
|
+
module DatabaseHelperShared
|
3
|
+
|
4
|
+
def rows_to_be_inserted(line)
|
5
|
+
line = line.gsub(insert_regex, '').gsub(/\s*;\s*$/, '')
|
6
|
+
context_aware_mysql_string_split(line)
|
7
|
+
end
|
8
|
+
|
9
|
+
def make_valid_value_string(value)
|
10
|
+
if value.nil?
|
11
|
+
"NULL"
|
12
|
+
elsif value =~ /^0x[0-9a-fA-F]+$/
|
13
|
+
value
|
14
|
+
else
|
15
|
+
"'" + value + "'"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Be aware, strings must be quoted in single quotes!
|
20
|
+
def context_aware_mysql_string_split(string)
|
21
|
+
in_sub_insert = false
|
22
|
+
in_quoted_string = false
|
23
|
+
escaped = false
|
24
|
+
current_field = nil
|
25
|
+
length = string.length
|
26
|
+
fields = []
|
27
|
+
output = []
|
28
|
+
|
29
|
+
string.each_char do |i|
|
30
|
+
if escaped
|
31
|
+
escaped = false
|
32
|
+
current_field ||= ""
|
33
|
+
current_field << i
|
34
|
+
else
|
35
|
+
if i == "\\"
|
36
|
+
escaped = true
|
37
|
+
current_field ||= ""
|
38
|
+
current_field << i
|
39
|
+
elsif i == "(" && !in_quoted_string && !in_sub_insert
|
40
|
+
in_sub_insert = true
|
41
|
+
elsif i == ")" && !in_quoted_string && in_sub_insert
|
42
|
+
fields << current_field unless current_field.nil?
|
43
|
+
output << fields unless fields.length == 0
|
44
|
+
in_sub_insert = false
|
45
|
+
fields = []
|
46
|
+
current_field = nil
|
47
|
+
elsif i == "'" && !in_quoted_string
|
48
|
+
fields << current_field unless current_field.nil?
|
49
|
+
current_field = ''
|
50
|
+
in_quoted_string = true
|
51
|
+
elsif i == "'" && in_quoted_string
|
52
|
+
fields << current_field unless current_field.nil?
|
53
|
+
current_field = nil
|
54
|
+
in_quoted_string = false
|
55
|
+
elsif i == "," && !in_quoted_string && in_sub_insert
|
56
|
+
fields << current_field unless current_field.nil?
|
57
|
+
current_field = nil
|
58
|
+
elsif i == "L" && !in_quoted_string && in_sub_insert && current_field == "NUL"
|
59
|
+
current_field = nil
|
60
|
+
fields << current_field
|
61
|
+
elsif (i == " " || i == "\t") && !in_quoted_string
|
62
|
+
# Don't add whitespace not in a string
|
63
|
+
elsif in_sub_insert
|
64
|
+
current_field ||= ""
|
65
|
+
current_field << i
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
fields << current_field unless current_field.nil?
|
71
|
+
output << fields unless fields.length == 0
|
72
|
+
output
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
data/lib/my_obfuscate/mysql.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
class MyObfuscate
|
2
2
|
class Mysql
|
3
|
-
|
3
|
+
include MyObfuscate::DatabaseHelperShared
|
4
4
|
|
5
5
|
def parse_insert_statement(line)
|
6
|
-
if regex_match =
|
6
|
+
if regex_match = insert_regex.match(line)
|
7
7
|
{
|
8
8
|
:table_name => regex_match[1].to_sym,
|
9
9
|
:column_names => regex_match[2].split(/`\s*,\s*`/).map { |col| col.gsub('`', "").to_sym }
|
@@ -11,81 +11,13 @@ class MyObfuscate
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def rows_to_be_inserted(line)
|
15
|
-
line = line.gsub(INSERT_REGEX, '').gsub(/\s*;\s*$/, '')
|
16
|
-
context_aware_mysql_string_split(line)
|
17
|
-
end
|
18
|
-
|
19
|
-
def make_valid_value_string(value)
|
20
|
-
if value.nil?
|
21
|
-
"NULL"
|
22
|
-
elsif value =~ /^0x[0-9a-fA-F]+$/
|
23
|
-
value
|
24
|
-
else
|
25
|
-
"'" + value + "'"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
14
|
def make_insert_statement(table_name, column_names, values_strings)
|
30
15
|
"INSERT INTO `#{table_name}` (`#{column_names.join('`, `')}`) VALUES #{values_strings};"
|
31
16
|
end
|
32
17
|
|
33
|
-
|
34
|
-
|
35
|
-
# Be aware, strings must be quoted in single quotes!
|
36
|
-
def context_aware_mysql_string_split(string)
|
37
|
-
in_sub_insert = false
|
38
|
-
in_quoted_string = false
|
39
|
-
escaped = false
|
40
|
-
current_field = nil
|
41
|
-
length = string.length
|
42
|
-
fields = []
|
43
|
-
output = []
|
44
|
-
|
45
|
-
string.each_char do |i|
|
46
|
-
if escaped
|
47
|
-
escaped = false
|
48
|
-
current_field ||= ""
|
49
|
-
current_field << i
|
50
|
-
else
|
51
|
-
if i == "\\"
|
52
|
-
escaped = true
|
53
|
-
current_field ||= ""
|
54
|
-
current_field << i
|
55
|
-
elsif i == "(" && !in_quoted_string && !in_sub_insert
|
56
|
-
in_sub_insert = true
|
57
|
-
elsif i == ")" && !in_quoted_string && in_sub_insert
|
58
|
-
fields << current_field unless current_field.nil?
|
59
|
-
output << fields unless fields.length == 0
|
60
|
-
in_sub_insert = false
|
61
|
-
fields = []
|
62
|
-
current_field = nil
|
63
|
-
elsif i == "'" && !in_quoted_string
|
64
|
-
fields << current_field unless current_field.nil?
|
65
|
-
current_field = ''
|
66
|
-
in_quoted_string = true
|
67
|
-
elsif i == "'" && in_quoted_string
|
68
|
-
fields << current_field unless current_field.nil?
|
69
|
-
current_field = nil
|
70
|
-
in_quoted_string = false
|
71
|
-
elsif i == "," && !in_quoted_string && in_sub_insert
|
72
|
-
fields << current_field unless current_field.nil?
|
73
|
-
current_field = nil
|
74
|
-
elsif i == "L" && !in_quoted_string && in_sub_insert && current_field == "NUL"
|
75
|
-
current_field = nil
|
76
|
-
fields << current_field
|
77
|
-
elsif (i == " " || i == "\t") && !in_quoted_string
|
78
|
-
# Don't add whitespace not in a string
|
79
|
-
elsif in_sub_insert
|
80
|
-
current_field ||= ""
|
81
|
-
current_field << i
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
fields << current_field unless current_field.nil?
|
87
|
-
output << fields unless fields.length == 0
|
88
|
-
output
|
18
|
+
def insert_regex
|
19
|
+
/^\s*INSERT INTO `(.*?)` \((.*?)\) VALUES\s*/i
|
89
20
|
end
|
21
|
+
|
90
22
|
end
|
91
23
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class MyObfuscate
|
2
|
+
class Postgres
|
3
|
+
include MyObfuscate::DatabaseHelperShared
|
4
|
+
|
5
|
+
def parse_insert_statement(line)
|
6
|
+
if regex_match = insert_regex.match(line)
|
7
|
+
{
|
8
|
+
:table_name => regex_match[1].to_sym,
|
9
|
+
:column_names => regex_match[2].split(/\s*,\s*/).map(&:to_sym)
|
10
|
+
}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def make_insert_statement(table_name, column_names, values_strings)
|
15
|
+
"INSERT INTO #{table_name} (#{column_names.join(', ')}) VALUES #{values_strings};"
|
16
|
+
end
|
17
|
+
|
18
|
+
def insert_regex
|
19
|
+
/^\s*INSERT INTO (.*?) \((.*?)\) VALUES\s*/i
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
class MyObfuscate
|
2
2
|
class SqlServer
|
3
|
-
INSERT_REGEX = /^\s*INSERT (?:INTO )?\[dbo\]\.\[(.*?)\] \((.*?)\) VALUES\s*/i
|
4
3
|
|
5
4
|
def parse_insert_statement(line)
|
6
|
-
if regex_match =
|
5
|
+
if regex_match = insert_regex.match(line)
|
7
6
|
{
|
8
7
|
:table_name => regex_match[1].to_sym,
|
9
8
|
:column_names => regex_match[2].split(/\]\s*,\s*\[/).map { |col| col.gsub(/[\[\]]/, "").to_sym }
|
@@ -12,7 +11,7 @@ class MyObfuscate
|
|
12
11
|
end
|
13
12
|
|
14
13
|
def rows_to_be_inserted(line)
|
15
|
-
line = line.gsub(
|
14
|
+
line = line.gsub(insert_regex, '').gsub(/\s*;?\s*$/, '').gsub(/^\(/, '').gsub(/\)$/, '')
|
16
15
|
context_aware_sql_server_string_split(line)
|
17
16
|
end
|
18
17
|
|
@@ -32,6 +31,10 @@ class MyObfuscate
|
|
32
31
|
|
33
32
|
private
|
34
33
|
|
34
|
+
def insert_regex
|
35
|
+
/^\s*INSERT (?:INTO )?\[dbo\]\.\[(.*?)\] \((.*?)\) VALUES\s*/i
|
36
|
+
end
|
37
|
+
|
35
38
|
def context_aware_sql_server_string_split(string)
|
36
39
|
in_quoted_string = false
|
37
40
|
backslash_escape = false
|
@@ -78,4 +81,4 @@ class MyObfuscate
|
|
78
81
|
[completed_fields]
|
79
82
|
end
|
80
83
|
end
|
81
|
-
end
|
84
|
+
end
|
data/lib/my_obfuscate/version.rb
CHANGED
data/lib/my_obfuscate.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'jcode' if RUBY_VERSION < '1.9'
|
2
|
-
require '
|
2
|
+
require 'digest/md5'
|
3
|
+
require 'ffaker'
|
4
|
+
require 'walker_method'
|
3
5
|
|
4
6
|
# Class for obfuscating MySQL dumps. This can parse mysqldump outputs when using the -c option, which includes
|
5
7
|
# column names in the insert statements.
|
@@ -24,6 +26,8 @@ class MyObfuscate
|
|
24
26
|
if @database_helper.nil?
|
25
27
|
if @database_type == :sql_server
|
26
28
|
@database_helper = SqlServer.new
|
29
|
+
elsif @database_type == :postgres
|
30
|
+
@database_helper = Postgres.new
|
27
31
|
else
|
28
32
|
@database_helper = Mysql.new
|
29
33
|
end
|
@@ -86,7 +90,7 @@ class MyObfuscate
|
|
86
90
|
|
87
91
|
table_config.each do |column, definition|
|
88
92
|
index = columns.index(column)
|
89
|
-
|
93
|
+
|
90
94
|
definition = { :type => definition } if definition.is_a?(Symbol)
|
91
95
|
|
92
96
|
if definition.has_key?(:unless)
|
@@ -108,11 +112,14 @@ class MyObfuscate
|
|
108
112
|
|
109
113
|
row[index.to_i] = case definition[:type]
|
110
114
|
when :email
|
111
|
-
|
115
|
+
md5 = Digest::MD5.hexdigest(rand.to_s)[0...5]
|
116
|
+
clean_quotes("#{Faker::Internet.email}.#{md5}.example.com")
|
112
117
|
when :string
|
113
118
|
random_string(definition[:length] || 30, definition[:chars] || SENSIBLE_CHARS)
|
114
119
|
when :lorem
|
115
120
|
clean_bad_whitespace(clean_quotes(Faker::Lorem.sentences(definition[:number] || 1).join(". ")))
|
121
|
+
when :like_english
|
122
|
+
clean_quotes random_english_sentences(definition[:number] || 1)
|
116
123
|
when :name
|
117
124
|
clean_quotes(Faker::Name.name)
|
118
125
|
when :first_name
|
@@ -120,25 +127,28 @@ class MyObfuscate
|
|
120
127
|
when :last_name
|
121
128
|
clean_quotes(Faker::Name.last_name)
|
122
129
|
when :address
|
123
|
-
clean_quotes("#{Faker::
|
130
|
+
clean_quotes("#{Faker::AddressUS.street_address}\\n#{Faker::AddressUS.city}, #{Faker::AddressUS.state_abbr} #{Faker::AddressUS.zip_code}")
|
124
131
|
when :street_address
|
125
|
-
clean_bad_whitespace(clean_quotes(Faker::
|
132
|
+
clean_bad_whitespace(clean_quotes(Faker::AddressUS.street_address))
|
126
133
|
when :city
|
127
|
-
clean_quotes(Faker::
|
134
|
+
clean_quotes(Faker::AddressUS.city)
|
128
135
|
when :state
|
129
|
-
Faker::
|
136
|
+
clean_quotes Faker::AddressUS.state_abbr
|
130
137
|
when :zip_code
|
131
|
-
Faker::
|
138
|
+
Faker::AddressUS.zip_code
|
132
139
|
when :phone
|
133
|
-
Faker::PhoneNumber.phone_number
|
140
|
+
clean_quotes Faker::PhoneNumber.phone_number
|
134
141
|
when :company
|
135
142
|
clean_bad_whitespace(clean_quotes(Faker::Company.name))
|
136
143
|
when :ipv4
|
137
144
|
Faker::Internet.ip_v4_address
|
138
145
|
when :ipv6
|
139
|
-
Faker
|
146
|
+
# Inlined from Faker because ffaker doesn't have ipv6.
|
147
|
+
@@ip_v6_space ||= (0..65535).to_a
|
148
|
+
container = (1..8).map{ |_| @@ip_v6_space.sample }
|
149
|
+
container.map{ |n| n.to_s(16) }.join(':')
|
140
150
|
when :url
|
141
|
-
clean_bad_whitespace(Faker::Internet.
|
151
|
+
clean_bad_whitespace(Faker::Internet.http_url)
|
142
152
|
when :integer
|
143
153
|
random_integer(definition[:between] || (0..1000)).to_s
|
144
154
|
when :fixed
|
@@ -171,6 +181,27 @@ class MyObfuscate
|
|
171
181
|
out
|
172
182
|
end
|
173
183
|
|
184
|
+
def self.random_english_sentences(num)
|
185
|
+
@@walker_method ||= begin
|
186
|
+
words, counts = [], []
|
187
|
+
File.read(File.expand_path(File.join(File.dirname(__FILE__), 'my_obfuscate', 'data', 'en_50K.txt'))).each_line do |line|
|
188
|
+
word, count = line.split(/\s+/)
|
189
|
+
words << word
|
190
|
+
counts << count.to_i
|
191
|
+
end
|
192
|
+
WalkerMethod.new(words, counts)
|
193
|
+
end
|
194
|
+
|
195
|
+
sentences = []
|
196
|
+
num.times do
|
197
|
+
words = []
|
198
|
+
(5 + rand * 6).to_i.times { words << @@walker_method.random }
|
199
|
+
sentences << words.join(" ") + "."
|
200
|
+
sentences.last[0] = sentences.last[0].upcase
|
201
|
+
end
|
202
|
+
sentences.join(" ")
|
203
|
+
end
|
204
|
+
|
174
205
|
def check_for_defined_columns_not_in_table(table_name, columns)
|
175
206
|
missing_columns = config[table_name].keys - columns
|
176
207
|
unless missing_columns.length == 0
|
@@ -206,17 +237,19 @@ class MyObfuscate
|
|
206
237
|
end
|
207
238
|
end
|
208
239
|
end
|
209
|
-
|
240
|
+
|
210
241
|
private
|
211
|
-
|
242
|
+
|
212
243
|
def self.clean_quotes(value)
|
213
244
|
value.gsub(/['"]/, '')
|
214
245
|
end
|
215
|
-
|
246
|
+
|
216
247
|
def self.clean_bad_whitespace(value)
|
217
248
|
value.gsub(/[\n\t\r]/, '')
|
218
249
|
end
|
219
250
|
end
|
220
251
|
|
252
|
+
require 'my_obfuscate/database_helper_shared'
|
221
253
|
require 'my_obfuscate/mysql'
|
222
254
|
require 'my_obfuscate/sql_server'
|
255
|
+
require 'my_obfuscate/postgres'
|
data/my_obfuscate.gemspec
CHANGED
@@ -8,12 +8,13 @@ Gem::Specification.new do |s|
|
|
8
8
|
|
9
9
|
s.authors = ["Andrew Cantino", "Dave Willett", "Mike Grafton", "Mason Glaves", "Greg Bell", "Mavenlink"]
|
10
10
|
s.description = %q{Standalone Ruby code for the selective rewriting of MySQL dumps in order to protect user privacy.}
|
11
|
-
s.email = %q{andrew@
|
12
|
-
s.homepage = %q{http://github.com/
|
11
|
+
s.email = %q{andrew@mavenlink.com}
|
12
|
+
s.homepage = %q{http://github.com/mavenlink/my_obfuscate}
|
13
13
|
s.summary = %q{Standalone Ruby code for the selective rewriting of MySQL dumps in order to protect user privacy.}
|
14
14
|
|
15
|
+
s.add_dependency "ffaker"
|
16
|
+
s.add_dependency "walker_method"
|
15
17
|
s.add_development_dependency "rspec"
|
16
|
-
s.add_dependency "faker", ">= 1.0.1"
|
17
18
|
|
18
19
|
s.files = `git ls-files`.split("\n")
|
19
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -1,20 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe MyObfuscate::Mysql do
|
4
|
-
describe "#parse_insert_statement" do
|
5
|
-
it "should return nil for other SQL syntaxes (MS SQL Server)" do
|
6
|
-
subject.parse_insert_statement("INSERT [dbo].[TASKS] ([TaskID], [TaskName]) VALUES (61, N'Report Thing')").should be_nil
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should return nil for MySQL non-insert statements" do
|
10
|
-
subject.parse_insert_statement("CREATE TABLE `some_table`;").should be_nil
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should return a hash of table name, column names for MySQL insert statements" do
|
14
|
-
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);")
|
15
|
-
hash.should == {:table_name => :some_table, :column_names => [:email, :name, :something, :age]}
|
16
|
-
end
|
17
|
-
end
|
1
|
+
shared_examples MyObfuscate::DatabaseHelperShared do
|
18
2
|
|
19
3
|
describe "#rows_to_be_inserted" do
|
20
4
|
it "should split a mysql string into fields" do
|
@@ -75,4 +59,5 @@ describe MyObfuscate::Mysql do
|
|
75
59
|
subject.make_valid_value_string(value).should == "'hello world'"
|
76
60
|
end
|
77
61
|
end
|
62
|
+
|
78
63
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'my_obfuscate/database_helper_shared_examples'
|
3
|
+
|
4
|
+
describe MyObfuscate::Mysql do
|
5
|
+
|
6
|
+
it_behaves_like MyObfuscate::DatabaseHelperShared
|
7
|
+
|
8
|
+
describe "#parse_insert_statement" do
|
9
|
+
it "should return nil for other SQL syntaxes (MS SQL Server)" do
|
10
|
+
subject.parse_insert_statement("INSERT [dbo].[TASKS] ([TaskID], [TaskName]) VALUES (61, N'Report Thing')").should be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return nil for MySQL non-insert statements" do
|
14
|
+
subject.parse_insert_statement("CREATE TABLE `some_table`;").should be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return a hash of table name, column names for MySQL insert statements" do
|
18
|
+
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);")
|
19
|
+
hash.should == {:table_name => :some_table, :column_names => [:email, :name, :something, :age]}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'my_obfuscate/database_helper_shared_examples'
|
3
|
+
|
4
|
+
describe MyObfuscate::Postgres do
|
5
|
+
|
6
|
+
it_behaves_like MyObfuscate::DatabaseHelperShared
|
7
|
+
|
8
|
+
describe "#parse_insert_statement" do
|
9
|
+
it "should return nil for other SQL syntaxes (MS SQL Server)" do
|
10
|
+
subject.parse_insert_statement("INSERT [dbo].[TASKS] ([TaskID], [TaskName]) VALUES (61, N'Report Thing')").should be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return nil for MySQL non-insert statements" do
|
14
|
+
subject.parse_insert_statement("CREATE TABLE `some_table`;").should be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return a hash of table name, column names for MySQL insert statements" do
|
18
|
+
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);")
|
19
|
+
hash.should == {:table_name => :some_table, :column_names => [:email, :name, :something, :age]}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
File without changes
|
data/spec/my_obfuscate_spec.rb
CHANGED
@@ -25,9 +25,11 @@ describe MyObfuscate do
|
|
25
25
|
|
26
26
|
describe "MyObfuscate.apply_table_config" do
|
27
27
|
it "should work on email addresses" do
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
100.times do
|
29
|
+
new_row = MyObfuscate.apply_table_config(["blah", "something_else"], {:a => {:type => :email}}, [:a, :b])
|
30
|
+
new_row.length.should == 2
|
31
|
+
new_row.first.should =~ /^[\w\.]+\@(\w+\.){2,3}[a-f0-9]{5}\.example\.com$/
|
32
|
+
end
|
31
33
|
end
|
32
34
|
|
33
35
|
it "should work on strings" do
|
@@ -248,7 +250,7 @@ describe MyObfuscate do
|
|
248
250
|
new_row[0].should_not == "blah"
|
249
251
|
new_row[0].should =~ /\d+/
|
250
252
|
end
|
251
|
-
|
253
|
+
|
252
254
|
describe "when faker generates values with quotes in them" do
|
253
255
|
before do
|
254
256
|
Faker::Address.stub(:city).and_return("O'ReillyTown")
|
@@ -257,7 +259,7 @@ describe MyObfuscate do
|
|
257
259
|
Faker::Name.stub(:last_name).and_return("O'Reilly")
|
258
260
|
Faker::Lorem.stub(:sentences).with(any_args).and_return(["Foo bar O'Thingy"])
|
259
261
|
end
|
260
|
-
|
262
|
+
|
261
263
|
it "should remove single quotes from the value" do
|
262
264
|
new_row = MyObfuscate.apply_table_config(["address", "city", "first", "last", "fullname", "some text"],
|
263
265
|
{:a => :address, :b => :city, :c => :first_name, :d => :last_name, :e => :name, :f => :lorem},
|
@@ -366,10 +368,11 @@ describe MyObfuscate do
|
|
366
368
|
@output_string.should_not 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);")
|
367
369
|
end
|
368
370
|
|
369
|
-
it "honors a special case: on the people table, rows with
|
371
|
+
it "honors a special case: on the people table, rows with skip_regexes that match are skipped" do
|
370
372
|
@output_string.should include("('bob@honk.com',")
|
371
373
|
@output_string.should include("('dontmurderme@direwolf.com',")
|
372
374
|
@output_string.should_not include("joe@joe.com")
|
375
|
+
@output_string.should include("example.com")
|
373
376
|
end
|
374
377
|
end
|
375
378
|
|
@@ -556,4 +559,23 @@ describe MyObfuscate do
|
|
556
559
|
end
|
557
560
|
end
|
558
561
|
end
|
562
|
+
|
563
|
+
describe "MyObfuscate.random_english_sentences" do
|
564
|
+
before do
|
565
|
+
File.should_receive(:read).once.and_return("hello 2")
|
566
|
+
end
|
567
|
+
|
568
|
+
after do
|
569
|
+
MyObfuscate.class_variable_set(:@@walker_method, nil)
|
570
|
+
end
|
571
|
+
|
572
|
+
it "should only load file data once" do
|
573
|
+
MyObfuscate.random_english_sentences(1)
|
574
|
+
MyObfuscate.random_english_sentences(1)
|
575
|
+
end
|
576
|
+
|
577
|
+
it "should make random sentences" do
|
578
|
+
MyObfuscate.random_english_sentences(2).should =~ /^(Hello( hello)+\.\s*){2}$/
|
579
|
+
end
|
580
|
+
end
|
559
581
|
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.
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,17 +14,17 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date:
|
17
|
+
date: 2013-04-19 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
|
-
name:
|
20
|
+
name: ffaker
|
21
21
|
requirement: !ruby/object:Gem::Requirement
|
22
22
|
none: false
|
23
23
|
requirements:
|
24
24
|
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
type: :
|
27
|
+
type: :runtime
|
28
28
|
prerelease: false
|
29
29
|
version_requirements: !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
@@ -33,13 +33,13 @@ dependencies:
|
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '0'
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
36
|
+
name: walker_method
|
37
37
|
requirement: !ruby/object:Gem::Requirement
|
38
38
|
none: false
|
39
39
|
requirements:
|
40
40
|
- - ! '>='
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
42
|
+
version: '0'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -47,29 +47,54 @@ dependencies:
|
|
47
47
|
requirements:
|
48
48
|
- - ! '>='
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version:
|
50
|
+
version: '0'
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: rspec
|
53
|
+
requirement: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
type: :development
|
60
|
+
prerelease: false
|
61
|
+
version_requirements: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
51
67
|
description: Standalone Ruby code for the selective rewriting of MySQL dumps in order
|
52
68
|
to protect user privacy.
|
53
|
-
email: andrew@
|
69
|
+
email: andrew@mavenlink.com
|
54
70
|
executables: []
|
55
71
|
extensions: []
|
56
72
|
extra_rdoc_files: []
|
57
73
|
files:
|
58
74
|
- .gitignore
|
75
|
+
- .ruby-gemset
|
76
|
+
- .ruby-version
|
77
|
+
- .travis.yml
|
78
|
+
- CHANGES
|
59
79
|
- Gemfile
|
60
80
|
- LICENSE
|
61
81
|
- README.rdoc
|
62
82
|
- Rakefile
|
63
83
|
- lib/my_obfuscate.rb
|
84
|
+
- lib/my_obfuscate/data/en_50K.txt
|
85
|
+
- lib/my_obfuscate/database_helper_shared.rb
|
64
86
|
- lib/my_obfuscate/mysql.rb
|
87
|
+
- lib/my_obfuscate/postgres.rb
|
65
88
|
- lib/my_obfuscate/sql_server.rb
|
66
89
|
- lib/my_obfuscate/version.rb
|
67
90
|
- my_obfuscate.gemspec
|
91
|
+
- spec/my_obfuscate/database_helper_shared_examples.rb
|
92
|
+
- spec/my_obfuscate/mysql_spec.rb
|
93
|
+
- spec/my_obfuscate/postgres_spec.rb
|
94
|
+
- spec/my_obfuscate/sql_server_spec.rb
|
68
95
|
- spec/my_obfuscate_spec.rb
|
69
|
-
- spec/mysql_spec.rb
|
70
96
|
- spec/spec_helper.rb
|
71
|
-
|
72
|
-
homepage: http://github.com/iterationlabs/my_obfuscate
|
97
|
+
homepage: http://github.com/mavenlink/my_obfuscate
|
73
98
|
licenses: []
|
74
99
|
post_install_message:
|
75
100
|
rdoc_options: []
|
@@ -89,9 +114,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
114
|
version: '0'
|
90
115
|
requirements: []
|
91
116
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.8.
|
117
|
+
rubygems_version: 1.8.25
|
93
118
|
signing_key:
|
94
119
|
specification_version: 3
|
95
120
|
summary: Standalone Ruby code for the selective rewriting of MySQL dumps in order
|
96
121
|
to protect user privacy.
|
97
|
-
test_files:
|
122
|
+
test_files:
|
123
|
+
- spec/my_obfuscate/database_helper_shared_examples.rb
|
124
|
+
- spec/my_obfuscate/mysql_spec.rb
|
125
|
+
- spec/my_obfuscate/postgres_spec.rb
|
126
|
+
- spec/my_obfuscate/sql_server_spec.rb
|
127
|
+
- spec/my_obfuscate_spec.rb
|
128
|
+
- spec/spec_helper.rb
|