def test_mask_message_fields_unset_field(self): """Field is not masked if it is not set.""" message = customer_user_access.CustomerUserAccess() copy = interceptor_module._mask_message_fields( ["email_address"], message, "REDACTED" ) self.assertFalse("email_address" in copy)
def test_mask_message_fields_bad_nested_field_name(self): """No error is raised if a nested field is not defined.""" message = customer_user_access.CustomerUserAccess() copy = interceptor_module._mask_message_fields( ["bad_name.another_bad.yet_another"], message, "REDACTED") self.assertFalse("email_address" in copy) self.assertFalse("inviter_user_email_address" in copy)
def test_mask_message_fields(self): """Returns a copy of the message with named fields masked.""" message = customer_user_access.CustomerUserAccess() message.email_address = "*****@*****.**" message.inviter_user_email_address = "*****@*****.**" copy = interceptor_module._mask_message_fields( ["email_address", "inviter_user_email_address"], message, "REDACTED" ) self.assertIsInstance(copy, message.__class__) self.assertIsNot(message, copy) self.assertEqual(copy.email_address, "REDACTED") self.assertEqual(copy.inviter_user_email_address, "REDACTED")
def test_mask_message_fields_unset_nested(self): """Nested field is not masked if it is not set.""" message = customer_user_access_service.MutateCustomerUserAccessRequest() copy = interceptor_module._mask_message_fields( [ "operation.update.email_address", "operation.update.inviter_user_email_address", ], message, "REDACTED", ) self.assertFalse("email_address" in copy.operation.update) self.assertFalse("inviter_user_email_address" in copy.operation.update)
def test_mask_message_fields_nested(self): """Masks nested fields on an object.""" message = customer_user_access_service.MutateCustomerUserAccessRequest( operation=customer_user_access_service.CustomerUserAccessOperation( update=customer_user_access.CustomerUserAccess( email_address="*****@*****.**", inviter_user_email_address="*****@*****.**", ))) copy = interceptor_module._mask_message_fields( [ "operation.update.email_address", "operation.update.inviter_user_email_address", ], message, "REDACTED", ) self.assertIsInstance(copy, message.__class__) self.assertIsNot(message, copy) self.assertEqual(copy.operation.update.email_address, "REDACTED") self.assertEqual(copy.operation.update.inviter_user_email_address, "REDACTED")