diff options
-rw-r--r-- | lib/pleroma/formatter.ex | 84 | ||||
-rw-r--r-- | lib/pleroma/user.ex | 8 | ||||
-rw-r--r-- | lib/pleroma/web/activity_pub/transmogrifier.ex | 12 | ||||
-rw-r--r-- | lib/pleroma/web/common_api/utils.ex | 29 | ||||
-rw-r--r-- | lib/pleroma/web/twitter_api/twitter_api.ex | 2 | ||||
-rw-r--r-- | lib/pleroma/web/web_finger/web_finger.ex | 15 | ||||
-rw-r--r-- | priv/static/packs/pl-dark-masto-fe.css | 26 | ||||
-rw-r--r-- | test/fixtures/httpoison_mock/winterdienst_webfinger.json | 1 | ||||
-rw-r--r-- | test/fixtures/mastodon-post-activity-hashtag.json | 70 | ||||
-rw-r--r-- | test/formatter_test.exs | 44 | ||||
-rw-r--r-- | test/support/httpoison_mock.ex | 6 | ||||
-rw-r--r-- | test/web/activity_pub/transmogrifier_test.exs | 7 | ||||
-rw-r--r-- | test/web/twitter_api/twitter_api_test.exs | 16 | ||||
-rw-r--r-- | test/web/web_finger/web_finger_test.exs | 12 |
14 files changed, 249 insertions, 83 deletions
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index fd8465c1c..2d3487f6a 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -2,11 +2,6 @@ defmodule Pleroma.Formatter do alias Pleroma.User alias Pleroma.Web.MediaProxy - @link_regex ~r/https?:\/\/[\w\.\/?=\-#%&@~\(\)]+[\w\/]/u - def linkify(text) do - Regex.replace(@link_regex, text, "<a href='\\0'>\\0</a>") - end - @tag_regex ~r/\#\w+/u def parse_tags(text, data \\ %{}) do Regex.scan(@tag_regex, text) @@ -25,15 +20,6 @@ defmodule Pleroma.Formatter do |> Enum.filter(fn ({_match, user}) -> user end) end - def html_escape(text) do - Regex.split(@link_regex, text, include_captures: true) - |> Enum.map_every(2, fn chunk -> - {:safe, part} = Phoenix.HTML.html_escape(chunk) - part - end) - |> Enum.join("") - end - @finmoji [ "a_trusted_friend", "alandislands", @@ -145,4 +131,74 @@ defmodule Pleroma.Formatter do def get_custom_emoji() do @emoji end + + @link_regex ~r/https?:\/\/[\w\.\/?=\-#%&@~\(\)]+[\w\/]/u + + def html_escape(text) do + Regex.split(@link_regex, text, include_captures: true) + |> Enum.map_every(2, fn chunk -> + {:safe, part} = Phoenix.HTML.html_escape(chunk) + part + end) + |> Enum.join("") + end + + @doc "changes http:... links to html links" + def add_links({subs, text}) do + links = Regex.scan(@link_regex, text) + |> Enum.map(fn ([url]) -> {Ecto.UUID.generate, url} end) + + uuid_text = links + |> Enum.reduce(text, fn({uuid, url}, acc) -> String.replace(acc, url, uuid) end) + + subs = subs ++ Enum.map(links, fn({uuid, url}) -> + {uuid, "<a href='#{url}'>#{url}</a>"} + end) + + {subs, uuid_text} + end + + @doc "Adds the links to mentioned users" + def add_user_links({subs, text}, mentions) do + mentions = mentions + |> Enum.sort_by(fn ({name, _}) -> -String.length(name) end) + |> Enum.map(fn({name, user}) -> {name, user, Ecto.UUID.generate} end) + + uuid_text = mentions + |> Enum.reduce(text, fn ({match, _user, uuid}, text) -> + String.replace(text, match, uuid) + end) + + subs = subs ++ Enum.map(mentions, fn ({match, %User{ap_id: ap_id}, uuid}) -> + short_match = String.split(match, "@") |> tl() |> hd() + {uuid, "<span><a href='#{ap_id}'>@<span>#{short_match}</span></a></span>"} + end) + + {subs, uuid_text} + end + + @doc "Adds the hashtag links" + def add_hashtag_links({subs, text}, tags) do + tags = tags + |> Enum.sort_by(fn ({name, _}) -> -String.length(name) end) + |> Enum.map(fn({name, short}) -> {name, short, Ecto.UUID.generate} end) + + uuid_text = tags + |> Enum.reduce(text, fn ({match, _short, uuid}, text) -> + String.replace(text, match, uuid) + end) + + subs = subs ++ Enum.map(tags, fn ({_, tag, uuid}) -> + url = "#<a href='#{Pleroma.Web.base_url}/tag/#{tag}' rel='tag'>#{tag}</a>" + {uuid, url} + end) + + {subs, uuid_text} + end + + def finalize({subs, text}) do + Enum.reduce(subs, text, fn({uuid, replacement}, result_text) -> + String.replace(result_text, uuid, replacement) + end) + end end diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 5da146014..e92b85f52 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -458,4 +458,12 @@ defmodule Pleroma.User do def ap_enabled?(%User{info: info}), do: info["ap_enabled"] def ap_enabled?(_), do: false + + def get_or_fetch(uri_or_nickname) do + if String.starts_with?(uri_or_nickname, "http") do + get_or_fetch_by_ap_id(uri_or_nickname) + else + get_or_fetch_by_nickname(uri_or_nickname) + end + end end diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 61631e1ea..6561b8d76 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -22,6 +22,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do |> fix_context |> fix_in_reply_to |> fix_emoji + |> fix_tag end def fix_in_reply_to(%{"inReplyTo" => in_reply_to_id} = object) when not is_nil(in_reply_to_id) do @@ -76,6 +77,17 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do |> Map.put("emoji", emoji) end + def fix_tag(object) do + tags = (object["tag"] || []) + |> Enum.filter(fn (data) -> data["type"] == "Hashtag" and data["name"] end) + |> Enum.map(fn (data) -> String.slice(data["name"], 1..-1) end) + + combined = (object["tag"] || []) ++ tags + + object + |> Map.put("tag", combined) + end + # TODO: validate those with a Ecto scheme # - tags # - emoji diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 75c63e5f4..3c09f0cc7 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -78,13 +78,15 @@ defmodule Pleroma.Web.CommonAPI.Utils do Enum.join([text | attachment_text], "<br>") end - def format_input(text, mentions, _tags) do + def format_input(text, mentions, tags) do text |> Formatter.html_escape - |> Formatter.linkify |> String.replace("\n", "<br>") - |> add_user_links(mentions) - # |> add_tag_links(tags) + |> (&({[], &1})).() + |> Formatter.add_links + |> Formatter.add_user_links(mentions) + |> Formatter.add_hashtag_links(tags) + |> Formatter.finalize end def add_tag_links(text, tags) do @@ -97,25 +99,6 @@ defmodule Pleroma.Web.CommonAPI.Utils do end) end - def add_user_links(text, mentions) do - mentions = mentions - |> Enum.sort_by(fn ({name, _}) -> -String.length(name) end) - |> Enum.map(fn({name, user}) -> {name, user, Ecto.UUID.generate} end) - - # This replaces the mention with a unique reference first so it doesn't - # contain parts of other replaced mentions. There probably is a better - # solution for this... - step_one = mentions - |> Enum.reduce(text, fn ({match, _user, uuid}, text) -> - String.replace(text, match, uuid) - end) - - Enum.reduce(mentions, step_one, fn ({match, %User{ap_id: ap_id}, uuid}, text) -> - short_match = String.split(match, "@") |> tl() |> hd() - String.replace(text, uuid, "<span><a href='#{ap_id}'>@<span>#{short_match}</span></a></span>") - end) - end - def make_note_data(actor, to, context, content_html, attachments, inReplyTo, tags, cw \\ nil, cc \\ []) do object = %{ "type" => "Note", diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 987a960bb..6e1f141f3 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -328,7 +328,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do end def get_external_profile(for_user, uri) do - with {:ok, %User{} = user} <- OStatus.find_or_make_user(uri) do + with %User{} = user <- User.get_or_fetch(uri) do spawn(fn -> with url <- user.info["topic"], {:ok, %{body: body}} <- @httpoison.get(url, [], follow_redirect: true, timeout: 10000, recv_timeout: 20000) do diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index d8eb6f3e0..7391edcd7 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -118,14 +118,23 @@ defmodule Pleroma.Web.WebFinger do {:ok, data} end - # TODO: maybe fill in other details from JRD webfinger response defp webfinger_from_json(doc) do data = Enum.reduce(doc["links"], %{"subject" => doc["subject"]}, fn (link, data) -> - case link["type"] do - "application/activity+json" -> + case {link["type"], link["rel"]} do + {"application/activity+json", "self"} -> Map.put(data, "ap_id", link["href"]) + {_, "magic-public-key"} -> + "data:application/magic-public-key," <> magic_key = link["href"] + Map.put(data, "magic_key", magic_key) + {"application/atom+xml", "http://schemas.google.com/g/2010#updates-from"} -> + Map.put(data, "topic", link["href"]) + {_, "salmon"} -> + Map.put(data, "salmon", link["href"]) + {_, "http://ostatus.org/schema/1.0/subscribe"} -> + Map.put(data, "subscribe_address", link["template"]) _ -> Logger.debug("Unhandled type: #{inspect(link["type"])}") + data end end) {:ok, data} diff --git a/priv/static/packs/pl-dark-masto-fe.css b/priv/static/packs/pl-dark-masto-fe.css index dc35b5408..019cf25b5 100644 --- a/priv/static/packs/pl-dark-masto-fe.css +++ b/priv/static/packs/pl-dark-masto-fe.css @@ -24,12 +24,8 @@ .notification { background-color: #121a24; } -.display-name__html, -.display-name__account { - color: #d8a070; -} - -.status__relative-time { +.reply-indicator__display-name .display-name__html, +.reply-indicator__display-name .display-name__account { color: #d8a070; } @@ -45,14 +41,6 @@ color: #d8a070; } -.fa { - color: #d8a070; -} - -.icon-button { - color: #d8a070 !important; -} - .status__content.status__content--with-action { color: #b9b9ba; } @@ -129,20 +117,16 @@ color: #d8a070; } -.text-icon-button { - color: #d8a070; -} - .getting-started__footer { background-color: #121a24; } .notification__message{ - background-color: #121a24; + background-color: #121a24; } a.status-link{ color: #d8a070; } -.column { +.column { flex: 1 1 auto !important; -}
\ No newline at end of file +} diff --git a/test/fixtures/httpoison_mock/winterdienst_webfinger.json b/test/fixtures/httpoison_mock/winterdienst_webfinger.json new file mode 100644 index 000000000..e7bfba9ed --- /dev/null +++ b/test/fixtures/httpoison_mock/winterdienst_webfinger.json @@ -0,0 +1 @@ +{"subject":"acct:winterdienst@gnusocial.de","aliases":["https:\/\/gnusocial.de\/user\/249296","https:\/\/gnusocial.de\/winterdienst","https:\/\/gnusocial.de\/index.php\/user\/249296","https:\/\/gnusocial.de\/index.php\/winterdienst"],"links":[{"rel":"http:\/\/webfinger.net\/rel\/profile-page","type":"text\/html","href":"https:\/\/gnusocial.de\/winterdienst"},{"rel":"http:\/\/gmpg.org\/xfn\/11","type":"text\/html","href":"https:\/\/gnusocial.de\/winterdienst"},{"rel":"describedby","type":"application\/rdf+xml","href":"https:\/\/gnusocial.de\/winterdienst\/foaf"},{"rel":"http:\/\/apinamespace.org\/atom","type":"application\/atomsvc+xml","href":"https:\/\/gnusocial.de\/api\/statusnet\/app\/service\/winterdienst.xml"},{"rel":"http:\/\/apinamespace.org\/twitter","href":"https:\/\/gnusocial.de\/api\/"},{"rel":"http:\/\/schemas.google.com\/g\/2010#updates-from","type":"application\/atom+xml","href":"https:\/\/gnusocial.de\/api\/statuses\/user_timeline\/249296.atom"},{"rel":"magic-public-key","href":"data:application\/magic-public-key,RSA.qfYaxztz7ZELrE4v5WpJrPM99SKI3iv9Y3Tw6nfLGk-4CRljNYqV8IYX2FXjeucC_DKhPNnlF6fXyASpcSmA_qupX9WC66eVhFhZ5OuyBOeLvJ1C4x7Hi7Di8MNBxY3VdQuQR0tTaS_YAZCwASKp7H6XEid3EJpGt0EQZoNzRd8=.AQAB"},{"rel":"salmon","href":"https:\/\/gnusocial.de\/main\/salmon\/user\/249296"},{"rel":"http:\/\/salmon-protocol.org\/ns\/salmon-replies","href":"https:\/\/gnusocial.de\/main\/salmon\/user\/249296"},{"rel":"http:\/\/salmon-protocol.org\/ns\/salmon-mention","href":"https:\/\/gnusocial.de\/main\/salmon\/user\/249296"},{"rel":"http:\/\/ostatus.org\/schema\/1.0\/subscribe","template":"https:\/\/gnusocial.de\/main\/ostatussub?profile={uri}"}]}
\ No newline at end of file diff --git a/test/fixtures/mastodon-post-activity-hashtag.json b/test/fixtures/mastodon-post-activity-hashtag.json new file mode 100644 index 000000000..ed0925d85 --- /dev/null +++ b/test/fixtures/mastodon-post-activity-hashtag.json @@ -0,0 +1,70 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "Emoji": "toot:Emoji", + "Hashtag": "as:Hashtag", + "atomUri": "ostatus:atomUri", + "conversation": "ostatus:conversation", + "inReplyToAtomUri": "ostatus:inReplyToAtomUri", + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "movedTo": "as:movedTo", + "ostatus": "http://ostatus.org#", + "sensitive": "as:sensitive", + "toot": "http://joinmastodon.org/ns#" + } + ], + "actor": "http://mastodon.example.org/users/admin", + "cc": [ + "http://mastodon.example.org/users/admin/followers", + "http://localtesting.pleroma.lol/users/lain" + ], + "id": "http://mastodon.example.org/users/admin/statuses/99512778738411822/activity", + "nickname": "lain", + "object": { + "atomUri": "http://mastodon.example.org/users/admin/statuses/99512778738411822", + "attachment": [], + "attributedTo": "http://mastodon.example.org/users/admin", + "cc": [ + "http://mastodon.example.org/users/admin/followers", + "http://localtesting.pleroma.lol/users/lain" + ], + "content": "<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span> #moo</p>", + "conversation": "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation", + "id": "http://mastodon.example.org/users/admin/statuses/99512778738411822", + "inReplyTo": null, + "inReplyToAtomUri": null, + "published": "2018-02-12T14:08:20Z", + "sensitive": true, + "summary": "cw", + "tag": [ + { + "href": "http://localtesting.pleroma.lol/users/lain", + "name": "@lain@localtesting.pleroma.lol", + "type": "Mention" + }, + { + "href": "http://mastodon.example.org/tags/moo", + "name": "#moo", + "type": "Hashtag" + } + ], + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "type": "Note", + "url": "http://mastodon.example.org/@admin/99512778738411822" + }, + "published": "2018-02-12T14:08:20Z", + "signature": { + "created": "2018-02-12T14:08:20Z", + "creator": "http://mastodon.example.org/users/admin#main-key", + "signatureValue": "rnNfcopkc6+Ju73P806popcfwrK9wGYHaJVG1/ZvrlEbWVDzaHjkXqj9Q3/xju5l8CSn9tvSgCCtPFqZsFQwn/pFIFUcw7ZWB2xi4bDm3NZ3S4XQ8JRaaX7og5hFxAhWkGhJhAkfxVnOg2hG+w2d/7d7vRVSC1vo5ip4erUaA/PkWusZvPIpxnRWoXaxJsFmVx0gJgjpJkYDyjaXUlp+jmaoseeZ4EPQUWqHLKJ59PRG0mg8j2xAjYH9nQaN14qMRmTGPxY8gfv/CUFcatA+8VJU9KEsJkDAwLVvglydNTLGrxpAJU78a2eaht0foV43XUIZGe3DKiJPgE+UOKGCJw==", + "type": "RsaSignature2017" + }, + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "type": "Create" +} diff --git a/test/formatter_test.exs b/test/formatter_test.exs index cb7695e8e..0e915d8d5 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -4,37 +4,67 @@ defmodule Pleroma.FormatterTest do import Pleroma.Factory - describe ".linkify" do + describe ".add_hashtag_links" do + test "turns hashtags into links" do + text = "I love #cofe and #2hu" + expected_text = "I love #<a href='http://localhost:4001/tag/cofe' rel='tag'>cofe</a> and #<a href='http://localhost:4001/tag/2hu' rel='tag'>2hu</a>" + + tags = Formatter.parse_tags(text) + assert expected_text == Formatter.add_hashtag_links({[], text}, tags) |> Formatter.finalize + end + end + + describe ".add_links" do test "turning urls into links" do text = "Hey, check out https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla." expected = "Hey, check out <a href='https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla'>https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla</a>." - assert Formatter.linkify(text) == expected + assert Formatter.add_links({[], text}) |> Formatter.finalize == expected text = "https://mastodon.social/@lambadalambda" expected = "<a href='https://mastodon.social/@lambadalambda'>https://mastodon.social/@lambadalambda</a>" - assert Formatter.linkify(text) == expected + assert Formatter.add_links({[], text}) |> Formatter.finalize == expected text = "@lambadalambda" expected = "@lambadalambda" - assert Formatter.linkify(text) == expected + assert Formatter.add_links({[], text}) |> Formatter.finalize == expected text = "http://www.cs.vu.nl/~ast/intel/" expected = "<a href='http://www.cs.vu.nl/~ast/intel/'>http://www.cs.vu.nl/~ast/intel/</a>" - assert Formatter.linkify(text) == expected + assert Formatter.add_links({[], text}) |> Formatter.finalize == expected text = "https://forum.zdoom.org/viewtopic.php?f=44&t=57087" expected = "<a href='https://forum.zdoom.org/viewtopic.php?f=44&t=57087'>https://forum.zdoom.org/viewtopic.php?f=44&t=57087</a>" - assert Formatter.linkify(text) == expected + assert Formatter.add_links({[], text}) |> Formatter.finalize == expected text = "https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul" expected = "<a href='https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul'>https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul</a>" - assert Formatter.linkify(text) == expected + assert Formatter.add_links({[], text}) |> Formatter.finalize == expected + end + end + + describe "add_user_links" do + test "gives a replacement for user links" do + text = "@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me" + gsimg = insert(:user, %{nickname: "gsimg"}) + archaeme = insert(:user, %{nickname: "archaeme"}) + archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"}) + + mentions = Pleroma.Formatter.parse_mentions(text) + + {subs, text} = Formatter.add_user_links({[], text}, mentions) + + assert length(subs) == 3 + Enum.each(subs, fn({uuid, _}) -> assert String.contains?(text, uuid) end) + + expected_text = "<span><a href='#{gsimg.ap_id}'>@<span>gsimg</span></a></span> According to <span><a href='#{archaeme.ap_id}'>@<span>archaeme</span></a></span>, that is @daggsy. Also hello <span><a href='#{archaeme_remote.ap_id}'>@<span>archaeme</span></a></span>" + + assert expected_text == Formatter.finalize({subs, text}) end end diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index 5d021a3b4..c70598691 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -9,6 +9,12 @@ defmodule HTTPoisonMock do body: File.read!("test/fixtures/httpoison_mock/framasoft@framatube.org.json") }} end + def get("http://gnusocial.de/.well-known/webfinger?resource=acct:winterdienst@gnusocial.de", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do + {:ok, %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/winterdienst_webfinger.json") + }} + end def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "nonexistant@social.heldscal.la"], follow_redirect: true]) do {:ok, %Response{ diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index caad9737a..375e74ad9 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -69,6 +69,13 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert object["sensitive"] == true end + test "it works for incoming notices with hashtags" do + data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Poison.decode! + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + assert Enum.at(data["object"]["tag"], 2) == "moo" + end + test "it works for incoming follow requests" do user = insert(:user) data = File.read!("test/fixtures/mastodon-follow-activity.json") |> Poison.decode! diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 6b0b182a3..7d578a751 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -34,7 +34,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do { :ok, activity = %Activity{} } = TwitterAPI.create_status(user, input) - assert get_in(activity.data, ["object", "content"]) == "Hello again, <span><a href='shp'>@<span>shp</span></a></span>.<script></script><br>This is on another :moominmamma: line. #2hu #epic #phantasmagoric<br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>" + expected_text = "Hello again, <span><a href='shp'>@<span>shp</span></a></span>.<script></script><br>This is on another :moominmamma: line. #<a href='http://localhost:4001/tag/2hu' rel='tag'>2hu</a> #<a href='http://localhost:4001/tag/epic' rel='tag'>epic</a> #<a href='http://localhost:4001/tag/phantasmagoric' rel='tag'>phantasmagoric</a><br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>" + assert get_in(activity.data, ["object", "content"]) == expected_text assert get_in(activity.data, ["object", "type"]) == "Note" assert get_in(activity.data, ["object", "actor"]) == user.ap_id assert get_in(activity.data, ["actor"]) == user.ap_id @@ -282,19 +283,6 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do assert is_binary(response) end - test "it adds user links to an existing text" do - text = "@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me" - - gsimg = insert(:user, %{nickname: "gsimg"}) - archaeme = insert(:user, %{nickname: "archaeme"}) - archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"}) - - mentions = Pleroma.Formatter.parse_mentions(text) - expected_text = "<span><a href='#{gsimg.ap_id}'>@<span>gsimg</span></a></span> According to <span><a href='#{archaeme.ap_id}'>@<span>archaeme</span></a></span>, that is @daggsy. Also hello <span><a href='#{archaeme_remote.ap_id}'>@<span>archaeme</span></a></span>" - - assert Utils.add_user_links(text, mentions) == expected_text - end - test "it favorites a status, returns the updated status" do user = insert(:user) note_activity = insert(:note_activity) diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs index ff60391fd..c7ad206eb 100644 --- a/test/web/web_finger/web_finger_test.exs +++ b/test/web/web_finger/web_finger_test.exs @@ -45,6 +45,18 @@ defmodule Pleroma.Web.WebFingerTest do {:ok, _data} = WebFinger.finger(user) end + test "returns the correctly for json ostatus users" do + user = "winterdienst@gnusocial.de" + + {:ok, data} = WebFinger.finger(user) + + assert data["magic_key"] == "RSA.qfYaxztz7ZELrE4v5WpJrPM99SKI3iv9Y3Tw6nfLGk-4CRljNYqV8IYX2FXjeucC_DKhPNnlF6fXyASpcSmA_qupX9WC66eVhFhZ5OuyBOeLvJ1C4x7Hi7Di8MNBxY3VdQuQR0tTaS_YAZCwASKp7H6XEid3EJpGt0EQZoNzRd8=.AQAB" + assert data["topic"] == "https://gnusocial.de/api/statuses/user_timeline/249296.atom" + assert data["subject"] == "acct:winterdienst@gnusocial.de" + assert data["salmon"] == "https://gnusocial.de/main/salmon/user/249296" + assert data["subscribe_address"] == "https://gnusocial.de/main/ostatussub?profile={uri}" + end + test "it works for friendica" do user = "lain@squeet.me" |