Merge branch 'develop' into issue/1790-updated-oban
This commit is contained in:
commit
4695bdd81b
194 changed files with 3217 additions and 970 deletions
57
test/config/deprecation_warnings_test.exs
Normal file
57
test/config/deprecation_warnings_test.exs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
defmodule Pleroma.Config.DeprecationWarningsTest do
|
||||
use ExUnit.Case, async: true
|
||||
use Pleroma.Tests.Helpers
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
|
||||
test "check_old_mrf_config/0" do
|
||||
clear_config([:instance, :rewrite_policy], Pleroma.Web.ActivityPub.MRF.NoOpPolicy)
|
||||
clear_config([:instance, :mrf_transparency], true)
|
||||
clear_config([:instance, :mrf_transparency_exclusions], [])
|
||||
|
||||
assert capture_log(fn -> Pleroma.Config.DeprecationWarnings.check_old_mrf_config() end) =~
|
||||
"""
|
||||
!!!DEPRECATION WARNING!!!
|
||||
Your config is using old namespaces for MRF configuration. They should work for now, but you are advised to change to new namespaces to prevent possible issues later:
|
||||
|
||||
* `config :pleroma, :instance, rewrite_policy` is now `config :pleroma, :mrf, policies`
|
||||
* `config :pleroma, :instance, mrf_transparency` is now `config :pleroma, :mrf, transparency`
|
||||
* `config :pleroma, :instance, mrf_transparency_exclusions` is now `config :pleroma, :mrf, transparency_exclusions`
|
||||
"""
|
||||
end
|
||||
|
||||
test "move_namespace_and_warn/2" do
|
||||
old_group1 = [:group, :key]
|
||||
old_group2 = [:group, :key2]
|
||||
old_group3 = [:group, :key3]
|
||||
|
||||
new_group1 = [:another_group, :key4]
|
||||
new_group2 = [:another_group, :key5]
|
||||
new_group3 = [:another_group, :key6]
|
||||
|
||||
clear_config(old_group1, 1)
|
||||
clear_config(old_group2, 2)
|
||||
clear_config(old_group3, 3)
|
||||
|
||||
clear_config(new_group1)
|
||||
clear_config(new_group2)
|
||||
clear_config(new_group3)
|
||||
|
||||
config_map = [
|
||||
{old_group1, new_group1, "\n error :key"},
|
||||
{old_group2, new_group2, "\n error :key2"},
|
||||
{old_group3, new_group3, "\n error :key3"}
|
||||
]
|
||||
|
||||
assert capture_log(fn ->
|
||||
Pleroma.Config.DeprecationWarnings.move_namespace_and_warn(
|
||||
config_map,
|
||||
"Warning preface"
|
||||
)
|
||||
end) =~ "Warning preface\n error :key\n error :key2\n error :key3"
|
||||
|
||||
assert Pleroma.Config.get(new_group1) == 1
|
||||
assert Pleroma.Config.get(new_group2) == 2
|
||||
assert Pleroma.Config.get(new_group3) == 3
|
||||
end
|
||||
end
|
||||
72
test/fixtures/fetch_mocks/104410921027210069.json
vendored
Normal file
72
test/fixtures/fetch_mocks/104410921027210069.json
vendored
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
{
|
||||
"@context" : [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
{
|
||||
"atomUri" : "ostatus:atomUri",
|
||||
"conversation" : "ostatus:conversation",
|
||||
"inReplyToAtomUri" : "ostatus:inReplyToAtomUri",
|
||||
"ostatus" : "http://ostatus.org#",
|
||||
"sensitive" : "as:sensitive",
|
||||
"toot" : "http://joinmastodon.org/ns#",
|
||||
"votersCount" : "toot:votersCount"
|
||||
}
|
||||
],
|
||||
"atomUri" : "https://busshi.moe/users/tuxcrafting/statuses/104410921027210069",
|
||||
"attachment" : [],
|
||||
"attributedTo" : "https://busshi.moe/users/tuxcrafting",
|
||||
"cc" : [
|
||||
"https://busshi.moe/users/tuxcrafting/followers",
|
||||
"https://stereophonic.space/users/fixpoint",
|
||||
"https://blob.cat/users/blobyoumu",
|
||||
"https://cawfee.club/users/grips",
|
||||
"https://jaeger.website/users/igel"
|
||||
],
|
||||
"content" : "<p><span class=\"h-card\"><a href=\"https://stereophonic.space/users/fixpoint\" class=\"u-url mention\">@<span>fixpoint</span></a></span> <span class=\"h-card\"><a href=\"https://blob.cat/users/blobyoumu\" class=\"u-url mention\">@<span>blobyoumu</span></a></span> <span class=\"h-card\"><a href=\"https://cawfee.club/users/grips\" class=\"u-url mention\">@<span>grips</span></a></span> <span class=\"h-card\"><a href=\"https://jaeger.website/users/igel\" class=\"u-url mention\">@<span>igel</span></a></span> there's a difference between not liking nukes and not liking nuclear power<br />nukes are pretty bad as are all WMDs in general but disliking nuclear power just indicates you are unable of thought</p>",
|
||||
"contentMap" : {
|
||||
"en" : "<p><span class=\"h-card\"><a href=\"https://stereophonic.space/users/fixpoint\" class=\"u-url mention\">@<span>fixpoint</span></a></span> <span class=\"h-card\"><a href=\"https://blob.cat/users/blobyoumu\" class=\"u-url mention\">@<span>blobyoumu</span></a></span> <span class=\"h-card\"><a href=\"https://cawfee.club/users/grips\" class=\"u-url mention\">@<span>grips</span></a></span> <span class=\"h-card\"><a href=\"https://jaeger.website/users/igel\" class=\"u-url mention\">@<span>igel</span></a></span> there's a difference between not liking nukes and not liking nuclear power<br />nukes are pretty bad as are all WMDs in general but disliking nuclear power just indicates you are unable of thought</p>"
|
||||
},
|
||||
"conversation" : "https://cawfee.club/contexts/ad6c73d8-efc2-4e74-84ea-2dacf1a27a5e",
|
||||
"id" : "https://busshi.moe/users/tuxcrafting/statuses/104410921027210069",
|
||||
"inReplyTo" : "https://stereophonic.space/objects/02997b83-3ea7-4b63-94af-ef3aa2d4ed17",
|
||||
"inReplyToAtomUri" : "https://stereophonic.space/objects/02997b83-3ea7-4b63-94af-ef3aa2d4ed17",
|
||||
"published" : "2020-06-26T15:10:19Z",
|
||||
"replies" : {
|
||||
"first" : {
|
||||
"items" : [],
|
||||
"next" : "https://busshi.moe/users/tuxcrafting/statuses/104410921027210069/replies?only_other_accounts=true&page=true",
|
||||
"partOf" : "https://busshi.moe/users/tuxcrafting/statuses/104410921027210069/replies",
|
||||
"type" : "CollectionPage"
|
||||
},
|
||||
"id" : "https://busshi.moe/users/tuxcrafting/statuses/104410921027210069/replies",
|
||||
"type" : "Collection"
|
||||
},
|
||||
"sensitive" : false,
|
||||
"summary" : null,
|
||||
"tag" : [
|
||||
{
|
||||
"href" : "https://stereophonic.space/users/fixpoint",
|
||||
"name" : "@fixpoint@stereophonic.space",
|
||||
"type" : "Mention"
|
||||
},
|
||||
{
|
||||
"href" : "https://blob.cat/users/blobyoumu",
|
||||
"name" : "@blobyoumu@blob.cat",
|
||||
"type" : "Mention"
|
||||
},
|
||||
{
|
||||
"href" : "https://cawfee.club/users/grips",
|
||||
"name" : "@grips@cawfee.club",
|
||||
"type" : "Mention"
|
||||
},
|
||||
{
|
||||
"href" : "https://jaeger.website/users/igel",
|
||||
"name" : "@igel@jaeger.website",
|
||||
"type" : "Mention"
|
||||
}
|
||||
],
|
||||
"to" : [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"type" : "Note",
|
||||
"url" : "https://busshi.moe/@tuxcrafting/104410921027210069"
|
||||
}
|
||||
59
test/fixtures/fetch_mocks/9wTkLEnuq47B25EehM.json
vendored
Normal file
59
test/fixtures/fetch_mocks/9wTkLEnuq47B25EehM.json
vendored
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
{
|
||||
"@context" : [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://social.sakamoto.gq/schemas/litepub-0.1.jsonld",
|
||||
{
|
||||
"@language" : "und"
|
||||
}
|
||||
],
|
||||
"actor" : "https://social.sakamoto.gq/users/eal",
|
||||
"attachment" : [],
|
||||
"attributedTo" : "https://social.sakamoto.gq/users/eal",
|
||||
"cc" : [
|
||||
"https://social.sakamoto.gq/users/eal/followers"
|
||||
],
|
||||
"content" : "<span class=\"h-card\"><a data-user=\"9uw2wH0iTYAMV7XnLU\" class=\"u-url mention\" href=\"https://busshi.moe/@tuxcrafting\" rel=\"ugc\">@<span>tuxcrafting</span></a></span> <span class=\"h-card\"><a data-user=\"9r5l8j8x23NI9KUFu4\" class=\"u-url mention\" href=\"https://stereophonic.space/users/fixpoint\" rel=\"ugc\">@<span>fixpoint</span></a></span> <span class=\"h-card\"><a data-user=\"9orDK545JwjY4Lxjge\" class=\"u-url mention\" href=\"https://blob.cat/users/blobyoumu\" rel=\"ugc\">@<span>blobyoumu</span></a></span> <span class=\"h-card\"><a data-user=\"68184\" class=\"u-url mention\" href=\"https://cawfee.club/users/grips\" rel=\"ugc\">@<span>grips</span></a></span> <span class=\"h-card\"><a data-user=\"9sAmMgHVKjTXKpgx84\" class=\"u-url mention\" href=\"https://jaeger.website/users/igel\" rel=\"ugc\">@<span>igel</span></a></span> What's bad about nukes?",
|
||||
"context" : "https://cawfee.club/contexts/ad6c73d8-efc2-4e74-84ea-2dacf1a27a5e",
|
||||
"conversation" : "https://cawfee.club/contexts/ad6c73d8-efc2-4e74-84ea-2dacf1a27a5e",
|
||||
"id" : "https://social.sakamoto.gq/objects/f20f2497-66d9-4a52-a2e1-1be2a39c32c1",
|
||||
"inReplyTo" : "https://busshi.moe/users/tuxcrafting/statuses/104410921027210069",
|
||||
"published" : "2020-06-26T15:20:15.975737Z",
|
||||
"sensitive" : false,
|
||||
"summary" : "",
|
||||
"tag" : [
|
||||
{
|
||||
"href" : "https://blob.cat/users/blobyoumu",
|
||||
"name" : "@blobyoumu@blob.cat",
|
||||
"type" : "Mention"
|
||||
},
|
||||
{
|
||||
"href" : "https://busshi.moe/users/tuxcrafting",
|
||||
"name" : "@tuxcrafting@busshi.moe",
|
||||
"type" : "Mention"
|
||||
},
|
||||
{
|
||||
"href" : "https://cawfee.club/users/grips",
|
||||
"name" : "@grips@cawfee.club",
|
||||
"type" : "Mention"
|
||||
},
|
||||
{
|
||||
"href" : "https://jaeger.website/users/igel",
|
||||
"name" : "@igel@jaeger.website",
|
||||
"type" : "Mention"
|
||||
},
|
||||
{
|
||||
"href" : "https://stereophonic.space/users/fixpoint",
|
||||
"name" : "@fixpoint@stereophonic.space",
|
||||
"type" : "Mention"
|
||||
}
|
||||
],
|
||||
"to" : [
|
||||
"https://busshi.moe/users/tuxcrafting",
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
"https://blob.cat/users/blobyoumu",
|
||||
"https://stereophonic.space/users/fixpoint",
|
||||
"https://cawfee.club/users/grips",
|
||||
"https://jaeger.website/users/igel"
|
||||
],
|
||||
"type" : "Note"
|
||||
}
|
||||
43
test/fixtures/fetch_mocks/eal.json
vendored
Normal file
43
test/fixtures/fetch_mocks/eal.json
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"@context" : [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://social.sakamoto.gq/schemas/litepub-0.1.jsonld",
|
||||
{
|
||||
"@language" : "und"
|
||||
}
|
||||
],
|
||||
"attachment" : [],
|
||||
"discoverable" : true,
|
||||
"endpoints" : {
|
||||
"oauthAuthorizationEndpoint" : "https://social.sakamoto.gq/oauth/authorize",
|
||||
"oauthRegistrationEndpoint" : "https://social.sakamoto.gq/api/v1/apps",
|
||||
"oauthTokenEndpoint" : "https://social.sakamoto.gq/oauth/token",
|
||||
"sharedInbox" : "https://social.sakamoto.gq/inbox",
|
||||
"uploadMedia" : "https://social.sakamoto.gq/api/ap/upload_media"
|
||||
},
|
||||
"followers" : "https://social.sakamoto.gq/users/eal/followers",
|
||||
"following" : "https://social.sakamoto.gq/users/eal/following",
|
||||
"icon" : {
|
||||
"type" : "Image",
|
||||
"url" : "https://social.sakamoto.gq/media/f1cb6f79bf6839f3223ca240441f766056b74ddd23c69bcaf8bb1ba1ecff6eec.jpg"
|
||||
},
|
||||
"id" : "https://social.sakamoto.gq/users/eal",
|
||||
"image" : {
|
||||
"type" : "Image",
|
||||
"url" : "https://social.sakamoto.gq/media/e5cccf26421e8366f4e34be3c9d5042b8bc8dcceccc7c8e89785fa312dd9632c.jpg"
|
||||
},
|
||||
"inbox" : "https://social.sakamoto.gq/users/eal/inbox",
|
||||
"manuallyApprovesFollowers" : false,
|
||||
"name" : "ìì",
|
||||
"outbox" : "https://social.sakamoto.gq/users/eal/outbox",
|
||||
"preferredUsername" : "eal",
|
||||
"publicKey" : {
|
||||
"id" : "https://social.sakamoto.gq/users/eal#main-key",
|
||||
"owner" : "https://social.sakamoto.gq/users/eal",
|
||||
"publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz3pF85YOhhv2Zaxv9YQ7\nrCe1aEhetCMVHtrK63tUVGoGdsblyKnVeJNbFcr6k3y35OpHS3HXIi6GzgihYcTu\nONLP4eQMHTnLUNAQZi03mjJA4iIq8v/tm8ZkL2mXsQSAbWj6Iq518mHNN7OvCoNt\n3Xjepl/0kgkc2gsund7m8r+Wu0Fusx6UlUyyAk3PexdDRdSSlVLeskqtP8jtdQDo\nL70pMyL+VD+Qb9RKFdtgJ+M4OqYP+7FVzCqXN0QIPhFf/kvHSLr+c4Y3Wm0nAKHU\n9CwXWXz5Xqscpv41KlgnUCOkTXb5eBSt23lNulae5srVzWBiFb6guiCpNzBGa+Sq\nrwIDAQAB\n-----END PUBLIC KEY-----\n\n"
|
||||
},
|
||||
"summary" : "Pizza napoletana supremacist.<br><br>Any artworks posted here that are good are not mine.",
|
||||
"tag" : [],
|
||||
"type" : "Person",
|
||||
"url" : "https://social.sakamoto.gq/users/eal"
|
||||
}
|
||||
59
test/fixtures/fetch_mocks/tuxcrafting.json
vendored
Normal file
59
test/fixtures/fetch_mocks/tuxcrafting.json
vendored
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
{
|
||||
"@context" : [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"IdentityProof" : "toot:IdentityProof",
|
||||
"PropertyValue" : "schema:PropertyValue",
|
||||
"alsoKnownAs" : {
|
||||
"@id" : "as:alsoKnownAs",
|
||||
"@type" : "@id"
|
||||
},
|
||||
"discoverable" : "toot:discoverable",
|
||||
"featured" : {
|
||||
"@id" : "toot:featured",
|
||||
"@type" : "@id"
|
||||
},
|
||||
"focalPoint" : {
|
||||
"@container" : "@list",
|
||||
"@id" : "toot:focalPoint"
|
||||
},
|
||||
"manuallyApprovesFollowers" : "as:manuallyApprovesFollowers",
|
||||
"movedTo" : {
|
||||
"@id" : "as:movedTo",
|
||||
"@type" : "@id"
|
||||
},
|
||||
"schema" : "http://schema.org#",
|
||||
"toot" : "http://joinmastodon.org/ns#",
|
||||
"value" : "schema:value"
|
||||
}
|
||||
],
|
||||
"attachment" : [],
|
||||
"discoverable" : true,
|
||||
"endpoints" : {
|
||||
"sharedInbox" : "https://busshi.moe/inbox"
|
||||
},
|
||||
"featured" : "https://busshi.moe/users/tuxcrafting/collections/featured",
|
||||
"followers" : "https://busshi.moe/users/tuxcrafting/followers",
|
||||
"following" : "https://busshi.moe/users/tuxcrafting/following",
|
||||
"icon" : {
|
||||
"mediaType" : "image/jpeg",
|
||||
"type" : "Image",
|
||||
"url" : "https://blobcdn.busshi.moe/busshifiles/accounts/avatars/000/046/872/original/054f0806ccb303d0.jpg"
|
||||
},
|
||||
"id" : "https://busshi.moe/users/tuxcrafting",
|
||||
"inbox" : "https://busshi.moe/users/tuxcrafting/inbox",
|
||||
"manuallyApprovesFollowers" : true,
|
||||
"name" : "@tuxcrafting@localhost:8080",
|
||||
"outbox" : "https://busshi.moe/users/tuxcrafting/outbox",
|
||||
"preferredUsername" : "tuxcrafting",
|
||||
"publicKey" : {
|
||||
"id" : "https://busshi.moe/users/tuxcrafting#main-key",
|
||||
"owner" : "https://busshi.moe/users/tuxcrafting",
|
||||
"publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwqWWTBf9OizsBiBhGS/M\nQTT6fB1VvQP6vvxouGZ5cGg1a97V67ouhjJ+nGMuWr++DNYjJYkk2TOynfykk0H/\n8rRSujSe3BNRKYGNzdnRJu/4XxgIE847Fqx5SijSP23JGYcn8TjeSUsN2u2YYVXK\n+Eb3Bu7DjGiqwNon6YB0h5qkGjkMSMVIFn0hZx6Z21bkfYWgra96Ok5OWf7Ck3je\nCuErlCMZcbQcHtFpBueJAxYchjNvm6fqwZxLX/NtaHdr7Fm2kin89mqzliapBlFH\nCXk7Jln6xV5I6ryggPAMzm3fuHzeo0RWlu8lrxLfARBVwaQQZS99bwqp6N9O2aUp\nYwIDAQAB\n-----END PUBLIC KEY-----\n"
|
||||
},
|
||||
"summary" : "<p>expert procrastinator</p><p>trans(humanist|gender|istorized)</p><p>web: <a href=\"https://tuxcrafting.port0.org\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">tuxcrafting.port0.org</span><span class=\"invisible\"></span></a><br />pronouns: she/they<br />languages: french (native)/english (fluent)/hebrew (ok-ish)/esperanto (barely)</p>",
|
||||
"tag" : [],
|
||||
"type" : "Person",
|
||||
"url" : "https://busshi.moe/@tuxcrafting"
|
||||
}
|
||||
1
test/fixtures/preload_static/instance/panel.html
vendored
Normal file
1
test/fixtures/preload_static/instance/panel.html
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
HEY!
|
||||
File diff suppressed because one or more lines are too long
188
test/fixtures/tesla_mock/peertube.moe-vid.json
vendored
188
test/fixtures/tesla_mock/peertube.moe-vid.json
vendored
File diff suppressed because one or more lines are too long
|
|
@ -237,5 +237,19 @@ defmodule Pleroma.HTMLTest do
|
|||
|
||||
assert {:ok, nil} = HTML.extract_first_external_url(object, object.data["content"])
|
||||
end
|
||||
|
||||
test "skips attachment links" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
status:
|
||||
"<a href=\"https://pleroma.gov/media/d24caa3a498e21e0298377a9ca0149a4f4f8b767178aacf837542282e2d94fb1.png?name=image.png\" class=\"attachment\">image.png</a>"
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert {:ok, nil} = HTML.extract_first_external_url(object, object.data["content"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
54
test/http/ex_aws_test.exs
Normal file
54
test/http/ex_aws_test.exs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.HTTP.ExAwsTest do
|
||||
use ExUnit.Case
|
||||
|
||||
import Tesla.Mock
|
||||
alias Pleroma.HTTP
|
||||
|
||||
@url "https://s3.amazonaws.com/test_bucket/test_image.jpg"
|
||||
|
||||
setup do
|
||||
mock(fn
|
||||
%{method: :get, url: @url, headers: [{"x-amz-bucket-region", "us-east-1"}]} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: "image-content",
|
||||
headers: [{"x-amz-bucket-region", "us-east-1"}]
|
||||
}
|
||||
|
||||
%{method: :post, url: @url, body: "image-content-2"} ->
|
||||
%Tesla.Env{status: 200, body: "image-content-2"}
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "request" do
|
||||
test "get" do
|
||||
assert HTTP.ExAws.request(:get, @url, "", [{"x-amz-bucket-region", "us-east-1"}]) == {
|
||||
:ok,
|
||||
%{
|
||||
body: "image-content",
|
||||
headers: [{"x-amz-bucket-region", "us-east-1"}],
|
||||
status_code: 200
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
test "post" do
|
||||
assert HTTP.ExAws.request(:post, @url, "image-content-2", [
|
||||
{"x-amz-bucket-region", "us-east-1"}
|
||||
]) == {
|
||||
:ok,
|
||||
%{
|
||||
body: "image-content-2",
|
||||
headers: [],
|
||||
status_code: 200
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
35
test/http/tzdata_test.exs
Normal file
35
test/http/tzdata_test.exs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.HTTP.TzdataTest do
|
||||
use ExUnit.Case
|
||||
|
||||
import Tesla.Mock
|
||||
alias Pleroma.HTTP
|
||||
@url "https://data.iana.org/time-zones/tzdata-latest.tar.gz"
|
||||
|
||||
setup do
|
||||
mock(fn
|
||||
%{method: :head, url: @url} ->
|
||||
%Tesla.Env{status: 200, body: ""}
|
||||
|
||||
%{method: :get, url: @url} ->
|
||||
%Tesla.Env{status: 200, body: "hello"}
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "head/1" do
|
||||
test "returns successfully result" do
|
||||
assert HTTP.Tzdata.head(@url, [], []) == {:ok, {200, []}}
|
||||
end
|
||||
end
|
||||
|
||||
describe "get/1" do
|
||||
test "returns successfully result" do
|
||||
assert HTTP.Tzdata.get(@url, [], []) == {:ok, {200, [], "hello"}}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -17,6 +17,9 @@ defmodule Pleroma.HTTPTest do
|
|||
} ->
|
||||
json(%{"my" => "data"})
|
||||
|
||||
%{method: :head, url: "http://example.com/hello"} ->
|
||||
%Tesla.Env{status: 200, body: ""}
|
||||
|
||||
%{method: :get, url: "http://example.com/hello"} ->
|
||||
%Tesla.Env{status: 200, body: "hello"}
|
||||
|
||||
|
|
@ -27,6 +30,12 @@ defmodule Pleroma.HTTPTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
describe "head/1" do
|
||||
test "returns successfully result" do
|
||||
assert HTTP.head("http://example.com/hello") == {:ok, %Tesla.Env{status: 200, body: ""}}
|
||||
end
|
||||
end
|
||||
|
||||
describe "get/1" do
|
||||
test "returns successfully result" do
|
||||
assert HTTP.get("http://example.com/hello") == {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,16 @@ defmodule Pleroma.NotificationTest do
|
|||
alias Pleroma.Web.Streamer
|
||||
|
||||
describe "create_notifications" do
|
||||
test "never returns nil" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, %{invisible: true})
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "yeah"})
|
||||
{:ok, activity} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")
|
||||
|
||||
refute {:ok, [nil]} == Notification.create_notifications(activity)
|
||||
end
|
||||
|
||||
test "creates a notification for an emoji reaction" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,46 @@ defmodule Pleroma.Object.FetcherTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
describe "error cases" do
|
||||
setup do
|
||||
mock(fn
|
||||
%{method: :get, url: "https://social.sakamoto.gq/notice/9wTkLEnuq47B25EehM"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/fetch_mocks/9wTkLEnuq47B25EehM.json")
|
||||
}
|
||||
|
||||
%{method: :get, url: "https://social.sakamoto.gq/users/eal"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/fetch_mocks/eal.json")
|
||||
}
|
||||
|
||||
%{method: :get, url: "https://busshi.moe/users/tuxcrafting/statuses/104410921027210069"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/fetch_mocks/104410921027210069.json")
|
||||
}
|
||||
|
||||
%{method: :get, url: "https://busshi.moe/users/tuxcrafting"} ->
|
||||
%Tesla.Env{
|
||||
status: 500
|
||||
}
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
test "it works when fetching the OP actor errors out" do
|
||||
# Here we simulate a case where the author of the OP can't be read
|
||||
assert {:ok, _} =
|
||||
Fetcher.fetch_object_from_id(
|
||||
"https://social.sakamoto.gq/notice/9wTkLEnuq47B25EehM"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "max thread distance restriction" do
|
||||
@ap_id "http://mastodon.example.org/@admin/99541947525187367"
|
||||
setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ defmodule Pleroma.Web.RuntimeStaticPlugTest do
|
|||
|
||||
test "overrides index" do
|
||||
bundled_index = get(build_conn(), "/")
|
||||
assert html_response(bundled_index, 200) == File.read!("priv/static/index.html")
|
||||
refute html_response(bundled_index, 200) == "hello world"
|
||||
|
||||
File.write!(@dir <> "/index.html", "hello world")
|
||||
|
||||
|
|
|
|||
|
|
@ -17,10 +17,11 @@ defmodule Pleroma.StatsTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "status visibility count" do
|
||||
describe "status visibility sum count" do
|
||||
test "on new status" do
|
||||
instance2 = "instance2.tld"
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
other_user = insert(:user, %{ap_id: "https://#{instance2}/@actor"})
|
||||
|
||||
CommonAPI.post(user, %{visibility: "public", status: "hey"})
|
||||
|
||||
|
|
@ -45,24 +46,24 @@ defmodule Pleroma.StatsTest do
|
|||
})
|
||||
end)
|
||||
|
||||
assert %{direct: 3, private: 4, public: 1, unlisted: 2} =
|
||||
assert %{"direct" => 3, "private" => 4, "public" => 1, "unlisted" => 2} =
|
||||
Pleroma.Stats.get_status_visibility_count()
|
||||
end
|
||||
|
||||
test "on status delete" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{visibility: "public", status: "hey"})
|
||||
assert %{public: 1} = Pleroma.Stats.get_status_visibility_count()
|
||||
assert %{"public" => 1} = Pleroma.Stats.get_status_visibility_count()
|
||||
CommonAPI.delete(activity.id, user)
|
||||
assert %{public: 0} = Pleroma.Stats.get_status_visibility_count()
|
||||
assert %{"public" => 0} = Pleroma.Stats.get_status_visibility_count()
|
||||
end
|
||||
|
||||
test "on status visibility update" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{visibility: "public", status: "hey"})
|
||||
assert %{public: 1, private: 0} = Pleroma.Stats.get_status_visibility_count()
|
||||
assert %{"public" => 1, "private" => 0} = Pleroma.Stats.get_status_visibility_count()
|
||||
{:ok, _} = CommonAPI.update_activity_scope(activity.id, %{visibility: "private"})
|
||||
assert %{public: 0, private: 1} = Pleroma.Stats.get_status_visibility_count()
|
||||
assert %{"public" => 0, "private" => 1} = Pleroma.Stats.get_status_visibility_count()
|
||||
end
|
||||
|
||||
test "doesn't count unrelated activities" do
|
||||
|
|
@ -73,8 +74,46 @@ defmodule Pleroma.StatsTest do
|
|||
CommonAPI.favorite(other_user, activity.id)
|
||||
CommonAPI.repeat(activity.id, other_user)
|
||||
|
||||
assert %{direct: 0, private: 0, public: 1, unlisted: 0} =
|
||||
assert %{"direct" => 0, "private" => 0, "public" => 1, "unlisted" => 0} =
|
||||
Pleroma.Stats.get_status_visibility_count()
|
||||
end
|
||||
end
|
||||
|
||||
describe "status visibility by instance count" do
|
||||
test "single instance" do
|
||||
local_instance = Pleroma.Web.Endpoint.url() |> String.split("//") |> Enum.at(1)
|
||||
instance2 = "instance2.tld"
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user, %{ap_id: "https://#{instance2}/@actor"})
|
||||
|
||||
CommonAPI.post(user1, %{visibility: "public", status: "hey"})
|
||||
|
||||
Enum.each(1..5, fn _ ->
|
||||
CommonAPI.post(user1, %{
|
||||
visibility: "unlisted",
|
||||
status: "hey"
|
||||
})
|
||||
end)
|
||||
|
||||
Enum.each(1..10, fn _ ->
|
||||
CommonAPI.post(user1, %{
|
||||
visibility: "direct",
|
||||
status: "hey @#{user2.nickname}"
|
||||
})
|
||||
end)
|
||||
|
||||
Enum.each(1..20, fn _ ->
|
||||
CommonAPI.post(user2, %{
|
||||
visibility: "private",
|
||||
status: "hey"
|
||||
})
|
||||
end)
|
||||
|
||||
assert %{"direct" => 10, "private" => 0, "public" => 1, "unlisted" => 5} =
|
||||
Pleroma.Stats.get_status_visibility_count(local_instance)
|
||||
|
||||
assert %{"direct" => 0, "private" => 20, "public" => 0, "unlisted" => 0} =
|
||||
Pleroma.Stats.get_status_visibility_count(instance2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ defmodule Pleroma.Factory do
|
|||
data = %{
|
||||
"type" => "Note",
|
||||
"content" => text,
|
||||
"source" => text,
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
|
||||
"actor" => user.ap_id,
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
|
|
|
|||
|
|
@ -121,14 +121,11 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
federation_reachability_timeout_days: 7,
|
||||
federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],
|
||||
allow_relay: true,
|
||||
rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,
|
||||
public: true,
|
||||
quarantined_instances: [],
|
||||
managed_config: true,
|
||||
static_dir: "instance/static/",
|
||||
allowed_post_formats: ["text/plain", "text/html", "text/markdown", "text/bbcode"],
|
||||
mrf_transparency: true,
|
||||
mrf_transparency_exclusions: [],
|
||||
autofollowed_nicknames: [],
|
||||
max_pinned_statuses: 1,
|
||||
attachment_links: false,
|
||||
|
|
@ -175,7 +172,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
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 rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,\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 mrf_transparency: true,\n mrf_transparency_exclusions: [],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n attachment_links: false,\n welcome_user_nickname: nil,\n welcome_message: nil,\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"
|
||||
"#{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 welcome_user_nickname: nil,\n welcome_message: nil,\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
|
||||
end
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ defmodule Mix.Tasks.Pleroma.RefreshCounterCacheTest do
|
|||
|
||||
assert capture_io(fn -> Mix.Tasks.Pleroma.RefreshCounterCache.run([]) end) =~ "Done\n"
|
||||
|
||||
assert %{direct: 3, private: 4, public: 1, unlisted: 2} =
|
||||
assert %{"direct" => 3, "private" => 4, "public" => 1, "unlisted" => 2} =
|
||||
Pleroma.Stats.get_status_visibility_count()
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ defmodule Pleroma.UserSearchTest do
|
|||
describe "User.search" do
|
||||
setup do: clear_config([:instance, :limit_to_local_content])
|
||||
|
||||
test "excluded invisible users from results" do
|
||||
test "excludes invisible users from results" do
|
||||
user = insert(:user, %{nickname: "john t1000"})
|
||||
insert(:user, %{invisible: true, nickname: "john t800"})
|
||||
|
||||
|
|
@ -25,6 +25,15 @@ defmodule Pleroma.UserSearchTest do
|
|||
assert found_user.id == user.id
|
||||
end
|
||||
|
||||
test "excludes service actors from results" do
|
||||
insert(:user, actor_type: "Application", nickname: "user1")
|
||||
service = insert(:user, actor_type: "Service", nickname: "user2")
|
||||
person = insert(:user, actor_type: "Person", nickname: "user3")
|
||||
|
||||
assert [found_user1, found_user2] = User.search("user")
|
||||
assert [found_user1.id, found_user2.id] -- [service.id, person.id] == []
|
||||
end
|
||||
|
||||
test "accepts limit parameter" do
|
||||
Enum.each(0..4, &insert(:user, %{nickname: "john#{&1}"}))
|
||||
assert length(User.search("john", limit: 3)) == 3
|
||||
|
|
|
|||
|
|
@ -199,6 +199,16 @@ defmodule Pleroma.UserTest do
|
|||
assert [^pending_follower] = User.get_follow_requests(locked)
|
||||
end
|
||||
|
||||
test "doesn't return follow requests for deactivated accounts" do
|
||||
locked = insert(:user, locked: true)
|
||||
pending_follower = insert(:user, %{deactivated: true})
|
||||
|
||||
CommonAPI.follow(pending_follower, locked)
|
||||
|
||||
assert true == pending_follower.deactivated
|
||||
assert [] = User.get_follow_requests(locked)
|
||||
end
|
||||
|
||||
test "clears follow requests when requester is blocked" do
|
||||
followed = insert(:user, locked: true)
|
||||
follower = insert(:user)
|
||||
|
|
@ -587,6 +597,31 @@ defmodule Pleroma.UserTest do
|
|||
refute user.last_refreshed_at == orig_user.last_refreshed_at
|
||||
end
|
||||
|
||||
test "if nicknames clash, the old user gets a prefix with the old id to the nickname" do
|
||||
a_week_ago = NaiveDateTime.add(NaiveDateTime.utc_now(), -604_800)
|
||||
|
||||
orig_user =
|
||||
insert(
|
||||
:user,
|
||||
local: false,
|
||||
nickname: "admin@mastodon.example.org",
|
||||
ap_id: "http://mastodon.example.org/users/harinezumigari",
|
||||
last_refreshed_at: a_week_ago
|
||||
)
|
||||
|
||||
assert orig_user.last_refreshed_at == a_week_ago
|
||||
|
||||
{:ok, user} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
|
||||
|
||||
assert user.inbox
|
||||
|
||||
refute user.id == orig_user.id
|
||||
|
||||
orig_user = User.get_by_id(orig_user.id)
|
||||
|
||||
assert orig_user.nickname == "#{orig_user.id}.admin@mastodon.example.org"
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
test "it returns the old user if stale, but unfetchable" do
|
||||
a_week_ago = NaiveDateTime.add(NaiveDateTime.utc_now(), -604_800)
|
||||
|
|
|
|||
|
|
@ -536,6 +536,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
assert_receive {:mix_shell, :info, ["relay.mastodon.host"]}
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
test "without valid signature, " <>
|
||||
"it only accepts Create activities and requires enabled federation",
|
||||
%{conn: conn} do
|
||||
|
|
@ -648,11 +649,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
test "it accepts announces with to as string instead of array", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, post} = CommonAPI.post(user, %{status: "hey"})
|
||||
announcer = insert(:user, local: false)
|
||||
|
||||
data = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"actor" => "http://mastodon.example.org/users/admin",
|
||||
"id" => "http://mastodon.example.org/users/admin/statuses/19512778738411822/activity",
|
||||
"object" => "https://mastodon.social/users/emelie/statuses/101849165031453009",
|
||||
"actor" => announcer.ap_id,
|
||||
"id" => "#{announcer.ap_id}/statuses/19512778738411822/activity",
|
||||
"object" => post.data["object"],
|
||||
"to" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"cc" => [user.ap_id],
|
||||
"type" => "Announce"
|
||||
|
|
|
|||
|
|
@ -992,54 +992,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "blocking" do
|
||||
test "reverts block activity on error" do
|
||||
[blocker, blocked] = insert_list(2, :user)
|
||||
|
||||
with_mock(Utils, [:passthrough], maybe_federate: fn _ -> {:error, :reverted} end) do
|
||||
assert {:error, :reverted} = ActivityPub.block(blocker, blocked)
|
||||
end
|
||||
|
||||
assert Repo.aggregate(Activity, :count, :id) == 0
|
||||
assert Repo.aggregate(Object, :count, :id) == 0
|
||||
end
|
||||
|
||||
test "creates a block activity" do
|
||||
clear_config([:instance, :federating], true)
|
||||
blocker = insert(:user)
|
||||
blocked = insert(:user)
|
||||
|
||||
with_mock Pleroma.Web.Federator,
|
||||
publish: fn _ -> nil end do
|
||||
{:ok, activity} = ActivityPub.block(blocker, blocked)
|
||||
|
||||
assert activity.data["type"] == "Block"
|
||||
assert activity.data["actor"] == blocker.ap_id
|
||||
assert activity.data["object"] == blocked.ap_id
|
||||
|
||||
assert called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
|
||||
test "works with outgoing blocks disabled, but doesn't federate" do
|
||||
clear_config([:instance, :federating], true)
|
||||
clear_config([:activitypub, :outgoing_blocks], false)
|
||||
blocker = insert(:user)
|
||||
blocked = insert(:user)
|
||||
|
||||
with_mock Pleroma.Web.Federator,
|
||||
publish: fn _ -> nil end do
|
||||
{:ok, activity} = ActivityPub.block(blocker, blocked)
|
||||
|
||||
assert activity.data["type"] == "Block"
|
||||
assert activity.data["actor"] == blocker.ap_id
|
||||
assert activity.data["object"] == blocked.ap_id
|
||||
|
||||
refute called(Pleroma.Web.Federator.publish(:_))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "timeline post-processing" do
|
||||
test "it filters broken threads" do
|
||||
user1 = insert(:user)
|
||||
|
|
@ -1092,52 +1044,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "update" do
|
||||
setup do: clear_config([:instance, :max_pinned_statuses])
|
||||
|
||||
test "it creates an update activity with the new user data" do
|
||||
user = insert(:user)
|
||||
{:ok, user} = User.ensure_keys_present(user)
|
||||
user_data = Pleroma.Web.ActivityPub.UserView.render("user.json", %{user: user})
|
||||
|
||||
{:ok, update} =
|
||||
ActivityPub.update(%{
|
||||
actor: user_data["id"],
|
||||
to: [user.follower_address],
|
||||
cc: [],
|
||||
object: user_data
|
||||
})
|
||||
|
||||
assert update.data["actor"] == user.ap_id
|
||||
assert update.data["to"] == [user.follower_address]
|
||||
assert embedded_object = update.data["object"]
|
||||
assert embedded_object["id"] == user_data["id"]
|
||||
assert embedded_object["type"] == user_data["type"]
|
||||
end
|
||||
end
|
||||
|
||||
test "returned pinned statuses" do
|
||||
Config.put([:instance, :max_pinned_statuses], 3)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity_one} = CommonAPI.post(user, %{status: "HI!!!"})
|
||||
{:ok, activity_two} = CommonAPI.post(user, %{status: "HI!!!"})
|
||||
{:ok, activity_three} = CommonAPI.post(user, %{status: "HI!!!"})
|
||||
|
||||
CommonAPI.pin(activity_one.id, user)
|
||||
user = refresh_record(user)
|
||||
|
||||
CommonAPI.pin(activity_two.id, user)
|
||||
user = refresh_record(user)
|
||||
|
||||
CommonAPI.pin(activity_three.id, user)
|
||||
user = refresh_record(user)
|
||||
|
||||
activities = ActivityPub.fetch_user_activities(user, nil, %{pinned: true})
|
||||
|
||||
assert 3 = length(activities)
|
||||
end
|
||||
|
||||
describe "flag/1" do
|
||||
setup do
|
||||
reporter = insert(:user)
|
||||
|
|
@ -2055,11 +1961,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
|
||||
describe "global activity expiration" do
|
||||
setup do: clear_config([:instance, :rewrite_policy])
|
||||
setup do: clear_config([:mrf, :policies])
|
||||
|
||||
test "creates an activity expiration for local Create activities" do
|
||||
Pleroma.Config.put(
|
||||
[:instance, :rewrite_policy],
|
||||
[:mrf, :policies],
|
||||
Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
|
|||
|
||||
describe "with new user" do
|
||||
test "it allows posts without links" do
|
||||
user = insert(:user)
|
||||
user = insert(:user, local: false)
|
||||
|
||||
assert user.note_count == 0
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
|
|||
end
|
||||
|
||||
test "it disallows posts with links" do
|
||||
user = insert(:user)
|
||||
user = insert(:user, local: false)
|
||||
|
||||
assert user.note_count == 0
|
||||
|
||||
|
|
@ -55,6 +55,18 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
|
|||
|
||||
{:reject, _} = AntiLinkSpamPolicy.filter(message)
|
||||
end
|
||||
|
||||
test "it allows posts with links for local users" do
|
||||
user = insert(:user)
|
||||
|
||||
assert user.note_count == 0
|
||||
|
||||
message =
|
||||
@linkful_message
|
||||
|> Map.put("actor", user.ap_id)
|
||||
|
||||
{:ok, _message} = AntiLinkSpamPolicy.filter(message)
|
||||
end
|
||||
end
|
||||
|
||||
describe "with old user" do
|
||||
|
|
|
|||
|
|
@ -60,8 +60,6 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
end
|
||||
|
||||
describe "describe/0" do
|
||||
setup do: clear_config([:instance, :rewrite_policy])
|
||||
|
||||
test "it works as expected with noop policy" do
|
||||
expected = %{
|
||||
mrf_policies: ["NoOpPolicy"],
|
||||
|
|
@ -72,7 +70,7 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
end
|
||||
|
||||
test "it works as expected with mock policy" do
|
||||
Pleroma.Config.put([:instance, :rewrite_policy], [MRFModuleMock])
|
||||
clear_config([:mrf, :policies], [MRFModuleMock])
|
||||
|
||||
expected = %{
|
||||
mrf_policies: ["MRFModuleMock"],
|
||||
|
|
|
|||
|
|
@ -622,4 +622,63 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
|
|||
assert {:actor, {"can not announce this object publicly", []}} in cng.errors
|
||||
end
|
||||
end
|
||||
|
||||
describe "updates" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
||||
object = %{
|
||||
"id" => user.ap_id,
|
||||
"name" => "A new name",
|
||||
"summary" => "A new bio"
|
||||
}
|
||||
|
||||
{:ok, valid_update, []} = Builder.update(user, object)
|
||||
|
||||
%{user: user, valid_update: valid_update}
|
||||
end
|
||||
|
||||
test "validates a basic object", %{valid_update: valid_update} do
|
||||
assert {:ok, _update, []} = ObjectValidator.validate(valid_update, [])
|
||||
end
|
||||
|
||||
test "returns an error if the object can't be updated by the actor", %{
|
||||
valid_update: valid_update
|
||||
} do
|
||||
other_user = insert(:user)
|
||||
|
||||
update =
|
||||
valid_update
|
||||
|> Map.put("actor", other_user.ap_id)
|
||||
|
||||
assert {:error, _cng} = ObjectValidator.validate(update, [])
|
||||
end
|
||||
end
|
||||
|
||||
describe "blocks" do
|
||||
setup do
|
||||
user = insert(:user, local: false)
|
||||
blocked = insert(:user)
|
||||
|
||||
{:ok, valid_block, []} = Builder.block(user, blocked)
|
||||
|
||||
%{user: user, valid_block: valid_block}
|
||||
end
|
||||
|
||||
test "validates a basic object", %{
|
||||
valid_block: valid_block
|
||||
} do
|
||||
assert {:ok, _block, []} = ObjectValidator.validate(valid_block, [])
|
||||
end
|
||||
|
||||
test "returns an error if we don't know the blocked user", %{
|
||||
valid_block: valid_block
|
||||
} do
|
||||
block =
|
||||
valid_block
|
||||
|> Map.put("object", "https://gensokyo.2hu/users/raymoo")
|
||||
|
||||
assert {:error, _cng} = ObjectValidator.validate(block, [])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -64,6 +64,72 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "blocking users" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
blocked = insert(:user)
|
||||
User.follow(blocked, user)
|
||||
User.follow(user, blocked)
|
||||
|
||||
{:ok, block_data, []} = Builder.block(user, blocked)
|
||||
{:ok, block, _meta} = ActivityPub.persist(block_data, local: true)
|
||||
|
||||
%{user: user, blocked: blocked, block: block}
|
||||
end
|
||||
|
||||
test "it unfollows and blocks", %{user: user, blocked: blocked, block: block} do
|
||||
assert User.following?(user, blocked)
|
||||
assert User.following?(blocked, user)
|
||||
|
||||
{:ok, _, _} = SideEffects.handle(block)
|
||||
|
||||
refute User.following?(user, blocked)
|
||||
refute User.following?(blocked, user)
|
||||
assert User.blocks?(user, blocked)
|
||||
end
|
||||
|
||||
test "it blocks but does not unfollow if the relevant setting is set", %{
|
||||
user: user,
|
||||
blocked: blocked,
|
||||
block: block
|
||||
} do
|
||||
clear_config([:activitypub, :unfollow_blocked], false)
|
||||
assert User.following?(user, blocked)
|
||||
assert User.following?(blocked, user)
|
||||
|
||||
{:ok, _, _} = SideEffects.handle(block)
|
||||
|
||||
refute User.following?(user, blocked)
|
||||
assert User.following?(blocked, user)
|
||||
assert User.blocks?(user, blocked)
|
||||
end
|
||||
end
|
||||
|
||||
describe "update users" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
{:ok, update_data, []} = Builder.update(user, %{"id" => user.ap_id, "name" => "new name!"})
|
||||
{:ok, update, _meta} = ActivityPub.persist(update_data, local: true)
|
||||
|
||||
%{user: user, update_data: update_data, update: update}
|
||||
end
|
||||
|
||||
test "it updates the user", %{user: user, update: update} do
|
||||
{:ok, _, _} = SideEffects.handle(update)
|
||||
user = User.get_by_id(user.id)
|
||||
assert user.name == "new name!"
|
||||
end
|
||||
|
||||
test "it uses a given changeset to update", %{user: user, update: update} do
|
||||
changeset = Ecto.Changeset.change(user, %{default_scope: "direct"})
|
||||
|
||||
assert user.default_scope == "public"
|
||||
{:ok, _, _} = SideEffects.handle(update, user_update_changeset: changeset)
|
||||
user = User.get_by_id(user.id)
|
||||
assert user.default_scope == "direct"
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete objects" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
|
@ -217,8 +283,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
{:ok, like} = CommonAPI.favorite(user, post.id)
|
||||
{:ok, reaction} = CommonAPI.react_with_emoji(post.id, user, "👍")
|
||||
{:ok, announce} = CommonAPI.repeat(post.id, user)
|
||||
{:ok, block} = ActivityPub.block(user, poster)
|
||||
User.block(user, poster)
|
||||
{:ok, block} = CommonAPI.block(user, poster)
|
||||
|
||||
{:ok, undo_data, _meta} = Builder.undo(user, like)
|
||||
{:ok, like_undo, _meta} = ActivityPub.persist(undo_data, local: true)
|
||||
|
|
@ -524,10 +589,29 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
end
|
||||
|
||||
test "it streams out the announce", %{announce: announce} do
|
||||
with_mock Pleroma.Web.ActivityPub.ActivityPub, [:passthrough], stream_out: fn _ -> nil end do
|
||||
with_mocks([
|
||||
{
|
||||
Pleroma.Web.Streamer,
|
||||
[],
|
||||
[
|
||||
stream: fn _, _ -> nil end
|
||||
]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.Push,
|
||||
[],
|
||||
[
|
||||
send: fn _ -> nil end
|
||||
]
|
||||
}
|
||||
]) do
|
||||
{:ok, announce, _} = SideEffects.handle(announce)
|
||||
|
||||
assert called(Pleroma.Web.ActivityPub.ActivityPub.stream_out(announce))
|
||||
assert called(
|
||||
Pleroma.Web.Streamer.stream(["user", "list", "public", "public:local"], announce)
|
||||
)
|
||||
|
||||
assert called(Pleroma.Web.Push.send(:_))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
63
test/web/activity_pub/transmogrifier/block_handling_test.exs
Normal file
63
test/web/activity_pub/transmogrifier/block_handling_test.exs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
# 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.BlockHandlingTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "it works for incoming blocks" do
|
||||
user = insert(:user)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-block-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
blocker = insert(:user, ap_id: data["actor"])
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["type"] == "Block"
|
||||
assert data["object"] == user.ap_id
|
||||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
|
||||
assert User.blocks?(blocker, user)
|
||||
end
|
||||
|
||||
test "incoming blocks successfully tear down any follow relationship" do
|
||||
blocker = insert(:user)
|
||||
blocked = insert(:user)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-block-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", blocked.ap_id)
|
||||
|> Map.put("actor", blocker.ap_id)
|
||||
|
||||
{:ok, blocker} = User.follow(blocker, blocked)
|
||||
{:ok, blocked} = User.follow(blocked, blocker)
|
||||
|
||||
assert User.following?(blocker, blocked)
|
||||
assert User.following?(blocked, blocker)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["type"] == "Block"
|
||||
assert data["object"] == blocked.ap_id
|
||||
assert data["actor"] == blocker.ap_id
|
||||
|
||||
blocker = User.get_cached_by_ap_id(data["actor"])
|
||||
blocked = User.get_cached_by_ap_id(data["object"])
|
||||
|
||||
assert User.blocks?(blocker, blocked)
|
||||
|
||||
refute User.following?(blocker, blocked)
|
||||
refute User.following?(blocked, blocker)
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,159 @@
|
|||
# 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.UserUpdateHandlingTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "it works for incoming update activities" do
|
||||
user = insert(:user, local: false)
|
||||
|
||||
update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
|
||||
|
||||
object =
|
||||
update_data["object"]
|
||||
|> Map.put("actor", user.ap_id)
|
||||
|> Map.put("id", user.ap_id)
|
||||
|
||||
update_data =
|
||||
update_data
|
||||
|> Map.put("actor", user.ap_id)
|
||||
|> Map.put("object", object)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
assert data["id"] == update_data["id"]
|
||||
|
||||
user = User.get_cached_by_ap_id(data["actor"])
|
||||
assert user.name == "gargle"
|
||||
|
||||
assert user.avatar["url"] == [
|
||||
%{
|
||||
"href" =>
|
||||
"https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
|
||||
}
|
||||
]
|
||||
|
||||
assert user.banner["url"] == [
|
||||
%{
|
||||
"href" =>
|
||||
"https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
|
||||
}
|
||||
]
|
||||
|
||||
assert user.bio == "<p>Some bio</p>"
|
||||
end
|
||||
|
||||
test "it works with alsoKnownAs" do
|
||||
%{ap_id: actor} = insert(:user, local: false)
|
||||
|
||||
assert User.get_cached_by_ap_id(actor).also_known_as == []
|
||||
|
||||
{:ok, _activity} =
|
||||
"test/fixtures/mastodon-update.json"
|
||||
|> File.read!()
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", actor)
|
||||
|> Map.update!("object", fn object ->
|
||||
object
|
||||
|> Map.put("actor", actor)
|
||||
|> Map.put("id", actor)
|
||||
|> Map.put("alsoKnownAs", [
|
||||
"http://mastodon.example.org/users/foo",
|
||||
"http://example.org/users/bar"
|
||||
])
|
||||
end)
|
||||
|> Transmogrifier.handle_incoming()
|
||||
|
||||
assert User.get_cached_by_ap_id(actor).also_known_as == [
|
||||
"http://mastodon.example.org/users/foo",
|
||||
"http://example.org/users/bar"
|
||||
]
|
||||
end
|
||||
|
||||
test "it works with custom profile fields" do
|
||||
user = insert(:user, local: false)
|
||||
|
||||
assert user.fields == []
|
||||
|
||||
update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
|
||||
|
||||
object =
|
||||
update_data["object"]
|
||||
|> Map.put("actor", user.ap_id)
|
||||
|> Map.put("id", user.ap_id)
|
||||
|
||||
update_data =
|
||||
update_data
|
||||
|> Map.put("actor", user.ap_id)
|
||||
|> Map.put("object", object)
|
||||
|
||||
{:ok, _update_activity} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert user.fields == [
|
||||
%{"name" => "foo", "value" => "updated"},
|
||||
%{"name" => "foo1", "value" => "updated"}
|
||||
]
|
||||
|
||||
Pleroma.Config.put([:instance, :max_remote_account_fields], 2)
|
||||
|
||||
update_data =
|
||||
update_data
|
||||
|> put_in(["object", "attachment"], [
|
||||
%{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
|
||||
%{"name" => "foo11", "type" => "PropertyValue", "value" => "bar11"},
|
||||
%{"name" => "foo22", "type" => "PropertyValue", "value" => "bar22"}
|
||||
])
|
||||
|> Map.put("id", update_data["id"] <> ".")
|
||||
|
||||
{:ok, _} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert user.fields == [
|
||||
%{"name" => "foo", "value" => "updated"},
|
||||
%{"name" => "foo1", "value" => "updated"}
|
||||
]
|
||||
|
||||
update_data =
|
||||
update_data
|
||||
|> put_in(["object", "attachment"], [])
|
||||
|> Map.put("id", update_data["id"] <> ".")
|
||||
|
||||
{:ok, _} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert user.fields == []
|
||||
end
|
||||
|
||||
test "it works for incoming update activities which lock the account" do
|
||||
user = insert(:user, local: false)
|
||||
|
||||
update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
|
||||
|
||||
object =
|
||||
update_data["object"]
|
||||
|> Map.put("actor", user.ap_id)
|
||||
|> Map.put("id", user.ap_id)
|
||||
|> Map.put("manuallyApprovesFollowers", true)
|
||||
|
||||
update_data =
|
||||
update_data
|
||||
|> Map.put("actor", user.ap_id)
|
||||
|> Map.put("object", object)
|
||||
|
||||
{:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
assert user.locked == true
|
||||
end
|
||||
end
|
||||
|
|
@ -401,162 +401,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
refute Map.has_key?(object_data, "reaction_count")
|
||||
end
|
||||
|
||||
test "it works for incoming update activities" do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
|
||||
|
||||
object =
|
||||
update_data["object"]
|
||||
|> Map.put("actor", data["actor"])
|
||||
|> Map.put("id", data["actor"])
|
||||
|
||||
update_data =
|
||||
update_data
|
||||
|> Map.put("actor", data["actor"])
|
||||
|> Map.put("object", object)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
assert data["id"] == update_data["id"]
|
||||
|
||||
user = User.get_cached_by_ap_id(data["actor"])
|
||||
assert user.name == "gargle"
|
||||
|
||||
assert user.avatar["url"] == [
|
||||
%{
|
||||
"href" =>
|
||||
"https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
|
||||
}
|
||||
]
|
||||
|
||||
assert user.banner["url"] == [
|
||||
%{
|
||||
"href" =>
|
||||
"https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
|
||||
}
|
||||
]
|
||||
|
||||
assert user.bio == "<p>Some bio</p>"
|
||||
end
|
||||
|
||||
test "it works with alsoKnownAs" do
|
||||
{:ok, %Activity{data: %{"actor" => actor}}} =
|
||||
"test/fixtures/mastodon-post-activity.json"
|
||||
|> File.read!()
|
||||
|> Poison.decode!()
|
||||
|> Transmogrifier.handle_incoming()
|
||||
|
||||
assert User.get_cached_by_ap_id(actor).also_known_as == ["http://example.org/users/foo"]
|
||||
|
||||
{:ok, _activity} =
|
||||
"test/fixtures/mastodon-update.json"
|
||||
|> File.read!()
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", actor)
|
||||
|> Map.update!("object", fn object ->
|
||||
object
|
||||
|> Map.put("actor", actor)
|
||||
|> Map.put("id", actor)
|
||||
|> Map.put("alsoKnownAs", [
|
||||
"http://mastodon.example.org/users/foo",
|
||||
"http://example.org/users/bar"
|
||||
])
|
||||
end)
|
||||
|> Transmogrifier.handle_incoming()
|
||||
|
||||
assert User.get_cached_by_ap_id(actor).also_known_as == [
|
||||
"http://mastodon.example.org/users/foo",
|
||||
"http://example.org/users/bar"
|
||||
]
|
||||
end
|
||||
|
||||
test "it works with custom profile fields" do
|
||||
{:ok, activity} =
|
||||
"test/fixtures/mastodon-post-activity.json"
|
||||
|> File.read!()
|
||||
|> Poison.decode!()
|
||||
|> Transmogrifier.handle_incoming()
|
||||
|
||||
user = User.get_cached_by_ap_id(activity.actor)
|
||||
|
||||
assert user.fields == [
|
||||
%{"name" => "foo", "value" => "bar"},
|
||||
%{"name" => "foo1", "value" => "bar1"}
|
||||
]
|
||||
|
||||
update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
|
||||
|
||||
object =
|
||||
update_data["object"]
|
||||
|> Map.put("actor", user.ap_id)
|
||||
|> Map.put("id", user.ap_id)
|
||||
|
||||
update_data =
|
||||
update_data
|
||||
|> Map.put("actor", user.ap_id)
|
||||
|> Map.put("object", object)
|
||||
|
||||
{:ok, _update_activity} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert user.fields == [
|
||||
%{"name" => "foo", "value" => "updated"},
|
||||
%{"name" => "foo1", "value" => "updated"}
|
||||
]
|
||||
|
||||
Pleroma.Config.put([:instance, :max_remote_account_fields], 2)
|
||||
|
||||
update_data =
|
||||
put_in(update_data, ["object", "attachment"], [
|
||||
%{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
|
||||
%{"name" => "foo11", "type" => "PropertyValue", "value" => "bar11"},
|
||||
%{"name" => "foo22", "type" => "PropertyValue", "value" => "bar22"}
|
||||
])
|
||||
|
||||
{:ok, _} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert user.fields == [
|
||||
%{"name" => "foo", "value" => "updated"},
|
||||
%{"name" => "foo1", "value" => "updated"}
|
||||
]
|
||||
|
||||
update_data = put_in(update_data, ["object", "attachment"], [])
|
||||
|
||||
{:ok, _} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert user.fields == []
|
||||
end
|
||||
|
||||
test "it works for incoming update activities which lock the account" do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
|
||||
|
||||
object =
|
||||
update_data["object"]
|
||||
|> Map.put("actor", data["actor"])
|
||||
|> Map.put("id", data["actor"])
|
||||
|> Map.put("manuallyApprovesFollowers", true)
|
||||
|
||||
update_data =
|
||||
update_data
|
||||
|> Map.put("actor", data["actor"])
|
||||
|> Map.put("object", object)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
user = User.get_cached_by_ap_id(data["actor"])
|
||||
assert user.locked == true
|
||||
end
|
||||
|
||||
test "it works for incomming unfollows with an existing follow" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -601,56 +445,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert [^pending_follower] = User.get_follow_requests(user)
|
||||
end
|
||||
|
||||
test "it works for incoming blocks" do
|
||||
user = insert(:user)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-block-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["type"] == "Block"
|
||||
assert data["object"] == user.ap_id
|
||||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
|
||||
blocker = User.get_cached_by_ap_id(data["actor"])
|
||||
|
||||
assert User.blocks?(blocker, user)
|
||||
end
|
||||
|
||||
test "incoming blocks successfully tear down any follow relationship" do
|
||||
blocker = insert(:user)
|
||||
blocked = insert(:user)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-block-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", blocked.ap_id)
|
||||
|> Map.put("actor", blocker.ap_id)
|
||||
|
||||
{:ok, blocker} = User.follow(blocker, blocked)
|
||||
{:ok, blocked} = User.follow(blocked, blocker)
|
||||
|
||||
assert User.following?(blocker, blocked)
|
||||
assert User.following?(blocked, blocker)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["type"] == "Block"
|
||||
assert data["object"] == blocked.ap_id
|
||||
assert data["actor"] == blocker.ap_id
|
||||
|
||||
blocker = User.get_cached_by_ap_id(data["actor"])
|
||||
blocked = User.get_cached_by_ap_id(data["object"])
|
||||
|
||||
assert User.blocks?(blocker, blocked)
|
||||
|
||||
refute User.following?(blocker, blocked)
|
||||
refute User.following?(blocked, blocker)
|
||||
end
|
||||
|
||||
test "it works for incoming accepts which were pre-accepted" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
|
|
|||
|
|
@ -27,16 +27,6 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "fetch the latest Block" do
|
||||
test "fetches the latest Block activity" do
|
||||
blocker = insert(:user)
|
||||
blocked = insert(:user)
|
||||
{:ok, activity} = ActivityPub.block(blocker, blocked)
|
||||
|
||||
assert activity == Utils.fetch_latest_block(blocker, blocked)
|
||||
end
|
||||
end
|
||||
|
||||
describe "determine_explicit_mentions()" do
|
||||
test "works with an object that has mentions" do
|
||||
object = %{
|
||||
|
|
@ -344,9 +334,9 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
assert {:ok, %Activity{} = _} = ActivityPub.block(user1, user2)
|
||||
assert {:ok, %Activity{} = _} = ActivityPub.block(user1, user2)
|
||||
assert {:ok, %Activity{} = activity} = ActivityPub.block(user1, user2)
|
||||
assert {:ok, %Activity{} = _} = CommonAPI.block(user1, user2)
|
||||
assert {:ok, %Activity{} = _} = CommonAPI.block(user1, user2)
|
||||
assert {:ok, %Activity{} = activity} = CommonAPI.block(user1, user2)
|
||||
|
||||
assert Utils.fetch_latest_block(user1, user2) == activity
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1732,6 +1732,26 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
assert %{"direct" => 0, "private" => 0, "public" => 1, "unlisted" => 2} =
|
||||
response["status_visibility"]
|
||||
end
|
||||
|
||||
test "by instance", %{conn: conn} do
|
||||
admin = insert(:user, is_admin: true)
|
||||
user1 = insert(:user)
|
||||
instance2 = "instance2.tld"
|
||||
user2 = insert(:user, %{ap_id: "https://#{instance2}/@actor"})
|
||||
|
||||
CommonAPI.post(user1, %{visibility: "public", status: "hey"})
|
||||
CommonAPI.post(user2, %{visibility: "unlisted", status: "hey"})
|
||||
CommonAPI.post(user2, %{visibility: "private", status: "hey"})
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, admin)
|
||||
|> get("/api/pleroma/admin/stats", instance: instance2)
|
||||
|> json_response(200)
|
||||
|
||||
assert %{"direct" => 0, "private" => 1, "public" => 0, "unlisted" => 1} =
|
||||
response["status_visibility"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,52 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
setup do: clear_config([:instance, :limit])
|
||||
setup do: clear_config([:instance, :max_pinned_statuses])
|
||||
|
||||
describe "blocking" do
|
||||
setup do
|
||||
blocker = insert(:user)
|
||||
blocked = insert(:user)
|
||||
User.follow(blocker, blocked)
|
||||
User.follow(blocked, blocker)
|
||||
%{blocker: blocker, blocked: blocked}
|
||||
end
|
||||
|
||||
test "it blocks and federates", %{blocker: blocker, blocked: blocked} do
|
||||
clear_config([:instance, :federating], true)
|
||||
|
||||
with_mock Pleroma.Web.Federator,
|
||||
publish: fn _ -> nil end do
|
||||
assert {:ok, block} = CommonAPI.block(blocker, blocked)
|
||||
|
||||
assert block.local
|
||||
assert User.blocks?(blocker, blocked)
|
||||
refute User.following?(blocker, blocked)
|
||||
refute User.following?(blocked, blocker)
|
||||
|
||||
assert called(Pleroma.Web.Federator.publish(block))
|
||||
end
|
||||
end
|
||||
|
||||
test "it blocks and does not federate if outgoing blocks are disabled", %{
|
||||
blocker: blocker,
|
||||
blocked: blocked
|
||||
} do
|
||||
clear_config([:instance, :federating], true)
|
||||
clear_config([:activitypub, :outgoing_blocks], false)
|
||||
|
||||
with_mock Pleroma.Web.Federator,
|
||||
publish: fn _ -> nil end do
|
||||
assert {:ok, block} = CommonAPI.block(blocker, blocked)
|
||||
|
||||
assert block.local
|
||||
assert User.blocks?(blocker, blocked)
|
||||
refute User.following?(blocker, blocked)
|
||||
refute User.following?(blocked, blocker)
|
||||
|
||||
refute called(Pleroma.Web.Federator.publish(block))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "posting chat messages" do
|
||||
setup do: clear_config([:instance, :chat_limit])
|
||||
|
||||
|
|
@ -445,6 +491,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
object = Object.normalize(activity)
|
||||
|
||||
assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
|
||||
assert object.data["source"] == post
|
||||
end
|
||||
|
||||
test "it filters out obviously bad tags when accepting a post as Markdown" do
|
||||
|
|
@ -461,6 +508,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
object = Object.normalize(activity)
|
||||
|
||||
assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
|
||||
assert object.data["source"] == post
|
||||
end
|
||||
|
||||
test "it does not allow replies to direct messages that are not direct messages themselves" do
|
||||
|
|
|
|||
|
|
@ -6,22 +6,56 @@ defmodule Pleroma.Web.FallbackTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
import Pleroma.Factory
|
||||
|
||||
test "GET /registration/:token", %{conn: conn} do
|
||||
assert conn
|
||||
|> get("/registration/foo")
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
describe "neither preloaded data nor metadata attached to" do
|
||||
test "GET /registration/:token", %{conn: conn} do
|
||||
response = get(conn, "/registration/foo")
|
||||
|
||||
assert html_response(response, 200) =~ "<!--server-generated-meta-->"
|
||||
end
|
||||
|
||||
test "GET /*path", %{conn: conn} do
|
||||
assert conn
|
||||
|> get("/foo")
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
end
|
||||
end
|
||||
|
||||
test "GET /:maybe_nickname_or_id", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
describe "preloaded data and metadata attached to" do
|
||||
test "GET /:maybe_nickname_or_id", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user_missing = get(conn, "/foo")
|
||||
user_present = get(conn, "/#{user.nickname}")
|
||||
|
||||
assert conn
|
||||
|> get("/foo")
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
assert(html_response(user_missing, 200) =~ "<!--server-generated-meta-->")
|
||||
refute html_response(user_present, 200) =~ "<!--server-generated-meta-->"
|
||||
assert html_response(user_present, 200) =~ "initial-results"
|
||||
end
|
||||
|
||||
refute conn
|
||||
|> get("/" <> user.nickname)
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
test "GET /*path", %{conn: conn} do
|
||||
assert conn
|
||||
|> get("/foo")
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
|
||||
refute conn
|
||||
|> get("/foo/bar")
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
end
|
||||
end
|
||||
|
||||
describe "preloaded data is attached to" do
|
||||
test "GET /main/public", %{conn: conn} do
|
||||
public_page = get(conn, "/main/public")
|
||||
|
||||
refute html_response(public_page, 200) =~ "<!--server-generated-meta-->"
|
||||
assert html_response(public_page, 200) =~ "initial-results"
|
||||
end
|
||||
|
||||
test "GET /main/all", %{conn: conn} do
|
||||
public_page = get(conn, "/main/all")
|
||||
|
||||
refute html_response(public_page, 200) =~ "<!--server-generated-meta-->"
|
||||
assert html_response(public_page, 200) =~ "initial-results"
|
||||
end
|
||||
end
|
||||
|
||||
test "GET /api*path", %{conn: conn} do
|
||||
|
|
@ -34,16 +68,6 @@ defmodule Pleroma.Web.FallbackTest do
|
|||
assert redirected_to(get(conn, "/pleroma/admin")) =~ "/pleroma/admin/"
|
||||
end
|
||||
|
||||
test "GET /*path", %{conn: conn} do
|
||||
assert conn
|
||||
|> get("/foo")
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
|
||||
assert conn
|
||||
|> get("/foo/bar")
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
end
|
||||
|
||||
test "OPTIONS /*path", %{conn: conn} do
|
||||
assert conn
|
||||
|> options("/foo")
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
|
||||
setup_all do: clear_config([:instance, :federating], true)
|
||||
setup do: clear_config([:instance, :allow_relay])
|
||||
setup do: clear_config([:instance, :rewrite_policy])
|
||||
setup do: clear_config([:mrf, :policies])
|
||||
setup do: clear_config([:mrf_keyword])
|
||||
|
||||
describe "Publish an activity" do
|
||||
|
|
@ -158,7 +158,7 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
Pleroma.Config.put([:mrf_keyword, :reject], ["lain"])
|
||||
|
||||
Pleroma.Config.put(
|
||||
[:instance, :rewrite_policy],
|
||||
[:mrf, :policies],
|
||||
Pleroma.Web.ActivityPub.MRF.KeywordPolicy
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ defmodule Pleroma.Web.MastodonAPI.MastoFEController do
|
|||
assert _result = json_response(conn, 200)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
assert user.settings == %{"programming" => "socks"}
|
||||
assert user.mastofe_settings == %{"programming" => "socks"}
|
||||
end
|
||||
|
||||
describe "index/2 redirections" do
|
||||
|
|
|
|||
|
|
@ -780,7 +780,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
assert %{"id" => _id, "muting" => true, "muting_notifications" => true} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/accounts/#{other_user.id}/mute")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
|
|
|
|||
|
|
@ -35,8 +35,10 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
|||
"background_image" => _
|
||||
} = result
|
||||
|
||||
assert result["pleroma"]["metadata"]["account_activation_required"] != nil
|
||||
assert result["pleroma"]["metadata"]["features"]
|
||||
assert result["pleroma"]["metadata"]["federation"]
|
||||
assert result["pleroma"]["metadata"]["fields_limits"]
|
||||
assert result["pleroma"]["vapid_public_key"]
|
||||
|
||||
assert email == from_config_email
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
assert status["id"] == to_string(activity.id)
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
test "constructs hashtags from search query", %{conn: conn} do
|
||||
results =
|
||||
conn
|
||||
|
|
@ -318,11 +319,13 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
test "search fetches remote accounts", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
query = URI.encode_query(%{q: " mike@osada.macgirvin.com ", resolve: true})
|
||||
|
||||
results =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, insert(:oauth_token, user: user, scopes: ["read"]))
|
||||
|> get("/api/v1/search?q=mike@osada.macgirvin.com&resolve=true")
|
||||
|> get("/api/v1/search?#{query}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
[account] = results["accounts"]
|
||||
|
|
|
|||
|
|
@ -760,13 +760,18 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
test "when you created it" do
|
||||
%{user: author, conn: conn} = oauth_access(["write:statuses"])
|
||||
activity = insert(:note_activity, user: author)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
conn =
|
||||
content = object.data["content"]
|
||||
source = object.data["source"]
|
||||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, author)
|
||||
|> delete("/api/v1/statuses/#{activity.id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert %{} = json_response_and_validate_schema(conn, 200)
|
||||
assert match?(%{"content" => ^content, "text" => ^source}, result)
|
||||
|
||||
refute Activity.get_by_id(activity.id)
|
||||
end
|
||||
|
|
@ -789,7 +794,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
conn = delete(conn, "/api/v1/statuses/#{activity.id}")
|
||||
|
||||
assert %{"error" => _} = json_response_and_validate_schema(conn, 403)
|
||||
assert %{"error" => "Record not found"} == json_response_and_validate_schema(conn, 404)
|
||||
|
||||
assert Activity.get_by_id(activity.id) == activity
|
||||
end
|
||||
|
|
|
|||
|
|
@ -183,6 +183,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
card: nil,
|
||||
reblog: nil,
|
||||
content: HTML.filter_tags(object_data["content"]),
|
||||
text: nil,
|
||||
created_at: created_at,
|
||||
reblogs_count: 0,
|
||||
replies_count: 0,
|
||||
|
|
@ -226,7 +227,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
expires_at: nil,
|
||||
direct_conversation_id: nil,
|
||||
thread_muted: false,
|
||||
emoji_reactions: []
|
||||
emoji_reactions: [],
|
||||
parent_visible: false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -620,4 +622,20 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
assert status.visibility == "list"
|
||||
end
|
||||
|
||||
test "has a field for parent visibility" do
|
||||
user = insert(:user)
|
||||
poster = insert(:user)
|
||||
|
||||
{:ok, invisible} = CommonAPI.post(poster, %{status: "hey", visibility: "private"})
|
||||
|
||||
{:ok, visible} =
|
||||
CommonAPI.post(poster, %{status: "hey", visibility: "private", in_reply_to_id: invisible.id})
|
||||
|
||||
status = StatusView.render("show.json", activity: visible, for: user)
|
||||
refute status.pleroma.parent_visible
|
||||
|
||||
status = StatusView.render("show.json", activity: visible, for: poster)
|
||||
assert status.pleroma.parent_visible
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -67,10 +67,10 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||
end
|
||||
|
||||
test "returns fieldsLimits field", %{conn: conn} do
|
||||
Config.put([:instance, :max_account_fields], 10)
|
||||
Config.put([:instance, :max_remote_account_fields], 15)
|
||||
Config.put([:instance, :account_field_name_length], 255)
|
||||
Config.put([:instance, :account_field_value_length], 2048)
|
||||
clear_config([:instance, :max_account_fields], 10)
|
||||
clear_config([:instance, :max_remote_account_fields], 15)
|
||||
clear_config([:instance, :account_field_name_length], 255)
|
||||
clear_config([:instance, :account_field_value_length], 2048)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -84,8 +84,7 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||
end
|
||||
|
||||
test "it returns the safe_dm_mentions feature if enabled", %{conn: conn} do
|
||||
option = Config.get([:instance, :safe_dm_mentions])
|
||||
Config.put([:instance, :safe_dm_mentions], true)
|
||||
clear_config([:instance, :safe_dm_mentions], true)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -102,8 +101,6 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||
|> json_response(:ok)
|
||||
|
||||
refute "safe_dm_mentions" in response["metadata"]["features"]
|
||||
|
||||
Config.put([:instance, :safe_dm_mentions], option)
|
||||
end
|
||||
|
||||
describe "`metadata/federation/enabled`" do
|
||||
|
|
@ -156,14 +153,11 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||
end
|
||||
|
||||
test "it shows MRF transparency data if enabled", %{conn: conn} do
|
||||
config = Config.get([:instance, :rewrite_policy])
|
||||
Config.put([:instance, :rewrite_policy], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
|
||||
|
||||
option = Config.get([:instance, :mrf_transparency])
|
||||
Config.put([:instance, :mrf_transparency], true)
|
||||
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
|
||||
clear_config([:mrf, :transparency], true)
|
||||
|
||||
simple_config = %{"reject" => ["example.com"]}
|
||||
Config.put(:mrf_simple, simple_config)
|
||||
clear_config(:mrf_simple, simple_config)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -171,26 +165,17 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||
|> json_response(:ok)
|
||||
|
||||
assert response["metadata"]["federation"]["mrf_simple"] == simple_config
|
||||
|
||||
Config.put([:instance, :rewrite_policy], config)
|
||||
Config.put([:instance, :mrf_transparency], option)
|
||||
Config.put(:mrf_simple, %{})
|
||||
end
|
||||
|
||||
test "it performs exclusions from MRF transparency data if configured", %{conn: conn} do
|
||||
config = Config.get([:instance, :rewrite_policy])
|
||||
Config.put([:instance, :rewrite_policy], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
|
||||
|
||||
option = Config.get([:instance, :mrf_transparency])
|
||||
Config.put([:instance, :mrf_transparency], true)
|
||||
|
||||
exclusions = Config.get([:instance, :mrf_transparency_exclusions])
|
||||
Config.put([:instance, :mrf_transparency_exclusions], ["other.site"])
|
||||
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
|
||||
clear_config([:mrf, :transparency], true)
|
||||
clear_config([:mrf, :transparency_exclusions], ["other.site"])
|
||||
|
||||
simple_config = %{"reject" => ["example.com", "other.site"]}
|
||||
expected_config = %{"reject" => ["example.com"]}
|
||||
clear_config(:mrf_simple, simple_config)
|
||||
|
||||
Config.put(:mrf_simple, simple_config)
|
||||
expected_config = %{"reject" => ["example.com"]}
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -199,10 +184,5 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||
|
||||
assert response["metadata"]["federation"]["mrf_simple"] == expected_config
|
||||
assert response["metadata"]["federation"]["exclusions"] == true
|
||||
|
||||
Config.put([:instance, :rewrite_policy], config)
|
||||
Config.put([:instance, :mrf_transparency], option)
|
||||
Config.put([:instance, :mrf_transparency_exclusions], exclusions)
|
||||
Config.put(:mrf_simple, %{})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
48
test/web/preload/instance_test.exs
Normal file
48
test/web/preload/instance_test.exs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Preload.Providers.InstanceTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Web.Preload.Providers.Instance
|
||||
|
||||
setup do: {:ok, Instance.generate_terms(nil)}
|
||||
|
||||
test "it renders the info", %{"/api/v1/instance" => info} do
|
||||
assert %{
|
||||
description: description,
|
||||
email: "admin@example.com",
|
||||
registrations: true
|
||||
} = info
|
||||
|
||||
assert String.equivalent?(description, "Pleroma: An efficient and flexible fediverse server")
|
||||
end
|
||||
|
||||
test "it renders the panel", %{"/instance/panel.html" => panel} do
|
||||
assert String.contains?(
|
||||
panel,
|
||||
"<p>Welcome to <a href=\"https://pleroma.social\" target=\"_blank\">Pleroma!</a></p>"
|
||||
)
|
||||
end
|
||||
|
||||
test "it works with overrides" do
|
||||
clear_config([:instance, :static_dir], "test/fixtures/preload_static")
|
||||
|
||||
%{"/instance/panel.html" => panel} = Instance.generate_terms(nil)
|
||||
|
||||
assert String.contains?(
|
||||
panel,
|
||||
"HEY!"
|
||||
)
|
||||
end
|
||||
|
||||
test "it renders the node_info", %{"/nodeinfo/2.0.json" => nodeinfo} do
|
||||
%{
|
||||
metadata: metadata,
|
||||
version: "2.0"
|
||||
} = nodeinfo
|
||||
|
||||
assert metadata.private == false
|
||||
assert metadata.suggestions == %{enabled: false}
|
||||
end
|
||||
end
|
||||
15
test/web/preload/status_net_test.exs
Normal file
15
test/web/preload/status_net_test.exs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Preload.Providers.StatusNetTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Web.Preload.Providers.StatusNet
|
||||
|
||||
setup do: {:ok, StatusNet.generate_terms(nil)}
|
||||
|
||||
test "it renders the info", %{"/api/statusnet/config.json" => info} do
|
||||
assert {:ok, res} = Jason.decode(info)
|
||||
assert res["site"]
|
||||
end
|
||||
end
|
||||
74
test/web/preload/timeline_test.exs
Normal file
74
test/web/preload/timeline_test.exs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Preload.Providers.TimelineTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.Preload.Providers.Timelines
|
||||
|
||||
@public_url "/api/v1/timelines/public"
|
||||
|
||||
describe "unauthenticated timeliness when restricted" do
|
||||
setup do
|
||||
svd_config = Pleroma.Config.get([:restrict_unauthenticated, :timelines])
|
||||
Pleroma.Config.put([:restrict_unauthenticated, :timelines], %{local: true, federated: true})
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:restrict_unauthenticated, :timelines], svd_config)
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
test "return nothing" do
|
||||
tl_data = Timelines.generate_terms(%{})
|
||||
|
||||
refute Map.has_key?(tl_data, "/api/v1/timelines/public")
|
||||
end
|
||||
end
|
||||
|
||||
describe "unauthenticated timeliness when unrestricted" do
|
||||
setup do
|
||||
svd_config = Pleroma.Config.get([:restrict_unauthenticated, :timelines])
|
||||
|
||||
Pleroma.Config.put([:restrict_unauthenticated, :timelines], %{
|
||||
local: false,
|
||||
federated: false
|
||||
})
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:restrict_unauthenticated, :timelines], svd_config)
|
||||
end)
|
||||
|
||||
{:ok, user: insert(:user)}
|
||||
end
|
||||
|
||||
test "returns the timeline when not restricted" do
|
||||
assert Timelines.generate_terms(%{})
|
||||
|> Map.has_key?(@public_url)
|
||||
end
|
||||
|
||||
test "returns public items", %{user: user} do
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "it's post 1!"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "it's post 2!"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "it's post 3!"})
|
||||
|
||||
assert Timelines.generate_terms(%{})
|
||||
|> Map.fetch!(@public_url)
|
||||
|> Enum.count() == 3
|
||||
end
|
||||
|
||||
test "does not return non-public items", %{user: user} do
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "it's post 1!", visibility: "unlisted"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "it's post 2!", visibility: "direct"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "it's post 3!"})
|
||||
|
||||
assert Timelines.generate_terms(%{})
|
||||
|> Map.fetch!(@public_url)
|
||||
|> Enum.count() == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
33
test/web/preload/user_test.exs
Normal file
33
test/web/preload/user_test.exs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Preload.Providers.UserTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Web.Preload.Providers.User
|
||||
|
||||
describe "returns empty when user doesn't exist" do
|
||||
test "nil user specified" do
|
||||
assert User.generate_terms(%{user: nil}) == %{}
|
||||
end
|
||||
|
||||
test "missing user specified" do
|
||||
assert User.generate_terms(%{user: :not_a_user}) == %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "specified user exists" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
||||
terms = User.generate_terms(%{user: user})
|
||||
%{terms: terms, user: user}
|
||||
end
|
||||
|
||||
test "account is rendered", %{terms: terms, user: user} do
|
||||
account = terms["/api/v1/accounts/#{user.id}"]
|
||||
assert %{acct: user, username: user} = account
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -116,6 +116,18 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
refute Streamer.filtered_by_user?(user, announce)
|
||||
end
|
||||
|
||||
test "it does not stream announces of the user's own posts in the 'user' stream", %{
|
||||
user: user
|
||||
} do
|
||||
Streamer.get_topic_and_add_socket("user", user)
|
||||
|
||||
other_user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "hey"})
|
||||
{:ok, announce} = CommonAPI.repeat(activity.id, other_user)
|
||||
|
||||
assert Streamer.filtered_by_user?(user, announce)
|
||||
end
|
||||
|
||||
test "it streams boosts of mastodon user in the 'user' stream", %{user: user} do
|
||||
Streamer.get_topic_and_add_socket("user", user)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ defmodule Pleroma.Workers.Cron.PurgeExpiredActivitiesWorkerTest do
|
|||
|
||||
setup do
|
||||
clear_config([ActivityExpiration, :enabled])
|
||||
clear_config([:instance, :rewrite_policy])
|
||||
end
|
||||
|
||||
test "deletes an expiration activity" do
|
||||
|
|
@ -42,10 +41,7 @@ defmodule Pleroma.Workers.Cron.PurgeExpiredActivitiesWorkerTest do
|
|||
test "works with ActivityExpirationPolicy" do
|
||||
Pleroma.Config.put([ActivityExpiration, :enabled], true)
|
||||
|
||||
Pleroma.Config.put(
|
||||
[:instance, :rewrite_policy],
|
||||
Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy
|
||||
)
|
||||
clear_config([:mrf, :policies], Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue