Merge remote-tracking branch 'pleroma/develop' into feature/disable-account
This commit is contained in:
commit
1557b99beb
107 changed files with 2297 additions and 616 deletions
83
test/bbs/handler_test.exs
Normal file
83
test/bbs/handler_test.exs
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
defmodule Pleroma.BBS.HandlerTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.BBS.Handler
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import ExUnit.CaptureIO
|
||||
import Pleroma.Factory
|
||||
import Ecto.Query
|
||||
|
||||
test "getting the home timeline" do
|
||||
user = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
||||
{:ok, user} = User.follow(user, followed)
|
||||
|
||||
{:ok, _first} = CommonAPI.post(user, %{"status" => "hey"})
|
||||
{:ok, _second} = CommonAPI.post(followed, %{"status" => "hello"})
|
||||
|
||||
output =
|
||||
capture_io(fn ->
|
||||
Handler.handle_command(%{user: user}, "home")
|
||||
end)
|
||||
|
||||
assert output =~ user.nickname
|
||||
assert output =~ followed.nickname
|
||||
|
||||
assert output =~ "hey"
|
||||
assert output =~ "hello"
|
||||
end
|
||||
|
||||
test "posting" do
|
||||
user = insert(:user)
|
||||
|
||||
output =
|
||||
capture_io(fn ->
|
||||
Handler.handle_command(%{user: user}, "p this is a test post")
|
||||
end)
|
||||
|
||||
assert output =~ "Posted"
|
||||
|
||||
activity =
|
||||
Repo.one(
|
||||
from(a in Activity,
|
||||
where: fragment("?->>'type' = ?", a.data, "Create")
|
||||
)
|
||||
)
|
||||
|
||||
assert activity.actor == user.ap_id
|
||||
object = Object.normalize(activity)
|
||||
assert object.data["content"] == "this is a test post"
|
||||
end
|
||||
|
||||
test "replying" do
|
||||
user = insert(:user)
|
||||
another_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(another_user, %{"status" => "this is a test post"})
|
||||
|
||||
output =
|
||||
capture_io(fn ->
|
||||
Handler.handle_command(%{user: user}, "r #{activity.id} this is a reply")
|
||||
end)
|
||||
|
||||
assert output =~ "Replied"
|
||||
|
||||
reply =
|
||||
Repo.one(
|
||||
from(a in Activity,
|
||||
where: fragment("?->>'type' = ?", a.data, "Create"),
|
||||
where: a.actor == ^user.ap_id
|
||||
)
|
||||
)
|
||||
|
||||
assert reply.actor == user.ap_id
|
||||
object = Object.normalize(reply)
|
||||
assert object.data["content"] == "this is a reply"
|
||||
assert object.data["inReplyTo"] == activity.data["object"]
|
||||
end
|
||||
end
|
||||
52
test/bookmark_test.exs
Normal file
52
test/bookmark_test.exs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
defmodule Pleroma.BookmarkTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Bookmark
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
describe "create/2" do
|
||||
test "with valid params" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Some cool information"})
|
||||
{:ok, bookmark} = Bookmark.create(user.id, activity.id)
|
||||
assert bookmark.user_id == user.id
|
||||
assert bookmark.activity_id == activity.id
|
||||
end
|
||||
|
||||
test "with invalid params" do
|
||||
{:error, changeset} = Bookmark.create(nil, "")
|
||||
refute changeset.valid?
|
||||
|
||||
assert changeset.errors == [
|
||||
user_id: {"can't be blank", [validation: :required]},
|
||||
activity_id: {"can't be blank", [validation: :required]}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
describe "destroy/2" do
|
||||
test "with valid params" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Some cool information"})
|
||||
{:ok, _bookmark} = Bookmark.create(user.id, activity.id)
|
||||
|
||||
{:ok, _deleted_bookmark} = Bookmark.destroy(user.id, activity.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "get/2" do
|
||||
test "gets a bookmark" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
"status" =>
|
||||
"Scientists Discover The Secret Behind Tenshi Eating A Corndog Being So Cute – Science Daily"
|
||||
})
|
||||
|
||||
{:ok, bookmark} = Bookmark.create(user.id, activity.id)
|
||||
assert bookmark == Bookmark.get(user.id, activity.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -147,7 +147,7 @@ defmodule Pleroma.FormatterTest do
|
|||
end
|
||||
|
||||
test "gives a replacement for user links when the user is using Osada" do
|
||||
mike = User.get_or_fetch("mike@osada.macgirvin.com")
|
||||
{:ok, mike} = User.get_or_fetch("mike@osada.macgirvin.com")
|
||||
|
||||
text = "@mike@osada.macgirvin.com test"
|
||||
|
||||
|
|
@ -248,7 +248,7 @@ defmodule Pleroma.FormatterTest do
|
|||
text = "I love :firefox:"
|
||||
|
||||
expected_result =
|
||||
"I love <img height=\"32px\" width=\"32px\" alt=\"firefox\" title=\"firefox\" src=\"/emoji/Firefox.gif\" />"
|
||||
"I love <img class=\"emoji\" alt=\"firefox\" title=\"firefox\" src=\"/emoji/Firefox.gif\" />"
|
||||
|
||||
assert Formatter.emojify(text) == expected_result
|
||||
end
|
||||
|
|
@ -263,7 +263,7 @@ defmodule Pleroma.FormatterTest do
|
|||
}
|
||||
|
||||
expected_result =
|
||||
"I love <img height=\"32px\" width=\"32px\" alt=\"\" title=\"\" src=\"https://placehold.it/1x1\" />"
|
||||
"I love <img class=\"emoji\" alt=\"\" title=\"\" src=\"https://placehold.it/1x1\" />"
|
||||
|
||||
assert Formatter.emojify(text, custom_emoji) == expected_result
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,6 +20,18 @@ defmodule Pleroma.HTMLTest do
|
|||
<img src="http://example.com/image.jpg" onerror="alert('hacked')">
|
||||
"""
|
||||
|
||||
@html_span_class_sample """
|
||||
<span class="animate-spin">hi</span>
|
||||
"""
|
||||
|
||||
@html_span_microformats_sample """
|
||||
<span class="h-card"><a class="u-url mention">@<span>foo</span></a></span>
|
||||
"""
|
||||
|
||||
@html_span_invalid_microformats_sample """
|
||||
<span class="h-card"><a class="u-url mention animate-spin">@<span>foo</span></a></span>
|
||||
"""
|
||||
|
||||
describe "StripTags scrubber" do
|
||||
test "works as expected" do
|
||||
expected = """
|
||||
|
|
@ -64,6 +76,36 @@ defmodule Pleroma.HTMLTest do
|
|||
|
||||
assert expected == HTML.filter_tags(@html_onerror_sample, Pleroma.HTML.Scrubber.TwitterText)
|
||||
end
|
||||
|
||||
test "does not allow spans with invalid classes" do
|
||||
expected = """
|
||||
<span>hi</span>
|
||||
"""
|
||||
|
||||
assert expected ==
|
||||
HTML.filter_tags(@html_span_class_sample, Pleroma.HTML.Scrubber.TwitterText)
|
||||
end
|
||||
|
||||
test "does allow microformats" do
|
||||
expected = """
|
||||
<span class="h-card"><a class="u-url mention">@<span>foo</span></a></span>
|
||||
"""
|
||||
|
||||
assert expected ==
|
||||
HTML.filter_tags(@html_span_microformats_sample, Pleroma.HTML.Scrubber.TwitterText)
|
||||
end
|
||||
|
||||
test "filters invalid microformats markup" do
|
||||
expected = """
|
||||
<span class="h-card"><a>@<span>foo</span></a></span>
|
||||
"""
|
||||
|
||||
assert expected ==
|
||||
HTML.filter_tags(
|
||||
@html_span_invalid_microformats_sample,
|
||||
Pleroma.HTML.Scrubber.TwitterText
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "default scrubber" do
|
||||
|
|
@ -88,5 +130,34 @@ defmodule Pleroma.HTMLTest do
|
|||
|
||||
assert expected == HTML.filter_tags(@html_onerror_sample, Pleroma.HTML.Scrubber.Default)
|
||||
end
|
||||
|
||||
test "does not allow spans with invalid classes" do
|
||||
expected = """
|
||||
<span>hi</span>
|
||||
"""
|
||||
|
||||
assert expected == HTML.filter_tags(@html_span_class_sample, Pleroma.HTML.Scrubber.Default)
|
||||
end
|
||||
|
||||
test "does allow microformats" do
|
||||
expected = """
|
||||
<span class="h-card"><a class="u-url mention">@<span>foo</span></a></span>
|
||||
"""
|
||||
|
||||
assert expected ==
|
||||
HTML.filter_tags(@html_span_microformats_sample, Pleroma.HTML.Scrubber.Default)
|
||||
end
|
||||
|
||||
test "filters invalid microformats markup" do
|
||||
expected = """
|
||||
<span class="h-card"><a>@<span>foo</span></a></span>
|
||||
"""
|
||||
|
||||
assert expected ==
|
||||
HTML.filter_tags(
|
||||
@html_span_invalid_microformats_sample,
|
||||
Pleroma.HTML.Scrubber.Default
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@ defmodule Pleroma.MediaProxyTest do
|
|||
import Pleroma.Web.MediaProxy
|
||||
alias Pleroma.Web.MediaProxy.MediaProxyController
|
||||
|
||||
setup do
|
||||
enabled = Pleroma.Config.get([:media_proxy, :enabled])
|
||||
on_exit(fn -> Pleroma.Config.put([:media_proxy, :enabled], enabled) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "when enabled" do
|
||||
setup do
|
||||
enabled = Pleroma.Config.get([:media_proxy, :enabled])
|
||||
|
||||
unless enabled do
|
||||
Pleroma.Config.put([:media_proxy, :enabled], true)
|
||||
on_exit(fn -> Pleroma.Config.put([:media_proxy, :enabled], enabled) end)
|
||||
end
|
||||
|
||||
Pleroma.Config.put([:media_proxy, :enabled], true)
|
||||
:ok
|
||||
end
|
||||
|
||||
|
|
@ -177,4 +177,13 @@ defmodule Pleroma.MediaProxyTest do
|
|||
{:ok, decoded} = decode_url(sig, base64)
|
||||
decoded
|
||||
end
|
||||
|
||||
test "mediaproxy whitelist" do
|
||||
Pleroma.Config.put([:media_proxy, :enabled], true)
|
||||
Pleroma.Config.put([:media_proxy, :whitelist], ["google.com", "feld.me"])
|
||||
url = "https://feld.me/foo.png"
|
||||
|
||||
unencoded = url(url)
|
||||
assert unencoded == url
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -38,6 +38,26 @@ defmodule Pleroma.Plugs.OAuthPlugTest do
|
|||
assert conn.assigns[:user] == opts[:user]
|
||||
end
|
||||
|
||||
test "with valid token(downcase) in url parameters, it assings the user", opts do
|
||||
conn =
|
||||
:get
|
||||
|> build_conn("/?access_token=#{opts[:token]}")
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> fetch_query_params()
|
||||
|> OAuthPlug.call(%{})
|
||||
|
||||
assert conn.assigns[:user] == opts[:user]
|
||||
end
|
||||
|
||||
test "with valid token(downcase) in body parameters, it assigns the user", opts do
|
||||
conn =
|
||||
:post
|
||||
|> build_conn("/api/v1/statuses", access_token: opts[:token], status: "test")
|
||||
|> OAuthPlug.call(%{})
|
||||
|
||||
assert conn.assigns[:user] == opts[:user]
|
||||
end
|
||||
|
||||
test "with invalid token, it not assigns the user", %{conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|
|
|
|||
44
test/repo_test.exs
Normal file
44
test/repo_test.exs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
defmodule Pleroma.RepoTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "find_resource/1" do
|
||||
test "returns user" do
|
||||
user = insert(:user)
|
||||
query = from(t in Pleroma.User, where: t.id == ^user.id)
|
||||
assert Repo.find_resource(query) == {:ok, user}
|
||||
end
|
||||
|
||||
test "returns not_found" do
|
||||
query = from(t in Pleroma.User, where: t.id == ^"9gBuXNpD2NyDmmxxdw")
|
||||
assert Repo.find_resource(query) == {:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_assoc/2" do
|
||||
test "get assoc from preloaded data" do
|
||||
user = %Pleroma.User{name: "Agent Smith"}
|
||||
token = %Pleroma.Web.OAuth.Token{insert(:oauth_token) | user: user}
|
||||
assert Repo.get_assoc(token, :user) == {:ok, user}
|
||||
end
|
||||
|
||||
test "get one-to-one assoc from repo" do
|
||||
user = insert(:user, name: "Jimi Hendrix")
|
||||
token = refresh_record(insert(:oauth_token, user: user))
|
||||
|
||||
assert Repo.get_assoc(token, :user) == {:ok, user}
|
||||
end
|
||||
|
||||
test "get one-to-many assoc from repo" do
|
||||
user = insert(:user)
|
||||
notification = refresh_record(insert(:notification, user: user))
|
||||
|
||||
assert Repo.get_assoc(user, :notifications) == {:ok, [notification]}
|
||||
end
|
||||
|
||||
test "return error if has not assoc " do
|
||||
token = insert(:oauth_token, user: nil)
|
||||
assert Repo.get_assoc(token, :user) == {:error, :not_found}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -363,7 +363,7 @@ defmodule Pleroma.UserTest do
|
|||
describe "get_or_fetch/1" do
|
||||
test "gets an existing user by nickname" do
|
||||
user = insert(:user)
|
||||
fetched_user = User.get_or_fetch(user.nickname)
|
||||
{:ok, fetched_user} = User.get_or_fetch(user.nickname)
|
||||
|
||||
assert user == fetched_user
|
||||
end
|
||||
|
|
@ -380,7 +380,7 @@ defmodule Pleroma.UserTest do
|
|||
info: %{}
|
||||
)
|
||||
|
||||
fetched_user = User.get_or_fetch(ap_id)
|
||||
{:ok, fetched_user} = User.get_or_fetch(ap_id)
|
||||
freshed_user = refresh_record(user)
|
||||
assert freshed_user == fetched_user
|
||||
end
|
||||
|
|
@ -389,14 +389,14 @@ defmodule Pleroma.UserTest do
|
|||
describe "fetching a user from nickname or trying to build one" do
|
||||
test "gets an existing user" do
|
||||
user = insert(:user)
|
||||
fetched_user = User.get_or_fetch_by_nickname(user.nickname)
|
||||
{:ok, fetched_user} = User.get_or_fetch_by_nickname(user.nickname)
|
||||
|
||||
assert user == fetched_user
|
||||
end
|
||||
|
||||
test "gets an existing user, case insensitive" do
|
||||
user = insert(:user, nickname: "nick")
|
||||
fetched_user = User.get_or_fetch_by_nickname("NICK")
|
||||
{:ok, fetched_user} = User.get_or_fetch_by_nickname("NICK")
|
||||
|
||||
assert user == fetched_user
|
||||
end
|
||||
|
|
@ -404,7 +404,7 @@ defmodule Pleroma.UserTest do
|
|||
test "gets an existing user by fully qualified nickname" do
|
||||
user = insert(:user)
|
||||
|
||||
fetched_user =
|
||||
{:ok, fetched_user} =
|
||||
User.get_or_fetch_by_nickname(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
|
||||
|
||||
assert user == fetched_user
|
||||
|
|
@ -414,24 +414,24 @@ defmodule Pleroma.UserTest do
|
|||
user = insert(:user, nickname: "nick")
|
||||
casing_altered_fqn = String.upcase(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
|
||||
|
||||
fetched_user = User.get_or_fetch_by_nickname(casing_altered_fqn)
|
||||
{:ok, fetched_user} = User.get_or_fetch_by_nickname(casing_altered_fqn)
|
||||
|
||||
assert user == fetched_user
|
||||
end
|
||||
|
||||
test "fetches an external user via ostatus if no user exists" do
|
||||
fetched_user = User.get_or_fetch_by_nickname("shp@social.heldscal.la")
|
||||
{:ok, fetched_user} = User.get_or_fetch_by_nickname("shp@social.heldscal.la")
|
||||
assert fetched_user.nickname == "shp@social.heldscal.la"
|
||||
end
|
||||
|
||||
test "returns nil if no user could be fetched" do
|
||||
fetched_user = User.get_or_fetch_by_nickname("nonexistant@social.heldscal.la")
|
||||
assert fetched_user == nil
|
||||
{:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant@social.heldscal.la")
|
||||
assert fetched_user == "not found nonexistant@social.heldscal.la"
|
||||
end
|
||||
|
||||
test "returns nil for nonexistant local user" do
|
||||
fetched_user = User.get_or_fetch_by_nickname("nonexistant")
|
||||
assert fetched_user == nil
|
||||
{:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant")
|
||||
assert fetched_user == "not found nonexistant"
|
||||
end
|
||||
|
||||
test "updates an existing user, if stale" do
|
||||
|
|
@ -449,7 +449,7 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
assert orig_user.last_refreshed_at == a_week_ago
|
||||
|
||||
user = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
|
||||
{:ok, user} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
|
||||
assert user.info.source_data["endpoints"]
|
||||
|
||||
refute user.last_refreshed_at == orig_user.last_refreshed_at
|
||||
|
|
@ -888,10 +888,12 @@ defmodule Pleroma.UserTest do
|
|||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
|
||||
{:ok, _} = User.delete_user_activities(user)
|
||||
|
||||
# TODO: Remove favorites, repeats, delete activities.
|
||||
refute Activity.get_by_id(activity.id)
|
||||
Ecto.Adapters.SQL.Sandbox.unboxed_run(Repo, fn ->
|
||||
{:ok, _} = User.delete_user_activities(user)
|
||||
# TODO: Remove favorites, repeats, delete activities.
|
||||
refute Activity.get_by_id(activity.id)
|
||||
end)
|
||||
end
|
||||
|
||||
test ".delete deactivates a user, all follow relationships and all create activities" do
|
||||
|
|
@ -1162,7 +1164,7 @@ defmodule Pleroma.UserTest do
|
|||
expected_text =
|
||||
"A.k.a. <span class='h-card'><a data-user='#{remote_user.id}' class='u-url mention' href='#{
|
||||
remote_user.ap_id
|
||||
}'>" <> "@<span>nick@domain.com</span></a></span>"
|
||||
}'>@<span>nick@domain.com</span></a></span>"
|
||||
|
||||
assert expected_text == User.parse_bio(bio, user)
|
||||
end
|
||||
|
|
@ -1184,33 +1186,6 @@ defmodule Pleroma.UserTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "bookmarks" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity1} =
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "heweoo!"
|
||||
})
|
||||
|
||||
id1 = Object.normalize(activity1).data["id"]
|
||||
|
||||
{:ok, activity2} =
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "heweoo!"
|
||||
})
|
||||
|
||||
id2 = Object.normalize(activity2).data["id"]
|
||||
|
||||
assert {:ok, user_state1} = User.bookmark(user, id1)
|
||||
assert user_state1.bookmarks == [id1]
|
||||
|
||||
assert {:ok, user_state2} = User.unbookmark(user, id1)
|
||||
assert user_state2.bookmarks == []
|
||||
|
||||
assert {:ok, user_state3} = User.bookmark(user, id2)
|
||||
assert user_state3.bookmarks == [id2]
|
||||
end
|
||||
|
||||
test "follower count is updated when a follower is blocked" do
|
||||
user = insert(:user)
|
||||
follower = insert(:user)
|
||||
|
|
|
|||
|
|
@ -215,6 +215,26 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
|
||||
end
|
||||
|
||||
test "it rejects incoming follow requests from blocked users when deny_follow_blocked is enabled" do
|
||||
Pleroma.Config.put([:user, :deny_follow_blocked], true)
|
||||
|
||||
user = insert(:user)
|
||||
{:ok, target} = User.get_or_fetch("http://mastodon.example.org/users/admin")
|
||||
|
||||
{:ok, user} = User.block(user, target)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
{:ok, %Activity{data: %{"id" => id}}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
%Activity{} = activity = Activity.get_by_ap_id(id)
|
||||
|
||||
assert activity.data["state"] == "reject"
|
||||
end
|
||||
|
||||
test "it works for incoming follow requests from hubzilla" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
|
|||
42
test/web/auth/authenticator_test.exs
Normal file
42
test/web/auth/authenticator_test.exs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Auth.AuthenticatorTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Web.Auth.Authenticator
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "fetch_user/1" do
|
||||
test "returns user by name" do
|
||||
user = insert(:user)
|
||||
assert Authenticator.fetch_user(user.nickname) == user
|
||||
end
|
||||
|
||||
test "returns user by email" do
|
||||
user = insert(:user)
|
||||
assert Authenticator.fetch_user(user.email) == user
|
||||
end
|
||||
|
||||
test "returns nil" do
|
||||
assert Authenticator.fetch_user("email") == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetch_credentials/1" do
|
||||
test "returns name and password from authorization params" do
|
||||
params = %{"authorization" => %{"name" => "test", "password" => "test-pass"}}
|
||||
assert Authenticator.fetch_credentials(params) == {:ok, {"test", "test-pass"}}
|
||||
end
|
||||
|
||||
test "returns name and password with grant_type 'password'" do
|
||||
params = %{"grant_type" => "password", "username" => "test", "password" => "test-pass"}
|
||||
assert Authenticator.fetch_credentials(params) == {:ok, {"test", "test-pass"}}
|
||||
end
|
||||
|
||||
test "returns error" do
|
||||
assert Authenticator.fetch_credentials(%{}) == {:error, :invalid_credentials}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -119,6 +119,31 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
assert output == expected
|
||||
end
|
||||
|
||||
test "works for bare text/bbcode" do
|
||||
text = "[b]hello world[/b]"
|
||||
expected = "<strong>hello world</strong>"
|
||||
|
||||
{output, [], []} = Utils.format_input(text, "text/bbcode")
|
||||
|
||||
assert output == expected
|
||||
|
||||
text = "[b]hello world![/b]\n\nsecond paragraph!"
|
||||
expected = "<strong>hello world!</strong><br>\n<br>\nsecond paragraph!"
|
||||
|
||||
{output, [], []} = Utils.format_input(text, "text/bbcode")
|
||||
|
||||
assert output == expected
|
||||
|
||||
text = "[b]hello world![/b]\n\n<strong>second paragraph!</strong>"
|
||||
|
||||
expected =
|
||||
"<strong>hello world!</strong><br>\n<br>\n<strong>second paragraph!</strong>"
|
||||
|
||||
{output, [], []} = Utils.format_input(text, "text/bbcode")
|
||||
|
||||
assert output == expected
|
||||
end
|
||||
|
||||
test "works for text/markdown with mentions" do
|
||||
{:ok, user} =
|
||||
UserBuilder.insert(%{nickname: "user__test", ap_id: "http://foo.com/user__test"})
|
||||
|
|
|
|||
|
|
@ -56,14 +56,17 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
bot: false,
|
||||
source: %{
|
||||
note: "",
|
||||
privacy: "public",
|
||||
sensitive: false
|
||||
sensitive: false,
|
||||
pleroma: %{}
|
||||
},
|
||||
pleroma: %{
|
||||
confirmation_pending: false,
|
||||
tags: [],
|
||||
is_admin: false,
|
||||
is_moderator: false,
|
||||
hide_favorites: true,
|
||||
hide_followers: false,
|
||||
hide_follows: false,
|
||||
relationship: %{}
|
||||
}
|
||||
}
|
||||
|
|
@ -81,8 +84,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
"follows" => true
|
||||
}
|
||||
|
||||
assert %{pleroma: %{notification_settings: ^notification_settings}} =
|
||||
AccountView.render("account.json", %{user: user, for: user})
|
||||
privacy = user.info.default_scope
|
||||
|
||||
assert %{
|
||||
pleroma: %{notification_settings: ^notification_settings},
|
||||
source: %{privacy: ^privacy}
|
||||
} = AccountView.render("account.json", %{user: user, for: user})
|
||||
end
|
||||
|
||||
test "Represent a Service(bot) account" do
|
||||
|
|
@ -114,14 +121,17 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
bot: true,
|
||||
source: %{
|
||||
note: "",
|
||||
privacy: "public",
|
||||
sensitive: false
|
||||
sensitive: false,
|
||||
pleroma: %{}
|
||||
},
|
||||
pleroma: %{
|
||||
confirmation_pending: false,
|
||||
tags: [],
|
||||
is_admin: false,
|
||||
is_moderator: false,
|
||||
hide_favorites: true,
|
||||
hide_followers: false,
|
||||
hide_follows: false,
|
||||
relationship: %{}
|
||||
}
|
||||
}
|
||||
|
|
@ -200,14 +210,17 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
bot: true,
|
||||
source: %{
|
||||
note: "",
|
||||
privacy: "public",
|
||||
sensitive: false
|
||||
sensitive: false,
|
||||
pleroma: %{}
|
||||
},
|
||||
pleroma: %{
|
||||
confirmation_pending: false,
|
||||
tags: [],
|
||||
is_admin: false,
|
||||
is_moderator: false,
|
||||
hide_favorites: true,
|
||||
hide_followers: false,
|
||||
hide_follows: false,
|
||||
relationship: %{
|
||||
id: to_string(user.id),
|
||||
following: false,
|
||||
|
|
|
|||
|
|
@ -1022,7 +1022,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
user2 = insert(:user)
|
||||
user3 = insert(:user)
|
||||
CommonAPI.favorite(activity.id, user2)
|
||||
{:ok, user2} = User.bookmark(user2, activity.data["object"]["id"])
|
||||
{:ok, _bookmark} = Pleroma.Bookmark.create(user2.id, activity.id)
|
||||
{:ok, reblog_activity1, _object} = CommonAPI.repeat(activity.id, user1)
|
||||
{:ok, _, _object} = CommonAPI.repeat(activity.id, user2)
|
||||
|
||||
|
|
@ -2214,6 +2214,78 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
assert user["locked"] == true
|
||||
end
|
||||
|
||||
test "updates the user's default scope", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{default_scope: "cofe"})
|
||||
|
||||
assert user = json_response(conn, 200)
|
||||
assert user["source"]["privacy"] == "cofe"
|
||||
end
|
||||
|
||||
test "updates the user's hide_followers status", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{hide_followers: "true"})
|
||||
|
||||
assert user = json_response(conn, 200)
|
||||
assert user["pleroma"]["hide_followers"] == true
|
||||
end
|
||||
|
||||
test "updates the user's hide_follows status", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{hide_follows: "true"})
|
||||
|
||||
assert user = json_response(conn, 200)
|
||||
assert user["pleroma"]["hide_follows"] == true
|
||||
end
|
||||
|
||||
test "updates the user's hide_favorites status", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{hide_favorites: "true"})
|
||||
|
||||
assert user = json_response(conn, 200)
|
||||
assert user["pleroma"]["hide_favorites"] == true
|
||||
end
|
||||
|
||||
test "updates the user's show_role status", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{show_role: "false"})
|
||||
|
||||
assert user = json_response(conn, 200)
|
||||
assert user["source"]["pleroma"]["show_role"] == false
|
||||
end
|
||||
|
||||
test "updates the user's no_rich_text status", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{no_rich_text: "true"})
|
||||
|
||||
assert user = json_response(conn, 200)
|
||||
assert user["source"]["pleroma"]["no_rich_text"] == true
|
||||
end
|
||||
|
||||
test "updates the user's name", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -2279,6 +2351,33 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "updates profile emojos", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
note = "*sips :blank:*"
|
||||
name = "I am :firefox:"
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{
|
||||
"note" => note,
|
||||
"display_name" => name
|
||||
})
|
||||
|
||||
assert json_response(conn, 200)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{user.id}")
|
||||
|
||||
assert user = json_response(conn, 200)
|
||||
|
||||
assert user["note"] == note
|
||||
assert user["display_name"] == name
|
||||
assert [%{"shortcode" => "blank"}, %{"shortcode" => "firefox"}] = user["emojis"]
|
||||
end
|
||||
end
|
||||
|
||||
test "get instance information", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Bookmark
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
|
|
@ -153,6 +154,25 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
assert status.muted == true
|
||||
end
|
||||
|
||||
test "tells if the status is bookmarked" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Cute girls doing cute things"})
|
||||
status = StatusView.render("status.json", %{activity: activity})
|
||||
|
||||
assert status.bookmarked == false
|
||||
|
||||
status = StatusView.render("status.json", %{activity: activity, for: user})
|
||||
|
||||
assert status.bookmarked == false
|
||||
|
||||
{:ok, _bookmark} = Bookmark.create(user.id, activity.id)
|
||||
|
||||
status = StatusView.render("status.json", %{activity: activity, for: user})
|
||||
|
||||
assert status.bookmarked == true
|
||||
end
|
||||
|
||||
test "a reply" do
|
||||
note = insert(:note_activity)
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
alias Pleroma.Web.OAuth.Authorization
|
||||
alias Pleroma.Web.OAuth.Token
|
||||
|
||||
@oauth_config_path [:oauth2, :issue_new_refresh_token]
|
||||
@session_opts [
|
||||
store: :cookie,
|
||||
key: "_test",
|
||||
|
|
@ -714,4 +715,199 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
refute Map.has_key?(resp, "access_token")
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /oauth/token - refresh token" do
|
||||
setup do
|
||||
oauth_token_config = Pleroma.Config.get(@oauth_config_path)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.get(@oauth_config_path, oauth_token_config)
|
||||
end)
|
||||
end
|
||||
|
||||
test "issues a new access token with keep fresh token" do
|
||||
Pleroma.Config.put(@oauth_config_path, true)
|
||||
user = insert(:user)
|
||||
app = insert(:oauth_app, scopes: ["read", "write"])
|
||||
|
||||
{:ok, auth} = Authorization.create_authorization(app, user, ["write"])
|
||||
{:ok, token} = Token.exchange_token(app, auth)
|
||||
|
||||
response =
|
||||
build_conn()
|
||||
|> post("/oauth/token", %{
|
||||
"grant_type" => "refresh_token",
|
||||
"refresh_token" => token.refresh_token,
|
||||
"client_id" => app.client_id,
|
||||
"client_secret" => app.client_secret
|
||||
})
|
||||
|> json_response(200)
|
||||
|
||||
ap_id = user.ap_id
|
||||
|
||||
assert match?(
|
||||
%{
|
||||
"scope" => "write",
|
||||
"token_type" => "Bearer",
|
||||
"expires_in" => 600,
|
||||
"access_token" => _,
|
||||
"refresh_token" => _,
|
||||
"me" => ^ap_id
|
||||
},
|
||||
response
|
||||
)
|
||||
|
||||
refute Repo.get_by(Token, token: token.token)
|
||||
new_token = Repo.get_by(Token, token: response["access_token"])
|
||||
assert new_token.refresh_token == token.refresh_token
|
||||
assert new_token.scopes == auth.scopes
|
||||
assert new_token.user_id == user.id
|
||||
assert new_token.app_id == app.id
|
||||
end
|
||||
|
||||
test "issues a new access token with new fresh token" do
|
||||
Pleroma.Config.put(@oauth_config_path, false)
|
||||
user = insert(:user)
|
||||
app = insert(:oauth_app, scopes: ["read", "write"])
|
||||
|
||||
{:ok, auth} = Authorization.create_authorization(app, user, ["write"])
|
||||
{:ok, token} = Token.exchange_token(app, auth)
|
||||
|
||||
response =
|
||||
build_conn()
|
||||
|> post("/oauth/token", %{
|
||||
"grant_type" => "refresh_token",
|
||||
"refresh_token" => token.refresh_token,
|
||||
"client_id" => app.client_id,
|
||||
"client_secret" => app.client_secret
|
||||
})
|
||||
|> json_response(200)
|
||||
|
||||
ap_id = user.ap_id
|
||||
|
||||
assert match?(
|
||||
%{
|
||||
"scope" => "write",
|
||||
"token_type" => "Bearer",
|
||||
"expires_in" => 600,
|
||||
"access_token" => _,
|
||||
"refresh_token" => _,
|
||||
"me" => ^ap_id
|
||||
},
|
||||
response
|
||||
)
|
||||
|
||||
refute Repo.get_by(Token, token: token.token)
|
||||
new_token = Repo.get_by(Token, token: response["access_token"])
|
||||
refute new_token.refresh_token == token.refresh_token
|
||||
assert new_token.scopes == auth.scopes
|
||||
assert new_token.user_id == user.id
|
||||
assert new_token.app_id == app.id
|
||||
end
|
||||
|
||||
test "returns 400 if we try use access token" do
|
||||
user = insert(:user)
|
||||
app = insert(:oauth_app, scopes: ["read", "write"])
|
||||
|
||||
{:ok, auth} = Authorization.create_authorization(app, user, ["write"])
|
||||
{:ok, token} = Token.exchange_token(app, auth)
|
||||
|
||||
response =
|
||||
build_conn()
|
||||
|> post("/oauth/token", %{
|
||||
"grant_type" => "refresh_token",
|
||||
"refresh_token" => token.token,
|
||||
"client_id" => app.client_id,
|
||||
"client_secret" => app.client_secret
|
||||
})
|
||||
|> json_response(400)
|
||||
|
||||
assert %{"error" => "Invalid credentials"} == response
|
||||
end
|
||||
|
||||
test "returns 400 if refresh_token invalid" do
|
||||
app = insert(:oauth_app, scopes: ["read", "write"])
|
||||
|
||||
response =
|
||||
build_conn()
|
||||
|> post("/oauth/token", %{
|
||||
"grant_type" => "refresh_token",
|
||||
"refresh_token" => "token.refresh_token",
|
||||
"client_id" => app.client_id,
|
||||
"client_secret" => app.client_secret
|
||||
})
|
||||
|> json_response(400)
|
||||
|
||||
assert %{"error" => "Invalid credentials"} == response
|
||||
end
|
||||
|
||||
test "issues a new token if token expired" do
|
||||
user = insert(:user)
|
||||
app = insert(:oauth_app, scopes: ["read", "write"])
|
||||
|
||||
{:ok, auth} = Authorization.create_authorization(app, user, ["write"])
|
||||
{:ok, token} = Token.exchange_token(app, auth)
|
||||
|
||||
change =
|
||||
Ecto.Changeset.change(
|
||||
token,
|
||||
%{valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), -86_400 * 30)}
|
||||
)
|
||||
|
||||
{:ok, access_token} = Repo.update(change)
|
||||
|
||||
response =
|
||||
build_conn()
|
||||
|> post("/oauth/token", %{
|
||||
"grant_type" => "refresh_token",
|
||||
"refresh_token" => access_token.refresh_token,
|
||||
"client_id" => app.client_id,
|
||||
"client_secret" => app.client_secret
|
||||
})
|
||||
|> json_response(200)
|
||||
|
||||
ap_id = user.ap_id
|
||||
|
||||
assert match?(
|
||||
%{
|
||||
"scope" => "write",
|
||||
"token_type" => "Bearer",
|
||||
"expires_in" => 600,
|
||||
"access_token" => _,
|
||||
"refresh_token" => _,
|
||||
"me" => ^ap_id
|
||||
},
|
||||
response
|
||||
)
|
||||
|
||||
refute Repo.get_by(Token, token: token.token)
|
||||
token = Repo.get_by(Token, token: response["access_token"])
|
||||
assert token
|
||||
assert token.scopes == auth.scopes
|
||||
assert token.user_id == user.id
|
||||
assert token.app_id == app.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /oauth/token - bad request" do
|
||||
test "returns 500" do
|
||||
response =
|
||||
build_conn()
|
||||
|> post("/oauth/token", %{})
|
||||
|> json_response(500)
|
||||
|
||||
assert %{"error" => "Bad request"} == response
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /oauth/revoke - bad request" do
|
||||
test "returns 500" do
|
||||
response =
|
||||
build_conn()
|
||||
|> post("/oauth/revoke", %{})
|
||||
|> json_response(500)
|
||||
|
||||
assert %{"error" => "Bad request"} == response
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
defmodule Pleroma.Web.Push.ImplTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.Push.Impl
|
||||
alias Pleroma.Web.Push.Subscription
|
||||
|
||||
|
|
@ -52,16 +54,12 @@ defmodule Pleroma.Web.Push.ImplTest do
|
|||
data: %{alerts: %{"follow" => true, "mention" => false}}
|
||||
)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "<Lorem ipsum dolor sit amet."})
|
||||
|
||||
notif =
|
||||
insert(:notification,
|
||||
user: user,
|
||||
activity: %Pleroma.Activity{
|
||||
data: %{
|
||||
"type" => "Create",
|
||||
"actor" => user.ap_id,
|
||||
"object" => %{"content" => "<Lorem ipsum dolor sit amet."}
|
||||
}
|
||||
}
|
||||
activity: activity
|
||||
)
|
||||
|
||||
assert Impl.perform(notif) == [:ok, :ok]
|
||||
|
|
@ -100,48 +98,65 @@ defmodule Pleroma.Web.Push.ImplTest do
|
|||
end
|
||||
|
||||
test "renders body for create activity" do
|
||||
user = insert(:user, nickname: "Bob")
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
"status" =>
|
||||
"<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert Impl.format_body(
|
||||
%{
|
||||
activity: %{
|
||||
data: %{
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"content" =>
|
||||
"<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
|
||||
}
|
||||
}
|
||||
}
|
||||
activity: activity
|
||||
},
|
||||
%{nickname: "Bob"}
|
||||
user,
|
||||
object
|
||||
) ==
|
||||
"@Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
|
||||
end
|
||||
|
||||
test "renders body for follow activity" do
|
||||
assert Impl.format_body(%{activity: %{data: %{"type" => "Follow"}}}, %{nickname: "Bob"}) ==
|
||||
user = insert(:user, nickname: "Bob")
|
||||
other_user = insert(:user)
|
||||
{:ok, _, _, activity} = CommonAPI.follow(user, other_user)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert Impl.format_body(%{activity: activity}, user, object) ==
|
||||
"@Bob has followed you"
|
||||
end
|
||||
|
||||
test "renders body for announce activity" do
|
||||
user = insert(:user)
|
||||
|
||||
note =
|
||||
insert(:note, %{
|
||||
data: %{
|
||||
"content" =>
|
||||
"<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
|
||||
}
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
"status" =>
|
||||
"<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
|
||||
})
|
||||
|
||||
note_activity = insert(:note_activity, %{note: note})
|
||||
announce_activity = insert(:announce_activity, %{user: user, note_activity: note_activity})
|
||||
{:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert Impl.format_body(%{activity: announce_activity}, user) ==
|
||||
assert Impl.format_body(%{activity: announce_activity}, user, object) ==
|
||||
"@#{user.nickname} repeated: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
|
||||
end
|
||||
|
||||
test "renders body for like activity" do
|
||||
assert Impl.format_body(%{activity: %{data: %{"type" => "Like"}}}, %{nickname: "Bob"}) ==
|
||||
user = insert(:user, nickname: "Bob")
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
"status" =>
|
||||
"<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
|
||||
})
|
||||
|
||||
{:ok, activity, _} = CommonAPI.favorite(activity.id, user)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert Impl.format_body(%{activity: activity}, user, object) ==
|
||||
"@Bob has favorited your post"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1611,6 +1611,34 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
|
||||
end
|
||||
|
||||
# Broken before the change to class="emoji" and non-<img/> in the DB
|
||||
@tag :skip
|
||||
test "it formats emojos", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/account/update_profile.json", %{
|
||||
"bio" => "I love our :moominmamma:"
|
||||
})
|
||||
|
||||
assert response = json_response(conn, 200)
|
||||
|
||||
assert %{
|
||||
"description" => "I love our :moominmamma:",
|
||||
"description_html" =>
|
||||
~s{I love our <img class="emoji" alt="moominmamma" title="moominmamma" src="} <>
|
||||
_
|
||||
} = response
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> get("/api/users/show.json?user_id=#{user.nickname}")
|
||||
|
||||
assert response == json_response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
defp valid_user(_context) do
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
|
|||
expected = ":firefox: meow"
|
||||
|
||||
expected_html =
|
||||
"<img height=\"32px\" width=\"32px\" alt=\"firefox\" title=\"firefox\" src=\"http://localhost:4001/emoji/Firefox.gif\" /> meow"
|
||||
"<img class=\"emoji\" alt=\"firefox\" title=\"firefox\" src=\"http://localhost:4001/emoji/Firefox.gif\" /> meow"
|
||||
|
||||
assert result["summary"] == expected
|
||||
assert result["summary_html"] == expected_html
|
||||
|
|
@ -371,4 +371,14 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
|
|||
assert length(result["attachments"]) == 1
|
||||
assert result["summary"] == "Friday Night"
|
||||
end
|
||||
|
||||
test "special characters are not escaped in text field for status created" do
|
||||
text = "<3 is on the way"
|
||||
|
||||
{:ok, activity} = CommonAPI.post(insert(:user), %{"status" => text})
|
||||
|
||||
result = ActivityView.render("activity.json", activity: activity)
|
||||
|
||||
assert result["text"] == text
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
|
|||
|
||||
test "A user with emoji in username" do
|
||||
expected =
|
||||
"<img height=\"32px\" width=\"32px\" alt=\"karjalanpiirakka\" title=\"karjalanpiirakka\" src=\"/file.png\" /> man"
|
||||
"<img class=\"emoji\" alt=\"karjalanpiirakka\" title=\"karjalanpiirakka\" src=\"/file.png\" /> man"
|
||||
|
||||
user =
|
||||
insert(:user, %{
|
||||
|
|
@ -89,29 +89,34 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
|
|||
"following" => false,
|
||||
"follows_you" => false,
|
||||
"statusnet_blocking" => false,
|
||||
"rights" => %{
|
||||
"delete_others_notice" => false,
|
||||
"admin" => false
|
||||
},
|
||||
"statusnet_profile_url" => user.ap_id,
|
||||
"cover_photo" => banner,
|
||||
"background_image" => nil,
|
||||
"is_local" => true,
|
||||
"locked" => false,
|
||||
"default_scope" => "public",
|
||||
"no_rich_text" => false,
|
||||
"hide_follows" => false,
|
||||
"hide_followers" => false,
|
||||
"fields" => [],
|
||||
"pleroma" => %{
|
||||
"confirmation_pending" => false,
|
||||
"tags" => []
|
||||
}
|
||||
},
|
||||
"rights" => %{"admin" => false, "delete_others_notice" => false},
|
||||
"role" => "member"
|
||||
}
|
||||
|
||||
assert represented == UserView.render("show.json", %{user: user})
|
||||
end
|
||||
|
||||
test "User exposes settings for themselves and only for themselves", %{user: user} do
|
||||
as_user = UserView.render("show.json", %{user: user, for: user})
|
||||
assert as_user["default_scope"] == user.info.default_scope
|
||||
assert as_user["no_rich_text"] == user.info.no_rich_text
|
||||
as_stranger = UserView.render("show.json", %{user: user})
|
||||
refute as_stranger["default_scope"]
|
||||
refute as_stranger["no_rich_text"]
|
||||
end
|
||||
|
||||
test "A user for a given other follower", %{user: user} do
|
||||
follower = insert(:user, %{following: [User.ap_followers(user)]})
|
||||
{:ok, user} = User.update_follower_count(user)
|
||||
|
|
@ -137,24 +142,20 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
|
|||
"following" => true,
|
||||
"follows_you" => false,
|
||||
"statusnet_blocking" => false,
|
||||
"rights" => %{
|
||||
"delete_others_notice" => false,
|
||||
"admin" => false
|
||||
},
|
||||
"statusnet_profile_url" => user.ap_id,
|
||||
"cover_photo" => banner,
|
||||
"background_image" => nil,
|
||||
"is_local" => true,
|
||||
"locked" => false,
|
||||
"default_scope" => "public",
|
||||
"no_rich_text" => false,
|
||||
"hide_follows" => false,
|
||||
"hide_followers" => false,
|
||||
"fields" => [],
|
||||
"pleroma" => %{
|
||||
"confirmation_pending" => false,
|
||||
"tags" => []
|
||||
}
|
||||
},
|
||||
"rights" => %{"admin" => false, "delete_others_notice" => false},
|
||||
"role" => "member"
|
||||
}
|
||||
|
||||
assert represented == UserView.render("show.json", %{user: user, for: follower})
|
||||
|
|
@ -186,24 +187,20 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
|
|||
"following" => false,
|
||||
"follows_you" => true,
|
||||
"statusnet_blocking" => false,
|
||||
"rights" => %{
|
||||
"delete_others_notice" => false,
|
||||
"admin" => false
|
||||
},
|
||||
"statusnet_profile_url" => follower.ap_id,
|
||||
"cover_photo" => banner,
|
||||
"background_image" => nil,
|
||||
"is_local" => true,
|
||||
"locked" => false,
|
||||
"default_scope" => "public",
|
||||
"no_rich_text" => false,
|
||||
"hide_follows" => false,
|
||||
"hide_followers" => false,
|
||||
"fields" => [],
|
||||
"pleroma" => %{
|
||||
"confirmation_pending" => false,
|
||||
"tags" => []
|
||||
}
|
||||
},
|
||||
"rights" => %{"admin" => false, "delete_others_notice" => false},
|
||||
"role" => "member"
|
||||
}
|
||||
|
||||
assert represented == UserView.render("show.json", %{user: follower, for: user})
|
||||
|
|
@ -272,24 +269,20 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
|
|||
"following" => false,
|
||||
"follows_you" => false,
|
||||
"statusnet_blocking" => true,
|
||||
"rights" => %{
|
||||
"delete_others_notice" => false,
|
||||
"admin" => false
|
||||
},
|
||||
"statusnet_profile_url" => user.ap_id,
|
||||
"cover_photo" => banner,
|
||||
"background_image" => nil,
|
||||
"is_local" => true,
|
||||
"locked" => false,
|
||||
"default_scope" => "public",
|
||||
"no_rich_text" => false,
|
||||
"hide_follows" => false,
|
||||
"hide_followers" => false,
|
||||
"fields" => [],
|
||||
"pleroma" => %{
|
||||
"confirmation_pending" => false,
|
||||
"tags" => []
|
||||
}
|
||||
},
|
||||
"rights" => %{"admin" => false, "delete_others_notice" => false},
|
||||
"role" => "member"
|
||||
}
|
||||
|
||||
blocker = User.get_cached_by_id(blocker.id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue