Skip to content

Commit

Permalink
Mask new PII info from API (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfrg authored Nov 14, 2023
1 parent 94b3b76 commit e47bb0e
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 1 deletion.
38 changes: 37 additions & 1 deletion lib/google/ads/google_ads/interceptors/logging_interceptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ class LoggingInterceptor < GRPC::ClientInterceptor
customer_user_access.email_address|
customer_user_access_invitation.email_address|
change_event.user_email|
feed.places_location_feed_data.email_address
feed.places_location_feed_data.email_address|
local_services_lead.contact_details.phone_number|
local_services_lead.contact_details.email|
local_services_lead.contact_details.consumer_name|
local_services_lead_conversation.message_details.text
/x

MASK_REPLACEMENT = "REDACTED"
Expand Down Expand Up @@ -244,11 +248,43 @@ def sanitize_message(message)
message["emailAddress"] = MASK_REPLACEMENT
end
message
elsif "LocalServicesLead" == message_class
# Sanitize sensitive fields when creating a LocalServiceLead.
message = clone_to_json(message)
sanitize_local_services_lead(message)
elsif "LocalServicesLeadConversation" == message_class
# Sanitize sensitive fields when creating a LocalServicesLeadConversation.
message = clone_to_json(message)
sanitize_local_services_lead_conversation(message)
else
message
end
end

def sanitize_local_services_lead_conversation(message)
if message.include?("messageDetails")
if message["messageDetails"].include?("text")
message["messageDetails"]["text"] = MASK_REPLACEMENT
end
end
message
end

def sanitize_local_services_lead(message)
if message.include?("contactDetails")
if message["contactDetails"].include?("email")
message["contactDetails"]["email"] = MASK_REPLACEMENT
end
if message["contactDetails"].include?("phoneNumber")
message["contactDetails"]["phoneNumber"] = MASK_REPLACEMENT
end
if message["contactDetails"].include?("consumerName")
message["contactDetails"]["consumerName"] = MASK_REPLACEMENT
end
end
message
end

def sanitize_customer_user_access(message)
if message.include?("emailAddress")
message["emailAddress"] = MASK_REPLACEMENT
Expand Down
84 changes: 84 additions & 0 deletions test/test_logging_interceptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,90 @@ def test_logging_interceptor_sanitizes_feed_get
assert_includes(data, "REDACTED")
end

def test_logging_interceptor_sanitizes_local_services_lead_contact_details_email
email_address = "abcdefghijkl"
li.request_response(
request: make_request,
call: make_fake_call,
method: :doesnt_matter
) do
Google::Ads::GoogleAds::V15::Resources::LocalServicesLead.new(
contact_details: Google::Ads::GoogleAds::V15::
Resources::ContactDetails.new(
email: email_address,
),
)
end

sio.rewind
data = sio.read
assert(!data.include?(email_address), "Failed to remove email address.")
assert_includes(data, "REDACTED")
end

def test_logging_interceptor_sanitizes_local_services_lead_contact_details_phone_number
phone_number = "abcdefghijkl"
li.request_response(
request: make_request,
call: make_fake_call,
method: :doesnt_matter
) do
Google::Ads::GoogleAds::V15::Resources::LocalServicesLead.new(
contact_details: Google::Ads::GoogleAds::V15::
Resources::ContactDetails.new(
phone_number: phone_number,
),
)
end

sio.rewind
data = sio.read
assert(!data.include?(phone_number), "Failed to remove phone number.")
assert_includes(data, "REDACTED")
end

def test_logging_interceptor_sanitizes_local_services_lead_contact_details_consumer_name
consumer_name = "abcdefghijkl"
li.request_response(
request: make_request,
call: make_fake_call,
method: :doesnt_matter
) do
Google::Ads::GoogleAds::V15::Resources::LocalServicesLead.new(
contact_details: Google::Ads::GoogleAds::V15::
Resources::ContactDetails.new(
consumer_name: consumer_name,
),
)
end

sio.rewind
data = sio.read
assert(!data.include?(consumer_name), "Failed to remove consumer name.")
assert_includes(data, "REDACTED")
end

def test_logging_interceptor_sanitizes_local_services_lead_conversation_text
text = "abcdefghijkl"
li.request_response(
request: make_request,
call: make_fake_call,
method: :doesnt_matter
) do
Google::Ads::GoogleAds::V15::Resources::LocalServicesLeadConversation.new(
message_details: Google::Ads::GoogleAds::V15::
Resources::MessageDetails.new(
text: text,
),
)
end

sio.rewind
data = sio.read
assert(!data.include?(text), "Failed to remove message_details text.")
assert_includes(data, "REDACTED")
end

def test_logging_interceptor_sanitizes_feed_mutate_request
email_address = "abcdefghijkl"
email_address_2 = "zyxwvutsr"
Expand Down

0 comments on commit e47bb0e

Please sign in to comment.