describe "unfollow/2" do
setup do: clear_config([:instance, :external_user_synchronization])
- test "unfollow with syncronizes external user" do
+ test "unfollow with synchronizes external user" do
clear_config([:instance, :external_user_synchronization], true)
followed =
end
setup do:
- clear_config(:mrf_simple,
- media_removal: [],
- media_nsfw: [],
- federated_timeline_removal: [],
- report_removal: [],
- reject: [],
- followers_only: [],
- accept: [],
- avatar_removal: [],
- banner_removal: [],
- reject_deletes: []
+ clear_config(
+ [:mrf_simple],
+ %{
+ media_removal: [],
+ media_nsfw: [],
+ federated_timeline_removal: [],
+ report_removal: [],
+ reject: [],
+ followers_only: [],
+ accept: [],
+ avatar_removal: [],
+ banner_removal: [],
+ reject_deletes: []
+ }
)
setup do:
assert changeset.valid?
end
- test "it sets the password_hash and ap_id" do
+ test "it sets the password_hash, ap_id, private key and followers collection address" do
changeset = User.register_changeset(%User{}, @full_user_data)
assert changeset.valid?
assert is_binary(changeset.changes[:password_hash])
+ assert is_binary(changeset.changes[:keys])
assert changeset.changes[:ap_id] == User.ap_id(%User{nickname: @full_user_data.nickname})
-
+ assert is_binary(changeset.changes[:keys])
assert changeset.changes.follower_address == "#{changeset.changes.ap_id}/followers"
end
freshed_user = refresh_record(user)
assert freshed_user == fetched_user
end
+
+ test "gets an existing user by nickname starting with http" do
+ user = insert(:user, nickname: "httpssome")
+ {:ok, fetched_user} = User.get_or_fetch("httpssome")
+
+ assert user == fetched_user
+ end
+ end
+
+ describe "get_or_fetch/1 remote users with tld, while BE is runned on subdomain" do
+ setup do: clear_config([Pleroma.Web.WebFinger, :update_nickname_on_user_fetch], true)
+
+ test "for mastodon" do
+ Tesla.Mock.mock(fn
+ %{url: "https://example.com/.well-known/host-meta"} ->
+ %Tesla.Env{
+ status: 302,
+ headers: [{"location", "https://sub.example.com/.well-known/host-meta"}]
+ }
+
+ %{url: "https://sub.example.com/.well-known/host-meta"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/masto-host-meta.xml"
+ |> File.read!()
+ |> String.replace("{{domain}}", "sub.example.com")
+ }
+
+ %{url: "https://sub.example.com/.well-known/webfinger?resource=acct:a@example.com"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/masto-webfinger.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", "a")
+ |> String.replace("{{domain}}", "example.com")
+ |> String.replace("{{subdomain}}", "sub.example.com"),
+ headers: [{"content-type", "application/jrd+json"}]
+ }
+
+ %{url: "https://sub.example.com/users/a"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/masto-user.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", "a")
+ |> String.replace("{{domain}}", "sub.example.com"),
+ headers: [{"content-type", "application/activity+json"}]
+ }
+
+ %{url: "https://sub.example.com/users/a/collections/featured"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ File.read!("test/fixtures/users_mock/masto_featured.json")
+ |> String.replace("{{domain}}", "sub.example.com")
+ |> String.replace("{{nickname}}", "a"),
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ ap_id = "a@example.com"
+ {:ok, fetched_user} = User.get_or_fetch(ap_id)
+
+ assert fetched_user.ap_id == "https://sub.example.com/users/a"
+ assert fetched_user.nickname == "a@example.com"
+ end
+
+ test "for pleroma" do
+ Tesla.Mock.mock(fn
+ %{url: "https://example.com/.well-known/host-meta"} ->
+ %Tesla.Env{
+ status: 302,
+ headers: [{"location", "https://sub.example.com/.well-known/host-meta"}]
+ }
+
+ %{url: "https://sub.example.com/.well-known/host-meta"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/pleroma-host-meta.xml"
+ |> File.read!()
+ |> String.replace("{{domain}}", "sub.example.com")
+ }
+
+ %{url: "https://sub.example.com/.well-known/webfinger?resource=acct:a@example.com"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/pleroma-webfinger.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", "a")
+ |> String.replace("{{domain}}", "example.com")
+ |> String.replace("{{subdomain}}", "sub.example.com"),
+ headers: [{"content-type", "application/jrd+json"}]
+ }
+
+ %{url: "https://sub.example.com/users/a"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/pleroma-user.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", "a")
+ |> String.replace("{{domain}}", "sub.example.com"),
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ ap_id = "a@example.com"
+ {:ok, fetched_user} = User.get_or_fetch(ap_id)
+
+ assert fetched_user.ap_id == "https://sub.example.com/users/a"
+ assert fetched_user.nickname == "a@example.com"
+ end
end
describe "fetching a user from nickname or trying to build one" do
assert user.last_refreshed_at == orig_user.last_refreshed_at
end
+
+ test "it doesn't fail on invalid alsoKnownAs entries" do
+ Tesla.Mock.mock(fn
+ %{url: "https://mbp.example.com/"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/microblogpub/user_with_invalid_also_known_as.json"
+ |> File.read!(),
+ headers: [{"content-type", "application/activity+json"}]
+ }
+
+ _ ->
+ %Tesla.Env{status: 404}
+ end)
+
+ assert {:ok, %User{also_known_as: []}} =
+ User.get_or_fetch_by_ap_id("https://mbp.example.com/")
+ end
end
test "returns an ap_id for a user" do
collateral_user =
insert(:user, %{ap_id: "https://another-awful-and-rude-instance.com/user/bully"})
- {:ok, user} = User.block_domain(user, "*.awful-and-rude-instance.com")
+ {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
refute User.blocks?(user, collateral_user)
end
user_domain = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
- {:ok, user} = User.block_domain(user, "*.awful-and-rude-instance.com")
+ {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
assert User.blocks?(user, user_from_subdomain)
assert User.blocks?(user, user_with_two_subdomains)
end
end
- describe "ensure_keys_present" do
- test "it creates keys for a user and stores them in info" do
- user = insert(:user)
- refute is_binary(user.keys)
- {:ok, user} = User.ensure_keys_present(user)
- assert is_binary(user.keys)
- end
-
- test "it doesn't create keys if there already are some" do
- user = insert(:user, keys: "xxx")
- {:ok, user} = User.ensure_keys_present(user)
- assert user.keys == "xxx"
- end
- end
-
describe "get_ap_ids_by_nicknames" do
test "it returns a list of AP ids for a given set of nicknames" do
user = insert(:user)
assert other_user.follower_count == 1
end
- test "syncronizes the counters with the remote instance for the followed when enabled" do
+ test "synchronizes the counters with the remote instance for the followed when enabled" do
clear_config([:instance, :external_user_synchronization], false)
user = insert(:user)
assert other_user.follower_count == 437
end
- test "syncronizes the counters with the remote instance for the follower when enabled" do
+ test "synchronizes the counters with the remote instance for the follower when enabled" do
clear_config([:instance, :external_user_synchronization], false)
user = insert(:user)