From c2da104af5a2ab88e3ffc9b19104b040aeae24f6 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Thu, 11 Aug 2016 15:09:39 +0200 Subject: [PATCH] Support anonymizing https urls --- lib/strategy/field/string/random_url.rb | 4 ++-- spec/strategy/field/string/random_url_spec.rb | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/strategy/field/string/random_url.rb b/lib/strategy/field/string/random_url.rb index 64655a8..e5e35bc 100644 --- a/lib/strategy/field/string/random_url.rb +++ b/lib/strategy/field/string/random_url.rb @@ -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 @@ -33,4 +33,4 @@ def anonymize field end end end -end \ No newline at end of file +end diff --git a/spec/strategy/field/string/random_url_spec.rb b/spec/strategy/field/string/random_url_spec.rb index 913c4ca..a73b7c5 100644 --- a/spec/strategy/field/string/random_url_spec.rb +++ b/spec/strategy/field/string/random_url_spec.rb @@ -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 \ No newline at end of file + 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