:ok
end
+ clear_config([:instance, :account_activation_required])
+
describe "when tags are nil" do
test "tagging a user" do
user = insert(:user, %{tags: nil})
assert activity
end
+ test "clears follow requests when requester is blocked" do
+ followed = insert(:user, %{info: %{locked: true}})
+ follower = insert(:user)
+
+ CommonAPI.follow(follower, followed)
+ assert {:ok, [_activity]} = User.get_follow_requests(followed)
+
+ {:ok, _follower} = User.block(followed, follower)
+ assert {:ok, []} = User.get_follow_requests(followed)
+ end
+
test "follow_all follows mutliple users" do
user = insert(:user)
followed_zero = insert(:user)
# assert websub
# end
- test "unfollow takes a user and another user" do
- followed = insert(:user)
- user = insert(:user, %{following: [User.ap_followers(followed)]})
+ describe "unfollow/2" do
+ setup do
+ setting = Pleroma.Config.get([:instance, :external_user_synchronization])
- {:ok, user, _activity} = User.unfollow(user, followed)
+ on_exit(fn ->
+ Pleroma.Config.put([:instance, :external_user_synchronization], setting)
+ end)
- user = User.get_cached_by_id(user.id)
+ :ok
+ end
- assert user.following == []
- end
+ test "unfollow with syncronizes external user" do
+ Pleroma.Config.put([:instance, :external_user_synchronization], true)
- test "unfollow doesn't unfollow yourself" do
- user = insert(:user)
+ followed =
+ insert(:user,
+ nickname: "fuser1",
+ follower_address: "http://localhost:4001/users/fuser1/followers",
+ following_address: "http://localhost:4001/users/fuser1/following",
+ ap_id: "http://localhost:4001/users/fuser1"
+ )
- {:error, _} = User.unfollow(user, user)
+ user =
+ insert(:user, %{
+ local: false,
+ nickname: "fuser2",
+ ap_id: "http://localhost:4001/users/fuser2",
+ follower_address: "http://localhost:4001/users/fuser2/followers",
+ following_address: "http://localhost:4001/users/fuser2/following",
+ following: [User.ap_followers(followed)]
+ })
- user = User.get_cached_by_id(user.id)
- assert user.following == [user.ap_id]
+ {:ok, user, _activity} = User.unfollow(user, followed)
+
+ user = User.get_cached_by_id(user.id)
+
+ assert user.following == []
+ end
+
+ test "unfollow takes a user and another user" do
+ followed = insert(:user)
+ user = insert(:user, %{following: [User.ap_followers(followed)]})
+
+ {:ok, user, _activity} = User.unfollow(user, followed)
+
+ user = User.get_cached_by_id(user.id)
+
+ assert user.following == []
+ end
+
+ test "unfollow doesn't unfollow yourself" do
+ user = insert(:user)
+
+ {:error, _} = User.unfollow(user, user)
+
+ user = User.get_cached_by_id(user.id)
+ assert user.following == [user.ap_id]
+ end
end
test "test if a user is following another user" do
password_confirmation: "test",
email: "email@example.com"
}
+ clear_config([:instance, :autofollowed_nicknames])
+ clear_config([:instance, :welcome_message])
+ clear_config([:instance, :welcome_user_nickname])
test "it autofollows accounts that are set for it" do
user = insert(:user)
assert User.following?(registered_user, user)
refute User.following?(registered_user, remote_user)
-
- Pleroma.Config.put([:instance, :autofollowed_nicknames], [])
end
test "it sends a welcome message if it is set" do
assert registered_user.ap_id in activity.recipients
assert Object.normalize(activity).data["content"] =~ "cool site"
assert activity.actor == welcome_user.ap_id
-
- Pleroma.Config.put([:instance, :welcome_user_nickname], nil)
- Pleroma.Config.put([:instance, :welcome_message], nil)
end
test "it requires an email, name, nickname and password, bio is optional" do
email: "email@example.com"
}
- setup do
- setting = Pleroma.Config.get([:instance, :account_activation_required])
-
- unless setting do
- Pleroma.Config.put([:instance, :account_activation_required], true)
- on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
- end
-
- :ok
+ clear_config([:instance, :account_activation_required]) do
+ Pleroma.Config.put([:instance, :account_activation_required], true)
end
test "it creates unconfirmed user" do
avatar: %{some: "avatar"}
}
+ clear_config([:instance, :user_bio_length])
+ clear_config([:instance, :user_name_length])
+
test "it confirms validity" do
cs = User.remote_user_creation(@valid_remote)
assert cs.valid?
refute cs.valid?
end)
end
-
- test "it restricts some sizes" do
- [bio: 5000, name: 100]
- |> Enum.each(fn {field, size} ->
- string = String.pad_leading(".", size)
- cs = User.remote_user_creation(Map.put(@valid_remote, field, string))
- assert cs.valid?
-
- string = String.pad_leading(".", size + 1)
- cs = User.remote_user_creation(Map.put(@valid_remote, field, string))
- refute cs.valid?
- end)
- end
end
describe "followers and friends" do
[user: user]
end
+ clear_config([:instance, :federating])
+
test ".delete_user_activities deletes all create activities", %{user: user} do
{:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
end
test "it deletes deactivated user" do
- admin = insert(:user, %{info: %{is_admin: true}})
{:ok, user} = insert(:user, info: %{deactivated: true}) |> User.set_cache()
- assert {:ok, _} = User.delete(user, admin.ap_id)
+ assert {:ok, _} = User.delete(user)
refute User.get_by_id(user.id)
end
Pleroma.Web.ActivityPub.Publisher,
[:passthrough],
[] do
- config_path = [:instance, :federating]
- initial_setting = Pleroma.Config.get(config_path)
- Pleroma.Config.put(config_path, true)
+ Pleroma.Config.put([:instance, :federating], true)
{:ok, follower} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
{:ok, _} = User.follow(follower, user)
inbox: "http://mastodon.example.org/inbox"
})
)
-
- Pleroma.Config.put(config_path, initial_setting)
end
end
assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
end
- test "insert or update a user from given data" do
- user = insert(:user, %{nickname: "nick@name.de"})
- data = %{ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname}
+ describe "insert or update a user from given data" do
+ test "with normal data" do
+ user = insert(:user, %{nickname: "nick@name.de"})
+ data = %{ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname}
+
+ assert {:ok, %User{}} = User.insert_or_update_user(data)
+ end
+
+ test "with overly long fields" do
+ current_max_length = Pleroma.Config.get([:instance, :account_field_value_length], 255)
+ user = insert(:user, nickname: "nickname@supergood.domain")
- assert {:ok, %User{}} = User.insert_or_update_user(data)
+ data = %{
+ ap_id: user.ap_id,
+ name: user.name,
+ nickname: user.nickname,
+ info: %{
+ fields: [
+ %{"name" => "myfield", "value" => String.duplicate("h", current_max_length + 1)}
+ ]
+ }
+ }
+
+ assert {:ok, %User{}} = User.insert_or_update_user(data)
+ end
+
+ test "with an overly long bio" do
+ current_max_length = Pleroma.Config.get([:instance, :user_bio_length], 5000)
+ user = insert(:user, nickname: "nickname@supergood.domain")
+
+ data = %{
+ ap_id: user.ap_id,
+ name: user.name,
+ nickname: user.nickname,
+ bio: String.duplicate("h", current_max_length + 1),
+ info: %{}
+ }
+
+ assert {:ok, %User{}} = User.insert_or_update_user(data)
+ end
+
+ test "with an overly long display name" do
+ current_max_length = Pleroma.Config.get([:instance, :user_name_length], 100)
+ user = insert(:user, nickname: "nickname@supergood.domain")
+
+ data = %{
+ ap_id: user.ap_id,
+ name: String.duplicate("h", current_max_length + 1),
+ nickname: user.nickname,
+ info: %{}
+ }
+
+ assert {:ok, %User{}} = User.insert_or_update_user(data)
+ end
end
describe "per-user rich-text filtering" do
refute User.auth_active?(local_user)
assert User.auth_active?(confirmed_user)
assert User.auth_active?(remote_user)
-
- Pleroma.Config.put([:instance, :account_activation_required], false)
end
describe "superuser?/1" do
other_user = insert(:user, local: true)
refute User.visible_for?(user, other_user)
-
- Pleroma.Config.put([:instance, :account_activation_required], false)
end
test "returns true when the account is unauthenticated and auth is not required" do
other_user = insert(:user, local: true, info: %{is_admin: true})
assert User.visible_for?(user, other_user)
-
- Pleroma.Config.put([:instance, :account_activation_required], false)
end
end
end
test "Adds rel=me on linkbacked urls" do
- user = insert(:user, ap_id: "http://social.example.org/users/lain")
+ user = insert(:user, ap_id: "https://social.example.org/users/lain")
- bio = "http://example.org/rel_me/null"
+ bio = "http://example.com/rel_me/null"
expected_text = "<a href=\"#{bio}\">#{bio}</a>"
assert expected_text == User.parse_bio(bio, user)
- bio = "http://example.org/rel_me/link"
- expected_text = "<a href=\"#{bio}\">#{bio}</a>"
+ bio = "http://example.com/rel_me/link"
+ expected_text = "<a href=\"#{bio}\" rel=\"me\">#{bio}</a>"
assert expected_text == User.parse_bio(bio, user)
- bio = "http://example.org/rel_me/anchor"
- expected_text = "<a href=\"#{bio}\">#{bio}</a>"
+ bio = "http://example.com/rel_me/anchor"
+ expected_text = "<a href=\"#{bio}\" rel=\"me\">#{bio}</a>"
assert expected_text == User.parse_bio(bio, user)
end
end
end
describe "following/followers synchronization" do
- setup do
- sync = Pleroma.Config.get([:instance, :external_user_synchronization])
- on_exit(fn -> Pleroma.Config.put([:instance, :external_user_synchronization], sync) end)
- end
+ clear_config([:instance, :external_user_synchronization])
test "updates the counters normally on following/getting a follow when disabled" do
Pleroma.Config.put([:instance, :external_user_synchronization], false)