Merge branch 'develop' into 'docs/add-clients-to-ex_doc'

# Conflicts:
#   mix.exs
This commit is contained in:
lambda 2019-02-17 17:39:45 +00:00
commit a2f4fc49fe
60 changed files with 600 additions and 127 deletions

View File

@ -19,7 +19,7 @@
# #
# You can give explicit globs or simply directories. # You can give explicit globs or simply directories.
# In the latter case `**/*.{ex,exs}` will be used. # In the latter case `**/*.{ex,exs}` will be used.
included: ["lib/", "src/", "web/", "apps/"], included: ["lib/", "src/", "web/", "apps/", "test/"],
excluded: [~r"/_build/", ~r"/deps/"] excluded: [~r"/_build/", ~r"/deps/"]
}, },
# #

View File

@ -1,7 +1,8 @@
image: elixir:1.7.2 image: elixir:1.7.2
services: services:
- postgres:9.6.2 - name: postgres:9.6.2
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
variables: variables:
POSTGRES_DB: pleroma_test POSTGRES_DB: pleroma_test
@ -35,4 +36,4 @@ lint:
unit-testing: unit-testing:
stage: test stage: test
script: script:
- mix test --trace - mix test --trace --preload-modules

View File

@ -162,7 +162,9 @@
mrf_transparency: true, mrf_transparency: true,
autofollowed_nicknames: [], autofollowed_nicknames: [],
max_pinned_statuses: 1, max_pinned_statuses: 1,
no_attachment_links: false no_attachment_links: false,
welcome_user_nickname: nil,
welcome_message: nil
config :pleroma, :markup, config :pleroma, :markup,
# XXX - unfortunately, inline images must be enabled by default right now, because # XXX - unfortunately, inline images must be enabled by default right now, because
@ -228,8 +230,8 @@
allow_direct: false allow_direct: false
config :pleroma, :mrf_hellthread, config :pleroma, :mrf_hellthread,
delist_threshold: 5, delist_threshold: 10,
reject_threshold: 10 reject_threshold: 20
config :pleroma, :mrf_simple, config :pleroma, :mrf_simple,
media_removal: [], media_removal: [],

View File

@ -16,7 +16,8 @@
debug_errors: true, debug_errors: true,
code_reloader: true, code_reloader: true,
check_origin: false, check_origin: false,
watchers: [] watchers: [],
secure_cookie_flag: false
config :pleroma, Pleroma.Mailer, adapter: Swoosh.Adapters.Local config :pleroma, Pleroma.Mailer, adapter: Swoosh.Adapters.Local

View File

@ -7,6 +7,7 @@ Feel free to contact us to be added to this list!
- Homepage: <http://www.pleroma.com/desktop-app/> - Homepage: <http://www.pleroma.com/desktop-app/>
- Source Code: ??? - Source Code: ???
- Platforms: Windows, Mac, (Linux?) - Platforms: Windows, Mac, (Linux?)
- Features: Streaming Ready
### Social ### Social
- Source Code: <https://gitlab.gnome.org/BrainBlasted/Social> - Source Code: <https://gitlab.gnome.org/BrainBlasted/Social>
@ -19,6 +20,7 @@ Feel free to contact us to be added to this list!
- Source Code: <https://github.com/h3poteto/whalebird-desktop> - Source Code: <https://github.com/h3poteto/whalebird-desktop>
- Contact: [@h3poteto@pleroma.io](https://pleroma.io/users/h3poteto) - Contact: [@h3poteto@pleroma.io](https://pleroma.io/users/h3poteto)
- Platforms: Windows, Mac, Linux - Platforms: Windows, Mac, Linux
- Features: Streaming Ready
## Handheld ## Handheld
### Amaroq ### Amaroq

View File

@ -0,0 +1,11 @@
# Differences in Mastodon API responses from vanilla Mastodon
A Pleroma instance can be identified by "<Mastodon version> (compatible; Pleroma <version>)" present in `version` field in response from `/api/v1/instance`
## Flake IDs
Pleroma uses 128-bit ids as opposed to Mastodon's 64 bits. However just like Mastodon's ids they are sortable strings
## Attachment cap
Some apps operate under the assumption that no more than 4 attachments can be returned or uploaded. Pleroma however does not enforce any limits on attachment count neither when returning the status object nor when posting.

View File

@ -97,6 +97,8 @@ config :pleroma, Pleroma.Mailer,
* `max_pinned_statuses`: The maximum number of pinned statuses. `0` will disable the feature. * `max_pinned_statuses`: The maximum number of pinned statuses. `0` will disable the feature.
* `autofollowed_nicknames`: Set to nicknames of (local) users that every new user should automatically follow. * `autofollowed_nicknames`: Set to nicknames of (local) users that every new user should automatically follow.
* `no_attachment_links`: Set to true to disable automatically adding attachment link text to statuses * `no_attachment_links`: Set to true to disable automatically adding attachment link text to statuses
* `welcome_message`: A message that will be send to a newly registered users as a direct message.
* `welcome_user_nickname`: The nickname of the local user that sends the welcome message.
## :logger ## :logger
* `backends`: `:console` is used to send logs to stdout, `{ExSyslogger, :ex_syslogger}` to log to syslog * `backends`: `:console` is used to send logs to stdout, `{ExSyslogger, :ex_syslogger}` to log to syslog

View File

@ -34,6 +34,21 @@ defp headers do
defp csp_string do defp csp_string do
scheme = Config.get([Pleroma.Web.Endpoint, :url])[:scheme] scheme = Config.get([Pleroma.Web.Endpoint, :url])[:scheme]
websocket_url = String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws")
connect_src =
if Mix.env() == :dev do
"connect-src 'self' http://localhost:3035/ " <> websocket_url
else
"connect-src 'self' " <> websocket_url
end
script_src =
if Mix.env() == :dev do
"script-src 'self' 'unsafe-eval'"
else
"script-src 'self'"
end
[ [
"default-src 'none'", "default-src 'none'",
@ -43,9 +58,9 @@ defp csp_string do
"media-src 'self' https:", "media-src 'self' https:",
"style-src 'self' 'unsafe-inline'", "style-src 'self' 'unsafe-inline'",
"font-src 'self'", "font-src 'self'",
"script-src 'self'",
"connect-src 'self' " <> String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws"),
"manifest-src 'self'", "manifest-src 'self'",
connect_src,
script_src,
if scheme == "https" do if scheme == "https" do
"upgrade-insecure-requests" "upgrade-insecure-requests"
end end

View File

@ -25,7 +25,7 @@ def put_file(upload) do
query = "#{cgi}?#{extension}" query = "#{cgi}?#{extension}"
with {:ok, %{status: 200, body: body}} <- with {:ok, %{status: 200, body: body}} <-
@httpoison.post(query, file_data, adapter: [pool: :default]) do @httpoison.post(query, file_data, [], adapter: [pool: :default]) do
remote_file_name = String.split(body) |> List.first() remote_file_name = String.split(body) |> List.first()
public_url = "#{files}/#{remote_file_name}.#{extension}" public_url = "#{files}/#{remote_file_name}.#{extension}"
{:ok, {:url, public_url}} {:ok, {:url, public_url}}

View File

@ -261,6 +261,7 @@ defp autofollow_users(user) do
def register(%Ecto.Changeset{} = changeset) do def register(%Ecto.Changeset{} = changeset) do
with {:ok, user} <- Repo.insert(changeset), with {:ok, user} <- Repo.insert(changeset),
{:ok, user} <- autofollow_users(user), {:ok, user} <- autofollow_users(user),
{:ok, _} <- Pleroma.User.WelcomeMessage.post_welcome_message_to_user(user),
{:ok, _} <- try_send_confirmation_email(user) do {:ok, _} <- try_send_confirmation_email(user) do
{:ok, user} {:ok, user}
end end
@ -311,12 +312,12 @@ def maybe_follow(%User{} = follower, %User{info: _info} = followed) do
end end
end end
@doc "A mass follow for local users. Respects blocks but does not create activities." @doc "A mass follow for local users. Respects blocks in both directions but does not create activities."
@spec follow_all(User.t(), list(User.t())) :: {atom(), User.t()} @spec follow_all(User.t(), list(User.t())) :: {atom(), User.t()}
def follow_all(follower, followeds) do def follow_all(follower, followeds) do
followed_addresses = followed_addresses =
followeds followeds
|> Enum.reject(fn %{ap_id: ap_id} -> ap_id in follower.info.blocks end) |> Enum.reject(fn followed -> blocks?(follower, followed) || blocks?(followed, follower) end)
|> Enum.map(fn %{follower_address: fa} -> fa end) |> Enum.map(fn %{follower_address: fa} -> fa end)
q = q =
@ -731,7 +732,7 @@ def search(query, resolve \\ false, for_user \\ nil) do
# Strip the beginning @ off if there is a query # Strip the beginning @ off if there is a query
query = String.trim_leading(query, "@") query = String.trim_leading(query, "@")
if resolve, do: User.get_or_fetch_by_nickname(query) if resolve, do: get_or_fetch(query)
fts_results = do_search(fts_search_subquery(query), for_user) fts_results = do_search(fts_search_subquery(query), for_user)

View File

@ -0,0 +1,30 @@
defmodule Pleroma.User.WelcomeMessage do
alias Pleroma.User
alias Pleroma.Web.CommonAPI
def post_welcome_message_to_user(user) do
with %User{} = sender_user <- welcome_user(),
message when is_binary(message) <- welcome_message() do
CommonAPI.post(sender_user, %{
"visibility" => "direct",
"status" => "@#{user.nickname}\n#{message}"
})
else
_ -> {:ok, nil}
end
end
defp welcome_user() do
with nickname when is_binary(nickname) <-
Pleroma.Config.get([:instance, :welcome_user_nickname]),
%User{local: true} = user <- User.get_cached_by_nickname(nickname) do
user
else
_ -> nil
end
end
defp welcome_message() do
Pleroma.Config.get([:instance, :welcome_message])
end
end

View File

@ -818,8 +818,6 @@ def fetch_object_from_id(id) do
if object = Object.get_cached_by_ap_id(id) do if object = Object.get_cached_by_ap_id(id) do
{:ok, object} {:ok, object}
else else
Logger.info("Fetching #{id} via AP")
with {:ok, data} <- fetch_and_contain_remote_object_from_id(id), with {:ok, data} <- fetch_and_contain_remote_object_from_id(id),
nil <- Object.normalize(data), nil <- Object.normalize(data),
params <- %{ params <- %{
@ -851,7 +849,7 @@ def fetch_object_from_id(id) do
end end
def fetch_and_contain_remote_object_from_id(id) do def fetch_and_contain_remote_object_from_id(id) do
Logger.info("Fetching #{id} via AP") Logger.info("Fetching object #{id} via AP")
with true <- String.starts_with?(id, "http"), with true <- String.starts_with?(id, "http"),
{:ok, %{body: body, status: code}} when code in 200..299 <- {:ok, %{body: body, status: code}} when code in 200..299 <-

View File

@ -6,40 +6,80 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do
alias Pleroma.User alias Pleroma.User
@behaviour Pleroma.Web.ActivityPub.MRF @behaviour Pleroma.Web.ActivityPub.MRF
defp delist_message(message) do defp delist_message(message, threshold) when threshold > 0 do
follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address
follower_collection? = Enum.member?(message["to"] ++ message["cc"], follower_collection)
message =
case get_recipient_count(message) do
{:public, recipients}
when follower_collection? and recipients > threshold ->
message message
|> Map.put("to", [follower_collection]) |> Map.put("to", [follower_collection])
|> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"]) |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"])
{:public, recipients} when recipients > threshold ->
message
|> Map.put("to", [])
|> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"])
_ ->
message
end
{:ok, message}
end
defp delist_message(message, _threshold), do: {:ok, message}
defp reject_message(message, threshold) when threshold > 0 do
with {_, recipients} <- get_recipient_count(message) do
if recipients > threshold do
{:reject, nil}
else
{:ok, message}
end
end
end
defp reject_message(message, _threshold), do: {:ok, message}
defp get_recipient_count(message) do
recipients = (message["to"] || []) ++ (message["cc"] || [])
follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address
if Enum.member?(recipients, "https://www.w3.org/ns/activitystreams#Public") do
recipients =
recipients
|> List.delete("https://www.w3.org/ns/activitystreams#Public")
|> List.delete(follower_collection)
{:public, length(recipients)}
else
recipients =
recipients
|> List.delete(follower_collection)
{:not_public, length(recipients)}
end
end end
@impl true @impl true
def filter(%{"type" => "Create"} = message) do def filter(%{"type" => "Create"} = message) do
delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold])
reject_threshold = reject_threshold =
Pleroma.Config.get( Pleroma.Config.get(
[:mrf_hellthread, :reject_threshold], [:mrf_hellthread, :reject_threshold],
Pleroma.Config.get([:mrf_hellthread, :threshold]) Pleroma.Config.get([:mrf_hellthread, :threshold])
) )
recipients = (message["to"] || []) ++ (message["cc"] || []) delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold])
cond do with {:ok, message} <- reject_message(message, reject_threshold),
length(recipients) > reject_threshold and reject_threshold > 0 -> {:ok, message} <- delist_message(message, delist_threshold) do
{:reject, nil} {:ok, message}
length(recipients) > delist_threshold and delist_threshold > 0 ->
if Enum.member?(message["to"], "https://www.w3.org/ns/activitystreams#Public") or
Enum.member?(message["cc"], "https://www.w3.org/ns/activitystreams#Public") do
{:ok, delist_message(message)}
else else
{:ok, message} _e -> {:reject, nil}
end
true ->
{:ok, message}
end end
end end

View File

@ -649,7 +649,7 @@ def get_obj_helper(id) do
if object = Object.normalize(id), do: {:ok, object}, else: nil if object = Object.normalize(id), do: {:ok, object}, else: nil
end end
def set_reply_to_uri(%{"inReplyTo" => inReplyTo} = object) do def set_reply_to_uri(%{"inReplyTo" => inReplyTo} = object) when is_binary(inReplyTo) do
with false <- String.starts_with?(inReplyTo, "http"), with false <- String.starts_with?(inReplyTo, "http"),
{:ok, %{data: replied_to_object}} <- get_obj_helper(inReplyTo) do {:ok, %{data: replied_to_object}} <- get_obj_helper(inReplyTo) do
Map.put(object, "inReplyTo", replied_to_object["external_url"] || inReplyTo) Map.put(object, "inReplyTo", replied_to_object["external_url"] || inReplyTo)
@ -765,12 +765,18 @@ def maybe_fix_object_url(data) do
def add_hashtags(object) do def add_hashtags(object) do
tags = tags =
(object["tag"] || []) (object["tag"] || [])
|> Enum.map(fn tag -> |> Enum.map(fn
# Expand internal representation tags into AS2 tags.
tag when is_binary(tag) ->
%{ %{
"href" => Pleroma.Web.Endpoint.url() <> "/tags/#{tag}", "href" => Pleroma.Web.Endpoint.url() <> "/tags/#{tag}",
"name" => "##{tag}", "name" => "##{tag}",
"type" => "Hashtag" "type" => "Hashtag"
} }
# Do not process tags which are already AS2 tag objects.
tag when is_map(tag) ->
tag
end) end)
object object

View File

@ -12,9 +12,26 @@ defmodule Pleroma.Web.ActivityPub.UserView do
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Transmogrifier alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.Router.Helpers
alias Pleroma.Web.Endpoint
import Ecto.Query import Ecto.Query
def render("endpoints.json", %{user: %User{nickname: nil, local: true} = _user}) do
%{"sharedInbox" => Helpers.activity_pub_url(Endpoint, :inbox)}
end
def render("endpoints.json", %{user: %User{local: true} = _user}) do
%{
"oauthAuthorizationEndpoint" => Helpers.o_auth_url(Endpoint, :authorize),
"oauthRegistrationEndpoint" => Helpers.mastodon_api_url(Endpoint, :create_app),
"oauthTokenEndpoint" => Helpers.o_auth_url(Endpoint, :token_exchange),
"sharedInbox" => Helpers.activity_pub_url(Endpoint, :inbox)
}
end
def render("endpoints.json", _), do: %{}
# the instance itself is not a Person, but instead an Application # the instance itself is not a Person, but instead an Application
def render("user.json", %{user: %{nickname: nil} = user}) do def render("user.json", %{user: %{nickname: nil} = user}) do
{:ok, user} = WebFinger.ensure_keys_present(user) {:ok, user} = WebFinger.ensure_keys_present(user)
@ -22,6 +39,8 @@ def render("user.json", %{user: %{nickname: nil} = user}) do
public_key = :public_key.pem_entry_encode(:SubjectPublicKeyInfo, public_key) public_key = :public_key.pem_entry_encode(:SubjectPublicKeyInfo, public_key)
public_key = :public_key.pem_encode([public_key]) public_key = :public_key.pem_encode([public_key])
endpoints = render("endpoints.json", %{user: user})
%{ %{
"id" => user.ap_id, "id" => user.ap_id,
"type" => "Application", "type" => "Application",
@ -37,9 +56,7 @@ def render("user.json", %{user: %{nickname: nil} = user}) do
"owner" => user.ap_id, "owner" => user.ap_id,
"publicKeyPem" => public_key "publicKeyPem" => public_key
}, },
"endpoints" => %{ "endpoints" => endpoints
"sharedInbox" => "#{Pleroma.Web.Endpoint.url()}/inbox"
}
} }
|> Map.merge(Utils.make_json_ld_header()) |> Map.merge(Utils.make_json_ld_header())
end end
@ -50,6 +67,8 @@ def render("user.json", %{user: user}) do
public_key = :public_key.pem_entry_encode(:SubjectPublicKeyInfo, public_key) public_key = :public_key.pem_entry_encode(:SubjectPublicKeyInfo, public_key)
public_key = :public_key.pem_encode([public_key]) public_key = :public_key.pem_encode([public_key])
endpoints = render("endpoints.json", %{user: user})
%{ %{
"id" => user.ap_id, "id" => user.ap_id,
"type" => "Person", "type" => "Person",
@ -67,9 +86,7 @@ def render("user.json", %{user: user}) do
"owner" => user.ap_id, "owner" => user.ap_id,
"publicKeyPem" => public_key "publicKeyPem" => public_key
}, },
"endpoints" => %{ "endpoints" => endpoints,
"sharedInbox" => "#{Pleroma.Web.Endpoint.url()}/inbox"
},
"icon" => %{ "icon" => %{
"type" => "Image", "type" => "Image",
"url" => User.avatar_url(user) "url" => User.avatar_url(user)
@ -88,7 +105,14 @@ def render("following.json", %{user: user, page: page}) do
query = from(user in query, select: [:ap_id]) query = from(user in query, select: [:ap_id])
following = Repo.all(query) following = Repo.all(query)
collection(following, "#{user.ap_id}/following", page, !user.info.hide_follows) total =
if !user.info.hide_follows do
length(following)
else
0
end
collection(following, "#{user.ap_id}/following", page, !user.info.hide_follows, total)
|> Map.merge(Utils.make_json_ld_header()) |> Map.merge(Utils.make_json_ld_header())
end end
@ -97,10 +121,17 @@ def render("following.json", %{user: user}) do
query = from(user in query, select: [:ap_id]) query = from(user in query, select: [:ap_id])
following = Repo.all(query) following = Repo.all(query)
total =
if !user.info.hide_follows do
length(following)
else
0
end
%{ %{
"id" => "#{user.ap_id}/following", "id" => "#{user.ap_id}/following",
"type" => "OrderedCollection", "type" => "OrderedCollection",
"totalItems" => length(following), "totalItems" => total,
"first" => collection(following, "#{user.ap_id}/following", 1, !user.info.hide_follows) "first" => collection(following, "#{user.ap_id}/following", 1, !user.info.hide_follows)
} }
|> Map.merge(Utils.make_json_ld_header()) |> Map.merge(Utils.make_json_ld_header())
@ -111,7 +142,14 @@ def render("followers.json", %{user: user, page: page}) do
query = from(user in query, select: [:ap_id]) query = from(user in query, select: [:ap_id])
followers = Repo.all(query) followers = Repo.all(query)
collection(followers, "#{user.ap_id}/followers", page, !user.info.hide_followers) total =
if !user.info.hide_followers do
length(followers)
else
0
end
collection(followers, "#{user.ap_id}/followers", page, !user.info.hide_followers, total)
|> Map.merge(Utils.make_json_ld_header()) |> Map.merge(Utils.make_json_ld_header())
end end
@ -120,19 +158,24 @@ def render("followers.json", %{user: user}) do
query = from(user in query, select: [:ap_id]) query = from(user in query, select: [:ap_id])
followers = Repo.all(query) followers = Repo.all(query)
total =
if !user.info.hide_followers do
length(followers)
else
0
end
%{ %{
"id" => "#{user.ap_id}/followers", "id" => "#{user.ap_id}/followers",
"type" => "OrderedCollection", "type" => "OrderedCollection",
"totalItems" => length(followers), "totalItems" => total,
"first" => collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_followers) "first" =>
collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_followers, total)
} }
|> Map.merge(Utils.make_json_ld_header()) |> Map.merge(Utils.make_json_ld_header())
end end
def render("outbox.json", %{user: user, max_id: max_qid}) do def render("outbox.json", %{user: user, max_id: max_qid}) do
# XXX: technically note_count is wrong for this, but it's better than nothing
info = User.user_info(user)
params = %{ params = %{
"limit" => "10" "limit" => "10"
} }
@ -160,7 +203,6 @@ def render("outbox.json", %{user: user, max_id: max_qid}) do
"id" => "#{iri}?max_id=#{max_id}", "id" => "#{iri}?max_id=#{max_id}",
"type" => "OrderedCollectionPage", "type" => "OrderedCollectionPage",
"partOf" => iri, "partOf" => iri,
"totalItems" => info.note_count,
"orderedItems" => collection, "orderedItems" => collection,
"next" => "#{iri}?max_id=#{min_id}" "next" => "#{iri}?max_id=#{min_id}"
} }
@ -169,7 +211,6 @@ def render("outbox.json", %{user: user, max_id: max_qid}) do
%{ %{
"id" => iri, "id" => iri,
"type" => "OrderedCollection", "type" => "OrderedCollection",
"totalItems" => info.note_count,
"first" => page "first" => page
} }
|> Map.merge(Utils.make_json_ld_header()) |> Map.merge(Utils.make_json_ld_header())
@ -207,7 +248,6 @@ def render("inbox.json", %{user: user, max_id: max_qid}) do
"id" => "#{iri}?max_id=#{max_id}", "id" => "#{iri}?max_id=#{max_id}",
"type" => "OrderedCollectionPage", "type" => "OrderedCollectionPage",
"partOf" => iri, "partOf" => iri,
"totalItems" => -1,
"orderedItems" => collection, "orderedItems" => collection,
"next" => "#{iri}?max_id=#{min_id}" "next" => "#{iri}?max_id=#{min_id}"
} }
@ -216,7 +256,6 @@ def render("inbox.json", %{user: user, max_id: max_qid}) do
%{ %{
"id" => iri, "id" => iri,
"type" => "OrderedCollection", "type" => "OrderedCollection",
"totalItems" => -1,
"first" => page "first" => page
} }
|> Map.merge(Utils.make_json_ld_header()) |> Map.merge(Utils.make_json_ld_header())

View File

@ -166,7 +166,7 @@ def render("status.json", %{activity: %{data: %{"object" => object}} = activity}
sensitive: sensitive, sensitive: sensitive,
spoiler_text: object["summary"] || "", spoiler_text: object["summary"] || "",
visibility: get_visibility(object), visibility: get_visibility(object),
media_attachments: attachments |> Enum.take(4), media_attachments: attachments,
mentions: mentions, mentions: mentions,
tags: build_tags(tags), tags: build_tags(tags),
application: %{ application: %{

View File

@ -19,11 +19,16 @@ def url(url) do
else else
secret = Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:secret_key_base] secret = Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:secret_key_base]
# Must preserve `%2F` for compatibility with S3 (https://git.pleroma.social/pleroma/pleroma/issues/580)
replacement = get_replacement(url, ":2F:")
# The URL is url-decoded and encoded again to ensure it is correctly encoded and not twice. # The URL is url-decoded and encoded again to ensure it is correctly encoded and not twice.
base64 = base64 =
url url
|> String.replace("%2F", replacement)
|> URI.decode() |> URI.decode()
|> URI.encode() |> URI.encode()
|> String.replace(replacement, "%2F")
|> Base.url_encode64(@base64_opts) |> Base.url_encode64(@base64_opts)
sig = :crypto.hmac(:sha, secret, base64) sig = :crypto.hmac(:sha, secret, base64)
@ -60,4 +65,12 @@ def build_url(sig_base64, url_base64, filename \\ nil) do
|> Enum.filter(fn value -> value end) |> Enum.filter(fn value -> value end)
|> Path.join() |> Path.join()
end end
defp get_replacement(url, replacement) do
if String.contains?(url, replacement) do
get_replacement(url, replacement <> replacement)
else
replacement
end
end
end end

View File

@ -25,8 +25,14 @@ def register_changeset(struct, params \\ %{}) do
if changeset.valid? do if changeset.valid? do
changeset changeset
|> put_change(:client_id, :crypto.strong_rand_bytes(32) |> Base.url_encode64()) |> put_change(
|> put_change(:client_secret, :crypto.strong_rand_bytes(32) |> Base.url_encode64()) :client_id,
:crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false)
)
|> put_change(
:client_secret,
:crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false)
)
else else
changeset changeset
end end

View File

@ -24,7 +24,7 @@ defmodule Pleroma.Web.OAuth.Authorization do
end end
def create_authorization(%App{} = app, %User{} = user) do def create_authorization(%App{} = app, %User{} = user) do
token = :crypto.strong_rand_bytes(32) |> Base.url_encode64() token = :crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false)
authorization = %Authorization{ authorization = %Authorization{
token: token, token: token,

View File

@ -173,7 +173,7 @@ defp fix_padding(token) do
token token
|> URI.decode() |> URI.decode()
|> Base.url_decode64!(padding: false) |> Base.url_decode64!(padding: false)
|> Base.url_encode64() |> Base.url_encode64(padding: false)
end end
defp get_app_from_request(conn, params) do defp get_app_from_request(conn, params) do

View File

@ -31,8 +31,8 @@ def exchange_token(app, auth) do
end end
def create_token(%App{} = app, %User{} = user) do def create_token(%App{} = app, %User{} = user) do
token = :crypto.strong_rand_bytes(32) |> Base.url_encode64() token = :crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false)
refresh_token = :crypto.strong_rand_bytes(32) |> Base.url_encode64() refresh_token = :crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false)
token = %Token{ token = %Token{
token: token, token: token,

View File

@ -468,8 +468,8 @@ defmodule Pleroma.Web.Router do
scope "/", Pleroma.Web.ActivityPub do scope "/", Pleroma.Web.ActivityPub do
pipe_through(:activitypub) pipe_through(:activitypub)
post("/users/:nickname/inbox", ActivityPubController, :inbox)
post("/inbox", ActivityPubController, :inbox) post("/inbox", ActivityPubController, :inbox)
post("/users/:nickname/inbox", ActivityPubController, :inbox)
end end
scope "/.well-known", Pleroma.Web do scope "/.well-known", Pleroma.Web do

View File

@ -67,6 +67,32 @@
font-weight: 500; font-weight: 500;
font-size: 16px; font-size: 16px;
} }
.alert-danger {
box-sizing: border-box;
width: 100%;
color: #D8000C;
background-color: #FFD2D2;
border-radius: 4px;
border: none;
padding: 10px;
margin-top: 20px;
font-weight: 500;
font-size: 16px;
}
.alert-info {
box-sizing: border-box;
width: 100%;
color: #00529B;
background-color: #BDE5F8;
border-radius: 4px;
border: none;
padding: 10px;
margin-top: 20px;
font-weight: 500;
font-size: 16px;
}
</style> </style>
</head> </head>
<body> <body>

View File

@ -1,5 +1,9 @@
<%= if get_flash(@conn, :info) do %>
<p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p> <p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>
<% end %>
<%= if get_flash(@conn, :error) do %>
<p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p> <p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>
<% end %>
<h2>OAuth Authorization</h2> <h2>OAuth Authorization</h2>
<%= form_for @conn, o_auth_path(@conn, :authorize), [as: "authorization"], fn f -> %> <%= form_for @conn, o_auth_path(@conn, :authorize), [as: "authorization"], fn f -> %>
<%= label f, :name, "Name or email" %> <%= label f, :name, "Name or email" %>

View File

@ -21,7 +21,14 @@ def project do
homepage_url: "https://pleroma.social/", homepage_url: "https://pleroma.social/",
docs: [ docs: [
logo: "priv/static/static/logo.png", logo: "priv/static/static/logo.png",
extras: ["README.md", "docs/Admin-API.md", "docs/Clients.md", "docs/config.md", "docs/Pleroma-API.md"], extras: [
"README.md",
"docs/config.md",
"docs/Pleroma-API.md",
"docs/Admin-API.md",
"docs/Clients.md",
"docs/Differences-in-MastodonAPI-Responses.md"
],
main: "readme", main: "readme",
output: "priv/static/doc" output: "priv/static/doc"
] ]

View File

@ -19,7 +19,11 @@
"value": "schema:value", "value": "schema:value",
"sensitive": "as:sensitive", "sensitive": "as:sensitive",
"litepub": "http://litepub.social/ns#", "litepub": "http://litepub.social/ns#",
"directMessage": "litepub:directMessage" "directMessage": "litepub:directMessage",
"oauthRegistrationEndpoint": {
"@id": "litepub:oauthRegistrationEndpoint",
"@type": "@id"
}
} }
] ]
} }

View File

@ -197,7 +197,7 @@ test "does not give a replacement for single-character local nicknames who don't
{subs, text} = Formatter.add_user_links({[], text}, mentions) {subs, text} = Formatter.add_user_links({[], text}, mentions)
assert length(subs) == 0 assert Enum.empty?(subs)
Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end) Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
expected_text = "@a hi" expected_text = "@a hi"

View File

@ -140,6 +140,15 @@ test "uses the configured base_url" do
assert String.starts_with?(encoded, Pleroma.Config.get([:media_proxy, :base_url])) assert String.starts_with?(encoded, Pleroma.Config.get([:media_proxy, :base_url]))
end end
# https://git.pleroma.social/pleroma/pleroma/issues/580
test "encoding S3 links (must preserve `%2F`)" do
url =
"https://s3.amazonaws.com/example/test.png?X-Amz-Credential=your-access-key-id%2F20130721%2Fus-east-1%2Fs3%2Faws4_request"
encoded = url(url)
assert decode_result(encoded) == url
end
end end
describe "when disabled" do describe "when disabled" do

View File

@ -6,7 +6,8 @@ defmodule Pleroma.NotificationTest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
alias Pleroma.{User, Notification} alias Pleroma.User
alias Pleroma.Notification
alias Pleroma.Web.ActivityPub.Transmogrifier alias Pleroma.Web.ActivityPub.Transmogrifier
import Pleroma.Factory import Pleroma.Factory
@ -299,7 +300,7 @@ test "liking an activity results in 1 notification, then 0 if the activity is de
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"}) {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
assert length(Notification.for_user(user)) == 0 assert Enum.empty?(Notification.for_user(user))
{:ok, _, _} = CommonAPI.favorite(activity.id, other_user) {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
@ -307,7 +308,7 @@ test "liking an activity results in 1 notification, then 0 if the activity is de
{:ok, _} = CommonAPI.delete(activity.id, user) {:ok, _} = CommonAPI.delete(activity.id, user)
assert length(Notification.for_user(user)) == 0 assert Enum.empty?(Notification.for_user(user))
end end
test "liking an activity results in 1 notification, then 0 if the activity is unliked" do test "liking an activity results in 1 notification, then 0 if the activity is unliked" do
@ -316,7 +317,7 @@ test "liking an activity results in 1 notification, then 0 if the activity is un
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"}) {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
assert length(Notification.for_user(user)) == 0 assert Enum.empty?(Notification.for_user(user))
{:ok, _, _} = CommonAPI.favorite(activity.id, other_user) {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
@ -324,7 +325,7 @@ test "liking an activity results in 1 notification, then 0 if the activity is un
{:ok, _, _, _} = CommonAPI.unfavorite(activity.id, other_user) {:ok, _, _, _} = CommonAPI.unfavorite(activity.id, other_user)
assert length(Notification.for_user(user)) == 0 assert Enum.empty?(Notification.for_user(user))
end end
test "repeating an activity results in 1 notification, then 0 if the activity is deleted" do test "repeating an activity results in 1 notification, then 0 if the activity is deleted" do
@ -333,7 +334,7 @@ test "repeating an activity results in 1 notification, then 0 if the activity is
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"}) {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
assert length(Notification.for_user(user)) == 0 assert Enum.empty?(Notification.for_user(user))
{:ok, _, _} = CommonAPI.repeat(activity.id, other_user) {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
@ -341,7 +342,7 @@ test "repeating an activity results in 1 notification, then 0 if the activity is
{:ok, _} = CommonAPI.delete(activity.id, user) {:ok, _} = CommonAPI.delete(activity.id, user)
assert length(Notification.for_user(user)) == 0 assert Enum.empty?(Notification.for_user(user))
end end
test "repeating an activity results in 1 notification, then 0 if the activity is unrepeated" do test "repeating an activity results in 1 notification, then 0 if the activity is unrepeated" do
@ -350,7 +351,7 @@ test "repeating an activity results in 1 notification, then 0 if the activity is
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"}) {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
assert length(Notification.for_user(user)) == 0 assert Enum.empty?(Notification.for_user(user))
{:ok, _, _} = CommonAPI.repeat(activity.id, other_user) {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
@ -358,7 +359,7 @@ test "repeating an activity results in 1 notification, then 0 if the activity is
{:ok, _, _} = CommonAPI.unrepeat(activity.id, other_user) {:ok, _, _} = CommonAPI.unrepeat(activity.id, other_user)
assert length(Notification.for_user(user)) == 0 assert Enum.empty?(Notification.for_user(user))
end end
test "liking an activity which is already deleted does not generate a notification" do test "liking an activity which is already deleted does not generate a notification" do
@ -367,15 +368,15 @@ test "liking an activity which is already deleted does not generate a notificati
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"}) {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
assert length(Notification.for_user(user)) == 0 assert Enum.empty?(Notification.for_user(user))
{:ok, _deletion_activity} = CommonAPI.delete(activity.id, user) {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
assert length(Notification.for_user(user)) == 0 assert Enum.empty?(Notification.for_user(user))
{:error, _} = CommonAPI.favorite(activity.id, other_user) {:error, _} = CommonAPI.favorite(activity.id, other_user)
assert length(Notification.for_user(user)) == 0 assert Enum.empty?(Notification.for_user(user))
end end
test "repeating an activity which is already deleted does not generate a notification" do test "repeating an activity which is already deleted does not generate a notification" do
@ -384,15 +385,15 @@ test "repeating an activity which is already deleted does not generate a notific
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"}) {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
assert length(Notification.for_user(user)) == 0 assert Enum.empty?(Notification.for_user(user))
{:ok, _deletion_activity} = CommonAPI.delete(activity.id, user) {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
assert length(Notification.for_user(user)) == 0 assert Enum.empty?(Notification.for_user(user))
{:error, _} = CommonAPI.repeat(activity.id, other_user) {:error, _} = CommonAPI.repeat(activity.id, other_user)
assert length(Notification.for_user(user)) == 0 assert Enum.empty?(Notification.for_user(user))
end end
test "replying to a deleted post without tagging does not generate a notification" do test "replying to a deleted post without tagging does not generate a notification" do
@ -408,7 +409,7 @@ test "replying to a deleted post without tagging does not generate a notificatio
"in_reply_to_status_id" => activity.id "in_reply_to_status_id" => activity.id
}) })
assert length(Notification.for_user(user)) == 0 assert Enum.empty?(Notification.for_user(user))
end end
end end
end end

View File

@ -5,7 +5,8 @@
defmodule Pleroma.ObjectTest do defmodule Pleroma.ObjectTest do
use Pleroma.DataCase use Pleroma.DataCase
import Pleroma.Factory import Pleroma.Factory
alias Pleroma.{Repo, Object} alias Pleroma.Repo
alias Pleroma.Object
test "returns an object by it's AP id" do test "returns an object by it's AP id" do
object = insert(:note) object = insert(:note)

View File

@ -1,5 +1,6 @@
defmodule Pleroma.Builders.UserBuilder do defmodule Pleroma.Builders.UserBuilder do
alias Pleroma.{User, Repo} alias Pleroma.User
alias Pleroma.Repo
def build(data \\ %{}) do def build(data \\ %{}) do
user = %User{ user = %User{

View File

@ -4,7 +4,9 @@
defmodule Mix.Tasks.Pleroma.RelayTest do defmodule Mix.Tasks.Pleroma.RelayTest do
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Web.ActivityPub.{ActivityPub, Relay, Utils} alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.ActivityPub.Relay
alias Pleroma.User alias Pleroma.User
use Pleroma.DataCase use Pleroma.DataCase

View File

@ -151,7 +151,7 @@ test "user is unsubscribed" do
assert message =~ "Successfully unsubscribed" assert message =~ "Successfully unsubscribed"
user = User.get_by_nickname(user.nickname) user = User.get_by_nickname(user.nickname)
assert length(user.following) == 0 assert Enum.empty?(user.following)
assert user.info.deactivated assert user.info.deactivated
end end

View File

@ -4,7 +4,9 @@
defmodule Pleroma.UserTest do defmodule Pleroma.UserTest do
alias Pleroma.Builders.UserBuilder alias Pleroma.Builders.UserBuilder
alias Pleroma.{User, Repo, Activity} alias Pleroma.Activity
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
use Pleroma.DataCase use Pleroma.DataCase
@ -55,18 +57,21 @@ test "follow_all follows mutliple users" do
followed_two = insert(:user) followed_two = insert(:user)
blocked = insert(:user) blocked = insert(:user)
not_followed = insert(:user) not_followed = insert(:user)
reverse_blocked = insert(:user)
{:ok, user} = User.block(user, blocked) {:ok, user} = User.block(user, blocked)
{:ok, reverse_blocked} = User.block(reverse_blocked, user)
{:ok, user} = User.follow(user, followed_zero) {:ok, user} = User.follow(user, followed_zero)
{:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked]) {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked, reverse_blocked])
assert User.following?(user, followed_one) assert User.following?(user, followed_one)
assert User.following?(user, followed_two) assert User.following?(user, followed_two)
assert User.following?(user, followed_zero) assert User.following?(user, followed_zero)
refute User.following?(user, not_followed) refute User.following?(user, not_followed)
refute User.following?(user, blocked) refute User.following?(user, blocked)
refute User.following?(user, reverse_blocked)
end end
test "follow_all follows mutliple users without duplicating" do test "follow_all follows mutliple users without duplicating" do
@ -191,6 +196,26 @@ test "it autofollows accounts that are set for it" do
assert User.following?(registered_user, user) assert User.following?(registered_user, user)
refute User.following?(registered_user, remote_user) refute User.following?(registered_user, remote_user)
Pleroma.Config.put([:instance, :autofollowed_nicknames], [])
end
test "it sends a welcome message if it is set" do
welcome_user = insert(:user)
Pleroma.Config.put([:instance, :welcome_user_nickname], welcome_user.nickname)
Pleroma.Config.put([:instance, :welcome_message], "Hello, this is a cool site")
cng = User.register_changeset(%User{}, @full_user_data)
{:ok, registered_user} = User.register(cng)
activity = Repo.one(Pleroma.Activity)
assert registered_user.ap_id in activity.recipients
assert activity.data["object"]["content"] =~ "cool site"
assert activity.actor == welcome_user.ap_id
Pleroma.Config.put([:instance, :welcome_user_nickname], nil)
Pleroma.Config.put([:instance, :welcome_message], nil)
end end
test "it requires an email, name, nickname and password, bio is optional" do test "it requires an email, name, nickname and password, bio is optional" do
@ -873,6 +898,16 @@ test "does not yield false-positive matches" do
assert [] == User.search(query) assert [] == User.search(query)
end) end)
end end
test "works with URIs" do
results = User.search("http://mastodon.example.org/users/admin", true)
result = results |> List.first()
user = User.get_by_ap_id("http://mastodon.example.org/users/admin")
assert length(results) == 1
assert user == result |> Map.put(:search_rank, nil)
end
end end
test "auth_active?/1 works correctly" do test "auth_active?/1 works correctly" do

View File

@ -5,8 +5,13 @@
defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
use Pleroma.Web.ConnCase use Pleroma.Web.ConnCase
import Pleroma.Factory import Pleroma.Factory
alias Pleroma.Web.ActivityPub.{UserView, ObjectView} alias Pleroma.Web.ActivityPub.UserView
alias Pleroma.{Object, Repo, Activity, User, Instances} alias Pleroma.Web.ActivityPub.ObjectView
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.Activity
alias Pleroma.User
alias Pleroma.Instances
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)
@ -397,7 +402,7 @@ test "it returns returns empty if the user has 'hide_followers' set", %{conn: co
|> json_response(200) |> json_response(200)
assert result["first"]["orderedItems"] == [] assert result["first"]["orderedItems"] == []
assert result["totalItems"] == 1 assert result["totalItems"] == 0
end end
test "it works for more than 10 users", %{conn: conn} do test "it works for more than 10 users", %{conn: conn} do
@ -452,7 +457,7 @@ test "it returns returns empty if the user has 'hide_follows' set", %{conn: conn
|> json_response(200) |> json_response(200)
assert result["first"]["orderedItems"] == [] assert result["first"]["orderedItems"] == []
assert result["totalItems"] == 1 assert result["totalItems"] == 0
end end
test "it works for more than 10 users", %{conn: conn} do test "it works for more than 10 users", %{conn: conn} do

View File

@ -7,7 +7,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
alias Pleroma.{Activity, Object, User, Instances} alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Instances
alias Pleroma.Builders.ActivityBuilder alias Pleroma.Builders.ActivityBuilder
import Pleroma.Factory import Pleroma.Factory

View File

@ -0,0 +1,73 @@
# Pleroma: A lightweight social networking server
# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
use Pleroma.DataCase
import Pleroma.Factory
import Pleroma.Web.ActivityPub.MRF.HellthreadPolicy
setup do
user = insert(:user)
message = %{
"actor" => user.ap_id,
"cc" => [user.follower_address],
"type" => "Create",
"to" => [
"https://www.w3.org/ns/activitystreams#Public",
"https://instance.tld/users/user1",
"https://instance.tld/users/user2",
"https://instance.tld/users/user3"
]
}
[user: user, message: message]
end
describe "reject" do
test "rejects the message if the recipient count is above reject_threshold", %{
message: message
} do
Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
{:reject, nil} = filter(message)
end
test "does not reject the message if the recipient count is below reject_threshold", %{
message: message
} do
Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
assert {:ok, ^message} = filter(message)
end
end
describe "delist" do
test "delists the message if the recipient count is above delist_threshold", %{
user: user,
message: message
} do
Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
{:ok, message} = filter(message)
assert user.follower_address in message["to"]
assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"]
end
test "does not delist the message if the recipient count is below delist_threshold", %{
message: message
} do
Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 4, reject_threshold: 0})
assert {:ok, ^message} = filter(message)
end
end
test "excludes follower collection and public URI from threshold count", %{message: message} do
Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
assert {:ok, ^message} = filter(message)
end
end

View File

@ -1128,4 +1128,58 @@ test "all objects with fake directions are rejected by the object fetcher" do
) )
end end
end end
describe "reserialization" do
test "successfully reserializes a message with inReplyTo == nil" do
user = insert(:user)
message = %{
"@context" => "https://www.w3.org/ns/activitystreams",
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
"cc" => [],
"type" => "Create",
"object" => %{
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
"cc" => [],
"type" => "Note",
"content" => "Hi",
"inReplyTo" => nil,
"attributedTo" => user.ap_id
},
"actor" => user.ap_id
}
{:ok, activity} = Transmogrifier.handle_incoming(message)
{:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
end
test "successfully reserializes a message with AS2 objects in IR" do
user = insert(:user)
message = %{
"@context" => "https://www.w3.org/ns/activitystreams",
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
"cc" => [],
"type" => "Create",
"object" => %{
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
"cc" => [],
"type" => "Note",
"content" => "Hi",
"inReplyTo" => nil,
"attributedTo" => user.ap_id,
"tag" => [
%{"name" => "#2hu", "href" => "http://example.com/2hu", "type" => "Hashtag"},
%{"name" => "Bob", "href" => "http://example.com/bob", "type" => "Mention"}
]
},
"actor" => user.ap_id
}
{:ok, activity} = Transmogrifier.handle_incoming(message)
{:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
end
end
end end

View File

@ -15,4 +15,43 @@ test "Renders a user, including the public key" do
assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY") assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
end end
describe "endpoints" do
test "local users have a usable endpoints structure" do
user = insert(:user)
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
result = UserView.render("user.json", %{user: user})
assert result["id"] == user.ap_id
%{
"sharedInbox" => _,
"oauthAuthorizationEndpoint" => _,
"oauthRegistrationEndpoint" => _,
"oauthTokenEndpoint" => _
} = result["endpoints"]
end
test "remote users have an empty endpoints structure" do
user = insert(:user, local: false)
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
result = UserView.render("user.json", %{user: user})
assert result["id"] == user.ap_id
assert result["endpoints"] == %{}
end
test "instance users do not expose oAuth endpoints" do
user = insert(:user, nickname: nil, local: true)
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
result = UserView.render("user.json", %{user: user})
refute result["endpoints"]["oauthAuthorizationEndpoint"]
refute result["endpoints"]["oauthRegistrationEndpoint"]
refute result["endpoints"]["oauthTokenEndpoint"]
end
end
end end

View File

@ -5,7 +5,8 @@
defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
use Pleroma.Web.ConnCase use Pleroma.Web.ConnCase
alias Pleroma.{Repo, User} alias Pleroma.Repo
alias Pleroma.User
import Pleroma.Factory import Pleroma.Factory
describe "/api/pleroma/admin/user" do describe "/api/pleroma/admin/user" do

View File

@ -2,7 +2,7 @@
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.CommonAPI.Test do defmodule Pleroma.Web.CommonAPITest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
alias Pleroma.User alias Pleroma.User

View File

@ -5,7 +5,7 @@
defmodule Pleroma.Web.CommonAPI.UtilsTest do defmodule Pleroma.Web.CommonAPI.UtilsTest do
alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.Endpoint alias Pleroma.Web.Endpoint
alias Pleroma.Builders.{UserBuilder} alias Pleroma.Builders.UserBuilder
use Pleroma.DataCase use Pleroma.DataCase
test "it adds attachment links to a given text and attachment set" do test "it adds attachment links to a given text and attachment set" do

View File

@ -3,7 +3,8 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.FederatorTest do defmodule Pleroma.Web.FederatorTest do
alias Pleroma.Web.{CommonAPI, Federator} alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Federator
alias Pleroma.Instances alias Pleroma.Instances
use Pleroma.DataCase use Pleroma.DataCase
import Pleroma.Factory import Pleroma.Factory

View File

@ -6,8 +6,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
use Pleroma.Web.ConnCase use Pleroma.Web.ConnCase
alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.{Repo, User, Object, Activity, Notification} alias Pleroma.Repo
alias Pleroma.Web.{OStatus, CommonAPI} alias Pleroma.User
alias Pleroma.Object
alias Pleroma.Activity
alias Pleroma.Notification
alias Pleroma.Web.OStatus
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.MastodonAPI.FilterView alias Pleroma.Web.MastodonAPI.FilterView
alias Ecto.Changeset alias Ecto.Changeset
@ -31,7 +36,7 @@ test "the home timeline", %{conn: conn} do
|> assign(:user, user) |> assign(:user, user)
|> get("/api/v1/timelines/home") |> get("/api/v1/timelines/home")
assert length(json_response(conn, 200)) == 0 assert Enum.empty?(json_response(conn, 200))
{:ok, user} = User.follow(user, following) {:ok, user} = User.follow(user, following)

View File

@ -5,7 +5,8 @@
defmodule Pleroma.Web.MastodonAPI.StatusViewTest do defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.Web.MastodonAPI.{StatusView, AccountView} alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.MastodonAPI.StatusView
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.OStatus alias Pleroma.Web.OStatus
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI

View File

@ -4,7 +4,8 @@
defmodule Pleroma.Web.OAuth.AuthorizationTest do defmodule Pleroma.Web.OAuth.AuthorizationTest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.Web.OAuth.{Authorization, App} alias Pleroma.Web.OAuth.Authorization
alias Pleroma.Web.OAuth.App
import Pleroma.Factory import Pleroma.Factory
test "create an authorization token for a valid app" do test "create an authorization token for a valid app" do

View File

@ -7,7 +7,8 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
import Pleroma.Factory import Pleroma.Factory
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.Web.OAuth.{Authorization, Token} alias Pleroma.Web.OAuth.Authorization
alias Pleroma.Web.OAuth.Token
test "redirects with oauth authorization" do test "redirects with oauth authorization" do
user = insert(:user) user = insert(:user)

View File

@ -4,7 +4,9 @@
defmodule Pleroma.Web.OAuth.TokenTest do defmodule Pleroma.Web.OAuth.TokenTest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.Web.OAuth.{App, Token, Authorization} alias Pleroma.Web.OAuth.App
alias Pleroma.Web.OAuth.Authorization
alias Pleroma.Web.OAuth.Token
alias Pleroma.Repo alias Pleroma.Repo
import Pleroma.Factory import Pleroma.Factory

View File

@ -6,7 +6,9 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.Web.OStatus.ActivityRepresenter alias Pleroma.Web.OStatus.ActivityRepresenter
alias Pleroma.{User, Activity, Object} alias Pleroma.Activity
alias Pleroma.User
alias Pleroma.Object
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.OStatus alias Pleroma.Web.OStatus

View File

@ -6,7 +6,9 @@ defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
use Pleroma.DataCase use Pleroma.DataCase
import Pleroma.Factory import Pleroma.Factory
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.OStatus.{FeedRepresenter, UserRepresenter, ActivityRepresenter} alias Pleroma.Web.OStatus.ActivityRepresenter
alias Pleroma.Web.OStatus.FeedRepresenter
alias Pleroma.Web.OStatus.UserRepresenter
alias Pleroma.Web.OStatus alias Pleroma.Web.OStatus
test "returns a feed of the last 20 items of the user" do test "returns a feed of the last 20 items of the user" do

View File

@ -4,7 +4,9 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
import Pleroma.Factory import Pleroma.Factory
import Tesla.Mock import Tesla.Mock
alias Pleroma.{Repo, Activity, Object} alias Pleroma.Repo
alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.Web.OStatus alias Pleroma.Web.OStatus
setup do setup do

View File

@ -5,7 +5,9 @@
defmodule Pleroma.Web.OStatus.OStatusControllerTest do defmodule Pleroma.Web.OStatus.OStatusControllerTest do
use Pleroma.Web.ConnCase use Pleroma.Web.ConnCase
import Pleroma.Factory import Pleroma.Factory
alias Pleroma.{User, Repo, Object} alias Pleroma.User
alias Pleroma.Repo
alias Pleroma.Object
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OStatus.ActivityRepresenter alias Pleroma.Web.OStatus.ActivityRepresenter

View File

@ -6,7 +6,11 @@ defmodule Pleroma.Web.OStatusTest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.Web.OStatus alias Pleroma.Web.OStatus
alias Pleroma.Web.XML alias Pleroma.Web.XML
alias Pleroma.{Object, Repo, User, Activity, Instances} alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Activity
alias Pleroma.Instances
import Pleroma.Factory import Pleroma.Factory
import ExUnit.CaptureLog import ExUnit.CaptureLog

View File

@ -5,7 +5,9 @@
defmodule Pleroma.Web.Salmon.SalmonTest do defmodule Pleroma.Web.Salmon.SalmonTest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.Web.Salmon alias Pleroma.Web.Salmon
alias Pleroma.{Repo, Activity, User} alias Pleroma.Activity
alias Pleroma.Repo
alias Pleroma.User
import Pleroma.Factory import Pleroma.Factory
@magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB" @magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"

View File

@ -4,8 +4,11 @@
defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.{User, Activity, Object} alias Pleroma.User
alias Pleroma.Web.TwitterAPI.Representers.{ActivityRepresenter, ObjectRepresenter} alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.TwitterAPI.UserView
import Pleroma.Factory import Pleroma.Factory

View File

@ -5,8 +5,13 @@
defmodule Pleroma.Web.TwitterAPI.ControllerTest do defmodule Pleroma.Web.TwitterAPI.ControllerTest do
use Pleroma.Web.ConnCase use Pleroma.Web.ConnCase
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
alias Pleroma.Builders.{ActivityBuilder, UserBuilder} alias Pleroma.Builders.ActivityBuilder
alias Pleroma.{Repo, Activity, User, Object, Notification} alias Pleroma.Builders.UserBuilder
alias Pleroma.Repo
alias Pleroma.Activity
alias Pleroma.User
alias Pleroma.Object
alias Pleroma.Notification
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Web.TwitterAPI.NotificationView alias Pleroma.Web.TwitterAPI.NotificationView

View File

@ -4,8 +4,13 @@
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView} alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.{Activity, User, Object, Repo, UserInviteToken} alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Activity
alias Pleroma.User
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.UserInviteToken
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.ActivityView alias Pleroma.Web.TwitterAPI.ActivityView

View File

@ -5,7 +5,8 @@
defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.{User, Notification} alias Pleroma.User
alias Pleroma.Notification
alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.TwitterAPI.NotificationView alias Pleroma.Web.TwitterAPI.NotificationView
alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.TwitterAPI.UserView

View File

@ -6,7 +6,8 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
use Pleroma.Web.ConnCase use Pleroma.Web.ConnCase
import Pleroma.Factory import Pleroma.Factory
alias Pleroma.Web.Websub.WebsubClientSubscription alias Pleroma.Web.Websub.WebsubClientSubscription
alias Pleroma.{Repo, Activity} alias Pleroma.Activity
alias Pleroma.Repo
alias Pleroma.Web.Websub alias Pleroma.Web.Websub
test "websub subscription request", %{conn: conn} do test "websub subscription request", %{conn: conn} do
@ -80,7 +81,7 @@ test "rejects incoming feed updates with the wrong signature", %{conn: conn} do
assert response(conn, 500) == "Error" assert response(conn, 500) == "Error"
assert length(Repo.all(Activity)) == 0 assert Enum.empty?(Repo.all(Activity))
end end
end end
end end

View File

@ -5,7 +5,8 @@
defmodule Pleroma.Web.WebsubTest do defmodule Pleroma.Web.WebsubTest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.Web.Websub alias Pleroma.Web.Websub
alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription} alias Pleroma.Web.Websub.WebsubServerSubscription
alias Pleroma.Web.Websub.WebsubClientSubscription
import Pleroma.Factory import Pleroma.Factory
alias Pleroma.Web.Router.Helpers alias Pleroma.Web.Router.Helpers
import Tesla.Mock import Tesla.Mock