data-anonymization 0.1.2 → 0.2.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.
- data/.documentup.json +1 -0
- data/.travis.yml +0 -1
- data/README.md +277 -52
- data/blacklist_dsl.rb +1 -3
- data/data-anonymization.gemspec +4 -0
- data/lib/core/dsl.rb +1 -1
- data/lib/data-anonymization.rb +3 -0
- data/lib/strategy/base.rb +21 -11
- data/lib/strategy/blacklist.rb +2 -1
- data/lib/strategy/field/contact/geojson_base.rb +24 -0
- data/lib/strategy/field/contact/random_address.rb +17 -0
- data/lib/strategy/field/contact/random_city.rb +17 -0
- data/lib/strategy/field/contact/random_phone_number.rb +13 -0
- data/lib/strategy/field/contact/random_province.rb +17 -0
- data/lib/strategy/field/contact/random_zipcode.rb +17 -0
- data/lib/strategy/field/datetime/anonymize_date.rb +39 -0
- data/lib/strategy/field/datetime/anonymize_datetime.rb +15 -0
- data/lib/strategy/field/datetime/anonymize_time.rb +58 -0
- data/lib/strategy/field/datetime/date_delta.rb +21 -0
- data/lib/strategy/field/{date_time_delta.rb → datetime/date_time_delta.rb} +3 -3
- data/lib/strategy/field/datetime/time_delta.rb +12 -0
- data/lib/strategy/field/default_anon.rb +12 -7
- data/lib/strategy/field/email/gmail_template.rb +16 -0
- data/lib/strategy/field/{random_email.rb → email/random_email.rb} +0 -0
- data/lib/strategy/field/{random_mailinator_email.rb → email/random_mailinator_email.rb} +0 -2
- data/lib/strategy/field/fields.rb +51 -20
- data/lib/strategy/field/name/random_first_name.rb +14 -0
- data/lib/strategy/field/{random_full_name.rb → name/random_full_name.rb} +0 -0
- data/lib/strategy/field/name/random_last_name.rb +14 -0
- data/lib/strategy/field/{random_user_name.rb → name/random_user_name.rb} +0 -0
- data/lib/strategy/field/number/random_float.rb +23 -0
- data/lib/strategy/field/{random_float_delta.rb → number/random_float_delta.rb} +2 -4
- data/lib/strategy/field/{random_int.rb → number/random_integer.rb} +1 -1
- data/lib/strategy/field/{random_integer_delta.rb → number/random_integer_delta.rb} +2 -5
- data/lib/strategy/field/{random_phone_number.rb → string/formatted_string_numbers.rb} +4 -1
- data/lib/strategy/field/{lorem_ipsum.rb → string/lorem_ipsum.rb} +0 -0
- data/lib/strategy/field/{random_string.rb → string/random_string.rb} +0 -0
- data/lib/strategy/field/{distinct_column_values.rb → string/select_from_database.rb} +2 -3
- data/lib/strategy/field/string/select_from_file.rb +18 -0
- data/lib/strategy/field/string/select_from_list.rb +17 -0
- data/lib/strategy/field/{string_template.rb → string/string_template.rb} +0 -0
- data/lib/strategy/whitelist.rb +4 -2
- data/lib/utils/database.rb +8 -6
- data/lib/utils/geojson_parser.rb +42 -0
- data/lib/utils/logging.rb +0 -9
- data/lib/utils/progress_bar.rb +29 -0
- data/lib/utils/random_float.rb +12 -0
- data/lib/utils/random_int.rb +3 -7
- data/lib/utils/resource.rb +4 -0
- data/lib/version.rb +1 -1
- data/resources/UK_addresses.geojson +300 -0
- data/resources/US_addresses.geojson +300 -0
- data/spec/acceptance/rdbms_blacklist_spec.rb +2 -2
- data/spec/acceptance/rdbms_whitelist_spec.rb +6 -8
- data/spec/resource/sample.geojson +1 -0
- data/spec/spec_helper.rb +3 -2
- data/spec/strategy/field/contact/random_address_spec.rb +12 -0
- data/spec/strategy/field/contact/random_city_spec.rb +14 -0
- data/spec/strategy/field/contact/random_phone_number_spec.rb +16 -0
- data/spec/strategy/field/contact/random_province_spec.rb +14 -0
- data/spec/strategy/field/contact/random_zipcode_spec.rb +14 -0
- data/spec/strategy/field/datetime/anonymize_date_spec.rb +27 -0
- data/spec/strategy/field/datetime/anonymize_datetime_spec.rb +57 -0
- data/spec/strategy/field/datetime/anonymize_time_spec.rb +57 -0
- data/spec/strategy/field/datetime/date_delta_spec.rb +36 -0
- data/spec/strategy/field/{date_time_delta_spec.rb → datetime/date_time_delta_spec.rb} +3 -2
- data/spec/strategy/field/datetime/time_delta_spec.rb +44 -0
- data/spec/strategy/field/default_anon_spec.rb +42 -0
- data/spec/strategy/field/email/gmail_template_spec.rb +17 -0
- data/spec/strategy/field/{random_email_spec.rb → email/random_email_spec.rb} +2 -2
- data/spec/strategy/field/email/random_mailinator_email_spec.rb +14 -0
- data/spec/strategy/field/{random_first_name_spec.rb → name/random_first_name_spec.rb} +2 -2
- data/spec/strategy/field/{random_full_name_spec.rb → name/random_full_name_spec.rb} +2 -2
- data/spec/strategy/field/{random_last_name_spec.rb → name/random_last_name_spec.rb} +2 -2
- data/spec/strategy/field/{random_user_name_spec.rb → name/random_user_name_spec.rb} +2 -2
- data/spec/strategy/field/{random_float_delta_spec.rb → number/random_float_delta_spec.rb} +2 -2
- data/spec/strategy/field/number/random_float_spec.rb +28 -0
- data/spec/strategy/field/{random_integer_delta_spec.rb → number/random_integer_delta_spec.rb} +3 -5
- data/spec/strategy/field/{random_int_spec.rb → number/random_integer_spec.rb} +4 -4
- data/spec/strategy/field/random_boolean_spec.rb +2 -2
- data/spec/strategy/field/string/formatted_string_numbers_spec.rb +15 -0
- data/spec/strategy/field/{lorem_ipsum_spec.rb → string/lorem_ipsum_spec.rb} +2 -2
- data/spec/strategy/field/{random_string_spec.rb → string/random_string_spec.rb} +2 -2
- data/spec/strategy/field/{distinct_column_values_spec.rb → string/select_from_database_spec.rb} +3 -3
- data/spec/strategy/field/{random_selection_spec.rb → string/select_from_list_spec.rb} +5 -5
- data/spec/strategy/field/{string_template_spec.rb → string/string_template_spec.rb} +2 -2
- data/spec/strategy/field/whitelist_spec.rb +2 -2
- data/spec/support/customer_sample.rb +1 -1
- data/spec/utils/database_spec.rb +2 -2
- data/spec/utils/geojson_parser_spec.rb +38 -0
- data/whitelist_dsl.rb +4 -6
- metadata +163 -59
- data/lib/strategy/field/anonymize_time.rb +0 -57
- data/lib/strategy/field/gmail_template.rb +0 -17
- data/lib/strategy/field/random_first_name.rb +0 -18
- data/lib/strategy/field/random_last_name.rb +0 -19
- data/lib/strategy/field/random_selection.rb +0 -23
- data/lib/strategy/field/user_name_template.rb +0 -22
- data/spec/strategy/field/anonymize_time_spec.rb +0 -23
- data/spec/strategy/field/gmail_template_spec.rb +0 -14
- data/spec/strategy/field/random_mailinator_email_spec.rb +0 -21
- data/spec/strategy/field/random_phone_number_spec.rb +0 -35
- data/spec/strategy/field/user_name_template_spec.rb +0 -13
@@ -17,12 +17,12 @@ describe "End 2 End RDBMS Blacklist Acceptance Test using SQLite database" do
|
|
17
17
|
|
18
18
|
table 'customers' do
|
19
19
|
primary_key 'cust_id'
|
20
|
-
anonymize('email').using
|
20
|
+
anonymize('email').using FieldStrategy::StringTemplate.new('test+#{row_number}@gmail.com')
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
DataAnon::Utils::SourceDatabase.establish_connection connection_spec
|
25
|
-
source = DataAnon::Utils::SourceTable.create 'customers', 'cust_id'
|
25
|
+
source = DataAnon::Utils::SourceTable.create 'customers', ['cust_id']
|
26
26
|
new_rec = source.find(CustomerSample::SAMPLE_DATA[:cust_id])
|
27
27
|
new_rec['email'].should == 'test+1@gmail.com'
|
28
28
|
|
@@ -15,8 +15,6 @@ describe "End 2 End RDBMS Whitelist Acceptance Test using SQLite database" do
|
|
15
15
|
|
16
16
|
it "should anonymize customer table record " do
|
17
17
|
|
18
|
-
DF = DataAnon::Strategy::Field
|
19
|
-
|
20
18
|
database "Customer" do
|
21
19
|
strategy DataAnon::Strategy::Whitelist
|
22
20
|
source_db source_connection_spec
|
@@ -25,16 +23,16 @@ describe "End 2 End RDBMS Whitelist Acceptance Test using SQLite database" do
|
|
25
23
|
table 'customers' do
|
26
24
|
primary_key 'cust_id'
|
27
25
|
whitelist 'cust_id', 'address', 'zipcode'
|
28
|
-
anonymize('first_name').using
|
29
|
-
anonymize('last_name').using
|
30
|
-
anonymize('state').using
|
31
|
-
anonymize('phone').using
|
32
|
-
anonymize('email').using
|
26
|
+
anonymize('first_name').using FieldStrategy::RandomFirstName.new
|
27
|
+
anonymize('last_name').using FieldStrategy::RandomLastName.new
|
28
|
+
anonymize('state').using FieldStrategy::SelectFromList.new(['Gujrat','Karnataka'])
|
29
|
+
anonymize('phone').using FieldStrategy::RandomPhoneNumber.new
|
30
|
+
anonymize('email').using FieldStrategy::StringTemplate.new('test+#{row_number}@gmail.com')
|
33
31
|
end
|
34
32
|
end
|
35
33
|
|
36
34
|
DataAnon::Utils::DestinationDatabase.establish_connection dest_connection_spec
|
37
|
-
dest_table = DataAnon::Utils::DestinationTable.create 'customers', 'cust_id'
|
35
|
+
dest_table = DataAnon::Utils::DestinationTable.create 'customers', ['cust_id']
|
38
36
|
new_rec = dest_table.find(CustomerSample::SAMPLE_DATA[:cust_id])
|
39
37
|
new_rec.first_name.should_not be("Sunit")
|
40
38
|
new_rec.last_name.should_not be("Parekh")
|
@@ -0,0 +1 @@
|
|
1
|
+
{"geometry": {"type": "Point", "coordinates": [-134.412039, 58.30057]}, "type": "Feature", "id": "SG_5xejzYOfDRcyoVHXqvO2hB_58.300570_-134.412039@1293731153", "properties": {"province": "AK", "city": "Juneau", "name": "Purchasing Dept", "tags": ["state"], "country": "US", "classifiers": [{"category": "Government", "type": "Public Place", "subcategory": "Office"}], "phone": "+1 907 465 2250", "href": "http://api.simplegeo.com/1.0/features/SG_5xejzYOfDRcyoVHXqvO2hB_58.300570_-134.412039@1293731153.json", "address": "333 Willoughby Ave", "owner": "simplegeo", "postcode": "99801"}}
|
data/spec/spec_helper.rb
CHANGED
@@ -2,11 +2,12 @@ require 'rspec'
|
|
2
2
|
require "pry"
|
3
3
|
require 'data-anonymization'
|
4
4
|
|
5
|
+
|
6
|
+
ENV['show_progress'] = 'false'
|
7
|
+
|
5
8
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
6
9
|
|
7
10
|
DataAnon::Utils::Logging.logger.level = Logger::INFO
|
8
|
-
DataAnon::Utils::Logging.progress_logger.level = Logger::WARN
|
9
|
-
|
10
11
|
|
11
12
|
RSpec.configure do |config|
|
12
13
|
config.expect_with :rspec
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DataAnon::Strategy::Field::RandomAddress do
|
4
|
+
|
5
|
+
RandomAddress = DataAnon::Strategy::Field::RandomAddress
|
6
|
+
let(:field) {DataAnon::Core::Field.new('address','1 Infinite Loop',1,nil)}
|
7
|
+
|
8
|
+
describe 'anonymized address should be different from original address' do
|
9
|
+
let(:anonymized_address) {RandomAddress.region_US.anonymize(field)}
|
10
|
+
it {anonymized_address.should_not eq("1 Infinite Loop")}
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DataAnon::Strategy::Field::RandomCity do
|
4
|
+
|
5
|
+
RandomCity = DataAnon::Strategy::Field::RandomCity
|
6
|
+
let(:field) { DataAnon::Core::Field.new('city', 'Atlanta', 1, nil) }
|
7
|
+
|
8
|
+
describe 'anonymized city should be different from original city' do
|
9
|
+
let(:anonymized_city) { RandomCity.region_US.anonymize(field) }
|
10
|
+
|
11
|
+
it { anonymized_city.should_not be_nil }
|
12
|
+
it { anonymized_city.should_not eq("Atlanta") }
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FieldStrategy::RandomPhoneNumber do
|
4
|
+
|
5
|
+
RandomPhoneNumber = FieldStrategy::RandomPhoneNumber
|
6
|
+
let(:field) { DataAnon::Core::Field.new('phone_number', "+0 (123) 456-7890", 1, nil) }
|
7
|
+
|
8
|
+
describe 'anonymized phone number preserving the format' do
|
9
|
+
let(:anonymized_number) { RandomPhoneNumber.new().anonymize(field) }
|
10
|
+
|
11
|
+
it { anonymized_number.should_not equal field.value }
|
12
|
+
it { anonymized_number.should match /\+\d\ \(\d{3}\)\ \d{3}-\d{4}$/ }
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DataAnon::Strategy::Field::RandomProvince do
|
4
|
+
|
5
|
+
RandomProvince = DataAnon::Strategy::Field::RandomProvince
|
6
|
+
let(:field) { DataAnon::Core::Field.new('province', 'Atlanta', 1, nil) }
|
7
|
+
|
8
|
+
describe 'anonymized province should be different from original province' do
|
9
|
+
let(:anonymized_province) { RandomProvince.region_US.anonymize(field) }
|
10
|
+
|
11
|
+
it { anonymized_province.should_not be_nil }
|
12
|
+
it { anonymized_province.should_not eq("Atlanta") }
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DataAnon::Strategy::Field::RandomZipcode do
|
4
|
+
|
5
|
+
RandomZipcode = DataAnon::Strategy::Field::RandomZipcode
|
6
|
+
let(:field) { DataAnon::Core::Field.new('zipcode', '12345', 1, nil) }
|
7
|
+
|
8
|
+
describe 'anonymized zipcode should be different from original zipcode' do
|
9
|
+
let(:anonymized_zipcode) { RandomZipcode.region_US.anonymize(field) }
|
10
|
+
|
11
|
+
it { anonymized_zipcode.should_not be_nil }
|
12
|
+
it { anonymized_zipcode.should_not eq("12345") }
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FieldStrategy::AnonymizeDate do
|
4
|
+
|
5
|
+
AnonymizeDate = FieldStrategy::AnonymizeDate
|
6
|
+
let(:field) { DataAnon::Core::Field.new('date', Date.new(2011,7,5), 1, nil) }
|
7
|
+
|
8
|
+
describe 'providing true only for month should randomize only the month field' do
|
9
|
+
|
10
|
+
let(:anonymized_time) { AnonymizeDate.only_month.anonymize(field) }
|
11
|
+
|
12
|
+
it { anonymized_time.should be_kind_of Date}
|
13
|
+
it { anonymized_time.year.should be 2011 }
|
14
|
+
it { anonymized_time.month.should be_between(1,12)}
|
15
|
+
it { anonymized_time.day.should be 5 }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'providing true only for date should randomize only the date field' do
|
19
|
+
|
20
|
+
let(:anonymized_time) { AnonymizeDate.only_day.anonymize(field) }
|
21
|
+
|
22
|
+
it { anonymized_time.year.should be 2011 }
|
23
|
+
it { anonymized_time.month.should be 7}
|
24
|
+
it { anonymized_time.day.should be_between(1,31) }
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FieldStrategy::AnonymizeDateTime do
|
4
|
+
|
5
|
+
AnonymizeDateTime = FieldStrategy::AnonymizeDateTime
|
6
|
+
let(:field) { DataAnon::Core::Field.new('date', DateTime.new(2000,1,1,12,12,12), 1, nil) }
|
7
|
+
|
8
|
+
describe 'providing true only for month should randomize only the month field' do
|
9
|
+
|
10
|
+
let(:anonymized_time) { AnonymizeDateTime.only_month.anonymize(field) }
|
11
|
+
|
12
|
+
it { anonymized_time.should be_kind_of DateTime}
|
13
|
+
it { anonymized_time.year.should be 2000 }
|
14
|
+
it { anonymized_time.month.should be_between(1,12)}
|
15
|
+
it { anonymized_time.day.should be 1 }
|
16
|
+
it { anonymized_time.hour.should be 12}
|
17
|
+
it { anonymized_time.min.should be 12}
|
18
|
+
it { anonymized_time.sec.should be 12}
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'providing true only for date should randomize only the date field' do
|
22
|
+
|
23
|
+
let(:anonymized_time) { AnonymizeDateTime.only_day.anonymize(field) }
|
24
|
+
|
25
|
+
it { anonymized_time.year.should be 2000 }
|
26
|
+
it { anonymized_time.month.should be 1}
|
27
|
+
it { anonymized_time.day.should be_between(1,31) }
|
28
|
+
it { anonymized_time.hour.should be 12}
|
29
|
+
it { anonymized_time.min.should be 12}
|
30
|
+
it { anonymized_time.sec.should be 12}
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'providing true only for hour should randomize only the hour field' do
|
34
|
+
|
35
|
+
let(:anonymized_time) { AnonymizeDateTime.only_hour.anonymize(field) }
|
36
|
+
|
37
|
+
it { anonymized_time.year.should be 2000 }
|
38
|
+
it { anonymized_time.month.should be 1}
|
39
|
+
it { anonymized_time.day.should be 1 }
|
40
|
+
it { anonymized_time.hour.should be_between(1,24)}
|
41
|
+
it { anonymized_time.min.should be 12}
|
42
|
+
it { anonymized_time.sec.should be 12}
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'providing true only for minute should randomize only the minute field' do
|
46
|
+
|
47
|
+
let(:anonymized_time) { AnonymizeDateTime.only_minute.anonymize(field) }
|
48
|
+
|
49
|
+
it { anonymized_time.year.should be 2000 }
|
50
|
+
it { anonymized_time.month.should be 1}
|
51
|
+
it { anonymized_time.day.should be 1 }
|
52
|
+
it { anonymized_time.hour.should be 12}
|
53
|
+
it { anonymized_time.min.should be_between(1,60)}
|
54
|
+
it { anonymized_time.sec.should be 12}
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FieldStrategy::AnonymizeTime do
|
4
|
+
|
5
|
+
AnonymizeTime = FieldStrategy::AnonymizeTime
|
6
|
+
let(:field) { DataAnon::Core::Field.new('date', Time.new(2000,1,1,12,12,12), 1, nil) }
|
7
|
+
|
8
|
+
describe 'providing true only for month should randomize only the month field' do
|
9
|
+
|
10
|
+
let(:anonymized_time) { AnonymizeTime.only_month.anonymize(field) }
|
11
|
+
|
12
|
+
it { anonymized_time.should be_kind_of Time}
|
13
|
+
it { anonymized_time.year.should be 2000 }
|
14
|
+
it { anonymized_time.month.should be_between(1,12)}
|
15
|
+
it { anonymized_time.day.should be 1 }
|
16
|
+
it { anonymized_time.hour.should be 12}
|
17
|
+
it { anonymized_time.min.should be 12}
|
18
|
+
it { anonymized_time.sec.should be 12}
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'providing true only for date should randomize only the date field' do
|
22
|
+
|
23
|
+
let(:anonymized_time) { AnonymizeTime.only_day.anonymize(field) }
|
24
|
+
|
25
|
+
it { anonymized_time.year.should be 2000 }
|
26
|
+
it { anonymized_time.month.should be 1}
|
27
|
+
it { anonymized_time.day.should be_between(1,31) }
|
28
|
+
it { anonymized_time.hour.should be 12}
|
29
|
+
it { anonymized_time.min.should be 12}
|
30
|
+
it { anonymized_time.sec.should be 12}
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'providing true only for hour should randomize only the hour field' do
|
34
|
+
|
35
|
+
let(:anonymized_time) { AnonymizeTime.only_hour.anonymize(field) }
|
36
|
+
|
37
|
+
it { anonymized_time.year.should be 2000 }
|
38
|
+
it { anonymized_time.month.should be 1}
|
39
|
+
it { anonymized_time.day.should be 1 }
|
40
|
+
it { anonymized_time.hour.should be_between(1,24)}
|
41
|
+
it { anonymized_time.min.should be 12}
|
42
|
+
it { anonymized_time.sec.should be 12}
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'providing true only for minute should randomize only the minute field' do
|
46
|
+
|
47
|
+
let(:anonymized_time) { AnonymizeTime.only_minute.anonymize(field) }
|
48
|
+
|
49
|
+
it { anonymized_time.year.should be 2000 }
|
50
|
+
it { anonymized_time.month.should be 1}
|
51
|
+
it { anonymized_time.day.should be 1 }
|
52
|
+
it { anonymized_time.hour.should be 12}
|
53
|
+
it { anonymized_time.min.should be_between(1,60)}
|
54
|
+
it { anonymized_time.sec.should be 12}
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FieldStrategy::DateDelta do
|
4
|
+
|
5
|
+
DateDelta = FieldStrategy::DateDelta
|
6
|
+
let(:field) { DataAnon::Core::Field.new('date', Date.new(2011,4,7), 1, nil) }
|
7
|
+
|
8
|
+
describe 'date should not remain the same' do
|
9
|
+
|
10
|
+
let(:anonymized_value) { DateDelta.new().anonymize(field) }
|
11
|
+
let(:date_difference) {anonymized_value - field.value}
|
12
|
+
|
13
|
+
it { anonymized_value.should be_kind_of Date}
|
14
|
+
it { anonymized_value.should_not == Date.new(2011,4,7) }
|
15
|
+
it { date_difference.should be_between(-5.days, 5.days) }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'date should not change when provided with 0 delta for both date and time' do
|
19
|
+
|
20
|
+
let(:anonymized_date) { DateDelta.new(0).anonymize(field) }
|
21
|
+
|
22
|
+
it {anonymized_date.should == Date.new(2011,4,7) }
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'date should be anonymized within provided delta' do
|
27
|
+
|
28
|
+
let(:anonymized_value) { DateDelta.new(5).anonymize(field) }
|
29
|
+
let(:date_difference) {anonymized_value - field.value}
|
30
|
+
|
31
|
+
it { date_difference.should be_between(-5.days, 5.days) }
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe FieldStrategy::DateTimeDelta do
|
4
4
|
|
5
|
-
DateTimeDelta =
|
5
|
+
DateTimeDelta = FieldStrategy::DateTimeDelta
|
6
6
|
let(:field) { DataAnon::Core::Field.new('date', DateTime.new(2000,1,1), 1, nil) }
|
7
7
|
|
8
8
|
describe 'datetime should not remain the same' do
|
@@ -10,6 +10,7 @@ describe DataAnon::Strategy::Field::DateTimeDelta do
|
|
10
10
|
let(:anonymized_value) { DateTimeDelta.new().anonymize(field) }
|
11
11
|
let(:date_difference) {anonymized_value.to_i - field.value.to_i}
|
12
12
|
|
13
|
+
it { anonymized_value.should be_kind_of DateTime}
|
13
14
|
it {date_difference.should_not be 0 }
|
14
15
|
end
|
15
16
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FieldStrategy::TimeDelta do
|
4
|
+
|
5
|
+
TimeDelta = FieldStrategy::TimeDelta
|
6
|
+
let(:field) { DataAnon::Core::Field.new('date', Time.new(2012,10,10,13,20,10), 1, nil) }
|
7
|
+
|
8
|
+
describe 'time should not remain the same' do
|
9
|
+
|
10
|
+
let(:anonymized_value) { TimeDelta.new().anonymize(field) }
|
11
|
+
let(:date_difference) {anonymized_value.to_i - field.value.to_i}
|
12
|
+
|
13
|
+
it { anonymized_value.should be_kind_of Time}
|
14
|
+
it {date_difference.should_not be 0 }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'time should not change when provided with 0 delta for both date and time' do
|
18
|
+
|
19
|
+
let(:anonymized_value) { TimeDelta.new(0,0).anonymize(field) }
|
20
|
+
let(:date_difference) {anonymized_value.to_i - field.value.to_i}
|
21
|
+
|
22
|
+
it {date_difference.should be 0 }
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'date should be anonymized within provided delta' do
|
27
|
+
|
28
|
+
let(:anonymized_value) { TimeDelta.new(5,0).anonymize(field) }
|
29
|
+
let(:date_difference) {anonymized_value.to_i - field.value.to_i}
|
30
|
+
|
31
|
+
it { date_difference.should be_between(-5.days, 5.days) }
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'time should be anonymized within provided delta' do
|
36
|
+
|
37
|
+
let(:anonymized_value) { TimeDelta.new(0,10).anonymize(field) }
|
38
|
+
let(:date_difference) {anonymized_value.to_i - field.value.to_i}
|
39
|
+
|
40
|
+
it { date_difference.should be_between(-10.minutes, 10.minutes)}
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FieldStrategy::DefaultAnon do
|
4
|
+
|
5
|
+
DefaultAnon = FieldStrategy::DefaultAnon
|
6
|
+
|
7
|
+
describe 'anonymized boolean true value' do
|
8
|
+
let(:field) {DataAnon::Core::Field.new('boolean_field',true,1,nil)}
|
9
|
+
let(:anonymized_value) {DefaultAnon.new.anonymize(field)}
|
10
|
+
|
11
|
+
it { [TrueClass,FalseClass].should include(anonymized_value.class) }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'anonymized boolean false value' do
|
15
|
+
let(:field) {DataAnon::Core::Field.new('boolean_field',false,1,nil)}
|
16
|
+
let(:anonymized_value) {DefaultAnon.new.anonymize(field)}
|
17
|
+
|
18
|
+
it { [TrueClass,FalseClass].should include(anonymized_value.class) }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'anonymized float value' do
|
22
|
+
let(:field) {DataAnon::Core::Field.new('float_field',2.0,1,nil)}
|
23
|
+
let(:anonymized_value) {DefaultAnon.new.anonymize(field)}
|
24
|
+
|
25
|
+
it { anonymized_value.should be_kind_of Float }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'anonymized int value' do
|
29
|
+
let(:field) {DataAnon::Core::Field.new('int_field',2,1,nil)}
|
30
|
+
let(:anonymized_value) {DefaultAnon.new.anonymize(field)}
|
31
|
+
|
32
|
+
it { anonymized_value.should be_kind_of Fixnum }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'anonymized string value' do
|
36
|
+
let(:field) {DataAnon::Core::Field.new('string_field','String',1,nil)}
|
37
|
+
let(:anonymized_value) {DefaultAnon.new.anonymize(field)}
|
38
|
+
|
39
|
+
it { anonymized_value.should be_kind_of String }
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FieldStrategy::GmailTemplate do
|
4
|
+
|
5
|
+
GmailTemplate = FieldStrategy::GmailTemplate
|
6
|
+
let(:field) { DataAnon::Core::Field.new('email', 'user@company.com', 456, nil) }
|
7
|
+
|
8
|
+
describe 'generated email using default username' do
|
9
|
+
let(:anonymized_email) { GmailTemplate.new.anonymize(field) }
|
10
|
+
it { anonymized_email.should eq('someusername+456@gmail.com') }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'generated email using given username' do
|
14
|
+
let(:anonymized_email) { GmailTemplate.new("fake").anonymize(field) }
|
15
|
+
it { anonymized_email.should eq('fake+456@gmail.com') }
|
16
|
+
end
|
17
|
+
end
|