Merge remote-tracking branch 'origin/develop' into sixohsix/pleroma-post_expiration
This commit is contained in:
commit
cc6c0b4ba6
276 changed files with 7847 additions and 1792 deletions
|
|
@ -5,14 +5,8 @@
|
|||
defmodule Pleroma.Config.TransferTaskTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
setup do
|
||||
dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
|
||||
|
||||
clear_config([:instance, :dynamic_configuration]) do
|
||||
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
|
||||
end)
|
||||
end
|
||||
|
||||
test "transfer config values from db to env" do
|
||||
|
|
@ -31,7 +25,7 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
value: [live: 15, com: 35]
|
||||
})
|
||||
|
||||
Pleroma.Config.TransferTask.start_link()
|
||||
Pleroma.Config.TransferTask.start_link([])
|
||||
|
||||
assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
|
||||
assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
|
||||
|
|
@ -50,7 +44,7 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
})
|
||||
|
||||
assert ExUnit.CaptureLog.capture_log(fn ->
|
||||
Pleroma.Config.TransferTask.start_link()
|
||||
Pleroma.Config.TransferTask.start_link([])
|
||||
end) =~
|
||||
"updating env causes error, key: \"undefined_atom_key\", error: %ArgumentError{message: \"argument error\"}"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,6 +8,50 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
alias Pleroma.Conversation.Participation
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
test "getting a participation will also preload things" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.post(user, %{"status" => "Hey @#{other_user.nickname}.", "visibility" => "direct"})
|
||||
|
||||
[participation] = Participation.for_user(user)
|
||||
|
||||
participation = Participation.get(participation.id, preload: [:conversation])
|
||||
|
||||
assert %Pleroma.Conversation{} = participation.conversation
|
||||
end
|
||||
|
||||
test "for a new conversation, it sets the recipents of the participation" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
third_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{"status" => "Hey @#{other_user.nickname}.", "visibility" => "direct"})
|
||||
|
||||
[participation] = Participation.for_user(user)
|
||||
participation = Pleroma.Repo.preload(participation, :recipients)
|
||||
|
||||
assert length(participation.recipients) == 2
|
||||
assert user in participation.recipients
|
||||
assert other_user in participation.recipients
|
||||
|
||||
# Mentioning another user in the same conversation will not add a new recipients.
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.post(user, %{
|
||||
"in_reply_to_status_id" => activity.id,
|
||||
"status" => "Hey @#{third_user.nickname}.",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
[participation] = Participation.for_user(user)
|
||||
participation = Pleroma.Repo.preload(participation, :recipients)
|
||||
|
||||
assert length(participation.recipients) == 2
|
||||
end
|
||||
|
||||
test "it creates a participation for a conversation and a user" do
|
||||
user = insert(:user)
|
||||
conversation = insert(:conversation)
|
||||
|
|
@ -102,4 +146,23 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
|
||||
[] = Participation.for_user_with_last_activity_id(user)
|
||||
end
|
||||
|
||||
test "it sets recipients, always keeping the owner of the participation even when not explicitly set" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
|
||||
[participation] = Participation.for_user_with_last_activity_id(user)
|
||||
|
||||
participation = Repo.preload(participation, :recipients)
|
||||
|
||||
assert participation.recipients |> length() == 1
|
||||
assert user in participation.recipients
|
||||
|
||||
{:ok, participation} = Participation.set_recipients(participation, [other_user.id])
|
||||
|
||||
assert participation.recipients |> length() == 2
|
||||
assert user in participation.recipients
|
||||
assert other_user in participation.recipients
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,14 +11,8 @@ defmodule Pleroma.ConversationTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup_all do
|
||||
config_path = [:instance, :federating]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
Pleroma.Config.put(config_path, true)
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
|
||||
:ok
|
||||
clear_config_all([:instance, :federating]) do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
end
|
||||
|
||||
test "it goes through old direct conversations" do
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ defmodule Pleroma.Emails.AdminEmailTest do
|
|||
|
||||
assert res.to == [{to_user.name, to_user.email}]
|
||||
assert res.from == {config[:name], config[:notify_email]}
|
||||
assert res.reply_to == {reporter.name, reporter.email}
|
||||
assert res.subject == "#{config[:name]} Report"
|
||||
|
||||
assert res.html_body ==
|
||||
|
|
@ -34,4 +33,17 @@ defmodule Pleroma.Emails.AdminEmailTest do
|
|||
status_url
|
||||
}\">#{status_url}</li>\n </ul>\n</p>\n\n"
|
||||
end
|
||||
|
||||
test "it works when the reporter is a remote user without email" do
|
||||
config = Pleroma.Config.get(:instance)
|
||||
to_user = insert(:user)
|
||||
reporter = insert(:user, email: nil, local: false)
|
||||
account = insert(:user)
|
||||
|
||||
res =
|
||||
AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment")
|
||||
|
||||
assert res.to == [{to_user.name, to_user.email}]
|
||||
assert res.from == {config[:name], config[:notify_email]}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -15,11 +15,7 @@ defmodule Pleroma.Emails.MailerTest do
|
|||
to: [{"Test User", "user1@example.com"}]
|
||||
}
|
||||
|
||||
setup do
|
||||
value = Pleroma.Config.get([Pleroma.Emails.Mailer, :enabled])
|
||||
on_exit(fn -> Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], value) end)
|
||||
:ok
|
||||
end
|
||||
clear_config([Pleroma.Emails.Mailer, :enabled])
|
||||
|
||||
test "not send email when mailer is disabled" do
|
||||
Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
|
||||
|
|
|
|||
36
test/fixtures/mastodon-update.json
vendored
36
test/fixtures/mastodon-update.json
vendored
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"type": "Update",
|
||||
"object": {
|
||||
"url": "http://mastodon.example.org/@gargron",
|
||||
"type": "Person",
|
||||
"summary": "<p>Some bio</p>",
|
||||
"publicKey": {
|
||||
{
|
||||
"type": "Update",
|
||||
"object": {
|
||||
"url": "http://mastodon.example.org/@gargron",
|
||||
"type": "Person",
|
||||
"summary": "<p>Some bio</p>",
|
||||
"publicKey": {
|
||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0gs3VnQf6am3R+CeBV4H\nlfI1HZTNRIBHgvFszRZkCERbRgEWMu+P+I6/7GJC5H5jhVQ60z4MmXcyHOGmYMK/\n5XyuHQz7V2Ssu1AxLfRN5Biq1ayb0+DT/E7QxNXDJPqSTnstZ6C7zKH/uAETqg3l\nBonjCQWyds+IYbQYxf5Sp3yhvQ80lMwHML3DaNCMlXWLoOnrOX5/yK5+dedesg2\n/HIvGk+HEt36vm6hoH7bwPuEkgA++ACqwjXRe5Mta7i3eilHxFaF8XIrJFARV0t\nqOu4GID/jG6oA+swIWndGrtR2QRJIt9QIBFfK3HG5M0koZbY1eTqwNFRHFL3xaD\nUQIDAQAB\n-----END PUBLIC KEY-----\n",
|
||||
"owner": "http://mastodon.example.org/users/gargron",
|
||||
"id": "http://mastodon.example.org/users/gargron#main-key"
|
||||
|
|
@ -20,7 +20,27 @@
|
|||
"endpoints": {
|
||||
"sharedInbox": "http://mastodon.example.org/inbox"
|
||||
},
|
||||
"icon":{"type":"Image","mediaType":"image/jpeg","url":"https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"},"image":{"type":"Image","mediaType":"image/png","url":"https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"}
|
||||
"attachment": [{
|
||||
"type": "PropertyValue",
|
||||
"name": "foo",
|
||||
"value": "updated"
|
||||
},
|
||||
{
|
||||
"type": "PropertyValue",
|
||||
"name": "foo1",
|
||||
"value": "updated"
|
||||
}
|
||||
],
|
||||
"icon": {
|
||||
"type": "Image",
|
||||
"mediaType": "image/jpeg",
|
||||
"url": "https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
|
||||
},
|
||||
"image": {
|
||||
"type": "Image",
|
||||
"mediaType": "image/png",
|
||||
"url": "https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
|
||||
}
|
||||
},
|
||||
"id": "http://mastodon.example.org/users/gargron#updates/1519563538",
|
||||
"actor": "http://mastodon.example.org/users/gargron",
|
||||
|
|
|
|||
227
test/fixtures/nypd-facial-recognition-children-teenagers.html
vendored
Normal file
227
test/fixtures/nypd-facial-recognition-children-teenagers.html
vendored
Normal file
File diff suppressed because one or more lines are too long
226
test/fixtures/nypd-facial-recognition-children-teenagers2.html
vendored
Normal file
226
test/fixtures/nypd-facial-recognition-children-teenagers2.html
vendored
Normal file
File diff suppressed because one or more lines are too long
227
test/fixtures/nypd-facial-recognition-children-teenagers3.html
vendored
Normal file
227
test/fixtures/nypd-facial-recognition-children-teenagers3.html
vendored
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -1 +1,54 @@
|
|||
{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","movedTo":"as:movedTo","Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji"}],"id":"http://mastodon.example.org/users/admin","type":"Person","following":"http://mastodon.example.org/users/admin/following","followers":"http://mastodon.example.org/users/admin/followers","inbox":"http://mastodon.example.org/users/admin/inbox","outbox":"http://mastodon.example.org/users/admin/outbox","preferredUsername":"admin","name":null,"summary":"\u003cp\u003e\u003c/p\u003e","url":"http://mastodon.example.org/@admin","manuallyApprovesFollowers":false,"publicKey":{"id":"http://mastodon.example.org/users/admin#main-key","owner":"http://mastodon.example.org/users/admin","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtc4Tir+3ADhSNF6VKrtW\nOU32T01w7V0yshmQei38YyiVwVvFu8XOP6ACchkdxbJ+C9mZud8qWaRJKVbFTMUG\nNX4+6Q+FobyuKrwN7CEwhDALZtaN2IPbaPd6uG1B7QhWorrY+yFa8f2TBM3BxnUy\nI4T+bMIZIEYG7KtljCBoQXuTQmGtuffO0UwJksidg2ffCF5Q+K//JfQagJ3UzrR+\nZXbKMJdAw4bCVJYs4Z5EhHYBwQWiXCyMGTd7BGlmMkY6Av7ZqHKC/owp3/0EWDNz\nNqF09Wcpr3y3e8nA10X40MJqp/wR+1xtxp+YGbq/Cj5hZGBG7etFOmIpVBrDOhry\nBwIDAQAB\n-----END PUBLIC KEY-----\n"},"endpoints":{"sharedInbox":"http://mastodon.example.org/inbox"},"icon":{"type":"Image","mediaType":"image/jpeg","url":"https://cdn.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"},"image":{"type":"Image","mediaType":"image/png","url":"https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"}}
|
||||
{
|
||||
"@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1", {
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"sensitive": "as:sensitive",
|
||||
"movedTo": "as:movedTo",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"Emoji": "toot:Emoji"
|
||||
}],
|
||||
"id": "http://mastodon.example.org/users/admin",
|
||||
"type": "Person",
|
||||
"following": "http://mastodon.example.org/users/admin/following",
|
||||
"followers": "http://mastodon.example.org/users/admin/followers",
|
||||
"inbox": "http://mastodon.example.org/users/admin/inbox",
|
||||
"outbox": "http://mastodon.example.org/users/admin/outbox",
|
||||
"preferredUsername": "admin",
|
||||
"name": null,
|
||||
"summary": "\u003cp\u003e\u003c/p\u003e",
|
||||
"url": "http://mastodon.example.org/@admin",
|
||||
"manuallyApprovesFollowers": false,
|
||||
"publicKey": {
|
||||
"id": "http://mastodon.example.org/users/admin#main-key",
|
||||
"owner": "http://mastodon.example.org/users/admin",
|
||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtc4Tir+3ADhSNF6VKrtW\nOU32T01w7V0yshmQei38YyiVwVvFu8XOP6ACchkdxbJ+C9mZud8qWaRJKVbFTMUG\nNX4+6Q+FobyuKrwN7CEwhDALZtaN2IPbaPd6uG1B7QhWorrY+yFa8f2TBM3BxnUy\nI4T+bMIZIEYG7KtljCBoQXuTQmGtuffO0UwJksidg2ffCF5Q+K//JfQagJ3UzrR+\nZXbKMJdAw4bCVJYs4Z5EhHYBwQWiXCyMGTd7BGlmMkY6Av7ZqHKC/owp3/0EWDNz\nNqF09Wcpr3y3e8nA10X40MJqp/wR+1xtxp+YGbq/Cj5hZGBG7etFOmIpVBrDOhry\nBwIDAQAB\n-----END PUBLIC KEY-----\n"
|
||||
},
|
||||
"attachment": [{
|
||||
"type": "PropertyValue",
|
||||
"name": "foo",
|
||||
"value": "bar"
|
||||
},
|
||||
{
|
||||
"type": "PropertyValue",
|
||||
"name": "foo1",
|
||||
"value": "bar1"
|
||||
}
|
||||
],
|
||||
"endpoints": {
|
||||
"sharedInbox": "http://mastodon.example.org/inbox"
|
||||
},
|
||||
"icon": {
|
||||
"type": "Image",
|
||||
"mediaType": "image/jpeg",
|
||||
"url": "https://cdn.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
|
||||
},
|
||||
"image": {
|
||||
"type": "Image",
|
||||
"mediaType": "image/png",
|
||||
"url": "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
10
test/fixtures/tesla_mock/kpherox@mstdn.jp.xml
vendored
Normal file
10
test/fixtures/tesla_mock/kpherox@mstdn.jp.xml
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
<Subject>acct:kPherox@mstdn.jp</Subject>
|
||||
<Alias>https://mstdn.jp/@kPherox</Alias>
|
||||
<Alias>https://mstdn.jp/users/kPherox</Alias>
|
||||
<Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="https://mstdn.jp/@kPherox"/>
|
||||
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="https://mstdn.jp/users/kPherox.atom"/>
|
||||
<Link rel="self" type="application/activity+json" href="https://mstdn.jp/users/kPherox"/>
|
||||
<Link rel="http://ostatus.org/schema/1.0/subscribe" template="https://mstdn.jp/authorize_interaction?acct={uri}"/>
|
||||
</XRD>
|
||||
18
test/fixtures/tesla_mock/wedistribute-article.json
vendored
Normal file
18
test/fixtures/tesla_mock/wedistribute-article.json
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams"
|
||||
],
|
||||
"type": "Article",
|
||||
"name": "The end is near: Mastodon plans to drop OStatus support",
|
||||
"content": "<!-- wp:paragraph {\"dropCap\":true} -->\n<p class=\"has-drop-cap\">The days of OStatus are numbered. The venerable protocol has served as a glue between many different types of servers since the early days of the Fediverse, connecting StatusNet (now GNU Social) to Friendica, Hubzilla, Mastodon, and Pleroma.</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Now that many fediverse platforms support ActivityPub as a successor protocol, Mastodon appears to be drawing a line in the sand. In <a href=\"https://www.patreon.com/posts/mastodon-2-9-and-28121681\">a Patreon update</a>, Eugen Rochko writes:</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><p>...OStatus...has overstayed its welcome in the code...and now that most of the network uses ActivityPub, it's time for it to go. </p><cite>Eugen Rochko, Mastodon creator</cite></blockquote>\n<!-- /wp:quote -->\n\n<!-- wp:paragraph -->\n<p>The <a href=\"https://github.com/tootsuite/mastodon/pull/11205\">pull request</a> to remove Pubsubhubbub and Salmon, two of the main components of OStatus, has already been merged into Mastodon's master branch.</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Some projects will be left in the dark as a side effect of this. GNU Social and PostActiv, for example, both only communicate using OStatus. While <a href=\"https://mastodon.social/@dansup/102076573310057902\">some discussion</a> exists regarding adopting ActivityPub for GNU Social, and <a href=\"https://notabug.org/diogo/gnu-social/src/activitypub/plugins/ActivityPub\">a plugin is in development</a>, it hasn't been formally adopted yet. We just hope that the <a href=\"https://status.fsf.org/main/public\">Free Software Foundation's instance</a> gets updated in time!</p>\n<!-- /wp:paragraph -->",
|
||||
"summary": "One of the largest platforms in the federated social web is dropping the protocol that it started with.",
|
||||
"attributedTo": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog",
|
||||
"url": "https://wedistribute.org/2019/07/mastodon-drops-ostatus/",
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
"https://wedistribute.org/wp-json/pterotype/v1/actor/-blog/followers"
|
||||
],
|
||||
"id": "https://wedistribute.org/wp-json/pterotype/v1/object/85810",
|
||||
"likes": "https://wedistribute.org/wp-json/pterotype/v1/object/85810/likes",
|
||||
"shares": "https://wedistribute.org/wp-json/pterotype/v1/object/85810/shares"
|
||||
}
|
||||
31
test/fixtures/tesla_mock/wedistribute-user.json
vendored
Normal file
31
test/fixtures/tesla_mock/wedistribute-user.json
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers"
|
||||
}
|
||||
],
|
||||
"type": "Organization",
|
||||
"id": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog",
|
||||
"following": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog/following",
|
||||
"followers": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog/followers",
|
||||
"liked": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog/liked",
|
||||
"inbox": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog/inbox",
|
||||
"outbox": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog/outbox",
|
||||
"name": "We Distribute",
|
||||
"preferredUsername": "blog",
|
||||
"summary": "<p>Connecting many threads in the federated web. We Distribute is an independent publication dedicated to the fediverse, decentralization, P2P technologies, and Free Software!</p>",
|
||||
"url": "https://wedistribute.org/",
|
||||
"publicKey": {
|
||||
"id": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog#publicKey",
|
||||
"owner": "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog",
|
||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\r\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1bmUJ+y8PS8JFVi0KugN\r\nFl4pLvLog3V2lsV9ftmCXpveB/WJx66Tr1fQLsU3qYvQFc8UPGWD52zV4RENR1SN\r\nx0O6T2f97KUbRM+Ckow7Jyjtssgl+Mqq8UBZQ/+H8I/1Vpvt5E5hUykhFgwzx9qg\r\nzoIA3OK7alOpQbSoKXo0QcOh6yTRUnMSRMJAgUoZJzzXI/FmH/DtKr7ziQ1T2KWs\r\nVs8mWnTb/OlCxiheLuMlmJNMF+lPyVthvMIxF6Z5gV9d5QAmASSCI628e6uH2EUF\r\nDEEF5jo+Z5ffeNv28953lrnM+VB/wTjl3tYA+zCQeAmUPksX3E+YkXGxj+4rxBAY\r\n8wIDAQAB\r\n-----END PUBLIC KEY-----"
|
||||
},
|
||||
"manuallyApprovesFollowers": false,
|
||||
"icon": {
|
||||
"url": "https://wedistribute.org/wp-content/uploads/2019/02/b067de423757a538.png",
|
||||
"type": "Image",
|
||||
"mediaType": "image/png"
|
||||
}
|
||||
}
|
||||
1
test/fixtures/users_mock/masto_closed_followers_page.json
vendored
Normal file
1
test/fixtures/users_mock/masto_closed_followers_page.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"@context":"https://www.w3.org/ns/activitystreams","id":"http://localhost:4001/users/masto_closed/followers?page=1","type":"OrderedCollectionPage","totalItems":437,"next":"http://localhost:4001/users/masto_closed/followers?page=2","partOf":"http://localhost:4001/users/masto_closed/followers","orderedItems":["https://testing.uguu.ltd/users/rin","https://patch.cx/users/rin","https://letsalllovela.in/users/xoxo","https://pleroma.site/users/crushv","https://aria.company/users/boris","https://kawen.space/users/crushv","https://freespeech.host/users/cvcvcv","https://pleroma.site/users/picpub","https://pixelfed.social/users/nosleep","https://boopsnoot.gq/users/5c1896d162f7d337f90492a3","https://pikachu.rocks/users/waifu","https://royal.crablettesare.life/users/crablettes"]}
|
||||
1
test/fixtures/users_mock/masto_closed_following_page.json
vendored
Normal file
1
test/fixtures/users_mock/masto_closed_following_page.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"@context":"https://www.w3.org/ns/activitystreams","id":"http://localhost:4001/users/masto_closed/following?page=1","type":"OrderedCollectionPage","totalItems":152,"next":"http://localhost:4001/users/masto_closed/following?page=2","partOf":"http://localhost:4001/users/masto_closed/following","orderedItems":["https://testing.uguu.ltd/users/rin","https://patch.cx/users/rin","https://letsalllovela.in/users/xoxo","https://pleroma.site/users/crushv","https://aria.company/users/boris","https://kawen.space/users/crushv","https://freespeech.host/users/cvcvcv","https://pleroma.site/users/picpub","https://pixelfed.social/users/nosleep","https://boopsnoot.gq/users/5c1896d162f7d337f90492a3","https://pikachu.rocks/users/waifu","https://royal.crablettesare.life/users/crablettes"]}
|
||||
|
|
@ -39,4 +39,9 @@ defmodule Pleroma.FlakeIdTest do
|
|||
assert dump(flake_s) == {:ok, flake}
|
||||
assert dump(flake) == {:ok, flake}
|
||||
end
|
||||
|
||||
test "is_flake_id?/1" do
|
||||
assert is_flake_id?("9eoozpwTul5mjSEDRI")
|
||||
refute is_flake_id?("http://example.com/activities/3ebbadd1-eb14-4e20-8118-b6f79c0c7b0b")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,21 +4,19 @@
|
|||
|
||||
defmodule Pleroma.HTTP.RequestBuilderTest do
|
||||
use ExUnit.Case, async: true
|
||||
use Pleroma.Tests.Helpers
|
||||
alias Pleroma.HTTP.RequestBuilder
|
||||
|
||||
describe "headers/2" do
|
||||
clear_config([:http, :send_user_agent])
|
||||
|
||||
test "don't send pleroma user agent" do
|
||||
assert RequestBuilder.headers(%{}, []) == %{headers: []}
|
||||
end
|
||||
|
||||
test "send pleroma user agent" do
|
||||
send = Pleroma.Config.get([:http, :send_user_agent])
|
||||
Pleroma.Config.put([:http, :send_user_agent], true)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:http, :send_user_agent], send)
|
||||
end)
|
||||
|
||||
assert RequestBuilder.headers(%{}, []) == %{
|
||||
headers: [{"User-Agent", Pleroma.Application.user_agent()}]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,13 +4,15 @@
|
|||
|
||||
defmodule Pleroma.NotificationTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.Streamer
|
||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "create_notifications" do
|
||||
test "notifies someone when they are directly addressed" do
|
||||
|
|
@ -352,6 +354,51 @@ defmodule Pleroma.NotificationTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "for_user_since/2" do
|
||||
defp days_ago(days) do
|
||||
NaiveDateTime.add(
|
||||
NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
|
||||
-days * 60 * 60 * 24,
|
||||
:second
|
||||
)
|
||||
end
|
||||
|
||||
test "Returns recent notifications" do
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
Enum.each(0..10, fn i ->
|
||||
{:ok, _activity} =
|
||||
CommonAPI.post(user1, %{
|
||||
"status" => "hey ##{i} @#{user2.nickname}!"
|
||||
})
|
||||
end)
|
||||
|
||||
{old, new} = Enum.split(Notification.for_user(user2), 5)
|
||||
|
||||
Enum.each(old, fn notification ->
|
||||
notification
|
||||
|> cast(%{updated_at: days_ago(10)}, [:updated_at])
|
||||
|> Pleroma.Repo.update!()
|
||||
end)
|
||||
|
||||
recent_notifications_ids =
|
||||
user2
|
||||
|> Notification.for_user_since(
|
||||
NaiveDateTime.add(NaiveDateTime.utc_now(), -5 * 86_400, :second)
|
||||
)
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
Enum.each(old, fn %{id: id} ->
|
||||
refute id in recent_notifications_ids
|
||||
end)
|
||||
|
||||
Enum.each(new, fn %{id: id} ->
|
||||
assert id in recent_notifications_ids
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
describe "notification target determination" do
|
||||
test "it sends notifications to addressed users in new messages" do
|
||||
user = insert(:user)
|
||||
|
|
@ -564,6 +611,64 @@ defmodule Pleroma.NotificationTest do
|
|||
|
||||
assert Enum.empty?(Notification.for_user(user))
|
||||
end
|
||||
|
||||
test "notifications are deleted if a local user is deleted" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}", "visibility" => "direct"})
|
||||
|
||||
refute Enum.empty?(Notification.for_user(other_user))
|
||||
|
||||
User.delete(user)
|
||||
|
||||
assert Enum.empty?(Notification.for_user(other_user))
|
||||
end
|
||||
|
||||
test "notifications are deleted if a remote user is deleted" do
|
||||
remote_user = insert(:user)
|
||||
local_user = insert(:user)
|
||||
|
||||
dm_message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"type" => "Create",
|
||||
"actor" => remote_user.ap_id,
|
||||
"id" => remote_user.ap_id <> "/activities/test",
|
||||
"to" => [local_user.ap_id],
|
||||
"cc" => [],
|
||||
"object" => %{
|
||||
"type" => "Note",
|
||||
"content" => "Hello!",
|
||||
"tag" => [
|
||||
%{
|
||||
"type" => "Mention",
|
||||
"href" => local_user.ap_id,
|
||||
"name" => "@#{local_user.nickname}"
|
||||
}
|
||||
],
|
||||
"to" => [local_user.ap_id],
|
||||
"cc" => [],
|
||||
"attributedTo" => remote_user.ap_id
|
||||
}
|
||||
}
|
||||
|
||||
{:ok, _dm_activity} = Transmogrifier.handle_incoming(dm_message)
|
||||
|
||||
refute Enum.empty?(Notification.for_user(local_user))
|
||||
|
||||
delete_user_message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"id" => remote_user.ap_id <> "/activities/delete",
|
||||
"actor" => remote_user.ap_id,
|
||||
"type" => "Delete",
|
||||
"object" => remote_user.ap_id
|
||||
}
|
||||
|
||||
{:ok, _delete_activity} = Transmogrifier.handle_incoming(delete_user_message)
|
||||
|
||||
assert Enum.empty?(Notification.for_user(local_user))
|
||||
end
|
||||
end
|
||||
|
||||
describe "for_user" do
|
||||
|
|
|
|||
|
|
@ -110,6 +110,13 @@ defmodule Pleroma.Object.FetcherTest do
|
|||
assert object
|
||||
end
|
||||
|
||||
test "it can fetch wedistribute articles" do
|
||||
{:ok, object} =
|
||||
Fetcher.fetch_object_from_id("https://wedistribute.org/wp-json/pterotype/v1/object/85810")
|
||||
|
||||
assert object
|
||||
end
|
||||
|
||||
test "all objects with fake directions are rejected by the object fetcher" do
|
||||
assert {:error, _} =
|
||||
Fetcher.fetch_and_contain_remote_object_from_id(
|
||||
|
|
@ -152,32 +159,28 @@ defmodule Pleroma.Object.FetcherTest do
|
|||
end
|
||||
|
||||
describe "signed fetches" do
|
||||
clear_config([:activitypub, :sign_object_fetches])
|
||||
|
||||
test_with_mock "it signs fetches when configured to do so",
|
||||
Pleroma.Signature,
|
||||
[:passthrough],
|
||||
[] do
|
||||
option = Pleroma.Config.get([:activitypub, :sign_object_fetches])
|
||||
Pleroma.Config.put([:activitypub, :sign_object_fetches], true)
|
||||
|
||||
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
|
||||
|
||||
assert called(Pleroma.Signature.sign(:_, :_))
|
||||
|
||||
Pleroma.Config.put([:activitypub, :sign_object_fetches], option)
|
||||
end
|
||||
|
||||
test_with_mock "it doesn't sign fetches when not configured to do so",
|
||||
Pleroma.Signature,
|
||||
[:passthrough],
|
||||
[] do
|
||||
option = Pleroma.Config.get([:activitypub, :sign_object_fetches])
|
||||
Pleroma.Config.put([:activitypub, :sign_object_fetches], false)
|
||||
|
||||
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
|
||||
|
||||
refute called(Pleroma.Signature.sign(:_, :_))
|
||||
|
||||
Pleroma.Config.put([:activitypub, :sign_object_fetches], option)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,8 +9,10 @@ defmodule Pleroma.Plugs.EnsurePublicOrAuthenticatedPlugTest do
|
|||
alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug
|
||||
alias Pleroma.User
|
||||
|
||||
clear_config([:instance, :public])
|
||||
|
||||
test "it halts if not public and no user is assigned", %{conn: conn} do
|
||||
set_public_to(false)
|
||||
Config.put([:instance, :public], false)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -21,7 +23,7 @@ defmodule Pleroma.Plugs.EnsurePublicOrAuthenticatedPlugTest do
|
|||
end
|
||||
|
||||
test "it continues if public", %{conn: conn} do
|
||||
set_public_to(true)
|
||||
Config.put([:instance, :public], true)
|
||||
|
||||
ret_conn =
|
||||
conn
|
||||
|
|
@ -31,7 +33,7 @@ defmodule Pleroma.Plugs.EnsurePublicOrAuthenticatedPlugTest do
|
|||
end
|
||||
|
||||
test "it continues if a user is assigned, even if not public", %{conn: conn} do
|
||||
set_public_to(false)
|
||||
Config.put([:instance, :public], false)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -43,13 +45,4 @@ defmodule Pleroma.Plugs.EnsurePublicOrAuthenticatedPlugTest do
|
|||
|
||||
assert ret_conn == conn
|
||||
end
|
||||
|
||||
defp set_public_to(value) do
|
||||
orig = Config.get!([:instance, :public])
|
||||
Config.put([:instance, :public], value)
|
||||
|
||||
on_exit(fn ->
|
||||
Config.put([:instance, :public], orig)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,17 +7,12 @@ defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do
|
|||
alias Pleroma.Config
|
||||
alias Plug.Conn
|
||||
|
||||
clear_config([:http_securiy, :enabled])
|
||||
clear_config([:http_security, :sts])
|
||||
|
||||
describe "http security enabled" do
|
||||
setup do
|
||||
enabled = Config.get([:http_securiy, :enabled])
|
||||
|
||||
Config.put([:http_security, :enabled], true)
|
||||
|
||||
on_exit(fn ->
|
||||
Config.put([:http_security, :enabled], enabled)
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
test "it sends CSP headers when enabled", %{conn: conn} do
|
||||
|
|
@ -81,14 +76,8 @@ defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do
|
|||
end
|
||||
|
||||
test "it does not send CSP headers when disabled", %{conn: conn} do
|
||||
enabled = Config.get([:http_securiy, :enabled])
|
||||
|
||||
Config.put([:http_security, :enabled], false)
|
||||
|
||||
on_exit(fn ->
|
||||
Config.put([:http_security, :enabled], enabled)
|
||||
end)
|
||||
|
||||
conn = get(conn, "/api/v1/instance")
|
||||
|
||||
assert Conn.get_resp_header(conn, "x-xss-protection") == []
|
||||
|
|
|
|||
|
|
@ -8,14 +8,12 @@ defmodule Pleroma.Web.RuntimeStaticPlugTest do
|
|||
@dir "test/tmp/instance_static"
|
||||
|
||||
setup do
|
||||
static_dir = Pleroma.Config.get([:instance, :static_dir])
|
||||
Pleroma.Config.put([:instance, :static_dir], @dir)
|
||||
File.mkdir_p!(@dir)
|
||||
on_exit(fn -> File.rm_rf(@dir) end)
|
||||
end
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :static_dir], static_dir)
|
||||
File.rm_rf(@dir)
|
||||
end)
|
||||
clear_config([:instance, :static_dir]) do
|
||||
Pleroma.Config.put([:instance, :static_dir], @dir)
|
||||
end
|
||||
|
||||
test "overrides index" do
|
||||
|
|
|
|||
38
test/plugs/set_format_plug_test.exs
Normal file
38
test/plugs/set_format_plug_test.exs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Plugs.SetFormatPlugTest do
|
||||
use ExUnit.Case, async: true
|
||||
use Plug.Test
|
||||
|
||||
alias Pleroma.Plugs.SetFormatPlug
|
||||
|
||||
test "set format from params" do
|
||||
conn =
|
||||
:get
|
||||
|> conn("/cofe?_format=json")
|
||||
|> SetFormatPlug.call([])
|
||||
|
||||
assert %{format: "json"} == conn.assigns
|
||||
end
|
||||
|
||||
test "set format from header" do
|
||||
conn =
|
||||
:get
|
||||
|> conn("/cofe")
|
||||
|> put_private(:phoenix_format, "xml")
|
||||
|> SetFormatPlug.call([])
|
||||
|
||||
assert %{format: "xml"} == conn.assigns
|
||||
end
|
||||
|
||||
test "doesn't set format" do
|
||||
conn =
|
||||
:get
|
||||
|> conn("/cofe")
|
||||
|> SetFormatPlug.call([])
|
||||
|
||||
refute conn.assigns[:format]
|
||||
end
|
||||
end
|
||||
|
|
@ -108,11 +108,11 @@ defmodule Pleroma.ReverseProxyTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "max_body_size returns error if streaming body more than that option", %{conn: conn} do
|
||||
test "max_body_length returns error if streaming body more than that option", %{conn: conn} do
|
||||
stream_mock(3, true)
|
||||
|
||||
assert capture_log(fn ->
|
||||
ReverseProxy.call(conn, "/stream-bytes/50", max_body_size: 30)
|
||||
ReverseProxy.call(conn, "/stream-bytes/50", max_body_length: 30)
|
||||
end) =~
|
||||
"[warn] Elixir.Pleroma.ReverseProxy request to /stream-bytes/50 failed while reading/chunking: :body_too_large"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ defmodule Pleroma.Builders.UserBuilder do
|
|||
nickname: "testname",
|
||||
password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
|
||||
bio: "A tester.",
|
||||
ap_id: "some id"
|
||||
ap_id: "some id",
|
||||
last_digest_emailed_at: NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
|
||||
}
|
||||
|
||||
Map.merge(user, data)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ defmodule Pleroma.Factory do
|
|||
nickname: sequence(:nickname, &"nick#{&1}"),
|
||||
password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
|
||||
bio: sequence(:bio, &"Tester Number #{&1}"),
|
||||
info: %{}
|
||||
info: %{},
|
||||
last_digest_emailed_at: NaiveDateTime.utc_now()
|
||||
}
|
||||
|
||||
%{
|
||||
|
|
@ -201,8 +202,8 @@ defmodule Pleroma.Factory do
|
|||
}
|
||||
end
|
||||
|
||||
def like_activity_factory do
|
||||
note_activity = insert(:note_activity)
|
||||
def like_activity_factory(attrs \\ %{}) do
|
||||
note_activity = attrs[:note_activity] || insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
user = insert(:user)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,52 @@ defmodule Pleroma.Tests.Helpers do
|
|||
Helpers for use in tests.
|
||||
"""
|
||||
|
||||
defmacro clear_config(config_path) do
|
||||
quote do
|
||||
clear_config(unquote(config_path)) do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defmacro clear_config(config_path, do: yield) do
|
||||
quote do
|
||||
setup do
|
||||
initial_setting = Pleroma.Config.get(unquote(config_path))
|
||||
unquote(yield)
|
||||
on_exit(fn -> Pleroma.Config.put(unquote(config_path), initial_setting) end)
|
||||
:ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defmacro clear_config_all(config_path) do
|
||||
quote do
|
||||
clear_config_all(unquote(config_path)) do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defmacro clear_config_all(config_path, do: yield) do
|
||||
quote do
|
||||
setup_all do
|
||||
initial_setting = Pleroma.Config.get(unquote(config_path))
|
||||
unquote(yield)
|
||||
on_exit(fn -> Pleroma.Config.put(unquote(config_path), initial_setting) end)
|
||||
:ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defmacro __using__(_opts) do
|
||||
quote do
|
||||
import Pleroma.Tests.Helpers,
|
||||
only: [
|
||||
clear_config: 1,
|
||||
clear_config: 2,
|
||||
clear_config_all: 1,
|
||||
clear_config_all: 2
|
||||
]
|
||||
|
||||
def collect_ids(collection) do
|
||||
collection
|
||||
|> Enum.map(& &1.id)
|
||||
|
|
@ -30,6 +74,15 @@ defmodule Pleroma.Tests.Helpers do
|
|||
|> Poison.encode!()
|
||||
|> Poison.decode!()
|
||||
end
|
||||
|
||||
defmacro guards_config(config_path) do
|
||||
quote do
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
Pleroma.Config.put(config_path, true)
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -51,6 +51,10 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://mastodon.social/users/not_found", _, _, _) do
|
||||
{:ok, %Tesla.Env{status: 404}}
|
||||
end
|
||||
|
||||
def get("https://mastodon.sdf.org/users/rinpatch", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
|
@ -301,6 +305,22 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://wedistribute.org/wp-json/pterotype/v1/object/85810", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/wedistribute-article.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("https://wedistribute.org/wp-json/pterotype/v1/actor/-blog", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("http://mastodon.example.org/users/admin", _, _, Accept: "application/activity+json") do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
|
@ -614,6 +634,15 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get(
|
||||
"https://social.heldscal.la/.well-known/webfinger?resource=invalid_content@social.heldscal.la",
|
||||
_,
|
||||
_,
|
||||
Accept: "application/xrd+xml,application/jrd+json"
|
||||
) do
|
||||
{:ok, %Tesla.Env{status: 200, body: ""}}
|
||||
end
|
||||
|
||||
def get("http://framatube.org/.well-known/host-meta", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
|
@ -767,6 +796,14 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("http://localhost:4001/users/masto_closed/followers?page=1", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/users_mock/masto_closed_followers_page.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
|
@ -775,6 +812,14 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("http://localhost:4001/users/masto_closed/following?page=1", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/users_mock/masto_closed_following_page.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
|
@ -915,6 +960,14 @@ defmodule HttpRequestMock do
|
|||
{:ok, %Tesla.Env{status: 404, body: ""}}
|
||||
end
|
||||
|
||||
def get("https://mstdn.jp/.well-known/webfinger?resource=acct:kpherox@mstdn.jp", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
|
||||
}}
|
||||
end
|
||||
|
||||
def get(url, query, body, headers) do
|
||||
{:error,
|
||||
"Not implemented the mock response for get #{inspect(url)}, #{query}, #{inspect(body)}, #{
|
||||
|
|
|
|||
13
test/support/mrf_module_mock.ex
Normal file
13
test/support/mrf_module_mock.ex
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule MRFModuleMock do
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||
|
||||
@impl true
|
||||
def filter(message), do: {:ok, message}
|
||||
|
||||
@impl true
|
||||
def describe, do: {:ok, %{mrf_module_mock: "some config data"}}
|
||||
end
|
||||
|
|
@ -11,21 +11,20 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
Mix.shell(Mix.Shell.Process)
|
||||
temp_file = "config/temp.exported_from_db.secret.exs"
|
||||
|
||||
dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
|
||||
|
||||
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
||||
|
||||
on_exit(fn ->
|
||||
Mix.shell(Mix.Shell.IO)
|
||||
Application.delete_env(:pleroma, :first_setting)
|
||||
Application.delete_env(:pleroma, :second_setting)
|
||||
Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
|
||||
:ok = File.rm(temp_file)
|
||||
end)
|
||||
|
||||
{:ok, temp_file: temp_file}
|
||||
end
|
||||
|
||||
clear_config_all([:instance, :dynamic_configuration]) do
|
||||
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
||||
end
|
||||
|
||||
test "settings are migrated to db" do
|
||||
assert Repo.all(Config) == []
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,12 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Mix.Tasks.Pleroma.DatabaseTest do
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
@ -19,6 +23,52 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
describe "running remove_embedded_objects" do
|
||||
test "it replaces objects with references" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
|
||||
new_data = Map.put(activity.data, "object", activity.object.data)
|
||||
|
||||
{:ok, activity} =
|
||||
activity
|
||||
|> Activity.change(%{data: new_data})
|
||||
|> Repo.update()
|
||||
|
||||
assert is_map(activity.data["object"])
|
||||
|
||||
Mix.Tasks.Pleroma.Database.run(["remove_embedded_objects"])
|
||||
|
||||
activity = Activity.get_by_id_with_object(activity.id)
|
||||
assert is_binary(activity.data["object"])
|
||||
end
|
||||
end
|
||||
|
||||
describe "prune_objects" do
|
||||
test "it prunes old objects from the database" do
|
||||
insert(:note)
|
||||
deadline = Pleroma.Config.get([:instance, :remote_post_retention_days]) + 1
|
||||
|
||||
date =
|
||||
Timex.now()
|
||||
|> Timex.shift(days: -deadline)
|
||||
|> Timex.to_naive_datetime()
|
||||
|> NaiveDateTime.truncate(:second)
|
||||
|
||||
%{id: id} =
|
||||
:note
|
||||
|> insert()
|
||||
|> Ecto.Changeset.change(%{inserted_at: date})
|
||||
|> Repo.update!()
|
||||
|
||||
assert length(Repo.all(Object)) == 2
|
||||
|
||||
Mix.Tasks.Pleroma.Database.run(["prune_objects"])
|
||||
|
||||
assert length(Repo.all(Object)) == 1
|
||||
refute Object.get_by_id(id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "running update_users_following_followers_counts" do
|
||||
test "following and followers count are updated" do
|
||||
[user, user2] = insert_pair(:user)
|
||||
|
|
@ -46,4 +96,37 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
|
|||
assert user.info.follower_count == 0
|
||||
end
|
||||
end
|
||||
|
||||
describe "running fix_likes_collections" do
|
||||
test "it turns OrderedCollection likes into empty arrays" do
|
||||
[user, user2] = insert_pair(:user)
|
||||
|
||||
{:ok, %{id: id, object: object}} = CommonAPI.post(user, %{"status" => "test"})
|
||||
{:ok, %{object: object2}} = CommonAPI.post(user, %{"status" => "test test"})
|
||||
|
||||
CommonAPI.favorite(id, user2)
|
||||
|
||||
likes = %{
|
||||
"first" =>
|
||||
"http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes?page=1",
|
||||
"id" => "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes",
|
||||
"totalItems" => 3,
|
||||
"type" => "OrderedCollection"
|
||||
}
|
||||
|
||||
new_data = Map.put(object2.data, "likes", likes)
|
||||
|
||||
object2
|
||||
|> Ecto.Changeset.change(%{data: new_data})
|
||||
|> Repo.update()
|
||||
|
||||
assert length(Object.get_by_id(object.id).data["likes"]) == 1
|
||||
assert is_map(Object.get_by_id(object2.id).data["likes"])
|
||||
|
||||
assert :ok == Mix.Tasks.Pleroma.Database.run(["fix_likes_collections"])
|
||||
|
||||
assert length(Object.get_by_id(object.id).data["likes"]) == 1
|
||||
assert Enum.empty?(Object.get_by_id(object2.id).data["likes"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
51
test/tasks/digest_test.exs
Normal file
51
test/tasks/digest_test.exs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
defmodule Mix.Tasks.Pleroma.DigestTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
setup_all do
|
||||
Mix.shell(Mix.Shell.Process)
|
||||
|
||||
on_exit(fn ->
|
||||
Mix.shell(Mix.Shell.IO)
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "pleroma.digest test" do
|
||||
test "Sends digest to the given user" do
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
Enum.each(0..10, fn i ->
|
||||
{:ok, _activity} =
|
||||
CommonAPI.post(user1, %{
|
||||
"status" => "hey ##{i} @#{user2.nickname}!"
|
||||
})
|
||||
end)
|
||||
|
||||
yesterday =
|
||||
NaiveDateTime.add(
|
||||
NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
|
||||
-60 * 60 * 24,
|
||||
:second
|
||||
)
|
||||
|
||||
{:ok, yesterday_date} = Timex.format(yesterday, "%F", :strftime)
|
||||
|
||||
:ok = Mix.Tasks.Pleroma.Digest.run(["test", user2.nickname, yesterday_date])
|
||||
|
||||
assert_receive {:mix_shell, :info, [message]}
|
||||
assert message =~ "Digest email have been sent"
|
||||
|
||||
assert_email_sent(
|
||||
to: {user2.name, user2.email},
|
||||
html_body: ~r/here is what you've missed!/i
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -69,4 +69,27 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
|
|||
assert undo_activity.data["object"] == cancelled_activity.data
|
||||
end
|
||||
end
|
||||
|
||||
describe "mix pleroma.relay list" do
|
||||
test "Prints relay subscription list" do
|
||||
:ok = Mix.Tasks.Pleroma.Relay.run(["list"])
|
||||
|
||||
refute_receive {:mix_shell, :info, _}
|
||||
|
||||
Pleroma.Web.ActivityPub.Relay.get_actor()
|
||||
|> Ecto.Changeset.change(
|
||||
following: [
|
||||
"http://test-app.com/user/test1",
|
||||
"http://test-app.com/user/test1",
|
||||
"http://test-app-42.com/user/test1"
|
||||
]
|
||||
)
|
||||
|> Pleroma.User.update_and_set_cache()
|
||||
|
||||
:ok = Mix.Tasks.Pleroma.Relay.run(["list"])
|
||||
|
||||
assert_receive {:mix_shell, :info, ["test-app.com"]}
|
||||
assert_receive {:mix_shell, :info, ["test-app-42.com"]}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,17 +4,17 @@
|
|||
|
||||
defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
|
||||
use ExUnit.Case
|
||||
use Pleroma.Tests.Helpers
|
||||
alias Mix.Tasks.Pleroma.RobotsTxt
|
||||
|
||||
clear_config([:instance, :static_dir])
|
||||
|
||||
test "creates new dir" do
|
||||
path = "test/fixtures/new_dir/"
|
||||
file_path = path <> "robots.txt"
|
||||
|
||||
static_dir = Pleroma.Config.get([:instance, :static_dir])
|
||||
Pleroma.Config.put([:instance, :static_dir], path)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :static_dir], static_dir)
|
||||
{:ok, ["test/fixtures/new_dir/", "test/fixtures/new_dir/robots.txt"]} = File.rm_rf(path)
|
||||
end)
|
||||
|
||||
|
|
@ -29,11 +29,9 @@ defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
|
|||
test "to existance folder" do
|
||||
path = "test/fixtures/"
|
||||
file_path = path <> "robots.txt"
|
||||
static_dir = Pleroma.Config.get([:instance, :static_dir])
|
||||
Pleroma.Config.put([:instance, :static_dir], path)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :static_dir], static_dir)
|
||||
:ok = File.rm(file_path)
|
||||
end)
|
||||
|
||||
|
|
|
|||
|
|
@ -9,12 +9,6 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilenameTest do
|
|||
alias Pleroma.Upload
|
||||
|
||||
setup do
|
||||
custom_filename = Config.get([Upload.Filter.AnonymizeFilename, :text])
|
||||
|
||||
on_exit(fn ->
|
||||
Config.put([Upload.Filter.AnonymizeFilename, :text], custom_filename)
|
||||
end)
|
||||
|
||||
upload_file = %Upload{
|
||||
name: "an… image.jpg",
|
||||
content_type: "image/jpg",
|
||||
|
|
@ -24,6 +18,8 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilenameTest do
|
|||
%{upload_file: upload_file}
|
||||
end
|
||||
|
||||
clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text])
|
||||
|
||||
test "it replaces filename on pre-defined text", %{upload_file: upload_file} do
|
||||
Config.put([Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
|
||||
{:ok, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ defmodule Pleroma.Upload.Filter.DedupeTest do
|
|||
|
||||
assert {
|
||||
:ok,
|
||||
%Pleroma.Upload{id: @shasum, path: "#{@shasum}.jpg"}
|
||||
%Pleroma.Upload{id: @shasum, path: @shasum <> ".jpg"}
|
||||
} = Dedupe.filter(upload)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,13 +10,7 @@ defmodule Pleroma.Upload.Filter.MogrifyTest do
|
|||
alias Pleroma.Upload
|
||||
alias Pleroma.Upload.Filter
|
||||
|
||||
setup do
|
||||
filter = Config.get([Filter.Mogrify, :args])
|
||||
|
||||
on_exit(fn ->
|
||||
Config.put([Filter.Mogrify, :args], filter)
|
||||
end)
|
||||
end
|
||||
clear_config([Filter.Mogrify, :args])
|
||||
|
||||
test "apply mogrify filter" do
|
||||
Config.put([Filter.Mogrify, :args], [{"tint", "40"}])
|
||||
|
|
|
|||
|
|
@ -8,13 +8,7 @@ defmodule Pleroma.Upload.FilterTest do
|
|||
alias Pleroma.Config
|
||||
alias Pleroma.Upload.Filter
|
||||
|
||||
setup do
|
||||
custom_filename = Config.get([Pleroma.Upload.Filter.AnonymizeFilename, :text])
|
||||
|
||||
on_exit(fn ->
|
||||
Config.put([Pleroma.Upload.Filter.AnonymizeFilename, :text], custom_filename)
|
||||
end)
|
||||
end
|
||||
clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text])
|
||||
|
||||
test "applies filters" do
|
||||
Config.put([Pleroma.Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
|
||||
|
|
|
|||
|
|
@ -122,24 +122,6 @@ defmodule Pleroma.UploadTest do
|
|||
assert String.starts_with?(url, Pleroma.Web.base_url() <> "/media/")
|
||||
end
|
||||
|
||||
test "returns a media url with configured base_url" do
|
||||
base_url = "https://cache.pleroma.social"
|
||||
|
||||
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
path: Path.absname("test/fixtures/image_tmp.jpg"),
|
||||
filename: "image.jpg"
|
||||
}
|
||||
|
||||
{:ok, data} = Upload.store(file, base_url: base_url)
|
||||
|
||||
assert %{"url" => [%{"href" => url}]} = data
|
||||
|
||||
assert String.starts_with?(url, base_url <> "/media/")
|
||||
end
|
||||
|
||||
test "copies the file to the configured folder with deduping" do
|
||||
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
|
||||
|
||||
|
|
@ -266,4 +248,28 @@ defmodule Pleroma.UploadTest do
|
|||
"%3A%3F%23%5B%5D%40%21%24%26%5C%27%28%29%2A%2B%2C%3B%3D.jpg"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Setting a custom base_url for uploaded media" do
|
||||
clear_config([Pleroma.Upload, :base_url]) do
|
||||
Pleroma.Config.put([Pleroma.Upload, :base_url], "https://cache.pleroma.social")
|
||||
end
|
||||
|
||||
test "returns a media url with configured base_url" do
|
||||
base_url = Pleroma.Config.get([Pleroma.Upload, :base_url])
|
||||
|
||||
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
path: Path.absname("test/fixtures/image_tmp.jpg"),
|
||||
filename: "image.jpg"
|
||||
}
|
||||
|
||||
{:ok, data} = Upload.store(file, base_url: base_url)
|
||||
|
||||
assert %{"url" => [%{"href" => url}]} = data
|
||||
|
||||
refute String.starts_with?(url, base_url <> "/media/")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
32
test/uploaders/local_test.exs
Normal file
32
test/uploaders/local_test.exs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Uploaders.LocalTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Uploaders.Local
|
||||
|
||||
describe "get_file/1" do
|
||||
test "it returns path to local folder for files" do
|
||||
assert Local.get_file("") == {:ok, {:static_dir, "test/uploads"}}
|
||||
end
|
||||
end
|
||||
|
||||
describe "put_file/1" do
|
||||
test "put file to local folder" do
|
||||
file_path = "local_upload/files/image.jpg"
|
||||
|
||||
file = %Pleroma.Upload{
|
||||
name: "image.jpg",
|
||||
content_type: "image/jpg",
|
||||
path: file_path,
|
||||
tempfile: Path.absname("test/fixtures/image_tmp.jpg")
|
||||
}
|
||||
|
||||
assert Local.put_file(file) == :ok
|
||||
|
||||
assert Path.join([Local.upload_path(), file_path])
|
||||
|> File.exists?()
|
||||
end
|
||||
end
|
||||
end
|
||||
50
test/uploaders/mdii_test.exs
Normal file
50
test/uploaders/mdii_test.exs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Uploaders.MDIITest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Uploaders.MDII
|
||||
import Tesla.Mock
|
||||
|
||||
describe "get_file/1" do
|
||||
test "it returns path to local folder for files" do
|
||||
assert MDII.get_file("") == {:ok, {:static_dir, "test/uploads"}}
|
||||
end
|
||||
end
|
||||
|
||||
describe "put_file/1" do
|
||||
setup do
|
||||
file_upload = %Pleroma.Upload{
|
||||
name: "mdii-image.jpg",
|
||||
content_type: "image/jpg",
|
||||
path: "test_folder/mdii-image.jpg",
|
||||
tempfile: Path.absname("test/fixtures/image_tmp.jpg")
|
||||
}
|
||||
|
||||
[file_upload: file_upload]
|
||||
end
|
||||
|
||||
test "save file", %{file_upload: file_upload} do
|
||||
mock(fn
|
||||
%{method: :post, url: "https://mdii.sakura.ne.jp/mdii-post.cgi?jpg"} ->
|
||||
%Tesla.Env{status: 200, body: "mdii-image"}
|
||||
end)
|
||||
|
||||
assert MDII.put_file(file_upload) ==
|
||||
{:ok, {:url, "https://mdii.sakura.ne.jp/mdii-image.jpg"}}
|
||||
end
|
||||
|
||||
test "save file to local if MDII isn`t available", %{file_upload: file_upload} do
|
||||
mock(fn
|
||||
%{method: :post, url: "https://mdii.sakura.ne.jp/mdii-post.cgi?jpg"} ->
|
||||
%Tesla.Env{status: 500}
|
||||
end)
|
||||
|
||||
assert MDII.put_file(file_upload) == :ok
|
||||
|
||||
assert Path.join([Pleroma.Uploaders.Local.upload_path(), file_upload.path])
|
||||
|> File.exists?()
|
||||
end
|
||||
end
|
||||
end
|
||||
82
test/uploaders/s3_test.exs
Normal file
82
test/uploaders/s3_test.exs
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Uploaders.S3Test do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Uploaders.S3
|
||||
|
||||
import Mock
|
||||
import ExUnit.CaptureLog
|
||||
|
||||
clear_config([Pleroma.Uploaders.S3]) do
|
||||
Config.put([Pleroma.Uploaders.S3],
|
||||
bucket: "test_bucket",
|
||||
public_endpoint: "https://s3.amazonaws.com"
|
||||
)
|
||||
end
|
||||
|
||||
describe "get_file/1" do
|
||||
test "it returns path to local folder for files" do
|
||||
assert S3.get_file("test_image.jpg") == {
|
||||
:ok,
|
||||
{:url, "https://s3.amazonaws.com/test_bucket/test_image.jpg"}
|
||||
}
|
||||
end
|
||||
|
||||
test "it returns path without bucket when truncated_namespace set to ''" do
|
||||
Config.put([Pleroma.Uploaders.S3],
|
||||
bucket: "test_bucket",
|
||||
public_endpoint: "https://s3.amazonaws.com",
|
||||
truncated_namespace: ""
|
||||
)
|
||||
|
||||
assert S3.get_file("test_image.jpg") == {
|
||||
:ok,
|
||||
{:url, "https://s3.amazonaws.com/test_image.jpg"}
|
||||
}
|
||||
end
|
||||
|
||||
test "it returns path with bucket namespace when namespace is set" do
|
||||
Config.put([Pleroma.Uploaders.S3],
|
||||
bucket: "test_bucket",
|
||||
public_endpoint: "https://s3.amazonaws.com",
|
||||
bucket_namespace: "family"
|
||||
)
|
||||
|
||||
assert S3.get_file("test_image.jpg") == {
|
||||
:ok,
|
||||
{:url, "https://s3.amazonaws.com/family:test_bucket/test_image.jpg"}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe "put_file/1" do
|
||||
setup do
|
||||
file_upload = %Pleroma.Upload{
|
||||
name: "image-tet.jpg",
|
||||
content_type: "image/jpg",
|
||||
path: "test_folder/image-tet.jpg",
|
||||
tempfile: Path.absname("test/fixtures/image_tmp.jpg")
|
||||
}
|
||||
|
||||
[file_upload: file_upload]
|
||||
end
|
||||
|
||||
test "save file", %{file_upload: file_upload} do
|
||||
with_mock ExAws, request: fn _ -> {:ok, :ok} end do
|
||||
assert S3.put_file(file_upload) == {:ok, {:file, "test_folder/image-tet.jpg"}}
|
||||
end
|
||||
end
|
||||
|
||||
test "returns error", %{file_upload: file_upload} do
|
||||
with_mock ExAws, request: fn _ -> {:error, "S3 Upload failed"} end do
|
||||
assert capture_log(fn ->
|
||||
assert S3.put_file(file_upload) == {:error, "S3 Upload failed"}
|
||||
end) =~ "Elixir.Pleroma.Uploaders.S3: {:error, \"S3 Upload failed\"}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
24
test/user_info_test.exs
Normal file
24
test/user_info_test.exs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
defmodule Pleroma.UserInfoTest do
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User.Info
|
||||
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "update_email_notifications/2" do
|
||||
setup do
|
||||
user = insert(:user, %{info: %{email_notifications: %{"digest" => true}}})
|
||||
|
||||
{:ok, user: user}
|
||||
end
|
||||
|
||||
test "Notifications are updated", %{user: user} do
|
||||
true = user.info.email_notifications["digest"]
|
||||
changeset = Info.update_email_notifications(user.info, %{"digest" => false})
|
||||
assert changeset.valid?
|
||||
{:ok, result} = Ecto.Changeset.apply_action(changeset, :insert)
|
||||
assert result.email_notifications["digest"] == false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -193,7 +193,14 @@ defmodule Pleroma.UserSearchTest do
|
|||
user = User.get_cached_by_ap_id("http://mastodon.example.org/users/admin")
|
||||
|
||||
assert length(results) == 1
|
||||
assert user == result |> Map.put(:search_rank, nil) |> Map.put(:search_type, nil)
|
||||
|
||||
expected =
|
||||
result
|
||||
|> Map.put(:search_rank, nil)
|
||||
|> Map.put(:search_type, nil)
|
||||
|> Map.put(:last_digest_emailed_at, nil)
|
||||
|
||||
assert user == expected
|
||||
end
|
||||
|
||||
test "excludes a blocked users from search result" do
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ defmodule Pleroma.UserTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
clear_config([:instance, :account_activation_required])
|
||||
|
||||
describe "when tags are nil" do
|
||||
test "tagging a user" do
|
||||
user = insert(:user, %{tags: nil})
|
||||
|
|
@ -90,6 +92,17 @@ defmodule Pleroma.UserTest do
|
|||
assert activity
|
||||
end
|
||||
|
||||
test "clears follow requests when requester is blocked" do
|
||||
followed = insert(:user, %{info: %{locked: true}})
|
||||
follower = insert(:user)
|
||||
|
||||
CommonAPI.follow(follower, followed)
|
||||
assert {:ok, [_activity]} = User.get_follow_requests(followed)
|
||||
|
||||
{:ok, _follower} = User.block(followed, follower)
|
||||
assert {:ok, []} = User.get_follow_requests(followed)
|
||||
end
|
||||
|
||||
test "follow_all follows mutliple users" do
|
||||
user = insert(:user)
|
||||
followed_zero = insert(:user)
|
||||
|
|
@ -192,24 +205,64 @@ defmodule Pleroma.UserTest do
|
|||
# assert websub
|
||||
# end
|
||||
|
||||
test "unfollow takes a user and another user" do
|
||||
followed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(followed)]})
|
||||
describe "unfollow/2" do
|
||||
setup do
|
||||
setting = Pleroma.Config.get([:instance, :external_user_synchronization])
|
||||
|
||||
{:ok, user, _activity} = User.unfollow(user, followed)
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :external_user_synchronization], setting)
|
||||
end)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
:ok
|
||||
end
|
||||
|
||||
assert user.following == []
|
||||
end
|
||||
test "unfollow with syncronizes external user" do
|
||||
Pleroma.Config.put([:instance, :external_user_synchronization], true)
|
||||
|
||||
test "unfollow doesn't unfollow yourself" do
|
||||
user = insert(:user)
|
||||
followed =
|
||||
insert(:user,
|
||||
nickname: "fuser1",
|
||||
follower_address: "http://localhost:4001/users/fuser1/followers",
|
||||
following_address: "http://localhost:4001/users/fuser1/following",
|
||||
ap_id: "http://localhost:4001/users/fuser1"
|
||||
)
|
||||
|
||||
{:error, _} = User.unfollow(user, user)
|
||||
user =
|
||||
insert(:user, %{
|
||||
local: false,
|
||||
nickname: "fuser2",
|
||||
ap_id: "http://localhost:4001/users/fuser2",
|
||||
follower_address: "http://localhost:4001/users/fuser2/followers",
|
||||
following_address: "http://localhost:4001/users/fuser2/following",
|
||||
following: [User.ap_followers(followed)]
|
||||
})
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
assert user.following == [user.ap_id]
|
||||
{:ok, user, _activity} = User.unfollow(user, followed)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
assert user.following == []
|
||||
end
|
||||
|
||||
test "unfollow takes a user and another user" do
|
||||
followed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(followed)]})
|
||||
|
||||
{:ok, user, _activity} = User.unfollow(user, followed)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
assert user.following == []
|
||||
end
|
||||
|
||||
test "unfollow doesn't unfollow yourself" do
|
||||
user = insert(:user)
|
||||
|
||||
{:error, _} = User.unfollow(user, user)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
assert user.following == [user.ap_id]
|
||||
end
|
||||
end
|
||||
|
||||
test "test if a user is following another user" do
|
||||
|
|
@ -236,6 +289,9 @@ defmodule Pleroma.UserTest do
|
|||
password_confirmation: "test",
|
||||
email: "email@example.com"
|
||||
}
|
||||
clear_config([:instance, :autofollowed_nicknames])
|
||||
clear_config([:instance, :welcome_message])
|
||||
clear_config([:instance, :welcome_user_nickname])
|
||||
|
||||
test "it autofollows accounts that are set for it" do
|
||||
user = insert(:user)
|
||||
|
|
@ -252,8 +308,6 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
assert User.following?(registered_user, user)
|
||||
refute User.following?(registered_user, remote_user)
|
||||
|
||||
Pleroma.Config.put([:instance, :autofollowed_nicknames], [])
|
||||
end
|
||||
|
||||
test "it sends a welcome message if it is set" do
|
||||
|
|
@ -269,9 +323,6 @@ defmodule Pleroma.UserTest do
|
|||
assert registered_user.ap_id in activity.recipients
|
||||
assert Object.normalize(activity).data["content"] =~ "cool site"
|
||||
assert activity.actor == welcome_user.ap_id
|
||||
|
||||
Pleroma.Config.put([:instance, :welcome_user_nickname], nil)
|
||||
Pleroma.Config.put([:instance, :welcome_message], nil)
|
||||
end
|
||||
|
||||
test "it requires an email, name, nickname and password, bio is optional" do
|
||||
|
|
@ -337,15 +388,8 @@ defmodule Pleroma.UserTest do
|
|||
email: "email@example.com"
|
||||
}
|
||||
|
||||
setup do
|
||||
setting = Pleroma.Config.get([:instance, :account_activation_required])
|
||||
|
||||
unless setting do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
|
||||
end
|
||||
|
||||
:ok
|
||||
clear_config([:instance, :account_activation_required]) do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
end
|
||||
|
||||
test "it creates unconfirmed user" do
|
||||
|
|
@ -497,6 +541,9 @@ defmodule Pleroma.UserTest do
|
|||
avatar: %{some: "avatar"}
|
||||
}
|
||||
|
||||
clear_config([:instance, :user_bio_length])
|
||||
clear_config([:instance, :user_name_length])
|
||||
|
||||
test "it confirms validity" do
|
||||
cs = User.remote_user_creation(@valid_remote)
|
||||
assert cs.valid?
|
||||
|
|
@ -525,7 +572,10 @@ defmodule Pleroma.UserTest do
|
|||
end
|
||||
|
||||
test "it restricts some sizes" do
|
||||
[bio: 5000, name: 100]
|
||||
bio_limit = Pleroma.Config.get([:instance, :user_bio_length], 5000)
|
||||
name_limit = Pleroma.Config.get([:instance, :user_name_length], 100)
|
||||
|
||||
[bio: bio_limit, name: name_limit]
|
||||
|> Enum.each(fn {field, size} ->
|
||||
string = String.pad_leading(".", size)
|
||||
cs = User.remote_user_creation(Map.put(@valid_remote, field, string))
|
||||
|
|
@ -989,6 +1039,8 @@ defmodule Pleroma.UserTest do
|
|||
[user: user]
|
||||
end
|
||||
|
||||
clear_config([:instance, :federating])
|
||||
|
||||
test ".delete_user_activities deletes all create activities", %{user: user} do
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
|
||||
|
||||
|
|
@ -998,6 +1050,13 @@ defmodule Pleroma.UserTest do
|
|||
refute Activity.get_by_id(activity.id)
|
||||
end
|
||||
|
||||
test "it deletes deactivated user" do
|
||||
{:ok, user} = insert(:user, info: %{deactivated: true}) |> User.set_cache()
|
||||
|
||||
assert {:ok, _} = User.delete(user)
|
||||
refute User.get_by_id(user.id)
|
||||
end
|
||||
|
||||
test "it deletes a user, all follow relationships and all activities", %{user: user} do
|
||||
follower = insert(:user)
|
||||
{:ok, follower} = User.follow(follower, user)
|
||||
|
|
@ -1039,9 +1098,7 @@ defmodule Pleroma.UserTest do
|
|||
Pleroma.Web.ActivityPub.Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
config_path = [:instance, :federating]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
Pleroma.Config.put(config_path, true)
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
|
||||
{:ok, follower} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
|
||||
{:ok, _} = User.follow(follower, user)
|
||||
|
|
@ -1053,8 +1110,6 @@ defmodule Pleroma.UserTest do
|
|||
inbox: "http://mastodon.example.org/inbox"
|
||||
})
|
||||
)
|
||||
|
||||
Pleroma.Config.put(config_path, initial_setting)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1120,8 +1175,6 @@ defmodule Pleroma.UserTest do
|
|||
refute User.auth_active?(local_user)
|
||||
assert User.auth_active?(confirmed_user)
|
||||
assert User.auth_active?(remote_user)
|
||||
|
||||
Pleroma.Config.put([:instance, :account_activation_required], false)
|
||||
end
|
||||
|
||||
describe "superuser?/1" do
|
||||
|
|
@ -1166,8 +1219,6 @@ defmodule Pleroma.UserTest do
|
|||
other_user = insert(:user, local: true)
|
||||
|
||||
refute User.visible_for?(user, other_user)
|
||||
|
||||
Pleroma.Config.put([:instance, :account_activation_required], false)
|
||||
end
|
||||
|
||||
test "returns true when the account is unauthenticated and auth is not required" do
|
||||
|
|
@ -1184,8 +1235,6 @@ defmodule Pleroma.UserTest do
|
|||
other_user = insert(:user, local: true, info: %{is_admin: true})
|
||||
|
||||
assert User.visible_for?(user, other_user)
|
||||
|
||||
Pleroma.Config.put([:instance, :account_activation_required], false)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1237,6 +1286,109 @@ defmodule Pleroma.UserTest do
|
|||
assert Map.get(user_show, "followers_count") == 2
|
||||
end
|
||||
|
||||
describe "list_inactive_users_query/1" do
|
||||
defp days_ago(days) do
|
||||
NaiveDateTime.add(
|
||||
NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
|
||||
-days * 60 * 60 * 24,
|
||||
:second
|
||||
)
|
||||
end
|
||||
|
||||
test "Users are inactive by default" do
|
||||
total = 10
|
||||
|
||||
users =
|
||||
Enum.map(1..total, fn _ ->
|
||||
insert(:user, last_digest_emailed_at: days_ago(20), info: %{deactivated: false})
|
||||
end)
|
||||
|
||||
inactive_users_ids =
|
||||
Pleroma.User.list_inactive_users_query()
|
||||
|> Pleroma.Repo.all()
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
Enum.each(users, fn user ->
|
||||
assert user.id in inactive_users_ids
|
||||
end)
|
||||
end
|
||||
|
||||
test "Only includes users who has no recent activity" do
|
||||
total = 10
|
||||
|
||||
users =
|
||||
Enum.map(1..total, fn _ ->
|
||||
insert(:user, last_digest_emailed_at: days_ago(20), info: %{deactivated: false})
|
||||
end)
|
||||
|
||||
{inactive, active} = Enum.split(users, trunc(total / 2))
|
||||
|
||||
Enum.map(active, fn user ->
|
||||
to = Enum.random(users -- [user])
|
||||
|
||||
{:ok, _} =
|
||||
Pleroma.Web.TwitterAPI.TwitterAPI.create_status(user, %{
|
||||
"status" => "hey @#{to.nickname}"
|
||||
})
|
||||
end)
|
||||
|
||||
inactive_users_ids =
|
||||
Pleroma.User.list_inactive_users_query()
|
||||
|> Pleroma.Repo.all()
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
Enum.each(active, fn user ->
|
||||
refute user.id in inactive_users_ids
|
||||
end)
|
||||
|
||||
Enum.each(inactive, fn user ->
|
||||
assert user.id in inactive_users_ids
|
||||
end)
|
||||
end
|
||||
|
||||
test "Only includes users with no read notifications" do
|
||||
total = 10
|
||||
|
||||
users =
|
||||
Enum.map(1..total, fn _ ->
|
||||
insert(:user, last_digest_emailed_at: days_ago(20), info: %{deactivated: false})
|
||||
end)
|
||||
|
||||
[sender | recipients] = users
|
||||
{inactive, active} = Enum.split(recipients, trunc(total / 2))
|
||||
|
||||
Enum.each(recipients, fn to ->
|
||||
{:ok, _} =
|
||||
Pleroma.Web.TwitterAPI.TwitterAPI.create_status(sender, %{
|
||||
"status" => "hey @#{to.nickname}"
|
||||
})
|
||||
|
||||
{:ok, _} =
|
||||
Pleroma.Web.TwitterAPI.TwitterAPI.create_status(sender, %{
|
||||
"status" => "hey again @#{to.nickname}"
|
||||
})
|
||||
end)
|
||||
|
||||
Enum.each(active, fn user ->
|
||||
[n1, _n2] = Pleroma.Notification.for_user(user)
|
||||
{:ok, _} = Pleroma.Notification.read_one(user, n1.id)
|
||||
end)
|
||||
|
||||
inactive_users_ids =
|
||||
Pleroma.User.list_inactive_users_query()
|
||||
|> Pleroma.Repo.all()
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
Enum.each(active, fn user ->
|
||||
refute user.id in inactive_users_ids
|
||||
end)
|
||||
|
||||
Enum.each(inactive, fn user ->
|
||||
assert user.id in inactive_users_ids
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
describe "toggle_confirmation/1" do
|
||||
test "if user is confirmed" do
|
||||
user = insert(:user, info: %{confirmation_pending: false})
|
||||
|
|
@ -1369,4 +1521,99 @@ defmodule Pleroma.UserTest do
|
|||
assert User.is_internal_user?(user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "update_and_set_cache/1" do
|
||||
test "returns error when user is stale instead Ecto.StaleEntryError" do
|
||||
user = insert(:user)
|
||||
|
||||
changeset = Ecto.Changeset.change(user, bio: "test")
|
||||
|
||||
Repo.delete(user)
|
||||
|
||||
assert {:error, %Ecto.Changeset{errors: [id: {"is stale", [stale: true]}], valid?: false}} =
|
||||
User.update_and_set_cache(changeset)
|
||||
end
|
||||
|
||||
test "performs update cache if user updated" do
|
||||
user = insert(:user)
|
||||
assert {:ok, nil} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
|
||||
|
||||
changeset = Ecto.Changeset.change(user, bio: "test-bio")
|
||||
|
||||
assert {:ok, %User{bio: "test-bio"} = user} = User.update_and_set_cache(changeset)
|
||||
assert {:ok, user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
|
||||
assert %User{bio: "test-bio"} = User.get_cached_by_ap_id(user.ap_id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "following/followers synchronization" do
|
||||
clear_config([:instance, :external_user_synchronization])
|
||||
|
||||
test "updates the counters normally on following/getting a follow when disabled" do
|
||||
Pleroma.Config.put([:instance, :external_user_synchronization], false)
|
||||
user = insert(:user)
|
||||
|
||||
other_user =
|
||||
insert(:user,
|
||||
local: false,
|
||||
follower_address: "http://localhost:4001/users/masto_closed/followers",
|
||||
following_address: "http://localhost:4001/users/masto_closed/following",
|
||||
info: %{ap_enabled: true}
|
||||
)
|
||||
|
||||
assert User.user_info(other_user).following_count == 0
|
||||
assert User.user_info(other_user).follower_count == 0
|
||||
|
||||
{:ok, user} = Pleroma.User.follow(user, other_user)
|
||||
other_user = Pleroma.User.get_by_id(other_user.id)
|
||||
|
||||
assert User.user_info(user).following_count == 1
|
||||
assert User.user_info(other_user).follower_count == 1
|
||||
end
|
||||
|
||||
test "syncronizes the counters with the remote instance for the followed when enabled" do
|
||||
Pleroma.Config.put([:instance, :external_user_synchronization], false)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
other_user =
|
||||
insert(:user,
|
||||
local: false,
|
||||
follower_address: "http://localhost:4001/users/masto_closed/followers",
|
||||
following_address: "http://localhost:4001/users/masto_closed/following",
|
||||
info: %{ap_enabled: true}
|
||||
)
|
||||
|
||||
assert User.user_info(other_user).following_count == 0
|
||||
assert User.user_info(other_user).follower_count == 0
|
||||
|
||||
Pleroma.Config.put([:instance, :external_user_synchronization], true)
|
||||
{:ok, _user} = User.follow(user, other_user)
|
||||
other_user = User.get_by_id(other_user.id)
|
||||
|
||||
assert User.user_info(other_user).follower_count == 437
|
||||
end
|
||||
|
||||
test "syncronizes the counters with the remote instance for the follower when enabled" do
|
||||
Pleroma.Config.put([:instance, :external_user_synchronization], false)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
other_user =
|
||||
insert(:user,
|
||||
local: false,
|
||||
follower_address: "http://localhost:4001/users/masto_closed/followers",
|
||||
following_address: "http://localhost:4001/users/masto_closed/following",
|
||||
info: %{ap_enabled: true}
|
||||
)
|
||||
|
||||
assert User.user_info(other_user).following_count == 0
|
||||
assert User.user_info(other_user).follower_count == 0
|
||||
|
||||
Pleroma.Config.put([:instance, :external_user_synchronization], true)
|
||||
{:ok, other_user} = User.follow(other_user, user)
|
||||
|
||||
assert User.user_info(other_user).following_count == 152
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -16,17 +16,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
config_path = [:instance, :federating]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
Pleroma.Config.put(config_path, true)
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
clear_config_all([:instance, :federating],
|
||||
do: Pleroma.Config.put([:instance, :federating], true)
|
||||
)
|
||||
|
||||
describe "/relay" do
|
||||
clear_config([:instance, :allow_relay])
|
||||
|
||||
test "with the relay active, it returns the relay user", %{conn: conn} do
|
||||
res =
|
||||
conn
|
||||
|
|
@ -43,8 +42,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|> get(activity_pub_path(conn, :relay))
|
||||
|> json_response(404)
|
||||
|> assert
|
||||
|
||||
Pleroma.Config.put([:instance, :allow_relay], true)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -180,18 +177,65 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
|
||||
describe "/object/:uuid/likes" do
|
||||
test "it returns the like activities in a collection", %{conn: conn} do
|
||||
setup do
|
||||
like = insert(:like_activity)
|
||||
like_object_ap_id = Object.normalize(like).data["id"]
|
||||
uuid = String.split(like_object_ap_id, "/") |> List.last()
|
||||
|
||||
uuid =
|
||||
like_object_ap_id
|
||||
|> String.split("/")
|
||||
|> List.last()
|
||||
|
||||
[id: like.data["id"], uuid: uuid]
|
||||
end
|
||||
|
||||
test "it returns the like activities in a collection", %{conn: conn, id: id, uuid: uuid} do
|
||||
result =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/objects/#{uuid}/likes")
|
||||
|> json_response(200)
|
||||
|
||||
assert List.first(result["first"]["orderedItems"])["id"] == like.data["id"]
|
||||
assert List.first(result["first"]["orderedItems"])["id"] == id
|
||||
assert result["type"] == "OrderedCollection"
|
||||
assert result["totalItems"] == 1
|
||||
refute result["first"]["next"]
|
||||
end
|
||||
|
||||
test "it does not crash when page number is exceeded total pages", %{conn: conn, uuid: uuid} do
|
||||
result =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/objects/#{uuid}/likes?page=2")
|
||||
|> json_response(200)
|
||||
|
||||
assert result["type"] == "OrderedCollectionPage"
|
||||
assert result["totalItems"] == 1
|
||||
refute result["next"]
|
||||
assert Enum.empty?(result["orderedItems"])
|
||||
end
|
||||
|
||||
test "it contains the next key when likes count is more than 10", %{conn: conn} do
|
||||
note = insert(:note_activity)
|
||||
insert_list(11, :like_activity, note_activity: note)
|
||||
|
||||
uuid =
|
||||
note
|
||||
|> Object.normalize()
|
||||
|> Map.get(:data)
|
||||
|> Map.get("id")
|
||||
|> String.split("/")
|
||||
|> List.last()
|
||||
|
||||
result =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/objects/#{uuid}/likes?page=1")
|
||||
|> json_response(200)
|
||||
|
||||
assert result["totalItems"] == 11
|
||||
assert length(result["orderedItems"]) == 10
|
||||
assert result["next"]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -538,6 +538,29 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert Enum.member?(activities, activity_one)
|
||||
end
|
||||
|
||||
test "doesn't return thread muted activities" do
|
||||
user = insert(:user)
|
||||
_activity_one = insert(:note_activity)
|
||||
note_two = insert(:note, data: %{"context" => "suya.."})
|
||||
activity_two = insert(:note_activity, note: note_two)
|
||||
|
||||
{:ok, _activity_two} = CommonAPI.add_mute(user, activity_two)
|
||||
|
||||
assert [_activity_one] = ActivityPub.fetch_activities([], %{"muting_user" => user})
|
||||
end
|
||||
|
||||
test "returns thread muted activities when with_muted is set" do
|
||||
user = insert(:user)
|
||||
_activity_one = insert(:note_activity)
|
||||
note_two = insert(:note, data: %{"context" => "suya.."})
|
||||
activity_two = insert(:note_activity, note: note_two)
|
||||
|
||||
{:ok, _activity_two} = CommonAPI.add_mute(user, activity_two)
|
||||
|
||||
assert [_activity_two, _activity_one] =
|
||||
ActivityPub.fetch_activities([], %{"muting_user" => user, "with_muted" => true})
|
||||
end
|
||||
|
||||
test "does include announces on request" do
|
||||
activity_three = insert(:note_activity)
|
||||
user = insert(:user)
|
||||
|
|
@ -677,14 +700,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert object.data["likes"] == [user.ap_id]
|
||||
assert object.data["like_count"] == 1
|
||||
|
||||
[note_activity] = Activity.get_all_create_by_object_ap_id(object.data["id"])
|
||||
assert note_activity.data["object"]["like_count"] == 1
|
||||
|
||||
{:ok, _like_activity, object} = ActivityPub.like(user_two, object)
|
||||
assert object.data["like_count"] == 2
|
||||
|
||||
[note_activity] = Activity.get_all_create_by_object_ap_id(object.data["id"])
|
||||
assert note_activity.data["object"]["like_count"] == 2
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1128,4 +1145,65 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert result.id == activity.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetch_follow_information_for_user" do
|
||||
test "syncronizes following/followers counters" do
|
||||
user =
|
||||
insert(:user,
|
||||
local: false,
|
||||
follower_address: "http://localhost:4001/users/fuser2/followers",
|
||||
following_address: "http://localhost:4001/users/fuser2/following"
|
||||
)
|
||||
|
||||
{:ok, info} = ActivityPub.fetch_follow_information_for_user(user)
|
||||
assert info.follower_count == 527
|
||||
assert info.following_count == 267
|
||||
end
|
||||
|
||||
test "detects hidden followers" do
|
||||
mock(fn env ->
|
||||
case env.url do
|
||||
"http://localhost:4001/users/masto_closed/followers?page=1" ->
|
||||
%Tesla.Env{status: 403, body: ""}
|
||||
|
||||
_ ->
|
||||
apply(HttpRequestMock, :request, [env])
|
||||
end
|
||||
end)
|
||||
|
||||
user =
|
||||
insert(:user,
|
||||
local: false,
|
||||
follower_address: "http://localhost:4001/users/masto_closed/followers",
|
||||
following_address: "http://localhost:4001/users/masto_closed/following"
|
||||
)
|
||||
|
||||
{:ok, info} = ActivityPub.fetch_follow_information_for_user(user)
|
||||
assert info.hide_followers == true
|
||||
assert info.hide_follows == false
|
||||
end
|
||||
|
||||
test "detects hidden follows" do
|
||||
mock(fn env ->
|
||||
case env.url do
|
||||
"http://localhost:4001/users/masto_closed/following?page=1" ->
|
||||
%Tesla.Env{status: 403, body: ""}
|
||||
|
||||
_ ->
|
||||
apply(HttpRequestMock, :request, [env])
|
||||
end
|
||||
end)
|
||||
|
||||
user =
|
||||
insert(:user,
|
||||
local: false,
|
||||
follower_address: "http://localhost:4001/users/masto_closed/followers",
|
||||
following_address: "http://localhost:4001/users/masto_closed/following"
|
||||
)
|
||||
|
||||
{:ok, info} = ActivityPub.fetch_follow_information_for_user(user)
|
||||
assert info.hide_followers == false
|
||||
assert info.hide_follows == true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
defmodule Pleroma.Web.ActivityPub.MRFTest do
|
||||
use ExUnit.Case, async: true
|
||||
use Pleroma.Tests.Helpers
|
||||
alias Pleroma.Web.ActivityPub.MRF
|
||||
|
||||
test "subdomains_regex/1" do
|
||||
assert MRF.subdomains_regex(["unsafe.tld", "*.unsafe.tld"]) == [
|
||||
~r/^unsafe.tld$/,
|
||||
~r/^(.*\.)*unsafe.tld$/
|
||||
~r/^unsafe.tld$/i,
|
||||
~r/^(.*\.)*unsafe.tld$/i
|
||||
]
|
||||
end
|
||||
|
||||
|
|
@ -13,7 +14,7 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
test "common domains" do
|
||||
regexes = MRF.subdomains_regex(["unsafe.tld", "unsafe2.tld"])
|
||||
|
||||
assert regexes == [~r/^unsafe.tld$/, ~r/^unsafe2.tld$/]
|
||||
assert regexes == [~r/^unsafe.tld$/i, ~r/^unsafe2.tld$/i]
|
||||
|
||||
assert MRF.subdomain_match?(regexes, "unsafe.tld")
|
||||
assert MRF.subdomain_match?(regexes, "unsafe2.tld")
|
||||
|
|
@ -24,7 +25,7 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
test "wildcard domains with one subdomain" do
|
||||
regexes = MRF.subdomains_regex(["*.unsafe.tld"])
|
||||
|
||||
assert regexes == [~r/^(.*\.)*unsafe.tld$/]
|
||||
assert regexes == [~r/^(.*\.)*unsafe.tld$/i]
|
||||
|
||||
assert MRF.subdomain_match?(regexes, "unsafe.tld")
|
||||
assert MRF.subdomain_match?(regexes, "sub.unsafe.tld")
|
||||
|
|
@ -35,12 +36,51 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
test "wildcard domains with two subdomains" do
|
||||
regexes = MRF.subdomains_regex(["*.unsafe.tld"])
|
||||
|
||||
assert regexes == [~r/^(.*\.)*unsafe.tld$/]
|
||||
assert regexes == [~r/^(.*\.)*unsafe.tld$/i]
|
||||
|
||||
assert MRF.subdomain_match?(regexes, "unsafe.tld")
|
||||
assert MRF.subdomain_match?(regexes, "sub.sub.unsafe.tld")
|
||||
refute MRF.subdomain_match?(regexes, "sub.anotherunsafe.tld")
|
||||
refute MRF.subdomain_match?(regexes, "sub.unsafe.tldanother")
|
||||
end
|
||||
|
||||
test "matches are case-insensitive" do
|
||||
regexes = MRF.subdomains_regex(["UnSafe.TLD", "UnSAFE2.Tld"])
|
||||
|
||||
assert regexes == [~r/^UnSafe.TLD$/i, ~r/^UnSAFE2.Tld$/i]
|
||||
|
||||
assert MRF.subdomain_match?(regexes, "UNSAFE.TLD")
|
||||
assert MRF.subdomain_match?(regexes, "UNSAFE2.TLD")
|
||||
assert MRF.subdomain_match?(regexes, "unsafe.tld")
|
||||
assert MRF.subdomain_match?(regexes, "unsafe2.tld")
|
||||
|
||||
refute MRF.subdomain_match?(regexes, "EXAMPLE.COM")
|
||||
refute MRF.subdomain_match?(regexes, "example.com")
|
||||
end
|
||||
end
|
||||
|
||||
describe "describe/0" do
|
||||
clear_config([:instance, :rewrite_policy])
|
||||
|
||||
test "it works as expected with noop policy" do
|
||||
expected = %{
|
||||
mrf_policies: ["NoOpPolicy"],
|
||||
exclusions: false
|
||||
}
|
||||
|
||||
{:ok, ^expected} = MRF.describe()
|
||||
end
|
||||
|
||||
test "it works as expected with mock policy" do
|
||||
Pleroma.Config.put([:instance, :rewrite_policy], [MRFModuleMock])
|
||||
|
||||
expected = %{
|
||||
mrf_policies: ["MRFModuleMock"],
|
||||
mrf_module_mock: "some config data",
|
||||
exclusions: false
|
||||
}
|
||||
|
||||
{:ok, ^expected} = MRF.describe()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,12 +8,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
|
|||
|
||||
alias Pleroma.Web.ActivityPub.MRF.RejectNonPublic
|
||||
|
||||
setup do
|
||||
policy = Pleroma.Config.get([:mrf_rejectnonpublic])
|
||||
on_exit(fn -> Pleroma.Config.put([:mrf_rejectnonpublic], policy) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
clear_config([:mrf_rejectnonpublic])
|
||||
|
||||
describe "public message" do
|
||||
test "it's allowed when address is public" do
|
||||
|
|
|
|||
|
|
@ -8,9 +8,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
alias Pleroma.Config
|
||||
alias Pleroma.Web.ActivityPub.MRF.SimplePolicy
|
||||
|
||||
setup do
|
||||
orig = Config.get!(:mrf_simple)
|
||||
|
||||
clear_config([:mrf_simple]) do
|
||||
Config.put(:mrf_simple,
|
||||
media_removal: [],
|
||||
media_nsfw: [],
|
||||
|
|
@ -21,10 +19,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
avatar_removal: [],
|
||||
banner_removal: []
|
||||
)
|
||||
|
||||
on_exit(fn ->
|
||||
Config.put(:mrf_simple, orig)
|
||||
end)
|
||||
end
|
||||
|
||||
describe "when :media_removal" do
|
||||
|
|
|
|||
|
|
@ -7,12 +7,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicyTest do
|
|||
|
||||
alias Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy
|
||||
|
||||
setup do
|
||||
policy = Pleroma.Config.get([:mrf_user_allowlist]) || []
|
||||
on_exit(fn -> Pleroma.Config.put([:mrf_user_allowlist], policy) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
clear_config([:mrf_user_allowlist, :localhost])
|
||||
|
||||
test "pass filter if allow list is empty" do
|
||||
actor = insert(:user)
|
||||
|
|
|
|||
106
test/web/activity_pub/mrf/vocabulary_policy_test.exs
Normal file
106
test/web/activity_pub/mrf/vocabulary_policy_test.exs
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Web.ActivityPub.MRF.VocabularyPolicy
|
||||
|
||||
describe "accept" do
|
||||
clear_config([:mrf_vocabulary, :accept])
|
||||
|
||||
test "it accepts based on parent activity type" do
|
||||
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Like"])
|
||||
|
||||
message = %{
|
||||
"type" => "Like",
|
||||
"object" => "whatever"
|
||||
}
|
||||
|
||||
{:ok, ^message} = VocabularyPolicy.filter(message)
|
||||
end
|
||||
|
||||
test "it accepts based on child object type" do
|
||||
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
|
||||
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"type" => "Note",
|
||||
"content" => "whatever"
|
||||
}
|
||||
}
|
||||
|
||||
{:ok, ^message} = VocabularyPolicy.filter(message)
|
||||
end
|
||||
|
||||
test "it does not accept disallowed child objects" do
|
||||
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
|
||||
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"type" => "Article",
|
||||
"content" => "whatever"
|
||||
}
|
||||
}
|
||||
|
||||
{:reject, nil} = VocabularyPolicy.filter(message)
|
||||
end
|
||||
|
||||
test "it does not accept disallowed parent types" do
|
||||
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Announce", "Note"])
|
||||
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"type" => "Note",
|
||||
"content" => "whatever"
|
||||
}
|
||||
}
|
||||
|
||||
{:reject, nil} = VocabularyPolicy.filter(message)
|
||||
end
|
||||
end
|
||||
|
||||
describe "reject" do
|
||||
clear_config([:mrf_vocabulary, :reject])
|
||||
|
||||
test "it rejects based on parent activity type" do
|
||||
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
|
||||
|
||||
message = %{
|
||||
"type" => "Like",
|
||||
"object" => "whatever"
|
||||
}
|
||||
|
||||
{:reject, nil} = VocabularyPolicy.filter(message)
|
||||
end
|
||||
|
||||
test "it rejects based on child object type" do
|
||||
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Note"])
|
||||
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"type" => "Note",
|
||||
"content" => "whatever"
|
||||
}
|
||||
}
|
||||
|
||||
{:reject, nil} = VocabularyPolicy.filter(message)
|
||||
end
|
||||
|
||||
test "it passes through objects that aren't disallowed" do
|
||||
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
|
||||
|
||||
message = %{
|
||||
"type" => "Announce",
|
||||
"object" => "whatever"
|
||||
}
|
||||
|
||||
{:ok, ^message} = VocabularyPolicy.filter(message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -5,11 +5,71 @@
|
|||
defmodule Pleroma.Web.ActivityPub.RelayTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Relay
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "gets an actor for the relay" do
|
||||
user = Relay.get_actor()
|
||||
assert user.ap_id == "#{Pleroma.Web.Endpoint.url()}/relay"
|
||||
end
|
||||
|
||||
assert user.ap_id =~ "/relay"
|
||||
describe "follow/1" do
|
||||
test "returns errors when user not found" do
|
||||
assert Relay.follow("test-ap-id") == {:error, "Could not fetch by AP id"}
|
||||
end
|
||||
|
||||
test "returns activity" do
|
||||
user = insert(:user)
|
||||
service_actor = Relay.get_actor()
|
||||
assert {:ok, %Activity{} = activity} = Relay.follow(user.ap_id)
|
||||
assert activity.actor == "#{Pleroma.Web.Endpoint.url()}/relay"
|
||||
assert user.ap_id in activity.recipients
|
||||
assert activity.data["type"] == "Follow"
|
||||
assert activity.data["actor"] == service_actor.ap_id
|
||||
assert activity.data["object"] == user.ap_id
|
||||
end
|
||||
end
|
||||
|
||||
describe "unfollow/1" do
|
||||
test "returns errors when user not found" do
|
||||
assert Relay.unfollow("test-ap-id") == {:error, "Could not fetch by AP id"}
|
||||
end
|
||||
|
||||
test "returns activity" do
|
||||
user = insert(:user)
|
||||
service_actor = Relay.get_actor()
|
||||
ActivityPub.follow(service_actor, user)
|
||||
assert {:ok, %Activity{} = activity} = Relay.unfollow(user.ap_id)
|
||||
assert activity.actor == "#{Pleroma.Web.Endpoint.url()}/relay"
|
||||
assert user.ap_id in activity.recipients
|
||||
assert activity.data["type"] == "Undo"
|
||||
assert activity.data["actor"] == service_actor.ap_id
|
||||
assert activity.data["to"] == [user.ap_id]
|
||||
end
|
||||
end
|
||||
|
||||
describe "publish/1" do
|
||||
test "returns error when activity not `Create` type" do
|
||||
activity = insert(:like_activity)
|
||||
assert Relay.publish(activity) == {:error, "Not implemented"}
|
||||
end
|
||||
|
||||
test "returns error when activity not public" do
|
||||
activity = insert(:direct_note_activity)
|
||||
assert Relay.publish(activity) == {:error, false}
|
||||
end
|
||||
|
||||
test "returns announce activity" do
|
||||
service_actor = Relay.get_actor()
|
||||
note = insert(:note_activity)
|
||||
assert {:ok, %Activity{} = activity, %Object{} = obj} = Relay.publish(note)
|
||||
assert activity.data["type"] == "Announce"
|
||||
assert activity.data["actor"] == service_actor.ap_id
|
||||
assert activity.data["object"] == obj.data["id"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
clear_config([:instance, :max_remote_account_fields])
|
||||
|
||||
describe "handle_incoming" do
|
||||
test "it ignores an incoming notice if we already have it" do
|
||||
activity = insert(:note_activity)
|
||||
|
|
@ -450,6 +452,27 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert !is_nil(data["cc"])
|
||||
end
|
||||
|
||||
test "it strips internal likes" do
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|
||||
likes = %{
|
||||
"first" =>
|
||||
"http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes?page=1",
|
||||
"id" => "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes",
|
||||
"totalItems" => 3,
|
||||
"type" => "OrderedCollection"
|
||||
}
|
||||
|
||||
object = Map.put(data["object"], "likes", likes)
|
||||
data = Map.put(data, "object", object)
|
||||
|
||||
{:ok, %Activity{object: object}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
refute Map.has_key?(object.data, "likes")
|
||||
end
|
||||
|
||||
test "it works for incoming update activities" do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
|
||||
|
|
@ -488,6 +511,60 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert user.bio == "<p>Some bio</p>"
|
||||
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.Info.fields(user.info) == [
|
||||
%{"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.Info.fields(user.info) == [
|
||||
%{"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.Info.fields(user.info) == [
|
||||
%{"name" => "foo", "value" => "updated"},
|
||||
%{"name" => "foo1", "value" => "updated"}
|
||||
]
|
||||
end
|
||||
|
||||
test "it works for incoming update activities which lock the account" do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
|
||||
|
|
@ -1061,14 +1138,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert is_nil(modified["object"]["announcements"])
|
||||
assert is_nil(modified["object"]["announcement_count"])
|
||||
assert is_nil(modified["object"]["context_id"])
|
||||
end
|
||||
|
||||
test "it adds like collection to object" do
|
||||
activity = insert(:note_activity)
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
assert modified["object"]["likes"]["type"] == "OrderedCollection"
|
||||
assert modified["object"]["likes"]["totalItems"] == 0
|
||||
assert is_nil(modified["object"]["likes"])
|
||||
end
|
||||
|
||||
test "the directMessage flag is present" do
|
||||
|
|
@ -1373,32 +1443,4 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
refute recipient.follower_address in fixed_object["to"]
|
||||
end
|
||||
end
|
||||
|
||||
test "update_following_followers_counters/1" do
|
||||
user1 =
|
||||
insert(:user,
|
||||
local: false,
|
||||
follower_address: "http://localhost:4001/users/masto_closed/followers",
|
||||
following_address: "http://localhost:4001/users/masto_closed/following"
|
||||
)
|
||||
|
||||
user2 =
|
||||
insert(:user,
|
||||
local: false,
|
||||
follower_address: "http://localhost:4001/users/fuser2/followers",
|
||||
following_address: "http://localhost:4001/users/fuser2/following"
|
||||
)
|
||||
|
||||
Transmogrifier.update_following_followers_counters(user1)
|
||||
Transmogrifier.update_following_followers_counters(user2)
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user1)
|
||||
assert followers == 437
|
||||
assert following == 152
|
||||
|
||||
%{follower_count: followers, following_count: following} = User.get_cached_user_info(user2)
|
||||
|
||||
assert followers == 527
|
||||
assert following == 267
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -22,6 +22,21 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
|
||||
end
|
||||
|
||||
test "Renders profile fields" do
|
||||
fields = [
|
||||
%{"name" => "foo", "value" => "bar"}
|
||||
]
|
||||
|
||||
{:ok, user} =
|
||||
insert(:user)
|
||||
|> User.upgrade_changeset(%{info: %{fields: fields}})
|
||||
|> User.update_and_set_cache()
|
||||
|
||||
assert %{
|
||||
"attachment" => [%{"name" => "foo", "type" => "PropertyValue", "value" => "bar"}]
|
||||
} = UserView.render("user.json", %{user: user})
|
||||
end
|
||||
|
||||
test "Does not add an avatar image if the user hasn't set one" do
|
||||
user = insert(:user)
|
||||
{:ok, user} = User.ensure_keys_present(user)
|
||||
|
|
|
|||
|
|
@ -294,20 +294,17 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "POST /api/pleroma/admin/email_invite, with valid config" do
|
||||
setup do
|
||||
registrations_open = Pleroma.Config.get([:instance, :registrations_open])
|
||||
invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
|
||||
Pleroma.Config.put([:instance, :registrations_open], false)
|
||||
Pleroma.Config.put([:instance, :invites_enabled], true)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :registrations_open], registrations_open)
|
||||
Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
|
||||
:ok
|
||||
end)
|
||||
|
||||
[user: insert(:user, info: %{is_admin: true})]
|
||||
end
|
||||
|
||||
clear_config([:instance, :registrations_open]) do
|
||||
Pleroma.Config.put([:instance, :registrations_open], false)
|
||||
end
|
||||
|
||||
clear_config([:instance, :invites_enabled]) do
|
||||
Pleroma.Config.put([:instance, :invites_enabled], true)
|
||||
end
|
||||
|
||||
test "sends invitation and returns 204", %{conn: conn, user: user} do
|
||||
recipient_email = "foo@bar.com"
|
||||
recipient_name = "J. D."
|
||||
|
|
@ -360,18 +357,13 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
[user: insert(:user, info: %{is_admin: true})]
|
||||
end
|
||||
|
||||
clear_config([:instance, :registrations_open])
|
||||
clear_config([:instance, :invites_enabled])
|
||||
|
||||
test "it returns 500 if `invites_enabled` is not enabled", %{conn: conn, user: user} do
|
||||
registrations_open = Pleroma.Config.get([:instance, :registrations_open])
|
||||
invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
|
||||
Pleroma.Config.put([:instance, :registrations_open], false)
|
||||
Pleroma.Config.put([:instance, :invites_enabled], false)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :registrations_open], registrations_open)
|
||||
Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
|
||||
:ok
|
||||
end)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|
|
@ -381,17 +373,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "it returns 500 if `registrations_open` is enabled", %{conn: conn, user: user} do
|
||||
registrations_open = Pleroma.Config.get([:instance, :registrations_open])
|
||||
invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
|
||||
Pleroma.Config.put([:instance, :registrations_open], true)
|
||||
Pleroma.Config.put([:instance, :invites_enabled], true)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :registrations_open], registrations_open)
|
||||
Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
|
||||
:ok
|
||||
end)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|
|
@ -1402,17 +1386,13 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
:ok = File.rm(temp_file)
|
||||
end)
|
||||
|
||||
dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
|
||||
|
||||
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
|
||||
end)
|
||||
|
||||
%{conn: assign(conn, :user, admin)}
|
||||
end
|
||||
|
||||
clear_config([:instance, :dynamic_configuration]) do
|
||||
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
||||
end
|
||||
|
||||
test "create new config setting in db", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, "/api/pleroma/admin/config", %{
|
||||
|
|
@ -1914,6 +1894,74 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
]
|
||||
}
|
||||
end
|
||||
|
||||
test "delete part of settings by atom subkeys", %{conn: conn} do
|
||||
config =
|
||||
insert(:config,
|
||||
key: "keyaa1",
|
||||
value: :erlang.term_to_binary(subkey1: "val1", subkey2: "val2", subkey3: "val3")
|
||||
)
|
||||
|
||||
conn =
|
||||
post(conn, "/api/pleroma/admin/config", %{
|
||||
configs: [
|
||||
%{
|
||||
group: config.group,
|
||||
key: config.key,
|
||||
subkeys: [":subkey1", ":subkey3"],
|
||||
delete: "true"
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
assert(
|
||||
json_response(conn, 200) == %{
|
||||
"configs" => [
|
||||
%{
|
||||
"group" => "pleroma",
|
||||
"key" => "keyaa1",
|
||||
"value" => [%{"tuple" => [":subkey2", "val2"]}]
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "config mix tasks run" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
temp_file = "config/test.exported_from_db.secret.exs"
|
||||
|
||||
Mix.shell(Mix.Shell.Quiet)
|
||||
|
||||
on_exit(fn ->
|
||||
Mix.shell(Mix.Shell.IO)
|
||||
:ok = File.rm(temp_file)
|
||||
end)
|
||||
|
||||
%{conn: assign(conn, :user, admin), admin: admin}
|
||||
end
|
||||
|
||||
clear_config([:instance, :dynamic_configuration]) do
|
||||
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
||||
end
|
||||
|
||||
test "transfer settings to DB and to file", %{conn: conn, admin: admin} do
|
||||
assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) == []
|
||||
conn = get(conn, "/api/pleroma/admin/config/migrate_to_db")
|
||||
assert json_response(conn, 200) == %{}
|
||||
assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) > 0
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> get("/api/pleroma/admin/config/migrate_from_db")
|
||||
|
||||
assert json_response(conn, 200) == %{}
|
||||
assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/users/:nickname/statuses" do
|
||||
|
|
|
|||
|
|
@ -5,18 +5,66 @@
|
|||
defmodule Pleroma.Web.CommonAPITest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Conversation.Participation
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Visibility
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
clear_config([:instance, :safe_dm_mentions])
|
||||
clear_config([:instance, :limit])
|
||||
clear_config([:instance, :max_pinned_statuses])
|
||||
|
||||
test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
|
||||
|
||||
[participation] = Participation.for_user(user)
|
||||
|
||||
{:ok, convo_reply} =
|
||||
CommonAPI.post(user, %{"status" => ".", "in_reply_to_conversation_id" => participation.id})
|
||||
|
||||
assert Visibility.is_direct?(convo_reply)
|
||||
|
||||
assert activity.data["context"] == convo_reply.data["context"]
|
||||
end
|
||||
|
||||
test "when replying to a conversation / participation, it only mentions the recipients explicitly declared in the participation" do
|
||||
har = insert(:user)
|
||||
jafnhar = insert(:user)
|
||||
tridi = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(har, %{
|
||||
"status" => "@#{jafnhar.nickname} hey",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
assert har.ap_id in activity.recipients
|
||||
assert jafnhar.ap_id in activity.recipients
|
||||
|
||||
[participation] = Participation.for_user(har)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(har, %{
|
||||
"status" => "I don't really like @#{tridi.nickname}",
|
||||
"visibility" => "direct",
|
||||
"in_reply_to_status_id" => activity.id,
|
||||
"in_reply_to_conversation_id" => participation.id
|
||||
})
|
||||
|
||||
assert har.ap_id in activity.recipients
|
||||
assert jafnhar.ap_id in activity.recipients
|
||||
refute tridi.ap_id in activity.recipients
|
||||
end
|
||||
|
||||
test "with the safe_dm_mention option set, it does not mention people beyond the initial tags" do
|
||||
har = insert(:user)
|
||||
jafnhar = insert(:user)
|
||||
tridi = insert(:user)
|
||||
option = Pleroma.Config.get([:instance, :safe_dm_mentions])
|
||||
Pleroma.Config.put([:instance, :safe_dm_mentions], true)
|
||||
|
||||
{:ok, activity} =
|
||||
|
|
@ -27,7 +75,6 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
refute tridi.ap_id in activity.recipients
|
||||
assert jafnhar.ap_id in activity.recipients
|
||||
Pleroma.Config.put([:instance, :safe_dm_mentions], option)
|
||||
end
|
||||
|
||||
test "it de-duplicates tags" do
|
||||
|
|
@ -150,15 +197,12 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
end
|
||||
|
||||
test "it returns error when character limit is exceeded" do
|
||||
limit = Pleroma.Config.get([:instance, :limit])
|
||||
Pleroma.Config.put([:instance, :limit], 5)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
assert {:error, "The status is over the character limit"} =
|
||||
CommonAPI.post(user, %{"status" => "foobar"})
|
||||
|
||||
Pleroma.Config.put([:instance, :limit], limit)
|
||||
end
|
||||
|
||||
test "it can handle activities that expire" do
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
mentioned_user = insert(:user)
|
||||
mentions = [mentioned_user.ap_id]
|
||||
|
||||
{to, cc} = Utils.get_to_and_cc(user, mentions, nil, "public")
|
||||
{to, cc} = Utils.get_to_and_cc(user, mentions, nil, "public", nil)
|
||||
|
||||
assert length(to) == 2
|
||||
assert length(cc) == 1
|
||||
|
|
@ -256,7 +256,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
{:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
|
||||
mentions = [mentioned_user.ap_id]
|
||||
|
||||
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "public")
|
||||
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "public", nil)
|
||||
|
||||
assert length(to) == 3
|
||||
assert length(cc) == 1
|
||||
|
|
@ -272,7 +272,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
mentioned_user = insert(:user)
|
||||
mentions = [mentioned_user.ap_id]
|
||||
|
||||
{to, cc} = Utils.get_to_and_cc(user, mentions, nil, "unlisted")
|
||||
{to, cc} = Utils.get_to_and_cc(user, mentions, nil, "unlisted", nil)
|
||||
|
||||
assert length(to) == 2
|
||||
assert length(cc) == 1
|
||||
|
|
@ -289,7 +289,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
{:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
|
||||
mentions = [mentioned_user.ap_id]
|
||||
|
||||
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "unlisted")
|
||||
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "unlisted", nil)
|
||||
|
||||
assert length(to) == 3
|
||||
assert length(cc) == 1
|
||||
|
|
@ -305,8 +305,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
mentioned_user = insert(:user)
|
||||
mentions = [mentioned_user.ap_id]
|
||||
|
||||
{to, cc} = Utils.get_to_and_cc(user, mentions, nil, "private")
|
||||
|
||||
{to, cc} = Utils.get_to_and_cc(user, mentions, nil, "private", nil)
|
||||
assert length(to) == 2
|
||||
assert length(cc) == 0
|
||||
|
||||
|
|
@ -321,7 +320,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
{:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
|
||||
mentions = [mentioned_user.ap_id]
|
||||
|
||||
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "private")
|
||||
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "private", nil)
|
||||
|
||||
assert length(to) == 3
|
||||
assert length(cc) == 0
|
||||
|
|
@ -336,7 +335,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
mentioned_user = insert(:user)
|
||||
mentions = [mentioned_user.ap_id]
|
||||
|
||||
{to, cc} = Utils.get_to_and_cc(user, mentions, nil, "direct")
|
||||
{to, cc} = Utils.get_to_and_cc(user, mentions, nil, "direct", nil)
|
||||
|
||||
assert length(to) == 1
|
||||
assert length(cc) == 0
|
||||
|
|
@ -351,7 +350,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
{:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
|
||||
mentions = [mentioned_user.ap_id]
|
||||
|
||||
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "direct")
|
||||
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "direct", nil)
|
||||
|
||||
assert length(to) == 2
|
||||
assert length(cc) == 0
|
||||
|
|
@ -360,4 +359,242 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
assert third_user.ap_id in to
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_by_id_or_ap_id/1" do
|
||||
test "get activity by id" do
|
||||
activity = insert(:note_activity)
|
||||
%Pleroma.Activity{} = note = Utils.get_by_id_or_ap_id(activity.id)
|
||||
assert note.id == activity.id
|
||||
end
|
||||
|
||||
test "get activity by ap_id" do
|
||||
activity = insert(:note_activity)
|
||||
%Pleroma.Activity{} = note = Utils.get_by_id_or_ap_id(activity.data["object"])
|
||||
assert note.id == activity.id
|
||||
end
|
||||
|
||||
test "get activity by object when type isn't `Create` " do
|
||||
activity = insert(:like_activity)
|
||||
%Pleroma.Activity{} = like = Utils.get_by_id_or_ap_id(activity.id)
|
||||
assert like.data["object"] == activity.data["object"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "to_master_date/1" do
|
||||
test "removes microseconds from date (NaiveDateTime)" do
|
||||
assert Utils.to_masto_date(~N[2015-01-23 23:50:07.123]) == "2015-01-23T23:50:07.000Z"
|
||||
end
|
||||
|
||||
test "removes microseconds from date (String)" do
|
||||
assert Utils.to_masto_date("2015-01-23T23:50:07.123Z") == "2015-01-23T23:50:07.000Z"
|
||||
end
|
||||
|
||||
test "returns empty string when date invalid" do
|
||||
assert Utils.to_masto_date("2015-01?23T23:50:07.123Z") == ""
|
||||
end
|
||||
end
|
||||
|
||||
describe "conversation_id_to_context/1" do
|
||||
test "returns id" do
|
||||
object = insert(:note)
|
||||
assert Utils.conversation_id_to_context(object.id) == object.data["id"]
|
||||
end
|
||||
|
||||
test "returns error if object not found" do
|
||||
assert Utils.conversation_id_to_context("123") == {:error, "No such conversation"}
|
||||
end
|
||||
end
|
||||
|
||||
describe "maybe_notify_mentioned_recipients/2" do
|
||||
test "returns recipients when activity is not `Create`" do
|
||||
activity = insert(:like_activity)
|
||||
assert Utils.maybe_notify_mentioned_recipients(["test"], activity) == ["test"]
|
||||
end
|
||||
|
||||
test "returns recipients from tag" do
|
||||
user = insert(:user)
|
||||
|
||||
object =
|
||||
insert(:note,
|
||||
user: user,
|
||||
data: %{
|
||||
"tag" => [
|
||||
%{"type" => "Hashtag"},
|
||||
"",
|
||||
%{"type" => "Mention", "href" => "https://testing.pleroma.lol/users/lain"},
|
||||
%{"type" => "Mention", "href" => "https://shitposter.club/user/5381"},
|
||||
%{"type" => "Mention", "href" => "https://shitposter.club/user/5381"}
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
activity = insert(:note_activity, user: user, note: object)
|
||||
|
||||
assert Utils.maybe_notify_mentioned_recipients(["test"], activity) == [
|
||||
"test",
|
||||
"https://testing.pleroma.lol/users/lain",
|
||||
"https://shitposter.club/user/5381"
|
||||
]
|
||||
end
|
||||
|
||||
test "returns recipients when object is map" do
|
||||
user = insert(:user)
|
||||
object = insert(:note, user: user)
|
||||
|
||||
activity =
|
||||
insert(:note_activity,
|
||||
user: user,
|
||||
note: object,
|
||||
data_attrs: %{
|
||||
"object" => %{
|
||||
"tag" => [
|
||||
%{"type" => "Hashtag"},
|
||||
"",
|
||||
%{"type" => "Mention", "href" => "https://testing.pleroma.lol/users/lain"},
|
||||
%{"type" => "Mention", "href" => "https://shitposter.club/user/5381"},
|
||||
%{"type" => "Mention", "href" => "https://shitposter.club/user/5381"}
|
||||
]
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Pleroma.Repo.delete(object)
|
||||
|
||||
assert Utils.maybe_notify_mentioned_recipients(["test"], activity) == [
|
||||
"test",
|
||||
"https://testing.pleroma.lol/users/lain",
|
||||
"https://shitposter.club/user/5381"
|
||||
]
|
||||
end
|
||||
|
||||
test "returns recipients when object not found" do
|
||||
user = insert(:user)
|
||||
object = insert(:note, user: user)
|
||||
|
||||
activity = insert(:note_activity, user: user, note: object)
|
||||
Pleroma.Repo.delete(object)
|
||||
|
||||
assert Utils.maybe_notify_mentioned_recipients(["test-test"], activity) == [
|
||||
"test-test"
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
describe "attachments_from_ids_descs/2" do
|
||||
test "returns [] when attachment ids is empty" do
|
||||
assert Utils.attachments_from_ids_descs([], "{}") == []
|
||||
end
|
||||
|
||||
test "returns list attachments with desc" do
|
||||
object = insert(:note)
|
||||
desc = Jason.encode!(%{object.id => "test-desc"})
|
||||
|
||||
assert Utils.attachments_from_ids_descs(["#{object.id}", "34"], desc) == [
|
||||
Map.merge(object.data, %{"name" => "test-desc"})
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
describe "attachments_from_ids/1" do
|
||||
test "returns attachments with descs" do
|
||||
object = insert(:note)
|
||||
desc = Jason.encode!(%{object.id => "test-desc"})
|
||||
|
||||
assert Utils.attachments_from_ids(%{
|
||||
"media_ids" => ["#{object.id}"],
|
||||
"descriptions" => desc
|
||||
}) == [
|
||||
Map.merge(object.data, %{"name" => "test-desc"})
|
||||
]
|
||||
end
|
||||
|
||||
test "returns attachments without descs" do
|
||||
object = insert(:note)
|
||||
assert Utils.attachments_from_ids(%{"media_ids" => ["#{object.id}"]}) == [object.data]
|
||||
end
|
||||
|
||||
test "returns [] when not pass media_ids" do
|
||||
assert Utils.attachments_from_ids(%{}) == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "maybe_add_list_data/3" do
|
||||
test "adds list params when found user list" do
|
||||
user = insert(:user)
|
||||
{:ok, %Pleroma.List{} = list} = Pleroma.List.create("title", user)
|
||||
|
||||
assert Utils.maybe_add_list_data(%{additional: %{}, object: %{}}, user, {:list, list.id}) ==
|
||||
%{
|
||||
additional: %{"bcc" => [list.ap_id], "listMessage" => list.ap_id},
|
||||
object: %{"listMessage" => list.ap_id}
|
||||
}
|
||||
end
|
||||
|
||||
test "returns original params when list not found" do
|
||||
user = insert(:user)
|
||||
{:ok, %Pleroma.List{} = list} = Pleroma.List.create("title", insert(:user))
|
||||
|
||||
assert Utils.maybe_add_list_data(%{additional: %{}, object: %{}}, user, {:list, list.id}) ==
|
||||
%{additional: %{}, object: %{}}
|
||||
end
|
||||
end
|
||||
|
||||
describe "make_note_data/11" do
|
||||
test "returns note data" do
|
||||
user = insert(:user)
|
||||
note = insert(:note)
|
||||
user2 = insert(:user)
|
||||
user3 = insert(:user)
|
||||
|
||||
assert Utils.make_note_data(
|
||||
user.ap_id,
|
||||
[user2.ap_id],
|
||||
"2hu",
|
||||
"<h1>This is :moominmamma: note</h1>",
|
||||
[],
|
||||
note.id,
|
||||
[name: "jimm"],
|
||||
"test summary",
|
||||
[user3.ap_id],
|
||||
false,
|
||||
%{"custom_tag" => "test"}
|
||||
) == %{
|
||||
"actor" => user.ap_id,
|
||||
"attachment" => [],
|
||||
"cc" => [user3.ap_id],
|
||||
"content" => "<h1>This is :moominmamma: note</h1>",
|
||||
"context" => "2hu",
|
||||
"sensitive" => false,
|
||||
"summary" => "test summary",
|
||||
"tag" => ["jimm"],
|
||||
"to" => [user2.ap_id],
|
||||
"type" => "Note",
|
||||
"custom_tag" => "test"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe "maybe_add_attachments/3" do
|
||||
test "returns parsed results when no_links is true" do
|
||||
assert Utils.maybe_add_attachments(
|
||||
{"test", [], ["tags"]},
|
||||
[],
|
||||
true
|
||||
) == {"test", [], ["tags"]}
|
||||
end
|
||||
|
||||
test "adds attachments to parsed results" do
|
||||
attachment = %{"url" => [%{"href" => "SakuraPM.png"}]}
|
||||
|
||||
assert Utils.maybe_add_attachments(
|
||||
{"test", [], ["tags"]},
|
||||
[attachment],
|
||||
false
|
||||
) == {
|
||||
"test<br><a href=\"SakuraPM.png\" class='attachment'>SakuraPM.png</a>",
|
||||
[],
|
||||
["tags"]
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
31
test/web/digest_email_worker_test.exs
Normal file
31
test/web/digest_email_worker_test.exs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.DigestEmailWorkerTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.DigestEmailWorker
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
test "it sends digest emails" do
|
||||
user = insert(:user)
|
||||
|
||||
date =
|
||||
Timex.now()
|
||||
|> Timex.shift(days: -10)
|
||||
|> Timex.to_naive_datetime()
|
||||
|
||||
user2 = insert(:user, last_digest_emailed_at: date)
|
||||
User.switch_email_notifications(user2, "digest", true)
|
||||
CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}!"})
|
||||
|
||||
DigestEmailWorker.perform()
|
||||
|
||||
assert_received {:email, email}
|
||||
assert email.to == [{user2.name, user2.email}]
|
||||
assert email.subject == "Your digest from #{Pleroma.Config.get(:instance)[:name]}"
|
||||
end
|
||||
end
|
||||
|
|
@ -30,6 +30,10 @@ defmodule Pleroma.Web.FallbackTest do
|
|||
|> json_response(404) == %{"error" => "Not implemented"}
|
||||
end
|
||||
|
||||
test "GET /pleroma/admin -> /pleroma/admin/", %{conn: conn} do
|
||||
assert redirected_to(get(conn, "/pleroma/admin")) =~ "/pleroma/admin/"
|
||||
end
|
||||
|
||||
test "GET /*path", %{conn: conn} do
|
||||
assert conn
|
||||
|> get("/foo")
|
||||
|
|
|
|||
|
|
@ -13,15 +13,17 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
config_path = [:instance, :federating]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
Pleroma.Config.put(config_path, true)
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
clear_config_all([:instance, :federating]) do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
end
|
||||
|
||||
clear_config([:instance, :allow_relay])
|
||||
clear_config([:instance, :rewrite_policy])
|
||||
clear_config([:mrf_keyword])
|
||||
|
||||
describe "Publisher.perform" do
|
||||
test "call `perform` with unknown task" do
|
||||
assert {
|
||||
|
|
@ -67,8 +69,6 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
end
|
||||
|
||||
refute_received :relay_publish
|
||||
|
||||
Pleroma.Config.put([:instance, :allow_relay], true)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -229,5 +229,20 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
|
||||
:error = Federator.incoming_ap_doc(params)
|
||||
end
|
||||
|
||||
test "it does not crash if MRF rejects the post" do
|
||||
Pleroma.Config.put([:mrf_keyword, :reject], ["lain"])
|
||||
|
||||
Pleroma.Config.put(
|
||||
[:instance, :rewrite_policy],
|
||||
Pleroma.Web.ActivityPub.MRF.KeywordPolicy
|
||||
)
|
||||
|
||||
params =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|
||||
assert Federator.incoming_ap_doc(params) == :error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,14 +10,8 @@ defmodule Pleroma.Instances.InstanceTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup_all do
|
||||
config_path = [:instance, :federation_reachability_timeout_days]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
Pleroma.Config.put(config_path, 1)
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
|
||||
:ok
|
||||
clear_config_all([:instance, :federation_reachability_timeout_days]) do
|
||||
Pleroma.Config.put([:instance, :federation_reachability_timeout_days], 1)
|
||||
end
|
||||
|
||||
describe "set_reachable/1" do
|
||||
|
|
|
|||
|
|
@ -7,14 +7,8 @@ defmodule Pleroma.InstancesTest do
|
|||
|
||||
use Pleroma.DataCase
|
||||
|
||||
setup_all do
|
||||
config_path = [:instance, :federation_reachability_timeout_days]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
Pleroma.Config.put(config_path, 1)
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
|
||||
:ok
|
||||
clear_config_all([:instance, :federation_reachability_timeout_days]) do
|
||||
Pleroma.Config.put([:instance, :federation_reachability_timeout_days], 1)
|
||||
end
|
||||
|
||||
describe "reachable?/1" do
|
||||
|
|
|
|||
|
|
@ -67,7 +67,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
source: %{
|
||||
note: "valid html",
|
||||
sensitive: false,
|
||||
pleroma: %{}
|
||||
pleroma: %{},
|
||||
fields: []
|
||||
},
|
||||
pleroma: %{
|
||||
background_image: "https://example.com/images/asuka_hospital.png",
|
||||
|
|
@ -134,7 +135,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
source: %{
|
||||
note: user.bio,
|
||||
sensitive: false,
|
||||
pleroma: %{}
|
||||
pleroma: %{},
|
||||
fields: []
|
||||
},
|
||||
pleroma: %{
|
||||
background_image: nil,
|
||||
|
|
@ -231,6 +233,16 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
AccountView.render("relationship.json", %{user: user, target: other_user})
|
||||
end
|
||||
|
||||
test "represent a relationship for the user blocking a domain" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, ap_id: "https://bad.site/users/other_user")
|
||||
|
||||
{:ok, user} = User.block_domain(user, "bad.site")
|
||||
|
||||
assert %{domain_blocking: true, blocking: false} =
|
||||
AccountView.render("relationship.json", %{user: user, target: other_user})
|
||||
end
|
||||
|
||||
test "represent a relationship for the user with a pending follow request" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, %{info: %User.Info{locked: true}})
|
||||
|
|
@ -294,7 +306,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
source: %{
|
||||
note: user.bio,
|
||||
sensitive: false,
|
||||
pleroma: %{}
|
||||
pleroma: %{},
|
||||
fields: []
|
||||
},
|
||||
pleroma: %{
|
||||
background_image: nil,
|
||||
|
|
@ -346,4 +359,31 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
result = AccountView.render("account.json", %{user: user})
|
||||
refute result.display_name == "<marquee> username </marquee>"
|
||||
end
|
||||
|
||||
describe "hiding follows/following" do
|
||||
test "shows when follows/following are hidden and sets follower/following count to 0" do
|
||||
user = insert(:user, info: %{hide_followers: true, hide_follows: true})
|
||||
other_user = insert(:user)
|
||||
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
|
||||
assert %{
|
||||
followers_count: 0,
|
||||
following_count: 0,
|
||||
pleroma: %{hide_follows: true, hide_followers: true}
|
||||
} = AccountView.render("account.json", %{user: user})
|
||||
end
|
||||
|
||||
test "shows actual follower/following count to the account owner" do
|
||||
user = insert(:user, info: %{hide_followers: true, hide_follows: true})
|
||||
other_user = insert(:user)
|
||||
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
|
||||
assert %{
|
||||
followers_count: 1,
|
||||
following_count: 1
|
||||
} = AccountView.render("account.json", %{user: user, for: user})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
34
test/web/mastodon_api/conversation_view_test.exs
Normal file
34
test/web/mastodon_api/conversation_view_test.exs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Conversation.Participation
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.MastodonAPI.ConversationView
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "represents a Mastodon Conversation entity" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}", "visibility" => "direct"})
|
||||
|
||||
[participation] = Participation.for_user_with_last_activity_id(user)
|
||||
|
||||
assert participation
|
||||
|
||||
conversation =
|
||||
ConversationView.render("participation.json", %{participation: participation, for: user})
|
||||
|
||||
assert conversation.id == participation.id |> to_string()
|
||||
assert conversation.last_status.id == activity.id
|
||||
|
||||
assert [account] = conversation.accounts
|
||||
assert account.id == other_user.id
|
||||
end
|
||||
end
|
||||
|
|
@ -9,6 +9,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Pleroma.Factory
|
||||
clear_config([:instance, :max_account_fields])
|
||||
|
||||
describe "updating credentials" do
|
||||
test "sets user settings in a generic way", %{conn: conn} do
|
||||
|
|
@ -300,5 +301,69 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert user["display_name"] == name
|
||||
assert [%{"shortcode" => "blank"}, %{"shortcode" => "firefox"}] = user["emojis"]
|
||||
end
|
||||
|
||||
test "update fields", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
fields = [
|
||||
%{"name" => "<a href=\"http://google.com\">foo</a>", "value" => "<script>bar</script>"},
|
||||
%{"name" => "link", "value" => "cofe.io"}
|
||||
]
|
||||
|
||||
account =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
|
||||
|> json_response(200)
|
||||
|
||||
assert account["fields"] == [
|
||||
%{"name" => "foo", "value" => "bar"},
|
||||
%{"name" => "link", "value" => "<a href=\"http://cofe.io\">cofe.io</a>"}
|
||||
]
|
||||
|
||||
assert account["source"]["fields"] == [
|
||||
%{
|
||||
"name" => "<a href=\"http://google.com\">foo</a>",
|
||||
"value" => "<script>bar</script>"
|
||||
},
|
||||
%{"name" => "link", "value" => "cofe.io"}
|
||||
]
|
||||
|
||||
name_limit = Pleroma.Config.get([:instance, :account_field_name_length])
|
||||
value_limit = Pleroma.Config.get([:instance, :account_field_value_length])
|
||||
|
||||
long_value = Enum.map(0..value_limit, fn _ -> "x" end) |> Enum.join()
|
||||
|
||||
fields = [%{"name" => "<b>foo<b>", "value" => long_value}]
|
||||
|
||||
assert %{"error" => "Invalid request"} ==
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
|
||||
|> json_response(403)
|
||||
|
||||
long_name = Enum.map(0..name_limit, fn _ -> "x" end) |> Enum.join()
|
||||
|
||||
fields = [%{"name" => long_name, "value" => "bar"}]
|
||||
|
||||
assert %{"error" => "Invalid request"} ==
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
|
||||
|> json_response(403)
|
||||
|
||||
Pleroma.Config.put([:instance, :max_account_fields], 1)
|
||||
|
||||
fields = [
|
||||
%{"name" => "<b>foo<b>", "value" => "<i>bar</i>"},
|
||||
%{"name" => "link", "value" => "cofe.io"}
|
||||
]
|
||||
|
||||
assert %{"error" => "Invalid request"} ==
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
alias Ecto.Changeset
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.ActivityExpiration
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
|
|
@ -33,6 +34,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
clear_config([:instance, :public])
|
||||
clear_config([:rich_media, :enabled])
|
||||
|
||||
test "the home timeline", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
following = insert(:user)
|
||||
|
|
@ -86,12 +90,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
end
|
||||
|
||||
test "the public timeline when public is set to false", %{conn: conn} do
|
||||
public = Pleroma.Config.get([:instance, :public])
|
||||
Pleroma.Config.put([:instance, :public], false)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :public], public)
|
||||
end)
|
||||
Config.put([:instance, :public], false)
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/public", %{"local" => "False"})
|
||||
|
|
@ -274,7 +273,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
end
|
||||
|
||||
test "posting a status with OGP link preview", %{conn: conn} do
|
||||
Pleroma.Config.put([:rich_media, :enabled], true)
|
||||
Config.put([:rich_media, :enabled], true)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -284,7 +283,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
assert %{"id" => id, "card" => %{"title" => "The Rock"}} = json_response(conn, 200)
|
||||
assert Activity.get_by_id(id)
|
||||
Pleroma.Config.put([:rich_media, :enabled], false)
|
||||
end
|
||||
|
||||
test "posting a direct status", %{conn: conn} do
|
||||
|
|
@ -328,7 +326,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
test "option limit is enforced", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
limit = Pleroma.Config.get([:instance, :poll_limits, :max_options])
|
||||
limit = Config.get([:instance, :poll_limits, :max_options])
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -344,7 +342,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
test "option character limit is enforced", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
limit = Pleroma.Config.get([:instance, :poll_limits, :max_option_chars])
|
||||
limit = Config.get([:instance, :poll_limits, :max_option_chars])
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -363,7 +361,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
test "minimal date limit is enforced", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
limit = Pleroma.Config.get([:instance, :poll_limits, :min_expiration])
|
||||
limit = Config.get([:instance, :poll_limits, :min_expiration])
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -382,7 +380,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
test "maximum date limit is enforced", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
limit = Pleroma.Config.get([:instance, :poll_limits, :max_expiration])
|
||||
limit = Config.get([:instance, :poll_limits, :max_expiration])
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -1657,14 +1655,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
describe "media upload" do
|
||||
setup do
|
||||
upload_config = Pleroma.Config.get([Pleroma.Upload])
|
||||
proxy_config = Pleroma.Config.get([:media_proxy])
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([Pleroma.Upload], upload_config)
|
||||
Pleroma.Config.put([:media_proxy], proxy_config)
|
||||
end)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
|
|
@ -1680,6 +1670,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
[conn: conn, image: image]
|
||||
end
|
||||
|
||||
clear_config([:media_proxy])
|
||||
clear_config([Pleroma.Upload])
|
||||
|
||||
test "returns uploaded image", %{conn: conn, image: image} do
|
||||
desc = "Description of the image"
|
||||
|
||||
|
|
@ -1695,40 +1688,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
object = Repo.get(Object, media["id"])
|
||||
assert object.data["actor"] == User.ap_id(conn.assigns[:user])
|
||||
end
|
||||
|
||||
test "returns proxied url when media proxy is enabled", %{conn: conn, image: image} do
|
||||
Pleroma.Config.put([Pleroma.Upload, :base_url], "https://media.pleroma.social")
|
||||
|
||||
proxy_url = "https://cache.pleroma.social"
|
||||
Pleroma.Config.put([:media_proxy, :enabled], true)
|
||||
Pleroma.Config.put([:media_proxy, :base_url], proxy_url)
|
||||
|
||||
media =
|
||||
conn
|
||||
|> post("/api/v1/media", %{"file" => image})
|
||||
|> json_response(:ok)
|
||||
|
||||
assert String.starts_with?(media["url"], proxy_url)
|
||||
end
|
||||
|
||||
test "returns media url when proxy is enabled but media url is whitelisted", %{
|
||||
conn: conn,
|
||||
image: image
|
||||
} do
|
||||
media_url = "https://media.pleroma.social"
|
||||
Pleroma.Config.put([Pleroma.Upload, :base_url], media_url)
|
||||
|
||||
Pleroma.Config.put([:media_proxy, :enabled], true)
|
||||
Pleroma.Config.put([:media_proxy, :base_url], "https://cache.pleroma.social")
|
||||
Pleroma.Config.put([:media_proxy, :whitelist], ["media.pleroma.social"])
|
||||
|
||||
media =
|
||||
conn
|
||||
|> post("/api/v1/media", %{"file" => image})
|
||||
|> json_response(:ok)
|
||||
|
||||
assert String.starts_with?(media["url"], media_url)
|
||||
end
|
||||
end
|
||||
|
||||
describe "locked accounts" do
|
||||
|
|
@ -2639,7 +2598,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
conn = get(conn, "/api/v1/instance")
|
||||
assert result = json_response(conn, 200)
|
||||
|
||||
email = Pleroma.Config.get([:instance, :email])
|
||||
email = Config.get([:instance, :email])
|
||||
# Note: not checking for "max_toot_chars" since it's optional
|
||||
assert %{
|
||||
"uri" => _,
|
||||
|
|
@ -2681,7 +2640,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> Changeset.put_embed(:info, info_change)
|
||||
|> User.update_and_set_cache()
|
||||
|
||||
Pleroma.Stats.update_stats()
|
||||
Pleroma.Stats.force_update()
|
||||
|
||||
conn = get(conn, "/api/v1/instance")
|
||||
|
||||
|
|
@ -2699,7 +2658,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
insert(:user, %{local: false, nickname: "u@peer1.com"})
|
||||
insert(:user, %{local: false, nickname: "u@peer2.com"})
|
||||
|
||||
Pleroma.Stats.update_stats()
|
||||
Pleroma.Stats.force_update()
|
||||
|
||||
conn = get(conn, "/api/v1/instance/peers")
|
||||
|
||||
|
|
@ -2724,14 +2683,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
describe "pinned statuses" do
|
||||
setup do
|
||||
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
||||
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
||||
|
||||
[user: user, activity: activity]
|
||||
end
|
||||
|
||||
clear_config([:instance, :max_pinned_statuses]) do
|
||||
Config.put([:instance, :max_pinned_statuses], 1)
|
||||
end
|
||||
|
||||
test "returns pinned statuses", %{conn: conn, user: user, activity: activity} do
|
||||
{:ok, _} = CommonAPI.pin(activity.id, user)
|
||||
|
||||
|
|
@ -2824,11 +2785,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
describe "cards" do
|
||||
setup do
|
||||
Pleroma.Config.put([:rich_media, :enabled], true)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:rich_media, :enabled], false)
|
||||
end)
|
||||
Config.put([:rich_media, :enabled], true)
|
||||
|
||||
user = insert(:user)
|
||||
%{user: user}
|
||||
|
|
@ -2959,8 +2916,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
describe "conversation muting" do
|
||||
setup do
|
||||
post_user = insert(:user)
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "HIE"})
|
||||
|
||||
{:ok, activity} = CommonAPI.post(post_user, %{"status" => "HIE"})
|
||||
|
||||
[user: user, activity: activity]
|
||||
end
|
||||
|
|
@ -3053,7 +3012,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
reporter: reporter,
|
||||
target_user: target_user
|
||||
} do
|
||||
max_size = Pleroma.Config.get([:instance, :max_report_comment_size], 1000)
|
||||
max_size = Config.get([:instance, :max_report_comment_size], 1000)
|
||||
comment = String.pad_trailing("a", max_size + 1, "a")
|
||||
|
||||
error = %{"error" => "Comment must be up to #{max_size} characters"}
|
||||
|
|
@ -3178,6 +3137,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
assert redirected_to(conn) == "/web/login"
|
||||
end
|
||||
|
||||
test "redirects not logged-in users to the login page on private instances", %{
|
||||
conn: conn,
|
||||
path: path
|
||||
} do
|
||||
Config.put([:instance, :public], false)
|
||||
|
||||
conn = get(conn, path)
|
||||
|
||||
assert conn.status == 302
|
||||
assert redirected_to(conn) == "/web/login"
|
||||
end
|
||||
|
||||
test "does not redirect logged in users to the login page", %{conn: conn, path: path} do
|
||||
token = insert(:oauth_token)
|
||||
|
||||
|
|
@ -3917,8 +3888,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
|
||||
|
||||
email = Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
|
||||
notify_email = Pleroma.Config.get([:instance, :notify_email])
|
||||
instance_name = Pleroma.Config.get([:instance, :name])
|
||||
notify_email = Config.get([:instance, :notify_email])
|
||||
instance_name = Config.get([:instance, :name])
|
||||
|
||||
assert_email_sent(
|
||||
from: {instance_name, notify_email},
|
||||
|
|
@ -3947,4 +3918,121 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
assert conn.resp_body == ""
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/v1/pleroma/accounts/confirmation_resend" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true)
|
||||
|
||||
{:ok, user} =
|
||||
user
|
||||
|> Changeset.change()
|
||||
|> Changeset.put_embed(:info, info_change)
|
||||
|> Repo.update()
|
||||
|
||||
assert user.info.confirmation_pending
|
||||
|
||||
[user: user]
|
||||
end
|
||||
|
||||
clear_config([:instance, :account_activation_required]) do
|
||||
Config.put([:instance, :account_activation_required], true)
|
||||
end
|
||||
|
||||
test "resend account confirmation email", %{conn: conn, user: user} do
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/pleroma/accounts/confirmation_resend?email=#{user.email}")
|
||||
|> json_response(:no_content)
|
||||
|
||||
email = Pleroma.Emails.UserEmail.account_confirmation_email(user)
|
||||
notify_email = Config.get([:instance, :notify_email])
|
||||
instance_name = Config.get([:instance, :name])
|
||||
|
||||
assert_email_sent(
|
||||
from: {instance_name, notify_email},
|
||||
to: {user.name, user.email},
|
||||
html_body: email.html_body
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/v1/suggestions" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
host = Config.get([Pleroma.Web.Endpoint, :url, :host])
|
||||
url500 = "http://test500?#{host}&#{user.nickname}"
|
||||
url200 = "http://test200?#{host}&#{user.nickname}"
|
||||
|
||||
mock(fn
|
||||
%{method: :get, url: ^url500} ->
|
||||
%Tesla.Env{status: 500, body: "bad request"}
|
||||
|
||||
%{method: :get, url: ^url200} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
~s([{"acct":"yj455","avatar":"https://social.heldscal.la/avatar/201.jpeg","avatar_static":"https://social.heldscal.la/avatar/s/201.jpeg"}, {"acct":"#{
|
||||
other_user.ap_id
|
||||
}","avatar":"https://social.heldscal.la/avatar/202.jpeg","avatar_static":"https://social.heldscal.la/avatar/s/202.jpeg"}])
|
||||
}
|
||||
end)
|
||||
|
||||
[user: user, other_user: other_user]
|
||||
end
|
||||
|
||||
clear_config(:suggestions)
|
||||
|
||||
test "returns empty result when suggestions disabled", %{conn: conn, user: user} do
|
||||
Config.put([:suggestions, :enabled], false)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/suggestions")
|
||||
|> json_response(200)
|
||||
|
||||
assert res == []
|
||||
end
|
||||
|
||||
test "returns error", %{conn: conn, user: user} do
|
||||
Config.put([:suggestions, :enabled], true)
|
||||
Config.put([:suggestions, :third_party_engine], "http://test500?{{host}}&{{user}}")
|
||||
|
||||
res =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/suggestions")
|
||||
|> json_response(500)
|
||||
|
||||
assert res == "Something went wrong"
|
||||
end
|
||||
|
||||
test "returns suggestions", %{conn: conn, user: user, other_user: other_user} do
|
||||
Config.put([:suggestions, :enabled], true)
|
||||
Config.put([:suggestions, :third_party_engine], "http://test200?{{host}}&{{user}}")
|
||||
|
||||
res =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/suggestions")
|
||||
|> json_response(200)
|
||||
|
||||
assert res == [
|
||||
%{
|
||||
"acct" => "yj455",
|
||||
"avatar" => "https://social.heldscal.la/avatar/201.jpeg",
|
||||
"avatar_static" => "https://social.heldscal.la/avatar/s/201.jpeg",
|
||||
"id" => 0
|
||||
},
|
||||
%{
|
||||
"acct" => other_user.ap_id,
|
||||
"avatar" => "https://social.heldscal.la/avatar/202.jpeg",
|
||||
"avatar_static" => "https://social.heldscal.la/avatar/s/202.jpeg",
|
||||
"id" => other_user.id
|
||||
}
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
103
test/web/mastodon_api/mastodon_api_test.exs
Normal file
103
test/web/mastodon_api/mastodon_api_test.exs
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.ScheduledActivity
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.MastodonAPI.MastodonAPI
|
||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "follow/3" do
|
||||
test "returns error when user deactivated" do
|
||||
follower = insert(:user)
|
||||
user = insert(:user, local: true, info: %{deactivated: true})
|
||||
{:error, error} = MastodonAPI.follow(follower, user)
|
||||
assert error == "Could not follow user: You are deactivated."
|
||||
end
|
||||
|
||||
test "following for user" do
|
||||
follower = insert(:user)
|
||||
user = insert(:user)
|
||||
{:ok, follower} = MastodonAPI.follow(follower, user)
|
||||
assert User.following?(follower, user)
|
||||
end
|
||||
|
||||
test "returns ok if user already followed" do
|
||||
follower = insert(:user)
|
||||
user = insert(:user)
|
||||
{:ok, follower} = User.follow(follower, user)
|
||||
{:ok, follower} = MastodonAPI.follow(follower, refresh_record(user))
|
||||
assert User.following?(follower, user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_followers/2" do
|
||||
test "returns user followers" do
|
||||
follower1_user = insert(:user)
|
||||
follower2_user = insert(:user)
|
||||
user = insert(:user)
|
||||
{:ok, _follower1_user} = User.follow(follower1_user, user)
|
||||
{:ok, follower2_user} = User.follow(follower2_user, user)
|
||||
|
||||
assert MastodonAPI.get_followers(user, %{"limit" => 1}) == [follower2_user]
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_friends/2" do
|
||||
test "returns user friends" do
|
||||
user = insert(:user)
|
||||
followed_one = insert(:user)
|
||||
followed_two = insert(:user)
|
||||
followed_three = insert(:user)
|
||||
|
||||
{:ok, user} = User.follow(user, followed_one)
|
||||
{:ok, user} = User.follow(user, followed_two)
|
||||
{:ok, user} = User.follow(user, followed_three)
|
||||
res = MastodonAPI.get_friends(user)
|
||||
|
||||
assert length(res) == 3
|
||||
assert Enum.member?(res, refresh_record(followed_three))
|
||||
assert Enum.member?(res, refresh_record(followed_two))
|
||||
assert Enum.member?(res, refresh_record(followed_one))
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_notifications/2" do
|
||||
test "returns notifications for user" do
|
||||
user = insert(:user)
|
||||
subscriber = insert(:user)
|
||||
|
||||
User.subscribe(subscriber, user)
|
||||
|
||||
{:ok, status} = TwitterAPI.create_status(user, %{"status" => "Akariiiin"})
|
||||
{:ok, status1} = TwitterAPI.create_status(user, %{"status" => "Magi"})
|
||||
{:ok, [notification]} = Notification.create_notifications(status)
|
||||
{:ok, [notification1]} = Notification.create_notifications(status1)
|
||||
res = MastodonAPI.get_notifications(subscriber)
|
||||
|
||||
assert Enum.member?(Enum.map(res, & &1.id), notification.id)
|
||||
assert Enum.member?(Enum.map(res, & &1.id), notification1.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_scheduled_activities/2" do
|
||||
test "returns user scheduled activities" do
|
||||
user = insert(:user)
|
||||
|
||||
today =
|
||||
NaiveDateTime.utc_now()
|
||||
|> NaiveDateTime.add(:timer.minutes(6), :millisecond)
|
||||
|> NaiveDateTime.to_iso8601()
|
||||
|
||||
attrs = %{params: %{}, scheduled_at: today}
|
||||
{:ok, schedule} = ScheduledActivity.create(user, attrs)
|
||||
assert MastodonAPI.get_scheduled_activities(user) == [schedule]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -95,6 +95,18 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|
||||
assert user_three.nickname in result_ids
|
||||
end
|
||||
|
||||
test "returns account if query contains a space", %{conn: conn} do
|
||||
user = insert(:user, %{nickname: "shp@shitposter.club"})
|
||||
|
||||
results =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/accounts/search", %{"q" => "shp@shitposter.club xxx "})
|
||||
|> json_response(200)
|
||||
|
||||
assert length(results) == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe ".search" do
|
||||
|
|
|
|||
|
|
@ -23,6 +23,21 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
test "returns the direct conversation id when given the `with_conversation_id` option" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
|
||||
|
||||
status =
|
||||
StatusView.render("status.json",
|
||||
activity: activity,
|
||||
with_direct_conversation_id: true,
|
||||
for: user
|
||||
)
|
||||
|
||||
assert status[:pleroma][:direct_conversation_id]
|
||||
end
|
||||
|
||||
test "returns a temporary ap_id based user for activities missing db users" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -134,7 +149,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
in_reply_to_account_acct: nil,
|
||||
content: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["content"])},
|
||||
spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["summary"])},
|
||||
expires_at: nil
|
||||
expires_at: nil,
|
||||
direct_conversation_id: nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -301,6 +317,16 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
assert %{id: "2"} = StatusView.render("attachment.json", %{attachment: object})
|
||||
end
|
||||
|
||||
test "put the url advertised in the Activity in to the url attribute" do
|
||||
id = "https://wedistribute.org/wp-json/pterotype/v1/object/85810"
|
||||
[activity] = Activity.search(nil, id)
|
||||
|
||||
status = StatusView.render("status.json", %{activity: activity})
|
||||
|
||||
assert status.uri == id
|
||||
assert status.url == "https://wedistribute.org/2019/07/mastodon-drops-ostatus/"
|
||||
end
|
||||
|
||||
test "a reblog" do
|
||||
user = insert(:user)
|
||||
activity = insert(:note_activity)
|
||||
|
|
|
|||
|
|
@ -4,14 +4,11 @@
|
|||
|
||||
defmodule Pleroma.Web.MediaProxyTest do
|
||||
use ExUnit.Case
|
||||
use Pleroma.Tests.Helpers
|
||||
import Pleroma.Web.MediaProxy
|
||||
alias Pleroma.Web.MediaProxy.MediaProxyController
|
||||
|
||||
setup do
|
||||
enabled = Pleroma.Config.get([:media_proxy, :enabled])
|
||||
on_exit(fn -> Pleroma.Config.put([:media_proxy, :enabled], enabled) end)
|
||||
:ok
|
||||
end
|
||||
clear_config([:media_proxy, :enabled])
|
||||
|
||||
describe "when enabled" do
|
||||
setup do
|
||||
|
|
@ -171,21 +168,6 @@ defmodule Pleroma.Web.MediaProxyTest do
|
|||
encoded = url(url)
|
||||
assert decode_result(encoded) == url
|
||||
end
|
||||
|
||||
test "does not change whitelisted urls" do
|
||||
upload_config = Pleroma.Config.get([Pleroma.Upload])
|
||||
media_url = "https://media.pleroma.social"
|
||||
Pleroma.Config.put([Pleroma.Upload, :base_url], media_url)
|
||||
Pleroma.Config.put([:media_proxy, :whitelist], ["media.pleroma.social"])
|
||||
Pleroma.Config.put([:media_proxy, :base_url], "https://cache.pleroma.social")
|
||||
|
||||
url = "#{media_url}/static/logo.png"
|
||||
encoded = url(url)
|
||||
|
||||
assert String.starts_with?(encoded, media_url)
|
||||
|
||||
Pleroma.Config.put([Pleroma.Upload], upload_config)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when disabled" do
|
||||
|
|
@ -215,12 +197,43 @@ defmodule Pleroma.Web.MediaProxyTest do
|
|||
decoded
|
||||
end
|
||||
|
||||
test "mediaproxy whitelist" do
|
||||
Pleroma.Config.put([:media_proxy, :enabled], true)
|
||||
Pleroma.Config.put([:media_proxy, :whitelist], ["google.com", "feld.me"])
|
||||
url = "https://feld.me/foo.png"
|
||||
describe "whitelist" do
|
||||
setup do
|
||||
Pleroma.Config.put([:media_proxy, :enabled], true)
|
||||
:ok
|
||||
end
|
||||
|
||||
unencoded = url(url)
|
||||
assert unencoded == url
|
||||
test "mediaproxy whitelist" do
|
||||
Pleroma.Config.put([:media_proxy, :whitelist], ["google.com", "feld.me"])
|
||||
url = "https://feld.me/foo.png"
|
||||
|
||||
unencoded = url(url)
|
||||
assert unencoded == url
|
||||
end
|
||||
|
||||
test "does not change whitelisted urls" do
|
||||
Pleroma.Config.put([:media_proxy, :whitelist], ["mycdn.akamai.com"])
|
||||
Pleroma.Config.put([:media_proxy, :base_url], "https://cache.pleroma.social")
|
||||
|
||||
media_url = "https://mycdn.akamai.com"
|
||||
|
||||
url = "#{media_url}/static/logo.png"
|
||||
encoded = url(url)
|
||||
|
||||
assert String.starts_with?(encoded, media_url)
|
||||
end
|
||||
|
||||
test "ensure Pleroma.Upload base_url is always whitelisted" do
|
||||
upload_config = Pleroma.Config.get([Pleroma.Upload])
|
||||
media_url = "https://media.pleroma.social"
|
||||
Pleroma.Config.put([Pleroma.Upload, :base_url], media_url)
|
||||
|
||||
url = "#{media_url}/static/logo.png"
|
||||
encoded = url(url)
|
||||
|
||||
assert String.starts_with?(encoded, media_url)
|
||||
|
||||
Pleroma.Config.put([Pleroma.Upload], upload_config)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -85,6 +85,9 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||
end
|
||||
|
||||
test "it shows MRF transparency data if enabled", %{conn: conn} do
|
||||
config = Pleroma.Config.get([:instance, :rewrite_policy])
|
||||
Pleroma.Config.put([:instance, :rewrite_policy], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
|
||||
|
||||
option = Pleroma.Config.get([:instance, :mrf_transparency])
|
||||
Pleroma.Config.put([:instance, :mrf_transparency], true)
|
||||
|
||||
|
|
@ -98,11 +101,15 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||
|
||||
assert response["metadata"]["federation"]["mrf_simple"] == simple_config
|
||||
|
||||
Pleroma.Config.put([:instance, :rewrite_policy], config)
|
||||
Pleroma.Config.put([:instance, :mrf_transparency], option)
|
||||
Pleroma.Config.put(:mrf_simple, %{})
|
||||
end
|
||||
|
||||
test "it performs exclusions from MRF transparency data if configured", %{conn: conn} do
|
||||
config = Pleroma.Config.get([:instance, :rewrite_policy])
|
||||
Pleroma.Config.put([:instance, :rewrite_policy], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
|
||||
|
||||
option = Pleroma.Config.get([:instance, :mrf_transparency])
|
||||
Pleroma.Config.put([:instance, :mrf_transparency], true)
|
||||
|
||||
|
|
@ -122,6 +129,7 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||
assert response["metadata"]["federation"]["mrf_simple"] == expected_config
|
||||
assert response["metadata"]["federation"]["exclusions"] == true
|
||||
|
||||
Pleroma.Config.put([:instance, :rewrite_policy], config)
|
||||
Pleroma.Config.put([:instance, :mrf_transparency], option)
|
||||
Pleroma.Config.put([:instance, :mrf_transparency_exclusions], exclusions)
|
||||
Pleroma.Config.put(:mrf_simple, %{})
|
||||
|
|
|
|||
|
|
@ -12,21 +12,12 @@ defmodule Pleroma.Web.OAuth.LDAPAuthorizationTest do
|
|||
|
||||
@skip if !Code.ensure_loaded?(:eldap), do: :skip
|
||||
|
||||
setup_all do
|
||||
ldap_authenticator =
|
||||
Pleroma.Config.get(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.PleromaAuthenticator)
|
||||
|
||||
ldap_enabled = Pleroma.Config.get([:ldap, :enabled])
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put(Pleroma.Web.Auth.Authenticator, ldap_authenticator)
|
||||
Pleroma.Config.put([:ldap, :enabled], ldap_enabled)
|
||||
end)
|
||||
|
||||
Pleroma.Config.put(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.LDAPAuthenticator)
|
||||
clear_config_all([:ldap, :enabled]) do
|
||||
Pleroma.Config.put([:ldap, :enabled], true)
|
||||
end
|
||||
|
||||
:ok
|
||||
clear_config_all(Pleroma.Web.Auth.Authenticator) do
|
||||
Pleroma.Config.put(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.LDAPAuthenticator)
|
||||
end
|
||||
|
||||
@tag @skip
|
||||
|
|
|
|||
|
|
@ -11,23 +11,15 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
alias Pleroma.Web.OAuth.OAuthController
|
||||
alias Pleroma.Web.OAuth.Token
|
||||
|
||||
@oauth_config_path [:oauth2, :issue_new_refresh_token]
|
||||
@session_opts [
|
||||
store: :cookie,
|
||||
key: "_test",
|
||||
signing_salt: "cooldude"
|
||||
]
|
||||
clear_config_all([:instance, :account_activation_required])
|
||||
|
||||
describe "in OAuth consumer mode, " do
|
||||
setup do
|
||||
oauth_consumer_strategies_path = [:auth, :oauth_consumer_strategies]
|
||||
oauth_consumer_strategies = Pleroma.Config.get(oauth_consumer_strategies_path)
|
||||
Pleroma.Config.put(oauth_consumer_strategies_path, ~w(twitter facebook))
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put(oauth_consumer_strategies_path, oauth_consumer_strategies)
|
||||
end)
|
||||
|
||||
[
|
||||
app: insert(:oauth_app),
|
||||
conn:
|
||||
|
|
@ -37,6 +29,13 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
]
|
||||
end
|
||||
|
||||
clear_config([:auth, :oauth_consumer_strategies]) do
|
||||
Pleroma.Config.put(
|
||||
[:auth, :oauth_consumer_strategies],
|
||||
~w(twitter facebook)
|
||||
)
|
||||
end
|
||||
|
||||
test "GET /oauth/authorize renders auth forms, including OAuth consumer form", %{
|
||||
app: app,
|
||||
conn: conn
|
||||
|
|
@ -775,12 +774,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
end
|
||||
|
||||
test "rejects token exchange for valid credentials belonging to unconfirmed user and confirmation is required" do
|
||||
setting = Pleroma.Config.get([:instance, :account_activation_required])
|
||||
|
||||
unless setting do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
|
||||
end
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
|
||||
password = "testpassword"
|
||||
user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
|
||||
|
|
@ -857,16 +851,10 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
end
|
||||
|
||||
describe "POST /oauth/token - refresh token" do
|
||||
setup do
|
||||
oauth_token_config = Pleroma.Config.get(@oauth_config_path)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.get(@oauth_config_path, oauth_token_config)
|
||||
end)
|
||||
end
|
||||
clear_config([:oauth2, :issue_new_refresh_token])
|
||||
|
||||
test "issues a new access token with keep fresh token" do
|
||||
Pleroma.Config.put(@oauth_config_path, true)
|
||||
Pleroma.Config.put([:oauth2, :issue_new_refresh_token], true)
|
||||
user = insert(:user)
|
||||
app = insert(:oauth_app, scopes: ["read", "write"])
|
||||
|
||||
|
|
@ -906,7 +894,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
end
|
||||
|
||||
test "issues a new access token with new fresh token" do
|
||||
Pleroma.Config.put(@oauth_config_path, false)
|
||||
Pleroma.Config.put([:oauth2, :issue_new_refresh_token], false)
|
||||
user = insert(:user)
|
||||
app = insert(:oauth_app, scopes: ["read", "write"])
|
||||
|
||||
|
|
|
|||
|
|
@ -15,16 +15,13 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
config_path = [:instance, :federating]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
Pleroma.Config.put(config_path, true)
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
clear_config_all([:instance, :federating]) do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
end
|
||||
|
||||
describe "salmon_incoming" do
|
||||
test "decodes a salmon", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
|
@ -101,160 +98,538 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
assert response(conn, 404)
|
||||
end
|
||||
|
||||
test "gets an object", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
|
||||
url = "/objects/#{uuid}"
|
||||
describe "GET object/2" do
|
||||
test "gets an object", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
|
||||
url = "/objects/#{uuid}"
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get(url)
|
||||
|
||||
expected =
|
||||
ActivityRepresenter.to_simple_form(note_activity, user, true)
|
||||
|> ActivityRepresenter.wrap_with_entry()
|
||||
|> :xmerl.export_simple(:xmerl_xml)
|
||||
|> to_string
|
||||
|
||||
assert response(conn, 200) == expected
|
||||
end
|
||||
|
||||
test "redirects to /notice/id for html format", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
|
||||
url = "/objects/#{uuid}"
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get(url)
|
||||
|
||||
assert redirected_to(conn) == "/notice/#{note_activity.id}"
|
||||
end
|
||||
|
||||
test "500s when user not found", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
User.invalidate_cache(user)
|
||||
Pleroma.Repo.delete(user)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
|
||||
url = "/objects/#{uuid}"
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get(url)
|
||||
|
||||
assert response(conn, 500) == ~S({"error":"Something went wrong"})
|
||||
end
|
||||
|
||||
test "404s on private objects", %{conn: conn} do
|
||||
note_activity = insert(:direct_note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
|
||||
|
||||
conn
|
||||
|> get("/objects/#{uuid}")
|
||||
|> response(404)
|
||||
end
|
||||
|
||||
test "404s on nonexisting objects", %{conn: conn} do
|
||||
conn
|
||||
|> get("/objects/123")
|
||||
|> response(404)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET activity/2" do
|
||||
test "gets an activity in xml format", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get(url)
|
||||
|> get("/activities/#{uuid}")
|
||||
|> response(200)
|
||||
end
|
||||
|
||||
expected =
|
||||
ActivityRepresenter.to_simple_form(note_activity, user, true)
|
||||
|> ActivityRepresenter.wrap_with_entry()
|
||||
|> :xmerl.export_simple(:xmerl_xml)
|
||||
|> to_string
|
||||
test "redirects to /notice/id for html format", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
|
||||
|
||||
assert response(conn, 200) == expected
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/activities/#{uuid}")
|
||||
|
||||
assert redirected_to(conn) == "/notice/#{note_activity.id}"
|
||||
end
|
||||
|
||||
test "505s when user not found", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
User.invalidate_cache(user)
|
||||
Pleroma.Repo.delete(user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/activities/#{uuid}")
|
||||
|
||||
assert response(conn, 500) == ~S({"error":"Something went wrong"})
|
||||
end
|
||||
|
||||
test "404s on deleted objects", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get("/objects/#{uuid}")
|
||||
|> response(200)
|
||||
|
||||
Object.delete(object)
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get("/objects/#{uuid}")
|
||||
|> response(404)
|
||||
end
|
||||
|
||||
test "404s on private activities", %{conn: conn} do
|
||||
note_activity = insert(:direct_note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
|
||||
|
||||
conn
|
||||
|> get("/activities/#{uuid}")
|
||||
|> response(404)
|
||||
end
|
||||
|
||||
test "404s on nonexistent activities", %{conn: conn} do
|
||||
conn
|
||||
|> get("/activities/123")
|
||||
|> response(404)
|
||||
end
|
||||
|
||||
test "gets an activity in AS2 format", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
|
||||
url = "/activities/#{uuid}"
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get(url)
|
||||
|
||||
assert json_response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
test "404s on private objects", %{conn: conn} do
|
||||
note_activity = insert(:direct_note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
|
||||
describe "GET notice/2" do
|
||||
test "gets a notice in xml format", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
|
||||
conn
|
||||
|> get("/objects/#{uuid}")
|
||||
|> response(404)
|
||||
end
|
||||
conn
|
||||
|> get("/notice/#{note_activity.id}")
|
||||
|> response(200)
|
||||
end
|
||||
|
||||
test "404s on nonexisting objects", %{conn: conn} do
|
||||
conn
|
||||
|> get("/objects/123")
|
||||
|> response(404)
|
||||
end
|
||||
test "gets a notice in AS2 format", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
|
||||
test "gets an activity in xml format", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get("/activities/#{uuid}")
|
||||
|> response(200)
|
||||
end
|
||||
|
||||
test "404s on deleted objects", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get("/objects/#{uuid}")
|
||||
|> response(200)
|
||||
|
||||
Object.delete(object)
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get("/objects/#{uuid}")
|
||||
|> response(404)
|
||||
end
|
||||
|
||||
test "404s on private activities", %{conn: conn} do
|
||||
note_activity = insert(:direct_note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
|
||||
|
||||
conn
|
||||
|> get("/activities/#{uuid}")
|
||||
|> response(404)
|
||||
end
|
||||
|
||||
test "404s on nonexistent activities", %{conn: conn} do
|
||||
conn
|
||||
|> get("/activities/123")
|
||||
|> response(404)
|
||||
end
|
||||
|
||||
test "gets a notice in xml format", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
|
||||
conn
|
||||
|> get("/notice/#{note_activity.id}")
|
||||
|> response(200)
|
||||
end
|
||||
|
||||
test "gets a notice in AS2 format", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/notice/#{note_activity.id}")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "only gets a notice in AS2 format for Create messages", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
url = "/notice/#{note_activity.id}"
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get(url)
|
||||
|> get("/notice/#{note_activity.id}")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
assert json_response(conn, 200)
|
||||
test "500s when actor not found", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
User.invalidate_cache(user)
|
||||
Pleroma.Repo.delete(user)
|
||||
|
||||
user = insert(:user)
|
||||
conn =
|
||||
conn
|
||||
|> get("/notice/#{note_activity.id}")
|
||||
|
||||
{:ok, like_activity, _} = CommonAPI.favorite(note_activity.id, user)
|
||||
url = "/notice/#{like_activity.id}"
|
||||
assert response(conn, 500) == ~S({"error":"Something went wrong"})
|
||||
end
|
||||
|
||||
assert like_activity.data["type"] == "Like"
|
||||
test "only gets a notice in AS2 format for Create messages", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
url = "/notice/#{note_activity.id}"
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get(url)
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get(url)
|
||||
|
||||
assert response(conn, 404)
|
||||
assert json_response(conn, 200)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, like_activity, _} = CommonAPI.favorite(note_activity.id, user)
|
||||
url = "/notice/#{like_activity.id}"
|
||||
|
||||
assert like_activity.data["type"] == "Like"
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get(url)
|
||||
|
||||
assert response(conn, 404)
|
||||
end
|
||||
|
||||
test "render html for redirect for html format", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/notice/#{note_activity.id}")
|
||||
|> response(200)
|
||||
|
||||
assert resp =~
|
||||
"<meta content=\"#{Pleroma.Web.base_url()}/notice/#{note_activity.id}\" property=\"og:url\">"
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, like_activity, _} = CommonAPI.favorite(note_activity.id, user)
|
||||
|
||||
assert like_activity.data["type"] == "Like"
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/notice/#{like_activity.id}")
|
||||
|> response(200)
|
||||
|
||||
assert resp =~ "<!--server-generated-meta-->"
|
||||
end
|
||||
|
||||
test "404s a private notice", %{conn: conn} do
|
||||
note_activity = insert(:direct_note_activity)
|
||||
url = "/notice/#{note_activity.id}"
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> get(url)
|
||||
|
||||
assert response(conn, 404)
|
||||
end
|
||||
|
||||
test "404s a nonexisting notice", %{conn: conn} do
|
||||
url = "/notice/123"
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> get(url)
|
||||
|
||||
assert response(conn, 404)
|
||||
end
|
||||
end
|
||||
|
||||
test "gets an activity in AS2 format", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
|
||||
url = "/activities/#{uuid}"
|
||||
describe "feed_redirect" do
|
||||
test "undefined format. it redirects to feed", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get(url)
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get("/users/#{user.nickname}")
|
||||
|> response(302)
|
||||
|
||||
assert json_response(conn, 200)
|
||||
assert response ==
|
||||
"<html><body>You are being <a href=\"#{Pleroma.Web.base_url()}/users/#{
|
||||
user.nickname
|
||||
}/feed.atom\">redirected</a>.</body></html>"
|
||||
end
|
||||
|
||||
test "undefined format. it returns error when user not found", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get("/users/jimm")
|
||||
|> response(404)
|
||||
|
||||
assert response == ~S({"error":"Not found"})
|
||||
end
|
||||
|
||||
test "activity+json format. it redirects on actual feed of user", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/users/#{user.nickname}")
|
||||
|> json_response(200)
|
||||
|
||||
assert response["endpoints"] == %{
|
||||
"oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize",
|
||||
"oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
|
||||
"oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
|
||||
"sharedInbox" => "#{Pleroma.Web.base_url()}/inbox"
|
||||
}
|
||||
|
||||
assert response["@context"] == [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"http://localhost:4001/schemas/litepub-0.1.jsonld",
|
||||
%{"@language" => "und"}
|
||||
]
|
||||
|
||||
assert Map.take(response, [
|
||||
"followers",
|
||||
"following",
|
||||
"id",
|
||||
"inbox",
|
||||
"manuallyApprovesFollowers",
|
||||
"name",
|
||||
"outbox",
|
||||
"preferredUsername",
|
||||
"summary",
|
||||
"tag",
|
||||
"type",
|
||||
"url"
|
||||
]) == %{
|
||||
"followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers",
|
||||
"following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following",
|
||||
"id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}",
|
||||
"inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox",
|
||||
"manuallyApprovesFollowers" => false,
|
||||
"name" => user.name,
|
||||
"outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox",
|
||||
"preferredUsername" => user.nickname,
|
||||
"summary" => user.bio,
|
||||
"tag" => [],
|
||||
"type" => "Person",
|
||||
"url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
|
||||
}
|
||||
end
|
||||
|
||||
test "activity+json format. it returns error whe use not found", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/users/jimm")
|
||||
|> json_response(404)
|
||||
|
||||
assert response == "Not found"
|
||||
end
|
||||
|
||||
test "json format. it redirects on actual feed of user", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> get("/users/#{user.nickname}")
|
||||
|> json_response(200)
|
||||
|
||||
assert response["endpoints"] == %{
|
||||
"oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize",
|
||||
"oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
|
||||
"oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
|
||||
"sharedInbox" => "#{Pleroma.Web.base_url()}/inbox"
|
||||
}
|
||||
|
||||
assert response["@context"] == [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"http://localhost:4001/schemas/litepub-0.1.jsonld",
|
||||
%{"@language" => "und"}
|
||||
]
|
||||
|
||||
assert Map.take(response, [
|
||||
"followers",
|
||||
"following",
|
||||
"id",
|
||||
"inbox",
|
||||
"manuallyApprovesFollowers",
|
||||
"name",
|
||||
"outbox",
|
||||
"preferredUsername",
|
||||
"summary",
|
||||
"tag",
|
||||
"type",
|
||||
"url"
|
||||
]) == %{
|
||||
"followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers",
|
||||
"following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following",
|
||||
"id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}",
|
||||
"inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox",
|
||||
"manuallyApprovesFollowers" => false,
|
||||
"name" => user.name,
|
||||
"outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox",
|
||||
"preferredUsername" => user.nickname,
|
||||
"summary" => user.bio,
|
||||
"tag" => [],
|
||||
"type" => "Person",
|
||||
"url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
|
||||
}
|
||||
end
|
||||
|
||||
test "json format. it returns error whe use not found", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> get("/users/jimm")
|
||||
|> json_response(404)
|
||||
|
||||
assert response == "Not found"
|
||||
end
|
||||
|
||||
test "html format. it redirects on actual feed of user", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/users/#{user.nickname}")
|
||||
|> response(200)
|
||||
|
||||
assert response ==
|
||||
Fallback.RedirectController.redirector_with_meta(
|
||||
conn,
|
||||
%{user: user}
|
||||
).resp_body
|
||||
end
|
||||
|
||||
test "html format. it returns error when user not found", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> get("/users/jimm")
|
||||
|> json_response(404)
|
||||
|
||||
assert response == %{"error" => "Not found"}
|
||||
end
|
||||
end
|
||||
|
||||
test "404s a private notice", %{conn: conn} do
|
||||
note_activity = insert(:direct_note_activity)
|
||||
url = "/notice/#{note_activity.id}"
|
||||
describe "GET /notice/:id/embed_player" do
|
||||
test "render embed player", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Pleroma.Object.normalize(note_activity)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> get(url)
|
||||
object_data =
|
||||
Map.put(object.data, "attachment", [
|
||||
%{
|
||||
"url" => [
|
||||
%{
|
||||
"href" =>
|
||||
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
}
|
||||
])
|
||||
|
||||
assert response(conn, 404)
|
||||
end
|
||||
object
|
||||
|> Ecto.Changeset.change(data: object_data)
|
||||
|> Pleroma.Repo.update()
|
||||
|
||||
test "404s a nonexisting notice", %{conn: conn} do
|
||||
url = "/notice/123"
|
||||
conn =
|
||||
conn
|
||||
|> get("/notice/#{note_activity.id}/embed_player")
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> get(url)
|
||||
assert Plug.Conn.get_resp_header(conn, "x-frame-options") == ["ALLOW"]
|
||||
|
||||
assert response(conn, 404)
|
||||
assert Plug.Conn.get_resp_header(
|
||||
conn,
|
||||
"content-security-policy"
|
||||
) == [
|
||||
"default-src 'none';style-src 'self' 'unsafe-inline';img-src 'self' data: https:; media-src 'self' https:;"
|
||||
]
|
||||
|
||||
assert response(conn, 200) =~
|
||||
"<video controls loop><source src=\"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4\" type=\"video/mp4\">Your browser does not support video/mp4 playback.</video>"
|
||||
end
|
||||
|
||||
test "404s when activity isn't create", %{conn: conn} do
|
||||
note_activity = insert(:note_activity, data_attrs: %{"type" => "Like"})
|
||||
|
||||
assert conn
|
||||
|> get("/notice/#{note_activity.id}/embed_player")
|
||||
|> response(404)
|
||||
end
|
||||
|
||||
test "404s when activity is direct message", %{conn: conn} do
|
||||
note_activity = insert(:note_activity, data_attrs: %{"directMessage" => true})
|
||||
|
||||
assert conn
|
||||
|> get("/notice/#{note_activity.id}/embed_player")
|
||||
|> response(404)
|
||||
end
|
||||
|
||||
test "404s when attachment is empty", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Pleroma.Object.normalize(note_activity)
|
||||
object_data = Map.put(object.data, "attachment", [])
|
||||
|
||||
object
|
||||
|> Ecto.Changeset.change(data: object_data)
|
||||
|> Pleroma.Repo.update()
|
||||
|
||||
assert conn
|
||||
|> get("/notice/#{note_activity.id}/embed_player")
|
||||
|> response(404)
|
||||
end
|
||||
|
||||
test "404s when attachment isn't audio or video", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Pleroma.Object.normalize(note_activity)
|
||||
|
||||
object_data =
|
||||
Map.put(object.data, "attachment", [
|
||||
%{
|
||||
"url" => [
|
||||
%{
|
||||
"href" => "https://peertube.moe/static/webseed/480.jpg",
|
||||
"mediaType" => "image/jpg",
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
}
|
||||
])
|
||||
|
||||
object
|
||||
|> Ecto.Changeset.change(data: object_data)
|
||||
|> Pleroma.Repo.update()
|
||||
|
||||
assert conn
|
||||
|> get("/notice/#{note_activity.id}/embed_player")
|
||||
|> response(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ defmodule Pleroma.Web.OStatusTest do
|
|||
assert retweeted_activity.data["type"] == "Create"
|
||||
assert retweeted_activity.data["actor"] == user.ap_id
|
||||
assert retweeted_activity.local
|
||||
assert retweeted_activity.data["object"]["announcement_count"] == 1
|
||||
assert Object.normalize(retweeted_activity).data["announcement_count"] == 1
|
||||
end
|
||||
|
||||
test "handle incoming retweets - Mastodon, salmon" do
|
||||
|
|
@ -326,6 +326,14 @@ defmodule Pleroma.Web.OStatusTest do
|
|||
assert User.following?(follower, followed)
|
||||
end
|
||||
|
||||
test "refuse following over OStatus if the followed's account is locked" do
|
||||
incoming = File.read!("test/fixtures/follow.xml")
|
||||
_user = insert(:user, info: %{locked: true}, ap_id: "https://pawoo.net/users/pekorino")
|
||||
|
||||
{:ok, [{:error, "It's not possible to follow locked accounts over OStatus"}]} =
|
||||
OStatus.handle_incoming(incoming)
|
||||
end
|
||||
|
||||
test "handle incoming unfollows with existing follow" do
|
||||
incoming_follow = File.read!("test/fixtures/follow.xml")
|
||||
{:ok, [_activity]} = OStatus.handle_incoming(incoming_follow)
|
||||
|
|
@ -426,7 +434,7 @@ defmodule Pleroma.Web.OStatusTest do
|
|||
}
|
||||
end
|
||||
|
||||
test "find_make_or_update_user takes an author element and returns an updated user" do
|
||||
test "find_make_or_update_actor takes an author element and returns an updated user" do
|
||||
uri = "https://social.heldscal.la/user/23211"
|
||||
|
||||
{:ok, user} = OStatus.find_or_make_user(uri)
|
||||
|
|
@ -439,14 +447,56 @@ defmodule Pleroma.Web.OStatusTest do
|
|||
|
||||
doc = XML.parse_document(File.read!("test/fixtures/23211.atom"))
|
||||
[author] = :xmerl_xpath.string('//author[1]', doc)
|
||||
{:ok, user} = OStatus.find_make_or_update_user(author)
|
||||
{:ok, user} = OStatus.find_make_or_update_actor(author)
|
||||
assert user.avatar["type"] == "Image"
|
||||
assert user.name == old_name
|
||||
assert user.bio == old_bio
|
||||
|
||||
{:ok, user_again} = OStatus.find_make_or_update_user(author)
|
||||
{:ok, user_again} = OStatus.find_make_or_update_actor(author)
|
||||
assert user_again == user
|
||||
end
|
||||
|
||||
test "find_or_make_user disallows protocol downgrade" do
|
||||
user = insert(:user, %{local: true})
|
||||
{:ok, user} = OStatus.find_or_make_user(user.ap_id)
|
||||
|
||||
assert User.ap_enabled?(user)
|
||||
|
||||
user =
|
||||
insert(:user, %{
|
||||
ap_id: "https://social.heldscal.la/user/23211",
|
||||
info: %{ap_enabled: true},
|
||||
local: false
|
||||
})
|
||||
|
||||
assert User.ap_enabled?(user)
|
||||
|
||||
{:ok, user} = OStatus.find_or_make_user(user.ap_id)
|
||||
assert User.ap_enabled?(user)
|
||||
end
|
||||
|
||||
test "find_make_or_update_actor disallows protocol downgrade" do
|
||||
user = insert(:user, %{local: true})
|
||||
{:ok, user} = OStatus.find_or_make_user(user.ap_id)
|
||||
|
||||
assert User.ap_enabled?(user)
|
||||
|
||||
user =
|
||||
insert(:user, %{
|
||||
ap_id: "https://social.heldscal.la/user/23211",
|
||||
info: %{ap_enabled: true},
|
||||
local: false
|
||||
})
|
||||
|
||||
assert User.ap_enabled?(user)
|
||||
|
||||
{:ok, user} = OStatus.find_or_make_user(user.ap_id)
|
||||
assert User.ap_enabled?(user)
|
||||
|
||||
doc = XML.parse_document(File.read!("test/fixtures/23211.atom"))
|
||||
[author] = :xmerl_xpath.string('//author[1]', doc)
|
||||
{:error, :invalid_protocol} = OStatus.find_make_or_update_actor(author)
|
||||
end
|
||||
end
|
||||
|
||||
describe "gathering user info from a user id" do
|
||||
|
|
|
|||
94
test/web/pleroma_api/pleroma_api_controller_test.exs
Normal file
94
test/web/pleroma_api/pleroma_api_controller_test.exs
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Conversation.Participation
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "/api/v1/pleroma/conversations/:id", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
|
||||
|
||||
[participation] = Participation.for_user(other_user)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, other_user)
|
||||
|> get("/api/v1/pleroma/conversations/#{participation.id}")
|
||||
|> json_response(200)
|
||||
|
||||
assert result["id"] == participation.id |> to_string()
|
||||
end
|
||||
|
||||
test "/api/v1/pleroma/conversations/:id/statuses", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
third_user = insert(:user)
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.post(user, %{"status" => "Hi @#{third_user.nickname}!", "visibility" => "direct"})
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
|
||||
|
||||
[participation] = Participation.for_user(other_user)
|
||||
|
||||
{:ok, activity_two} =
|
||||
CommonAPI.post(other_user, %{
|
||||
"status" => "Hi!",
|
||||
"in_reply_to_status_id" => activity.id,
|
||||
"in_reply_to_conversation_id" => participation.id
|
||||
})
|
||||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, other_user)
|
||||
|> get("/api/v1/pleroma/conversations/#{participation.id}/statuses")
|
||||
|> json_response(200)
|
||||
|
||||
assert length(result) == 2
|
||||
|
||||
id_one = activity.id
|
||||
id_two = activity_two.id
|
||||
assert [%{"id" => ^id_one}, %{"id" => ^id_two}] = result
|
||||
end
|
||||
|
||||
test "PATCH /api/v1/pleroma/conversations/:id", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(user, %{"status" => "Hi", "visibility" => "direct"})
|
||||
|
||||
[participation] = Participation.for_user(user)
|
||||
|
||||
participation = Repo.preload(participation, :recipients)
|
||||
|
||||
assert [user] == participation.recipients
|
||||
assert other_user not in participation.recipients
|
||||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/pleroma/conversations/#{participation.id}", %{
|
||||
"recipients" => [user.id, other_user.id]
|
||||
})
|
||||
|> json_response(200)
|
||||
|
||||
assert result["id"] == participation.id |> to_string
|
||||
|
||||
[participation] = Participation.for_user(user)
|
||||
participation = Repo.preload(participation, :recipients)
|
||||
|
||||
assert user in participation.recipients
|
||||
assert other_user in participation.recipients
|
||||
end
|
||||
end
|
||||
|
|
@ -4,15 +4,7 @@
|
|||
|
||||
defmodule Pleroma.Web.FederatingPlugTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
setup_all do
|
||||
config_path = [:instance, :federating]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
clear_config_all([:instance, :federating])
|
||||
|
||||
test "returns and halt the conn when federating is disabled" do
|
||||
Pleroma.Config.put([:instance, :federating], false)
|
||||
|
|
|
|||
|
|
@ -124,8 +124,7 @@ defmodule Pleroma.Web.Push.ImplTest do
|
|||
{:ok, _, _, activity} = CommonAPI.follow(user, other_user)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert Impl.format_body(%{activity: activity}, user, object) ==
|
||||
"@Bob has followed you"
|
||||
assert Impl.format_body(%{activity: activity}, user, object) == "@Bob has followed you"
|
||||
end
|
||||
|
||||
test "renders body for announce activity" do
|
||||
|
|
@ -156,7 +155,6 @@ defmodule Pleroma.Web.Push.ImplTest do
|
|||
{:ok, activity, _} = CommonAPI.favorite(activity.id, user)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert Impl.format_body(%{activity: activity}, user, object) ==
|
||||
"@Bob has favorited your post"
|
||||
assert Impl.format_body(%{activity: activity}, user, object) == "@Bob has favorited your post"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -60,7 +60,8 @@ defmodule Pleroma.Web.RichMedia.TTL.AwsSignedUrlTest do
|
|||
{:ok, cache_ttl} = Cachex.ttl(:rich_media_cache, url)
|
||||
|
||||
# as there is delay in setting and pulling the data from cache we ignore 1 second
|
||||
assert_in_delta(valid_till * 1000, cache_ttl, 1000)
|
||||
# make it 2 seconds for flakyness
|
||||
assert_in_delta(valid_till * 1000, cache_ttl, 2000)
|
||||
end
|
||||
|
||||
defp construct_s3_url(timestamp, valid_till) do
|
||||
|
|
|
|||
|
|
@ -15,12 +15,12 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
|
|||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
rich_media = Config.get([:rich_media, :enabled])
|
||||
on_exit(fn -> Config.put([:rich_media, :enabled], rich_media) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
clear_config([:rich_media, :enabled])
|
||||
|
||||
test "refuses to crawl incomplete URLs" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
|
|||
69
test/web/rich_media/parsers/twitter_card_test.exs
Normal file
69
test/web/rich_media/parsers/twitter_card_test.exs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do
|
||||
use ExUnit.Case, async: true
|
||||
alias Pleroma.Web.RichMedia.Parsers.TwitterCard
|
||||
|
||||
test "returns error when html not contains twitter card" do
|
||||
assert TwitterCard.parse("", %{}) == {:error, "No twitter card metadata found"}
|
||||
end
|
||||
|
||||
test "parses twitter card with only name attributes" do
|
||||
html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers3.html")
|
||||
|
||||
assert TwitterCard.parse(html, %{}) ==
|
||||
{:ok,
|
||||
%{
|
||||
"app:id:googleplay": "com.nytimes.android",
|
||||
"app:name:googleplay": "NYTimes",
|
||||
"app:url:googleplay": "nytimes://reader/id/100000006583622",
|
||||
site: nil,
|
||||
title:
|
||||
"She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database. - The New York Times"
|
||||
}}
|
||||
end
|
||||
|
||||
test "parses twitter card with only property attributes" do
|
||||
html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers2.html")
|
||||
|
||||
assert TwitterCard.parse(html, %{}) ==
|
||||
{:ok,
|
||||
%{
|
||||
card: "summary_large_image",
|
||||
description:
|
||||
"With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.",
|
||||
image:
|
||||
"https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-videoSixteenByNineJumbo1600.jpg",
|
||||
"image:alt": "",
|
||||
title:
|
||||
"She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.",
|
||||
url:
|
||||
"https://www.nytimes.com/2019/08/01/nyregion/nypd-facial-recognition-children-teenagers.html"
|
||||
}}
|
||||
end
|
||||
|
||||
test "parses twitter card with name & property attributes" do
|
||||
html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers.html")
|
||||
|
||||
assert TwitterCard.parse(html, %{}) ==
|
||||
{:ok,
|
||||
%{
|
||||
"app:id:googleplay": "com.nytimes.android",
|
||||
"app:name:googleplay": "NYTimes",
|
||||
"app:url:googleplay": "nytimes://reader/id/100000006583622",
|
||||
card: "summary_large_image",
|
||||
description:
|
||||
"With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.",
|
||||
image:
|
||||
"https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-videoSixteenByNineJumbo1600.jpg",
|
||||
"image:alt": "",
|
||||
site: nil,
|
||||
title:
|
||||
"She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.",
|
||||
url:
|
||||
"https://www.nytimes.com/2019/08/01/nyregion/nypd-facial-recognition-children-teenagers.html"
|
||||
}}
|
||||
end
|
||||
end
|
||||
|
|
@ -11,15 +11,7 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
alias Pleroma.Web.Streamer
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
skip_thread_containment = Pleroma.Config.get([:instance, :skip_thread_containment])
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :skip_thread_containment], skip_thread_containment)
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
clear_config_all([:instance, :skip_thread_containment])
|
||||
|
||||
describe "user streams" do
|
||||
setup do
|
||||
|
|
@ -103,6 +95,25 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
Streamer.stream("user:notification", notif)
|
||||
Task.await(task)
|
||||
end
|
||||
|
||||
test "it doesn't send notify to the 'user:notification' stream' when a domain is blocked", %{
|
||||
user: user
|
||||
} do
|
||||
user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
|
||||
task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
|
||||
|
||||
Streamer.add_socket(
|
||||
"user:notification",
|
||||
%{transport_pid: task.pid, assigns: %{user: user}}
|
||||
)
|
||||
|
||||
{:ok, user} = User.block_domain(user, "hecking-lewd-place.com")
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
|
||||
{:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
|
||||
|
||||
Streamer.stream("user:notification", notif)
|
||||
Task.await(task)
|
||||
end
|
||||
end
|
||||
|
||||
test "it sends to public" do
|
||||
|
|
@ -395,6 +406,26 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
Task.await(task)
|
||||
end
|
||||
|
||||
test "it doesn't send posts from muted threads" do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
{:ok, user2, user, _activity} = CommonAPI.follow(user2, user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
|
||||
|
||||
{:ok, activity} = CommonAPI.add_mute(user2, activity)
|
||||
|
||||
task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
|
||||
|
||||
Streamer.add_socket(
|
||||
"user",
|
||||
%{transport_pid: task.pid, assigns: %{user: user2}}
|
||||
)
|
||||
|
||||
Streamer.stream("user", activity)
|
||||
Task.await(task)
|
||||
end
|
||||
|
||||
describe "direct streams" do
|
||||
setup do
|
||||
GenServer.start(Streamer, %{}, name: Streamer)
|
||||
|
|
|
|||
|
|
@ -151,6 +151,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
describe "GET /statuses/public_timeline.json" do
|
||||
setup [:valid_user]
|
||||
clear_config([:instance, :public])
|
||||
|
||||
test "returns statuses", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
|
@ -173,8 +174,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
conn
|
||||
|> get("/api/statuses/public_timeline.json")
|
||||
|> json_response(403)
|
||||
|
||||
Pleroma.Config.put([:instance, :public], true)
|
||||
end
|
||||
|
||||
test "returns 200 to authenticated request when the instance is not public",
|
||||
|
|
@ -185,8 +184,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|> with_credentials(user.nickname, "test")
|
||||
|> get("/api/statuses/public_timeline.json")
|
||||
|> json_response(200)
|
||||
|
||||
Pleroma.Config.put([:instance, :public], true)
|
||||
end
|
||||
|
||||
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
|
||||
|
|
@ -220,6 +217,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
describe "GET /statuses/public_and_external_timeline.json" do
|
||||
setup [:valid_user]
|
||||
clear_config([:instance, :public])
|
||||
|
||||
test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :public], false)
|
||||
|
|
@ -227,8 +225,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
conn
|
||||
|> get("/api/statuses/public_and_external_timeline.json")
|
||||
|> json_response(403)
|
||||
|
||||
Pleroma.Config.put([:instance, :public], true)
|
||||
end
|
||||
|
||||
test "returns 200 to authenticated request when the instance is not public",
|
||||
|
|
@ -239,8 +235,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|> with_credentials(user.nickname, "test")
|
||||
|> get("/api/statuses/public_and_external_timeline.json")
|
||||
|> json_response(200)
|
||||
|
||||
Pleroma.Config.put([:instance, :public], true)
|
||||
end
|
||||
|
||||
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
|
||||
|
|
@ -1176,13 +1170,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
describe "POST /api/account/resend_confirmation_email" do
|
||||
setup do
|
||||
setting = Pleroma.Config.get([:instance, :account_activation_required])
|
||||
|
||||
unless setting do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
|
||||
end
|
||||
|
||||
user = insert(:user)
|
||||
info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true)
|
||||
|
||||
|
|
@ -1197,6 +1184,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
[user: user]
|
||||
end
|
||||
|
||||
clear_config([:instance, :account_activation_required]) do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
end
|
||||
|
||||
test "it returns 204 No Content", %{conn: conn, user: user} do
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
clear_config([:instance])
|
||||
clear_config([:frontend_configurations, :pleroma_fe])
|
||||
clear_config([:user, :deny_follow_blocked])
|
||||
|
||||
describe "POST /api/pleroma/follow_import" do
|
||||
test "it returns HTTP 200", %{conn: conn} do
|
||||
user1 = insert(:user)
|
||||
|
|
@ -31,6 +35,35 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
assert response == "job started"
|
||||
end
|
||||
|
||||
test "it imports follow lists from file", %{conn: conn} do
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
with_mocks([
|
||||
{File, [],
|
||||
read!: fn "follow_list.txt" ->
|
||||
"Account address,Show boosts\n#{user2.ap_id},true"
|
||||
end},
|
||||
{PleromaJobQueue, [:passthrough], []}
|
||||
]) do
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user1)
|
||||
|> post("/api/pleroma/follow_import", %{"list" => %Plug.Upload{path: "follow_list.txt"}})
|
||||
|> json_response(:ok)
|
||||
|
||||
assert called(
|
||||
PleromaJobQueue.enqueue(
|
||||
:background,
|
||||
User,
|
||||
[:follow_import, user1, [user2.ap_id]]
|
||||
)
|
||||
)
|
||||
|
||||
assert response == "job started"
|
||||
end
|
||||
end
|
||||
|
||||
test "it imports new-style mastodon follow lists", %{conn: conn} do
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
|
@ -79,6 +112,33 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|
||||
assert response == "job started"
|
||||
end
|
||||
|
||||
test "it imports blocks users from file", %{conn: conn} do
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
user3 = insert(:user)
|
||||
|
||||
with_mocks([
|
||||
{File, [], read!: fn "blocks_list.txt" -> "#{user2.ap_id} #{user3.ap_id}" end},
|
||||
{PleromaJobQueue, [:passthrough], []}
|
||||
]) do
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user1)
|
||||
|> post("/api/pleroma/blocks_import", %{"list" => %Plug.Upload{path: "blocks_list.txt"}})
|
||||
|> json_response(:ok)
|
||||
|
||||
assert called(
|
||||
PleromaJobQueue.enqueue(
|
||||
:background,
|
||||
User,
|
||||
[:blocks_import, user1, [user2.ap_id, user3.ap_id]]
|
||||
)
|
||||
)
|
||||
|
||||
assert response == "job started"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/notifications/read" do
|
||||
|
|
@ -98,6 +158,18 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
assert Repo.get(Notification, notification1.id).seen
|
||||
refute Repo.get(Notification, notification2.id).seen
|
||||
end
|
||||
|
||||
test "it returns error when notification not found", %{conn: conn} do
|
||||
user1 = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user1)
|
||||
|> post("/api/pleroma/notifications/read", %{"id" => "22222222222222"})
|
||||
|> json_response(403)
|
||||
|
||||
assert response == %{"error" => "Cannot get notification"}
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT /api/pleroma/notification_settings" do
|
||||
|
|
@ -123,9 +195,64 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "GET /api/statusnet/config.json" do
|
||||
describe "GET /api/statusnet/config" do
|
||||
test "it returns config in xml format", %{conn: conn} do
|
||||
instance = Pleroma.Config.get(:instance)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get("/api/statusnet/config")
|
||||
|> response(:ok)
|
||||
|
||||
assert response ==
|
||||
"<config>\n<site>\n<name>#{Keyword.get(instance, :name)}</name>\n<site>#{
|
||||
Pleroma.Web.base_url()
|
||||
}</site>\n<textlimit>#{Keyword.get(instance, :limit)}</textlimit>\n<closed>#{
|
||||
!Keyword.get(instance, :registrations_open)
|
||||
}</closed>\n</site>\n</config>\n"
|
||||
end
|
||||
|
||||
test "it returns config in json format", %{conn: conn} do
|
||||
instance = Pleroma.Config.get(:instance)
|
||||
Pleroma.Config.put([:instance, :managed_config], true)
|
||||
Pleroma.Config.put([:instance, :registrations_open], false)
|
||||
Pleroma.Config.put([:instance, :invites_enabled], true)
|
||||
Pleroma.Config.put([:instance, :public], false)
|
||||
Pleroma.Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> get("/api/statusnet/config")
|
||||
|> json_response(:ok)
|
||||
|
||||
expected_data = %{
|
||||
"site" => %{
|
||||
"accountActivationRequired" => "0",
|
||||
"closed" => "1",
|
||||
"description" => Keyword.get(instance, :description),
|
||||
"invitesEnabled" => "1",
|
||||
"name" => Keyword.get(instance, :name),
|
||||
"pleromafe" => %{"theme" => "asuka-hospital"},
|
||||
"private" => "1",
|
||||
"safeDMMentionsEnabled" => "0",
|
||||
"server" => Pleroma.Web.base_url(),
|
||||
"textlimit" => to_string(Keyword.get(instance, :limit)),
|
||||
"uploadlimit" => %{
|
||||
"avatarlimit" => to_string(Keyword.get(instance, :avatar_upload_limit)),
|
||||
"backgroundlimit" => to_string(Keyword.get(instance, :background_upload_limit)),
|
||||
"bannerlimit" => to_string(Keyword.get(instance, :banner_upload_limit)),
|
||||
"uploadlimit" => to_string(Keyword.get(instance, :upload_limit))
|
||||
},
|
||||
"vapidPublicKey" => Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key)
|
||||
}
|
||||
}
|
||||
|
||||
assert response == expected_data
|
||||
end
|
||||
|
||||
test "returns the state of safe_dm_mentions flag", %{conn: conn} do
|
||||
option = Pleroma.Config.get([:instance, :safe_dm_mentions])
|
||||
Pleroma.Config.put([:instance, :safe_dm_mentions], true)
|
||||
|
||||
response =
|
||||
|
|
@ -143,8 +270,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|> json_response(:ok)
|
||||
|
||||
assert response["site"]["safeDMMentionsEnabled"] == "0"
|
||||
|
||||
Pleroma.Config.put([:instance, :safe_dm_mentions], option)
|
||||
end
|
||||
|
||||
test "it returns the managed config", %{conn: conn} do
|
||||
|
|
@ -210,7 +335,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "GET /ostatus_subscribe?acct=...." do
|
||||
describe "GET /ostatus_subscribe - remote_follow/2" do
|
||||
test "adds status to pleroma instance if the `acct` is a status", %{conn: conn} do
|
||||
conn =
|
||||
get(
|
||||
|
|
@ -230,18 +355,176 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|
||||
assert html_response(response, 200) =~ "Log in to follow"
|
||||
end
|
||||
|
||||
test "show follow page if the `acct` is a account link", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/ostatus_subscribe?acct=https://mastodon.social/users/emelie")
|
||||
|
||||
assert html_response(response, 200) =~ "Remote follow"
|
||||
end
|
||||
|
||||
test "show follow page with error when user cannot fecth by `acct` link", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/ostatus_subscribe?acct=https://mastodon.social/users/not_found")
|
||||
|
||||
assert html_response(response, 200) =~ "Error fetching user"
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /ostatus_subscribe - do_remote_follow/2 with assigned user " do
|
||||
test "follows user", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/ostatus_subscribe", %{"user" => %{"id" => user2.id}})
|
||||
|> response(200)
|
||||
|
||||
assert response =~ "Account followed!"
|
||||
assert user2.follower_address in refresh_record(user).following
|
||||
end
|
||||
|
||||
test "returns error when user is deactivated", %{conn: conn} do
|
||||
user = insert(:user, info: %{deactivated: true})
|
||||
user2 = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/ostatus_subscribe", %{"user" => %{"id" => user2.id}})
|
||||
|> response(200)
|
||||
|
||||
assert response =~ "Error following account"
|
||||
end
|
||||
|
||||
test "returns error when user is blocked", %{conn: conn} do
|
||||
Pleroma.Config.put([:user, :deny_follow_blocked], true)
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, _user} = Pleroma.User.block(user2, user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/ostatus_subscribe", %{"user" => %{"id" => user2.id}})
|
||||
|> response(200)
|
||||
|
||||
assert response =~ "Error following account"
|
||||
end
|
||||
|
||||
test "returns error when followee not found", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/ostatus_subscribe", %{"user" => %{"id" => "jimm"}})
|
||||
|> response(200)
|
||||
|
||||
assert response =~ "Error following account"
|
||||
end
|
||||
|
||||
test "returns success result when user already in followers", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
{:ok, _, _, _} = CommonAPI.follow(user, user2)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, refresh_record(user))
|
||||
|> post("/ostatus_subscribe", %{"user" => %{"id" => user2.id}})
|
||||
|> response(200)
|
||||
|
||||
assert response =~ "Account followed!"
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /ostatus_subscribe - do_remote_follow/2 without assigned user " do
|
||||
test "follows", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> post("/ostatus_subscribe", %{
|
||||
"authorization" => %{"name" => user.nickname, "password" => "test", "id" => user2.id}
|
||||
})
|
||||
|> response(200)
|
||||
|
||||
assert response =~ "Account followed!"
|
||||
assert user2.follower_address in refresh_record(user).following
|
||||
end
|
||||
|
||||
test "returns error when followee not found", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> post("/ostatus_subscribe", %{
|
||||
"authorization" => %{"name" => user.nickname, "password" => "test", "id" => "jimm"}
|
||||
})
|
||||
|> response(200)
|
||||
|
||||
assert response =~ "Error following account"
|
||||
end
|
||||
|
||||
test "returns error when login invalid", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> post("/ostatus_subscribe", %{
|
||||
"authorization" => %{"name" => "jimm", "password" => "test", "id" => user.id}
|
||||
})
|
||||
|> response(200)
|
||||
|
||||
assert response =~ "Wrong username or password"
|
||||
end
|
||||
|
||||
test "returns error when password invalid", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> post("/ostatus_subscribe", %{
|
||||
"authorization" => %{"name" => user.nickname, "password" => "42", "id" => user2.id}
|
||||
})
|
||||
|> response(200)
|
||||
|
||||
assert response =~ "Wrong username or password"
|
||||
end
|
||||
|
||||
test "returns error when user is blocked", %{conn: conn} do
|
||||
Pleroma.Config.put([:user, :deny_follow_blocked], true)
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
{:ok, _user} = Pleroma.User.block(user2, user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> post("/ostatus_subscribe", %{
|
||||
"authorization" => %{"name" => user.nickname, "password" => "test", "id" => user2.id}
|
||||
})
|
||||
|> response(200)
|
||||
|
||||
assert response =~ "Error following account"
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/healthcheck" do
|
||||
setup do
|
||||
config_healthcheck = Pleroma.Config.get([:instance, :healthcheck])
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :healthcheck], config_healthcheck)
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
clear_config([:instance, :healthcheck])
|
||||
|
||||
test "returns 503 when healthcheck disabled", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :healthcheck], false)
|
||||
|
|
@ -311,5 +594,104 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|
||||
assert user.info.deactivated == true
|
||||
end
|
||||
|
||||
test "it returns returns when password invalid", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/pleroma/disable_account", %{"password" => "test1"})
|
||||
|> json_response(:ok)
|
||||
|
||||
assert response == %{"error" => "Invalid password."}
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
refute user.info.deactivated
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/statusnet/version" do
|
||||
test "it returns version in xml format", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get("/api/statusnet/version")
|
||||
|> response(:ok)
|
||||
|
||||
assert response == "<version>#{Pleroma.Application.named_version()}</version>"
|
||||
end
|
||||
|
||||
test "it returns version in json format", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> get("/api/statusnet/version")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert response == "#{Pleroma.Application.named_version()}"
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /main/ostatus - remote_subscribe/2" do
|
||||
test "renders subscribe form", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> post("/main/ostatus", %{"nickname" => user.nickname, "profile" => ""})
|
||||
|> response(:ok)
|
||||
|
||||
refute response =~ "Could not find user"
|
||||
assert response =~ "Remotely follow #{user.nickname}"
|
||||
end
|
||||
|
||||
test "renders subscribe form with error when user not found", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> post("/main/ostatus", %{"nickname" => "nickname", "profile" => ""})
|
||||
|> response(:ok)
|
||||
|
||||
assert response =~ "Could not find user"
|
||||
refute response =~ "Remotely follow"
|
||||
end
|
||||
|
||||
test "it redirect to webfinger url", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user, ap_id: "shp@social.heldscal.la")
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> post("/main/ostatus", %{
|
||||
"user" => %{"nickname" => user.nickname, "profile" => user2.ap_id}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) ==
|
||||
"https://social.heldscal.la/main/ostatussub?profile=#{user.ap_id}"
|
||||
end
|
||||
|
||||
test "it renders form with error when use not found", %{conn: conn} do
|
||||
user2 = insert(:user, ap_id: "shp@social.heldscal.la")
|
||||
|
||||
response =
|
||||
conn
|
||||
|> post("/main/ostatus", %{"user" => %{"nickname" => "jimm", "profile" => user2.ap_id}})
|
||||
|> response(:ok)
|
||||
|
||||
assert response =~ "Something went wrong."
|
||||
end
|
||||
end
|
||||
|
||||
test "it returns new captcha", %{conn: conn} do
|
||||
with_mock Pleroma.Captcha,
|
||||
new: fn -> "test_captcha" end do
|
||||
resp =
|
||||
conn
|
||||
|> get("/api/pleroma/captcha")
|
||||
|> response(200)
|
||||
|
||||
assert resp == "\"test_captcha\""
|
||||
assert called(Pleroma.Captcha.new())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,15 +10,26 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
|||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
config_path = [:instance, :federating]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
Pleroma.Config.put(config_path, true)
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
clear_config_all([:instance, :federating]) do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
end
|
||||
|
||||
test "GET host-meta" do
|
||||
response =
|
||||
build_conn()
|
||||
|> get("/.well-known/host-meta")
|
||||
|
||||
assert response.status == 200
|
||||
|
||||
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()
|
||||
}/.well-known/webfinger?resource={uri}" type="application/xrd+xml" /></XRD>)
|
||||
end
|
||||
|
||||
test "Webfinger JRD" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -30,6 +41,16 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
|||
assert json_response(response, 200)["subject"] == "acct:#{user.nickname}@localhost"
|
||||
end
|
||||
|
||||
test "it returns 404 when user isn't found (JSON)" do
|
||||
result =
|
||||
build_conn()
|
||||
|> put_req_header("accept", "application/jrd+json")
|
||||
|> get("/.well-known/webfinger?resource=acct:jimm@localhost")
|
||||
|> json_response(404)
|
||||
|
||||
assert result == "Couldn't find user"
|
||||
end
|
||||
|
||||
test "Webfinger XML" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -41,6 +62,26 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
|||
assert response(response, 200)
|
||||
end
|
||||
|
||||
test "it returns 404 when user isn't found (XML)" do
|
||||
result =
|
||||
build_conn()
|
||||
|> put_req_header("accept", "application/xrd+xml")
|
||||
|> get("/.well-known/webfinger?resource=acct:jimm@localhost")
|
||||
|> response(404)
|
||||
|
||||
assert result == "Couldn't find user"
|
||||
end
|
||||
|
||||
test "Sends a 404 when invalid format" do
|
||||
user = insert(:user)
|
||||
|
||||
assert_raise Phoenix.NotAcceptableError, fn ->
|
||||
build_conn()
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
|
||||
end
|
||||
end
|
||||
|
||||
test "Sends a 400 when resource param is missing" do
|
||||
response =
|
||||
build_conn()
|
||||
|
|
|
|||
|
|
@ -40,6 +40,11 @@ defmodule Pleroma.Web.WebFingerTest do
|
|||
end
|
||||
|
||||
describe "fingering" do
|
||||
test "returns error when fails parse xml or json" do
|
||||
user = "invalid_content@social.heldscal.la"
|
||||
assert {:error, %Jason.DecodeError{}} = WebFinger.finger(user)
|
||||
end
|
||||
|
||||
test "returns the info for an OStatus user" do
|
||||
user = "shp@social.heldscal.la"
|
||||
|
||||
|
|
@ -81,6 +86,20 @@ defmodule Pleroma.Web.WebFingerTest do
|
|||
assert data["subscribe_address"] == "https://gnusocial.de/main/ostatussub?profile={uri}"
|
||||
end
|
||||
|
||||
test "it work for AP-only user" do
|
||||
user = "kpherox@mstdn.jp"
|
||||
|
||||
{:ok, data} = WebFinger.finger(user)
|
||||
|
||||
assert data["magic_key"] == nil
|
||||
assert data["salmon"] == nil
|
||||
|
||||
assert data["topic"] == "https://mstdn.jp/users/kPherox.atom"
|
||||
assert data["subject"] == "acct:kPherox@mstdn.jp"
|
||||
assert data["ap_id"] == "https://mstdn.jp/users/kPherox"
|
||||
assert data["subscribe_address"] == "https://mstdn.jp/authorize_interaction?acct={uri}"
|
||||
end
|
||||
|
||||
test "it works for friendica" do
|
||||
user = "lain@squeet.me"
|
||||
|
||||
|
|
|
|||
|
|
@ -9,14 +9,8 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
|
|||
alias Pleroma.Web.Websub
|
||||
alias Pleroma.Web.Websub.WebsubClientSubscription
|
||||
|
||||
setup_all do
|
||||
config_path = [:instance, :federating]
|
||||
initial_setting = Pleroma.Config.get(config_path)
|
||||
|
||||
Pleroma.Config.put(config_path, true)
|
||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
||||
|
||||
:ok
|
||||
clear_config_all([:instance, :federating]) do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
end
|
||||
|
||||
test "websub subscription request", %{conn: conn} do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue