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