changes to address comments made to merge request #167

jsonld-processing
Alain St-Denis 2022-06-05 14:43:42 +00:00
rodzic 3236f667d4
commit 97db29ab73
6 zmienionych plików z 12 dodań i 10 usunięć

Wyświetl plik

@ -17,6 +17,10 @@
* Signatures are not verified and the corresponding payload is dropped is no public key is found. * Signatures are not verified and the corresponding payload is dropped is no public key is found.
### Internal changes
* Dropped python 3.6 support.
## [0.22.0] - 2021-08-15 ## [0.22.0] - 2021-08-15
### Added ### Added

Wyświetl plik

@ -29,7 +29,6 @@ def disable_network_calls(monkeypatch):
return saved_get(*args, **kwargs) return saved_get(*args, **kwargs)
return DEFAULT return DEFAULT
#monkeypatch.setattr("requests.get", Mock(return_value=MockResponse))
monkeypatch.setattr("requests.get", Mock(return_value=MockResponse, side_effect=side_effect)) monkeypatch.setattr("requests.get", Mock(return_value=MockResponse, side_effect=side_effect))

Wyświetl plik

@ -166,8 +166,6 @@ class TestEntitiesConvertToAS2:
def test_post_to_as2__with_mentions(self, activitypubpost_mentions): def test_post_to_as2__with_mentions(self, activitypubpost_mentions):
activitypubpost_mentions.pre_send() activitypubpost_mentions.pre_send()
result = activitypubpost_mentions.to_as2() result = activitypubpost_mentions.to_as2()
with open('/tmp/test.out','w') as f:
pprint(result, stream=f)
assert result == { assert result == {
'@context': [ '@context': [
'https://www.w3.org/ns/activitystreams', 'https://www.w3.org/ns/activitystreams',

Wyświetl plik

@ -41,12 +41,13 @@ class TestGetProfileIdFromWebfinger:
class TestRetrieveAndParseDocument: class TestRetrieveAndParseDocument:
@pytest.mark.skip
@patch("federation.utils.activitypub.fetch_document", autospec=True, return_value=(None, None, None)) @patch("federation.utils.activitypub.fetch_document", autospec=True, return_value=(None, None, None))
def test_calls_fetch_document(self, mock_fetch): def test_calls_fetch_document(self, mock_fetch):
retrieve_and_parse_document("https://example.com/foobar") retrieve_and_parse_document("https://example.com/foobar")
# auth argument is passed with kwargs
auth = mock_fetch.call_args.kwargs.get('auth', None)
mock_fetch.assert_called_once_with( mock_fetch.assert_called_once_with(
"https://example.com/foobar", extra_headers={'accept': 'application/activity+json'}, "https://example.com/foobar", extra_headers={'accept': 'application/activity+json'}, auth=auth,
) )
@patch("federation.utils.activitypub.fetch_document", autospec=True, return_value=( @patch("federation.utils.activitypub.fetch_document", autospec=True, return_value=(

Wyświetl plik

@ -11,10 +11,10 @@ from federation.utils.text import decode_if_bytes, validate_handle
logger = logging.getLogger('federation') logger = logging.getLogger('federation')
try: try:
from federation.utils.django import get_admin_user from federation.utils.django import get_federation_user
admin_user = get_admin_user() federation_user = get_federation_user()
except (ImportError, AttributeError): except (ImportError, AttributeError):
admin_user = None federation_user = None
logger.warning("django is required for requests signing") logger.warning("django is required for requests signing")
def get_profile_id_from_webfinger(handle: str) -> Optional[str]: def get_profile_id_from_webfinger(handle: str) -> Optional[str]:
@ -45,7 +45,7 @@ def retrieve_and_parse_document(fid: str) -> Optional[Any]:
""" """
document, status_code, ex = fetch_document(fid, document, status_code, ex = fetch_document(fid,
extra_headers={'accept': 'application/activity+json'}, extra_headers={'accept': 'application/activity+json'},
auth=get_http_authentication(admin_user.rsa_private_key,f'{admin_user.id}#main-key') if admin_user else None) auth=get_http_authentication(federation_user.rsa_private_key,f'{federation_user.id}#main-key') if federation_user else None)
if document: if document:
document = json.loads(decode_if_bytes(document)) document = json.loads(decode_if_bytes(document))
entities = message_to_objects(document, fid) entities = message_to_objects(document, fid)

Wyświetl plik

@ -45,7 +45,7 @@ def get_function_from_config(item):
func = getattr(module, func_name) func = getattr(module, func_name)
return func return func
def get_admin_user(): def get_federation_user():
config = get_configuration() config = get_configuration()
if not config.get('federation_id'): return None if not config.get('federation_id'): return None