2019-11-05 14:02:31 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-11-05 14:02:31 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-10-21 08:23:10 +00:00
|
|
|
defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest do
|
2020-12-21 11:21:40 +00:00
|
|
|
use Pleroma.DataCase, async: true
|
2019-11-05 14:02:31 +00:00
|
|
|
|
2020-10-21 08:23:10 +00:00
|
|
|
alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator
|
2019-11-05 14:02:31 +00:00
|
|
|
alias Pleroma.Web.ActivityPub.Utils
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
2022-07-10 17:06:25 +00:00
|
|
|
setup_all do
|
|
|
|
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
|
|
|
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2019-11-05 14:02:31 +00:00
|
|
|
describe "Notes" do
|
|
|
|
setup do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
note = %{
|
|
|
|
"id" => Utils.generate_activity_id(),
|
|
|
|
"type" => "Note",
|
|
|
|
"actor" => user.ap_id,
|
|
|
|
"to" => [user.follower_address],
|
|
|
|
"cc" => [],
|
|
|
|
"content" => "Hellow this is content.",
|
|
|
|
"context" => "xxx",
|
|
|
|
"summary" => "a post"
|
|
|
|
}
|
|
|
|
|
|
|
|
%{user: user, note: note}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "a basic note validates", %{note: note} do
|
2020-10-21 08:23:10 +00:00
|
|
|
%{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
|
2019-11-05 14:02:31 +00:00
|
|
|
end
|
2022-01-07 16:51:04 +00:00
|
|
|
|
|
|
|
test "a note with a remote replies collection should validate", _ do
|
|
|
|
insert(:user, %{ap_id: "https://bookwyrm.com/user/TestUser"})
|
|
|
|
collection = File.read!("test/fixtures/bookwyrm-replies-collection.json")
|
|
|
|
|
|
|
|
Tesla.Mock.mock(fn %{
|
|
|
|
method: :get,
|
|
|
|
url: "https://bookwyrm.com/user/TestUser/review/17/replies?page=1"
|
|
|
|
} ->
|
|
|
|
%Tesla.Env{
|
|
|
|
status: 200,
|
|
|
|
body: collection,
|
|
|
|
headers: HttpRequestMock.activitypub_object_headers()
|
|
|
|
}
|
|
|
|
end)
|
|
|
|
|
|
|
|
note = Jason.decode!(File.read!("test/fixtures/bookwyrm-article.json"))
|
|
|
|
|
|
|
|
%{valid?: true, changes: %{replies: ["https://bookwyrm.com/user/TestUser/status/18"]}} =
|
|
|
|
ArticleNotePageValidator.cast_and_validate(note)
|
|
|
|
end
|
2022-07-01 11:14:55 +00:00
|
|
|
|
|
|
|
test "a note with an attachment should work", _ do
|
|
|
|
insert(:user, %{ap_id: "https://owncast.localhost.localdomain/federation/user/streamer"})
|
|
|
|
|
|
|
|
note =
|
|
|
|
"test/fixtures/owncast-note-with-attachment.json"
|
|
|
|
|> File.read!()
|
|
|
|
|> Jason.decode!()
|
|
|
|
|
|
|
|
%{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
|
|
|
|
end
|
2022-07-10 17:06:25 +00:00
|
|
|
|
|
|
|
test "a misskey MFM status with a content field should work and be linked", _ do
|
2022-07-11 11:48:29 +00:00
|
|
|
local_user =
|
|
|
|
insert(:user, %{nickname: "akkoma_user", ap_id: "http://localhost:4001/users/akkoma_user"})
|
|
|
|
|
|
|
|
remote_user =
|
|
|
|
insert(:user, %{
|
|
|
|
nickname: "remote_user",
|
|
|
|
ap_id: "http://misskey.local.live/users/remote_user"
|
|
|
|
})
|
2022-07-10 17:06:25 +00:00
|
|
|
|
2022-07-11 13:48:43 +00:00
|
|
|
full_tag_remote_user =
|
|
|
|
insert(:user, %{
|
|
|
|
nickname: "full_tag_remote_user",
|
|
|
|
ap_id: "http://misskey.local.live/users/full_tag_remote_user"
|
|
|
|
})
|
|
|
|
|
2022-07-10 17:06:25 +00:00
|
|
|
insert(:user, %{ap_id: "https://misskey.local.live/users/92hzkskwgy"})
|
|
|
|
|
|
|
|
note =
|
|
|
|
"test/fixtures/misskey/mfm_x_format.json"
|
|
|
|
|> File.read!()
|
|
|
|
|> Jason.decode!()
|
|
|
|
|
|
|
|
%{
|
|
|
|
valid?: true,
|
|
|
|
changes: %{
|
2022-07-11 11:48:29 +00:00
|
|
|
content: content,
|
2022-07-10 17:06:25 +00:00
|
|
|
source: %{
|
2022-07-11 11:48:29 +00:00
|
|
|
"content" =>
|
2022-07-11 13:48:43 +00:00
|
|
|
"@akkoma_user @remote_user @full_tag_remote_user@misskey.local.live @oops_not_a_mention linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa",
|
2022-07-10 17:06:25 +00:00
|
|
|
"mediaType" => "text/x.misskeymarkdown"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} = ArticleNotePageValidator.cast_and_validate(note)
|
2022-07-11 11:48:29 +00:00
|
|
|
|
|
|
|
assert content =~
|
|
|
|
"<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{local_user.id}\" href=\"#{local_user.ap_id}\" rel=\"ugc\">@<span>akkoma_user</span></a></span>"
|
|
|
|
|
|
|
|
assert content =~
|
|
|
|
"<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{remote_user.id}\" href=\"#{remote_user.ap_id}\" rel=\"ugc\">@<span>remote_user</span></a></span>"
|
|
|
|
|
2022-07-11 13:48:43 +00:00
|
|
|
assert content =~
|
|
|
|
"<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{full_tag_remote_user.id}\" href=\"#{full_tag_remote_user.ap_id}\" rel=\"ugc\">@<span>full_tag_remote_user</span></a></span>"
|
|
|
|
|
2022-07-11 11:48:29 +00:00
|
|
|
assert content =~ "@oops_not_a_mention"
|
|
|
|
assert content =~ "$[jelly mfm goes here] <br><br>## aaa"
|
2022-07-10 17:06:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "a misskey MFM status with a _misskey_content field should work and be linked", _ do
|
2022-07-11 11:48:29 +00:00
|
|
|
local_user =
|
|
|
|
insert(:user, %{nickname: "akkoma_user", ap_id: "http://localhost:4001/users/akkoma_user"})
|
2022-07-10 17:06:25 +00:00
|
|
|
|
|
|
|
insert(:user, %{ap_id: "https://misskey.local.live/users/92hzkskwgy"})
|
|
|
|
|
|
|
|
note =
|
|
|
|
"test/fixtures/misskey/mfm_underscore_format.json"
|
|
|
|
|> File.read!()
|
|
|
|
|> Jason.decode!()
|
|
|
|
|
|
|
|
expected_content =
|
|
|
|
"<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{local_user.id}\" href=\"#{local_user.ap_id}\" rel=\"ugc\">@<span>akkoma_user</span></a></span> linkifylink <a class=\"hashtag\" data-tag=\"dancedance\" href=\"http://localhost:4001/tag/dancedance\" rel=\"tag ugc\">#dancedance</a> $[jelly mfm goes here] <br><br>## aaa"
|
|
|
|
|
|
|
|
%{
|
|
|
|
valid?: true,
|
|
|
|
changes: %{
|
|
|
|
content: ^expected_content,
|
|
|
|
source: %{
|
|
|
|
"content" => "@akkoma_user linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa",
|
|
|
|
"mediaType" => "text/x.misskeymarkdown"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} = ArticleNotePageValidator.cast_and_validate(note)
|
|
|
|
end
|
2022-07-25 16:30:06 +00:00
|
|
|
|
|
|
|
test "a misskey quote should work", _ do
|
|
|
|
Tesla.Mock.mock(fn %{
|
|
|
|
method: :get,
|
|
|
|
url: "https://example.com/objects/43479e20-c0f8-4f49-bf7f-13fab8234924"
|
|
|
|
} ->
|
|
|
|
%Tesla.Env{
|
|
|
|
status: 200,
|
|
|
|
body: File.read!("test/fixtures/quoted_status.json"),
|
|
|
|
headers: HttpRequestMock.activitypub_object_headers()
|
|
|
|
}
|
|
|
|
end)
|
|
|
|
|
|
|
|
insert(:user, %{ap_id: "https://misskey.io/users/93492q0ip0"})
|
|
|
|
insert(:user, %{ap_id: "https://example.com/users/user"})
|
|
|
|
|
|
|
|
note =
|
|
|
|
"test/fixtures/misskey/quote.json"
|
|
|
|
|> File.read!()
|
|
|
|
|> Jason.decode!()
|
|
|
|
|
|
|
|
%{
|
|
|
|
valid?: true,
|
|
|
|
changes: %{
|
|
|
|
quoteUri: "https://example.com/objects/43479e20-c0f8-4f49-bf7f-13fab8234924"
|
|
|
|
}
|
|
|
|
} = ArticleNotePageValidator.cast_and_validate(note)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "a fedibird quote should work", _ do
|
|
|
|
Tesla.Mock.mock(fn %{
|
|
|
|
method: :get,
|
|
|
|
url: "https://example.com/objects/43479e20-c0f8-4f49-bf7f-13fab8234924"
|
|
|
|
} ->
|
|
|
|
%Tesla.Env{
|
|
|
|
status: 200,
|
|
|
|
body: File.read!("test/fixtures/quoted_status.json"),
|
|
|
|
headers: HttpRequestMock.activitypub_object_headers()
|
|
|
|
}
|
|
|
|
end)
|
|
|
|
|
|
|
|
insert(:user, %{ap_id: "https://fedibird.com/users/akkoma_ap_integration_tester"})
|
|
|
|
insert(:user, %{ap_id: "https://example.com/users/user"})
|
|
|
|
|
|
|
|
note =
|
|
|
|
"test/fixtures/fedibird/quote.json"
|
|
|
|
|> File.read!()
|
|
|
|
|> Jason.decode!()
|
|
|
|
|
|
|
|
%{
|
|
|
|
valid?: true,
|
|
|
|
changes: %{
|
|
|
|
quoteUri: "https://example.com/objects/43479e20-c0f8-4f49-bf7f-13fab8234924"
|
|
|
|
}
|
|
|
|
} = ArticleNotePageValidator.cast_and_validate(note)
|
|
|
|
end
|
2019-11-05 14:02:31 +00:00
|
|
|
end
|
|
|
|
end
|