summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/config/temp.secret.exs2
-rw-r--r--test/fixtures/tesla_mock/framatube.org_host_meta2
-rw-r--r--test/fixtures/tesla_mock/status.alpicola.com_host_meta2
-rw-r--r--test/fixtures/webfinger/masto-host-meta.xml4
-rw-r--r--test/fixtures/webfinger/masto-user.json92
-rw-r--r--test/fixtures/webfinger/masto-webfinger.json23
-rw-r--r--test/fixtures/webfinger/pleroma-host-meta.xml1
-rw-r--r--test/fixtures/webfinger/pleroma-user.json58
-rw-r--r--test/fixtures/webfinger/pleroma-webfinger.json27
-rw-r--r--test/mix/tasks/pleroma/config_test.exs8
-rw-r--r--test/pleroma/activity_test.exs1
-rw-r--r--test/pleroma/config/loader_test.exs1
-rw-r--r--test/pleroma/config/transfer_task_test.exs22
-rw-r--r--test/pleroma/config_db_test.exs18
-rw-r--r--test/pleroma/html_test.exs26
-rw-r--r--test/pleroma/object/fetcher_test.exs12
-rw-r--r--test/pleroma/resilience_test.exs103
-rw-r--r--test/pleroma/user_test.exs132
-rw-r--r--test/pleroma/web/activity_pub/activity_pub_test.exs10
-rw-r--r--test/pleroma/web/activity_pub/mrf/simple_policy_test.exs22
-rw-r--r--test/pleroma/web/activity_pub/mrf/tag_policy_test.exs36
-rw-r--r--test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs13
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/utils_test.exs47
-rw-r--r--test/pleroma/web/admin_api/controllers/chat_controller_test.exs2
-rw-r--r--test/pleroma/web/admin_api/controllers/config_controller_test.exs60
-rw-r--r--test/pleroma/web/admin_api/controllers/report_controller_test.exs26
-rw-r--r--test/pleroma/web/common_api_test.exs36
-rw-r--r--test/pleroma/web/feed/tag_controller_test.exs5
-rw-r--r--test/pleroma/web/feed/user_controller_test.exs8
-rw-r--r--test/pleroma/web/mastodon_api/controllers/account_controller_test.exs40
-rw-r--r--test/pleroma/web/mastodon_api/controllers/report_controller_test.exs37
-rw-r--r--test/pleroma/web/mastodon_api/controllers/search_controller_test.exs1
-rw-r--r--test/pleroma/web/mastodon_api/controllers/status_controller_test.exs37
-rw-r--r--test/pleroma/web/mastodon_api/update_credentials_test.exs82
-rw-r--r--test/pleroma/web/metadata/providers/twitter_card_test.exs56
-rw-r--r--test/pleroma/web/plugs/http_security_plug_test.exs4
-rw-r--r--test/pleroma/web/push/impl_test.exs15
-rw-r--r--test/pleroma/web/twitter_api/remote_follow_controller_test.exs2
-rw-r--r--test/pleroma/web/web_finger/web_finger_controller_test.exs29
-rw-r--r--test/pleroma/web/web_finger_test.exs8
-rw-r--r--test/pleroma/workers/publisher_worker_test.exs40
-rw-r--r--test/support/http_request_mock.ex20
43 files changed, 1008 insertions, 164 deletions
diff --git a/test/fixtures/config/temp.secret.exs b/test/fixtures/config/temp.secret.exs
index d4140d0c4..e5709ba6f 100644
--- a/test/fixtures/config/temp.secret.exs
+++ b/test/fixtures/config/temp.secret.exs
@@ -8,8 +8,6 @@ config :pleroma, :first_setting, key: "value", key2: [Pleroma.Repo]
config :pleroma, :second_setting, key: "value2", key2: ["Activity"]
-config :quack, level: :info
-
config :pleroma, Pleroma.Repo, pool: Ecto.Adapters.SQL.Sandbox
config :postgrex, :json_library, Poison
diff --git a/test/fixtures/tesla_mock/framatube.org_host_meta b/test/fixtures/tesla_mock/framatube.org_host_meta
index 91516ff6d..02e25bd64 100644
--- a/test/fixtures/tesla_mock/framatube.org_host_meta
+++ b/test/fixtures/tesla_mock/framatube.org_host_meta
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
-<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><hm:Host xmlns:hm="http://host-meta.net/xrd/1.0">framatube.org</hm:Host><Link rel="lrdd" template="http://framatube.org/main/xrd?uri={uri}"><Title>Resource Descriptor</Title></Link></XRD>
+<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><hm:Host xmlns:hm="http://host-meta.net/xrd/1.0">framatube.org</hm:Host><Link rel="lrdd" template="https://framatube.org/main/xrd?uri={uri}"><Title>Resource Descriptor</Title></Link></XRD>
diff --git a/test/fixtures/tesla_mock/status.alpicola.com_host_meta b/test/fixtures/tesla_mock/status.alpicola.com_host_meta
index 6948c30ea..78155f644 100644
--- a/test/fixtures/tesla_mock/status.alpicola.com_host_meta
+++ b/test/fixtures/tesla_mock/status.alpicola.com_host_meta
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
-<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><hm:Host xmlns:hm="http://host-meta.net/xrd/1.0">status.alpicola.com</hm:Host><Link rel="lrdd" template="http://status.alpicola.com/main/xrd?uri={uri}"><Title>Resource Descriptor</Title></Link></XRD> \ No newline at end of file
+<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><hm:Host xmlns:hm="http://host-meta.net/xrd/1.0">status.alpicola.com</hm:Host><Link rel="lrdd" template="https://status.alpicola.com/main/xrd?uri={uri}"><Title>Resource Descriptor</Title></Link></XRD>
diff --git a/test/fixtures/webfinger/masto-host-meta.xml b/test/fixtures/webfinger/masto-host-meta.xml
new file mode 100644
index 000000000..f432a27c3
--- /dev/null
+++ b/test/fixtures/webfinger/masto-host-meta.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
+ <Link rel="lrdd" template="https://{{domain}}/.well-known/webfinger?resource={uri}"/>
+</XRD>
diff --git a/test/fixtures/webfinger/masto-user.json b/test/fixtures/webfinger/masto-user.json
new file mode 100644
index 000000000..1702de011
--- /dev/null
+++ b/test/fixtures/webfinger/masto-user.json
@@ -0,0 +1,92 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ {
+ "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+ "toot": "http://joinmastodon.org/ns#",
+ "featured": {
+ "@id": "toot:featured",
+ "@type": "@id"
+ },
+ "featuredTags": {
+ "@id": "toot:featuredTags",
+ "@type": "@id"
+ },
+ "alsoKnownAs": {
+ "@id": "as:alsoKnownAs",
+ "@type": "@id"
+ },
+ "movedTo": {
+ "@id": "as:movedTo",
+ "@type": "@id"
+ },
+ "schema": "http://schema.org#",
+ "PropertyValue": "schema:PropertyValue",
+ "value": "schema:value",
+ "IdentityProof": "toot:IdentityProof",
+ "discoverable": "toot:discoverable",
+ "Device": "toot:Device",
+ "Ed25519Signature": "toot:Ed25519Signature",
+ "Ed25519Key": "toot:Ed25519Key",
+ "Curve25519Key": "toot:Curve25519Key",
+ "EncryptedMessage": "toot:EncryptedMessage",
+ "publicKeyBase64": "toot:publicKeyBase64",
+ "deviceId": "toot:deviceId",
+ "claim": {
+ "@type": "@id",
+ "@id": "toot:claim"
+ },
+ "fingerprintKey": {
+ "@type": "@id",
+ "@id": "toot:fingerprintKey"
+ },
+ "identityKey": {
+ "@type": "@id",
+ "@id": "toot:identityKey"
+ },
+ "devices": {
+ "@type": "@id",
+ "@id": "toot:devices"
+ },
+ "messageFranking": "toot:messageFranking",
+ "messageType": "toot:messageType",
+ "cipherText": "toot:cipherText",
+ "suspended": "toot:suspended",
+ "focalPoint": {
+ "@container": "@list",
+ "@id": "toot:focalPoint"
+ }
+ }
+ ],
+ "id": "https://{{domain}}/users/{{nickname}}",
+ "type": "Person",
+ "following": "https://{{domain}}/users/{{nickname}}/following",
+ "followers": "https://{{domain}}/users/{{nickname}}/followers",
+ "inbox": "https://{{domain}}/users/{{nickname}}/inbox",
+ "outbox": "https://{{domain}}/users/{{nickname}}/outbox",
+ "featured": "https://{{domain}}/users/{{nickname}}/collections/featured",
+ "featuredTags": "https://{{domain}}/users/{{nickname}}/collections/tags",
+ "preferredUsername": "{{nickname}}",
+ "name": "Name Name",
+ "summary": "<p>Summary</p>",
+ "url": "https://{{domain}}/@{{nickname}}",
+ "manuallyApprovesFollowers": false,
+ "discoverable": false,
+ "devices": "https://{{domain}}/users/{{nickname}}/collections/devices",
+ "publicKey": {
+ "id": "https://{{domain}}/users/{{nickname}}#main-key",
+ "owner": "https://{{domain}}/users/{{nickname}}",
+ "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvwDujxmxoYHs64MyVB3L\nG5ZyBxV3ufaMRBFu42bkcTpISq1WwZ+3Zb6CI8zOO+nM+Q2llrVRYjZa4ZFnOLvM\nTq/Kf+Zf5wy2aCRer88gX+MsJOAtItSi412y0a/rKOuFaDYLOLeTkRvmGLgZWbsr\nZJOp+YWb3zQ5qsIOInkc5BwI172tMsGeFtsnbNApPV4lrmtTGaJ8RiM8MR7XANBO\nfOHggSt1+eAIKGIsCmINEMzs1mG9D75xKtC/sM8GfbvBclQcBstGkHAEj1VHPW0c\nh6Bok5/QQppicyb8UA1PAA9bznSFtKlYE4xCH8rlCDSDTBRtdnBWHKcj619Ujz4Q\nawIDAQAB\n-----END PUBLIC KEY-----\n"
+ },
+ "tag": [],
+ "attachment": [],
+ "endpoints": {
+ "sharedInbox": "https://{{domain}}/inbox"
+ },
+ "icon": {
+ "type": "Image",
+ "mediaType": "image/jpeg",
+ "url": "https://s3.wasabisys.com/merp/accounts/avatars/000/000/001/original/6fdd3eee632af247.jpg"
+ }
+}
diff --git a/test/fixtures/webfinger/masto-webfinger.json b/test/fixtures/webfinger/masto-webfinger.json
new file mode 100644
index 000000000..561be3fff
--- /dev/null
+++ b/test/fixtures/webfinger/masto-webfinger.json
@@ -0,0 +1,23 @@
+{
+ "subject": "acct:{{nickname}}@{{domain}}",
+ "aliases": [
+ "https://{{subdomain}}/@{{nickname}}",
+ "https://{{subdomain}}/users/{{nickname}}"
+ ],
+ "links": [
+ {
+ "rel": "http://webfinger.net/rel/profile-page",
+ "type": "text/html",
+ "href": "https://{{subdomain}}/@{{nickname}}"
+ },
+ {
+ "rel": "self",
+ "type": "application/activity+json",
+ "href": "https://{{subdomain}}/users/{{nickname}}"
+ },
+ {
+ "rel": "http://ostatus.org/schema/1.0/subscribe",
+ "template": "https://{{subdomain}}/authorize_interaction?uri={uri}"
+ }
+ ]
+}
diff --git a/test/fixtures/webfinger/pleroma-host-meta.xml b/test/fixtures/webfinger/pleroma-host-meta.xml
new file mode 100644
index 000000000..88c274a1a
--- /dev/null
+++ b/test/fixtures/webfinger/pleroma-host-meta.xml
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" template="https://{{domain}}/.well-known/webfinger?resource={uri}" type="application/xrd+xml" /></XRD>
diff --git a/test/fixtures/webfinger/pleroma-user.json b/test/fixtures/webfinger/pleroma-user.json
new file mode 100644
index 000000000..b822db46c
--- /dev/null
+++ b/test/fixtures/webfinger/pleroma-user.json
@@ -0,0 +1,58 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://{{domain}}/schemas/litepub-0.1.jsonld",
+ {
+ "@language": "und"
+ }
+ ],
+ "alsoKnownAs": [],
+ "attachment": [],
+ "capabilities": {
+ "acceptsChatMessages": true
+ },
+ "discoverable": true,
+ "endpoints": {
+ "oauthAuthorizationEndpoint": "https://{{domain}}/oauth/authorize",
+ "oauthRegistrationEndpoint": "https://{{domain}}/api/v1/apps",
+ "oauthTokenEndpoint": "https://{{domain}}/oauth/token",
+ "sharedInbox": "https://{{domain}}/inbox",
+ "uploadMedia": "https://{{domain}}/api/ap/upload_media"
+ },
+ "followers": "https://{{domain}}/users/{{nickname}}/followers",
+ "following": "https://{{domain}}/users/{{nickname}}/following",
+ "icon": {
+ "type": "Image",
+ "url": "https://{{domain}}/media/a932a27f158b63c3a97e3a57d5384f714a82249274c6fc66c9eca581b4fd8af2.jpg"
+ },
+ "id": "https://{{domain}}/users/{{nickname}}",
+ "image": {
+ "type": "Image",
+ "url": "https://{{domain}}/media/db15f476d0ad14488db4762b7800479e6ef67b1824f8b9ea5c1fa05b7525c5b7.jpg"
+ },
+ "inbox": "https://{{domain}}/users/{{nickname}}/inbox",
+ "manuallyApprovesFollowers": false,
+ "name": "{{nickname}} :verified:",
+ "outbox": "https://{{domain}}/users/{{nickname}}/outbox",
+ "preferredUsername": "{{nickname}}",
+ "publicKey": {
+ "id": "https://{{domain}}/users/{{nickname}}#main-key",
+ "owner": "https://{{domain}}/users/{{nickname}}",
+ "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu4XOAopC4nRIxNlHlt60\n//nCicuedu5wvLGIoQ+KUM2u7/PhLrrTDEqr1A7yQL95S0X8ryYtALgFLI5A54ww\nqjMIbIGAs44lEmDLMEd+XI+XxREE8wdsFpb4QQzWug0DTyqlMouTU25k0tfKh1rF\n4PMJ3uBSjDTAGgFvLNyFWTiVVgChbTNgGOmrEBucRl4NmKzQ69/FIUwENV88oQSU\n3bWvQTEH9rWH1rCLpkmQwdRiWfnhFX/4EUqXukfgoskvenKR8ff3nYhElDqFoE0e\nqUnIW1OZceyl8JewVLcL6m0/wdKeosTsfrcWc8DKfnRYQcBGNoBEq9GrOHDU0q2v\nyQIDAQAB\n-----END PUBLIC KEY-----\n\n"
+ },
+ "summary": "Pleroma BE dev",
+ "tag": [
+ {
+ "icon": {
+ "type": "Image",
+ "url": "https://{{domain}}/emoji/mine/6143373a807b1ae7.png"
+ },
+ "id": "https://{{domain}}/emoji/mine/6143373a807b1ae7.png",
+ "name": ":verified:",
+ "type": "Emoji",
+ "updated": "1970-01-01T00:00:00Z"
+ }
+ ],
+ "type": "Person",
+ "url": "https://{{domain}}/users/{{nickname}}"
+}
diff --git a/test/fixtures/webfinger/pleroma-webfinger.json b/test/fixtures/webfinger/pleroma-webfinger.json
new file mode 100644
index 000000000..8f075eaaf
--- /dev/null
+++ b/test/fixtures/webfinger/pleroma-webfinger.json
@@ -0,0 +1,27 @@
+{
+ "aliases": [
+ "https://{{subdomain}}/users/{{nickname}}"
+ ],
+ "links": [
+ {
+ "href": "https://{{subdomain}}/users/{{nickname}}",
+ "rel": "http://webfinger.net/rel/profile-page",
+ "type": "text/html"
+ },
+ {
+ "href": "https://{{subdomain}}/users/{{nickname}}",
+ "rel": "self",
+ "type": "application/activity+json"
+ },
+ {
+ "href": "https://{{subdomain}}/users/{{nickname}}",
+ "rel": "self",
+ "type": "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
+ },
+ {
+ "rel": "http://ostatus.org/schema/1.0/subscribe",
+ "template": "https://{{subdomain}}/ostatus_subscribe?acct={uri}"
+ }
+ ],
+ "subject": "acct:{{nickname}}@{{domain}}"
+}
diff --git a/test/mix/tasks/pleroma/config_test.exs b/test/mix/tasks/pleroma/config_test.exs
index f90ef8804..cf6d74907 100644
--- a/test/mix/tasks/pleroma/config_test.exs
+++ b/test/mix/tasks/pleroma/config_test.exs
@@ -49,7 +49,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
describe "migrate_to_db/1" do
setup do
clear_config(:configurable_from_database, true)
- clear_config([:quack, :level])
end
@tag capture_log: true
@@ -72,14 +71,12 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
config1 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"})
config2 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":second_setting"})
- config3 = ConfigDB.get_by_params(%{group: ":quack", key: ":level"})
refute ConfigDB.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"})
refute ConfigDB.get_by_params(%{group: ":postgrex", key: ":json_library"})
refute ConfigDB.get_by_params(%{group: ":pleroma", key: ":database"})
assert config1.value == [key: "value", key2: [Repo]]
assert config2.value == [key: "value2", key2: ["Activity"]]
- assert config3.value == :info
end
test "config table is truncated before migration" do
@@ -108,7 +105,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
test "settings are migrated to file and deleted from db", %{temp_file: temp_file} do
insert_config_record(:pleroma, :setting_first, key: "value", key2: ["Activity"])
insert_config_record(:pleroma, :setting_second, key: "value2", key2: [Repo])
- insert_config_record(:quack, :level, :info)
MixTask.run(["migrate_from_db", "--env", "temp", "-d"])
@@ -117,7 +113,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
file = File.read!(temp_file)
assert file =~ "config :pleroma, :setting_first,"
assert file =~ "config :pleroma, :setting_second,"
- assert file =~ "config :quack, :level, :info"
end
test "load a settings with large values and pass to file", %{temp_file: temp_file} do
@@ -199,7 +194,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
setup do
insert_config_record(:pleroma, :setting_first, key: "value", key2: ["Activity"])
insert_config_record(:pleroma, :setting_second, key: "value2", key2: [Repo])
- insert_config_record(:quack, :level, :info)
path = "test/instance_static"
file_path = Path.join(path, "temp.exported_from_db.secret.exs")
@@ -215,7 +209,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
file = File.read!(file_path)
assert file =~ "config :pleroma, :setting_first,"
assert file =~ "config :pleroma, :setting_second,"
- assert file =~ "config :quack, :level, :info"
end
test "release", %{file_path: file_path} do
@@ -227,7 +220,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
file = File.read!(file_path)
assert file =~ "config :pleroma, :setting_first,"
assert file =~ "config :pleroma, :setting_second,"
- assert file =~ "config :quack, :level, :info"
end
end
diff --git a/test/pleroma/activity_test.exs b/test/pleroma/activity_test.exs
index e38384c9c..a48a68837 100644
--- a/test/pleroma/activity_test.exs
+++ b/test/pleroma/activity_test.exs
@@ -145,6 +145,7 @@ defmodule Pleroma.ActivityTest do
setup do: clear_config([:instance, :limit_to_local_content])
+ @tag :skip_on_mac
test "finds utf8 text in statuses", %{
japanese_activity: japanese_activity,
user: user
diff --git a/test/pleroma/config/loader_test.exs b/test/pleroma/config/loader_test.exs
index 095067e61..784817d49 100644
--- a/test/pleroma/config/loader_test.exs
+++ b/test/pleroma/config/loader_test.exs
@@ -11,7 +11,6 @@ defmodule Pleroma.Config.LoaderTest do
config = Loader.read("test/fixtures/config/temp.secret.exs")
assert config[:pleroma][:first_setting][:key] == "value"
assert config[:pleroma][:first_setting][:key2] == [Pleroma.Repo]
- assert config[:quack][:level] == :info
end
test "filter_group/2" do
diff --git a/test/pleroma/config/transfer_task_test.exs b/test/pleroma/config/transfer_task_test.exs
index 3dc917362..6295fa888 100644
--- a/test/pleroma/config/transfer_task_test.exs
+++ b/test/pleroma/config/transfer_task_test.exs
@@ -15,13 +15,11 @@ defmodule Pleroma.Config.TransferTaskTest do
test "transfer config values from db to env" do
refute Application.get_env(:pleroma, :test_key)
refute Application.get_env(:idna, :test_key)
- refute Application.get_env(:quack, :test_key)
refute Application.get_env(:postgrex, :test_key)
initial = Application.get_env(:logger, :level)
insert(:config, key: :test_key, value: [live: 2, com: 3])
insert(:config, group: :idna, key: :test_key, value: [live: 15, com: 35])
- insert(:config, group: :quack, key: :test_key, value: [:test_value1, :test_value2])
insert(:config, group: :postgrex, key: :test_key, value: :value)
insert(:config, group: :logger, key: :level, value: :debug)
@@ -29,36 +27,32 @@ defmodule Pleroma.Config.TransferTaskTest do
assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
- assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
assert Application.get_env(:logger, :level) == :debug
assert Application.get_env(:postgrex, :test_key) == :value
on_exit(fn ->
Application.delete_env(:pleroma, :test_key)
Application.delete_env(:idna, :test_key)
- Application.delete_env(:quack, :test_key)
Application.delete_env(:postgrex, :test_key)
Application.put_env(:logger, :level, initial)
end)
end
test "transfer config values for 1 group and some keys" do
- level = Application.get_env(:quack, :level)
- meta = Application.get_env(:quack, :meta)
+ level = Application.get_env(:somegroup, :level)
+ meta = Application.get_env(:somegroup, :meta)
- insert(:config, group: :quack, key: :level, value: :info)
- insert(:config, group: :quack, key: :meta, value: [:none])
+ insert(:config, group: :somegroup, key: :level, value: :info)
+ insert(:config, group: :somegroup, key: :meta, value: [:none])
TransferTask.start_link([])
- assert Application.get_env(:quack, :level) == :info
- assert Application.get_env(:quack, :meta) == [:none]
- default = Pleroma.Config.Holder.default_config(:quack, :webhook_url)
- assert Application.get_env(:quack, :webhook_url) == default
+ assert Application.get_env(:somegroup, :level) == :info
+ assert Application.get_env(:somegroup, :meta) == [:none]
on_exit(fn ->
- Application.put_env(:quack, :level, level)
- Application.put_env(:quack, :meta, meta)
+ Application.put_env(:somegroup, :level, level)
+ Application.put_env(:somegroup, :meta, meta)
end)
end
diff --git a/test/pleroma/config_db_test.exs b/test/pleroma/config_db_test.exs
index ba7c615e2..8eb0ab4cf 100644
--- a/test/pleroma/config_db_test.exs
+++ b/test/pleroma/config_db_test.exs
@@ -16,13 +16,13 @@ defmodule Pleroma.ConfigDBTest do
test "get_all_as_keyword/0" do
saved = insert(:config)
- insert(:config, group: ":quack", key: ":level", value: :info)
- insert(:config, group: ":quack", key: ":meta", value: [:none])
+ insert(:config, group: ":goose", key: ":level", value: :info)
+ insert(:config, group: ":goose", key: ":meta", value: [:none])
insert(:config,
- group: ":quack",
+ group: ":goose",
key: ":webhook_url",
- value: "https://hooks.slack.com/services/KEY/some_val"
+ value: "https://gander.com/"
)
config = ConfigDB.get_all_as_keyword()
@@ -31,9 +31,9 @@ defmodule Pleroma.ConfigDBTest do
{saved.key, saved.value}
]
- assert config[:quack][:level] == :info
- assert config[:quack][:meta] == [:none]
- assert config[:quack][:webhook_url] == "https://hooks.slack.com/services/KEY/some_val"
+ assert config[:goose][:level] == :info
+ assert config[:goose][:meta] == [:none]
+ assert config[:goose][:webhook_url] == "https://gander.com/"
end
describe "update_or_create/1" do
@@ -267,10 +267,6 @@ defmodule Pleroma.ConfigDBTest do
assert ConfigDB.to_elixir_types("ExSyslogger") == ExSyslogger
end
- test "Quack.Logger module" do
- assert ConfigDB.to_elixir_types("Quack.Logger") == Quack.Logger
- end
-
test "Swoosh.Adapters modules" do
assert ConfigDB.to_elixir_types("Swoosh.Adapters.SMTP") == Swoosh.Adapters.SMTP
assert ConfigDB.to_elixir_types("Swoosh.Adapters.AmazonSES") == Swoosh.Adapters.AmazonSES
diff --git a/test/pleroma/html_test.exs b/test/pleroma/html_test.exs
index 970baf63b..b99689903 100644
--- a/test/pleroma/html_test.exs
+++ b/test/pleroma/html_test.exs
@@ -17,6 +17,7 @@ defmodule Pleroma.HTMLTest do
this is a link with allowed "rel" attribute: <a href="http://example.com/" rel="tag">example.com</a>
this is a link with not allowed "rel" attribute: <a href="http://example.com/" rel="tag noallowed">example.com</a>
this is an image: <img src="http://example.com/image.jpg"><br />
+ this is an inline emoji: <img class="emoji" src="http://example.com/image.jpg"><br />
<script>alert('hacked')</script>
"""
@@ -24,6 +25,10 @@ defmodule Pleroma.HTMLTest do
<img src="http://example.com/image.jpg" onerror="alert('hacked')">
"""
+ @html_stillimage_sample """
+ <img class="still-image" src="http://example.com/image.jpg">
+ """
+
@html_span_class_sample """
<span class="animate-spin">hi</span>
"""
@@ -45,6 +50,7 @@ defmodule Pleroma.HTMLTest do
this is a link with allowed &quot;rel&quot; attribute: example.com
this is a link with not allowed &quot;rel&quot; attribute: example.com
this is an image:
+ this is an inline emoji:
alert(&#39;hacked&#39;)
"""
@@ -67,6 +73,7 @@ defmodule Pleroma.HTMLTest do
this is a link with allowed &quot;rel&quot; attribute: <a href="http://example.com/" rel="tag">example.com</a>
this is a link with not allowed &quot;rel&quot; attribute: <a href="http://example.com/">example.com</a>
this is an image: <img src="http://example.com/image.jpg"/><br/>
+ this is an inline emoji: <img class="emoji" src="http://example.com/image.jpg"/><br/>
alert(&#39;hacked&#39;)
"""
@@ -90,6 +97,15 @@ defmodule Pleroma.HTMLTest do
HTML.filter_tags(@html_span_class_sample, Pleroma.HTML.Scrubber.TwitterText)
end
+ test "does not allow images with invalid classes" do
+ expected = """
+ <img src="http://example.com/image.jpg"/>
+ """
+
+ assert expected ==
+ HTML.filter_tags(@html_stillimage_sample, Pleroma.HTML.Scrubber.TwitterText)
+ end
+
test "does allow microformats" do
expected = """
<span class="h-card"><a class="u-url mention">@<span>foo</span></a></span>
@@ -121,6 +137,7 @@ defmodule Pleroma.HTMLTest do
this is a link with allowed &quot;rel&quot; attribute: <a href="http://example.com/" rel="tag">example.com</a>
this is a link with not allowed &quot;rel&quot; attribute: <a href="http://example.com/">example.com</a>
this is an image: <img src="http://example.com/image.jpg"/><br/>
+ this is an inline emoji: <img class="emoji" src="http://example.com/image.jpg"/><br/>
alert(&#39;hacked&#39;)
"""
@@ -143,6 +160,15 @@ defmodule Pleroma.HTMLTest do
assert expected == HTML.filter_tags(@html_span_class_sample, Pleroma.HTML.Scrubber.Default)
end
+ test "does not allow images with invalid classes" do
+ expected = """
+ <img src="http://example.com/image.jpg"/>
+ """
+
+ assert expected ==
+ HTML.filter_tags(@html_stillimage_sample, Pleroma.HTML.Scrubber.TwitterText)
+ end
+
test "does allow microformats" do
expected = """
<span class="h-card"><a class="u-url mention">@<span>foo</span></a></span>
diff --git a/test/pleroma/object/fetcher_test.exs b/test/pleroma/object/fetcher_test.exs
index 1f97f36f7..c8ad66ddb 100644
--- a/test/pleroma/object/fetcher_test.exs
+++ b/test/pleroma/object/fetcher_test.exs
@@ -6,6 +6,7 @@ defmodule Pleroma.Object.FetcherTest do
use Pleroma.DataCase
alias Pleroma.Activity
+ alias Pleroma.Instances
alias Pleroma.Object
alias Pleroma.Object.Fetcher
@@ -159,6 +160,17 @@ defmodule Pleroma.Object.FetcherTest do
"https://patch.cx/media/03ca3c8b4ac3ddd08bf0f84be7885f2f88de0f709112131a22d83650819e36c2.json"
)
end
+
+ test "it resets instance reachability on successful fetch" do
+ id = "http://mastodon.example.org/@admin/99541947525187367"
+ Instances.set_consistently_unreachable(id)
+ refute Instances.reachable?(id)
+
+ {:ok, _object} =
+ Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
+
+ assert Instances.reachable?(id)
+ end
end
describe "implementation quirks" do
diff --git a/test/pleroma/resilience_test.exs b/test/pleroma/resilience_test.exs
new file mode 100644
index 000000000..9dc5d0dd6
--- /dev/null
+++ b/test/pleroma/resilience_test.exs
@@ -0,0 +1,103 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.ResilienceTest do
+ use Pleroma.Web.ConnCase, async: true
+
+ import Pleroma.Factory
+
+ alias Pleroma.Activity
+ alias Pleroma.Repo
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.MastodonAPI.StatusView
+
+ setup do
+ # user = insert(:user)
+ %{user: user, conn: conn} = oauth_access(["write", "read"])
+ other_user = insert(:user)
+
+ {:ok, post_one} = CommonAPI.post(user, %{status: "Here is a post"})
+ {:ok, like} = CommonAPI.favorite(other_user, post_one.id)
+
+ %{
+ user: user,
+ other_user: other_user,
+ post_one: post_one,
+ like: like,
+ conn: conn
+ }
+ end
+
+ test "after destruction of like activities, things still work", %{
+ user: user,
+ post_one: post,
+ other_user: other_user,
+ conn: conn,
+ like: like
+ } do
+ post = Repo.get(Activity, post.id)
+
+ # Rendering the liked status
+ rendered_for_user = StatusView.render("show.json", %{activity: post, for: user})
+ assert rendered_for_user.favourites_count == 1
+
+ rendered_for_other_user = StatusView.render("show.json", %{activity: post, for: other_user})
+ assert rendered_for_other_user.favourites_count == 1
+ assert rendered_for_other_user.favourited
+
+ # Getting the favourited by
+ [liking_user] =
+ conn
+ |> get("/api/v1/statuses/#{post.id}/favourited_by")
+ |> json_response(200)
+
+ assert liking_user["id"] == other_user.id
+
+ # We have one notification
+ [notification] =
+ conn
+ |> get("/api/v1/notifications")
+ |> json_response(200)
+
+ assert notification["type"] == "favourite"
+
+ # Destroying the like
+ Repo.delete(like)
+ post = Repo.get(Activity, post.id)
+
+ # Rendering the liked status
+ rendered_for_user = StatusView.render("show.json", %{activity: post, for: user})
+ assert rendered_for_user.favourites_count == 1
+
+ rendered_for_other_user = StatusView.render("show.json", %{activity: post, for: other_user})
+ assert rendered_for_other_user.favourites_count == 1
+ assert rendered_for_other_user.favourited
+
+ # Getting the favourited by
+ [liking_user] =
+ conn
+ |> get("/api/v1/statuses/#{post.id}/favourited_by")
+ |> json_response(200)
+
+ assert liking_user["id"] == other_user.id
+
+ # Notification is removed
+
+ assert [] ==
+ conn
+ |> get("/api/v1/notifications")
+ |> json_response(200)
+
+ # Favoriting again doesn't hurt
+ {:ok, _like_two} = CommonAPI.favorite(other_user, post.id)
+
+ post = Repo.get(Activity, post.id)
+
+ # Rendering the liked status
+ rendered_for_user = StatusView.render("show.json", %{activity: post, for: user})
+ assert rendered_for_user.favourites_count == 1
+
+ # General fallout: Can't unfavorite stuff anymore. Acceptable for remote users.
+ end
+end
diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs
index 11789b64d..a58c8f68b 100644
--- a/test/pleroma/user_test.exs
+++ b/test/pleroma/user_test.exs
@@ -591,6 +591,21 @@ defmodule Pleroma.UserTest do
refute_email_sent()
end
+ test "it works when the registering user does not provide an email" do
+ clear_config([Pleroma.Emails.Mailer, :enabled], false)
+ clear_config([:instance, :account_activation_required], false)
+ clear_config([:instance, :account_approval_required], true)
+
+ cng = User.register_changeset(%User{}, @full_user_data |> Map.put(:email, ""))
+
+ # The user is still created
+ assert {:ok, %User{nickname: "nick"}} = User.register(cng)
+
+ # No emails are sent
+ ObanHelpers.perform_all()
+ refute_email_sent()
+ end
+
test "it requires an email, name, nickname and password, bio is optional when account_activation_required is enabled" do
clear_config([:instance, :account_activation_required], true)
@@ -850,6 +865,123 @@ defmodule Pleroma.UserTest do
freshed_user = refresh_record(user)
assert freshed_user == fetched_user
end
+
+ test "gets an existing user by nickname starting with http" do
+ user = insert(:user, nickname: "httpssome")
+ {:ok, fetched_user} = User.get_or_fetch("httpssome")
+
+ assert user == fetched_user
+ end
+ end
+
+ describe "get_or_fetch/1 remote users with tld, while BE is runned on subdomain" do
+ setup do: clear_config([Pleroma.Web.WebFinger, :update_nickname_on_user_fetch], true)
+
+ test "for mastodon" do
+ Tesla.Mock.mock(fn
+ %{url: "https://example.com/.well-known/host-meta"} ->
+ %Tesla.Env{
+ status: 302,
+ headers: [{"location", "https://sub.example.com/.well-known/host-meta"}]
+ }
+
+ %{url: "https://sub.example.com/.well-known/host-meta"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/masto-host-meta.xml"
+ |> File.read!()
+ |> String.replace("{{domain}}", "sub.example.com")
+ }
+
+ %{url: "https://sub.example.com/.well-known/webfinger?resource=acct:a@example.com"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/masto-webfinger.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", "a")
+ |> String.replace("{{domain}}", "example.com")
+ |> String.replace("{{subdomain}}", "sub.example.com"),
+ headers: [{"content-type", "application/jrd+json"}]
+ }
+
+ %{url: "https://sub.example.com/users/a"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/masto-user.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", "a")
+ |> String.replace("{{domain}}", "sub.example.com"),
+ headers: [{"content-type", "application/activity+json"}]
+ }
+
+ %{url: "https://sub.example.com/users/a/collections/featured"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ File.read!("test/fixtures/users_mock/masto_featured.json")
+ |> String.replace("{{domain}}", "sub.example.com")
+ |> String.replace("{{nickname}}", "a"),
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ ap_id = "a@example.com"
+ {:ok, fetched_user} = User.get_or_fetch(ap_id)
+
+ assert fetched_user.ap_id == "https://sub.example.com/users/a"
+ assert fetched_user.nickname == "a@example.com"
+ end
+
+ test "for pleroma" do
+ Tesla.Mock.mock(fn
+ %{url: "https://example.com/.well-known/host-meta"} ->
+ %Tesla.Env{
+ status: 302,
+ headers: [{"location", "https://sub.example.com/.well-known/host-meta"}]
+ }
+
+ %{url: "https://sub.example.com/.well-known/host-meta"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/pleroma-host-meta.xml"
+ |> File.read!()
+ |> String.replace("{{domain}}", "sub.example.com")
+ }
+
+ %{url: "https://sub.example.com/.well-known/webfinger?resource=acct:a@example.com"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/pleroma-webfinger.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", "a")
+ |> String.replace("{{domain}}", "example.com")
+ |> String.replace("{{subdomain}}", "sub.example.com"),
+ headers: [{"content-type", "application/jrd+json"}]
+ }
+
+ %{url: "https://sub.example.com/users/a"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/pleroma-user.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", "a")
+ |> String.replace("{{domain}}", "sub.example.com"),
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ ap_id = "a@example.com"
+ {:ok, fetched_user} = User.get_or_fetch(ap_id)
+
+ assert fetched_user.ap_id == "https://sub.example.com/users/a"
+ assert fetched_user.nickname == "a@example.com"
+ end
end
describe "fetching a user from nickname or trying to build one" do
diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs
index 13f3d93b8..fc6fc039d 100644
--- a/test/pleroma/web/activity_pub/activity_pub_test.exs
+++ b/test/pleroma/web/activity_pub/activity_pub_test.exs
@@ -1504,6 +1504,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
reporter_ap_id = reporter.ap_id
target_ap_id = target_account.ap_id
activity_ap_id = activity.data["id"]
+ object_ap_id = activity.object.data["id"]
activity_with_object = Activity.get_by_ap_id_with_object(activity_ap_id)
@@ -1515,6 +1516,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
reported_activity: activity,
content: content,
activity_ap_id: activity_ap_id,
+ object_ap_id: object_ap_id,
activity_with_object: activity_with_object,
reporter_ap_id: reporter_ap_id,
target_ap_id: target_ap_id
@@ -1528,7 +1530,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
target_account: target_account,
reported_activity: reported_activity,
content: content,
- activity_ap_id: activity_ap_id,
+ object_ap_id: object_ap_id,
activity_with_object: activity_with_object,
reporter_ap_id: reporter_ap_id,
target_ap_id: target_ap_id
@@ -1544,7 +1546,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
note_obj = %{
"type" => "Note",
- "id" => activity_ap_id,
+ "id" => object_ap_id,
"content" => content,
"published" => activity_with_object.object.data["published"],
"actor" =>
@@ -1568,6 +1570,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
context: context,
target_account: target_account,
reported_activity: reported_activity,
+ object_ap_id: object_ap_id,
content: content
},
Utils,
@@ -1582,8 +1585,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
content: content
})
- new_data =
- put_in(activity.data, ["object"], [target_account.ap_id, reported_activity.data["id"]])
+ new_data = put_in(activity.data, ["object"], [target_account.ap_id, object_ap_id])
assert_called(Utils.maybe_federate(%{activity | data: new_data}))
end
diff --git a/test/pleroma/web/activity_pub/mrf/simple_policy_test.exs b/test/pleroma/web/activity_pub/mrf/simple_policy_test.exs
index 674b506c3..57fc00af5 100644
--- a/test/pleroma/web/activity_pub/mrf/simple_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/simple_policy_test.exs
@@ -57,6 +57,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
assert SimplePolicy.filter(local_message) == {:ok, local_message}
end
+
+ test "works with Updates" do
+ clear_config([:mrf_simple, :media_removal], [{"remote.instance", "Some reason"}])
+ media_message = build_media_message(type: "Update")
+
+ assert SimplePolicy.filter(media_message) ==
+ {:ok,
+ media_message
+ |> Map.put("object", Map.delete(media_message["object"], "attachment"))}
+ end
end
describe "when :media_nsfw" do
@@ -90,12 +100,20 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
assert SimplePolicy.filter(local_message) == {:ok, local_message}
end
+
+ test "works with Updates" do
+ clear_config([:mrf_simple, :media_nsfw], [{"remote.instance", "Whetever"}])
+ media_message = build_media_message(type: "Update")
+
+ assert SimplePolicy.filter(media_message) ==
+ {:ok, put_in(media_message, ["object", "sensitive"], true)}
+ end
end
- defp build_media_message do
+ defp build_media_message(opts \\ []) do
%{
"actor" => "https://remote.instance/users/bob",
- "type" => "Create",
+ "type" => opts[:type] || "Create",
"object" => %{
"attachment" => [%{}],
"tag" => ["foo"],
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 46be316ee..a0db8df54 100644
--- a/test/pleroma/web/activity_pub/mrf/tag_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/tag_policy_test.exs
@@ -99,6 +99,24 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do
assert TagPolicy.filter(message) == {:ok, except_message}
end
+
+ test "removes attachments in Updates" do
+ actor = insert(:user, tags: ["mrf_tag:media-strip"])
+
+ message = %{
+ "actor" => actor.ap_id,
+ "type" => "Update",
+ "object" => %{"attachment" => ["file1"]}
+ }
+
+ except_message = %{
+ "actor" => actor.ap_id,
+ "type" => "Update",
+ "object" => %{}
+ }
+
+ assert TagPolicy.filter(message) == {:ok, except_message}
+ end
end
describe "mrf_tag:media-force-nsfw" do
@@ -119,5 +137,23 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do
assert TagPolicy.filter(message) == {:ok, except_message}
end
+
+ test "Mark as sensitive on presence of attachments in Updates" do
+ actor = insert(:user, tags: ["mrf_tag:media-force-nsfw"])
+
+ message = %{
+ "actor" => actor.ap_id,
+ "type" => "Update",
+ "object" => %{"tag" => ["test"], "attachment" => ["file1"]}
+ }
+
+ except_message = %{
+ "actor" => actor.ap_id,
+ "type" => "Update",
+ "object" => %{"tag" => ["test"], "attachment" => ["file1"], "sensitive" => true}
+ }
+
+ assert TagPolicy.filter(message) == {:ok, except_message}
+ end
end
end
diff --git a/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs
index 9a17e277e..77f2044e9 100644
--- a/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs
@@ -11,6 +11,19 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
import Pleroma.Factory
describe "attachments" do
+ test "fails without url" do
+ attachment = %{
+ "mediaType" => "",
+ "name" => "",
+ "summary" => "298p3RG7j27tfsZ9RQ.jpg",
+ "type" => "Document"
+ }
+
+ assert {:error, _cng} =
+ AttachmentValidator.cast_and_validate(attachment)
+ |> Ecto.Changeset.apply_action(:insert)
+ end
+
test "works with honkerific attachments" do
attachment = %{
"mediaType" => "",
diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs
index 273f2611d..6b4636d22 100644
--- a/test/pleroma/web/activity_pub/transmogrifier_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs
@@ -61,7 +61,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
note_obj = %{
"type" => "Note",
- "id" => activity.data["id"],
+ "id" => activity.object.data["id"],
"content" => "test post",
"published" => object.data["published"],
"actor" => AccountView.render("show.json", %{user: user, skip_visibility_check: true})
diff --git a/test/pleroma/web/activity_pub/utils_test.exs b/test/pleroma/web/activity_pub/utils_test.exs
index e42893849..e7d1e01c4 100644
--- a/test/pleroma/web/activity_pub/utils_test.exs
+++ b/test/pleroma/web/activity_pub/utils_test.exs
@@ -473,7 +473,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
content = "foobar"
target_ap_id = target_account.ap_id
- activity_ap_id = activity.data["id"]
+ object_ap_id = activity.object.data["id"]
res =
Utils.make_flag_data(
@@ -489,7 +489,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
note_obj = %{
"type" => "Note",
- "id" => activity_ap_id,
+ "id" => object_ap_id,
"content" => content,
"published" => activity.object.data["published"],
"actor" =>
@@ -504,6 +504,49 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
"state" => "open"
} = res
end
+
+ test "returns map with Flag object with a non-Create Activity" do
+ reporter = insert(:user)
+ posting_account = insert(:user)
+ target_account = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(posting_account, %{status: "foobar"})
+ {:ok, like} = CommonAPI.favorite(target_account, activity.id)
+ context = Utils.generate_context_id()
+ content = "foobar"
+
+ target_ap_id = target_account.ap_id
+ object_ap_id = activity.object.data["id"]
+
+ res =
+ Utils.make_flag_data(
+ %{
+ actor: reporter,
+ context: context,
+ account: target_account,
+ statuses: [%{"id" => like.data["id"]}],
+ content: content
+ },
+ %{}
+ )
+
+ note_obj = %{
+ "type" => "Note",
+ "id" => object_ap_id,
+ "content" => content,
+ "published" => activity.object.data["published"],
+ "actor" =>
+ AccountView.render("show.json", %{user: posting_account, skip_visibility_check: true})
+ }
+
+ assert %{
+ "type" => "Flag",
+ "content" => ^content,
+ "context" => ^context,
+ "object" => [^target_ap_id, ^note_obj],
+ "state" => "open"
+ } = res
+ end
end
describe "add_announce_to_object/2" do
diff --git a/test/pleroma/web/admin_api/controllers/chat_controller_test.exs b/test/pleroma/web/admin_api/controllers/chat_controller_test.exs
index ccf25a244..0ef7c367b 100644
--- a/test/pleroma/web/admin_api/controllers/chat_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/chat_controller_test.exs
@@ -53,7 +53,7 @@ defmodule Pleroma.Web.AdminAPI.ChatControllerTest do
log_entry = Repo.one(ModerationLog)
assert ModerationLog.get_log_entry_message(log_entry) ==
- "@#{admin.nickname} deleted chat message ##{cm_ref.id}"
+ "@#{admin.nickname} deleted chat message ##{message.id}"
assert result["id"] == cm_ref.id
refute MessageReference.get_by_id(cm_ref.id)
diff --git a/test/pleroma/web/admin_api/controllers/config_controller_test.exs b/test/pleroma/web/admin_api/controllers/config_controller_test.exs
index 6d014b65b..9ef7c0c46 100644
--- a/test/pleroma/web/admin_api/controllers/config_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/config_controller_test.exs
@@ -317,14 +317,14 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
end
test "save configs setting without explicit key", %{conn: conn} do
- level = Application.get_env(:quack, :level)
- meta = Application.get_env(:quack, :meta)
- webhook_url = Application.get_env(:quack, :webhook_url)
+ adapter = Application.get_env(:http, :adapter)
+ send_user_agent = Application.get_env(:http, :send_user_agent)
+ user_agent = Application.get_env(:http, :user_agent)
on_exit(fn ->
- Application.put_env(:quack, :level, level)
- Application.put_env(:quack, :meta, meta)
- Application.put_env(:quack, :webhook_url, webhook_url)
+ Application.put_env(:http, :adapter, adapter)
+ Application.put_env(:http, :send_user_agent, send_user_agent)
+ Application.put_env(:http, :user_agent, user_agent)
end)
conn =
@@ -333,19 +333,19 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|> post("/api/pleroma/admin/config", %{
configs: [
%{
- group: ":quack",
- key: ":level",
- value: ":info"
+ group: ":http",
+ key: ":adapter",
+ value: [":someval"]
},
%{
- group: ":quack",
- key: ":meta",
- value: [":none"]
+ group: ":http",
+ key: ":send_user_agent",
+ value: true
},
%{
- group: ":quack",
- key: ":webhook_url",
- value: "https://hooks.slack.com/services/KEY"
+ group: ":http",
+ key: ":user_agent",
+ value: [":default"]
}
]
})
@@ -353,30 +353,30 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
assert json_response_and_validate_schema(conn, 200) == %{
"configs" => [
%{
- "group" => ":quack",
- "key" => ":level",
- "value" => ":info",
- "db" => [":level"]
+ "group" => ":http",
+ "key" => ":adapter",
+ "value" => [":someval"],
+ "db" => [":adapter"]
},
%{
- "group" => ":quack",
- "key" => ":meta",
- "value" => [":none"],
- "db" => [":meta"]
+ "group" => ":http",
+ "key" => ":send_user_agent",
+ "value" => true,
+ "db" => [":send_user_agent"]
},
%{
- "group" => ":quack",
- "key" => ":webhook_url",
- "value" => "https://hooks.slack.com/services/KEY",
- "db" => [":webhook_url"]
+ "group" => ":http",
+ "key" => ":user_agent",
+ "value" => [":default"],
+ "db" => [":user_agent"]
}
],
"need_reboot" => false
}
- assert Application.get_env(:quack, :level) == :info
- assert Application.get_env(:quack, :meta) == [:none]
- assert Application.get_env(:quack, :webhook_url) == "https://hooks.slack.com/services/KEY"
+ assert Application.get_env(:http, :adapter) == [:someval]
+ assert Application.get_env(:http, :send_user_agent) == true
+ assert Application.get_env(:http, :user_agent) == [:default]
end
test "saving config with partial update", %{conn: conn} do
diff --git a/test/pleroma/web/admin_api/controllers/report_controller_test.exs b/test/pleroma/web/admin_api/controllers/report_controller_test.exs
index 30dcb87e2..6fd3fbe5a 100644
--- a/test/pleroma/web/admin_api/controllers/report_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/report_controller_test.exs
@@ -54,6 +54,32 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
assert notes["content"] == "this is an admin note"
end
+ test "renders reported content even if the status is deleted", %{conn: conn} do
+ [reporter, target_user] = insert_pair(:user)
+ activity = insert(:note_activity, user: target_user)
+ activity = Activity.normalize(activity)
+
+ {:ok, %{id: report_id}} =
+ CommonAPI.report(reporter, %{
+ account_id: target_user.id,
+ comment: "I feel offended",
+ status_ids: [activity.id]
+ })
+
+ CommonAPI.delete(activity.id, target_user)
+
+ response =
+ conn
+ |> get("/api/pleroma/admin/reports/#{report_id}")
+ |> json_response_and_validate_schema(:ok)
+
+ assert response["id"] == report_id
+
+ assert [status] = response["statuses"]
+ assert activity.object.data["id"] == status["uri"]
+ assert activity.object.data["content"] == status["content"]
+ end
+
test "returns 404 when report id is invalid", %{conn: conn} do
conn = get(conn, "/api/pleroma/admin/reports/test")
diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs
index ee01548f9..9d52bd93e 100644
--- a/test/pleroma/web/common_api_test.exs
+++ b/test/pleroma/web/common_api_test.exs
@@ -1100,10 +1100,11 @@ defmodule Pleroma.Web.CommonAPITest do
target_user = insert(:user)
{:ok, activity} = CommonAPI.post(target_user, %{status: "foobar"})
+ activity = Activity.normalize(activity)
reporter_ap_id = reporter.ap_id
target_ap_id = target_user.ap_id
- activity_ap_id = activity.data["id"]
+ reported_object_ap_id = activity.object.data["id"]
comment = "foobar"
report_data = %{
@@ -1114,7 +1115,7 @@ defmodule Pleroma.Web.CommonAPITest do
note_obj = %{
"type" => "Note",
- "id" => activity_ap_id,
+ "id" => reported_object_ap_id,
"content" => "foobar",
"published" => activity.object.data["published"],
"actor" => AccountView.render("show.json", %{user: target_user})
@@ -1136,6 +1137,7 @@ defmodule Pleroma.Web.CommonAPITest do
test "updates report state" do
[reporter, target_user] = insert_pair(:user)
activity = insert(:note_activity, user: target_user)
+ object = Object.normalize(activity)
{:ok, %Activity{id: report_id}} =
CommonAPI.report(reporter, %{
@@ -1148,10 +1150,36 @@ defmodule Pleroma.Web.CommonAPITest do
assert report.data["state"] == "resolved"
- [reported_user, activity_id] = report.data["object"]
+ [reported_user, object_id] = report.data["object"]
assert reported_user == target_user.ap_id
- assert activity_id == activity.data["id"]
+ assert object_id == object.data["id"]
+ end
+
+ test "updates report state, don't strip when report_strip_status is false" do
+ clear_config([:instance, :report_strip_status], false)
+
+ [reporter, target_user] = insert_pair(:user)
+ activity = insert(:note_activity, user: target_user)
+
+ {:ok, %Activity{id: report_id, data: report_data}} =
+ CommonAPI.report(reporter, %{
+ account_id: target_user.id,
+ comment: "I feel offended",
+ status_ids: [activity.id]
+ })
+
+ {:ok, report} = CommonAPI.update_report_state(report_id, "resolved")
+
+ assert report.data["state"] == "resolved"
+
+ [reported_user, reported_activity] = report.data["object"]
+
+ assert reported_user == target_user.ap_id
+ assert is_map(reported_activity)
+
+ assert reported_activity["content"] ==
+ report_data["object"] |> Enum.at(1) |> Map.get("content")
end
test "does not update report state when state is unsupported" do
diff --git a/test/pleroma/web/feed/tag_controller_test.exs b/test/pleroma/web/feed/tag_controller_test.exs
index 1bd2b157c..58ab8f137 100644
--- a/test/pleroma/web/feed/tag_controller_test.exs
+++ b/test/pleroma/web/feed/tag_controller_test.exs
@@ -63,7 +63,6 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
]
assert xpath(xml, ~x"//feed/entry/author/name/text()"ls) == [user.nickname, user.nickname]
- assert xpath(xml, ~x"//feed/entry/author/id/text()"ls) == [user.ap_id, user.ap_id]
conn =
conn
@@ -138,8 +137,8 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
]
assert xpath(xml, ~x"//channel/item/pubDate/text()"sl) == [
- FeedView.pub_date(activity2.data["published"]),
- FeedView.pub_date(activity1.data["published"])
+ FeedView.to_rfc2822(activity2.data["published"]),
+ FeedView.to_rfc2822(activity1.data["published"])
]
assert xpath(xml, ~x"//channel/item/enclosure/@url"sl) == [
diff --git a/test/pleroma/web/feed/user_controller_test.exs b/test/pleroma/web/feed/user_controller_test.exs
index 38cde3315..de32d3d4b 100644
--- a/test/pleroma/web/feed/user_controller_test.exs
+++ b/test/pleroma/web/feed/user_controller_test.exs
@@ -74,7 +74,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|> SweetXml.parse()
|> SweetXml.xpath(~x"//entry/title/text()"l)
- assert activity_titles == ['42 &amp; Thi...', 'This &amp; t...']
+ assert activity_titles == ['2hu', '2hu & as']
assert resp =~ FeedView.escape(object.data["content"])
assert resp =~ FeedView.escape(object.data["summary"])
assert resp =~ FeedView.escape(object.data["context"])
@@ -90,7 +90,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|> SweetXml.parse()
|> SweetXml.xpath(~x"//entry/title/text()"l)
- assert activity_titles == ['This &amp; t...']
+ assert activity_titles == ['2hu & as']
end
test "gets a rss feed", %{conn: conn, user: user, object: object, max_id: max_id} do
@@ -105,7 +105,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|> SweetXml.parse()
|> SweetXml.xpath(~x"//item/title/text()"l)
- assert activity_titles == ['42 &amp; Thi...', 'This &amp; t...']
+ assert activity_titles == ['2hu', '2hu & as']
assert resp =~ FeedView.escape(object.data["content"])
assert resp =~ FeedView.escape(object.data["summary"])
assert resp =~ FeedView.escape(object.data["context"])
@@ -121,7 +121,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|> SweetXml.parse()
|> SweetXml.xpath(~x"//item/title/text()"l)
- assert activity_titles == ['This &amp; t...']
+ assert activity_titles == ['2hu & as']
end
test "returns 404 for a missing feed", %{conn: conn} do
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 2bf4edb70..958b7f76f 100644
--- a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
@@ -896,6 +896,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|> post("/api/v1/accounts/#{followed.id}/follow", %{reblogs: true})
|> json_response_and_validate_schema(200)
+ assert %{"showing_reblogs" => true} =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/accounts/#{followed.id}/follow", %{reblogs: "1"})
+ |> json_response_and_validate_schema(200)
+
assert [%{"id" => ^reblog_id}] =
conn
|> get("/api/v1/timelines/home")
@@ -925,6 +931,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|> post("/api/v1/accounts/#{followed.id}/follow", %{reblogs: false})
|> json_response_and_validate_schema(200)
+ assert %{"showing_reblogs" => false} =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/accounts/#{followed.id}/follow", %{reblogs: "0"})
+ |> json_response_and_validate_schema(200)
+
assert [] ==
conn
|> get("/api/v1/timelines/home")
@@ -935,21 +947,23 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
%{conn: conn} = oauth_access(["follow"])
followed = insert(:user)
- ret_conn =
- conn
- |> put_req_header("content-type", "application/json")
- |> post("/api/v1/accounts/#{followed.id}/follow", %{notify: true})
-
- assert %{"id" => _id, "subscribing" => true} =
- json_response_and_validate_schema(ret_conn, 200)
+ assert %{"subscribing" => true} =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/accounts/#{followed.id}/follow", %{notify: true})
+ |> json_response_and_validate_schema(200)
- ret_conn =
- conn
- |> put_req_header("content-type", "application/json")
- |> post("/api/v1/accounts/#{followed.id}/follow", %{notify: false})
+ assert %{"subscribing" => true} =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/accounts/#{followed.id}/follow", %{notify: "1"})
+ |> json_response_and_validate_schema(200)
- assert %{"id" => _id, "subscribing" => false} =
- json_response_and_validate_schema(ret_conn, 200)
+ assert %{"subscribing" => false} =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/accounts/#{followed.id}/follow", %{notify: false})
+ |> json_response_and_validate_schema(200)
end
test "following / unfollowing errors", %{user: user, conn: conn} do
diff --git a/test/pleroma/web/mastodon_api/controllers/report_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/report_controller_test.exs
index 6d1a63334..c7aa76122 100644
--- a/test/pleroma/web/mastodon_api/controllers/report_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/report_controller_test.exs
@@ -5,6 +5,8 @@
defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
use Pleroma.Web.ConnCase, async: true
+ alias Pleroma.Activity
+ alias Pleroma.Repo
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
@@ -27,6 +29,41 @@ defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
|> json_response_and_validate_schema(200)
end
+ test "submit a report with a fake Create", %{
+ conn: conn
+ } do
+ target_user = insert(:user)
+
+ note = insert(:note, user: target_user)
+
+ activity_params = %{
+ "object" => note.data["id"],
+ "actor" => note.data["actor"],
+ "to" => note.data["to"] || [],
+ "cc" => note.data["cc"] || [],
+ "type" => "Create"
+ }
+
+ {:ok, fake_activity} =
+ Repo.insert(%Activity{
+ data: activity_params,
+ recipients: activity_params["to"] ++ activity_params["cc"],
+ local: true,
+ actor: activity_params["actor"]
+ })
+
+ assert %{"action_taken" => false, "id" => _} =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/reports", %{
+ "account_id" => target_user.id,
+ "status_ids" => [fake_activity.id],
+ "comment" => "bad status!",
+ "forward" => "false"
+ })
+ |> json_response_and_validate_schema(200)
+ end
+
test "submit a report with statuses and comment", %{
conn: conn,
target_user: target_user,
diff --git a/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs
index 9a5d88109..0a9240b70 100644
--- a/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs
@@ -37,6 +37,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
end
end
+ @tag :skip_on_mac
test "search", %{conn: conn} do
user = insert(:user)
user_two = insert(:user, %{nickname: "shp@shitposter.club"})
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 e23bddbff..dbb840574 100644
--- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
@@ -8,6 +8,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
alias Pleroma.Activity
alias Pleroma.Conversation.Participation
+ alias Pleroma.ModerationLog
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.ScheduledActivity
@@ -970,30 +971,40 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
assert Activity.get_by_id(activity.id) == activity
end
- test "when you're an admin or moderator", %{conn: conn} do
- activity1 = insert(:note_activity)
- activity2 = insert(:note_activity)
- admin = insert(:user, is_admin: true)
- moderator = insert(:user, is_moderator: true)
+ test "when you're an admin", %{conn: conn} do
+ activity = insert(:note_activity)
+ user = insert(:user, is_admin: true)
res_conn =
conn
- |> assign(:user, admin)
- |> assign(:token, insert(:oauth_token, user: admin, scopes: ["write:statuses"]))
- |> delete("/api/v1/statuses/#{activity1.id}")
+ |> assign(:user, user)
+ |> assign(:token, insert(:oauth_token, user: user, scopes: ["write:statuses"]))
+ |> delete("/api/v1/statuses/#{activity.id}")
assert %{} = json_response_and_validate_schema(res_conn, 200)
+ assert ModerationLog |> Repo.one() |> ModerationLog.get_log_entry_message() ==
+ "@#{user.nickname} deleted status ##{activity.id}"
+
+ refute Activity.get_by_id(activity.id)
+ end
+
+ test "when you're a moderator", %{conn: conn} do
+ activity = insert(:note_activity)
+ user = insert(:user, is_moderator: true)
+
res_conn =
conn
- |> assign(:user, moderator)
- |> assign(:token, insert(:oauth_token, user: moderator, scopes: ["write:statuses"]))
- |> delete("/api/v1/statuses/#{activity2.id}")
+ |> assign(:user, user)
+ |> assign(:token, insert(:oauth_token, user: user, scopes: ["write:statuses"]))
+ |> delete("/api/v1/statuses/#{activity.id}")
assert %{} = json_response_and_validate_schema(res_conn, 200)
- refute Activity.get_by_id(activity1.id)
- refute Activity.get_by_id(activity2.id)
+ assert ModerationLog |> Repo.one() |> ModerationLog.get_log_entry_message() ==
+ "@#{user.nickname} deleted status ##{activity.id}"
+
+ refute Activity.get_by_id(activity.id)
end
end
diff --git a/test/pleroma/web/mastodon_api/update_credentials_test.exs b/test/pleroma/web/mastodon_api/update_credentials_test.exs
index f5211a60e..d5fac7e25 100644
--- a/test/pleroma/web/mastodon_api/update_credentials_test.exs
+++ b/test/pleroma/web/mastodon_api/update_credentials_test.exs
@@ -259,6 +259,34 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
assert user.avatar == nil
end
+ test "updates the user's avatar, upload_limit, returns a HTTP 413", %{conn: conn, user: user} do
+ upload_limit = Config.get([:instance, :upload_limit]) * 8 + 8
+
+ assert :ok ==
+ File.write(Path.absname("test/tmp/large_binary.data"), <<0::size(upload_limit)>>)
+
+ new_avatar_oversized = %Plug.Upload{
+ content_type: nil,
+ path: Path.absname("test/tmp/large_binary.data"),
+ filename: "large_binary.data"
+ }
+
+ assert user.avatar == %{}
+
+ res =
+ patch(conn, "/api/v1/accounts/update_credentials", %{"avatar" => new_avatar_oversized})
+
+ assert user_response = json_response_and_validate_schema(res, 413)
+ assert user_response["avatar"] != User.avatar_url(user)
+
+ user = User.get_by_id(user.id)
+ assert user.avatar == %{}
+
+ clear_config([:instance, :upload_limit], upload_limit)
+
+ assert :ok == File.rm(Path.absname("test/tmp/large_binary.data"))
+ end
+
test "updates the user's banner", %{user: user, conn: conn} do
new_header = %Plug.Upload{
content_type: "image/jpeg",
@@ -278,6 +306,32 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
assert user.banner == nil
end
+ test "updates the user's banner, upload_limit, returns a HTTP 413", %{conn: conn, user: user} do
+ upload_limit = Config.get([:instance, :upload_limit]) * 8 + 8
+
+ assert :ok ==
+ File.write(Path.absname("test/tmp/large_binary.data"), <<0::size(upload_limit)>>)
+
+ new_header_oversized = %Plug.Upload{
+ content_type: nil,
+ path: Path.absname("test/tmp/large_binary.data"),
+ filename: "large_binary.data"
+ }
+
+ res =
+ patch(conn, "/api/v1/accounts/update_credentials", %{"header" => new_header_oversized})
+
+ assert user_response = json_response_and_validate_schema(res, 413)
+ assert user_response["header"] != User.banner_url(user)
+
+ user = User.get_by_id(user.id)
+ assert user.banner == %{}
+
+ clear_config([:instance, :upload_limit], upload_limit)
+
+ assert :ok == File.rm(Path.absname("test/tmp/large_binary.data"))
+ end
+
test "updates the user's background", %{conn: conn, user: user} do
new_header = %Plug.Upload{
content_type: "image/jpeg",
@@ -301,6 +355,34 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
assert user.background == nil
end
+ test "updates the user's background, upload_limit, returns a HTTP 413", %{
+ conn: conn,
+ user: user
+ } do
+ upload_limit = Config.get([:instance, :upload_limit]) * 8 + 8
+
+ assert :ok ==
+ File.write(Path.absname("test/tmp/large_binary.data"), <<0::size(upload_limit)>>)
+
+ new_background_oversized = %Plug.Upload{
+ content_type: nil,
+ path: Path.absname("test/tmp/large_binary.data"),
+ filename: "large_binary.data"
+ }
+
+ res =
+ patch(conn, "/api/v1/accounts/update_credentials", %{
+ "pleroma_background_image" => new_background_oversized
+ })
+
+ assert user_response = json_response_and_validate_schema(res, 413)
+ assert user.background == %{}
+
+ clear_config([:instance, :upload_limit], upload_limit)
+
+ assert :ok == File.rm(Path.absname("test/tmp/large_binary.data"))
+ end
+
test "requires 'write:accounts' permission" do
token1 = insert(:oauth_token, scopes: ["read"])
token2 = insert(:oauth_token, scopes: ["write", "follow"])
diff --git a/test/pleroma/web/metadata/providers/twitter_card_test.exs b/test/pleroma/web/metadata/providers/twitter_card_test.exs
index 1a0cea9ce..be4cfbe7b 100644
--- a/test/pleroma/web/metadata/providers/twitter_card_test.exs
+++ b/test/pleroma/web/metadata/providers/twitter_card_test.exs
@@ -22,10 +22,10 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
res = TwitterCard.build_tags(%{user: user})
assert res == [
- {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
- {:meta, [property: "twitter:description", content: "born 19 March 1994"], []},
- {:meta, [property: "twitter:image", content: avatar_url], []},
- {:meta, [property: "twitter:card", content: "summary"], []}
+ {:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
+ {:meta, [name: "twitter:description", content: "born 19 March 1994"], []},
+ {:meta, [name: "twitter:image", content: avatar_url], []},
+ {:meta, [name: "twitter:card", content: "summary"], []}
]
end
@@ -47,11 +47,11 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
assert [
- {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
- {:meta, [property: "twitter:description", content: "pleroma in a nutshell"], []},
- {:meta, [property: "twitter:image", content: "http://localhost:4001/images/avi.png"],
+ {:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
+ {:meta, [name: "twitter:description", content: "pleroma in a nutshell"], []},
+ {:meta, [name: "twitter:image", content: "http://localhost:4001/images/avi.png"],
[]},
- {:meta, [property: "twitter:card", content: "summary"], []}
+ {:meta, [name: "twitter:card", content: "summary"], []}
] == result
end
@@ -73,15 +73,15 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
assert [
- {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
+ {:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
{:meta,
[
- property: "twitter:description",
+ name: "twitter:description",
content: "Public service announcement on caffeine consumption"
], []},
- {:meta, [property: "twitter:image", content: "http://localhost:4001/images/avi.png"],
+ {:meta, [name: "twitter:image", content: "http://localhost:4001/images/avi.png"],
[]},
- {:meta, [property: "twitter:card", content: "summary"], []}
+ {:meta, [name: "twitter:card", content: "summary"], []}
] == result
end
@@ -123,11 +123,11 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
assert [
- {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
- {:meta, [property: "twitter:description", content: "pleroma in a nutshell"], []},
- {:meta, [property: "twitter:image", content: "http://localhost:4001/images/avi.png"],
+ {:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
+ {:meta, [name: "twitter:description", content: "pleroma in a nutshell"], []},
+ {:meta, [name: "twitter:image", content: "http://localhost:4001/images/avi.png"],
[]},
- {:meta, [property: "twitter:card", content: "summary"], []}
+ {:meta, [name: "twitter:card", content: "summary"], []}
] == result
end
@@ -179,26 +179,26 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
assert [
- {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
- {:meta, [property: "twitter:description", content: "pleroma in a nutshell"], []},
- {:meta, [property: "twitter:card", content: "summary_large_image"], []},
- {:meta, [property: "twitter:player", content: "https://pleroma.gov/tenshi.png"], []},
- {:meta, [property: "twitter:player:width", content: "1280"], []},
- {:meta, [property: "twitter:player:height", content: "1024"], []},
- {:meta, [property: "twitter:card", content: "player"], []},
+ {:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
+ {:meta, [name: "twitter:description", content: "pleroma in a nutshell"], []},
+ {:meta, [name: "twitter:card", content: "summary_large_image"], []},
+ {:meta, [name: "twitter:player", content: "https://pleroma.gov/tenshi.png"], []},
+ {:meta, [name: "twitter:player:width", content: "1280"], []},
+ {:meta, [name: "twitter:player:height", content: "1024"], []},
+ {:meta, [name: "twitter:card", content: "player"], []},
{:meta,
[
- property: "twitter:player",
+ name: "twitter:player",
content: Router.Helpers.o_status_url(Endpoint, :notice_player, activity.id)
], []},
- {:meta, [property: "twitter:player:width", content: "800"], []},
- {:meta, [property: "twitter:player:height", content: "600"], []},
+ {:meta, [name: "twitter:player:width", content: "800"], []},
+ {:meta, [name: "twitter:player:height", content: "600"], []},
{:meta,
[
- property: "twitter:player:stream",
+ name: "twitter:player:stream",
content: "https://pleroma.gov/about/juche.webm"
], []},
- {:meta, [property: "twitter:player:stream:content_type", content: "video/webm"], []}
+ {:meta, [name: "twitter:player:stream:content_type", content: "video/webm"], []}
] == result
end
end
diff --git a/test/pleroma/web/plugs/http_security_plug_test.exs b/test/pleroma/web/plugs/http_security_plug_test.exs
index e1e97c1ce..c79170382 100644
--- a/test/pleroma/web/plugs/http_security_plug_test.exs
+++ b/test/pleroma/web/plugs/http_security_plug_test.exs
@@ -59,9 +59,9 @@ defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do
assert csp =~ ~r|report-uri https://endpoint.com;report-to csp-endpoint;|
- [reply_to] = Conn.get_resp_header(conn, "reply-to")
+ [report_to] = Conn.get_resp_header(conn, "report-to")
- assert reply_to ==
+ assert report_to ==
"{\"endpoints\":[{\"url\":\"https://endpoint.com\"}],\"group\":\"csp-endpoint\",\"max-age\":10886400}"
end
diff --git a/test/pleroma/web/push/impl_test.exs b/test/pleroma/web/push/impl_test.exs
index b8112cce5..2eee0acd9 100644
--- a/test/pleroma/web/push/impl_test.exs
+++ b/test/pleroma/web/push/impl_test.exs
@@ -202,6 +202,21 @@ defmodule Pleroma.Web.Push.ImplTest do
"New Reaction"
end
+ test "renders title and body for update activity" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "lorem ipsum"})
+
+ {:ok, activity} = CommonAPI.update(user, activity, %{status: "edited status"})
+ object = Object.normalize(activity, fetch: false)
+
+ assert Impl.format_body(%{activity: activity, type: "update"}, user, object) ==
+ "@#{user.nickname} edited a status"
+
+ assert Impl.format_title(%{activity: activity, type: "update"}) ==
+ "New Update"
+ end
+
test "renders title for create activity with direct visibility" do
user = insert(:user, nickname: "Bob")
diff --git a/test/pleroma/web/twitter_api/remote_follow_controller_test.exs b/test/pleroma/web/twitter_api/remote_follow_controller_test.exs
index 2b57a42a4..1194e0afe 100644
--- a/test/pleroma/web/twitter_api/remote_follow_controller_test.exs
+++ b/test/pleroma/web/twitter_api/remote_follow_controller_test.exs
@@ -3,7 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
- use Pleroma.Web.ConnCase
+ use Pleroma.Web.ConnCase, async: true
alias Pleroma.MFA
alias Pleroma.MFA.TOTP
diff --git a/test/pleroma/web/web_finger/web_finger_controller_test.exs b/test/pleroma/web/web_finger/web_finger_controller_test.exs
index b5be28e67..5e3ac26f9 100644
--- a/test/pleroma/web/web_finger/web_finger_controller_test.exs
+++ b/test/pleroma/web/web_finger/web_finger_controller_test.exs
@@ -48,6 +48,35 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
]
end
+ test "reach user on tld, while pleroma is runned on subdomain" do
+ Pleroma.Web.Endpoint.config_change(
+ [{Pleroma.Web.Endpoint, url: [host: "sub.example.com"]}],
+ []
+ )
+
+ clear_config([Pleroma.Web.Endpoint, :url, :host], "sub.example.com")
+
+ clear_config([Pleroma.Web.WebFinger, :domain], "example.com")
+
+ user = insert(:user, ap_id: "https://sub.example.com/users/bobby", nickname: "bobby")
+
+ response =
+ build_conn()
+ |> put_req_header("accept", "application/jrd+json")
+ |> get("/.well-known/webfinger?resource=acct:#{user.nickname}@example.com")
+ |> json_response(200)
+
+ assert response["subject"] == "acct:#{user.nickname}@example.com"
+ assert response["aliases"] == ["https://sub.example.com/users/#{user.nickname}"]
+
+ on_exit(fn ->
+ Pleroma.Web.Endpoint.config_change(
+ [{Pleroma.Web.Endpoint, url: [host: "localhost"]}],
+ []
+ )
+ end)
+ end
+
test "it returns 404 when user isn't found (JSON)" do
result =
build_conn()
diff --git a/test/pleroma/web/web_finger_test.exs b/test/pleroma/web/web_finger_test.exs
index 1cc6ae675..fafef54fe 100644
--- a/test/pleroma/web/web_finger_test.exs
+++ b/test/pleroma/web/web_finger_test.exs
@@ -47,7 +47,7 @@ defmodule Pleroma.Web.WebFingerTest do
test "returns error when there is no content-type header" do
Tesla.Mock.mock(fn
- %{url: "http://social.heldscal.la/.well-known/host-meta"} ->
+ %{url: "https://social.heldscal.la/.well-known/host-meta"} ->
{:ok,
%Tesla.Env{
status: 200,
@@ -120,7 +120,7 @@ defmodule Pleroma.Web.WebFingerTest do
test "it gets the xrd endpoint for statusnet" do
{:ok, template} = WebFinger.find_lrdd_template("status.alpicola.com")
- assert template == "http://status.alpicola.com/main/xrd?uri={uri}"
+ assert template == "https://status.alpicola.com/main/xrd?uri={uri}"
end
test "it works with idna domains as nickname" do
@@ -147,7 +147,7 @@ defmodule Pleroma.Web.WebFingerTest do
headers: [{"content-type", "application/jrd+json"}]
}}
- %{url: "http://mastodon.social/.well-known/host-meta"} ->
+ %{url: "https://mastodon.social/.well-known/host-meta"} ->
{:ok,
%Tesla.Env{
status: 200,
@@ -170,7 +170,7 @@ defmodule Pleroma.Web.WebFingerTest do
headers: [{"content-type", "application/xrd+xml"}]
}}
- %{url: "http://pawoo.net/.well-known/host-meta"} ->
+ %{url: "https://pawoo.net/.well-known/host-meta"} ->
{:ok,
%Tesla.Env{
status: 200,
diff --git a/test/pleroma/workers/publisher_worker_test.exs b/test/pleroma/workers/publisher_worker_test.exs
new file mode 100644
index 000000000..13372bf49
--- /dev/null
+++ b/test/pleroma/workers/publisher_worker_test.exs
@@ -0,0 +1,40 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Workers.PublisherWorkerTest do
+ use Pleroma.DataCase, async: true
+ use Oban.Testing, repo: Pleroma.Repo
+
+ import Pleroma.Factory
+
+ alias Pleroma.Object
+ alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.ActivityPub.Builder
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.Federator
+
+ describe "Oban job priority:" do
+ setup do
+ user = insert(:user)
+
+ {:ok, post} = CommonAPI.post(user, %{status: "Regrettable post"})
+ object = Object.normalize(post, fetch: false)
+ {:ok, delete_data, _meta} = Builder.delete(user, object.data["id"])
+ {:ok, delete, _meta} = ActivityPub.persist(delete_data, local: true)
+
+ %{
+ post: post,
+ delete: delete
+ }
+ end
+
+ test "Deletions are lower priority", %{delete: delete} do
+ assert {:ok, %Oban.Job{priority: 3}} = Federator.publish(delete)
+ end
+
+ test "Creates are normal priority", %{post: post} do
+ assert {:ok, %Oban.Job{priority: 0}} = Federator.publish(post)
+ end
+ end
+end
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index 7f6065579..b0cf613ac 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -424,14 +424,6 @@ defmodule HttpRequestMock do
{:error, :nxdomain}
end
- def get("http://osada.macgirvin.com/.well-known/host-meta", _, _, _) do
- {:ok,
- %Tesla.Env{
- status: 404,
- body: ""
- }}
- end
-
def get("https://osada.macgirvin.com/.well-known/host-meta", _, _, _) do
{:ok,
%Tesla.Env{
@@ -765,7 +757,7 @@ defmodule HttpRequestMock do
{:ok, %Tesla.Env{status: 406, body: ""}}
end
- def get("http://squeet.me/.well-known/host-meta", _, _, _) do
+ def get("https://squeet.me/.well-known/host-meta", _, _, _) do
{:ok,
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
end
@@ -806,7 +798,7 @@ defmodule HttpRequestMock do
{:ok, %Tesla.Env{status: 200, body: "", headers: [{"content-type", "application/jrd+json"}]}}
end
- def get("http://framatube.org/.well-known/host-meta", _, _, _) do
+ def get("https://framatube.org/.well-known/host-meta", _, _, _) do
{:ok,
%Tesla.Env{
status: 200,
@@ -815,7 +807,7 @@ defmodule HttpRequestMock do
end
def get(
- "http://framatube.org/main/xrd?uri=acct:framasoft@framatube.org",
+ "https://framatube.org/main/xrd?uri=acct:framasoft@framatube.org",
_,
_,
[{"accept", "application/xrd+xml,application/jrd+json"}]
@@ -850,7 +842,7 @@ defmodule HttpRequestMock do
}}
end
- def get("http://status.alpicola.com/.well-known/host-meta", _, _, _) do
+ def get("https://status.alpicola.com/.well-known/host-meta", _, _, _) do
{:ok,
%Tesla.Env{
status: 200,
@@ -858,7 +850,7 @@ defmodule HttpRequestMock do
}}
end
- def get("http://macgirvin.com/.well-known/host-meta", _, _, _) do
+ def get("https://macgirvin.com/.well-known/host-meta", _, _, _) do
{:ok,
%Tesla.Env{
status: 200,
@@ -866,7 +858,7 @@ defmodule HttpRequestMock do
}}
end
- def get("http://gerzilla.de/.well-known/host-meta", _, _, _) do
+ def get("https://gerzilla.de/.well-known/host-meta", _, _, _) do
{:ok,
%Tesla.Env{
status: 200,