Merge remote-tracking branch 'pleroma/develop' into admin-api-users-sort
This commit is contained in:
commit
deb3f91136
360 changed files with 8296 additions and 2872 deletions
|
|
@ -3,6 +3,7 @@
|
|||
"type": "Create",
|
||||
"object": {
|
||||
"type": "Note",
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"content": "It's a note"
|
||||
},
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
|
|
|
|||
80
test/fixtures/bridgy/actor.json
vendored
Normal file
80
test/fixtures/bridgy/actor.json
vendored
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
{
|
||||
"id": "https://fed.brid.gy/jk.nipponalba.scot",
|
||||
"url": "https://fed.brid.gy/r/https://jk.nipponalba.scot",
|
||||
"urls": [
|
||||
{
|
||||
"value": "https://jk.nipponalba.scot"
|
||||
},
|
||||
{
|
||||
"value": "https://social.nipponalba.scot/jk"
|
||||
},
|
||||
{
|
||||
"value": "https://px.nipponalba.scot/jk"
|
||||
}
|
||||
],
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
"type": "Person",
|
||||
"name": "J K 🇯🇵🏴",
|
||||
"image": [
|
||||
{
|
||||
"url": "https://jk.nipponalba.scot/images/profile.jpg",
|
||||
"type": "Image",
|
||||
"name": "profile picture"
|
||||
}
|
||||
],
|
||||
"tag": [
|
||||
{
|
||||
"type": "Tag",
|
||||
"name": "Craft Beer"
|
||||
},
|
||||
{
|
||||
"type": "Tag",
|
||||
"name": "Single Malt Whisky"
|
||||
},
|
||||
{
|
||||
"type": "Tag",
|
||||
"name": "Homebrewing"
|
||||
},
|
||||
{
|
||||
"type": "Tag",
|
||||
"name": "Scottish Politics"
|
||||
},
|
||||
{
|
||||
"type": "Tag",
|
||||
"name": "Scottish History"
|
||||
},
|
||||
{
|
||||
"type": "Tag",
|
||||
"name": "Japanese History"
|
||||
},
|
||||
{
|
||||
"type": "Tag",
|
||||
"name": "Tech"
|
||||
},
|
||||
{
|
||||
"type": "Tag",
|
||||
"name": "Veganism"
|
||||
},
|
||||
{
|
||||
"type": "Tag",
|
||||
"name": "Cooking"
|
||||
}
|
||||
],
|
||||
"icon": [
|
||||
{
|
||||
"url": "https://jk.nipponalba.scot/images/profile.jpg",
|
||||
"type": "Image",
|
||||
"name": "profile picture"
|
||||
}
|
||||
],
|
||||
"preferredUsername": "jk.nipponalba.scot",
|
||||
"summary": "",
|
||||
"publicKey": {
|
||||
"id": "jk.nipponalba.scot",
|
||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdarxwzxnNbJ2hneWOYHkYJowk\npyigQtxlUd0VjgSQHwxU9kWqfbrHBVADyTtcqi/4dAzQd3UnCI1TPNnn4LPZY9PW\noiWd3Zl1/EfLFxO7LU9GS7fcSLQkyj5JNhSlN3I8QPudZbybrgRDVZYooDe1D+52\n5KLGqC2ajrIVOiDRTQIDAQAB\n-----END PUBLIC KEY-----"
|
||||
},
|
||||
"inbox": "https://fed.brid.gy/jk.nipponalba.scot/inbox",
|
||||
"outbox": "https://fed.brid.gy/jk.nipponalba.scot/outbox",
|
||||
"following": "https://fed.brid.gy/jk.nipponalba.scot/following",
|
||||
"followers": "https://fed.brid.gy/jk.nipponalba.scot/followers"
|
||||
}
|
||||
5
test/fixtures/config/temp.exported_from_db.secret.exs
vendored
Normal file
5
test/fixtures/config/temp.exported_from_db.secret.exs
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import Config
|
||||
|
||||
config :pleroma, exported_config_merged: true
|
||||
|
||||
config :pleroma, :first_setting, key: "new value"
|
||||
2
test/fixtures/config/temp.secret.exs
vendored
2
test/fixtures/config/temp.secret.exs
vendored
|
|
@ -2,7 +2,7 @@
|
|||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
use Mix.Config
|
||||
import Config
|
||||
|
||||
config :pleroma, :first_setting, key: "value", key2: [Pleroma.Repo]
|
||||
|
||||
|
|
|
|||
39
test/fixtures/mastodon/collections/featured.json
vendored
Normal file
39
test/fixtures/mastodon/collections/featured.json
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://{{domain}}/schemas/litepub-0.1.jsonld",
|
||||
{
|
||||
"@language": "und"
|
||||
}
|
||||
],
|
||||
"id": "https://{{domain}}/users/{{nickname}}/collections/featured",
|
||||
"orderedItems": [
|
||||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://{{domain}}/schemas/litepub-0.1.jsonld",
|
||||
{
|
||||
"@language": "und"
|
||||
}
|
||||
],
|
||||
"actor": "https://{{domain}}/users/{{nickname}}",
|
||||
"attachment": [],
|
||||
"attributedTo": "https://{{domain}}/users/{{nickname}}",
|
||||
"cc": [
|
||||
"https://{{domain}}/users/{{nickname}}/followers"
|
||||
],
|
||||
"content": "",
|
||||
"id": "https://{{domain}}/objects/{{object_id}}",
|
||||
"published": "2021-02-12T15:13:43.915429Z",
|
||||
"sensitive": false,
|
||||
"source": "",
|
||||
"summary": "",
|
||||
"tag": [],
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"type": "Note"
|
||||
}
|
||||
],
|
||||
"type": "OrderedCollection"
|
||||
}
|
||||
2
test/fixtures/modules/good_mrf.ex
vendored
2
test/fixtures/modules/good_mrf.ex
vendored
|
|
@ -1,5 +1,5 @@
|
|||
defmodule Fixtures.Modules.GoodMRF do
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@impl true
|
||||
def filter(a), do: {:ok, a}
|
||||
|
|
|
|||
47
test/fixtures/statuses/masto-note.json
vendored
Normal file
47
test/fixtures/statuses/masto-note.json
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
{
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"sensitive": "as:sensitive",
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"votersCount": "toot:votersCount"
|
||||
}
|
||||
],
|
||||
"id": "https://example.com/users/{{nickname}}/statuses/{{status_id}}",
|
||||
"type": "Note",
|
||||
"summary": null,
|
||||
"inReplyTo": null,
|
||||
"published": "2021-02-24T12:40:49Z",
|
||||
"url": "https://example.com/@{{nickname}}/{{status_id}}",
|
||||
"attributedTo": "https://example.com/users/{{nickname}}",
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"cc": [
|
||||
"https://example.com/users/{{nickname}}/followers"
|
||||
],
|
||||
"sensitive": false,
|
||||
"atomUri": "https://example.com/users/{{nickname}}/statuses/{{status_id}}",
|
||||
"inReplyToAtomUri": null,
|
||||
"conversation": "tag:example.com,2021-02-24:objectId=15:objectType=Conversation",
|
||||
"content": "<p></p>",
|
||||
"contentMap": {
|
||||
"en": "<p></p>"
|
||||
},
|
||||
"attachment": [],
|
||||
"tag": [],
|
||||
"replies": {
|
||||
"id": "https://example.com/users/{{nickname}}/statuses/{{status_id}}/replies",
|
||||
"type": "Collection",
|
||||
"first": {
|
||||
"type": "CollectionPage",
|
||||
"next": "https://example.com/users/{{nickname}}/statuses/{{status_id}}/replies?only_other_accounts=true&page=true",
|
||||
"partOf": "https://example.com/users/{{nickname}}/statuses/{{status_id}}/replies",
|
||||
"items": []
|
||||
}
|
||||
}
|
||||
}
|
||||
27
test/fixtures/statuses/note.json
vendored
Normal file
27
test/fixtures/statuses/note.json
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://example.com/schemas/litepub-0.1.jsonld",
|
||||
{
|
||||
"@language": "und"
|
||||
}
|
||||
],
|
||||
"actor": "https://example.com/users/{{nickname}}",
|
||||
"attachment": [],
|
||||
"attributedTo": "https://example.com/users/{{nickname}}",
|
||||
"cc": [
|
||||
"https://example.com/users/{{nickname}}/followers"
|
||||
],
|
||||
"content": "Content",
|
||||
"context": "https://example.com/contexts/e4b180e1-7403-477f-aeb4-de57e7a3fe7f",
|
||||
"conversation": "https://example.com/contexts/e4b180e1-7403-477f-aeb4-de57e7a3fe7f",
|
||||
"id": "https://example.com/objects/{{object_id}}",
|
||||
"published": "2019-12-15T22:00:05.279583Z",
|
||||
"sensitive": false,
|
||||
"summary": "",
|
||||
"tag": [],
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"type": "Note"
|
||||
}
|
||||
49
test/fixtures/tesla_mock/emoji-in-summary.json
vendored
Normal file
49
test/fixtures/tesla_mock/emoji-in-summary.json
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://patch.cx/schemas/litepub-0.1.jsonld",
|
||||
{
|
||||
"@language": "und"
|
||||
}
|
||||
],
|
||||
"actor": "https://patch.cx/users/rin",
|
||||
"attachment": [],
|
||||
"attributedTo": "https://patch.cx/users/rin",
|
||||
"cc": [
|
||||
"https://patch.cx/users/rin/followers"
|
||||
],
|
||||
"content": ":joker_disapprove: <br><br>just grabbing a test fixture, nevermind me",
|
||||
"context": "https://patch.cx/contexts/2c3ce4b4-18b1-4b1a-8965-3932027b5326",
|
||||
"conversation": "https://patch.cx/contexts/2c3ce4b4-18b1-4b1a-8965-3932027b5326",
|
||||
"id": "https://patch.cx/objects/a399c28e-c821-4820-bc3e-4afeb044c16f",
|
||||
"published": "2021-03-22T16:54:46.461939Z",
|
||||
"sensitive": null,
|
||||
"source": ":joker_disapprove: \r\n\r\njust grabbing a test fixture, nevermind me",
|
||||
"summary": ":joker_smile: ",
|
||||
"tag": [
|
||||
{
|
||||
"icon": {
|
||||
"type": "Image",
|
||||
"url": "https://patch.cx/emoji/custom/joker_disapprove.png"
|
||||
},
|
||||
"id": "https://patch.cx/emoji/custom/joker_disapprove.png",
|
||||
"name": ":joker_disapprove:",
|
||||
"type": "Emoji",
|
||||
"updated": "1970-01-01T00:00:00Z"
|
||||
},
|
||||
{
|
||||
"icon": {
|
||||
"type": "Image",
|
||||
"url": "https://patch.cx/emoji/custom/joker_smile.png"
|
||||
},
|
||||
"id": "https://patch.cx/emoji/custom/joker_smile.png",
|
||||
"name": ":joker_smile:",
|
||||
"type": "Emoji",
|
||||
"updated": "1970-01-01T00:00:00Z"
|
||||
}
|
||||
],
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"type": "Note"
|
||||
}
|
||||
17
test/fixtures/tesla_mock/lemmy-page.json
vendored
Normal file
17
test/fixtures/tesla_mock/lemmy-page.json
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"commentsEnabled": true,
|
||||
"sensitive": false,
|
||||
"stickied": false,
|
||||
"attributedTo": "https://enterprise.lemmy.ml/u/nutomic",
|
||||
"summary": "Hello Federation!",
|
||||
"url": "https://enterprise.lemmy.ml/pictrs/image/US52d9DPvf.jpg",
|
||||
"image": {
|
||||
"type": "Image",
|
||||
"url": "https://enterprise.lemmy.ml/pictrs/image/lwFAcXHUjS.jpg"
|
||||
},
|
||||
"published": "2020-09-14T15:03:11.909105+00:00",
|
||||
"to": "https://enterprise.lemmy.ml/c/main",
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
"id": "https://enterprise.lemmy.ml/post/3",
|
||||
"type": "Page"
|
||||
}
|
||||
27
test/fixtures/tesla_mock/lemmy-user.json
vendored
Normal file
27
test/fixtures/tesla_mock/lemmy-user.json
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"publicKey": {
|
||||
"id": "https://enterprise.lemmy.ml/u/nutomic#main-key",
|
||||
"owner": "https://enterprise.lemmy.ml/u/nutomic",
|
||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvfwAYPxp1gOk2HcCRoUd\nupoecvmnpzRc5Gu6/N3YQyOyRsrYuiYLNQq2cgM3kcU80ZeEetkwkYgXkRJOKu/b\nBWb7i1zt2tdr5k6lUdW8dfCyjht8ooFPQdov8J3QYHfgBHyUYxuCNfSujryxx2wu\nLQcdjRQa5NIWcomSO8OXmCF5/Yhg2XWCbtnlxEq6Y+AFddr1mAlTOy5pBr5d+xZz\njLw/U3CioNJ79yGi/sJhgp6IyJqtUSoN3b4BgRIEts2QVvn44W1rQy9wCbRYQrO1\nBcB9Wel4k3rJJK8uHg+LpHVMaZppkNaWGkMBhMbzr8qmIlcNWNi7cbMK/p5vyviy\nSwIDAQAB\n-----END PUBLIC KEY-----\n"
|
||||
},
|
||||
"inbox": "https://enterprise.lemmy.ml/u/nutomic/inbox",
|
||||
"preferredUsername": "Nutomic",
|
||||
"endpoints": {
|
||||
"sharedInbox": "https://enterprise.lemmy.ml/inbox"
|
||||
},
|
||||
"summary": "some bio",
|
||||
"icon": {
|
||||
"type": "Image",
|
||||
"url": "https://enterprise.lemmy.ml/pictrs/image/F6Z7QcWZRJ.jpg"
|
||||
},
|
||||
"image": {
|
||||
"type": "Image",
|
||||
"url": "https://enterprise.lemmy.ml:/pictrs/image/Q79N9oCDEG.png"
|
||||
},
|
||||
"published": "2020-09-14T14:54:53.080949+00:00",
|
||||
"updated": "2020-10-14T10:58:28.139178+00:00",
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
"id": "https://enterprise.lemmy.ml/u/nutomic",
|
||||
"type": "Person",
|
||||
"name": "nutomic"
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
<Link rel="lrdd" template="https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource={uri}" type="application/xrd+xml" />
|
||||
</XRD>
|
||||
18
test/fixtures/users_mock/masto_featured.json
vendored
Normal file
18
test/fixtures/users_mock/masto_featured.json
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
{
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"sensitive": "as:sensitive",
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"votersCount": "toot:votersCount"
|
||||
}
|
||||
],
|
||||
"id": "https://{{domain}}/users/{{nickname}}/collections/featured",
|
||||
"type": "OrderedCollection",
|
||||
"totalItems": 0,
|
||||
"orderedItems": []
|
||||
}
|
||||
42
test/fixtures/users_mock/user.json
vendored
Normal file
42
test/fixtures/users_mock/user.json
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://example.com/schemas/litepub-0.1.jsonld",
|
||||
{
|
||||
"@language": "und"
|
||||
}
|
||||
],
|
||||
"attachment": [],
|
||||
"endpoints": {
|
||||
"oauthAuthorizationEndpoint": "https://example.com/oauth/authorize",
|
||||
"oauthRegistrationEndpoint": "https://example.com/api/v1/apps",
|
||||
"oauthTokenEndpoint": "https://example.com/oauth/token",
|
||||
"sharedInbox": "https://example.com/inbox"
|
||||
},
|
||||
"followers": "https://example.com/users/{{nickname}}/followers",
|
||||
"following": "https://example.com/users/{{nickname}}/following",
|
||||
"icon": {
|
||||
"type": "Image",
|
||||
"url": "https://example.com/media/4e914f5b84e4a259a3f6c2d2edc9ab642f2ab05f3e3d9c52c81fc2d984b3d51e.jpg"
|
||||
},
|
||||
"id": "https://example.com/users/{{nickname}}",
|
||||
"image": {
|
||||
"type": "Image",
|
||||
"url": "https://example.com/media/f739efddefeee49c6e67e947c4811fdc911785c16ae43da4c3684051fbf8da6a.jpg?name=f739efddefeee49c6e67e947c4811fdc911785c16ae43da4c3684051fbf8da6a.jpg"
|
||||
},
|
||||
"inbox": "https://example.com/users/{{nickname}}/inbox",
|
||||
"manuallyApprovesFollowers": false,
|
||||
"name": "{{nickname}}",
|
||||
"outbox": "https://example.com/users/{{nickname}}/outbox",
|
||||
"preferredUsername": "{{nickname}}",
|
||||
"publicKey": {
|
||||
"id": "https://example.com/users/{{nickname}}#main-key",
|
||||
"owner": "https://example.com/users/{{nickname}}",
|
||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5DLtwGXNZElJyxFGfcVc\nXANhaMadj/iYYQwZjOJTV9QsbtiNBeIK54PJrYuU0/0YIdrvS1iqheX5IwXRhcwa\nhm3ZyLz7XeN9st7FBni4BmZMBtMpxAuYuu5p/jbWy13qAiYOhPreCx0wrWgm/lBD\n9mkgaxIxPooBE0S4ZWEJIDIV1Vft3AWcRUyWW1vIBK0uZzs6GYshbQZB952S0yo4\nFzI1hABGHncH8UvuFauh4EZ8tY7/X5I0pGRnDOcRN1dAht5w5yTA+6r5kebiFQjP\nIzN/eCO/a9Flrj9YGW7HDNtjSOH0A31PLRGlJtJO3yK57dnf5ppyCZGfL4emShQo\ncQIDAQAB\n-----END PUBLIC KEY-----\n\n"
|
||||
},
|
||||
"featured": "https://example.com/users/{{nickname}}/collections/featured",
|
||||
"summary": "your friendly neighborhood pleroma developer<br>I like cute things and distributed systems, and really hate delete and redrafts",
|
||||
"tag": [],
|
||||
"type": "Person",
|
||||
"url": "https://example.com/users/{{nickname}}"
|
||||
}
|
||||
BIN
test/fixtures/video.mp4
vendored
Normal file
BIN
test/fixtures/video.mp4
vendored
Normal file
Binary file not shown.
|
|
@ -188,15 +188,46 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
assert File.exists?(temp_file)
|
||||
{:ok, file} = File.read(temp_file)
|
||||
|
||||
header =
|
||||
if Code.ensure_loaded?(Config.Reader) do
|
||||
"import Config"
|
||||
else
|
||||
"use Mix.Config"
|
||||
end
|
||||
|
||||
assert file ==
|
||||
"#{header}\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n attachment_links: false,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n"
|
||||
"import Config\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n attachment_links: false,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n"
|
||||
end
|
||||
end
|
||||
|
||||
describe "migrate_from_db/1" do
|
||||
setup do: clear_config(:configurable_from_database, true)
|
||||
|
||||
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")
|
||||
|
||||
on_exit(fn -> File.rm!(file_path) end)
|
||||
|
||||
[file_path: file_path]
|
||||
end
|
||||
|
||||
test "with path parameter", %{file_path: file_path} do
|
||||
MixTask.run(["migrate_from_db", "--env", "temp", "--path", Path.dirname(file_path)])
|
||||
|
||||
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
|
||||
clear_config(:release, true)
|
||||
clear_config(:config_path, file_path)
|
||||
|
||||
MixTask.run(["migrate_from_db", "--env", "temp"])
|
||||
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ defmodule Mix.Tasks.Pleroma.Ecto.MigrateTest do
|
|||
|
||||
assert capture_log(fn ->
|
||||
Mix.Tasks.Pleroma.Ecto.Migrate.run()
|
||||
end) =~ "[info] Already up"
|
||||
end) =~ "[info] Migrations already up"
|
||||
|
||||
Logger.configure(level: level)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ defmodule Pleroma.Activity.Ir.TopicsTest do
|
|||
|
||||
require Pleroma.Constants
|
||||
|
||||
import Mock
|
||||
|
||||
describe "poll answer" do
|
||||
test "produce no topics" do
|
||||
activity = %Activity{object: %Object{data: %{"type" => "Answer"}}}
|
||||
|
|
@ -77,14 +79,13 @@ defmodule Pleroma.Activity.Ir.TopicsTest do
|
|||
refute Enum.member?(topics, "public:local:media")
|
||||
end
|
||||
|
||||
test "converts tags to hash tags", %{activity: %{object: %{data: data} = object} = activity} do
|
||||
tagged_data = Map.put(data, "tag", ["foo", "bar"])
|
||||
activity = %{activity | object: %{object | data: tagged_data}}
|
||||
test "converts tags to hash tags", %{activity: activity} do
|
||||
with_mock(Object, [:passthrough], hashtags: fn _ -> ["foo", "bar"] end) do
|
||||
topics = Topics.get_activity_topics(activity)
|
||||
|
||||
topics = Topics.get_activity_topics(activity)
|
||||
|
||||
assert Enum.member?(topics, "hashtag:foo")
|
||||
assert Enum.member?(topics, "hashtag:bar")
|
||||
assert Enum.member?(topics, "hashtag:foo")
|
||||
assert Enum.member?(topics, "hashtag:bar")
|
||||
end
|
||||
end
|
||||
|
||||
test "only converts strings to hash tags", %{
|
||||
|
|
|
|||
|
|
@ -123,7 +123,8 @@ defmodule Pleroma.ActivityTest do
|
|||
"type" => "Note",
|
||||
"content" => "find me!",
|
||||
"id" => "http://mastodon.example.org/users/admin/objects/1",
|
||||
"attributedTo" => "http://mastodon.example.org/users/admin"
|
||||
"attributedTo" => "http://mastodon.example.org/users/admin",
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
},
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
}
|
||||
|
|
@ -132,6 +133,7 @@ defmodule Pleroma.ActivityTest do
|
|||
{:ok, japanese_activity} = Pleroma.Web.CommonAPI.post(user, %{status: "更新情報"})
|
||||
{:ok, job} = Pleroma.Web.Federator.incoming_ap_doc(params)
|
||||
{:ok, remote_activity} = ObanHelpers.perform(job)
|
||||
remote_activity = Activity.get_by_id_with_object(remote_activity.id)
|
||||
|
||||
%{
|
||||
japanese_activity: japanese_activity,
|
||||
|
|
@ -254,4 +256,26 @@ defmodule Pleroma.ActivityTest do
|
|||
|
||||
assert %{id: ^id} = Activity.get_by_object_ap_id_with_object(obj_id)
|
||||
end
|
||||
|
||||
test "add_by_params_query/3" do
|
||||
user = insert(:user)
|
||||
|
||||
note = insert(:note_activity, user: user)
|
||||
|
||||
insert(:add_activity, user: user, note: note)
|
||||
insert(:add_activity, user: user, note: note)
|
||||
insert(:add_activity, user: user)
|
||||
|
||||
assert Repo.aggregate(Activity, :count, :id) == 4
|
||||
|
||||
add_query =
|
||||
Activity.add_by_params_query(note.data["object"], user.ap_id, user.featured_address)
|
||||
|
||||
assert Repo.aggregate(add_query, :count, :id) == 2
|
||||
|
||||
Repo.delete_all(add_query)
|
||||
assert Repo.aggregate(add_query, :count, :id) == 0
|
||||
|
||||
assert Repo.aggregate(Activity, :count, :id) == 2
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -35,13 +35,13 @@ defmodule Pleroma.ApplicationRequirementsTest do
|
|||
setup do: clear_config([:welcome])
|
||||
setup do: clear_config([Pleroma.Emails.Mailer])
|
||||
|
||||
test "raises if welcome email enabled but mail disabled" do
|
||||
test "warns if welcome email enabled but mail disabled" do
|
||||
clear_config([:welcome, :email, :enabled], true)
|
||||
clear_config([Pleroma.Emails.Mailer, :enabled], false)
|
||||
|
||||
assert_raise Pleroma.ApplicationRequirements.VerifyError, "The mail disabled.", fn ->
|
||||
capture_log(&Pleroma.ApplicationRequirements.verify!/0)
|
||||
end
|
||||
assert capture_log(fn ->
|
||||
assert Pleroma.ApplicationRequirements.verify!() == :ok
|
||||
end) =~ "Welcome emails will NOT be sent"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -57,15 +57,13 @@ defmodule Pleroma.ApplicationRequirementsTest do
|
|||
|
||||
setup do: clear_config([:instance, :account_activation_required])
|
||||
|
||||
test "raises if account confirmation is required but mailer isn't enable" do
|
||||
test "warns if account confirmation is required but mailer isn't enabled" do
|
||||
clear_config([:instance, :account_activation_required], true)
|
||||
clear_config([Pleroma.Emails.Mailer, :enabled], false)
|
||||
|
||||
assert_raise Pleroma.ApplicationRequirements.VerifyError,
|
||||
"Account activation enabled, but Mailer is disabled. Cannot send confirmation emails.",
|
||||
fn ->
|
||||
capture_log(&Pleroma.ApplicationRequirements.verify!/0)
|
||||
end
|
||||
assert capture_log(fn ->
|
||||
assert Pleroma.ApplicationRequirements.verify!() == :ok
|
||||
end) =~ "Users will NOT be able to confirm their accounts"
|
||||
end
|
||||
|
||||
test "doesn't do anything if account confirmation is disabled" do
|
||||
|
|
|
|||
|
|
@ -146,4 +146,14 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
|
|||
"Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings"
|
||||
end
|
||||
end
|
||||
|
||||
test "check_old_chat_shoutbox/0" do
|
||||
clear_config([:instance, :chat_limit], 1_000)
|
||||
clear_config([:chat, :enabled], true)
|
||||
|
||||
assert capture_log(fn ->
|
||||
DeprecationWarnings.check_old_chat_shoutbox()
|
||||
end) =~
|
||||
"Your config is using the old namespace for the Shoutbox configuration."
|
||||
end
|
||||
end
|
||||
|
|
|
|||
45
test/pleroma/config/release_runtime_provider_test.exs
Normal file
45
test/pleroma/config/release_runtime_provider_test.exs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
defmodule Pleroma.Config.ReleaseRuntimeProviderTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias Pleroma.Config.ReleaseRuntimeProvider
|
||||
|
||||
describe "load/2" do
|
||||
test "loads release defaults config and warns about non-existent runtime config" do
|
||||
ExUnit.CaptureIO.capture_io(fn ->
|
||||
merged = ReleaseRuntimeProvider.load([], [])
|
||||
assert merged == Pleroma.Config.Holder.release_defaults()
|
||||
end) =~
|
||||
"!!! Config path is not declared! Please ensure it exists and that PLEROMA_CONFIG_PATH is unset or points to an existing file"
|
||||
end
|
||||
|
||||
test "merged runtime config" do
|
||||
merged =
|
||||
ReleaseRuntimeProvider.load([], config_path: "test/fixtures/config/temp.secret.exs")
|
||||
|
||||
assert merged[:pleroma][:first_setting] == [key: "value", key2: [Pleroma.Repo]]
|
||||
assert merged[:pleroma][:second_setting] == [key: "value2", key2: ["Activity"]]
|
||||
end
|
||||
|
||||
test "merged exported config" do
|
||||
ExUnit.CaptureIO.capture_io(fn ->
|
||||
merged =
|
||||
ReleaseRuntimeProvider.load([],
|
||||
exported_config_path: "test/fixtures/config/temp.exported_from_db.secret.exs"
|
||||
)
|
||||
|
||||
assert merged[:pleroma][:exported_config_merged]
|
||||
end) =~
|
||||
"!!! Config path is not declared! Please ensure it exists and that PLEROMA_CONFIG_PATH is unset or points to an existing file"
|
||||
end
|
||||
|
||||
test "runtime config is merged with exported config" do
|
||||
merged =
|
||||
ReleaseRuntimeProvider.load([],
|
||||
config_path: "test/fixtures/config/temp.secret.exs",
|
||||
exported_config_path: "test/fixtures/config/temp.exported_from_db.secret.exs"
|
||||
)
|
||||
|
||||
assert merged[:pleroma][:first_setting] == [key2: [Pleroma.Repo], key: "new value"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -93,8 +93,8 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
end
|
||||
|
||||
test "on reboot time key" do
|
||||
clear_config(:chat)
|
||||
insert(:config, key: :chat, value: [enabled: false])
|
||||
clear_config(:shout)
|
||||
insert(:config, key: :shout, value: [enabled: false])
|
||||
assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
|
||||
end
|
||||
|
||||
|
|
@ -105,10 +105,10 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
end
|
||||
|
||||
test "don't restart pleroma on reboot time key and subkey if there is false flag" do
|
||||
clear_config(:chat)
|
||||
clear_config(:shout)
|
||||
clear_config(Pleroma.Captcha)
|
||||
|
||||
insert(:config, key: :chat, value: [enabled: false])
|
||||
insert(:config, key: :shout, value: [enabled: false])
|
||||
insert(:config, key: Pleroma.Captcha, value: [seconds_valid: 60])
|
||||
|
||||
refute String.contains?(
|
||||
|
|
|
|||
|
|
@ -1,79 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
defmodule Pleroma.EarmarkRendererTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
test "Paragraph" do
|
||||
code = ~s[Hello\n\nWorld!]
|
||||
result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
|
||||
assert result == "<p>Hello</p><p>World!</p>"
|
||||
end
|
||||
|
||||
test "raw HTML" do
|
||||
code = ~s[<a href="http://example.org/">OwO</a><!-- what's this?-->]
|
||||
result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
|
||||
assert result == "<p>#{code}</p>"
|
||||
end
|
||||
|
||||
test "rulers" do
|
||||
code = ~s[before\n\n-----\n\nafter]
|
||||
result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
|
||||
assert result == "<p>before</p><hr /><p>after</p>"
|
||||
end
|
||||
|
||||
test "headings" do
|
||||
code = ~s[# h1\n## h2\n### h3\n]
|
||||
result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
|
||||
assert result == ~s[<h1>h1</h1><h2>h2</h2><h3>h3</h3>]
|
||||
end
|
||||
|
||||
test "blockquote" do
|
||||
code = ~s[> whoms't are you quoting?]
|
||||
result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
|
||||
assert result == "<blockquote><p>whoms’t are you quoting?</p></blockquote>"
|
||||
end
|
||||
|
||||
test "code" do
|
||||
code = ~s[`mix`]
|
||||
result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
|
||||
assert result == ~s[<p><code class="inline">mix</code></p>]
|
||||
|
||||
code = ~s[``mix``]
|
||||
result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
|
||||
assert result == ~s[<p><code class="inline">mix</code></p>]
|
||||
|
||||
code = ~s[```\nputs "Hello World"\n```]
|
||||
result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
|
||||
assert result == ~s[<pre><code class="">puts "Hello World"</code></pre>]
|
||||
end
|
||||
|
||||
test "lists" do
|
||||
code = ~s[- one\n- two\n- three\n- four]
|
||||
result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
|
||||
assert result == "<ul><li>one</li><li>two</li><li>three</li><li>four</li></ul>"
|
||||
|
||||
code = ~s[1. one\n2. two\n3. three\n4. four\n]
|
||||
result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
|
||||
assert result == "<ol><li>one</li><li>two</li><li>three</li><li>four</li></ol>"
|
||||
end
|
||||
|
||||
test "delegated renderers" do
|
||||
code = ~s[a<br/>b]
|
||||
result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
|
||||
assert result == "<p>#{code}</p>"
|
||||
|
||||
code = ~s[*aaaa~*]
|
||||
result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
|
||||
assert result == ~s[<p><em>aaaa~</em></p>]
|
||||
|
||||
code = ~s[**aaaa~**]
|
||||
result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
|
||||
assert result == ~s[<p><strong>aaaa~</strong></p>]
|
||||
|
||||
# strikethrought
|
||||
code = ~s[<del>aaaa~</del>]
|
||||
result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
|
||||
assert result == ~s[<p><del>aaaa~</del></p>]
|
||||
end
|
||||
end
|
||||
|
|
@ -6,10 +6,10 @@ defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.RecipientsTest do
|
|||
alias Pleroma.EctoType.ActivityPub.ObjectValidators.Recipients
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
test "it asserts that all elements of the list are object ids" do
|
||||
test "it only keeps elements that are valid object ids" do
|
||||
list = ["https://lain.com/users/lain", "invalid"]
|
||||
|
||||
assert :error == Recipients.cast(list)
|
||||
assert {:ok, ["https://lain.com/users/lain"]} == Recipients.cast(list)
|
||||
end
|
||||
|
||||
test "it works with a list" do
|
||||
|
|
|
|||
17
test/pleroma/hashtag_test.exs
Normal file
17
test/pleroma/hashtag_test.exs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.HashtagTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Hashtag
|
||||
|
||||
describe "changeset validations" do
|
||||
test "ensure non-blank :name" do
|
||||
changeset = Hashtag.changeset(%Hashtag{}, %{name: ""})
|
||||
|
||||
assert {:name, {"can't be blank", [validation: :required]}} in changeset.errors
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -34,24 +34,32 @@ defmodule Pleroma.HTTP.RequestBuilderTest do
|
|||
|
||||
describe "add_param/4" do
|
||||
test "add file parameter" do
|
||||
%Request{
|
||||
body: %Tesla.Multipart{
|
||||
boundary: _,
|
||||
content_type_params: [],
|
||||
parts: [
|
||||
%Tesla.Multipart.Part{
|
||||
body: %File.Stream{
|
||||
line_or_bytes: 2048,
|
||||
modes: [:raw, :read_ahead, :read, :binary],
|
||||
path: "some-path/filename.png",
|
||||
raw: true
|
||||
},
|
||||
dispositions: [name: "filename.png", filename: "filename.png"],
|
||||
headers: []
|
||||
}
|
||||
]
|
||||
}
|
||||
} = RequestBuilder.add_param(%Request{}, :file, "filename.png", "some-path/filename.png")
|
||||
assert match?(
|
||||
%Request{
|
||||
body: %Tesla.Multipart{
|
||||
boundary: _,
|
||||
content_type_params: [],
|
||||
parts: [
|
||||
%Tesla.Multipart.Part{
|
||||
body: %File.Stream{
|
||||
line_or_bytes: 2048,
|
||||
modes: [:raw, :read_ahead, :binary],
|
||||
path: "some-path/filename.png",
|
||||
raw: true
|
||||
},
|
||||
dispositions: [name: "filename.png", filename: "filename.png"],
|
||||
headers: []
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
RequestBuilder.add_param(
|
||||
%Request{},
|
||||
:file,
|
||||
"filename.png",
|
||||
"some-path/filename.png"
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
test "add key to body" do
|
||||
|
|
|
|||
|
|
@ -624,6 +624,8 @@ defmodule Pleroma.NotificationTest do
|
|||
"actor" => user.ap_id,
|
||||
"object" => %{
|
||||
"type" => "Note",
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"content" => "message with a Mention tag, but no explicit tagging",
|
||||
"tag" => [
|
||||
%{
|
||||
|
|
@ -655,6 +657,9 @@ defmodule Pleroma.NotificationTest do
|
|||
"actor" => user.ap_id,
|
||||
"object" => %{
|
||||
"type" => "Note",
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"cc" => [other_user.ap_id],
|
||||
"content" => "hi everyone",
|
||||
"attributedTo" => user.ap_id
|
||||
}
|
||||
|
|
@ -951,6 +956,7 @@ defmodule Pleroma.NotificationTest do
|
|||
"cc" => [],
|
||||
"object" => %{
|
||||
"type" => "Note",
|
||||
"id" => remote_user.ap_id <> "/objects/test",
|
||||
"content" => "Hello!",
|
||||
"tag" => [
|
||||
%{
|
||||
|
|
|
|||
|
|
@ -66,6 +66,14 @@ defmodule Pleroma.Object.FetcherTest do
|
|||
%Tesla.Env{
|
||||
status: 500
|
||||
}
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://stereophonic.space/objects/02997b83-3ea7-4b63-94af-ef3aa2d4ed17"
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 500
|
||||
}
|
||||
end)
|
||||
|
||||
:ok
|
||||
|
|
@ -124,8 +132,7 @@ defmodule Pleroma.Object.FetcherTest do
|
|||
{:ok, object} =
|
||||
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
|
||||
|
||||
assert activity = Activity.get_create_by_object_ap_id(object.data["id"])
|
||||
assert activity.data["id"]
|
||||
assert _activity = Activity.get_create_by_object_ap_id(object.data["id"])
|
||||
|
||||
{:ok, object_again} =
|
||||
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
|
||||
|
|
|
|||
|
|
@ -5,10 +5,13 @@
|
|||
defmodule Pleroma.ObjectTest do
|
||||
use Pleroma.DataCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Hashtag
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
|
|
@ -417,4 +420,28 @@ defmodule Pleroma.ObjectTest do
|
|||
assert updated_object.data["like_count"] == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe ":hashtags association" do
|
||||
test "Hashtag records are created with Object record and updated on its change" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, %{object: object}} =
|
||||
CommonAPI.post(user, %{status: "some text #hashtag1 #hashtag2 ..."})
|
||||
|
||||
assert [%Hashtag{name: "hashtag1"}, %Hashtag{name: "hashtag2"}] =
|
||||
Enum.sort_by(object.hashtags, & &1.name)
|
||||
|
||||
{:ok, object} = Object.update_data(object, %{"tag" => []})
|
||||
|
||||
assert [] = object.hashtags
|
||||
|
||||
object = Object.get_by_id(object.id) |> Repo.preload(:hashtags)
|
||||
assert [] = object.hashtags
|
||||
|
||||
{:ok, object} = Object.update_data(object, %{"tag" => ["abc", "def"]})
|
||||
|
||||
assert [%Hashtag{name: "abc"}, %Hashtag{name: "def"}] =
|
||||
Enum.sort_by(object.hashtags, & &1.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
52
test/pleroma/repo/migrations/rename_instance_chat_test.exs
Normal file
52
test/pleroma/repo/migrations/rename_instance_chat_test.exs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
defmodule Pleroma.Repo.Migrations.RenameInstanceChatTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
import Pleroma.Tests.Helpers
|
||||
alias Pleroma.ConfigDB
|
||||
|
||||
setup do: clear_config([:instance])
|
||||
setup do: clear_config([:chat])
|
||||
setup_all do: require_migration("20200806175913_rename_instance_chat")
|
||||
|
||||
describe "up/0" do
|
||||
test "migrates chat settings to shout", %{migration: migration} do
|
||||
insert(:config, group: :pleroma, key: :instance, value: [chat_limit: 6000])
|
||||
insert(:config, group: :pleroma, key: :chat, value: [enabled: true])
|
||||
|
||||
assert migration.up() == :ok
|
||||
|
||||
assert ConfigDB.get_by_params(%{group: :pleroma, key: :chat}) == nil
|
||||
assert ConfigDB.get_by_params(%{group: :pleroma, key: :instance}) == nil
|
||||
|
||||
assert ConfigDB.get_by_params(%{group: :pleroma, key: :shout}).value == [
|
||||
limit: 6000,
|
||||
enabled: true
|
||||
]
|
||||
end
|
||||
|
||||
test "does nothing when chat settings are not set", %{migration: migration} do
|
||||
assert migration.up() == :noop
|
||||
assert ConfigDB.get_by_params(%{group: :pleroma, key: :chat}) == nil
|
||||
assert ConfigDB.get_by_params(%{group: :pleroma, key: :shout}) == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "down/0" do
|
||||
test "migrates shout settings back to instance and chat", %{migration: migration} do
|
||||
insert(:config, group: :pleroma, key: :shout, value: [limit: 42, enabled: true])
|
||||
|
||||
assert migration.down() == :ok
|
||||
|
||||
assert ConfigDB.get_by_params(%{group: :pleroma, key: :chat}).value == [enabled: true]
|
||||
assert ConfigDB.get_by_params(%{group: :pleroma, key: :instance}).value == [chat_limit: 42]
|
||||
assert ConfigDB.get_by_params(%{group: :pleroma, key: :shout}) == nil
|
||||
end
|
||||
|
||||
test "does nothing when shout settings are not set", %{migration: migration} do
|
||||
assert migration.down() == :noop
|
||||
assert ConfigDB.get_by_params(%{group: :pleroma, key: :chat}) == nil
|
||||
assert ConfigDB.get_by_params(%{group: :pleroma, key: :instance}) == nil
|
||||
assert ConfigDB.get_by_params(%{group: :pleroma, key: :shout}) == nil
|
||||
end
|
||||
end
|
||||
end
|
||||
33
test/pleroma/upload/filter/analyze_metadata_test.exs
Normal file
33
test/pleroma/upload/filter/analyze_metadata_test.exs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Upload.Filter.AnalyzeMetadataTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
alias Pleroma.Upload.Filter.AnalyzeMetadata
|
||||
|
||||
test "adds the dimensions and blurhash for images" do
|
||||
upload = %Pleroma.Upload{
|
||||
name: "an… image.jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
tempfile: Path.absname("test/fixtures/image.jpg")
|
||||
}
|
||||
|
||||
{:ok, :filtered, meta} = AnalyzeMetadata.filter(upload)
|
||||
|
||||
assert %{width: 1024, height: 768} = meta
|
||||
assert meta.blurhash
|
||||
end
|
||||
|
||||
test "adds the dimensions for videos" do
|
||||
upload = %Pleroma.Upload{
|
||||
name: "coolvideo.mp4",
|
||||
content_type: "video/mp4",
|
||||
path: Path.absname("test/fixtures/video.mp4"),
|
||||
tempfile: Path.absname("test/fixtures/video.mp4")
|
||||
}
|
||||
|
||||
assert {:ok, :filtered, %{width: 480, height: 480}} = AnalyzeMetadata.filter(upload)
|
||||
end
|
||||
end
|
||||
|
|
@ -151,7 +151,7 @@ defmodule Pleroma.UserTest do
|
|||
test "ap_id returns the activity pub id for the user" do
|
||||
user = UserBuilder.build()
|
||||
|
||||
expected_ap_id = "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
|
||||
expected_ap_id = "#{Pleroma.Web.Endpoint.url()}/users/#{user.nickname}"
|
||||
|
||||
assert expected_ap_id == User.ap_id(user)
|
||||
end
|
||||
|
|
@ -572,6 +572,24 @@ defmodule Pleroma.UserTest do
|
|||
)
|
||||
end
|
||||
|
||||
test "it fails gracefully with invalid email config" do
|
||||
cng = User.register_changeset(%User{}, @full_user_data)
|
||||
|
||||
# Disable the mailer but enable all the things that want to send emails
|
||||
clear_config([Pleroma.Emails.Mailer, :enabled], false)
|
||||
clear_config([:instance, :account_activation_required], true)
|
||||
clear_config([:instance, :account_approval_required], true)
|
||||
clear_config([:welcome, :email, :enabled], true)
|
||||
clear_config([:welcome, :email, :sender], "lain@lain.com")
|
||||
|
||||
# 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)
|
||||
|
||||
|
|
@ -1621,9 +1639,9 @@ defmodule Pleroma.UserTest do
|
|||
follower_count: 9,
|
||||
following_count: 9001,
|
||||
is_locked: true,
|
||||
is_confirmed: false,
|
||||
is_confirmed: true,
|
||||
password_reset_pending: true,
|
||||
is_approved: false,
|
||||
is_approved: true,
|
||||
registration_reason: "ahhhhh",
|
||||
confirmation_token: "qqqq",
|
||||
domain_blocks: ["lain.com"],
|
||||
|
|
@ -1651,8 +1669,8 @@ defmodule Pleroma.UserTest do
|
|||
email: nil,
|
||||
name: nil,
|
||||
password_hash: nil,
|
||||
keys: nil,
|
||||
public_key: nil,
|
||||
keys: "RSA begin buplic key",
|
||||
public_key: "--PRIVATE KEYE--",
|
||||
avatar: %{},
|
||||
tags: [],
|
||||
last_refreshed_at: nil,
|
||||
|
|
@ -1684,6 +1702,24 @@ defmodule Pleroma.UserTest do
|
|||
} = user
|
||||
end
|
||||
|
||||
test "delete/1 purges a remote user" do
|
||||
user =
|
||||
insert(:user, %{
|
||||
name: "qqqqqqq",
|
||||
avatar: %{"a" => "b"},
|
||||
banner: %{"a" => "b"},
|
||||
local: false
|
||||
})
|
||||
|
||||
{:ok, job} = User.delete(user)
|
||||
{:ok, _} = ObanHelpers.perform(job)
|
||||
user = User.get_by_id(user.id)
|
||||
|
||||
assert user.name == nil
|
||||
assert user.avatar == %{}
|
||||
assert user.banner == %{}
|
||||
end
|
||||
|
||||
test "get_public_key_for_ap_id fetches a user that's not in the db" do
|
||||
assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
|
||||
end
|
||||
|
|
@ -2338,4 +2374,49 @@ defmodule Pleroma.UserTest do
|
|||
assert User.active_user_count(6) == 3
|
||||
assert User.active_user_count(1) == 1
|
||||
end
|
||||
|
||||
describe "pins" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
||||
[user: user, object_id: object_id_from_created_activity(user)]
|
||||
end
|
||||
|
||||
test "unique pins", %{user: user, object_id: object_id} do
|
||||
assert {:ok, %{pinned_objects: %{^object_id => pinned_at1} = pins} = updated_user} =
|
||||
User.add_pinned_object_id(user, object_id)
|
||||
|
||||
assert Enum.count(pins) == 1
|
||||
|
||||
assert {:ok, %{pinned_objects: %{^object_id => pinned_at2} = pins}} =
|
||||
User.add_pinned_object_id(updated_user, object_id)
|
||||
|
||||
assert pinned_at1 == pinned_at2
|
||||
|
||||
assert Enum.count(pins) == 1
|
||||
end
|
||||
|
||||
test "respects max_pinned_statuses limit", %{user: user, object_id: object_id} do
|
||||
clear_config([:instance, :max_pinned_statuses], 1)
|
||||
{:ok, updated} = User.add_pinned_object_id(user, object_id)
|
||||
|
||||
object_id2 = object_id_from_created_activity(user)
|
||||
|
||||
{:error, %{errors: errors}} = User.add_pinned_object_id(updated, object_id2)
|
||||
assert Keyword.has_key?(errors, :pinned_objects)
|
||||
end
|
||||
|
||||
test "remove_pinned_object_id/2", %{user: user, object_id: object_id} do
|
||||
assert {:ok, updated} = User.add_pinned_object_id(user, object_id)
|
||||
|
||||
{:ok, after_remove} = User.remove_pinned_object_id(updated, object_id)
|
||||
assert after_remove.pinned_objects == %{}
|
||||
end
|
||||
end
|
||||
|
||||
defp object_id_from_created_activity(user) do
|
||||
%{id: id} = insert(:note_activity, user: user)
|
||||
%{object: %{data: %{"id" => object_id}}} = Activity.get_by_id_with_object(id)
|
||||
object_id
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -539,7 +539,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Jason.decode!()
|
||||
|> Map.put("actor", user.ap_id)
|
||||
|> put_in(["object", "attridbutedTo"], user.ap_id)
|
||||
|> put_in(["object", "attributedTo"], user.ap_id)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -636,6 +636,186 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|> post("/inbox", non_create_data)
|
||||
|> json_response(400)
|
||||
end
|
||||
|
||||
test "accepts Add/Remove activities", %{conn: conn} do
|
||||
object_id = "c61d6733-e256-4fe1-ab13-1e369789423f"
|
||||
|
||||
status =
|
||||
File.read!("test/fixtures/statuses/note.json")
|
||||
|> String.replace("{{nickname}}", "lain")
|
||||
|> String.replace("{{object_id}}", object_id)
|
||||
|
||||
object_url = "https://example.com/objects/#{object_id}"
|
||||
|
||||
user =
|
||||
File.read!("test/fixtures/users_mock/user.json")
|
||||
|> String.replace("{{nickname}}", "lain")
|
||||
|
||||
actor = "https://example.com/users/lain"
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: ^object_url
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: status,
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url: ^actor
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: user,
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
|
||||
%{method: :get, url: "https://example.com/users/lain/collections/featured"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
"test/fixtures/users_mock/masto_featured.json"
|
||||
|> File.read!()
|
||||
|> String.replace("{{domain}}", "example.com")
|
||||
|> String.replace("{{nickname}}", "lain"),
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
end)
|
||||
|
||||
data = %{
|
||||
"id" => "https://example.com/objects/d61d6733-e256-4fe1-ab13-1e369789423f",
|
||||
"actor" => actor,
|
||||
"object" => object_url,
|
||||
"target" => "https://example.com/users/lain/collections/featured",
|
||||
"type" => "Add",
|
||||
"to" => [Pleroma.Constants.as_public()]
|
||||
}
|
||||
|
||||
assert "ok" ==
|
||||
conn
|
||||
|> assign(:valid_signature, true)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/inbox", data)
|
||||
|> json_response(200)
|
||||
|
||||
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
|
||||
assert Activity.get_by_ap_id(data["id"])
|
||||
user = User.get_cached_by_ap_id(data["actor"])
|
||||
assert user.pinned_objects[data["object"]]
|
||||
|
||||
data = %{
|
||||
"id" => "https://example.com/objects/d61d6733-e256-4fe1-ab13-1e369789423d",
|
||||
"actor" => actor,
|
||||
"object" => object_url,
|
||||
"target" => "https://example.com/users/lain/collections/featured",
|
||||
"type" => "Remove",
|
||||
"to" => [Pleroma.Constants.as_public()]
|
||||
}
|
||||
|
||||
assert "ok" ==
|
||||
conn
|
||||
|> assign(:valid_signature, true)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/inbox", data)
|
||||
|> json_response(200)
|
||||
|
||||
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
|
||||
user = refresh_record(user)
|
||||
refute user.pinned_objects[data["object"]]
|
||||
end
|
||||
|
||||
test "mastodon pin/unpin", %{conn: conn} do
|
||||
status_id = "105786274556060421"
|
||||
|
||||
status =
|
||||
File.read!("test/fixtures/statuses/masto-note.json")
|
||||
|> String.replace("{{nickname}}", "lain")
|
||||
|> String.replace("{{status_id}}", status_id)
|
||||
|
||||
status_url = "https://example.com/users/lain/statuses/#{status_id}"
|
||||
|
||||
user =
|
||||
File.read!("test/fixtures/users_mock/user.json")
|
||||
|> String.replace("{{nickname}}", "lain")
|
||||
|
||||
actor = "https://example.com/users/lain"
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: ^status_url
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: status,
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url: ^actor
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: user,
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
|
||||
%{method: :get, url: "https://example.com/users/lain/collections/featured"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
"test/fixtures/users_mock/masto_featured.json"
|
||||
|> File.read!()
|
||||
|> String.replace("{{domain}}", "example.com")
|
||||
|> String.replace("{{nickname}}", "lain"),
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
end)
|
||||
|
||||
data = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"actor" => actor,
|
||||
"object" => status_url,
|
||||
"target" => "https://example.com/users/lain/collections/featured",
|
||||
"type" => "Add"
|
||||
}
|
||||
|
||||
assert "ok" ==
|
||||
conn
|
||||
|> assign(:valid_signature, true)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/inbox", data)
|
||||
|> json_response(200)
|
||||
|
||||
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
|
||||
assert Activity.get_by_object_ap_id_with_object(data["object"])
|
||||
user = User.get_cached_by_ap_id(data["actor"])
|
||||
assert user.pinned_objects[data["object"]]
|
||||
|
||||
data = %{
|
||||
"actor" => actor,
|
||||
"object" => status_url,
|
||||
"target" => "https://example.com/users/lain/collections/featured",
|
||||
"type" => "Remove"
|
||||
}
|
||||
|
||||
assert "ok" ==
|
||||
conn
|
||||
|> assign(:valid_signature, true)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/inbox", data)
|
||||
|> json_response(200)
|
||||
|
||||
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
|
||||
assert Activity.get_by_object_ap_id_with_object(data["object"])
|
||||
user = refresh_record(user)
|
||||
refute user.pinned_objects[data["object"]]
|
||||
end
|
||||
end
|
||||
|
||||
describe "/users/:nickname/inbox" do
|
||||
|
|
@ -649,7 +829,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
test "it inserts an incoming activity into the database", %{conn: conn, data: data} do
|
||||
user = insert(:user)
|
||||
data = Map.put(data, "bcc", [user.ap_id])
|
||||
|
||||
data =
|
||||
data
|
||||
|> Map.put("bcc", [user.ap_id])
|
||||
|> Kernel.put_in(["object", "bcc"], [user.ap_id])
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -666,8 +850,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
user = insert(:user)
|
||||
|
||||
data =
|
||||
Map.put(data, "to", user.ap_id)
|
||||
|> Map.delete("cc")
|
||||
data
|
||||
|> Map.put("to", user.ap_id)
|
||||
|> Map.put("cc", [])
|
||||
|> Kernel.put_in(["object", "to"], user.ap_id)
|
||||
|> Kernel.put_in(["object", "cc"], [])
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -684,8 +871,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
user = insert(:user)
|
||||
|
||||
data =
|
||||
Map.put(data, "cc", user.ap_id)
|
||||
|> Map.delete("to")
|
||||
data
|
||||
|> Map.put("to", [])
|
||||
|> Map.put("cc", user.ap_id)
|
||||
|> Kernel.put_in(["object", "to"], [])
|
||||
|> Kernel.put_in(["object", "cc"], user.ap_id)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -703,9 +893,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
user = insert(:user)
|
||||
|
||||
data =
|
||||
Map.put(data, "bcc", user.ap_id)
|
||||
|> Map.delete("to")
|
||||
|> Map.delete("cc")
|
||||
data
|
||||
|> Map.put("to", [])
|
||||
|> Map.put("cc", [])
|
||||
|> Map.put("bcc", user.ap_id)
|
||||
|> Kernel.put_in(["object", "to"], [])
|
||||
|> Kernel.put_in(["object", "cc"], [])
|
||||
|> Kernel.put_in(["object", "bcc"], user.ap_id)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -820,29 +1014,34 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
assert Instances.reachable?(sender_host)
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
test "it removes all follower collections but actor's", %{conn: conn} do
|
||||
[actor, recipient] = insert_pair(:user)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/activitypub-client-post-activity.json")
|
||||
|> Jason.decode!()
|
||||
to = [
|
||||
recipient.ap_id,
|
||||
recipient.follower_address,
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
]
|
||||
|
||||
object = Map.put(data["object"], "attributedTo", actor.ap_id)
|
||||
cc = [recipient.follower_address, actor.follower_address]
|
||||
|
||||
data =
|
||||
data
|
||||
|> Map.put("id", Utils.generate_object_id())
|
||||
|> Map.put("actor", actor.ap_id)
|
||||
|> Map.put("object", object)
|
||||
|> Map.put("cc", [
|
||||
recipient.follower_address,
|
||||
actor.follower_address
|
||||
])
|
||||
|> Map.put("to", [
|
||||
recipient.ap_id,
|
||||
recipient.follower_address,
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
])
|
||||
data = %{
|
||||
"@context" => ["https://www.w3.org/ns/activitystreams"],
|
||||
"type" => "Create",
|
||||
"id" => Utils.generate_activity_id(),
|
||||
"to" => to,
|
||||
"cc" => cc,
|
||||
"actor" => actor.ap_id,
|
||||
"object" => %{
|
||||
"type" => "Note",
|
||||
"to" => to,
|
||||
"cc" => cc,
|
||||
"content" => "It's a note",
|
||||
"attributedTo" => actor.ap_id,
|
||||
"id" => Utils.generate_object_id()
|
||||
}
|
||||
}
|
||||
|
||||
conn
|
||||
|> assign(:valid_signature, true)
|
||||
|
|
@ -852,7 +1051,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
|
||||
|
||||
activity = Activity.get_by_ap_id(data["id"])
|
||||
assert activity = Activity.get_by_ap_id(data["id"])
|
||||
|
||||
assert activity.id
|
||||
assert actor.follower_address in activity.recipients
|
||||
|
|
@ -984,7 +1183,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
"actor" => remote_actor,
|
||||
"content" => "test report",
|
||||
"id" => "https://#{remote_domain}/e3b12fd1-948c-446e-b93b-a5e67edbe1d8",
|
||||
"nickname" => reported_user.nickname,
|
||||
"object" => [
|
||||
reported_user.ap_id,
|
||||
note.data["object"]
|
||||
|
|
@ -1136,9 +1334,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
activity: %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"type" => "Create",
|
||||
"object" => %{"type" => "Note", "content" => "AP C2S test"},
|
||||
"to" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"cc" => []
|
||||
"object" => %{
|
||||
"type" => "Note",
|
||||
"content" => "AP C2S test",
|
||||
"to" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"cc" => []
|
||||
}
|
||||
}
|
||||
]
|
||||
end
|
||||
|
|
@ -1244,19 +1445,19 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
data = %{
|
||||
type: "Delete",
|
||||
object: %{
|
||||
id: note_object.data["id"]
|
||||
"type" => "Delete",
|
||||
"object" => %{
|
||||
"id" => note_object.data["id"]
|
||||
}
|
||||
}
|
||||
|
||||
conn =
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{user.nickname}/outbox", data)
|
||||
|> json_response(201)
|
||||
|
||||
result = json_response(conn, 201)
|
||||
assert Activity.get_by_ap_id(result["id"])
|
||||
|
||||
assert object = Object.get_by_ap_id(note_object.data["id"])
|
||||
|
|
@ -1281,7 +1482,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{user.nickname}/outbox", data)
|
||||
|
||||
assert json_response(conn, 400)
|
||||
assert json_response(conn, 403)
|
||||
end
|
||||
|
||||
test "it increases like count when receiving a like action", %{conn: conn} do
|
||||
|
|
@ -1359,7 +1560,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|> post("/users/#{user.nickname}/outbox", activity)
|
||||
|> json_response(400)
|
||||
|
||||
assert result == "Note is over the character limit"
|
||||
assert result == "Character limit (5 characters) exceeded, contains 11 characters"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1736,10 +1937,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
"object" => %{
|
||||
"type" => "Note",
|
||||
"content" => "AP C2S test, attachment",
|
||||
"attachment" => [object]
|
||||
},
|
||||
"to" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"cc" => []
|
||||
"attachment" => [object],
|
||||
"to" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"cc" => []
|
||||
}
|
||||
}
|
||||
|
||||
activity_response =
|
||||
|
|
@ -1772,4 +1973,29 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
||||
test "pinned collection", %{conn: conn} do
|
||||
clear_config([:instance, :max_pinned_statuses], 2)
|
||||
user = insert(:user)
|
||||
objects = insert_list(2, :note, user: user)
|
||||
|
||||
Enum.reduce(objects, user, fn %{data: %{"id" => object_id}}, user ->
|
||||
{:ok, updated} = User.add_pinned_object_id(user, object_id)
|
||||
updated
|
||||
end)
|
||||
|
||||
%{nickname: nickname, featured_address: featured_address, pinned_objects: pinned_objects} =
|
||||
refresh_record(user)
|
||||
|
||||
%{"id" => ^featured_address, "orderedItems" => items, "totalItems" => 2} =
|
||||
conn
|
||||
|> get("/users/#{nickname}/collections/featured")
|
||||
|> json_response(200)
|
||||
|
||||
object_ids = Enum.map(items, & &1["id"])
|
||||
|
||||
assert Enum.all?(pinned_objects, fn {obj_id, _} ->
|
||||
obj_id in object_ids
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -208,37 +208,173 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert user.name == "Bernie2020 group"
|
||||
assert user.actor_type == "Group"
|
||||
end
|
||||
|
||||
test "works for bridgy actors" do
|
||||
user_id = "https://fed.brid.gy/jk.nipponalba.scot"
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: :get, url: ^user_id} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/bridgy/actor.json"),
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
end)
|
||||
|
||||
{:ok, user} = ActivityPub.make_user_from_ap_id(user_id)
|
||||
|
||||
assert user.actor_type == "Person"
|
||||
|
||||
assert user.avatar == %{
|
||||
"type" => "Image",
|
||||
"url" => [%{"href" => "https://jk.nipponalba.scot/images/profile.jpg"}]
|
||||
}
|
||||
|
||||
assert user.banner == %{
|
||||
"type" => "Image",
|
||||
"url" => [%{"href" => "https://jk.nipponalba.scot/images/profile.jpg"}]
|
||||
}
|
||||
end
|
||||
|
||||
test "fetches user featured collection" do
|
||||
ap_id = "https://example.com/users/lain"
|
||||
|
||||
featured_url = "https://example.com/users/lain/collections/featured"
|
||||
|
||||
user_data =
|
||||
"test/fixtures/users_mock/user.json"
|
||||
|> File.read!()
|
||||
|> String.replace("{{nickname}}", "lain")
|
||||
|> Jason.decode!()
|
||||
|> Map.put("featured", featured_url)
|
||||
|> Jason.encode!()
|
||||
|
||||
object_id = Ecto.UUID.generate()
|
||||
|
||||
featured_data =
|
||||
"test/fixtures/mastodon/collections/featured.json"
|
||||
|> File.read!()
|
||||
|> String.replace("{{domain}}", "example.com")
|
||||
|> String.replace("{{nickname}}", "lain")
|
||||
|> String.replace("{{object_id}}", object_id)
|
||||
|
||||
object_url = "https://example.com/objects/#{object_id}"
|
||||
|
||||
object_data =
|
||||
"test/fixtures/statuses/note.json"
|
||||
|> File.read!()
|
||||
|> String.replace("{{object_id}}", object_id)
|
||||
|> String.replace("{{nickname}}", "lain")
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: ^ap_id
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: user_data,
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url: ^featured_url
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: featured_data,
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
end)
|
||||
|
||||
Tesla.Mock.mock_global(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: ^object_url
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: object_data,
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
end)
|
||||
|
||||
{:ok, user} = ActivityPub.make_user_from_ap_id(ap_id)
|
||||
Process.sleep(50)
|
||||
|
||||
assert user.featured_address == featured_url
|
||||
assert Map.has_key?(user.pinned_objects, object_url)
|
||||
|
||||
in_db = Pleroma.User.get_by_ap_id(ap_id)
|
||||
assert in_db.featured_address == featured_url
|
||||
assert Map.has_key?(user.pinned_objects, object_url)
|
||||
|
||||
assert %{data: %{"id" => ^object_url}} = Object.get_by_ap_id(object_url)
|
||||
end
|
||||
end
|
||||
|
||||
test "it fetches the appropriate tag-restricted posts" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, status_one} = CommonAPI.post(user, %{status: ". #test"})
|
||||
{:ok, status_one} = CommonAPI.post(user, %{status: ". #TEST"})
|
||||
{:ok, status_two} = CommonAPI.post(user, %{status: ". #essais"})
|
||||
{:ok, status_three} = CommonAPI.post(user, %{status: ". #test #reject"})
|
||||
{:ok, status_three} = CommonAPI.post(user, %{status: ". #test #Reject"})
|
||||
|
||||
fetch_one = ActivityPub.fetch_activities([], %{type: "Create", tag: "test"})
|
||||
{:ok, status_four} = CommonAPI.post(user, %{status: ". #Any1 #any2"})
|
||||
{:ok, status_five} = CommonAPI.post(user, %{status: ". #Any2 #any1"})
|
||||
|
||||
fetch_two = ActivityPub.fetch_activities([], %{type: "Create", tag: ["test", "essais"]})
|
||||
for hashtag_timeline_strategy <- [:enabled, :disabled] do
|
||||
clear_config([:features, :improved_hashtag_timeline], hashtag_timeline_strategy)
|
||||
|
||||
fetch_three =
|
||||
ActivityPub.fetch_activities([], %{
|
||||
type: "Create",
|
||||
tag: ["test", "essais"],
|
||||
tag_reject: ["reject"]
|
||||
})
|
||||
fetch_one = ActivityPub.fetch_activities([], %{type: "Create", tag: "test"})
|
||||
|
||||
fetch_four =
|
||||
ActivityPub.fetch_activities([], %{
|
||||
type: "Create",
|
||||
tag: ["test"],
|
||||
tag_all: ["test", "reject"]
|
||||
})
|
||||
fetch_two = ActivityPub.fetch_activities([], %{type: "Create", tag: ["TEST", "essais"]})
|
||||
|
||||
assert fetch_one == [status_one, status_three]
|
||||
assert fetch_two == [status_one, status_two, status_three]
|
||||
assert fetch_three == [status_one, status_two]
|
||||
assert fetch_four == [status_three]
|
||||
fetch_three =
|
||||
ActivityPub.fetch_activities([], %{
|
||||
type: "Create",
|
||||
tag: ["test", "Essais"],
|
||||
tag_reject: ["reject"]
|
||||
})
|
||||
|
||||
fetch_four =
|
||||
ActivityPub.fetch_activities([], %{
|
||||
type: "Create",
|
||||
tag: ["test"],
|
||||
tag_all: ["test", "REJECT"]
|
||||
})
|
||||
|
||||
# Testing that deduplication (if needed) is done on DB (not Ecto) level; :limit is important
|
||||
fetch_five =
|
||||
ActivityPub.fetch_activities([], %{
|
||||
type: "Create",
|
||||
tag: ["ANY1", "any2"],
|
||||
limit: 2
|
||||
})
|
||||
|
||||
fetch_six =
|
||||
ActivityPub.fetch_activities([], %{
|
||||
type: "Create",
|
||||
tag: ["any1", "Any2"],
|
||||
tag_all: [],
|
||||
tag_reject: []
|
||||
})
|
||||
|
||||
# Regression test: passing empty lists as filter options shouldn't affect the results
|
||||
assert fetch_five == fetch_six
|
||||
|
||||
[fetch_one, fetch_two, fetch_three, fetch_four, fetch_five] =
|
||||
Enum.map([fetch_one, fetch_two, fetch_three, fetch_four, fetch_five], fn statuses ->
|
||||
Enum.map(statuses, fn s -> Repo.preload(s, object: :hashtags) end)
|
||||
end)
|
||||
|
||||
assert fetch_one == [status_one, status_three]
|
||||
assert fetch_two == [status_one, status_two, status_three]
|
||||
assert fetch_three == [status_one, status_two]
|
||||
assert fetch_four == [status_three]
|
||||
assert fetch_five == [status_four, status_five]
|
||||
end
|
||||
end
|
||||
|
||||
describe "insertion" do
|
||||
|
|
|
|||
126
test/pleroma/web/activity_pub/mrf/follow_bot_policy_test.exs
Normal file
126
test/pleroma/web/activity_pub/mrf/follow_bot_policy_test.exs
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.FollowBotPolicyTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.MRF.FollowBotPolicy
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "FollowBotPolicy" do
|
||||
test "follows remote users" do
|
||||
bot = insert(:user, actor_type: "Service")
|
||||
remote_user = insert(:user, local: false)
|
||||
clear_config([:mrf_follow_bot, :follower_nickname], bot.nickname)
|
||||
|
||||
message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"to" => [remote_user.follower_address],
|
||||
"cc" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"content" => "Test post",
|
||||
"type" => "Note",
|
||||
"attributedTo" => remote_user.ap_id,
|
||||
"inReplyTo" => nil
|
||||
},
|
||||
"actor" => remote_user.ap_id
|
||||
}
|
||||
|
||||
refute User.following?(bot, remote_user)
|
||||
|
||||
assert User.get_follow_requests(remote_user) |> length == 0
|
||||
|
||||
FollowBotPolicy.filter(message)
|
||||
|
||||
assert User.get_follow_requests(remote_user) |> length == 1
|
||||
end
|
||||
|
||||
test "does not follow users with #nobot in bio" do
|
||||
bot = insert(:user, actor_type: "Service")
|
||||
remote_user = insert(:user, %{local: false, bio: "go away bots! #nobot"})
|
||||
clear_config([:mrf_follow_bot, :follower_nickname], bot.nickname)
|
||||
|
||||
message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"to" => [remote_user.follower_address],
|
||||
"cc" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"content" => "I don't like follow bots",
|
||||
"type" => "Note",
|
||||
"attributedTo" => remote_user.ap_id,
|
||||
"inReplyTo" => nil
|
||||
},
|
||||
"actor" => remote_user.ap_id
|
||||
}
|
||||
|
||||
refute User.following?(bot, remote_user)
|
||||
|
||||
assert User.get_follow_requests(remote_user) |> length == 0
|
||||
|
||||
FollowBotPolicy.filter(message)
|
||||
|
||||
assert User.get_follow_requests(remote_user) |> length == 0
|
||||
end
|
||||
|
||||
test "does not follow local users" do
|
||||
bot = insert(:user, actor_type: "Service")
|
||||
local_user = insert(:user, local: true)
|
||||
clear_config([:mrf_follow_bot, :follower_nickname], bot.nickname)
|
||||
|
||||
message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"to" => [local_user.follower_address],
|
||||
"cc" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"content" => "Hi I'm a local user",
|
||||
"type" => "Note",
|
||||
"attributedTo" => local_user.ap_id,
|
||||
"inReplyTo" => nil
|
||||
},
|
||||
"actor" => local_user.ap_id
|
||||
}
|
||||
|
||||
refute User.following?(bot, local_user)
|
||||
|
||||
assert User.get_follow_requests(local_user) |> length == 0
|
||||
|
||||
FollowBotPolicy.filter(message)
|
||||
|
||||
assert User.get_follow_requests(local_user) |> length == 0
|
||||
end
|
||||
|
||||
test "does not follow users requiring follower approval" do
|
||||
bot = insert(:user, actor_type: "Service")
|
||||
remote_user = insert(:user, %{local: false, is_locked: true})
|
||||
clear_config([:mrf_follow_bot, :follower_nickname], bot.nickname)
|
||||
|
||||
message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"to" => [remote_user.follower_address],
|
||||
"cc" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"content" => "I don't like randos following me",
|
||||
"type" => "Note",
|
||||
"attributedTo" => remote_user.ap_id,
|
||||
"inReplyTo" => nil
|
||||
},
|
||||
"actor" => remote_user.ap_id
|
||||
}
|
||||
|
||||
refute User.following?(bot, remote_user)
|
||||
|
||||
assert User.get_follow_requests(remote_user) |> length == 0
|
||||
|
||||
FollowBotPolicy.filter(message)
|
||||
|
||||
assert User.get_follow_requests(remote_user) |> length == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
31
test/pleroma/web/activity_pub/mrf/hashtag_policy_test.exs
Normal file
31
test/pleroma/web/activity_pub/mrf/hashtag_policy_test.exs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.HashtagPolicyTest do
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "it sets the sensitive property with relevant hashtags" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "#nsfw hey"})
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
assert modified["object"]["sensitive"]
|
||||
end
|
||||
|
||||
test "it doesn't sets the sensitive property with irrelevant hashtags" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "#cofe hey"})
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
refute modified["object"]["sensitive"]
|
||||
end
|
||||
end
|
||||
|
|
@ -75,10 +75,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
local_message = build_local_message()
|
||||
|
||||
assert SimplePolicy.filter(media_message) ==
|
||||
{:ok,
|
||||
media_message
|
||||
|> put_in(["object", "tag"], ["foo", "nsfw"])
|
||||
|> put_in(["object", "sensitive"], true)}
|
||||
{:ok, put_in(media_message, ["object", "sensitive"], true)}
|
||||
|
||||
assert SimplePolicy.filter(local_message) == {:ok, local_message}
|
||||
end
|
||||
|
|
@ -89,10 +86,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
local_message = build_local_message()
|
||||
|
||||
assert SimplePolicy.filter(media_message) ==
|
||||
{:ok,
|
||||
media_message
|
||||
|> put_in(["object", "tag"], ["foo", "nsfw"])
|
||||
|> put_in(["object", "sensitive"], true)}
|
||||
{:ok, put_in(media_message, ["object", "sensitive"], true)}
|
||||
|
||||
assert SimplePolicy.filter(local_message) == {:ok, local_message}
|
||||
end
|
||||
|
|
@ -260,6 +254,30 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|
||||
assert {:reject, _} = SimplePolicy.filter(remote_user)
|
||||
end
|
||||
|
||||
test "reject Announce when object would be rejected" do
|
||||
clear_config([:mrf_simple, :reject], ["blocked.tld"])
|
||||
|
||||
announce = %{
|
||||
"type" => "Announce",
|
||||
"actor" => "https://okay.tld/users/alice",
|
||||
"object" => %{"type" => "Note", "actor" => "https://blocked.tld/users/bob"}
|
||||
}
|
||||
|
||||
assert {:reject, _} = SimplePolicy.filter(announce)
|
||||
end
|
||||
|
||||
test "reject by URI object" do
|
||||
clear_config([:mrf_simple, :reject], ["blocked.tld"])
|
||||
|
||||
announce = %{
|
||||
"type" => "Announce",
|
||||
"actor" => "https://okay.tld/users/alice",
|
||||
"object" => "https://blocked.tld/activities/1"
|
||||
}
|
||||
|
||||
assert {:reject, _} = SimplePolicy.filter(announce)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when :followers_only" do
|
||||
|
|
@ -504,7 +522,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|
||||
defp build_local_message do
|
||||
%{
|
||||
"actor" => "#{Pleroma.Web.base_url()}/users/alice",
|
||||
"actor" => "#{Pleroma.Web.Endpoint.url()}/users/alice",
|
||||
"to" => [],
|
||||
"cc" => []
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do
|
|||
except_message = %{
|
||||
"actor" => actor.ap_id,
|
||||
"type" => "Create",
|
||||
"object" => %{"tag" => ["test", "nsfw"], "attachment" => ["file1"], "sensitive" => true}
|
||||
"object" => %{"tag" => ["test"], "attachment" => ["file1"], "sensitive" => true}
|
||||
}
|
||||
|
||||
assert TagPolicy.filter(message) == {:ok, except_message}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,12 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.NoOpPolicy])
|
||||
|
||||
expected = %{
|
||||
mrf_policies: ["NoOpPolicy"],
|
||||
mrf_policies: ["NoOpPolicy", "HashtagPolicy"],
|
||||
mrf_hashtag: %{
|
||||
federated_timeline_removal: [],
|
||||
reject: [],
|
||||
sensitive: ["nsfw"]
|
||||
},
|
||||
exclusions: false
|
||||
}
|
||||
|
||||
|
|
@ -79,8 +84,13 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
clear_config([:mrf, :policies], [MRFModuleMock])
|
||||
|
||||
expected = %{
|
||||
mrf_policies: ["MRFModuleMock"],
|
||||
mrf_policies: ["MRFModuleMock", "HashtagPolicy"],
|
||||
mrf_module_mock: "some config data",
|
||||
mrf_hashtag: %{
|
||||
federated_timeline_removal: [],
|
||||
reject: [],
|
||||
sensitive: ["nsfw"]
|
||||
},
|
||||
exclusions: false
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,18 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidationTest do
|
|||
assert {:ok, _object, _meta} = ObjectValidator.validate(valid_announce, [])
|
||||
end
|
||||
|
||||
test "keeps announced object context", %{valid_announce: valid_announce} do
|
||||
assert %Object{data: %{"context" => object_context}} =
|
||||
Object.get_cached_by_ap_id(valid_announce["object"])
|
||||
|
||||
{:ok, %{"context" => context}, _} =
|
||||
valid_announce
|
||||
|> Map.put("context", "https://example.org/invalid_context_id")
|
||||
|> ObjectValidator.validate([])
|
||||
|
||||
assert context == object_context
|
||||
end
|
||||
|
||||
test "returns an error if the object can't be found", %{valid_announce: valid_announce} do
|
||||
without_object =
|
||||
valid_announce
|
||||
|
|
@ -51,16 +63,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidationTest do
|
|||
assert {:object, {"can't find object", []}} in cng.errors
|
||||
end
|
||||
|
||||
test "returns an error if we don't have the actor", %{valid_announce: valid_announce} do
|
||||
nonexisting_actor =
|
||||
valid_announce
|
||||
|> Map.put("actor", "https://gensokyo.2hu/users/raymoo")
|
||||
|
||||
{:error, cng} = ObjectValidator.validate(nonexisting_actor, [])
|
||||
|
||||
assert {:actor, {"can't find user", []}} in cng.errors
|
||||
end
|
||||
|
||||
test "returns an error if the actor already announced the object", %{
|
||||
valid_announce: valid_announce,
|
||||
announcer: announcer,
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidatorTest do
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidator
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
@ -29,7 +29,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidatorTest do
|
|||
end
|
||||
|
||||
test "a basic note validates", %{note: note} do
|
||||
%{valid?: true} = ArticleNoteValidator.cast_and_validate(note)
|
||||
%{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -72,5 +72,38 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
|
|||
|
||||
assert attachment.mediaType == "image/jpeg"
|
||||
end
|
||||
|
||||
test "it handles image dimensions" do
|
||||
attachment = %{
|
||||
"url" => [
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mediaType" => "image/jpeg",
|
||||
"href" => "https://example.com/images/1.jpg",
|
||||
"width" => 200,
|
||||
"height" => 100
|
||||
}
|
||||
],
|
||||
"type" => "Document",
|
||||
"name" => nil,
|
||||
"mediaType" => "image/jpeg"
|
||||
}
|
||||
|
||||
{:ok, attachment} =
|
||||
AttachmentValidator.cast_and_validate(attachment)
|
||||
|> Ecto.Changeset.apply_action(:insert)
|
||||
|
||||
assert [
|
||||
%{
|
||||
href: "https://example.com/images/1.jpg",
|
||||
type: "Link",
|
||||
mediaType: "image/jpeg",
|
||||
width: 200,
|
||||
height: 100
|
||||
}
|
||||
] = attachment.url
|
||||
|
||||
assert attachment.mediaType == "image/jpeg"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -40,17 +40,30 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.LikeValidationTest do
|
|||
assert LikeValidator.cast_and_validate(valid_like).valid?
|
||||
end
|
||||
|
||||
test "sets the 'to' field to the object actor if no recipients are given", %{
|
||||
test "Add object actor from 'to' field if it doesn't owns the like", %{valid_like: valid_like} do
|
||||
user = insert(:user)
|
||||
|
||||
object_actor = valid_like["actor"]
|
||||
|
||||
valid_like =
|
||||
valid_like
|
||||
|> Map.put("actor", user.ap_id)
|
||||
|> Map.put("to", [])
|
||||
|
||||
{:ok, object, _meta} = ObjectValidator.validate(valid_like, [])
|
||||
assert object_actor in object["to"]
|
||||
end
|
||||
|
||||
test "Removes object actor from 'to' field if it owns the like", %{
|
||||
valid_like: valid_like,
|
||||
user: user
|
||||
} do
|
||||
without_recipients =
|
||||
valid_like =
|
||||
valid_like
|
||||
|> Map.delete("to")
|
||||
|> Map.put("to", [user.ap_id])
|
||||
|
||||
{:ok, object, _meta} = ObjectValidator.validate(without_recipients, [])
|
||||
|
||||
assert object["to"] == [user.ap_id]
|
||||
{:ok, object, _meta} = ObjectValidator.validate(valid_like, [])
|
||||
refute user.ap_id in object["to"]
|
||||
end
|
||||
|
||||
test "sets the context field to the context of the object if no context is given", %{
|
||||
|
|
@ -66,16 +79,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.LikeValidationTest do
|
|||
assert object["context"] == post_activity.data["context"]
|
||||
end
|
||||
|
||||
test "it errors when the actor is missing or not known", %{valid_like: valid_like} do
|
||||
without_actor = Map.delete(valid_like, "actor")
|
||||
|
||||
refute LikeValidator.cast_and_validate(without_actor).valid?
|
||||
|
||||
with_invalid_actor = Map.put(valid_like, "actor", "invalidactor")
|
||||
|
||||
refute LikeValidator.cast_and_validate(with_invalid_actor).valid?
|
||||
end
|
||||
|
||||
test "it errors when the object is missing or not known", %{valid_like: valid_like} do
|
||||
without_object = Map.delete(valid_like, "object")
|
||||
|
||||
|
|
|
|||
|
|
@ -25,9 +25,6 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|||
MRFMock
|
||||
|> expect(:pipeline_filter, fn o, m -> {:ok, o, m} end)
|
||||
|
||||
ActivityPubMock
|
||||
|> expect(:persist, fn o, m -> {:ok, o, m} end)
|
||||
|
||||
SideEffectsMock
|
||||
|> expect(:handle, fn o, m -> {:ok, o, m} end)
|
||||
|> expect(:handle_after_transaction, fn m -> m end)
|
||||
|
|
@ -42,6 +39,9 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|||
|
||||
activity_with_object = %{activity | data: Map.put(activity.data, "object", object)}
|
||||
|
||||
ActivityPubMock
|
||||
|> expect(:persist, fn _, m -> {:ok, activity, m} end)
|
||||
|
||||
FederatorMock
|
||||
|> expect(:publish, fn ^activity_with_object -> :ok end)
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|||
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(
|
||||
activity,
|
||||
activity.data,
|
||||
meta
|
||||
)
|
||||
end
|
||||
|
|
@ -59,6 +59,9 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|||
activity = insert(:note_activity)
|
||||
meta = [local: true]
|
||||
|
||||
ActivityPubMock
|
||||
|> expect(:persist, fn _, m -> {:ok, activity, m} end)
|
||||
|
||||
FederatorMock
|
||||
|> expect(:publish, fn ^activity -> :ok end)
|
||||
|
||||
|
|
@ -66,29 +69,35 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|||
|> expect(:get, fn [:instance, :federating] -> true end)
|
||||
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)
|
||||
end
|
||||
|
||||
test "it goes through validation, filtering, persisting, side effects without federation for remote activities" do
|
||||
activity = insert(:note_activity)
|
||||
meta = [local: false]
|
||||
|
||||
ActivityPubMock
|
||||
|> expect(:persist, fn _, m -> {:ok, activity, m} end)
|
||||
|
||||
ConfigMock
|
||||
|> expect(:get, fn [:instance, :federating] -> true end)
|
||||
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)
|
||||
end
|
||||
|
||||
test "it goes through validation, filtering, persisting, side effects without federation for local activities if federation is deactivated" do
|
||||
activity = insert(:note_activity)
|
||||
meta = [local: true]
|
||||
|
||||
ActivityPubMock
|
||||
|> expect(:persist, fn _, m -> {:ok, activity, m} end)
|
||||
|
||||
ConfigMock
|
||||
|> expect(:get, fn [:instance, :federating] -> false end)
|
||||
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
},
|
||||
%{
|
||||
"rel" => "http://ostatus.org/schema/1.0/subscribe",
|
||||
"template" => "#{Pleroma.Web.base_url()}/ostatus_subscribe?acct={uri}"
|
||||
"template" => "#{Pleroma.Web.Endpoint.url()}/ostatus_subscribe?acct={uri}"
|
||||
}
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
assert {:ok, %Activity{} = activity} = Relay.publish(note)
|
||||
assert activity.data["type"] == "Announce"
|
||||
assert activity.data["actor"] == service_actor.ap_id
|
||||
assert activity.data["to"] == [service_actor.follower_address]
|
||||
assert service_actor.follower_address in activity.data["to"]
|
||||
assert called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,172 @@
|
|||
defmodule Pleroma.Web.ActivityPub.Transmogrifier.AddRemoveHandlingTest do
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
|
||||
test "it accepts Add/Remove activities" do
|
||||
user =
|
||||
"test/fixtures/users_mock/user.json"
|
||||
|> File.read!()
|
||||
|> String.replace("{{nickname}}", "lain")
|
||||
|
||||
object_id = "c61d6733-e256-4fe1-ab13-1e369789423f"
|
||||
|
||||
object =
|
||||
"test/fixtures/statuses/note.json"
|
||||
|> File.read!()
|
||||
|> String.replace("{{nickname}}", "lain")
|
||||
|> String.replace("{{object_id}}", object_id)
|
||||
|
||||
object_url = "https://example.com/objects/#{object_id}"
|
||||
|
||||
actor = "https://example.com/users/lain"
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: ^actor
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: user,
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url: ^object_url
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: object,
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
|
||||
%{method: :get, url: "https://example.com/users/lain/collections/featured"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
"test/fixtures/users_mock/masto_featured.json"
|
||||
|> File.read!()
|
||||
|> String.replace("{{domain}}", "example.com")
|
||||
|> String.replace("{{nickname}}", "lain"),
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
end)
|
||||
|
||||
message = %{
|
||||
"id" => "https://example.com/objects/d61d6733-e256-4fe1-ab13-1e369789423f",
|
||||
"actor" => actor,
|
||||
"object" => object_url,
|
||||
"target" => "https://example.com/users/lain/collections/featured",
|
||||
"type" => "Add",
|
||||
"to" => [Pleroma.Constants.as_public()],
|
||||
"cc" => ["https://example.com/users/lain/followers"]
|
||||
}
|
||||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||
assert activity.data == message
|
||||
user = User.get_cached_by_ap_id(actor)
|
||||
assert user.pinned_objects[object_url]
|
||||
|
||||
remove = %{
|
||||
"id" => "http://localhost:400/objects/d61d6733-e256-4fe1-ab13-1e369789423d",
|
||||
"actor" => actor,
|
||||
"object" => object_url,
|
||||
"target" => "https://example.com/users/lain/collections/featured",
|
||||
"type" => "Remove",
|
||||
"to" => [Pleroma.Constants.as_public()],
|
||||
"cc" => ["https://example.com/users/lain/followers"]
|
||||
}
|
||||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(remove)
|
||||
assert activity.data == remove
|
||||
|
||||
user = refresh_record(user)
|
||||
refute user.pinned_objects[object_url]
|
||||
end
|
||||
|
||||
test "Add/Remove activities for remote users without featured address" do
|
||||
user = insert(:user, local: false, domain: "example.com")
|
||||
|
||||
user =
|
||||
user
|
||||
|> Ecto.Changeset.change(featured_address: nil)
|
||||
|> Repo.update!()
|
||||
|
||||
%{host: host} = URI.parse(user.ap_id)
|
||||
|
||||
user_data =
|
||||
"test/fixtures/users_mock/user.json"
|
||||
|> File.read!()
|
||||
|> String.replace("{{nickname}}", user.nickname)
|
||||
|
||||
object_id = "c61d6733-e256-4fe1-ab13-1e369789423f"
|
||||
|
||||
object =
|
||||
"test/fixtures/statuses/note.json"
|
||||
|> File.read!()
|
||||
|> String.replace("{{nickname}}", user.nickname)
|
||||
|> String.replace("{{object_id}}", object_id)
|
||||
|
||||
object_url = "https://#{host}/objects/#{object_id}"
|
||||
|
||||
actor = "https://#{host}/users/#{user.nickname}"
|
||||
|
||||
featured = "https://#{host}/users/#{user.nickname}/collections/featured"
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: ^actor
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: user_data,
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url: ^object_url
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: object,
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
|
||||
%{method: :get, url: ^featured} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
"test/fixtures/users_mock/masto_featured.json"
|
||||
|> File.read!()
|
||||
|> String.replace("{{domain}}", "#{host}")
|
||||
|> String.replace("{{nickname}}", user.nickname),
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
end)
|
||||
|
||||
message = %{
|
||||
"id" => "https://#{host}/objects/d61d6733-e256-4fe1-ab13-1e369789423f",
|
||||
"actor" => actor,
|
||||
"object" => object_url,
|
||||
"target" => "https://#{host}/users/#{user.nickname}/collections/featured",
|
||||
"type" => "Add",
|
||||
"to" => [Pleroma.Constants.as_public()],
|
||||
"cc" => ["https://#{host}/users/#{user.nickname}/followers"]
|
||||
}
|
||||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||
assert activity.data == message
|
||||
user = User.get_cached_by_ap_id(actor)
|
||||
assert user.pinned_objects[object_url]
|
||||
end
|
||||
end
|
||||
|
|
@ -150,27 +150,4 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do
|
|||
|
||||
assert {:error, _e} = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "it does not clobber the addressing on announce activities" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "hey"})
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-announce.json")
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", Object.normalize(activity, fetch: false).data["id"])
|
||||
|> Map.put("to", ["http://mastodon.example.org/users/admin/followers"])
|
||||
|> Map.put("cc", [])
|
||||
|
||||
_user =
|
||||
insert(:user,
|
||||
local: false,
|
||||
ap_id: data["actor"],
|
||||
follower_address: "http://mastodon.example.org/users/admin/followers"
|
||||
)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["to"] == ["http://mastodon.example.org/users/admin/followers"]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
|
|||
"actor" => "http://mastodon.example.org/users/admin",
|
||||
"object" => %{
|
||||
"type" => "Audio",
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"cc" => [],
|
||||
"id" => "http://mastodon.example.org/users/admin/listens/1234",
|
||||
"attributedTo" => "http://mastodon.example.org/users/admin",
|
||||
"title" => "lain radio episode 1",
|
||||
|
|
@ -61,7 +63,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
|
|||
|
||||
assert object.data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
|
||||
assert object.data["cc"] == []
|
||||
assert object.data["cc"] == [
|
||||
"https://channels.tests.funkwhale.audio/federation/actors/compositions/followers"
|
||||
]
|
||||
|
||||
assert object.data["url"] == "https://channels.tests.funkwhale.audio/library/tracks/74"
|
||||
|
||||
|
|
@ -76,7 +80,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
|
|||
"href" =>
|
||||
"https://channels.tests.funkwhale.audio/api/v1/listen/3901e5d8-0445-49d5-9711-e096cf32e515/?upload=42342395-0208-4fee-a38d-259a6dae0871&download=false",
|
||||
"mediaType" => "audio/ogg",
|
||||
"type" => "Link"
|
||||
"type" => "Link",
|
||||
"width" => nil,
|
||||
"height" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.EventHandlingTest do
|
|||
)
|
||||
|
||||
assert object.data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
assert object.data["cc"] == []
|
||||
assert object.data["cc"] == ["https://mobilizon.org/@tcit/followers"]
|
||||
|
||||
assert object.data["url"] ==
|
||||
"https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39"
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
import ExUnit.CaptureLog
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
|
@ -39,37 +39,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
object = Object.normalize(data["object"], fetch: false)
|
||||
|
||||
assert "test" in object.data["tag"]
|
||||
end
|
||||
|
||||
test "it cleans up incoming notices which are not really DMs" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
to = [user.ap_id, other_user.ap_id]
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Jason.decode!()
|
||||
|> Map.put("to", to)
|
||||
|> Map.put("cc", [])
|
||||
|
||||
object =
|
||||
data["object"]
|
||||
|> Map.put("to", to)
|
||||
|> Map.put("cc", [])
|
||||
|
||||
data = Map.put(data, "object", object)
|
||||
|
||||
{:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["to"] == []
|
||||
assert data["cc"] == to
|
||||
|
||||
object_data = Object.normalize(activity, fetch: false).data
|
||||
|
||||
assert object_data["to"] == []
|
||||
assert object_data["cc"] == to
|
||||
assert "test" in Object.tags(object)
|
||||
assert Object.hashtags(object) == ["test"]
|
||||
end
|
||||
|
||||
test "it ignores an incoming notice if we already have it" do
|
||||
|
|
@ -146,9 +117,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
data
|
||||
|> Map.put("object", object)
|
||||
|
||||
assert capture_log(fn ->
|
||||
{:ok, _returned_activity} = Transmogrifier.handle_incoming(data)
|
||||
end) =~ "[warn] Couldn't fetch \"https://404.site/whatever\", error: nil"
|
||||
assert {:ok, _returned_activity} = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "it does not work for deactivated users" do
|
||||
|
|
@ -173,8 +142,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
assert data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
|
||||
assert data["cc"] == [
|
||||
"http://mastodon.example.org/users/admin/followers",
|
||||
"http://localtesting.pleroma.lol/users/lain"
|
||||
"http://localtesting.pleroma.lol/users/lain",
|
||||
"http://mastodon.example.org/users/admin/followers"
|
||||
]
|
||||
|
||||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
|
|
@ -187,8 +156,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
assert object_data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
|
||||
assert object_data["cc"] == [
|
||||
"http://mastodon.example.org/users/admin/followers",
|
||||
"http://localtesting.pleroma.lol/users/lain"
|
||||
"http://localtesting.pleroma.lol/users/lain",
|
||||
"http://mastodon.example.org/users/admin/followers"
|
||||
]
|
||||
|
||||
assert object_data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
|
|
@ -220,7 +189,25 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
object = Object.normalize(data["object"], fetch: false)
|
||||
|
||||
assert Enum.at(object.data["tag"], 2) == "moo"
|
||||
assert match?(
|
||||
%{
|
||||
"href" => "http://localtesting.pleroma.lol/users/lain",
|
||||
"name" => "@lain@localtesting.pleroma.lol",
|
||||
"type" => "Mention"
|
||||
},
|
||||
Enum.at(object.data["tag"], 0)
|
||||
)
|
||||
|
||||
assert match?(
|
||||
%{
|
||||
"href" => "http://mastodon.example.org/tags/moo",
|
||||
"name" => "#moo",
|
||||
"type" => "Hashtag"
|
||||
},
|
||||
Enum.at(object.data["tag"], 1)
|
||||
)
|
||||
|
||||
assert "moo" == Enum.at(object.data["tag"], 2)
|
||||
end
|
||||
|
||||
test "it works for incoming notices with contentMap" do
|
||||
|
|
@ -274,13 +261,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Jason.decode!()
|
||||
|> Map.put("actor", user.ap_id)
|
||||
|> Map.put("to", nil)
|
||||
|> Map.put("cc", nil)
|
||||
|
||||
object =
|
||||
data["object"]
|
||||
|> Map.put("attributedTo", user.ap_id)
|
||||
|> Map.put("to", nil)
|
||||
|> Map.put("cc", nil)
|
||||
|> Map.put("id", user.ap_id <> "/activities/12345678")
|
||||
|
||||
|
|
@ -288,8 +273,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert !is_nil(data["to"])
|
||||
assert !is_nil(data["cc"])
|
||||
refute is_nil(data["cc"])
|
||||
end
|
||||
|
||||
test "it strips internal likes" do
|
||||
|
|
@ -308,9 +292,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
object = Map.put(data["object"], "likes", likes)
|
||||
data = Map.put(data, "object", object)
|
||||
|
||||
{:ok, %Activity{object: object}} = Transmogrifier.handle_incoming(data)
|
||||
{:ok, %Activity{} = activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
refute Map.has_key?(object.data, "likes")
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert object.data["likes"] == []
|
||||
end
|
||||
|
||||
test "it strips internal reactions" do
|
||||
|
|
@ -328,70 +314,46 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
end
|
||||
|
||||
test "it correctly processes messages with non-array to field" do
|
||||
user = insert(:user)
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("to", "https://www.w3.org/ns/activitystreams#Public")
|
||||
|> put_in(["object", "to"], "https://www.w3.org/ns/activitystreams#Public")
|
||||
|
||||
message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"to" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"content" => "blah blah blah",
|
||||
"type" => "Note",
|
||||
"attributedTo" => user.ap_id,
|
||||
"inReplyTo" => nil
|
||||
},
|
||||
"actor" => user.ap_id
|
||||
}
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||
assert [
|
||||
"http://localtesting.pleroma.lol/users/lain",
|
||||
"http://mastodon.example.org/users/admin/followers"
|
||||
] == activity.data["cc"]
|
||||
|
||||
assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["to"]
|
||||
end
|
||||
|
||||
test "it correctly processes messages with non-array cc field" do
|
||||
user = insert(:user)
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("cc", "http://mastodon.example.org/users/admin/followers")
|
||||
|> put_in(["object", "cc"], "http://mastodon.example.org/users/admin/followers")
|
||||
|
||||
message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"to" => user.follower_address,
|
||||
"cc" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"content" => "blah blah blah",
|
||||
"type" => "Note",
|
||||
"attributedTo" => user.ap_id,
|
||||
"inReplyTo" => nil
|
||||
},
|
||||
"actor" => user.ap_id
|
||||
}
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||
|
||||
assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["cc"]
|
||||
assert [user.follower_address] == activity.data["to"]
|
||||
assert ["http://mastodon.example.org/users/admin/followers"] == activity.data["cc"]
|
||||
assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["to"]
|
||||
end
|
||||
|
||||
test "it correctly processes messages with weirdness in address fields" do
|
||||
user = insert(:user)
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("cc", ["http://mastodon.example.org/users/admin/followers", ["¿"]])
|
||||
|> put_in(["object", "cc"], ["http://mastodon.example.org/users/admin/followers", ["¿"]])
|
||||
|
||||
message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"to" => [nil, user.follower_address],
|
||||
"cc" => ["https://www.w3.org/ns/activitystreams#Public", ["¿"]],
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"content" => "…",
|
||||
"type" => "Note",
|
||||
"attributedTo" => user.ap_id,
|
||||
"inReplyTo" => nil
|
||||
},
|
||||
"actor" => user.ap_id
|
||||
}
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||
|
||||
assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["cc"]
|
||||
assert [user.follower_address] == activity.data["to"]
|
||||
assert ["http://mastodon.example.org/users/admin/followers"] == activity.data["cc"]
|
||||
assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["to"]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -417,7 +379,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
} do
|
||||
clear_config([:instance, :federation_incoming_replies_max_depth], 10)
|
||||
|
||||
{:ok, _activity} = Transmogrifier.handle_incoming(data)
|
||||
{:ok, activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
object = Object.normalize(activity.data["object"])
|
||||
|
||||
assert object.data["replies"] == items
|
||||
|
||||
for id <- items do
|
||||
job_args = %{"op" => "fetch_remote", "id" => id, "depth" => 1}
|
||||
|
|
@ -440,45 +406,38 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
|
||||
|
||||
setup do
|
||||
user = insert(:user)
|
||||
replies = %{
|
||||
"type" => "Collection",
|
||||
"items" => [Utils.generate_object_id(), Utils.generate_object_id()]
|
||||
}
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "post1"})
|
||||
activity =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Kernel.put_in(["object", "replies"], replies)
|
||||
|
||||
{:ok, reply1} =
|
||||
CommonAPI.post(user, %{status: "reply1", in_reply_to_status_id: activity.id})
|
||||
|
||||
{:ok, reply2} =
|
||||
CommonAPI.post(user, %{status: "reply2", in_reply_to_status_id: activity.id})
|
||||
|
||||
replies_uris = Enum.map([reply1, reply2], fn a -> a.object.data["id"] end)
|
||||
|
||||
{:ok, federation_output} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
Repo.delete(activity.object)
|
||||
Repo.delete(activity)
|
||||
|
||||
%{federation_output: federation_output, replies_uris: replies_uris}
|
||||
%{activity: activity}
|
||||
end
|
||||
|
||||
test "schedules background fetching of `replies` items if max thread depth limit allows", %{
|
||||
federation_output: federation_output,
|
||||
replies_uris: replies_uris
|
||||
activity: activity
|
||||
} do
|
||||
clear_config([:instance, :federation_incoming_replies_max_depth], 1)
|
||||
|
||||
{:ok, _activity} = Transmogrifier.handle_incoming(federation_output)
|
||||
assert {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(activity)
|
||||
object = Object.normalize(data["object"])
|
||||
|
||||
for id <- replies_uris do
|
||||
for id <- object.data["replies"] do
|
||||
job_args = %{"op" => "fetch_remote", "id" => id, "depth" => 1}
|
||||
assert_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker, args: job_args)
|
||||
end
|
||||
end
|
||||
|
||||
test "does NOT schedule background fetching of `replies` beyond max thread depth limit allows",
|
||||
%{federation_output: federation_output} do
|
||||
%{activity: activity} do
|
||||
clear_config([:instance, :federation_incoming_replies_max_depth], 0)
|
||||
|
||||
{:ok, _activity} = Transmogrifier.handle_incoming(federation_output)
|
||||
{:ok, _activity} = Transmogrifier.handle_incoming(activity)
|
||||
|
||||
assert all_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker) == []
|
||||
end
|
||||
|
|
@ -496,6 +455,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
"object" => %{
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"cc" => [],
|
||||
"id" => Utils.generate_object_id(),
|
||||
"type" => "Note",
|
||||
"content" => "Hi",
|
||||
"inReplyTo" => nil,
|
||||
|
|
@ -520,6 +480,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
"object" => %{
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"cc" => [],
|
||||
"id" => Utils.generate_object_id(),
|
||||
"type" => "Note",
|
||||
"content" => "Hi",
|
||||
"inReplyTo" => nil,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.Transmogrifier.PageHandlingTest do
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Object.Fetcher
|
||||
|
||||
test "Lemmy Page" do
|
||||
Tesla.Mock.mock(fn
|
||||
%{url: "https://enterprise.lemmy.ml/post/3"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
headers: [{"content-type", "application/activity+json"}],
|
||||
body: File.read!("test/fixtures/tesla_mock/lemmy-page.json")
|
||||
}
|
||||
|
||||
%{url: "https://enterprise.lemmy.ml/u/nutomic"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
headers: [{"content-type", "application/activity+json"}],
|
||||
body: File.read!("test/fixtures/tesla_mock/lemmy-user.json")
|
||||
}
|
||||
end)
|
||||
|
||||
{:ok, object} = Fetcher.fetch_object_from_id("https://enterprise.lemmy.ml/post/3")
|
||||
|
||||
assert object.data["summary"] == "Hello Federation!"
|
||||
assert object.data["published"] == "2020-09-14T15:03:11.909105Z"
|
||||
|
||||
# WAT
|
||||
assert object.data["url"] == "https://enterprise.lemmy.ml/pictrs/image/US52d9DPvf.jpg"
|
||||
end
|
||||
end
|
||||
|
|
@ -60,7 +60,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
|
|||
"href" =>
|
||||
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
"type" => "Link",
|
||||
"width" => nil,
|
||||
"height" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -83,7 +85,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
|
|||
"href" =>
|
||||
"https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
"type" => "Link",
|
||||
"width" => nil,
|
||||
"height" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -113,7 +117,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
|
|||
"href" =>
|
||||
"https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/abece3c3-b9c6-47f4-8040-f3eed8c602e6-1080-fragmented.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
"type" => "Link",
|
||||
"width" => nil,
|
||||
"height" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.AdminAPI.AccountView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
|
|
@ -153,23 +154,13 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "it adds the sensitive property" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "#nsfw hey"})
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
assert modified["object"]["sensitive"]
|
||||
end
|
||||
|
||||
test "it adds the json-ld context and the conversation property" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "hey"})
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
assert modified["@context"] ==
|
||||
Pleroma.Web.ActivityPub.Utils.make_json_ld_header()["@context"]
|
||||
assert modified["@context"] == Utils.make_json_ld_header()["@context"]
|
||||
|
||||
assert modified["object"]["conversation"] == modified["context"]
|
||||
end
|
||||
|
|
@ -455,7 +446,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
end)
|
||||
}
|
||||
|
||||
fixed_object = Transmogrifier.fix_explicit_addressing(object)
|
||||
fixed_object = Transmogrifier.fix_explicit_addressing(object, user.follower_address)
|
||||
assert Enum.all?(explicitly_mentioned_actors, &(&1 in fixed_object["to"]))
|
||||
refute "https://social.beepboop.ga/users/dirb" in fixed_object["to"]
|
||||
assert "https://social.beepboop.ga/users/dirb" in fixed_object["cc"]
|
||||
|
|
@ -468,7 +459,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
"cc" => []
|
||||
}
|
||||
|
||||
fixed_object = Transmogrifier.fix_explicit_addressing(object)
|
||||
fixed_object = Transmogrifier.fix_explicit_addressing(object, user.follower_address)
|
||||
assert user.follower_address in fixed_object["to"]
|
||||
refute user.follower_address in fixed_object["cc"]
|
||||
end
|
||||
|
|
@ -482,7 +473,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
"cc" => [user.follower_address, recipient.follower_address]
|
||||
}
|
||||
|
||||
fixed_object = Transmogrifier.fix_explicit_addressing(object)
|
||||
fixed_object = Transmogrifier.fix_explicit_addressing(object, user.follower_address)
|
||||
|
||||
assert user.follower_address in fixed_object["cc"]
|
||||
refute recipient.follower_address in fixed_object["cc"]
|
||||
|
|
|
|||
|
|
@ -409,7 +409,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
end
|
||||
|
||||
test "saving config which need pleroma reboot", %{conn: conn} do
|
||||
clear_config([:chat, :enabled], true)
|
||||
clear_config([:shout, :enabled], true)
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|
|
@ -417,7 +417,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
"/api/pleroma/admin/config",
|
||||
%{
|
||||
configs: [
|
||||
%{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]}
|
||||
%{group: ":pleroma", key: ":shout", value: [%{"tuple" => [":enabled", true]}]}
|
||||
]
|
||||
}
|
||||
)
|
||||
|
|
@ -426,7 +426,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
%{
|
||||
"db" => [":enabled"],
|
||||
"group" => ":pleroma",
|
||||
"key" => ":chat",
|
||||
"key" => ":shout",
|
||||
"value" => [%{"tuple" => [":enabled", true]}]
|
||||
}
|
||||
],
|
||||
|
|
@ -454,7 +454,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
end
|
||||
|
||||
test "update setting which need reboot, don't change reboot flag until reboot", %{conn: conn} do
|
||||
clear_config([:chat, :enabled], true)
|
||||
clear_config([:shout, :enabled], true)
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|
|
@ -462,7 +462,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
"/api/pleroma/admin/config",
|
||||
%{
|
||||
configs: [
|
||||
%{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]}
|
||||
%{group: ":pleroma", key: ":shout", value: [%{"tuple" => [":enabled", true]}]}
|
||||
]
|
||||
}
|
||||
)
|
||||
|
|
@ -471,7 +471,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
%{
|
||||
"db" => [":enabled"],
|
||||
"group" => ":pleroma",
|
||||
"key" => ":chat",
|
||||
"key" => ":shout",
|
||||
"value" => [%{"tuple" => [":enabled", true]}]
|
||||
}
|
||||
],
|
||||
|
|
@ -1410,6 +1410,79 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
"need_reboot" => false
|
||||
}
|
||||
end
|
||||
|
||||
test "custom instance thumbnail", %{conn: conn} do
|
||||
clear_config([:instance])
|
||||
|
||||
params = %{
|
||||
"group" => ":pleroma",
|
||||
"key" => ":instance",
|
||||
"value" => [
|
||||
%{
|
||||
"tuple" => [
|
||||
":instance_thumbnail",
|
||||
"https://example.com/media/new_thumbnail.jpg"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/config", %{"configs" => [params]})
|
||||
|> json_response_and_validate_schema(200) ==
|
||||
%{
|
||||
"configs" => [
|
||||
%{
|
||||
"db" => [":instance_thumbnail"],
|
||||
"group" => ":pleroma",
|
||||
"key" => ":instance",
|
||||
"value" => params["value"]
|
||||
}
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/instance")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Map.take(["thumbnail"]) ==
|
||||
%{"thumbnail" => "https://example.com/media/new_thumbnail.jpg"}
|
||||
end
|
||||
|
||||
test "Concurrent Limiter", %{conn: conn} do
|
||||
clear_config([ConcurrentLimiter])
|
||||
|
||||
params = %{
|
||||
"group" => ":pleroma",
|
||||
"key" => "ConcurrentLimiter",
|
||||
"value" => [
|
||||
%{
|
||||
"tuple" => [
|
||||
"Pleroma.Web.RichMedia.Helpers",
|
||||
[
|
||||
%{"tuple" => [":max_running", 6]},
|
||||
%{"tuple" => [":max_waiting", 6]}
|
||||
]
|
||||
]
|
||||
},
|
||||
%{
|
||||
"tuple" => [
|
||||
"Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy",
|
||||
[
|
||||
%{"tuple" => [":max_running", 7]},
|
||||
%{"tuple" => [":max_waiting", 7]}
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/config", %{"configs" => [params]})
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/config/descriptions" do
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ defmodule Pleroma.Web.AdminAPI.OAuthAppControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Web
|
||||
alias Pleroma.Web.Endpoint
|
||||
|
||||
setup do
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
|
@ -36,7 +36,7 @@ defmodule Pleroma.Web.AdminAPI.OAuthAppControllerTest do
|
|||
end
|
||||
|
||||
test "success", %{conn: conn} do
|
||||
base_url = Web.base_url()
|
||||
base_url = Endpoint.url()
|
||||
app_name = "Trusted app"
|
||||
|
||||
response =
|
||||
|
|
@ -58,7 +58,7 @@ defmodule Pleroma.Web.AdminAPI.OAuthAppControllerTest do
|
|||
end
|
||||
|
||||
test "with trusted", %{conn: conn} do
|
||||
base_url = Web.base_url()
|
||||
base_url = Endpoint.url()
|
||||
app_name = "Trusted app"
|
||||
|
||||
response =
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web
|
||||
alias Pleroma.Web.ActivityPub.Relay
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.Endpoint
|
||||
alias Pleroma.Web.MediaProxy
|
||||
|
||||
setup_all do
|
||||
|
|
@ -44,7 +44,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn = get(build_conn(), "/api/pleroma/admin/users/#{user.nickname}?admin_token=password123")
|
||||
|
||||
assert json_response(conn, 200)
|
||||
assert json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "GET /api/pleroma/admin/users/:nickname requires admin:read:accounts or broader scope",
|
||||
|
|
@ -67,7 +67,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|> assign(:token, good_token)
|
||||
|> get(url)
|
||||
|
||||
assert json_response(conn, 200)
|
||||
assert json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
for good_token <- [good_token1, good_token2, good_token3] do
|
||||
|
|
@ -87,7 +87,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|> assign(:token, bad_token)
|
||||
|> get(url)
|
||||
|
||||
assert json_response(conn, :forbidden)
|
||||
assert json_response_and_validate_schema(conn, :forbidden)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -131,7 +131,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} deleted users: @#{user.nickname}"
|
||||
|
||||
assert json_response(conn, 200) == [user.nickname]
|
||||
assert json_response_and_validate_schema(conn, 200) == [user.nickname]
|
||||
|
||||
user = Repo.get(User, user.id)
|
||||
refute user.is_active
|
||||
|
|
@ -152,28 +152,30 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
conn =
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> delete("/api/pleroma/admin/users", %{
|
||||
nicknames: [user_one.nickname, user_two.nickname]
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} deleted users: @#{user_one.nickname}, @#{user_two.nickname}"
|
||||
|
||||
response = json_response(conn, 200)
|
||||
assert response -- [user_one.nickname, user_two.nickname] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "/api/pleroma/admin/users" do
|
||||
test "Create", %{conn: conn} do
|
||||
conn =
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/users", %{
|
||||
"users" => [
|
||||
%{
|
||||
|
|
@ -188,8 +190,9 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
}
|
||||
]
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(&Map.get(&1, "type"))
|
||||
|
||||
response = json_response(conn, 200) |> Enum.map(&Map.get(&1, "type"))
|
||||
assert response == ["success", "success"]
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
|
@ -203,6 +206,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/users", %{
|
||||
"users" => [
|
||||
%{
|
||||
|
|
@ -213,7 +217,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
]
|
||||
})
|
||||
|
||||
assert json_response(conn, 409) == [
|
||||
assert json_response_and_validate_schema(conn, 409) == [
|
||||
%{
|
||||
"code" => 409,
|
||||
"data" => %{
|
||||
|
|
@ -232,6 +236,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/users", %{
|
||||
"users" => [
|
||||
%{
|
||||
|
|
@ -242,7 +247,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
]
|
||||
})
|
||||
|
||||
assert json_response(conn, 409) == [
|
||||
assert json_response_and_validate_schema(conn, 409) == [
|
||||
%{
|
||||
"code" => 409,
|
||||
"data" => %{
|
||||
|
|
@ -261,6 +266,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/users", %{
|
||||
"users" => [
|
||||
%{
|
||||
|
|
@ -276,7 +282,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
]
|
||||
})
|
||||
|
||||
assert json_response(conn, 409) == [
|
||||
assert json_response_and_validate_schema(conn, 409) == [
|
||||
%{
|
||||
"code" => 409,
|
||||
"data" => %{
|
||||
|
|
@ -307,7 +313,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}")
|
||||
|
||||
assert user_response(user) == json_response(conn, 200)
|
||||
assert user_response(user) == json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "when the user doesn't exist", %{conn: conn} do
|
||||
|
|
@ -315,7 +321,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}")
|
||||
|
||||
assert %{"error" => "Not found"} == json_response(conn, 404)
|
||||
assert %{"error" => "Not found"} == json_response_and_validate_schema(conn, 404)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -326,6 +332,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/users/follow", %{
|
||||
"follower" => follower.nickname,
|
||||
"followed" => user.nickname
|
||||
|
|
@ -352,6 +359,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/users/unfollow", %{
|
||||
"follower" => follower.nickname,
|
||||
"followed" => user.nickname
|
||||
|
|
@ -393,7 +401,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
)
|
||||
]
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 3,
|
||||
"page_size" => 50,
|
||||
"users" => users
|
||||
|
|
@ -401,14 +409,14 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
end
|
||||
|
||||
test "pagination works correctly with service users", %{conn: conn} do
|
||||
service1 = User.get_or_create_service_actor_by_ap_id(Web.base_url() <> "/meido", "meido")
|
||||
service1 = User.get_or_create_service_actor_by_ap_id(Endpoint.url() <> "/meido", "meido")
|
||||
|
||||
insert_list(25, :user)
|
||||
|
||||
assert %{"count" => 26, "page_size" => 10, "users" => users1} =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/users?page=1&filters=", %{page_size: "10"})
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert Enum.count(users1) == 10
|
||||
assert service1 not in users1
|
||||
|
|
@ -416,7 +424,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
assert %{"count" => 26, "page_size" => 10, "users" => users2} =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/users?page=2&filters=", %{page_size: "10"})
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert Enum.count(users2) == 10
|
||||
assert service1 not in users2
|
||||
|
|
@ -424,7 +432,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
assert %{"count" => 26, "page_size" => 10, "users" => users3} =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/users?page=3&filters=", %{page_size: "10"})
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert Enum.count(users3) == 6
|
||||
assert service1 not in users3
|
||||
|
|
@ -435,7 +443,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn = get(conn, "/api/pleroma/admin/users?page=2")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 2,
|
||||
"page_size" => 50,
|
||||
"users" => []
|
||||
|
|
@ -447,7 +455,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn = get(conn, "/api/pleroma/admin/users?query=bo")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [user_response(user, %{"local" => true})]
|
||||
|
|
@ -460,7 +468,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn = get(conn, "/api/pleroma/admin/users?query=domain.com")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [user_response(user)]
|
||||
|
|
@ -473,7 +481,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn = get(conn, "/api/pleroma/admin/users?query=nickname@domain.com")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [user_response(user)]
|
||||
|
|
@ -486,7 +494,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn = get(conn, "/api/pleroma/admin/users?name=display")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [user_response(user)]
|
||||
|
|
@ -499,7 +507,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn = get(conn, "/api/pleroma/admin/users?email=email@example.com")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [user_response(user)]
|
||||
|
|
@ -512,7 +520,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn1 = get(conn, "/api/pleroma/admin/users?query=a&page_size=1&page=1")
|
||||
|
||||
assert json_response(conn1, 200) == %{
|
||||
assert json_response_and_validate_schema(conn1, 200) == %{
|
||||
"count" => 2,
|
||||
"page_size" => 1,
|
||||
"users" => [user_response(user2)]
|
||||
|
|
@ -520,7 +528,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn2 = get(conn, "/api/pleroma/admin/users?query=a&page_size=1&page=2")
|
||||
|
||||
assert json_response(conn2, 200) == %{
|
||||
assert json_response_and_validate_schema(conn2, 200) == %{
|
||||
"count" => 2,
|
||||
"page_size" => 1,
|
||||
"users" => [user_response(user)]
|
||||
|
|
@ -540,7 +548,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|> assign(:token, token)
|
||||
|> get("/api/pleroma/admin/users?query=bo&filters=local")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [user_response(user)]
|
||||
|
|
@ -566,7 +574,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
})
|
||||
]
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 3,
|
||||
"page_size" => 50,
|
||||
"users" => users
|
||||
|
|
@ -583,7 +591,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
result =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/users?filters=unconfirmed")
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
users =
|
||||
Enum.map([old_user, sad_user], fn user ->
|
||||
|
|
@ -615,7 +623,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
)
|
||||
]
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => users
|
||||
|
|
@ -640,7 +648,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
})
|
||||
]
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 2,
|
||||
"page_size" => 50,
|
||||
"users" => users
|
||||
|
|
@ -654,7 +662,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn = get(conn, "/api/pleroma/admin/users?filters=is_moderator")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [
|
||||
|
|
@ -675,8 +683,8 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
response =
|
||||
conn
|
||||
|> get(user_path(conn, :list), %{actor_types: ["Person"]})
|
||||
|> json_response(200)
|
||||
|> get(user_path(conn, :index), %{actor_types: ["Person"]})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
users = [
|
||||
user_response(user2),
|
||||
|
|
@ -696,8 +704,8 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
response =
|
||||
conn
|
||||
|> get(user_path(conn, :list), %{actor_types: ["Person", "Service"]})
|
||||
|> json_response(200)
|
||||
|> get(user_path(conn, :index), %{actor_types: ["Person", "Service"]})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
users = [
|
||||
user_response(user2),
|
||||
|
|
@ -717,8 +725,8 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
response =
|
||||
conn
|
||||
|> get(user_path(conn, :list), %{actor_types: ["Service"]})
|
||||
|> json_response(200)
|
||||
|> get(user_path(conn, :index), %{actor_types: ["Service"]})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
users = [user_response(user_service, %{"actor_type" => "Service"})]
|
||||
|
||||
|
|
@ -738,7 +746,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
user_response(user1, %{"tags" => ["first"]})
|
||||
]
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 2,
|
||||
"page_size" => 50,
|
||||
"users" => users
|
||||
|
|
@ -763,7 +771,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
%{"id" => ^user_id},
|
||||
%{"id" => ^admin_id}
|
||||
]
|
||||
} = json_response(conn, 200)
|
||||
} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "it works with multiple filters" do
|
||||
|
|
@ -780,7 +788,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|> assign(:token, token)
|
||||
|> get("/api/pleroma/admin/users?filters=deactivated,external")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [user_response(user)]
|
||||
|
|
@ -792,7 +800,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
|
||||
conn = get(conn, "/api/pleroma/admin/users")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [
|
||||
|
|
@ -807,13 +815,14 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
user_two = insert(:user, is_active: false)
|
||||
|
||||
conn =
|
||||
patch(
|
||||
conn,
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> patch(
|
||||
"/api/pleroma/admin/users/activate",
|
||||
%{nicknames: [user_one.nickname, user_two.nickname]}
|
||||
)
|
||||
|
||||
response = json_response(conn, 200)
|
||||
response = json_response_and_validate_schema(conn, 200)
|
||||
assert Enum.map(response["users"], & &1["is_active"]) == [true, true]
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
|
@ -827,13 +836,14 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
user_two = insert(:user, is_active: true)
|
||||
|
||||
conn =
|
||||
patch(
|
||||
conn,
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> patch(
|
||||
"/api/pleroma/admin/users/deactivate",
|
||||
%{nicknames: [user_one.nickname, user_two.nickname]}
|
||||
)
|
||||
|
||||
response = json_response(conn, 200)
|
||||
response = json_response_and_validate_schema(conn, 200)
|
||||
assert Enum.map(response["users"], & &1["is_active"]) == [false, false]
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
|
@ -847,13 +857,14 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
user_two = insert(:user, is_approved: false)
|
||||
|
||||
conn =
|
||||
patch(
|
||||
conn,
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> patch(
|
||||
"/api/pleroma/admin/users/approve",
|
||||
%{nicknames: [user_one.nickname, user_two.nickname]}
|
||||
)
|
||||
|
||||
response = json_response(conn, 200)
|
||||
response = json_response_and_validate_schema(conn, 200)
|
||||
assert Enum.map(response["users"], & &1["is_approved"]) == [true, true]
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
|
@ -865,9 +876,12 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation", %{admin: admin, conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn = patch(conn, "/api/pleroma/admin/users/#{user.nickname}/toggle_activation")
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> patch("/api/pleroma/admin/users/#{user.nickname}/toggle_activation")
|
||||
|
||||
assert json_response(conn, 200) ==
|
||||
assert json_response_and_validate_schema(conn, 200) ==
|
||||
user_response(
|
||||
user,
|
||||
%{"is_active" => !user.is_active}
|
||||
|
|
|
|||
|
|
@ -5,38 +5,38 @@
|
|||
defmodule Pleroma.Web.Auth.AuthenticatorTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
alias Pleroma.Web.Auth.Authenticator
|
||||
alias Pleroma.Web.Auth.Helpers
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "fetch_user/1" do
|
||||
test "returns user by name" do
|
||||
user = insert(:user)
|
||||
assert Authenticator.fetch_user(user.nickname) == user
|
||||
assert Helpers.fetch_user(user.nickname) == user
|
||||
end
|
||||
|
||||
test "returns user by email" do
|
||||
user = insert(:user)
|
||||
assert Authenticator.fetch_user(user.email) == user
|
||||
assert Helpers.fetch_user(user.email) == user
|
||||
end
|
||||
|
||||
test "returns nil" do
|
||||
assert Authenticator.fetch_user("email") == nil
|
||||
assert Helpers.fetch_user("email") == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetch_credentials/1" do
|
||||
test "returns name and password from authorization params" do
|
||||
params = %{"authorization" => %{"name" => "test", "password" => "test-pass"}}
|
||||
assert Authenticator.fetch_credentials(params) == {:ok, {"test", "test-pass"}}
|
||||
assert Helpers.fetch_credentials(params) == {:ok, {"test", "test-pass"}}
|
||||
end
|
||||
|
||||
test "returns name and password with grant_type 'password'" do
|
||||
params = %{"grant_type" => "password", "username" => "test", "password" => "test-pass"}
|
||||
assert Authenticator.fetch_credentials(params) == {:ok, {"test", "test-pass"}}
|
||||
assert Helpers.fetch_credentials(params) == {:ok, {"test", "test-pass"}}
|
||||
end
|
||||
|
||||
test "returns error" do
|
||||
assert Authenticator.fetch_credentials(%{}) == {:error, :invalid_credentials}
|
||||
assert Helpers.fetch_credentials(%{}) == {:error, :invalid_credentials}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -168,6 +168,123 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "format_input/3 with markdown" do
|
||||
test "Paragraph" do
|
||||
code = ~s[Hello\n\nWorld!]
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == "<p>Hello</p><p>World!</p>"
|
||||
end
|
||||
|
||||
test "links" do
|
||||
code = "https://en.wikipedia.org/wiki/Animal_Crossing_(video_game)"
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == ~s[<p><a href="#{code}">#{code}</a></p>]
|
||||
|
||||
code = "https://github.com/pragdave/earmark/"
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == ~s[<p><a href="#{code}">#{code}</a></p>]
|
||||
end
|
||||
|
||||
test "link with local mention" do
|
||||
insert(:user, %{nickname: "lain"})
|
||||
|
||||
code = "https://example.com/@lain"
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == ~s[<p><a href="#{code}">#{code}</a></p>]
|
||||
end
|
||||
|
||||
test "local mentions" do
|
||||
mario = insert(:user, %{nickname: "mario"})
|
||||
luigi = insert(:user, %{nickname: "luigi"})
|
||||
|
||||
code = "@mario @luigi yo what's up?"
|
||||
{result, _, []} = Utils.format_input(code, "text/markdown")
|
||||
|
||||
assert result ==
|
||||
~s[<p><span class="h-card"><a class="u-url mention" data-user="#{mario.id}" href="#{
|
||||
mario.ap_id
|
||||
}" rel="ugc">@<span>mario</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{
|
||||
luigi.id
|
||||
}" href="#{luigi.ap_id}" rel="ugc">@<span>luigi</span></a></span> yo what’s up?</p>]
|
||||
end
|
||||
|
||||
test "remote mentions" do
|
||||
mario = insert(:user, %{nickname: "mario@mushroom.world", local: false})
|
||||
luigi = insert(:user, %{nickname: "luigi@mushroom.world", local: false})
|
||||
|
||||
code = "@mario@mushroom.world @luigi@mushroom.world yo what's up?"
|
||||
{result, _, []} = Utils.format_input(code, "text/markdown")
|
||||
|
||||
assert result ==
|
||||
~s[<p><span class="h-card"><a class="u-url mention" data-user="#{mario.id}" href="#{
|
||||
mario.ap_id
|
||||
}" rel="ugc">@<span>mario</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{
|
||||
luigi.id
|
||||
}" href="#{luigi.ap_id}" rel="ugc">@<span>luigi</span></a></span> yo what’s up?</p>]
|
||||
end
|
||||
|
||||
test "raw HTML" do
|
||||
code = ~s[<a href="http://example.org/">OwO</a><!-- what's this?-->]
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == ~s[<a href="http://example.org/">OwO</a>]
|
||||
end
|
||||
|
||||
test "rulers" do
|
||||
code = ~s[before\n\n-----\n\nafter]
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == "<p>before</p><hr/><p>after</p>"
|
||||
end
|
||||
|
||||
test "blockquote" do
|
||||
code = ~s[> whoms't are you quoting?]
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == "<blockquote><p>whoms’t are you quoting?</p></blockquote>"
|
||||
end
|
||||
|
||||
test "code" do
|
||||
code = ~s[`mix`]
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == ~s[<p><code class="inline">mix</code></p>]
|
||||
|
||||
code = ~s[``mix``]
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == ~s[<p><code class="inline">mix</code></p>]
|
||||
|
||||
code = ~s[```\nputs "Hello World"\n```]
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == ~s[<pre><code>puts "Hello World"</code></pre>]
|
||||
|
||||
code = ~s[ <div>\n </div>]
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == ~s[<pre><code><div>\n</div></code></pre>]
|
||||
end
|
||||
|
||||
test "lists" do
|
||||
code = ~s[- one\n- two\n- three\n- four]
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == "<ul><li>one</li><li>two</li><li>three</li><li>four</li></ul>"
|
||||
|
||||
code = ~s[1. one\n2. two\n3. three\n4. four\n]
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == "<ol><li>one</li><li>two</li><li>three</li><li>four</li></ol>"
|
||||
end
|
||||
|
||||
test "delegated renderers" do
|
||||
code = ~s[*aaaa~*]
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == ~s[<p><em>aaaa~</em></p>]
|
||||
|
||||
code = ~s[**aaaa~**]
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == ~s[<p><strong>aaaa~</strong></p>]
|
||||
|
||||
# strikethrough
|
||||
code = ~s[~~aaaa~~~]
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == ~s[<p><del>aaaa</del>~</p>]
|
||||
end
|
||||
end
|
||||
|
||||
describe "context_to_conversation_id" do
|
||||
test "creates a mapping object" do
|
||||
conversation_id = Utils.context_to_conversation_id("random context")
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
require Pleroma.Constants
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
setup do: clear_config([:instance, :safe_dm_mentions])
|
||||
setup do: clear_config([:instance, :limit])
|
||||
setup do: clear_config([:instance, :max_pinned_statuses])
|
||||
|
|
@ -493,7 +498,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
assert object.data["tag"] == ["2hu"]
|
||||
assert Object.tags(object) == ["2hu"]
|
||||
end
|
||||
|
||||
test "it adds emoji in the object" do
|
||||
|
|
@ -514,7 +519,28 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
{:ok, activity} = CommonAPI.post(user, %{status: "hey :blank:"})
|
||||
|
||||
assert %{"blank" => url} = Object.normalize(activity).data["emoji"]
|
||||
assert url == "#{Pleroma.Web.base_url()}/emoji/blank.png"
|
||||
assert url == "#{Pleroma.Web.Endpoint.url()}/emoji/blank.png"
|
||||
end
|
||||
|
||||
test "it copies emoji from the subject of the parent post" do
|
||||
%Object{} =
|
||||
object =
|
||||
Object.normalize("https://patch.cx/objects/a399c28e-c821-4820-bc3e-4afeb044c16f",
|
||||
fetch: true
|
||||
)
|
||||
|
||||
activity = Activity.get_create_by_object_ap_id(object.data["id"])
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, reply_activity} =
|
||||
CommonAPI.post(user, %{
|
||||
in_reply_to_id: activity.id,
|
||||
status: ":joker_disapprove:",
|
||||
spoiler_text: ":joker_smile:"
|
||||
})
|
||||
|
||||
assert Object.normalize(reply_activity).data["emoji"]["joker_smile"]
|
||||
refute Object.normalize(reply_activity).data["emoji"]["joker_disapprove"]
|
||||
end
|
||||
|
||||
test "deactivated users can't post" do
|
||||
|
|
@ -571,7 +597,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
|
||||
assert object.data["content"] == "<p><b>2hu</b></p>"
|
||||
assert object.data["source"] == post
|
||||
end
|
||||
|
||||
|
|
@ -801,13 +827,17 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
[user: user, activity: activity]
|
||||
end
|
||||
|
||||
test "activity not found error", %{user: user} do
|
||||
assert {:error, :not_found} = CommonAPI.pin("id", user)
|
||||
end
|
||||
|
||||
test "pin status", %{user: user, activity: activity} do
|
||||
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
|
||||
|
||||
id = activity.id
|
||||
%{data: %{"id" => object_id}} = Object.normalize(activity)
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %User{pinned_activities: [^id]} = user
|
||||
assert user.pinned_objects |> Map.keys() == [object_id]
|
||||
end
|
||||
|
||||
test "pin poll", %{user: user} do
|
||||
|
|
@ -819,10 +849,11 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
|
||||
|
||||
id = activity.id
|
||||
%{data: %{"id" => object_id}} = Object.normalize(activity)
|
||||
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %User{pinned_activities: [^id]} = user
|
||||
assert user.pinned_objects |> Map.keys() == [object_id]
|
||||
end
|
||||
|
||||
test "unlisted statuses can be pinned", %{user: user} do
|
||||
|
|
@ -833,7 +864,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
test "only self-authored can be pinned", %{activity: activity} do
|
||||
user = insert(:user)
|
||||
|
||||
assert {:error, "Could not pin"} = CommonAPI.pin(activity.id, user)
|
||||
assert {:error, :ownership_error} = CommonAPI.pin(activity.id, user)
|
||||
end
|
||||
|
||||
test "max pinned statuses", %{user: user, activity: activity_one} do
|
||||
|
|
@ -843,8 +874,12 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
user = refresh_record(user)
|
||||
|
||||
assert {:error, "You have already pinned the maximum number of statuses"} =
|
||||
CommonAPI.pin(activity_two.id, user)
|
||||
assert {:error, :pinned_statuses_limit_reached} = CommonAPI.pin(activity_two.id, user)
|
||||
end
|
||||
|
||||
test "only public can be pinned", %{user: user} do
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "private status", visibility: "private"})
|
||||
{:error, :visibility_error} = CommonAPI.pin(activity.id, user)
|
||||
end
|
||||
|
||||
test "unpin status", %{user: user, activity: activity} do
|
||||
|
|
@ -858,7 +893,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %User{pinned_activities: []} = user
|
||||
assert user.pinned_objects == %{}
|
||||
end
|
||||
|
||||
test "should unpin when deleting a status", %{user: user, activity: activity} do
|
||||
|
|
@ -870,7 +905,40 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %User{pinned_activities: []} = user
|
||||
assert user.pinned_objects == %{}
|
||||
end
|
||||
|
||||
test "ephemeral activity won't be deleted if was pinned", %{user: user} do
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "Hello!", expires_in: 601})
|
||||
|
||||
assert Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
|
||||
|
||||
{:ok, _activity} = CommonAPI.pin(activity.id, user)
|
||||
refute Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
|
||||
|
||||
user = refresh_record(user)
|
||||
{:ok, _} = CommonAPI.unpin(activity.id, user)
|
||||
|
||||
# recreates expiration job on unpin
|
||||
assert Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
|
||||
end
|
||||
|
||||
test "ephemeral activity deletion job won't be deleted on pinning error", %{
|
||||
user: user,
|
||||
activity: activity
|
||||
} do
|
||||
clear_config([:instance, :max_pinned_statuses], 1)
|
||||
|
||||
{:ok, _activity} = CommonAPI.pin(activity.id, user)
|
||||
|
||||
{:ok, activity2} = CommonAPI.post(user, %{status: "another status", expires_in: 601})
|
||||
|
||||
assert Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity2.id)
|
||||
|
||||
user = refresh_record(user)
|
||||
{:error, :pinned_statuses_limit_reached} = CommonAPI.pin(activity2.id, user)
|
||||
|
||||
assert Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity2.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -123,7 +123,8 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
"type" => "Note",
|
||||
"content" => "hi world!",
|
||||
"id" => "http://mastodon.example.org/users/admin/objects/1",
|
||||
"attributedTo" => "http://mastodon.example.org/users/admin"
|
||||
"attributedTo" => "http://mastodon.example.org/users/admin",
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
},
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
}
|
||||
|
|
@ -145,7 +146,8 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
"type" => "Note",
|
||||
"content" => "hi world!",
|
||||
"id" => "http://mastodon.example.org/users/admin/objects/1",
|
||||
"attributedTo" => "http://mastodon.example.org/users/admin"
|
||||
"attributedTo" => "http://mastodon.example.org/users/admin",
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
},
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,10 +127,10 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
"These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
|
||||
|
||||
assert xpath(xml, ~x"//channel/link/text()") ==
|
||||
'#{Pleroma.Web.base_url()}/tags/pleromaart.rss'
|
||||
'#{Pleroma.Web.Endpoint.url()}/tags/pleromaart.rss'
|
||||
|
||||
assert xpath(xml, ~x"//channel/webfeeds:logo/text()") ==
|
||||
'#{Pleroma.Web.base_url()}/static/logo.svg'
|
||||
'#{Pleroma.Web.Endpoint.url()}/static/logo.svg'
|
||||
|
||||
assert xpath(xml, ~x"//channel/item/title/text()"l) == [
|
||||
'42 This is :moominmamm...',
|
||||
|
|
|
|||
|
|
@ -217,7 +217,9 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
|> get("/users/#{user.nickname}")
|
||||
|
||||
assert conn.status == 302
|
||||
assert redirected_to(conn) == "#{Pleroma.Web.base_url()}/users/#{user.nickname}/feed.atom"
|
||||
|
||||
assert redirected_to(conn) ==
|
||||
"#{Pleroma.Web.Endpoint.url()}/users/#{user.nickname}/feed.atom"
|
||||
end
|
||||
|
||||
test "with non-html / non-json format, it returns error when user is not found", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -514,11 +514,11 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
{:ok, post_2} = CommonAPI.post(user, %{status: "second post"})
|
||||
|
||||
response_1 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1")
|
||||
assert [res] = json_response(response_1, 200)
|
||||
assert [res] = json_response_and_validate_schema(response_1, 200)
|
||||
assert res["id"] == post_2.id
|
||||
|
||||
response_2 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1&max_id=#{res["id"]}")
|
||||
assert [res] = json_response(response_2, 200)
|
||||
assert [res] = json_response_and_validate_schema(response_2, 200)
|
||||
assert res["id"] == post_1.id
|
||||
|
||||
refute response_1 == response_2
|
||||
|
|
@ -881,7 +881,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert [] ==
|
||||
conn
|
||||
|> get("/api/v1/timelines/home")
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert %{"showing_reblogs" => true} =
|
||||
conn
|
||||
|
|
@ -892,7 +892,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert [%{"id" => ^reblog_id}] =
|
||||
conn
|
||||
|> get("/api/v1/timelines/home")
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "following with reblogs" do
|
||||
|
|
@ -910,7 +910,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert [%{"id" => ^reblog_id}] =
|
||||
conn
|
||||
|> get("/api/v1/timelines/home")
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert %{"showing_reblogs" => false} =
|
||||
conn
|
||||
|
|
@ -921,7 +921,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert [] ==
|
||||
conn
|
||||
|> get("/api/v1/timelines/home")
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "following / unfollowing errors", %{user: user, conn: conn} do
|
||||
|
|
|
|||
|
|
@ -214,7 +214,8 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{direct.id}/context")
|
||||
|
||||
assert %{"ancestors" => [], "descendants" => []} == json_response(res_conn, 200)
|
||||
assert %{"ancestors" => [], "descendants" => []} ==
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
end
|
||||
|
||||
test "Removes a conversation", %{user: user_one, conn: conn} do
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
|||
assert result = json_response_and_validate_schema(conn, 200)
|
||||
|
||||
email = Pleroma.Config.get([:instance, :email])
|
||||
thumbnail = Pleroma.Web.base_url() <> Pleroma.Config.get([:instance, :instance_thumbnail])
|
||||
background = Pleroma.Web.base_url() <> Pleroma.Config.get([:instance, :background_image])
|
||||
thumbnail = Pleroma.Web.Endpoint.url() <> Pleroma.Config.get([:instance, :instance_thumbnail])
|
||||
background = Pleroma.Web.Endpoint.url() <> Pleroma.Config.get([:instance, :background_image])
|
||||
|
||||
# Note: not checking for "max_toot_chars" since it's optional
|
||||
assert %{
|
||||
|
|
@ -38,7 +38,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
|||
"background_upload_limit" => _,
|
||||
"banner_upload_limit" => _,
|
||||
"background_image" => from_config_background,
|
||||
"chat_limit" => _,
|
||||
"shout_limit" => _,
|
||||
"description_limit" => _
|
||||
} = result
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
|
|
@ -67,6 +69,59 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
|||
object = Object.get_by_id(media["id"])
|
||||
assert object.data["actor"] == user.ap_id
|
||||
end
|
||||
|
||||
test "/api/v2/media, upload_limit", %{conn: conn, user: user} do
|
||||
desc = "Description of the binary"
|
||||
|
||||
upload_limit = Config.get([:instance, :upload_limit]) * 8 + 8
|
||||
|
||||
assert :ok ==
|
||||
File.write(Path.absname("test/tmp/large_binary.data"), <<0::size(upload_limit)>>)
|
||||
|
||||
large_binary = %Plug.Upload{
|
||||
content_type: nil,
|
||||
path: Path.absname("test/tmp/large_binary.data"),
|
||||
filename: "large_binary.data"
|
||||
}
|
||||
|
||||
assert capture_log(fn ->
|
||||
assert %{"error" => "file_too_large"} =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> post("/api/v2/media", %{
|
||||
"file" => large_binary,
|
||||
"description" => desc
|
||||
})
|
||||
|> json_response_and_validate_schema(400)
|
||||
end) =~
|
||||
"[error] Elixir.Pleroma.Upload store (using Pleroma.Uploaders.Local) failed: :file_too_large"
|
||||
|
||||
clear_config([:instance, :upload_limit], upload_limit)
|
||||
|
||||
assert response =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> post("/api/v2/media", %{
|
||||
"file" => large_binary,
|
||||
"description" => desc
|
||||
})
|
||||
|> json_response_and_validate_schema(202)
|
||||
|
||||
assert media_id = response["id"]
|
||||
|
||||
%{conn: conn} = oauth_access(["read:media"], user: user)
|
||||
|
||||
media =
|
||||
conn
|
||||
|> get("/api/v1/media/#{media_id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert media["type"] == "unknown"
|
||||
assert media["description"] == desc
|
||||
assert media["id"]
|
||||
|
||||
assert :ok == File.rm(Path.absname("test/tmp/large_binary.data"))
|
||||
end
|
||||
end
|
||||
|
||||
describe "Update media description" do
|
||||
|
|
@ -140,7 +195,7 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
|||
|
||||
conn
|
||||
|> get("/api/v1/media/#{object.id}")
|
||||
|> json_response(403)
|
||||
|> json_response_and_validate_schema(403)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.Endpoint
|
||||
import Pleroma.Factory
|
||||
import ExUnit.CaptureLog
|
||||
import Tesla.Mock
|
||||
|
|
@ -61,7 +61,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
assert account["id"] == to_string(user_three.id)
|
||||
|
||||
assert results["hashtags"] == [
|
||||
%{"name" => "private", "url" => "#{Web.base_url()}/tag/private"}
|
||||
%{"name" => "private", "url" => "#{Endpoint.url()}/tag/private"}
|
||||
]
|
||||
|
||||
[status] = results["statuses"]
|
||||
|
|
@ -72,7 +72,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert results["hashtags"] == [
|
||||
%{"name" => "天子", "url" => "#{Web.base_url()}/tag/天子"}
|
||||
%{"name" => "天子", "url" => "#{Endpoint.url()}/tag/天子"}
|
||||
]
|
||||
|
||||
[status] = results["statuses"]
|
||||
|
|
@ -87,8 +87,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert results["hashtags"] == [
|
||||
%{"name" => "explicit", "url" => "#{Web.base_url()}/tag/explicit"},
|
||||
%{"name" => "hashtags", "url" => "#{Web.base_url()}/tag/hashtags"}
|
||||
%{"name" => "explicit", "url" => "#{Endpoint.url()}/tag/explicit"},
|
||||
%{"name" => "hashtags", "url" => "#{Endpoint.url()}/tag/hashtags"}
|
||||
]
|
||||
|
||||
results =
|
||||
|
|
@ -97,9 +97,9 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert results["hashtags"] == [
|
||||
%{"name" => "john", "url" => "#{Web.base_url()}/tag/john"},
|
||||
%{"name" => "doe", "url" => "#{Web.base_url()}/tag/doe"},
|
||||
%{"name" => "JohnDoe", "url" => "#{Web.base_url()}/tag/JohnDoe"}
|
||||
%{"name" => "john", "url" => "#{Endpoint.url()}/tag/john"},
|
||||
%{"name" => "doe", "url" => "#{Endpoint.url()}/tag/doe"},
|
||||
%{"name" => "JohnDoe", "url" => "#{Endpoint.url()}/tag/JohnDoe"}
|
||||
]
|
||||
|
||||
results =
|
||||
|
|
@ -108,9 +108,9 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert results["hashtags"] == [
|
||||
%{"name" => "accident", "url" => "#{Web.base_url()}/tag/accident"},
|
||||
%{"name" => "prone", "url" => "#{Web.base_url()}/tag/prone"},
|
||||
%{"name" => "AccidentProne", "url" => "#{Web.base_url()}/tag/AccidentProne"}
|
||||
%{"name" => "accident", "url" => "#{Endpoint.url()}/tag/accident"},
|
||||
%{"name" => "prone", "url" => "#{Endpoint.url()}/tag/prone"},
|
||||
%{"name" => "AccidentProne", "url" => "#{Endpoint.url()}/tag/AccidentProne"}
|
||||
]
|
||||
|
||||
results =
|
||||
|
|
@ -119,7 +119,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert results["hashtags"] == [
|
||||
%{"name" => "shpuld", "url" => "#{Web.base_url()}/tag/shpuld"}
|
||||
%{"name" => "shpuld", "url" => "#{Endpoint.url()}/tag/shpuld"}
|
||||
]
|
||||
|
||||
results =
|
||||
|
|
@ -136,18 +136,18 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert results["hashtags"] == [
|
||||
%{"name" => "nascar", "url" => "#{Web.base_url()}/tag/nascar"},
|
||||
%{"name" => "ban", "url" => "#{Web.base_url()}/tag/ban"},
|
||||
%{"name" => "display", "url" => "#{Web.base_url()}/tag/display"},
|
||||
%{"name" => "confederate", "url" => "#{Web.base_url()}/tag/confederate"},
|
||||
%{"name" => "flag", "url" => "#{Web.base_url()}/tag/flag"},
|
||||
%{"name" => "all", "url" => "#{Web.base_url()}/tag/all"},
|
||||
%{"name" => "events", "url" => "#{Web.base_url()}/tag/events"},
|
||||
%{"name" => "properties", "url" => "#{Web.base_url()}/tag/properties"},
|
||||
%{"name" => "nascar", "url" => "#{Endpoint.url()}/tag/nascar"},
|
||||
%{"name" => "ban", "url" => "#{Endpoint.url()}/tag/ban"},
|
||||
%{"name" => "display", "url" => "#{Endpoint.url()}/tag/display"},
|
||||
%{"name" => "confederate", "url" => "#{Endpoint.url()}/tag/confederate"},
|
||||
%{"name" => "flag", "url" => "#{Endpoint.url()}/tag/flag"},
|
||||
%{"name" => "all", "url" => "#{Endpoint.url()}/tag/all"},
|
||||
%{"name" => "events", "url" => "#{Endpoint.url()}/tag/events"},
|
||||
%{"name" => "properties", "url" => "#{Endpoint.url()}/tag/properties"},
|
||||
%{
|
||||
"name" => "NascarBanDisplayConfederateFlagAllEventsProperties",
|
||||
"url" =>
|
||||
"#{Web.base_url()}/tag/NascarBanDisplayConfederateFlagAllEventsProperties"
|
||||
"#{Endpoint.url()}/tag/NascarBanDisplayConfederateFlagAllEventsProperties"
|
||||
}
|
||||
]
|
||||
end
|
||||
|
|
@ -163,8 +163,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert results["hashtags"] == [
|
||||
%{"name" => "text", "url" => "#{Web.base_url()}/tag/text"},
|
||||
%{"name" => "with", "url" => "#{Web.base_url()}/tag/with"}
|
||||
%{"name" => "text", "url" => "#{Endpoint.url()}/tag/text"},
|
||||
%{"name" => "with", "url" => "#{Endpoint.url()}/tag/with"}
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
@ -81,6 +82,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
"sensitive" => 0
|
||||
})
|
||||
|
||||
# Idempotency plug response means detection fail
|
||||
assert %{"id" => second_id} = json_response(conn_two, 200)
|
||||
assert id == second_id
|
||||
|
||||
|
|
@ -358,7 +360,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert activity.data["cc"] == []
|
||||
end
|
||||
|
||||
@tag :skip
|
||||
test "discloses application metadata when enabled" do
|
||||
user = insert(:user, disclose_client: true)
|
||||
%{user: _user, token: token, conn: conn} = oauth_access(["write:statuses"], user: user)
|
||||
|
|
@ -377,6 +378,16 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
"status" => "cofe is my copilot"
|
||||
})
|
||||
|
||||
assert %{
|
||||
"content" => "cofe is my copilot"
|
||||
} = json_response_and_validate_schema(result, 200)
|
||||
|
||||
activity = result.assigns.activity.id
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("api/v1/statuses/#{activity}")
|
||||
|
||||
assert %{
|
||||
"content" => "cofe is my copilot",
|
||||
"application" => %{
|
||||
|
|
@ -397,6 +408,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
"status" => "club mate is my wingman"
|
||||
})
|
||||
|
||||
assert %{"content" => "club mate is my wingman"} =
|
||||
json_response_and_validate_schema(result, 200)
|
||||
|
||||
activity = result.assigns.activity.id
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("api/v1/statuses/#{activity}")
|
||||
|
||||
assert %{
|
||||
"content" => "club mate is my wingman",
|
||||
"application" => nil
|
||||
|
|
@ -1191,20 +1211,27 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
setup do: clear_config([:instance, :max_pinned_statuses], 1)
|
||||
|
||||
test "pin status", %{conn: conn, user: user, activity: activity} do
|
||||
id_str = to_string(activity.id)
|
||||
id = activity.id
|
||||
|
||||
assert %{"id" => ^id_str, "pinned" => true} =
|
||||
assert %{"id" => ^id, "pinned" => true} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses/#{activity.id}/pin")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => ^id_str, "pinned" => true}] =
|
||||
assert [%{"id" => ^id, "pinned" => true}] =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "non authenticated user", %{activity: activity} do
|
||||
assert build_conn()
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses/#{activity.id}/pin")
|
||||
|> json_response(403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "/pin: returns 400 error when activity is not public", %{conn: conn, user: user} do
|
||||
{:ok, dm} = CommonAPI.post(user, %{status: "test", visibility: "direct"})
|
||||
|
||||
|
|
@ -1213,7 +1240,18 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses/#{dm.id}/pin")
|
||||
|
||||
assert json_response_and_validate_schema(conn, 400) == %{"error" => "Could not pin"}
|
||||
assert json_response_and_validate_schema(conn, 422) == %{
|
||||
"error" => "Non-public status cannot be pinned"
|
||||
}
|
||||
end
|
||||
|
||||
test "pin by another user", %{activity: activity} do
|
||||
%{conn: conn} = oauth_access(["write:accounts"])
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses/#{activity.id}/pin")
|
||||
|> json_response(422) == %{"error" => "Someone else's status cannot be pinned"}
|
||||
end
|
||||
|
||||
test "unpin status", %{conn: conn, user: user, activity: activity} do
|
||||
|
|
@ -1234,13 +1272,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "/unpin: returns 400 error when activity is not exist", %{conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses/1/unpin")
|
||||
|
||||
assert json_response_and_validate_schema(conn, 400) == %{"error" => "Could not unpin"}
|
||||
test "/unpin: returns 404 error when activity doesn't exist", %{conn: conn} do
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses/1/unpin")
|
||||
|> json_response_and_validate_schema(404) == %{"error" => "Record not found"}
|
||||
end
|
||||
|
||||
test "max pinned statuses", %{conn: conn, user: user, activity: activity_one} do
|
||||
|
|
@ -1524,7 +1560,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|> assign(:token, insert(:oauth_token, user: user3, scopes: ["read:statuses"]))
|
||||
|> get("api/v1/timelines/home")
|
||||
|
||||
[reblogged_activity] = json_response(conn3, 200)
|
||||
[reblogged_activity] = json_response_and_validate_schema(conn3, 200)
|
||||
|
||||
assert reblogged_activity["reblog"]["in_reply_to_id"] == replied_to.id
|
||||
|
||||
|
|
@ -1875,10 +1911,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
"visibility" => "local"
|
||||
})
|
||||
|
||||
local = Pleroma.Constants.as_local_public()
|
||||
local = Utils.as_local_public()
|
||||
|
||||
assert %{"content" => "cofe", "id" => id, "visibility" => "local"} =
|
||||
json_response(conn_one, 200)
|
||||
json_response_and_validate_schema(conn_one, 200)
|
||||
|
||||
assert %Activity{id: ^id, data: %{"to" => [^local]}} = Activity.get_by_id(id)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -905,10 +905,10 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
%{conn: auth_conn} = oauth_access(["read:statuses"])
|
||||
|
||||
res_conn = get(auth_conn, "#{base_uri}?local=true")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
assert length(json_response_and_validate_schema(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(auth_conn, "#{base_uri}?local=false")
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
||||
end
|
||||
|
||||
test "with default settings on private instances, returns 403 for unauthenticated users", %{
|
||||
|
|
@ -922,7 +922,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
for local <- [true, false] do
|
||||
res_conn = get(conn, "#{base_uri}?local=#{local}")
|
||||
|
||||
assert json_response(res_conn, :unauthorized) == error_response
|
||||
assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
|
||||
end
|
||||
|
||||
ensure_authenticated_access(base_uri)
|
||||
|
|
@ -939,7 +939,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
for local <- [true, false] do
|
||||
res_conn = get(conn, "#{base_uri}?local=#{local}")
|
||||
|
||||
assert json_response(res_conn, :unauthorized) == error_response
|
||||
assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
|
||||
end
|
||||
|
||||
ensure_authenticated_access(base_uri)
|
||||
|
|
@ -951,10 +951,10 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
clear_config([:restrict_unauthenticated, :timelines, :federated], true)
|
||||
|
||||
res_conn = get(conn, "#{base_uri}?local=true")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
assert length(json_response_and_validate_schema(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "#{base_uri}?local=false")
|
||||
assert json_response(res_conn, :unauthorized) == error_response
|
||||
assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
|
||||
|
||||
ensure_authenticated_access(base_uri)
|
||||
end
|
||||
|
|
@ -966,11 +966,11 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
clear_config([:restrict_unauthenticated, :timelines, :federated], false)
|
||||
|
||||
res_conn = get(conn, "#{base_uri}?local=true")
|
||||
assert json_response(res_conn, :unauthorized) == error_response
|
||||
assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
|
||||
|
||||
# Note: local activities get delivered as part of federated timeline
|
||||
res_conn = get(conn, "#{base_uri}?local=false")
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
||||
|
||||
ensure_authenticated_access(base_uri)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ defmodule Pleroma.Web.MastodonAPI.MastoFEControllerTest do
|
|||
|> assign(:token, insert(:oauth_token, user: user, scopes: ["write:accounts"]))
|
||||
|> put("/api/web/settings", %{"data" => %{"programming" => "socks"}})
|
||||
|
||||
assert _result = json_response(conn, 200)
|
||||
assert %{} = json_response(conn, 200)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
assert user.mastofe_settings == %{"programming" => "socks"}
|
||||
|
|
|
|||
|
|
@ -468,6 +468,23 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
%{user: user, for: user}
|
||||
)[:pleroma][:unread_notifications_count] == 7
|
||||
end
|
||||
|
||||
test "shows email only to the account owner" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert AccountView.render(
|
||||
"show.json",
|
||||
%{user: user, for: other_user}
|
||||
)[:pleroma][:email] == nil
|
||||
|
||||
assert AccountView.render(
|
||||
"show.json",
|
||||
%{user: user, for: user}
|
||||
)[:pleroma][:email] == user.email
|
||||
end
|
||||
end
|
||||
|
||||
describe "follow requests counter" do
|
||||
|
|
@ -562,12 +579,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
|> Enum.all?(fn
|
||||
{key, url} when key in [:avatar, :avatar_static, :header, :header_static] ->
|
||||
String.starts_with?(url, Pleroma.Web.base_url())
|
||||
String.starts_with?(url, Pleroma.Web.Endpoint.url())
|
||||
|
||||
{:emojis, emojis} ->
|
||||
Enum.all?(emojis, fn %{url: url, static_url: static_url} ->
|
||||
String.starts_with?(url, Pleroma.Web.base_url()) &&
|
||||
String.starts_with?(static_url, Pleroma.Web.base_url())
|
||||
String.starts_with?(url, Pleroma.Web.Endpoint.url()) &&
|
||||
String.starts_with?(static_url, Pleroma.Web.Endpoint.url())
|
||||
end)
|
||||
|
||||
_ ->
|
||||
|
|
|
|||
|
|
@ -262,8 +262,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
mentions: [],
|
||||
tags: [
|
||||
%{
|
||||
name: "#{object_data["tag"]}",
|
||||
url: "http://localhost:4001/tag/#{object_data["tag"]}"
|
||||
name: "#{hd(object_data["tag"])}",
|
||||
url: "http://localhost:4001/tag/#{hd(object_data["tag"])}"
|
||||
}
|
||||
],
|
||||
application: nil,
|
||||
|
|
@ -286,7 +286,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
direct_conversation_id: nil,
|
||||
thread_muted: false,
|
||||
emoji_reactions: [],
|
||||
parent_visible: false
|
||||
parent_visible: false,
|
||||
pinned_at: nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -458,7 +459,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
"url" => [
|
||||
%{
|
||||
"mediaType" => "image/png",
|
||||
"href" => "someurl"
|
||||
"href" => "someurl",
|
||||
"width" => 200,
|
||||
"height" => 100
|
||||
}
|
||||
],
|
||||
"blurhash" => "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn",
|
||||
|
|
@ -474,6 +477,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
text_url: "someurl",
|
||||
description: nil,
|
||||
pleroma: %{mime_type: "image/png"},
|
||||
meta: %{original: %{width: 200, height: 100, aspect: 2}},
|
||||
blurhash: "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,7 @@ defmodule Pleroma.Web.MediaProxyTest do
|
|||
alias Pleroma.Web.MediaProxy
|
||||
|
||||
defp decode_result(encoded) do
|
||||
[_, "proxy", sig, base64 | _] = URI.parse(encoded).path |> String.split("/")
|
||||
{:ok, decoded} = MediaProxy.decode_url(sig, base64)
|
||||
{:ok, decoded} = MediaProxy.decode_url(encoded)
|
||||
decoded
|
||||
end
|
||||
|
||||
|
|
@ -42,7 +41,7 @@ defmodule Pleroma.Web.MediaProxyTest do
|
|||
|
||||
assert String.starts_with?(
|
||||
encoded,
|
||||
Config.get([:media_proxy, :base_url], Pleroma.Web.base_url())
|
||||
Config.get([:media_proxy, :base_url], Pleroma.Web.Endpoint.url())
|
||||
)
|
||||
|
||||
assert String.ends_with?(encoded, "/logo.png")
|
||||
|
|
|
|||
|
|
@ -22,7 +22,12 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
|
|||
"attachment" => [
|
||||
%{
|
||||
"url" => [
|
||||
%{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}
|
||||
%{
|
||||
"mediaType" => "image/png",
|
||||
"href" => "https://pleroma.gov/tenshi.png",
|
||||
"height" => 1024,
|
||||
"width" => 1280
|
||||
}
|
||||
]
|
||||
},
|
||||
%{
|
||||
|
|
@ -35,7 +40,12 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
|
|||
},
|
||||
%{
|
||||
"url" => [
|
||||
%{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
|
||||
%{
|
||||
"mediaType" => "video/webm",
|
||||
"href" => "https://pleroma.gov/about/juche.webm",
|
||||
"height" => 600,
|
||||
"width" => 800
|
||||
}
|
||||
]
|
||||
},
|
||||
%{
|
||||
|
|
@ -55,11 +65,15 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
|
|||
assert Enum.all?(
|
||||
[
|
||||
{:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []},
|
||||
{:meta, [property: "og:image:width", content: "1280"], []},
|
||||
{:meta, [property: "og:image:height", content: "1024"], []},
|
||||
{:meta,
|
||||
[property: "og:audio", content: "http://www.gnu.org/music/free-software-song.au"],
|
||||
[]},
|
||||
{:meta, [property: "og:video", content: "https://pleroma.gov/about/juche.webm"],
|
||||
[]}
|
||||
[]},
|
||||
{:meta, [property: "og:video:width", content: "800"], []},
|
||||
{:meta, [property: "og:video:height", content: "600"], []}
|
||||
],
|
||||
fn element -> element in result end
|
||||
)
|
||||
|
|
@ -93,4 +107,84 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
|
|||
|
||||
refute {:meta, [property: "og:image", content: "https://misskey.microsoft/corndog.png"], []} in result
|
||||
end
|
||||
|
||||
test "video attachments have image thumbnail with WxH metadata with Preview Proxy enabled" do
|
||||
clear_config([:media_proxy, :enabled], true)
|
||||
clear_config([:media_preview_proxy, :enabled], true)
|
||||
user = insert(:user)
|
||||
|
||||
note =
|
||||
insert(:note, %{
|
||||
data: %{
|
||||
"actor" => user.ap_id,
|
||||
"id" => "https://pleroma.gov/objects/whatever",
|
||||
"content" => "test video post",
|
||||
"sensitive" => false,
|
||||
"attachment" => [
|
||||
%{
|
||||
"url" => [
|
||||
%{
|
||||
"mediaType" => "video/webm",
|
||||
"href" => "https://pleroma.gov/about/juche.webm",
|
||||
"height" => 600,
|
||||
"width" => 800
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
|
||||
|
||||
assert {:meta, [property: "og:image:width", content: "800"], []} in result
|
||||
assert {:meta, [property: "og:image:height", content: "600"], []} in result
|
||||
|
||||
assert {:meta,
|
||||
[
|
||||
property: "og:image",
|
||||
content:
|
||||
"http://localhost:4001/proxy/preview/LzAnlke-l5oZbNzWsrHfprX1rGw/aHR0cHM6Ly9wbGVyb21hLmdvdi9hYm91dC9qdWNoZS53ZWJt/juche.webm"
|
||||
], []} in result
|
||||
end
|
||||
|
||||
test "video attachments have no image thumbnail with Preview Proxy disabled" do
|
||||
clear_config([:media_proxy, :enabled], true)
|
||||
clear_config([:media_preview_proxy, :enabled], false)
|
||||
user = insert(:user)
|
||||
|
||||
note =
|
||||
insert(:note, %{
|
||||
data: %{
|
||||
"actor" => user.ap_id,
|
||||
"id" => "https://pleroma.gov/objects/whatever",
|
||||
"content" => "test video post",
|
||||
"sensitive" => false,
|
||||
"attachment" => [
|
||||
%{
|
||||
"url" => [
|
||||
%{
|
||||
"mediaType" => "video/webm",
|
||||
"href" => "https://pleroma.gov/about/juche.webm",
|
||||
"height" => 600,
|
||||
"width" => 800
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
|
||||
|
||||
refute {:meta, [property: "og:image:width", content: "800"], []} in result
|
||||
refute {:meta, [property: "og:image:height", content: "600"], []} in result
|
||||
|
||||
refute {:meta,
|
||||
[
|
||||
property: "og:image",
|
||||
content:
|
||||
"http://localhost:4001/proxy/preview/LzAnlke-l5oZbNzWsrHfprX1rGw/aHR0cHM6Ly9wbGVyb21hLmdvdi9hYm91dC9qdWNoZS53ZWJt/juche.webm"
|
||||
], []} in result
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
|
|||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.Endpoint
|
||||
alias Pleroma.Web.MediaProxy
|
||||
alias Pleroma.Web.Metadata.Providers.TwitterCard
|
||||
alias Pleroma.Web.Metadata.Utils
|
||||
alias Pleroma.Web.Router
|
||||
|
|
@ -17,7 +18,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
|
|||
|
||||
test "it renders twitter card for user info" do
|
||||
user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
|
||||
avatar_url = Utils.attachment_url(User.avatar_url(user))
|
||||
avatar_url = MediaProxy.preview_url(User.avatar_url(user))
|
||||
res = TwitterCard.build_tags(%{user: user})
|
||||
|
||||
assert res == [
|
||||
|
|
@ -46,7 +47,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
|
|||
|
||||
assert [
|
||||
{:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
|
||||
{:meta, [property: "twitter:description", content: "“pleroma in a nutshell”"], []},
|
||||
{:meta, [property: "twitter:description", content: "pleroma in a nutshell"], []},
|
||||
{:meta, [property: "twitter:image", content: "http://localhost:4001/images/avi.png"],
|
||||
[]},
|
||||
{:meta, [property: "twitter:card", content: "summary"], []}
|
||||
|
|
@ -91,7 +92,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
|
|||
|
||||
assert [
|
||||
{:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
|
||||
{:meta, [property: "twitter:description", content: "“pleroma in a nutshell”"], []},
|
||||
{:meta, [property: "twitter:description", content: "pleroma in a nutshell"], []},
|
||||
{:meta, [property: "twitter:image", content: "http://localhost:4001/images/avi.png"],
|
||||
[]},
|
||||
{:meta, [property: "twitter:card", content: "summary"], []}
|
||||
|
|
@ -111,7 +112,14 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
|
|||
"content" => "pleroma in a nutshell",
|
||||
"attachment" => [
|
||||
%{
|
||||
"url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}]
|
||||
"url" => [
|
||||
%{
|
||||
"mediaType" => "image/png",
|
||||
"href" => "https://pleroma.gov/tenshi.png",
|
||||
"height" => 1024,
|
||||
"width" => 1280
|
||||
}
|
||||
]
|
||||
},
|
||||
%{
|
||||
"url" => [
|
||||
|
|
@ -123,7 +131,12 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
|
|||
},
|
||||
%{
|
||||
"url" => [
|
||||
%{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
|
||||
%{
|
||||
"mediaType" => "video/webm",
|
||||
"href" => "https://pleroma.gov/about/juche.webm",
|
||||
"height" => 600,
|
||||
"width" => 800
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
@ -134,17 +147,25 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
|
|||
|
||||
assert [
|
||||
{:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
|
||||
{:meta, [property: "twitter:description", content: "“pleroma in a nutshell”"], []},
|
||||
{: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,
|
||||
[
|
||||
property: "twitter:player",
|
||||
content: Router.Helpers.o_status_url(Endpoint, :notice_player, activity.id)
|
||||
], []},
|
||||
{:meta, [property: "twitter:player:width", content: "480"], []},
|
||||
{:meta, [property: "twitter:player:height", content: "480"], []}
|
||||
{:meta, [property: "twitter:player:width", content: "800"], []},
|
||||
{:meta, [property: "twitter:player:height", content: "600"], []},
|
||||
{:meta,
|
||||
[
|
||||
property: "twitter:player:stream",
|
||||
content: "https://pleroma.gov/about/juche.webm"
|
||||
], []},
|
||||
{:meta, [property: "twitter:player:stream:content_type", content: "video/webm"], []}
|
||||
] == result
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -805,10 +805,12 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
"client_secret" => app.client_secret
|
||||
})
|
||||
|
||||
assert %{"access_token" => token} = json_response(conn, 200)
|
||||
assert %{"id" => id, "access_token" => access_token} = json_response(conn, 200)
|
||||
|
||||
token = Repo.get_by(Token, token: token)
|
||||
token = Repo.get_by(Token, token: access_token)
|
||||
assert token
|
||||
assert token.id == id
|
||||
assert token.token == access_token
|
||||
assert token.scopes == app.scopes
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|> response(200)
|
||||
|
||||
assert resp =~
|
||||
"<meta content=\"#{Pleroma.Web.base_url()}/notice/#{note_activity.id}\" property=\"og:url\">"
|
||||
"<meta content=\"#{Pleroma.Web.Endpoint.url()}/notice/#{note_activity.id}\" property=\"og:url\">"
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
|
|||
assert %{"error" => "Insufficient permissions: follow | write:follows."} ==
|
||||
json_response(conn, 403)
|
||||
else
|
||||
assert json_response(conn, 200)
|
||||
assert json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -103,6 +103,6 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
|||
"check_password"
|
||||
]
|
||||
|
||||
assert expected_routes == Pleroma.Web.get_api_routes()
|
||||
assert expected_routes == Pleroma.Web.Router.get_api_routes()
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ChatChannelTest do
|
||||
defmodule Pleroma.Web.ShoutChannelTest do
|
||||
use Pleroma.Web.ChannelCase
|
||||
alias Pleroma.Web.ChatChannel
|
||||
alias Pleroma.Web.ShoutChannel
|
||||
alias Pleroma.Web.UserSocket
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
@ -14,7 +14,7 @@ defmodule Pleroma.Web.ChatChannelTest do
|
|||
|
||||
{:ok, _, socket} =
|
||||
socket(UserSocket, "", %{user_name: user.nickname})
|
||||
|> subscribe_and_join(ChatChannel, "chat:public")
|
||||
|> subscribe_and_join(ShoutChannel, "chat:public")
|
||||
|
||||
{:ok, socket: socket}
|
||||
end
|
||||
|
|
@ -25,7 +25,7 @@ defmodule Pleroma.Web.ChatChannelTest do
|
|||
end
|
||||
|
||||
describe "message lengths" do
|
||||
setup do: clear_config([:instance, :chat_limit])
|
||||
setup do: clear_config([:shout, :limit])
|
||||
|
||||
test "it ignores messages of length zero", %{socket: socket} do
|
||||
push(socket, "new_msg", %{"text" => ""})
|
||||
|
|
@ -33,7 +33,7 @@ defmodule Pleroma.Web.ChatChannelTest do
|
|||
end
|
||||
|
||||
test "it ignores messages above a certain length", %{socket: socket} do
|
||||
clear_config([:instance, :chat_limit], 2)
|
||||
clear_config([:shout, :limit], 2)
|
||||
push(socket, "new_msg", %{"text" => "123"})
|
||||
refute_broadcast("new_msg", %{text: "123"})
|
||||
end
|
||||
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
|||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
@ -185,16 +186,16 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
|||
test "302 for remote cached status", %{conn: conn, user: user} do
|
||||
message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"to" => user.follower_address,
|
||||
"cc" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"type" => "Create",
|
||||
"actor" => user.ap_id,
|
||||
"object" => %{
|
||||
"to" => user.follower_address,
|
||||
"cc" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"id" => Utils.generate_object_id(),
|
||||
"content" => "blah blah blah",
|
||||
"type" => "Note",
|
||||
"attributedTo" => user.ap_id,
|
||||
"inReplyTo" => nil
|
||||
},
|
||||
"actor" => user.ap_id
|
||||
"attributedTo" => user.ap_id
|
||||
}
|
||||
}
|
||||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||
|
|
|
|||
|
|
@ -7,59 +7,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.OAuth.Token
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "POST /api/qvitter/statuses/notifications/read" do
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
conn = post(conn, "/api/qvitter/statuses/notifications/read", %{"latest_id" => 1_234_567})
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials, without any params" do
|
||||
%{conn: conn} = oauth_access(["write:notifications"])
|
||||
|
||||
conn = post(conn, "/api/qvitter/statuses/notifications/read")
|
||||
|
||||
assert json_response(conn, 400) == %{
|
||||
"error" => "You need to specify latest_id",
|
||||
"request" => "/api/qvitter/statuses/notifications/read"
|
||||
}
|
||||
end
|
||||
|
||||
test "with credentials, with params" do
|
||||
%{user: current_user, conn: conn} =
|
||||
oauth_access(["read:notifications", "write:notifications"])
|
||||
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.post(other_user, %{
|
||||
status: "Hey @#{current_user.nickname}"
|
||||
})
|
||||
|
||||
response_conn =
|
||||
conn
|
||||
|> get("/api/v1/notifications")
|
||||
|
||||
[notification] = json_response(response_conn, 200)
|
||||
|
||||
assert notification["pleroma"]["is_seen"] == false
|
||||
|
||||
response_conn =
|
||||
conn
|
||||
|> post("/api/qvitter/statuses/notifications/read", %{"latest_id" => notification["id"]})
|
||||
|
||||
[notification] = response = json_response(response_conn, 200)
|
||||
|
||||
assert length(response) == 1
|
||||
|
||||
assert notification["pleroma"]["is_seen"] == true
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/account/confirm_email/:id/:token" do
|
||||
setup do
|
||||
{:ok, user} =
|
||||
|
|
|
|||
|
|
@ -27,6 +27,16 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
|
|||
body: File.read!("test/fixtures/tesla_mock/status.emelie.json")
|
||||
}
|
||||
|
||||
%{method: :get, url: "https://mastodon.social/users/emelie/collections/featured"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
headers: [{"content-type", "application/activity+json"}],
|
||||
body:
|
||||
File.read!("test/fixtures/users_mock/masto_featured.json")
|
||||
|> String.replace("{{domain}}", "mastodon.social")
|
||||
|> String.replace("{{nickname}}", "emelie")
|
||||
}
|
||||
|
||||
%{method: :get, url: "https://mastodon.social/users/emelie"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
|
|
@ -52,6 +62,16 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
|
|||
headers: [{"content-type", "application/activity+json"}],
|
||||
body: File.read!("test/fixtures/tesla_mock/emelie.json")
|
||||
}
|
||||
|
||||
%{method: :get, url: "https://mastodon.social/users/emelie/collections/featured"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
headers: [{"content-type", "application/activity+json"}],
|
||||
body:
|
||||
File.read!("test/fixtures/users_mock/masto_featured.json")
|
||||
|> String.replace("{{domain}}", "mastodon.social")
|
||||
|> String.replace("{{nickname}}", "emelie")
|
||||
}
|
||||
end)
|
||||
|
||||
response =
|
||||
|
|
@ -70,6 +90,16 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
|
|||
headers: [{"content-type", "application/activity+json"}],
|
||||
body: File.read!("test/fixtures/tesla_mock/emelie.json")
|
||||
}
|
||||
|
||||
%{method: :get, url: "https://mastodon.social/users/emelie/collections/featured"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
headers: [{"content-type", "application/activity+json"}],
|
||||
body:
|
||||
File.read!("test/fixtures/users_mock/masto_featured.json")
|
||||
|> String.replace("{{domain}}", "mastodon.social")
|
||||
|> String.replace("{{nickname}}", "emelie")
|
||||
}
|
||||
end)
|
||||
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -25,11 +25,14 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|
||||
test "it updates notification settings", %{user: user, conn: conn} do
|
||||
conn
|
||||
|> put("/api/pleroma/notification_settings", %{
|
||||
"block_from_strangers" => true,
|
||||
"bar" => 1
|
||||
})
|
||||
|> json_response(:ok)
|
||||
|> put(
|
||||
"/api/pleroma/notification_settings?#{
|
||||
URI.encode_query(%{
|
||||
block_from_strangers: true
|
||||
})
|
||||
}"
|
||||
)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
user = refresh_record(user)
|
||||
|
||||
|
|
@ -41,8 +44,14 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|
||||
test "it updates notification settings to enable hiding contents", %{user: user, conn: conn} do
|
||||
conn
|
||||
|> put("/api/pleroma/notification_settings", %{"hide_notification_contents" => "1"})
|
||||
|> json_response(:ok)
|
||||
|> put(
|
||||
"/api/pleroma/notification_settings?#{
|
||||
URI.encode_query(%{
|
||||
hide_notification_contents: 1
|
||||
})
|
||||
}"
|
||||
)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
user = refresh_record(user)
|
||||
|
||||
|
|
@ -70,7 +79,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/frontend_configurations")
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert response == Jason.encode!(config |> Enum.into(%{})) |> Jason.decode!()
|
||||
end
|
||||
|
|
@ -81,7 +90,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
emoji =
|
||||
conn
|
||||
|> get("/api/pleroma/emoji")
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert Enum.all?(emoji, fn
|
||||
{_key,
|
||||
|
|
@ -103,7 +112,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/healthcheck")
|
||||
|> json_response(503)
|
||||
|> json_response_and_validate_schema(503)
|
||||
|
||||
assert response == %{}
|
||||
end
|
||||
|
|
@ -116,7 +125,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/healthcheck")
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert %{
|
||||
"active" => _,
|
||||
|
|
@ -136,7 +145,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/healthcheck")
|
||||
|> json_response(503)
|
||||
|> json_response_and_validate_schema(503)
|
||||
|
||||
assert %{
|
||||
"active" => _,
|
||||
|
|
@ -155,8 +164,8 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
test "with valid permissions and password, it disables the account", %{conn: conn, user: user} do
|
||||
response =
|
||||
conn
|
||||
|> post("/api/pleroma/disable_account", %{"password" => "test"})
|
||||
|> json_response(:ok)
|
||||
|> post("/api/pleroma/disable_account?password=test")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert response == %{"status" => "success"}
|
||||
ObanHelpers.perform_all()
|
||||
|
|
@ -171,8 +180,8 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|
||||
response =
|
||||
conn
|
||||
|> post("/api/pleroma/disable_account", %{"password" => "test1"})
|
||||
|> json_response(:ok)
|
||||
|> post("/api/pleroma/disable_account?password=test1")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert response == %{"error" => "Invalid password."}
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
|
@ -252,54 +261,61 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
conn =
|
||||
conn
|
||||
|> assign(:token, nil)
|
||||
|> post("/api/pleroma/change_email")
|
||||
|> post(
|
||||
"/api/pleroma/change_email?#{
|
||||
URI.encode_query(%{password: "hi", email: "test@test.com"})
|
||||
}"
|
||||
)
|
||||
|
||||
assert json_response(conn, 403) == %{"error" => "Insufficient permissions: write:accounts."}
|
||||
assert json_response_and_validate_schema(conn, 403) == %{
|
||||
"error" => "Insufficient permissions: write:accounts."
|
||||
}
|
||||
end
|
||||
|
||||
test "with proper permissions and invalid password", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, "/api/pleroma/change_email", %{
|
||||
"password" => "hi",
|
||||
"email" => "test@test.com"
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_email?#{
|
||||
URI.encode_query(%{password: "hi", email: "test@test.com"})
|
||||
}"
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == %{"error" => "Invalid password."}
|
||||
assert json_response_and_validate_schema(conn, 200) == %{"error" => "Invalid password."}
|
||||
end
|
||||
|
||||
test "with proper permissions, valid password and invalid email", %{
|
||||
conn: conn
|
||||
} do
|
||||
conn =
|
||||
post(conn, "/api/pleroma/change_email", %{
|
||||
"password" => "test",
|
||||
"email" => "foobar"
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_email?#{URI.encode_query(%{password: "test", email: "foobar"})}"
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == %{"error" => "Email has invalid format."}
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"error" => "Email has invalid format."
|
||||
}
|
||||
end
|
||||
|
||||
test "with proper permissions, valid password and no email", %{
|
||||
conn: conn
|
||||
} do
|
||||
conn =
|
||||
post(conn, "/api/pleroma/change_email", %{
|
||||
"password" => "test"
|
||||
})
|
||||
conn = post(conn, "/api/pleroma/change_email?#{URI.encode_query(%{password: "test"})}")
|
||||
|
||||
assert json_response(conn, 200) == %{"error" => "Email can't be blank."}
|
||||
assert %{"error" => "Missing field: email."} = json_response_and_validate_schema(conn, 400)
|
||||
end
|
||||
|
||||
test "with proper permissions, valid password and blank email", %{
|
||||
conn: conn
|
||||
} do
|
||||
conn =
|
||||
post(conn, "/api/pleroma/change_email", %{
|
||||
"password" => "test",
|
||||
"email" => ""
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_email?#{URI.encode_query(%{password: "test", email: ""})}"
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == %{"error" => "Email can't be blank."}
|
||||
assert json_response_and_validate_schema(conn, 200) == %{"error" => "Email can't be blank."}
|
||||
end
|
||||
|
||||
test "with proper permissions, valid password and non unique email", %{
|
||||
|
|
@ -308,24 +324,28 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
post(conn, "/api/pleroma/change_email", %{
|
||||
"password" => "test",
|
||||
"email" => user.email
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_email?#{URI.encode_query(%{password: "test", email: user.email})}"
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == %{"error" => "Email has already been taken."}
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"error" => "Email has already been taken."
|
||||
}
|
||||
end
|
||||
|
||||
test "with proper permissions, valid password and valid email", %{
|
||||
conn: conn
|
||||
} do
|
||||
conn =
|
||||
post(conn, "/api/pleroma/change_email", %{
|
||||
"password" => "test",
|
||||
"email" => "cofe@foobar.com"
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_email?#{
|
||||
URI.encode_query(%{password: "test", email: "cofe@foobar.com"})
|
||||
}"
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == %{"status" => "success"}
|
||||
assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -336,20 +356,35 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
conn =
|
||||
conn
|
||||
|> assign(:token, nil)
|
||||
|> post("/api/pleroma/change_password")
|
||||
|> post(
|
||||
"/api/pleroma/change_password?#{
|
||||
URI.encode_query(%{
|
||||
password: "hi",
|
||||
new_password: "newpass",
|
||||
new_password_confirmation: "newpass"
|
||||
})
|
||||
}"
|
||||
)
|
||||
|
||||
assert json_response(conn, 403) == %{"error" => "Insufficient permissions: write:accounts."}
|
||||
assert json_response_and_validate_schema(conn, 403) == %{
|
||||
"error" => "Insufficient permissions: write:accounts."
|
||||
}
|
||||
end
|
||||
|
||||
test "with proper permissions and invalid password", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, "/api/pleroma/change_password", %{
|
||||
"password" => "hi",
|
||||
"new_password" => "newpass",
|
||||
"new_password_confirmation" => "newpass"
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_password?#{
|
||||
URI.encode_query(%{
|
||||
password: "hi",
|
||||
new_password: "newpass",
|
||||
new_password_confirmation: "newpass"
|
||||
})
|
||||
}"
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == %{"error" => "Invalid password."}
|
||||
assert json_response_and_validate_schema(conn, 200) == %{"error" => "Invalid password."}
|
||||
end
|
||||
|
||||
test "with proper permissions, valid password and new password and confirmation not matching",
|
||||
|
|
@ -357,13 +392,18 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
conn: conn
|
||||
} do
|
||||
conn =
|
||||
post(conn, "/api/pleroma/change_password", %{
|
||||
"password" => "test",
|
||||
"new_password" => "newpass",
|
||||
"new_password_confirmation" => "notnewpass"
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_password?#{
|
||||
URI.encode_query(%{
|
||||
password: "test",
|
||||
new_password: "newpass",
|
||||
new_password_confirmation: "notnewpass"
|
||||
})
|
||||
}"
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"error" => "New password does not match confirmation."
|
||||
}
|
||||
end
|
||||
|
|
@ -372,13 +412,14 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
conn: conn
|
||||
} do
|
||||
conn =
|
||||
post(conn, "/api/pleroma/change_password", %{
|
||||
"password" => "test",
|
||||
"new_password" => "",
|
||||
"new_password_confirmation" => ""
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_password?#{
|
||||
URI.encode_query(%{password: "test", new_password: "", new_password_confirmation: ""})
|
||||
}"
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
assert json_response_and_validate_schema(conn, 200) == %{
|
||||
"error" => "New password can't be blank."
|
||||
}
|
||||
end
|
||||
|
|
@ -388,13 +429,18 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
user: user
|
||||
} do
|
||||
conn =
|
||||
post(conn, "/api/pleroma/change_password", %{
|
||||
"password" => "test",
|
||||
"new_password" => "newpass",
|
||||
"new_password_confirmation" => "newpass"
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_password?#{
|
||||
URI.encode_query(%{
|
||||
password: "test",
|
||||
new_password: "newpass",
|
||||
new_password_confirmation: "newpass"
|
||||
})
|
||||
}"
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == %{"status" => "success"}
|
||||
assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
|
||||
fetched_user = User.get_cached_by_id(user.id)
|
||||
assert Pleroma.Password.Pbkdf2.verify_pass("newpass", fetched_user.password_hash) == true
|
||||
end
|
||||
|
|
@ -409,7 +455,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|> assign(:token, nil)
|
||||
|> post("/api/pleroma/delete_account")
|
||||
|
||||
assert json_response(conn, 403) ==
|
||||
assert json_response_and_validate_schema(conn, 403) ==
|
||||
%{"error" => "Insufficient permissions: write:accounts."}
|
||||
end
|
||||
|
||||
|
|
@ -417,14 +463,16 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
for params <- [%{"password" => "hi"}, %{}] do
|
||||
ret_conn = post(conn, "/api/pleroma/delete_account", params)
|
||||
|
||||
assert json_response(ret_conn, 200) == %{"error" => "Invalid password."}
|
||||
assert json_response_and_validate_schema(ret_conn, 200) == %{
|
||||
"error" => "Invalid password."
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
test "with proper permissions and valid password", %{conn: conn, user: user} do
|
||||
conn = post(conn, "/api/pleroma/delete_account", %{"password" => "test"})
|
||||
conn = post(conn, "/api/pleroma/delete_account?password=test")
|
||||
ObanHelpers.perform_all()
|
||||
assert json_response(conn, 200) == %{"status" => "success"}
|
||||
assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
|
||||
|
||||
user = User.get_by_id(user.id)
|
||||
refute user.is_active
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
|||
|
||||
assert response.resp_body ==
|
||||
~s(<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" template="#{
|
||||
Pleroma.Web.base_url()
|
||||
Pleroma.Web.Endpoint.url()
|
||||
}/.well-known/webfinger?resource={uri}" type="application/xrd+xml" /></XRD>)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ defmodule Pleroma.Web.WebFingerTest do
|
|||
test "returns a link to the xml lrdd" do
|
||||
host_info = WebFinger.host_meta()
|
||||
|
||||
assert String.contains?(host_info, Pleroma.Web.base_url())
|
||||
assert String.contains?(host_info, Pleroma.Web.Endpoint.url())
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -45,6 +45,26 @@ defmodule Pleroma.Web.WebFingerTest do
|
|||
assert {:error, _} = WebFinger.finger("pleroma.social")
|
||||
end
|
||||
|
||||
test "returns error when there is no content-type header" do
|
||||
Tesla.Mock.mock(fn
|
||||
%{url: "http://social.heldscal.la/.well-known/host-meta"} ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
|
||||
}}
|
||||
|
||||
%{
|
||||
url:
|
||||
"https://social.heldscal.la/.well-known/webfinger?resource=acct:invalid_content@social.heldscal.la"
|
||||
} ->
|
||||
{:ok, %Tesla.Env{status: 200, body: ""}}
|
||||
end)
|
||||
|
||||
user = "invalid_content@social.heldscal.la"
|
||||
assert {:error, {:content_type, nil}} = WebFinger.finger(user)
|
||||
end
|
||||
|
||||
test "returns error when fails parse xml or json" do
|
||||
user = "invalid_content@social.heldscal.la"
|
||||
assert {:error, %Jason.DecodeError{}} = WebFinger.finger(user)
|
||||
|
|
@ -113,5 +133,52 @@ defmodule Pleroma.Web.WebFingerTest do
|
|||
ap_id = "https://" <> to_string(:idna.encode("zetsubou.みんな")) <> "/users/lain"
|
||||
{:ok, _data} = WebFinger.finger(ap_id)
|
||||
end
|
||||
|
||||
test "respects json content-type" do
|
||||
Tesla.Mock.mock(fn
|
||||
%{
|
||||
url:
|
||||
"https://mastodon.social/.well-known/webfinger?resource=acct:emelie@mastodon.social"
|
||||
} ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/webfinger_emelie.json"),
|
||||
headers: [{"content-type", "application/jrd+json"}]
|
||||
}}
|
||||
|
||||
%{url: "http://mastodon.social/.well-known/host-meta"} ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
|
||||
}}
|
||||
end)
|
||||
|
||||
{:ok, _data} = WebFinger.finger("emelie@mastodon.social")
|
||||
end
|
||||
|
||||
test "respects xml content-type" do
|
||||
Tesla.Mock.mock(fn
|
||||
%{
|
||||
url: "https://pawoo.net/.well-known/webfinger?resource=acct:pekorino@pawoo.net"
|
||||
} ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.xml"),
|
||||
headers: [{"content-type", "application/xrd+xml"}]
|
||||
}}
|
||||
|
||||
%{url: "http://pawoo.net/.well-known/host-meta"} ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta")
|
||||
}}
|
||||
end)
|
||||
|
||||
{:ok, _data} = WebFinger.finger("pekorino@pawoo.net")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -67,13 +67,11 @@ defmodule Pleroma.Web.ConnCase do
|
|||
end
|
||||
|
||||
defp json_response_and_validate_schema(
|
||||
%{
|
||||
private: %{
|
||||
open_api_spex: %{operation_id: op_id, operation_lookup: lookup, spec: spec}
|
||||
}
|
||||
} = conn,
|
||||
%{private: %{operation_id: op_id}} = conn,
|
||||
status
|
||||
) do
|
||||
{spec, lookup} = OpenApiSpex.Plug.PutApiSpec.get_spec_and_operation_lookup(conn)
|
||||
|
||||
content_type =
|
||||
conn
|
||||
|> Plug.Conn.get_resp_header("content-type")
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
defmodule Pleroma.Factory do
|
||||
use ExMachina.Ecto, repo: Pleroma.Repo
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
|
||||
|
|
@ -41,23 +44,27 @@ defmodule Pleroma.Factory do
|
|||
|
||||
urls =
|
||||
if attrs[:local] == false do
|
||||
base_domain = Enum.random(["domain1.com", "domain2.com", "domain3.com"])
|
||||
base_domain = attrs[:domain] || Enum.random(["domain1.com", "domain2.com", "domain3.com"])
|
||||
|
||||
ap_id = "https://#{base_domain}/users/#{user.nickname}"
|
||||
|
||||
%{
|
||||
ap_id: ap_id,
|
||||
follower_address: ap_id <> "/followers",
|
||||
following_address: ap_id <> "/following"
|
||||
following_address: ap_id <> "/following",
|
||||
featured_address: ap_id <> "/collections/featured"
|
||||
}
|
||||
else
|
||||
%{
|
||||
ap_id: User.ap_id(user),
|
||||
follower_address: User.ap_followers(user),
|
||||
following_address: User.ap_following(user)
|
||||
following_address: User.ap_following(user),
|
||||
featured_address: User.ap_featured_collection(user)
|
||||
}
|
||||
end
|
||||
|
||||
attrs = Map.delete(attrs, :domain)
|
||||
|
||||
user
|
||||
|> Map.put(:raw_bio, user.bio)
|
||||
|> Map.merge(urls)
|
||||
|
|
@ -184,8 +191,8 @@ defmodule Pleroma.Factory do
|
|||
end
|
||||
|
||||
def article_factory do
|
||||
note_factory()
|
||||
|> Map.put("type", "Article")
|
||||
%Pleroma.Object{data: data} = note_factory()
|
||||
%Pleroma.Object{data: Map.merge(data, %{"type" => "Article"})}
|
||||
end
|
||||
|
||||
def tombstone_factory do
|
||||
|
|
@ -221,6 +228,45 @@ defmodule Pleroma.Factory do
|
|||
}
|
||||
end
|
||||
|
||||
def add_activity_factory(attrs \\ %{}) do
|
||||
featured_collection_activity(attrs, "Add")
|
||||
end
|
||||
|
||||
def remove_activity_factor(attrs \\ %{}) do
|
||||
featured_collection_activity(attrs, "Remove")
|
||||
end
|
||||
|
||||
defp featured_collection_activity(attrs, type) do
|
||||
user = attrs[:user] || insert(:user)
|
||||
note = attrs[:note] || insert(:note, user: user)
|
||||
|
||||
data_attrs =
|
||||
attrs
|
||||
|> Map.get(:data_attrs, %{})
|
||||
|> Map.put(:type, type)
|
||||
|
||||
attrs = Map.drop(attrs, [:user, :note, :data_attrs])
|
||||
|
||||
data =
|
||||
%{
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||
"target" => user.featured_address,
|
||||
"object" => note.data["object"],
|
||||
"actor" => note.data["actor"],
|
||||
"type" => "Add",
|
||||
"to" => [Pleroma.Constants.as_public()],
|
||||
"cc" => [user.follower_address]
|
||||
}
|
||||
|> Map.merge(data_attrs)
|
||||
|
||||
%Pleroma.Activity{
|
||||
data: data,
|
||||
actor: data["actor"],
|
||||
recipients: data["to"]
|
||||
}
|
||||
|> Map.merge(attrs)
|
||||
end
|
||||
|
||||
def note_activity_factory(attrs \\ %{}) do
|
||||
user = attrs[:user] || insert(:user)
|
||||
note = attrs[:note] || insert(:note, user: user)
|
||||
|
|
|
|||
|
|
@ -42,8 +42,7 @@ defmodule Pleroma.Tests.Helpers do
|
|||
# Displaying a warning to prevent unintentional clearing of all but one keys in section
|
||||
if Keyword.keyword?(temp_setting) and length(temp_setting) == 1 do
|
||||
Logger.warn(
|
||||
"Please change to `clear_config([section]); clear_config([section, key], value)`: " <>
|
||||
"#{inspect(config_path)}, #{inspect(temp_setting)}"
|
||||
"Please change `clear_config([section], key: value)` to `clear_config([section, key], value)`"
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -89,6 +89,18 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://mastodon.sdf.org/users/rinpatch/collections/featured", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
File.read!("test/fixtures/users_mock/masto_featured.json")
|
||||
|> String.replace("{{domain}}", "mastodon.sdf.org")
|
||||
|> String.replace("{{nickname}}", "rinpatch"),
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}}
|
||||
end
|
||||
|
||||
def get("https://patch.cx/objects/tesla_mock/poll_attachment", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
|
@ -122,7 +134,7 @@ defmodule HttpRequestMock do
|
|||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/mike@osada.macgirvin.com.json"),
|
||||
headers: activitypub_object_headers()
|
||||
headers: [{"content-type", "application/jrd+json"}]
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -187,7 +199,8 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
|
||||
body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml"),
|
||||
headers: [{"content-type", "application/xrd+xml"}]
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -526,22 +539,6 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("http://zetsubou.xn--q9jyb4c/.well-known/host-meta", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/xn--q9jyb4c_host_meta")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("https://zetsubou.xn--q9jyb4c/.well-known/host-meta", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/xn--q9jyb4c_host_meta")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("http://pleroma.soykaf.com/.well-known/host-meta", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
|
@ -786,7 +783,8 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml")
|
||||
body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml"),
|
||||
headers: [{"content-type", "application/xrd+xml"}]
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -796,7 +794,7 @@ defmodule HttpRequestMock do
|
|||
_,
|
||||
[{"accept", "application/xrd+xml,application/jrd+json"}]
|
||||
) do
|
||||
{:ok, %Tesla.Env{status: 200, body: ""}}
|
||||
{:ok, %Tesla.Env{status: 200, body: "", headers: [{"content-type", "application/jrd+json"}]}}
|
||||
end
|
||||
|
||||
def get("http://framatube.org/.well-known/host-meta", _, _, _) do
|
||||
|
|
@ -816,7 +814,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
headers: [{"content-type", "application/json"}],
|
||||
headers: [{"content-type", "application/jrd+json"}],
|
||||
body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
|
||||
}}
|
||||
end
|
||||
|
|
@ -876,7 +874,7 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
headers: [{"content-type", "application/json"}],
|
||||
headers: [{"content-type", "application/jrd+json"}],
|
||||
body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
|
||||
}}
|
||||
end
|
||||
|
|
@ -919,6 +917,18 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://mastodon.social/users/lambadalambda/collections/featured", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
File.read!("test/fixtures/users_mock/masto_featured.json")
|
||||
|> String.replace("{{domain}}", "mastodon.social")
|
||||
|> String.replace("{{nickname}}", "lambadalambda"),
|
||||
headers: activitypub_object_headers()
|
||||
}}
|
||||
end
|
||||
|
||||
def get("https://apfed.club/channel/indio", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
|
@ -1074,7 +1084,8 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/lain.xml")
|
||||
body: File.read!("test/fixtures/lain.xml"),
|
||||
headers: [{"content-type", "application/xrd+xml"}]
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -1087,7 +1098,16 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/lain.xml")
|
||||
body: File.read!("test/fixtures/lain.xml"),
|
||||
headers: [{"content-type", "application/xrd+xml"}]
|
||||
}}
|
||||
end
|
||||
|
||||
def get("http://zetsubou.xn--q9jyb4c/.well-known/host-meta", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -1153,7 +1173,8 @@ defmodule HttpRequestMock do
|
|||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
|
||||
body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml"),
|
||||
headers: [{"content-type", "application/xrd+xml"}]
|
||||
}}
|
||||
end
|
||||
|
||||
|
|
@ -1281,6 +1302,15 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://patch.cx/objects/a399c28e-c821-4820-bc3e-4afeb044c16f", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/emoji-in-summary.json"),
|
||||
headers: activitypub_object_headers()
|
||||
}}
|
||||
end
|
||||
|
||||
def get(url, query, body, headers) do
|
||||
{:error,
|
||||
"Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule MRFModuleMock do
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@impl true
|
||||
def filter(message), do: {:ok, message}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue