iterationlabs-my_obfuscate 0.3.4 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -6,3 +6,5 @@ pkg
6
6
  .idea
7
7
  .rvmrc
8
8
  Gemfile.lock
9
+ *.deb
10
+ *.gem
@@ -4,7 +4,7 @@ Standalone Ruby code for the selective rewriting of SQL dumps in order to protec
4
4
 
5
5
  = Install
6
6
 
7
- sudo gem install my_obfuscate
7
+ (sudo) gem install iterationlabs-my_obfuscate
8
8
 
9
9
  = Example Usage
10
10
 
@@ -53,7 +53,7 @@ And to get an obfuscated dump:
53
53
  mysqldump -c --add-drop-table -u user -ppassword database | ruby obfuscator.rb > obfuscated_dump.sql
54
54
 
55
55
  Note that the -c option on mysqldump is required to use my_obfuscator. If you get MySQL errors due to very long lines,
56
- try some combination of `--max_allowed_packet=128M`, `--single-transaction`, `--skip-extended-insert`, and `--quick`.
56
+ try some combination of --max_allowed_packet=128M, --single-transaction, --skip-extended-insert, and --quick.
57
57
 
58
58
  == Database Server
59
59
 
@@ -9,11 +9,11 @@ Gem::Specification.new do |s|
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
11
  s.email = %q{andrew@iterationlabs.com}
12
- s.homepage = %q{http://github.com/iterationlabs/myobfuscate}
12
+ s.homepage = %q{http://github.com/iterationlabs/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
15
  s.add_development_dependency "rspec"
16
- s.add_dependency "faker", "=0.9.5"
16
+ s.add_dependency "faker", ">= 1.0.1"
17
17
 
18
18
  s.files = `git ls-files`.split("\n")
19
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -1,7 +1,5 @@
1
1
  require 'jcode' if RUBY_VERSION < '1.9'
2
2
  require 'faker'
3
- require 'my_obfuscate/mysql'
4
- require 'my_obfuscate/sql_server'
5
3
 
6
4
  # Class for obfuscating MySQL dumps. This can parse mysqldump outputs when using the -c option, which includes
7
5
  # column names in the insert statements.
@@ -110,7 +108,7 @@ class MyObfuscate
110
108
 
111
109
  row[index.to_i] = case definition[:type]
112
110
  when :email
113
- random_string(definition[:length] || (4..10), USERNAME_CHARS) + "@example.com"
111
+ clean_quotes(Faker::Internet.email)
114
112
  when :string
115
113
  random_string(definition[:length] || 30, definition[:chars] || SENSIBLE_CHARS)
116
114
  when :lorem
@@ -133,6 +131,14 @@ class MyObfuscate
133
131
  Faker::Address.zip_code
134
132
  when :phone
135
133
  Faker::PhoneNumber.phone_number
134
+ when :company
135
+ clean_bad_whitespace(clean_quotes(Faker::Company.name))
136
+ when :ipv4
137
+ Faker::Internet.ip_v4_address
138
+ when :ipv6
139
+ Faker::Internet.ip_v6_address
140
+ when :url
141
+ clean_bad_whitespace(Faker::Internet.url)
136
142
  when :integer
137
143
  random_integer(definition[:between] || (0..1000)).to_s
138
144
  when :fixed
@@ -211,3 +217,6 @@ class MyObfuscate
211
217
  value.gsub(/[\n\t\r]/, '')
212
218
  end
213
219
  end
220
+
221
+ require 'my_obfuscate/mysql'
222
+ require 'my_obfuscate/sql_server'
@@ -19,6 +19,8 @@ class MyObfuscate
19
19
  def make_valid_value_string(value)
20
20
  if value.nil?
21
21
  "NULL"
22
+ elsif value =~ /^0x[0-9a-fA-F]+$/
23
+ value
22
24
  else
23
25
  "'" + value + "'"
24
26
  end
@@ -86,4 +88,4 @@ class MyObfuscate
86
88
  output
87
89
  end
88
90
  end
89
- end
91
+ end
@@ -1,3 +1,3 @@
1
1
  class MyObfuscate
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.6"
3
3
  end
@@ -27,7 +27,7 @@ describe MyObfuscate do
27
27
  it "should work on email addresses" do
28
28
  new_row = MyObfuscate.apply_table_config(["blah", "something_else"], {:a => {:type => :email}}, [:a, :b])
29
29
  new_row.length.should == 2
30
- new_row.first.should =~ /^\w+\@\w+\.\w+$/
30
+ new_row.first.should =~ /^[\w\.]+\@\w+\.\w+$/
31
31
  end
32
32
 
33
33
  it "should work on strings" do
@@ -174,6 +174,34 @@ describe MyObfuscate do
174
174
  new_row[1].should =~ /\w\.(?!\Z)/
175
175
  end
176
176
 
177
+ it "should be able to generate an :company" do
178
+ new_row = MyObfuscate.apply_table_config(["Smith and Sons", "something_else", "5"], {:a => :company}, [:a, :b, :c])
179
+ new_row.length.should == 3
180
+ new_row[0].should_not == "Smith and Sons"
181
+ new_row[0].should =~ /\w+/
182
+ end
183
+
184
+ it "should be able to generate an :url" do
185
+ new_row = MyObfuscate.apply_table_config(["http://mystuff.blogger.com", "something_else", "5"], {:a => :url}, [:a, :b, :c])
186
+ new_row.length.should == 3
187
+ new_row[0].should_not == "http://mystuff.blogger.com"
188
+ new_row[0].should =~ /http:\/\/\w+/
189
+ end
190
+
191
+ it "should be able to generate an :ipv4" do
192
+ new_row = MyObfuscate.apply_table_config(["1.2.3.4", "something_else", "5"], {:a => :ipv4}, [:a, :b, :c])
193
+ new_row.length.should == 3
194
+ new_row[0].should_not == "1.2.3.4"
195
+ new_row[0].should =~ /\d+\.\d+\.\d+\.\d+/
196
+ end
197
+
198
+ it "should be able to generate an :ipv6" do
199
+ new_row = MyObfuscate.apply_table_config(["fe80:0000:0000:0000:0202:b3ff:fe1e:8329", "something_else", "5"], {:a => :ipv6}, [:a, :b, :c])
200
+ new_row.length.should == 3
201
+ new_row[0].should_not == "fe80:0000:0000:0000:0202:b3ff:fe1e:8329"
202
+ new_row[0].should =~ /[0-9a-f:]+/
203
+ end
204
+
177
205
  it "should be able to generate an :address" do
178
206
  new_row = MyObfuscate.apply_table_config(["blah", "something_else", "5"], {:a => :address}, [:a, :b, :c])
179
207
  new_row.length.should == 3
@@ -528,4 +556,4 @@ describe MyObfuscate do
528
556
  end
529
557
  end
530
558
  end
531
- end
559
+ end
@@ -46,5 +46,33 @@ describe MyObfuscate::Mysql do
46
46
  fields = [[nil, '', '', '', '25', '2', '', "hi", '']]
47
47
  subject.rows_to_be_inserted(string).should == fields
48
48
  end
49
+
50
+ it "should work with hex encoded blobs" do
51
+ string = "INSERT INTO `some_table` (thing1,thing2) VALUES ('bla' , 'blobdata', 'blubb' , 0xACED00057372001F6A6176612E7574696C2E436F6C6C656) ;"
52
+ fields = [['bla', 'blobdata', 'blubb', '0xACED00057372001F6A6176612E7574696C2E436F6C6C656']]
53
+ subject.rows_to_be_inserted(string).should == fields
54
+ end
55
+ end
56
+
57
+ describe "#make_valid_value_string" do
58
+ it "should work with nil values" do
59
+ value = nil
60
+ subject.make_valid_value_string(value).should == 'NULL'
61
+ end
62
+
63
+ it "should work with hex-encoded blob data" do
64
+ value = "0xACED00057372001F6A6176612E7574696C2E436F6C6C656"
65
+ subject.make_valid_value_string(value).should == '0xACED00057372001F6A6176612E7574696C2E436F6C6C656'
66
+ end
67
+
68
+ it "should quote hex-encoded ALIKE data" do
69
+ value = "40x17x7"
70
+ subject.make_valid_value_string(value).should == "'40x17x7'"
71
+ end
72
+
73
+ it "should quote all other values" do
74
+ value = "hello world"
75
+ subject.make_valid_value_string(value).should == "'hello world'"
76
+ end
49
77
  end
50
- end
78
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iterationlabs-my_obfuscate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2012-04-10 00:00:00.000000000 Z
17
+ date: 2012-05-15 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: rspec
@@ -37,17 +37,17 @@ dependencies:
37
37
  requirement: !ruby/object:Gem::Requirement
38
38
  none: false
39
39
  requirements:
40
- - - '='
40
+ - - ! '>='
41
41
  - !ruby/object:Gem::Version
42
- version: 0.9.5
42
+ version: 1.0.1
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  none: false
47
47
  requirements:
48
- - - '='
48
+ - - ! '>='
49
49
  - !ruby/object:Gem::Version
50
- version: 0.9.5
50
+ version: 1.0.1
51
51
  description: Standalone Ruby code for the selective rewriting of MySQL dumps in order
52
52
  to protect user privacy.
53
53
  email: andrew@iterationlabs.com
@@ -69,7 +69,7 @@ files:
69
69
  - spec/mysql_spec.rb
70
70
  - spec/spec_helper.rb
71
71
  - spec/sql_server_spec.rb
72
- homepage: http://github.com/iterationlabs/myobfuscate
72
+ homepage: http://github.com/iterationlabs/my_obfuscate
73
73
  licenses: []
74
74
  post_install_message:
75
75
  rdoc_options: []
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  requirements: []
91
91
  rubyforge_project:
92
- rubygems_version: 1.8.21
92
+ rubygems_version: 1.8.24
93
93
  signing_key:
94
94
  specification_version: 3
95
95
  summary: Standalone Ruby code for the selective rewriting of MySQL dumps in order