2019-06-14 09:19:22 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-06-14 09:19:22 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-06-23 15:16:47 +00:00
|
|
|
defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
2019-06-14 09:19:22 +00:00
|
|
|
alias Pleroma.Repo
|
|
|
|
alias Pleroma.User
|
|
|
|
|
|
|
|
use Pleroma.Web.ConnCase
|
|
|
|
|
2020-06-01 11:03:22 +00:00
|
|
|
import Mock
|
2019-06-14 09:19:22 +00:00
|
|
|
import Pleroma.Factory
|
2020-03-20 15:33:00 +00:00
|
|
|
|
2019-06-14 09:19:22 +00:00
|
|
|
describe "updating credentials" do
|
2019-12-19 14:23:27 +00:00
|
|
|
setup do: oauth_access(["write:accounts"])
|
2020-04-07 10:53:12 +00:00
|
|
|
setup :request_content_type
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
test "sets user settings in a generic way", %{conn: conn} do
|
2019-06-14 09:19:22 +00:00
|
|
|
res_conn =
|
2019-12-19 14:23:27 +00:00
|
|
|
patch(conn, "/api/v1/accounts/update_credentials", %{
|
2019-06-14 09:19:22 +00:00
|
|
|
"pleroma_settings_store" => %{
|
|
|
|
pleroma_fe: %{
|
|
|
|
theme: "bla"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-04-27 16:46:52 +00:00
|
|
|
assert user_data = json_response_and_validate_schema(res_conn, 200)
|
2019-12-19 14:23:27 +00:00
|
|
|
assert user_data["pleroma"]["settings_store"] == %{"pleroma_fe" => %{"theme" => "bla"}}
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
user = Repo.get(User, user_data["id"])
|
2019-06-14 09:19:22 +00:00
|
|
|
|
|
|
|
res_conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{
|
|
|
|
"pleroma_settings_store" => %{
|
|
|
|
masto_fe: %{
|
|
|
|
theme: "bla"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-04-27 16:46:52 +00:00
|
|
|
assert user_data = json_response_and_validate_schema(res_conn, 200)
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
assert user_data["pleroma"]["settings_store"] ==
|
2019-06-14 09:19:22 +00:00
|
|
|
%{
|
|
|
|
"pleroma_fe" => %{"theme" => "bla"},
|
|
|
|
"masto_fe" => %{"theme" => "bla"}
|
|
|
|
}
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
user = Repo.get(User, user_data["id"])
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2020-06-01 11:03:22 +00:00
|
|
|
clear_config([:instance, :federating], true)
|
|
|
|
|
|
|
|
with_mock Pleroma.Web.Federator,
|
|
|
|
publish: fn _activity -> :ok end do
|
|
|
|
res_conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{
|
|
|
|
"pleroma_settings_store" => %{
|
|
|
|
masto_fe: %{
|
|
|
|
theme: "blub"
|
|
|
|
}
|
2019-06-14 09:19:22 +00:00
|
|
|
}
|
2020-06-01 11:03:22 +00:00
|
|
|
})
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2020-06-01 11:03:22 +00:00
|
|
|
assert user_data = json_response_and_validate_schema(res_conn, 200)
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2020-06-01 11:03:22 +00:00
|
|
|
assert user_data["pleroma"]["settings_store"] ==
|
|
|
|
%{
|
|
|
|
"pleroma_fe" => %{"theme" => "bla"},
|
|
|
|
"masto_fe" => %{"theme" => "blub"}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_called(Pleroma.Web.Federator.publish(:_))
|
|
|
|
end
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "updates the user's bio", %{conn: conn} do
|
|
|
|
user2 = insert(:user)
|
|
|
|
|
2020-03-23 21:52:25 +00:00
|
|
|
raw_bio = "I drink #cofe with @#{user2.nickname}\n\nsuya.."
|
|
|
|
|
|
|
|
conn = patch(conn, "/api/v1/accounts/update_credentials", %{"note" => raw_bio})
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2020-04-27 16:46:52 +00:00
|
|
|
assert user_data = json_response_and_validate_schema(conn, 200)
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
assert user_data["note"] ==
|
2020-04-08 19:58:31 +00:00
|
|
|
~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="#{
|
2019-09-19 07:39:52 +00:00
|
|
|
user2.id
|
2020-04-08 19:58:31 +00:00
|
|
|
}" href="#{user2.ap_id}" rel="ugc">@<span>#{user2.nickname}</span></a></span><br/><br/>suya..)
|
2020-03-23 21:52:25 +00:00
|
|
|
|
|
|
|
assert user_data["source"]["note"] == raw_bio
|
|
|
|
|
|
|
|
user = Repo.get(User, user_data["id"])
|
|
|
|
|
|
|
|
assert user.raw_bio == raw_bio
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "updates the user's locking status", %{conn: conn} do
|
2019-12-19 14:23:27 +00:00
|
|
|
conn = patch(conn, "/api/v1/accounts/update_credentials", %{locked: "true"})
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2020-04-27 16:46:52 +00:00
|
|
|
assert user_data = json_response_and_validate_schema(conn, 200)
|
2019-12-19 14:23:27 +00:00
|
|
|
assert user_data["locked"] == true
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|
|
|
|
|
2020-07-03 13:54:25 +00:00
|
|
|
test "updates the user's chat acceptance status", %{conn: conn} do
|
|
|
|
conn = patch(conn, "/api/v1/accounts/update_credentials", %{accepts_chat_messages: "false"})
|
|
|
|
|
|
|
|
assert user_data = json_response_and_validate_schema(conn, 200)
|
|
|
|
assert user_data["pleroma"]["accepts_chat_messages"] == false
|
|
|
|
end
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
test "updates the user's allow_following_move", %{user: user, conn: conn} do
|
2019-11-12 11:36:50 +00:00
|
|
|
assert user.allow_following_move == true
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
conn = patch(conn, "/api/v1/accounts/update_credentials", %{allow_following_move: "false"})
|
2019-11-12 11:36:50 +00:00
|
|
|
|
|
|
|
assert refresh_record(user).allow_following_move == false
|
2020-04-27 16:46:52 +00:00
|
|
|
assert user_data = json_response_and_validate_schema(conn, 200)
|
2019-12-19 14:23:27 +00:00
|
|
|
assert user_data["pleroma"]["allow_following_move"] == false
|
2019-11-12 11:36:50 +00:00
|
|
|
end
|
|
|
|
|
2019-06-14 09:19:22 +00:00
|
|
|
test "updates the user's default scope", %{conn: conn} do
|
2020-04-07 12:18:23 +00:00
|
|
|
conn = patch(conn, "/api/v1/accounts/update_credentials", %{default_scope: "unlisted"})
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2020-04-27 16:46:52 +00:00
|
|
|
assert user_data = json_response_and_validate_schema(conn, 200)
|
2020-04-07 12:18:23 +00:00
|
|
|
assert user_data["source"]["privacy"] == "unlisted"
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|
|
|
|
|
2020-05-19 06:42:41 +00:00
|
|
|
test "updates the user's privacy", %{conn: conn} do
|
|
|
|
conn = patch(conn, "/api/v1/accounts/update_credentials", %{source: %{privacy: "unlisted"}})
|
|
|
|
|
|
|
|
assert user_data = json_response_and_validate_schema(conn, 200)
|
|
|
|
assert user_data["source"]["privacy"] == "unlisted"
|
|
|
|
end
|
|
|
|
|
2019-06-14 09:19:22 +00:00
|
|
|
test "updates the user's hide_followers status", %{conn: conn} do
|
2019-12-19 14:23:27 +00:00
|
|
|
conn = patch(conn, "/api/v1/accounts/update_credentials", %{hide_followers: "true"})
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2020-04-27 16:46:52 +00:00
|
|
|
assert user_data = json_response_and_validate_schema(conn, 200)
|
2019-12-19 14:23:27 +00:00
|
|
|
assert user_data["pleroma"]["hide_followers"] == true
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|
|
|
|
|
2020-03-25 14:46:17 +00:00
|
|
|
test "updates the user's discoverable status", %{conn: conn} do
|
|
|
|
assert %{"source" => %{"pleroma" => %{"discoverable" => true}}} =
|
|
|
|
conn
|
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{discoverable: "true"})
|
2020-04-27 16:46:52 +00:00
|
|
|
|> json_response_and_validate_schema(:ok)
|
2020-03-25 14:46:17 +00:00
|
|
|
|
|
|
|
assert %{"source" => %{"pleroma" => %{"discoverable" => false}}} =
|
|
|
|
conn
|
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{discoverable: "false"})
|
2020-04-27 16:46:52 +00:00
|
|
|
|> json_response_and_validate_schema(:ok)
|
2020-03-25 14:46:17 +00:00
|
|
|
end
|
|
|
|
|
2019-09-13 14:37:30 +00:00
|
|
|
test "updates the user's hide_followers_count and hide_follows_count", %{conn: conn} do
|
|
|
|
conn =
|
2019-12-19 14:23:27 +00:00
|
|
|
patch(conn, "/api/v1/accounts/update_credentials", %{
|
2019-09-13 14:37:30 +00:00
|
|
|
hide_followers_count: "true",
|
|
|
|
hide_follows_count: "true"
|
|
|
|
})
|
|
|
|
|
2020-04-27 16:46:52 +00:00
|
|
|
assert user_data = json_response_and_validate_schema(conn, 200)
|
2019-12-19 14:23:27 +00:00
|
|
|
assert user_data["pleroma"]["hide_followers_count"] == true
|
|
|
|
assert user_data["pleroma"]["hide_follows_count"] == true
|
2019-09-13 14:37:30 +00:00
|
|
|
end
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
test "updates the user's skip_thread_containment option", %{user: user, conn: conn} do
|
2019-06-14 09:19:22 +00:00
|
|
|
response =
|
|
|
|
conn
|
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{skip_thread_containment: "true"})
|
2020-04-27 16:46:52 +00:00
|
|
|
|> json_response_and_validate_schema(200)
|
2019-06-14 09:19:22 +00:00
|
|
|
|
|
|
|
assert response["pleroma"]["skip_thread_containment"] == true
|
2019-10-16 18:59:21 +00:00
|
|
|
assert refresh_record(user).skip_thread_containment
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "updates the user's hide_follows status", %{conn: conn} do
|
2019-12-19 14:23:27 +00:00
|
|
|
conn = patch(conn, "/api/v1/accounts/update_credentials", %{hide_follows: "true"})
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2020-04-27 16:46:52 +00:00
|
|
|
assert user_data = json_response_and_validate_schema(conn, 200)
|
2019-12-19 14:23:27 +00:00
|
|
|
assert user_data["pleroma"]["hide_follows"] == true
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "updates the user's hide_favorites status", %{conn: conn} do
|
2019-12-19 14:23:27 +00:00
|
|
|
conn = patch(conn, "/api/v1/accounts/update_credentials", %{hide_favorites: "true"})
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2020-04-27 16:46:52 +00:00
|
|
|
assert user_data = json_response_and_validate_schema(conn, 200)
|
2019-12-19 14:23:27 +00:00
|
|
|
assert user_data["pleroma"]["hide_favorites"] == true
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "updates the user's show_role status", %{conn: conn} do
|
2019-12-19 14:23:27 +00:00
|
|
|
conn = patch(conn, "/api/v1/accounts/update_credentials", %{show_role: "false"})
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2020-04-27 16:46:52 +00:00
|
|
|
assert user_data = json_response_and_validate_schema(conn, 200)
|
2019-12-19 14:23:27 +00:00
|
|
|
assert user_data["source"]["pleroma"]["show_role"] == false
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "updates the user's no_rich_text status", %{conn: conn} do
|
2019-12-19 14:23:27 +00:00
|
|
|
conn = patch(conn, "/api/v1/accounts/update_credentials", %{no_rich_text: "true"})
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2020-04-27 16:46:52 +00:00
|
|
|
assert user_data = json_response_and_validate_schema(conn, 200)
|
2019-12-19 14:23:27 +00:00
|
|
|
assert user_data["source"]["pleroma"]["no_rich_text"] == true
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "updates the user's name", %{conn: conn} do
|
|
|
|
conn =
|
2019-12-19 14:23:27 +00:00
|
|
|
patch(conn, "/api/v1/accounts/update_credentials", %{"display_name" => "markorepairs"})
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2020-04-27 16:46:52 +00:00
|
|
|
assert user_data = json_response_and_validate_schema(conn, 200)
|
2019-12-19 14:23:27 +00:00
|
|
|
assert user_data["display_name"] == "markorepairs"
|
2020-08-10 08:33:05 +00:00
|
|
|
|
|
|
|
update_activity = Repo.one(Pleroma.Activity)
|
|
|
|
assert update_activity.data["type"] == "Update"
|
|
|
|
assert update_activity.data["object"]["name"] == "markorepairs"
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|
|
|
|
|
2020-08-07 21:48:03 +00:00
|
|
|
test "updates the user's AKAs", %{conn: conn} do
|
|
|
|
conn =
|
|
|
|
patch(conn, "/api/v1/accounts/update_credentials", %{
|
|
|
|
"also_known_as" => ["https://mushroom.kingdom/users/mario"]
|
|
|
|
})
|
|
|
|
|
|
|
|
assert user_data = json_response_and_validate_schema(conn, 200)
|
|
|
|
assert user_data["pleroma"]["also_known_as"] == ["https://mushroom.kingdom/users/mario"]
|
|
|
|
end
|
|
|
|
|
2021-01-05 12:10:14 +00:00
|
|
|
test "doesn't update non-url akas", %{conn: conn} do
|
|
|
|
conn =
|
|
|
|
patch(conn, "/api/v1/accounts/update_credentials", %{
|
|
|
|
"also_known_as" => ["aReallyCoolGuy"]
|
|
|
|
})
|
|
|
|
|
|
|
|
assert json_response_and_validate_schema(conn, 403)
|
|
|
|
end
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
test "updates the user's avatar", %{user: user, conn: conn} do
|
2019-06-14 09:19:22 +00:00
|
|
|
new_avatar = %Plug.Upload{
|
2020-10-13 15:37:24 +00:00
|
|
|
content_type: "image/jpeg",
|
2019-06-14 09:19:22 +00:00
|
|
|
path: Path.absname("test/fixtures/image.jpg"),
|
|
|
|
filename: "an_image.jpg"
|
|
|
|
}
|
|
|
|
|
2020-07-07 14:20:50 +00:00
|
|
|
assert user.avatar == %{}
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2020-07-07 14:20:50 +00:00
|
|
|
res = patch(conn, "/api/v1/accounts/update_credentials", %{"avatar" => new_avatar})
|
|
|
|
|
|
|
|
assert user_response = json_response_and_validate_schema(res, 200)
|
2019-06-14 09:19:22 +00:00
|
|
|
assert user_response["avatar"] != User.avatar_url(user)
|
2020-07-07 14:20:50 +00:00
|
|
|
|
|
|
|
user = User.get_by_id(user.id)
|
|
|
|
refute user.avatar == %{}
|
|
|
|
|
|
|
|
# Also resets it
|
|
|
|
_res = patch(conn, "/api/v1/accounts/update_credentials", %{"avatar" => ""})
|
|
|
|
|
|
|
|
user = User.get_by_id(user.id)
|
|
|
|
assert user.avatar == nil
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
test "updates the user's banner", %{user: user, conn: conn} do
|
2019-06-14 09:19:22 +00:00
|
|
|
new_header = %Plug.Upload{
|
2020-10-13 15:37:24 +00:00
|
|
|
content_type: "image/jpeg",
|
2019-06-14 09:19:22 +00:00
|
|
|
path: Path.absname("test/fixtures/image.jpg"),
|
|
|
|
filename: "an_image.jpg"
|
|
|
|
}
|
|
|
|
|
2020-07-07 14:20:50 +00:00
|
|
|
res = patch(conn, "/api/v1/accounts/update_credentials", %{"header" => new_header})
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2020-07-07 14:20:50 +00:00
|
|
|
assert user_response = json_response_and_validate_schema(res, 200)
|
2019-06-14 09:19:22 +00:00
|
|
|
assert user_response["header"] != User.banner_url(user)
|
2020-07-07 14:20:50 +00:00
|
|
|
|
|
|
|
# Also resets it
|
|
|
|
_res = patch(conn, "/api/v1/accounts/update_credentials", %{"header" => ""})
|
|
|
|
|
|
|
|
user = User.get_by_id(user.id)
|
|
|
|
assert user.banner == nil
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|
|
|
|
|
2020-07-07 14:20:50 +00:00
|
|
|
test "updates the user's background", %{conn: conn, user: user} do
|
2019-06-14 09:19:22 +00:00
|
|
|
new_header = %Plug.Upload{
|
2020-10-13 15:37:24 +00:00
|
|
|
content_type: "image/jpeg",
|
2019-06-14 09:19:22 +00:00
|
|
|
path: Path.absname("test/fixtures/image.jpg"),
|
|
|
|
filename: "an_image.jpg"
|
|
|
|
}
|
|
|
|
|
2020-07-07 14:20:50 +00:00
|
|
|
res =
|
2020-07-01 08:51:56 +00:00
|
|
|
patch(conn, "/api/v1/accounts/update_credentials", %{
|
2019-06-14 09:19:22 +00:00
|
|
|
"pleroma_background_image" => new_header
|
|
|
|
})
|
|
|
|
|
2020-07-07 14:20:50 +00:00
|
|
|
assert user_response = json_response_and_validate_schema(res, 200)
|
2019-06-14 09:19:22 +00:00
|
|
|
assert user_response["pleroma"]["background_image"]
|
2020-07-07 14:20:50 +00:00
|
|
|
#
|
|
|
|
# Also resets it
|
|
|
|
_res =
|
|
|
|
patch(conn, "/api/v1/accounts/update_credentials", %{"pleroma_background_image" => ""})
|
|
|
|
|
|
|
|
user = User.get_by_id(user.id)
|
|
|
|
assert user.background == nil
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
test "requires 'write:accounts' permission" do
|
2019-06-14 09:19:22 +00:00
|
|
|
token1 = insert(:oauth_token, scopes: ["read"])
|
|
|
|
token2 = insert(:oauth_token, scopes: ["write", "follow"])
|
|
|
|
|
|
|
|
for token <- [token1, token2] do
|
|
|
|
conn =
|
2019-12-19 14:23:27 +00:00
|
|
|
build_conn()
|
2020-04-07 10:53:12 +00:00
|
|
|
|> put_req_header("content-type", "multipart/form-data")
|
2019-06-14 09:19:22 +00:00
|
|
|
|> put_req_header("authorization", "Bearer #{token.token}")
|
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{})
|
|
|
|
|
|
|
|
if token == token1 do
|
2019-09-15 15:22:08 +00:00
|
|
|
assert %{"error" => "Insufficient permissions: write:accounts."} ==
|
2020-04-27 16:46:52 +00:00
|
|
|
json_response_and_validate_schema(conn, 403)
|
2019-06-14 09:19:22 +00:00
|
|
|
else
|
2020-04-27 16:46:52 +00:00
|
|
|
assert json_response_and_validate_schema(conn, 200)
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
test "updates profile emojos", %{user: user, conn: conn} do
|
2019-06-14 09:19:22 +00:00
|
|
|
note = "*sips :blank:*"
|
|
|
|
name = "I am :firefox:"
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
ret_conn =
|
|
|
|
patch(conn, "/api/v1/accounts/update_credentials", %{
|
2019-06-14 09:19:22 +00:00
|
|
|
"note" => note,
|
|
|
|
"display_name" => name
|
|
|
|
})
|
|
|
|
|
2020-04-27 16:46:52 +00:00
|
|
|
assert json_response_and_validate_schema(ret_conn, 200)
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
conn = get(conn, "/api/v1/accounts/#{user.id}")
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2020-04-27 16:46:52 +00:00
|
|
|
assert user_data = json_response_and_validate_schema(conn, 200)
|
2019-06-14 09:19:22 +00:00
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
assert user_data["note"] == note
|
|
|
|
assert user_data["display_name"] == name
|
|
|
|
assert [%{"shortcode" => "blank"}, %{"shortcode" => "firefox"}] = user_data["emojis"]
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|
2019-07-24 12:26:35 +00:00
|
|
|
|
|
|
|
test "update fields", %{conn: conn} do
|
|
|
|
fields = [
|
2019-08-06 11:21:25 +00:00
|
|
|
%{"name" => "<a href=\"http://google.com\">foo</a>", "value" => "<script>bar</script>"},
|
2020-03-31 15:05:13 +00:00
|
|
|
%{"name" => "link.io", "value" => "cofe.io"}
|
2019-07-24 12:26:35 +00:00
|
|
|
]
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
account_data =
|
2019-07-24 12:26:35 +00:00
|
|
|
conn
|
2019-08-24 21:51:05 +00:00
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
2020-04-27 16:46:52 +00:00
|
|
|
|> json_response_and_validate_schema(200)
|
2019-07-24 12:26:35 +00:00
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
assert account_data["fields"] == [
|
2020-01-30 16:47:57 +00:00
|
|
|
%{"name" => "<a href=\"http://google.com\">foo</a>", "value" => "bar"},
|
2020-03-31 15:05:13 +00:00
|
|
|
%{
|
|
|
|
"name" => "link.io",
|
|
|
|
"value" => ~S(<a href="http://cofe.io" rel="ugc">cofe.io</a>)
|
|
|
|
}
|
2019-07-24 12:26:35 +00:00
|
|
|
]
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
assert account_data["source"]["fields"] == [
|
2019-08-06 11:21:25 +00:00
|
|
|
%{
|
|
|
|
"name" => "<a href=\"http://google.com\">foo</a>",
|
|
|
|
"value" => "<script>bar</script>"
|
|
|
|
},
|
2020-03-31 15:05:13 +00:00
|
|
|
%{"name" => "link.io", "value" => "cofe.io"}
|
2019-07-24 12:26:35 +00:00
|
|
|
]
|
2020-03-31 15:05:13 +00:00
|
|
|
end
|
2019-07-24 12:26:35 +00:00
|
|
|
|
2020-07-09 17:07:07 +00:00
|
|
|
test "emojis in fields labels", %{conn: conn} do
|
|
|
|
fields = [
|
|
|
|
%{"name" => ":firefox:", "value" => "is best 2hu"},
|
|
|
|
%{"name" => "they wins", "value" => ":blank:"}
|
|
|
|
]
|
|
|
|
|
|
|
|
account_data =
|
|
|
|
conn
|
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
assert account_data["fields"] == [
|
|
|
|
%{"name" => ":firefox:", "value" => "is best 2hu"},
|
|
|
|
%{"name" => "they wins", "value" => ":blank:"}
|
|
|
|
]
|
|
|
|
|
|
|
|
assert account_data["source"]["fields"] == [
|
|
|
|
%{"name" => ":firefox:", "value" => "is best 2hu"},
|
|
|
|
%{"name" => "they wins", "value" => ":blank:"}
|
|
|
|
]
|
|
|
|
|
|
|
|
assert [%{"shortcode" => "blank"}, %{"shortcode" => "firefox"}] = account_data["emojis"]
|
|
|
|
end
|
|
|
|
|
2020-04-07 08:44:53 +00:00
|
|
|
test "update fields via x-www-form-urlencoded", %{conn: conn} do
|
2019-08-25 18:49:47 +00:00
|
|
|
fields =
|
|
|
|
[
|
|
|
|
"fields_attributes[1][name]=link",
|
2020-03-31 15:05:13 +00:00
|
|
|
"fields_attributes[1][value]=http://cofe.io",
|
|
|
|
"fields_attributes[0][name]=foo",
|
2019-08-25 18:49:47 +00:00
|
|
|
"fields_attributes[0][value]=bar"
|
|
|
|
]
|
|
|
|
|> Enum.join("&")
|
|
|
|
|
|
|
|
account =
|
|
|
|
conn
|
|
|
|
|> put_req_header("content-type", "application/x-www-form-urlencoded")
|
|
|
|
|> patch("/api/v1/accounts/update_credentials", fields)
|
2020-04-27 16:46:52 +00:00
|
|
|
|> json_response_and_validate_schema(200)
|
2019-08-25 18:49:47 +00:00
|
|
|
|
|
|
|
assert account["fields"] == [
|
2020-03-31 15:05:13 +00:00
|
|
|
%{"name" => "foo", "value" => "bar"},
|
|
|
|
%{
|
|
|
|
"name" => "link",
|
|
|
|
"value" => ~S(<a href="http://cofe.io" rel="ugc">http://cofe.io</a>)
|
|
|
|
}
|
2019-08-25 18:49:47 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
assert account["source"]["fields"] == [
|
2020-03-31 15:05:13 +00:00
|
|
|
%{"name" => "foo", "value" => "bar"},
|
|
|
|
%{"name" => "link", "value" => "http://cofe.io"}
|
2019-08-25 18:49:47 +00:00
|
|
|
]
|
2020-03-31 15:05:13 +00:00
|
|
|
end
|
2019-08-25 18:49:47 +00:00
|
|
|
|
2020-03-31 15:05:13 +00:00
|
|
|
test "update fields with empty name", %{conn: conn} do
|
|
|
|
fields = [
|
|
|
|
%{"name" => "foo", "value" => ""},
|
|
|
|
%{"name" => "", "value" => "bar"}
|
|
|
|
]
|
|
|
|
|
|
|
|
account =
|
|
|
|
conn
|
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
2020-04-27 16:46:52 +00:00
|
|
|
|> json_response_and_validate_schema(200)
|
2020-03-31 15:05:13 +00:00
|
|
|
|
|
|
|
assert account["fields"] == [
|
|
|
|
%{"name" => "foo", "value" => ""}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "update fields when invalid request", %{conn: conn} do
|
2019-08-01 08:09:15 +00:00
|
|
|
name_limit = Pleroma.Config.get([:instance, :account_field_name_length])
|
2019-07-30 10:22:52 +00:00
|
|
|
value_limit = Pleroma.Config.get([:instance, :account_field_value_length])
|
|
|
|
|
2020-03-31 15:05:13 +00:00
|
|
|
long_name = Enum.map(0..name_limit, fn _ -> "x" end) |> Enum.join()
|
2019-08-01 08:09:15 +00:00
|
|
|
long_value = Enum.map(0..value_limit, fn _ -> "x" end) |> Enum.join()
|
2019-07-30 10:22:52 +00:00
|
|
|
|
2020-03-31 15:05:13 +00:00
|
|
|
fields = [%{"name" => "foo", "value" => long_value}]
|
2019-07-30 10:22:52 +00:00
|
|
|
|
|
|
|
assert %{"error" => "Invalid request"} ==
|
|
|
|
conn
|
2019-08-24 21:51:05 +00:00
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
2020-04-27 16:46:52 +00:00
|
|
|
|> json_response_and_validate_schema(403)
|
2019-07-30 10:22:52 +00:00
|
|
|
|
2019-08-01 08:09:15 +00:00
|
|
|
fields = [%{"name" => long_name, "value" => "bar"}]
|
2019-07-30 10:22:52 +00:00
|
|
|
|
|
|
|
assert %{"error" => "Invalid request"} ==
|
|
|
|
conn
|
2019-08-24 21:51:05 +00:00
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
2020-04-27 16:46:52 +00:00
|
|
|
|> json_response_and_validate_schema(403)
|
2019-07-30 10:22:52 +00:00
|
|
|
|
2020-12-21 14:05:56 +00:00
|
|
|
clear_config([:instance, :max_account_fields], 1)
|
2019-07-24 12:26:35 +00:00
|
|
|
|
|
|
|
fields = [
|
2020-03-31 15:05:13 +00:00
|
|
|
%{"name" => "foo", "value" => "bar"},
|
2019-07-24 12:26:35 +00:00
|
|
|
%{"name" => "link", "value" => "cofe.io"}
|
|
|
|
]
|
|
|
|
|
2019-07-30 10:22:52 +00:00
|
|
|
assert %{"error" => "Invalid request"} ==
|
|
|
|
conn
|
2019-08-24 21:51:05 +00:00
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
2020-04-27 16:46:52 +00:00
|
|
|
|> json_response_and_validate_schema(403)
|
2019-07-24 12:26:35 +00:00
|
|
|
end
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|
2020-06-19 19:18:07 +00:00
|
|
|
|
|
|
|
describe "Mark account as bot" do
|
|
|
|
setup do: oauth_access(["write:accounts"])
|
|
|
|
setup :request_content_type
|
|
|
|
|
|
|
|
test "changing actor_type to Service makes account a bot", %{conn: conn} do
|
|
|
|
account =
|
|
|
|
conn
|
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{actor_type: "Service"})
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
assert account["bot"]
|
|
|
|
assert account["source"]["pleroma"]["actor_type"] == "Service"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "changing actor_type to Person makes account a human", %{conn: conn} do
|
|
|
|
account =
|
|
|
|
conn
|
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{actor_type: "Person"})
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
refute account["bot"]
|
|
|
|
assert account["source"]["pleroma"]["actor_type"] == "Person"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "changing actor_type to Application causes error", %{conn: conn} do
|
|
|
|
response =
|
|
|
|
conn
|
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{actor_type: "Application"})
|
|
|
|
|> json_response_and_validate_schema(403)
|
|
|
|
|
|
|
|
assert %{"error" => "Invalid request"} == response
|
|
|
|
end
|
|
|
|
|
|
|
|
test "changing bot field to true changes actor_type to Service", %{conn: conn} do
|
|
|
|
account =
|
|
|
|
conn
|
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{bot: "true"})
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
assert account["bot"]
|
|
|
|
assert account["source"]["pleroma"]["actor_type"] == "Service"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "changing bot field to false changes actor_type to Person", %{conn: conn} do
|
|
|
|
account =
|
|
|
|
conn
|
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{bot: "false"})
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
refute account["bot"]
|
|
|
|
assert account["source"]["pleroma"]["actor_type"] == "Person"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "actor_type field has a higher priority than bot", %{conn: conn} do
|
|
|
|
account =
|
|
|
|
conn
|
|
|
|
|> patch("/api/v1/accounts/update_credentials", %{
|
|
|
|
actor_type: "Person",
|
|
|
|
bot: "true"
|
|
|
|
})
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
refute account["bot"]
|
|
|
|
assert account["source"]["pleroma"]["actor_type"] == "Person"
|
|
|
|
end
|
|
|
|
end
|
2019-06-14 09:19:22 +00:00
|
|
|
end
|