Skip to content

Commit

Permalink
Support anonymizing https urls
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdev committed Aug 11, 2016
1 parent 4d73577 commit c2da104
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/strategy/field/string/random_url.rb
Expand Up @@ -13,7 +13,7 @@ def anonymize field

url = field.value
randomized_url = ""
protocols = url.scan(/http:\/\/|www\./)
protocols = url.scan(/https?:\/\/|www\./)
protocols.each do |token|
url = url.gsub(token,"")
randomized_url += token
Expand All @@ -33,4 +33,4 @@ def anonymize field
end
end
end
end
end
16 changes: 12 additions & 4 deletions spec/strategy/field/string/random_url_spec.rb
Expand Up @@ -5,11 +5,19 @@
RandomUrl = FieldStrategy::RandomUrl

describe 'anonymized url must not be the same as original url' do
let(:field) {DataAnon::Core::Field.new('string_field','http://fakeurl.com',1,nil)}
let(:url) { 'http://example.org' }

let(:field) {DataAnon::Core::Field.new('string_field',url,1,nil)}
let(:anonymized_url) {RandomUrl.new.anonymize(field)}

it {anonymized_url.should_not equal field.value}
it {anonymized_url.should match /https?:\/\/[\S]+/}
end
it {anonymized_url.should match /http:\/\/[\S]+/}

end
context 'with https url' do
let(:url) { 'https://example.org' }

it {anonymized_url.should_not equal field.value}
it {anonymized_url.should match /https:\/\/[\S]+/}
end
end
end

0 comments on commit c2da104

Please sign in to comment.