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 =
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
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)