Merge branch 'support/issue_442' into 'develop'
[#442] fix warnings See merge request pleroma/pleroma!536
This commit is contained in:
commit
2592b3c81a
32 changed files with 203 additions and 183 deletions
|
@ -212,7 +212,7 @@ def maybe_direct_follow(%User{} = follower, %User{local: true} = followed) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def maybe_direct_follow(%User{} = follower, %User{} = followed) do
|
def maybe_direct_follow(%User{} = follower, %User{} = followed) do
|
||||||
if !User.ap_enabled?(followed) do
|
if not User.ap_enabled?(followed) do
|
||||||
follow(follower, followed)
|
follow(follower, followed)
|
||||||
else
|
else
|
||||||
{:ok, follower}
|
{:ok, follower}
|
||||||
|
@ -736,7 +736,8 @@ def public_key_from_info(%{
|
||||||
source_data: %{"publicKey" => %{"publicKeyPem" => public_key_pem}}
|
source_data: %{"publicKey" => %{"publicKeyPem" => public_key_pem}}
|
||||||
}) do
|
}) do
|
||||||
key =
|
key =
|
||||||
:public_key.pem_decode(public_key_pem)
|
public_key_pem
|
||||||
|
|> :public_key.pem_decode()
|
||||||
|> hd()
|
|> hd()
|
||||||
|> :public_key.pem_entry_decode()
|
|> :public_key.pem_entry_decode()
|
||||||
|
|
||||||
|
@ -774,13 +775,10 @@ def ap_enabled?(%User{local: true}), do: true
|
||||||
def ap_enabled?(%User{info: info}), do: info.ap_enabled
|
def ap_enabled?(%User{info: info}), do: info.ap_enabled
|
||||||
def ap_enabled?(_), do: false
|
def ap_enabled?(_), do: false
|
||||||
|
|
||||||
def get_or_fetch(uri_or_nickname) do
|
@doc "Gets or fetch a user by uri or nickname."
|
||||||
if String.starts_with?(uri_or_nickname, "http") do
|
@spec get_or_fetch(String.t()) :: User.t()
|
||||||
get_or_fetch_by_ap_id(uri_or_nickname)
|
def get_or_fetch("http" <> _host = uri), do: get_or_fetch_by_ap_id(uri)
|
||||||
else
|
def get_or_fetch(nickname), do: get_or_fetch_by_nickname(nickname)
|
||||||
get_or_fetch_by_nickname(uri_or_nickname)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# wait a period of time and return newest version of the User structs
|
# wait a period of time and return newest version of the User structs
|
||||||
# this is because we have synchronous follow APIs and need to simulate them
|
# this is because we have synchronous follow APIs and need to simulate them
|
||||||
|
@ -821,7 +819,9 @@ def parse_bio(bio, user) do
|
||||||
{String.trim(name, ":"), url}
|
{String.trim(name, ":"), url}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
CommonUtils.format_input(bio, mentions, tags, "text/plain") |> Formatter.emojify(emoji)
|
bio
|
||||||
|
|> CommonUtils.format_input(mentions, tags, "text/plain")
|
||||||
|
|> Formatter.emojify(emoji)
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag(user_identifiers, tags) when is_list(user_identifiers) do
|
def tag(user_identifiers, tags) when is_list(user_identifiers) do
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
defmodule Pleroma.Web.CommonAPI.Utils do
|
defmodule Pleroma.Web.CommonAPI.Utils do
|
||||||
alias Pleroma.{Repo, Object, Formatter, Activity}
|
alias Calendar.Strftime
|
||||||
|
alias Comeonin.Pbkdf2
|
||||||
|
alias Pleroma.{Activity, Formatter, Object, Repo}
|
||||||
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
alias Pleroma.Web.Endpoint
|
alias Pleroma.Web.Endpoint
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
alias Pleroma.User
|
|
||||||
alias Calendar.Strftime
|
|
||||||
alias Comeonin.Pbkdf2
|
|
||||||
|
|
||||||
# This is a hack for twidere.
|
# This is a hack for twidere.
|
||||||
def get_by_id_or_ap_id(id) do
|
def get_by_id_or_ap_id(id) do
|
||||||
|
@ -148,7 +149,7 @@ def add_tag_links(text, tags) do
|
||||||
|> Enum.sort_by(fn {tag, _} -> -String.length(tag) end)
|
|> Enum.sort_by(fn {tag, _} -> -String.length(tag) end)
|
||||||
|
|
||||||
Enum.reduce(tags, text, fn {full, tag}, text ->
|
Enum.reduce(tags, text, fn {full, tag}, text ->
|
||||||
url = "<a href='#{Pleroma.Web.base_url()}/tag/#{tag}' rel='tag'>##{tag}</a>"
|
url = "<a href='#{Web.base_url()}/tag/#{tag}' rel='tag'>##{tag}</a>"
|
||||||
String.replace(text, full, url)
|
String.replace(text, full, url)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
|
@ -180,7 +180,7 @@ defp send_to_user(_, _, _), do: nil
|
||||||
"Undo",
|
"Undo",
|
||||||
"Delete"
|
"Delete"
|
||||||
]
|
]
|
||||||
def publish(user, activity, poster \\ &@httpoison.post/4)
|
def publish(user, activity, poster \\ &@httpoison.post/3)
|
||||||
|
|
||||||
def publish(%{info: %{keys: keys}} = user, %{data: %{"type" => type}} = activity, poster)
|
def publish(%{info: %{keys: keys}} = user, %{data: %{"type" => type}} = activity, poster)
|
||||||
when type in @supported_activities do
|
when type in @supported_activities do
|
||||||
|
|
|
@ -256,8 +256,7 @@ def finger(account) do
|
||||||
with response <-
|
with response <-
|
||||||
@httpoison.get(
|
@httpoison.get(
|
||||||
address,
|
address,
|
||||||
[Accept: "application/xrd+xml,application/jrd+json"],
|
Accept: "application/xrd+xml,application/jrd+json"
|
||||||
follow_redirect: true
|
|
||||||
),
|
),
|
||||||
{:ok, %{status: status, body: body}} when status in 200..299 <- response do
|
{:ok, %{status: status, body: body}} when status in 200..299 <- response do
|
||||||
doc = XML.parse_document(body)
|
doc = XML.parse_document(body)
|
||||||
|
|
|
@ -25,7 +25,7 @@ def parse_document(text) do
|
||||||
{doc, _rest} =
|
{doc, _rest} =
|
||||||
text
|
text
|
||||||
|> :binary.bin_to_list()
|
|> :binary.bin_to_list()
|
||||||
|> :xmerl_scan.string()
|
|> :xmerl_scan.string(quiet: true)
|
||||||
|
|
||||||
doc
|
doc
|
||||||
rescue
|
rescue
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
defmodule Pleroma.FilterTest do
|
defmodule Pleroma.FilterTest do
|
||||||
alias Pleroma.{User, Repo}
|
alias Pleroma.Repo
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
import Ecto.Query
|
|
||||||
|
|
||||||
describe "creating filters" do
|
describe "creating filters" do
|
||||||
test "creating one filter" do
|
test "creating one filter" do
|
||||||
|
@ -99,7 +98,7 @@ test "deleting a filter" do
|
||||||
context: ["home"]
|
context: ["home"]
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, filter} = Pleroma.Filter.create(query)
|
{:ok, _filter} = Pleroma.Filter.create(query)
|
||||||
{:ok, filter} = Pleroma.Filter.delete(query)
|
{:ok, filter} = Pleroma.Filter.delete(query)
|
||||||
assert is_nil(Repo.get(Pleroma.Filter, filter.filter_id))
|
assert is_nil(Repo.get(Pleroma.Filter, filter.filter_id))
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
defmodule Pleroma.ListTest do
|
defmodule Pleroma.ListTest do
|
||||||
alias Pleroma.{User, Repo}
|
alias Pleroma.Repo
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
import Ecto.Query
|
|
||||||
|
|
||||||
test "creating a list" do
|
test "creating a list" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
@ -32,7 +31,7 @@ test "removing an user from a list" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
{:ok, list} = Pleroma.List.create("title", user)
|
{:ok, list} = Pleroma.List.create("title", user)
|
||||||
{:ok, %{following: following}} = Pleroma.List.follow(list, other_user)
|
{:ok, %{following: _following}} = Pleroma.List.follow(list, other_user)
|
||||||
{:ok, %{following: following}} = Pleroma.List.unfollow(list, other_user)
|
{:ok, %{following: following}} = Pleroma.List.unfollow(list, other_user)
|
||||||
assert [] == following
|
assert [] == following
|
||||||
end
|
end
|
||||||
|
|
|
@ -127,12 +127,12 @@ test "it sets all notifications as read up to a specified notification ID" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
||||||
{:ok, activity} =
|
{:ok, _activity} =
|
||||||
TwitterAPI.create_status(user, %{
|
TwitterAPI.create_status(user, %{
|
||||||
"status" => "hey @#{other_user.nickname}!"
|
"status" => "hey @#{other_user.nickname}!"
|
||||||
})
|
})
|
||||||
|
|
||||||
{:ok, activity} =
|
{:ok, _activity} =
|
||||||
TwitterAPI.create_status(user, %{
|
TwitterAPI.create_status(user, %{
|
||||||
"status" => "hey again @#{other_user.nickname}!"
|
"status" => "hey again @#{other_user.nickname}!"
|
||||||
})
|
})
|
||||||
|
@ -142,14 +142,14 @@ test "it sets all notifications as read up to a specified notification ID" do
|
||||||
|
|
||||||
assert n2.id > n1.id
|
assert n2.id > n1.id
|
||||||
|
|
||||||
{:ok, activity} =
|
{:ok, _activity} =
|
||||||
TwitterAPI.create_status(user, %{
|
TwitterAPI.create_status(user, %{
|
||||||
"status" => "hey yet again @#{other_user.nickname}!"
|
"status" => "hey yet again @#{other_user.nickname}!"
|
||||||
})
|
})
|
||||||
|
|
||||||
Notification.set_read_up_to(other_user, n2.id)
|
Notification.set_read_up_to(other_user, n2.id)
|
||||||
|
|
||||||
[n3, n2, n1] = notifs = Notification.for_user(other_user)
|
[n3, n2, n1] = Notification.for_user(other_user)
|
||||||
|
|
||||||
assert n1.seen == true
|
assert n1.seen == true
|
||||||
assert n2.seen == true
|
assert n2.seen == true
|
||||||
|
|
|
@ -4,7 +4,7 @@ defmodule Pleroma.Plugs.UserIsAdminPlugTest do
|
||||||
alias Pleroma.Plugs.UserIsAdminPlug
|
alias Pleroma.Plugs.UserIsAdminPlug
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
test "accepts a user that is admin", %{conn: conn} do
|
test "accepts a user that is admin" do
|
||||||
user = insert(:user, info: %{is_admin: true})
|
user = insert(:user, info: %{is_admin: true})
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
|
@ -18,7 +18,7 @@ test "accepts a user that is admin", %{conn: conn} do
|
||||||
assert conn == ret_conn
|
assert conn == ret_conn
|
||||||
end
|
end
|
||||||
|
|
||||||
test "denies a user that isn't admin", %{conn: conn} do
|
test "denies a user that isn't admin" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
|
@ -29,7 +29,7 @@ test "denies a user that isn't admin", %{conn: conn} do
|
||||||
assert conn.status == 403
|
assert conn.status == 403
|
||||||
end
|
end
|
||||||
|
|
||||||
test "denies when a user isn't set", %{conn: conn} do
|
test "denies when a user isn't set" do
|
||||||
conn =
|
conn =
|
||||||
build_conn()
|
build_conn()
|
||||||
|> UserIsAdminPlug.call(%{})
|
|> UserIsAdminPlug.call(%{})
|
||||||
|
|
|
@ -19,6 +19,7 @@ defmodule Pleroma.Web.ConnCase do
|
||||||
quote do
|
quote do
|
||||||
# Import conveniences for testing with connections
|
# Import conveniences for testing with connections
|
||||||
use Phoenix.ConnTest
|
use Phoenix.ConnTest
|
||||||
|
use Pleroma.Tests.Helpers
|
||||||
import Pleroma.Web.Router.Helpers
|
import Pleroma.Web.Router.Helpers
|
||||||
|
|
||||||
# The default endpoint for testing
|
# The default endpoint for testing
|
||||||
|
|
|
@ -22,6 +22,7 @@ defmodule Pleroma.DataCase do
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
import Pleroma.DataCase
|
import Pleroma.DataCase
|
||||||
|
use Pleroma.Tests.Helpers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
25
test/support/helpers.ex
Normal file
25
test/support/helpers.ex
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
defmodule Pleroma.Tests.Helpers do
|
||||||
|
@moduledoc """
|
||||||
|
Helpers for use in tests.
|
||||||
|
"""
|
||||||
|
|
||||||
|
defmacro __using__(_opts) do
|
||||||
|
quote do
|
||||||
|
def refresh_record(%{id: id, __struct__: model} = _),
|
||||||
|
do: refresh_record(model, %{id: id})
|
||||||
|
|
||||||
|
def refresh_record(model, %{id: id} = _) do
|
||||||
|
Pleroma.Repo.get_by(model, id: id)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Used for comparing json rendering during tests.
|
||||||
|
def render_json(view, template, assigns) do
|
||||||
|
assigns = Map.new(assigns)
|
||||||
|
|
||||||
|
view.render(template, assigns)
|
||||||
|
|> Poison.encode!()
|
||||||
|
|> Poison.decode!()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,13 +1,10 @@
|
||||||
defmodule Pleroma.UserTest do
|
defmodule Pleroma.UserTest do
|
||||||
alias Pleroma.Builders.UserBuilder
|
alias Pleroma.Builders.UserBuilder
|
||||||
alias Pleroma.{User, Repo, Activity}
|
alias Pleroma.{User, Repo, Activity}
|
||||||
alias Pleroma.Web.OStatus
|
|
||||||
alias Pleroma.Web.Websub.WebsubClientSubscription
|
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
import Ecto.Query
|
|
||||||
|
|
||||||
setup_all do
|
setup_all do
|
||||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
|
@ -163,6 +160,32 @@ test "it ensures info is not nil" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
assert user == fetched_user
|
||||||
|
end
|
||||||
|
|
||||||
|
test "gets an existing user by ap_id" do
|
||||||
|
ap_id = "http://mastodon.example.org/users/admin"
|
||||||
|
|
||||||
|
user =
|
||||||
|
insert(
|
||||||
|
:user,
|
||||||
|
local: false,
|
||||||
|
nickname: "admin@mastodon.example.org",
|
||||||
|
ap_id: ap_id,
|
||||||
|
info: %{}
|
||||||
|
)
|
||||||
|
|
||||||
|
fetched_user = User.get_or_fetch(ap_id)
|
||||||
|
freshed_user = refresh_record(user)
|
||||||
|
assert freshed_user == fetched_user
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "fetching a user from nickname or trying to build one" do
|
describe "fetching a user from nickname or trying to build one" do
|
||||||
test "gets an existing user" do
|
test "gets an existing user" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
@ -574,7 +597,7 @@ test "html_filter_policy returns TwitterText scrubber when rich-text is disabled
|
||||||
describe "caching" do
|
describe "caching" do
|
||||||
test "invalidate_cache works" do
|
test "invalidate_cache works" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
user_info = User.get_cached_user_info(user)
|
_user_info = User.get_cached_user_info(user)
|
||||||
|
|
||||||
User.invalidate_cache(user)
|
User.invalidate_cache(user)
|
||||||
|
|
||||||
|
@ -600,9 +623,9 @@ test "User.delete() plugs any possible zombie objects" do
|
||||||
|
|
||||||
describe "User.search" do
|
describe "User.search" do
|
||||||
test "finds a user, ranking by similarity" do
|
test "finds a user, ranking by similarity" do
|
||||||
user = insert(:user, %{name: "lain"})
|
_user = insert(:user, %{name: "lain"})
|
||||||
user_two = insert(:user, %{name: "ean"})
|
_user_two = insert(:user, %{name: "ean"})
|
||||||
user_three = insert(:user, %{name: "ebn", nickname: "lain@mastodon.social"})
|
_user_three = insert(:user, %{name: "ebn", nickname: "lain@mastodon.social"})
|
||||||
user_four = insert(:user, %{nickname: "lain@pleroma.soykaf.com"})
|
user_four = insert(:user, %{nickname: "lain@pleroma.soykaf.com"})
|
||||||
|
|
||||||
assert user_four ==
|
assert user_four ==
|
||||||
|
|
|
@ -23,10 +23,10 @@ test "with the relay active, it returns the relay user", %{conn: conn} do
|
||||||
test "with the relay disabled, it returns 404", %{conn: conn} do
|
test "with the relay disabled, it returns 404", %{conn: conn} do
|
||||||
Pleroma.Config.put([:instance, :allow_relay], false)
|
Pleroma.Config.put([:instance, :allow_relay], false)
|
||||||
|
|
||||||
res =
|
conn
|
||||||
conn
|
|> get(activity_pub_path(conn, :relay))
|
||||||
|> get(activity_pub_path(conn, :relay))
|
|> json_response(404)
|
||||||
|> json_response(404)
|
|> assert
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :allow_relay], true)
|
Pleroma.Config.put([:instance, :allow_relay], true)
|
||||||
end
|
end
|
||||||
|
|
|
@ -180,7 +180,7 @@ test "doesn't return blocked activities" do
|
||||||
test "doesn't retrieve unlisted activities" do
|
test "doesn't retrieve unlisted activities" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
{:ok, unlisted_activity} =
|
{:ok, _unlisted_activity} =
|
||||||
CommonAPI.post(user, %{"status" => "yeah", "visibility" => "unlisted"})
|
CommonAPI.post(user, %{"status" => "yeah", "visibility" => "unlisted"})
|
||||||
|
|
||||||
{:ok, listed_activity} = CommonAPI.post(user, %{"status" => "yeah"})
|
{:ok, listed_activity} = CommonAPI.post(user, %{"status" => "yeah"})
|
||||||
|
|
|
@ -982,13 +982,12 @@ test "contain_origin_from_id() allows matching IDs" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "users cannot be collided through fake direction spoofing attempts" do
|
test "users cannot be collided through fake direction spoofing attempts" do
|
||||||
user =
|
insert(:user, %{
|
||||||
insert(:user, %{
|
nickname: "rye@niu.moe",
|
||||||
nickname: "rye@niu.moe",
|
local: false,
|
||||||
local: false,
|
ap_id: "https://niu.moe/users/rye",
|
||||||
ap_id: "https://niu.moe/users/rye",
|
follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
|
||||||
follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
{:error, _} = User.get_or_fetch_by_ap_id("https://n1u.moe/users/rye")
|
{:error, _} = User.get_or_fetch_by_ap_id("https://n1u.moe/users/rye")
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,9 +2,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
||||||
use Pleroma.Web.ConnCase
|
use Pleroma.Web.ConnCase
|
||||||
|
|
||||||
alias Pleroma.{Repo, User}
|
alias Pleroma.{Repo, User}
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
import ExUnit.CaptureLog
|
|
||||||
|
|
||||||
describe "/api/pleroma/admin/user" do
|
describe "/api/pleroma/admin/user" do
|
||||||
test "Delete" do
|
test "Delete" do
|
||||||
|
|
|
@ -11,9 +11,6 @@ defmodule Pleroma.Web.HTTPSignaturesTest do
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
@private_key hd(:public_key.pem_decode(File.read!("test/web/http_sigs/priv.key")))
|
|
||||||
|> :public_key.pem_entry_decode()
|
|
||||||
|
|
||||||
@public_key hd(:public_key.pem_decode(File.read!("test/web/http_sigs/pub.key")))
|
@public_key hd(:public_key.pem_decode(File.read!("test/web/http_sigs/pub.key")))
|
||||||
|> :public_key.pem_entry_decode()
|
|> :public_key.pem_entry_decode()
|
||||||
|
|
||||||
|
@ -26,8 +23,6 @@ defmodule Pleroma.Web.HTTPSignaturesTest do
|
||||||
"content-length" => "18"
|
"content-length" => "18"
|
||||||
}
|
}
|
||||||
|
|
||||||
@body "{\"hello\": \"world\"}"
|
|
||||||
|
|
||||||
@default_signature """
|
@default_signature """
|
||||||
keyId="Test",algorithm="rsa-sha256",signature="jKyvPcxB4JbmYY4mByyBY7cZfNl4OW9HpFQlG7N4YcJPteKTu4MWCLyk+gIr0wDgqtLWf9NLpMAMimdfsH7FSWGfbMFSrsVTHNTk0rK3usrfFnti1dxsM4jl0kYJCKTGI/UWkqiaxwNiKqGcdlEDrTcUhhsFsOIo8VhddmZTZ8w="
|
keyId="Test",algorithm="rsa-sha256",signature="jKyvPcxB4JbmYY4mByyBY7cZfNl4OW9HpFQlG7N4YcJPteKTu4MWCLyk+gIr0wDgqtLWf9NLpMAMimdfsH7FSWGfbMFSrsVTHNTk0rK3usrfFnti1dxsM4jl0kYJCKTGI/UWkqiaxwNiKqGcdlEDrTcUhhsFsOIo8VhddmZTZ8w="
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -2,7 +2,6 @@ defmodule Pleroma.Web.MastodonAPI.ListViewTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
alias Pleroma.Web.MastodonAPI.ListView
|
alias Pleroma.Web.MastodonAPI.ListView
|
||||||
alias Pleroma.List
|
|
||||||
|
|
||||||
test "Represent a list" do
|
test "Represent a list" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
|
@ -5,7 +5,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
||||||
alias Pleroma.{Repo, User, Object, Activity, Notification}
|
alias Pleroma.{Repo, User, Object, Activity, Notification}
|
||||||
alias Pleroma.Web.{OStatus, CommonAPI}
|
alias Pleroma.Web.{OStatus, CommonAPI}
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
alias Pleroma.Web.MastodonAPI.FilterView
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
import ExUnit.CaptureLog
|
import ExUnit.CaptureLog
|
||||||
import Tesla.Mock
|
import Tesla.Mock
|
||||||
|
@ -351,12 +351,18 @@ test "fetching a list of filters", %{conn: conn} do
|
||||||
{:ok, filter_one} = Pleroma.Filter.create(query_one)
|
{:ok, filter_one} = Pleroma.Filter.create(query_one)
|
||||||
{:ok, filter_two} = Pleroma.Filter.create(query_two)
|
{:ok, filter_two} = Pleroma.Filter.create(query_two)
|
||||||
|
|
||||||
conn =
|
response =
|
||||||
conn
|
conn
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|> get("/api/v1/filters")
|
|> get("/api/v1/filters")
|
||||||
|
|> json_response(200)
|
||||||
|
|
||||||
assert response = json_response(conn, 200)
|
assert response ==
|
||||||
|
render_json(
|
||||||
|
FilterView,
|
||||||
|
"filters.json",
|
||||||
|
filters: [filter_two, filter_one]
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "get a filter", %{conn: conn} do
|
test "get a filter", %{conn: conn} do
|
||||||
|
@ -389,7 +395,7 @@ test "update a filter", %{conn: conn} do
|
||||||
context: ["home"]
|
context: ["home"]
|
||||||
}
|
}
|
||||||
|
|
||||||
{:ok, filter} = Pleroma.Filter.create(query)
|
{:ok, _filter} = Pleroma.Filter.create(query)
|
||||||
|
|
||||||
new = %Pleroma.Filter{
|
new = %Pleroma.Filter{
|
||||||
phrase: "nii",
|
phrase: "nii",
|
||||||
|
@ -554,7 +560,7 @@ test "list timeline does not leak non-public statuses for unfollowed users", %{c
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
{:ok, activity_one} = TwitterAPI.create_status(other_user, %{"status" => "Marisa is cute."})
|
{:ok, activity_one} = TwitterAPI.create_status(other_user, %{"status" => "Marisa is cute."})
|
||||||
|
|
||||||
{:ok, activity_two} =
|
{:ok, _activity_two} =
|
||||||
TwitterAPI.create_status(other_user, %{
|
TwitterAPI.create_status(other_user, %{
|
||||||
"status" => "Marisa is cute.",
|
"status" => "Marisa is cute.",
|
||||||
"visibility" => "private"
|
"visibility" => "private"
|
||||||
|
@ -854,7 +860,7 @@ test "/api/v1/follow_requests works" do
|
||||||
user = insert(:user, %{info: %Pleroma.User.Info{locked: true}})
|
user = insert(:user, %{info: %Pleroma.User.Info{locked: true}})
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
||||||
{:ok, activity} = ActivityPub.follow(other_user, user)
|
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
||||||
|
|
||||||
user = Repo.get(User, user.id)
|
user = Repo.get(User, user.id)
|
||||||
other_user = Repo.get(User, other_user.id)
|
other_user = Repo.get(User, other_user.id)
|
||||||
|
@ -874,7 +880,7 @@ test "/api/v1/follow_requests/:id/authorize works" do
|
||||||
user = insert(:user, %{info: %Pleroma.User.Info{locked: true}})
|
user = insert(:user, %{info: %Pleroma.User.Info{locked: true}})
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
||||||
{:ok, activity} = ActivityPub.follow(other_user, user)
|
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
||||||
|
|
||||||
user = Repo.get(User, user.id)
|
user = Repo.get(User, user.id)
|
||||||
other_user = Repo.get(User, other_user.id)
|
other_user = Repo.get(User, other_user.id)
|
||||||
|
@ -911,7 +917,7 @@ test "/api/v1/follow_requests/:id/reject works" do
|
||||||
user = insert(:user, %{info: %Pleroma.User.Info{locked: true}})
|
user = insert(:user, %{info: %Pleroma.User.Info{locked: true}})
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
||||||
{:ok, activity} = ActivityPub.follow(other_user, user)
|
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
build_conn()
|
build_conn()
|
||||||
|
@ -1015,7 +1021,7 @@ test "getting followers", %{conn: conn} do
|
||||||
test "getting followers, hide_network", %{conn: conn} do
|
test "getting followers, hide_network", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user, %{info: %{hide_network: true}})
|
other_user = insert(:user, %{info: %{hide_network: true}})
|
||||||
{:ok, user} = User.follow(user, other_user)
|
{:ok, _user} = User.follow(user, other_user)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|
@ -1027,7 +1033,7 @@ test "getting followers, hide_network", %{conn: conn} do
|
||||||
test "getting followers, hide_network, same user requesting", %{conn: conn} do
|
test "getting followers, hide_network, same user requesting", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user, %{info: %{hide_network: true}})
|
other_user = insert(:user, %{info: %{hide_network: true}})
|
||||||
{:ok, user} = User.follow(user, other_user)
|
{:ok, _user} = User.follow(user, other_user)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
defmodule Pleroma.Web.MastodonApi.MastodonSocketTest do
|
defmodule Pleroma.Web.MastodonApi.MastodonSocketTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
|
|
||||||
alias Pleroma.Web.MastodonApi.MastodonSocket
|
|
||||||
alias Pleroma.Web.{Streamer, CommonAPI}
|
alias Pleroma.Web.{Streamer, CommonAPI}
|
||||||
alias Pleroma.User
|
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ test "delete authorizations" do
|
||||||
{:ok, auth} = Authorization.create_authorization(app, user)
|
{:ok, auth} = Authorization.create_authorization(app, user)
|
||||||
{:ok, auth} = Authorization.use_token(auth)
|
{:ok, auth} = Authorization.use_token(auth)
|
||||||
|
|
||||||
{auths, _} = Authorization.delete_user_authorizations(user)
|
Authorization.delete_user_authorizations(user)
|
||||||
|
|
||||||
{_, invalid} = Authorization.use_token(auth)
|
{_, invalid} = Authorization.use_token(auth)
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,8 @@ test "deletes all tokens of a user" do
|
||||||
{:ok, auth1} = Authorization.create_authorization(app1, user)
|
{:ok, auth1} = Authorization.create_authorization(app1, user)
|
||||||
{:ok, auth2} = Authorization.create_authorization(app2, user)
|
{:ok, auth2} = Authorization.create_authorization(app2, user)
|
||||||
|
|
||||||
{:ok, token1} = Token.exchange_token(app1, auth1)
|
{:ok, _token1} = Token.exchange_token(app1, auth1)
|
||||||
{:ok, token2} = Token.exchange_token(app2, auth2)
|
{:ok, _token2} = Token.exchange_token(app2, auth2)
|
||||||
|
|
||||||
{tokens, _} = Token.delete_user_tokens(user)
|
{tokens, _} = Token.delete_user_tokens(user)
|
||||||
|
|
||||||
|
|
|
@ -42,10 +42,10 @@ test "decodes a salmon with a changed magic key", %{conn: conn} do
|
||||||
"RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
|
"RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
|
||||||
})
|
})
|
||||||
|
|
||||||
cng =
|
salmon_user
|
||||||
Ecto.Changeset.change(salmon_user)
|
|> Ecto.Changeset.change()
|
||||||
|> Ecto.Changeset.put_embed(:info, info_cng)
|
|> Ecto.Changeset.put_embed(:info, info_cng)
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
build_conn()
|
build_conn()
|
||||||
|
@ -97,82 +97,58 @@ test "gets an object", %{conn: conn} do
|
||||||
|
|
||||||
test "404s on private objects", %{conn: conn} do
|
test "404s on private objects", %{conn: conn} do
|
||||||
note_activity = insert(:direct_note_activity)
|
note_activity = insert(:direct_note_activity)
|
||||||
user = User.get_by_ap_id(note_activity.data["actor"])
|
|
||||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
|
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
|
||||||
url = "/objects/#{uuid}"
|
|
||||||
|
|
||||||
conn =
|
conn
|
||||||
conn
|
|> get("/objects/#{uuid}")
|
||||||
|> get(url)
|
|> response(404)
|
||||||
|
|
||||||
assert response(conn, 404)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "404s on nonexisting objects", %{conn: conn} do
|
test "404s on nonexisting objects", %{conn: conn} do
|
||||||
url = "/objects/123"
|
conn
|
||||||
|
|> get("/objects/123")
|
||||||
conn =
|
|> response(404)
|
||||||
conn
|
|
||||||
|> get(url)
|
|
||||||
|
|
||||||
assert response(conn, 404)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "gets an activity", %{conn: conn} do
|
test "gets an activity", %{conn: conn} do
|
||||||
note_activity = insert(:note_activity)
|
note_activity = insert(:note_activity)
|
||||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
|
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
|
||||||
url = "/activities/#{uuid}"
|
|
||||||
|
|
||||||
conn =
|
conn
|
||||||
conn
|
|> get("/activities/#{uuid}")
|
||||||
|> get(url)
|
|> response(200)
|
||||||
|
|
||||||
assert response(conn, 200)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "404s on private activities", %{conn: conn} do
|
test "404s on private activities", %{conn: conn} do
|
||||||
note_activity = insert(:direct_note_activity)
|
note_activity = insert(:direct_note_activity)
|
||||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
|
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
|
||||||
url = "/activities/#{uuid}"
|
|
||||||
|
|
||||||
conn =
|
conn
|
||||||
conn
|
|> get("/activities/#{uuid}")
|
||||||
|> get(url)
|
|> response(404)
|
||||||
|
|
||||||
assert response(conn, 404)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "404s on nonexistent activities", %{conn: conn} do
|
test "404s on nonexistent activities", %{conn: conn} do
|
||||||
url = "/activities/123"
|
conn
|
||||||
|
|> get("/activities/123")
|
||||||
conn =
|
|> response(404)
|
||||||
conn
|
|
||||||
|> get(url)
|
|
||||||
|
|
||||||
assert response(conn, 404)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "gets a notice", %{conn: conn} do
|
test "gets a notice", %{conn: conn} do
|
||||||
note_activity = insert(:note_activity)
|
note_activity = insert(:note_activity)
|
||||||
url = "/notice/#{note_activity.id}"
|
|
||||||
|
|
||||||
conn =
|
conn
|
||||||
conn
|
|> get("/notice/#{note_activity.id}")
|
||||||
|> get(url)
|
|> response(200)
|
||||||
|
|
||||||
assert response(conn, 200)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "gets a notice in AS2 format", %{conn: conn} do
|
test "gets a notice in AS2 format", %{conn: conn} do
|
||||||
note_activity = insert(:note_activity)
|
note_activity = insert(:note_activity)
|
||||||
url = "/notice/#{note_activity.id}"
|
|
||||||
|
|
||||||
conn =
|
conn
|
||||||
conn
|
|> put_req_header("accept", "application/activity+json")
|
||||||
|> put_req_header("accept", "application/activity+json")
|
|> get("/notice/#{note_activity.id}")
|
||||||
|> get(url)
|
|> json_response(200)
|
||||||
|
|
||||||
assert json_response(conn, 200)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "only gets a notice in AS2 format for Create messages", %{conn: conn} do
|
test "only gets a notice in AS2 format for Create messages", %{conn: conn} do
|
||||||
|
|
|
@ -511,7 +511,7 @@ test "Article objects are not representable" do
|
||||||
|> Map.put("type", "Article")
|
|> Map.put("type", "Article")
|
||||||
|
|
||||||
cs = Object.change(note_object, %{data: note_data})
|
cs = Object.change(note_object, %{data: note_data})
|
||||||
{:ok, article_object} = Repo.update(cs)
|
{:ok, _article_object} = Repo.update(cs)
|
||||||
|
|
||||||
# the underlying object is now an Article instead of a note, so this should fail
|
# the underlying object is now an Article instead of a note, so this should fail
|
||||||
refute OStatus.is_representable?(note_activity)
|
refute OStatus.is_representable?(note_activity)
|
||||||
|
|
|
@ -4,7 +4,7 @@ def publish_one(ret) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defmodule Pleroma.ActivityTest do
|
defmodule Pleroma.Web.Federator.RetryQueueTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
alias Pleroma.Web.Federator.RetryQueue
|
alias Pleroma.Web.Federator.RetryQueue
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
|
||||||
alias Pleroma.Web.Salmon
|
alias Pleroma.Web.Salmon
|
||||||
alias Pleroma.{Repo, Activity, User}
|
alias Pleroma.{Repo, Activity, User}
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
import Tesla.Mock
|
|
||||||
|
|
||||||
@magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
|
@magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
|
||||||
|
|
||||||
|
@ -11,8 +10,8 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
|
||||||
|
|
||||||
@magickey_friendica "RSA.AMwa8FUs2fWEjX0xN7yRQgegQffhBpuKNC6fa5VNSVorFjGZhRrlPMn7TQOeihlc9lBz2OsHlIedbYn2uJ7yCs0.AQAB"
|
@magickey_friendica "RSA.AMwa8FUs2fWEjX0xN7yRQgegQffhBpuKNC6fa5VNSVorFjGZhRrlPMn7TQOeihlc9lBz2OsHlIedbYn2uJ7yCs0.AQAB"
|
||||||
|
|
||||||
setup do
|
setup_all do
|
||||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -75,7 +74,7 @@ test "it gets a magic key" do
|
||||||
test "it pushes an activity to remote accounts it's addressed to" do
|
test "it pushes an activity to remote accounts it's addressed to" do
|
||||||
user_data = %{
|
user_data = %{
|
||||||
info: %{
|
info: %{
|
||||||
"salmon" => "http://example.org/salmon"
|
salmon: "http://test-example.org/salmon"
|
||||||
},
|
},
|
||||||
local: false
|
local: false
|
||||||
}
|
}
|
||||||
|
@ -97,8 +96,8 @@ test "it pushes an activity to remote accounts it's addressed to" do
|
||||||
user = Repo.get_by(User, ap_id: activity.data["actor"])
|
user = Repo.get_by(User, ap_id: activity.data["actor"])
|
||||||
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
|
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
|
||||||
|
|
||||||
poster = fn url, _data, _headers, _options ->
|
poster = fn url, _data, _headers ->
|
||||||
assert url == "http://example.org/salmon"
|
assert url == "http://test-example.org/salmon"
|
||||||
end
|
end
|
||||||
|
|
||||||
Salmon.publish(user, activity, poster)
|
Salmon.publish(user, activity, poster)
|
||||||
|
|
|
@ -3,7 +3,6 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
||||||
alias Pleroma.{User, Activity, Object}
|
alias Pleroma.{User, Activity, Object}
|
||||||
alias Pleroma.Web.TwitterAPI.Representers.{ActivityRepresenter, ObjectRepresenter}
|
alias Pleroma.Web.TwitterAPI.Representers.{ActivityRepresenter, ObjectRepresenter}
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Builders.UserBuilder
|
|
||||||
alias Pleroma.Web.TwitterAPI.UserView
|
alias Pleroma.Web.TwitterAPI.UserView
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
|
|
@ -12,20 +12,18 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
@banner "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
|
||||||
|
|
||||||
describe "POST /api/account/update_profile_banner" do
|
describe "POST /api/account/update_profile_banner" do
|
||||||
test "it updates the banner", %{conn: conn} do
|
test "it updates the banner", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
new_banner =
|
conn
|
||||||
"data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
|
|> assign(:user, user)
|
||||||
|
|> post(authenticated_twitter_api__path(conn, :update_banner), %{"banner" => @banner})
|
||||||
|
|> json_response(200)
|
||||||
|
|
||||||
response =
|
user = refresh_record(user)
|
||||||
conn
|
|
||||||
|> assign(:user, user)
|
|
||||||
|> post(authenticated_twitter_api__path(conn, :update_banner), %{"banner" => new_banner})
|
|
||||||
|> json_response(200)
|
|
||||||
|
|
||||||
user = Repo.get(User, user.id)
|
|
||||||
assert user.info.banner["type"] == "Image"
|
assert user.info.banner["type"] == "Image"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -34,16 +32,12 @@ test "it updates the banner", %{conn: conn} do
|
||||||
test "it updates the background", %{conn: conn} do
|
test "it updates the background", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
new_bg =
|
conn
|
||||||
"data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
|
|> assign(:user, user)
|
||||||
|
|> post(authenticated_twitter_api__path(conn, :update_background), %{"img" => @banner})
|
||||||
|
|> json_response(200)
|
||||||
|
|
||||||
response =
|
user = refresh_record(user)
|
||||||
conn
|
|
||||||
|> assign(:user, user)
|
|
||||||
|> post(authenticated_twitter_api__path(conn, :update_background), %{"img" => new_bg})
|
|
||||||
|> json_response(200)
|
|
||||||
|
|
||||||
user = Repo.get(User, user.id)
|
|
||||||
assert user.info.background["type"] == "Image"
|
assert user.info.background["type"] == "Image"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -57,12 +51,12 @@ test "without valid credentials", %{conn: conn} do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "with credentials", %{conn: conn, user: user} do
|
test "with credentials", %{conn: conn, user: user} do
|
||||||
conn =
|
response =
|
||||||
conn
|
conn
|
||||||
|> with_credentials(user.nickname, "test")
|
|> with_credentials(user.nickname, "test")
|
||||||
|> post("/api/account/verify_credentials.json")
|
|> post("/api/account/verify_credentials.json")
|
||||||
|
|> json_response(200)
|
||||||
|
|
||||||
assert response = json_response(conn, 200)
|
|
||||||
assert response == UserView.render("show.json", %{user: user, token: response["token"]})
|
assert response == UserView.render("show.json", %{user: user, token: response["token"]})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -84,17 +78,28 @@ test "with credentials", %{conn: conn, user: user} do
|
||||||
"error" => "Client must provide a 'status' parameter with a value."
|
"error" => "Client must provide a 'status' parameter with a value."
|
||||||
}
|
}
|
||||||
|
|
||||||
conn = conn_with_creds |> post(request_path)
|
conn =
|
||||||
|
conn_with_creds
|
||||||
|
|> post(request_path)
|
||||||
|
|
||||||
assert json_response(conn, 400) == error_response
|
assert json_response(conn, 400) == error_response
|
||||||
|
|
||||||
conn = conn_with_creds |> post(request_path, %{status: ""})
|
conn =
|
||||||
|
conn_with_creds
|
||||||
|
|> post(request_path, %{status: ""})
|
||||||
|
|
||||||
assert json_response(conn, 400) == error_response
|
assert json_response(conn, 400) == error_response
|
||||||
|
|
||||||
conn = conn_with_creds |> post(request_path, %{status: " "})
|
conn =
|
||||||
|
conn_with_creds
|
||||||
|
|> post(request_path, %{status: " "})
|
||||||
|
|
||||||
assert json_response(conn, 400) == error_response
|
assert json_response(conn, 400) == error_response
|
||||||
|
|
||||||
# we post with visibility private in order to avoid triggering relay
|
# we post with visibility private in order to avoid triggering relay
|
||||||
conn = conn_with_creds |> post(request_path, %{status: "Nice meme.", visibility: "private"})
|
conn =
|
||||||
|
conn_with_creds
|
||||||
|
|> post(request_path, %{status: "Nice meme.", visibility: "private"})
|
||||||
|
|
||||||
assert json_response(conn, 200) ==
|
assert json_response(conn, 200) ==
|
||||||
ActivityRepresenter.to_map(Repo.one(Activity), %{user: user})
|
ActivityRepresenter.to_map(Repo.one(Activity), %{user: user})
|
||||||
|
@ -117,7 +122,7 @@ test "returns statuses", %{conn: conn} do
|
||||||
assert length(response) == 10
|
assert length(response) == 10
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns 403 to unauthenticated request when the instance is not public" do
|
test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
|
||||||
instance =
|
instance =
|
||||||
Application.get_env(:pleroma, :instance)
|
Application.get_env(:pleroma, :instance)
|
||||||
|> Keyword.put(:public, false)
|
|> Keyword.put(:public, false)
|
||||||
|
@ -135,7 +140,7 @@ test "returns 403 to unauthenticated request when the instance is not public" do
|
||||||
Application.put_env(:pleroma, :instance, instance)
|
Application.put_env(:pleroma, :instance, instance)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns 200 to unauthenticated request when the instance is public" do
|
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
|
||||||
conn
|
conn
|
||||||
|> get("/api/statuses/public_timeline.json")
|
|> get("/api/statuses/public_timeline.json")
|
||||||
|> json_response(200)
|
|> json_response(200)
|
||||||
|
@ -143,7 +148,7 @@ test "returns 200 to unauthenticated request when the instance is public" do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /statuses/public_and_external_timeline.json" do
|
describe "GET /statuses/public_and_external_timeline.json" do
|
||||||
test "returns 403 to unauthenticated request when the instance is not public" do
|
test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
|
||||||
instance =
|
instance =
|
||||||
Application.get_env(:pleroma, :instance)
|
Application.get_env(:pleroma, :instance)
|
||||||
|> Keyword.put(:public, false)
|
|> Keyword.put(:public, false)
|
||||||
|
@ -161,7 +166,7 @@ test "returns 403 to unauthenticated request when the instance is not public" do
|
||||||
Application.put_env(:pleroma, :instance, instance)
|
Application.put_env(:pleroma, :instance, instance)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns 200 to unauthenticated request when the instance is public" do
|
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
|
||||||
conn
|
conn
|
||||||
|> get("/api/statuses/public_and_external_timeline.json")
|
|> get("/api/statuses/public_and_external_timeline.json")
|
||||||
|> json_response(200)
|
|> json_response(200)
|
||||||
|
@ -654,14 +659,13 @@ test "unimplemented mutes without valid credentials", %{conn: conn} do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "unimplemented mutes with credentials", %{conn: conn, user: current_user} do
|
test "unimplemented mutes with credentials", %{conn: conn, user: current_user} do
|
||||||
conn =
|
response =
|
||||||
conn
|
conn
|
||||||
|> with_credentials(current_user.nickname, "test")
|
|> with_credentials(current_user.nickname, "test")
|
||||||
|> get("/api/qvitter/mutes.json")
|
|> get("/api/qvitter/mutes.json")
|
||||||
|
|> json_response(200)
|
||||||
|
|
||||||
current_user = Repo.get(User, current_user.id)
|
assert [] = response
|
||||||
|
|
||||||
assert [] = json_response(conn, 200)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -893,15 +897,16 @@ test "it returns empty for a hidden network", %{conn: conn} do
|
||||||
follower_two = insert(:user)
|
follower_two = insert(:user)
|
||||||
not_follower = insert(:user)
|
not_follower = insert(:user)
|
||||||
|
|
||||||
{:ok, follower_one} = User.follow(follower_one, user)
|
{:ok, _follower_one} = User.follow(follower_one, user)
|
||||||
{:ok, follower_two} = User.follow(follower_two, user)
|
{:ok, _follower_two} = User.follow(follower_two, user)
|
||||||
|
|
||||||
conn =
|
response =
|
||||||
conn
|
conn
|
||||||
|> assign(:user, not_follower)
|
|> assign(:user, not_follower)
|
||||||
|> get("/api/statuses/followers", %{"user_id" => user.id})
|
|> get("/api/statuses/followers", %{"user_id" => user.id})
|
||||||
|
|> json_response(200)
|
||||||
|
|
||||||
assert [] == json_response(conn, 200)
|
assert [] == response
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns the followers for a hidden network if requested by the user themselves", %{
|
test "it returns the followers for a hidden network if requested by the user themselves", %{
|
||||||
|
@ -910,10 +915,10 @@ test "it returns the followers for a hidden network if requested by the user the
|
||||||
user = insert(:user, %{info: %{hide_network: true}})
|
user = insert(:user, %{info: %{hide_network: true}})
|
||||||
follower_one = insert(:user)
|
follower_one = insert(:user)
|
||||||
follower_two = insert(:user)
|
follower_two = insert(:user)
|
||||||
not_follower = insert(:user)
|
_not_follower = insert(:user)
|
||||||
|
|
||||||
{:ok, follower_one} = User.follow(follower_one, user)
|
{:ok, _follower_one} = User.follow(follower_one, user)
|
||||||
{:ok, follower_two} = User.follow(follower_two, user)
|
{:ok, _follower_two} = User.follow(follower_two, user)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|
@ -989,17 +994,18 @@ test "it returns friends for a hidden network if the user themselves request it"
|
||||||
user = insert(:user, %{info: %{hide_network: true}})
|
user = insert(:user, %{info: %{hide_network: true}})
|
||||||
followed_one = insert(:user)
|
followed_one = insert(:user)
|
||||||
followed_two = insert(:user)
|
followed_two = insert(:user)
|
||||||
not_followed = insert(:user)
|
_not_followed = insert(:user)
|
||||||
|
|
||||||
{:ok, user} = User.follow(user, followed_one)
|
{:ok, _user} = User.follow(user, followed_one)
|
||||||
{:ok, user} = User.follow(user, followed_two)
|
{:ok, _user} = User.follow(user, followed_two)
|
||||||
|
|
||||||
conn =
|
response =
|
||||||
conn
|
conn
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|> get("/api/statuses/friends", %{"user_id" => user.id})
|
|> get("/api/statuses/friends", %{"user_id" => user.id})
|
||||||
|
|> json_response(200)
|
||||||
|
|
||||||
refute [] == json_response(conn, 200)
|
refute [] == response
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns a given user's friends with screen_name", %{conn: conn} do
|
test "it returns a given user's friends with screen_name", %{conn: conn} do
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
alias Pleroma.Builders.UserBuilder
|
|
||||||
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView}
|
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView}
|
||||||
alias Pleroma.{Activity, User, Object, Repo, UserInviteToken}
|
alias Pleroma.{Activity, User, Object, Repo, UserInviteToken}
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
|
|
@ -8,7 +8,6 @@ defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
|
||||||
alias Pleroma.Web.TwitterAPI.ActivityView
|
alias Pleroma.Web.TwitterAPI.ActivityView
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
alias Pleroma.Web.CommonAPI.Utils
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Builders.UserBuilder
|
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
@ -67,7 +66,7 @@ test "A retweet notification" do
|
||||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||||
repeater = insert(:user)
|
repeater = insert(:user)
|
||||||
|
|
||||||
{:ok, activity} = TwitterAPI.repeat(repeater, note_activity.id)
|
{:ok, _activity} = TwitterAPI.repeat(repeater, note_activity.id)
|
||||||
[notification] = Notification.for_user(user)
|
[notification] = Notification.for_user(user)
|
||||||
|
|
||||||
represented = %{
|
represented = %{
|
||||||
|
@ -89,7 +88,7 @@ test "A like notification" do
|
||||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||||
liker = insert(:user)
|
liker = insert(:user)
|
||||||
|
|
||||||
{:ok, activity} = TwitterAPI.fav(liker, note_activity.id)
|
{:ok, _activity} = TwitterAPI.fav(liker, note_activity.id)
|
||||||
[notification] = Notification.for_user(user)
|
[notification] = Notification.for_user(user)
|
||||||
|
|
||||||
represented = %{
|
represented = %{
|
||||||
|
|
|
@ -4,7 +4,6 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.TwitterAPI.UserView
|
alias Pleroma.Web.TwitterAPI.UserView
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
alias Pleroma.Web.CommonAPI.Utils
|
||||||
alias Pleroma.Builders.UserBuilder
|
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
@ -27,7 +26,7 @@ test "A user with an avatar object", %{user: user} do
|
||||||
assert represented["profile_image_url"] == image
|
assert represented["profile_image_url"] == image
|
||||||
end
|
end
|
||||||
|
|
||||||
test "A user with emoji in username", %{user: user} do
|
test "A user with emoji in username" do
|
||||||
expected =
|
expected =
|
||||||
"<img height=\"32px\" width=\"32px\" alt=\"karjalanpiirakka\" title=\"karjalanpiirakka\" src=\"/file.png\" /> man"
|
"<img height=\"32px\" width=\"32px\" alt=\"karjalanpiirakka\" title=\"karjalanpiirakka\" src=\"/file.png\" /> man"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue