diff --git a/lib/google/ads/google_ads/interceptors/logging_interceptor.rb b/lib/google/ads/google_ads/interceptors/logging_interceptor.rb index b9dd10869..24f0f1ef6 100644 --- a/lib/google/ads/google_ads/interceptors/logging_interceptor.rb +++ b/lib/google/ads/google_ads/interceptors/logging_interceptor.rb @@ -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" @@ -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 diff --git a/test/test_logging_interceptor.rb b/test/test_logging_interceptor.rb index 91943da0b..710e74474 100644 --- a/test/test_logging_interceptor.rb +++ b/test/test_logging_interceptor.rb @@ -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"