Merge branch 'develop' into issue/1342
This commit is contained in:
commit
3fe7a1fd35
36 changed files with 563 additions and 84 deletions
|
|
@ -9,7 +9,11 @@
|
|||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"Emoji": "toot:Emoji"
|
||||
"Emoji": "toot:Emoji",
|
||||
"alsoKnownAs": {
|
||||
"@id": "as:alsoKnownAs",
|
||||
"@type": "@id"
|
||||
}
|
||||
}],
|
||||
"id": "http://mastodon.example.org/users/admin",
|
||||
"type": "Person",
|
||||
|
|
@ -50,5 +54,6 @@
|
|||
"type": "Image",
|
||||
"mediaType": "image/png",
|
||||
"url": "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
|
||||
}
|
||||
},
|
||||
"alsoKnownAs": ["http://example.org/users/foo"]
|
||||
}
|
||||
|
|
|
|||
19
test/fixtures/users_mock/friendica_followers.json
vendored
Normal file
19
test/fixtures/users_mock/friendica_followers.json
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"vcard": "http://www.w3.org/2006/vcard/ns#",
|
||||
"dfrn": "http://purl.org/macgirvin/dfrn/1.0/",
|
||||
"diaspora": "https://diasporafoundation.org/ns/",
|
||||
"litepub": "http://litepub.social/ns#",
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"sensitive": "as:sensitive",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"directMessage": "litepub:directMessage"
|
||||
}
|
||||
],
|
||||
"id": "http://localhost:8080/followers/fuser3",
|
||||
"type": "OrderedCollection",
|
||||
"totalItems": 296
|
||||
}
|
||||
19
test/fixtures/users_mock/friendica_following.json
vendored
Normal file
19
test/fixtures/users_mock/friendica_following.json
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"vcard": "http://www.w3.org/2006/vcard/ns#",
|
||||
"dfrn": "http://purl.org/macgirvin/dfrn/1.0/",
|
||||
"diaspora": "https://diasporafoundation.org/ns/",
|
||||
"litepub": "http://litepub.social/ns#",
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"sensitive": "as:sensitive",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"directMessage": "litepub:directMessage"
|
||||
}
|
||||
],
|
||||
"id": "http://localhost:8080/following/fuser3",
|
||||
"type": "OrderedCollection",
|
||||
"totalItems": 32
|
||||
}
|
||||
|
|
@ -228,5 +228,16 @@ defmodule Pleroma.HTMLTest do
|
|||
|
||||
assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
|
||||
end
|
||||
|
||||
test "does not crash when there is an HTML entity in a link" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{"status" => "\"http://cofe.com/?boomer=ok&foo=bar\""})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert {:ok, nil} = HTML.extract_first_external_url(object, object.data["content"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -642,6 +642,35 @@ defmodule Pleroma.NotificationTest do
|
|||
|
||||
assert Enum.empty?(Notification.for_user(local_user))
|
||||
end
|
||||
|
||||
test "move activity generates a notification" do
|
||||
%{ap_id: old_ap_id} = old_user = insert(:user)
|
||||
%{ap_id: new_ap_id} = new_user = insert(:user, also_known_as: [old_ap_id])
|
||||
follower = insert(:user)
|
||||
other_follower = insert(:user, %{allow_following_move: false})
|
||||
|
||||
User.follow(follower, old_user)
|
||||
User.follow(other_follower, old_user)
|
||||
|
||||
Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert [
|
||||
%{
|
||||
activity: %{
|
||||
data: %{"type" => "Move", "actor" => ^old_ap_id, "target" => ^new_ap_id}
|
||||
}
|
||||
}
|
||||
] = Notification.for_user(follower)
|
||||
|
||||
assert [
|
||||
%{
|
||||
activity: %{
|
||||
data: %{"type" => "Move", "actor" => ^old_ap_id, "target" => ^new_ap_id}
|
||||
}
|
||||
}
|
||||
] = Notification.for_user(other_follower)
|
||||
end
|
||||
end
|
||||
|
||||
describe "for_user" do
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ defmodule Pleroma.Factory do
|
|||
nickname: sequence(:nickname, &"nick#{&1}"),
|
||||
password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
|
||||
bio: sequence(:bio, &"Tester Number #{&1}"),
|
||||
info: %{},
|
||||
last_digest_emailed_at: NaiveDateTime.utc_now(),
|
||||
notification_settings: %Pleroma.User.NotificationSetting{}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1035,6 +1035,22 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("http://localhost:8080/followers/fuser3", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/users_mock/friendica_followers.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("http://localhost:8080/following/fuser3", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/users_mock/friendica_following.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
|
|
|||
|
|
@ -367,18 +367,6 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
assert changeset.changes.follower_address == "#{changeset.changes.ap_id}/followers"
|
||||
end
|
||||
|
||||
test "it ensures info is not nil" do
|
||||
changeset = User.register_changeset(%User{}, @full_user_data)
|
||||
|
||||
assert changeset.valid?
|
||||
|
||||
{:ok, user} =
|
||||
changeset
|
||||
|> Repo.insert()
|
||||
|
||||
refute is_nil(user.info)
|
||||
end
|
||||
end
|
||||
|
||||
describe "user registration, with :account_activation_required" do
|
||||
|
|
@ -432,8 +420,7 @@ defmodule Pleroma.UserTest do
|
|||
:user,
|
||||
local: false,
|
||||
nickname: "admin@mastodon.example.org",
|
||||
ap_id: ap_id,
|
||||
info: %{}
|
||||
ap_id: ap_id
|
||||
)
|
||||
|
||||
{:ok, fetched_user} = User.get_or_fetch(ap_id)
|
||||
|
|
@ -494,8 +481,7 @@ defmodule Pleroma.UserTest do
|
|||
local: false,
|
||||
nickname: "admin@mastodon.example.org",
|
||||
ap_id: "http://mastodon.example.org/users/admin",
|
||||
last_refreshed_at: a_week_ago,
|
||||
info: %{}
|
||||
last_refreshed_at: a_week_ago
|
||||
)
|
||||
|
||||
assert orig_user.last_refreshed_at == a_week_ago
|
||||
|
|
@ -536,7 +522,6 @@ defmodule Pleroma.UserTest do
|
|||
name: "Someone",
|
||||
nickname: "a@b.de",
|
||||
ap_id: "http...",
|
||||
info: %{some: "info"},
|
||||
avatar: %{some: "avatar"}
|
||||
}
|
||||
|
||||
|
|
@ -1143,8 +1128,7 @@ defmodule Pleroma.UserTest do
|
|||
ap_id: user.ap_id,
|
||||
name: user.name,
|
||||
nickname: user.nickname,
|
||||
bio: String.duplicate("h", current_max_length + 1),
|
||||
info: %{}
|
||||
bio: String.duplicate("h", current_max_length + 1)
|
||||
}
|
||||
|
||||
assert {:ok, %User{}} = User.insert_or_update_user(data)
|
||||
|
|
@ -1157,8 +1141,7 @@ defmodule Pleroma.UserTest do
|
|||
data = %{
|
||||
ap_id: user.ap_id,
|
||||
name: String.duplicate("h", current_max_length + 1),
|
||||
nickname: user.nickname,
|
||||
info: %{}
|
||||
nickname: user.nickname
|
||||
}
|
||||
|
||||
assert {:ok, %User{}} = User.insert_or_update_user(data)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,11 @@
|
|||
|
||||
defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
||||
use Pleroma.DataCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Builders.ActivityBuilder
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
|
|
@ -1554,5 +1557,80 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert follow_info.hide_followers == false
|
||||
assert follow_info.hide_follows == true
|
||||
end
|
||||
|
||||
test "detects hidden follows/followers for friendica" do
|
||||
user =
|
||||
insert(:user,
|
||||
local: false,
|
||||
follower_address: "http://localhost:8080/followers/fuser3",
|
||||
following_address: "http://localhost:8080/following/fuser3"
|
||||
)
|
||||
|
||||
{:ok, follow_info} = ActivityPub.fetch_follow_information_for_user(user)
|
||||
assert follow_info.hide_followers == true
|
||||
assert follow_info.follower_count == 296
|
||||
assert follow_info.following_count == 32
|
||||
assert follow_info.hide_follows == true
|
||||
end
|
||||
end
|
||||
|
||||
describe "Move activity" do
|
||||
test "create" do
|
||||
%{ap_id: old_ap_id} = old_user = insert(:user)
|
||||
%{ap_id: new_ap_id} = new_user = insert(:user, also_known_as: [old_ap_id])
|
||||
follower = insert(:user)
|
||||
follower_move_opted_out = insert(:user, allow_following_move: false)
|
||||
|
||||
User.follow(follower, old_user)
|
||||
User.follow(follower_move_opted_out, old_user)
|
||||
|
||||
assert User.following?(follower, old_user)
|
||||
assert User.following?(follower_move_opted_out, old_user)
|
||||
|
||||
assert {:ok, activity} = ActivityPub.move(old_user, new_user)
|
||||
|
||||
assert %Activity{
|
||||
actor: ^old_ap_id,
|
||||
data: %{
|
||||
"actor" => ^old_ap_id,
|
||||
"object" => ^old_ap_id,
|
||||
"target" => ^new_ap_id,
|
||||
"type" => "Move"
|
||||
},
|
||||
local: true
|
||||
} = activity
|
||||
|
||||
params = %{
|
||||
"op" => "move_following",
|
||||
"origin_id" => old_user.id,
|
||||
"target_id" => new_user.id
|
||||
}
|
||||
|
||||
assert_enqueued(worker: Pleroma.Workers.BackgroundWorker, args: params)
|
||||
|
||||
Pleroma.Workers.BackgroundWorker.perform(params, nil)
|
||||
|
||||
refute User.following?(follower, old_user)
|
||||
assert User.following?(follower, new_user)
|
||||
|
||||
assert User.following?(follower_move_opted_out, old_user)
|
||||
refute User.following?(follower_move_opted_out, new_user)
|
||||
|
||||
activity = %Activity{activity | object: nil}
|
||||
|
||||
assert [%Notification{activity: ^activity}] =
|
||||
Notification.for_user_since(follower, ~N[2019-04-13 11:22:33])
|
||||
|
||||
assert [%Notification{activity: ^activity}] =
|
||||
Notification.for_user_since(follower_move_opted_out, ~N[2019-04-13 11:22:33])
|
||||
end
|
||||
|
||||
test "old user must be in the new user's `also_known_as` list" do
|
||||
old_user = insert(:user)
|
||||
new_user = insert(:user)
|
||||
|
||||
assert {:error, "Target account must have the origin in `alsoKnownAs`"} =
|
||||
ActivityPub.move(old_user, new_user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -683,6 +683,37 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert user.bio == "<p>Some bio</p>"
|
||||
end
|
||||
|
||||
test "it works with alsoKnownAs" do
|
||||
{:ok, %Activity{data: %{"actor" => actor}}} =
|
||||
"test/fixtures/mastodon-post-activity.json"
|
||||
|> File.read!()
|
||||
|> Poison.decode!()
|
||||
|> Transmogrifier.handle_incoming()
|
||||
|
||||
assert User.get_cached_by_ap_id(actor).also_known_as == ["http://example.org/users/foo"]
|
||||
|
||||
{:ok, _activity} =
|
||||
"test/fixtures/mastodon-update.json"
|
||||
|> File.read!()
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", actor)
|
||||
|> Map.update!("object", fn object ->
|
||||
object
|
||||
|> Map.put("actor", actor)
|
||||
|> Map.put("id", actor)
|
||||
|> Map.put("alsoKnownAs", [
|
||||
"http://mastodon.example.org/users/foo",
|
||||
"http://example.org/users/bar"
|
||||
])
|
||||
end)
|
||||
|> Transmogrifier.handle_incoming()
|
||||
|
||||
assert User.get_cached_by_ap_id(actor).also_known_as == [
|
||||
"http://mastodon.example.org/users/foo",
|
||||
"http://example.org/users/bar"
|
||||
]
|
||||
end
|
||||
|
||||
test "it works with custom profile fields" do
|
||||
{:ok, activity} =
|
||||
"test/fixtures/mastodon-post-activity.json"
|
||||
|
|
@ -1272,6 +1303,30 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["cc"]
|
||||
assert [user.follower_address] == activity.data["to"]
|
||||
end
|
||||
|
||||
test "it accepts Move activities" do
|
||||
old_user = insert(:user)
|
||||
new_user = insert(:user)
|
||||
|
||||
message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"type" => "Move",
|
||||
"actor" => old_user.ap_id,
|
||||
"object" => old_user.ap_id,
|
||||
"target" => new_user.ap_id
|
||||
}
|
||||
|
||||
assert :error = Transmogrifier.handle_incoming(message)
|
||||
|
||||
{:ok, _new_user} = User.update_and_set_cache(new_user, %{also_known_as: [old_user.ap_id]})
|
||||
|
||||
assert {:ok, %Activity{} = activity} = Transmogrifier.handle_incoming(message)
|
||||
assert activity.actor == old_user.ap_id
|
||||
assert activity.data["actor"] == old_user.ap_id
|
||||
assert activity.data["object"] == old_user.ap_id
|
||||
assert activity.data["target"] == new_user.ap_id
|
||||
assert activity.data["type"] == "Move"
|
||||
end
|
||||
end
|
||||
|
||||
describe "prepare outgoing" do
|
||||
|
|
|
|||
|
|
@ -103,6 +103,21 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert user["locked"] == true
|
||||
end
|
||||
|
||||
test "updates the user's allow_following_move", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
assert user.allow_following_move == true
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{allow_following_move: "false"})
|
||||
|
||||
assert refresh_record(user).allow_following_move == false
|
||||
assert user = json_response(conn, 200)
|
||||
assert user["pleroma"]["allow_following_move"] == false
|
||||
end
|
||||
|
||||
test "updates the user's default scope", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
privacy = user.default_scope
|
||||
|
||||
assert %{
|
||||
pleroma: %{notification_settings: ^notification_settings},
|
||||
pleroma: %{notification_settings: ^notification_settings, allow_following_move: true},
|
||||
source: %{privacy: ^privacy}
|
||||
} = AccountView.render("show.json", %{user: user, for: user})
|
||||
end
|
||||
|
|
|
|||
|
|
@ -107,4 +107,31 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
assert [] ==
|
||||
NotificationView.render("index.json", %{notifications: [notification], for: followed})
|
||||
end
|
||||
|
||||
test "Move notification" do
|
||||
%{ap_id: old_ap_id} = old_user = insert(:user)
|
||||
%{ap_id: _new_ap_id} = new_user = insert(:user, also_known_as: [old_ap_id])
|
||||
follower = insert(:user)
|
||||
|
||||
User.follow(follower, old_user)
|
||||
Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)
|
||||
Pleroma.Tests.ObanHelpers.perform_all()
|
||||
|
||||
old_user = refresh_record(old_user)
|
||||
new_user = refresh_record(new_user)
|
||||
|
||||
[notification] = Notification.for_user(follower)
|
||||
|
||||
expected = %{
|
||||
id: to_string(notification.id),
|
||||
pleroma: %{is_seen: false},
|
||||
type: "move",
|
||||
account: AccountView.render("show.json", %{user: old_user, for: follower}),
|
||||
target: AccountView.render("show.json", %{user: new_user, for: follower}),
|
||||
created_at: Utils.to_masto_date(notification.inserted_at)
|
||||
}
|
||||
|
||||
assert [expected] ==
|
||||
NotificationView.render("index.json", %{notifications: [notification], for: follower})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue