Merge branch 'develop' into global-status-expiration
This commit is contained in:
commit
decaa64f75
244 changed files with 6395 additions and 2717 deletions
|
|
@ -765,51 +765,87 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "POST /users/:nickname/outbox" do
|
||||
test "it rejects posts from other users / unauuthenticated users", %{conn: conn} do
|
||||
data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!()
|
||||
describe "POST /users/:nickname/outbox (C2S)" do
|
||||
setup do
|
||||
[
|
||||
activity: %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"type" => "Create",
|
||||
"object" => %{"type" => "Note", "content" => "AP C2S test"},
|
||||
"to" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"cc" => []
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
test "it rejects posts from other users / unauthenticated users", %{
|
||||
conn: conn,
|
||||
activity: activity
|
||||
} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
conn = put_req_header(conn, "content-type", "application/activity+json")
|
||||
|
||||
conn
|
||||
|> post("/users/#{user.nickname}/outbox", data)
|
||||
|> post("/users/#{user.nickname}/outbox", activity)
|
||||
|> json_response(403)
|
||||
|
||||
conn
|
||||
|> assign(:user, other_user)
|
||||
|> post("/users/#{user.nickname}/outbox", data)
|
||||
|> post("/users/#{user.nickname}/outbox", activity)
|
||||
|> json_response(403)
|
||||
end
|
||||
|
||||
test "it inserts an incoming create activity into the database", %{conn: conn} do
|
||||
data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!()
|
||||
test "it inserts an incoming create activity into the database", %{
|
||||
conn: conn,
|
||||
activity: activity
|
||||
} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{user.nickname}/outbox", data)
|
||||
|
||||
result = json_response(conn, 201)
|
||||
|> post("/users/#{user.nickname}/outbox", activity)
|
||||
|> json_response(201)
|
||||
|
||||
assert Activity.get_by_ap_id(result["id"])
|
||||
assert result["object"]
|
||||
assert %Object{data: object} = Object.normalize(result["object"])
|
||||
assert object["content"] == activity["object"]["content"]
|
||||
end
|
||||
|
||||
test "it rejects an incoming activity with bogus type", %{conn: conn} do
|
||||
data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!()
|
||||
test "it inserts an incoming sensitive activity into the database", %{
|
||||
conn: conn,
|
||||
activity: activity
|
||||
} do
|
||||
user = insert(:user)
|
||||
object = Map.put(activity["object"], "sensitive", true)
|
||||
activity = Map.put(activity, "object", object)
|
||||
|
||||
data =
|
||||
data
|
||||
|> Map.put("type", "BadType")
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{user.nickname}/outbox", activity)
|
||||
|> json_response(201)
|
||||
|
||||
assert Activity.get_by_ap_id(result["id"])
|
||||
assert result["object"]
|
||||
assert %Object{data: object} = Object.normalize(result["object"])
|
||||
assert object["sensitive"] == activity["object"]["sensitive"]
|
||||
assert object["content"] == activity["object"]["content"]
|
||||
end
|
||||
|
||||
test "it rejects an incoming activity with bogus type", %{conn: conn, activity: activity} do
|
||||
user = insert(:user)
|
||||
activity = Map.put(activity, "type", "BadType")
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{user.nickname}/outbox", data)
|
||||
|> post("/users/#{user.nickname}/outbox", activity)
|
||||
|
||||
assert json_response(conn, 400)
|
||||
end
|
||||
|
|
@ -1019,12 +1055,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
assert result["totalItems"] == 15
|
||||
end
|
||||
|
||||
test "returns 403 if requester is not logged in", %{conn: conn} do
|
||||
test "does not require authentication", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn
|
||||
|> get("/users/#{user.nickname}/followers")
|
||||
|> json_response(403)
|
||||
|> json_response(200)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1116,12 +1152,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
assert result["totalItems"] == 15
|
||||
end
|
||||
|
||||
test "returns 403 if requester is not logged in", %{conn: conn} do
|
||||
test "does not require authentication", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn
|
||||
|> get("/users/#{user.nickname}/following")
|
||||
|> json_response(403)
|
||||
|> json_response(200)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.Federator
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
import Mock
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
|
@ -2404,6 +2405,53 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
u4: %{r1: r4_1.id}}
|
||||
end
|
||||
|
||||
describe "maybe_update_follow_information/1" do
|
||||
setup do
|
||||
clear_config([:instance, :external_user_synchronization], true)
|
||||
|
||||
user = %{
|
||||
local: false,
|
||||
ap_id: "https://gensokyo.2hu/users/raymoo",
|
||||
following_address: "https://gensokyo.2hu/users/following",
|
||||
follower_address: "https://gensokyo.2hu/users/followers",
|
||||
type: "Person"
|
||||
}
|
||||
|
||||
%{user: user}
|
||||
end
|
||||
|
||||
test "logs an error when it can't fetch the info", %{user: user} do
|
||||
assert capture_log(fn ->
|
||||
ActivityPub.maybe_update_follow_information(user)
|
||||
end) =~ "Follower/Following counter update for #{user.ap_id} failed"
|
||||
end
|
||||
|
||||
test "just returns the input if the user type is Application", %{
|
||||
user: user
|
||||
} do
|
||||
user =
|
||||
user
|
||||
|> Map.put(:type, "Application")
|
||||
|
||||
refute capture_log(fn ->
|
||||
assert ^user = ActivityPub.maybe_update_follow_information(user)
|
||||
end) =~ "Follower/Following counter update for #{user.ap_id} failed"
|
||||
end
|
||||
|
||||
test "it just returns the input if the user has no following/follower addresses", %{
|
||||
user: user
|
||||
} do
|
||||
user =
|
||||
user
|
||||
|> Map.put(:following_address, nil)
|
||||
|> Map.put(:follower_address, nil)
|
||||
|
||||
refute capture_log(fn ->
|
||||
assert ^user = ActivityPub.maybe_update_follow_information(user)
|
||||
end) =~ "Follower/Following counter update for #{user.ap_id} failed"
|
||||
end
|
||||
end
|
||||
|
||||
describe "global activity expiration" do
|
||||
setup do: clear_config([:instance, :rewrite_policy])
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,32 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
|
|||
assert LikeValidator.cast_and_validate(valid_like).valid?
|
||||
end
|
||||
|
||||
test "sets the 'to' field to the object actor if no recipients are given", %{
|
||||
valid_like: valid_like,
|
||||
user: user
|
||||
} do
|
||||
without_recipients =
|
||||
valid_like
|
||||
|> Map.delete("to")
|
||||
|
||||
{:ok, object, _meta} = ObjectValidator.validate(without_recipients, [])
|
||||
|
||||
assert object["to"] == [user.ap_id]
|
||||
end
|
||||
|
||||
test "sets the context field to the context of the object if no context is given", %{
|
||||
valid_like: valid_like,
|
||||
post_activity: post_activity
|
||||
} do
|
||||
without_context =
|
||||
valid_like
|
||||
|> Map.delete("context")
|
||||
|
||||
{:ok, object, _meta} = ObjectValidator.validate(without_context, [])
|
||||
|
||||
assert object["context"] == post_activity.data["context"]
|
||||
end
|
||||
|
||||
test "it errors when the actor is missing or not known", %{valid_like: valid_like} do
|
||||
without_actor = Map.delete(valid_like, "actor")
|
||||
|
||||
|
|
|
|||
78
test/web/activity_pub/transmogrifier/like_handling_test.exs
Normal file
78
test/web/activity_pub/transmogrifier/like_handling_test.exs
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.Transmogrifier.LikeHandlingTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "it works for incoming likes" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-like.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|
||||
_actor = insert(:user, ap_id: data["actor"], local: false)
|
||||
|
||||
{:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
refute Enum.empty?(activity.recipients)
|
||||
|
||||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
assert data["type"] == "Like"
|
||||
assert data["id"] == "http://mastodon.example.org/users/admin#likes/2"
|
||||
assert data["object"] == activity.data["object"]
|
||||
end
|
||||
|
||||
test "it works for incoming misskey likes, turning them into EmojiReacts" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/misskey-like.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|
||||
_actor = insert(:user, ap_id: data["actor"], local: false)
|
||||
|
||||
{:ok, %Activity{data: activity_data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert activity_data["actor"] == data["actor"]
|
||||
assert activity_data["type"] == "EmojiReact"
|
||||
assert activity_data["id"] == data["id"]
|
||||
assert activity_data["object"] == activity.data["object"]
|
||||
assert activity_data["content"] == "🍮"
|
||||
end
|
||||
|
||||
test "it works for incoming misskey likes that contain unicode emojis, turning them into EmojiReacts" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/misskey-like.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|> Map.put("_misskey_reaction", "⭐")
|
||||
|
||||
_actor = insert(:user, ap_id: data["actor"], local: false)
|
||||
|
||||
{:ok, %Activity{data: activity_data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert activity_data["actor"] == data["actor"]
|
||||
assert activity_data["type"] == "EmojiReact"
|
||||
assert activity_data["id"] == data["id"]
|
||||
assert activity_data["object"] == activity.data["object"]
|
||||
assert activity_data["content"] == "⭐"
|
||||
end
|
||||
end
|
||||
|
|
@ -325,62 +325,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert object_data["cc"] == to
|
||||
end
|
||||
|
||||
test "it works for incoming likes" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-like.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|
||||
{:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
refute Enum.empty?(activity.recipients)
|
||||
|
||||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
assert data["type"] == "Like"
|
||||
assert data["id"] == "http://mastodon.example.org/users/admin#likes/2"
|
||||
assert data["object"] == activity.data["object"]
|
||||
end
|
||||
|
||||
test "it works for incoming misskey likes, turning them into EmojiReacts" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/misskey-like.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["actor"] == data["actor"]
|
||||
assert data["type"] == "EmojiReact"
|
||||
assert data["id"] == data["id"]
|
||||
assert data["object"] == activity.data["object"]
|
||||
assert data["content"] == "🍮"
|
||||
end
|
||||
|
||||
test "it works for incoming misskey likes that contain unicode emojis, turning them into EmojiReacts" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/misskey-like.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|> Map.put("_misskey_reaction", "⭐")
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["actor"] == data["actor"]
|
||||
assert data["type"] == "EmojiReact"
|
||||
assert data["id"] == data["id"]
|
||||
assert data["object"] == activity.data["object"]
|
||||
assert data["content"] == "⭐"
|
||||
end
|
||||
|
||||
test "it works for incoming emoji reactions" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
|
||||
|
|
@ -872,7 +816,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
@tag capture_log: true
|
||||
test "it works for incoming user deletes" do
|
||||
%{ap_id: ap_id} = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
|
||||
%{ap_id: ap_id} =
|
||||
insert(:user, ap_id: "http://mastodon.example.org/users/admin", local: false)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-delete-user.json")
|
||||
|
|
@ -1221,6 +1166,35 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
:error = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "skip converting the content when it is nil" do
|
||||
object_id = "https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe"
|
||||
|
||||
{:ok, object} = Fetcher.fetch_and_contain_remote_object_from_id(object_id)
|
||||
|
||||
result =
|
||||
Pleroma.Web.ActivityPub.Transmogrifier.fix_object(Map.merge(object, %{"content" => nil}))
|
||||
|
||||
assert result["content"] == nil
|
||||
end
|
||||
|
||||
test "it converts content of object to html" do
|
||||
object_id = "https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe"
|
||||
|
||||
{:ok, %{"content" => content_markdown}} =
|
||||
Fetcher.fetch_and_contain_remote_object_from_id(object_id)
|
||||
|
||||
{:ok, %Pleroma.Object{data: %{"content" => content}} = object} =
|
||||
Fetcher.fetch_object_from_id(object_id)
|
||||
|
||||
assert content_markdown ==
|
||||
"Support this and our other Michigan!/usr/group videos and meetings. Learn more at http://mug.org/membership\n\nTwenty Years in Jail: FreeBSD's Jails, Then and Now\n\nJails started as a limited virtualization system, but over the last two years they've..."
|
||||
|
||||
assert content ==
|
||||
"<p>Support this and our other Michigan!/usr/group videos and meetings. Learn more at <a href=\"http://mug.org/membership\">http://mug.org/membership</a></p><p>Twenty Years in Jail: FreeBSD’s Jails, Then and Now</p><p>Jails started as a limited virtualization system, but over the last two years they’ve…</p>"
|
||||
|
||||
assert object.data["mediaType"] == "text/html"
|
||||
end
|
||||
|
||||
test "it remaps video URLs as attachments if necessary" do
|
||||
{:ok, object} =
|
||||
Fetcher.fetch_object_from_id(
|
||||
|
|
|
|||
|
|
@ -1347,9 +1347,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
{:ok, %{id: report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
response =
|
||||
|
|
@ -1374,16 +1374,16 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
{:ok, %{id: report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
{:ok, %{id: second_report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel very offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel very offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
%{
|
||||
|
|
@ -1523,9 +1523,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
{:ok, %{id: report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
response =
|
||||
|
|
@ -1547,15 +1547,15 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
{:ok, %{id: first_report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
{:ok, %{id: second_report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I don't like this user"
|
||||
account_id: target_user.id,
|
||||
comment: "I don't like this user"
|
||||
})
|
||||
|
||||
CommonAPI.update_report_state(second_report_id, "closed")
|
||||
|
|
@ -3431,9 +3431,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
{:ok, %{id: report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
post(conn, "/api/pleroma/admin/reports/#{report_id}/notes", %{
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
|
||||
{:ok, activity} = CommonAPI.report(user, %{account_id: other_user.id})
|
||||
|
||||
expected = %{
|
||||
content: nil,
|
||||
|
|
@ -48,7 +48,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "toot"})
|
||||
|
||||
{:ok, report_activity} =
|
||||
CommonAPI.report(user, %{"account_id" => other_user.id, "status_ids" => [activity.id]})
|
||||
CommonAPI.report(user, %{account_id: other_user.id, status_ids: [activity.id]})
|
||||
|
||||
other_user = Pleroma.User.get_by_id(other_user.id)
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
|
||||
{:ok, activity} = CommonAPI.report(user, %{account_id: other_user.id})
|
||||
{:ok, activity} = CommonAPI.update_report_state(activity.id, "closed")
|
||||
|
||||
assert %{state: "closed"} =
|
||||
|
|
@ -94,8 +94,8 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
|
||||
{:ok, activity} =
|
||||
CommonAPI.report(user, %{
|
||||
"account_id" => other_user.id,
|
||||
"comment" => "posts are too good for this instance"
|
||||
account_id: other_user.id,
|
||||
comment: "posts are too good for this instance"
|
||||
})
|
||||
|
||||
assert %{content: "posts are too good for this instance"} =
|
||||
|
|
@ -108,8 +108,8 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
|
||||
{:ok, activity} =
|
||||
CommonAPI.report(user, %{
|
||||
"account_id" => other_user.id,
|
||||
"comment" => ""
|
||||
account_id: other_user.id,
|
||||
comment: ""
|
||||
})
|
||||
|
||||
data = Map.put(activity.data, "content", "<script> alert('hecked :D:D:D:D:D:D:D') </script>")
|
||||
|
|
@ -125,8 +125,8 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
|
||||
{:ok, activity} =
|
||||
CommonAPI.report(user, %{
|
||||
"account_id" => other_user.id,
|
||||
"comment" => ""
|
||||
account_id: other_user.id,
|
||||
comment: ""
|
||||
})
|
||||
|
||||
Pleroma.User.delete(other_user)
|
||||
|
|
|
|||
242
test/web/auth/auth_test_controller_test.exs
Normal file
242
test/web/auth/auth_test_controller_test.exs
Normal file
|
|
@ -0,0 +1,242 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Tests.AuthTestControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "do_oauth_check" do
|
||||
test "serves with proper OAuth token (fulfilling requested scopes)" do
|
||||
%{conn: good_token_conn, user: user} = oauth_access(["read"])
|
||||
|
||||
assert %{"user_id" => user.id} ==
|
||||
good_token_conn
|
||||
|> get("/test/authenticated_api/do_oauth_check")
|
||||
|> json_response(200)
|
||||
|
||||
# Unintended usage (:api) — use with :authenticated_api instead
|
||||
assert %{"user_id" => user.id} ==
|
||||
good_token_conn
|
||||
|> get("/test/api/do_oauth_check")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "fails on no token / missing scope(s)" do
|
||||
%{conn: bad_token_conn} = oauth_access(["irrelevant_scope"])
|
||||
|
||||
bad_token_conn
|
||||
|> get("/test/authenticated_api/do_oauth_check")
|
||||
|> json_response(403)
|
||||
|
||||
bad_token_conn
|
||||
|> assign(:token, nil)
|
||||
|> get("/test/api/do_oauth_check")
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
||||
describe "fallback_oauth_check" do
|
||||
test "serves with proper OAuth token (fulfilling requested scopes)" do
|
||||
%{conn: good_token_conn, user: user} = oauth_access(["read"])
|
||||
|
||||
assert %{"user_id" => user.id} ==
|
||||
good_token_conn
|
||||
|> get("/test/api/fallback_oauth_check")
|
||||
|> json_response(200)
|
||||
|
||||
# Unintended usage (:authenticated_api) — use with :api instead
|
||||
assert %{"user_id" => user.id} ==
|
||||
good_token_conn
|
||||
|> get("/test/authenticated_api/fallback_oauth_check")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "for :api on public instance, drops :user and renders on no token / missing scope(s)" do
|
||||
clear_config([:instance, :public], true)
|
||||
|
||||
%{conn: bad_token_conn} = oauth_access(["irrelevant_scope"])
|
||||
|
||||
assert %{"user_id" => nil} ==
|
||||
bad_token_conn
|
||||
|> get("/test/api/fallback_oauth_check")
|
||||
|> json_response(200)
|
||||
|
||||
assert %{"user_id" => nil} ==
|
||||
bad_token_conn
|
||||
|> assign(:token, nil)
|
||||
|> get("/test/api/fallback_oauth_check")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "for :api on private instance, fails on no token / missing scope(s)" do
|
||||
clear_config([:instance, :public], false)
|
||||
|
||||
%{conn: bad_token_conn} = oauth_access(["irrelevant_scope"])
|
||||
|
||||
bad_token_conn
|
||||
|> get("/test/api/fallback_oauth_check")
|
||||
|> json_response(403)
|
||||
|
||||
bad_token_conn
|
||||
|> assign(:token, nil)
|
||||
|> get("/test/api/fallback_oauth_check")
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
||||
describe "skip_oauth_check" do
|
||||
test "for :authenticated_api, serves if :user is set (regardless of token / token scopes)" do
|
||||
user = insert(:user)
|
||||
|
||||
assert %{"user_id" => user.id} ==
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> get("/test/authenticated_api/skip_oauth_check")
|
||||
|> json_response(200)
|
||||
|
||||
%{conn: bad_token_conn, user: user} = oauth_access(["irrelevant_scope"])
|
||||
|
||||
assert %{"user_id" => user.id} ==
|
||||
bad_token_conn
|
||||
|> get("/test/authenticated_api/skip_oauth_check")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "serves via :api on public instance if :user is not set" do
|
||||
clear_config([:instance, :public], true)
|
||||
|
||||
assert %{"user_id" => nil} ==
|
||||
build_conn()
|
||||
|> get("/test/api/skip_oauth_check")
|
||||
|> json_response(200)
|
||||
|
||||
build_conn()
|
||||
|> get("/test/authenticated_api/skip_oauth_check")
|
||||
|> json_response(403)
|
||||
end
|
||||
|
||||
test "fails on private instance if :user is not set" do
|
||||
clear_config([:instance, :public], false)
|
||||
|
||||
build_conn()
|
||||
|> get("/test/api/skip_oauth_check")
|
||||
|> json_response(403)
|
||||
|
||||
build_conn()
|
||||
|> get("/test/authenticated_api/skip_oauth_check")
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
||||
describe "fallback_oauth_skip_publicity_check" do
|
||||
test "serves with proper OAuth token (fulfilling requested scopes)" do
|
||||
%{conn: good_token_conn, user: user} = oauth_access(["read"])
|
||||
|
||||
assert %{"user_id" => user.id} ==
|
||||
good_token_conn
|
||||
|> get("/test/api/fallback_oauth_skip_publicity_check")
|
||||
|> json_response(200)
|
||||
|
||||
# Unintended usage (:authenticated_api)
|
||||
assert %{"user_id" => user.id} ==
|
||||
good_token_conn
|
||||
|> get("/test/authenticated_api/fallback_oauth_skip_publicity_check")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "for :api on private / public instance, drops :user and renders on token issue" do
|
||||
%{conn: bad_token_conn} = oauth_access(["irrelevant_scope"])
|
||||
|
||||
for is_public <- [true, false] do
|
||||
clear_config([:instance, :public], is_public)
|
||||
|
||||
assert %{"user_id" => nil} ==
|
||||
bad_token_conn
|
||||
|> get("/test/api/fallback_oauth_skip_publicity_check")
|
||||
|> json_response(200)
|
||||
|
||||
assert %{"user_id" => nil} ==
|
||||
bad_token_conn
|
||||
|> assign(:token, nil)
|
||||
|> get("/test/api/fallback_oauth_skip_publicity_check")
|
||||
|> json_response(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "skip_oauth_skip_publicity_check" do
|
||||
test "for :authenticated_api, serves if :user is set (regardless of token / token scopes)" do
|
||||
user = insert(:user)
|
||||
|
||||
assert %{"user_id" => user.id} ==
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> get("/test/authenticated_api/skip_oauth_skip_publicity_check")
|
||||
|> json_response(200)
|
||||
|
||||
%{conn: bad_token_conn, user: user} = oauth_access(["irrelevant_scope"])
|
||||
|
||||
assert %{"user_id" => user.id} ==
|
||||
bad_token_conn
|
||||
|> get("/test/authenticated_api/skip_oauth_skip_publicity_check")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "for :api, serves on private and public instances regardless of whether :user is set" do
|
||||
user = insert(:user)
|
||||
|
||||
for is_public <- [true, false] do
|
||||
clear_config([:instance, :public], is_public)
|
||||
|
||||
assert %{"user_id" => nil} ==
|
||||
build_conn()
|
||||
|> get("/test/api/skip_oauth_skip_publicity_check")
|
||||
|> json_response(200)
|
||||
|
||||
assert %{"user_id" => user.id} ==
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> get("/test/api/skip_oauth_skip_publicity_check")
|
||||
|> json_response(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "missing_oauth_check_definition" do
|
||||
def test_missing_oauth_check_definition_failure(endpoint, expected_error) do
|
||||
%{conn: conn} = oauth_access(["read", "write", "follow", "push", "admin"])
|
||||
|
||||
assert %{"error" => expected_error} ==
|
||||
conn
|
||||
|> get(endpoint)
|
||||
|> json_response(403)
|
||||
end
|
||||
|
||||
test "fails if served via :authenticated_api" do
|
||||
test_missing_oauth_check_definition_failure(
|
||||
"/test/authenticated_api/missing_oauth_check_definition",
|
||||
"Security violation: OAuth scopes check was neither handled nor explicitly skipped."
|
||||
)
|
||||
end
|
||||
|
||||
test "fails if served via :api and the instance is private" do
|
||||
clear_config([:instance, :public], false)
|
||||
|
||||
test_missing_oauth_check_definition_failure(
|
||||
"/test/api/missing_oauth_check_definition",
|
||||
"This resource requires authentication."
|
||||
)
|
||||
end
|
||||
|
||||
test "succeeds with dropped :user if served via :api on public instance" do
|
||||
%{conn: conn} = oauth_access(["read", "write", "follow", "push", "admin"])
|
||||
|
||||
assert %{"user_id" => nil} ==
|
||||
conn
|
||||
|> get("/test/api/missing_oauth_check_definition")
|
||||
|> json_response(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Tests.OAuthTestControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup %{conn: conn} do
|
||||
user = insert(:user)
|
||||
conn = assign(conn, :user, user)
|
||||
%{conn: conn, user: user}
|
||||
end
|
||||
|
||||
test "missed_oauth", %{conn: conn} do
|
||||
res =
|
||||
conn
|
||||
|> get("/test/authenticated_api/missed_oauth")
|
||||
|> json_response(403)
|
||||
|
||||
assert res ==
|
||||
%{
|
||||
"error" =>
|
||||
"Security violation: OAuth scopes check was neither handled nor explicitly skipped."
|
||||
}
|
||||
end
|
||||
|
||||
test "skipped_oauth", %{conn: conn} do
|
||||
conn
|
||||
|> assign(:token, nil)
|
||||
|> get("/test/authenticated_api/skipped_oauth")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "performed_oauth", %{user: user} do
|
||||
%{conn: good_token_conn} = oauth_access(["read"], user: user)
|
||||
|
||||
good_token_conn
|
||||
|> get("/test/authenticated_api/performed_oauth")
|
||||
|> json_response(200)
|
||||
|
||||
%{conn: bad_token_conn} = oauth_access(["follow"], user: user)
|
||||
|
||||
bad_token_conn
|
||||
|> get("/test/authenticated_api/performed_oauth")
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
|
@ -485,9 +485,9 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
comment = "foobar"
|
||||
|
||||
report_data = %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => comment,
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: comment,
|
||||
status_ids: [activity.id]
|
||||
}
|
||||
|
||||
note_obj = %{
|
||||
|
|
@ -517,9 +517,9 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
{:ok, %Activity{id: report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
{:ok, report} = CommonAPI.update_report_state(report_id, "resolved")
|
||||
|
|
@ -538,9 +538,9 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
{:ok, %Activity{id: report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
assert CommonAPI.update_report_state(report_id, "test") == {:error, "Unsupported state"}
|
||||
|
|
@ -552,16 +552,16 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
{:ok, %Activity{id: first_report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
{:ok, %Activity{id: second_report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel very offended!",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel very offended!",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
{:ok, report_ids} =
|
||||
|
|
@ -697,6 +697,14 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
assert Repo.get(Activity, follow_activity_two.id).data["state"] == "reject"
|
||||
assert Repo.get(Activity, follow_activity_three.id).data["state"] == "pending"
|
||||
end
|
||||
|
||||
test "doesn't create a following relationship if the corresponding follow request doesn't exist" do
|
||||
user = insert(:user, locked: true)
|
||||
not_follower = insert(:user)
|
||||
CommonAPI.accept_follow_request(not_follower, user)
|
||||
|
||||
assert Pleroma.FollowingRelationship.following?(not_follower, user) == false
|
||||
end
|
||||
end
|
||||
|
||||
describe "vote/3" do
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
|
||||
describe "updating credentials" do
|
||||
setup do: oauth_access(["write:accounts"])
|
||||
setup :request_content_type
|
||||
|
||||
test "sets user settings in a generic way", %{conn: conn} do
|
||||
res_conn =
|
||||
|
|
@ -25,7 +26,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
}
|
||||
})
|
||||
|
||||
assert user_data = json_response(res_conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(res_conn, 200)
|
||||
assert user_data["pleroma"]["settings_store"] == %{"pleroma_fe" => %{"theme" => "bla"}}
|
||||
|
||||
user = Repo.get(User, user_data["id"])
|
||||
|
|
@ -41,7 +42,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
}
|
||||
})
|
||||
|
||||
assert user_data = json_response(res_conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
assert user_data["pleroma"]["settings_store"] ==
|
||||
%{
|
||||
|
|
@ -62,7 +63,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
}
|
||||
})
|
||||
|
||||
assert user_data = json_response(res_conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
assert user_data["pleroma"]["settings_store"] ==
|
||||
%{
|
||||
|
|
@ -79,7 +80,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
"note" => "I drink #cofe with @#{user2.nickname}\n\nsuya.."
|
||||
})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
|
||||
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 class="u-url mention" data-user="#{
|
||||
|
|
@ -90,7 +91,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
test "updates the user's locking status", %{conn: conn} do
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{locked: "true"})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["locked"] == true
|
||||
end
|
||||
|
||||
|
|
@ -100,21 +101,21 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{allow_following_move: "false"})
|
||||
|
||||
assert refresh_record(user).allow_following_move == false
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["pleroma"]["allow_following_move"] == false
|
||||
end
|
||||
|
||||
test "updates the user's default scope", %{conn: conn} do
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{default_scope: "cofe"})
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{default_scope: "unlisted"})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data["source"]["privacy"] == "cofe"
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["source"]["privacy"] == "unlisted"
|
||||
end
|
||||
|
||||
test "updates the user's hide_followers status", %{conn: conn} do
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{hide_followers: "true"})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["pleroma"]["hide_followers"] == true
|
||||
end
|
||||
|
||||
|
|
@ -122,12 +123,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert %{"source" => %{"pleroma" => %{"discoverable" => true}}} =
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{discoverable: "true"})
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert %{"source" => %{"pleroma" => %{"discoverable" => false}}} =
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{discoverable: "false"})
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
end
|
||||
|
||||
test "updates the user's hide_followers_count and hide_follows_count", %{conn: conn} do
|
||||
|
|
@ -137,7 +138,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
hide_follows_count: "true"
|
||||
})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["pleroma"]["hide_followers_count"] == true
|
||||
assert user_data["pleroma"]["hide_follows_count"] == true
|
||||
end
|
||||
|
|
@ -146,7 +147,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
response =
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{skip_thread_containment: "true"})
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["pleroma"]["skip_thread_containment"] == true
|
||||
assert refresh_record(user).skip_thread_containment
|
||||
|
|
@ -155,28 +156,28 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
test "updates the user's hide_follows status", %{conn: conn} do
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{hide_follows: "true"})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["pleroma"]["hide_follows"] == true
|
||||
end
|
||||
|
||||
test "updates the user's hide_favorites status", %{conn: conn} do
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{hide_favorites: "true"})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["pleroma"]["hide_favorites"] == true
|
||||
end
|
||||
|
||||
test "updates the user's show_role status", %{conn: conn} do
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{show_role: "false"})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["source"]["pleroma"]["show_role"] == false
|
||||
end
|
||||
|
||||
test "updates the user's no_rich_text status", %{conn: conn} do
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{no_rich_text: "true"})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["source"]["pleroma"]["no_rich_text"] == true
|
||||
end
|
||||
|
||||
|
|
@ -184,7 +185,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
conn =
|
||||
patch(conn, "/api/v1/accounts/update_credentials", %{"display_name" => "markorepairs"})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["display_name"] == "markorepairs"
|
||||
end
|
||||
|
||||
|
|
@ -197,7 +198,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{"avatar" => new_avatar})
|
||||
|
||||
assert user_response = json_response(conn, 200)
|
||||
assert user_response = json_response_and_validate_schema(conn, 200)
|
||||
assert user_response["avatar"] != User.avatar_url(user)
|
||||
end
|
||||
|
||||
|
|
@ -210,7 +211,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{"header" => new_header})
|
||||
|
||||
assert user_response = json_response(conn, 200)
|
||||
assert user_response = json_response_and_validate_schema(conn, 200)
|
||||
assert user_response["header"] != User.banner_url(user)
|
||||
end
|
||||
|
||||
|
|
@ -226,7 +227,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
"pleroma_background_image" => new_header
|
||||
})
|
||||
|
||||
assert user_response = json_response(conn, 200)
|
||||
assert user_response = json_response_and_validate_schema(conn, 200)
|
||||
assert user_response["pleroma"]["background_image"]
|
||||
end
|
||||
|
||||
|
|
@ -237,14 +238,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
for token <- [token1, token2] do
|
||||
conn =
|
||||
build_conn()
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> put_req_header("authorization", "Bearer #{token.token}")
|
||||
|> patch("/api/v1/accounts/update_credentials", %{})
|
||||
|
||||
if token == token1 do
|
||||
assert %{"error" => "Insufficient permissions: write:accounts."} ==
|
||||
json_response(conn, 403)
|
||||
json_response_and_validate_schema(conn, 403)
|
||||
else
|
||||
assert json_response(conn, 200)
|
||||
assert json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -259,11 +261,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
"display_name" => name
|
||||
})
|
||||
|
||||
assert json_response(ret_conn, 200)
|
||||
assert json_response_and_validate_schema(ret_conn, 200)
|
||||
|
||||
conn = get(conn, "/api/v1/accounts/#{user.id}")
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
|
||||
assert user_data["note"] == note
|
||||
assert user_data["display_name"] == name
|
||||
|
|
@ -279,7 +281,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
account_data =
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert account_data["fields"] == [
|
||||
%{"name" => "<a href=\"http://google.com\">foo</a>", "value" => "bar"},
|
||||
|
|
@ -312,7 +314,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
conn
|
||||
|> put_req_header("content-type", "application/x-www-form-urlencoded")
|
||||
|> patch("/api/v1/accounts/update_credentials", fields)
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert account["fields"] == [
|
||||
%{"name" => "foo", "value" => "bar"},
|
||||
|
|
@ -337,7 +339,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
account =
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert account["fields"] == [
|
||||
%{"name" => "foo", "value" => ""}
|
||||
|
|
@ -356,14 +358,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert %{"error" => "Invalid request"} ==
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
||||
|> json_response(403)
|
||||
|> json_response_and_validate_schema(403)
|
||||
|
||||
fields = [%{"name" => long_name, "value" => "bar"}]
|
||||
|
||||
assert %{"error" => "Invalid request"} ==
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
||||
|> json_response(403)
|
||||
|> json_response_and_validate_schema(403)
|
||||
|
||||
Pleroma.Config.put([:instance, :max_account_fields], 1)
|
||||
|
||||
|
|
@ -375,7 +377,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert %{"error" => "Invalid request"} ==
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
||||
|> json_response(403)
|
||||
|> json_response_and_validate_schema(403)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
defmodule Pleroma.Web.MastodonAPI.CustomEmojiControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
alias Pleroma.Web.ApiSpec
|
||||
import OpenApiSpex.TestAssertions
|
||||
|
||||
test "with tags", %{conn: conn} do
|
||||
assert resp =
|
||||
|
|
@ -21,6 +19,5 @@ defmodule Pleroma.Web.MastodonAPI.CustomEmojiControllerTest do
|
|||
assert Map.has_key?(emoji, "category")
|
||||
assert Map.has_key?(emoji, "url")
|
||||
assert Map.has_key?(emoji, "visible_in_picker")
|
||||
assert_schema(emoji, "CustomEmoji", ApiSpec.spec())
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
|||
"banner_upload_limit" => _
|
||||
} = result
|
||||
|
||||
assert result["pleroma"]["metadata"]["features"]
|
||||
assert result["pleroma"]["metadata"]["federation"]
|
||||
assert result["pleroma"]["vapid_public_key"]
|
||||
|
||||
assert email == from_config_email
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications")
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert Enum.all?(response, fn n ->
|
||||
get_in(n, ["account", "pleroma", "relationship"]) == %{}
|
||||
|
|
@ -50,7 +50,9 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
user.ap_id
|
||||
}\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
|
||||
|
||||
assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
|
||||
assert [%{"status" => %{"content" => response}} | _rest] =
|
||||
json_response_and_validate_schema(conn, 200)
|
||||
|
||||
assert response == expected_response
|
||||
end
|
||||
|
||||
|
|
@ -69,7 +71,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
user.ap_id
|
||||
}\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
|
||||
|
||||
assert %{"status" => %{"content" => response}} = json_response(conn, 200)
|
||||
assert %{"status" => %{"content" => response}} = json_response_and_validate_schema(conn, 200)
|
||||
assert response == expected_response
|
||||
end
|
||||
|
||||
|
|
@ -84,9 +86,10 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/notifications/dismiss", %{"id" => notification.id})
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/notifications/dismiss", %{"id" => to_string(notification.id)})
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
assert %{} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "dismissing a single notification" do
|
||||
|
|
@ -102,7 +105,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|> assign(:user, user)
|
||||
|> post("/api/v1/notifications/#{notification.id}/dismiss")
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
assert %{} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "clearing all notifications" do
|
||||
|
|
@ -115,11 +118,11 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
ret_conn = post(conn, "/api/v1/notifications/clear")
|
||||
|
||||
assert %{} = json_response(ret_conn, 200)
|
||||
assert %{} = json_response_and_validate_schema(ret_conn, 200)
|
||||
|
||||
ret_conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert all = json_response(ret_conn, 200)
|
||||
assert all = json_response_and_validate_schema(ret_conn, 200)
|
||||
assert all == []
|
||||
end
|
||||
|
||||
|
|
@ -143,7 +146,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications?limit=2&min_id=#{notification1_id}")
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
|
||||
|
||||
|
|
@ -151,7 +154,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications?limit=2&since_id=#{notification1_id}")
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||
|
||||
|
|
@ -159,7 +162,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications?limit=2&max_id=#{notification4_id}")
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
|
||||
end
|
||||
|
|
@ -181,36 +184,28 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
{:ok, private_activity} =
|
||||
CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "private"})
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{
|
||||
exclude_visibilities: ["public", "unlisted", "private"]
|
||||
})
|
||||
query = params_to_query(%{exclude_visibilities: ["public", "unlisted", "private"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?" <> query)
|
||||
|
||||
assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
|
||||
assert [%{"status" => %{"id" => id}}] = json_response_and_validate_schema(conn_res, 200)
|
||||
assert id == direct_activity.id
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{
|
||||
exclude_visibilities: ["public", "unlisted", "direct"]
|
||||
})
|
||||
query = params_to_query(%{exclude_visibilities: ["public", "unlisted", "direct"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?" <> query)
|
||||
|
||||
assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
|
||||
assert [%{"status" => %{"id" => id}}] = json_response_and_validate_schema(conn_res, 200)
|
||||
assert id == private_activity.id
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{
|
||||
exclude_visibilities: ["public", "private", "direct"]
|
||||
})
|
||||
query = params_to_query(%{exclude_visibilities: ["public", "private", "direct"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?" <> query)
|
||||
|
||||
assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
|
||||
assert [%{"status" => %{"id" => id}}] = json_response_and_validate_schema(conn_res, 200)
|
||||
assert id == unlisted_activity.id
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{
|
||||
exclude_visibilities: ["unlisted", "private", "direct"]
|
||||
})
|
||||
query = params_to_query(%{exclude_visibilities: ["unlisted", "private", "direct"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?" <> query)
|
||||
|
||||
assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
|
||||
assert [%{"status" => %{"id" => id}}] = json_response_and_validate_schema(conn_res, 200)
|
||||
assert id == public_activity.id
|
||||
end
|
||||
|
||||
|
|
@ -237,8 +232,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
activity_ids =
|
||||
conn
|
||||
|> get("/api/v1/notifications", %{exclude_visibilities: ["direct"]})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/notifications?exclude_visibilities[]=direct")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["status"]["id"])
|
||||
|
||||
assert public_activity.id in activity_ids
|
||||
|
|
@ -248,8 +243,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
activity_ids =
|
||||
conn
|
||||
|> get("/api/v1/notifications", %{exclude_visibilities: ["unlisted"]})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/notifications?exclude_visibilities[]=unlisted")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["status"]["id"])
|
||||
|
||||
assert public_activity.id in activity_ids
|
||||
|
|
@ -259,8 +254,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
activity_ids =
|
||||
conn
|
||||
|> get("/api/v1/notifications", %{exclude_visibilities: ["private"]})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/notifications?exclude_visibilities[]=private")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["status"]["id"])
|
||||
|
||||
assert public_activity.id in activity_ids
|
||||
|
|
@ -270,8 +265,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
activity_ids =
|
||||
conn
|
||||
|> get("/api/v1/notifications", %{exclude_visibilities: ["public"]})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/notifications?exclude_visibilities[]=public")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["status"]["id"])
|
||||
|
||||
refute public_activity.id in activity_ids
|
||||
|
|
@ -295,8 +290,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
activity_ids =
|
||||
conn
|
||||
|> get("/api/v1/notifications", %{exclude_visibilities: ["unlisted"]})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/notifications?exclude_visibilities[]=unlisted")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["status"]["id"])
|
||||
|
||||
assert public_activity.id in activity_ids
|
||||
|
|
@ -319,25 +314,27 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
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", %{exclude_types: ["mention", "favourite", "reblog"]})
|
||||
query = params_to_query(%{exclude_types: ["mention", "favourite", "reblog"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?" <> query)
|
||||
|
||||
assert [%{"id" => ^follow_notification_id}] = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^follow_notification_id}] = json_response_and_validate_schema(conn_res, 200)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["favourite", "reblog", "follow"]})
|
||||
query = params_to_query(%{exclude_types: ["favourite", "reblog", "follow"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?" <> query)
|
||||
|
||||
assert [%{"id" => ^mention_notification_id}] = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^mention_notification_id}] =
|
||||
json_response_and_validate_schema(conn_res, 200)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["reblog", "follow", "mention"]})
|
||||
query = params_to_query(%{exclude_types: ["reblog", "follow", "mention"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?" <> query)
|
||||
|
||||
assert [%{"id" => ^favorite_notification_id}] = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^favorite_notification_id}] =
|
||||
json_response_and_validate_schema(conn_res, 200)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["follow", "mention", "favourite"]})
|
||||
query = params_to_query(%{exclude_types: ["follow", "mention", "favourite"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?" <> query)
|
||||
|
||||
assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^reblog_notification_id}] = json_response_and_validate_schema(conn_res, 200)
|
||||
end
|
||||
|
||||
test "filters notifications using include_types" do
|
||||
|
|
@ -355,32 +352,34 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
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"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?include_types[]=follow")
|
||||
|
||||
assert [%{"id" => ^follow_notification_id}] = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^follow_notification_id}] = json_response_and_validate_schema(conn_res, 200)
|
||||
|
||||
conn_res = get(conn, "/api/v1/notifications", %{include_types: ["mention"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?include_types[]=mention")
|
||||
|
||||
assert [%{"id" => ^mention_notification_id}] = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^mention_notification_id}] =
|
||||
json_response_and_validate_schema(conn_res, 200)
|
||||
|
||||
conn_res = get(conn, "/api/v1/notifications", %{include_types: ["favourite"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?include_types[]=favourite")
|
||||
|
||||
assert [%{"id" => ^favorite_notification_id}] = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^favorite_notification_id}] =
|
||||
json_response_and_validate_schema(conn_res, 200)
|
||||
|
||||
conn_res = get(conn, "/api/v1/notifications", %{include_types: ["reblog"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?include_types[]=reblog")
|
||||
|
||||
assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^reblog_notification_id}] = json_response_and_validate_schema(conn_res, 200)
|
||||
|
||||
result = conn |> get("/api/v1/notifications") |> json_response(200)
|
||||
result = conn |> get("/api/v1/notifications") |> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(result) == 4
|
||||
|
||||
query = params_to_query(%{include_types: ["follow", "mention", "favourite", "reblog"]})
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications", %{
|
||||
include_types: ["follow", "mention", "favourite", "reblog"]
|
||||
})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/notifications?" <> query)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(result) == 4
|
||||
end
|
||||
|
|
@ -402,7 +401,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications")
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert [%{"id" => ^notification2_id}, %{"id" => ^notification1_id}] = result
|
||||
|
||||
|
|
@ -414,22 +413,19 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
result =
|
||||
conn2
|
||||
|> get("/api/v1/notifications")
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||
|
||||
conn_destroy =
|
||||
conn
|
||||
|> delete("/api/v1/notifications/destroy_multiple", %{
|
||||
"ids" => [notification1_id, notification2_id]
|
||||
})
|
||||
query = params_to_query(%{ids: [notification1_id, notification2_id]})
|
||||
conn_destroy = delete(conn, "/api/v1/notifications/destroy_multiple?" <> query)
|
||||
|
||||
assert json_response(conn_destroy, 200) == %{}
|
||||
assert json_response_and_validate_schema(conn_destroy, 200) == %{}
|
||||
|
||||
result =
|
||||
conn2
|
||||
|> get("/api/v1/notifications")
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||
end
|
||||
|
|
@ -443,13 +439,13 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
ret_conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(ret_conn, 200)) == 1
|
||||
assert length(json_response_and_validate_schema(ret_conn, 200)) == 1
|
||||
|
||||
{:ok, _user_relationships} = User.mute(user, user2)
|
||||
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert json_response(conn, 200) == []
|
||||
assert json_response_and_validate_schema(conn, 200) == []
|
||||
end
|
||||
|
||||
test "see notifications after muting user without notifications" do
|
||||
|
|
@ -461,13 +457,13 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
ret_conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(ret_conn, 200)) == 1
|
||||
assert length(json_response_and_validate_schema(ret_conn, 200)) == 1
|
||||
|
||||
{:ok, _user_relationships} = User.mute(user, user2, false)
|
||||
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
assert length(json_response_and_validate_schema(conn, 200)) == 1
|
||||
end
|
||||
|
||||
test "see notifications after muting user with notifications and with_muted parameter" do
|
||||
|
|
@ -479,13 +475,13 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
ret_conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(ret_conn, 200)) == 1
|
||||
assert length(json_response_and_validate_schema(ret_conn, 200)) == 1
|
||||
|
||||
{:ok, _user_relationships} = User.mute(user, user2)
|
||||
|
||||
conn = get(conn, "/api/v1/notifications", %{"with_muted" => "true"})
|
||||
conn = get(conn, "/api/v1/notifications?with_muted=true")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
assert length(json_response_and_validate_schema(conn, 200)) == 1
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
|
|
@ -512,7 +508,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
assert length(json_response_and_validate_schema(conn, 200)) == 1
|
||||
end
|
||||
|
||||
describe "link headers" do
|
||||
|
|
@ -538,10 +534,10 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications", %{media_only: true})
|
||||
|> get("/api/v1/notifications?limit=5")
|
||||
|
||||
assert [link_header] = get_resp_header(conn, "link")
|
||||
assert link_header =~ ~r/media_only=true/
|
||||
assert link_header =~ ~r/limit=5/
|
||||
assert link_header =~ ~r/min_id=#{notification2.id}/
|
||||
assert link_header =~ ~r/max_id=#{notification1.id}/
|
||||
end
|
||||
|
|
@ -560,14 +556,14 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
assert [%{"account" => %{"id" => ^account_id}}] =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications", %{account_id: account_id})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/notifications?account_id=#{account_id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert %{"error" => "Account is not found"} =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications", %{account_id: "cofe"})
|
||||
|> json_response(404)
|
||||
|> get("/api/v1/notifications?account_id=cofe")
|
||||
|> json_response_and_validate_schema(404)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -577,4 +573,11 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|> Map.get(:id)
|
||||
|> to_string()
|
||||
end
|
||||
|
||||
defp params_to_query(%{} = params) do
|
||||
Enum.map_join(params, "&", fn
|
||||
{k, v} when is_list(v) -> Enum.map_join(v, "&", &"#{k}[]=#{&1}")
|
||||
{k, v} -> k <> "=" <> v
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -22,8 +22,9 @@ defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
|
|||
test "submit a basic report", %{conn: conn, target_user: target_user} do
|
||||
assert %{"action_taken" => false, "id" => _} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/reports", %{"account_id" => target_user.id})
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "submit a report with statuses and comment", %{
|
||||
|
|
@ -33,23 +34,25 @@ defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
|
|||
} do
|
||||
assert %{"action_taken" => false, "id" => _} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/reports", %{
|
||||
"account_id" => target_user.id,
|
||||
"status_ids" => [activity.id],
|
||||
"comment" => "bad status!",
|
||||
"forward" => "false"
|
||||
})
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "account_id is required", %{
|
||||
conn: conn,
|
||||
activity: activity
|
||||
} do
|
||||
assert %{"error" => "Valid `account_id` required"} =
|
||||
assert %{"error" => "Missing field: account_id."} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/reports", %{"status_ids" => [activity.id]})
|
||||
|> json_response(400)
|
||||
|> json_response_and_validate_schema(400)
|
||||
end
|
||||
|
||||
test "comment must be up to the size specified in the config", %{
|
||||
|
|
@ -63,17 +66,21 @@ defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
|
|||
|
||||
assert ^error =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/reports", %{"account_id" => target_user.id, "comment" => comment})
|
||||
|> json_response(400)
|
||||
|> json_response_and_validate_schema(400)
|
||||
end
|
||||
|
||||
test "returns error when account is not exist", %{
|
||||
conn: conn,
|
||||
activity: activity
|
||||
} do
|
||||
conn = post(conn, "/api/v1/reports", %{"status_ids" => [activity.id], "account_id" => "foo"})
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/reports", %{"status_ids" => [activity.id], "account_id" => "foo"})
|
||||
|
||||
assert json_response(conn, 400) == %{"error" => "Account not found"}
|
||||
assert json_response_and_validate_schema(conn, 400) == %{"error" => "Account not found"}
|
||||
end
|
||||
|
||||
test "doesn't fail if an admin has no email", %{conn: conn, target_user: target_user} do
|
||||
|
|
@ -81,7 +88,8 @@ defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
|
|||
|
||||
assert %{"action_taken" => false, "id" => _} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/reports", %{"account_id" => target_user.id})
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Config
|
||||
|
||||
setup do: oauth_access(["read"])
|
||||
|
||||
test "returns empty result", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -7,35 +7,28 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
describe "empty_array/2 (stubs)" do
|
||||
test "GET /api/v1/accounts/:id/identity_proofs" do
|
||||
%{user: user, conn: conn} = oauth_access(["n/a"])
|
||||
%{user: user, conn: conn} = oauth_access(["read:accounts"])
|
||||
|
||||
res =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/accounts/#{user.id}/identity_proofs")
|
||||
|> json_response(200)
|
||||
|
||||
assert res == []
|
||||
assert [] ==
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{user.id}/identity_proofs")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "GET /api/v1/endorsements" do
|
||||
%{conn: conn} = oauth_access(["read:accounts"])
|
||||
|
||||
res =
|
||||
conn
|
||||
|> get("/api/v1/endorsements")
|
||||
|> json_response(200)
|
||||
|
||||
assert res == []
|
||||
assert [] ==
|
||||
conn
|
||||
|> get("/api/v1/endorsements")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "GET /api/v1/trends", %{conn: conn} do
|
||||
res =
|
||||
conn
|
||||
|> get("/api/v1/trends")
|
||||
|> json_response(200)
|
||||
|
||||
assert res == []
|
||||
assert [] ==
|
||||
conn
|
||||
|> get("/api/v1/trends")
|
||||
|> json_response(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -151,15 +151,18 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
assert like["id"] == activity.id
|
||||
end
|
||||
|
||||
test "does not return favorites for specified user_id when user is not logged in", %{
|
||||
test "returns favorites for specified user_id when requester is not logged in", %{
|
||||
user: user
|
||||
} do
|
||||
activity = insert(:note_activity)
|
||||
CommonAPI.favorite(user, activity.id)
|
||||
|
||||
build_conn()
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
|
||||
|> json_response(403)
|
||||
response =
|
||||
build_conn()
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
|
||||
|> json_response(200)
|
||||
|
||||
assert length(response) == 1
|
||||
end
|
||||
|
||||
test "returns favorited DM only when user is logged in and he is one of recipients", %{
|
||||
|
|
@ -185,9 +188,12 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
assert length(response) == 1
|
||||
end
|
||||
|
||||
build_conn()
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
|
||||
|> json_response(403)
|
||||
response =
|
||||
build_conn()
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
|
||||
|> json_response(200)
|
||||
|
||||
assert length(response) == 0
|
||||
end
|
||||
|
||||
test "does not return others' favorited DM when user is not one of recipients", %{
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -19,13 +19,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
end
|
||||
|
||||
test "with credentials, without any params" do
|
||||
%{user: current_user, conn: conn} =
|
||||
oauth_access(["read:notifications", "write:notifications"])
|
||||
%{conn: conn} = oauth_access(["write:notifications"])
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, current_user)
|
||||
|> post("/api/qvitter/statuses/notifications/read")
|
||||
conn = post(conn, "/api/qvitter/statuses/notifications/read")
|
||||
|
||||
assert json_response(conn, 400) == %{
|
||||
"error" => "You need to specify latest_id",
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "it registers a new user and returns the user." do
|
||||
data = %{
|
||||
"nickname" => "lain",
|
||||
"email" => "lain@wired.jp",
|
||||
"fullname" => "lain iwakura",
|
||||
"password" => "bear",
|
||||
"confirm" => "bear"
|
||||
:username => "lain",
|
||||
:email => "lain@wired.jp",
|
||||
:fullname => "lain iwakura",
|
||||
:password => "bear",
|
||||
:confirm => "bear"
|
||||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
|
@ -35,12 +35,12 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "it registers a new user with empty string in bio and returns the user." do
|
||||
data = %{
|
||||
"nickname" => "lain",
|
||||
"email" => "lain@wired.jp",
|
||||
"fullname" => "lain iwakura",
|
||||
"bio" => "",
|
||||
"password" => "bear",
|
||||
"confirm" => "bear"
|
||||
:username => "lain",
|
||||
:email => "lain@wired.jp",
|
||||
:fullname => "lain iwakura",
|
||||
:bio => "",
|
||||
:password => "bear",
|
||||
:confirm => "bear"
|
||||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
|
@ -60,12 +60,12 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
end
|
||||
|
||||
data = %{
|
||||
"nickname" => "lain",
|
||||
"email" => "lain@wired.jp",
|
||||
"fullname" => "lain iwakura",
|
||||
"bio" => "",
|
||||
"password" => "bear",
|
||||
"confirm" => "bear"
|
||||
:username => "lain",
|
||||
:email => "lain@wired.jp",
|
||||
:fullname => "lain iwakura",
|
||||
:bio => "",
|
||||
:password => "bear",
|
||||
:confirm => "bear"
|
||||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
|
@ -87,23 +87,23 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "it registers a new user and parses mentions in the bio" do
|
||||
data1 = %{
|
||||
"nickname" => "john",
|
||||
"email" => "john@gmail.com",
|
||||
"fullname" => "John Doe",
|
||||
"bio" => "test",
|
||||
"password" => "bear",
|
||||
"confirm" => "bear"
|
||||
:username => "john",
|
||||
:email => "john@gmail.com",
|
||||
:fullname => "John Doe",
|
||||
:bio => "test",
|
||||
:password => "bear",
|
||||
:confirm => "bear"
|
||||
}
|
||||
|
||||
{:ok, user1} = TwitterAPI.register_user(data1)
|
||||
|
||||
data2 = %{
|
||||
"nickname" => "lain",
|
||||
"email" => "lain@wired.jp",
|
||||
"fullname" => "lain iwakura",
|
||||
"bio" => "@john test",
|
||||
"password" => "bear",
|
||||
"confirm" => "bear"
|
||||
:username => "lain",
|
||||
:email => "lain@wired.jp",
|
||||
:fullname => "lain iwakura",
|
||||
:bio => "@john test",
|
||||
:password => "bear",
|
||||
:confirm => "bear"
|
||||
}
|
||||
|
||||
{:ok, user2} = TwitterAPI.register_user(data2)
|
||||
|
|
@ -123,13 +123,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
{:ok, invite} = UserInviteToken.create_invite()
|
||||
|
||||
data = %{
|
||||
"nickname" => "vinny",
|
||||
"email" => "pasta@pizza.vs",
|
||||
"fullname" => "Vinny Vinesauce",
|
||||
"bio" => "streamer",
|
||||
"password" => "hiptofbees",
|
||||
"confirm" => "hiptofbees",
|
||||
"token" => invite.token
|
||||
:username => "vinny",
|
||||
:email => "pasta@pizza.vs",
|
||||
:fullname => "Vinny Vinesauce",
|
||||
:bio => "streamer",
|
||||
:password => "hiptofbees",
|
||||
:confirm => "hiptofbees",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
|
@ -145,13 +145,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "returns error on invalid token" do
|
||||
data = %{
|
||||
"nickname" => "GrimReaper",
|
||||
"email" => "death@reapers.afterlife",
|
||||
"fullname" => "Reaper Grim",
|
||||
"bio" => "Your time has come",
|
||||
"password" => "scythe",
|
||||
"confirm" => "scythe",
|
||||
"token" => "DudeLetMeInImAFairy"
|
||||
:username => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
:password => "scythe",
|
||||
:confirm => "scythe",
|
||||
:token => "DudeLetMeInImAFairy"
|
||||
}
|
||||
|
||||
{:error, msg} = TwitterAPI.register_user(data)
|
||||
|
|
@ -165,13 +165,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
UserInviteToken.update_invite!(invite, used: true)
|
||||
|
||||
data = %{
|
||||
"nickname" => "GrimReaper",
|
||||
"email" => "death@reapers.afterlife",
|
||||
"fullname" => "Reaper Grim",
|
||||
"bio" => "Your time has come",
|
||||
"password" => "scythe",
|
||||
"confirm" => "scythe",
|
||||
"token" => invite.token
|
||||
:username => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
:password => "scythe",
|
||||
:confirm => "scythe",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:error, msg} = TwitterAPI.register_user(data)
|
||||
|
|
@ -186,16 +186,16 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
setup do
|
||||
data = %{
|
||||
"nickname" => "vinny",
|
||||
"email" => "pasta@pizza.vs",
|
||||
"fullname" => "Vinny Vinesauce",
|
||||
"bio" => "streamer",
|
||||
"password" => "hiptofbees",
|
||||
"confirm" => "hiptofbees"
|
||||
:username => "vinny",
|
||||
:email => "pasta@pizza.vs",
|
||||
:fullname => "Vinny Vinesauce",
|
||||
:bio => "streamer",
|
||||
:password => "hiptofbees",
|
||||
:confirm => "hiptofbees"
|
||||
}
|
||||
|
||||
check_fn = fn invite ->
|
||||
data = Map.put(data, "token", invite.token)
|
||||
data = Map.put(data, :token, invite.token)
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
fetched_user = User.get_cached_by_nickname("vinny")
|
||||
|
||||
|
|
@ -250,13 +250,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
UserInviteToken.update_invite!(invite, uses: 99)
|
||||
|
||||
data = %{
|
||||
"nickname" => "vinny",
|
||||
"email" => "pasta@pizza.vs",
|
||||
"fullname" => "Vinny Vinesauce",
|
||||
"bio" => "streamer",
|
||||
"password" => "hiptofbees",
|
||||
"confirm" => "hiptofbees",
|
||||
"token" => invite.token
|
||||
:username => "vinny",
|
||||
:email => "pasta@pizza.vs",
|
||||
:fullname => "Vinny Vinesauce",
|
||||
:bio => "streamer",
|
||||
:password => "hiptofbees",
|
||||
:confirm => "hiptofbees",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
|
@ -269,13 +269,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
AccountView.render("show.json", %{user: fetched_user})
|
||||
|
||||
data = %{
|
||||
"nickname" => "GrimReaper",
|
||||
"email" => "death@reapers.afterlife",
|
||||
"fullname" => "Reaper Grim",
|
||||
"bio" => "Your time has come",
|
||||
"password" => "scythe",
|
||||
"confirm" => "scythe",
|
||||
"token" => invite.token
|
||||
:username => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
:password => "scythe",
|
||||
:confirm => "scythe",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:error, msg} = TwitterAPI.register_user(data)
|
||||
|
|
@ -292,13 +292,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
{:ok, invite} = UserInviteToken.create_invite(%{expires_at: Date.utc_today(), max_use: 100})
|
||||
|
||||
data = %{
|
||||
"nickname" => "vinny",
|
||||
"email" => "pasta@pizza.vs",
|
||||
"fullname" => "Vinny Vinesauce",
|
||||
"bio" => "streamer",
|
||||
"password" => "hiptofbees",
|
||||
"confirm" => "hiptofbees",
|
||||
"token" => invite.token
|
||||
:username => "vinny",
|
||||
:email => "pasta@pizza.vs",
|
||||
:fullname => "Vinny Vinesauce",
|
||||
:bio => "streamer",
|
||||
:password => "hiptofbees",
|
||||
:confirm => "hiptofbees",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
|
@ -317,13 +317,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
UserInviteToken.update_invite!(invite, uses: 99)
|
||||
|
||||
data = %{
|
||||
"nickname" => "vinny",
|
||||
"email" => "pasta@pizza.vs",
|
||||
"fullname" => "Vinny Vinesauce",
|
||||
"bio" => "streamer",
|
||||
"password" => "hiptofbees",
|
||||
"confirm" => "hiptofbees",
|
||||
"token" => invite.token
|
||||
:username => "vinny",
|
||||
:email => "pasta@pizza.vs",
|
||||
:fullname => "Vinny Vinesauce",
|
||||
:bio => "streamer",
|
||||
:password => "hiptofbees",
|
||||
:confirm => "hiptofbees",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
|
@ -335,13 +335,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
AccountView.render("show.json", %{user: fetched_user})
|
||||
|
||||
data = %{
|
||||
"nickname" => "GrimReaper",
|
||||
"email" => "death@reapers.afterlife",
|
||||
"fullname" => "Reaper Grim",
|
||||
"bio" => "Your time has come",
|
||||
"password" => "scythe",
|
||||
"confirm" => "scythe",
|
||||
"token" => invite.token
|
||||
:username => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
:password => "scythe",
|
||||
:confirm => "scythe",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:error, msg} = TwitterAPI.register_user(data)
|
||||
|
|
@ -355,13 +355,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
UserInviteToken.create_invite(%{expires_at: Date.add(Date.utc_today(), -1), max_use: 100})
|
||||
|
||||
data = %{
|
||||
"nickname" => "GrimReaper",
|
||||
"email" => "death@reapers.afterlife",
|
||||
"fullname" => "Reaper Grim",
|
||||
"bio" => "Your time has come",
|
||||
"password" => "scythe",
|
||||
"confirm" => "scythe",
|
||||
"token" => invite.token
|
||||
:username => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
:password => "scythe",
|
||||
:confirm => "scythe",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:error, msg} = TwitterAPI.register_user(data)
|
||||
|
|
@ -377,13 +377,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
UserInviteToken.update_invite!(invite, uses: 100)
|
||||
|
||||
data = %{
|
||||
"nickname" => "GrimReaper",
|
||||
"email" => "death@reapers.afterlife",
|
||||
"fullname" => "Reaper Grim",
|
||||
"bio" => "Your time has come",
|
||||
"password" => "scythe",
|
||||
"confirm" => "scythe",
|
||||
"token" => invite.token
|
||||
:username => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
:password => "scythe",
|
||||
:confirm => "scythe",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:error, msg} = TwitterAPI.register_user(data)
|
||||
|
|
@ -395,16 +395,15 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "it returns the error on registration problems" do
|
||||
data = %{
|
||||
"nickname" => "lain",
|
||||
"email" => "lain@wired.jp",
|
||||
"fullname" => "lain iwakura",
|
||||
"bio" => "close the world.",
|
||||
"password" => "bear"
|
||||
:username => "lain",
|
||||
:email => "lain@wired.jp",
|
||||
:fullname => "lain iwakura",
|
||||
:bio => "close the world."
|
||||
}
|
||||
|
||||
{:error, error_object} = TwitterAPI.register_user(data)
|
||||
{:error, error} = TwitterAPI.register_user(data)
|
||||
|
||||
assert is_binary(error_object[:error])
|
||||
assert is_binary(error)
|
||||
refute User.get_cached_by_nickname("lain")
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue