Merge branch 'develop' into issue/1276
This commit is contained in:
commit
dfd2c74184
259 changed files with 4072 additions and 2048 deletions
|
|
@ -9,7 +9,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Pleroma.Factory
|
||||
clear_config([:instance, :max_account_fields])
|
||||
|
||||
setup do: clear_config([:instance, :max_account_fields])
|
||||
|
||||
describe "updating credentials" do
|
||||
setup do: oauth_access(["write:accounts"])
|
||||
|
|
@ -75,7 +76,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
|
||||
conn =
|
||||
patch(conn, "/api/v1/accounts/update_credentials", %{
|
||||
"note" => "I drink #cofe with @#{user2.nickname}"
|
||||
"note" => "I drink #cofe with @#{user2.nickname}\n\nsuya.."
|
||||
})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
|
|
@ -83,7 +84,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert user_data["note"] ==
|
||||
~s(I drink <a class="hashtag" data-tag="cofe" href="http://localhost:4001/tag/cofe">#cofe</a> with <span class="h-card"><a data-user="#{
|
||||
user2.id
|
||||
}" class="u-url mention" href="#{user2.ap_id}" rel="ugc">@<span>#{user2.nickname}</span></a></span>)
|
||||
}" class="u-url mention" href="#{user2.ap_id}" rel="ugc">@<span>#{user2.nickname}</span></a></span><br/><br/>suya..)
|
||||
end
|
||||
|
||||
test "updates the user's locking status", %{conn: conn} do
|
||||
|
|
@ -117,6 +118,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert user_data["pleroma"]["hide_followers"] == true
|
||||
end
|
||||
|
||||
test "updates the user's discoverable status", %{conn: conn} do
|
||||
assert %{"source" => %{"pleroma" => %{"discoverable" => true}}} =
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{discoverable: "true"})
|
||||
|> json_response(:ok)
|
||||
|
||||
assert %{"source" => %{"pleroma" => %{"discoverable" => false}}} =
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{discoverable: "false"})
|
||||
|> json_response(:ok)
|
||||
end
|
||||
|
||||
test "updates the user's hide_followers_count and hide_follows_count", %{conn: conn} do
|
||||
conn =
|
||||
patch(conn, "/api/v1/accounts/update_credentials", %{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
|
|
@ -15,7 +16,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
import Pleroma.Factory
|
||||
|
||||
describe "account fetching" do
|
||||
clear_config([:instance, :limit_to_local_content])
|
||||
setup do: clear_config([:instance, :limit_to_local_content])
|
||||
|
||||
test "works by id" do
|
||||
user = insert(:user)
|
||||
|
|
@ -46,7 +47,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
test "works by nickname for remote users" do
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], false)
|
||||
Config.put([:instance, :limit_to_local_content], false)
|
||||
user = insert(:user, nickname: "user@example.com", local: false)
|
||||
|
||||
conn =
|
||||
|
|
@ -58,7 +59,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
test "respects limit_to_local_content == :all for remote user nicknames" do
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], :all)
|
||||
Config.put([:instance, :limit_to_local_content], :all)
|
||||
|
||||
user = insert(:user, nickname: "user@example.com", local: false)
|
||||
|
||||
|
|
@ -70,7 +71,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
test "respects limit_to_local_content == :unauthenticated for remote user nicknames" do
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
|
||||
Config.put([:instance, :limit_to_local_content], :unauthenticated)
|
||||
|
||||
user = insert(:user, nickname: "user@example.com", local: false)
|
||||
reading_user = insert(:user)
|
||||
|
|
@ -140,6 +141,98 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
defp local_and_remote_users do
|
||||
local = insert(:user)
|
||||
remote = insert(:user, local: false)
|
||||
{:ok, local: local, remote: remote}
|
||||
end
|
||||
|
||||
describe "user fetching with restrict unauthenticated profiles for local and remote" do
|
||||
setup do: local_and_remote_users()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Can't find user"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Can't find user"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "user fetching with restrict unauthenticated profiles for local" do
|
||||
setup do: local_and_remote_users()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Can't find user"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "user fetching with restrict unauthenticated profiles for remote" do
|
||||
setup do: local_and_remote_users()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Can't find user"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "user timelines" do
|
||||
setup do: oauth_access(["read:statuses"])
|
||||
|
||||
|
|
@ -293,6 +386,102 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
defp local_and_remote_activities(%{local: local, remote: remote}) do
|
||||
insert(:note_activity, user: local)
|
||||
insert(:note_activity, user: remote, local: false)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "statuses with restrict unauthenticated profiles for local and remote" do
|
||||
setup do: local_and_remote_users()
|
||||
setup :local_and_remote_activities
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Can't find user"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Can't find user"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "statuses with restrict unauthenticated profiles for local" do
|
||||
setup do: local_and_remote_users()
|
||||
setup :local_and_remote_activities
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Can't find user"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "statuses with restrict unauthenticated profiles for remote" do
|
||||
setup do: local_and_remote_users()
|
||||
setup :local_and_remote_activities
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Can't find user"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "followers" do
|
||||
setup do: oauth_access(["read:accounts"])
|
||||
|
||||
|
|
@ -601,6 +790,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
[valid_params: valid_params]
|
||||
end
|
||||
|
||||
setup do: clear_config([:instance, :account_activation_required])
|
||||
|
||||
test "Account registration via Application", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, "/api/v1/apps", %{
|
||||
|
|
@ -685,7 +876,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert json_response(res, 200)
|
||||
|
||||
[{127, 0, 0, 1}, {127, 0, 0, 2}, {127, 0, 0, 3}, {127, 0, 0, 4}]
|
||||
|> Stream.zip(valid_params)
|
||||
|> Stream.zip(Map.delete(valid_params, :email))
|
||||
|> Enum.each(fn {ip, {attr, _}} ->
|
||||
res =
|
||||
conn
|
||||
|
|
@ -697,6 +888,54 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end)
|
||||
end
|
||||
|
||||
setup do: clear_config([:instance, :account_activation_required])
|
||||
|
||||
test "returns bad_request if missing email params when :account_activation_required is enabled",
|
||||
%{conn: conn, valid_params: valid_params} do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
|
||||
app_token = insert(:oauth_token, user: nil)
|
||||
conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> Map.put(:remote_ip, {127, 0, 0, 5})
|
||||
|> post("/api/v1/accounts", Map.delete(valid_params, :email))
|
||||
|
||||
assert json_response(res, 400) == %{"error" => "Missing parameters"}
|
||||
|
||||
res =
|
||||
conn
|
||||
|> Map.put(:remote_ip, {127, 0, 0, 6})
|
||||
|> post("/api/v1/accounts", Map.put(valid_params, :email, ""))
|
||||
|
||||
assert json_response(res, 400) == %{"error" => "{\"email\":[\"can't be blank\"]}"}
|
||||
end
|
||||
|
||||
test "allow registration without an email", %{conn: conn, valid_params: valid_params} do
|
||||
app_token = insert(:oauth_token, user: nil)
|
||||
conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> Map.put(:remote_ip, {127, 0, 0, 7})
|
||||
|> post("/api/v1/accounts", Map.delete(valid_params, :email))
|
||||
|
||||
assert json_response(res, 200)
|
||||
end
|
||||
|
||||
test "allow registration with an empty email", %{conn: conn, valid_params: valid_params} do
|
||||
app_token = insert(:oauth_token, user: nil)
|
||||
conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> Map.put(:remote_ip, {127, 0, 0, 8})
|
||||
|> post("/api/v1/accounts", Map.put(valid_params, :email, ""))
|
||||
|
||||
assert json_response(res, 200)
|
||||
end
|
||||
|
||||
test "returns forbidden if token is invalid", %{conn: conn, valid_params: valid_params} do
|
||||
conn = put_req_header(conn, "authorization", "Bearer " <> "invalid-token")
|
||||
|
||||
|
|
@ -706,13 +945,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
describe "create account by app / rate limit" do
|
||||
clear_config([Pleroma.Plugs.RemoteIp, :enabled]) do
|
||||
Pleroma.Config.put([Pleroma.Plugs.RemoteIp, :enabled], true)
|
||||
end
|
||||
|
||||
clear_config([:rate_limit, :app_account_creation]) do
|
||||
Pleroma.Config.put([:rate_limit, :app_account_creation], {10_000, 2})
|
||||
end
|
||||
setup do: clear_config([:rate_limit, :app_account_creation], {10_000, 2})
|
||||
|
||||
test "respects rate limit setting", %{conn: conn} do
|
||||
app_token = insert(:oauth_token, user: nil)
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
|||
[image: image]
|
||||
end
|
||||
|
||||
clear_config([:media_proxy])
|
||||
clear_config([Pleroma.Upload])
|
||||
setup do: clear_config([:media_proxy])
|
||||
setup do: clear_config([Pleroma.Upload])
|
||||
|
||||
test "returns uploaded image", %{conn: conn, image: image} do
|
||||
desc = "Description of the image"
|
||||
|
|
|
|||
|
|
@ -304,6 +304,51 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200)
|
||||
end
|
||||
|
||||
test "filters notifications using include_types" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:notifications"])
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, mention_activity} = CommonAPI.post(other_user, %{"status" => "hey @#{user.nickname}"})
|
||||
{:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"})
|
||||
{:ok, favorite_activity, _} = CommonAPI.favorite(create_activity.id, other_user)
|
||||
{:ok, reblog_activity, _} = CommonAPI.repeat(create_activity.id, other_user)
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user)
|
||||
|
||||
mention_notification_id = get_notification_id_by_activity(mention_activity)
|
||||
favorite_notification_id = get_notification_id_by_activity(favorite_activity)
|
||||
reblog_notification_id = get_notification_id_by_activity(reblog_activity)
|
||||
follow_notification_id = get_notification_id_by_activity(follow_activity)
|
||||
|
||||
conn_res = get(conn, "/api/v1/notifications", %{include_types: ["follow"]})
|
||||
|
||||
assert [%{"id" => ^follow_notification_id}] = json_response(conn_res, 200)
|
||||
|
||||
conn_res = get(conn, "/api/v1/notifications", %{include_types: ["mention"]})
|
||||
|
||||
assert [%{"id" => ^mention_notification_id}] = json_response(conn_res, 200)
|
||||
|
||||
conn_res = get(conn, "/api/v1/notifications", %{include_types: ["favourite"]})
|
||||
|
||||
assert [%{"id" => ^favorite_notification_id}] = json_response(conn_res, 200)
|
||||
|
||||
conn_res = get(conn, "/api/v1/notifications", %{include_types: ["reblog"]})
|
||||
|
||||
assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200)
|
||||
|
||||
result = conn |> get("/api/v1/notifications") |> json_response(200)
|
||||
|
||||
assert length(result) == 4
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications", %{
|
||||
include_types: ["follow", "mention", "favourite", "reblog"]
|
||||
})
|
||||
|> json_response(200)
|
||||
|
||||
assert length(result) == 4
|
||||
end
|
||||
|
||||
test "destroy multiple" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:notifications", "write:notifications"])
|
||||
other_user = insert(:user)
|
||||
|
|
@ -407,7 +452,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
assert length(json_response(conn, 200)) == 1
|
||||
end
|
||||
|
||||
test "see move notifications with `with_move` parameter" do
|
||||
test "see move notifications" do
|
||||
old_user = insert(:user)
|
||||
new_user = insert(:user, also_known_as: [old_user.ap_id])
|
||||
%{user: follower, conn: conn} = oauth_access(["read:notifications"])
|
||||
|
|
@ -416,11 +461,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)
|
||||
Pleroma.Tests.ObanHelpers.perform_all()
|
||||
|
||||
ret_conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert json_response(ret_conn, 200) == []
|
||||
|
||||
conn = get(conn, "/api/v1/notifications", %{"with_move" => "true"})
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityControllerTest do
|
|||
import Pleroma.Factory
|
||||
import Ecto.Query
|
||||
|
||||
clear_config([ScheduledActivity, :enabled])
|
||||
setup do: clear_config([ScheduledActivity, :enabled])
|
||||
|
||||
test "shows scheduled activities" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:statuses"])
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
clear_config([:instance, :federating])
|
||||
clear_config([:instance, :allow_relay])
|
||||
clear_config([:rich_media, :enabled])
|
||||
setup do: clear_config([:instance, :federating])
|
||||
setup do: clear_config([:instance, :allow_relay])
|
||||
setup do: clear_config([:rich_media, :enabled])
|
||||
|
||||
describe "posting statuses" do
|
||||
setup do: oauth_access(["write:statuses"])
|
||||
|
|
@ -476,6 +476,95 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert id == to_string(activity.id)
|
||||
end
|
||||
|
||||
defp local_and_remote_activities do
|
||||
local = insert(:note_activity)
|
||||
remote = insert(:note_activity, local: false)
|
||||
{:ok, local: local, remote: remote}
|
||||
end
|
||||
|
||||
describe "status with restrict unauthenticated activities for local and remote" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Record not found"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Record not found"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "status with restrict unauthenticated activities for local" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Record not found"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "status with restrict unauthenticated activities for remote" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Record not found"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
test "getting a status that doesn't exist returns 404" do
|
||||
%{conn: conn} = oauth_access(["read:statuses"])
|
||||
activity = insert(:note_activity)
|
||||
|
|
@ -514,6 +603,70 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert [%{"id" => ^id1}, %{"id" => ^id2}] = Enum.sort_by(json_response(conn, :ok), & &1["id"])
|
||||
end
|
||||
|
||||
describe "getting statuses by ids with restricted unauthenticated for local and remote" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
|
||||
|
||||
assert json_response(res_conn, 200) == []
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
|
||||
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting statuses by ids with restricted unauthenticated for local" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
|
||||
|
||||
remote_id = remote.id
|
||||
assert [%{"id" => ^remote_id}] = json_response(res_conn, 200)
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
|
||||
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting statuses by ids with restricted unauthenticated for remote" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
|
||||
|
||||
local_id = local.id
|
||||
assert [%{"id" => ^local_id}] = json_response(res_conn, 200)
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
|
||||
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "deleting a status" do
|
||||
test "when you created it" do
|
||||
%{user: author, conn: conn} = oauth_access(["write:statuses"])
|
||||
|
|
@ -739,9 +892,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
%{activity: activity}
|
||||
end
|
||||
|
||||
clear_config([:instance, :max_pinned_statuses]) do
|
||||
Config.put([:instance, :max_pinned_statuses], 1)
|
||||
end
|
||||
setup do: clear_config([:instance, :max_pinned_statuses], 1)
|
||||
|
||||
test "pin status", %{conn: conn, user: user, activity: activity} do
|
||||
id_str = to_string(activity.id)
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
clear_config([:instance, :public])
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
|
@ -23,9 +21,12 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
setup do: oauth_access(["read:statuses"])
|
||||
|
||||
test "the home timeline", %{user: user, conn: conn} do
|
||||
following = insert(:user)
|
||||
following = insert(:user, nickname: "followed")
|
||||
third_user = insert(:user, nickname: "repeated")
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
|
||||
{:ok, _activity} = CommonAPI.post(following, %{"status" => "post"})
|
||||
{:ok, activity} = CommonAPI.post(third_user, %{"status" => "repeated post"})
|
||||
{:ok, _, _} = CommonAPI.repeat(activity.id, following)
|
||||
|
||||
ret_conn = get(conn, "/api/v1/timelines/home")
|
||||
|
||||
|
|
@ -33,9 +34,54 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
|
||||
{:ok, _user} = User.follow(user, following)
|
||||
|
||||
conn = get(conn, "/api/v1/timelines/home")
|
||||
ret_conn = get(conn, "/api/v1/timelines/home")
|
||||
|
||||
assert [%{"content" => "test"}] = json_response(conn, :ok)
|
||||
assert [
|
||||
%{
|
||||
"reblog" => %{
|
||||
"content" => "repeated post",
|
||||
"account" => %{
|
||||
"pleroma" => %{
|
||||
"relationship" => %{"following" => false, "followed_by" => false}
|
||||
}
|
||||
}
|
||||
},
|
||||
"account" => %{"pleroma" => %{"relationship" => %{"following" => true}}}
|
||||
},
|
||||
%{
|
||||
"content" => "post",
|
||||
"account" => %{
|
||||
"acct" => "followed",
|
||||
"pleroma" => %{"relationship" => %{"following" => true}}
|
||||
}
|
||||
}
|
||||
] = json_response(ret_conn, :ok)
|
||||
|
||||
{:ok, _user} = User.follow(third_user, user)
|
||||
|
||||
ret_conn = get(conn, "/api/v1/timelines/home")
|
||||
|
||||
assert [
|
||||
%{
|
||||
"reblog" => %{
|
||||
"content" => "repeated post",
|
||||
"account" => %{
|
||||
"acct" => "repeated",
|
||||
"pleroma" => %{
|
||||
"relationship" => %{"following" => false, "followed_by" => true}
|
||||
}
|
||||
}
|
||||
},
|
||||
"account" => %{"pleroma" => %{"relationship" => %{"following" => true}}}
|
||||
},
|
||||
%{
|
||||
"content" => "post",
|
||||
"account" => %{
|
||||
"acct" => "followed",
|
||||
"pleroma" => %{"relationship" => %{"following" => true}}
|
||||
}
|
||||
}
|
||||
] = json_response(ret_conn, :ok)
|
||||
end
|
||||
|
||||
test "the home timeline when the direct messages are excluded", %{user: user, conn: conn} do
|
||||
|
|
@ -80,15 +126,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
assert [%{"content" => "test"}] = json_response(conn, :ok)
|
||||
end
|
||||
|
||||
test "the public timeline when public is set to false", %{conn: conn} do
|
||||
Config.put([:instance, :public], false)
|
||||
|
||||
assert %{"error" => "This resource requires authentication."} ==
|
||||
conn
|
||||
|> get("/api/v1/timelines/public", %{"local" => "False"})
|
||||
|> json_response(:forbidden)
|
||||
end
|
||||
|
||||
test "the public timeline includes only public statuses for an authenticated user" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:statuses"])
|
||||
|
||||
|
|
@ -102,6 +139,98 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
defp local_and_remote_activities do
|
||||
insert(:note_activity)
|
||||
insert(:note_activity, local: false)
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "public with restrict unauthenticated timeline for local and federated timelines" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn} do
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})
|
||||
|
||||
assert json_response(res_conn, :unauthorized) == %{
|
||||
"error" => "authorization required for timeline view"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"})
|
||||
|
||||
assert json_response(res_conn, :unauthorized) == %{
|
||||
"error" => "authorization required for timeline view"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated" do
|
||||
%{conn: conn} = oauth_access(["read:statuses"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"})
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "public with restrict unauthenticated timeline for local" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn} do
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})
|
||||
|
||||
assert json_response(res_conn, :unauthorized) == %{
|
||||
"error" => "authorization required for timeline view"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"})
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{conn: _conn} do
|
||||
%{conn: conn} = oauth_access(["read:statuses"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"})
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "public with restrict unauthenticated timeline for remote" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn} do
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"})
|
||||
|
||||
assert json_response(res_conn, :unauthorized) == %{
|
||||
"error" => "authorization required for timeline view"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{conn: _conn} do
|
||||
%{conn: conn} = oauth_access(["read:statuses"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"})
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "direct" do
|
||||
test "direct timeline", %{conn: conn} do
|
||||
user_one = insert(:user)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue