Exemplo n.º 1
0
 def test_generate_hcard_raises_on_unknown_attribute(self):
     with pytest.raises(ValueError):
         generate_hcard("diaspora",
                        hostname="hostname",
                        fullname="fullname",
                        firstname="firstname",
                        unknown="unknown")
Exemplo n.º 2
0
 def test_generate_hcard_raises_on_missing_attribute(self):
     with pytest.raises(AssertionError):
         generate_hcard(
             "diaspora",
             hostname="hostname",
             fullname="fullname",
             firstname="firstname"
         )
Exemplo n.º 3
0
 def test_generate_hcard_raises_on_unknown_attribute(self):
     with pytest.raises(ValueError):
         generate_hcard(
             "diaspora",
             hostname="hostname",
             fullname="fullname",
             firstname="firstname",
             username="******"
         )
Exemplo n.º 4
0
 def test_profile_is_parsed(self):
     hcard = generate_hcard(
         "diaspora",
         hostname="https://example.com",
         fullname="fullname",
         firstname="firstname",
         lastname="lastname",
         photo300="photo300",
         photo100="photo100",
         photo50="photo50",
         searchable="true",
         guid="guidguidguidguid",
         public_key="public_key",
         username="******",
     )
     profile = parse_profile_from_hcard(hcard, "*****@*****.**")
     assert profile.name == "fullname"
     assert profile.image_urls == {
         "small": "photo50", "medium": "photo100", "large": "photo300"
     }
     assert profile.public == True
     assert profile.handle == "*****@*****.**"
     assert profile.guid == "guidguidguidguid"
     assert profile.public_key == "public_key\n"
     profile.validate()
Exemplo n.º 5
0
 def test_profile_is_parsed(self):
     hcard = generate_hcard(
         "diaspora",
         hostname="https://example.com",
         fullname="fullname",
         firstname="firstname",
         lastname="lastname",
         photo300="photo300",
         photo100="photo100",
         photo50="photo50",
         searchable="true",
         guid="guidguidguidguid",
         public_key="public_key",
         username="******",
     )
     profile = parse_profile_from_hcard(hcard, "*****@*****.**")
     assert profile.name == "fullname"
     assert profile.image_urls == {
         "small": "photo50", "medium": "photo100", "large": "photo300"
     }
     assert profile.public == True
     assert profile.handle == "*****@*****.**"
     assert profile.guid == "guidguidguidguid"
     assert profile.public_key == "public_key\n"
     profile.validate()
Exemplo n.º 6
0
def hcard(guid):
    if guid != app.config.get("RELAY_GUID"):
        return abort(404)
    hcard = generate_hcard("diaspora",
                           hostname=app.config.get("SERVER_HOST"),
                           fullname=app.config.get("RELAY_NAME"),
                           firstname=app.config.get("RELAY_NAME"),
                           lastname="",
                           photo300="",
                           photo100="",
                           photo50="",
                           searchable="false")
    return Response(hcard, status=200)
Exemplo n.º 7
0
 def test_generate_valid_hcard(self):
     with open("federation/hostmeta/templates/hcard_diaspora.html") as f:
         template = f.read().replace("$", "")
     hcard = generate_hcard(
         "diaspora",
         hostname="hostname",
         fullname="fullname",
         firstname="firstname",
         lastname="lastname",
         photo300="photo300",
         photo100="photo100",
         photo50="photo50",
         searchable="searchable"
     )
     assert hcard == template
Exemplo n.º 8
0
def hcard(guid):
    if guid != app.config.get("RELAY_GUID"):
        return abort(404)
    hcard = generate_hcard(
        "diaspora",
        hostname=app.config.get("SERVER_HOST"),
        fullname=app.config.get("RELAY_NAME"),
        firstname=app.config.get("RELAY_NAME"),
        lastname="",
        photo300="",
        photo100="",
        photo50="",
        searchable="false"
    )
    return Response(hcard, status=200)
Exemplo n.º 9
0
 def test_parse_profile_from_hcard_called(self, mock_retrieve, mock_parse):
     hcard = generate_hcard(
         "diaspora",
         hostname="https://hostname",
         fullname="fullname",
         firstname="firstname",
         lastname="lastname",
         photo300="photo300",
         photo100="photo100",
         photo50="photo50",
         searchable="true",
         guid="guid",
         public_key="public_key",
         username="******",
     )
     mock_retrieve.return_value = hcard
     retrieve_and_parse_profile("foo@bar")
     mock_parse.assert_called_with(hcard, "foo@bar")
Exemplo n.º 10
0
 def test_generate_valid_hcard(self):
     with open("federation/hostmeta/templates/hcard_diaspora.html") as f:
         template = f.read().replace("$", "")
     hcard = generate_hcard(
         "diaspora",
         hostname="hostname",
         fullname="fullname",
         firstname="firstname",
         lastname="lastname",
         photo300="photo300",
         photo100="photo100",
         photo50="photo50",
         searchable="searchable",
         guid="guid",
         public_key="public_key",
         username="******",
     )
     assert hcard == template
Exemplo n.º 11
0
 def test_parse_profile_from_hcard_called(self, mock_retrieve, mock_parse):
     hcard = generate_hcard(
         "diaspora",
         hostname="https://hostname",
         fullname="fullname",
         firstname="firstname",
         lastname="lastname",
         photo300="photo300",
         photo100="photo100",
         photo50="photo50",
         searchable="true",
         guid="guid",
         public_key="public_key",
         username="******",
     )
     mock_retrieve.return_value = hcard
     retrieve_and_parse_profile("foo@bar")
     mock_parse.assert_called_with(hcard, "foo@bar")
Exemplo n.º 12
0
 def test_profile_that_doesnt_validate_returns_none(self, mock_retrieve, mock_parse):
     hcard = generate_hcard(
         "diaspora",
         hostname="https://hostname",
         fullname="fullname",
         firstname="firstname",
         lastname="lastname",
         photo300="photo300",
         photo100="photo100",
         photo50="photo50",
         searchable="true",
         guid="guid",
         public_key="public_key",
         username="******",
     )
     mock_retrieve.return_value = hcard
     mock_parse.return_value = Profile(guid="123")
     profile = retrieve_and_parse_profile("foo@bar")
     assert profile == None
Exemplo n.º 13
0
 def test_profile_that_doesnt_validate_returns_none(self, mock_retrieve, mock_parse):
     hcard = generate_hcard(
         "diaspora",
         hostname="https://hostname",
         fullname="fullname",
         firstname="firstname",
         lastname="lastname",
         photo300="photo300",
         photo100="photo100",
         photo50="photo50",
         searchable="true",
         guid="guid",
         public_key="public_key",
         username="******",
     )
     mock_retrieve.return_value = hcard
     mock_parse.return_value = Profile(guid="123")
     profile = retrieve_and_parse_profile("foo@bar")
     assert profile == None
Exemplo n.º 14
0
 def test_profile_validate_is_called(self, mock_retrieve, mock_parse):
     hcard = generate_hcard(
         "diaspora",
         hostname="https://hostname",
         fullname="fullname",
         firstname="firstname",
         lastname="lastname",
         photo300="photo300",
         photo100="photo100",
         photo50="photo50",
         searchable="true",
         guid="guid",
         public_key="public_key",
         username="******",
     )
     mock_retrieve.return_value = hcard
     mock_profile = Mock()
     mock_parse.return_value = mock_profile
     retrieve_and_parse_profile("foo@bar")
     assert mock_profile.validate.called
Exemplo n.º 15
0
 def test_profile_validate_is_called(self, mock_retrieve, mock_parse):
     hcard = generate_hcard(
         "diaspora",
         hostname="https://hostname",
         fullname="fullname",
         firstname="firstname",
         lastname="lastname",
         photo300="photo300",
         photo100="photo100",
         photo50="photo50",
         searchable="true",
         guid="guid",
         public_key="public_key",
         username="******",
     )
     mock_retrieve.return_value = hcard
     mock_profile = Mock()
     mock_parse.return_value = mock_profile
     retrieve_and_parse_profile("foo@bar")
     assert mock_profile.validate.called
Exemplo n.º 16
0
def hcard_view(request, guid):
    """Generate a hcard document.

    For local users only.
    """
    try:
        profile = get_object_or_404(Profile, guid=guid, user__isnull=False)
    except ValueError:
        raise Http404()
    hcard = generate_hcard(
        "diaspora",
        hostname=settings.SOCIALHOME_URL,
        fullname=profile.name,
        firstname=profile.get_first_name(),
        lastname=profile.get_last_name(),
        photo300=profile.safer_image_url_large,
        photo100=profile.safer_image_url_medium,
        photo50=profile.safer_image_url_small,
        searchable="true" if profile.public else "false",
        guid=profile.guid,
        username=profile.user.username,
        public_key=profile.rsa_public_key,
    )
    return HttpResponse(hcard)
Exemplo n.º 17
0
 def test_generate_hcard_raises_on_missing_attribute(self):
     with pytest.raises(AssertionError):
         generate_hcard("diaspora",
                        hostname="hostname",
                        fullname="fullname",
                        firstname="firstname")