def test_blacklistgenerate_hash(self): # The generate_hash function implementation should not change; We risk contacting people on the blacklist for (id_type, id_value) in self.Inputs: got = blacklist.generate_hash(id_type, id_value) expected = "{id_type}$sha256${hash}".format( id_type=id_type, hash=sha256(id_value).hexdigest()) self.assertEqual(got, expected)
def test_blacklist_api_query_is_in_blacklist_false(self): id_type, id_value = self.Inputs[1] responses.add( responses.GET, 'http://example.com?id='+blacklist.generate_hash(id_type, id_value), body="{\"msg\": \"no\"}", status=404 ) in_blacklist = blacklist.api_query_is_in_blacklist(id_type, id_value) self.assertFalse(in_blacklist)
def __init__(self, badge_instance): self.recipient_id_hash = \ generate_hash(badge_instance.recipient_type, badge_instance.recipient_identifier) self.entity_id = badge_instance.badgeclass.entity_id
def _generate_blacklist_response_body(identifier, id_type='email'): return [{"id": generate_hash(id_type, identifier)}]
def _generate_blacklist_url(identifier, id_type='email'): hashed_identifier = generate_hash(id_type, identifier) return "{endpoint}?id={recipient_id_hash}".format( endpoint=SETTINGS_OVERRIDE['BADGR_BLACKLIST_QUERY_ENDPOINT'], recipient_id_hash=hashed_identifier)