From 582dbe5c8dceafdbcb266aeb43279456818e773a Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 17 Oct 2018 19:15:20 +0000 Subject: [PATCH 1/2] formatter: fix matching osada users --- lib/pleroma/formatter.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 5b63fb795..21b08a62e 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -248,7 +248,12 @@ defmodule Pleroma.Formatter do subs = subs ++ Enum.map(mentions, fn {match, %User{ap_id: ap_id, info: info}, uuid} -> - ap_id = info["source_data"]["url"] || ap_id + ap_id = + if is_binary(info["source_data"]["url"]) do + info["source_data"]["url"] + else + ap_id + end short_match = String.split(match, "@") |> tl() |> hd() From 958c5e02e8ba37a5412c46f944e0e8458b125ee8 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 17 Oct 2018 19:27:05 +0000 Subject: [PATCH 2/2] tests: add a testcase for matching osada users in the formatter --- .../https___osada.macgirvin.com_channel_mike.json | 54 ++++++++++++++++++++++ .../httpoison_mock/mike@osada.macgirvin.com.json | 53 +++++++++++++++++++++ test/formatter_test.exs | 19 ++++++++ test/support/httpoison_mock.ex | 21 +++++++++ 4 files changed, 147 insertions(+) create mode 100644 test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json create mode 100644 test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json diff --git a/test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json b/test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json new file mode 100644 index 000000000..c42f3a53c --- /dev/null +++ b/test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json @@ -0,0 +1,54 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1" + ], + "type": "Person", + "id": "https://osada.macgirvin.com/channel/mike", + "preferredUsername": "mike", + "name": "Mike Macgirvin (Osada)", + "updated": "2018-08-29T03:09:11Z", + "icon": { + "type": "Image", + "mediaType": "image/jpeg", + "updated": "2018-08-29T03:10:13Z", + "url": "https://osada.macgirvin.com/photo/profile/l/2", + "height": 300, + "width": 300 + }, + "url": [ + { + "type": "Link", + "mediaType": "text/html", + "href": "https://osada.macgirvin.com/channel/mike" + }, + { + "type": "Link", + "mediaType": "text/x-zot+json", + "href": "https://osada.macgirvin.com/channel/mike" + } + ], + "inbox": "https://osada.macgirvin.com/inbox/mike", + "outbox": "https://osada.macgirvin.com/outbox/mike", + "followers": "https://osada.macgirvin.com/followers/mike", + "following": "https://osada.macgirvin.com/following/mike", + "endpoints": { + "sharedInbox": "https://osada.macgirvin.com/inbox" + }, + "publicKey": { + "id": "https://osada.macgirvin.com/channel/mike/public_key_pem", + "owner": "https://osada.macgirvin.com/channel/mike", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAskSyK2VwBNKbzZl9XNJk\nvxU5AAilmRArMmmKSzphdHaVBHakeafUfixvqNrQ/oX2srJvJKcghNmEMrJ6MJ7r\npeEndVOo7pcP4PwVjtnC06p3J711q5tBehqM25BfCLCrB2YqWF6c8zk3CPN3Na21\n8k5s4cO95N/rGN+Po0XFAX/HjKjlpgNpKRDrpxmXxTU8NZfAqeQGJ5oiMBZI9vVB\n+eU7t1L6F5/XWuUCeP4OMrG8oZX822AREba8rknS6DpkWGES0Rx2eNOyYTf6ue75\nI6Ek6rlO+da5wMWr+3BvYMq4JMIwTHzAO+ZqqJPFpzKSiVuAWb2DOX/MDFecVWJE\ntF/R60lONxe4e/00MPCoDdqkLKdwROsk1yGL7z4Zk6jOWFEhIcWy/d2Ya5CpPvS3\nu4wNN4jkYAjra+8TiloRELhV4gpcEk8nkyNwLXOhYm7zQ5sIc5rfXoIrFzALB86W\nG05Nnqg+77zZIaTZpD9qekYlaEt+0OVtt9TTIeTiudQ983l6mfKwZYymrzymH1dL\nVgxBRYo+Z53QOSLiSKELfTBZxEoP1pBw6RiOHXydmJ/39hGgc2YAY/5ADwW2F2yb\nJ7+gxG6bPJ3ikDLYcD4CB5iJQdnTcDsFt3jyHAT6wOCzFAYPbHUqtzHfUM30dZBn\nnJhQF8udPLcXLaj6GW75JacCAwEAAQ==\n-----END PUBLIC KEY-----\n" + }, + "signature": { + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1" + ], + "type": "RsaSignature2017", + "nonce": "bd60167a764a936788d9538531284dfacc258daae0297bc34a83bce136dedb5d", + "creator": "https://osada.macgirvin.com/channel/mike/public_key_pem", + "created": "2018-10-17T07:16:28Z", + "signatureValue": "WbfFVIPImkd3yNu6brz0CvZaeV242rwAbH0vy8DM4vfnXCxLr5Uv/Wj9gwP+tbooTxGaahAKBeqlGkQp8RLEo37LATrKMRLA/0V6DeeV+C5ORWR9B4WxyWiD3s/9Wf+KesFMtktNLAcMZ5PfnOS/xNYerhnpkp/gWPxtkglmLIWJv+w18A5zZ01JCxsO4QljHbhYaEUPHUfQ97abrkLECeam+FThVwdO6BFCtbjoNXHfzjpSZL/oKyBpi5/fpnqMqOLOQPs5WgBBZJvjEYYkQcoPTyxYI5NGpNbzIjGHPQNuACnOelH16A7L+q4swLWDIaEFeXQ2/5bmqVKZDZZ6usNP4QyTVszwd8jqo27qcDTNibXDUTsTdKpNQvM/3UncBuzuzmUV3FczhtGshIU1/pRVZiQycpVqPlGLvXhP/yZCe+1siyqDd+3uMaS2vkHTObSl5r+VYof+c+TcjrZXHSWnQTg8/X3zkoBWosrQ93VZcwjzMxQoARYv6rphbOoTz7RPmGAXYUt3/PDWkqDlmQDwCpLNNkJo1EidyefZBdD9HXQpCBO0ZU0NHb0JmPvg/+zU0krxlv70bm3RHA/maBETVjroIWzt7EwQEg5pL2hVnvSBG+1wF3BtRVe77etkPOHxLnYYIcAMLlVKCcgDd89DPIziQyruvkx1busHI08=" + } +} diff --git a/test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json b/test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json new file mode 100644 index 000000000..fe6b83ca6 --- /dev/null +++ b/test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json @@ -0,0 +1,53 @@ +{ + "subject": "acct:mike@osada.macgirvin.com", + "aliases": [ + "https://osada.macgirvin.com/channel/mike", + "https://osada.macgirvin.com/~mike", + "https://osada.macgirvin.com/@mike" + ], + "properties": { + "http://webfinger.net/ns/name": "Mike Macgirvin (Osada)", + "http://xmlns.com/foaf/0.1/name": "Mike Macgirvin (Osada)", + "https://w3id.org/security/v1#publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAskSyK2VwBNKbzZl9XNJk\nvxU5AAilmRArMmmKSzphdHaVBHakeafUfixvqNrQ/oX2srJvJKcghNmEMrJ6MJ7r\npeEndVOo7pcP4PwVjtnC06p3J711q5tBehqM25BfCLCrB2YqWF6c8zk3CPN3Na21\n8k5s4cO95N/rGN+Po0XFAX/HjKjlpgNpKRDrpxmXxTU8NZfAqeQGJ5oiMBZI9vVB\n+eU7t1L6F5/XWuUCeP4OMrG8oZX822AREba8rknS6DpkWGES0Rx2eNOyYTf6ue75\nI6Ek6rlO+da5wMWr+3BvYMq4JMIwTHzAO+ZqqJPFpzKSiVuAWb2DOX/MDFecVWJE\ntF/R60lONxe4e/00MPCoDdqkLKdwROsk1yGL7z4Zk6jOWFEhIcWy/d2Ya5CpPvS3\nu4wNN4jkYAjra+8TiloRELhV4gpcEk8nkyNwLXOhYm7zQ5sIc5rfXoIrFzALB86W\nG05Nnqg+77zZIaTZpD9qekYlaEt+0OVtt9TTIeTiudQ983l6mfKwZYymrzymH1dL\nVgxBRYo+Z53QOSLiSKELfTBZxEoP1pBw6RiOHXydmJ/39hGgc2YAY/5ADwW2F2yb\nJ7+gxG6bPJ3ikDLYcD4CB5iJQdnTcDsFt3jyHAT6wOCzFAYPbHUqtzHfUM30dZBn\nnJhQF8udPLcXLaj6GW75JacCAwEAAQ==\n-----END PUBLIC KEY-----\n", + "http://purl.org/zot/federation": "zot6,activitypub" + }, + "links": [ + { + "rel": "http://webfinger.net/rel/avatar", + "type": "image/jpeg", + "href": "https://osada.macgirvin.com/photo/profile/l/2" + }, + { + "rel": "http://webfinger.net/rel/blog", + "href": "https://osada.macgirvin.com/channel/mike" + }, + { + "rel": "http://openid.net/specs/connect/1.0/issuer", + "href": "https://osada.macgirvin.com" + }, + { + "rel": "http://purl.org/zot/protocol/6.0", + "type": "application/x-zot+json", + "href": "https://osada.macgirvin.com/channel/mike" + }, + { + "rel": "http://purl.org/openwebauth/v1", + "type": "application/x-zot+json", + "href": "https://osada.macgirvin.com/owa" + }, + { + "rel": "http://ostatus.org/schema/1.0/subscribe", + "template": "https://osada.macgirvin.com/follow?url={uri}" + }, + { + "rel": "self", + "type": "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", + "href": "https://osada.macgirvin.com/channel/mike" + }, + { + "rel": "self", + "type": "application/activity+json", + "href": "https://osada.macgirvin.com/channel/mike" + } + ] +} diff --git a/test/formatter_test.exs b/test/formatter_test.exs index e37b17879..13084baa7 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -1,5 +1,6 @@ defmodule Pleroma.FormatterTest do alias Pleroma.Formatter + alias Pleroma.User use Pleroma.DataCase import Pleroma.Factory @@ -131,6 +132,24 @@ defmodule Pleroma.FormatterTest do assert expected_text == Formatter.finalize({subs, text}) end + test "gives a replacement for user links when the user is using Osada" do + mike = User.get_or_fetch("mike@osada.macgirvin.com") + + text = "@mike@osada.macgirvin.com test" + + mentions = Formatter.parse_mentions(text) + + {subs, text} = Formatter.add_user_links({[], text}, mentions) + + assert length(subs) == 1 + Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end) + + expected_text = + "@mike test" + + assert expected_text == Formatter.finalize({subs, text}) + end + test "gives a replacement for single-character local nicknames" do text = "@o hi" o = insert(:user, %{nickname: "o"}) diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index d8b79abef..75c78d70e 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -3,6 +3,27 @@ defmodule HTTPoisonMock do def get(url, body \\ [], headers \\ []) + def get("https://osada.macgirvin.com/channel/mike", _, _) do + {:ok, + %Response{ + status_code: 200, + body: + File.read!("test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json") + }} + end + + def get( + "https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com", + _, + _ + ) do + {:ok, + %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json") + }} + end + def get("https://info.pleroma.site/activity.json", _, _) do {:ok, %Response{