forked from AkkomaGang/akkoma
Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
This commit is contained in:
commit
df10367b35
21 changed files with 334 additions and 63 deletions
|
@ -41,6 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
- Mastodon API: Add support for categories for custom emojis by reusing the group feature. <https://github.com/tootsuite/mastodon/pull/11196>
|
||||
- Mastodon API: Add support for muting/unmuting notifications
|
||||
- Mastodon API: Add support for the `blocked_by` attribute in the relationship API (`GET /api/v1/accounts/relationships`). <https://github.com/tootsuite/mastodon/pull/10373>
|
||||
- Mastodon API: Add support for the `domain_blocking` attribute in the relationship API (`GET /api/v1/accounts/relationships`).
|
||||
- Mastodon API: Add `pleroma.deactivated` to the Account entity
|
||||
- Mastodon API: added `/auth/password` endpoint for password reset with rate limit.
|
||||
- Mastodon API: /api/v1/accounts/:id/statuses now supports nicknames or user id
|
||||
|
|
24
lib/pleroma/plugs/set_format_plug.ex
Normal file
24
lib/pleroma/plugs/set_format_plug.ex
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Plugs.SetFormatPlug do
|
||||
import Plug.Conn, only: [assign: 3, fetch_query_params: 1]
|
||||
|
||||
def init(_), do: nil
|
||||
|
||||
def call(conn, _) do
|
||||
case get_format(conn) do
|
||||
nil -> conn
|
||||
format -> assign(conn, :format, format)
|
||||
end
|
||||
end
|
||||
|
||||
defp get_format(conn) do
|
||||
conn.private[:phoenix_format] ||
|
||||
case fetch_query_params(conn) do
|
||||
%{query_params: %{"_format" => format}} -> format
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
end
|
|
@ -228,7 +228,14 @@ defp url_from_spec(%__MODULE__{name: name}, base_url, {:file, path}) do
|
|||
""
|
||||
end
|
||||
|
||||
[base_url, "media", path]
|
||||
prefix =
|
||||
if is_nil(Pleroma.Config.get([__MODULE__, :base_url])) do
|
||||
"media"
|
||||
else
|
||||
""
|
||||
end
|
||||
|
||||
[base_url, prefix, path]
|
||||
|> Path.join()
|
||||
end
|
||||
|
||||
|
|
|
@ -882,19 +882,26 @@ def muted_notifications?(nil, _), do: false
|
|||
def muted_notifications?(user, %{ap_id: ap_id}),
|
||||
do: Enum.member?(user.info.muted_notifications, ap_id)
|
||||
|
||||
def blocks?(%User{info: info} = _user, %{ap_id: ap_id}) do
|
||||
blocks = info.blocks
|
||||
|
||||
domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(info.domain_blocks)
|
||||
|
||||
%{host: host} = URI.parse(ap_id)
|
||||
|
||||
Enum.member?(blocks, ap_id) ||
|
||||
Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, host)
|
||||
def blocks?(%User{} = user, %User{} = target) do
|
||||
blocks_ap_id?(user, target) || blocks_domain?(user, target)
|
||||
end
|
||||
|
||||
def blocks?(nil, _), do: false
|
||||
|
||||
def blocks_ap_id?(%User{} = user, %User{} = target) do
|
||||
Enum.member?(user.info.blocks, target.ap_id)
|
||||
end
|
||||
|
||||
def blocks_ap_id?(_, _), do: false
|
||||
|
||||
def blocks_domain?(%User{} = user, %User{} = target) do
|
||||
domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.info.domain_blocks)
|
||||
%{host: host} = URI.parse(target.ap_id)
|
||||
Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, host)
|
||||
end
|
||||
|
||||
def blocks_domain?(_, _), do: false
|
||||
|
||||
def subscribed_to?(user, %{ap_id: ap_id}) do
|
||||
with %User{} = target <- get_cached_by_ap_id(ap_id) do
|
||||
Enum.member?(target.info.subscribers, user.ap_id)
|
||||
|
|
|
@ -50,13 +50,13 @@ def render("relationship.json", %{user: %User{} = user, target: %User{} = target
|
|||
id: to_string(target.id),
|
||||
following: User.following?(user, target),
|
||||
followed_by: User.following?(target, user),
|
||||
blocking: User.blocks?(user, target),
|
||||
blocked_by: User.blocks?(target, user),
|
||||
blocking: User.blocks_ap_id?(user, target),
|
||||
blocked_by: User.blocks_ap_id?(target, user),
|
||||
muting: User.mutes?(user, target),
|
||||
muting_notifications: User.muted_notifications?(user, target),
|
||||
subscribing: User.subscribed_to?(user, target),
|
||||
requested: requested,
|
||||
domain_blocking: false,
|
||||
domain_blocking: User.blocks_domain?(user, target),
|
||||
showing_reblogs: User.showing_reblogs?(user, target),
|
||||
endorsed: false
|
||||
}
|
||||
|
|
|
@ -222,7 +222,7 @@ def render("status.json", %{activity: %{data: %{"object" => _object}} = activity
|
|||
if user.local do
|
||||
Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity)
|
||||
else
|
||||
object.data["external_url"] || object.data["id"]
|
||||
object.data["url"] || object.data["external_url"] || object.data["id"]
|
||||
end
|
||||
|
||||
%{
|
||||
|
|
|
@ -17,7 +17,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
|
|||
alias Pleroma.Web
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.OStatus
|
||||
alias Pleroma.Web.WebFinger
|
||||
|
||||
def help_test(conn, _params) do
|
||||
|
@ -60,7 +59,7 @@ def remote_follow(%{assigns: %{user: user}} = conn, %{"acct" => acct}) do
|
|||
%Activity{id: activity_id} = Activity.get_create_by_object_ap_id(object.data["id"])
|
||||
redirect(conn, to: "/notice/#{activity_id}")
|
||||
else
|
||||
{err, followee} = OStatus.find_or_make_user(acct)
|
||||
{err, followee} = User.get_or_fetch(acct)
|
||||
avatar = User.avatar_url(followee)
|
||||
name = followee.nickname
|
||||
id = followee.id
|
||||
|
|
|
@ -86,11 +86,17 @@ def represent_user(user, "XML") do
|
|||
|> XmlBuilder.to_doc()
|
||||
end
|
||||
|
||||
defp get_magic_key(magic_key) do
|
||||
"data:application/magic-public-key," <> magic_key = magic_key
|
||||
defp get_magic_key("data:application/magic-public-key," <> magic_key) do
|
||||
{:ok, magic_key}
|
||||
rescue
|
||||
MatchError -> {:error, "Missing magic key data."}
|
||||
end
|
||||
|
||||
defp get_magic_key(nil) do
|
||||
Logger.debug("Undefined magic key.")
|
||||
{:ok, nil}
|
||||
end
|
||||
|
||||
defp get_magic_key(_) do
|
||||
{:error, "Missing magic key data."}
|
||||
end
|
||||
|
||||
defp webfinger_from_xml(doc) do
|
||||
|
@ -187,6 +193,7 @@ def find_lrdd_template(domain) do
|
|||
end
|
||||
end
|
||||
|
||||
@spec finger(String.t()) :: {:ok, map()} | {:error, any()}
|
||||
def finger(account) do
|
||||
account = String.trim_leading(account, "@")
|
||||
|
||||
|
@ -220,8 +227,6 @@ def finger(account) do
|
|||
else
|
||||
with {:ok, doc} <- Jason.decode(body) do
|
||||
webfinger_from_json(doc)
|
||||
else
|
||||
{:error, e} -> e
|
||||
end
|
||||
end
|
||||
else
|
||||
|
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.WebFinger.WebFingerController do
|
|||
|
||||
alias Pleroma.Web.WebFinger
|
||||
|
||||
plug(Pleroma.Plugs.SetFormatPlug)
|
||||
plug(Pleroma.Web.FederatingPlug)
|
||||
|
||||
def host_meta(conn, _params) do
|
||||
|
@ -17,9 +18,8 @@ def host_meta(conn, _params) do
|
|||
|> send_resp(200, xml)
|
||||
end
|
||||
|
||||
def webfinger(conn, %{"resource" => resource}) do
|
||||
case get_format(conn) do
|
||||
n when n in ["xml", "xrd+xml"] ->
|
||||
def webfinger(%{assigns: %{format: format}} = conn, %{"resource" => resource})
|
||||
when format in ["xml", "xrd+xml"] do
|
||||
with {:ok, response} <- WebFinger.webfinger(resource, "XML") do
|
||||
conn
|
||||
|> put_resp_content_type("application/xrd+xml")
|
||||
|
@ -27,20 +27,19 @@ def webfinger(conn, %{"resource" => resource}) do
|
|||
else
|
||||
_e -> send_resp(conn, 404, "Couldn't find user")
|
||||
end
|
||||
end
|
||||
|
||||
n when n in ["json", "jrd+json"] ->
|
||||
def webfinger(%{assigns: %{format: format}} = conn, %{"resource" => resource})
|
||||
when format in ["json", "jrd+json"] do
|
||||
with {:ok, response} <- WebFinger.webfinger(resource, "JSON") do
|
||||
json(conn, response)
|
||||
else
|
||||
_e -> send_resp(conn, 404, "Couldn't find user")
|
||||
end
|
||||
|
||||
_ ->
|
||||
send_resp(conn, 404, "Unsupported format")
|
||||
_e ->
|
||||
conn
|
||||
|> put_status(404)
|
||||
|> json("Couldn't find user")
|
||||
end
|
||||
end
|
||||
|
||||
def webfinger(conn, _params) do
|
||||
send_resp(conn, 400, "Bad Request")
|
||||
end
|
||||
def webfinger(conn, _params), do: send_resp(conn, 400, "Bad Request")
|
||||
end
|
||||
|
|
10
test/fixtures/tesla_mock/kpherox@mstdn.jp.xml
vendored
Normal file
10
test/fixtures/tesla_mock/kpherox@mstdn.jp.xml
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
<Subject>acct:kPherox@mstdn.jp</Subject>
|
||||
<Alias>https://mstdn.jp/@kPherox</Alias>
|
||||
<Alias>https://mstdn.jp/users/kPherox</Alias>
|
||||
<Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="https://mstdn.jp/@kPherox"/>
|
||||
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="https://mstdn.jp/users/kPherox.atom"/>
|
||||
<Link rel="self" type="application/activity+json" href="https://mstdn.jp/users/kPherox"/>
|
||||
<Link rel="http://ostatus.org/schema/1.0/subscribe" template="https://mstdn.jp/authorize_interaction?acct={uri}"/>
|
||||
</XRD>
|
18
test/fixtures/tesla_mock/wedistribute-article.json
vendored
Normal file
18
test/fixtures/tesla_mock/wedistribute-article.json
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams"
|
||||
],
|
||||
"type": "Article",
|
||||
"name": "The end is near: Mastodon plans to drop OStatus support",
|
||||
"content": "<!-- wp:paragraph {\"dropCap\":true} -->\n<p class=\"has-drop-cap\">The days of OStatus are numbered. The venerable protocol has served as a glue between many different types of servers since the early days of the Fediverse, connecting StatusNet (now GNU Social) to Friendica, Hubzilla, Mastodon, and Pleroma.</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Now that many fediverse platforms support ActivityPub as a successor protocol, Mastodon appears to be drawing a line in the sand. In <a href=\"https://www.patreon.com/posts/mastodon-2-9-and-28121681\">a Patreon update</a>, Eugen Rochko writes:</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><p>...OStatus...has overstayed its welcome in the code...and now that most of the network uses ActivityPub, it's time for it to go. </p><cite>Eugen Rochko, Mastodon creator</cite></blockquote>\n<!-- /wp:quote -->\n\n<!-- wp:paragraph -->\n<p>The <a href=\"https://github.com/tootsuite/mastodon/pull/11205\">pull request</a> to remove Pubsubhubbub and Salmon, two of the main components of OStatus, has already been merged into Mastodon's master branch.</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Some projects will be left in the dark as a side effect of this. GNU Social and PostActiv, for example, both only communicate using OStatus. While <a href=\"https://mastodon.social/@dansup/102076573310057902\">some discussion</a> exists regarding adopting ActivityPub for GNU Social, and <a href=\"https://notabug.org/diogo/gnu-social/src/activitypub/plugins/ActivityPub\">a plugin is in development</a>, it hasn't been formally adopted yet. We just hope that the <a href=\"https://status.fsf.org/main/public\">Free Software Foundation's instance</a> gets updated in time!</p>\n<!-- /wp:paragraph -->",
|
||||
"summary": "One of the largest platforms in the federated social web is dropping the protocol that it started with.",
|
||||
"attributedTo": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog",
|
||||
"url": "https://wedistribute.org/2019/07/mastodon-drops-ostatus/",
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
"https://wedistribute.org/wp-json/pterotype/v1/actor/-blog/followers"
|
||||
],
|
||||
"id": "https://wedistribute.org/wp-json/pterotype/v1/object/85810",
|
||||
"likes": "https://wedistribute.org/wp-json/pterotype/v1/object/85810/likes",
|
||||
"shares": "https://wedistribute.org/wp-json/pterotype/v1/object/85810/shares"
|
||||
}
|
31
test/fixtures/tesla_mock/wedistribute-user.json
vendored
Normal file
31
test/fixtures/tesla_mock/wedistribute-user.json
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers"
|
||||
}
|
||||
],
|
||||
"type": "Organization",
|
||||
"id": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog",
|
||||
"following": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog/following",
|
||||
"followers": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog/followers",
|
||||
"liked": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog/liked",
|
||||
"inbox": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog/inbox",
|
||||
"outbox": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog/outbox",
|
||||
"name": "We Distribute",
|
||||
"preferredUsername": "blog",
|
||||
"summary": "<p>Connecting many threads in the federated web. We Distribute is an independent publication dedicated to the fediverse, decentralization, P2P technologies, and Free Software!</p>",
|
||||
"url": "https://wedistribute.org/",
|
||||
"publicKey": {
|
||||
"id": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog#publicKey",
|
||||
"owner": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog",
|
||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\r\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1bmUJ+y8PS8JFVi0KugN\r\nFl4pLvLog3V2lsV9ftmCXpveB/WJx66Tr1fQLsU3qYvQFc8UPGWD52zV4RENR1SN\r\nx0O6T2f97KUbRM+Ckow7Jyjtssgl+Mqq8UBZQ/+H8I/1Vpvt5E5hUykhFgwzx9qg\r\nzoIA3OK7alOpQbSoKXo0QcOh6yTRUnMSRMJAgUoZJzzXI/FmH/DtKr7ziQ1T2KWs\r\nVs8mWnTb/OlCxiheLuMlmJNMF+lPyVthvMIxF6Z5gV9d5QAmASSCI628e6uH2EUF\r\nDEEF5jo+Z5ffeNv28953lrnM+VB/wTjl3tYA+zCQeAmUPksX3E+YkXGxj+4rxBAY\r\n8wIDAQAB\r\n-----END PUBLIC KEY-----"
|
||||
},
|
||||
"manuallyApprovesFollowers": false,
|
||||
"icon": {
|
||||
"url": "https://wedistribute.org/wp-content/uploads/2019/02/b067de423757a538.png",
|
||||
"type": "Image",
|
||||
"mediaType": "image/png"
|
||||
}
|
||||
}
|
|
@ -110,6 +110,13 @@ test "it can fetch peertube videos" do
|
|||
assert object
|
||||
end
|
||||
|
||||
test "it can fetch wedistribute articles" do
|
||||
{:ok, object} =
|
||||
Fetcher.fetch_object_from_id("https://wedistribute.org/wp-json/pterotype/v1/object/85810")
|
||||
|
||||
assert object
|
||||
end
|
||||
|
||||
test "all objects with fake directions are rejected by the object fetcher" do
|
||||
assert {:error, _} =
|
||||
Fetcher.fetch_and_contain_remote_object_from_id(
|
||||
|
|
38
test/plugs/set_format_plug_test.exs
Normal file
38
test/plugs/set_format_plug_test.exs
Normal file
|
@ -0,0 +1,38 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Plugs.SetFormatPlugTest do
|
||||
use ExUnit.Case, async: true
|
||||
use Plug.Test
|
||||
|
||||
alias Pleroma.Plugs.SetFormatPlug
|
||||
|
||||
test "set format from params" do
|
||||
conn =
|
||||
:get
|
||||
|> conn("/cofe?_format=json")
|
||||
|> SetFormatPlug.call([])
|
||||
|
||||
assert %{format: "json"} == conn.assigns
|
||||
end
|
||||
|
||||
test "set format from header" do
|
||||
conn =
|
||||
:get
|
||||
|> conn("/cofe")
|
||||
|> put_private(:phoenix_format, "xml")
|
||||
|> SetFormatPlug.call([])
|
||||
|
||||
assert %{format: "xml"} == conn.assigns
|
||||
end
|
||||
|
||||
test "doesn't set format" do
|
||||
conn =
|
||||
:get
|
||||
|> conn("/cofe")
|
||||
|> SetFormatPlug.call([])
|
||||
|
||||
refute conn.assigns[:format]
|
||||
end
|
||||
end
|
|
@ -301,6 +301,22 @@ def get("https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://wedistribute.org/wp-json/pterotype/v1/object/85810", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/wedistribute-article.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("https://wedistribute.org/wp-json/pterotype/v1/actor/-blog", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("http://mastodon.example.org/users/admin", _, _, Accept: "application/activity+json") do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
@ -614,6 +630,15 @@ def get(
|
|||
}}
|
||||
end
|
||||
|
||||
def get(
|
||||
"https://social.heldscal.la/.well-known/webfinger?resource=invalid_content@social.heldscal.la",
|
||||
_,
|
||||
_,
|
||||
Accept: "application/xrd+xml,application/jrd+json"
|
||||
) do
|
||||
{:ok, %Tesla.Env{status: 200, body: ""}}
|
||||
end
|
||||
|
||||
def get("http://framatube.org/.well-known/host-meta", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
@ -915,6 +940,14 @@ def get("https://info.pleroma.site/activity3.json", _, _, _) do
|
|||
{:ok, %Tesla.Env{status: 404, body: ""}}
|
||||
end
|
||||
|
||||
def get("https://mstdn.jp/.well-known/webfinger?resource=acct:kpherox@mstdn.jp", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
def get(url, query, body, headers) do
|
||||
{:error,
|
||||
"Not implemented the mock response for get #{inspect(url)}, #{query}, #{inspect(body)}, #{
|
||||
|
|
|
@ -25,7 +25,7 @@ test "adds shasum" do
|
|||
|
||||
assert {
|
||||
:ok,
|
||||
%Pleroma.Upload{id: @shasum, path: "#{@shasum}.jpg"}
|
||||
%Pleroma.Upload{id: @shasum, path: @shasum <> ".jpg"}
|
||||
} = Dedupe.filter(upload)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -122,24 +122,6 @@ test "returns a media url" do
|
|||
assert String.starts_with?(url, Pleroma.Web.base_url() <> "/media/")
|
||||
end
|
||||
|
||||
test "returns a media url with configured base_url" do
|
||||
base_url = "https://cache.pleroma.social"
|
||||
|
||||
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
path: Path.absname("test/fixtures/image_tmp.jpg"),
|
||||
filename: "image.jpg"
|
||||
}
|
||||
|
||||
{:ok, data} = Upload.store(file, base_url: base_url)
|
||||
|
||||
assert %{"url" => [%{"href" => url}]} = data
|
||||
|
||||
assert String.starts_with?(url, base_url <> "/media/")
|
||||
end
|
||||
|
||||
test "copies the file to the configured folder with deduping" do
|
||||
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
|
||||
|
||||
|
@ -266,4 +248,32 @@ test "escapes reserved uri characters" do
|
|||
"%3A%3F%23%5B%5D%40%21%24%26%5C%27%28%29%2A%2B%2C%3B%3D.jpg"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Setting a custom base_url for uploaded media" do
|
||||
setup do
|
||||
Pleroma.Config.put([Pleroma.Upload, :base_url], "https://cache.pleroma.social")
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([Pleroma.Upload, :base_url], nil)
|
||||
end)
|
||||
end
|
||||
|
||||
test "returns a media url with configured base_url" do
|
||||
base_url = Pleroma.Config.get([Pleroma.Upload, :base_url])
|
||||
|
||||
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
path: Path.absname("test/fixtures/image_tmp.jpg"),
|
||||
filename: "image.jpg"
|
||||
}
|
||||
|
||||
{:ok, data} = Upload.store(file, base_url: base_url)
|
||||
|
||||
assert %{"url" => [%{"href" => url}]} = data
|
||||
|
||||
refute String.starts_with?(url, base_url <> "/media/")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -231,6 +231,16 @@ test "represent a relationship for the blocking and blocked user" do
|
|||
AccountView.render("relationship.json", %{user: user, target: other_user})
|
||||
end
|
||||
|
||||
test "represent a relationship for the user blocking a domain" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, ap_id: "https://bad.site/users/other_user")
|
||||
|
||||
{:ok, user} = User.block_domain(user, "bad.site")
|
||||
|
||||
assert %{domain_blocking: true, blocking: false} =
|
||||
AccountView.render("relationship.json", %{user: user, target: other_user})
|
||||
end
|
||||
|
||||
test "represent a relationship for the user with a pending follow request" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, %{info: %User.Info{locked: true}})
|
||||
|
|
|
@ -300,6 +300,16 @@ test "attachments" do
|
|||
assert %{id: "2"} = StatusView.render("attachment.json", %{attachment: object})
|
||||
end
|
||||
|
||||
test "put the url advertised in the Activity in to the url attribute" do
|
||||
id = "https://wedistribute.org/wp-json/pterotype/v1/object/85810"
|
||||
[activity] = Activity.search(nil, id)
|
||||
|
||||
status = StatusView.render("status.json", %{activity: activity})
|
||||
|
||||
assert status.uri == id
|
||||
assert status.url == "https://wedistribute.org/2019/07/mastodon-drops-ostatus/"
|
||||
end
|
||||
|
||||
test "a reblog" do
|
||||
user = insert(:user)
|
||||
activity = insert(:note_activity)
|
||||
|
|
|
@ -19,6 +19,19 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
test "GET host-meta" do
|
||||
response =
|
||||
build_conn()
|
||||
|> get("/.well-known/host-meta")
|
||||
|
||||
assert response.status == 200
|
||||
|
||||
assert response.resp_body ==
|
||||
~s(<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" template="#{
|
||||
Pleroma.Web.base_url()
|
||||
}/.well-known/webfinger?resource={uri}" type="application/xrd+xml" /></XRD>)
|
||||
end
|
||||
|
||||
test "Webfinger JRD" do
|
||||
user = insert(:user)
|
||||
|
||||
|
@ -30,6 +43,16 @@ test "Webfinger JRD" do
|
|||
assert json_response(response, 200)["subject"] == "acct:#{user.nickname}@localhost"
|
||||
end
|
||||
|
||||
test "it returns 404 when user isn't found (JSON)" do
|
||||
result =
|
||||
build_conn()
|
||||
|> put_req_header("accept", "application/jrd+json")
|
||||
|> get("/.well-known/webfinger?resource=acct:jimm@localhost")
|
||||
|> json_response(404)
|
||||
|
||||
assert result == "Couldn't find user"
|
||||
end
|
||||
|
||||
test "Webfinger XML" do
|
||||
user = insert(:user)
|
||||
|
||||
|
@ -41,6 +64,26 @@ test "Webfinger XML" do
|
|||
assert response(response, 200)
|
||||
end
|
||||
|
||||
test "it returns 404 when user isn't found (XML)" do
|
||||
result =
|
||||
build_conn()
|
||||
|> put_req_header("accept", "application/xrd+xml")
|
||||
|> get("/.well-known/webfinger?resource=acct:jimm@localhost")
|
||||
|> response(404)
|
||||
|
||||
assert result == "Couldn't find user"
|
||||
end
|
||||
|
||||
test "Sends a 404 when invalid format" do
|
||||
user = insert(:user)
|
||||
|
||||
assert_raise Phoenix.NotAcceptableError, fn ->
|
||||
build_conn()
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
|
||||
end
|
||||
end
|
||||
|
||||
test "Sends a 400 when resource param is missing" do
|
||||
response =
|
||||
build_conn()
|
||||
|
|
|
@ -40,6 +40,11 @@ test "works for ap_ids" do
|
|||
end
|
||||
|
||||
describe "fingering" do
|
||||
test "returns error when fails parse xml or json" do
|
||||
user = "invalid_content@social.heldscal.la"
|
||||
assert {:error, %Jason.DecodeError{}} = WebFinger.finger(user)
|
||||
end
|
||||
|
||||
test "returns the info for an OStatus user" do
|
||||
user = "shp@social.heldscal.la"
|
||||
|
||||
|
@ -81,6 +86,20 @@ test "returns the correctly for json ostatus users" do
|
|||
assert data["subscribe_address"] == "https://gnusocial.de/main/ostatussub?profile={uri}"
|
||||
end
|
||||
|
||||
test "it work for AP-only user" do
|
||||
user = "kpherox@mstdn.jp"
|
||||
|
||||
{:ok, data} = WebFinger.finger(user)
|
||||
|
||||
assert data["magic_key"] == nil
|
||||
assert data["salmon"] == nil
|
||||
|
||||
assert data["topic"] == "https://mstdn.jp/users/kPherox.atom"
|
||||
assert data["subject"] == "acct:kPherox@mstdn.jp"
|
||||
assert data["ap_id"] == "https://mstdn.jp/users/kPherox"
|
||||
assert data["subscribe_address"] == "https://mstdn.jp/authorize_interaction?acct={uri}"
|
||||
end
|
||||
|
||||
test "it works for friendica" do
|
||||
user = "lain@squeet.me"
|
||||
|
||||
|
|
Loading…
Reference in a new issue