Exemplo n.º 1
0
def test_retrieve_ap_object_honor_instance_policy_domain(factories):
    domain = factories["moderation.InstancePolicy"](
        block_all=True, for_domain=True
    ).target_domain
    fid = "https://{}/test".format(domain.name)

    with pytest.raises(exceptions.BlockedActorOrDomain):
        utils.retrieve_ap_object(fid, actor=None)
Exemplo n.º 2
0
def test_retrieve_ap_object_honor_mrf_inbox_before_http(
    mrf_inbox_registry, factories, mocker
):
    apply = mocker.patch.object(mrf_inbox_registry, "apply", return_value=(None, False))
    fid = "http://domain/test"
    with pytest.raises(exceptions.BlockedActorOrDomain):
        utils.retrieve_ap_object(fid, actor=None)

    apply.assert_called_once_with({"id": fid})
Exemplo n.º 3
0
def test_retrieve_ap_object_honor_instance_policy_different_url_and_id(
    r_mock, factories
):
    domain = factories["moderation.InstancePolicy"](
        block_all=True, for_domain=True
    ).target_domain
    fid = "https://ok/test"
    r_mock.get(fid, json={"id": "http://{}/test".format(domain.name)})

    with pytest.raises(exceptions.BlockedActorOrDomain):
        utils.retrieve_ap_object(fid, actor=None)
Exemplo n.º 4
0
def test_retrieve_ap_object_honor_mrf_inbox_after_http(
    r_mock, mrf_inbox_registry, factories, mocker
):
    apply = mocker.patch.object(
        mrf_inbox_registry, "apply", side_effect=[(True, False), (None, False)]
    )
    payload = {"id": "http://domain/test", "actor": "hello"}
    r_mock.get(payload["id"], json=payload)
    with pytest.raises(exceptions.BlockedActorOrDomain):
        utils.retrieve_ap_object(payload["id"], actor=None)

    apply.assert_any_call({"id": payload["id"]})
    apply.assert_any_call(payload)
Exemplo n.º 5
0
def test_retrieve_ap_object(db, r_mock):
    fid = "https://some.url"
    m = r_mock.get(fid, json={"hello": "world"})
    result = utils.retrieve_ap_object(fid, actor=None)

    assert result == {"hello": "world"}
    assert m.request_history[-1].headers["Accept"] == "application/activity+json"
Exemplo n.º 6
0
def test_retrieve_with_actor(r_mock, factories):
    actor = factories["federation.Actor"]()
    fid = "https://some.url"
    m = r_mock.get(fid, json={"hello": "world"})
    result = utils.retrieve_ap_object(fid, actor=actor)

    assert result == {"hello": "world"}
    assert m.request_history[-1].headers["Accept"] == "application/activity+json"
    assert m.request_history[-1].headers["Signature"] is not None
Exemplo n.º 7
0
def test_retrieve_with_serializer(db, r_mock):
    class S(serializers.Serializer):
        def create(self, validated_data):
            return {"persisted": "object"}

    fid = "https://some.url"
    r_mock.get(fid, json={"hello": "world"})
    result = utils.retrieve_ap_object(fid, actor=None, serializer_class=S)

    assert result == {"persisted": "object"}
Exemplo n.º 8
0
def test_retrieve_with_queryset(factories):
    actor = factories["federation.Actor"]()

    assert utils.retrieve_ap_object(actor.fid, actor=None, queryset=actor.__class__)