aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/mastodon-post-activity-nsfw.json68
-rw-r--r--test/fixtures/mewmew_no_name.json46
-rw-r--r--test/pleroma/notification_test.exs2
-rw-r--r--test/pleroma/user_test.exs18
-rw-r--r--test/pleroma/web/activity_pub/activity_pub_controller_test.exs48
-rw-r--r--test/pleroma/web/activity_pub/activity_pub_test.exs19
-rw-r--r--test/pleroma/web/activity_pub/mrf/reject_non_public_test.exs8
-rw-r--r--test/pleroma/web/activity_pub/mrf/tag_policy_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier_test.exs12
-rw-r--r--test/pleroma/web/common_api_test.exs16
-rw-r--r--test/pleroma/web/endpoint/metrics_exporter_test.exs68
-rw-r--r--test/pleroma/web/fed_sockets/fed_registry_test.exs4
-rw-r--r--test/pleroma/web/feed/tag_controller_test.exs13
-rw-r--r--test/pleroma/web/feed/user_controller_test.exs12
-rw-r--r--test/pleroma/web/mastodon_api/controllers/account_controller_test.exs8
-rw-r--r--test/pleroma/web/mastodon_api/controllers/status_controller_test.exs2
-rw-r--r--test/pleroma/web/o_auth/o_auth_controller_test.exs14
-rw-r--r--test/pleroma/web/o_status/o_status_controller_test.exs24
-rw-r--r--test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs2
-rw-r--r--test/pleroma/web/pleroma_api/controllers/mascot_controller_test.exs2
-rw-r--r--test/pleroma/web/plugs/frontend_static_plug_test.exs21
-rw-r--r--test/pleroma/web/static_fe/static_fe_controller_test.exs47
-rw-r--r--test/support/channel_case.ex2
-rw-r--r--test/support/conn_case.ex25
25 files changed, 359 insertions, 126 deletions
diff --git a/test/fixtures/mastodon-post-activity-nsfw.json b/test/fixtures/mastodon-post-activity-nsfw.json
new file mode 100644
index 000000000..70729a1bd
--- /dev/null
+++ b/test/fixtures/mastodon-post-activity-nsfw.json
@@ -0,0 +1,68 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ {
+ "Emoji": "toot:Emoji",
+ "Hashtag": "as:Hashtag",
+ "atomUri": "ostatus:atomUri",
+ "conversation": "ostatus:conversation",
+ "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+ "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+ "movedTo": "as:movedTo",
+ "ostatus": "http://ostatus.org#",
+ "toot": "http://joinmastodon.org/ns#"
+ }
+ ],
+ "actor": "http://mastodon.example.org/users/admin",
+ "cc": [
+ "http://mastodon.example.org/users/admin/followers",
+ "http://localtesting.pleroma.lol/users/lain"
+ ],
+ "id": "http://mastodon.example.org/users/admin/statuses/99512778738411822/activity",
+ "nickname": "lain",
+ "object": {
+ "atomUri": "http://mastodon.example.org/users/admin/statuses/99512778738411822",
+ "attachment": [],
+ "attributedTo": "http://mastodon.example.org/users/admin",
+ "cc": [
+ "http://mastodon.example.org/users/admin/followers",
+ "http://localtesting.pleroma.lol/users/lain"
+ ],
+ "content": "<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span> #moo</p>",
+ "conversation": "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation",
+ "id": "http://mastodon.example.org/users/admin/statuses/99512778738411822",
+ "inReplyTo": null,
+ "inReplyToAtomUri": null,
+ "published": "2018-02-12T14:08:20Z",
+ "summary": "cw",
+ "tag": [
+ {
+ "href": "http://localtesting.pleroma.lol/users/lain",
+ "name": "@lain@localtesting.pleroma.lol",
+ "type": "Mention"
+ },
+ {
+ "href": "http://mastodon.example.org/tags/nsfw",
+ "name": "#NSFW",
+ "type": "Hashtag"
+ }
+ ],
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "type": "Note",
+ "url": "http://mastodon.example.org/@admin/99512778738411822"
+ },
+ "published": "2018-02-12T14:08:20Z",
+ "signature": {
+ "created": "2018-02-12T14:08:20Z",
+ "creator": "http://mastodon.example.org/users/admin#main-key",
+ "signatureValue": "rnNfcopkc6+Ju73P806popcfwrK9wGYHaJVG1/ZvrlEbWVDzaHjkXqj9Q3/xju5l8CSn9tvSgCCtPFqZsFQwn/pFIFUcw7ZWB2xi4bDm3NZ3S4XQ8JRaaX7og5hFxAhWkGhJhAkfxVnOg2hG+w2d/7d7vRVSC1vo5ip4erUaA/PkWusZvPIpxnRWoXaxJsFmVx0gJgjpJkYDyjaXUlp+jmaoseeZ4EPQUWqHLKJ59PRG0mg8j2xAjYH9nQaN14qMRmTGPxY8gfv/CUFcatA+8VJU9KEsJkDAwLVvglydNTLGrxpAJU78a2eaht0foV43XUIZGe3DKiJPgE+UOKGCJw==",
+ "type": "RsaSignature2017"
+ },
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "type": "Create"
+}
diff --git a/test/fixtures/mewmew_no_name.json b/test/fixtures/mewmew_no_name.json
new file mode 100644
index 000000000..532d4cf70
--- /dev/null
+++ b/test/fixtures/mewmew_no_name.json
@@ -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"
+}
diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs
index 0e9630f28..a74fb7bc2 100644
--- a/test/pleroma/notification_test.exs
+++ b/test/pleroma/notification_test.exs
@@ -400,7 +400,7 @@ defmodule Pleroma.NotificationTest do
user = insert(:user, is_locked: true)
follower = insert(:user)
{:ok, _, _, _follow_activity} = CommonAPI.follow(follower, user)
- assert [notification] = Notification.for_user(user)
+ assert [_notification] = Notification.for_user(user)
{:ok, _follower} = CommonAPI.reject_follow_request(follower, user)
assert [] = Notification.for_user(user)
end
diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs
index 7220ce846..9ae52d594 100644
--- a/test/pleroma/user_test.exs
+++ b/test/pleroma/user_test.exs
@@ -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)
diff --git a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs
index b11e2f961..b696a24f4 100644
--- a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs
@@ -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
diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs
index e6b6086e6..43bd14ee6 100644
--- a/test/pleroma/web/activity_pub/activity_pub_test.exs
+++ b/test/pleroma/web/activity_pub/activity_pub_test.exs
@@ -505,22 +505,22 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
# public
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, :visibility, "public"))
- assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
+ assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
assert object.data["repliesCount"] == 1
# unlisted
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, :visibility, "unlisted"))
- assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
+ assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
assert object.data["repliesCount"] == 2
# private
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, :visibility, "private"))
- assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
+ assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
assert object.data["repliesCount"] == 2
# direct
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, :visibility, "direct"))
- assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
+ assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
assert object.data["repliesCount"] == 2
end
end
@@ -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
diff --git a/test/pleroma/web/activity_pub/mrf/reject_non_public_test.exs b/test/pleroma/web/activity_pub/mrf/reject_non_public_test.exs
index 58b46b9a2..e08eb3ba6 100644
--- a/test/pleroma/web/activity_pub/mrf/reject_non_public_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/reject_non_public_test.exs
@@ -21,7 +21,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
"type" => "Create"
}
- assert {:ok, message} = RejectNonPublic.filter(message)
+ assert {:ok, _message} = RejectNonPublic.filter(message)
end
test "it's allowed when cc address contain public address" do
@@ -34,7 +34,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
"type" => "Create"
}
- assert {:ok, message} = RejectNonPublic.filter(message)
+ assert {:ok, _message} = RejectNonPublic.filter(message)
end
end
@@ -50,7 +50,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
}
Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], true)
- assert {:ok, message} = RejectNonPublic.filter(message)
+ assert {:ok, _message} = RejectNonPublic.filter(message)
end
test "it's rejected when addrer of message in the follower addresses of user and it disabled in config" do
@@ -80,7 +80,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
}
Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], true)
- assert {:ok, message} = RejectNonPublic.filter(message)
+ assert {:ok, _message} = RejectNonPublic.filter(message)
end
test "it's reject when direct messages aren't allow" do
diff --git a/test/pleroma/web/activity_pub/mrf/tag_policy_test.exs b/test/pleroma/web/activity_pub/mrf/tag_policy_test.exs
index 6ff71d640..ffc30ba62 100644
--- a/test/pleroma/web/activity_pub/mrf/tag_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/tag_policy_test.exs
@@ -29,7 +29,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do
actor = insert(:user, tags: ["mrf_tag:disable-remote-subscription"])
follower = insert(:user, tags: ["mrf_tag:disable-remote-subscription"], local: true)
message = %{"object" => actor.ap_id, "type" => "Follow", "actor" => follower.ap_id}
- assert {:ok, message} = TagPolicy.filter(message)
+ assert {:ok, _message} = TagPolicy.filter(message)
end
end
diff --git a/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs
index e895636b5..54335acdb 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs
@@ -144,7 +144,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do
_user = insert(:user, local: false, ap_id: data["actor"])
- assert {:error, e} = Transmogrifier.handle_incoming(data)
+ assert {:error, _e} = Transmogrifier.handle_incoming(data)
end
test "it does not clobber the addressing on announce activities" do
diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs
index 561674f01..e39af1dfc 100644
--- a/test/pleroma/web/activity_pub/transmogrifier_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs
@@ -101,7 +101,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
returned_object = Object.normalize(returned_activity, false)
- assert activity =
+ assert %Activity{} =
Activity.get_create_by_object_ap_id(
"https://mstdn.io/users/mayuutann/statuses/99568293732299394"
)
@@ -206,6 +206,16 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert user.note_count == 1
end
+ test "it works for incoming notices without the sensitive property but an nsfw hashtag" do
+ data = File.read!("test/fixtures/mastodon-post-activity-nsfw.json") |> Poison.decode!()
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+
+ object_data = Object.normalize(data["object"], false).data
+
+ assert object_data["sensitive"] == true
+ end
+
test "it works for incoming notices with hashtags" do
data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Poison.decode!()
diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs
index f5d09f396..c5b90ad84 100644
--- a/test/pleroma/web/common_api_test.exs
+++ b/test/pleroma/web/common_api_test.exs
@@ -95,6 +95,20 @@ defmodule Pleroma.Web.CommonAPITest do
describe "posting chat messages" do
setup do: clear_config([:instance, :chat_limit])
+ test "it posts a self-chat" do
+ author = insert(:user)
+ recipient = author
+
+ {:ok, activity} =
+ CommonAPI.post_chat_message(
+ author,
+ recipient,
+ "remember to buy milk when milk truk arive"
+ )
+
+ assert activity.data["type"] == "Create"
+ end
+
test "it posts a chat message without content but with an attachment" do
author = insert(:user)
recipient = insert(:user)
@@ -622,7 +636,7 @@ defmodule Pleroma.Web.CommonAPITest do
assert {:error, "The status is over the character limit"} =
CommonAPI.post(user, %{status: "foobar"})
- assert {:ok, activity} = CommonAPI.post(user, %{status: "12345"})
+ assert {:ok, _activity} = CommonAPI.post(user, %{status: "12345"})
end
test "it can handle activities that expire" do
diff --git a/test/pleroma/web/endpoint/metrics_exporter_test.exs b/test/pleroma/web/endpoint/metrics_exporter_test.exs
new file mode 100644
index 000000000..875addc96
--- /dev/null
+++ b/test/pleroma/web/endpoint/metrics_exporter_test.exs
@@ -0,0 +1,68 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Endpoint.MetricsExporterTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Web.Endpoint.MetricsExporter
+
+ defp config do
+ Application.get_env(:prometheus, MetricsExporter)
+ end
+
+ describe "with default config" do
+ test "does NOT expose app metrics", %{conn: conn} do
+ conn
+ |> get(config()[:path])
+ |> json_response(404)
+ end
+ end
+
+ describe "when enabled" do
+ setup do
+ initial_config = config()
+ on_exit(fn -> Application.put_env(:prometheus, MetricsExporter, initial_config) end)
+
+ Application.put_env(
+ :prometheus,
+ MetricsExporter,
+ Keyword.put(initial_config, :enabled, true)
+ )
+ end
+
+ test "serves app metrics", %{conn: conn} do
+ conn = get(conn, config()[:path])
+ assert response = response(conn, 200)
+
+ for metric <- [
+ "http_requests_total",
+ "http_request_duration_microseconds",
+ "phoenix_controller_call_duration",
+ "telemetry_scrape_duration",
+ "erlang_vm_memory_atom_bytes_total"
+ ] do
+ assert response =~ ~r/#{metric}/
+ end
+ end
+
+ test "when IP whitelist configured, " <>
+ "serves app metrics only if client IP is whitelisted",
+ %{conn: conn} do
+ Application.put_env(
+ :prometheus,
+ MetricsExporter,
+ Keyword.put(config(), :ip_whitelist, ["127.127.127.127", {1, 1, 1, 1}, '255.255.255.255'])
+ )
+
+ conn
+ |> get(config()[:path])
+ |> json_response(404)
+
+ conn
+ |> Map.put(:remote_ip, {127, 127, 127, 127})
+ |> get(config()[:path])
+ |> response(200)
+ end
+ end
+end
diff --git a/test/pleroma/web/fed_sockets/fed_registry_test.exs b/test/pleroma/web/fed_sockets/fed_registry_test.exs
index 19ac874d6..73aaced46 100644
--- a/test/pleroma/web/fed_sockets/fed_registry_test.exs
+++ b/test/pleroma/web/fed_sockets/fed_registry_test.exs
@@ -52,7 +52,7 @@ defmodule Pleroma.Web.FedSockets.FedRegistryTest do
end
test "will be ignored" do
- assert {:ok, %SocketInfo{origin: origin, pid: pid_one}} =
+ assert {:ok, %SocketInfo{origin: origin, pid: _pid_one}} =
FedRegistry.get_fed_socket(@good_domain_origin)
assert origin == "good.domain:80"
@@ -63,7 +63,7 @@ defmodule Pleroma.Web.FedSockets.FedRegistryTest do
test "the newer process will be closed" do
pid_two = build_test_socket(@good_domain)
- assert {:ok, %SocketInfo{origin: origin, pid: pid_one}} =
+ assert {:ok, %SocketInfo{origin: origin, pid: _pid_one}} =
FedRegistry.get_fed_socket(@good_domain_origin)
assert origin == "good.domain:80"
diff --git a/test/pleroma/web/feed/tag_controller_test.exs b/test/pleroma/web/feed/tag_controller_test.exs
index 868e40965..e4084b0e5 100644
--- a/test/pleroma/web/feed/tag_controller_test.exs
+++ b/test/pleroma/web/feed/tag_controller_test.exs
@@ -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
diff --git a/test/pleroma/web/feed/user_controller_test.exs b/test/pleroma/web/feed/user_controller_test.exs
index a5dc0894b..eabfe3a63 100644
--- a/test/pleroma/web/feed/user_controller_test.exs
+++ b/test/pleroma/web/feed/user_controller_test.exs
@@ -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
diff --git a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
index c86223b26..58ce76ab8 100644
--- a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
@@ -32,7 +32,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
test "works by nickname" do
user = insert(:user)
- assert %{"id" => user_id} =
+ assert %{"id" => _user_id} =
build_conn()
|> get("/api/v1/accounts/#{user.nickname}")
|> json_response_and_validate_schema(200)
@@ -43,7 +43,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
user = insert(:user, nickname: "user@example.com", local: false)
- assert %{"id" => user_id} =
+ assert %{"id" => _user_id} =
build_conn()
|> get("/api/v1/accounts/#{user.nickname}")
|> json_response_and_validate_schema(200)
@@ -1429,10 +1429,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
test "returns lists to which the account belongs" do
%{user: user, conn: conn} = oauth_access(["read:lists"])
other_user = insert(:user)
- assert {:ok, %Pleroma.List{id: list_id} = list} = Pleroma.List.create("Test List", user)
+ assert {:ok, %Pleroma.List{id: _list_id} = list} = Pleroma.List.create("Test List", user)
{:ok, %{following: _following}} = Pleroma.List.follow(list, other_user)
- assert [%{"id" => list_id, "title" => "Test List"}] =
+ assert [%{"id" => _list_id, "title" => "Test List"}] =
conn
|> get("/api/v1/accounts/#{other_user.id}/lists")
|> json_response_and_validate_schema(200)
diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
index 61359214a..436608e51 100644
--- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
@@ -937,7 +937,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|> get("/api/v1/statuses/#{reblog_activity1.id}")
assert %{
- "reblog" => %{"id" => id, "reblogged" => false, "reblogs_count" => 2},
+ "reblog" => %{"id" => _id, "reblogged" => false, "reblogs_count" => 2},
"reblogged" => false,
"favourited" => false,
"bookmarked" => false
diff --git a/test/pleroma/web/o_auth/o_auth_controller_test.exs b/test/pleroma/web/o_auth/o_auth_controller_test.exs
index 1200126b8..a00df8cc7 100644
--- a/test/pleroma/web/o_auth/o_auth_controller_test.exs
+++ b/test/pleroma/web/o_auth/o_auth_controller_test.exs
@@ -77,7 +77,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
}
)
- assert response = html_response(conn, 302)
+ assert html_response(conn, 302)
redirect_query = URI.parse(redirected_to(conn)).query
assert %{"state" => state_param} = URI.decode_query(redirect_query)
@@ -119,7 +119,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
}
)
- assert response = html_response(conn, 302)
+ assert html_response(conn, 302)
assert redirected_to(conn) =~ ~r/#{redirect_uri}\?code=.+/
end
@@ -182,7 +182,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
}
)
- assert response = html_response(conn, 302)
+ assert html_response(conn, 302)
assert redirected_to(conn) == app.redirect_uris
assert get_flash(conn, :error) == "Failed to authenticate: (error description)."
end
@@ -238,7 +238,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
}
)
- assert response = html_response(conn, 302)
+ assert html_response(conn, 302)
assert redirected_to(conn) =~ ~r/#{redirect_uri}\?code=.+/
end
@@ -268,7 +268,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
}
)
- assert response = html_response(conn, 401)
+ assert html_response(conn, 401)
end
test "with invalid params, POST /oauth/register?op=register renders registration_details page",
@@ -336,7 +336,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
}
)
- assert response = html_response(conn, 302)
+ assert html_response(conn, 302)
assert redirected_to(conn) =~ ~r/#{redirect_uri}\?code=.+/
end
@@ -367,7 +367,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
}
)
- assert response = html_response(conn, 401)
+ assert html_response(conn, 401)
end
test "with invalid params, POST /oauth/register?op=connect renders registration_details page",
diff --git a/test/pleroma/web/o_status/o_status_controller_test.exs b/test/pleroma/web/o_status/o_status_controller_test.exs
index ee498f4b5..65b2c22db 100644
--- a/test/pleroma/web/o_status/o_status_controller_test.exs
+++ b/test/pleroma/web/o_status/o_status_controller_test.exs
@@ -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
diff --git a/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs
index 386ad8634..3445f0ca0 100644
--- a/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs
@@ -569,7 +569,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
test "for pack name with special chars", %{conn: conn} do
assert %{
- "files" => files,
+ "files" => _files,
"files_count" => 1,
"pack" => %{
"can-download" => true,
diff --git a/test/pleroma/web/pleroma_api/controllers/mascot_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/mascot_controller_test.exs
index d6be92869..289119d45 100644
--- a/test/pleroma/web/pleroma_api/controllers/mascot_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/mascot_controller_test.exs
@@ -34,7 +34,7 @@ defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
|> put_req_header("content-type", "multipart/form-data")
|> put("/api/v1/pleroma/mascot", %{"file" => file})
- assert %{"id" => _, "type" => image} = json_response_and_validate_schema(conn, 200)
+ assert %{"id" => _, "type" => _image} = json_response_and_validate_schema(conn, 200)
end
test "mascot retrieving" do
diff --git a/test/pleroma/web/plugs/frontend_static_plug_test.exs b/test/pleroma/web/plugs/frontend_static_plug_test.exs
index f6f7d7bdb..8b7b022fc 100644
--- a/test/pleroma/web/plugs/frontend_static_plug_test.exs
+++ b/test/pleroma/web/plugs/frontend_static_plug_test.exs
@@ -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
diff --git a/test/pleroma/web/static_fe/static_fe_controller_test.exs b/test/pleroma/web/static_fe/static_fe_controller_test.exs
index f819a1e52..19506f1d8 100644
--- a/test/pleroma/web/static_fe/static_fe_controller_test.exs
+++ b/test/pleroma/web/static_fe/static_fe_controller_test.exs
@@ -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!"})
+
+ 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!"})
- ensure_federating_or_authenticated(conn, "/notice/#{activity.id}", user)
+ conn
+ |> get("/notice/#{activity.id}")
+ |> html_response(404)
end
end
end
diff --git a/test/support/channel_case.ex b/test/support/channel_case.ex
index d63a0f06b..114184a9f 100644
--- a/test/support/channel_case.ex
+++ b/test/support/channel_case.ex
@@ -22,7 +22,7 @@ defmodule Pleroma.Web.ChannelCase do
using do
quote do
# Import conveniences for testing with channels
- use Phoenix.ChannelTest
+ import Phoenix.ChannelTest
use Pleroma.Tests.Helpers
# The default endpoint for testing
diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex
index 7ef681258..47cb65a80 100644
--- a/test/support/conn_case.ex
+++ b/test/support/conn_case.ex
@@ -22,7 +22,8 @@ defmodule Pleroma.Web.ConnCase do
using do
quote do
# Import conveniences for testing with connections
- use Phoenix.ConnTest
+ import Plug.Conn
+ import Phoenix.ConnTest
use Pleroma.Tests.Helpers
import Pleroma.Web.Router.Helpers
@@ -111,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