Merge remote-tracking branch 'origin/develop' into feature/local-only-scope
This commit is contained in:
commit
8542d2efee
25 changed files with 396 additions and 259 deletions
46
test/fixtures/mewmew_no_name.json
vendored
Normal file
46
test/fixtures/mewmew_no_name.json
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
{
|
||||
"@context" : [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://princess.cat/schemas/litepub-0.1.jsonld",
|
||||
{
|
||||
"@language" : "und"
|
||||
}
|
||||
],
|
||||
"attachment" : [],
|
||||
"capabilities" : {
|
||||
"acceptsChatMessages" : true
|
||||
},
|
||||
"discoverable" : false,
|
||||
"endpoints" : {
|
||||
"oauthAuthorizationEndpoint" : "https://princess.cat/oauth/authorize",
|
||||
"oauthRegistrationEndpoint" : "https://princess.cat/api/v1/apps",
|
||||
"oauthTokenEndpoint" : "https://princess.cat/oauth/token",
|
||||
"sharedInbox" : "https://princess.cat/inbox",
|
||||
"uploadMedia" : "https://princess.cat/api/ap/upload_media"
|
||||
},
|
||||
"followers" : "https://princess.cat/users/mewmew/followers",
|
||||
"following" : "https://princess.cat/users/mewmew/following",
|
||||
"icon" : {
|
||||
"type" : "Image",
|
||||
"url" : "https://princess.cat/media/12794fb50e86911e65be97f69196814049dcb398a2f8b58b99bb6591576e648c.png?name=blobcatpresentpink.png"
|
||||
},
|
||||
"id" : "https://princess.cat/users/mewmew",
|
||||
"image" : {
|
||||
"type" : "Image",
|
||||
"url" : "https://princess.cat/media/05d8bf3953ab6028fc920494ffc643fbee9dcef40d7bdd06f107e19acbfbd7f9.png"
|
||||
},
|
||||
"inbox" : "https://princess.cat/users/mewmew/inbox",
|
||||
"manuallyApprovesFollowers" : true,
|
||||
"name" : " ",
|
||||
"outbox" : "https://princess.cat/users/mewmew/outbox",
|
||||
"preferredUsername" : "mewmew",
|
||||
"publicKey" : {
|
||||
"id" : "https://princess.cat/users/mewmew#main-key",
|
||||
"owner" : "https://princess.cat/users/mewmew",
|
||||
"publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAru7VpygVef4zrFwnj0Mh\nrbO/2z2EdKN3rERtNrT8zWsLXNLQ50lfpRPnGDrd+xq7Rva4EIu0d5KJJ9n4vtY0\nuxK3On9vA2oyjLlR9O0lI3XTrHJborG3P7IPXrmNUMFpHiFHNqHp5tugUrs1gUFq\n7tmOmM92IP4Wjk8qNHFcsfnUbaPTX7sNIhteQKdi5HrTb/6lrEIe4G/FlMKRqxo3\nRNHuv6SNFQuiUKvFzjzazvjkjvBSm+aFROgdHa2tKl88StpLr7xmuY8qNFCRT6W0\nLacRp6c8ah5f03Kd+xCBVhCKvKaF1K0ERnQTBiitUh85md+Mtx/CoDoLnmpnngR3\nvQIDAQAB\n-----END PUBLIC KEY-----\n\n"
|
||||
},
|
||||
"summary" : "please reply to my posts as direct messages if you have many followers",
|
||||
"tag" : [],
|
||||
"type" : "Person",
|
||||
"url" : "https://princess.cat/users/mewmew"
|
||||
}
|
||||
|
|
@ -388,6 +388,7 @@ defmodule Pleroma.UserTest do
|
|||
}
|
||||
|
||||
setup do: clear_config([:instance, :autofollowed_nicknames])
|
||||
setup do: clear_config([:instance, :autofollowing_nicknames])
|
||||
setup do: clear_config([:welcome])
|
||||
setup do: clear_config([:instance, :account_activation_required])
|
||||
|
||||
|
|
@ -408,6 +409,23 @@ defmodule Pleroma.UserTest do
|
|||
refute User.following?(registered_user, remote_user)
|
||||
end
|
||||
|
||||
test "it adds automatic followers for new registered accounts" do
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
Pleroma.Config.put([:instance, :autofollowing_nicknames], [
|
||||
user1.nickname,
|
||||
user2.nickname
|
||||
])
|
||||
|
||||
cng = User.register_changeset(%User{}, @full_user_data)
|
||||
|
||||
{:ok, registered_user} = User.register(cng)
|
||||
|
||||
assert User.following?(user1, registered_user)
|
||||
assert User.following?(user2, registered_user)
|
||||
end
|
||||
|
||||
test "it sends a welcome message if it is set" do
|
||||
welcome_user = insert(:user)
|
||||
Pleroma.Config.put([:welcome, :direct_message, :enabled], true)
|
||||
|
|
|
|||
|
|
@ -156,21 +156,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert response == "Not found"
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
put_req_header(
|
||||
conn,
|
||||
"accept",
|
||||
"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
|
||||
)
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/users/#{user.nickname}.json", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "mastodon compatibility routes" do
|
||||
|
|
@ -338,18 +323,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert "Not found" == json_response(conn2, :not_found)
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
note = insert(:note)
|
||||
uuid = String.split(note.data["id"], "/") |> List.last()
|
||||
|
||||
conn = put_req_header(conn, "accept", "application/activity+json")
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/objects/#{uuid}", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/activities/:uuid" do
|
||||
|
|
@ -421,18 +394,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert "Not found" == json_response(conn2, :not_found)
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
activity = insert(:note_activity)
|
||||
uuid = String.split(activity.data["id"], "/") |> List.last()
|
||||
|
||||
conn = put_req_header(conn, "accept", "application/activity+json")
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/activities/#{uuid}", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/inbox" do
|
||||
|
|
@ -893,15 +854,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert response(conn, 200) =~ announce_activity.data["object"]
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
conn = put_req_header(conn, "accept", "application/activity+json")
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/users/#{user.nickname}/outbox", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /users/:nickname/outbox (C2S)" do
|
||||
|
|
|
|||
|
|
@ -2273,4 +2273,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert length(activities) == 2
|
||||
end
|
||||
end
|
||||
|
||||
test "allow fetching of accounts with an empty string name field" do
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: :get, url: "https://princess.cat/users/mewmew"} ->
|
||||
file = File.read!("test/fixtures/mewmew_no_name.json")
|
||||
%Tesla.Env{status: 200, body: file}
|
||||
end)
|
||||
|
||||
{:ok, user} = ActivityPub.make_user_from_ap_id("https://princess.cat/users/mewmew")
|
||||
assert user.name == " "
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ defmodule Pleroma.Web.Endpoint.MetricsExporterTest do
|
|||
for metric <- [
|
||||
"http_requests_total",
|
||||
"http_request_duration_microseconds",
|
||||
"phoenix_controller_render_duration",
|
||||
"phoenix_controller_call_duration",
|
||||
"telemetry_scrape_duration",
|
||||
"erlang_vm_memory_atom_bytes_total"
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
import Pleroma.Factory
|
||||
import SweetXml
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.Feed.FeedView
|
||||
|
|
@ -15,7 +16,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
setup do: clear_config([:feed])
|
||||
|
||||
test "gets a feed (ATOM)", %{conn: conn} do
|
||||
Pleroma.Config.put(
|
||||
Config.put(
|
||||
[:feed, :post_title],
|
||||
%{max_length: 25, omission: "..."}
|
||||
)
|
||||
|
|
@ -82,7 +83,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
end
|
||||
|
||||
test "gets a feed (RSS)", %{conn: conn} do
|
||||
Pleroma.Config.put(
|
||||
Config.put(
|
||||
[:feed, :post_title],
|
||||
%{max_length: 25, omission: "..."}
|
||||
)
|
||||
|
|
@ -157,7 +158,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/rss+xml")
|
||||
|> get(tag_feed_path(conn, :feed, "pleromaart"))
|
||||
|> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
|
||||
|> response(200)
|
||||
|
||||
xml = parse(response)
|
||||
|
|
@ -183,14 +184,12 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
end
|
||||
|
||||
describe "private instance" do
|
||||
setup do: clear_config([:instance, :public])
|
||||
setup do: clear_config([:instance, :public], false)
|
||||
|
||||
test "returns 404 for tags feed", %{conn: conn} do
|
||||
Config.put([:instance, :public], false)
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/rss+xml")
|
||||
|> get(tag_feed_path(conn, :feed, "pleromaart"))
|
||||
|> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
|
||||
|> response(404)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
setup do: clear_config([:instance, :federating], true)
|
||||
setup do: clear_config([:static_fe, :enabled], false)
|
||||
|
||||
describe "feed" do
|
||||
setup do: clear_config([:feed])
|
||||
|
|
@ -192,6 +192,16 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
|> get(user_feed_path(conn, :feed, user.nickname))
|
||||
|> response(404)
|
||||
end
|
||||
|
||||
test "does not require authentication on non-federating instances", %{conn: conn} do
|
||||
clear_config([:instance, :federating], false)
|
||||
user = insert(:user)
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/rss+xml")
|
||||
|> get("/users/#{user.nickname}/feed.rss")
|
||||
|> response(200)
|
||||
end
|
||||
end
|
||||
|
||||
# Note: see ActivityPubControllerTest for JSON format tests
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
|
|
@ -21,7 +20,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
setup do: clear_config([:instance, :federating], true)
|
||||
setup do: clear_config([:static_fe, :enabled], false)
|
||||
|
||||
describe "Mastodon compatibility routes" do
|
||||
setup %{conn: conn} do
|
||||
|
|
@ -215,15 +214,16 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
assert response(conn, 404)
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
test "does not require authentication on non-federating instances", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
clear_config([:instance, :federating], false)
|
||||
note_activity = insert(:note_activity)
|
||||
|
||||
conn = put_req_header(conn, "accept", "text/html")
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/notice/#{note_activity.id}", user)
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/notice/#{note_activity.id}")
|
||||
|> response(200)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -325,14 +325,16 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|> response(404)
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
test "does not require authentication on non-federating instances", %{
|
||||
conn: conn,
|
||||
note_activity: note_activity
|
||||
} do
|
||||
user = insert(:user)
|
||||
conn = put_req_header(conn, "accept", "text/html")
|
||||
clear_config([:instance, :federating], false)
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/notice/#{note_activity.id}/embed_player", user)
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/notice/#{note_activity.id}/embed_player")
|
||||
|> response(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
import Mock
|
||||
|
||||
@dir "test/tmp/instance_static"
|
||||
|
||||
|
|
@ -53,4 +54,24 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
|||
index = get(conn, "/pleroma/admin/")
|
||||
assert html_response(index, 200) == "from frontend plug"
|
||||
end
|
||||
|
||||
test "exclude invalid path", %{conn: conn} do
|
||||
name = "pleroma-fe"
|
||||
ref = "dist"
|
||||
clear_config([:media_proxy, :enabled], true)
|
||||
clear_config([Pleroma.Web.Endpoint, :secret_key_base], "00000000000")
|
||||
clear_config([:frontends, :primary], %{"name" => name, "ref" => ref})
|
||||
path = "#{@dir}/frontends/#{name}/#{ref}"
|
||||
|
||||
File.mkdir_p!("#{path}/proxy/rr/ss")
|
||||
File.write!("#{path}/proxy/rr/ss/Ek7w8WPVcAApOvN.jpg:large", "FB image")
|
||||
|
||||
url =
|
||||
Pleroma.Web.MediaProxy.encode_url("https://pbs.twimg.com/media/Ek7w8WPVcAApOvN.jpg:large")
|
||||
|
||||
with_mock Pleroma.ReverseProxy,
|
||||
call: fn _conn, _url, _opts -> %Plug.Conn{status: :success} end do
|
||||
assert %Plug.Conn{status: :success} = get(conn, url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,14 +6,12 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup_all do: clear_config([:static_fe, :enabled], true)
|
||||
setup do: clear_config([:instance, :federating], true)
|
||||
|
||||
setup %{conn: conn} do
|
||||
conn = put_req_header(conn, "accept", "text/html")
|
||||
|
|
@ -74,8 +72,27 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
|||
refute html =~ ">test29<"
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
|
||||
ensure_federating_or_authenticated(conn, "/users/#{user.nickname}", user)
|
||||
test "does not require authentication on non-federating instances", %{
|
||||
conn: conn,
|
||||
user: user
|
||||
} do
|
||||
clear_config([:instance, :federating], false)
|
||||
|
||||
conn = get(conn, "/users/#{user.nickname}")
|
||||
|
||||
assert html_response(conn, 200) =~ user.nickname
|
||||
end
|
||||
|
||||
test "returns 404 for local user with `restrict_unauthenticated/profiles/local` setting", %{
|
||||
conn: conn
|
||||
} do
|
||||
clear_config([:restrict_unauthenticated, :profiles, :local], true)
|
||||
|
||||
local_user = insert(:user, local: true)
|
||||
|
||||
conn
|
||||
|> get("/users/#{local_user.nickname}")
|
||||
|> html_response(404)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -187,10 +204,28 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
|||
assert html_response(conn, 302) =~ "redirected"
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
|
||||
test "does not require authentication on non-federating instances", %{
|
||||
conn: conn,
|
||||
user: user
|
||||
} do
|
||||
clear_config([:instance, :federating], false)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"})
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/notice/#{activity.id}", user)
|
||||
conn = get(conn, "/notice/#{activity.id}")
|
||||
|
||||
assert html_response(conn, 200) =~ "testing a thing!"
|
||||
end
|
||||
|
||||
test "returns 404 for local public activity with `restrict_unauthenticated/activities/local` setting",
|
||||
%{conn: conn, user: user} do
|
||||
clear_config([:restrict_unauthenticated, :activities, :local], true)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"})
|
||||
|
||||
conn
|
||||
|> get("/notice/#{activity.id}")
|
||||
|> html_response(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -112,28 +112,6 @@ defmodule Pleroma.Web.ConnCase do
|
|||
defp json_response_and_validate_schema(conn, _status) do
|
||||
flunk("Response schema not found for #{conn.method} #{conn.request_path} #{conn.status}")
|
||||
end
|
||||
|
||||
defp ensure_federating_or_authenticated(conn, url, user) do
|
||||
initial_setting = Config.get([:instance, :federating])
|
||||
on_exit(fn -> Config.put([:instance, :federating], initial_setting) end)
|
||||
|
||||
Config.put([:instance, :federating], false)
|
||||
|
||||
conn
|
||||
|> get(url)
|
||||
|> response(403)
|
||||
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get(url)
|
||||
|> response(200)
|
||||
|
||||
Config.put([:instance, :federating], true)
|
||||
|
||||
conn
|
||||
|> get(url)
|
||||
|> response(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue