Merge remote-tracking branch 'origin/develop' into birth-dates
This commit is contained in:
commit
aaa9314f4c
131 changed files with 668 additions and 162 deletions
14
test/fixtures/mastodon/collections/external_featured.json
vendored
Normal file
14
test/fixtures/mastodon/collections/external_featured.json
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://{{domain}}/schemas/litepub-0.1.jsonld",
|
||||
{
|
||||
"@language": "und"
|
||||
}
|
||||
],
|
||||
"id": "https://{{domain}}/users/{{nickname}}/collections/featured",
|
||||
"orderedItems": [
|
||||
"https://{{domain}}/objects/{{object_id}}"
|
||||
],
|
||||
"type": "OrderedCollection"
|
||||
}
|
||||
79
test/fixtures/soapbox_no_mentions_in_content.json
vendored
Normal file
79
test/fixtures/soapbox_no_mentions_in_content.json
vendored
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://gleasonator.com/schemas/litepub-0.1.jsonld",
|
||||
{
|
||||
"@language": "und"
|
||||
}
|
||||
],
|
||||
"actor": "https://gleasonator.com/users/alex",
|
||||
"attachment": [
|
||||
{
|
||||
"blurhash": "b15#-6_3~l%eDkNraAM#HYMf",
|
||||
"height": 2147,
|
||||
"mediaType": "image/png",
|
||||
"name": "",
|
||||
"type": "Document",
|
||||
"url": "https://media.gleasonator.com/2df1c9cc26c35028db65848143971da0c5a6e04dbd423b194bb018b6c601db9b.png",
|
||||
"width": 966
|
||||
},
|
||||
{
|
||||
"blurhash": "b168EX~q~W-;DiM{VtIUD%Io",
|
||||
"height": 2147,
|
||||
"mediaType": "image/png",
|
||||
"name": "",
|
||||
"type": "Document",
|
||||
"url": "https://media.gleasonator.com/22b42b4cddc1aecc7e2d3dc20bcdd66d5c4e44c2bef119de948e95a587e36b66.png",
|
||||
"width": 966
|
||||
}
|
||||
],
|
||||
"attributedTo": "https://gleasonator.com/users/alex",
|
||||
"cc": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"content": "<p>Haha yeah, you can control who you reply to.</p>",
|
||||
"context": "https://gleasonator.com/contexts/ba6c8bd9-ac4d-479e-9bd9-5bf570068ae7",
|
||||
"conversation": "https://gleasonator.com/contexts/ba6c8bd9-ac4d-479e-9bd9-5bf570068ae7",
|
||||
"id": "https://gleasonator.com/objects/02af65fe-04f8-46bc-9b1e-31dfe76eaffd",
|
||||
"inReplyTo": "https://shitposter.club/objects/c686d811-4368-48e1-ba11-82c129f93165",
|
||||
"published": "2022-01-19T03:37:35.976545Z",
|
||||
"sensitive": false,
|
||||
"source": "Haha yeah, you can control who you reply to.",
|
||||
"summary": "",
|
||||
"tag": [
|
||||
{
|
||||
"href": "https://lain.com/users/lain",
|
||||
"name": "@lain@lain.com",
|
||||
"type": "Mention"
|
||||
},
|
||||
{
|
||||
"href": "https://shitposter.club/users/coolboymew",
|
||||
"name": "@coolboymew@shitposter.club",
|
||||
"type": "Mention"
|
||||
},
|
||||
{
|
||||
"href": "https://shitposter.club/users/dielan",
|
||||
"name": "@dielan@shitposter.club",
|
||||
"type": "Mention"
|
||||
},
|
||||
{
|
||||
"href": "https://tuusin.misono-ya.info/users/hakui",
|
||||
"name": "@hakui@tuusin.misono-ya.info",
|
||||
"type": "Mention"
|
||||
},
|
||||
{
|
||||
"href": "https://xyzzy.link/users/fence",
|
||||
"name": "@fence@xyzzy.link",
|
||||
"type": "Mention"
|
||||
}
|
||||
],
|
||||
"to": [
|
||||
"https://shitposter.club/users/dielan",
|
||||
"https://gleasonator.com/users/alex/followers",
|
||||
"https://shitposter.club/users/coolboymew",
|
||||
"https://xyzzy.link/users/fence",
|
||||
"https://tuusin.misono-ya.info/users/hakui",
|
||||
"https://lain.com/users/lain"
|
||||
],
|
||||
"type": "Note"
|
||||
}
|
||||
|
|
@ -270,6 +270,34 @@ defmodule Pleroma.FormatterTest do
|
|||
|
||||
assert {^expected_text, ^expected_mentions, []} = Formatter.linkify(text)
|
||||
end
|
||||
|
||||
test "correctly parses mentions in html" do
|
||||
text = "<p>@lain hello</p>"
|
||||
lain = insert(:user, %{nickname: "lain"})
|
||||
|
||||
{text, mentions, []} = Formatter.linkify(text)
|
||||
|
||||
assert length(mentions) == 1
|
||||
|
||||
expected_text =
|
||||
~s(<p><span class="h-card"><a class="u-url mention" data-user="#{lain.id}" href="#{lain.ap_id}" rel="ugc">@<span>lain</span></a></span> hello</p>)
|
||||
|
||||
assert expected_text == text
|
||||
end
|
||||
|
||||
test "correctly parses mentions on the last line of html" do
|
||||
text = "<p>Hello</p><p>@lain</p>"
|
||||
lain = insert(:user, %{nickname: "lain"})
|
||||
|
||||
{text, mentions, []} = Formatter.linkify(text)
|
||||
|
||||
assert length(mentions) == 1
|
||||
|
||||
expected_text =
|
||||
~s(<p>Hello</p><p><span class="h-card"><a class="u-url mention" data-user="#{lain.id}" href="#{lain.ap_id}" rel="ugc">@<span>lain</span></a></span></p>)
|
||||
|
||||
assert expected_text == text
|
||||
end
|
||||
end
|
||||
|
||||
describe ".parse_tags" do
|
||||
|
|
@ -285,6 +313,57 @@ defmodule Pleroma.FormatterTest do
|
|||
|
||||
assert {_text, [], ^expected_tags} = Formatter.linkify(text)
|
||||
end
|
||||
|
||||
test "parses tags in html" do
|
||||
text = "<p>This is a #test</p>"
|
||||
|
||||
expected_tags = [
|
||||
{"#test", "test"}
|
||||
]
|
||||
|
||||
assert {_text, [], ^expected_tags} = Formatter.linkify(text)
|
||||
end
|
||||
|
||||
test "parses mulitple tags in html" do
|
||||
text = "<p>#tag1 #tag2 #tag3 #tag4</p>"
|
||||
|
||||
expected_tags = [
|
||||
{"#tag1", "tag1"},
|
||||
{"#tag2", "tag2"},
|
||||
{"#tag3", "tag3"},
|
||||
{"#tag4", "tag4"}
|
||||
]
|
||||
|
||||
assert {_text, [], ^expected_tags} = Formatter.linkify(text)
|
||||
end
|
||||
|
||||
test "parses tags on the last line of html" do
|
||||
text = "<p>This is a</p><p>#test</p>"
|
||||
|
||||
expected_tags = [
|
||||
{"#test", "test"}
|
||||
]
|
||||
|
||||
assert {_text, [], ^expected_tags} = Formatter.linkify(text)
|
||||
end
|
||||
|
||||
test "parses mulitple tags on mulitple lines in html" do
|
||||
text =
|
||||
"<p>testing...</p><p>#tag1 #tag2 #tag3 #tag4</p><p>paragraph</p><p>#tag5 #tag6 #tag7 #tag8</p>"
|
||||
|
||||
expected_tags = [
|
||||
{"#tag1", "tag1"},
|
||||
{"#tag2", "tag2"},
|
||||
{"#tag3", "tag3"},
|
||||
{"#tag4", "tag4"},
|
||||
{"#tag5", "tag5"},
|
||||
{"#tag6", "tag6"},
|
||||
{"#tag7", "tag7"},
|
||||
{"#tag8", "tag8"}
|
||||
]
|
||||
|
||||
assert {_text, [], ^expected_tags} = Formatter.linkify(text)
|
||||
end
|
||||
end
|
||||
|
||||
test "it escapes HTML in plain text" do
|
||||
|
|
|
|||
|
|
@ -312,6 +312,83 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
|
||||
assert %{data: %{"id" => ^object_url}} = Object.get_by_ap_id(object_url)
|
||||
end
|
||||
|
||||
test "fetches user featured collection without embedded object" do
|
||||
ap_id = "https://example.com/users/lain"
|
||||
|
||||
featured_url = "https://example.com/users/lain/collections/featured"
|
||||
|
||||
user_data =
|
||||
"test/fixtures/users_mock/user.json"
|
||||
|> File.read!()
|
||||
|> String.replace("{{nickname}}", "lain")
|
||||
|> Jason.decode!()
|
||||
|> Map.put("featured", featured_url)
|
||||
|> Jason.encode!()
|
||||
|
||||
object_id = Ecto.UUID.generate()
|
||||
|
||||
featured_data =
|
||||
"test/fixtures/mastodon/collections/external_featured.json"
|
||||
|> File.read!()
|
||||
|> String.replace("{{domain}}", "example.com")
|
||||
|> String.replace("{{nickname}}", "lain")
|
||||
|> String.replace("{{object_id}}", object_id)
|
||||
|
||||
object_url = "https://example.com/objects/#{object_id}"
|
||||
|
||||
object_data =
|
||||
"test/fixtures/statuses/note.json"
|
||||
|> File.read!()
|
||||
|> String.replace("{{object_id}}", object_id)
|
||||
|> String.replace("{{nickname}}", "lain")
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: ^ap_id
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: user_data,
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url: ^featured_url
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: featured_data,
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
end)
|
||||
|
||||
Tesla.Mock.mock_global(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: ^object_url
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: object_data,
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
end)
|
||||
|
||||
{:ok, user} = ActivityPub.make_user_from_ap_id(ap_id)
|
||||
Process.sleep(50)
|
||||
|
||||
assert user.featured_address == featured_url
|
||||
assert Map.has_key?(user.pinned_objects, object_url)
|
||||
|
||||
in_db = Pleroma.User.get_by_ap_id(ap_id)
|
||||
assert in_db.featured_address == featured_url
|
||||
assert Map.has_key?(user.pinned_objects, object_url)
|
||||
|
||||
assert %{data: %{"id" => ^object_url}} = Object.get_by_ap_id(object_url)
|
||||
end
|
||||
end
|
||||
|
||||
test "it fetches the appropriate tag-restricted posts" do
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionsInContentTest do
|
||||
alias Pleroma.Web.ActivityPub.MRF.ForceMentionsInContent
|
||||
import Pleroma.Factory
|
||||
use Pleroma.DataCase
|
||||
|
||||
test "adds mentions to post content" do
|
||||
users = %{
|
||||
"lain@lain.com" => "https://lain.com/users/lain",
|
||||
"coolboymew@shitposter.club" => "https://shitposter.club/users/coolboymew",
|
||||
"dielan@shitposter.club" => "https://shitposter.club/users/dielan",
|
||||
"hakui@tuusin.misono-ya.info" => "https://tuusin.misono-ya.info/users/hakui",
|
||||
"fence@xyzzy.link" => "https://xyzzy.link/users/fence"
|
||||
}
|
||||
|
||||
Enum.each(users, fn {nickname, ap_id} ->
|
||||
insert(:user, ap_id: ap_id, nickname: nickname, local: false)
|
||||
end)
|
||||
|
||||
object = File.read!("test/fixtures/soapbox_no_mentions_in_content.json") |> Jason.decode!()
|
||||
|
||||
activity = %{
|
||||
"type" => "Create",
|
||||
"actor" => "https://gleasonator.com/users/alex",
|
||||
"object" => object
|
||||
}
|
||||
|
||||
{:ok, %{"object" => %{"content" => filtered}}} = ForceMentionsInContent.filter(activity)
|
||||
Enum.each(users, fn {nickname, _} -> assert filtered =~ nickname end)
|
||||
end
|
||||
end
|
||||
|
|
@ -5,7 +5,9 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.InternalFetchActor
|
||||
|
|
@ -404,15 +406,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert id_two == to_string(activity.id)
|
||||
end
|
||||
|
||||
test "unimplemented pinned statuses feature", %{conn: conn} do
|
||||
note = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note.data["actor"])
|
||||
|
||||
conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?pinned=true")
|
||||
|
||||
assert json_response_and_validate_schema(conn, 200) == []
|
||||
end
|
||||
|
||||
test "gets an users media, excludes reblogs", %{conn: conn} do
|
||||
note = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note.data["actor"])
|
||||
|
|
@ -1038,6 +1031,35 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "view pinned private statuses" do
|
||||
user = insert(:user)
|
||||
reader = insert(:user)
|
||||
|
||||
# Create a private status and pin it
|
||||
{:ok, %{id: activity_id} = activity} =
|
||||
CommonAPI.post(user, %{status: "psst", visibility: "private"})
|
||||
|
||||
%{data: %{"id" => object_ap_id}} = Object.normalize(activity)
|
||||
{:ok, _} = User.add_pinned_object_id(user, object_ap_id)
|
||||
|
||||
%{conn: conn} = oauth_access(["read:statuses"], user: reader)
|
||||
|
||||
# A non-follower can't see the pinned status
|
||||
assert [] ==
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
# Follow the user, then the pinned status can be seen
|
||||
CommonAPI.follow(reader, user)
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert [%{"id" => ^activity_id, "pinned" => true}] =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "blocking / unblocking a user" do
|
||||
%{conn: conn} = oauth_access(["follow"])
|
||||
other_user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -64,12 +64,13 @@ defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do
|
|||
|
||||
assert response["irreversible"] == false
|
||||
|
||||
expires_at =
|
||||
expected_expiration =
|
||||
NaiveDateTime.utc_now()
|
||||
|> NaiveDateTime.add(in_seconds)
|
||||
|> Pleroma.Web.CommonAPI.Utils.to_masto_date()
|
||||
|
||||
assert response["expires_at"] == expires_at
|
||||
{:ok, actual_expiration} = NaiveDateTime.from_iso8601(response["expires_at"])
|
||||
|
||||
assert abs(NaiveDateTime.diff(expected_expiration, actual_expiration)) <= 5
|
||||
|
||||
filter = Filter.get(response["id"], user)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue