my_obfuscate 0.3.0 → 0.3.7
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/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.rdoc +49 -14
- data/Rakefile +4 -56
- data/lib/my_obfuscate.rb +117 -82
- data/lib/my_obfuscate/mysql.rb +91 -0
- data/lib/my_obfuscate/sql_server.rb +81 -0
- data/lib/my_obfuscate/version.rb +3 -0
- data/my_obfuscate.gemspec +12 -44
- data/spec/my_obfuscate_spec.rb +442 -129
- data/spec/mysql_spec.rb +78 -0
- data/spec/spec_helper.rb +5 -5
- data/spec/sql_server_spec.rb +58 -0
- metadata +70 -51
- data/.document +0 -5
- data/VERSION +0 -1
data/spec/mysql_spec.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
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
|
18
|
+
|
19
|
+
describe "#rows_to_be_inserted" do
|
20
|
+
it "should split a mysql string into fields" do
|
21
|
+
string = "INSERT INTO `some_table` (thing1,thing2) VALUES ('bob@bob.com','bob', 'somethingelse1', 25, '2', 10, 'hi') ; "
|
22
|
+
fields = [['bob@bob.com', 'bob', 'somethingelse1', '25', '2', '10', "hi"]]
|
23
|
+
subject.rows_to_be_inserted(string).should == fields
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should work ok with escaped characters" do
|
27
|
+
string = "INSERT INTO `some_table` (thing1,thing2) VALUES ('bob,@bob.c , om', 'bo\\', b', 'some\"thin\\gel\\\\\\'se1', 25, '2', 10, 'hi', 5) ; "
|
28
|
+
fields = [['bob,@bob.c , om', 'bo\\\', b', 'some"thin\\gel\\\\\\\'se1', '25', '2', '10', "hi", "5"]]
|
29
|
+
subject.rows_to_be_inserted(string).should == fields
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should work with multiple subinserts" do
|
33
|
+
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) ;"
|
34
|
+
fields = [["1", "2", "3", "((m))(oo()s,e"], ['bob,@bob.c , om', 'bo\\\', b', 'some"thin\\gel\\\\\\\'se1', '25', '2', '10', "hi", "5"]]
|
35
|
+
subject.rows_to_be_inserted(string).should == fields
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should work ok with NULL values" do
|
39
|
+
string = "INSERT INTO `some_table` (thing1,thing2) VALUES (NULL , 'bob@bob.com','bob', NULL, 25, '2', NULL, 'hi', NULL ); "
|
40
|
+
fields = [[nil, 'bob@bob.com', 'bob', nil, '25', '2', nil, "hi", nil]]
|
41
|
+
subject.rows_to_be_inserted(string).should == fields
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should work with empty strings" do
|
45
|
+
string = "INSERT INTO `some_table` (thing1,thing2) VALUES (NULL , '', '' , '', 25, '2','', 'hi','') ;"
|
46
|
+
fields = [[nil, '', '', '', '25', '2', '', "hi", '']]
|
47
|
+
subject.rows_to_be_inserted(string).should == fields
|
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
|
77
|
+
end
|
78
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.require(:default, :development)
|
1
4
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
5
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
-
require 'rubygems'
|
4
6
|
require 'my_obfuscate'
|
5
|
-
require 'spec'
|
6
|
-
require 'spec/autorun'
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
RSpec.configure do |config|
|
9
|
+
# config.mock_with :rr
|
10
10
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MyObfuscate::SqlServer do
|
4
|
+
describe "#parse_insert_statement" do
|
5
|
+
it "should return a hash of table_name, column_names for SQL Server input statements" do
|
6
|
+
hash = subject.parse_insert_statement("INSERT [dbo].[TASKS] ([TaskID], [TaskName]) VALUES (61, N'Report Thing')")
|
7
|
+
hash.should == { :table_name => :TASKS, :column_names => [:TaskID, :TaskName] }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return nil for SQL Server non-insert statements" do
|
11
|
+
subject.parse_insert_statement("CREATE TABLE [dbo].[WORKFLOW](").should be_nil
|
12
|
+
end
|
13
|
+
|
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);").should be_nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#rows_to_be_inserted" do
|
20
|
+
it "should split a SQL Server string into fields" do
|
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
|
+
fields = [['bob@bob.com', 'bob', 'somethingelse1', '25', '2', '10', "hi", "CAST(0x00009E1A00000000 AS DATETIME)"]]
|
23
|
+
subject.rows_to_be_inserted(string).should == fields
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should work ok with single quote escape" do
|
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
|
+
fields = [['bob,@bob.c , om', "bo'', b", "some\"thingel''se1", '25', '2', '10', "hi", "5"]]
|
29
|
+
subject.rows_to_be_inserted(string).should == fields
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should work ok with NULL values" do
|
33
|
+
string = "INSERT [dbo].[some_table] ([thing1],[thing2]) VALUES (NULL , N'bob@bob.com','bob', NULL, 25, N'2', NULL, 'hi', NULL ); "
|
34
|
+
fields = [[nil, 'bob@bob.com', 'bob', nil, '25', '2', nil, "hi", nil]]
|
35
|
+
subject.rows_to_be_inserted(string).should == fields
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should work with empty strings" do
|
39
|
+
string = "INSERT [dbo].[some_table] ([thing1],[thing2]) VALUES (NULL , N'', '' , '', 25, '2','', N'hi','') ;"
|
40
|
+
fields = [[nil, '', '','', '25', '2', '', "hi", '']]
|
41
|
+
subject.rows_to_be_inserted(string).should == fields
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#make_valid_value_string" do
|
46
|
+
it "should output 'NULL' when the value is nil" do
|
47
|
+
subject.make_valid_value_string(nil).should == "NULL"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should enclose the value in quotes if it's a string" do
|
51
|
+
subject.make_valid_value_string("something").should == "N'something'"
|
52
|
+
end
|
53
|
+
|
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)").should == "CAST(0x00009E1A00000000 AS DATETIME)"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,78 +1,97 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: my_obfuscate
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.7
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
|
-
authors:
|
7
|
+
authors:
|
7
8
|
- Andrew Cantino
|
8
9
|
- Dave Willett
|
9
10
|
- Mike Grafton
|
10
11
|
- Mason Glaves
|
12
|
+
- Greg Bell
|
13
|
+
- Mavenlink
|
11
14
|
autorequire:
|
12
15
|
bindir: bin
|
13
16
|
cert_chain: []
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
dependencies:
|
18
|
-
- !ruby/object:Gem::Dependency
|
17
|
+
date: 2012-07-27 00:00:00.000000000 Z
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
19
20
|
name: rspec
|
21
|
+
requirement: !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
20
27
|
type: :development
|
21
|
-
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
prerelease: false
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: faker
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.0.1
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 1.0.1
|
51
|
+
description: Standalone Ruby code for the selective rewriting of MySQL dumps in order
|
52
|
+
to protect user privacy.
|
53
|
+
email: andrew@iterationlabs.com
|
30
54
|
executables: []
|
31
|
-
|
32
55
|
extensions: []
|
33
|
-
|
34
|
-
|
35
|
-
- LICENSE
|
36
|
-
- README.rdoc
|
37
|
-
files:
|
38
|
-
- .document
|
56
|
+
extra_rdoc_files: []
|
57
|
+
files:
|
39
58
|
- .gitignore
|
59
|
+
- Gemfile
|
40
60
|
- LICENSE
|
41
61
|
- README.rdoc
|
42
62
|
- Rakefile
|
43
|
-
- VERSION
|
44
63
|
- lib/my_obfuscate.rb
|
64
|
+
- lib/my_obfuscate/mysql.rb
|
65
|
+
- lib/my_obfuscate/sql_server.rb
|
66
|
+
- lib/my_obfuscate/version.rb
|
45
67
|
- my_obfuscate.gemspec
|
46
68
|
- spec/my_obfuscate_spec.rb
|
69
|
+
- spec/mysql_spec.rb
|
47
70
|
- spec/spec_helper.rb
|
48
|
-
|
49
|
-
homepage: http://github.com/
|
71
|
+
- spec/sql_server_spec.rb
|
72
|
+
homepage: http://github.com/iterationlabs/my_obfuscate
|
50
73
|
licenses: []
|
51
|
-
|
52
74
|
post_install_message:
|
53
|
-
rdoc_options:
|
54
|
-
|
55
|
-
require_paths:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
56
77
|
- lib
|
57
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
69
90
|
requirements: []
|
70
|
-
|
71
|
-
|
72
|
-
rubygems_version: 1.3.5
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.8.19
|
73
93
|
signing_key:
|
74
94
|
specification_version: 3
|
75
|
-
summary: Standalone Ruby code for the selective rewriting of MySQL dumps in order
|
76
|
-
|
77
|
-
|
78
|
-
- spec/spec_helper.rb
|
95
|
+
summary: Standalone Ruby code for the selective rewriting of MySQL dumps in order
|
96
|
+
to protect user privacy.
|
97
|
+
test_files: []
|
data/.document
DELETED
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.3.0
|