summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/activity_test.exs69
-rw-r--r--test/bbs/handler_test.exs12
-rw-r--r--test/bookmark_test.exs4
-rw-r--r--test/config/transfer_task_test.exs57
-rw-r--r--test/conversation/participation_test.exs16
-rw-r--r--test/conversation_test.exs10
-rw-r--r--test/emails/admin_email_test.exs37
-rw-r--r--test/emails/mailer_test.exs57
-rw-r--r--test/emails/user_email_test.exs48
-rw-r--r--test/emoji_test.exs4
-rw-r--r--test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml5
-rw-r--r--test/fixtures/lain.xml12
-rw-r--r--test/fixtures/mastodon-delete-user.json24
-rw-r--r--test/fixtures/mastodon-question-activity.json99
-rw-r--r--test/fixtures/mastodon-vote.json16
-rw-r--r--test/fixtures/rich_media/non_ogp_embed.html1479
-rw-r--r--test/fixtures/rich_media/ogp-missing-data.html8
-rw-r--r--test/fixtures/rich_media/ogp-missing-title.html12
-rw-r--r--test/fixtures/rich_media/ogp.html1
-rw-r--r--test/fixtures/tesla_mock/7369654.atom (renamed from test/fixtures/httpoison_mock/7369654.atom)0
-rw-r--r--test/fixtures/tesla_mock/7369654.html (renamed from test/fixtures/httpoison_mock/7369654.html)0
-rw-r--r--test/fixtures/tesla_mock/7even.json (renamed from test/fixtures/httpoison_mock/7even.json)0
-rw-r--r--test/fixtures/tesla_mock/admin@mastdon.example.org.json (renamed from test/fixtures/httpoison_mock/admin@mastdon.example.org.json)0
-rw-r--r--test/fixtures/tesla_mock/atarifrosch_feed.xml (renamed from test/fixtures/httpoison_mock/atarifrosch_feed.xml)0
-rw-r--r--test/fixtures/tesla_mock/atarifrosch_webfinger.xml (renamed from test/fixtures/httpoison_mock/atarifrosch_webfinger.xml)0
-rw-r--r--test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json (renamed from test/fixtures/httpoison_mock/baptiste.gelex.xyz-article.json)0
-rw-r--r--test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json (renamed from test/fixtures/httpoison_mock/baptiste.gelex.xyz-user.json)0
-rw-r--r--test/fixtures/tesla_mock/eal_sakamoto.xml (renamed from test/fixtures/httpoison_mock/eal_sakamoto.xml)0
-rw-r--r--test/fixtures/tesla_mock/emelie.atom (renamed from test/fixtures/httpoison_mock/emelie.atom)0
-rw-r--r--test/fixtures/tesla_mock/emelie.json1
-rw-r--r--test/fixtures/tesla_mock/framasoft@framatube.org.json (renamed from test/fixtures/httpoison_mock/framasoft@framatube.org.json)0
-rw-r--r--test/fixtures/tesla_mock/framatube.org_host_meta (renamed from test/fixtures/httpoison_mock/framatube.org_host_meta)0
-rw-r--r--test/fixtures/tesla_mock/gerzilla.de_host_meta (renamed from test/fixtures/httpoison_mock/gerzilla.de_host_meta)0
-rw-r--r--test/fixtures/tesla_mock/gnusocial.de_host_meta (renamed from test/fixtures/httpoison_mock/gnusocial.de_host_meta)0
-rw-r--r--test/fixtures/tesla_mock/gs.example.org_host_meta (renamed from test/fixtures/httpoison_mock/gs.example.org_host_meta)0
-rw-r--r--test/fixtures/tesla_mock/hellpie.json (renamed from test/fixtures/httpoison_mock/hellpie.json)0
-rw-r--r--test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml (renamed from test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml)0
-rw-r--r--test/fixtures/tesla_mock/http___mastodon.example.org_users_admin_status_1234.json (renamed from test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json)0
-rw-r--r--test/fixtures/tesla_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml (renamed from test/fixtures/httpoison_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml)0
-rw-r--r--test/fixtures/tesla_mock/https___info.pleroma.site_actor.json (renamed from test/fixtures/httpoison_mock/https___info.pleroma.site_actor.json)0
-rw-r--r--test/fixtures/tesla_mock/https___mamot.fr_users_Skruyb.atom (renamed from test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom)0
-rw-r--r--test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.atom (renamed from test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.atom)0
-rw-r--r--test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml (renamed from test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml)0
-rw-r--r--test/fixtures/tesla_mock/https___osada.macgirvin.com_channel_mike.json (renamed from test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json)0
-rw-r--r--test/fixtures/tesla_mock/https___pawoo.net_users_aqidaqidaqid.xml (renamed from test/fixtures/httpoison_mock/https___pawoo.net_users_aqidaqidaqid.xml)0
-rw-r--r--test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.atom (renamed from test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.atom)0
-rw-r--r--test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.xml (renamed from test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml)0
-rw-r--r--test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml (renamed from test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml)0
-rw-r--r--test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml (renamed from test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml)0
-rw-r--r--test/fixtures/tesla_mock/https___prismo.news__mxb.json (renamed from test/fixtures/httpoison_mock/https___prismo.news__mxb.json)0
-rw-r--r--test/fixtures/tesla_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml (renamed from test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml)0
-rw-r--r--test/fixtures/tesla_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml (renamed from test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml)0
-rw-r--r--test/fixtures/tesla_mock/https___shitposter.club_notice_2827873.html (renamed from test/fixtures/httpoison_mock/https___shitposter.club_notice_2827873.html)0
-rw-r--r--test/fixtures/tesla_mock/https___shitposter.club_user_1.xml (renamed from test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml)0
-rw-r--r--test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml (renamed from test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml)0
-rw-r--r--test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml (renamed from test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml)0
-rw-r--r--test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml (renamed from test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml)0
-rw-r--r--test/fixtures/tesla_mock/https___social.heldscal.la_user_29191.xml (renamed from test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml)0
-rw-r--r--test/fixtures/tesla_mock/https__info.pleroma.site_activity.json (renamed from test/fixtures/httpoison_mock/https__info.pleroma.site_activity.json)0
-rw-r--r--test/fixtures/tesla_mock/https__info.pleroma.site_activity2.json (renamed from test/fixtures/httpoison_mock/https__info.pleroma.site_activity2.json)0
-rw-r--r--test/fixtures/tesla_mock/https__info.pleroma.site_activity3.json (renamed from test/fixtures/httpoison_mock/https__info.pleroma.site_activity3.json)0
-rw-r--r--test/fixtures/tesla_mock/https__info.pleroma.site_activity4.json (renamed from test/fixtures/httpoison_mock/https__info.pleroma.site_activity4.json)0
-rw-r--r--test/fixtures/tesla_mock/kaniini@gerzilla.de.json (renamed from test/fixtures/httpoison_mock/kaniini@gerzilla.de.json)0
-rw-r--r--test/fixtures/tesla_mock/kaniini@hubzilla.example.org.json (renamed from test/fixtures/httpoison_mock/kaniini@hubzilla.example.org.json)0
-rw-r--r--test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml (renamed from test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml)0
-rw-r--r--test/fixtures/tesla_mock/lucifermysticus.json (renamed from test/fixtures/httpoison_mock/lucifermysticus.json)0
-rw-r--r--test/fixtures/tesla_mock/macgirvin.com_host_meta (renamed from test/fixtures/httpoison_mock/macgirvin.com_host_meta)0
-rw-r--r--test/fixtures/tesla_mock/mamot.fr_host_meta (renamed from test/fixtures/httpoison_mock/mamot.fr_host_meta)0
-rw-r--r--test/fixtures/tesla_mock/mastodon.social_host_meta (renamed from test/fixtures/httpoison_mock/mastodon.social_host_meta)0
-rw-r--r--test/fixtures/tesla_mock/mastodon.xyz_host_meta (renamed from test/fixtures/httpoison_mock/mastodon.xyz_host_meta)0
-rw-r--r--test/fixtures/tesla_mock/mayumayu.json (renamed from test/fixtures/httpoison_mock/mayumayu.json)0
-rw-r--r--test/fixtures/tesla_mock/mayumayupost.json (renamed from test/fixtures/httpoison_mock/mayumayupost.json)0
-rw-r--r--test/fixtures/tesla_mock/mike@osada.macgirvin.com.json (renamed from test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json)0
-rw-r--r--test/fixtures/tesla_mock/nonexistant@social.heldscal.la.xml (renamed from test/fixtures/httpoison_mock/nonexistant@social.heldscal.la.xml)0
-rw-r--r--test/fixtures/tesla_mock/pawoo.net_host_meta (renamed from test/fixtures/httpoison_mock/pawoo.net_host_meta)0
-rw-r--r--test/fixtures/tesla_mock/peertube.moe-vid.json (renamed from test/fixtures/httpoison_mock/peertube.moe-vid.json)0
-rw-r--r--test/fixtures/tesla_mock/pleroma.soykaf.com_host_meta (renamed from test/fixtures/httpoison_mock/pleroma.soykaf.com_host_meta)0
-rw-r--r--test/fixtures/tesla_mock/puckipedia.com.json (renamed from test/fixtures/httpoison_mock/puckipedia.com.json)0
-rw-r--r--test/fixtures/tesla_mock/rinpatch.json64
-rw-r--r--test/fixtures/tesla_mock/rye.json (renamed from test/fixtures/httpoison_mock/rye.json)0
-rw-r--r--test/fixtures/tesla_mock/sakamoto.atom (renamed from test/fixtures/httpoison_mock/sakamoto.atom)0
-rw-r--r--test/fixtures/tesla_mock/sakamoto_eal_feed.atom (renamed from test/fixtures/httpoison_mock/sakamoto_eal_feed.atom)0
-rw-r--r--test/fixtures/tesla_mock/shitposter.club_host_meta (renamed from test/fixtures/httpoison_mock/shitposter.club_host_meta)0
-rw-r--r--test/fixtures/tesla_mock/shp@pleroma.soykaf.com.feed (renamed from test/fixtures/httpoison_mock/shp@pleroma.soykaf.com.feed)0
-rw-r--r--test/fixtures/tesla_mock/shp@pleroma.soykaf.com.webfigner (renamed from test/fixtures/httpoison_mock/shp@pleroma.soykaf.com.webfigner)0
-rw-r--r--test/fixtures/tesla_mock/shp@social.heldscal.la.xml (renamed from test/fixtures/httpoison_mock/shp@social.heldscal.la.xml)0
-rw-r--r--test/fixtures/tesla_mock/skruyb@mamot.fr.atom (renamed from test/fixtures/httpoison_mock/skruyb@mamot.fr.atom)0
-rw-r--r--test/fixtures/tesla_mock/social.heldscal.la_host_meta (renamed from test/fixtures/httpoison_mock/social.heldscal.la_host_meta)0
-rw-r--r--test/fixtures/tesla_mock/social.sakamoto.gq_host_meta (renamed from test/fixtures/httpoison_mock/social.sakamoto.gq_host_meta)0
-rw-r--r--test/fixtures/tesla_mock/social.stopwatchingus-heidelberg.de_host_meta (renamed from test/fixtures/httpoison_mock/social.stopwatchingus-heidelberg.de_host_meta)0
-rw-r--r--test/fixtures/tesla_mock/social.wxcafe.net_host_meta (renamed from test/fixtures/httpoison_mock/social.wxcafe.net_host_meta)0
-rw-r--r--test/fixtures/tesla_mock/spc_5381.atom (renamed from test/fixtures/httpoison_mock/spc_5381.atom)0
-rw-r--r--test/fixtures/tesla_mock/spc_5381_xrd.xml (renamed from test/fixtures/httpoison_mock/spc_5381_xrd.xml)0
-rw-r--r--test/fixtures/tesla_mock/squeet.me_host_meta (renamed from test/fixtures/httpoison_mock/squeet.me_host_meta)0
-rw-r--r--test/fixtures/tesla_mock/status.alpicola.com_host_meta (renamed from test/fixtures/httpoison_mock/status.alpicola.com_host_meta)0
-rw-r--r--test/fixtures/tesla_mock/status.emelie.json (renamed from test/fixtures/httpoison_mock/status.emelie.json)0
-rw-r--r--test/fixtures/tesla_mock/webfinger_emelie.json (renamed from test/fixtures/httpoison_mock/webfinger_emelie.json)0
-rw-r--r--test/fixtures/tesla_mock/winterdienst_webfinger.json (renamed from test/fixtures/httpoison_mock/winterdienst_webfinger.json)0
-rw-r--r--test/fixtures/users_mock/masto_closed_followers.json7
-rw-r--r--test/fixtures/users_mock/masto_closed_following.json7
-rw-r--r--test/fixtures/users_mock/pleroma_followers.json20
-rw-r--r--test/fixtures/users_mock/pleroma_following.json20
-rw-r--r--test/healthcheck_test.exs4
-rw-r--r--test/html_test.exs69
-rw-r--r--test/http/request_builder_test.exs95
-rw-r--r--test/integration/mastodon_websocket_test.exs17
-rw-r--r--test/keys_test.exs4
-rw-r--r--test/list_test.exs26
-rw-r--r--test/notification_test.exs200
-rw-r--r--test/object/containment_test.exs45
-rw-r--r--test/object/fetcher_test.exs60
-rw-r--r--test/plugs/idempotency_plug_test.exs110
-rw-r--r--test/plugs/rate_limit_plug_test.exs50
-rw-r--r--test/plugs/rate_limiter_test.exs174
-rw-r--r--test/plugs/set_locale_plug_test.exs46
-rw-r--r--test/repo_test.exs4
-rw-r--r--test/reverse_proxy_test.exs300
-rw-r--r--test/signature_test.exs99
-rw-r--r--test/support/factory.ex23
-rw-r--r--test/support/helpers.ex6
-rw-r--r--test/support/http_request_mock.ex336
-rw-r--r--test/tasks/config_test.exs67
-rw-r--r--test/tasks/ecto/ecto_test.exs15
-rw-r--r--test/tasks/ecto/migrate_test.exs20
-rw-r--r--test/tasks/ecto/rollback_test.exs20
-rw-r--r--test/tasks/instance_test.exs (renamed from test/tasks/instance.exs)22
-rw-r--r--test/tasks/pleroma_test.exs50
-rw-r--r--test/tasks/robots_txt_test.exs47
-rw-r--r--test/tasks/user_test.exs24
-rw-r--r--test/test_helper.exs2
-rw-r--r--test/upload/filter/anonymize_filename_test.exs44
-rw-r--r--test/user_invite_token_test.exs4
-rw-r--r--test/user_search_test.exs304
-rw-r--r--test/user_test.exs292
-rw-r--r--test/web/activity_pub/activity_pub_controller_test.exs169
-rw-r--r--test/web/activity_pub/activity_pub_test.exs95
-rw-r--r--test/web/activity_pub/mrf/anti_link_spam_policy_test.exs145
-rw-r--r--test/web/activity_pub/mrf/ensure_re_prepended_test.exs82
-rw-r--r--test/web/activity_pub/mrf/mediaproxy_warming_policy_test.exs45
-rw-r--r--test/web/activity_pub/mrf/no_placeholder_text_policy_test.exs37
-rw-r--r--test/web/activity_pub/mrf/normalize_markup_test.exs42
-rw-r--r--test/web/activity_pub/mrf/reject_non_public_test.exs105
-rw-r--r--test/web/activity_pub/mrf/subchain_policy_test.exs32
-rw-r--r--test/web/activity_pub/mrf/tag_policy_test.exs123
-rw-r--r--test/web/activity_pub/mrf/user_allowlist_policy_test.exs36
-rw-r--r--test/web/activity_pub/transmogrifier/follow_handling_test.exs143
-rw-r--r--test/web/activity_pub/transmogrifier_test.exs342
-rw-r--r--test/web/activity_pub/utils_test.exs95
-rw-r--r--test/web/activity_pub/views/object_view_test.exs14
-rw-r--r--test/web/activity_pub/views/user_view_test.exs29
-rw-r--r--test/web/activity_pub/visibilty_test.exs121
-rw-r--r--test/web/admin_api/admin_api_controller_test.exs661
-rw-r--r--test/web/admin_api/config_test.exs465
-rw-r--r--test/web/admin_api/views/report_view_test.exs130
-rw-r--r--test/web/common_api/common_api_test.exs139
-rw-r--r--test/web/common_api/common_api_utils_test.exs152
-rw-r--r--test/web/federator_test.exs7
-rw-r--r--test/web/mastodon_api/account_view_test.exs50
-rw-r--r--test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs304
-rw-r--r--test/web/mastodon_api/mastodon_api_controller_test.exs1536
-rw-r--r--test/web/mastodon_api/search_controller_test.exs267
-rw-r--r--test/web/mastodon_api/status_view_test.exs239
-rw-r--r--test/web/media_proxy/media_proxy_controller_test.exs73
-rw-r--r--test/web/media_proxy/media_proxy_test.exs (renamed from test/media_proxy_test.exs)76
-rw-r--r--test/web/metadata/player_view_test.exs33
-rw-r--r--test/web/metadata/rel_me_test.exs4
-rw-r--r--test/web/metadata/twitter_card_test.exs123
-rw-r--r--test/web/node_info_test.exs43
-rw-r--r--test/web/oauth/oauth_controller_test.exs183
-rw-r--r--test/web/ostatus/activity_representer_test.exs19
-rw-r--r--test/web/ostatus/incoming_documents/delete_handling_test.exs13
-rw-r--r--test/web/ostatus/ostatus_controller_test.exs20
-rw-r--r--test/web/ostatus/ostatus_test.exs72
-rw-r--r--test/web/plugs/federating_plug_test.exs23
-rw-r--r--test/web/rel_me_test.exs4
-rw-r--r--test/web/rich_media/helpers_test.exs51
-rw-r--r--test/web/rich_media/parser_test.exs39
-rw-r--r--test/web/streamer_test.exs230
-rw-r--r--test/web/twitter_api/password_controller_test.exs60
-rw-r--r--test/web/twitter_api/twitter_api_controller_test.exs144
-rw-r--r--test/web/twitter_api/twitter_api_test.exs18
-rw-r--r--test/web/twitter_api/util_controller_test.exs13
-rw-r--r--test/web/twitter_api/views/activity_view_test.exs6
-rw-r--r--test/web/twitter_api/views/user_view_test.exs14
-rw-r--r--test/web/web_finger/web_finger_controller_test.exs6
-rw-r--r--test/web/web_finger/web_finger_test.exs11
-rw-r--r--test/web/websub/websub_controller_test.exs10
187 files changed, 10308 insertions, 1253 deletions
diff --git a/test/activity_test.exs b/test/activity_test.exs
index 15c95502a..b27f6fd36 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -6,6 +6,7 @@ defmodule Pleroma.ActivityTest do
use Pleroma.DataCase
alias Pleroma.Activity
alias Pleroma.Bookmark
+ alias Pleroma.Object
alias Pleroma.ThreadMute
import Pleroma.Factory
@@ -18,15 +19,18 @@ defmodule Pleroma.ActivityTest do
test "returns activities by it's objects AP ids" do
activity = insert(:note_activity)
- [found_activity] = Activity.get_all_create_by_object_ap_id(activity.data["object"]["id"])
+ object_data = Object.normalize(activity).data
+
+ [found_activity] = Activity.get_all_create_by_object_ap_id(object_data["id"])
assert activity == found_activity
end
test "returns the activity that created an object" do
activity = insert(:note_activity)
+ object_data = Object.normalize(activity).data
- found_activity = Activity.get_create_by_object_ap_id(activity.data["object"]["id"])
+ found_activity = Activity.get_create_by_object_ap_id(object_data["id"])
assert activity == found_activity
end
@@ -99,4 +103,65 @@ defmodule Pleroma.ActivityTest do
assert Activity.get_bookmark(queried_activity, user) == bookmark
end
end
+
+ describe "search" do
+ setup do
+ Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+
+ user = insert(:user)
+
+ params = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "actor" => "http://mastodon.example.org/users/admin",
+ "type" => "Create",
+ "id" => "http://mastodon.example.org/users/admin/activities/1",
+ "object" => %{
+ "type" => "Note",
+ "content" => "find me!",
+ "id" => "http://mastodon.example.org/users/admin/objects/1",
+ "attributedTo" => "http://mastodon.example.org/users/admin"
+ },
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"]
+ }
+
+ {:ok, local_activity} = Pleroma.Web.CommonAPI.post(user, %{"status" => "find me!"})
+ {:ok, remote_activity} = Pleroma.Web.Federator.incoming_ap_doc(params)
+ %{local_activity: local_activity, remote_activity: remote_activity, user: user}
+ end
+
+ test "find local and remote statuses for authenticated users", %{
+ local_activity: local_activity,
+ remote_activity: remote_activity,
+ user: user
+ } do
+ activities = Enum.sort_by(Activity.search(user, "find me"), & &1.id)
+
+ assert [^local_activity, ^remote_activity] = activities
+ end
+
+ test "find only local statuses for unauthenticated users", %{local_activity: local_activity} do
+ assert [^local_activity] = Activity.search(nil, "find me")
+ end
+
+ test "find only local statuses for unauthenticated users when `limit_to_local_content` is `:all`",
+ %{local_activity: local_activity} do
+ Pleroma.Config.put([:instance, :limit_to_local_content], :all)
+ assert [^local_activity] = Activity.search(nil, "find me")
+ Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ end
+
+ test "find all statuses for unauthenticated users when `limit_to_local_content` is `false`",
+ %{
+ local_activity: local_activity,
+ remote_activity: remote_activity
+ } do
+ Pleroma.Config.put([:instance, :limit_to_local_content], false)
+
+ activities = Enum.sort_by(Activity.search(nil, "find me"), & &1.id)
+
+ assert [^local_activity, ^remote_activity] = activities
+
+ Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ end
+ end
end
diff --git a/test/bbs/handler_test.exs b/test/bbs/handler_test.exs
index 7d5d68d11..4f0c13417 100644
--- a/test/bbs/handler_test.exs
+++ b/test/bbs/handler_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.BBS.HandlerTest do
use Pleroma.DataCase
alias Pleroma.Activity
@@ -59,6 +63,7 @@ defmodule Pleroma.BBS.HandlerTest do
another_user = insert(:user)
{:ok, activity} = CommonAPI.post(another_user, %{"status" => "this is a test post"})
+ activity_object = Object.normalize(activity)
output =
capture_io(fn ->
@@ -76,8 +81,9 @@ defmodule Pleroma.BBS.HandlerTest do
)
assert reply.actor == user.ap_id
- object = Object.normalize(reply)
- assert object.data["content"] == "this is a reply"
- assert object.data["inReplyTo"] == activity.data["object"]
+
+ reply_object_data = Object.normalize(reply).data
+ assert reply_object_data["content"] == "this is a reply"
+ assert reply_object_data["inReplyTo"] == activity_object.data["id"]
end
end
diff --git a/test/bookmark_test.exs b/test/bookmark_test.exs
index b81c102ef..e54bd359c 100644
--- a/test/bookmark_test.exs
+++ b/test/bookmark_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.BookmarkTest do
use Pleroma.DataCase
import Pleroma.Factory
diff --git a/test/config/transfer_task_test.exs b/test/config/transfer_task_test.exs
new file mode 100644
index 000000000..dbeadbe87
--- /dev/null
+++ b/test/config/transfer_task_test.exs
@@ -0,0 +1,57 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Config.TransferTaskTest do
+ use Pleroma.DataCase
+
+ setup do
+ 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)
+ end
+
+ test "transfer config values from db to env" do
+ refute Application.get_env(:pleroma, :test_key)
+ refute Application.get_env(:idna, :test_key)
+
+ Pleroma.Web.AdminAPI.Config.create(%{
+ group: "pleroma",
+ key: "test_key",
+ value: [live: 2, com: 3]
+ })
+
+ Pleroma.Web.AdminAPI.Config.create(%{
+ group: "idna",
+ key: "test_key",
+ value: [live: 15, com: 35]
+ })
+
+ 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]
+
+ on_exit(fn ->
+ Application.delete_env(:pleroma, :test_key)
+ Application.delete_env(:idna, :test_key)
+ end)
+ end
+
+ test "non existing atom" do
+ Pleroma.Web.AdminAPI.Config.create(%{
+ group: "pleroma",
+ key: "undefined_atom_key",
+ value: [live: 2, com: 3]
+ })
+
+ assert ExUnit.CaptureLog.capture_log(fn ->
+ Pleroma.Config.TransferTask.start_link()
+ end) =~
+ "updating env causes error, key: \"undefined_atom_key\", error: %ArgumentError{message: \"argument error\"}"
+ end
+end
diff --git a/test/conversation/participation_test.exs b/test/conversation/participation_test.exs
index 568953b07..2a03e5d67 100644
--- a/test/conversation/participation_test.exs
+++ b/test/conversation/participation_test.exs
@@ -72,8 +72,11 @@ defmodule Pleroma.Conversation.ParticipationTest do
object2 = Pleroma.Object.normalize(activity_two)
object3 = Pleroma.Object.normalize(activity_three)
+ user = Repo.get(Pleroma.User, user.id)
+
assert participation_one.conversation.ap_id == object3.data["context"]
assert participation_two.conversation.ap_id == object2.data["context"]
+ assert participation_one.conversation.users == [user]
# Pagination
assert [participation_one] = Participation.for_user(user, %{"limit" => 1})
@@ -86,4 +89,17 @@ defmodule Pleroma.Conversation.ParticipationTest do
assert participation_one.last_activity_id == activity_three.id
end
+
+ test "Doesn't die when the conversation gets empty" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+ [participation] = Participation.for_user_with_last_activity_id(user)
+
+ assert participation.last_activity_id == activity.id
+
+ {:ok, _} = CommonAPI.delete(activity.id, user)
+
+ [] = Participation.for_user_with_last_activity_id(user)
+ end
end
diff --git a/test/conversation_test.exs b/test/conversation_test.exs
index 5903d10ff..aa193e0d4 100644
--- a/test/conversation_test.exs
+++ b/test/conversation_test.exs
@@ -11,6 +11,16 @@ 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
+ end
+
test "it goes through old direct conversations" do
user = insert(:user)
other_user = insert(:user)
diff --git a/test/emails/admin_email_test.exs b/test/emails/admin_email_test.exs
new file mode 100644
index 000000000..4bf54b0c2
--- /dev/null
+++ b/test/emails/admin_email_test.exs
@@ -0,0 +1,37 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Emails.AdminEmailTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+
+ alias Pleroma.Emails.AdminEmail
+ alias Pleroma.Web.Router.Helpers
+
+ test "build report email" do
+ config = Pleroma.Config.get(:instance)
+ to_user = insert(:user)
+ reporter = insert(:user)
+ account = insert(:user)
+
+ res =
+ AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment")
+
+ status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, "12")
+ reporter_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, reporter.nickname)
+ account_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, account.nickname)
+
+ 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 ==
+ "<p>Reported by: <a href=\"#{reporter_url}\">#{reporter.nickname}</a></p>\n<p>Reported Account: <a href=\"#{
+ account_url
+ }\">#{account.nickname}</a></p>\n<p>Comment: Test comment\n<p> Statuses:\n <ul>\n <li><a href=\"#{
+ status_url
+ }\">#{status_url}</li>\n </ul>\n</p>\n\n"
+ end
+end
diff --git a/test/emails/mailer_test.exs b/test/emails/mailer_test.exs
new file mode 100644
index 000000000..450bb09c7
--- /dev/null
+++ b/test/emails/mailer_test.exs
@@ -0,0 +1,57 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Emails.MailerTest do
+ use Pleroma.DataCase
+ alias Pleroma.Emails.Mailer
+
+ import Swoosh.TestAssertions
+
+ @email %Swoosh.Email{
+ from: {"Pleroma", "noreply@example.com"},
+ html_body: "Test email",
+ subject: "Pleroma test email",
+ 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
+
+ test "not send email when mailer is disabled" do
+ Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
+ Mailer.deliver(@email)
+
+ refute_email_sent(
+ from: {"Pleroma", "noreply@example.com"},
+ to: [{"Test User", "user1@example.com"}],
+ html_body: "Test email",
+ subject: "Pleroma test email"
+ )
+ end
+
+ test "send email" do
+ Mailer.deliver(@email)
+
+ assert_email_sent(
+ from: {"Pleroma", "noreply@example.com"},
+ to: [{"Test User", "user1@example.com"}],
+ html_body: "Test email",
+ subject: "Pleroma test email"
+ )
+ end
+
+ test "perform" do
+ Mailer.perform(:deliver_async, @email, [])
+
+ assert_email_sent(
+ from: {"Pleroma", "noreply@example.com"},
+ to: [{"Test User", "user1@example.com"}],
+ html_body: "Test email",
+ subject: "Pleroma test email"
+ )
+ end
+end
diff --git a/test/emails/user_email_test.exs b/test/emails/user_email_test.exs
new file mode 100644
index 000000000..7d8df6abc
--- /dev/null
+++ b/test/emails/user_email_test.exs
@@ -0,0 +1,48 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Emails.UserEmailTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Emails.UserEmail
+ alias Pleroma.Web.Endpoint
+ alias Pleroma.Web.Router
+
+ import Pleroma.Factory
+
+ test "build password reset email" do
+ config = Pleroma.Config.get(:instance)
+ user = insert(:user)
+ email = UserEmail.password_reset_email(user, "test_token")
+ assert email.from == {config[:name], config[:notify_email]}
+ assert email.to == [{user.name, user.email}]
+ assert email.subject == "Password reset"
+ assert email.html_body =~ Router.Helpers.reset_password_url(Endpoint, :reset, "test_token")
+ end
+
+ test "build user invitation email" do
+ config = Pleroma.Config.get(:instance)
+ user = insert(:user)
+ token = %Pleroma.UserInviteToken{token: "test-token"}
+ email = UserEmail.user_invitation_email(user, token, "test@test.com", "Jonh")
+ assert email.from == {config[:name], config[:notify_email]}
+ assert email.subject == "Invitation to Pleroma"
+ assert email.to == [{"Jonh", "test@test.com"}]
+
+ assert email.html_body =~
+ Router.Helpers.redirect_url(Endpoint, :registration_page, token.token)
+ end
+
+ test "build account confirmation email" do
+ config = Pleroma.Config.get(:instance)
+ user = insert(:user, info: %Pleroma.User.Info{confirmation_token: "conf-token"})
+ email = UserEmail.account_confirmation_email(user)
+ assert email.from == {config[:name], config[:notify_email]}
+ assert email.to == [{user.name, user.email}]
+ assert email.subject == "#{config[:name]} account confirmation"
+
+ assert email.html_body =~
+ Router.Helpers.confirm_email_url(Endpoint, :confirm_email, user.id, "conf-token")
+ end
+end
diff --git a/test/emoji_test.exs b/test/emoji_test.exs
index 2eaa26be6..07ac6ff1d 100644
--- a/test/emoji_test.exs
+++ b/test/emoji_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.EmojiTest do
use ExUnit.Case, async: true
alias Pleroma.Emoji
diff --git a/test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml b/test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml
new file mode 100644
index 000000000..df64d44b0
--- /dev/null
+++ b/test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<XRD
+ xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
+ <Link rel="lrdd" template="https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource={uri}" type="application/xrd+xml" />
+</XRD>
diff --git a/test/fixtures/lain.xml b/test/fixtures/lain.xml
new file mode 100644
index 000000000..332b3b28d
--- /dev/null
+++ b/test/fixtures/lain.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<XRD
+ xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
+ <Subject>acct:lain@zetsubou.xn--q9jyb4c</Subject>
+ <Alias>https://zetsubou.xn--q9jyb4c/users/lain</Alias>
+ <Link href="https://zetsubou.xn--q9jyb4c/users/lain/feed.atom" rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" />
+ <Link href="https://zetsubou.xn--q9jyb4c/users/lain" rel="http://webfinger.net/rel/profile-page" type="text/html" />
+ <Link href="https://zetsubou.xn--q9jyb4c/users/lain/salmon" rel="salmon" />
+ <Link href="data:application/magic-public-key,RSA.7yTJNuPH7wSsg6sMH4XLi-OL6JL8idyRMwNsWy2xzKWPJRWVK5hxG1kMGQ4qC_9ksqIaT7c7DIQFJYYbhRTnXYdac1UxaWivzl5l2HYPOOF1_-gbE6TCaI4ItTQo5eB4yyy3zozrIuv_GY8W0Ww58Re8Z_G4DFFmnipgiBKNaHthxNQqtxcK-o4rUv3xdyr_M9KYi3QISCGiaV_t8xkdVREixzNmWpsqM5YZ46xXT0SiGSHDubLE_OGhyvWqf_WkJrnDBETL3WjXU4QsPmBbVBgLvLcHei_uAD-9d3QImSuWwBXXQZIzY7Diro6u8dZuPIoLmnbUp1-mViBwCUMWSQ==.AQAB" rel="magic-public-key" />
+ <Link href="https://zetsubou.xn--q9jyb4c/users/lain" rel="self" type="application/activity+json" />
+ <Link rel="http://ostatus.org/schema/1.0/subscribe" template="https://zetsubou.xn--q9jyb4c/ostatus_subscribe?acct={uri}" />
+</XRD>
diff --git a/test/fixtures/mastodon-delete-user.json b/test/fixtures/mastodon-delete-user.json
new file mode 100644
index 000000000..f19088fec
--- /dev/null
+++ b/test/fixtures/mastodon-delete-user.json
@@ -0,0 +1,24 @@
+{
+ "type": "Delete",
+ "object": {
+ "type": "Person",
+ "id": "http://mastodon.example.org/users/admin",
+ "atomUri": "http://mastodon.example.org/users/admin"
+ },
+ "id": "http://mastodon.example.org/users/admin#delete",
+ "actor": "http://mastodon.example.org/users/admin",
+ "@context": [
+ {
+ "toot": "http://joinmastodon.org/ns#",
+ "sensitive": "as:sensitive",
+ "ostatus": "http://ostatus.org#",
+ "movedTo": "as:movedTo",
+ "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+ "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+ "conversation": "ostatus:conversation",
+ "atomUri": "ostatus:atomUri",
+ "Hashtag": "as:Hashtag",
+ "Emoji": "toot:Emoji"
+ }
+ ]
+}
diff --git a/test/fixtures/mastodon-question-activity.json b/test/fixtures/mastodon-question-activity.json
new file mode 100644
index 000000000..ac329c7d5
--- /dev/null
+++ b/test/fixtures/mastodon-question-activity.json
@@ -0,0 +1,99 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ {
+ "ostatus": "http://ostatus.org#",
+ "atomUri": "ostatus:atomUri",
+ "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+ "conversation": "ostatus:conversation",
+ "sensitive": "as:sensitive",
+ "Hashtag": "as:Hashtag",
+ "toot": "http://joinmastodon.org/ns#",
+ "Emoji": "toot:Emoji",
+ "focalPoint": {
+ "@container": "@list",
+ "@id": "toot:focalPoint"
+ }
+ }
+ ],
+ "id": "https://mastodon.sdf.org/users/rinpatch/statuses/102070944809637304/activity",
+ "type": "Create",
+ "actor": "https://mastodon.sdf.org/users/rinpatch",
+ "published": "2019-05-10T09:03:36Z",
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "cc": [
+ "https://mastodon.sdf.org/users/rinpatch/followers"
+ ],
+ "object": {
+ "id": "https://mastodon.sdf.org/users/rinpatch/statuses/102070944809637304",
+ "type": "Question",
+ "summary": null,
+ "inReplyTo": null,
+ "published": "2019-05-10T09:03:36Z",
+ "url": "https://mastodon.sdf.org/@rinpatch/102070944809637304",
+ "attributedTo": "https://mastodon.sdf.org/users/rinpatch",
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "cc": [
+ "https://mastodon.sdf.org/users/rinpatch/followers"
+ ],
+ "sensitive": false,
+ "atomUri": "https://mastodon.sdf.org/users/rinpatch/statuses/102070944809637304",
+ "inReplyToAtomUri": null,
+ "conversation": "tag:mastodon.sdf.org,2019-05-10:objectId=15095122:objectType=Conversation",
+ "content": "<p>Why is Tenshi eating a corndog so cute?</p>",
+ "contentMap": {
+ "en": "<p>Why is Tenshi eating a corndog so cute?</p>"
+ },
+ "endTime": "2019-05-11T09:03:36Z",
+ "closed": "2019-05-11T09:03:36Z",
+ "attachment": [],
+ "tag": [],
+ "replies": {
+ "id": "https://mastodon.sdf.org/users/rinpatch/statuses/102070944809637304/replies",
+ "type": "Collection",
+ "first": {
+ "type": "CollectionPage",
+ "partOf": "https://mastodon.sdf.org/users/rinpatch/statuses/102070944809637304/replies",
+ "items": []
+ }
+ },
+ "oneOf": [
+ {
+ "type": "Note",
+ "name": "Dunno",
+ "replies": {
+ "type": "Collection",
+ "totalItems": 0
+ }
+ },
+ {
+ "type": "Note",
+ "name": "Everyone knows that!",
+ "replies": {
+ "type": "Collection",
+ "totalItems": 1
+ }
+ },
+ {
+ "type": "Note",
+ "name": "25 char limit is dumb",
+ "replies": {
+ "type": "Collection",
+ "totalItems": 0
+ }
+ },
+ {
+ "type": "Note",
+ "name": "I can't even fit a funny",
+ "replies": {
+ "type": "Collection",
+ "totalItems": 1
+ }
+ }
+ ]
+ }
+}
diff --git a/test/fixtures/mastodon-vote.json b/test/fixtures/mastodon-vote.json
new file mode 100644
index 000000000..c2c5f40c0
--- /dev/null
+++ b/test/fixtures/mastodon-vote.json
@@ -0,0 +1,16 @@
+{
+ "@context": "https://www.w3.org/ns/activitystreams",
+ "actor": "https://mastodon.sdf.org/users/rinpatch",
+ "id": "https://mastodon.sdf.org/users/rinpatch#votes/387/activity",
+ "nickname": "rin",
+ "object": {
+ "attributedTo": "https://mastodon.sdf.org/users/rinpatch",
+ "id": "https://mastodon.sdf.org/users/rinpatch#votes/387",
+ "inReplyTo": "https://testing.uguu.ltd/objects/9d300947-2dcb-445d-8978-9a3b4b84fa14",
+ "name": "suya..",
+ "to": "https://testing.uguu.ltd/users/rin",
+ "type": "Note"
+ },
+ "to": "https://testing.uguu.ltd/users/rin",
+ "type": "Create"
+}
diff --git a/test/fixtures/rich_media/non_ogp_embed.html b/test/fixtures/rich_media/non_ogp_embed.html
new file mode 100644
index 000000000..62a1d677a
--- /dev/null
+++ b/test/fixtures/rich_media/non_ogp_embed.html
@@ -0,0 +1,1479 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
+ <meta charset="UTF-8">
+ <link rel="apple-touch-icon-precomposed" sizes="57x57" href="https://img.mfcimg.com/images/favicons/apple-touch-icon-57x57.png?nc=1" />
+<link rel="apple-touch-icon-precomposed" sizes="114x114" href="https://img.mfcimg.com/images/favicons/apple-touch-icon-114x114.png?nc=1" />
+<link rel="apple-touch-icon-precomposed" sizes="72x72" href="https://img.mfcimg.com/images/favicons/apple-touch-icon-72x72.png?nc=1" />
+<link rel="apple-touch-icon-precomposed" sizes="144x144" href="https://img.mfcimg.com/images/favicons/apple-touch-icon-144x144.png?nc=1" />
+<link rel="apple-touch-icon-precomposed" sizes="60x60" href="https://img.mfcimg.com/images/favicons/apple-touch-icon-60x60.png?nc=1" />
+<link rel="apple-touch-icon-precomposed" sizes="120x120" href="https://img.mfcimg.com/images/favicons/apple-touch-icon-120x120.png?nc=1" />
+<link rel="apple-touch-icon-precomposed" sizes="76x76" href="https://img.mfcimg.com/images/favicons/apple-touch-icon-76x76.png?nc=1" />
+<link rel="apple-touch-icon-precomposed" sizes="152x152" href="https://img.mfcimg.com/images/favicons/apple-touch-icon-152x152.png?nc=1" />
+<link rel="icon" type="image/png" href="https://img.mfcimg.com/images/favicons/favicon-196x196.png?nc=1" sizes="196x196" />
+<link rel="icon" type="image/png" href="https://img.mfcimg.com/images/favicons/favicon-96x96.png?nc=1" sizes="96x96" />
+<link rel="icon" type="image/png" href="https://img.mfcimg.com/images/favicons/favicon-32x32.png?nc=1" sizes="32x32" />
+<link rel="icon" type="image/png" href="https://img.mfcimg.com/images/favicons/favicon-16x16.png?nc=1" sizes="16x16" />
+<link rel="icon" type="image/png" href="https://img.mfcimg.com/images/favicons/favicon-128.png?nc=1" sizes="128x128" />
+<meta name="application-name" content="MyFreeCams.com Profiles" />
+<meta name="msapplication-TileColor" content="#008000" />
+<meta name="msapplication-TileImage" content="https://img.mfcimg.com/images/favicons/mstile-144x144.png?nc=1" />
+<meta name="msapplication-square70x70logo" content="https://img.mfcimg.com/images/favicons/mstile-70x70.png?nc=1" />
+<meta name="msapplication-square150x150logo" content="https://img.mfcimg.com/images/favicons/mstile-150x150.png?nc=1" />
+<meta name="msapplication-wide310x150logo" content="https://img.mfcimg.com/images/favicons/mstile-310x150.png?nc=1" />
+<meta name="msapplication-square310x310logo" content="https://img.mfcimg.com/images/favicons/mstile-310x310.png?nc=1" />
+
+ <script src="https://img.mfcimg.com/profiles/jquery/jquery-1.9.1.min.js"></script>
+<script src="https://img.mfcimg.com/profiles/jquery/jquery-ui-1.9.2.min.js"></script>
+<script src="https://img.mfcimg.com/profiles/jquery/jquery.ui.touch-punch.min.js"></script> <script>
+ var g_hPlatform = { "id": 1, "domain": "myfreecams.com", "name": "MyFreeCams", "code": "mfc", "image_url": "https://img.mfcimg.com/" };
+
+ try { document.domain = 'myfreecams.com'; } catch (e) {}
+
+ var MfcAssets = {
+ images: "/bundles/mfcprofile/vendor/img/",
+ urls: {
+ www: "https://www.myfreecams.com/",
+ new_comments: "/BlueAngelLove/comments/since/0"
+ }
+ };
+
+ var MfcPageVars = {
+ userId: 0,
+ accessLevel: 0,
+ token: "xIqyjzUBSrt6Rbl_su7UOrDxNZJlZNc4nsWh6eXxDkg",
+ profileState: {"number":127,"string":"Offline"},
+ serverTime: {"unixTime":1561209909,"time":"6:25am PDT","dst":1},
+ profileUsername: "BlueAngelLove",
+ admirers: 4719,
+ username: "",
+ userPhotoUrl: "",
+ vToken: "4c4ea23b221f89b73c964b7f99a50f78",
+ avatarRev: 0,
+ avgRating: {"rating_count":7060,"rating_average":"4.8681"},
+ rating: 0
+};
+
+
+ function MfcProfilePage( jQuery )
+ {
+ var _self = this;
+
+ _self.$ = jQuery;
+
+ _self.token = ( typeof(MfcPageVars) !== 'undefined' && MfcPageVars.token ) ? MfcPageVars.token : _self.$('meta[name=token]').attr('content');
+
+ _self.beforeDomReady();
+
+
+ _self.$(function(){ _self.afterDomReady(); });
+ };
+
+ MfcProfilePage.prototype.beforeDomReady = function()
+ {
+ var _self = this;
+ var $ = _self.$;
+
+ if ( _self.token )
+ {
+ $.ajaxSetup({
+ beforeSend: function(xhr, settings) {
+ if ( settings.type === 'GET' || settings.crossDomain )
+ return;
+
+ if ( $.type(settings.data) === 'object' && $.type(settings.data.append) === 'function' )
+ {
+ settings.data.append('_token', _self.token);
+ }
+ else if ( $.type(settings.data) === 'string' && settings.data.indexOf('_token=') === -1 )
+ {
+ if ( settings.data.length === 0 )
+ {
+ xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
+ } else {
+ settings.data += '&';
+ }
+
+ settings.data += encodeURIComponent('_token') + '=' + encodeURIComponent(_self.token);
+ }
+ }
+ });
+
+ $(document).on('submit', 'form', function(e)
+ {
+ if ( ! $(this).find('#_token').length && ! $(this).data('mfc-no-token') )
+ $(this).append($('<input type="hidden" name="_token" id="_token" value="' + _self.token + '">'));
+ });
+ }
+ };
+
+ MfcProfilePage.prototype.afterDomReady = function()
+ {
+ var _self = this;
+ var $ = this.$;
+
+ var page = $('body').data('mfc-page');
+
+ if ( $.isFunction(_self[page]) )
+ _self[page]();
+ };
+
+ new MfcProfilePage(jQuery);
+</script>
+
+ <link href="https://img.mfcimg.com/profiles/prod/22793316144741120/css/profiles.css?nc=22793316144741120" type="text/css" rel="stylesheet">
+
+ <title>BlueAngelLove's Homepage on MyFreeCams.com</title>
+ <meta name="description" content="BlueAngelLove's webcam homepage on MyFreeCams.com - your #1 adult webcam community">
+ <meta name="keywords" content="webcams,models,adult,community,nude,chat,video">
+
+ <style type="text/css">
+ body.mfc_display_inline_mode #header_bar, body.mfc_display_inline_mode #footer_bar {
+ visibility: hidden;
+ }
+ body.mfc_profile_standard.mfc_display_inline_mode {
+ margin-left: 0;
+ margin-right: 0;
+ padding-left: 5px;
+ padding-right: 5px;
+ }
+ body.mfc_profile_standard.mfc_display_inline_mode #profile_about_me {
+ display: flex;
+ flex-flow: wrap;
+ }
+ body.mfc_profile_standard.mfc_display_inline_mode #profile_about_me .heading {
+ flex: 0 0 100%;
+ }
+ body.mfc_profile_standard.mfc_display_inline_mode #profile_about_me .container {
+ flex: 0 1 50%;
+ margin: 0;
+ padding: 0;
+ }
+ body.mfc_profile_standard.mfc_display_inline_mode #profile_about_me #about_me_container, body.mfc_profile_standard.mfc_display_inline_mode #profile_about_me #tags_container {
+ flex: 0 0 100%;
+ margin-top: 0;
+ margin-bottom: 0;
+ }
+ @media (max-width: 850px) {
+ body.mfc_profile_standard.mfc_display_inline_mode #profile_about_me .container {
+ flex: 0 0 100%;
+ }
+ }
+ @media (min-width: 1500px) {
+ body.mfc_profile_standard.mfc_display_inline_mode #profile_about_me .container {
+ flex: 0 0 33%;
+ }
+ }
+ </style>
+
+ <link href="/BlueAngelLove/css?nc=204272526" rel="stylesheet" type="text/css">
+
+
+ <script type="text/javascript">
+ g_bInIframe = (function(w) {
+ try {
+ return w.self !== w.top;
+ } catch (e) {
+ return true;
+ }
+ return false;
+ })(window);
+
+ (function(w,d) {
+ 'use strict';
+
+ var hrefClickFn = function (e) {
+ e = e || w.event;
+
+ var target = findHrefElFn(e.target || e.srcElement);
+
+ if ( target != undefined && ((target.hostname + target.pathname.replace(/(^\/?)/,'/')).toLowerCase() !== (location.hostname + location.pathname).toLowerCase()) ) {
+ target.setAttribute('target', '_blank');
+ target.setAttribute('rel', 'noopener noreferrer');
+ }
+
+ return true;
+ };
+
+ var isHrefElFn = function(el) {
+ var elName = (el.nodeName || el.tagName).toLowerCase();
+ if ( (elName === 'a' || elName === 'area') && el.href != undefined ) { return true; }
+ return false;
+ };
+
+ var findHrefElFn = function(el) {
+ if ( isHrefElFn(el) ) { return el; }
+ while (el = el.parentNode) {
+ if ( isHrefElFn(el) ) { return el; }
+ }
+ return undefined;
+ };
+
+ if ( g_bInIframe ) {
+ if ( d.addEventListener ) {
+ d.addEventListener('click', hrefClickFn);
+ } else {
+ d.attachEvent('onclick', hrefClickFn);
+ }
+ }
+ })(window, document);
+</script>
+
+ </head>
+ <body class="mfc_profile_customized" data-mfc-page="userShow">
+ <script type="text/javascript">
+ (function(w,d,v) {
+ 'use strict';
+
+ var classes = [];
+ var search = w.location.search || '';
+ var vs = (typeof v === 'object' && v.profileState) ? v.profileState.number : 127;
+
+ if ( search.match(/[?&]inline_mode=1/) ) {
+ classes.push('mfc_display_inline_mode');
+ }
+ if ( search.match(/[?&]online=1/) || vs != 127 ) {
+ classes.push('mfc_online');
+ }
+ if ( 'Model' === 'Model' && ( search.match(/[?&]broadcasting=1/) || vs < 90 ) ) {
+ classes.push('mfc_broadcasting');
+ }
+
+ if ( classes.length ) {
+ d.getElementsByTagName('body')[0].className += ' ' + classes.join(' ');
+ }
+
+ })(window, document, MfcPageVars);
+</script>
+ <div id="fixed_background"></div>
+
+ <div id="header_bar">
+ <div class="header_links">
+ <a href="/">Profiles.MyFreeCams.com</a> |
+ <a href='https://www.myfreecams.com/'>MyFreeCams.com</a> |
+ <a href="/_/my_profile">My Profile</a> |
+ <a href="/_/login">Profile Settings</a>
+ </div>
+
+ <div class="clearfix header_time">
+
+ <div id="server_time">
+ <table>
+ <tbody>
+ <tr>
+ <td>Your Time:</td>
+ <td id="your_time"></td>
+ </tr>
+ <tr>
+ <td>MyFreeCams Time:</td>
+ <td id="mfc_time"></td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+
+ </div>
+ </div>
+
+ <div id="profile">
+ <div class="profile_row">
+ <div class="profile_section" id="profile_header">
+ <div class="profile_section_content">
+ <div class="profile_section_background"></div>
+
+ <div id="avatar_holder">
+ <img id="profile_avatar" class="img_radius_shadow" src="https://img.mfcimg.com/photos2/320/3204009/avatar.90x90.jpg?nc=1557647675" onError="this.onerror=null; this.src='https://img.mfcimg.com/images/nophoto-f.gif';">
+ </div>
+
+ <div id="profile_header_container">
+ <div class="heading">
+ BlueAngelLove
+ </div>
+
+ <div class="container" id="status_container">
+ <div class="label" id="status_label">
+ Status:
+ </div>
+ <div class="value" id="status_value">
+ <span id="member_status_value" class="hidden"></span>
+ <span id="member_type_value">&nbsp;- Model -</span>
+ <span id="member_message_value" class="hidden" data-mfc-member-type="Model"><a href="#" id="show_message_dialog">Send a MyFreeCams Mail</a></span>
+ </div>
+ </div>
+
+
+
+ <div class="container" id="blurb_container">
+ <span class="label" id="blurb_label">
+ Profile Headline:
+ </span>
+
+ <span class="value" id="blurb_value">
+ Enjoy and Love
+ </span>
+ </div>
+
+
+
+
+
+
+
+
+ <div class="container" id="unix_last_broadcast_container">
+ <span class="label" id="unix_last_broadcast_label">
+ Last Broadcast:
+ </span>
+
+ <span class="value convert-time" id="unix_last_broadcast_value" data-mfc-unix-time="1561100400" data-mfc-time-format="ddd, MMM D YYYY"></span>
+ </div>
+
+
+
+
+
+ <div class="container" id="unix_last_updated_container">
+ <span class="label" id="unix_last_updated_label">
+ Last Updated:
+ </span>
+
+ <span class="value convert-time" id="unix_last_updated_value" data-mfc-unix-time="1561193088" data-mfc-time-format="llll"></span>
+ </div>
+
+
+
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div class="profile_row" id="profile_main_about_holder">
+
+ <div id="profile_main_photo">
+ <div class="profile_section">
+ <div class="profile_section_content">
+ <div class="profile_section_background"></div>
+
+
+ <div class="heading">
+ My Most Recent Pictures
+ </div>
+ <div class="recent_photos">
+ <img src="https://img.mfcimg.com/photos2/320/3204009/986-665-202-679-12065535.80x80.jpg" class="img_radius_shadow show_preview" onError="this.onerror=null; this.src='https://img.mfcimg.com/images/nophoto-f.gif';" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/986-665-202-679-12065535.250.jpg">
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div class="profile_section" id="profile_about_me_friends">
+ <div class="profile_section_content">
+ <div class="profile_section_background"></div>
+
+ <div class="profile_subsection" id="profile_about_me">
+
+ <div class="heading">
+ About Me
+ </div>
+
+
+
+ <div class="container" id="username_container">
+ <span class="label" id="username_label">
+ Username:
+ </span>
+
+ <span class="value" id="username_value">
+ BlueAngelLove </span>
+ </div>
+
+
+
+
+
+
+
+
+ <div class="container" id="gender_container">
+ <span class="label" id="gender_label">
+ Gender:
+ </span>
+
+ <span class="value" id="gender_value">
+ Female </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="body_type_container">
+ <span class="label" id="body_type_label">
+ Body Type:
+ </span>
+
+ <span class="value" id="body_type_value">
+ Athletic </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="ethnicity_container">
+ <span class="label" id="ethnicity_label">
+ Ethnicity:
+ </span>
+
+ <span class="value" id="ethnicity_value">
+ Other </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="hair_container">
+ <span class="label" id="hair_label">
+ Hair:
+ </span>
+
+ <span class="value" id="hair_value">
+ Brown </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="eyes_container">
+ <span class="label" id="eyes_label">
+ Eyes:
+ </span>
+
+ <span class="value" id="eyes_value">
+ Blue </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="weight_container">
+ <span class="label" id="weight_label">
+ Weight:
+ </span>
+
+ <span class="value" id="weight_value">
+ 45 kilos </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="height_container">
+ <span class="label" id="height_label">
+ Height:
+ </span>
+
+ <span class="value" id="height_value">
+ 165 centimeters </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="age_container">
+ <span class="label" id="age_label">
+ Age:
+ </span>
+
+ <span class="value" id="age_value">
+ 34 </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="city_container">
+ <span class="label" id="city_label">
+ City:
+ </span>
+
+ <span class="value" id="city_value">
+ Mountains </span>
+ </div>
+
+
+
+
+
+
+
+
+
+
+
+ <div class="container" id="sexual_preference_container">
+ <span class="label" id="sexual_preference_label">
+ Sexual Preference:
+ </span>
+
+ <span class="value" id="sexual_preference_value">
+ Bisexual </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="smoke_container">
+ <span class="label" id="smoke_label">
+ Smoke:
+ </span>
+
+ <span class="value" id="smoke_value">
+ Non Smoker </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="drink_container">
+ <span class="label" id="drink_label">
+ Drink:
+ </span>
+
+ <span class="value" id="drink_value">
+ Non Drinker </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="drugs_container">
+ <span class="label" id="drugs_label">
+ Drugs:
+ </span>
+
+ <span class="value" id="drugs_value">
+ Never </span>
+ </div>
+
+
+
+
+
+
+
+
+ <div class="container" id="occupation_container">
+ <span class="label" id="occupation_label">
+ Occupation/Major:
+ </span>
+
+ <span class="value" id="occupation_value">
+ Guide </span>
+ </div>
+
+
+
+
+
+
+
+
+ <div class="container" id="favorite_food_container">
+ <span class="label" id="favorite_food_label">
+ Favorite Food:
+ </span>
+
+ <span class="value" id="favorite_food_value">
+ Chocolate </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="pets_container">
+ <span class="label" id="pets_label">
+ Pets:
+ </span>
+
+ <span class="value" id="pets_value">
+ I dont like pets </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="automobile_container">
+ <span class="label" id="automobile_label">
+ Automobile:
+ </span>
+
+ <span class="value" id="automobile_value">
+ Ford </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="about_me_container">
+ <span class="label" id="about_me_label">
+ About Me:
+ </span>
+
+ <span class="value" id="about_me_value">
+ <a href="//www.dmca.com/Protection/Status.aspx?ID=96b05ddf-1265-4f81-9d84-7dcfeb87cbb6" title="DMCA.com Protection Status" class="dmca-badge"> <img src="https://images.dmca.com/Badges/dmca_protected_16_120.png?ID=96b05ddf-1265-4f81-9d84-7dcfeb87cbb6" alt="DMCA.com Protection Status"></a><a href="http://www.cutercounter.com/" target="_blank" rel="noopener noreferrer"><img src="http://www.cutercounter.com/hits.php?id=grmpackf&amp;nd=7&amp;style=102" border="0" alt="website counter"></a>
+<div id="myCv" class="gen">
+<div class="defaultbg"></div>
+<div class="maintitle">BlueAngelLove</div>
+ <div id="buttons">
+ <a href="https://wa.me/40747018024" class="btn blue"> CONTACT ME </a>
+ <div class="corp">
+
+ <div id="ModelCard">
+ <img src="https://img.mfcimg.com/photos2/320/3204009/314-736-287-236-10552594.jpg" alt="Model's image"><hr><div class="bum"></div>
+ <div class="bum"><a href="http://www.myfreecams.com/mfc2/php/tip.php?request=tip&amp;username=blueangellove" title="Tip Me Offline">Tip Me Offline</a></div>
+ <div class="bum"><a href="http://www.amazon.co.uk/wishlist/3D0MOTP0S0SE5" target="_blank" title="My Amazon Wishlist" rel="noopener noreferrer">My Amazon Wishlist</a></div>
+ <div class="bum"><a href="https://twitter.com/BlueAngelLove33" target="_blank" title="Follow me on Twitter" rel="noopener noreferrer">Follow Me on Twitter</a></div>
+ <div class="bum"><a href="https://wa.me/40747018024" target="_blank" title="Follow me on WhatsApp" rel="noopener noreferrer">Follow Me on Whatsapp</a></div>
+ <div class="bum"><a href="https://www.instagram.com/blueangellove3?r=nametag" title="Follow me on Instagram">Follow Me on Instagram</a></div>
+ <div class="bum"><a href="https://www.snapchat.com/add/cjullyana" title="Follow me on Snapchat">Follow Me on SnapChat</a></div>
+ <div class="bum"><a href="http://hatscripts.com/addskype?BlueAngelLove33" title="Follow me on Skype">Follow Me on Skype</a></div>
+ <div class="bum"><a href="https://www.youtube.com/playlist?list=PLGqo-7BiklVM37HIBud981EpiXxV3yM4m" title="Follow me on Youtube">Follow Me on Youtube </a></div>
+ <div class="bum"><a href="#roomrules" target="_blank" title="Join my Chat Room" rel="noopener noreferrer">Join My Room</a></div>
+ <div class="bum"><a href="https://MFCsha.re/BlueAngelLove" title="Follow me on MFC Share">Follow Me on MFC Share</a></div>
+ <div class="bum"><a href="https://social.myfreecams.com/BlueAngelLove" title="Follow me on Social MFC">Follow Me on Social MFC </a></div>
+ <div class="bum"><a href="https://www.rabb.it/s/d556sr" title="Follow me on Rabbit TV">Follow me on Rabbit TV</a></div>
+ <div class="bum"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=Y8KLFSLZJAKP2&amp;source=url" title="Spoil Me and Offer Your Gift">Spoil Me and Offer Your Gift</a></div>
+ <div class="bum"><a href="https://player.vimeo.com/video/326274838" title="Follow Me">Follow Me</a></div>
+ <div class="bum"><a href="https://www.timeanddate.com/worldclock/personal.html?cities=179,136,248,250,263,152,2462,716,195,69&amp;wch=2" title="TIME CONVERTOR">TIME CONVERTOR</a></div>
+ <hr></div>
+ </div>
+ <div id="AboutMe">
+ <div class="skilltitle">Angel</div>
+ <div class="corp corpus xcr">
+ <div class="unscor">
+ I Want To Be Seduced
+ <div class="skills_model1"><div class="metru_experience skill bxhdw"></div></div>
+ </div>
+ <div class="unscor">
+ I Love Flirt
+ <div class="skills_model1"><div class="metru_coding skill bxhdw"></div></div>
+ </div>
+ <div class="unscor">
+ I Want Be Part Of Your life
+ <div class="skills_model1"><div class="metru_concept skill bxhdw"></div></div>
+ </div>
+ <div class="unscor">
+ I Love Dancing
+ <div class="skills_model1"><div class="metru_concept skill bxhdw"></div></div>
+ </div>
+ <div class="unscor">
+ I Love Erotic Chats
+ <div class="skills_model1"><div class="metru_graphic skill bxhdw"></div></div>
+ </div>
+ <div class="unscor">
+ I am Funny
+ <div class="skills_model1"><div class="metru_coding skill bxhdw"></div></div>
+ </div>
+ <div class="unscor">
+ I Enjoy C2C
+ <div class="skills_model1"><div class="metru_experience skill bxhdw"></div></div>
+ </div>
+ <div class="unscor">
+ I Love Sex and Feel u
+ <div class="skills_model1"><div class="metru_concept skill bxhdw"></div></div>
+ </div>
+ </div>
+ <hr></div>
+ </div>
+ <hr><div class="maintitle">June Month Contestst-Top 3 tippers Get A gift mailed,videos,pictures and will my right hand full month and room helpers as well (be my men for a month or who knows...maybe forever) ***
+Love Ya Angels*** We are currently ranked #2200 overall </div>
+ <p class="dasinfo">Get Listed on My Wall of Fame</p>
+ <div class="corp zreq">
+ <div class="ttippers xcr">
+
+ <p> ElmosEgo 6570 Tks </p>
+ <p> Rw2lite 4800 Tks </p>
+ <p> Toastboi 2093 Tks </p>
+ <p> Acoolahole 1850 Tks </p>
+ <p> Gonodog 1299 Tks </p>
+ <p> Pumpy_G 800 Tks </p>
+ <p> Fowser 690 Tks </p>
+ <p> Aquanautic 600 Tks </p>
+ <p> Daveonthelake 535 Tks </p>
+ <p> Wildpervert2 500 Tks </p>
+ <p> Cloud10101 350 Tks </p>
+ <p> Branson102 337 Tks </p>
+ <p> TheCopperhead 329 Tks </p>
+ <p> Mouche99 250 Tks </p>
+ <p> The88drummer 233 Tks </p>
+ <p> Stringtrees86 199 Tks </p>
+ <p> Blazegordon 183 Tks </p>
+ <p> Waiting_4 183 Tks </p>
+ <p> Sam_mie 170 Tks </p>
+ <p> UtterTripe 150 Tks </p>
+ <p> Darth_penguin 150 Tks </p>
+ <p> Playfullpurv 120 Tks </p>
+ <p> Jordnsprings 103 Tks </p>
+ <p> Travelinlover 100 Tks </p>
+ <p> Da884 100 Tks </p>
+
+ </div>
+ <a href="https://imgbb.com/"><img src="https://i.ibb.co/mybZhYn/cory1.jpg" alt="cory1" border="0"></a>
+</div>
+ <hr><div class="maintitle">May Contest winners - Each month Top 3 tippers Get A gift mailed, videos and pictures - Love Ya Angels </div>
+ <p class="dasinfo">Get Listed on My Wall of Fame</p>
+ <div class="corp zreq">
+ <div class="ttippers xcr">
+ <p> Rw2lite </p>
+ <p> ElmosEgo </p>
+ <p> TJuonesWoah </p>
+
+</div>
+ <a href="https://imgbb.com/"><img src="https://i.ibb.co/mybZhYn/cory1.jpg" alt="cory1" border="0"></a>
+</div>
+ <hr><div class="maintitle"> Menu Per Day </div>
+ <p class="dasinfo">LOVE YA ANGELS</p>
+ <div class="corp zreq">
+ <div class="ttippers xcr">
+ <p> Monday - Outfits Strip </p>
+ <p> Tusday - Raffle </p>
+ <p> Wensday - Gamblers Night </p>
+ <p> Thusday - Orgasmic Vibra or Dildos </p>
+ <p> Friday - Wheel/Treat or Trick </p>
+ <p> Saturday - Phrase </p>
+ <p> Sunday - Keno and Boyfriend choice </p>
+
+
+
+ </div>
+ <div class="dasinfo">You have to tip to get listed above so do your best to get on my exclusive Top Tippers List</div>
+ <div class="bum"></div>
+ </div>
+ <a href="https://ibb.co/vcFmK7x"><img src="https://i.ibb.co/j8NG1cv/Whats-App-Image-2019-01-09-at-10-35-17.jpg" alt="Whats-App-Image-2019-01-09-at-10-35-17" border="0"></a>
+ <a href="https://ibb.co/RcMF0T5"><img src="https://i.ibb.co/kXr782d/45280406-1564895203655742-4887638015087738880-n.jpg" alt="45280406-1564895203655742-4887638015087738880-n" border="0"></a>
+ <a href="https://ibb.co/1s0Tp2r"><img src="https://i.ibb.co/gvrJXgS/best.jpg" alt="best" border="0"></a>
+ <a href="https://ibb.co/cJmJHHv"><img src="https://i.ibb.co/F6P6MMW/Whats-App-Image-2019-01-09-at-10-35-16.jpg" alt="Whats-App-Image-2019-01-09-at-10-35-16" border="0"></a>
+
+ <div class="bum"><a href="http://www.myfreecams.com/mfc2/php/tip.php?request=tip&amp;username=blueangellove" title="Tip Me Offline">Tip Me Offline</a></div>
+ <div class="bum"><a href="http://www.amazon.co.uk/wishlist/3D0MOTP0S0SE5" target="_blank" title="My Amazon Wishlist" rel="noopener noreferrer">My Amazon Wishlist</a></div>
+ <div class="bum"><a href="https://twitter.com/BlueAngelLove33" target="_blank" title="Follow me on Twitter" rel="noopener noreferrer">Follow Me on Twitter</a></div>
+ <div class="bum"><a href="https://wa.me/40747018024" target="_blank" title="Follow me on WhatsApp" rel="noopener noreferrer">Follow Me on Whatsapp</a></div>
+ <div class="bum"><a href="https://www.instagram.com/blueangellove3?r=nametag" title="Follow me on Instagram">Follow Me on Instagram</a></div>
+ <div class="bum"><a href="https://www.snapchat.com/add/cjullyana" title="Follow me on Snapchat">Follow Me on SnapChat</a></div>
+ <div class="bum"><a href="http://hatscripts.com/addskype?BlueAngelLove33" title="Follow me on Skype">Follow Me on Skype</a></div>
+ <div class="bum"><a href="https://www.youtube.com/playlist?list=PLGqo-7BiklVM37HIBud981EpiXxV3yM4m" title="Follow me on Youtube">Follow Me on Youtube </a></div>
+ <div class="bum"><a href="#roomrules" target="_blank" title="Join my Chat Room" rel="noopener noreferrer">Join My Room</a></div>
+ <div class="bum"><a href="https://MFCsha.re/BlueAngelLove" title="Follow me on MFC Share">Follow Me on MFC Share</a></div>
+ <div class="bum"><a href="https://social.myfreecams.com/BlueAngelLove" title="Follow me on Social MFC">Follow Me on Social MFC </a></div>
+ <div class="bum"><a href="https://www.rabb.it/s/d556sr" title="Follow me on Rabbit TV">Follow me on Rabbit TV</a></div>
+ <div class="bum"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=Y8KLFSLZJAKP2&amp;source=url" title="Spoil Me and Offer Your Gift">Spoil Me and Offer Your Gift</a></div>
+ <div class="bum"><a href="https://player.vimeo.com/video/326274838" title="Follow Me">Follow Me</a></div>
+ <div class="bum"><a href="https://www.timeanddate.com/worldclock/personal.html?cities=179,136,248,250,263,152,2462,716,195,69&amp;wch=2" title="TIME CONVERTOR">TIME CONVERTOR</a></div>
+ <hr><div id="GNav">
+ <div id="GNwrapper">
+ <a class="abMe" title="About Me" href="#aboutmesection"></a></div>
+</div>
+<div class="bum"><a href="https://MFCsha.re/BlueAngelLove" title="Follow me on MFC Share">Follow Me on MFC Share</a></div>
+<img src="https://i.ibb.co/Pmt2PsP/Whats-App-Image-2019-05-12-at-05-55-35-1.jpg" alt="Whats-App-Image-2019-05-12-at-05-55-35-1" border="0"><img src="https://image.ibb.co/bt1tzq/lovense-level.png" alt="lovense-level" border="0"><div>
+<span class="neontexte"></span></div>
+<div id="OneSection">
+<div></div>
+<div>
+<img src="http://1.bp.blogspot.com/-qTHLNVFggQU/VFdFIOFPDqI/AAAAAAAAGdU/6cWnDLVp0d8/s1600/findme.png" class="findme" alt="camgirl xxx amateur sex sexy"></div>
+</div>
+<div>
+<div id="TwoSection">
+<div id="aboutmesection">
+<a href="https://ibb.co/ZS2D4vh"><img src="https://i.ibb.co/421rvCj/39741863-284302529029606-7659956026455621632-n.jpg" alt="39741863-284302529029606-7659956026455621632-n" border="0"></a>
+<div id="abtmesec" class="frame">
+<span class="neontext">Let's Fun Laugh Live</span><br><i>I am Jullia from Transylvania and is a pleasure to have u around Enjoy me and my room</i><br><br><span class="neontext">BlueAngelLove</span><br><i>I am good, but not an angel. I do sin, but I am not the devil. I am just a girl in a big world trying to find someone to love and be loved</i><br><br></div>
+<a href="https://ibb.co/gvVKkkf"><img src="https://i.ibb.co/6vBCjjT/20171114-113848.jpg" alt="20171114-113848" border="0"></a><a>
+</a></div>~~~Live~Laugh~Love~~~<i><a href="https://info.flagcounter.com/1Ea8"><img src="https://s04.flagcounter.com/countxl/1Ea8/bg_85C2FF/txt_242424/border_CCCCCC/columns_3/maxflags_33/viewers_0/labels_1/pageviews_0/flags_0/percent_0/" alt="Flag Counter" border="0"></a>
+</i></div><div id="vimlft" class="frame"></div></div></div> </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="tags_container">
+ <span class="label" id="tags_label">
+ Tags:
+ </span>
+
+ <span class="value" id="tags_value">
+ natural, blue eyes, toys, funny, oil, shower, fetish, costume, sex, natural, masturbation, finger, dp, anal, girl next door, romantic, naughty, pervert, open mind, play roles, horny, playful, smiley, lover, sweet, sexy, beautiful, hot, shaved, friendly, pussy, skype </span>
+ </div>
+
+
+
+ </div>
+
+ <div class="profile_subsection" id="profile_friends">
+
+ <div class="heading">
+ Friends
+ </div>
+
+ <div class="container" id="average_rating_container">
+ <span class="label" id="average_rating_label">
+ Average Rating:
+ </span>
+ <span class="value" id="average_rating_value">
+ <span id="average_rating"></span>
+ <span id="average_rating_count"></span>
+ </span>
+ </div>
+
+ <div class="container" id="rate_container">
+ <span class="label" id="rate_label">
+ Rate BlueAngelLove:
+ </span>
+ <span class="value" id="rate_value">
+ <form id="new_rating" class="hidden" action="/BlueAngelLove/ratings" method="post">
+ <span id="rating_value_bar"></span>
+ <span id="rating_confirm" class="hidden emphasis notice"></span>
+</form>
+<div id="new_rating_login_message" class="hidden">
+ You must <a href="/_/login">login</a> to rate.
+</div> </span>
+ </div>
+
+ <div class="container" id="admirers_container">
+ <span class="label" id="admirers_label">
+ Admirers:
+ <br>
+ <form id="new_admirer" action="/BlueAngelLove/admirers" method="post">
+
+ (<a href='#' id="admire">admire</a><span id="admire_confirm" class="hidden notice">admired!</span>)
+</form> </span>
+ <span class="value" id="admirers_value"></span>
+ </div>
+
+ <div class="container" id="friends_container">
+ <span class="label" id="friends_label">
+ Profile Friends:
+ <br>
+ <form id="new_homepage_friend" action="/BlueAngelLove/homepage_friends" method="post">
+
+ (<a href='#' id='make_friend'>make friend</a><span id="make_friend_confirm" class="hidden notice">added!</span>)
+</form> </span>
+ <span class="value" id="friends_value">
+ <a href="/Schnitzngrubn">Schnitzngrubn</a>
+ <a href="/UtterTripe">UtterTripe</a>
+ <a href="/MisterPopular">MisterPopular</a>
+ <a href="/neoviewer">neoviewer</a>
+ <a href="/lasse1991">lasse1991</a>
+ <a href="/toastboi">toastboi</a>
+ <a href="/obiwan1965">obiwan1965</a>
+ <a href="/Eastie_Beasty">Eastie_Beasty</a>
+ <a href="/Robby1890">Robby1890</a>
+ <a href="/rw2lite">rw2lite</a>
+ <a href="/zoomie2178">zoomie2178</a>
+ <a href="/AS_rayman41">AS_rayman41</a>
+ <a href="/CJamz87">CJamz87</a>
+ <a href="/Dunky4Jullia">Dunky4Jullia</a>
+ <a href="/Zdasher">Zdasher</a>
+ <a href="/Fowser">Fowser</a>
+ <a href="/buffaloman69">buffaloman69</a>
+ <a href="/Numb33rs">Numb33rs</a>
+ <a href="/ElmosEgo">ElmosEgo</a>
+ <a href="/DaleCooper_">DaleCooper_</a>
+ <a href="/Aquanautic">Aquanautic</a>
+ <a href="/Waiting_4">Waiting_4</a>
+ <a href="/Oliver_xXx">Oliver_xXx</a>
+ <a href="/motion454">motion454</a>
+ <a href="/The_Greg1">The_Greg1</a>
+ <a href="/Razumichin">Razumichin</a>
+ <a href="/Sam_mie">Sam_mie</a>
+ </span>
+ </div>
+
+ <div class="container" id="favorite_models_container">
+ <span class="label" id="favorite_models_label">
+ Favorite Models:
+ </span>
+ <span class="value" id="favorite_models_value">
+ <a href="/BlueAngelLove">BlueAngelLove</a>
+ </span>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ </div>
+ <div class="profile_row">
+ <div class="profile_section" id="profile_password_photo_galleries">
+ <div class="profile_section_content">
+ <div class="profile_section_background"></div>
+
+ <div class="heading">
+ Password Protected Galleries
+ </div>
+
+ <div class="holder" id="password_photo_gallery_control"></div>
+ <ul class="photo_gallery_previews" id="password_photo_gallery_previews">
+ <li class="photo_gallery_preview" data-mfc-name="Paris , Disneyland , Belgium , Frankfurt , Berlin" data-mfc-url="/BlueAngelLove/view_gallery/498241/password">
+ <div class="photo_gallery_name">
+ <a href="#" class="photo_gallery_link" data-mfc-gallery="498241" data-mfc-protected="1">Paris , Disneyland , Belgium , Frankfurt , Berlin</a>
+
+ </div>
+ <a href="#" class="photo_gallery_link" data-mfc-gallery="498241" data-mfc-protected="1"><img class='photo_gallery_lock img_radius_shadow' src='https://img.mfcimg.com/images/lock-icon.gif'></a>
+
+ <div class="photo_gallery_count">
+ 17 Photos
+ </div>
+ </li>
+
+
+ <li class="photo_gallery_preview" data-mfc-name="Paris , Disneyland , Belgium , Frankfurt , Berlin ..." data-mfc-url="/BlueAngelLove/view_gallery/498240/password">
+ <div class="photo_gallery_name">
+ <a href="#" class="photo_gallery_link" data-mfc-gallery="498240" data-mfc-protected="1">Paris , Disneyland , Belgium , Frankfurt , Berlin ...</a>
+
+ </div>
+ <a href="#" class="photo_gallery_link" data-mfc-gallery="498240" data-mfc-protected="1"><img class='photo_gallery_lock img_radius_shadow' src='https://img.mfcimg.com/images/lock-icon.gif'></a>
+
+ <div class="photo_gallery_count">
+ 37 Photos
+ </div>
+ </li>
+
+
+ <li class="photo_gallery_preview" data-mfc-name="CJ Art - Free Gallery - Just pm me and i give u the password" data-mfc-url="/BlueAngelLove/view_gallery/343862/password">
+ <div class="photo_gallery_name">
+ <a href="#" class="photo_gallery_link" data-mfc-gallery="343862" data-mfc-protected="1">CJ Art - Free Gallery - Just pm me and i give u the password</a>
+
+ </div>
+ <a href="#" class="photo_gallery_link" data-mfc-gallery="343862" data-mfc-protected="1"><img class='photo_gallery_lock img_radius_shadow' src='https://img.mfcimg.com/images/lock-icon.gif'></a>
+
+ <div class="photo_gallery_count">
+ 15 Photos
+ </div>
+ </li>
+
+
+ <li class="photo_gallery_preview" data-mfc-name="4MyAngels - Free Gallery - Just pm me and i give u the password" data-mfc-url="/BlueAngelLove/view_gallery/340500/password">
+ <div class="photo_gallery_name">
+ <a href="#" class="photo_gallery_link" data-mfc-gallery="340500" data-mfc-protected="1">4MyAngels - Free Gallery - Just pm me and i give u the password</a>
+
+ </div>
+ <a href="#" class="photo_gallery_link" data-mfc-gallery="340500" data-mfc-protected="1"><img class='photo_gallery_lock img_radius_shadow' src='https://img.mfcimg.com/images/lock-icon.gif'></a>
+
+ <div class="photo_gallery_count">
+ 97 Photos
+ </div>
+ </li>
+
+
+ </ul>
+ </div>
+ </div>
+
+ </div>
+ <div class="hidden profile_row" id="password_photo_galleries">
+ <div class="profile_section">
+ <div class="profile_section_content">
+ <div class="profile_section_background"></div>
+ </div>
+ </div>
+ </div>
+ <div class="profile_row">
+ <div class="profile_section" id="profile_photo_galleries">
+ <div class="profile_section_content">
+ <div class="profile_section_background"></div>
+
+ <div class="heading">
+ Photo Galleries
+ </div>
+
+ <div class="holder" id="photo_gallery_control"></div>
+ <ul class="photo_gallery_previews" id="photo_gallery_previews">
+ <li class="photo_gallery_preview" data-mfc-name="Recent Photo" >
+ <div class="photo_gallery_name">
+ <a href="#" class="photo_gallery_link" data-mfc-gallery="3" >Recent Photo</a>
+
+ </div>
+ <a href="#" class="photo_gallery_link" data-mfc-gallery="3" ><img class='photo_gallery_image img_radius_shadow' src='https://img.mfcimg.com/photos2/320/3204009/986-665-202-679-12065535.80x80.jpg' onError="this.onerror=null; this.src='https://img.mfcimg.com/images/nophoto-f.gif';"></a>
+
+ <div class="photo_gallery_count">
+ 1 Photo
+ </div>
+ </li>
+
+
+ <li class="photo_gallery_preview" data-mfc-name="jullia" >
+ <div class="photo_gallery_name">
+ <a href="#" class="photo_gallery_link" data-mfc-gallery="56075" >jullia</a>
+
+ </div>
+ <a href="#" class="photo_gallery_link" data-mfc-gallery="56075" ><img class='photo_gallery_image img_radius_shadow' src='https://img.mfcimg.com/photos2/320/3204009/681-423-335-230-1243247.80x80.jpg' onError="this.onerror=null; this.src='https://img.mfcimg.com/images/nophoto-f.gif';"></a>
+
+ <div class="photo_gallery_count">
+ 68 Photos
+ </div>
+ </li>
+
+
+ </ul>
+ </div>
+ </div>
+
+ </div>
+ <div class="hidden profile_row" id="photo_galleries">
+ <div class="profile_section">
+ <div class="profile_section_content">
+ <div class="profile_section_background"></div>
+ <div class="hidden photo_gallery" id="profile_photo_gallery_3">
+ <div class="heading">
+ Recent Photo
+ </div>
+
+ <div class="images">
+ <a href="https://img.mfcimg.com/photos2/320/3204009/986-665-202-679-12065535.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/986-665-202-679-12065535.80x80.jpg" data-mfc-caption="" data-mfc-width="1600" data-mfc-height="1200" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/986-665-202-679-12065535.250.jpg"></a>
+ </div>
+</div> <div class="hidden photo_gallery" id="profile_photo_gallery_56075">
+ <div class="heading">
+ jullia
+ </div>
+
+ <div class="images">
+ <a href="https://img.mfcimg.com/photos2/320/3204009/681-423-335-230-1243247.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/681-423-335-230-1243247.80x80.jpg" data-mfc-caption="" data-mfc-width="975" data-mfc-height="635" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/681-423-335-230-1243247.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/317-507-429-599-1243547.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/317-507-429-599-1243547.80x80.jpg" data-mfc-caption="" data-mfc-width="841" data-mfc-height="905" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/317-507-429-599-1243547.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/140-305-410-615-1243548.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/140-305-410-615-1243548.80x80.jpg" data-mfc-caption="" data-mfc-width="553" data-mfc-height="703" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/140-305-410-615-1243548.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/307-788-771-545-1243550.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/307-788-771-545-1243550.80x80.jpg" data-mfc-caption="" data-mfc-width="649" data-mfc-height="875" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/307-788-771-545-1243550.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/684-466-940-744-1243551.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/684-466-940-744-1243551.80x80.jpg" data-mfc-caption="" data-mfc-width="504" data-mfc-height="558" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/684-466-940-744-1243551.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/231-700-451-967-1317683.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/231-700-451-967-1317683.80x80.jpg" data-mfc-caption="" data-mfc-width="759" data-mfc-height="631" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/231-700-451-967-1317683.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/889-473-722-704-1317685.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/889-473-722-704-1317685.80x80.jpg" data-mfc-caption="" data-mfc-width="794" data-mfc-height="616" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/889-473-722-704-1317685.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/632-850-956-399-1317690.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/632-850-956-399-1317690.80x80.jpg" data-mfc-caption="" data-mfc-width="774" data-mfc-height="769" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/632-850-956-399-1317690.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/340-370-972-798-1317693.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/340-370-972-798-1317693.80x80.jpg" data-mfc-caption="" data-mfc-width="718" data-mfc-height="491" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/340-370-972-798-1317693.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/675-946-621-275-1320874.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/675-946-621-275-1320874.80x80.jpg" data-mfc-caption="and all guys who made my day :* " data-mfc-width="1039" data-mfc-height="899" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/675-946-621-275-1320874.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/989-178-581-568-1352794.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/989-178-581-568-1352794.80x80.jpg" data-mfc-caption="" data-mfc-width="555" data-mfc-height="623" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/989-178-581-568-1352794.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/780-959-310-914-1352798.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/780-959-310-914-1352798.80x80.jpg" data-mfc-caption="" data-mfc-width="625" data-mfc-height="552" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/780-959-310-914-1352798.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/636-984-916-475-1354386.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/636-984-916-475-1354386.80x80.jpg" data-mfc-caption="" data-mfc-width="635" data-mfc-height="746" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/636-984-916-475-1354386.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/744-644-726-778-1491823.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/744-644-726-778-1491823.80x80.jpg" data-mfc-caption="" data-mfc-width="983" data-mfc-height="943" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/744-644-726-778-1491823.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/657-707-347-607-1491824.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/657-707-347-607-1491824.80x80.jpg" data-mfc-caption="" data-mfc-width="953" data-mfc-height="943" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/657-707-347-607-1491824.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/735-531-553-176-1648078.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/735-531-553-176-1648078.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/735-531-553-176-1648078.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/736-829-137-558-1648081.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/736-829-137-558-1648081.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/736-829-137-558-1648081.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/451-346-815-316-1648083.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/451-346-815-316-1648083.80x80.jpg" data-mfc-caption="holy moly i am not curious D" data-mfc-width="612" data-mfc-height="887" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/451-346-815-316-1648083.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/902-338-266-573-1648084.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/902-338-266-573-1648084.80x80.jpg" data-mfc-caption="still not curious " data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/902-338-266-573-1648084.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/738-765-195-927-1648085.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/738-765-195-927-1648085.80x80.jpg" data-mfc-caption="u curious one " data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/738-765-195-927-1648085.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/928-809-867-351-1652571.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/928-809-867-351-1652571.80x80.jpg" data-mfc-caption="" data-mfc-width="979" data-mfc-height="490" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/928-809-867-351-1652571.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/462-736-528-238-1686155.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/462-736-528-238-1686155.80x80.jpg" data-mfc-caption="" data-mfc-width="1280" data-mfc-height="512" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/462-736-528-238-1686155.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/334-394-125-456-1686157.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/334-394-125-456-1686157.80x80.jpg" data-mfc-caption="" data-mfc-width="972" data-mfc-height="1021" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/334-394-125-456-1686157.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/315-230-389-269-1686158.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/315-230-389-269-1686158.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/315-230-389-269-1686158.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/654-561-626-601-1686163.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/654-561-626-601-1686163.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/654-561-626-601-1686163.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/951-538-671-632-1686164.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/951-538-671-632-1686164.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/951-538-671-632-1686164.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/344-284-425-291-1686166.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/344-284-425-291-1686166.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/344-284-425-291-1686166.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/841-495-993-546-1686168.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/841-495-993-546-1686168.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/841-495-993-546-1686168.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/464-292-321-375-1686169.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/464-292-321-375-1686169.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/464-292-321-375-1686169.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/116-821-970-661-1686171.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/116-821-970-661-1686171.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/116-821-970-661-1686171.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/225-535-697-812-1686172.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/225-535-697-812-1686172.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/225-535-697-812-1686172.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/555-716-876-756-1686173.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/555-716-876-756-1686173.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/555-716-876-756-1686173.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/716-290-623-869-1686175.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/716-290-623-869-1686175.80x80.jpg" data-mfc-caption="" data-mfc-width="1038" data-mfc-height="1006" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/716-290-623-869-1686175.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/230-899-707-297-1686178.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/230-899-707-297-1686178.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/230-899-707-297-1686178.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/162-148-524-271-1686182.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/162-148-524-271-1686182.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/162-148-524-271-1686182.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/415-762-949-132-1686186.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/415-762-949-132-1686186.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/415-762-949-132-1686186.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/755-564-921-527-1686189.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/755-564-921-527-1686189.80x80.jpg" data-mfc-caption="" data-mfc-width="623" data-mfc-height="654" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/755-564-921-527-1686189.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/336-756-382-542-1767063.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/336-756-382-542-1767063.80x80.jpg" data-mfc-caption="" data-mfc-width="1280" data-mfc-height="1023" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/336-756-382-542-1767063.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/855-646-780-704-1767067.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/855-646-780-704-1767067.80x80.jpg" data-mfc-caption="" data-mfc-width="1280" data-mfc-height="1023" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/855-646-780-704-1767067.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/371-515-389-663-1767070.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/371-515-389-663-1767070.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/371-515-389-663-1767070.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/971-471-877-691-1767071.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/971-471-877-691-1767071.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/971-471-877-691-1767071.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/408-470-703-495-1767072.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/408-470-703-495-1767072.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/408-470-703-495-1767072.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/349-843-504-986-1767076.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/349-843-504-986-1767076.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/349-843-504-986-1767076.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/929-861-253-392-1767078.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/929-861-253-392-1767078.80x80.jpg" data-mfc-caption="" data-mfc-width="2560" data-mfc-height="1024" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/929-861-253-392-1767078.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/806-418-694-591-1767139.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/806-418-694-591-1767139.80x80.jpg" data-mfc-caption="" data-mfc-width="1280" data-mfc-height="800" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/806-418-694-591-1767139.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/713-749-399-951-1767140.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/713-749-399-951-1767140.80x80.jpg" data-mfc-caption="" data-mfc-width="1280" data-mfc-height="800" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/713-749-399-951-1767140.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/940-530-100-397-1847969.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/940-530-100-397-1847969.80x80.jpg" data-mfc-caption="" data-mfc-width="1280" data-mfc-height="800" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/940-530-100-397-1847969.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/331-281-416-758-1847972.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/331-281-416-758-1847972.80x80.jpg" data-mfc-caption="" data-mfc-width="1280" data-mfc-height="800" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/331-281-416-758-1847972.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/989-327-876-935-2041425.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/989-327-876-935-2041425.80x80.jpg" data-mfc-caption="" data-mfc-width="1280" data-mfc-height="800" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/989-327-876-935-2041425.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/789-661-181-290-2227549.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/789-661-181-290-2227549.80x80.jpg" data-mfc-caption="" data-mfc-width="1920" data-mfc-height="1288" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/789-661-181-290-2227549.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/253-580-172-496-2617499.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/253-580-172-496-2617499.80x80.jpg" data-mfc-caption="" data-mfc-width="977" data-mfc-height="767" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/253-580-172-496-2617499.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/987-119-713-682-2624979.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/987-119-713-682-2624979.80x80.jpg" data-mfc-caption="" data-mfc-width="1142" data-mfc-height="566" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/987-119-713-682-2624979.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/559-379-311-707-2633932.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/559-379-311-707-2633932.80x80.jpg" data-mfc-caption="" data-mfc-width="1920" data-mfc-height="1288" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/559-379-311-707-2633932.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/177-536-481-276-7714372.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/177-536-481-276-7714372.80x80.jpg" data-mfc-caption="" data-mfc-width="1366" data-mfc-height="768" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/177-536-481-276-7714372.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/511-128-866-710-7714373.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/511-128-866-710-7714373.80x80.jpg" data-mfc-caption="" data-mfc-width="1366" data-mfc-height="768" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/511-128-866-710-7714373.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/126-900-930-456-7714374.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/126-900-930-456-7714374.80x80.jpg" data-mfc-caption="" data-mfc-width="671" data-mfc-height="649" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/126-900-930-456-7714374.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/639-324-503-206-7714375.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/639-324-503-206-7714375.80x80.jpg" data-mfc-caption="" data-mfc-width="673" data-mfc-height="671" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/639-324-503-206-7714375.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/746-103-976-888-8099406.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/746-103-976-888-8099406.80x80.jpg" data-mfc-caption="" data-mfc-width="1075" data-mfc-height="822" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/746-103-976-888-8099406.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/361-992-343-713-8099407.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/361-992-343-713-8099407.80x80.jpg" data-mfc-caption="" data-mfc-width="1920" data-mfc-height="1080" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/361-992-343-713-8099407.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/184-179-678-355-8099408.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/184-179-678-355-8099408.80x80.jpg" data-mfc-caption="" data-mfc-width="1920" data-mfc-height="1080" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/184-179-678-355-8099408.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/834-731-356-329-8099409.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/834-731-356-329-8099409.80x80.jpg" data-mfc-caption="" data-mfc-width="1920" data-mfc-height="1080" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/834-731-356-329-8099409.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/717-329-382-179-8828007.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/717-329-382-179-8828007.80x80.jpg" data-mfc-caption="" data-mfc-width="1013" data-mfc-height="853" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/717-329-382-179-8828007.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/621-220-484-504-8828008.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/621-220-484-504-8828008.80x80.jpg" data-mfc-caption="" data-mfc-width="1920" data-mfc-height="1080" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/621-220-484-504-8828008.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/530-414-264-944-8828009.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/530-414-264-944-8828009.80x80.jpg" data-mfc-caption="" data-mfc-width="1291" data-mfc-height="835" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/530-414-264-944-8828009.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/615-981-631-653-11173625.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/615-981-631-653-11173625.80x80.jpg" data-mfc-caption="" data-mfc-width="731" data-mfc-height="709" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/615-981-631-653-11173625.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/110-404-655-657-11173626.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/110-404-655-657-11173626.80x80.jpg" data-mfc-caption="" data-mfc-width="721" data-mfc-height="685" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/110-404-655-657-11173626.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/217-437-695-748-11204527.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/217-437-695-748-11204527.80x80.jpg" data-mfc-caption="" data-mfc-width="1351" data-mfc-height="313" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/217-437-695-748-11204527.250.jpg"></a>
+ <a href="https://img.mfcimg.com/photos2/320/3204009/129-477-684-510-12067688.jpg"><img class="photo_gallery_image show_preview" src="https://img.mfcimg.com/photos2/320/3204009/129-477-684-510-12067688.80x80.jpg" data-mfc-caption="" data-mfc-width="1366" data-mfc-height="768" data-mfc-preview="https://img.mfcimg.com/photos2/320/3204009/129-477-684-510-12067688.250.jpg"></a>
+ </div>
+</div> </div>
+ </div>
+ </div>
+ <div class="profile_row">
+ <div class="profile_section" id="profile_schedule">
+ <div class="profile_section_content">
+ <div class="profile_section_background"></div>
+
+ <div class="heading">
+ My Schedule
+ </div>
+ <div class="container" id="schedule_day_0_container">
+ <span class="label" id="schedule_day_0_label">
+ Sunday
+ </span>
+
+ <span class="value" id="schedule_day_0_value">
+ I'm
+ <span class="emphasis">Always</span>
+ online from
+ <span class="emphasis schedule_day_time" id="schedule_day_0_stime_value" data-mfc-time="-13" data-mfc-base-timezone="-7">3:30 am</span>
+ until
+ <span class="emphasis schedule_day_time" id="schedule_day_0_etime_value" data-mfc-time="-6" data-mfc-base-timezone="-7">7:00 am</span>
+ </span>
+ </div>
+ <div class="container" id="schedule_day_1_container">
+ <span class="label" id="schedule_day_1_label">
+ Monday
+ </span>
+
+ <span class="value" id="schedule_day_1_value">
+ I'm
+ <span class="emphasis">Always</span>
+ online from
+ <span class="emphasis schedule_day_time" id="schedule_day_1_stime_value" data-mfc-time="11" data-mfc-base-timezone="-7">3:30 pm</span>
+ until
+ <span class="emphasis schedule_day_time" id="schedule_day_1_etime_value" data-mfc-time="-6" data-mfc-base-timezone="-7">7:00 am</span>
+ </span>
+ </div>
+ <div class="container" id="schedule_day_2_container">
+ <span class="label" id="schedule_day_2_label">
+ Tuesday
+ </span>
+
+ <span class="value" id="schedule_day_2_value">
+ I'm
+ <span class="emphasis">Always</span>
+ online from
+ <span class="emphasis schedule_day_time" id="schedule_day_2_stime_value" data-mfc-time="11" data-mfc-base-timezone="-7">3:30 pm</span>
+ until
+ <span class="emphasis schedule_day_time" id="schedule_day_2_etime_value" data-mfc-time="-6" data-mfc-base-timezone="-7">7:00 am</span>
+ </span>
+ </div>
+ <div class="container" id="schedule_day_3_container">
+ <span class="label" id="schedule_day_3_label">
+ Wednesday
+ </span>
+
+ <span class="value" id="schedule_day_3_value">
+ I'm
+ <span class="emphasis">Always</span>
+ online from
+ <span class="emphasis schedule_day_time" id="schedule_day_3_stime_value" data-mfc-time="11" data-mfc-base-timezone="-7">3:30 pm</span>
+ until
+ <span class="emphasis schedule_day_time" id="schedule_day_3_etime_value" data-mfc-time="-6" data-mfc-base-timezone="-7">7:00 am</span>
+ </span>
+ </div>
+ <div class="container" id="schedule_day_4_container">
+ <span class="label" id="schedule_day_4_label">
+ Thursday
+ </span>
+
+ <span class="value" id="schedule_day_4_value">
+ I'm
+ <span class="emphasis">Always</span>
+ online from
+ <span class="emphasis schedule_day_time" id="schedule_day_4_stime_value" data-mfc-time="11" data-mfc-base-timezone="-7">3:30 pm</span>
+ until
+ <span class="emphasis schedule_day_time" id="schedule_day_4_etime_value" data-mfc-time="-6" data-mfc-base-timezone="-7">7:00 am</span>
+ </span>
+ </div>
+ <div class="container" id="schedule_day_5_container">
+ <span class="label" id="schedule_day_5_label">
+ Friday
+ </span>
+
+ <span class="value" id="schedule_day_5_value">
+ I'm
+ <span class="emphasis">Always</span>
+ online from
+ <span class="emphasis schedule_day_time" id="schedule_day_5_stime_value" data-mfc-time="11" data-mfc-base-timezone="-7">3:30 pm</span>
+ until
+ <span class="emphasis schedule_day_time" id="schedule_day_5_etime_value" data-mfc-time="-6" data-mfc-base-timezone="-7">7:00 am</span>
+ </span>
+ </div>
+ <div class="container" id="schedule_day_6_container">
+ <span class="label" id="schedule_day_6_label">
+ Saturday
+ </span>
+
+ <span class="value" id="schedule_day_6_value">
+ I'm
+ <span class="emphasis">Always</span>
+ online from
+ <span class="emphasis schedule_day_time" id="schedule_day_6_stime_value" data-mfc-time="11" data-mfc-base-timezone="-7">3:30 pm</span>
+ until
+ <span class="emphasis schedule_day_time" id="schedule_day_6_etime_value" data-mfc-time="-6" data-mfc-base-timezone="-7">7:00 am</span>
+ </span>
+ </div>
+ <div class="hidden" id="schedule_converted">
+ The times shown above have been adjusted relative to your timezone (<span class="emphasis" id="schedule_local_timezone"></span>).
+ </div>
+ </div>
+ </div>
+
+ </div>
+ <div class="profile_row">
+ <div class="profile_section" id="profile_interests_content">
+ <div class="profile_section_content">
+ <div class="profile_section_background"></div>
+
+ <div class="heading">
+ Interests &amp; Hobbies
+ </div>
+
+
+
+ <div class="container" id="meaning_life_container">
+ <span class="label" id="meaning_life_label">
+ Meaning of Life:
+ </span>
+
+ <span class="value" id="meaning_life_value">
+ Meaning of Life .To Love and Be Loved and keep what i have and who i have in my life right now </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="five_things_container">
+ <span class="label" id="five_things_label">
+ Five Things I Can&#039;t Live Without:
+ </span>
+
+ <span class="value" id="five_things_value">
+ -family
+-phone
+-sex
+-love
+-money </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="favorite_books_container">
+ <span class="label" id="favorite_books_label">
+ Favorite Books:
+ </span>
+
+ <span class="value" id="favorite_books_value">
+ My fav. book was Count of Monte Cristo </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="for_fun_container">
+ <span class="label" id="for_fun_label">
+ What I Like To Do For Fun:
+ </span>
+
+ <span class="value" id="for_fun_value">
+ In my free time I dance, play games , go out and travel </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="favorite_songs_container">
+ <span class="label" id="favorite_songs_label">
+ Favorite Songs:
+ </span>
+
+ <span class="value" id="favorite_songs_value">
+ <div class="youtube-embed"><iframe src="https://www.youtube.com/embed/DE9IchvpOPk?ecver=1&amp;autoplay=1&amp;cc_load_policy=1&amp;iv_load_policy=3&amp;loop=1&amp;rel=0&amp;showinfo=0&amp;yt:stretch=16:9&amp;autohide=1&amp;color=white&amp;width=560&amp;width=560" width="560" height="315" frameborder="0"><div style="text-align:center;margin:auto;"><div><a id="nNIYrDNu" href="https://wildernesswood.co.uk">https://wildernesswood.co.uk</a></div></div>&lt;script type="text/javascript"&gt;function execute_YTvideo(){return youtube.query({ids:"channel==MINE",startDate:"2018-01-01",endDate:"2018-12-31",metrics:"views,estimatedMinutesWatched,averageViewDuration,averageViewPercentage,subscribersGained",dimensions:"day",sort:"day"}).then(function(e){},function(e){console.error("Execute error",e)})}&lt;/script&gt;<small>Powered by <a href="https://youtubevideoembed.com/">Embed YouTube Video</a></small></iframe></div> </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="favorite_movies_container">
+ <span class="label" id="favorite_movies_label">
+ Favorite Movies:
+ </span>
+
+ <span class="value" id="favorite_movies_value">
+ <iframe width="560" height="315" src="//www.youtube.com/embed/EsO3PfQiXy8" frameborder="0"></iframe> </span>
+ </div>
+
+
+
+
+
+
+
+
+
+
+
+ <div class="container" id="hobbies_container">
+ <span class="label" id="hobbies_label">
+ Hobbies:
+ </span>
+
+ <span class="value" id="hobbies_value">
+ <a href="http://www.amazon.co.uk/wishlist/3D0MOTP0S0SE5">My Amazon Wishlistuk</a> </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="talents_container">
+ <span class="label" id="talents_label">
+ Talents:
+ </span>
+
+ <span class="value" id="talents_value">
+ i love to Dance , Travel and Cook </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="perfect_mate_container">
+ <span class="label" id="perfect_mate_label">
+ Perfect Mate:
+ </span>
+
+ <span class="value" id="perfect_mate_value">
+ Perfect mate is Magic Mike </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="perfect_date_container">
+ <span class="label" id="perfect_date_label">
+ Perfect Date:
+ </span>
+
+ <span class="value" id="perfect_date_value">
+ Perfect Date .You and Me , romatic dinner and wild sex </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="turn_ons_container">
+ <span class="label" id="turn_ons_label">
+ Turn Ons/Offs:
+ </span>
+
+ <span class="value" id="turn_ons_value">
+ I hate Liers and Rude Peoples </span>
+ </div>
+
+
+
+
+
+ <div class="container" id="know_me_container">
+ <span class="label" id="know_me_label">
+ Best Reason to Get to Know Me:
+ </span>
+
+ <span class="value" id="know_me_value">
+ My dear men, please dont put a label on medont make me a category before you get to know me! </span>
+ </div>
+
+
+
+ </div>
+ </div>
+
+ </div>
+
+ </div>
+
+ <div id="footer_bar">
+ <div class="footer_links">
+ <a href="/">Profiles.MyFreeCams.com</a> |
+ <a href='https://www.myfreecams.com/'>MyFreeCams.com</a> |
+ <a href="/_/my_profile">My Profile</a> |
+ <a href="/_/login">Profile Settings</a>
+ </div>
+ </div>
+
+ <div id="gallery_password_container" style="display: none !important;">
+ <div id="gallery_password_form_modal">
+ <div id="protected_gallery_name"></div>
+ <div id="protected_gallery_instructions">
+ You must specify the password to view this gallery
+ </div>
+ <form id="gallery_password_form" method=post data-mfc-no-token="1password_protected_gallery">
+ <label for="gallery_password">Password:</label>
+ <input type="password" name="gallery_password" id="gallery_password">
+ <input type="submit" name="submit" value="submit" data-mfc-submitted="verifying...">
+ </form>
+ <div id="gallery_password_form_error"></div>
+ </div>
+ </div>
+ <div id="send_message_container" style="display: none !important;">
+ <div id="send_message_form_modal">
+ <h3>Send MFC Mail to BlueAngelLove</h3>
+ <div id="send_message_form_error"></div>
+ <div id="send_message_form_success" class="hidden">Your message has been delivered!</div>
+ </div>
+ </div>
+ <script src="https://assets.mfcimg.com/js/MfcBrokenImageDetector.js"></script>
+ <script src="https://assets.mfcimg.com/js/MfcUtilities.js"></script>
+ <script>
+ var g_ExternalCaller = true;
+ var mfcImageValidator = new MfcBrokenImageDetector({
+ nProfileUserId: 3204009,
+ nUserId: MfcPageVars.userId,
+ sImgSelector: '.wall_post_body img',
+ sImgParentSelector: '.wall_post_body',
+ sToken: MfcPageVars.vToken
+ });
+
+ mfcImageValidator.checkImages();
+ </script>
+ <script src="https://img.mfcimg.com/profiles/prod/22793316144741120/js/profiles.js?nc=22793316144741120"></script>
+ <script type="text/javascript">
+
+ var _gaq = _gaq || [];
+ _gaq.push(['_setAccount', 'UA-295864-5']);
+ _gaq.push(['_setDomainName', 'myfreecams.com']);
+ _gaq.push(['_trackPageview']);
+
+ (function() {
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+ })();
+
+</script> </body>
+</html> \ No newline at end of file
diff --git a/test/fixtures/rich_media/ogp-missing-data.html b/test/fixtures/rich_media/ogp-missing-data.html
new file mode 100644
index 000000000..5746dc2f4
--- /dev/null
+++ b/test/fixtures/rich_media/ogp-missing-data.html
@@ -0,0 +1,8 @@
+<html prefix="og: http://ogp.me/ns#">
+ <head>
+ <title>Pleroma</title>
+ <meta property="og:title" content="Pleroma" />
+ <meta property="og:type" content="website" />
+ <meta property="og:url" content="https://pleroma.social/" />
+ </head>
+</html>
diff --git a/test/fixtures/rich_media/ogp-missing-title.html b/test/fixtures/rich_media/ogp-missing-title.html
new file mode 100644
index 000000000..fcdbedfc6
--- /dev/null
+++ b/test/fixtures/rich_media/ogp-missing-title.html
@@ -0,0 +1,12 @@
+<html prefix="og: http://ogp.me/ns#">
+
+<head>
+ <title>The Rock (1996)</title>
+ <meta property="og:type" content="video.movie" />
+ <meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
+ <meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
+ <meta property="og:description"
+ content="Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.">
+</head>
+
+</html>
diff --git a/test/fixtures/rich_media/ogp.html b/test/fixtures/rich_media/ogp.html
index c886b5871..4b5a33595 100644
--- a/test/fixtures/rich_media/ogp.html
+++ b/test/fixtures/rich_media/ogp.html
@@ -5,5 +5,6 @@
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
+ <meta property="og:description" content="Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.">
</head>
</html>
diff --git a/test/fixtures/httpoison_mock/7369654.atom b/test/fixtures/tesla_mock/7369654.atom
index 74fd9ce6b..74fd9ce6b 100644
--- a/test/fixtures/httpoison_mock/7369654.atom
+++ b/test/fixtures/tesla_mock/7369654.atom
diff --git a/test/fixtures/httpoison_mock/7369654.html b/test/fixtures/tesla_mock/7369654.html
index a75a90b90..a75a90b90 100644
--- a/test/fixtures/httpoison_mock/7369654.html
+++ b/test/fixtures/tesla_mock/7369654.html
diff --git a/test/fixtures/httpoison_mock/7even.json b/test/fixtures/tesla_mock/7even.json
index eb3bab14e..eb3bab14e 100644
--- a/test/fixtures/httpoison_mock/7even.json
+++ b/test/fixtures/tesla_mock/7even.json
diff --git a/test/fixtures/httpoison_mock/admin@mastdon.example.org.json b/test/fixtures/tesla_mock/admin@mastdon.example.org.json
index c297e4349..c297e4349 100644
--- a/test/fixtures/httpoison_mock/admin@mastdon.example.org.json
+++ b/test/fixtures/tesla_mock/admin@mastdon.example.org.json
diff --git a/test/fixtures/httpoison_mock/atarifrosch_feed.xml b/test/fixtures/tesla_mock/atarifrosch_feed.xml
index e00df782e..e00df782e 100644
--- a/test/fixtures/httpoison_mock/atarifrosch_feed.xml
+++ b/test/fixtures/tesla_mock/atarifrosch_feed.xml
diff --git a/test/fixtures/httpoison_mock/atarifrosch_webfinger.xml b/test/fixtures/tesla_mock/atarifrosch_webfinger.xml
index 24188362c..24188362c 100644
--- a/test/fixtures/httpoison_mock/atarifrosch_webfinger.xml
+++ b/test/fixtures/tesla_mock/atarifrosch_webfinger.xml
diff --git a/test/fixtures/httpoison_mock/baptiste.gelex.xyz-article.json b/test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json
index 3f3f0f4fb..3f3f0f4fb 100644
--- a/test/fixtures/httpoison_mock/baptiste.gelex.xyz-article.json
+++ b/test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json
diff --git a/test/fixtures/httpoison_mock/baptiste.gelex.xyz-user.json b/test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json
index b226204ba..b226204ba 100644
--- a/test/fixtures/httpoison_mock/baptiste.gelex.xyz-user.json
+++ b/test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json
diff --git a/test/fixtures/httpoison_mock/eal_sakamoto.xml b/test/fixtures/tesla_mock/eal_sakamoto.xml
index 934d539c9..934d539c9 100644
--- a/test/fixtures/httpoison_mock/eal_sakamoto.xml
+++ b/test/fixtures/tesla_mock/eal_sakamoto.xml
diff --git a/test/fixtures/httpoison_mock/emelie.atom b/test/fixtures/tesla_mock/emelie.atom
index ddaa1c6ca..ddaa1c6ca 100644
--- a/test/fixtures/httpoison_mock/emelie.atom
+++ b/test/fixtures/tesla_mock/emelie.atom
diff --git a/test/fixtures/tesla_mock/emelie.json b/test/fixtures/tesla_mock/emelie.json
new file mode 100644
index 000000000..592fc0e4e
--- /dev/null
+++ b/test/fixtures/tesla_mock/emelie.json
@@ -0,0 +1 @@
+{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","toot":"http://joinmastodon.org/ns#","featured":{"@id":"toot:featured","@type":"@id"},"alsoKnownAs":{"@id":"as:alsoKnownAs","@type":"@id"},"movedTo":{"@id":"as:movedTo","@type":"@id"},"schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value","Hashtag":"as:Hashtag","Emoji":"toot:Emoji","IdentityProof":"toot:IdentityProof","focalPoint":{"@container":"@list","@id":"toot:focalPoint"}}],"id":"https://mastodon.social/users/emelie","type":"Person","following":"https://mastodon.social/users/emelie/following","followers":"https://mastodon.social/users/emelie/followers","inbox":"https://mastodon.social/users/emelie/inbox","outbox":"https://mastodon.social/users/emelie/outbox","featured":"https://mastodon.social/users/emelie/collections/featured","preferredUsername":"emelie","name":"emelie 🎨","summary":"\u003cp\u003e23 / \u003ca href=\"https://mastodon.social/tags/sweden\" class=\"mention hashtag\" rel=\"tag\"\u003e#\u003cspan\u003eSweden\u003c/span\u003e\u003c/a\u003e / \u003ca href=\"https://mastodon.social/tags/artist\" class=\"mention hashtag\" rel=\"tag\"\u003e#\u003cspan\u003eArtist\u003c/span\u003e\u003c/a\u003e / \u003ca href=\"https://mastodon.social/tags/equestrian\" class=\"mention hashtag\" rel=\"tag\"\u003e#\u003cspan\u003eEquestrian\u003c/span\u003e\u003c/a\u003e / \u003ca href=\"https://mastodon.social/tags/gamedev\" class=\"mention hashtag\" rel=\"tag\"\u003e#\u003cspan\u003eGameDev\u003c/span\u003e\u003c/a\u003e\u003c/p\u003e\u003cp\u003eIf I ain\u0026apos;t spending time with my pets, I\u0026apos;m probably drawing. 🐴 🐱 🐰\u003c/p\u003e","url":"https://mastodon.social/@emelie","manuallyApprovesFollowers":false,"publicKey":{"id":"https://mastodon.social/users/emelie#main-key","owner":"https://mastodon.social/users/emelie","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu3CWs1oAJPE3ZJ9sj6Ut\n/Mu+mTE7MOijsQc8/6c73XVVuhIEomiozJIH7l8a7S1n5SYL4UuiwcubSOi7u1bb\nGpYnp5TYhN+Cxvq/P80V4/ncNIPSQzS49it7nSLeG5pA21lGPDA44huquES1un6p\n9gSmbTwngVX9oe4MYuUeh0Z7vijjU13Llz1cRq/ZgPQPgfz+2NJf+VeXnvyDZDYx\nZPVBBlrMl3VoGbu0M5L8SjY35559KCZ3woIvqRolcoHXfgvJMdPcJgSZVYxlCw3d\nA95q9jQcn6s87CPSUs7bmYEQCrDVn5m5NER5TzwBmP4cgJl9AaDVWQtRd4jFZNTx\nlQIDAQAB\n-----END PUBLIC KEY-----\n"},"tag":[{"type":"Hashtag","href":"https://mastodon.social/explore/sweden","name":"#sweden"},{"type":"Hashtag","href":"https://mastodon.social/explore/gamedev","name":"#gamedev"},{"type":"Hashtag","href":"https://mastodon.social/explore/artist","name":"#artist"},{"type":"Hashtag","href":"https://mastodon.social/explore/equestrian","name":"#equestrian"}],"attachment":[{"type":"PropertyValue","name":"Ko-fi","value":"\u003ca href=\"https://ko-fi.com/emeliepng\" rel=\"me nofollow noopener\" target=\"_blank\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003eko-fi.com/emeliepng\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e"},{"type":"PropertyValue","name":"Instagram","value":"\u003ca href=\"https://www.instagram.com/emelie_png/\" rel=\"me nofollow noopener\" target=\"_blank\"\u003e\u003cspan class=\"invisible\"\u003ehttps://www.\u003c/span\u003e\u003cspan class=\"\"\u003einstagram.com/emelie_png/\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e"},{"type":"PropertyValue","name":"Carrd","value":"\u003ca href=\"https://emelie.carrd.co/\" rel=\"me nofollow noopener\" target=\"_blank\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003eemelie.carrd.co/\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e"},{"type":"PropertyValue","name":"Artstation","value":"\u003ca href=\"https://emiri.artstation.com\" rel=\"me nofollow noopener\" target=\"_blank\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003eemiri.artstation.com\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e"}],"endpoints":{"sharedInbox":"https://mastodon.social/inbox"},"icon":{"type":"Image","mediaType":"image/png","url":"https://files.mastodon.social/accounts/avatars/000/015/657/original/e7163f98280da1a4.png"},"image":{"type":"Image","mediaType":"image/png","url":"https://files.mastodon.social/accounts/headers/000/015/657/original/847f331f3dd9e38b.png"}} \ No newline at end of file
diff --git a/test/fixtures/httpoison_mock/framasoft@framatube.org.json b/test/fixtures/tesla_mock/framasoft@framatube.org.json
index dcd5e88f5..dcd5e88f5 100644
--- a/test/fixtures/httpoison_mock/framasoft@framatube.org.json
+++ b/test/fixtures/tesla_mock/framasoft@framatube.org.json
diff --git a/test/fixtures/httpoison_mock/framatube.org_host_meta b/test/fixtures/tesla_mock/framatube.org_host_meta
index 91516ff6d..91516ff6d 100644
--- a/test/fixtures/httpoison_mock/framatube.org_host_meta
+++ b/test/fixtures/tesla_mock/framatube.org_host_meta
diff --git a/test/fixtures/httpoison_mock/gerzilla.de_host_meta b/test/fixtures/tesla_mock/gerzilla.de_host_meta
index fae8f37eb..fae8f37eb 100644
--- a/test/fixtures/httpoison_mock/gerzilla.de_host_meta
+++ b/test/fixtures/tesla_mock/gerzilla.de_host_meta
diff --git a/test/fixtures/httpoison_mock/gnusocial.de_host_meta b/test/fixtures/tesla_mock/gnusocial.de_host_meta
index a4affb102..a4affb102 100644
--- a/test/fixtures/httpoison_mock/gnusocial.de_host_meta
+++ b/test/fixtures/tesla_mock/gnusocial.de_host_meta
diff --git a/test/fixtures/httpoison_mock/gs.example.org_host_meta b/test/fixtures/tesla_mock/gs.example.org_host_meta
index c2fcd7305..c2fcd7305 100644
--- a/test/fixtures/httpoison_mock/gs.example.org_host_meta
+++ b/test/fixtures/tesla_mock/gs.example.org_host_meta
diff --git a/test/fixtures/httpoison_mock/hellpie.json b/test/fixtures/tesla_mock/hellpie.json
index e228ba394..e228ba394 100644
--- a/test/fixtures/httpoison_mock/hellpie.json
+++ b/test/fixtures/tesla_mock/hellpie.json
diff --git a/test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml b/test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml
index 058f629ab..058f629ab 100644
--- a/test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml
+++ b/test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml
diff --git a/test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json b/test/fixtures/tesla_mock/http___mastodon.example.org_users_admin_status_1234.json
index 5c7c9c6d3..5c7c9c6d3 100644
--- a/test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json
+++ b/test/fixtures/tesla_mock/http___mastodon.example.org_users_admin_status_1234.json
diff --git a/test/fixtures/httpoison_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml b/test/fixtures/tesla_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml
index 490467708..490467708 100644
--- a/test/fixtures/httpoison_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml
+++ b/test/fixtures/tesla_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml
diff --git a/test/fixtures/httpoison_mock/https___info.pleroma.site_actor.json b/test/fixtures/tesla_mock/https___info.pleroma.site_actor.json
index 9dabf0e52..9dabf0e52 100644
--- a/test/fixtures/httpoison_mock/https___info.pleroma.site_actor.json
+++ b/test/fixtures/tesla_mock/https___info.pleroma.site_actor.json
diff --git a/test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom b/test/fixtures/tesla_mock/https___mamot.fr_users_Skruyb.atom
index b5f3d923b..b5f3d923b 100644
--- a/test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom
+++ b/test/fixtures/tesla_mock/https___mamot.fr_users_Skruyb.atom
diff --git a/test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.atom b/test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.atom
index 4d732b109..4d732b109 100644
--- a/test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.atom
+++ b/test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.atom
diff --git a/test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml b/test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml
index 6a6a978a2..6a6a978a2 100644
--- a/test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml
+++ b/test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml
diff --git a/test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json b/test/fixtures/tesla_mock/https___osada.macgirvin.com_channel_mike.json
index c42f3a53c..c42f3a53c 100644
--- a/test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json
+++ b/test/fixtures/tesla_mock/https___osada.macgirvin.com_channel_mike.json
diff --git a/test/fixtures/httpoison_mock/https___pawoo.net_users_aqidaqidaqid.xml b/test/fixtures/tesla_mock/https___pawoo.net_users_aqidaqidaqid.xml
index 2de8a44b9..2de8a44b9 100644
--- a/test/fixtures/httpoison_mock/https___pawoo.net_users_aqidaqidaqid.xml
+++ b/test/fixtures/tesla_mock/https___pawoo.net_users_aqidaqidaqid.xml
diff --git a/test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.atom b/test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.atom
index 17d1956e8..17d1956e8 100644
--- a/test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.atom
+++ b/test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.atom
diff --git a/test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml b/test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.xml
index 1f1478a5e..1f1478a5e 100644
--- a/test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml
+++ b/test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.xml
diff --git a/test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml b/test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml
index 284a30df0..284a30df0 100644
--- a/test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml
+++ b/test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml
diff --git a/test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml b/test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml
index a2a2629a6..a2a2629a6 100644
--- a/test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml
+++ b/test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml
diff --git a/test/fixtures/httpoison_mock/https___prismo.news__mxb.json b/test/fixtures/tesla_mock/https___prismo.news__mxb.json
index a2fe53117..a2fe53117 100644
--- a/test/fixtures/httpoison_mock/https___prismo.news__mxb.json
+++ b/test/fixtures/tesla_mock/https___prismo.news__mxb.json
diff --git a/test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml b/test/fixtures/tesla_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml
index 26fdebb49..26fdebb49 100644
--- a/test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml
+++ b/test/fixtures/tesla_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml
diff --git a/test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml b/test/fixtures/tesla_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml
index 31df7c2a6..31df7c2a6 100644
--- a/test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml
+++ b/test/fixtures/tesla_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml
diff --git a/test/fixtures/httpoison_mock/https___shitposter.club_notice_2827873.html b/test/fixtures/tesla_mock/https___shitposter.club_notice_2827873.html
index 54745ef3d..54745ef3d 100644
--- a/test/fixtures/httpoison_mock/https___shitposter.club_notice_2827873.html
+++ b/test/fixtures/tesla_mock/https___shitposter.club_notice_2827873.html
diff --git a/test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml b/test/fixtures/tesla_mock/https___shitposter.club_user_1.xml
index bf54c80c8..bf54c80c8 100644
--- a/test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml
+++ b/test/fixtures/tesla_mock/https___shitposter.club_user_1.xml
diff --git a/test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml b/test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml
index 6cba5c28f..6cba5c28f 100644
--- a/test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml
+++ b/test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml
diff --git a/test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml b/test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml
index f70fbc695..f70fbc695 100644
--- a/test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml
+++ b/test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml
diff --git a/test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml b/test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml
index 426a52939..426a52939 100644
--- a/test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml
+++ b/test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml
diff --git a/test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml b/test/fixtures/tesla_mock/https___social.heldscal.la_user_29191.xml
index 641103377..641103377 100644
--- a/test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml
+++ b/test/fixtures/tesla_mock/https___social.heldscal.la_user_29191.xml
diff --git a/test/fixtures/httpoison_mock/https__info.pleroma.site_activity.json b/test/fixtures/tesla_mock/https__info.pleroma.site_activity.json
index a0dc4c830..a0dc4c830 100644
--- a/test/fixtures/httpoison_mock/https__info.pleroma.site_activity.json
+++ b/test/fixtures/tesla_mock/https__info.pleroma.site_activity.json
diff --git a/test/fixtures/httpoison_mock/https__info.pleroma.site_activity2.json b/test/fixtures/tesla_mock/https__info.pleroma.site_activity2.json
index b16a9279b..b16a9279b 100644
--- a/test/fixtures/httpoison_mock/https__info.pleroma.site_activity2.json
+++ b/test/fixtures/tesla_mock/https__info.pleroma.site_activity2.json
diff --git a/test/fixtures/httpoison_mock/https__info.pleroma.site_activity3.json b/test/fixtures/tesla_mock/https__info.pleroma.site_activity3.json
index 1df73f2c5..1df73f2c5 100644
--- a/test/fixtures/httpoison_mock/https__info.pleroma.site_activity3.json
+++ b/test/fixtures/tesla_mock/https__info.pleroma.site_activity3.json
diff --git a/test/fixtures/httpoison_mock/https__info.pleroma.site_activity4.json b/test/fixtures/tesla_mock/https__info.pleroma.site_activity4.json
index 57a73b12a..57a73b12a 100644
--- a/test/fixtures/httpoison_mock/https__info.pleroma.site_activity4.json
+++ b/test/fixtures/tesla_mock/https__info.pleroma.site_activity4.json
diff --git a/test/fixtures/httpoison_mock/kaniini@gerzilla.de.json b/test/fixtures/tesla_mock/kaniini@gerzilla.de.json
index be2f69b18..be2f69b18 100644
--- a/test/fixtures/httpoison_mock/kaniini@gerzilla.de.json
+++ b/test/fixtures/tesla_mock/kaniini@gerzilla.de.json
diff --git a/test/fixtures/httpoison_mock/kaniini@hubzilla.example.org.json b/test/fixtures/tesla_mock/kaniini@hubzilla.example.org.json
index 11c79e11e..11c79e11e 100644
--- a/test/fixtures/httpoison_mock/kaniini@hubzilla.example.org.json
+++ b/test/fixtures/tesla_mock/kaniini@hubzilla.example.org.json
diff --git a/test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml b/test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml
index 948e4758e..948e4758e 100644
--- a/test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml
+++ b/test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml
diff --git a/test/fixtures/httpoison_mock/lucifermysticus.json b/test/fixtures/tesla_mock/lucifermysticus.json
index 0409046e2..0409046e2 100644
--- a/test/fixtures/httpoison_mock/lucifermysticus.json
+++ b/test/fixtures/tesla_mock/lucifermysticus.json
diff --git a/test/fixtures/httpoison_mock/macgirvin.com_host_meta b/test/fixtures/tesla_mock/macgirvin.com_host_meta
index cd30b602f..cd30b602f 100644
--- a/test/fixtures/httpoison_mock/macgirvin.com_host_meta
+++ b/test/fixtures/tesla_mock/macgirvin.com_host_meta
diff --git a/test/fixtures/httpoison_mock/mamot.fr_host_meta b/test/fixtures/tesla_mock/mamot.fr_host_meta
index ed7a95094..ed7a95094 100644
--- a/test/fixtures/httpoison_mock/mamot.fr_host_meta
+++ b/test/fixtures/tesla_mock/mamot.fr_host_meta
diff --git a/test/fixtures/httpoison_mock/mastodon.social_host_meta b/test/fixtures/tesla_mock/mastodon.social_host_meta
index 78e46e260..78e46e260 100644
--- a/test/fixtures/httpoison_mock/mastodon.social_host_meta
+++ b/test/fixtures/tesla_mock/mastodon.social_host_meta
diff --git a/test/fixtures/httpoison_mock/mastodon.xyz_host_meta b/test/fixtures/tesla_mock/mastodon.xyz_host_meta
index 8604316fb..8604316fb 100644
--- a/test/fixtures/httpoison_mock/mastodon.xyz_host_meta
+++ b/test/fixtures/tesla_mock/mastodon.xyz_host_meta
diff --git a/test/fixtures/httpoison_mock/mayumayu.json b/test/fixtures/tesla_mock/mayumayu.json
index 2d5cdae1e..2d5cdae1e 100644
--- a/test/fixtures/httpoison_mock/mayumayu.json
+++ b/test/fixtures/tesla_mock/mayumayu.json
diff --git a/test/fixtures/httpoison_mock/mayumayupost.json b/test/fixtures/tesla_mock/mayumayupost.json
index fbee043e6..fbee043e6 100644
--- a/test/fixtures/httpoison_mock/mayumayupost.json
+++ b/test/fixtures/tesla_mock/mayumayupost.json
diff --git a/test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json b/test/fixtures/tesla_mock/mike@osada.macgirvin.com.json
index fe6b83ca6..fe6b83ca6 100644
--- a/test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json
+++ b/test/fixtures/tesla_mock/mike@osada.macgirvin.com.json
diff --git a/test/fixtures/httpoison_mock/nonexistant@social.heldscal.la.xml b/test/fixtures/tesla_mock/nonexistant@social.heldscal.la.xml
index 2a61de8dd..2a61de8dd 100644
--- a/test/fixtures/httpoison_mock/nonexistant@social.heldscal.la.xml
+++ b/test/fixtures/tesla_mock/nonexistant@social.heldscal.la.xml
diff --git a/test/fixtures/httpoison_mock/pawoo.net_host_meta b/test/fixtures/tesla_mock/pawoo.net_host_meta
index dbbe7be5f..dbbe7be5f 100644
--- a/test/fixtures/httpoison_mock/pawoo.net_host_meta
+++ b/test/fixtures/tesla_mock/pawoo.net_host_meta
diff --git a/test/fixtures/httpoison_mock/peertube.moe-vid.json b/test/fixtures/tesla_mock/peertube.moe-vid.json
index 76296eb7d..76296eb7d 100644
--- a/test/fixtures/httpoison_mock/peertube.moe-vid.json
+++ b/test/fixtures/tesla_mock/peertube.moe-vid.json
diff --git a/test/fixtures/httpoison_mock/pleroma.soykaf.com_host_meta b/test/fixtures/tesla_mock/pleroma.soykaf.com_host_meta
index fb5c15a4f..fb5c15a4f 100644
--- a/test/fixtures/httpoison_mock/pleroma.soykaf.com_host_meta
+++ b/test/fixtures/tesla_mock/pleroma.soykaf.com_host_meta
diff --git a/test/fixtures/httpoison_mock/puckipedia.com.json b/test/fixtures/tesla_mock/puckipedia.com.json
index d18dfbae7..d18dfbae7 100644
--- a/test/fixtures/httpoison_mock/puckipedia.com.json
+++ b/test/fixtures/tesla_mock/puckipedia.com.json
diff --git a/test/fixtures/tesla_mock/rinpatch.json b/test/fixtures/tesla_mock/rinpatch.json
new file mode 100644
index 000000000..59311ecb6
--- /dev/null
+++ b/test/fixtures/tesla_mock/rinpatch.json
@@ -0,0 +1,64 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ {
+ "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+ "toot": "http://joinmastodon.org/ns#",
+ "featured": {
+ "@id": "toot:featured",
+ "@type": "@id"
+ },
+ "alsoKnownAs": {
+ "@id": "as:alsoKnownAs",
+ "@type": "@id"
+ },
+ "movedTo": {
+ "@id": "as:movedTo",
+ "@type": "@id"
+ },
+ "schema": "http://schema.org#",
+ "PropertyValue": "schema:PropertyValue",
+ "value": "schema:value",
+ "Hashtag": "as:Hashtag",
+ "Emoji": "toot:Emoji",
+ "IdentityProof": "toot:IdentityProof",
+ "focalPoint": {
+ "@container": "@list",
+ "@id": "toot:focalPoint"
+ }
+ }
+ ],
+ "id": "https://mastodon.sdf.org/users/rinpatch",
+ "type": "Person",
+ "following": "https://mastodon.sdf.org/users/rinpatch/following",
+ "followers": "https://mastodon.sdf.org/users/rinpatch/followers",
+ "inbox": "https://mastodon.sdf.org/users/rinpatch/inbox",
+ "outbox": "https://mastodon.sdf.org/users/rinpatch/outbox",
+ "featured": "https://mastodon.sdf.org/users/rinpatch/collections/featured",
+ "preferredUsername": "rinpatch",
+ "name": "rinpatch",
+ "summary": "<p>umu</p>",
+ "url": "https://mastodon.sdf.org/@rinpatch",
+ "manuallyApprovesFollowers": false,
+ "publicKey": {
+ "id": "https://mastodon.sdf.org/users/rinpatch#main-key",
+ "owner": "https://mastodon.sdf.org/users/rinpatch",
+ "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1vbhYKDopb5xzfJB2TZY\n0ZvgxqdAhbSKKkQC5Q2b0ofhvueDy2AuZTnVk1/BbHNlqKlwhJUSpA6LiTZVvtcc\nMn6cmSaJJEg30gRF5GARP8FMcuq8e2jmceiW99NnUX17MQXsddSf2JFUwD0rUE8H\nBsgD7UzE9+zlA/PJOTBO7fvBEz9PTQ3r4sRMTJVFvKz2MU/U+aRNTuexRKMMPnUw\nfp6VWh1F44VWJEQOs4tOEjGiQiMQh5OfBk1w2haT3vrDbQvq23tNpUP1cRomLUtx\nEBcGKi5DMMBzE1RTVT1YUykR/zLWlA+JSmw7P6cWtsHYZovs8dgn8Po3X//6N+ng\nTQIDAQAB\n-----END PUBLIC KEY-----\n"
+ },
+ "tag": [],
+ "attachment": [],
+ "endpoints": {
+ "sharedInbox": "https://mastodon.sdf.org/inbox"
+ },
+ "icon": {
+ "type": "Image",
+ "mediaType": "image/jpeg",
+ "url": "https://mastodon.sdf.org/system/accounts/avatars/000/067/580/original/bf05521bf711b7a0.jpg?1533238802"
+ },
+ "image": {
+ "type": "Image",
+ "mediaType": "image/gif",
+ "url": "https://mastodon.sdf.org/system/accounts/headers/000/067/580/original/a99b987e798f7063.gif?1533278217"
+ }
+}
diff --git a/test/fixtures/httpoison_mock/rye.json b/test/fixtures/tesla_mock/rye.json
index f31d1ddd8..f31d1ddd8 100644
--- a/test/fixtures/httpoison_mock/rye.json
+++ b/test/fixtures/tesla_mock/rye.json
diff --git a/test/fixtures/httpoison_mock/sakamoto.atom b/test/fixtures/tesla_mock/sakamoto.atom
index 648946795..648946795 100644
--- a/test/fixtures/httpoison_mock/sakamoto.atom
+++ b/test/fixtures/tesla_mock/sakamoto.atom
diff --git a/test/fixtures/httpoison_mock/sakamoto_eal_feed.atom b/test/fixtures/tesla_mock/sakamoto_eal_feed.atom
index 9340d9038..9340d9038 100644
--- a/test/fixtures/httpoison_mock/sakamoto_eal_feed.atom
+++ b/test/fixtures/tesla_mock/sakamoto_eal_feed.atom
diff --git a/test/fixtures/httpoison_mock/shitposter.club_host_meta b/test/fixtures/tesla_mock/shitposter.club_host_meta
index 9d012e1df..9d012e1df 100644
--- a/test/fixtures/httpoison_mock/shitposter.club_host_meta
+++ b/test/fixtures/tesla_mock/shitposter.club_host_meta
diff --git a/test/fixtures/httpoison_mock/shp@pleroma.soykaf.com.feed b/test/fixtures/tesla_mock/shp@pleroma.soykaf.com.feed
index b24ef7ab6..b24ef7ab6 100644
--- a/test/fixtures/httpoison_mock/shp@pleroma.soykaf.com.feed
+++ b/test/fixtures/tesla_mock/shp@pleroma.soykaf.com.feed
diff --git a/test/fixtures/httpoison_mock/shp@pleroma.soykaf.com.webfigner b/test/fixtures/tesla_mock/shp@pleroma.soykaf.com.webfigner
index 23e84306c..23e84306c 100644
--- a/test/fixtures/httpoison_mock/shp@pleroma.soykaf.com.webfigner
+++ b/test/fixtures/tesla_mock/shp@pleroma.soykaf.com.webfigner
diff --git a/test/fixtures/httpoison_mock/shp@social.heldscal.la.xml b/test/fixtures/tesla_mock/shp@social.heldscal.la.xml
index 4cde42e3f..4cde42e3f 100644
--- a/test/fixtures/httpoison_mock/shp@social.heldscal.la.xml
+++ b/test/fixtures/tesla_mock/shp@social.heldscal.la.xml
diff --git a/test/fixtures/httpoison_mock/skruyb@mamot.fr.atom b/test/fixtures/tesla_mock/skruyb@mamot.fr.atom
index 1bbbc29f5..1bbbc29f5 100644
--- a/test/fixtures/httpoison_mock/skruyb@mamot.fr.atom
+++ b/test/fixtures/tesla_mock/skruyb@mamot.fr.atom
diff --git a/test/fixtures/httpoison_mock/social.heldscal.la_host_meta b/test/fixtures/tesla_mock/social.heldscal.la_host_meta
index 540e6257e..540e6257e 100644
--- a/test/fixtures/httpoison_mock/social.heldscal.la_host_meta
+++ b/test/fixtures/tesla_mock/social.heldscal.la_host_meta
diff --git a/test/fixtures/httpoison_mock/social.sakamoto.gq_host_meta b/test/fixtures/tesla_mock/social.sakamoto.gq_host_meta
index f193dce2b..f193dce2b 100644
--- a/test/fixtures/httpoison_mock/social.sakamoto.gq_host_meta
+++ b/test/fixtures/tesla_mock/social.sakamoto.gq_host_meta
diff --git a/test/fixtures/httpoison_mock/social.stopwatchingus-heidelberg.de_host_meta b/test/fixtures/tesla_mock/social.stopwatchingus-heidelberg.de_host_meta
index aafc9f60d..aafc9f60d 100644
--- a/test/fixtures/httpoison_mock/social.stopwatchingus-heidelberg.de_host_meta
+++ b/test/fixtures/tesla_mock/social.stopwatchingus-heidelberg.de_host_meta
diff --git a/test/fixtures/httpoison_mock/social.wxcafe.net_host_meta b/test/fixtures/tesla_mock/social.wxcafe.net_host_meta
index 5ffc40a90..5ffc40a90 100644
--- a/test/fixtures/httpoison_mock/social.wxcafe.net_host_meta
+++ b/test/fixtures/tesla_mock/social.wxcafe.net_host_meta
diff --git a/test/fixtures/httpoison_mock/spc_5381.atom b/test/fixtures/tesla_mock/spc_5381.atom
index c3288e97b..c3288e97b 100644
--- a/test/fixtures/httpoison_mock/spc_5381.atom
+++ b/test/fixtures/tesla_mock/spc_5381.atom
diff --git a/test/fixtures/httpoison_mock/spc_5381_xrd.xml b/test/fixtures/tesla_mock/spc_5381_xrd.xml
index b15fb276d..b15fb276d 100644
--- a/test/fixtures/httpoison_mock/spc_5381_xrd.xml
+++ b/test/fixtures/tesla_mock/spc_5381_xrd.xml
diff --git a/test/fixtures/httpoison_mock/squeet.me_host_meta b/test/fixtures/tesla_mock/squeet.me_host_meta
index 4a94ae574..4a94ae574 100644
--- a/test/fixtures/httpoison_mock/squeet.me_host_meta
+++ b/test/fixtures/tesla_mock/squeet.me_host_meta
diff --git a/test/fixtures/httpoison_mock/status.alpicola.com_host_meta b/test/fixtures/tesla_mock/status.alpicola.com_host_meta
index 6948c30ea..6948c30ea 100644
--- a/test/fixtures/httpoison_mock/status.alpicola.com_host_meta
+++ b/test/fixtures/tesla_mock/status.alpicola.com_host_meta
diff --git a/test/fixtures/httpoison_mock/status.emelie.json b/test/fixtures/tesla_mock/status.emelie.json
index 4aada0377..4aada0377 100644
--- a/test/fixtures/httpoison_mock/status.emelie.json
+++ b/test/fixtures/tesla_mock/status.emelie.json
diff --git a/test/fixtures/httpoison_mock/webfinger_emelie.json b/test/fixtures/tesla_mock/webfinger_emelie.json
index 0b61cb618..0b61cb618 100644
--- a/test/fixtures/httpoison_mock/webfinger_emelie.json
+++ b/test/fixtures/tesla_mock/webfinger_emelie.json
diff --git a/test/fixtures/httpoison_mock/winterdienst_webfinger.json b/test/fixtures/tesla_mock/winterdienst_webfinger.json
index e7bfba9ed..e7bfba9ed 100644
--- a/test/fixtures/httpoison_mock/winterdienst_webfinger.json
+++ b/test/fixtures/tesla_mock/winterdienst_webfinger.json
diff --git a/test/fixtures/users_mock/masto_closed_followers.json b/test/fixtures/users_mock/masto_closed_followers.json
new file mode 100644
index 000000000..da296892d
--- /dev/null
+++ b/test/fixtures/users_mock/masto_closed_followers.json
@@ -0,0 +1,7 @@
+{
+ "@context": "https://www.w3.org/ns/activitystreams",
+ "id": "http://localhost:4001/users/masto_closed/followers",
+ "type": "OrderedCollection",
+ "totalItems": 437,
+ "first": "http://localhost:4001/users/masto_closed/followers?page=1"
+}
diff --git a/test/fixtures/users_mock/masto_closed_following.json b/test/fixtures/users_mock/masto_closed_following.json
new file mode 100644
index 000000000..146d49f9c
--- /dev/null
+++ b/test/fixtures/users_mock/masto_closed_following.json
@@ -0,0 +1,7 @@
+{
+ "@context": "https://www.w3.org/ns/activitystreams",
+ "id": "http://localhost:4001/users/masto_closed/following",
+ "type": "OrderedCollection",
+ "totalItems": 152,
+ "first": "http://localhost:4001/users/masto_closed/following?page=1"
+}
diff --git a/test/fixtures/users_mock/pleroma_followers.json b/test/fixtures/users_mock/pleroma_followers.json
new file mode 100644
index 000000000..db71d084b
--- /dev/null
+++ b/test/fixtures/users_mock/pleroma_followers.json
@@ -0,0 +1,20 @@
+{
+ "type": "OrderedCollection",
+ "totalItems": 527,
+ "id": "http://localhost:4001/users/fuser2/followers",
+ "first": {
+ "type": "OrderedCollectionPage",
+ "totalItems": 527,
+ "partOf": "http://localhost:4001/users/fuser2/followers",
+ "orderedItems": [],
+ "next": "http://localhost:4001/users/fuser2/followers?page=2",
+ "id": "http://localhost:4001/users/fuser2/followers?page=1"
+ },
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "http://localhost:4001/schemas/litepub-0.1.jsonld",
+ {
+ "@language": "und"
+ }
+ ]
+}
diff --git a/test/fixtures/users_mock/pleroma_following.json b/test/fixtures/users_mock/pleroma_following.json
new file mode 100644
index 000000000..33d087703
--- /dev/null
+++ b/test/fixtures/users_mock/pleroma_following.json
@@ -0,0 +1,20 @@
+{
+ "type": "OrderedCollection",
+ "totalItems": 267,
+ "id": "http://localhost:4001/users/fuser2/following",
+ "first": {
+ "type": "OrderedCollectionPage",
+ "totalItems": 267,
+ "partOf": "http://localhost:4001/users/fuser2/following",
+ "orderedItems": [],
+ "next": "http://localhost:4001/users/fuser2/following?page=2",
+ "id": "http://localhost:4001/users/fuser2/following?page=1"
+ },
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "http://localhost:4001/schemas/litepub-0.1.jsonld",
+ {
+ "@language": "und"
+ }
+ ]
+}
diff --git a/test/healthcheck_test.exs b/test/healthcheck_test.exs
index e05061220..6bb8d5b7f 100644
--- a/test/healthcheck_test.exs
+++ b/test/healthcheck_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.HealthcheckTest do
use Pleroma.DataCase
alias Pleroma.Healthcheck
diff --git a/test/html_test.exs b/test/html_test.exs
index 08738276e..b8906c46a 100644
--- a/test/html_test.exs
+++ b/test/html_test.exs
@@ -4,8 +4,12 @@
defmodule Pleroma.HTMLTest do
alias Pleroma.HTML
+ alias Pleroma.Object
+ alias Pleroma.Web.CommonAPI
use Pleroma.DataCase
+ import Pleroma.Factory
+
@html_sample """
<b>this is in bold</b>
<p>this is a paragraph</p>
@@ -160,4 +164,69 @@ defmodule Pleroma.HTMLTest do
)
end
end
+
+ describe "extract_first_external_url" do
+ test "extracts the url" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "I think I just found the best github repo https://github.com/komeiji-satori/Dress"
+ })
+
+ object = Object.normalize(activity)
+ {:ok, url} = HTML.extract_first_external_url(object, object.data["content"])
+ assert url == "https://github.com/komeiji-satori/Dress"
+ end
+
+ test "skips mentions" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "@#{other_user.nickname} install misskey! https://github.com/syuilo/misskey/blob/develop/docs/setup.en.md"
+ })
+
+ object = Object.normalize(activity)
+ {:ok, url} = HTML.extract_first_external_url(object, object.data["content"])
+
+ assert url == "https://github.com/syuilo/misskey/blob/develop/docs/setup.en.md"
+
+ refute url == other_user.ap_id
+ end
+
+ test "skips hashtags" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "#cofe https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
+ })
+
+ object = Object.normalize(activity)
+ {:ok, url} = HTML.extract_first_external_url(object, object.data["content"])
+
+ assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
+ end
+
+ test "skips microformats hashtags" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "<a href=\"https://pleroma.gov/tags/cofe\" rel=\"tag\">#cofe</a> https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140",
+ "content_type" => "text/html"
+ })
+
+ object = Object.normalize(activity)
+ {:ok, url} = HTML.extract_first_external_url(object, object.data["content"])
+
+ assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
+ end
+ end
end
diff --git a/test/http/request_builder_test.exs b/test/http/request_builder_test.exs
new file mode 100644
index 000000000..7febe84c5
--- /dev/null
+++ b/test/http/request_builder_test.exs
@@ -0,0 +1,95 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.HTTP.RequestBuilderTest do
+ use ExUnit.Case, async: true
+ alias Pleroma.HTTP.RequestBuilder
+
+ describe "headers/2" do
+ 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()}]
+ }
+ end
+ end
+
+ describe "add_optional_params/3" do
+ test "don't add if keyword is empty" do
+ assert RequestBuilder.add_optional_params(%{}, %{}, []) == %{}
+ end
+
+ test "add query parameter" do
+ assert RequestBuilder.add_optional_params(
+ %{},
+ %{query: :query, body: :body, another: :val},
+ [
+ {:query, "param1=val1&param2=val2"},
+ {:body, "some body"}
+ ]
+ ) == %{query: "param1=val1&param2=val2", body: "some body"}
+ end
+ end
+
+ describe "add_param/4" do
+ test "add file parameter" do
+ %{
+ body: %Tesla.Multipart{
+ boundary: _,
+ content_type_params: [],
+ parts: [
+ %Tesla.Multipart.Part{
+ body: %File.Stream{
+ line_or_bytes: 2048,
+ modes: [:raw, :read_ahead, :read, :binary],
+ path: "some-path/filename.png",
+ raw: true
+ },
+ dispositions: [name: "filename.png", filename: "filename.png"],
+ headers: []
+ }
+ ]
+ }
+ } = RequestBuilder.add_param(%{}, :file, "filename.png", "some-path/filename.png")
+ end
+
+ test "add key to body" do
+ %{
+ body: %Tesla.Multipart{
+ boundary: _,
+ content_type_params: [],
+ parts: [
+ %Tesla.Multipart.Part{
+ body: "\"someval\"",
+ dispositions: [name: "somekey"],
+ headers: ["Content-Type": "application/json"]
+ }
+ ]
+ }
+ } = RequestBuilder.add_param(%{}, :body, "somekey", "someval")
+ end
+
+ test "add form parameter" do
+ assert RequestBuilder.add_param(%{}, :form, "somename", "someval") == %{
+ body: %{"somename" => "someval"}
+ }
+ end
+
+ test "add for location" do
+ assert RequestBuilder.add_param(%{}, :some_location, "somekey", "someval") == %{
+ some_location: [{"somekey", "someval"}]
+ }
+ end
+ end
+end
diff --git a/test/integration/mastodon_websocket_test.exs b/test/integration/mastodon_websocket_test.exs
index b42c9ef07..3975cdcd6 100644
--- a/test/integration/mastodon_websocket_test.exs
+++ b/test/integration/mastodon_websocket_test.exs
@@ -97,5 +97,22 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
test "accepts valid tokens", state do
assert {:ok, _} = start_socket("?stream=user&access_token=#{state.token.token}")
end
+
+ test "accepts the 'user' stream", %{token: token} = _state do
+ assert {:ok, _} = start_socket("?stream=user&access_token=#{token.token}")
+ assert {:error, {403, "Forbidden"}} = start_socket("?stream=user")
+ end
+
+ test "accepts the 'user:notification' stream", %{token: token} = _state do
+ assert {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}")
+ assert {:error, {403, "Forbidden"}} = start_socket("?stream=user:notification")
+ end
+
+ test "accepts valid token on Sec-WebSocket-Protocol header", %{token: token} do
+ assert {:ok, _} = start_socket("?stream=user", [{"Sec-WebSocket-Protocol", token.token}])
+
+ assert {:error, {403, "Forbidden"}} =
+ start_socket("?stream=user", [{"Sec-WebSocket-Protocol", "I am a friend"}])
+ end
end
end
diff --git a/test/keys_test.exs b/test/keys_test.exs
index 776fdea6f..059f70b74 100644
--- a/test/keys_test.exs
+++ b/test/keys_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.KeysTest do
use Pleroma.DataCase
diff --git a/test/list_test.exs b/test/list_test.exs
index 1909c0cd9..f39033d02 100644
--- a/test/list_test.exs
+++ b/test/list_test.exs
@@ -113,4 +113,30 @@ defmodule Pleroma.ListTest do
assert owned_list in lists_2
refute not_owned_list in lists_2
end
+
+ test "get by ap_id" do
+ user = insert(:user)
+ {:ok, list} = Pleroma.List.create("foo", user)
+ assert Pleroma.List.get_by_ap_id(list.ap_id) == list
+ end
+
+ test "memberships" do
+ user = insert(:user)
+ member = insert(:user)
+ {:ok, list} = Pleroma.List.create("foo", user)
+ {:ok, list} = Pleroma.List.follow(list, member)
+
+ assert Pleroma.List.memberships(member) == [list.ap_id]
+ end
+
+ test "member?" do
+ user = insert(:user)
+ member = insert(:user)
+
+ {:ok, list} = Pleroma.List.create("foo", user)
+ {:ok, list} = Pleroma.List.follow(list, member)
+
+ assert Pleroma.List.member?(list, member)
+ refute Pleroma.List.member?(list, user)
+ end
end
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 581db58a8..dda570b49 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -8,6 +8,7 @@ defmodule Pleroma.NotificationTest do
alias Pleroma.User
alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.Streamer
alias Pleroma.Web.TwitterAPI.TwitterAPI
import Pleroma.Factory
@@ -44,26 +45,66 @@ defmodule Pleroma.NotificationTest do
end
describe "create_notification" do
- test "it doesn't create a notification for user if the user blocks the activity author" do
+ setup do
+ GenServer.start(Streamer, %{}, name: Streamer)
+
+ on_exit(fn ->
+ if pid = Process.whereis(Streamer) do
+ Process.exit(pid, :kill)
+ end
+ end)
+ end
+
+ test "it creates a notification for user and send to the 'user' and the 'user:notification' stream" do
+ user = insert(:user)
+ task = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
+ task_user_notification = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
+ Streamer.add_socket("user", %{transport_pid: task.pid, assigns: %{user: user}})
+
+ Streamer.add_socket(
+ "user:notification",
+ %{transport_pid: task_user_notification.pid, assigns: %{user: user}}
+ )
+
+ activity = insert(:note_activity)
+
+ notify = Notification.create_notification(activity, user)
+ assert notify.user_id == user.id
+ Task.await(task)
+ Task.await(task_user_notification)
+ end
+
+ test "it creates a notification for user if the user blocks the activity author" do
activity = insert(:note_activity)
author = User.get_cached_by_ap_id(activity.data["actor"])
user = insert(:user)
{:ok, user} = User.block(user, author)
- assert nil == Notification.create_notification(activity, user)
+ assert Notification.create_notification(activity, user)
end
- test "it doesn't create a notificatin for the user if the user mutes the activity author" do
+ test "it creates a notificatin for the user if the user mutes the activity author" do
muter = insert(:user)
muted = insert(:user)
{:ok, _} = User.mute(muter, muted)
muter = Repo.get(User, muter.id)
{:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
- assert nil == Notification.create_notification(activity, muter)
+ assert Notification.create_notification(activity, muter)
+ end
+
+ test "notification created if user is muted without notifications" do
+ muter = insert(:user)
+ muted = insert(:user)
+
+ {:ok, muter} = User.mute(muter, muted, false)
+
+ {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
+
+ assert Notification.create_notification(activity, muter)
end
- test "it doesn't create a notification for an activity from a muted thread" do
+ test "it creates a notification for an activity from a muted thread" do
muter = insert(:user)
other_user = insert(:user)
{:ok, activity} = CommonAPI.post(muter, %{"status" => "hey"})
@@ -75,34 +116,7 @@ defmodule Pleroma.NotificationTest do
"in_reply_to_status_id" => activity.id
})
- assert nil == Notification.create_notification(activity, muter)
- end
-
- test "it disables notifications from people on remote instances" do
- user = insert(:user, info: %{notification_settings: %{"remote" => false}})
- other_user = insert(:user)
-
- create_activity = %{
- "@context" => "https://www.w3.org/ns/activitystreams",
- "type" => "Create",
- "to" => ["https://www.w3.org/ns/activitystreams#Public"],
- "actor" => other_user.ap_id,
- "object" => %{
- "type" => "Note",
- "content" => "Hi @#{user.nickname}",
- "attributedTo" => other_user.ap_id
- }
- }
-
- {:ok, %{local: false} = activity} = Transmogrifier.handle_incoming(create_activity)
- assert nil == Notification.create_notification(activity, user)
- end
-
- test "it disables notifications from people on the local instance" do
- user = insert(:user, info: %{notification_settings: %{"local" => false}})
- other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hey @#{user.nickname}"})
- assert nil == Notification.create_notification(activity, user)
+ assert Notification.create_notification(activity, muter)
end
test "it disables notifications from followers" do
@@ -110,7 +124,14 @@ defmodule Pleroma.NotificationTest do
followed = insert(:user, info: %{notification_settings: %{"followers" => false}})
User.follow(follower, followed)
{:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
- assert nil == Notification.create_notification(activity, followed)
+ refute Notification.create_notification(activity, followed)
+ end
+
+ test "it disables notifications from non-followers" do
+ follower = insert(:user)
+ followed = insert(:user, info: %{notification_settings: %{"non_followers" => false}})
+ {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
+ refute Notification.create_notification(activity, followed)
end
test "it disables notifications from people the user follows" do
@@ -119,14 +140,21 @@ defmodule Pleroma.NotificationTest do
User.follow(follower, followed)
follower = Repo.get(User, follower.id)
{:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
- assert nil == Notification.create_notification(activity, follower)
+ refute Notification.create_notification(activity, follower)
+ end
+
+ test "it disables notifications from people the user does not follow" do
+ follower = insert(:user, info: %{notification_settings: %{"non_follows" => false}})
+ followed = insert(:user)
+ {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
+ refute Notification.create_notification(activity, follower)
end
test "it doesn't create a notification for user if he is the activity author" do
activity = insert(:note_activity)
author = User.get_cached_by_ap_id(activity.data["actor"])
- assert nil == Notification.create_notification(activity, author)
+ refute Notification.create_notification(activity, author)
end
test "it doesn't create a notification for follow-unfollow-follow chains" do
@@ -136,7 +164,7 @@ defmodule Pleroma.NotificationTest do
Notification.create_notification(activity, followed_user)
TwitterAPI.unfollow(user, %{"user_id" => followed_user.id})
{:ok, _, _, activity_dupe} = TwitterAPI.follow(user, %{"user_id" => followed_user.id})
- assert nil == Notification.create_notification(activity_dupe, followed_user)
+ refute Notification.create_notification(activity_dupe, followed_user)
end
test "it doesn't create a notification for like-unlike-like chains" do
@@ -147,7 +175,7 @@ defmodule Pleroma.NotificationTest do
Notification.create_notification(fav_status, liked_user)
TwitterAPI.unfav(user, status.id)
{:ok, dupe} = TwitterAPI.fav(user, status.id)
- assert nil == Notification.create_notification(dupe, liked_user)
+ refute Notification.create_notification(dupe, liked_user)
end
test "it doesn't create a notification for repeat-unrepeat-repeat chains" do
@@ -163,7 +191,7 @@ defmodule Pleroma.NotificationTest do
Notification.create_notification(retweeted_activity, retweeted_user)
TwitterAPI.unrepeat(user, status.id)
{:ok, dupe} = TwitterAPI.repeat(user, status.id)
- assert nil == Notification.create_notification(dupe, retweeted_user)
+ refute Notification.create_notification(dupe, retweeted_user)
end
test "it doesn't create duplicate notifications for follow+subscribed users" do
@@ -515,4 +543,98 @@ defmodule Pleroma.NotificationTest do
assert Enum.empty?(Notification.for_user(user))
end
end
+
+ describe "for_user" do
+ test "it returns notifications for muted user without notifications" do
+ user = insert(:user)
+ muted = insert(:user)
+ {:ok, user} = User.mute(user, muted, false)
+
+ {:ok, _activity} = TwitterAPI.create_status(muted, %{"status" => "hey @#{user.nickname}"})
+
+ assert length(Notification.for_user(user)) == 1
+ end
+
+ test "it doesn't return notifications for muted user with notifications" do
+ user = insert(:user)
+ muted = insert(:user)
+ {:ok, user} = User.mute(user, muted)
+
+ {:ok, _activity} = TwitterAPI.create_status(muted, %{"status" => "hey @#{user.nickname}"})
+
+ assert Notification.for_user(user) == []
+ end
+
+ test "it doesn't return notifications for blocked user" do
+ user = insert(:user)
+ blocked = insert(:user)
+ {:ok, user} = User.block(user, blocked)
+
+ {:ok, _activity} = TwitterAPI.create_status(blocked, %{"status" => "hey @#{user.nickname}"})
+
+ assert Notification.for_user(user) == []
+ end
+
+ test "it doesn't return notificatitons for blocked domain" do
+ user = insert(:user)
+ blocked = insert(:user, ap_id: "http://some-domain.com")
+ {:ok, user} = User.block_domain(user, "some-domain.com")
+
+ {:ok, _activity} = TwitterAPI.create_status(blocked, %{"status" => "hey @#{user.nickname}"})
+
+ assert Notification.for_user(user) == []
+ end
+
+ test "it doesn't return notifications for muted thread" do
+ user = insert(:user)
+ another_user = insert(:user)
+
+ {:ok, activity} =
+ TwitterAPI.create_status(another_user, %{"status" => "hey @#{user.nickname}"})
+
+ {:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
+ assert Notification.for_user(user) == []
+ end
+
+ test "it returns notifications for muted user with notifications and with_muted parameter" do
+ user = insert(:user)
+ muted = insert(:user)
+ {:ok, user} = User.mute(user, muted)
+
+ {:ok, _activity} = TwitterAPI.create_status(muted, %{"status" => "hey @#{user.nickname}"})
+
+ assert length(Notification.for_user(user, %{with_muted: true})) == 1
+ end
+
+ test "it returns notifications for blocked user and with_muted parameter" do
+ user = insert(:user)
+ blocked = insert(:user)
+ {:ok, user} = User.block(user, blocked)
+
+ {:ok, _activity} = TwitterAPI.create_status(blocked, %{"status" => "hey @#{user.nickname}"})
+
+ assert length(Notification.for_user(user, %{with_muted: true})) == 1
+ end
+
+ test "it returns notificatitons for blocked domain and with_muted parameter" do
+ user = insert(:user)
+ blocked = insert(:user, ap_id: "http://some-domain.com")
+ {:ok, user} = User.block_domain(user, "some-domain.com")
+
+ {:ok, _activity} = TwitterAPI.create_status(blocked, %{"status" => "hey @#{user.nickname}"})
+
+ assert length(Notification.for_user(user, %{with_muted: true})) == 1
+ end
+
+ test "it returns notifications for muted thread with_muted parameter" do
+ user = insert(:user)
+ another_user = insert(:user)
+
+ {:ok, activity} =
+ TwitterAPI.create_status(another_user, %{"status" => "hey @#{user.nickname}"})
+
+ {:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
+ assert length(Notification.for_user(user, %{with_muted: true})) == 1
+ end
+ end
end
diff --git a/test/object/containment_test.exs b/test/object/containment_test.exs
index 452064093..61cd1b412 100644
--- a/test/object/containment_test.exs
+++ b/test/object/containment_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Object.ContainmentTest do
use Pleroma.DataCase
@@ -5,6 +9,12 @@ defmodule Pleroma.Object.ContainmentTest do
alias Pleroma.User
import Pleroma.Factory
+ import ExUnit.CaptureLog
+
+ setup_all do
+ Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
describe "general origin containment" do
test "contain_origin_from_id() catches obvious spoofing attempts" do
@@ -52,7 +62,40 @@ defmodule Pleroma.Object.ContainmentTest do
follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
})
- {:error, _} = User.get_or_fetch_by_ap_id("https://n1u.moe/users/rye")
+ assert capture_log(fn ->
+ {:error, _} = User.get_or_fetch_by_ap_id("https://n1u.moe/users/rye")
+ end) =~
+ "[error] Could not decode user at fetch https://n1u.moe/users/rye, {:error, :error}"
+ end
+ end
+
+ describe "containment of children" do
+ test "contain_child() catches spoofing attempts" do
+ data = %{
+ "id" => "http://example.com/whatever",
+ "type" => "Create",
+ "object" => %{
+ "id" => "http://example.net/~alyssa/activities/1234",
+ "attributedTo" => "http://example.org/~alyssa"
+ },
+ "actor" => "http://example.com/~bob"
+ }
+
+ :error = Containment.contain_child(data)
+ end
+
+ test "contain_child() allows correct origins" do
+ data = %{
+ "id" => "http://example.org/~alyssa/activities/5678",
+ "type" => "Create",
+ "object" => %{
+ "id" => "http://example.org/~alyssa/activities/1234",
+ "attributedTo" => "http://example.org/~alyssa"
+ },
+ "actor" => "http://example.org/~alyssa"
+ }
+
+ :ok = Containment.contain_child(data)
end
end
end
diff --git a/test/object/fetcher_test.exs b/test/object/fetcher_test.exs
index d604fd5f5..56a9d775f 100644
--- a/test/object/fetcher_test.exs
+++ b/test/object/fetcher_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Object.FetcherTest do
use Pleroma.DataCase
@@ -5,23 +9,49 @@ defmodule Pleroma.Object.FetcherTest do
alias Pleroma.Object
alias Pleroma.Object.Fetcher
import Tesla.Mock
+ import Mock
setup do
- mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ mock(fn
+ %{method: :get, url: "https://mastodon.example.org/users/userisgone"} ->
+ %Tesla.Env{status: 410}
+
+ %{method: :get, url: "https://mastodon.example.org/users/userisgone404"} ->
+ %Tesla.Env{status: 404}
+
+ env ->
+ apply(HttpRequestMock, :request, [env])
+ end)
+
:ok
end
describe "actor origin containment" do
- test "it rejects objects with a bogus origin" do
+ test_with_mock "it rejects objects with a bogus origin",
+ Pleroma.Web.OStatus,
+ [:passthrough],
+ [] do
{:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity.json")
+
+ refute called(Pleroma.Web.OStatus.fetch_activity_from_url(:_))
end
- test "it rejects objects when attributedTo is wrong (variant 1)" do
+ test_with_mock "it rejects objects when attributedTo is wrong (variant 1)",
+ Pleroma.Web.OStatus,
+ [:passthrough],
+ [] do
{:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity2.json")
+
+ refute called(Pleroma.Web.OStatus.fetch_activity_from_url(:_))
end
- test "it rejects objects when attributedTo is wrong (variant 2)" do
+ test_with_mock "it rejects objects when attributedTo is wrong (variant 2)",
+ Pleroma.Web.OStatus,
+ [:passthrough],
+ [] do
{:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity3.json")
+
+ refute called(Pleroma.Web.OStatus.fetch_activity_from_url(:_))
end
end
@@ -81,10 +111,24 @@ defmodule Pleroma.Object.FetcherTest do
end
test "all objects with fake directions are rejected by the object fetcher" do
- {:error, _} =
- Fetcher.fetch_and_contain_remote_object_from_id(
- "https://info.pleroma.site/activity4.json"
- )
+ assert {:error, _} =
+ Fetcher.fetch_and_contain_remote_object_from_id(
+ "https://info.pleroma.site/activity4.json"
+ )
+ end
+
+ test "handle HTTP 410 Gone response" do
+ assert {:error, "Object has been deleted"} ==
+ Fetcher.fetch_and_contain_remote_object_from_id(
+ "https://mastodon.example.org/users/userisgone"
+ )
+ end
+
+ test "handle HTTP 404 response" do
+ assert {:error, "Object has been deleted"} ==
+ Fetcher.fetch_and_contain_remote_object_from_id(
+ "https://mastodon.example.org/users/userisgone404"
+ )
end
end
diff --git a/test/plugs/idempotency_plug_test.exs b/test/plugs/idempotency_plug_test.exs
new file mode 100644
index 000000000..ac1735f13
--- /dev/null
+++ b/test/plugs/idempotency_plug_test.exs
@@ -0,0 +1,110 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Plugs.IdempotencyPlugTest do
+ use ExUnit.Case, async: true
+ use Plug.Test
+
+ alias Pleroma.Plugs.IdempotencyPlug
+ alias Plug.Conn
+
+ test "returns result from cache" do
+ key = "test1"
+ orig_request_id = "test1"
+ second_request_id = "test2"
+ body = "testing"
+ status = 200
+
+ :post
+ |> conn("/cofe")
+ |> put_req_header("idempotency-key", key)
+ |> Conn.put_resp_header("x-request-id", orig_request_id)
+ |> Conn.put_resp_content_type("application/json")
+ |> IdempotencyPlug.call([])
+ |> Conn.send_resp(status, body)
+
+ conn =
+ :post
+ |> conn("/cofe")
+ |> put_req_header("idempotency-key", key)
+ |> Conn.put_resp_header("x-request-id", second_request_id)
+ |> Conn.put_resp_content_type("application/json")
+ |> IdempotencyPlug.call([])
+
+ assert_raise Conn.AlreadySentError, fn ->
+ Conn.send_resp(conn, :im_a_teapot, "no cofe")
+ end
+
+ assert conn.resp_body == body
+ assert conn.status == status
+
+ assert [^second_request_id] = Conn.get_resp_header(conn, "x-request-id")
+ assert [^orig_request_id] = Conn.get_resp_header(conn, "x-original-request-id")
+ assert [^key] = Conn.get_resp_header(conn, "idempotency-key")
+ assert ["true"] = Conn.get_resp_header(conn, "idempotent-replayed")
+ assert ["application/json; charset=utf-8"] = Conn.get_resp_header(conn, "content-type")
+ end
+
+ test "pass conn downstream if the cache not found" do
+ key = "test2"
+ orig_request_id = "test3"
+ body = "testing"
+ status = 200
+
+ conn =
+ :post
+ |> conn("/cofe")
+ |> put_req_header("idempotency-key", key)
+ |> Conn.put_resp_header("x-request-id", orig_request_id)
+ |> Conn.put_resp_content_type("application/json")
+ |> IdempotencyPlug.call([])
+ |> Conn.send_resp(status, body)
+
+ assert conn.resp_body == body
+ assert conn.status == status
+
+ assert [] = Conn.get_resp_header(conn, "idempotent-replayed")
+ assert [^key] = Conn.get_resp_header(conn, "idempotency-key")
+ end
+
+ test "passes conn downstream if idempotency is not present in headers" do
+ orig_request_id = "test4"
+ body = "testing"
+ status = 200
+
+ conn =
+ :post
+ |> conn("/cofe")
+ |> Conn.put_resp_header("x-request-id", orig_request_id)
+ |> Conn.put_resp_content_type("application/json")
+ |> IdempotencyPlug.call([])
+ |> Conn.send_resp(status, body)
+
+ assert [] = Conn.get_resp_header(conn, "idempotency-key")
+ end
+
+ test "doesn't work with GET/DELETE" do
+ key = "test3"
+ body = "testing"
+ status = 200
+
+ conn =
+ :get
+ |> conn("/cofe")
+ |> put_req_header("idempotency-key", key)
+ |> IdempotencyPlug.call([])
+ |> Conn.send_resp(status, body)
+
+ assert [] = Conn.get_resp_header(conn, "idempotency-key")
+
+ conn =
+ :delete
+ |> conn("/cofe")
+ |> put_req_header("idempotency-key", key)
+ |> IdempotencyPlug.call([])
+ |> Conn.send_resp(status, body)
+
+ assert [] = Conn.get_resp_header(conn, "idempotency-key")
+ end
+end
diff --git a/test/plugs/rate_limit_plug_test.exs b/test/plugs/rate_limit_plug_test.exs
deleted file mode 100644
index 2ec9a8fb7..000000000
--- a/test/plugs/rate_limit_plug_test.exs
+++ /dev/null
@@ -1,50 +0,0 @@
-defmodule Pleroma.Plugs.RateLimitPlugTest do
- use ExUnit.Case, async: true
- use Plug.Test
-
- alias Pleroma.Plugs.RateLimitPlug
-
- @opts RateLimitPlug.init(%{max_requests: 5, interval: 1})
-
- setup do
- enabled = Pleroma.Config.get([:app_account_creation, :enabled])
-
- Pleroma.Config.put([:app_account_creation, :enabled], true)
-
- on_exit(fn ->
- Pleroma.Config.put([:app_account_creation, :enabled], enabled)
- end)
-
- :ok
- end
-
- test "it restricts by opts" do
- conn = conn(:get, "/")
- bucket_name = conn.remote_ip |> Tuple.to_list() |> Enum.join(".")
- ms = 1000
-
- conn = RateLimitPlug.call(conn, @opts)
- {1, 4, _, _, _} = ExRated.inspect_bucket(bucket_name, ms, 5)
- conn = RateLimitPlug.call(conn, @opts)
- {2, 3, _, _, _} = ExRated.inspect_bucket(bucket_name, ms, 5)
- conn = RateLimitPlug.call(conn, @opts)
- {3, 2, _, _, _} = ExRated.inspect_bucket(bucket_name, ms, 5)
- conn = RateLimitPlug.call(conn, @opts)
- {4, 1, _, _, _} = ExRated.inspect_bucket(bucket_name, ms, 5)
- conn = RateLimitPlug.call(conn, @opts)
- {5, 0, to_reset, _, _} = ExRated.inspect_bucket(bucket_name, ms, 5)
- conn = RateLimitPlug.call(conn, @opts)
- assert conn.status == 403
- assert conn.halted
- assert conn.resp_body == "{\"error\":\"Rate limit exceeded.\"}"
-
- Process.sleep(to_reset)
-
- conn = conn(:get, "/")
- conn = RateLimitPlug.call(conn, @opts)
- {1, 4, _, _, _} = ExRated.inspect_bucket(bucket_name, ms, 5)
- refute conn.status == 403
- refute conn.halted
- refute conn.resp_body
- end
-end
diff --git a/test/plugs/rate_limiter_test.exs b/test/plugs/rate_limiter_test.exs
new file mode 100644
index 000000000..395095079
--- /dev/null
+++ b/test/plugs/rate_limiter_test.exs
@@ -0,0 +1,174 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Plugs.RateLimiterTest do
+ use ExUnit.Case, async: true
+ use Plug.Test
+
+ alias Pleroma.Plugs.RateLimiter
+
+ import Pleroma.Factory
+
+ # Note: each example must work with separate buckets in order to prevent concurrency issues
+
+ test "init/1" do
+ limiter_name = :test_init
+ Pleroma.Config.put([:rate_limit, limiter_name], {1, 1})
+
+ assert {limiter_name, {1, 1}, []} == RateLimiter.init(limiter_name)
+ assert nil == RateLimiter.init(:foo)
+ end
+
+ test "ip/1" do
+ assert "127.0.0.1" == RateLimiter.ip(%{remote_ip: {127, 0, 0, 1}})
+ end
+
+ test "it restricts by opts" do
+ limiter_name = :test_opts
+ scale = 1000
+ limit = 5
+
+ Pleroma.Config.put([:rate_limit, limiter_name], {scale, limit})
+
+ opts = RateLimiter.init(limiter_name)
+ conn = conn(:get, "/")
+ bucket_name = "#{limiter_name}:#{RateLimiter.ip(conn)}"
+
+ conn = RateLimiter.call(conn, opts)
+ assert {1, 4, _, _, _} = ExRated.inspect_bucket(bucket_name, scale, limit)
+
+ conn = RateLimiter.call(conn, opts)
+ assert {2, 3, _, _, _} = ExRated.inspect_bucket(bucket_name, scale, limit)
+
+ conn = RateLimiter.call(conn, opts)
+ assert {3, 2, _, _, _} = ExRated.inspect_bucket(bucket_name, scale, limit)
+
+ conn = RateLimiter.call(conn, opts)
+ assert {4, 1, _, _, _} = ExRated.inspect_bucket(bucket_name, scale, limit)
+
+ conn = RateLimiter.call(conn, opts)
+ assert {5, 0, to_reset, _, _} = ExRated.inspect_bucket(bucket_name, scale, limit)
+
+ conn = RateLimiter.call(conn, opts)
+
+ assert %{"error" => "Throttled"} = Phoenix.ConnTest.json_response(conn, :too_many_requests)
+ assert conn.halted
+
+ Process.sleep(to_reset)
+
+ conn = conn(:get, "/")
+
+ conn = RateLimiter.call(conn, opts)
+ assert {1, 4, _, _, _} = ExRated.inspect_bucket(bucket_name, scale, limit)
+
+ refute conn.status == Plug.Conn.Status.code(:too_many_requests)
+ refute conn.resp_body
+ refute conn.halted
+ end
+
+ test "`bucket_name` option overrides default bucket name" do
+ limiter_name = :test_bucket_name
+ scale = 1000
+ limit = 5
+
+ Pleroma.Config.put([:rate_limit, limiter_name], {scale, limit})
+ base_bucket_name = "#{limiter_name}:group1"
+ opts = RateLimiter.init({limiter_name, bucket_name: base_bucket_name})
+
+ conn = conn(:get, "/")
+ default_bucket_name = "#{limiter_name}:#{RateLimiter.ip(conn)}"
+ customized_bucket_name = "#{base_bucket_name}:#{RateLimiter.ip(conn)}"
+
+ RateLimiter.call(conn, opts)
+ assert {1, 4, _, _, _} = ExRated.inspect_bucket(customized_bucket_name, scale, limit)
+ assert {0, 5, _, _, _} = ExRated.inspect_bucket(default_bucket_name, scale, limit)
+ end
+
+ test "`params` option appends specified params' values to bucket name" do
+ limiter_name = :test_params
+ scale = 1000
+ limit = 5
+
+ Pleroma.Config.put([:rate_limit, limiter_name], {scale, limit})
+ opts = RateLimiter.init({limiter_name, params: ["id"]})
+ id = "1"
+
+ conn = conn(:get, "/?id=#{id}")
+ conn = Plug.Conn.fetch_query_params(conn)
+
+ default_bucket_name = "#{limiter_name}:#{RateLimiter.ip(conn)}"
+ parametrized_bucket_name = "#{limiter_name}:#{id}:#{RateLimiter.ip(conn)}"
+
+ RateLimiter.call(conn, opts)
+ assert {1, 4, _, _, _} = ExRated.inspect_bucket(parametrized_bucket_name, scale, limit)
+ assert {0, 5, _, _, _} = ExRated.inspect_bucket(default_bucket_name, scale, limit)
+ end
+
+ test "it supports combination of options modifying bucket name" do
+ limiter_name = :test_options_combo
+ scale = 1000
+ limit = 5
+
+ Pleroma.Config.put([:rate_limit, limiter_name], {scale, limit})
+ base_bucket_name = "#{limiter_name}:group1"
+ opts = RateLimiter.init({limiter_name, bucket_name: base_bucket_name, params: ["id"]})
+ id = "100"
+
+ conn = conn(:get, "/?id=#{id}")
+ conn = Plug.Conn.fetch_query_params(conn)
+
+ default_bucket_name = "#{limiter_name}:#{RateLimiter.ip(conn)}"
+ parametrized_bucket_name = "#{base_bucket_name}:#{id}:#{RateLimiter.ip(conn)}"
+
+ RateLimiter.call(conn, opts)
+ assert {1, 4, _, _, _} = ExRated.inspect_bucket(parametrized_bucket_name, scale, limit)
+ assert {0, 5, _, _, _} = ExRated.inspect_bucket(default_bucket_name, scale, limit)
+ end
+
+ test "optional limits for authenticated users" do
+ limiter_name = :test_authenticated
+ Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
+
+ scale = 1000
+ limit = 5
+ Pleroma.Config.put([:rate_limit, limiter_name], [{1, 10}, {scale, limit}])
+
+ opts = RateLimiter.init(limiter_name)
+
+ user = insert(:user)
+ conn = conn(:get, "/") |> assign(:user, user)
+ bucket_name = "#{limiter_name}:#{user.id}"
+
+ conn = RateLimiter.call(conn, opts)
+ assert {1, 4, _, _, _} = ExRated.inspect_bucket(bucket_name, scale, limit)
+
+ conn = RateLimiter.call(conn, opts)
+ assert {2, 3, _, _, _} = ExRated.inspect_bucket(bucket_name, scale, limit)
+
+ conn = RateLimiter.call(conn, opts)
+ assert {3, 2, _, _, _} = ExRated.inspect_bucket(bucket_name, scale, limit)
+
+ conn = RateLimiter.call(conn, opts)
+ assert {4, 1, _, _, _} = ExRated.inspect_bucket(bucket_name, scale, limit)
+
+ conn = RateLimiter.call(conn, opts)
+ assert {5, 0, to_reset, _, _} = ExRated.inspect_bucket(bucket_name, scale, limit)
+
+ conn = RateLimiter.call(conn, opts)
+
+ assert %{"error" => "Throttled"} = Phoenix.ConnTest.json_response(conn, :too_many_requests)
+ assert conn.halted
+
+ Process.sleep(to_reset)
+
+ conn = conn(:get, "/") |> assign(:user, user)
+
+ conn = RateLimiter.call(conn, opts)
+ assert {1, 4, _, _, _} = ExRated.inspect_bucket(bucket_name, scale, limit)
+
+ refute conn.status == Plug.Conn.Status.code(:too_many_requests)
+ refute conn.resp_body
+ refute conn.halted
+ end
+end
diff --git a/test/plugs/set_locale_plug_test.exs b/test/plugs/set_locale_plug_test.exs
new file mode 100644
index 000000000..b6c4c1cea
--- /dev/null
+++ b/test/plugs/set_locale_plug_test.exs
@@ -0,0 +1,46 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Plugs.SetLocalePlugTest do
+ use ExUnit.Case, async: true
+ use Plug.Test
+
+ alias Pleroma.Plugs.SetLocalePlug
+ alias Plug.Conn
+
+ test "default locale is `en`" do
+ conn =
+ :get
+ |> conn("/cofe")
+ |> SetLocalePlug.call([])
+
+ assert "en" == Gettext.get_locale()
+ assert %{locale: "en"} == conn.assigns
+ end
+
+ test "use supported locale from `accept-language`" do
+ conn =
+ :get
+ |> conn("/cofe")
+ |> Conn.put_req_header(
+ "accept-language",
+ "ru, fr-CH, fr;q=0.9, en;q=0.8, *;q=0.5"
+ )
+ |> SetLocalePlug.call([])
+
+ assert "ru" == Gettext.get_locale()
+ assert %{locale: "ru"} == conn.assigns
+ end
+
+ test "use default locale if locale from `accept-language` is not supported" do
+ conn =
+ :get
+ |> conn("/cofe")
+ |> Conn.put_req_header("accept-language", "tlh")
+ |> SetLocalePlug.call([])
+
+ assert "en" == Gettext.get_locale()
+ assert %{locale: "en"} == conn.assigns
+ end
+end
diff --git a/test/repo_test.exs b/test/repo_test.exs
index 85085a1fa..85b64d4d1 100644
--- a/test/repo_test.exs
+++ b/test/repo_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.RepoTest do
use Pleroma.DataCase
import Pleroma.Factory
diff --git a/test/reverse_proxy_test.exs b/test/reverse_proxy_test.exs
new file mode 100644
index 000000000..f4b7d6add
--- /dev/null
+++ b/test/reverse_proxy_test.exs
@@ -0,0 +1,300 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.ReverseProxyTest do
+ use Pleroma.Web.ConnCase, async: true
+ import ExUnit.CaptureLog
+ import Mox
+ alias Pleroma.ReverseProxy
+ alias Pleroma.ReverseProxy.ClientMock
+
+ setup_all do
+ {:ok, _} = Registry.start_link(keys: :unique, name: Pleroma.ReverseProxy.ClientMock)
+ :ok
+ end
+
+ setup :verify_on_exit!
+
+ defp user_agent_mock(user_agent, invokes) do
+ json = Jason.encode!(%{"user-agent": user_agent})
+
+ ClientMock
+ |> expect(:request, fn :get, url, _, _, _ ->
+ Registry.register(Pleroma.ReverseProxy.ClientMock, url, 0)
+
+ {:ok, 200,
+ [
+ {"content-type", "application/json"},
+ {"content-length", byte_size(json) |> to_string()}
+ ], %{url: url}}
+ end)
+ |> expect(:stream_body, invokes, fn %{url: url} ->
+ case Registry.lookup(Pleroma.ReverseProxy.ClientMock, url) do
+ [{_, 0}] ->
+ Registry.update_value(Pleroma.ReverseProxy.ClientMock, url, &(&1 + 1))
+ {:ok, json}
+
+ [{_, 1}] ->
+ Registry.unregister(Pleroma.ReverseProxy.ClientMock, url)
+ :done
+ end
+ end)
+ end
+
+ describe "user-agent" do
+ test "don't keep", %{conn: conn} do
+ user_agent_mock("hackney/1.15.1", 2)
+ conn = ReverseProxy.call(conn, "/user-agent")
+ assert json_response(conn, 200) == %{"user-agent" => "hackney/1.15.1"}
+ end
+
+ test "keep", %{conn: conn} do
+ user_agent_mock(Pleroma.Application.user_agent(), 2)
+ conn = ReverseProxy.call(conn, "/user-agent-keep", keep_user_agent: true)
+ assert json_response(conn, 200) == %{"user-agent" => Pleroma.Application.user_agent()}
+ end
+ end
+
+ test "closed connection", %{conn: conn} do
+ ClientMock
+ |> expect(:request, fn :get, "/closed", _, _, _ -> {:ok, 200, [], %{}} end)
+ |> expect(:stream_body, fn _ -> {:error, :closed} end)
+ |> expect(:close, fn _ -> :ok end)
+
+ conn = ReverseProxy.call(conn, "/closed")
+ assert conn.halted
+ end
+
+ describe "max_body " do
+ test "length returns error if content-length more than option", %{conn: conn} do
+ user_agent_mock("hackney/1.15.1", 0)
+
+ assert capture_log(fn ->
+ ReverseProxy.call(conn, "/user-agent", max_body_length: 4)
+ end) =~
+ "[error] Elixir.Pleroma.ReverseProxy: request to \"/user-agent\" failed: :body_too_large"
+ end
+
+ defp stream_mock(invokes, with_close? \\ false) do
+ ClientMock
+ |> expect(:request, fn :get, "/stream-bytes/" <> length, _, _, _ ->
+ Registry.register(Pleroma.ReverseProxy.ClientMock, "/stream-bytes/" <> length, 0)
+
+ {:ok, 200, [{"content-type", "application/octet-stream"}],
+ %{url: "/stream-bytes/" <> length}}
+ end)
+ |> expect(:stream_body, invokes, fn %{url: "/stream-bytes/" <> length} ->
+ max = String.to_integer(length)
+
+ case Registry.lookup(Pleroma.ReverseProxy.ClientMock, "/stream-bytes/" <> length) do
+ [{_, current}] when current < max ->
+ Registry.update_value(
+ Pleroma.ReverseProxy.ClientMock,
+ "/stream-bytes/" <> length,
+ &(&1 + 10)
+ )
+
+ {:ok, "0123456789"}
+
+ [{_, ^max}] ->
+ Registry.unregister(Pleroma.ReverseProxy.ClientMock, "/stream-bytes/" <> length)
+ :done
+ end
+ end)
+
+ if with_close? do
+ expect(ClientMock, :close, fn _ -> :ok end)
+ end
+ end
+
+ test "max_body_size 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)
+ end) =~
+ "[warn] Elixir.Pleroma.ReverseProxy request to /stream-bytes/50 failed while reading/chunking: :body_too_large"
+ end
+ end
+
+ describe "HEAD requests" do
+ test "common", %{conn: conn} do
+ ClientMock
+ |> expect(:request, fn :head, "/head", _, _, _ ->
+ {:ok, 200, [{"content-type", "text/html; charset=utf-8"}]}
+ end)
+
+ conn = ReverseProxy.call(Map.put(conn, :method, "HEAD"), "/head")
+ assert html_response(conn, 200) == ""
+ end
+ end
+
+ defp error_mock(status) when is_integer(status) do
+ ClientMock
+ |> expect(:request, fn :get, "/status/" <> _, _, _, _ ->
+ {:error, status}
+ end)
+ end
+
+ describe "returns error on" do
+ test "500", %{conn: conn} do
+ error_mock(500)
+
+ capture_log(fn -> ReverseProxy.call(conn, "/status/500") end) =~
+ "[error] Elixir.Pleroma.ReverseProxy: request to /status/500 failed with HTTP status 500"
+ end
+
+ test "400", %{conn: conn} do
+ error_mock(400)
+
+ capture_log(fn -> ReverseProxy.call(conn, "/status/400") end) =~
+ "[error] Elixir.Pleroma.ReverseProxy: request to /status/400 failed with HTTP status 400"
+ end
+
+ test "204", %{conn: conn} do
+ ClientMock
+ |> expect(:request, fn :get, "/status/204", _, _, _ -> {:ok, 204, [], %{}} end)
+
+ capture_log(fn ->
+ conn = ReverseProxy.call(conn, "/status/204")
+ assert conn.resp_body == "Request failed: No Content"
+ assert conn.halted
+ end) =~
+ "[error] Elixir.Pleroma.ReverseProxy: request to \"/status/204\" failed with HTTP status 204"
+ end
+ end
+
+ test "streaming", %{conn: conn} do
+ stream_mock(21)
+ conn = ReverseProxy.call(conn, "/stream-bytes/200")
+ assert conn.state == :chunked
+ assert byte_size(conn.resp_body) == 200
+ assert Plug.Conn.get_resp_header(conn, "content-type") == ["application/octet-stream"]
+ end
+
+ defp headers_mock(_) do
+ ClientMock
+ |> expect(:request, fn :get, "/headers", headers, _, _ ->
+ Registry.register(Pleroma.ReverseProxy.ClientMock, "/headers", 0)
+ {:ok, 200, [{"content-type", "application/json"}], %{url: "/headers", headers: headers}}
+ end)
+ |> expect(:stream_body, 2, fn %{url: url, headers: headers} ->
+ case Registry.lookup(Pleroma.ReverseProxy.ClientMock, url) do
+ [{_, 0}] ->
+ Registry.update_value(Pleroma.ReverseProxy.ClientMock, url, &(&1 + 1))
+ headers = for {k, v} <- headers, into: %{}, do: {String.capitalize(k), v}
+ {:ok, Jason.encode!(%{headers: headers})}
+
+ [{_, 1}] ->
+ Registry.unregister(Pleroma.ReverseProxy.ClientMock, url)
+ :done
+ end
+ end)
+
+ :ok
+ end
+
+ describe "keep request headers" do
+ setup [:headers_mock]
+
+ test "header passes", %{conn: conn} do
+ conn =
+ Plug.Conn.put_req_header(
+ conn,
+ "accept",
+ "text/html"
+ )
+ |> ReverseProxy.call("/headers")
+
+ %{"headers" => headers} = json_response(conn, 200)
+ assert headers["Accept"] == "text/html"
+ end
+
+ test "header is filtered", %{conn: conn} do
+ conn =
+ Plug.Conn.put_req_header(
+ conn,
+ "accept-language",
+ "en-US"
+ )
+ |> ReverseProxy.call("/headers")
+
+ %{"headers" => headers} = json_response(conn, 200)
+ refute headers["Accept-Language"]
+ end
+ end
+
+ test "returns 400 on non GET, HEAD requests", %{conn: conn} do
+ conn = ReverseProxy.call(Map.put(conn, :method, "POST"), "/ip")
+ assert conn.status == 400
+ end
+
+ describe "cache resp headers" do
+ test "returns headers", %{conn: conn} do
+ ClientMock
+ |> expect(:request, fn :get, "/cache/" <> ttl, _, _, _ ->
+ {:ok, 200, [{"cache-control", "public, max-age=" <> ttl}], %{}}
+ end)
+ |> expect(:stream_body, fn _ -> :done end)
+
+ conn = ReverseProxy.call(conn, "/cache/10")
+ assert {"cache-control", "public, max-age=10"} in conn.resp_headers
+ end
+
+ test "add cache-control", %{conn: conn} do
+ ClientMock
+ |> expect(:request, fn :get, "/cache", _, _, _ ->
+ {:ok, 200, [{"ETag", "some ETag"}], %{}}
+ end)
+ |> expect(:stream_body, fn _ -> :done end)
+
+ conn = ReverseProxy.call(conn, "/cache")
+ assert {"cache-control", "public"} in conn.resp_headers
+ end
+ end
+
+ defp disposition_headers_mock(headers) do
+ ClientMock
+ |> expect(:request, fn :get, "/disposition", _, _, _ ->
+ Registry.register(Pleroma.ReverseProxy.ClientMock, "/disposition", 0)
+
+ {:ok, 200, headers, %{url: "/disposition"}}
+ end)
+ |> expect(:stream_body, 2, fn %{url: "/disposition"} ->
+ case Registry.lookup(Pleroma.ReverseProxy.ClientMock, "/disposition") do
+ [{_, 0}] ->
+ Registry.update_value(Pleroma.ReverseProxy.ClientMock, "/disposition", &(&1 + 1))
+ {:ok, ""}
+
+ [{_, 1}] ->
+ Registry.unregister(Pleroma.ReverseProxy.ClientMock, "/disposition")
+ :done
+ end
+ end)
+ end
+
+ describe "response content disposition header" do
+ test "not atachment", %{conn: conn} do
+ disposition_headers_mock([
+ {"content-type", "image/gif"},
+ {"content-length", 0}
+ ])
+
+ conn = ReverseProxy.call(conn, "/disposition")
+
+ assert {"content-type", "image/gif"} in conn.resp_headers
+ end
+
+ test "with content-disposition header", %{conn: conn} do
+ disposition_headers_mock([
+ {"content-disposition", "attachment; filename=\"filename.jpg\""},
+ {"content-length", 0}
+ ])
+
+ conn = ReverseProxy.call(conn, "/disposition")
+
+ assert {"content-disposition", "attachment; filename=\"filename.jpg\""} in conn.resp_headers
+ end
+ end
+end
diff --git a/test/signature_test.exs b/test/signature_test.exs
new file mode 100644
index 000000000..4920196c7
--- /dev/null
+++ b/test/signature_test.exs
@@ -0,0 +1,99 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.SignatureTest do
+ use Pleroma.DataCase
+
+ import Pleroma.Factory
+ import Tesla.Mock
+
+ alias Pleroma.Signature
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
+ @private_key "-----BEGIN RSA PRIVATE KEY-----\nMIIEpQIBAAKCAQEA48qb4v6kqigZutO9Ot0wkp27GIF2LiVaADgxQORZozZR63jH\nTaoOrS3Xhngbgc8SSOhfXET3omzeCLqaLNfXnZ8OXmuhJfJSU6mPUvmZ9QdT332j\nfN/g3iWGhYMf/M9ftCKh96nvFVO/tMruzS9xx7tkrfJjehdxh/3LlJMMImPtwcD7\nkFXwyt1qZTAU6Si4oQAJxRDQXHp1ttLl3Ob829VM7IKkrVmY8TD+JSlV0jtVJPj6\n1J19ytKTx/7UaucYvb9HIiBpkuiy5n/irDqKLVf5QEdZoNCdojOZlKJmTLqHhzKP\n3E9TxsUjhrf4/EqegNc/j982RvOxeu4i40zMQwIDAQABAoIBAQDH5DXjfh21i7b4\ncXJuw0cqget617CDUhemdakTDs9yH+rHPZd3mbGDWuT0hVVuFe4vuGpmJ8c+61X0\nRvugOlBlavxK8xvYlsqTzAmPgKUPljyNtEzQ+gz0I+3mH2jkin2rL3D+SksZZgKm\nfiYMPIQWB2WUF04gB46DDb2mRVuymGHyBOQjIx3WC0KW2mzfoFUFRlZEF+Nt8Ilw\nT+g/u0aZ1IWoszbsVFOEdghgZET0HEarum0B2Je/ozcPYtwmU10iBANGMKdLqaP/\nj954BPunrUf6gmlnLZKIKklJj0advx0NA+cL79+zeVB3zexRYSA5o9q0WPhiuTwR\n/aedWHnBAoGBAP0sDWBAM1Y4TRAf8ZI9PcztwLyHPzfEIqzbObJJnx1icUMt7BWi\n+/RMOnhrlPGE1kMhOqSxvXYN3u+eSmWTqai2sSH5Hdw2EqnrISSTnwNUPINX7fHH\njEkgmXQ6ixE48SuBZnb4w1EjdB/BA6/sjL+FNhggOc87tizLTkMXmMtTAoGBAOZV\n+wPuAMBDBXmbmxCuDIjoVmgSlgeRunB1SA8RCPAFAiUo3+/zEgzW2Oz8kgI+xVwM\n33XkLKrWG1Orhpp6Hm57MjIc5MG+zF4/YRDpE/KNG9qU1tiz0UD5hOpIU9pP4bR/\ngxgPxZzvbk4h5BfHWLpjlk8UUpgk6uxqfti48c1RAoGBALBOKDZ6HwYRCSGMjUcg\n3NPEUi84JD8qmFc2B7Tv7h2he2ykIz9iFAGpwCIyETQsJKX1Ewi0OlNnD3RhEEAy\nl7jFGQ+mkzPSeCbadmcpYlgIJmf1KN/x7fDTAepeBpCEzfZVE80QKbxsaybd3Dp8\nCfwpwWUFtBxr4c7J+gNhAGe/AoGAPn8ZyqkrPv9wXtyfqFjxQbx4pWhVmNwrkBPi\nZ2Qh3q4dNOPwTvTO8vjghvzIyR8rAZzkjOJKVFgftgYWUZfM5gE7T2mTkBYq8W+U\n8LetF+S9qAM2gDnaDx0kuUTCq7t87DKk6URuQ/SbI0wCzYjjRD99KxvChVGPBHKo\n1DjqMuECgYEAgJGNm7/lJCS2wk81whfy/ttKGsEIkyhPFYQmdGzSYC5aDc2gp1R3\nxtOkYEvdjfaLfDGEa4UX8CHHF+w3t9u8hBtcdhMH6GYb9iv6z0VBTt4A/11HUR49\n3Z7TQ18Iyh3jAUCzFV9IJlLIExq5Y7P4B3ojWFBN607sDCt8BMPbDYs=\n-----END RSA PRIVATE KEY-----"
+
+ @public_key %{
+ "id" => "https://mastodon.social/users/lambadalambda#main-key",
+ "owner" => "https://mastodon.social/users/lambadalambda",
+ "publicKeyPem" =>
+ "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw0P/Tq4gb4G/QVuMGbJo\nC/AfMNcv+m7NfrlOwkVzcU47jgESuYI4UtJayissCdBycHUnfVUd9qol+eznSODz\nCJhfJloqEIC+aSnuEPGA0POtWad6DU0E6/Ho5zQn5WAWUwbRQqowbrsm/GHo2+3v\neR5jGenwA6sYhINg/c3QQbksyV0uJ20Umyx88w8+TJuv53twOfmyDWuYNoQ3y5cc\nHKOZcLHxYOhvwg3PFaGfFHMFiNmF40dTXt9K96r7sbzc44iLD+VphbMPJEjkMuf8\nPGEFOBzy8pm3wJZw2v32RNW2VESwMYyqDzwHXGSq1a73cS7hEnc79gXlELsK04L9\nQQIDAQAB\n-----END PUBLIC KEY-----\n"
+ }
+
+ @rsa_public_key {
+ :RSAPublicKey,
+ 24_650_000_183_914_698_290_885_268_529_673_621_967_457_234_469_123_179_408_466_269_598_577_505_928_170_923_974_132_111_403_341_217_239_999_189_084_572_368_839_502_170_501_850_920_051_662_384_964_248_315_257_926_552_945_648_828_895_432_624_227_029_881_278_113_244_073_644_360_744_504_606_177_648_469_825_063_267_913_017_309_199_785_535_546_734_904_379_798_564_556_494_962_268_682_532_371_146_333_972_821_570_577_277_375_020_977_087_539_994_500_097_107_935_618_711_808_260_846_821_077_839_605_098_669_707_417_692_791_905_543_116_911_754_774_323_678_879_466_618_738_207_538_013_885_607_095_203_516_030_057_611_111_308_904_599_045_146_148_350_745_339_208_006_497_478_057_622_336_882_506_112_530_056_970_653_403_292_123_624_453_213_574_011_183_684_739_084_105_206_483_178_943_532_208_537_215_396_831_110_268_758_639_826_369_857,
+ # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
+ 65_537
+ }
+
+ describe "fetch_public_key/1" do
+ test "it returns key" do
+ expected_result = {:ok, @rsa_public_key}
+
+ user = insert(:user, %{info: %{source_data: %{"publicKey" => @public_key}}})
+
+ assert Signature.fetch_public_key(%Plug.Conn{params: %{"actor" => user.ap_id}}) ==
+ expected_result
+ end
+
+ test "it returns error when not found user" do
+ assert Signature.fetch_public_key(%Plug.Conn{params: %{"actor" => "test-ap_id"}}) ==
+ {:error, :error}
+ end
+
+ test "it returns error if public key is empty" do
+ user = insert(:user, %{info: %{source_data: %{"publicKey" => %{}}}})
+
+ assert Signature.fetch_public_key(%Plug.Conn{params: %{"actor" => user.ap_id}}) ==
+ {:error, :error}
+ end
+ end
+
+ describe "refetch_public_key/1" do
+ test "it returns key" do
+ ap_id = "https://mastodon.social/users/lambadalambda"
+
+ assert Signature.refetch_public_key(%Plug.Conn{params: %{"actor" => ap_id}}) ==
+ {:ok, @rsa_public_key}
+ end
+
+ test "it returns error when not found user" do
+ assert Signature.refetch_public_key(%Plug.Conn{params: %{"actor" => "test-ap_id"}}) ==
+ {:error, {:error, :ok}}
+ end
+ end
+
+ describe "sign/2" do
+ test "it returns signature headers" do
+ user =
+ insert(:user, %{
+ ap_id: "https://mastodon.social/users/lambadalambda",
+ info: %{keys: @private_key}
+ })
+
+ assert Signature.sign(
+ user,
+ %{
+ host: "test.test",
+ "content-length": 100
+ }
+ ) ==
+ "keyId=\"https://mastodon.social/users/lambadalambda#main-key\",algorithm=\"rsa-sha256\",headers=\"content-length host\",signature=\"sibUOoqsFfTDerquAkyprxzDjmJm6erYc42W5w1IyyxusWngSinq5ILTjaBxFvfarvc7ci1xAi+5gkBwtshRMWm7S+Uqix24Yg5EYafXRun9P25XVnYBEIH4XQ+wlnnzNIXQkU3PU9e6D8aajDZVp3hPJNeYt1gIPOA81bROI8/glzb1SAwQVGRbqUHHHKcwR8keiR/W2h7BwG3pVRy4JgnIZRSW7fQogKedDg02gzRXwUDFDk0pr2p3q6bUWHUXNV8cZIzlMK+v9NlyFbVYBTHctAR26GIAN6Hz0eV0mAQAePHDY1mXppbA8Gpp6hqaMuYfwifcXmcc+QFm4e+n3A==\""
+ end
+
+ test "it returns error" do
+ user =
+ insert(:user, %{ap_id: "https://mastodon.social/users/lambadalambda", info: %{keys: ""}})
+
+ assert Signature.sign(
+ user,
+ %{host: "test.test", "content-length": 100}
+ ) == {:error, []}
+ end
+ end
+end
diff --git a/test/support/factory.ex b/test/support/factory.ex
index be6247ca4..531eb81e4 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -4,6 +4,7 @@
defmodule Pleroma.Factory do
use ExMachina.Ecto, repo: Pleroma.Repo
+ alias Pleroma.Object
alias Pleroma.User
def participation_factory do
@@ -37,6 +38,7 @@ defmodule Pleroma.Factory do
user
| ap_id: User.ap_id(user),
follower_address: User.ap_followers(user),
+ following_address: User.ap_following(user),
following: [User.ap_id(user)]
}
end
@@ -116,13 +118,14 @@ defmodule Pleroma.Factory do
def note_activity_factory(attrs \\ %{}) do
user = attrs[:user] || insert(:user)
note = attrs[:note] || insert(:note, user: user)
+ attrs = Map.drop(attrs, [:user, :note])
data = %{
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
"type" => "Create",
"actor" => note.data["actor"],
"to" => note.data["to"],
- "object" => note.data,
+ "object" => note.data["id"],
"published" => DateTime.utc_now() |> DateTime.to_iso8601(),
"context" => note.data["context"]
}
@@ -132,6 +135,7 @@ defmodule Pleroma.Factory do
actor: data["actor"],
recipients: data["to"]
}
+ |> Map.merge(attrs)
end
def article_activity_factory do
@@ -176,13 +180,14 @@ defmodule Pleroma.Factory do
def like_activity_factory do
note_activity = insert(:note_activity)
+ object = Object.normalize(note_activity)
user = insert(:user)
data = %{
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
"actor" => user.ap_id,
"type" => "Like",
- "object" => note_activity.data["object"]["id"],
+ "object" => object.data["id"],
"published_at" => DateTime.utc_now() |> DateTime.to_iso8601()
}
@@ -310,4 +315,18 @@ defmodule Pleroma.Factory do
}
}
end
+
+ def config_factory do
+ %Pleroma.Web.AdminAPI.Config{
+ key: sequence(:key, &"some_key_#{&1}"),
+ group: "pleroma",
+ value:
+ sequence(
+ :value,
+ fn key ->
+ :erlang.term_to_binary(%{another_key: "#{key}somevalue", another: "#{key}somevalue"})
+ end
+ )
+ }
+ end
end
diff --git a/test/support/helpers.ex b/test/support/helpers.ex
index 6e389ce52..1a92be065 100644
--- a/test/support/helpers.ex
+++ b/test/support/helpers.ex
@@ -9,6 +9,12 @@ defmodule Pleroma.Tests.Helpers do
defmacro __using__(_opts) do
quote do
+ def collect_ids(collection) do
+ collection
+ |> Enum.map(& &1.id)
+ |> Enum.sort()
+ end
+
def refresh_record(%{id: id, __struct__: model} = _),
do: refresh_record(model, %{id: id})
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index 5b355bfe6..7811f7807 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -31,8 +31,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body:
- File.read!("test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json")
+ body: File.read!("test/fixtures/tesla_mock/https___osada.macgirvin.com_channel_mike.json")
}}
end
@@ -40,7 +39,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/status.emelie.json")
+ body: File.read!("test/fixtures/tesla_mock/status.emelie.json")
}}
end
@@ -48,7 +47,15 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/emelie.json")
+ body: File.read!("test/fixtures/tesla_mock/emelie.json")
+ }}
+ end
+
+ def get("https://mastodon.sdf.org/users/rinpatch", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/rinpatch.json")
}}
end
@@ -61,7 +68,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/webfinger_emelie.json")
+ body: File.read!("test/fixtures/tesla_mock/webfinger_emelie.json")
}}
end
@@ -69,7 +76,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/emelie.atom")
+ body: File.read!("test/fixtures/tesla_mock/emelie.atom")
}}
end
@@ -82,7 +89,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json")
+ body: File.read!("test/fixtures/tesla_mock/mike@osada.macgirvin.com.json")
}}
end
@@ -95,7 +102,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
+ body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_29191.xml")
}}
end
@@ -103,7 +110,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.atom")
+ body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.atom")
}}
end
@@ -116,7 +123,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
+ body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.xml")
}}
end
@@ -129,7 +136,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/atarifrosch_feed.xml")
+ body: File.read!("test/fixtures/tesla_mock/atarifrosch_feed.xml")
}}
end
@@ -142,7 +149,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/atarifrosch_webfinger.xml")
+ body: File.read!("test/fixtures/tesla_mock/atarifrosch_webfinger.xml")
}}
end
@@ -150,7 +157,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom")
+ body: File.read!("test/fixtures/tesla_mock/https___mamot.fr_users_Skruyb.atom")
}}
end
@@ -163,7 +170,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
+ body: File.read!("test/fixtures/tesla_mock/skruyb@mamot.fr.atom")
}}
end
@@ -176,7 +183,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/nonexistant@social.heldscal.la.xml")
+ body: File.read!("test/fixtures/tesla_mock/nonexistant@social.heldscal.la.xml")
}}
end
@@ -189,7 +196,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml")
+ body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
}}
end
@@ -202,7 +209,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/lucifermysticus.json")
+ body: File.read!("test/fixtures/tesla_mock/lucifermysticus.json")
}}
end
@@ -210,7 +217,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___prismo.news__mxb.json")
+ body: File.read!("test/fixtures/tesla_mock/https___prismo.news__mxb.json")
}}
end
@@ -223,7 +230,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/kaniini@hubzilla.example.org.json")
+ body: File.read!("test/fixtures/tesla_mock/kaniini@hubzilla.example.org.json")
}}
end
@@ -231,7 +238,15 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/rye.json")
+ body: File.read!("test/fixtures/tesla_mock/rye.json")
+ }}
+ end
+
+ def get("https://n1u.moe/users/rye", _, _, Accept: "application/activity+json") do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/rye.json")
}}
end
@@ -241,7 +256,7 @@ defmodule HttpRequestMock do
status: 200,
body:
File.read!(
- "test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json"
+ "test/fixtures/tesla_mock/http___mastodon.example.org_users_admin_status_1234.json"
)
}}
end
@@ -250,7 +265,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/puckipedia.com.json")
+ body: File.read!("test/fixtures/tesla_mock/puckipedia.com.json")
}}
end
@@ -258,7 +273,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/7even.json")
+ body: File.read!("test/fixtures/tesla_mock/7even.json")
}}
end
@@ -266,7 +281,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/peertube.moe-vid.json")
+ body: File.read!("test/fixtures/tesla_mock/peertube.moe-vid.json")
}}
end
@@ -274,7 +289,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/baptiste.gelex.xyz-user.json")
+ body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json")
}}
end
@@ -282,7 +297,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/baptiste.gelex.xyz-article.json")
+ body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json")
}}
end
@@ -290,10 +305,14 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/admin@mastdon.example.org.json")
+ body: File.read!("test/fixtures/tesla_mock/admin@mastdon.example.org.json")
}}
end
+ def get("http://mastodon.example.org/users/gargron", _, _, Accept: "application/activity+json") do
+ {:error, :nxdomain}
+ end
+
def get(
"http://mastodon.example.org/@admin/99541947525187367",
_,
@@ -311,7 +330,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/7369654.html")
+ body: File.read!("test/fixtures/tesla_mock/7369654.html")
}}
end
@@ -319,7 +338,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/mayumayu.json")
+ body: File.read!("test/fixtures/tesla_mock/mayumayu.json")
}}
end
@@ -332,7 +351,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/mayumayupost.json")
+ body: File.read!("test/fixtures/tesla_mock/mayumayupost.json")
}}
end
@@ -342,7 +361,7 @@ defmodule HttpRequestMock do
status: 200,
body:
File.read!(
- "test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml"
+ "test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml"
)
}}
end
@@ -355,7 +374,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml")
+ body: File.read!("test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml")
}}
end
@@ -365,7 +384,7 @@ defmodule HttpRequestMock do
status: 200,
body:
File.read!(
- "test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml"
+ "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml"
)
}}
end
@@ -379,7 +398,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml")
+ body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_user_1.xml")
}}
end
@@ -387,8 +406,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body:
- File.read!("test/fixtures/httpoison_mock/https___shitposter.club_notice_2827873.html")
+ body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_notice_2827873.html")
}}
end
@@ -398,7 +416,7 @@ defmodule HttpRequestMock do
status: 200,
body:
File.read!(
- "test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml"
+ "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml"
)
}}
end
@@ -411,7 +429,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/spc_5381.atom")
+ body: File.read!("test/fixtures/tesla_mock/spc_5381.atom")
}}
end
@@ -424,7 +442,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/spc_5381_xrd.xml")
+ body: File.read!("test/fixtures/tesla_mock/spc_5381_xrd.xml")
}}
end
@@ -432,7 +450,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/shitposter.club_host_meta")
+ body: File.read!("test/fixtures/tesla_mock/shitposter.club_host_meta")
}}
end
@@ -440,7 +458,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/7369654.atom")
+ body: File.read!("test/fixtures/tesla_mock/7369654.atom")
}}
end
@@ -448,7 +466,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/7369654.html")
+ body: File.read!("test/fixtures/tesla_mock/7369654.html")
}}
end
@@ -456,7 +474,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/sakamoto_eal_feed.atom")
+ body: File.read!("test/fixtures/tesla_mock/sakamoto_eal_feed.atom")
}}
end
@@ -464,7 +482,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/social.sakamoto.gq_host_meta")
+ body: File.read!("test/fixtures/tesla_mock/social.sakamoto.gq_host_meta")
}}
end
@@ -477,7 +495,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml")
+ body: File.read!("test/fixtures/tesla_mock/eal_sakamoto.xml")
}}
end
@@ -487,14 +505,14 @@ defmodule HttpRequestMock do
_,
Accept: "application/atom+xml"
) do
- {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/httpoison_mock/sakamoto.atom")}}
+ {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sakamoto.atom")}}
end
def get("http://mastodon.social/.well-known/host-meta", _, _, _) do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/mastodon.social_host_meta")
+ body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
}}
end
@@ -508,9 +526,7 @@ defmodule HttpRequestMock do
%Tesla.Env{
status: 200,
body:
- File.read!(
- "test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml"
- )
+ File.read!("test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml")
}}
end
@@ -518,7 +534,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/gs.example.org_host_meta")
+ body: File.read!("test/fixtures/tesla_mock/gs.example.org_host_meta")
}}
end
@@ -532,19 +548,26 @@ defmodule HttpRequestMock do
%Tesla.Env{
status: 200,
body:
- File.read!(
- "test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml"
- )
+ File.read!("test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml")
}}
end
+ def get(
+ "http://gs.example.org:4040/index.php/user/1",
+ _,
+ _,
+ Accept: "application/activity+json"
+ ) do
+ {:ok, %Tesla.Env{status: 406, body: ""}}
+ end
+
def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _, _, _) do
{:ok,
%Tesla.Env{
status: 200,
body:
File.read!(
- "test/fixtures/httpoison_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml"
+ "test/fixtures/tesla_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml"
)
}}
end
@@ -555,14 +578,14 @@ defmodule HttpRequestMock do
status: 200,
body:
File.read!(
- "test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml"
+ "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml"
)
}}
end
def get("http://squeet.me/.well-known/host-meta", _, _, _) do
{:ok,
- %Tesla.Env{status: 200, body: File.read!("test/fixtures/httpoison_mock/squeet.me_host_meta")}}
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
end
def get(
@@ -574,7 +597,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml")
+ body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
}}
end
@@ -587,7 +610,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml")
+ body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml")
}}
end
@@ -595,7 +618,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/framatube.org_host_meta")
+ body: File.read!("test/fixtures/tesla_mock/framatube.org_host_meta")
}}
end
@@ -609,7 +632,7 @@ defmodule HttpRequestMock do
%Tesla.Env{
status: 200,
headers: [{"content-type", "application/json"}],
- body: File.read!("test/fixtures/httpoison_mock/framasoft@framatube.org.json")
+ body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
}}
end
@@ -617,7 +640,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/gnusocial.de_host_meta")
+ body: File.read!("test/fixtures/tesla_mock/gnusocial.de_host_meta")
}}
end
@@ -630,7 +653,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/winterdienst_webfinger.json")
+ body: File.read!("test/fixtures/tesla_mock/winterdienst_webfinger.json")
}}
end
@@ -638,7 +661,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/status.alpicola.com_host_meta")
+ body: File.read!("test/fixtures/tesla_mock/status.alpicola.com_host_meta")
}}
end
@@ -646,7 +669,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/macgirvin.com_host_meta")
+ body: File.read!("test/fixtures/tesla_mock/macgirvin.com_host_meta")
}}
end
@@ -654,7 +677,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/gerzilla.de_host_meta")
+ body: File.read!("test/fixtures/tesla_mock/gerzilla.de_host_meta")
}}
end
@@ -668,7 +691,7 @@ defmodule HttpRequestMock do
%Tesla.Env{
status: 200,
headers: [{"content-type", "application/json"}],
- body: File.read!("test/fixtures/httpoison_mock/kaniini@gerzilla.de.json")
+ body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
}}
end
@@ -678,7 +701,7 @@ defmodule HttpRequestMock do
status: 200,
body:
File.read!(
- "test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
+ "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
)
}}
end
@@ -692,7 +715,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")
+ body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml")
}}
end
@@ -700,7 +723,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/social.heldscal.la_host_meta")
+ body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
}}
end
@@ -708,7 +731,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/httpoison_mock/social.heldscal.la_host_meta")
+ body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
}}
end
@@ -728,6 +751,78 @@ defmodule HttpRequestMock do
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
end
+ def get("https://example.com/ogp", _, _, _) do
+ {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
+ end
+
+ def get("https://pleroma.local/notice/9kCP7V", _, _, _) do
+ {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
+ end
+
+ def get("http://localhost:4001/users/masto_closed/followers", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/users_mock/masto_closed_followers.json")
+ }}
+ end
+
+ def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/users_mock/masto_closed_following.json")
+ }}
+ end
+
+ def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/users_mock/pleroma_followers.json")
+ }}
+ end
+
+ def get("http://localhost:4001/users/fuser2/following", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/users_mock/pleroma_following.json")
+ }}
+ end
+
+ def get("http://domain-with-errors:4001/users/fuser1/followers", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 504,
+ body: ""
+ }}
+ end
+
+ def get("http://domain-with-errors:4001/users/fuser1/following", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 504,
+ body: ""
+ }}
+ end
+
+ def get("http://example.com/ogp-missing-data", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
+ }}
+ end
+
+ def get("https://example.com/ogp-missing-data", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
+ }}
+ end
+
def get("http://example.com/malformed", _, _, _) do
{:ok,
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
@@ -745,6 +840,81 @@ defmodule HttpRequestMock do
}}
end
+ def get(
+ "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=lain@zetsubou.xn--q9jyb4c",
+ _,
+ _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/lain.xml")
+ }}
+ end
+
+ def get(
+ "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=https://zetsubou.xn--q9jyb4c/users/lain",
+ _,
+ _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/lain.xml")
+ }}
+ end
+
+ def get(
+ "https://zetsubou.xn--q9jyb4c/.well-known/host-meta",
+ _,
+ _,
+ _
+ ) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
+ }}
+ end
+
+ def get("https://info.pleroma.site/activity.json", _, _, Accept: "application/activity+json") do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity.json")
+ }}
+ end
+
+ def get("https://info.pleroma.site/activity.json", _, _, _) do
+ {:ok, %Tesla.Env{status: 404, body: ""}}
+ end
+
+ def get("https://info.pleroma.site/activity2.json", _, _, Accept: "application/activity+json") do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity2.json")
+ }}
+ end
+
+ def get("https://info.pleroma.site/activity2.json", _, _, _) do
+ {:ok, %Tesla.Env{status: 404, body: ""}}
+ end
+
+ def get("https://info.pleroma.site/activity3.json", _, _, Accept: "application/activity+json") do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity3.json")
+ }}
+ end
+
+ def get("https://info.pleroma.site/activity3.json", _, _, _) do
+ {:ok, %Tesla.Env{status: 404, body: ""}}
+ end
+
def get(url, query, body, headers) do
{:error,
"Not implemented the mock response for get #{inspect(url)}, #{query}, #{inspect(body)}, #{
@@ -765,6 +935,30 @@ defmodule HttpRequestMock do
}}
end
+ def post("http://mastodon.example.org/inbox", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: ""
+ }}
+ end
+
+ def post("https://hubzilla.example.org/inbox", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: ""
+ }}
+ end
+
+ def post("http://gs.example.org/index.php/main/salmon/user/1", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: ""
+ }}
+ end
+
def post("http://200.site" <> _, _, _, _) do
{:ok,
%Tesla.Env{
diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs
new file mode 100644
index 000000000..a9b79eb5b
--- /dev/null
+++ b/test/tasks/config_test.exs
@@ -0,0 +1,67 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Mix.Tasks.Pleroma.ConfigTest do
+ use Pleroma.DataCase
+ alias Pleroma.Repo
+ alias Pleroma.Web.AdminAPI.Config
+
+ setup_all 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
+
+ test "settings are migrated to db" do
+ assert Repo.all(Config) == []
+
+ Application.put_env(:pleroma, :first_setting, key: "value", key2: [Pleroma.Repo])
+ Application.put_env(:pleroma, :second_setting, key: "value2", key2: [Pleroma.Activity])
+
+ Mix.Tasks.Pleroma.Config.run(["migrate_to_db"])
+
+ first_db = Config.get_by_params(%{group: "pleroma", key: ":first_setting"})
+ second_db = Config.get_by_params(%{group: "pleroma", key: ":second_setting"})
+ refute Config.get_by_params(%{group: "pleroma", key: "Pleroma.Repo"})
+
+ assert Config.from_binary(first_db.value) == [key: "value", key2: [Pleroma.Repo]]
+ assert Config.from_binary(second_db.value) == [key: "value2", key2: [Pleroma.Activity]]
+ end
+
+ test "settings are migrated to file and deleted from db", %{temp_file: temp_file} do
+ Config.create(%{
+ group: "pleroma",
+ key: ":setting_first",
+ value: [key: "value", key2: [Pleroma.Activity]]
+ })
+
+ Config.create(%{
+ group: "pleroma",
+ key: ":setting_second",
+ value: [key: "valu2", key2: [Pleroma.Repo]]
+ })
+
+ Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "temp", "true"])
+
+ assert Repo.all(Config) == []
+ assert File.exists?(temp_file)
+ {:ok, file} = File.read(temp_file)
+
+ assert file =~ "config :pleroma, :setting_first,"
+ assert file =~ "config :pleroma, :setting_second,"
+ end
+end
diff --git a/test/tasks/ecto/ecto_test.exs b/test/tasks/ecto/ecto_test.exs
new file mode 100644
index 000000000..a1b9ca174
--- /dev/null
+++ b/test/tasks/ecto/ecto_test.exs
@@ -0,0 +1,15 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Mix.Tasks.Pleroma.EctoTest do
+ use ExUnit.Case, async: true
+
+ test "raise on bad path" do
+ assert_raise RuntimeError, ~r/Could not find migrations directory/, fn ->
+ Mix.Tasks.Pleroma.Ecto.ensure_migrations_path(Pleroma.Repo,
+ migrations_path: "some-path"
+ )
+ end
+ end
+end
diff --git a/test/tasks/ecto/migrate_test.exs b/test/tasks/ecto/migrate_test.exs
new file mode 100644
index 000000000..0538a7b40
--- /dev/null
+++ b/test/tasks/ecto/migrate_test.exs
@@ -0,0 +1,20 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-onl
+
+defmodule Mix.Tasks.Pleroma.Ecto.MigrateTest do
+ use Pleroma.DataCase, async: true
+ import ExUnit.CaptureLog
+ require Logger
+
+ test "ecto.migrate info message" do
+ level = Logger.level()
+ Logger.configure(level: :warn)
+
+ assert capture_log(fn ->
+ Mix.Tasks.Pleroma.Ecto.Migrate.run()
+ end) =~ "[info] Already up"
+
+ Logger.configure(level: level)
+ end
+end
diff --git a/test/tasks/ecto/rollback_test.exs b/test/tasks/ecto/rollback_test.exs
new file mode 100644
index 000000000..c33c4e940
--- /dev/null
+++ b/test/tasks/ecto/rollback_test.exs
@@ -0,0 +1,20 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Mix.Tasks.Pleroma.Ecto.RollbackTest do
+ use Pleroma.DataCase
+ import ExUnit.CaptureLog
+ require Logger
+
+ test "ecto.rollback info message" do
+ level = Logger.level()
+ Logger.configure(level: :warn)
+
+ assert capture_log(fn ->
+ Mix.Tasks.Pleroma.Ecto.Rollback.run()
+ end) =~ "[info] Rollback succesfully"
+
+ Logger.configure(level: level)
+ end
+end
diff --git a/test/tasks/instance.exs b/test/tasks/instance_test.exs
index 6917a2376..70986374e 100644
--- a/test/tasks/instance.exs
+++ b/test/tasks/instance_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.InstanceTest do
use ExUnit.Case, async: true
@@ -36,7 +40,19 @@ defmodule Pleroma.InstanceTest do
"--dbpass",
"dbpass",
"--indexable",
- "y"
+ "y",
+ "--db-configurable",
+ "y",
+ "--rum",
+ "y",
+ "--listen-port",
+ "4000",
+ "--listen-ip",
+ "127.0.0.1",
+ "--uploads-dir",
+ "test/uploads",
+ "--static-dir",
+ "instance/static/"
])
end
@@ -53,10 +69,12 @@ defmodule Pleroma.InstanceTest do
assert generated_config =~ "database: \"dbname\""
assert generated_config =~ "username: \"dbuser\""
assert generated_config =~ "password: \"dbpass\""
+ assert generated_config =~ "dynamic_configuration: true"
+ assert generated_config =~ "http: [ip: {127, 0, 0, 1}, port: 4000]"
assert File.read!(tmp_path() <> "setup.psql") == generated_setup_psql()
end
defp generated_setup_psql do
- ~s(CREATE USER dbuser WITH ENCRYPTED PASSWORD 'dbpass';\nCREATE DATABASE dbname OWNER dbuser;\n\\c dbname;\n--Extensions made by ecto.migrate that need superuser access\nCREATE EXTENSION IF NOT EXISTS citext;\nCREATE EXTENSION IF NOT EXISTS pg_trgm;\nCREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";\n)
+ ~s(CREATE USER dbuser WITH ENCRYPTED PASSWORD 'dbpass';\nCREATE DATABASE dbname OWNER dbuser;\n\\c dbname;\n--Extensions made by ecto.migrate that need superuser access\nCREATE EXTENSION IF NOT EXISTS citext;\nCREATE EXTENSION IF NOT EXISTS pg_trgm;\nCREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";\nCREATE EXTENSION IF NOT EXISTS rum;\n)
end
end
diff --git a/test/tasks/pleroma_test.exs b/test/tasks/pleroma_test.exs
new file mode 100644
index 000000000..a20bd9cf2
--- /dev/null
+++ b/test/tasks/pleroma_test.exs
@@ -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 Mix.PleromaTest do
+ use ExUnit.Case, async: true
+ import Mix.Pleroma
+
+ setup_all do
+ Mix.shell(Mix.Shell.Process)
+
+ on_exit(fn ->
+ Mix.shell(Mix.Shell.IO)
+ end)
+
+ :ok
+ end
+
+ describe "shell_prompt/1" do
+ test "input" do
+ send(self(), {:mix_shell_input, :prompt, "Yes"})
+
+ answer = shell_prompt("Do you want this?")
+ assert_received {:mix_shell, :prompt, [message]}
+ assert message =~ "Do you want this?"
+ assert answer == "Yes"
+ end
+
+ test "with defval" do
+ send(self(), {:mix_shell_input, :prompt, "\n"})
+
+ answer = shell_prompt("Do you want this?", "defval")
+
+ assert_received {:mix_shell, :prompt, [message]}
+ assert message =~ "Do you want this? [defval]"
+ assert answer == "defval"
+ end
+ end
+
+ describe "get_option/3" do
+ test "get from options" do
+ assert get_option([domain: "some-domain.com"], :domain, "Promt") == "some-domain.com"
+ end
+
+ test "get from prompt" do
+ send(self(), {:mix_shell_input, :prompt, "another-domain.com"})
+ assert get_option([], :domain, "Prompt") == "another-domain.com"
+ end
+ end
+end
diff --git a/test/tasks/robots_txt_test.exs b/test/tasks/robots_txt_test.exs
new file mode 100644
index 000000000..78a3f17b4
--- /dev/null
+++ b/test/tasks/robots_txt_test.exs
@@ -0,0 +1,47 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
+ use ExUnit.Case
+ alias Mix.Tasks.Pleroma.RobotsTxt
+
+ 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)
+
+ RobotsTxt.run(["disallow_all"])
+
+ assert File.exists?(file_path)
+ {:ok, file} = File.read(file_path)
+
+ assert file == "User-Agent: *\nDisallow: /\n"
+ end
+
+ 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)
+
+ RobotsTxt.run(["disallow_all"])
+
+ assert File.exists?(file_path)
+ {:ok, file} = File.read(file_path)
+
+ assert file == "User-Agent: *\nDisallow: /\n"
+ end
+end
diff --git a/test/tasks/user_test.exs b/test/tasks/user_test.exs
index 260ce0d95..3d4b08fba 100644
--- a/test/tasks/user_test.exs
+++ b/test/tasks/user_test.exs
@@ -89,8 +89,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ " deleted"
- user = User.get_cached_by_nickname(user.nickname)
- assert user.info.deactivated
+ refute User.get_by_nickname(user.nickname)
end
test "no user to delete" do
@@ -366,4 +365,25 @@ defmodule Mix.Tasks.Pleroma.UserTest do
refute user.info.confirmation_token
end
end
+
+ describe "search" do
+ test "it returns users matching" do
+ user = insert(:user)
+ moon = insert(:user, nickname: "moon", name: "fediverse expert moon")
+ moot = insert(:user, nickname: "moot")
+ kawen = insert(:user, nickname: "kawen", name: "fediverse expert moon")
+
+ {:ok, user} = User.follow(user, kawen)
+
+ assert [moon.id, kawen.id] == User.Search.search("moon") |> Enum.map(& &1.id)
+ res = User.search("moo") |> Enum.map(& &1.id)
+ assert moon.id in res
+ assert moot.id in res
+ assert kawen.id in res
+ assert [moon.id, kawen.id] == User.Search.search("moon fediverse") |> Enum.map(& &1.id)
+
+ assert [kawen.id, moon.id] ==
+ User.Search.search("moon fediverse", for_user: user) |> Enum.map(& &1.id)
+ end
+ end
end
diff --git a/test/test_helper.exs b/test/test_helper.exs
index f604ba63d..3e33f0335 100644
--- a/test/test_helper.exs
+++ b/test/test_helper.exs
@@ -3,6 +3,6 @@
# SPDX-License-Identifier: AGPL-3.0-only
ExUnit.start()
-
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, :manual)
+Mox.defmock(Pleroma.ReverseProxy.ClientMock, for: Pleroma.ReverseProxy.Client)
{:ok, _} = Application.ensure_all_started(:ex_machina)
diff --git a/test/upload/filter/anonymize_filename_test.exs b/test/upload/filter/anonymize_filename_test.exs
new file mode 100644
index 000000000..a31b38ab1
--- /dev/null
+++ b/test/upload/filter/anonymize_filename_test.exs
@@ -0,0 +1,44 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Upload.Filter.AnonymizeFilenameTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Config
+ 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",
+ path: Path.absname("test/fixtures/image_tmp.jpg")
+ }
+
+ %{upload_file: upload_file}
+ end
+
+ 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)
+ assert name == "custom-file.png"
+ end
+
+ test "it replaces filename on pre-defined text expression", %{upload_file: upload_file} do
+ Config.put([Upload.Filter.AnonymizeFilename, :text], "custom-file.{extension}")
+ {:ok, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
+ assert name == "custom-file.jpg"
+ end
+
+ test "it replaces filename on random text", %{upload_file: upload_file} do
+ {:ok, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
+ assert <<_::bytes-size(14)>> <> ".jpg" = name
+ refute name == "an… image.jpg"
+ end
+end
diff --git a/test/user_invite_token_test.exs b/test/user_invite_token_test.exs
index 276788254..111e40361 100644
--- a/test/user_invite_token_test.exs
+++ b/test/user_invite_token_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.UserInviteTokenTest do
use ExUnit.Case, async: true
use Pleroma.DataCase
diff --git a/test/user_search_test.exs b/test/user_search_test.exs
new file mode 100644
index 000000000..4de6c82a5
--- /dev/null
+++ b/test/user_search_test.exs
@@ -0,0 +1,304 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.UserSearchTest do
+ alias Pleroma.Repo
+ alias Pleroma.User
+ use Pleroma.DataCase
+
+ import Pleroma.Factory
+
+ setup_all do
+ Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
+ describe "User.search" do
+ test "accepts limit parameter" do
+ Enum.each(0..4, &insert(:user, %{nickname: "john#{&1}"}))
+ assert length(User.search("john", limit: 3)) == 3
+ assert length(User.search("john")) == 5
+ end
+
+ test "accepts offset parameter" do
+ Enum.each(0..4, &insert(:user, %{nickname: "john#{&1}"}))
+ assert length(User.search("john", limit: 3)) == 3
+ assert length(User.search("john", limit: 3, offset: 3)) == 2
+ end
+
+ test "finds a user by full or partial nickname" do
+ user = insert(:user, %{nickname: "john"})
+
+ Enum.each(["john", "jo", "j"], fn query ->
+ assert user ==
+ User.search(query)
+ |> List.first()
+ |> Map.put(:search_rank, nil)
+ |> Map.put(:search_type, nil)
+ end)
+ end
+
+ test "finds a user by full or partial name" do
+ user = insert(:user, %{name: "John Doe"})
+
+ Enum.each(["John Doe", "JOHN", "doe", "j d", "j", "d"], fn query ->
+ assert user ==
+ User.search(query)
+ |> List.first()
+ |> Map.put(:search_rank, nil)
+ |> Map.put(:search_type, nil)
+ end)
+ end
+
+ test "finds users, preferring nickname matches over name matches" do
+ u1 = insert(:user, %{name: "lain", nickname: "nick1"})
+ u2 = insert(:user, %{nickname: "lain", name: "nick1"})
+
+ assert [u2.id, u1.id] == Enum.map(User.search("lain"), & &1.id)
+ end
+
+ test "finds users, considering density of matched tokens" do
+ u1 = insert(:user, %{name: "Bar Bar plus Word Word"})
+ u2 = insert(:user, %{name: "Word Word Bar Bar Bar"})
+
+ assert [u2.id, u1.id] == Enum.map(User.search("bar word"), & &1.id)
+ end
+
+ test "finds users, ranking by similarity" do
+ u1 = insert(:user, %{name: "lain"})
+ _u2 = insert(:user, %{name: "ean"})
+ u3 = insert(:user, %{name: "ebn", nickname: "lain@mastodon.social"})
+ u4 = insert(:user, %{nickname: "lain@pleroma.soykaf.com"})
+
+ assert [u4.id, u3.id, u1.id] == Enum.map(User.search("lain@ple", for_user: u1), & &1.id)
+ end
+
+ test "finds users, handling misspelled requests" do
+ u1 = insert(:user, %{name: "lain"})
+
+ assert [u1.id] == Enum.map(User.search("laiin"), & &1.id)
+ end
+
+ test "finds users, boosting ranks of friends and followers" do
+ u1 = insert(:user)
+ u2 = insert(:user, %{name: "Doe"})
+ follower = insert(:user, %{name: "Doe"})
+ friend = insert(:user, %{name: "Doe"})
+
+ {:ok, follower} = User.follow(follower, u1)
+ {:ok, u1} = User.follow(u1, friend)
+
+ assert [friend.id, follower.id, u2.id] --
+ Enum.map(User.search("doe", resolve: false, for_user: u1), & &1.id) == []
+ end
+
+ test "finds followers of user by partial name" do
+ u1 = insert(:user)
+ u2 = insert(:user, %{name: "Jimi"})
+ follower_jimi = insert(:user, %{name: "Jimi Hendrix"})
+ follower_lizz = insert(:user, %{name: "Lizz Wright"})
+ friend = insert(:user, %{name: "Jimi"})
+
+ {:ok, follower_jimi} = User.follow(follower_jimi, u1)
+ {:ok, _follower_lizz} = User.follow(follower_lizz, u2)
+ {:ok, u1} = User.follow(u1, friend)
+
+ assert Enum.map(User.search("jimi", following: true, for_user: u1), & &1.id) == [
+ follower_jimi.id
+ ]
+
+ assert User.search("lizz", following: true, for_user: u1) == []
+ end
+
+ test "find local and remote users for authenticated users" do
+ u1 = insert(:user, %{name: "lain"})
+ u2 = insert(:user, %{name: "ebn", nickname: "lain@mastodon.social", local: false})
+ u3 = insert(:user, %{nickname: "lain@pleroma.soykaf.com", local: false})
+
+ results =
+ "lain"
+ |> User.search(for_user: u1)
+ |> Enum.map(& &1.id)
+ |> Enum.sort()
+
+ assert [u1.id, u2.id, u3.id] == results
+ end
+
+ test "find only local users for unauthenticated users" do
+ %{id: id} = insert(:user, %{name: "lain"})
+ insert(:user, %{name: "ebn", nickname: "lain@mastodon.social", local: false})
+ insert(:user, %{nickname: "lain@pleroma.soykaf.com", local: false})
+
+ assert [%{id: ^id}] = User.search("lain")
+ end
+
+ test "find only local users for authenticated users when `limit_to_local_content` is `:all`" do
+ Pleroma.Config.put([:instance, :limit_to_local_content], :all)
+
+ %{id: id} = insert(:user, %{name: "lain"})
+ insert(:user, %{name: "ebn", nickname: "lain@mastodon.social", local: false})
+ insert(:user, %{nickname: "lain@pleroma.soykaf.com", local: false})
+
+ assert [%{id: ^id}] = User.search("lain")
+
+ Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ end
+
+ test "find all users for unauthenticated users when `limit_to_local_content` is `false`" do
+ Pleroma.Config.put([:instance, :limit_to_local_content], false)
+
+ u1 = insert(:user, %{name: "lain"})
+ u2 = insert(:user, %{name: "ebn", nickname: "lain@mastodon.social", local: false})
+ u3 = insert(:user, %{nickname: "lain@pleroma.soykaf.com", local: false})
+
+ results =
+ "lain"
+ |> User.search()
+ |> Enum.map(& &1.id)
+ |> Enum.sort()
+
+ assert [u1.id, u2.id, u3.id] == results
+
+ Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ end
+
+ test "finds a user whose name is nil" do
+ _user = insert(:user, %{name: "notamatch", nickname: "testuser@pleroma.amplifie.red"})
+ user_two = insert(:user, %{name: nil, nickname: "lain@pleroma.soykaf.com"})
+
+ assert user_two ==
+ User.search("lain@pleroma.soykaf.com")
+ |> List.first()
+ |> Map.put(:search_rank, nil)
+ |> Map.put(:search_type, nil)
+ end
+
+ test "does not yield false-positive matches" do
+ insert(:user, %{name: "John Doe"})
+
+ Enum.each(["mary", "a", ""], fn query ->
+ assert [] == User.search(query)
+ end)
+ end
+
+ test "works with URIs" do
+ user = insert(:user)
+
+ results =
+ User.search("http://mastodon.example.org/users/admin", resolve: true, for_user: user)
+
+ result = results |> List.first()
+
+ 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)
+ end
+
+ test "excludes a blocked users from search result" do
+ user = insert(:user, %{nickname: "Bill"})
+
+ [blocked_user | users] = Enum.map(0..3, &insert(:user, %{nickname: "john#{&1}"}))
+
+ blocked_user2 =
+ insert(
+ :user,
+ %{nickname: "john awful", ap_id: "https://awful-and-rude-instance.com/user/bully"}
+ )
+
+ User.block_domain(user, "awful-and-rude-instance.com")
+ User.block(user, blocked_user)
+
+ account_ids = User.search("john", for_user: refresh_record(user)) |> collect_ids
+
+ assert account_ids == collect_ids(users)
+ refute Enum.member?(account_ids, blocked_user.id)
+ refute Enum.member?(account_ids, blocked_user2.id)
+ assert length(account_ids) == 3
+ end
+
+ test "local user has the same search_rank as for users with the same nickname, but another domain" do
+ user = insert(:user)
+ insert(:user, nickname: "lain@mastodon.social")
+ insert(:user, nickname: "lain")
+ insert(:user, nickname: "lain@pleroma.social")
+
+ assert User.search("lain@localhost", resolve: true, for_user: user)
+ |> Enum.each(fn u -> u.search_rank == 0.5 end)
+ end
+
+ test "localhost is the part of the domain" do
+ user = insert(:user)
+ insert(:user, nickname: "another@somedomain")
+ insert(:user, nickname: "lain")
+ insert(:user, nickname: "lain@examplelocalhost")
+
+ result = User.search("lain@examplelocalhost", resolve: true, for_user: user)
+ assert Enum.each(result, fn u -> u.search_rank == 0.5 end)
+ assert length(result) == 2
+ end
+
+ test "local user search with users" do
+ user = insert(:user)
+ local_user = insert(:user, nickname: "lain")
+ insert(:user, nickname: "another@localhost.com")
+ insert(:user, nickname: "localhost@localhost.com")
+
+ [result] = User.search("lain@localhost", resolve: true, for_user: user)
+ assert Map.put(result, :search_rank, nil) |> Map.put(:search_type, nil) == local_user
+ end
+
+ test "works with idna domains" do
+ user = insert(:user, nickname: "lain@" <> to_string(:idna.encode("zetsubou.みんな")))
+
+ results = User.search("lain@zetsubou.みんな", resolve: false, for_user: user)
+
+ result = List.first(results)
+
+ assert user == result |> Map.put(:search_rank, nil) |> Map.put(:search_type, nil)
+ end
+
+ test "works with idna domains converted input" do
+ user = insert(:user, nickname: "lain@" <> to_string(:idna.encode("zetsubou.みんな")))
+
+ results =
+ User.search("lain@zetsubou." <> to_string(:idna.encode("zetsubou.みんな")),
+ resolve: false,
+ for_user: user
+ )
+
+ result = List.first(results)
+
+ assert user == result |> Map.put(:search_rank, nil) |> Map.put(:search_type, nil)
+ end
+
+ test "works with idna domains and bad chars in domain" do
+ user = insert(:user, nickname: "lain@" <> to_string(:idna.encode("zetsubou.みんな")))
+
+ results =
+ User.search("lain@zetsubou!@#$%^&*()+,-/:;<=>?[]'_{}|~`.みんな",
+ resolve: false,
+ for_user: user
+ )
+
+ result = List.first(results)
+
+ assert user == result |> Map.put(:search_rank, nil) |> Map.put(:search_type, nil)
+ end
+
+ test "works with idna domains and query as link" do
+ user = insert(:user, nickname: "lain@" <> to_string(:idna.encode("zetsubou.みんな")))
+
+ results =
+ User.search("https://zetsubou.みんな/users/lain",
+ resolve: false,
+ for_user: user
+ )
+
+ result = List.first(results)
+
+ assert user == result |> Map.put(:search_rank, nil) |> Map.put(:search_type, nil)
+ end
+ end
+end
diff --git a/test/user_test.exs b/test/user_test.exs
index 019f2b56d..264b7a40e 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -14,6 +14,7 @@ defmodule Pleroma.UserTest do
use Pleroma.DataCase
import Pleroma.Factory
+ import Mock
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
@@ -53,6 +54,14 @@ defmodule Pleroma.UserTest do
assert expected_followers_collection == User.ap_followers(user)
end
+ test "ap_following returns the following collection for the user" do
+ user = UserBuilder.build()
+
+ expected_followers_collection = "#{User.ap_id(user)}/following"
+
+ assert expected_followers_collection == User.ap_following(user)
+ end
+
test "returns all pending follow requests" do
unlocked = insert(:user)
locked = insert(:user, %{info: %{locked: true}})
@@ -75,7 +84,7 @@ defmodule Pleroma.UserTest do
Pleroma.Web.TwitterAPI.TwitterAPI.follow(pending_follower, %{"user_id" => locked.id})
Pleroma.Web.TwitterAPI.TwitterAPI.follow(pending_follower, %{"user_id" => locked.id})
Pleroma.Web.TwitterAPI.TwitterAPI.follow(accepted_follower, %{"user_id" => locked.id})
- User.maybe_follow(accepted_follower, locked)
+ User.follow(accepted_follower, locked)
assert {:ok, [activity]} = User.get_follow_requests(locked)
assert activity
@@ -678,10 +687,12 @@ defmodule Pleroma.UserTest do
muted_user = insert(:user)
refute User.mutes?(user, muted_user)
+ refute User.muted_notifications?(user, muted_user)
{:ok, user} = User.mute(user, muted_user)
assert User.mutes?(user, muted_user)
+ assert User.muted_notifications?(user, muted_user)
end
test "it unmutes users" do
@@ -692,6 +703,20 @@ defmodule Pleroma.UserTest do
{:ok, user} = User.unmute(user, muted_user)
refute User.mutes?(user, muted_user)
+ refute User.muted_notifications?(user, muted_user)
+ end
+
+ test "it mutes user without notifications" do
+ user = insert(:user)
+ muted_user = insert(:user)
+
+ refute User.mutes?(user, muted_user)
+ refute User.muted_notifications?(user, muted_user)
+
+ {:ok, user} = User.mute(user, muted_user, false)
+
+ assert User.mutes?(user, muted_user)
+ refute User.muted_notifications?(user, muted_user)
end
end
@@ -915,47 +940,80 @@ defmodule Pleroma.UserTest do
end
end
- test ".delete_user_activities deletes all create activities" do
- user = insert(:user)
+ describe "delete" do
+ setup do
+ {:ok, user} = insert(:user) |> User.set_cache()
+
+ [user: user]
+ end
- {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
+ test ".delete_user_activities deletes all create activities", %{user: user} do
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
- Ecto.Adapters.SQL.Sandbox.unboxed_run(Repo, fn ->
{:ok, _} = User.delete_user_activities(user)
+
# TODO: Remove favorites, repeats, delete activities.
refute Activity.get_by_id(activity.id)
- end)
- end
+ end
- test ".delete deactivates a user, all follow relationships and all create activities" do
- user = insert(:user)
- followed = insert(:user)
- follower = insert(:user)
+ test "it deletes a user, all follow relationships and all activities", %{user: user} do
+ follower = insert(:user)
+ {:ok, follower} = User.follow(follower, user)
- {:ok, user} = User.follow(user, followed)
- {:ok, follower} = User.follow(follower, user)
+ object = insert(:note, user: user)
+ activity = insert(:note_activity, user: user, note: object)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
- {:ok, activity_two} = CommonAPI.post(follower, %{"status" => "3hu"})
+ object_two = insert(:note, user: follower)
+ activity_two = insert(:note_activity, user: follower, note: object_two)
- {:ok, _, _} = CommonAPI.favorite(activity_two.id, user)
- {:ok, _, _} = CommonAPI.favorite(activity.id, follower)
- {:ok, _, _} = CommonAPI.repeat(activity.id, follower)
+ {:ok, like, _} = CommonAPI.favorite(activity_two.id, user)
+ {:ok, like_two, _} = CommonAPI.favorite(activity.id, follower)
+ {:ok, repeat, _} = CommonAPI.repeat(activity_two.id, user)
- {:ok, _} = User.delete(user)
+ {:ok, _} = User.delete(user)
- followed = User.get_cached_by_id(followed.id)
- follower = User.get_cached_by_id(follower.id)
- user = User.get_cached_by_id(user.id)
+ follower = User.get_cached_by_id(follower.id)
+
+ refute User.following?(follower, user)
+ refute User.get_by_id(user.id)
+ assert {:ok, nil} == Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
+
+ user_activities =
+ user.ap_id
+ |> Activity.query_by_actor()
+ |> Repo.all()
+ |> Enum.map(fn act -> act.data["type"] end)
+
+ assert Enum.all?(user_activities, fn act -> act in ~w(Delete Undo) end)
+
+ refute Activity.get_by_id(activity.id)
+ refute Activity.get_by_id(like.id)
+ refute Activity.get_by_id(like_two.id)
+ refute Activity.get_by_id(repeat.id)
+ end
+
+ test_with_mock "it sends out User Delete activity",
+ %{user: user},
+ Pleroma.Web.ActivityPub.Publisher,
+ [:passthrough],
+ [] do
+ config_path = [:instance, :federating]
+ initial_setting = Pleroma.Config.get(config_path)
+ Pleroma.Config.put(config_path, true)
- assert user.info.deactivated
+ {:ok, follower} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
+ {:ok, _} = User.follow(follower, user)
- refute User.following?(user, followed)
- refute User.following?(followed, follower)
+ {:ok, _user} = User.delete(user)
- # TODO: Remove favorites, repeats, delete activities.
+ assert called(
+ Pleroma.Web.ActivityPub.Publisher.publish_one(%{
+ inbox: "http://mastodon.example.org/inbox"
+ })
+ )
- refute Activity.get_by_id(activity.id)
+ Pleroma.Config.put(config_path, initial_setting)
+ end
end
test "get_public_key_for_ap_id fetches a user that's not in the db" do
@@ -1010,103 +1068,6 @@ defmodule Pleroma.UserTest do
end
end
- describe "User.search" do
- test "finds a user by full or partial nickname" do
- user = insert(:user, %{nickname: "john"})
-
- Enum.each(["john", "jo", "j"], fn query ->
- assert user ==
- User.search(query)
- |> List.first()
- |> Map.put(:search_rank, nil)
- |> Map.put(:search_type, nil)
- end)
- end
-
- test "finds a user by full or partial name" do
- user = insert(:user, %{name: "John Doe"})
-
- Enum.each(["John Doe", "JOHN", "doe", "j d", "j", "d"], fn query ->
- assert user ==
- User.search(query)
- |> List.first()
- |> Map.put(:search_rank, nil)
- |> Map.put(:search_type, nil)
- end)
- end
-
- test "finds users, preferring nickname matches over name matches" do
- u1 = insert(:user, %{name: "lain", nickname: "nick1"})
- u2 = insert(:user, %{nickname: "lain", name: "nick1"})
-
- assert [u2.id, u1.id] == Enum.map(User.search("lain"), & &1.id)
- end
-
- test "finds users, considering density of matched tokens" do
- u1 = insert(:user, %{name: "Bar Bar plus Word Word"})
- u2 = insert(:user, %{name: "Word Word Bar Bar Bar"})
-
- assert [u2.id, u1.id] == Enum.map(User.search("bar word"), & &1.id)
- end
-
- test "finds users, ranking by similarity" do
- u1 = insert(:user, %{name: "lain"})
- _u2 = insert(:user, %{name: "ean"})
- u3 = insert(:user, %{name: "ebn", nickname: "lain@mastodon.social"})
- u4 = insert(:user, %{nickname: "lain@pleroma.soykaf.com"})
-
- assert [u4.id, u3.id, u1.id] == Enum.map(User.search("lain@ple"), & &1.id)
- end
-
- test "finds users, handling misspelled requests" do
- u1 = insert(:user, %{name: "lain"})
-
- assert [u1.id] == Enum.map(User.search("laiin"), & &1.id)
- end
-
- test "finds users, boosting ranks of friends and followers" do
- u1 = insert(:user)
- u2 = insert(:user, %{name: "Doe"})
- follower = insert(:user, %{name: "Doe"})
- friend = insert(:user, %{name: "Doe"})
-
- {:ok, follower} = User.follow(follower, u1)
- {:ok, u1} = User.follow(u1, friend)
-
- assert [friend.id, follower.id, u2.id] --
- Enum.map(User.search("doe", resolve: false, for_user: u1), & &1.id) == []
- end
-
- test "finds a user whose name is nil" do
- _user = insert(:user, %{name: "notamatch", nickname: "testuser@pleroma.amplifie.red"})
- user_two = insert(:user, %{name: nil, nickname: "lain@pleroma.soykaf.com"})
-
- assert user_two ==
- User.search("lain@pleroma.soykaf.com")
- |> List.first()
- |> Map.put(:search_rank, nil)
- |> Map.put(:search_type, nil)
- end
-
- test "does not yield false-positive matches" do
- insert(:user, %{name: "John Doe"})
-
- Enum.each(["mary", "a", ""], fn query ->
- assert [] == User.search(query)
- end)
- end
-
- test "works with URIs" do
- results = User.search("http://mastodon.example.org/users/admin", resolve: true)
- result = results |> List.first()
-
- 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)
- end
- end
-
test "auth_active?/1 works correctly" do
Pleroma.Config.put([:instance, :account_activation_required], true)
@@ -1266,4 +1227,87 @@ defmodule Pleroma.UserTest do
assert user.info.keys == "xxx"
end
end
+
+ describe "get_ap_ids_by_nicknames" do
+ test "it returns a list of AP ids for a given set of nicknames" do
+ user = insert(:user)
+ user_two = insert(:user)
+
+ ap_ids = User.get_ap_ids_by_nicknames([user.nickname, user_two.nickname, "nonexistent"])
+ assert length(ap_ids) == 2
+ assert user.ap_id in ap_ids
+ assert user_two.ap_id in ap_ids
+ end
+ end
+
+ describe "sync followers count" do
+ setup do
+ user1 = insert(:user, local: false, ap_id: "http://localhost:4001/users/masto_closed")
+ user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2")
+ insert(:user, local: true)
+ insert(:user, local: false, info: %{deactivated: true})
+ {:ok, user1: user1, user2: user2}
+ end
+
+ test "external_users/1 external active users with limit", %{user1: user1, user2: user2} do
+ [fdb_user1] = User.external_users(limit: 1)
+
+ assert fdb_user1.ap_id
+ assert fdb_user1.ap_id == user1.ap_id
+ assert fdb_user1.id == user1.id
+
+ [fdb_user2] = User.external_users(max_id: fdb_user1.id, limit: 1)
+
+ assert fdb_user2.ap_id
+ assert fdb_user2.ap_id == user2.ap_id
+ assert fdb_user2.id == user2.id
+
+ assert User.external_users(max_id: fdb_user2.id, limit: 1) == []
+ end
+ end
+
+ describe "set_info_cache/2" do
+ setup do
+ user = insert(:user)
+ {:ok, user: user}
+ end
+
+ test "update from args", %{user: user} do
+ User.set_info_cache(user, %{following_count: 15, follower_count: 18})
+
+ %{follower_count: followers, following_count: following} = User.get_cached_user_info(user)
+ assert followers == 18
+ assert following == 15
+ end
+
+ test "without args", %{user: user} do
+ User.set_info_cache(user, %{})
+
+ %{follower_count: followers, following_count: following} = User.get_cached_user_info(user)
+ assert followers == 0
+ assert following == 0
+ end
+ end
+
+ describe "user_info/2" do
+ setup do
+ user = insert(:user)
+ {:ok, user: user}
+ end
+
+ test "update from args", %{user: user} do
+ %{follower_count: followers, following_count: following} =
+ User.user_info(user, %{following_count: 15, follower_count: 18})
+
+ assert followers == 18
+ assert following == 15
+ end
+
+ test "without args", %{user: user} do
+ %{follower_count: followers, following_count: following} = User.user_info(user)
+
+ assert followers == 0
+ assert following == 0
+ end
+ end
end
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 30adfda36..452172bb4 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -11,9 +11,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ObjectView
alias Pleroma.Web.ActivityPub.UserView
+ alias Pleroma.Web.ActivityPub.Utils
+ alias Pleroma.Web.CommonAPI
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
@@ -162,7 +171,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
describe "/object/:uuid/likes" do
test "it returns the like activities in a collection", %{conn: conn} do
like = insert(:like_activity)
- uuid = String.split(like.data["object"], "/") |> List.last()
+ like_object_ap_id = Object.normalize(like).data["id"]
+ uuid = String.split(like_object_ap_id, "/") |> List.last()
result =
conn
@@ -234,13 +244,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
describe "/users/:nickname/inbox" do
- test "it inserts an incoming activity into the database", %{conn: conn} do
- user = insert(:user)
-
+ setup do
data =
File.read!("test/fixtures/mastodon-post-activity.json")
|> Poison.decode!()
- |> Map.put("bcc", [user.ap_id])
+
+ [data: data]
+ end
+
+ test "it inserts an incoming activity into the database", %{conn: conn, data: data} do
+ user = insert(:user)
+ data = Map.put(data, "bcc", [user.ap_id])
conn =
conn
@@ -253,16 +267,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert Activity.get_by_ap_id(data["id"])
end
- test "it accepts messages from actors that are followed by the user", %{conn: conn} do
+ test "it accepts messages from actors that are followed by the user", %{
+ conn: conn,
+ data: data
+ } do
recipient = insert(:user)
actor = insert(:user, %{ap_id: "http://mastodon.example.org/users/actor"})
{:ok, recipient} = User.follow(recipient, actor)
- data =
- File.read!("test/fixtures/mastodon-post-activity.json")
- |> Poison.decode!()
-
object =
data["object"]
|> Map.put("attributedTo", actor.ap_id)
@@ -298,6 +311,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it returns a note activity in a collection", %{conn: conn} do
note_activity = insert(:direct_note_activity)
+ note_object = Object.normalize(note_activity)
user = User.get_cached_by_ap_id(hd(note_activity.data["to"]))
conn =
@@ -306,16 +320,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> put_req_header("accept", "application/activity+json")
|> get("/users/#{user.nickname}/inbox")
- assert response(conn, 200) =~ note_activity.data["object"]["content"]
+ assert response(conn, 200) =~ note_object.data["content"]
end
- test "it clears `unreachable` federation status of the sender", %{conn: conn} do
+ test "it clears `unreachable` federation status of the sender", %{conn: conn, data: data} do
user = insert(:user)
-
- data =
- File.read!("test/fixtures/mastodon-post-activity.json")
- |> Poison.decode!()
- |> Map.put("bcc", [user.ap_id])
+ data = Map.put(data, "bcc", [user.ap_id])
sender_host = URI.parse(data["actor"]).host
Instances.set_consistently_unreachable(sender_host)
@@ -330,6 +340,47 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert "ok" == json_response(conn, 200)
assert Instances.reachable?(sender_host)
end
+
+ test "it removes all follower collections but actor's", %{conn: conn} do
+ [actor, recipient] = insert_pair(:user)
+
+ data =
+ File.read!("test/fixtures/activitypub-client-post-activity.json")
+ |> Poison.decode!()
+
+ object = Map.put(data["object"], "attributedTo", actor.ap_id)
+
+ data =
+ data
+ |> Map.put("id", Utils.generate_object_id())
+ |> Map.put("actor", actor.ap_id)
+ |> Map.put("object", object)
+ |> Map.put("cc", [
+ recipient.follower_address,
+ actor.follower_address
+ ])
+ |> Map.put("to", [
+ recipient.ap_id,
+ recipient.follower_address,
+ "https://www.w3.org/ns/activitystreams#Public"
+ ])
+
+ conn
+ |> assign(:valid_signature, true)
+ |> put_req_header("content-type", "application/activity+json")
+ |> post("/users/#{recipient.nickname}/inbox", data)
+ |> json_response(200)
+
+ activity = Activity.get_by_ap_id(data["id"])
+
+ assert activity.id
+ assert actor.follower_address in activity.recipients
+ assert actor.follower_address in activity.data["cc"]
+
+ refute recipient.follower_address in activity.recipients
+ refute recipient.follower_address in activity.data["cc"]
+ refute recipient.follower_address in activity.data["to"]
+ end
end
describe "/users/:nickname/outbox" do
@@ -347,6 +398,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it returns a note activity in a collection", %{conn: conn} do
note_activity = insert(:note_activity)
+ note_object = Object.normalize(note_activity)
user = User.get_cached_by_ap_id(note_activity.data["actor"])
conn =
@@ -354,7 +406,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> put_req_header("accept", "application/activity+json")
|> get("/users/#{user.nickname}/outbox")
- assert response(conn, 200) =~ note_activity.data["object"]["content"]
+ assert response(conn, 200) =~ note_object.data["content"]
end
test "it returns an announce activity in a collection", %{conn: conn} do
@@ -416,12 +468,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it erects a tombstone when receiving a delete activity", %{conn: conn} do
note_activity = insert(:note_activity)
+ note_object = Object.normalize(note_activity)
user = User.get_cached_by_ap_id(note_activity.data["actor"])
data = %{
type: "Delete",
object: %{
- id: note_activity.data["object"]["id"]
+ id: note_object.data["id"]
}
}
@@ -434,19 +487,19 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
result = json_response(conn, 201)
assert Activity.get_by_ap_id(result["id"])
- object = Object.get_by_ap_id(note_activity.data["object"]["id"])
- assert object
+ assert object = Object.get_by_ap_id(note_object.data["id"])
assert object.data["type"] == "Tombstone"
end
test "it rejects delete activity of object from other actor", %{conn: conn} do
note_activity = insert(:note_activity)
+ note_object = Object.normalize(note_activity)
user = insert(:user)
data = %{
type: "Delete",
object: %{
- id: note_activity.data["object"]["id"]
+ id: note_object.data["id"]
}
}
@@ -461,12 +514,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it increases like count when receiving a like action", %{conn: conn} do
note_activity = insert(:note_activity)
+ note_object = Object.normalize(note_activity)
user = User.get_cached_by_ap_id(note_activity.data["actor"])
data = %{
type: "Like",
object: %{
- id: note_activity.data["object"]["id"]
+ id: note_object.data["id"]
}
}
@@ -479,8 +533,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
result = json_response(conn, 201)
assert Activity.get_by_ap_id(result["id"])
- object = Object.get_by_ap_id(note_activity.data["object"]["id"])
- assert object
+ assert object = Object.get_by_ap_id(note_object.data["id"])
assert object.data["like_count"] == 1
end
end
@@ -499,7 +552,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert result["first"]["orderedItems"] == [user.ap_id]
end
- test "it returns returns empty if the user has 'hide_followers' set", %{conn: conn} do
+ test "it returns returns a uri if the user has 'hide_followers' set", %{conn: conn} do
user = insert(:user)
user_two = insert(:user, %{info: %{hide_followers: true}})
User.follow(user, user_two)
@@ -509,8 +562,35 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> get("/users/#{user_two.nickname}/followers")
|> json_response(200)
- assert result["first"]["orderedItems"] == []
- assert result["totalItems"] == 0
+ assert is_binary(result["first"])
+ end
+
+ test "it returns a 403 error on pages, if the user has 'hide_followers' set and the request is not authenticated",
+ %{conn: conn} do
+ user = insert(:user, %{info: %{hide_followers: true}})
+
+ result =
+ conn
+ |> get("/users/#{user.nickname}/followers?page=1")
+
+ assert result.status == 403
+ assert result.resp_body == ""
+ end
+
+ test "it renders the page, if the user has 'hide_followers' set and the request is authenticated with the same user",
+ %{conn: conn} do
+ user = insert(:user, %{info: %{hide_followers: true}})
+ other_user = insert(:user)
+ {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
+
+ result =
+ conn
+ |> assign(:user, user)
+ |> get("/users/#{user.nickname}/followers?page=1")
+ |> json_response(200)
+
+ assert result["totalItems"] == 1
+ assert result["orderedItems"] == [other_user.ap_id]
end
test "it works for more than 10 users", %{conn: conn} do
@@ -554,7 +634,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert result["first"]["orderedItems"] == [user_two.ap_id]
end
- test "it returns returns empty if the user has 'hide_follows' set", %{conn: conn} do
+ test "it returns a uri if the user has 'hide_follows' set", %{conn: conn} do
user = insert(:user, %{info: %{hide_follows: true}})
user_two = insert(:user)
User.follow(user, user_two)
@@ -564,8 +644,35 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> get("/users/#{user.nickname}/following")
|> json_response(200)
- assert result["first"]["orderedItems"] == []
- assert result["totalItems"] == 0
+ assert is_binary(result["first"])
+ end
+
+ test "it returns a 403 error on pages, if the user has 'hide_follows' set and the request is not authenticated",
+ %{conn: conn} do
+ user = insert(:user, %{info: %{hide_follows: true}})
+
+ result =
+ conn
+ |> get("/users/#{user.nickname}/following?page=1")
+
+ assert result.status == 403
+ assert result.resp_body == ""
+ end
+
+ test "it renders the page, if the user has 'hide_follows' set and the request is authenticated with the same user",
+ %{conn: conn} do
+ user = insert(:user, %{info: %{hide_follows: true}})
+ other_user = insert(:user)
+ {:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
+
+ result =
+ conn
+ |> assign(:user, user)
+ |> get("/users/#{user.nickname}/following?page=1")
+ |> json_response(200)
+
+ assert result["totalItems"] == 1
+ assert result["orderedItems"] == [other_user.ap_id]
end
test "it works for more than 10 users", %{conn: conn} do
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index f743f380b..00adbc0f9 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -254,10 +254,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
}
{:ok, %Activity{} = activity} = ActivityPub.insert(data)
- object = Object.normalize(activity.data["object"])
-
+ assert object = Object.normalize(activity)
assert is_binary(object.data["id"])
- assert %Object{} = Object.get_by_ap_id(activity.data["object"])
end
end
@@ -659,7 +657,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
describe "like an object" do
test "adds a like activity to the db" do
note_activity = insert(:note_activity)
- object = Object.get_by_ap_id(note_activity.data["object"]["id"])
+ assert object = Object.normalize(note_activity)
+
user = insert(:user)
user_two = insert(:user)
@@ -678,19 +677,23 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert like_activity == same_like_activity
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
describe "unliking" do
test "unliking a previously liked object" do
note_activity = insert(:note_activity)
- object = Object.get_by_ap_id(note_activity.data["object"]["id"])
+ object = Object.normalize(note_activity)
user = insert(:user)
# Unliking something that hasn't been liked does nothing
@@ -710,7 +713,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
describe "announcing an object" do
test "adds an announce activity to the db" do
note_activity = insert(:note_activity)
- object = Object.get_by_ap_id(note_activity.data["object"]["id"])
+ object = Object.normalize(note_activity)
user = insert(:user)
{:ok, announce_activity, object} = ActivityPub.announce(user, object)
@@ -731,7 +734,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
describe "unannouncing an object" do
test "unannouncing a previously announced object" do
note_activity = insert(:note_activity)
- object = Object.get_by_ap_id(note_activity.data["object"]["id"])
+ object = Object.normalize(note_activity)
user = insert(:user)
# Unannouncing an object that is not announced does nothing
@@ -810,10 +813,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert activity.data["type"] == "Undo"
assert activity.data["actor"] == follower.ap_id
- assert is_map(activity.data["object"])
- assert activity.data["object"]["type"] == "Follow"
- assert activity.data["object"]["object"] == followed.ap_id
- assert activity.data["object"]["id"] == follow_activity.data["id"]
+ embedded_object = activity.data["object"]
+ assert is_map(embedded_object)
+ assert embedded_object["type"] == "Follow"
+ assert embedded_object["object"] == followed.ap_id
+ assert embedded_object["id"] == follow_activity.data["id"]
end
end
@@ -839,22 +843,23 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert activity.data["type"] == "Undo"
assert activity.data["actor"] == blocker.ap_id
- assert is_map(activity.data["object"])
- assert activity.data["object"]["type"] == "Block"
- assert activity.data["object"]["object"] == blocked.ap_id
- assert activity.data["object"]["id"] == block_activity.data["id"]
+ embedded_object = activity.data["object"]
+ assert is_map(embedded_object)
+ assert embedded_object["type"] == "Block"
+ assert embedded_object["object"] == blocked.ap_id
+ assert embedded_object["id"] == block_activity.data["id"]
end
end
describe "deletion" do
test "it creates a delete activity and deletes the original object" do
note = insert(:note_activity)
- object = Object.get_by_ap_id(note.data["object"]["id"])
+ object = Object.normalize(note)
{:ok, delete} = ActivityPub.delete(object)
assert delete.data["type"] == "Delete"
assert delete.data["actor"] == note.data["actor"]
- assert delete.data["object"] == note.data["object"]["id"]
+ assert delete.data["object"] == object.data["id"]
assert Activity.get_by_id(delete.id) != nil
@@ -900,13 +905,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
test "it creates a delete activity and checks that it is also sent to users mentioned by the deleted object" do
user = insert(:user)
note = insert(:note_activity)
+ object = Object.normalize(note)
{:ok, object} =
- Object.get_by_ap_id(note.data["object"]["id"])
+ object
|> Object.change(%{
data: %{
- "actor" => note.data["object"]["actor"],
- "id" => note.data["object"]["id"],
+ "actor" => object.data["actor"],
+ "id" => object.data["id"],
"to" => [user.ap_id],
"type" => "Note"
}
@@ -1018,8 +1024,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert update.data["actor"] == user.ap_id
assert update.data["to"] == [user.follower_address]
- assert update.data["object"]["id"] == user_data["id"]
- assert update.data["object"]["type"] == user_data["type"]
+ assert embedded_object = update.data["object"]
+ assert embedded_object["id"] == user_data["id"]
+ assert embedded_object["type"] == user_data["type"]
end
end
@@ -1183,7 +1190,51 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end
end
+ test "fetch_activities/2 returns activities addressed to a list " do
+ user = insert(:user)
+ member = insert(:user)
+ {:ok, list} = Pleroma.List.create("foo", user)
+ {:ok, list} = Pleroma.List.follow(list, member)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
+
+ activity = Repo.preload(activity, :bookmark)
+ activity = %Activity{activity | thread_muted?: !!activity.thread_muted?}
+
+ assert ActivityPub.fetch_activities([], %{"user" => user}) == [activity]
+ end
+
def data_uri do
File.read!("test/fixtures/avatar_data_uri")
end
+
+ describe "fetch_activities_bounded" do
+ test "fetches private posts for followed users" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "thought I looked cute might delete later :3",
+ "visibility" => "private"
+ })
+
+ [result] = ActivityPub.fetch_activities_bounded([user.follower_address], [])
+ assert result.id == activity.id
+ end
+
+ test "fetches only public posts for other users" do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe", "visibility" => "public"})
+
+ {:ok, _private_activity} =
+ CommonAPI.post(user, %{
+ "status" => "why is tenshi eating a corndog so cute?",
+ "visibility" => "private"
+ })
+
+ [result] = ActivityPub.fetch_activities_bounded([], [user.follower_address])
+ assert result.id == activity.id
+ end
+ end
end
diff --git a/test/web/activity_pub/mrf/anti_link_spam_policy_test.exs b/test/web/activity_pub/mrf/anti_link_spam_policy_test.exs
new file mode 100644
index 000000000..03dc299ec
--- /dev/null
+++ b/test/web/activity_pub/mrf/anti_link_spam_policy_test.exs
@@ -0,0 +1,145 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+ import ExUnit.CaptureLog
+
+ alias Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy
+
+ @linkless_message %{
+ "type" => "Create",
+ "object" => %{
+ "content" => "hi world!"
+ }
+ }
+
+ @linkful_message %{
+ "type" => "Create",
+ "object" => %{
+ "content" => "<a href='https://example.com'>hi world!</a>"
+ }
+ }
+
+ @response_message %{
+ "type" => "Create",
+ "object" => %{
+ "name" => "yes",
+ "type" => "Answer"
+ }
+ }
+
+ describe "with new user" do
+ test "it allows posts without links" do
+ user = insert(:user)
+
+ assert user.info.note_count == 0
+
+ message =
+ @linkless_message
+ |> Map.put("actor", user.ap_id)
+
+ {:ok, _message} = AntiLinkSpamPolicy.filter(message)
+ end
+
+ test "it disallows posts with links" do
+ user = insert(:user)
+
+ assert user.info.note_count == 0
+
+ message =
+ @linkful_message
+ |> Map.put("actor", user.ap_id)
+
+ {:reject, _} = AntiLinkSpamPolicy.filter(message)
+ end
+ end
+
+ describe "with old user" do
+ test "it allows posts without links" do
+ user = insert(:user, info: %{note_count: 1})
+
+ assert user.info.note_count == 1
+
+ message =
+ @linkless_message
+ |> Map.put("actor", user.ap_id)
+
+ {:ok, _message} = AntiLinkSpamPolicy.filter(message)
+ end
+
+ test "it allows posts with links" do
+ user = insert(:user, info: %{note_count: 1})
+
+ assert user.info.note_count == 1
+
+ message =
+ @linkful_message
+ |> Map.put("actor", user.ap_id)
+
+ {:ok, _message} = AntiLinkSpamPolicy.filter(message)
+ end
+ end
+
+ describe "with followed new user" do
+ test "it allows posts without links" do
+ user = insert(:user, info: %{follower_count: 1})
+
+ assert user.info.follower_count == 1
+
+ message =
+ @linkless_message
+ |> Map.put("actor", user.ap_id)
+
+ {:ok, _message} = AntiLinkSpamPolicy.filter(message)
+ end
+
+ test "it allows posts with links" do
+ user = insert(:user, info: %{follower_count: 1})
+
+ assert user.info.follower_count == 1
+
+ message =
+ @linkful_message
+ |> Map.put("actor", user.ap_id)
+
+ {:ok, _message} = AntiLinkSpamPolicy.filter(message)
+ end
+ end
+
+ describe "with unknown actors" do
+ test "it rejects posts without links" do
+ message =
+ @linkless_message
+ |> Map.put("actor", "http://invalid.actor")
+
+ assert capture_log(fn ->
+ {:reject, _} = AntiLinkSpamPolicy.filter(message)
+ end) =~ "[error] Could not decode user at fetch http://invalid.actor"
+ end
+
+ test "it rejects posts with links" do
+ message =
+ @linkful_message
+ |> Map.put("actor", "http://invalid.actor")
+
+ assert capture_log(fn ->
+ {:reject, _} = AntiLinkSpamPolicy.filter(message)
+ end) =~ "[error] Could not decode user at fetch http://invalid.actor"
+ end
+ end
+
+ describe "with contentless-objects" do
+ test "it does not reject them or error out" do
+ user = insert(:user, info: %{note_count: 1})
+
+ message =
+ @response_message
+ |> Map.put("actor", user.ap_id)
+
+ {:ok, _message} = AntiLinkSpamPolicy.filter(message)
+ end
+ end
+end
diff --git a/test/web/activity_pub/mrf/ensure_re_prepended_test.exs b/test/web/activity_pub/mrf/ensure_re_prepended_test.exs
new file mode 100644
index 000000000..dbc8b9e80
--- /dev/null
+++ b/test/web/activity_pub/mrf/ensure_re_prepended_test.exs
@@ -0,0 +1,82 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrependedTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Activity
+ alias Pleroma.Object
+ alias Pleroma.Web.ActivityPub.MRF.EnsureRePrepended
+
+ describe "rewrites summary" do
+ test "it adds `re:` to summary object when child summary and parent summary equal" do
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "summary" => "object-summary",
+ "inReplyTo" => %Activity{object: %Object{data: %{"summary" => "object-summary"}}}
+ }
+ }
+
+ assert {:ok, res} = EnsureRePrepended.filter(message)
+ assert res["object"]["summary"] == "re: object-summary"
+ end
+
+ test "it adds `re:` to summary object when child summary containts re-subject of parent summary " do
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "summary" => "object-summary",
+ "inReplyTo" => %Activity{object: %Object{data: %{"summary" => "re: object-summary"}}}
+ }
+ }
+
+ assert {:ok, res} = EnsureRePrepended.filter(message)
+ assert res["object"]["summary"] == "re: object-summary"
+ end
+ end
+
+ describe "skip filter" do
+ test "it skip if type isn't 'Create'" do
+ message = %{
+ "type" => "Annotation",
+ "object" => %{"summary" => "object-summary"}
+ }
+
+ assert {:ok, res} = EnsureRePrepended.filter(message)
+ assert res == message
+ end
+
+ test "it skip if summary is empty" do
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "inReplyTo" => %Activity{object: %Object{data: %{"summary" => "summary"}}}
+ }
+ }
+
+ assert {:ok, res} = EnsureRePrepended.filter(message)
+ assert res == message
+ end
+
+ test "it skip if inReplyTo is empty" do
+ message = %{"type" => "Create", "object" => %{"summary" => "summary"}}
+ assert {:ok, res} = EnsureRePrepended.filter(message)
+ assert res == message
+ end
+
+ test "it skip if parent and child summary isn't equal" do
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "summary" => "object-summary",
+ "inReplyTo" => %Activity{object: %Object{data: %{"summary" => "summary"}}}
+ }
+ }
+
+ assert {:ok, res} = EnsureRePrepended.filter(message)
+ assert res == message
+ end
+ end
+end
diff --git a/test/web/activity_pub/mrf/mediaproxy_warming_policy_test.exs b/test/web/activity_pub/mrf/mediaproxy_warming_policy_test.exs
new file mode 100644
index 000000000..372e789be
--- /dev/null
+++ b/test/web/activity_pub/mrf/mediaproxy_warming_policy_test.exs
@@ -0,0 +1,45 @@
+# 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.MediaProxyWarmingPolicyTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.HTTP
+ alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
+
+ import Mock
+
+ @message %{
+ "type" => "Create",
+ "object" => %{
+ "type" => "Note",
+ "content" => "content",
+ "attachment" => [
+ %{"url" => [%{"href" => "http://example.com/image.jpg"}]}
+ ]
+ }
+ }
+
+ test "it prefetches media proxy URIs" do
+ with_mock HTTP, get: fn _, _, _ -> {:ok, []} end do
+ MediaProxyWarmingPolicy.filter(@message)
+ assert called(HTTP.get(:_, :_, :_))
+ end
+ end
+
+ test "it does nothing when no attachments are present" do
+ object =
+ @message["object"]
+ |> Map.delete("attachment")
+
+ message =
+ @message
+ |> Map.put("object", object)
+
+ with_mock HTTP, get: fn _, _, _ -> {:ok, []} end do
+ MediaProxyWarmingPolicy.filter(message)
+ refute called(HTTP.get(:_, :_, :_))
+ end
+ end
+end
diff --git a/test/web/activity_pub/mrf/no_placeholder_text_policy_test.exs b/test/web/activity_pub/mrf/no_placeholder_text_policy_test.exs
new file mode 100644
index 000000000..63ed71129
--- /dev/null
+++ b/test/web/activity_pub/mrf/no_placeholder_text_policy_test.exs
@@ -0,0 +1,37 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicyTest do
+ use Pleroma.DataCase
+ alias Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicy
+
+ test "it clears content object" do
+ message = %{
+ "type" => "Create",
+ "object" => %{"content" => ".", "attachment" => "image"}
+ }
+
+ assert {:ok, res} = NoPlaceholderTextPolicy.filter(message)
+ assert res["object"]["content"] == ""
+
+ message = put_in(message, ["object", "content"], "<p>.</p>")
+ assert {:ok, res} = NoPlaceholderTextPolicy.filter(message)
+ assert res["object"]["content"] == ""
+ end
+
+ @messages [
+ %{
+ "type" => "Create",
+ "object" => %{"content" => "test", "attachment" => "image"}
+ },
+ %{"type" => "Create", "object" => %{"content" => "."}},
+ %{"type" => "Create", "object" => %{"content" => "<p>.</p>"}}
+ ]
+ test "it skips filter" do
+ Enum.each(@messages, fn message ->
+ assert {:ok, res} = NoPlaceholderTextPolicy.filter(message)
+ assert res == message
+ end)
+ end
+end
diff --git a/test/web/activity_pub/mrf/normalize_markup_test.exs b/test/web/activity_pub/mrf/normalize_markup_test.exs
new file mode 100644
index 000000000..3916a1f35
--- /dev/null
+++ b/test/web/activity_pub/mrf/normalize_markup_test.exs
@@ -0,0 +1,42 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkupTest do
+ use Pleroma.DataCase
+ alias Pleroma.Web.ActivityPub.MRF.NormalizeMarkup
+
+ @html_sample """
+ <b>this is in bold</b>
+ <p>this is a paragraph</p>
+ this is a linebreak<br />
+ this is a link with allowed "rel" attribute: <a href="http://example.com/" rel="tag">example.com</a>
+ this is a link with not allowed "rel" attribute: <a href="http://example.com/" rel="tag noallowed">example.com</a>
+ this is an image: <img src="http://example.com/image.jpg"><br />
+ <script>alert('hacked')</script>
+ """
+
+ test "it filter html tags" do
+ expected = """
+ <b>this is in bold</b>
+ <p>this is a paragraph</p>
+ this is a linebreak<br />
+ this is a link with allowed "rel" attribute: <a href="http://example.com/" rel="tag">example.com</a>
+ this is a link with not allowed "rel" attribute: <a href="http://example.com/">example.com</a>
+ this is an image: <img src="http://example.com/image.jpg" /><br />
+ alert('hacked')
+ """
+
+ message = %{"type" => "Create", "object" => %{"content" => @html_sample}}
+
+ assert {:ok, res} = NormalizeMarkup.filter(message)
+ assert res["object"]["content"] == expected
+ end
+
+ test "it skips filter if type isn't `Create`" do
+ message = %{"type" => "Note", "object" => %{}}
+
+ assert {:ok, res} = NormalizeMarkup.filter(message)
+ assert res == message
+ end
+end
diff --git a/test/web/activity_pub/mrf/reject_non_public_test.exs b/test/web/activity_pub/mrf/reject_non_public_test.exs
new file mode 100644
index 000000000..fdf6b245e
--- /dev/null
+++ b/test/web/activity_pub/mrf/reject_non_public_test.exs
@@ -0,0 +1,105 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+
+ 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
+
+ describe "public message" do
+ test "it's allowed when address is public" do
+ actor = insert(:user, follower_address: "test-address")
+
+ message = %{
+ "actor" => actor.ap_id,
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
+ "type" => "Create"
+ }
+
+ assert {:ok, message} = RejectNonPublic.filter(message)
+ end
+
+ test "it's allowed when cc address contain public address" do
+ actor = insert(:user, follower_address: "test-address")
+
+ message = %{
+ "actor" => actor.ap_id,
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
+ "type" => "Create"
+ }
+
+ assert {:ok, message} = RejectNonPublic.filter(message)
+ end
+ end
+
+ describe "followers message" do
+ test "it's allowed when addrer of message in the follower addresses of user and it enabled in config" do
+ actor = insert(:user, follower_address: "test-address")
+
+ message = %{
+ "actor" => actor.ap_id,
+ "to" => ["test-address"],
+ "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
+ "type" => "Create"
+ }
+
+ Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], true)
+ assert {:ok, message} = RejectNonPublic.filter(message)
+ end
+
+ test "it's rejected when addrer of message in the follower addresses of user and it disabled in config" do
+ actor = insert(:user, follower_address: "test-address")
+
+ message = %{
+ "actor" => actor.ap_id,
+ "to" => ["test-address"],
+ "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
+ "type" => "Create"
+ }
+
+ Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], false)
+ assert {:reject, nil} = RejectNonPublic.filter(message)
+ end
+ end
+
+ describe "direct message" do
+ test "it's allows when direct messages are allow" do
+ actor = insert(:user)
+
+ message = %{
+ "actor" => actor.ap_id,
+ "to" => ["https://www.w3.org/ns/activitystreams#Publid"],
+ "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
+ "type" => "Create"
+ }
+
+ Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], true)
+ assert {:ok, message} = RejectNonPublic.filter(message)
+ end
+
+ test "it's reject when direct messages aren't allow" do
+ actor = insert(:user)
+
+ message = %{
+ "actor" => actor.ap_id,
+ "to" => ["https://www.w3.org/ns/activitystreams#Publid~~~"],
+ "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
+ "type" => "Create"
+ }
+
+ Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], false)
+ assert {:reject, nil} = RejectNonPublic.filter(message)
+ end
+ end
+end
diff --git a/test/web/activity_pub/mrf/subchain_policy_test.exs b/test/web/activity_pub/mrf/subchain_policy_test.exs
new file mode 100644
index 000000000..f7cbcad48
--- /dev/null
+++ b/test/web/activity_pub/mrf/subchain_policy_test.exs
@@ -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.Web.ActivityPub.MRF.SubchainPolicyTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.ActivityPub.MRF.DropPolicy
+ alias Pleroma.Web.ActivityPub.MRF.SubchainPolicy
+
+ @message %{
+ "actor" => "https://banned.com",
+ "type" => "Create",
+ "object" => %{"content" => "hi"}
+ }
+
+ test "it matches and processes subchains when the actor matches a configured target" do
+ Pleroma.Config.put([:mrf_subchain, :match_actor], %{
+ ~r/^https:\/\/banned.com/s => [DropPolicy]
+ })
+
+ {:reject, _} = SubchainPolicy.filter(@message)
+ end
+
+ test "it doesn't match and process subchains when the actor doesn't match a configured target" do
+ Pleroma.Config.put([:mrf_subchain, :match_actor], %{
+ ~r/^https:\/\/borked.com/s => [DropPolicy]
+ })
+
+ {:ok, _message} = SubchainPolicy.filter(@message)
+ end
+end
diff --git a/test/web/activity_pub/mrf/tag_policy_test.exs b/test/web/activity_pub/mrf/tag_policy_test.exs
new file mode 100644
index 000000000..4aa35311e
--- /dev/null
+++ b/test/web/activity_pub/mrf/tag_policy_test.exs
@@ -0,0 +1,123 @@
+# 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.TagPolicyTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+
+ alias Pleroma.Web.ActivityPub.MRF.TagPolicy
+ @public "https://www.w3.org/ns/activitystreams#Public"
+
+ describe "mrf_tag:disable-any-subscription" do
+ test "rejects message" do
+ actor = insert(:user, tags: ["mrf_tag:disable-any-subscription"])
+ message = %{"object" => actor.ap_id, "type" => "Follow"}
+ assert {:reject, nil} = TagPolicy.filter(message)
+ end
+ end
+
+ describe "mrf_tag:disable-remote-subscription" do
+ test "rejects non-local follow requests" do
+ actor = insert(:user, tags: ["mrf_tag:disable-remote-subscription"])
+ follower = insert(:user, tags: ["mrf_tag:disable-remote-subscription"], local: false)
+ message = %{"object" => actor.ap_id, "type" => "Follow", "actor" => follower.ap_id}
+ assert {:reject, nil} = TagPolicy.filter(message)
+ end
+
+ test "allows non-local follow requests" do
+ actor = insert(:user, tags: ["mrf_tag:disable-remote-subscription"])
+ follower = insert(:user, tags: ["mrf_tag:disable-remote-subscription"], local: true)
+ message = %{"object" => actor.ap_id, "type" => "Follow", "actor" => follower.ap_id}
+ assert {:ok, message} = TagPolicy.filter(message)
+ end
+ end
+
+ describe "mrf_tag:sandbox" do
+ test "removes from public timelines" do
+ actor = insert(:user, tags: ["mrf_tag:sandbox"])
+
+ message = %{
+ "actor" => actor.ap_id,
+ "type" => "Create",
+ "object" => %{},
+ "to" => [@public, "f"],
+ "cc" => [@public, "d"]
+ }
+
+ except_message = %{
+ "actor" => actor.ap_id,
+ "type" => "Create",
+ "object" => %{"to" => ["f", actor.follower_address], "cc" => ["d"]},
+ "to" => ["f", actor.follower_address],
+ "cc" => ["d"]
+ }
+
+ assert TagPolicy.filter(message) == {:ok, except_message}
+ end
+ end
+
+ describe "mrf_tag:force-unlisted" do
+ test "removes from the federated timeline" do
+ actor = insert(:user, tags: ["mrf_tag:force-unlisted"])
+
+ message = %{
+ "actor" => actor.ap_id,
+ "type" => "Create",
+ "object" => %{},
+ "to" => [@public, "f"],
+ "cc" => [actor.follower_address, "d"]
+ }
+
+ except_message = %{
+ "actor" => actor.ap_id,
+ "type" => "Create",
+ "object" => %{"to" => ["f", actor.follower_address], "cc" => ["d", @public]},
+ "to" => ["f", actor.follower_address],
+ "cc" => ["d", @public]
+ }
+
+ assert TagPolicy.filter(message) == {:ok, except_message}
+ end
+ end
+
+ describe "mrf_tag:media-strip" do
+ test "removes attachments" do
+ actor = insert(:user, tags: ["mrf_tag:media-strip"])
+
+ message = %{
+ "actor" => actor.ap_id,
+ "type" => "Create",
+ "object" => %{"attachment" => ["file1"]}
+ }
+
+ except_message = %{
+ "actor" => actor.ap_id,
+ "type" => "Create",
+ "object" => %{}
+ }
+
+ assert TagPolicy.filter(message) == {:ok, except_message}
+ end
+ end
+
+ describe "mrf_tag:media-force-nsfw" do
+ test "Mark as sensitive on presence of attachments" do
+ actor = insert(:user, tags: ["mrf_tag:media-force-nsfw"])
+
+ message = %{
+ "actor" => actor.ap_id,
+ "type" => "Create",
+ "object" => %{"tag" => ["test"], "attachment" => ["file1"]}
+ }
+
+ except_message = %{
+ "actor" => actor.ap_id,
+ "type" => "Create",
+ "object" => %{"tag" => ["test", "nsfw"], "attachment" => ["file1"], "sensitive" => true}
+ }
+
+ assert TagPolicy.filter(message) == {:ok, except_message}
+ end
+ end
+end
diff --git a/test/web/activity_pub/mrf/user_allowlist_policy_test.exs b/test/web/activity_pub/mrf/user_allowlist_policy_test.exs
new file mode 100644
index 000000000..6519e2398
--- /dev/null
+++ b/test/web/activity_pub/mrf/user_allowlist_policy_test.exs
@@ -0,0 +1,36 @@
+# 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.UserAllowListPolicyTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+
+ 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
+
+ test "pass filter if allow list is empty" do
+ actor = insert(:user)
+ message = %{"actor" => actor.ap_id}
+ assert UserAllowListPolicy.filter(message) == {:ok, message}
+ end
+
+ test "pass filter if allow list isn't empty and user in allow list" do
+ actor = insert(:user)
+ Pleroma.Config.put([:mrf_user_allowlist, :localhost], [actor.ap_id, "test-ap-id"])
+ message = %{"actor" => actor.ap_id}
+ assert UserAllowListPolicy.filter(message) == {:ok, message}
+ end
+
+ test "rejected if allow list isn't empty and user not in allow list" do
+ actor = insert(:user)
+ Pleroma.Config.put([:mrf_user_allowlist, :localhost], ["test-ap-id"])
+ message = %{"actor" => actor.ap_id}
+ assert UserAllowListPolicy.filter(message) == {:reject, nil}
+ end
+end
diff --git a/test/web/activity_pub/transmogrifier/follow_handling_test.exs b/test/web/activity_pub/transmogrifier/follow_handling_test.exs
new file mode 100644
index 000000000..857d65564
--- /dev/null
+++ b/test/web/activity_pub/transmogrifier/follow_handling_test.exs
@@ -0,0 +1,143 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
+ use Pleroma.DataCase
+ alias Pleroma.Activity
+ alias Pleroma.Repo
+ alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.Transmogrifier
+ alias Pleroma.Web.ActivityPub.Utils
+
+ import Pleroma.Factory
+ import Ecto.Query
+
+ setup_all do
+ Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
+ describe "handle_incoming" do
+ test "it works for incoming follow requests" do
+ user = insert(:user)
+
+ data =
+ File.read!("test/fixtures/mastodon-follow-activity.json")
+ |> Poison.decode!()
+ |> Map.put("object", user.ap_id)
+
+ {:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
+
+ assert data["actor"] == "http://mastodon.example.org/users/admin"
+ assert data["type"] == "Follow"
+ assert data["id"] == "http://mastodon.example.org/users/admin#follows/2"
+
+ activity = Repo.get(Activity, activity.id)
+ assert activity.data["state"] == "accept"
+ assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
+ end
+
+ test "with locked accounts, it does not create a follow or an accept" do
+ user = insert(:user, info: %{locked: true})
+
+ data =
+ File.read!("test/fixtures/mastodon-follow-activity.json")
+ |> Poison.decode!()
+ |> Map.put("object", user.ap_id)
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+
+ assert data["state"] == "pending"
+
+ refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)
+
+ accepts =
+ from(
+ a in Activity,
+ where: fragment("?->>'type' = ?", a.data, "Accept")
+ )
+ |> Repo.all()
+
+ assert length(accepts) == 0
+ end
+
+ test "it works for follow requests when you are already followed, creating a new accept activity" do
+ # This is important because the remote might have the wrong idea about the
+ # current follow status. This can lead to instance A thinking that x@A is
+ # followed by y@B, but B thinks they are not. In this case, the follow can
+ # never go through again because it will never get an Accept.
+ user = insert(:user)
+
+ data =
+ File.read!("test/fixtures/mastodon-follow-activity.json")
+ |> Poison.decode!()
+ |> Map.put("object", user.ap_id)
+
+ {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
+
+ accepts =
+ from(
+ a in Activity,
+ where: fragment("?->>'type' = ?", a.data, "Accept")
+ )
+ |> Repo.all()
+
+ assert length(accepts) == 1
+
+ data =
+ File.read!("test/fixtures/mastodon-follow-activity.json")
+ |> Poison.decode!()
+ |> Map.put("id", String.replace(data["id"], "2", "3"))
+ |> Map.put("object", user.ap_id)
+
+ {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
+
+ accepts =
+ from(
+ a in Activity,
+ where: fragment("?->>'type' = ?", a.data, "Accept")
+ )
+ |> Repo.all()
+
+ assert length(accepts) == 2
+ end
+
+ test "it rejects incoming follow requests from blocked users when deny_follow_blocked is enabled" do
+ Pleroma.Config.put([:user, :deny_follow_blocked], true)
+
+ user = insert(:user)
+ {:ok, target} = User.get_or_fetch("http://mastodon.example.org/users/admin")
+
+ {:ok, user} = User.block(user, target)
+
+ data =
+ File.read!("test/fixtures/mastodon-follow-activity.json")
+ |> Poison.decode!()
+ |> Map.put("object", user.ap_id)
+
+ {:ok, %Activity{data: %{"id" => id}}} = Transmogrifier.handle_incoming(data)
+
+ %Activity{} = activity = Activity.get_by_ap_id(id)
+
+ assert activity.data["state"] == "reject"
+ end
+
+ test "it works for incoming follow requests from hubzilla" do
+ user = insert(:user)
+
+ data =
+ File.read!("test/fixtures/hubzilla-follow-activity.json")
+ |> Poison.decode!()
+ |> Map.put("object", user.ap_id)
+ |> Utils.normalize_params()
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+
+ assert data["actor"] == "https://hubzilla.example.org/channel/kaniini"
+ assert data["type"] == "Follow"
+ assert data["id"] == "https://hubzilla.example.org/channel/kaniini#follows/2"
+ assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
+ end
+ end
+end
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index c24b50f8c..a1f5f6e36 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -11,12 +11,13 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Transmogrifier
- alias Pleroma.Web.ActivityPub.Utils
+ alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OStatus
alias Pleroma.Web.Websub.WebsubClientSubscription
+ import Mock
import Pleroma.Factory
- alias Pleroma.Web.CommonAPI
+ import ExUnit.CaptureLog
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
@@ -30,7 +31,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data =
File.read!("test/fixtures/mastodon-post-activity.json")
|> Poison.decode!()
- |> Map.put("object", activity.data["object"])
+ |> Map.put("object", Object.normalize(activity).data)
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
@@ -46,12 +47,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data["object"]
|> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
- data =
- data
- |> Map.put("object", object)
-
+ data = Map.put(data, "object", object)
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
- returned_object = Object.normalize(returned_activity.data["object"])
+ returned_object = Object.normalize(returned_activity, false)
assert activity =
Activity.get_create_by_object_ap_id(
@@ -61,6 +59,50 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert returned_object.data["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
end
+ test "it does not fetch replied-to activities beyond max_replies_depth" do
+ data =
+ File.read!("test/fixtures/mastodon-post-activity.json")
+ |> Poison.decode!()
+
+ object =
+ data["object"]
+ |> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
+
+ data = Map.put(data, "object", object)
+
+ with_mock Pleroma.Web.Federator,
+ allowed_incoming_reply_depth?: fn _ -> false end do
+ {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
+
+ returned_object = Object.normalize(returned_activity, false)
+
+ refute Activity.get_create_by_object_ap_id(
+ "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
+ )
+
+ assert returned_object.data["inReplyToAtomUri"] ==
+ "https://shitposter.club/notice/2827873"
+ end
+ end
+
+ test "it does not crash if the object in inReplyTo can't be fetched" do
+ data =
+ File.read!("test/fixtures/mastodon-post-activity.json")
+ |> Poison.decode!()
+
+ object =
+ data["object"]
+ |> Map.put("inReplyTo", "https://404.site/whatever")
+
+ data =
+ data
+ |> Map.put("object", object)
+
+ assert capture_log(fn ->
+ {:ok, _returned_activity} = Transmogrifier.handle_incoming(data)
+ end) =~ "[error] Couldn't fetch \"\"https://404.site/whatever\"\", error: nil"
+ end
+
test "it works for incoming notices" do
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
@@ -81,25 +123,27 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["actor"] == "http://mastodon.example.org/users/admin"
- object = Object.normalize(data["object"]).data
- assert object["id"] == "http://mastodon.example.org/users/admin/statuses/99512778738411822"
+ object_data = Object.normalize(data["object"]).data
+
+ assert object_data["id"] ==
+ "http://mastodon.example.org/users/admin/statuses/99512778738411822"
- assert object["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
+ assert object_data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
- assert object["cc"] == [
+ assert object_data["cc"] == [
"http://mastodon.example.org/users/admin/followers",
"http://localtesting.pleroma.lol/users/lain"
]
- assert object["actor"] == "http://mastodon.example.org/users/admin"
- assert object["attributedTo"] == "http://mastodon.example.org/users/admin"
+ assert object_data["actor"] == "http://mastodon.example.org/users/admin"
+ assert object_data["attributedTo"] == "http://mastodon.example.org/users/admin"
- assert object["context"] ==
+ assert object_data["context"] ==
"tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation"
- assert object["sensitive"] == true
+ assert object_data["sensitive"] == true
- user = User.get_cached_by_ap_id(object["actor"])
+ user = User.get_cached_by_ap_id(object_data["actor"])
assert user.info.note_count == 1
end
@@ -113,6 +157,55 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert Enum.at(object.data["tag"], 2) == "moo"
end
+ test "it works for incoming questions" do
+ data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
+
+ {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
+
+ object = Object.normalize(activity)
+
+ assert Enum.all?(object.data["oneOf"], fn choice ->
+ choice["name"] in [
+ "Dunno",
+ "Everyone knows that!",
+ "25 char limit is dumb",
+ "I can't even fit a funny"
+ ]
+ end)
+ end
+
+ test "it rewrites Note votes to Answers and increments vote counters on question activities" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "suya...",
+ "poll" => %{"options" => ["suya", "suya.", "suya.."], "expires_in" => 10}
+ })
+
+ object = Object.normalize(activity)
+
+ data =
+ File.read!("test/fixtures/mastodon-vote.json")
+ |> Poison.decode!()
+ |> Kernel.put_in(["to"], user.ap_id)
+ |> Kernel.put_in(["object", "inReplyTo"], object.data["id"])
+ |> Kernel.put_in(["object", "to"], user.ap_id)
+
+ {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
+ answer_object = Object.normalize(activity)
+ assert answer_object.data["type"] == "Answer"
+ object = Object.get_by_ap_id(object.data["id"])
+
+ assert Enum.any?(
+ object.data["oneOf"],
+ fn
+ %{"name" => "suya..", "replies" => %{"totalItems" => 1}} -> true
+ _ -> false
+ end
+ )
+ end
+
test "it works for incoming notices with contentMap" do
data =
File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Poison.decode!()
@@ -199,59 +292,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert object_data["cc"] == to
end
- test "it works for incoming follow requests" do
- user = insert(:user)
-
- data =
- File.read!("test/fixtures/mastodon-follow-activity.json")
- |> Poison.decode!()
- |> Map.put("object", user.ap_id)
-
- {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
-
- assert data["actor"] == "http://mastodon.example.org/users/admin"
- assert data["type"] == "Follow"
- assert data["id"] == "http://mastodon.example.org/users/admin#follows/2"
- assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
- end
-
- test "it rejects incoming follow requests from blocked users when deny_follow_blocked is enabled" do
- Pleroma.Config.put([:user, :deny_follow_blocked], true)
-
- user = insert(:user)
- {:ok, target} = User.get_or_fetch("http://mastodon.example.org/users/admin")
-
- {:ok, user} = User.block(user, target)
-
- data =
- File.read!("test/fixtures/mastodon-follow-activity.json")
- |> Poison.decode!()
- |> Map.put("object", user.ap_id)
-
- {:ok, %Activity{data: %{"id" => id}}} = Transmogrifier.handle_incoming(data)
-
- %Activity{} = activity = Activity.get_by_ap_id(id)
-
- assert activity.data["state"] == "reject"
- end
-
- test "it works for incoming follow requests from hubzilla" do
- user = insert(:user)
-
- data =
- File.read!("test/fixtures/hubzilla-follow-activity.json")
- |> Poison.decode!()
- |> Map.put("object", user.ap_id)
- |> Utils.normalize_params()
-
- {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
-
- assert data["actor"] == "https://hubzilla.example.org/channel/kaniini"
- assert data["type"] == "Follow"
- assert data["id"] == "https://hubzilla.example.org/channel/kaniini#follows/2"
- assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
- end
-
test "it works for incoming likes" do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
@@ -376,6 +416,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|> Map.put("attributedTo", user.ap_id)
|> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
|> Map.put("cc", [])
+ |> Map.put("id", user.ap_id <> "/activities/12345678")
data = Map.put(data, "object", object)
@@ -399,6 +440,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|> Map.put("attributedTo", user.ap_id)
|> Map.put("to", nil)
|> Map.put("cc", nil)
+ |> Map.put("id", user.ap_id <> "/activities/12345678")
data = Map.put(data, "object", object)
@@ -505,11 +547,38 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data
|> Map.put("object", object)
- :error = Transmogrifier.handle_incoming(data)
+ assert capture_log(fn ->
+ :error = Transmogrifier.handle_incoming(data)
+ end) =~
+ "[error] Could not decode user at fetch http://mastodon.example.org/users/gargron, {:error, {:error, :nxdomain}}"
assert Activity.get_by_id(activity.id)
end
+ test "it works for incoming user deletes" do
+ %{ap_id: ap_id} = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
+
+ data =
+ File.read!("test/fixtures/mastodon-delete-user.json")
+ |> Poison.decode!()
+
+ {:ok, _} = Transmogrifier.handle_incoming(data)
+
+ refute User.get_cached_by_ap_id(ap_id)
+ end
+
+ test "it fails for incoming user deletes with spoofed origin" do
+ %{ap_id: ap_id} = insert(:user)
+
+ data =
+ File.read!("test/fixtures/mastodon-delete-user.json")
+ |> Poison.decode!()
+ |> Map.put("actor", ap_id)
+
+ assert :error == Transmogrifier.handle_incoming(data)
+ assert User.get_cached_by_ap_id(ap_id)
+ end
+
test "it works for incoming unannounces with an existing notice" do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
@@ -531,10 +600,11 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
assert data["type"] == "Undo"
- assert data["object"]["type"] == "Announce"
- assert data["object"]["object"] == activity.data["object"]
+ assert object_data = data["object"]
+ assert object_data["type"] == "Announce"
+ assert object_data["object"] == activity.data["object"]
- assert data["object"]["id"] ==
+ assert object_data["id"] ==
"http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
end
@@ -844,7 +914,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
other_user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity)
message = %{
"@context" => "https://www.w3.org/ns/activitystreams",
@@ -1028,6 +1098,18 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert modified["directMessage"] == true
end
+
+ test "it strips BCC field" do
+ user = insert(:user)
+ {:ok, list} = Pleroma.List.create("foo", user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
+
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
+
+ assert is_nil(modified["bcc"])
+ end
end
describe "user upgrade" do
@@ -1053,6 +1135,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert user.info.ap_enabled
assert user.info.note_count == 1
assert user.follower_address == "https://niu.moe/users/rye/followers"
+ assert user.following_address == "https://niu.moe/users/rye/following"
user = User.get_cached_by_id(user.id)
assert user.info.note_count == 1
@@ -1209,4 +1292,113 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
end
end
+
+ test "Rewrites Answers to Notes" do
+ user = insert(:user)
+
+ {:ok, poll_activity} =
+ CommonAPI.post(user, %{
+ "status" => "suya...",
+ "poll" => %{"options" => ["suya", "suya.", "suya.."], "expires_in" => 10}
+ })
+
+ poll_object = Object.normalize(poll_activity)
+ # TODO: Replace with CommonAPI vote creation when implemented
+ data =
+ File.read!("test/fixtures/mastodon-vote.json")
+ |> Poison.decode!()
+ |> Kernel.put_in(["to"], user.ap_id)
+ |> Kernel.put_in(["object", "inReplyTo"], poll_object.data["id"])
+ |> Kernel.put_in(["object", "to"], user.ap_id)
+
+ {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
+ {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
+
+ assert data["object"]["type"] == "Note"
+ end
+
+ describe "fix_explicit_addressing" do
+ setup do
+ user = insert(:user)
+ [user: user]
+ end
+
+ test "moves non-explicitly mentioned actors to cc", %{user: user} do
+ explicitly_mentioned_actors = [
+ "https://pleroma.gold/users/user1",
+ "https://pleroma.gold/user2"
+ ]
+
+ object = %{
+ "actor" => user.ap_id,
+ "to" => explicitly_mentioned_actors ++ ["https://social.beepboop.ga/users/dirb"],
+ "cc" => [],
+ "tag" =>
+ Enum.map(explicitly_mentioned_actors, fn href ->
+ %{"type" => "Mention", "href" => href}
+ end)
+ }
+
+ fixed_object = Transmogrifier.fix_explicit_addressing(object)
+ assert Enum.all?(explicitly_mentioned_actors, &(&1 in fixed_object["to"]))
+ refute "https://social.beepboop.ga/users/dirb" in fixed_object["to"]
+ assert "https://social.beepboop.ga/users/dirb" in fixed_object["cc"]
+ end
+
+ test "does not move actor's follower collection to cc", %{user: user} do
+ object = %{
+ "actor" => user.ap_id,
+ "to" => [user.follower_address],
+ "cc" => []
+ }
+
+ fixed_object = Transmogrifier.fix_explicit_addressing(object)
+ assert user.follower_address in fixed_object["to"]
+ refute user.follower_address in fixed_object["cc"]
+ end
+
+ test "removes recipient's follower collection from cc", %{user: user} do
+ recipient = insert(:user)
+
+ object = %{
+ "actor" => user.ap_id,
+ "to" => [recipient.ap_id, "https://www.w3.org/ns/activitystreams#Public"],
+ "cc" => [user.follower_address, recipient.follower_address]
+ }
+
+ fixed_object = Transmogrifier.fix_explicit_addressing(object)
+
+ assert user.follower_address in fixed_object["cc"]
+ refute recipient.follower_address in fixed_object["cc"]
+ 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
diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs
index c57fae437..ca5f057a7 100644
--- a/test/web/activity_pub/utils_test.exs
+++ b/test/web/activity_pub/utils_test.exs
@@ -1,6 +1,12 @@
+# 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.UtilsTest do
use Pleroma.DataCase
alias Pleroma.Activity
+ alias Pleroma.Object
+ alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
@@ -204,4 +210,93 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
]
}
end
+
+ describe "get_existing_votes" do
+ test "fetches existing votes" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "How do I pronounce LaTeX?",
+ "poll" => %{
+ "options" => ["laytekh", "lahtekh", "latex"],
+ "expires_in" => 20,
+ "multiple" => true
+ }
+ })
+
+ object = Object.normalize(activity)
+ {:ok, votes, object} = CommonAPI.vote(other_user, object, [0, 1])
+ assert Enum.sort(Utils.get_existing_votes(other_user.ap_id, object)) == Enum.sort(votes)
+ end
+
+ test "fetches only Create activities" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Are we living in a society?",
+ "poll" => %{
+ "options" => ["yes", "no"],
+ "expires_in" => 20
+ }
+ })
+
+ object = Object.normalize(activity)
+ {:ok, [vote], object} = CommonAPI.vote(other_user, object, [0])
+ vote_object = Object.normalize(vote)
+ {:ok, _activity, _object} = ActivityPub.like(user, vote_object)
+ [fetched_vote] = Utils.get_existing_votes(other_user.ap_id, object)
+ assert fetched_vote.id == vote.id
+ end
+ end
+
+ describe "update_follow_state_for_all/2" do
+ test "updates the state of all Follow activities with the same actor and object" do
+ user = insert(:user, info: %{locked: true})
+ follower = insert(:user)
+
+ {:ok, follow_activity} = ActivityPub.follow(follower, user)
+ {:ok, follow_activity_two} = ActivityPub.follow(follower, user)
+
+ data =
+ follow_activity_two.data
+ |> Map.put("state", "accept")
+
+ cng = Ecto.Changeset.change(follow_activity_two, data: data)
+
+ {:ok, follow_activity_two} = Repo.update(cng)
+
+ {:ok, follow_activity_two} =
+ Utils.update_follow_state_for_all(follow_activity_two, "accept")
+
+ assert Repo.get(Activity, follow_activity.id).data["state"] == "accept"
+ assert Repo.get(Activity, follow_activity_two.id).data["state"] == "accept"
+ end
+ end
+
+ describe "update_follow_state/2" do
+ test "updates the state of the given follow activity" do
+ user = insert(:user, info: %{locked: true})
+ follower = insert(:user)
+
+ {:ok, follow_activity} = ActivityPub.follow(follower, user)
+ {:ok, follow_activity_two} = ActivityPub.follow(follower, user)
+
+ data =
+ follow_activity_two.data
+ |> Map.put("state", "accept")
+
+ cng = Ecto.Changeset.change(follow_activity_two, data: data)
+
+ {:ok, follow_activity_two} = Repo.update(cng)
+
+ {:ok, follow_activity_two} = Utils.update_follow_state(follow_activity_two, "reject")
+
+ assert Repo.get(Activity, follow_activity.id).data["state"] == "pending"
+ assert Repo.get(Activity, follow_activity_two.id).data["state"] == "reject"
+ end
+ end
end
diff --git a/test/web/activity_pub/views/object_view_test.exs b/test/web/activity_pub/views/object_view_test.exs
index d939fc5a7..13447dc29 100644
--- a/test/web/activity_pub/views/object_view_test.exs
+++ b/test/web/activity_pub/views/object_view_test.exs
@@ -1,7 +1,12 @@
+# 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.ObjectViewTest do
use Pleroma.DataCase
import Pleroma.Factory
+ alias Pleroma.Object
alias Pleroma.Web.ActivityPub.ObjectView
alias Pleroma.Web.CommonAPI
@@ -19,19 +24,21 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
test "renders a note activity" do
note = insert(:note_activity)
+ object = Object.normalize(note)
result = ObjectView.render("object.json", %{object: note})
assert result["id"] == note.data["id"]
assert result["to"] == note.data["to"]
assert result["object"]["type"] == "Note"
- assert result["object"]["content"] == note.data["object"]["content"]
+ assert result["object"]["content"] == object.data["content"]
assert result["type"] == "Create"
assert result["@context"]
end
test "renders a like activity" do
note = insert(:note_activity)
+ object = Object.normalize(note)
user = insert(:user)
{:ok, like_activity, _} = CommonAPI.favorite(note.id, user)
@@ -39,12 +46,13 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
result = ObjectView.render("object.json", %{object: like_activity})
assert result["id"] == like_activity.data["id"]
- assert result["object"] == note.data["object"]["id"]
+ assert result["object"] == object.data["id"]
assert result["type"] == "Like"
end
test "renders an announce activity" do
note = insert(:note_activity)
+ object = Object.normalize(note)
user = insert(:user)
{:ok, announce_activity, _} = CommonAPI.repeat(note.id, user)
@@ -52,7 +60,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
result = ObjectView.render("object.json", %{object: announce_activity})
assert result["id"] == announce_activity.data["id"]
- assert result["object"] == note.data["object"]["id"]
+ assert result["object"] == object.data["id"]
assert result["type"] == "Announce"
end
end
diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs
index e6483db8b..86254117f 100644
--- a/test/web/activity_pub/views/user_view_test.exs
+++ b/test/web/activity_pub/views/user_view_test.exs
@@ -1,9 +1,14 @@
+# 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.UserViewTest do
use Pleroma.DataCase
import Pleroma.Factory
alias Pleroma.User
alias Pleroma.Web.ActivityPub.UserView
+ alias Pleroma.Web.CommonAPI
test "Renders a user, including the public key" do
user = insert(:user)
@@ -78,4 +83,28 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
refute result["endpoints"]["oauthTokenEndpoint"]
end
end
+
+ describe "followers" do
+ test "sets totalItems to zero when followers are hidden" do
+ user = insert(:user)
+ other_user = insert(:user)
+ {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
+ assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
+ info = Map.put(user.info, :hide_followers, true)
+ user = Map.put(user, :info, info)
+ assert %{"totalItems" => 0} = UserView.render("followers.json", %{user: user})
+ end
+ end
+
+ describe "following" do
+ test "sets totalItems to zero when follows are hidden" do
+ user = insert(:user)
+ other_user = insert(:user)
+ {:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
+ assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
+ info = Map.put(user.info, :hide_follows, true)
+ user = Map.put(user, :info, info)
+ assert %{"totalItems" => 0} = UserView.render("following.json", %{user: user})
+ end
+ end
end
diff --git a/test/web/activity_pub/visibilty_test.exs b/test/web/activity_pub/visibilty_test.exs
index e2584f635..b62a89e68 100644
--- a/test/web/activity_pub/visibilty_test.exs
+++ b/test/web/activity_pub/visibilty_test.exs
@@ -1,6 +1,11 @@
+# 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.VisibilityTest do
use Pleroma.DataCase
+ alias Pleroma.Activity
alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
@@ -11,6 +16,9 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
following = insert(:user)
unrelated = insert(:user)
{:ok, following} = Pleroma.User.follow(following, user)
+ {:ok, list} = Pleroma.List.create("foo", user)
+
+ Pleroma.List.follow(list, unrelated)
{:ok, public} =
CommonAPI.post(user, %{"status" => "@#{mentioned.nickname}", "visibility" => "public"})
@@ -24,6 +32,12 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
{:ok, unlisted} =
CommonAPI.post(user, %{"status" => "@#{mentioned.nickname}", "visibility" => "unlisted"})
+ {:ok, list} =
+ CommonAPI.post(user, %{
+ "status" => "@#{mentioned.nickname}",
+ "visibility" => "list:#{list.id}"
+ })
+
%{
public: public,
private: private,
@@ -32,29 +46,65 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
user: user,
mentioned: mentioned,
following: following,
- unrelated: unrelated
+ unrelated: unrelated,
+ list: list
}
end
- test "is_direct?", %{public: public, private: private, direct: direct, unlisted: unlisted} do
+ test "is_direct?", %{
+ public: public,
+ private: private,
+ direct: direct,
+ unlisted: unlisted,
+ list: list
+ } do
assert Visibility.is_direct?(direct)
refute Visibility.is_direct?(public)
refute Visibility.is_direct?(private)
refute Visibility.is_direct?(unlisted)
+ assert Visibility.is_direct?(list)
end
- test "is_public?", %{public: public, private: private, direct: direct, unlisted: unlisted} do
+ test "is_public?", %{
+ public: public,
+ private: private,
+ direct: direct,
+ unlisted: unlisted,
+ list: list
+ } do
refute Visibility.is_public?(direct)
assert Visibility.is_public?(public)
refute Visibility.is_public?(private)
assert Visibility.is_public?(unlisted)
+ refute Visibility.is_public?(list)
end
- test "is_private?", %{public: public, private: private, direct: direct, unlisted: unlisted} do
+ test "is_private?", %{
+ public: public,
+ private: private,
+ direct: direct,
+ unlisted: unlisted,
+ list: list
+ } do
refute Visibility.is_private?(direct)
refute Visibility.is_private?(public)
assert Visibility.is_private?(private)
refute Visibility.is_private?(unlisted)
+ refute Visibility.is_private?(list)
+ end
+
+ test "is_list?", %{
+ public: public,
+ private: private,
+ direct: direct,
+ unlisted: unlisted,
+ list: list
+ } do
+ refute Visibility.is_list?(direct)
+ refute Visibility.is_list?(public)
+ refute Visibility.is_list?(private)
+ refute Visibility.is_list?(unlisted)
+ assert Visibility.is_list?(list)
end
test "visible_for_user?", %{
@@ -65,7 +115,8 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
user: user,
mentioned: mentioned,
following: following,
- unrelated: unrelated
+ unrelated: unrelated,
+ list: list
} do
# All visible to author
@@ -73,6 +124,7 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
assert Visibility.visible_for_user?(private, user)
assert Visibility.visible_for_user?(unlisted, user)
assert Visibility.visible_for_user?(direct, user)
+ assert Visibility.visible_for_user?(list, user)
# All visible to a mentioned user
@@ -80,6 +132,7 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
assert Visibility.visible_for_user?(private, mentioned)
assert Visibility.visible_for_user?(unlisted, mentioned)
assert Visibility.visible_for_user?(direct, mentioned)
+ assert Visibility.visible_for_user?(list, mentioned)
# DM not visible for just follower
@@ -87,6 +140,7 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
assert Visibility.visible_for_user?(private, following)
assert Visibility.visible_for_user?(unlisted, following)
refute Visibility.visible_for_user?(direct, following)
+ refute Visibility.visible_for_user?(list, following)
# Public and unlisted visible for unrelated user
@@ -94,6 +148,9 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
assert Visibility.visible_for_user?(unlisted, unrelated)
refute Visibility.visible_for_user?(private, unrelated)
refute Visibility.visible_for_user?(direct, unrelated)
+
+ # Visible for a list member
+ assert Visibility.visible_for_user?(list, unrelated)
end
test "doesn't die when the user doesn't exist",
@@ -110,11 +167,63 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
public: public,
private: private,
direct: direct,
- unlisted: unlisted
+ unlisted: unlisted,
+ list: list
} do
assert Visibility.get_visibility(public) == "public"
assert Visibility.get_visibility(private) == "private"
assert Visibility.get_visibility(direct) == "direct"
assert Visibility.get_visibility(unlisted) == "unlisted"
+ assert Visibility.get_visibility(list) == "list"
+ end
+
+ test "get_visibility with directMessage flag" do
+ assert Visibility.get_visibility(%{data: %{"directMessage" => true}}) == "direct"
+ end
+
+ test "get_visibility with listMessage flag" do
+ assert Visibility.get_visibility(%{data: %{"listMessage" => ""}}) == "list"
+ end
+
+ describe "entire_thread_visible_for_user?/2" do
+ test "returns false if not found activity", %{user: user} do
+ refute Visibility.entire_thread_visible_for_user?(%Activity{}, user)
+ end
+
+ test "returns true if activity hasn't 'Create' type", %{user: user} do
+ activity = insert(:like_activity)
+ assert Visibility.entire_thread_visible_for_user?(activity, user)
+ end
+
+ test "returns false when invalid recipients", %{user: user} do
+ author = insert(:user)
+
+ activity =
+ insert(:note_activity,
+ note:
+ insert(:note,
+ user: author,
+ data: %{"to" => ["test-user"]}
+ )
+ )
+
+ refute Visibility.entire_thread_visible_for_user?(activity, user)
+ end
+
+ test "returns true if user following to author" do
+ author = insert(:user)
+ user = insert(:user, following: [author.ap_id])
+
+ activity =
+ insert(:note_activity,
+ note:
+ insert(:note,
+ user: author,
+ data: %{"to" => [user.ap_id]}
+ )
+ )
+
+ assert Visibility.entire_thread_visible_for_user?(activity, user)
+ end
end
end
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 43dcf945a..ee48b752c 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -6,9 +6,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
use Pleroma.Web.ConnCase
alias Pleroma.Activity
+ alias Pleroma.HTML
alias Pleroma.User
alias Pleroma.UserInviteToken
alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.MediaProxy
import Pleroma.Factory
describe "/api/pleroma/admin/users" do
@@ -58,7 +60,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"local" => true,
"nickname" => user.nickname,
"roles" => %{"admin" => false, "moderator" => false},
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(user) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(user.name || user.nickname)
}
assert expected == json_response(conn, 200)
@@ -445,7 +449,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => admin.nickname,
"roles" => %{"admin" => true, "moderator" => false},
"local" => true,
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(admin) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(admin.name || admin.nickname)
},
%{
"deactivated" => user.info.deactivated,
@@ -453,7 +459,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => user.nickname,
"roles" => %{"admin" => false, "moderator" => false},
"local" => false,
- "tags" => ["foo", "bar"]
+ "tags" => ["foo", "bar"],
+ "avatar" => User.avatar_url(user) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(user.name || user.nickname)
}
]
|> Enum.sort_by(& &1["nickname"])
@@ -492,7 +500,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => user.nickname,
"roles" => %{"admin" => false, "moderator" => false},
"local" => true,
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(user) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(user.name || user.nickname)
}
]
}
@@ -514,7 +524,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => user.nickname,
"roles" => %{"admin" => false, "moderator" => false},
"local" => true,
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(user) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(user.name || user.nickname)
}
]
}
@@ -536,7 +548,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => user.nickname,
"roles" => %{"admin" => false, "moderator" => false},
"local" => true,
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(user) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(user.name || user.nickname)
}
]
}
@@ -558,7 +572,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => user.nickname,
"roles" => %{"admin" => false, "moderator" => false},
"local" => true,
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(user) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(user.name || user.nickname)
}
]
}
@@ -580,7 +596,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => user.nickname,
"roles" => %{"admin" => false, "moderator" => false},
"local" => true,
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(user) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(user.name || user.nickname)
}
]
}
@@ -602,7 +620,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => user.nickname,
"roles" => %{"admin" => false, "moderator" => false},
"local" => true,
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(user) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(user.name || user.nickname)
}
]
}
@@ -619,7 +639,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => user2.nickname,
"roles" => %{"admin" => false, "moderator" => false},
"local" => true,
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(user2) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(user2.name || user2.nickname)
}
]
}
@@ -646,7 +668,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => user.nickname,
"roles" => %{"admin" => false, "moderator" => false},
"local" => true,
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(user) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(user.name || user.nickname)
}
]
}
@@ -671,7 +695,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => user.nickname,
"roles" => %{"admin" => false, "moderator" => false},
"local" => true,
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(user) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(user.name || user.nickname)
},
%{
"deactivated" => admin.info.deactivated,
@@ -679,7 +705,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => admin.nickname,
"roles" => %{"admin" => true, "moderator" => false},
"local" => true,
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(admin) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(admin.name || admin.nickname)
},
%{
"deactivated" => false,
@@ -687,7 +715,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"local" => true,
"nickname" => old_admin.nickname,
"roles" => %{"admin" => true, "moderator" => false},
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(old_admin) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(old_admin.name || old_admin.nickname)
}
]
|> Enum.sort_by(& &1["nickname"])
@@ -714,7 +744,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => admin.nickname,
"roles" => %{"admin" => true, "moderator" => false},
"local" => admin.local,
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(admin) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(admin.name || admin.nickname)
},
%{
"deactivated" => false,
@@ -722,7 +754,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => second_admin.nickname,
"roles" => %{"admin" => true, "moderator" => false},
"local" => second_admin.local,
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(second_admin) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(second_admin.name || second_admin.nickname)
}
]
|> Enum.sort_by(& &1["nickname"])
@@ -751,7 +785,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => moderator.nickname,
"roles" => %{"admin" => false, "moderator" => true},
"local" => moderator.local,
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(moderator) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(moderator.name || moderator.nickname)
}
]
}
@@ -773,7 +809,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => user1.nickname,
"roles" => %{"admin" => false, "moderator" => false},
"local" => user1.local,
- "tags" => ["first"]
+ "tags" => ["first"],
+ "avatar" => User.avatar_url(user1) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(user1.name || user1.nickname)
},
%{
"deactivated" => false,
@@ -781,7 +819,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => user2.nickname,
"roles" => %{"admin" => false, "moderator" => false},
"local" => user2.local,
- "tags" => ["second"]
+ "tags" => ["second"],
+ "avatar" => User.avatar_url(user2) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(user2.name || user2.nickname)
}
]
|> Enum.sort_by(& &1["nickname"])
@@ -815,7 +855,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => user.nickname,
"roles" => %{"admin" => false, "moderator" => false},
"local" => user.local,
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(user) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(user.name || user.nickname)
}
]
}
@@ -838,7 +880,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => user.nickname,
"roles" => %{"admin" => false, "moderator" => false},
"local" => true,
- "tags" => []
+ "tags" => [],
+ "avatar" => User.avatar_url(user) |> MediaProxy.url(),
+ "display_name" => HTML.strip_tags(user.name || user.nickname)
}
end
@@ -1190,7 +1234,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
recipients = Enum.map(response["mentions"], & &1["username"])
- assert conn.assigns[:user].nickname in recipients
assert reporter.nickname in recipients
assert response["content"] == "I will check it out"
assert response["visibility"] == "direct"
@@ -1292,4 +1335,578 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert json_response(conn, :bad_request) == "Could not delete"
end
end
+
+ describe "GET /api/pleroma/admin/config" do
+ setup %{conn: conn} do
+ admin = insert(:user, info: %{is_admin: true})
+
+ %{conn: assign(conn, :user, admin)}
+ end
+
+ test "without any settings in db", %{conn: conn} do
+ conn = get(conn, "/api/pleroma/admin/config")
+
+ assert json_response(conn, 200) == %{"configs" => []}
+ end
+
+ test "with settings in db", %{conn: conn} do
+ config1 = insert(:config)
+ config2 = insert(:config)
+
+ conn = get(conn, "/api/pleroma/admin/config")
+
+ %{
+ "configs" => [
+ %{
+ "key" => key1,
+ "value" => _
+ },
+ %{
+ "key" => key2,
+ "value" => _
+ }
+ ]
+ } = json_response(conn, 200)
+
+ assert key1 == config1.key
+ assert key2 == config2.key
+ end
+ end
+
+ describe "POST /api/pleroma/admin/config" do
+ setup %{conn: conn} do
+ admin = insert(:user, info: %{is_admin: true})
+
+ temp_file = "config/test.exported_from_db.secret.exs"
+
+ on_exit(fn ->
+ Application.delete_env(:pleroma, :key1)
+ Application.delete_env(:pleroma, :key2)
+ Application.delete_env(:pleroma, :key3)
+ Application.delete_env(:pleroma, :key4)
+ Application.delete_env(:pleroma, :keyaa1)
+ Application.delete_env(:pleroma, :keyaa2)
+ Application.delete_env(:pleroma, Pleroma.Web.Endpoint.NotReal)
+ Application.delete_env(:pleroma, Pleroma.Captcha.NotReal)
+ :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
+
+ test "create new config setting in db", %{conn: conn} do
+ conn =
+ post(conn, "/api/pleroma/admin/config", %{
+ configs: [
+ %{group: "pleroma", key: "key1", value: "value1"},
+ %{
+ group: "ueberauth",
+ key: "Ueberauth.Strategy.Twitter.OAuth",
+ value: [%{"tuple" => [":consumer_secret", "aaaa"]}]
+ },
+ %{
+ group: "pleroma",
+ key: "key2",
+ value: %{
+ ":nested_1" => "nested_value1",
+ ":nested_2" => [
+ %{":nested_22" => "nested_value222"},
+ %{":nested_33" => %{":nested_44" => "nested_444"}}
+ ]
+ }
+ },
+ %{
+ group: "pleroma",
+ key: "key3",
+ value: [
+ %{"nested_3" => ":nested_3", "nested_33" => "nested_33"},
+ %{"nested_4" => true}
+ ]
+ },
+ %{
+ group: "pleroma",
+ key: "key4",
+ value: %{":nested_5" => ":upload", "endpoint" => "https://example.com"}
+ },
+ %{
+ group: "idna",
+ key: "key5",
+ value: %{"tuple" => ["string", "Pleroma.Captcha.NotReal", []]}
+ }
+ ]
+ })
+
+ assert json_response(conn, 200) == %{
+ "configs" => [
+ %{
+ "group" => "pleroma",
+ "key" => "key1",
+ "value" => "value1"
+ },
+ %{
+ "group" => "ueberauth",
+ "key" => "Ueberauth.Strategy.Twitter.OAuth",
+ "value" => [%{"tuple" => [":consumer_secret", "aaaa"]}]
+ },
+ %{
+ "group" => "pleroma",
+ "key" => "key2",
+ "value" => %{
+ ":nested_1" => "nested_value1",
+ ":nested_2" => [
+ %{":nested_22" => "nested_value222"},
+ %{":nested_33" => %{":nested_44" => "nested_444"}}
+ ]
+ }
+ },
+ %{
+ "group" => "pleroma",
+ "key" => "key3",
+ "value" => [
+ %{"nested_3" => ":nested_3", "nested_33" => "nested_33"},
+ %{"nested_4" => true}
+ ]
+ },
+ %{
+ "group" => "pleroma",
+ "key" => "key4",
+ "value" => %{"endpoint" => "https://example.com", ":nested_5" => ":upload"}
+ },
+ %{
+ "group" => "idna",
+ "key" => "key5",
+ "value" => %{"tuple" => ["string", "Pleroma.Captcha.NotReal", []]}
+ }
+ ]
+ }
+
+ assert Application.get_env(:pleroma, :key1) == "value1"
+
+ assert Application.get_env(:pleroma, :key2) == %{
+ nested_1: "nested_value1",
+ nested_2: [
+ %{nested_22: "nested_value222"},
+ %{nested_33: %{nested_44: "nested_444"}}
+ ]
+ }
+
+ assert Application.get_env(:pleroma, :key3) == [
+ %{"nested_3" => :nested_3, "nested_33" => "nested_33"},
+ %{"nested_4" => true}
+ ]
+
+ assert Application.get_env(:pleroma, :key4) == %{
+ "endpoint" => "https://example.com",
+ nested_5: :upload
+ }
+
+ assert Application.get_env(:idna, :key5) == {"string", Pleroma.Captcha.NotReal, []}
+ end
+
+ test "update config setting & delete", %{conn: conn} do
+ config1 = insert(:config, key: "keyaa1")
+ config2 = insert(:config, key: "keyaa2")
+
+ insert(:config,
+ group: "ueberauth",
+ key: "Ueberauth.Strategy.Microsoft.OAuth",
+ value: :erlang.term_to_binary([])
+ )
+
+ conn =
+ post(conn, "/api/pleroma/admin/config", %{
+ configs: [
+ %{group: config1.group, key: config1.key, value: "another_value"},
+ %{group: config2.group, key: config2.key, delete: "true"},
+ %{
+ group: "ueberauth",
+ key: "Ueberauth.Strategy.Microsoft.OAuth",
+ delete: "true"
+ }
+ ]
+ })
+
+ assert json_response(conn, 200) == %{
+ "configs" => [
+ %{
+ "group" => "pleroma",
+ "key" => config1.key,
+ "value" => "another_value"
+ }
+ ]
+ }
+
+ assert Application.get_env(:pleroma, :keyaa1) == "another_value"
+ refute Application.get_env(:pleroma, :keyaa2)
+ end
+
+ test "common config example", %{conn: conn} do
+ conn =
+ post(conn, "/api/pleroma/admin/config", %{
+ configs: [
+ %{
+ "group" => "pleroma",
+ "key" => "Pleroma.Captcha.NotReal",
+ "value" => [
+ %{"tuple" => [":enabled", false]},
+ %{"tuple" => [":method", "Pleroma.Captcha.Kocaptcha"]},
+ %{"tuple" => [":seconds_valid", 60]},
+ %{"tuple" => [":path", ""]},
+ %{"tuple" => [":key1", nil]}
+ ]
+ }
+ ]
+ })
+
+ assert json_response(conn, 200) == %{
+ "configs" => [
+ %{
+ "group" => "pleroma",
+ "key" => "Pleroma.Captcha.NotReal",
+ "value" => [
+ %{"tuple" => [":enabled", false]},
+ %{"tuple" => [":method", "Pleroma.Captcha.Kocaptcha"]},
+ %{"tuple" => [":seconds_valid", 60]},
+ %{"tuple" => [":path", ""]},
+ %{"tuple" => [":key1", nil]}
+ ]
+ }
+ ]
+ }
+ end
+
+ test "tuples with more than two values", %{conn: conn} do
+ conn =
+ post(conn, "/api/pleroma/admin/config", %{
+ configs: [
+ %{
+ "group" => "pleroma",
+ "key" => "Pleroma.Web.Endpoint.NotReal",
+ "value" => [
+ %{
+ "tuple" => [
+ ":http",
+ [
+ %{
+ "tuple" => [
+ ":key2",
+ [
+ %{
+ "tuple" => [
+ ":_",
+ [
+ %{
+ "tuple" => [
+ "/api/v1/streaming",
+ "Pleroma.Web.MastodonAPI.WebsocketHandler",
+ []
+ ]
+ },
+ %{
+ "tuple" => [
+ "/websocket",
+ "Phoenix.Endpoint.CowboyWebSocket",
+ %{
+ "tuple" => [
+ "Phoenix.Transports.WebSocket",
+ %{
+ "tuple" => [
+ "Pleroma.Web.Endpoint",
+ "Pleroma.Web.UserSocket",
+ []
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ %{
+ "tuple" => [
+ ":_",
+ "Phoenix.Endpoint.Cowboy2Handler",
+ %{"tuple" => ["Pleroma.Web.Endpoint", []]}
+ ]
+ }
+ ]
+ ]
+ }
+ ]
+ ]
+ }
+ ]
+ ]
+ }
+ ]
+ }
+ ]
+ })
+
+ assert json_response(conn, 200) == %{
+ "configs" => [
+ %{
+ "group" => "pleroma",
+ "key" => "Pleroma.Web.Endpoint.NotReal",
+ "value" => [
+ %{
+ "tuple" => [
+ ":http",
+ [
+ %{
+ "tuple" => [
+ ":key2",
+ [
+ %{
+ "tuple" => [
+ ":_",
+ [
+ %{
+ "tuple" => [
+ "/api/v1/streaming",
+ "Pleroma.Web.MastodonAPI.WebsocketHandler",
+ []
+ ]
+ },
+ %{
+ "tuple" => [
+ "/websocket",
+ "Phoenix.Endpoint.CowboyWebSocket",
+ %{
+ "tuple" => [
+ "Phoenix.Transports.WebSocket",
+ %{
+ "tuple" => [
+ "Pleroma.Web.Endpoint",
+ "Pleroma.Web.UserSocket",
+ []
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ %{
+ "tuple" => [
+ ":_",
+ "Phoenix.Endpoint.Cowboy2Handler",
+ %{"tuple" => ["Pleroma.Web.Endpoint", []]}
+ ]
+ }
+ ]
+ ]
+ }
+ ]
+ ]
+ }
+ ]
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ end
+
+ test "settings with nesting map", %{conn: conn} do
+ conn =
+ post(conn, "/api/pleroma/admin/config", %{
+ configs: [
+ %{
+ "group" => "pleroma",
+ "key" => ":key1",
+ "value" => [
+ %{"tuple" => [":key2", "some_val"]},
+ %{
+ "tuple" => [
+ ":key3",
+ %{
+ ":max_options" => 20,
+ ":max_option_chars" => 200,
+ ":min_expiration" => 0,
+ ":max_expiration" => 31_536_000,
+ "nested" => %{
+ ":max_options" => 20,
+ ":max_option_chars" => 200,
+ ":min_expiration" => 0,
+ ":max_expiration" => 31_536_000
+ }
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ })
+
+ assert json_response(conn, 200) ==
+ %{
+ "configs" => [
+ %{
+ "group" => "pleroma",
+ "key" => ":key1",
+ "value" => [
+ %{"tuple" => [":key2", "some_val"]},
+ %{
+ "tuple" => [
+ ":key3",
+ %{
+ ":max_expiration" => 31_536_000,
+ ":max_option_chars" => 200,
+ ":max_options" => 20,
+ ":min_expiration" => 0,
+ "nested" => %{
+ ":max_expiration" => 31_536_000,
+ ":max_option_chars" => 200,
+ ":max_options" => 20,
+ ":min_expiration" => 0
+ }
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ end
+
+ test "value as map", %{conn: conn} do
+ conn =
+ post(conn, "/api/pleroma/admin/config", %{
+ configs: [
+ %{
+ "group" => "pleroma",
+ "key" => ":key1",
+ "value" => %{"key" => "some_val"}
+ }
+ ]
+ })
+
+ assert json_response(conn, 200) ==
+ %{
+ "configs" => [
+ %{
+ "group" => "pleroma",
+ "key" => ":key1",
+ "value" => %{"key" => "some_val"}
+ }
+ ]
+ }
+ end
+
+ test "dispatch setting", %{conn: conn} do
+ conn =
+ post(conn, "/api/pleroma/admin/config", %{
+ configs: [
+ %{
+ "group" => "pleroma",
+ "key" => "Pleroma.Web.Endpoint.NotReal",
+ "value" => [
+ %{
+ "tuple" => [
+ ":http",
+ [
+ %{"tuple" => [":ip", %{"tuple" => [127, 0, 0, 1]}]},
+ %{"tuple" => [":dispatch", ["{:_,
+ [
+ {\"/api/v1/streaming\", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
+ {\"/websocket\", Phoenix.Endpoint.CowboyWebSocket,
+ {Phoenix.Transports.WebSocket,
+ {Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, [path: \"/websocket\"]}}},
+ {:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}
+ ]}"]]}
+ ]
+ ]
+ }
+ ]
+ }
+ ]
+ })
+
+ dispatch_string =
+ "{:_, [{\"/api/v1/streaming\", Pleroma.Web.MastodonAPI.WebsocketHandler, []}, " <>
+ "{\"/websocket\", Phoenix.Endpoint.CowboyWebSocket, {Phoenix.Transports.WebSocket, " <>
+ "{Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, [path: \"/websocket\"]}}}, " <>
+ "{:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}]}"
+
+ assert json_response(conn, 200) == %{
+ "configs" => [
+ %{
+ "group" => "pleroma",
+ "key" => "Pleroma.Web.Endpoint.NotReal",
+ "value" => [
+ %{
+ "tuple" => [
+ ":http",
+ [
+ %{"tuple" => [":ip", %{"tuple" => [127, 0, 0, 1]}]},
+ %{
+ "tuple" => [
+ ":dispatch",
+ [
+ dispatch_string
+ ]
+ ]
+ }
+ ]
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ end
+
+ test "queues key as atom", %{conn: conn} do
+ conn =
+ post(conn, "/api/pleroma/admin/config", %{
+ configs: [
+ %{
+ "group" => "pleroma_job_queue",
+ "key" => ":queues",
+ "value" => [
+ %{"tuple" => [":federator_incoming", 50]},
+ %{"tuple" => [":federator_outgoing", 50]},
+ %{"tuple" => [":web_push", 50]},
+ %{"tuple" => [":mailer", 10]},
+ %{"tuple" => [":transmogrifier", 20]},
+ %{"tuple" => [":scheduled_activities", 10]},
+ %{"tuple" => [":background", 5]}
+ ]
+ }
+ ]
+ })
+
+ assert json_response(conn, 200) == %{
+ "configs" => [
+ %{
+ "group" => "pleroma_job_queue",
+ "key" => ":queues",
+ "value" => [
+ %{"tuple" => [":federator_incoming", 50]},
+ %{"tuple" => [":federator_outgoing", 50]},
+ %{"tuple" => [":web_push", 50]},
+ %{"tuple" => [":mailer", 10]},
+ %{"tuple" => [":transmogrifier", 20]},
+ %{"tuple" => [":scheduled_activities", 10]},
+ %{"tuple" => [":background", 5]}
+ ]
+ }
+ ]
+ }
+ end
+ end
+end
+
+# Needed for testing
+defmodule Pleroma.Web.Endpoint.NotReal do
+end
+
+defmodule Pleroma.Captcha.NotReal do
end
diff --git a/test/web/admin_api/config_test.exs b/test/web/admin_api/config_test.exs
new file mode 100644
index 000000000..d41666ef3
--- /dev/null
+++ b/test/web/admin_api/config_test.exs
@@ -0,0 +1,465 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.AdminAPI.ConfigTest do
+ use Pleroma.DataCase, async: true
+ import Pleroma.Factory
+ alias Pleroma.Web.AdminAPI.Config
+
+ test "get_by_key/1" do
+ config = insert(:config)
+ insert(:config)
+
+ assert config == Config.get_by_params(%{group: config.group, key: config.key})
+ end
+
+ test "create/1" do
+ {:ok, config} = Config.create(%{group: "pleroma", key: "some_key", value: "some_value"})
+ assert config == Config.get_by_params(%{group: "pleroma", key: "some_key"})
+ end
+
+ test "update/1" do
+ config = insert(:config)
+ {:ok, updated} = Config.update(config, %{value: "some_value"})
+ loaded = Config.get_by_params(%{group: config.group, key: config.key})
+ assert loaded == updated
+ end
+
+ test "update_or_create/1" do
+ config = insert(:config)
+ key2 = "another_key"
+
+ params = [
+ %{group: "pleroma", key: key2, value: "another_value"},
+ %{group: config.group, key: config.key, value: "new_value"}
+ ]
+
+ assert Repo.all(Config) |> length() == 1
+
+ Enum.each(params, &Config.update_or_create(&1))
+
+ assert Repo.all(Config) |> length() == 2
+
+ config1 = Config.get_by_params(%{group: config.group, key: config.key})
+ config2 = Config.get_by_params(%{group: "pleroma", key: key2})
+
+ assert config1.value == Config.transform("new_value")
+ assert config2.value == Config.transform("another_value")
+ end
+
+ test "delete/1" do
+ config = insert(:config)
+ {:ok, _} = Config.delete(%{key: config.key, group: config.group})
+ refute Config.get_by_params(%{key: config.key, group: config.group})
+ end
+
+ describe "transform/1" do
+ test "string" do
+ binary = Config.transform("value as string")
+ assert binary == :erlang.term_to_binary("value as string")
+ assert Config.from_binary(binary) == "value as string"
+ end
+
+ test "boolean" do
+ binary = Config.transform(false)
+ assert binary == :erlang.term_to_binary(false)
+ assert Config.from_binary(binary) == false
+ end
+
+ test "nil" do
+ binary = Config.transform(nil)
+ assert binary == :erlang.term_to_binary(nil)
+ assert Config.from_binary(binary) == nil
+ end
+
+ test "integer" do
+ binary = Config.transform(150)
+ assert binary == :erlang.term_to_binary(150)
+ assert Config.from_binary(binary) == 150
+ end
+
+ test "atom" do
+ binary = Config.transform(":atom")
+ assert binary == :erlang.term_to_binary(:atom)
+ assert Config.from_binary(binary) == :atom
+ end
+
+ test "pleroma module" do
+ binary = Config.transform("Pleroma.Bookmark")
+ assert binary == :erlang.term_to_binary(Pleroma.Bookmark)
+ assert Config.from_binary(binary) == Pleroma.Bookmark
+ end
+
+ test "phoenix module" do
+ binary = Config.transform("Phoenix.Socket.V1.JSONSerializer")
+ assert binary == :erlang.term_to_binary(Phoenix.Socket.V1.JSONSerializer)
+ assert Config.from_binary(binary) == Phoenix.Socket.V1.JSONSerializer
+ end
+
+ test "sigil" do
+ binary = Config.transform("~r/comp[lL][aA][iI][nN]er/")
+ assert binary == :erlang.term_to_binary(~r/comp[lL][aA][iI][nN]er/)
+ assert Config.from_binary(binary) == ~r/comp[lL][aA][iI][nN]er/
+ end
+
+ test "2 child tuple" do
+ binary = Config.transform(%{"tuple" => ["v1", ":v2"]})
+ assert binary == :erlang.term_to_binary({"v1", :v2})
+ assert Config.from_binary(binary) == {"v1", :v2}
+ end
+
+ test "tuple with n childs" do
+ binary =
+ Config.transform(%{
+ "tuple" => [
+ "v1",
+ ":v2",
+ "Pleroma.Bookmark",
+ 150,
+ false,
+ "Phoenix.Socket.V1.JSONSerializer"
+ ]
+ })
+
+ assert binary ==
+ :erlang.term_to_binary(
+ {"v1", :v2, Pleroma.Bookmark, 150, false, Phoenix.Socket.V1.JSONSerializer}
+ )
+
+ assert Config.from_binary(binary) ==
+ {"v1", :v2, Pleroma.Bookmark, 150, false, Phoenix.Socket.V1.JSONSerializer}
+ end
+
+ test "tuple with dispatch key" do
+ binary = Config.transform(%{"tuple" => [":dispatch", ["{:_,
+ [
+ {\"/api/v1/streaming\", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
+ {\"/websocket\", Phoenix.Endpoint.CowboyWebSocket,
+ {Phoenix.Transports.WebSocket,
+ {Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, [path: \"/websocket\"]}}},
+ {:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}
+ ]}"]]})
+
+ assert binary ==
+ :erlang.term_to_binary(
+ {:dispatch,
+ [
+ {:_,
+ [
+ {"/api/v1/streaming", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
+ {"/websocket", Phoenix.Endpoint.CowboyWebSocket,
+ {Phoenix.Transports.WebSocket,
+ {Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, [path: "/websocket"]}}},
+ {:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}
+ ]}
+ ]}
+ )
+
+ assert Config.from_binary(binary) ==
+ {:dispatch,
+ [
+ {:_,
+ [
+ {"/api/v1/streaming", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
+ {"/websocket", Phoenix.Endpoint.CowboyWebSocket,
+ {Phoenix.Transports.WebSocket,
+ {Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, [path: "/websocket"]}}},
+ {:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}
+ ]}
+ ]}
+ end
+
+ test "map with string key" do
+ binary = Config.transform(%{"key" => "value"})
+ assert binary == :erlang.term_to_binary(%{"key" => "value"})
+ assert Config.from_binary(binary) == %{"key" => "value"}
+ end
+
+ test "map with atom key" do
+ binary = Config.transform(%{":key" => "value"})
+ assert binary == :erlang.term_to_binary(%{key: "value"})
+ assert Config.from_binary(binary) == %{key: "value"}
+ end
+
+ test "list of strings" do
+ binary = Config.transform(["v1", "v2", "v3"])
+ assert binary == :erlang.term_to_binary(["v1", "v2", "v3"])
+ assert Config.from_binary(binary) == ["v1", "v2", "v3"]
+ end
+
+ test "list of modules" do
+ binary = Config.transform(["Pleroma.Repo", "Pleroma.Activity"])
+ assert binary == :erlang.term_to_binary([Pleroma.Repo, Pleroma.Activity])
+ assert Config.from_binary(binary) == [Pleroma.Repo, Pleroma.Activity]
+ end
+
+ test "list of atoms" do
+ binary = Config.transform([":v1", ":v2", ":v3"])
+ assert binary == :erlang.term_to_binary([:v1, :v2, :v3])
+ assert Config.from_binary(binary) == [:v1, :v2, :v3]
+ end
+
+ test "list of mixed values" do
+ binary =
+ Config.transform([
+ "v1",
+ ":v2",
+ "Pleroma.Repo",
+ "Phoenix.Socket.V1.JSONSerializer",
+ 15,
+ false
+ ])
+
+ assert binary ==
+ :erlang.term_to_binary([
+ "v1",
+ :v2,
+ Pleroma.Repo,
+ Phoenix.Socket.V1.JSONSerializer,
+ 15,
+ false
+ ])
+
+ assert Config.from_binary(binary) == [
+ "v1",
+ :v2,
+ Pleroma.Repo,
+ Phoenix.Socket.V1.JSONSerializer,
+ 15,
+ false
+ ]
+ end
+
+ test "simple keyword" do
+ binary = Config.transform([%{"tuple" => [":key", "value"]}])
+ assert binary == :erlang.term_to_binary([{:key, "value"}])
+ assert Config.from_binary(binary) == [{:key, "value"}]
+ assert Config.from_binary(binary) == [key: "value"]
+ end
+
+ test "keyword" do
+ binary =
+ Config.transform([
+ %{"tuple" => [":types", "Pleroma.PostgresTypes"]},
+ %{"tuple" => [":telemetry_event", ["Pleroma.Repo.Instrumenter"]]},
+ %{"tuple" => [":migration_lock", nil]},
+ %{"tuple" => [":key1", 150]},
+ %{"tuple" => [":key2", "string"]}
+ ])
+
+ assert binary ==
+ :erlang.term_to_binary(
+ types: Pleroma.PostgresTypes,
+ telemetry_event: [Pleroma.Repo.Instrumenter],
+ migration_lock: nil,
+ key1: 150,
+ key2: "string"
+ )
+
+ assert Config.from_binary(binary) == [
+ types: Pleroma.PostgresTypes,
+ telemetry_event: [Pleroma.Repo.Instrumenter],
+ migration_lock: nil,
+ key1: 150,
+ key2: "string"
+ ]
+ end
+
+ test "complex keyword with nested mixed childs" do
+ binary =
+ Config.transform([
+ %{"tuple" => [":uploader", "Pleroma.Uploaders.Local"]},
+ %{"tuple" => [":filters", ["Pleroma.Upload.Filter.Dedupe"]]},
+ %{"tuple" => [":link_name", true]},
+ %{"tuple" => [":proxy_remote", false]},
+ %{"tuple" => [":common_map", %{":key" => "value"}]},
+ %{
+ "tuple" => [
+ ":proxy_opts",
+ [
+ %{"tuple" => [":redirect_on_failure", false]},
+ %{"tuple" => [":max_body_length", 1_048_576]},
+ %{
+ "tuple" => [
+ ":http",
+ [%{"tuple" => [":follow_redirect", true]}, %{"tuple" => [":pool", ":upload"]}]
+ ]
+ }
+ ]
+ ]
+ }
+ ])
+
+ assert binary ==
+ :erlang.term_to_binary(
+ uploader: Pleroma.Uploaders.Local,
+ filters: [Pleroma.Upload.Filter.Dedupe],
+ link_name: true,
+ proxy_remote: false,
+ common_map: %{key: "value"},
+ proxy_opts: [
+ redirect_on_failure: false,
+ max_body_length: 1_048_576,
+ http: [
+ follow_redirect: true,
+ pool: :upload
+ ]
+ ]
+ )
+
+ assert Config.from_binary(binary) ==
+ [
+ uploader: Pleroma.Uploaders.Local,
+ filters: [Pleroma.Upload.Filter.Dedupe],
+ link_name: true,
+ proxy_remote: false,
+ common_map: %{key: "value"},
+ proxy_opts: [
+ redirect_on_failure: false,
+ max_body_length: 1_048_576,
+ http: [
+ follow_redirect: true,
+ pool: :upload
+ ]
+ ]
+ ]
+ end
+
+ test "common keyword" do
+ binary =
+ Config.transform([
+ %{"tuple" => [":level", ":warn"]},
+ %{"tuple" => [":meta", [":all"]]},
+ %{"tuple" => [":path", ""]},
+ %{"tuple" => [":val", nil]},
+ %{"tuple" => [":webhook_url", "https://hooks.slack.com/services/YOUR-KEY-HERE"]}
+ ])
+
+ assert binary ==
+ :erlang.term_to_binary(
+ level: :warn,
+ meta: [:all],
+ path: "",
+ val: nil,
+ webhook_url: "https://hooks.slack.com/services/YOUR-KEY-HERE"
+ )
+
+ assert Config.from_binary(binary) == [
+ level: :warn,
+ meta: [:all],
+ path: "",
+ val: nil,
+ webhook_url: "https://hooks.slack.com/services/YOUR-KEY-HERE"
+ ]
+ end
+
+ test "complex keyword with sigil" do
+ binary =
+ Config.transform([
+ %{"tuple" => [":federated_timeline_removal", []]},
+ %{"tuple" => [":reject", ["~r/comp[lL][aA][iI][nN]er/"]]},
+ %{"tuple" => [":replace", []]}
+ ])
+
+ assert binary ==
+ :erlang.term_to_binary(
+ federated_timeline_removal: [],
+ reject: [~r/comp[lL][aA][iI][nN]er/],
+ replace: []
+ )
+
+ assert Config.from_binary(binary) ==
+ [federated_timeline_removal: [], reject: [~r/comp[lL][aA][iI][nN]er/], replace: []]
+ end
+
+ test "complex keyword with tuples with more than 2 values" do
+ binary =
+ Config.transform([
+ %{
+ "tuple" => [
+ ":http",
+ [
+ %{
+ "tuple" => [
+ ":key1",
+ [
+ %{
+ "tuple" => [
+ ":_",
+ [
+ %{
+ "tuple" => [
+ "/api/v1/streaming",
+ "Pleroma.Web.MastodonAPI.WebsocketHandler",
+ []
+ ]
+ },
+ %{
+ "tuple" => [
+ "/websocket",
+ "Phoenix.Endpoint.CowboyWebSocket",
+ %{
+ "tuple" => [
+ "Phoenix.Transports.WebSocket",
+ %{
+ "tuple" => [
+ "Pleroma.Web.Endpoint",
+ "Pleroma.Web.UserSocket",
+ []
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ %{
+ "tuple" => [
+ ":_",
+ "Phoenix.Endpoint.Cowboy2Handler",
+ %{"tuple" => ["Pleroma.Web.Endpoint", []]}
+ ]
+ }
+ ]
+ ]
+ }
+ ]
+ ]
+ }
+ ]
+ ]
+ }
+ ])
+
+ assert binary ==
+ :erlang.term_to_binary(
+ http: [
+ key1: [
+ _: [
+ {"/api/v1/streaming", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
+ {"/websocket", Phoenix.Endpoint.CowboyWebSocket,
+ {Phoenix.Transports.WebSocket,
+ {Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, []}}},
+ {:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}
+ ]
+ ]
+ ]
+ )
+
+ assert Config.from_binary(binary) == [
+ http: [
+ key1: [
+ {:_,
+ [
+ {"/api/v1/streaming", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
+ {"/websocket", Phoenix.Endpoint.CowboyWebSocket,
+ {Phoenix.Transports.WebSocket,
+ {Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, []}}},
+ {:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}
+ ]}
+ ]
+ ]
+ ]
+ end
+ end
+end
diff --git a/test/web/admin_api/views/report_view_test.exs b/test/web/admin_api/views/report_view_test.exs
new file mode 100644
index 000000000..a00c9c579
--- /dev/null
+++ b/test/web/admin_api/views/report_view_test.exs
@@ -0,0 +1,130 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.AdminAPI.ReportViewTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+ alias Pleroma.Web.AdminAPI.ReportView
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.MastodonAPI.AccountView
+ alias Pleroma.Web.MastodonAPI.StatusView
+
+ test "renders a report" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
+
+ expected = %{
+ content: nil,
+ actor:
+ Map.merge(
+ AccountView.render("account.json", %{user: user}),
+ Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user})
+ ),
+ account:
+ Map.merge(
+ AccountView.render("account.json", %{user: other_user}),
+ Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: other_user})
+ ),
+ statuses: [],
+ state: "open",
+ id: activity.id
+ }
+
+ result =
+ ReportView.render("show.json", %{report: activity})
+ |> Map.delete(:created_at)
+
+ assert result == expected
+ end
+
+ test "includes reported statuses" do
+ user = insert(:user)
+ other_user = insert(:user)
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "toot"})
+
+ {:ok, report_activity} =
+ CommonAPI.report(user, %{"account_id" => other_user.id, "status_ids" => [activity.id]})
+
+ expected = %{
+ content: nil,
+ actor:
+ Map.merge(
+ AccountView.render("account.json", %{user: user}),
+ Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user})
+ ),
+ account:
+ Map.merge(
+ AccountView.render("account.json", %{user: other_user}),
+ Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: other_user})
+ ),
+ statuses: [StatusView.render("status.json", %{activity: activity})],
+ state: "open",
+ id: report_activity.id
+ }
+
+ result =
+ ReportView.render("show.json", %{report: report_activity})
+ |> Map.delete(:created_at)
+
+ assert result == expected
+ end
+
+ test "renders report's state" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
+ {:ok, activity} = CommonAPI.update_report_state(activity.id, "closed")
+ assert %{state: "closed"} = ReportView.render("show.json", %{report: activity})
+ end
+
+ test "renders report description" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.report(user, %{
+ "account_id" => other_user.id,
+ "comment" => "posts are too good for this instance"
+ })
+
+ assert %{content: "posts are too good for this instance"} =
+ ReportView.render("show.json", %{report: activity})
+ end
+
+ test "sanitizes report description" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.report(user, %{
+ "account_id" => other_user.id,
+ "comment" => ""
+ })
+
+ data = Map.put(activity.data, "content", "<script> alert('hecked :D:D:D:D:D:D:D') </script>")
+ activity = Map.put(activity, :data, data)
+
+ refute "<script> alert('hecked :D:D:D:D:D:D:D') </script>" ==
+ ReportView.render("show.json", %{report: activity})[:content]
+ end
+
+ test "doesn't error out when the user doesn't exists" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.report(user, %{
+ "account_id" => other_user.id,
+ "comment" => ""
+ })
+
+ Pleroma.User.delete(other_user)
+ Pleroma.User.invalidate_cache(other_user)
+
+ assert %{} = ReportView.render("show.json", %{report: activity})
+ end
+end
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 696060fb1..16b3f121d 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.CommonAPITest do
alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
@@ -33,7 +34,7 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu #2HU"})
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity)
assert object.data["tag"] == ["2hu"]
end
@@ -56,6 +57,25 @@ defmodule Pleroma.Web.CommonAPITest do
end
describe "posting" do
+ test "it supports explicit addressing" do
+ user = insert(:user)
+ user_two = insert(:user)
+ user_three = insert(:user)
+ user_four = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "Hey, I think @#{user_three.nickname} is ugly. @#{user_four.nickname} is alright though.",
+ "to" => [user_two.nickname, user_four.nickname, "nonexistent"]
+ })
+
+ assert user.ap_id in activity.recipients
+ assert user_two.ap_id in activity.recipients
+ assert user_four.ap_id in activity.recipients
+ refute user_three.ap_id in activity.recipients
+ end
+
test "it filters out obviously bad tags when accepting a post as HTML" do
user = insert(:user)
@@ -67,7 +87,7 @@ defmodule Pleroma.Web.CommonAPITest do
"content_type" => "text/html"
})
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity)
assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
end
@@ -83,7 +103,7 @@ defmodule Pleroma.Web.CommonAPITest do
"content_type" => "text/markdown"
})
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity)
assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
end
@@ -101,7 +121,7 @@ defmodule Pleroma.Web.CommonAPITest do
})
Enum.each(["public", "private", "unlisted"], fn visibility ->
- assert {:error, {:private_to_public, _}} =
+ assert {:error, "The message visibility must be direct"} =
CommonAPI.post(user, %{
"status" => "suya..",
"visibility" => visibility,
@@ -109,6 +129,37 @@ defmodule Pleroma.Web.CommonAPITest do
})
end)
end
+
+ test "it allows to address a list" do
+ user = insert(:user)
+ {:ok, list} = Pleroma.List.create("foo", user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
+
+ assert activity.data["bcc"] == [list.ap_id]
+ assert activity.recipients == [list.ap_id, user.ap_id]
+ assert activity.data["listMessage"] == list.ap_id
+ end
+
+ test "it returns error when status is empty and no attachments" do
+ user = insert(:user)
+
+ assert {:error, "Cannot post an empty status without attachments"} =
+ CommonAPI.post(user, %{"status" => ""})
+ 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
end
describe "reactions" do
@@ -168,6 +219,11 @@ defmodule Pleroma.Web.CommonAPITest do
assert %User{info: %{pinned_activities: [^id]}} = user
end
+ test "unlisted statuses can be pinned", %{user: user} do
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!", "visibility" => "unlisted"})
+ assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
+ end
+
test "only self-authored can be pinned", %{activity: activity} do
user = insert(:user)
@@ -320,4 +376,79 @@ defmodule Pleroma.Web.CommonAPITest do
assert User.showing_reblogs?(muter, muted) == true
end
end
+
+ describe "unfollow/2" do
+ test "also unsubscribes a user" do
+ [follower, followed] = insert_pair(:user)
+ {:ok, follower, followed, _} = CommonAPI.follow(follower, followed)
+ {:ok, followed} = User.subscribe(follower, followed)
+
+ assert User.subscribed_to?(follower, followed)
+
+ {:ok, follower} = CommonAPI.unfollow(follower, followed)
+
+ refute User.subscribed_to?(follower, followed)
+ end
+ end
+
+ describe "accept_follow_request/2" do
+ test "after acceptance, it sets all existing pending follow request states to 'accept'" do
+ user = insert(:user, info: %{locked: true})
+ follower = insert(:user)
+ follower_two = insert(:user)
+
+ {:ok, follow_activity} = ActivityPub.follow(follower, user)
+ {:ok, follow_activity_two} = ActivityPub.follow(follower, user)
+ {:ok, follow_activity_three} = ActivityPub.follow(follower_two, user)
+
+ assert follow_activity.data["state"] == "pending"
+ assert follow_activity_two.data["state"] == "pending"
+ assert follow_activity_three.data["state"] == "pending"
+
+ {:ok, _follower} = CommonAPI.accept_follow_request(follower, user)
+
+ assert Repo.get(Activity, follow_activity.id).data["state"] == "accept"
+ assert Repo.get(Activity, follow_activity_two.id).data["state"] == "accept"
+ assert Repo.get(Activity, follow_activity_three.id).data["state"] == "pending"
+ end
+
+ test "after rejection, it sets all existing pending follow request states to 'reject'" do
+ user = insert(:user, info: %{locked: true})
+ follower = insert(:user)
+ follower_two = insert(:user)
+
+ {:ok, follow_activity} = ActivityPub.follow(follower, user)
+ {:ok, follow_activity_two} = ActivityPub.follow(follower, user)
+ {:ok, follow_activity_three} = ActivityPub.follow(follower_two, user)
+
+ assert follow_activity.data["state"] == "pending"
+ assert follow_activity_two.data["state"] == "pending"
+ assert follow_activity_three.data["state"] == "pending"
+
+ {:ok, _follower} = CommonAPI.reject_follow_request(follower, user)
+
+ assert Repo.get(Activity, follow_activity.id).data["state"] == "reject"
+ assert Repo.get(Activity, follow_activity_two.id).data["state"] == "reject"
+ assert Repo.get(Activity, follow_activity_three.id).data["state"] == "pending"
+ end
+ end
+
+ describe "vote/3" do
+ test "does not allow to vote twice" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Am I cute?",
+ "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20}
+ })
+
+ object = Object.normalize(activity)
+
+ {:ok, _, object} = CommonAPI.vote(other_user, object, [0])
+
+ assert {:error, "Already voted"} == CommonAPI.vote(other_user, object, [1])
+ end
+ end
end
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index ab4c62b35..af320f31f 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -5,10 +5,16 @@
defmodule Pleroma.Web.CommonAPI.UtilsTest do
alias Pleroma.Builders.UserBuilder
alias Pleroma.Object
+ alias Pleroma.Web.CommonAPI
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.Endpoint
use Pleroma.DataCase
+ import ExUnit.CaptureLog
+ import Pleroma.Factory
+
+ @public_address "https://www.w3.org/ns/activitystreams#Public"
+
test "it adds attachment links to a given text and attachment set" do
name =
"Sakura%20Mana%20%E2%80%93%20Turned%20on%20by%20a%20Senior%20OL%20with%20a%20Temptating%20Tight%20Skirt-s%20Full%20Hipline%20and%20Panty%20Shot-%20Beautiful%20Thick%20Thighs-%20and%20Erotic%20Ass-%20-2015-%20--%20Oppaitime%208-28-2017%206-50-33%20PM.png"
@@ -197,7 +203,9 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
expected = ""
- assert Utils.date_to_asctime(date) == expected
+ assert capture_log(fn ->
+ assert Utils.date_to_asctime(date) == expected
+ end) =~ "[warn] Date #{date} in wrong format, must be ISO 8601"
end
test "when date is a Unix timestamp" do
@@ -205,13 +213,151 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
expected = ""
- assert Utils.date_to_asctime(date) == expected
+ assert capture_log(fn ->
+ assert Utils.date_to_asctime(date) == expected
+ end) =~ "[warn] Date #{date} in wrong format, must be ISO 8601"
end
test "when date is nil" do
expected = ""
- assert Utils.date_to_asctime(nil) == expected
+ assert capture_log(fn ->
+ assert Utils.date_to_asctime(nil) == expected
+ end) =~ "[warn] Date in wrong format, must be ISO 8601"
+ end
+
+ test "when date is a random string" do
+ assert capture_log(fn ->
+ assert Utils.date_to_asctime("foo") == ""
+ end) =~ "[warn] Date foo in wrong format, must be ISO 8601"
+ end
+ end
+
+ describe "get_to_and_cc" do
+ test "for public posts, not a reply" do
+ user = insert(:user)
+ mentioned_user = insert(:user)
+ mentions = [mentioned_user.ap_id]
+
+ {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "public")
+
+ assert length(to) == 2
+ assert length(cc) == 1
+
+ assert @public_address in to
+ assert mentioned_user.ap_id in to
+ assert user.follower_address in cc
+ end
+
+ test "for public posts, a reply" do
+ user = insert(:user)
+ mentioned_user = insert(:user)
+ third_user = insert(:user)
+ {:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
+ mentions = [mentioned_user.ap_id]
+
+ {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "public")
+
+ assert length(to) == 3
+ assert length(cc) == 1
+
+ assert @public_address in to
+ assert mentioned_user.ap_id in to
+ assert third_user.ap_id in to
+ assert user.follower_address in cc
+ end
+
+ test "for unlisted posts, not a reply" do
+ user = insert(:user)
+ mentioned_user = insert(:user)
+ mentions = [mentioned_user.ap_id]
+
+ {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "unlisted")
+
+ assert length(to) == 2
+ assert length(cc) == 1
+
+ assert @public_address in cc
+ assert mentioned_user.ap_id in to
+ assert user.follower_address in to
+ end
+
+ test "for unlisted posts, a reply" do
+ user = insert(:user)
+ mentioned_user = insert(:user)
+ third_user = insert(:user)
+ {:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
+ mentions = [mentioned_user.ap_id]
+
+ {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "unlisted")
+
+ assert length(to) == 3
+ assert length(cc) == 1
+
+ assert @public_address in cc
+ assert mentioned_user.ap_id in to
+ assert third_user.ap_id in to
+ assert user.follower_address in to
+ end
+
+ test "for private posts, not a reply" do
+ user = insert(:user)
+ mentioned_user = insert(:user)
+ mentions = [mentioned_user.ap_id]
+
+ {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "private")
+
+ assert length(to) == 2
+ assert length(cc) == 0
+
+ assert mentioned_user.ap_id in to
+ assert user.follower_address in to
+ end
+
+ test "for private posts, a reply" do
+ user = insert(:user)
+ mentioned_user = insert(:user)
+ third_user = insert(:user)
+ {:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
+ mentions = [mentioned_user.ap_id]
+
+ {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "private")
+
+ assert length(to) == 3
+ assert length(cc) == 0
+
+ assert mentioned_user.ap_id in to
+ assert third_user.ap_id in to
+ assert user.follower_address in to
+ end
+
+ test "for direct posts, not a reply" do
+ user = insert(:user)
+ mentioned_user = insert(:user)
+ mentions = [mentioned_user.ap_id]
+
+ {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "direct")
+
+ assert length(to) == 1
+ assert length(cc) == 0
+
+ assert mentioned_user.ap_id in to
+ end
+
+ test "for direct posts, a reply" do
+ user = insert(:user)
+ mentioned_user = insert(:user)
+ third_user = insert(:user)
+ {:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
+ mentions = [mentioned_user.ap_id]
+
+ {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "direct")
+
+ assert length(to) == 2
+ assert length(cc) == 0
+
+ assert mentioned_user.ap_id in to
+ assert third_user.ap_id in to
end
end
end
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 0f43bc8f2..69dd4d747 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -12,6 +12,13 @@ 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
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index aaf2261bb..de6aeec72 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -19,9 +19,18 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
]
}
+ background_image = %{
+ "url" => [%{"href" => "https://example.com/images/asuka_hospital.png"}]
+ }
+
user =
insert(:user, %{
- info: %{note_count: 5, follower_count: 3, source_data: source_data},
+ info: %{
+ note_count: 5,
+ follower_count: 3,
+ source_data: source_data,
+ background: background_image
+ },
nickname: "shp@shitposter.club",
name: ":karjalanpiirakka: shp",
bio: "<script src=\"invalid-html\"></script><span>valid html</span>",
@@ -60,6 +69,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
pleroma: %{}
},
pleroma: %{
+ background_image: "https://example.com/images/asuka_hospital.png",
confirmation_pending: false,
tags: [],
is_admin: false,
@@ -67,7 +77,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
hide_favorites: true,
hide_followers: false,
hide_follows: false,
- relationship: %{}
+ relationship: %{},
+ skip_thread_containment: false
}
}
@@ -78,10 +89,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
user = insert(:user)
notification_settings = %{
- "remote" => true,
- "local" => true,
"followers" => true,
- "follows" => true
+ "follows" => true,
+ "non_follows" => true,
+ "non_followers" => true
}
privacy = user.info.default_scope
@@ -125,6 +136,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
pleroma: %{}
},
pleroma: %{
+ background_image: nil,
confirmation_pending: false,
tags: [],
is_admin: false,
@@ -132,7 +144,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
hide_favorites: true,
hide_followers: false,
hide_follows: false,
- relationship: %{}
+ relationship: %{},
+ skip_thread_containment: false
}
}
@@ -214,6 +227,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
pleroma: %{}
},
pleroma: %{
+ background_image: nil,
confirmation_pending: false,
tags: [],
is_admin: false,
@@ -233,10 +247,32 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
domain_blocking: false,
showing_reblogs: true,
endorsed: false
- }
+ },
+ skip_thread_containment: false
}
}
assert expected == AccountView.render("account.json", %{user: user, for: other_user})
end
+
+ test "returns the settings store if the requesting user is the represented user and it's requested specifically" do
+ user = insert(:user, %{info: %User.Info{pleroma_settings_store: %{fe: "test"}}})
+
+ result =
+ AccountView.render("account.json", %{user: user, for: user, with_pleroma_settings: true})
+
+ assert result.pleroma.settings_store == %{:fe => "test"}
+
+ result = AccountView.render("account.json", %{user: user, with_pleroma_settings: true})
+ assert result.pleroma[:settings_store] == nil
+
+ result = AccountView.render("account.json", %{user: user, for: user})
+ assert result.pleroma[:settings_store] == nil
+ end
+
+ test "sanitizes display names" do
+ user = insert(:user, name: "<marquee> username </marquee>")
+ result = AccountView.render("account.json", %{user: user})
+ refute result.display_name == "<marquee> username </marquee>"
+ end
end
diff --git a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
new file mode 100644
index 000000000..71d0c8af8
--- /dev/null
+++ b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
@@ -0,0 +1,304 @@
+# 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.MastodonAPIController.UpdateCredentialsTest do
+ alias Pleroma.Repo
+ alias Pleroma.User
+
+ use Pleroma.Web.ConnCase
+
+ import Pleroma.Factory
+
+ describe "updating credentials" do
+ test "sets user settings in a generic way", %{conn: conn} do
+ user = insert(:user)
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{
+ "pleroma_settings_store" => %{
+ pleroma_fe: %{
+ theme: "bla"
+ }
+ }
+ })
+
+ assert user = json_response(res_conn, 200)
+ assert user["pleroma"]["settings_store"] == %{"pleroma_fe" => %{"theme" => "bla"}}
+
+ user = Repo.get(User, user["id"])
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{
+ "pleroma_settings_store" => %{
+ masto_fe: %{
+ theme: "bla"
+ }
+ }
+ })
+
+ assert user = json_response(res_conn, 200)
+
+ assert user["pleroma"]["settings_store"] ==
+ %{
+ "pleroma_fe" => %{"theme" => "bla"},
+ "masto_fe" => %{"theme" => "bla"}
+ }
+
+ user = Repo.get(User, user["id"])
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{
+ "pleroma_settings_store" => %{
+ masto_fe: %{
+ theme: "blub"
+ }
+ }
+ })
+
+ assert user = json_response(res_conn, 200)
+
+ assert user["pleroma"]["settings_store"] ==
+ %{
+ "pleroma_fe" => %{"theme" => "bla"},
+ "masto_fe" => %{"theme" => "blub"}
+ }
+ end
+
+ test "updates the user's bio", %{conn: conn} do
+ user = insert(:user)
+ user2 = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{
+ "note" => "I drink #cofe with @#{user2.nickname}"
+ })
+
+ assert user = json_response(conn, 200)
+
+ assert user["note"] ==
+ ~s(I drink <a class="hashtag" data-tag="cofe" href="http://localhost:4001/tag/cofe" rel="tag">#cofe</a> with <span class="h-card"><a data-user=") <>
+ user2.id <>
+ ~s(" class="u-url mention" href=") <>
+ user2.ap_id <> ~s(">@<span>) <> user2.nickname <> ~s(</span></a></span>)
+ end
+
+ test "updates the user's locking status", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{locked: "true"})
+
+ assert user = json_response(conn, 200)
+ assert user["locked"] == true
+ end
+
+ test "updates the user's default scope", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{default_scope: "cofe"})
+
+ assert user = json_response(conn, 200)
+ assert user["source"]["privacy"] == "cofe"
+ end
+
+ test "updates the user's hide_followers status", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{hide_followers: "true"})
+
+ assert user = json_response(conn, 200)
+ assert user["pleroma"]["hide_followers"] == true
+ end
+
+ test "updates the user's skip_thread_containment option", %{conn: conn} do
+ user = insert(:user)
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{skip_thread_containment: "true"})
+ |> json_response(200)
+
+ assert response["pleroma"]["skip_thread_containment"] == true
+ assert refresh_record(user).info.skip_thread_containment
+ end
+
+ test "updates the user's hide_follows status", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{hide_follows: "true"})
+
+ assert user = json_response(conn, 200)
+ assert user["pleroma"]["hide_follows"] == true
+ end
+
+ test "updates the user's hide_favorites status", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{hide_favorites: "true"})
+
+ assert user = json_response(conn, 200)
+ assert user["pleroma"]["hide_favorites"] == true
+ end
+
+ test "updates the user's show_role status", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{show_role: "false"})
+
+ assert user = json_response(conn, 200)
+ assert user["source"]["pleroma"]["show_role"] == false
+ end
+
+ test "updates the user's no_rich_text status", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{no_rich_text: "true"})
+
+ assert user = json_response(conn, 200)
+ assert user["source"]["pleroma"]["no_rich_text"] == true
+ end
+
+ test "updates the user's name", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"display_name" => "markorepairs"})
+
+ assert user = json_response(conn, 200)
+ assert user["display_name"] == "markorepairs"
+ end
+
+ test "updates the user's avatar", %{conn: conn} do
+ user = insert(:user)
+
+ new_avatar = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"avatar" => new_avatar})
+
+ assert user_response = json_response(conn, 200)
+ assert user_response["avatar"] != User.avatar_url(user)
+ end
+
+ test "updates the user's banner", %{conn: conn} do
+ user = insert(:user)
+
+ new_header = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"header" => new_header})
+
+ assert user_response = json_response(conn, 200)
+ assert user_response["header"] != User.banner_url(user)
+ end
+
+ test "updates the user's background", %{conn: conn} do
+ user = insert(:user)
+
+ new_header = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{
+ "pleroma_background_image" => new_header
+ })
+
+ assert user_response = json_response(conn, 200)
+ assert user_response["pleroma"]["background_image"]
+ end
+
+ test "requires 'write' permission", %{conn: conn} do
+ token1 = insert(:oauth_token, scopes: ["read"])
+ token2 = insert(:oauth_token, scopes: ["write", "follow"])
+
+ for token <- [token1, token2] do
+ conn =
+ conn
+ |> put_req_header("authorization", "Bearer #{token.token}")
+ |> patch("/api/v1/accounts/update_credentials", %{})
+
+ if token == token1 do
+ assert %{"error" => "Insufficient permissions: write."} == json_response(conn, 403)
+ else
+ assert json_response(conn, 200)
+ end
+ end
+ end
+
+ test "updates profile emojos", %{conn: conn} do
+ user = insert(:user)
+
+ note = "*sips :blank:*"
+ name = "I am :firefox:"
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{
+ "note" => note,
+ "display_name" => name
+ })
+
+ assert json_response(conn, 200)
+
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}")
+
+ assert user = json_response(conn, 200)
+
+ assert user["note"] == note
+ assert user["display_name"] == name
+ assert [%{"shortcode" => "blank"}, %{"shortcode" => "firefox"}] = user["emojis"]
+ end
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 1d9f5a816..af24fddc1 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -24,6 +24,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
import ExUnit.CaptureLog
import Tesla.Mock
+ @image "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
+
setup do
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok
@@ -33,7 +35,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = insert(:user)
following = insert(:user)
- {:ok, _activity} = TwitterAPI.create_status(following, %{"status" => "test"})
+ {:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
conn =
conn
@@ -56,7 +58,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
following = insert(:user)
capture_log(fn ->
- {:ok, _activity} = TwitterAPI.create_status(following, %{"status" => "test"})
+ {:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
{:ok, [_activity]} =
OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
@@ -94,150 +96,283 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> json_response(403) == %{"error" => "This resource requires authentication."}
end
- test "posting a status", %{conn: conn} do
- user = insert(:user)
+ describe "posting statuses" do
+ setup do
+ user = insert(:user)
- idempotency_key = "Pikachu rocks!"
+ conn =
+ build_conn()
+ |> assign(:user, user)
- conn_one =
- conn
- |> assign(:user, user)
- |> put_req_header("idempotency-key", idempotency_key)
- |> post("/api/v1/statuses", %{
- "status" => "cofe",
- "spoiler_text" => "2hu",
- "sensitive" => "false"
- })
+ [conn: conn]
+ end
- {:ok, ttl} = Cachex.ttl(:idempotency_cache, idempotency_key)
- # Six hours
- assert ttl > :timer.seconds(6 * 60 * 60 - 1)
+ test "posting a status", %{conn: conn} do
+ idempotency_key = "Pikachu rocks!"
- assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu", "sensitive" => false} =
- json_response(conn_one, 200)
+ conn_one =
+ conn
+ |> put_req_header("idempotency-key", idempotency_key)
+ |> post("/api/v1/statuses", %{
+ "status" => "cofe",
+ "spoiler_text" => "2hu",
+ "sensitive" => "false"
+ })
- assert Activity.get_by_id(id)
+ {:ok, ttl} = Cachex.ttl(:idempotency_cache, idempotency_key)
+ # Six hours
+ assert ttl > :timer.seconds(6 * 60 * 60 - 1)
- conn_two =
- conn
- |> assign(:user, user)
- |> put_req_header("idempotency-key", idempotency_key)
- |> post("/api/v1/statuses", %{
- "status" => "cofe",
- "spoiler_text" => "2hu",
- "sensitive" => "false"
- })
+ assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu", "sensitive" => false} =
+ json_response(conn_one, 200)
- assert %{"id" => second_id} = json_response(conn_two, 200)
+ assert Activity.get_by_id(id)
- assert id == second_id
+ conn_two =
+ conn
+ |> put_req_header("idempotency-key", idempotency_key)
+ |> post("/api/v1/statuses", %{
+ "status" => "cofe",
+ "spoiler_text" => "2hu",
+ "sensitive" => "false"
+ })
- conn_three =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{
- "status" => "cofe",
- "spoiler_text" => "2hu",
- "sensitive" => "false"
- })
+ assert %{"id" => second_id} = json_response(conn_two, 200)
+ assert id == second_id
- assert %{"id" => third_id} = json_response(conn_three, 200)
+ conn_three =
+ conn
+ |> post("/api/v1/statuses", %{
+ "status" => "cofe",
+ "spoiler_text" => "2hu",
+ "sensitive" => "false"
+ })
- refute id == third_id
- end
+ assert %{"id" => third_id} = json_response(conn_three, 200)
+ refute id == third_id
+ end
- test "posting a sensitive status", %{conn: conn} do
- user = insert(:user)
+ test "replying to a status", %{conn: conn} do
+ user = insert(:user)
+ {:ok, replied_to} = CommonAPI.post(user, %{"status" => "cofe"})
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{"status" => "cofe", "sensitive" => true})
+ conn =
+ conn
+ |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => replied_to.id})
- assert %{"content" => "cofe", "id" => id, "sensitive" => true} = json_response(conn, 200)
- assert Activity.get_by_id(id)
- end
+ assert %{"content" => "xD", "id" => id} = json_response(conn, 200)
- test "posting a fake status", %{conn: conn} do
- user = insert(:user)
+ activity = Activity.get_by_id(id)
- real_conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{
- "status" =>
- "\"Tenshi Eating a Corndog\" is a much discussed concept on /jp/. The significance of it is disputed, so I will focus on one core concept: the symbolism behind it"
- })
+ assert activity.data["context"] == replied_to.data["context"]
+ assert Activity.get_in_reply_to_activity(activity).id == replied_to.id
+ end
- real_status = json_response(real_conn, 200)
+ test "replying to a direct message with visibility other than direct", %{conn: conn} do
+ user = insert(:user)
+ {:ok, replied_to} = CommonAPI.post(user, %{"status" => "suya..", "visibility" => "direct"})
- assert real_status
- assert Object.get_by_ap_id(real_status["uri"])
+ Enum.each(["public", "private", "unlisted"], fn visibility ->
+ conn =
+ conn
+ |> post("/api/v1/statuses", %{
+ "status" => "@#{user.nickname} hey",
+ "in_reply_to_id" => replied_to.id,
+ "visibility" => visibility
+ })
- real_status =
- real_status
- |> Map.put("id", nil)
- |> Map.put("url", nil)
- |> Map.put("uri", nil)
- |> Map.put("created_at", nil)
- |> Kernel.put_in(["pleroma", "conversation_id"], nil)
+ assert json_response(conn, 422) == %{"error" => "The message visibility must be direct"}
+ end)
+ end
- fake_conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{
- "status" =>
- "\"Tenshi Eating a Corndog\" is a much discussed concept on /jp/. The significance of it is disputed, so I will focus on one core concept: the symbolism behind it",
- "preview" => true
- })
+ test "posting a status with an invalid in_reply_to_id", %{conn: conn} do
+ conn =
+ conn
+ |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => ""})
- fake_status = json_response(fake_conn, 200)
+ assert %{"content" => "xD", "id" => id} = json_response(conn, 200)
+ assert Activity.get_by_id(id)
+ end
- assert fake_status
- refute Object.get_by_ap_id(fake_status["uri"])
+ test "posting a sensitive status", %{conn: conn} do
+ conn =
+ conn
+ |> post("/api/v1/statuses", %{"status" => "cofe", "sensitive" => true})
- fake_status =
- fake_status
- |> Map.put("id", nil)
- |> Map.put("url", nil)
- |> Map.put("uri", nil)
- |> Map.put("created_at", nil)
- |> Kernel.put_in(["pleroma", "conversation_id"], nil)
+ assert %{"content" => "cofe", "id" => id, "sensitive" => true} = json_response(conn, 200)
+ assert Activity.get_by_id(id)
+ end
- assert real_status == fake_status
- end
+ test "posting a fake status", %{conn: conn} do
+ real_conn =
+ conn
+ |> post("/api/v1/statuses", %{
+ "status" =>
+ "\"Tenshi Eating a Corndog\" is a much discussed concept on /jp/. The significance of it is disputed, so I will focus on one core concept: the symbolism behind it"
+ })
- test "posting a status with OGP link preview", %{conn: conn} do
- Pleroma.Config.put([:rich_media, :enabled], true)
- user = insert(:user)
+ real_status = json_response(real_conn, 200)
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{
- "status" => "http://example.com/ogp"
- })
+ assert real_status
+ assert Object.get_by_ap_id(real_status["uri"])
+
+ real_status =
+ real_status
+ |> Map.put("id", nil)
+ |> Map.put("url", nil)
+ |> Map.put("uri", nil)
+ |> Map.put("created_at", nil)
+ |> Kernel.put_in(["pleroma", "conversation_id"], nil)
+
+ fake_conn =
+ conn
+ |> post("/api/v1/statuses", %{
+ "status" =>
+ "\"Tenshi Eating a Corndog\" is a much discussed concept on /jp/. The significance of it is disputed, so I will focus on one core concept: the symbolism behind it",
+ "preview" => true
+ })
- assert %{"id" => id, "card" => %{"title" => "The Rock"}} = json_response(conn, 200)
- assert Activity.get_by_id(id)
- Pleroma.Config.put([:rich_media, :enabled], false)
+ fake_status = json_response(fake_conn, 200)
+
+ assert fake_status
+ refute Object.get_by_ap_id(fake_status["uri"])
+
+ fake_status =
+ fake_status
+ |> Map.put("id", nil)
+ |> Map.put("url", nil)
+ |> Map.put("uri", nil)
+ |> Map.put("created_at", nil)
+ |> Kernel.put_in(["pleroma", "conversation_id"], nil)
+
+ assert real_status == fake_status
+ end
+
+ test "posting a status with OGP link preview", %{conn: conn} do
+ Pleroma.Config.put([:rich_media, :enabled], true)
+
+ conn =
+ conn
+ |> post("/api/v1/statuses", %{
+ "status" => "https://example.com/ogp"
+ })
+
+ 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
+ user2 = insert(:user)
+ content = "direct cofe @#{user2.nickname}"
+
+ conn =
+ conn
+ |> post("api/v1/statuses", %{"status" => content, "visibility" => "direct"})
+
+ assert %{"id" => id, "visibility" => "direct"} = json_response(conn, 200)
+ assert activity = Activity.get_by_id(id)
+ assert activity.recipients == [user2.ap_id, conn.assigns[:user].ap_id]
+ assert activity.data["to"] == [user2.ap_id]
+ assert activity.data["cc"] == []
+ end
end
- test "posting a direct status", %{conn: conn} do
- user1 = insert(:user)
- user2 = insert(:user)
- content = "direct cofe @#{user2.nickname}"
+ describe "posting polls" do
+ test "posting a poll", %{conn: conn} do
+ user = insert(:user)
+ time = NaiveDateTime.utc_now()
- conn =
- conn
- |> assign(:user, user1)
- |> post("api/v1/statuses", %{"status" => content, "visibility" => "direct"})
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{
+ "status" => "Who is the #bestgrill?",
+ "poll" => %{"options" => ["Rei", "Asuka", "Misato"], "expires_in" => 420}
+ })
- assert %{"id" => id, "visibility" => "direct"} = json_response(conn, 200)
- assert activity = Activity.get_by_id(id)
- assert activity.recipients == [user2.ap_id, user1.ap_id]
- assert activity.data["to"] == [user2.ap_id]
- assert activity.data["cc"] == []
+ response = json_response(conn, 200)
+
+ assert Enum.all?(response["poll"]["options"], fn %{"title" => title} ->
+ title in ["Rei", "Asuka", "Misato"]
+ end)
+
+ assert NaiveDateTime.diff(NaiveDateTime.from_iso8601!(response["poll"]["expires_at"]), time) in 420..430
+ refute response["poll"]["expred"]
+ end
+
+ test "option limit is enforced", %{conn: conn} do
+ user = insert(:user)
+ limit = Pleroma.Config.get([:instance, :poll_limits, :max_options])
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{
+ "status" => "desu~",
+ "poll" => %{"options" => Enum.map(0..limit, fn _ -> "desu" end), "expires_in" => 1}
+ })
+
+ %{"error" => error} = json_response(conn, 422)
+ assert error == "Poll can't contain more than #{limit} options"
+ end
+
+ test "option character limit is enforced", %{conn: conn} do
+ user = insert(:user)
+ limit = Pleroma.Config.get([:instance, :poll_limits, :max_option_chars])
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{
+ "status" => "...",
+ "poll" => %{
+ "options" => [Enum.reduce(0..limit, "", fn _, acc -> acc <> "." end)],
+ "expires_in" => 1
+ }
+ })
+
+ %{"error" => error} = json_response(conn, 422)
+ assert error == "Poll options cannot be longer than #{limit} characters each"
+ end
+
+ test "minimal date limit is enforced", %{conn: conn} do
+ user = insert(:user)
+ limit = Pleroma.Config.get([:instance, :poll_limits, :min_expiration])
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{
+ "status" => "imagine arbitrary limits",
+ "poll" => %{
+ "options" => ["this post was made by pleroma gang"],
+ "expires_in" => limit - 1
+ }
+ })
+
+ %{"error" => error} = json_response(conn, 422)
+ assert error == "Expiration date is too soon"
+ end
+
+ test "maximum date limit is enforced", %{conn: conn} do
+ user = insert(:user)
+ limit = Pleroma.Config.get([:instance, :poll_limits, :max_expiration])
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{
+ "status" => "imagine arbitrary limits",
+ "poll" => %{
+ "options" => ["this post was made by pleroma gang"],
+ "expires_in" => limit + 1
+ }
+ })
+
+ %{"error" => error} = json_response(conn, 422)
+ assert error == "Expiration date is too far in the future"
+ end
end
test "direct timeline", %{conn: conn} do
@@ -317,12 +452,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "Conversations", %{conn: conn} do
user_one = insert(:user)
user_two = insert(:user)
+ user_three = insert(:user)
{:ok, user_two} = User.follow(user_two, user_one)
{:ok, direct} =
CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}!",
+ "status" => "Hi @#{user_two.nickname}, @#{user_three.nickname}!",
"visibility" => "direct"
})
@@ -348,7 +484,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
}
] = response
+ account_ids = Enum.map(res_accounts, & &1["id"])
assert length(res_accounts) == 2
+ assert user_two.id in account_ids
+ assert user_three.id in account_ids
assert is_binary(res_id)
assert unread == true
assert res_last_status["id"] == direct.id
@@ -400,81 +539,146 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert status["id"] == direct.id
end
- test "replying to a status", %{conn: conn} do
+ test "verify_credentials", %{conn: conn} do
user = insert(:user)
- {:ok, replied_to} = TwitterAPI.create_status(user, %{"status" => "cofe"})
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/verify_credentials")
+
+ response = json_response(conn, 200)
+
+ assert %{"id" => id, "source" => %{"privacy" => "public"}} = response
+ assert response["pleroma"]["chat_token"]
+ assert id == to_string(user.id)
+ end
+
+ test "verify_credentials default scope unlisted", %{conn: conn} do
+ user = insert(:user, %{info: %User.Info{default_scope: "unlisted"}})
conn =
conn
|> assign(:user, user)
- |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => replied_to.id})
+ |> get("/api/v1/accounts/verify_credentials")
- assert %{"content" => "xD", "id" => id} = json_response(conn, 200)
+ assert %{"id" => id, "source" => %{"privacy" => "unlisted"}} = json_response(conn, 200)
+ assert id == to_string(user.id)
+ end
- activity = Activity.get_by_id(id)
+ test "apps/verify_credentials", %{conn: conn} do
+ token = insert(:oauth_token)
- assert activity.data["context"] == replied_to.data["context"]
- assert Activity.get_in_reply_to_activity(activity).id == replied_to.id
+ conn =
+ conn
+ |> assign(:user, token.user)
+ |> assign(:token, token)
+ |> get("/api/v1/apps/verify_credentials")
+
+ app = Repo.preload(token, :app).app
+
+ expected = %{
+ "name" => app.client_name,
+ "website" => app.website,
+ "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
+ }
+
+ assert expected == json_response(conn, 200)
end
- test "posting a status with an invalid in_reply_to_id", %{conn: conn} do
+ test "user avatar can be set", %{conn: conn} do
user = insert(:user)
+ avatar_image = File.read!("test/fixtures/avatar_data_uri")
conn =
conn
|> assign(:user, user)
- |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => ""})
+ |> patch("/api/v1/pleroma/accounts/update_avatar", %{img: avatar_image})
- assert %{"content" => "xD", "id" => id} = json_response(conn, 200)
+ user = refresh_record(user)
- activity = Activity.get_by_id(id)
+ assert %{
+ "name" => _,
+ "type" => _,
+ "url" => [
+ %{
+ "href" => _,
+ "mediaType" => _,
+ "type" => _
+ }
+ ]
+ } = user.avatar
- assert activity
+ assert %{"url" => _} = json_response(conn, 200)
end
- test "verify_credentials", %{conn: conn} do
+ test "user avatar can be reset", %{conn: conn} do
user = insert(:user)
conn =
conn
|> assign(:user, user)
- |> get("/api/v1/accounts/verify_credentials")
+ |> patch("/api/v1/pleroma/accounts/update_avatar", %{img: ""})
- assert %{"id" => id, "source" => %{"privacy" => "public"}} = json_response(conn, 200)
- assert id == to_string(user.id)
+ user = User.get_cached_by_id(user.id)
+
+ assert user.avatar == nil
+
+ assert %{"url" => nil} = json_response(conn, 200)
end
- test "verify_credentials default scope unlisted", %{conn: conn} do
- user = insert(:user, %{info: %User.Info{default_scope: "unlisted"}})
+ test "can set profile banner", %{conn: conn} do
+ user = insert(:user)
conn =
conn
|> assign(:user, user)
- |> get("/api/v1/accounts/verify_credentials")
+ |> patch("/api/v1/pleroma/accounts/update_banner", %{"banner" => @image})
- assert %{"id" => id, "source" => %{"privacy" => "unlisted"}} = json_response(conn, 200)
- assert id == to_string(user.id)
+ user = refresh_record(user)
+ assert user.info.banner["type"] == "Image"
+
+ assert %{"url" => _} = json_response(conn, 200)
end
- test "apps/verify_credentials", %{conn: conn} do
- token = insert(:oauth_token)
+ test "can reset profile banner", %{conn: conn} do
+ user = insert(:user)
conn =
conn
- |> assign(:user, token.user)
- |> assign(:token, token)
- |> get("/api/v1/apps/verify_credentials")
+ |> assign(:user, user)
+ |> patch("/api/v1/pleroma/accounts/update_banner", %{"banner" => ""})
- app = Repo.preload(token, :app).app
+ user = refresh_record(user)
+ assert user.info.banner == %{}
- expected = %{
- "name" => app.client_name,
- "website" => app.website,
- "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
- }
+ assert %{"url" => nil} = json_response(conn, 200)
+ end
- assert expected == json_response(conn, 200)
+ test "background image can be set", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/pleroma/accounts/update_background", %{"img" => @image})
+
+ user = refresh_record(user)
+ assert user.info.background["type"] == "Image"
+ assert %{"url" => _} = json_response(conn, 200)
+ end
+
+ test "background image can be reset", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/pleroma/accounts/update_background", %{"img" => ""})
+
+ user = refresh_record(user)
+ assert user.info.background == %{}
+ assert %{"url" => nil} = json_response(conn, 200)
end
test "creates an oauth app", %{conn: conn} do
@@ -800,8 +1004,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "list timeline", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
- {:ok, _activity_one} = TwitterAPI.create_status(user, %{"status" => "Marisa is cute."})
- {:ok, activity_two} = TwitterAPI.create_status(other_user, %{"status" => "Marisa is cute."})
+ {:ok, _activity_one} = CommonAPI.post(user, %{"status" => "Marisa is cute."})
+ {:ok, activity_two} = CommonAPI.post(other_user, %{"status" => "Marisa is cute."})
{:ok, list} = Pleroma.List.create("name", user)
{:ok, list} = Pleroma.List.follow(list, other_user)
@@ -818,10 +1022,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "list timeline does not leak non-public statuses for unfollowed users", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity_one} = TwitterAPI.create_status(other_user, %{"status" => "Marisa is cute."})
+ {:ok, activity_one} = CommonAPI.post(other_user, %{"status" => "Marisa is cute."})
{:ok, _activity_two} =
- TwitterAPI.create_status(other_user, %{
+ CommonAPI.post(other_user, %{
"status" => "Marisa is cute.",
"visibility" => "private"
})
@@ -845,8 +1049,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} =
- TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
{:ok, [_notification]} = Notification.create_notifications(activity)
@@ -868,8 +1071,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} =
- TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
{:ok, [notification]} = Notification.create_notifications(activity)
@@ -891,8 +1093,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} =
- TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
{:ok, [notification]} = Notification.create_notifications(activity)
@@ -908,8 +1109,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} =
- TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
{:ok, [_notification]} = Notification.create_notifications(activity)
@@ -1070,6 +1270,71 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
result = json_response(conn_res, 200)
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
end
+
+ test "doesn't see notifications after muting user with notifications", %{conn: conn} do
+ user = insert(:user)
+ user2 = insert(:user)
+
+ {:ok, _, _, _} = CommonAPI.follow(user, user2)
+ {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
+
+ conn = assign(conn, :user, user)
+
+ conn = get(conn, "/api/v1/notifications")
+
+ assert length(json_response(conn, 200)) == 1
+
+ {:ok, user} = User.mute(user, user2)
+
+ conn = assign(build_conn(), :user, user)
+ conn = get(conn, "/api/v1/notifications")
+
+ assert json_response(conn, 200) == []
+ end
+
+ test "see notifications after muting user without notifications", %{conn: conn} do
+ user = insert(:user)
+ user2 = insert(:user)
+
+ {:ok, _, _, _} = CommonAPI.follow(user, user2)
+ {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
+
+ conn = assign(conn, :user, user)
+
+ conn = get(conn, "/api/v1/notifications")
+
+ assert length(json_response(conn, 200)) == 1
+
+ {:ok, user} = User.mute(user, user2, false)
+
+ conn = assign(build_conn(), :user, user)
+ conn = get(conn, "/api/v1/notifications")
+
+ assert length(json_response(conn, 200)) == 1
+ end
+
+ test "see notifications after muting user with notifications and with_muted parameter", %{
+ conn: conn
+ } do
+ user = insert(:user)
+ user2 = insert(:user)
+
+ {:ok, _, _, _} = CommonAPI.follow(user, user2)
+ {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
+
+ conn = assign(conn, :user, user)
+
+ conn = get(conn, "/api/v1/notifications")
+
+ assert length(json_response(conn, 200)) == 1
+
+ {:ok, user} = User.mute(user, user2)
+
+ conn = assign(build_conn(), :user, user)
+ conn = get(conn, "/api/v1/notifications", %{"with_muted" => "true"})
+
+ assert length(json_response(conn, 200)) == 1
+ end
end
describe "reblogging" do
@@ -1126,6 +1391,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert to_string(activity.id) == id
end
+
+ test "returns 400 error when activity is not exist", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/foo/reblog")
+
+ assert json_response(conn, 400) == %{"error" => "Could not repeat"}
+ end
end
describe "unreblogging" do
@@ -1144,6 +1420,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert to_string(activity.id) == id
end
+
+ test "returns 400 error when activity is not exist", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/foo/unreblog")
+
+ assert json_response(conn, 400) == %{"error" => "Could not unrepeat"}
+ end
end
describe "favoriting" do
@@ -1162,16 +1449,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert to_string(activity.id) == id
end
- test "returns 500 for a wrong id", %{conn: conn} do
+ test "returns 400 error for a wrong id", %{conn: conn} do
user = insert(:user)
- resp =
+ conn =
conn
|> assign(:user, user)
|> post("/api/v1/statuses/1/favourite")
- |> json_response(500)
- assert resp == "Something went wrong"
+ assert json_response(conn, 400) == %{"error" => "Could not favorite"}
end
end
@@ -1192,6 +1478,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert to_string(activity.id) == id
end
+
+ test "returns 400 error for a wrong id", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/1/unfavourite")
+
+ assert json_response(conn, 400) == %{"error" => "Could not unfavorite"}
+ end
end
describe "user timelines" do
@@ -1262,10 +1559,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
media =
TwitterAPI.upload(file, user, "json")
- |> Poison.decode!()
+ |> Jason.decode!()
{:ok, image_post} =
- TwitterAPI.create_status(user, %{"status" => "cofe", "media_ids" => [media["media_id"]]})
+ CommonAPI.post(user, %{"status" => "cofe", "media_ids" => [media["media_id"]]})
conn =
conn
@@ -1301,6 +1598,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [%{"id" => id}] = json_response(conn, 200)
assert id == to_string(post.id)
end
+
+ test "filters user's statuses by a hashtag", %{conn: conn} do
+ user = insert(:user)
+ {:ok, post} = CommonAPI.post(user, %{"status" => "#hashtag"})
+ {:ok, _post} = CommonAPI.post(user, %{"status" => "hashtag"})
+
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/statuses", %{"tagged" => "hashtag"})
+
+ assert [%{"id" => id}] = json_response(conn, 200)
+ assert id == to_string(post.id)
+ end
end
describe "user relationships" do
@@ -1320,6 +1630,82 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
+ 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 =
+ build_conn()
+ |> assign(:user, user)
+
+ image = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ [conn: conn, image: image]
+ end
+
+ test "returns uploaded image", %{conn: conn, image: image} do
+ desc = "Description of the image"
+
+ media =
+ conn
+ |> post("/api/v1/media", %{"file" => image, "description" => desc})
+ |> json_response(:ok)
+
+ assert media["type"] == "image"
+ assert media["description"] == desc
+ assert media["id"]
+
+ 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
test "/api/v1/follow_requests works" do
user = insert(:user, %{info: %User.Info{locked: true}})
@@ -1429,32 +1815,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert id == user.id
end
- test "media upload", %{conn: conn} do
- file = %Plug.Upload{
- content_type: "image/jpg",
- path: Path.absname("test/fixtures/image.jpg"),
- filename: "an_image.jpg"
- }
-
- desc = "Description of the image"
-
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/media", %{"file" => file, "description" => desc})
-
- assert media = json_response(conn, 200)
-
- assert media["type"] == "image"
- assert media["description"] == desc
- assert media["id"]
-
- object = Repo.get(Object, media["id"])
- assert object.data["actor"] == User.ap_id(user)
- end
-
test "mascot upload", %{conn: conn} do
user = insert(:user)
@@ -1525,7 +1885,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
following = insert(:user)
capture_log(fn ->
- {:ok, activity} = TwitterAPI.create_status(following, %{"status" => "test #2hu"})
+ {:ok, activity} = CommonAPI.post(following, %{"status" => "test #2hu"})
{:ok, [_activity]} =
OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
@@ -1838,25 +2198,52 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"error" => "Record not found"} = json_response(conn_res, 404)
end
- test "muting / unmuting a user", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
+ describe "mute/unmute" do
+ test "with notifications", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/accounts/#{other_user.id}/mute")
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/mute")
- assert %{"id" => _id, "muting" => true} = json_response(conn, 200)
+ response = json_response(conn, 200)
- user = User.get_cached_by_id(user.id)
+ assert %{"id" => _id, "muting" => true, "muting_notifications" => true} = response
+ user = User.get_cached_by_id(user.id)
- conn =
- build_conn()
- |> assign(:user, user)
- |> post("/api/v1/accounts/#{other_user.id}/unmute")
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/unmute")
+
+ response = json_response(conn, 200)
+ assert %{"id" => _id, "muting" => false, "muting_notifications" => false} = response
+ end
- assert %{"id" => _id, "muting" => false} = json_response(conn, 200)
+ test "without notifications", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/mute", %{"notifications" => "false"})
+
+ response = json_response(conn, 200)
+
+ assert %{"id" => _id, "muting" => true, "muting_notifications" => false} = response
+ user = User.get_cached_by_id(user.id)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/unmute")
+
+ response = json_response(conn, 200)
+ assert %{"id" => _id, "muting" => false, "muting_notifications" => false} = response
+ end
end
test "subscribing / unsubscribing to a user", %{conn: conn} do
@@ -1983,104 +2370,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end)
end
- test "account search", %{conn: conn} do
- user = insert(:user)
- user_two = insert(:user, %{nickname: "shp@shitposter.club"})
- user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
-
- results =
- conn
- |> assign(:user, user)
- |> get("/api/v1/accounts/search", %{"q" => "shp"})
- |> json_response(200)
-
- result_ids = for result <- results, do: result["acct"]
-
- assert user_two.nickname in result_ids
- assert user_three.nickname in result_ids
-
- results =
- conn
- |> assign(:user, user)
- |> get("/api/v1/accounts/search", %{"q" => "2hu"})
- |> json_response(200)
-
- result_ids = for result <- results, do: result["acct"]
-
- assert user_three.nickname in result_ids
- end
-
- test "search", %{conn: conn} do
- user = insert(:user)
- user_two = insert(:user, %{nickname: "shp@shitposter.club"})
- user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu"})
-
- {:ok, _activity} =
- CommonAPI.post(user, %{
- "status" => "This is about 2hu, but private",
- "visibility" => "private"
- })
-
- {:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"})
-
- conn =
- conn
- |> get("/api/v1/search", %{"q" => "2hu"})
-
- assert results = json_response(conn, 200)
-
- [account | _] = results["accounts"]
- assert account["id"] == to_string(user_three.id)
-
- assert results["hashtags"] == []
-
- [status] = results["statuses"]
- assert status["id"] == to_string(activity.id)
- end
-
- test "search fetches remote statuses", %{conn: conn} do
- capture_log(fn ->
- conn =
- conn
- |> get("/api/v1/search", %{"q" => "https://shitposter.club/notice/2827873"})
-
- assert results = json_response(conn, 200)
-
- [status] = results["statuses"]
- assert status["uri"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
- end)
- end
-
- test "search doesn't show statuses that it shouldn't", %{conn: conn} do
- {:ok, activity} =
- CommonAPI.post(insert(:user), %{
- "status" => "This is about 2hu, but private",
- "visibility" => "private"
- })
-
- capture_log(fn ->
- conn =
- conn
- |> get("/api/v1/search", %{"q" => Object.normalize(activity).data["id"]})
-
- assert results = json_response(conn, 200)
-
- [] = results["statuses"]
- end)
- end
-
- test "search fetches remote accounts", %{conn: conn} do
- conn =
- conn
- |> get("/api/v1/search", %{"q" => "shp@social.heldscal.la", "resolve" => "true"})
-
- assert results = json_response(conn, 200)
- [account] = results["accounts"]
- assert account["acct"] == "shp@social.heldscal.la"
- end
-
test "returns the favorites of a user", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
@@ -2321,205 +2610,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- describe "updating credentials" do
- test "updates the user's bio", %{conn: conn} do
- user = insert(:user)
- user2 = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{
- "note" => "I drink #cofe with @#{user2.nickname}"
- })
-
- assert user = json_response(conn, 200)
-
- assert user["note"] ==
- ~s(I drink <a class="hashtag" data-tag="cofe" href="http://localhost:4001/tag/cofe" rel="tag">#cofe</a> with <span class="h-card"><a data-user=") <>
- user2.id <>
- ~s(" class="u-url mention" href=") <>
- user2.ap_id <> ~s(">@<span>) <> user2.nickname <> ~s(</span></a></span>)
- end
-
- test "updates the user's locking status", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{locked: "true"})
-
- assert user = json_response(conn, 200)
- assert user["locked"] == true
- end
-
- test "updates the user's default scope", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{default_scope: "cofe"})
-
- assert user = json_response(conn, 200)
- assert user["source"]["privacy"] == "cofe"
- end
-
- test "updates the user's hide_followers status", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{hide_followers: "true"})
-
- assert user = json_response(conn, 200)
- assert user["pleroma"]["hide_followers"] == true
- end
-
- test "updates the user's hide_follows status", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{hide_follows: "true"})
-
- assert user = json_response(conn, 200)
- assert user["pleroma"]["hide_follows"] == true
- end
-
- test "updates the user's hide_favorites status", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{hide_favorites: "true"})
-
- assert user = json_response(conn, 200)
- assert user["pleroma"]["hide_favorites"] == true
- end
-
- test "updates the user's show_role status", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{show_role: "false"})
-
- assert user = json_response(conn, 200)
- assert user["source"]["pleroma"]["show_role"] == false
- end
-
- test "updates the user's no_rich_text status", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{no_rich_text: "true"})
-
- assert user = json_response(conn, 200)
- assert user["source"]["pleroma"]["no_rich_text"] == true
- end
-
- test "updates the user's name", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"display_name" => "markorepairs"})
-
- assert user = json_response(conn, 200)
- assert user["display_name"] == "markorepairs"
- end
-
- test "updates the user's avatar", %{conn: conn} do
- user = insert(:user)
-
- new_avatar = %Plug.Upload{
- content_type: "image/jpg",
- path: Path.absname("test/fixtures/image.jpg"),
- filename: "an_image.jpg"
- }
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"avatar" => new_avatar})
-
- assert user_response = json_response(conn, 200)
- assert user_response["avatar"] != User.avatar_url(user)
- end
-
- test "updates the user's banner", %{conn: conn} do
- user = insert(:user)
-
- new_header = %Plug.Upload{
- content_type: "image/jpg",
- path: Path.absname("test/fixtures/image.jpg"),
- filename: "an_image.jpg"
- }
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"header" => new_header})
-
- assert user_response = json_response(conn, 200)
- assert user_response["header"] != User.banner_url(user)
- end
-
- test "requires 'write' permission", %{conn: conn} do
- token1 = insert(:oauth_token, scopes: ["read"])
- token2 = insert(:oauth_token, scopes: ["write", "follow"])
-
- for token <- [token1, token2] do
- conn =
- conn
- |> put_req_header("authorization", "Bearer #{token.token}")
- |> patch("/api/v1/accounts/update_credentials", %{})
-
- if token == token1 do
- assert %{"error" => "Insufficient permissions: write."} == json_response(conn, 403)
- else
- assert json_response(conn, 200)
- end
- end
- end
-
- test "updates profile emojos", %{conn: conn} do
- user = insert(:user)
-
- note = "*sips :blank:*"
- name = "I am :firefox:"
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{
- "note" => note,
- "display_name" => name
- })
-
- assert json_response(conn, 200)
-
- conn =
- conn
- |> get("/api/v1/accounts/#{user.id}")
-
- assert user = json_response(conn, 200)
-
- assert user["note"] == note
- assert user["display_name"] == name
- assert [%{"shortcode" => "blank"}, %{"shortcode" => "firefox"}] = user["emojis"]
- end
- end
-
test "get instance information", %{conn: conn} do
conn = get(conn, "/api/v1/instance")
assert result = json_response(conn, 200)
@@ -2538,7 +2628,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
"stats" => _,
"thumbnail" => _,
"languages" => _,
- "registrations" => _
+ "registrations" => _,
+ "poll_limits" => _
} = result
assert email == from_config_email
@@ -2553,7 +2644,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
insert(:user, %{local: false, nickname: "u@peer1.com"})
insert(:user, %{local: false, nickname: "u@peer2.com"})
- {:ok, _} = TwitterAPI.create_status(user, %{"status" => "cofe"})
+ {:ok, _} = CommonAPI.post(user, %{"status" => "cofe"})
# Stats should count users with missing or nil `info.deactivated` value
user = User.get_cached_by_id(user.id)
@@ -2646,6 +2737,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> json_response(200)
end
+ test "/pin: returns 400 error when activity is not public", %{conn: conn, user: user} do
+ {:ok, dm} = CommonAPI.post(user, %{"status" => "test", "visibility" => "direct"})
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{dm.id}/pin")
+
+ assert json_response(conn, 400) == %{"error" => "Could not pin"}
+ end
+
test "unpin status", %{conn: conn, user: user, activity: activity} do
{:ok, _} = CommonAPI.pin(activity.id, user)
@@ -2665,6 +2767,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> json_response(200)
end
+ test "/unpin: returns 400 error when activity is not exist", %{conn: conn, user: user} do
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/1/unpin")
+
+ assert json_response(conn, 400) == %{"error" => "Could not unpin"}
+ end
+
test "max pinned statuses", %{conn: conn, user: user, activity: activity_one} do
{:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
@@ -2684,37 +2795,54 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> post("/api/v1/statuses/#{activity_two.id}/pin")
|> json_response(400)
end
+ end
- test "Status rich-media Card", %{conn: conn, user: user} do
+ describe "cards" do
+ setup do
Pleroma.Config.put([:rich_media, :enabled], true)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "http://example.com/ogp"})
+
+ on_exit(fn ->
+ Pleroma.Config.put([:rich_media, :enabled], false)
+ end)
+
+ user = insert(:user)
+ %{user: user}
+ end
+
+ test "returns rich-media card", %{conn: conn, user: user} do
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "https://example.com/ogp"})
+
+ card_data = %{
+ "image" => "http://ia.media-imdb.com/images/rock.jpg",
+ "provider_name" => "www.imdb.com",
+ "provider_url" => "http://www.imdb.com",
+ "title" => "The Rock",
+ "type" => "link",
+ "url" => "http://www.imdb.com/title/tt0117500/",
+ "description" =>
+ "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
+ "pleroma" => %{
+ "opengraph" => %{
+ "image" => "http://ia.media-imdb.com/images/rock.jpg",
+ "title" => "The Rock",
+ "type" => "video.movie",
+ "url" => "http://www.imdb.com/title/tt0117500/",
+ "description" =>
+ "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer."
+ }
+ }
+ }
response =
conn
|> get("/api/v1/statuses/#{activity.id}/card")
|> json_response(200)
- assert response == %{
- "image" => "http://ia.media-imdb.com/images/rock.jpg",
- "provider_name" => "www.imdb.com",
- "provider_url" => "http://www.imdb.com",
- "title" => "The Rock",
- "type" => "link",
- "url" => "http://www.imdb.com/title/tt0117500/",
- "description" => nil,
- "pleroma" => %{
- "opengraph" => %{
- "image" => "http://ia.media-imdb.com/images/rock.jpg",
- "title" => "The Rock",
- "type" => "video.movie",
- "url" => "http://www.imdb.com/title/tt0117500/"
- }
- }
- }
+ assert response == card_data
# works with private posts
{:ok, activity} =
- CommonAPI.post(user, %{"status" => "http://example.com/ogp", "visibility" => "direct"})
+ CommonAPI.post(user, %{"status" => "https://example.com/ogp", "visibility" => "direct"})
response_two =
conn
@@ -2722,9 +2850,34 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> get("/api/v1/statuses/#{activity.id}/card")
|> json_response(200)
- assert response_two == response
+ assert response_two == card_data
+ end
- Pleroma.Config.put([:rich_media, :enabled], false)
+ test "replaces missing description with an empty string", %{conn: conn, user: user} do
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "https://example.com/ogp-missing-data"})
+
+ response =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}/card")
+ |> json_response(:ok)
+
+ assert response == %{
+ "type" => "link",
+ "title" => "Pleroma",
+ "description" => "",
+ "image" => nil,
+ "provider_name" => "pleroma.social",
+ "provider_url" => "https://pleroma.social",
+ "url" => "https://pleroma.social/",
+ "pleroma" => %{
+ "opengraph" => %{
+ "title" => "Pleroma",
+ "type" => "website",
+ "url" => "https://pleroma.social/"
+ }
+ }
+ }
end
end
@@ -2797,6 +2950,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> json_response(200)
end
+ test "cannot mute already muted conversation", %{conn: conn, user: user, activity: activity} do
+ {:ok, _} = CommonAPI.add_mute(user, activity)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity.id}/mute")
+
+ assert json_response(conn, 400) == %{"error" => "conversation is already muted"}
+ end
+
test "unmute conversation", %{conn: conn, user: user, activity: activity} do
{:ok, _} = CommonAPI.add_mute(user, activity)
@@ -2811,31 +2975,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- test "flavours switching (Pleroma Extension)", %{conn: conn} do
- user = insert(:user)
-
- get_old_flavour =
- conn
- |> assign(:user, user)
- |> get("/api/v1/pleroma/flavour")
-
- assert "glitch" == json_response(get_old_flavour, 200)
-
- set_flavour =
- conn
- |> assign(:user, user)
- |> post("/api/v1/pleroma/flavour/vanilla")
-
- assert "vanilla" == json_response(set_flavour, 200)
-
- get_new_flavour =
- conn
- |> assign(:user, user)
- |> post("/api/v1/pleroma/flavour/vanilla")
-
- assert json_response(set_flavour, 200) == json_response(get_new_flavour, 200)
- end
-
describe "reports" do
setup do
reporter = insert(:user)
@@ -2866,7 +3005,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> post("/api/v1/reports", %{
"account_id" => target_user.id,
"status_ids" => [activity.id],
- "comment" => "bad status!"
+ "comment" => "bad status!",
+ "forward" => "false"
})
|> json_response(200)
end
@@ -2899,6 +3039,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> post("/api/v1/reports", %{"account_id" => target_user.id, "comment" => comment})
|> json_response(400)
end
+
+ test "returns error when account is not exist", %{
+ conn: conn,
+ reporter: reporter,
+ activity: activity
+ } do
+ conn =
+ conn
+ |> assign(:user, reporter)
+ |> post("/api/v1/reports", %{"status_ids" => [activity.id], "account_id" => "foo"})
+
+ assert json_response(conn, 400) == %{"error" => "Account not found"}
+ end
end
describe "link headers" do
@@ -2970,6 +3123,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert Map.has_key?(emoji, "static_url")
assert Map.has_key?(emoji, "tags")
assert is_list(emoji["tags"])
+ assert Map.has_key?(emoji, "category")
assert Map.has_key?(emoji, "url")
assert Map.has_key?(emoji, "visible_in_picker")
end
@@ -3257,7 +3411,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user2 = insert(:user)
user3 = insert(:user)
- {:ok, replied_to} = TwitterAPI.create_status(user1, %{"status" => "cofe"})
+ {:ok, replied_to} = CommonAPI.post(user1, %{"status" => "cofe"})
# Reply to status from another user
conn1 =
@@ -3298,24 +3452,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
describe "create account by app" do
- setup do
- enabled = Pleroma.Config.get([:app_account_creation, :enabled])
- max_requests = Pleroma.Config.get([:app_account_creation, :max_requests])
- interval = Pleroma.Config.get([:app_account_creation, :interval])
-
- Pleroma.Config.put([:app_account_creation, :enabled], true)
- Pleroma.Config.put([:app_account_creation, :max_requests], 5)
- Pleroma.Config.put([:app_account_creation, :interval], 1)
-
- on_exit(fn ->
- Pleroma.Config.put([:app_account_creation, :enabled], enabled)
- Pleroma.Config.put([:app_account_creation, :max_requests], max_requests)
- Pleroma.Config.put([:app_account_creation, :interval], interval)
- end)
-
- :ok
- end
-
test "Account registration via Application", %{conn: conn} do
conn =
conn
@@ -3418,7 +3554,257 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
agreement: true
})
- assert json_response(conn, 403) == %{"error" => "Rate limit exceeded."}
+ assert json_response(conn, :too_many_requests) == %{"error" => "Throttled"}
+ end
+ end
+
+ describe "GET /api/v1/polls/:id" do
+ test "returns poll entity for object id", %{conn: conn} do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Pleroma does",
+ "poll" => %{"options" => ["what Mastodon't", "n't what Mastodoes"], "expires_in" => 20}
+ })
+
+ object = Object.normalize(activity)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/polls/#{object.id}")
+
+ response = json_response(conn, 200)
+ id = object.id
+ assert %{"id" => ^id, "expired" => false, "multiple" => false} = response
+ end
+
+ test "does not expose polls for private statuses", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Pleroma does",
+ "poll" => %{"options" => ["what Mastodon't", "n't what Mastodoes"], "expires_in" => 20},
+ "visibility" => "private"
+ })
+
+ object = Object.normalize(activity)
+
+ conn =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/polls/#{object.id}")
+
+ assert json_response(conn, 404)
+ end
+ end
+
+ describe "POST /api/v1/polls/:id/votes" do
+ test "votes are added to the poll", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "A very delicious sandwich",
+ "poll" => %{
+ "options" => ["Lettuce", "Grilled Bacon", "Tomato"],
+ "expires_in" => 20,
+ "multiple" => true
+ }
+ })
+
+ object = Object.normalize(activity)
+
+ conn =
+ conn
+ |> assign(:user, other_user)
+ |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0, 1, 2]})
+
+ assert json_response(conn, 200)
+ object = Object.get_by_id(object.id)
+
+ assert Enum.all?(object.data["anyOf"], fn %{"replies" => %{"totalItems" => total_items}} ->
+ total_items == 1
+ end)
+ end
+
+ test "author can't vote", %{conn: conn} do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Am I cute?",
+ "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20}
+ })
+
+ object = Object.normalize(activity)
+
+ assert conn
+ |> assign(:user, user)
+ |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [1]})
+ |> json_response(422) == %{"error" => "Poll's author can't vote"}
+
+ object = Object.get_by_id(object.id)
+
+ refute Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 1
+ end
+
+ test "does not allow multiple choices on a single-choice question", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "The glass is",
+ "poll" => %{"options" => ["half empty", "half full"], "expires_in" => 20}
+ })
+
+ object = Object.normalize(activity)
+
+ assert conn
+ |> assign(:user, other_user)
+ |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0, 1]})
+ |> json_response(422) == %{"error" => "Too many choices"}
+
+ object = Object.get_by_id(object.id)
+
+ refute Enum.any?(object.data["oneOf"], fn %{"replies" => %{"totalItems" => total_items}} ->
+ total_items == 1
+ end)
+ end
+
+ test "does not allow choice index to be greater than options count", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Am I cute?",
+ "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20}
+ })
+
+ object = Object.normalize(activity)
+
+ conn =
+ conn
+ |> assign(:user, other_user)
+ |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [2]})
+
+ assert json_response(conn, 422) == %{"error" => "Invalid indices"}
+ end
+
+ test "returns 404 error when object is not exist", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/polls/1/votes", %{"choices" => [0]})
+
+ assert json_response(conn, 404) == %{"error" => "Record not found"}
+ end
+
+ test "returns 404 when poll is private and not available for user", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Am I cute?",
+ "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20},
+ "visibility" => "private"
+ })
+
+ object = Object.normalize(activity)
+
+ conn =
+ conn
+ |> assign(:user, other_user)
+ |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0]})
+
+ assert json_response(conn, 404) == %{"error" => "Record not found"}
+ end
+ end
+
+ describe "GET /api/v1/statuses/:id/favourited_by" do
+ setup do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+
+ [conn: conn, activity: activity]
+ end
+
+ test "returns users who have favorited the status", %{conn: conn, activity: activity} do
+ other_user = insert(:user)
+ {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
+
+ response =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}/favourited_by")
+ |> json_response(:ok)
+
+ [%{"id" => id}] = response
+
+ assert id == other_user.id
+ end
+
+ test "returns empty array when status has not been favorited yet", %{
+ conn: conn,
+ activity: activity
+ } do
+ response =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}/favourited_by")
+ |> json_response(:ok)
+
+ assert Enum.empty?(response)
+ end
+ end
+
+ describe "GET /api/v1/statuses/:id/reblogged_by" do
+ setup do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+
+ [conn: conn, activity: activity]
+ end
+
+ test "returns users who have reblogged the status", %{conn: conn, activity: activity} do
+ other_user = insert(:user)
+ {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
+
+ response =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
+ |> json_response(:ok)
+
+ [%{"id" => id}] = response
+
+ assert id == other_user.id
+ end
+
+ test "returns empty array when status has not been reblogged yet", %{
+ conn: conn,
+ activity: activity
+ } do
+ response =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
+ |> json_response(:ok)
+
+ assert Enum.empty?(response)
end
end
end
diff --git a/test/web/mastodon_api/search_controller_test.exs b/test/web/mastodon_api/search_controller_test.exs
new file mode 100644
index 000000000..9f50c09f4
--- /dev/null
+++ b/test/web/mastodon_api/search_controller_test.exs
@@ -0,0 +1,267 @@
+# 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.SearchControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Object
+ alias Pleroma.Web
+ alias Pleroma.Web.CommonAPI
+ import Pleroma.Factory
+ import ExUnit.CaptureLog
+ import Tesla.Mock
+ import Mock
+
+ setup do
+ mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
+ describe ".search2" do
+ test "it returns empty result if user or status search return undefined error", %{conn: conn} do
+ with_mocks [
+ {Pleroma.User, [], [search: fn _q, _o -> raise "Oops" end]},
+ {Pleroma.Activity, [], [search: fn _u, _q, _o -> raise "Oops" end]}
+ ] do
+ conn = get(conn, "/api/v2/search", %{"q" => "2hu"})
+
+ assert results = json_response(conn, 200)
+
+ assert results["accounts"] == []
+ assert results["statuses"] == []
+ end
+ end
+
+ test "search", %{conn: conn} do
+ user = insert(:user)
+ user_two = insert(:user, %{nickname: "shp@shitposter.club"})
+ user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu private"})
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{
+ "status" => "This is about 2hu, but private",
+ "visibility" => "private"
+ })
+
+ {:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"})
+
+ conn = get(conn, "/api/v2/search", %{"q" => "2hu #private"})
+
+ assert results = json_response(conn, 200)
+
+ [account | _] = results["accounts"]
+ assert account["id"] == to_string(user_three.id)
+
+ assert results["hashtags"] == [
+ %{"name" => "private", "url" => "#{Web.base_url()}/tag/private"}
+ ]
+
+ [status] = results["statuses"]
+ assert status["id"] == to_string(activity.id)
+ end
+ end
+
+ describe ".account_search" do
+ test "account search", %{conn: conn} do
+ user = insert(:user)
+ user_two = insert(:user, %{nickname: "shp@shitposter.club"})
+ user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
+
+ results =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/search", %{"q" => "shp"})
+ |> json_response(200)
+
+ result_ids = for result <- results, do: result["acct"]
+
+ assert user_two.nickname in result_ids
+ assert user_three.nickname in result_ids
+
+ results =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/search", %{"q" => "2hu"})
+ |> json_response(200)
+
+ result_ids = for result <- results, do: result["acct"]
+
+ assert user_three.nickname in result_ids
+ end
+ end
+
+ describe ".search" do
+ test "it returns empty result if user or status search return undefined error", %{conn: conn} do
+ with_mocks [
+ {Pleroma.User, [], [search: fn _q, _o -> raise "Oops" end]},
+ {Pleroma.Activity, [], [search: fn _u, _q, _o -> raise "Oops" end]}
+ ] do
+ conn =
+ conn
+ |> get("/api/v1/search", %{"q" => "2hu"})
+
+ assert results = json_response(conn, 200)
+
+ assert results["accounts"] == []
+ assert results["statuses"] == []
+ end
+ end
+
+ test "search", %{conn: conn} do
+ user = insert(:user)
+ user_two = insert(:user, %{nickname: "shp@shitposter.club"})
+ user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu"})
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{
+ "status" => "This is about 2hu, but private",
+ "visibility" => "private"
+ })
+
+ {:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"})
+
+ conn =
+ conn
+ |> get("/api/v1/search", %{"q" => "2hu"})
+
+ assert results = json_response(conn, 200)
+
+ [account | _] = results["accounts"]
+ assert account["id"] == to_string(user_three.id)
+
+ assert results["hashtags"] == []
+
+ [status] = results["statuses"]
+ assert status["id"] == to_string(activity.id)
+ end
+
+ test "search fetches remote statuses", %{conn: conn} do
+ capture_log(fn ->
+ conn =
+ conn
+ |> get("/api/v1/search", %{"q" => "https://shitposter.club/notice/2827873"})
+
+ assert results = json_response(conn, 200)
+
+ [status] = results["statuses"]
+
+ assert status["uri"] ==
+ "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
+ end)
+ end
+
+ test "search doesn't show statuses that it shouldn't", %{conn: conn} do
+ {:ok, activity} =
+ CommonAPI.post(insert(:user), %{
+ "status" => "This is about 2hu, but private",
+ "visibility" => "private"
+ })
+
+ capture_log(fn ->
+ conn =
+ conn
+ |> get("/api/v1/search", %{"q" => Object.normalize(activity).data["id"]})
+
+ assert results = json_response(conn, 200)
+
+ [] = results["statuses"]
+ end)
+ end
+
+ test "search fetches remote accounts", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/search", %{"q" => "shp@social.heldscal.la", "resolve" => "true"})
+
+ assert results = json_response(conn, 200)
+ [account] = results["accounts"]
+ assert account["acct"] == "shp@social.heldscal.la"
+ end
+
+ test "search doesn't fetch remote accounts if resolve is false", %{conn: conn} do
+ conn =
+ conn
+ |> get("/api/v1/search", %{"q" => "shp@social.heldscal.la", "resolve" => "false"})
+
+ assert results = json_response(conn, 200)
+ assert [] == results["accounts"]
+ end
+
+ test "search with limit and offset", %{conn: conn} do
+ user = insert(:user)
+ _user_two = insert(:user, %{nickname: "shp@shitposter.club"})
+ _user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
+
+ {:ok, _activity1} = CommonAPI.post(user, %{"status" => "This is about 2hu"})
+ {:ok, _activity2} = CommonAPI.post(user, %{"status" => "This is also about 2hu"})
+
+ result =
+ conn
+ |> get("/api/v1/search", %{"q" => "2hu", "limit" => 1})
+
+ assert results = json_response(result, 200)
+ assert [%{"id" => activity_id1}] = results["statuses"]
+ assert [_] = results["accounts"]
+
+ results =
+ conn
+ |> get("/api/v1/search", %{"q" => "2hu", "limit" => 1, "offset" => 1})
+ |> json_response(200)
+
+ assert [%{"id" => activity_id2}] = results["statuses"]
+ assert [] = results["accounts"]
+
+ assert activity_id1 != activity_id2
+ end
+
+ test "search returns results only for the given type", %{conn: conn} do
+ user = insert(:user)
+ _user_two = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
+
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => "This is about 2hu"})
+
+ assert %{"statuses" => [_activity], "accounts" => [], "hashtags" => []} =
+ conn
+ |> get("/api/v1/search", %{"q" => "2hu", "type" => "statuses"})
+ |> json_response(200)
+
+ assert %{"statuses" => [], "accounts" => [_user_two], "hashtags" => []} =
+ conn
+ |> get("/api/v1/search", %{"q" => "2hu", "type" => "accounts"})
+ |> json_response(200)
+ end
+
+ test "search uses account_id to filter statuses by the author", %{conn: conn} do
+ user = insert(:user, %{nickname: "shp@shitposter.club"})
+ user_two = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
+
+ {:ok, activity1} = CommonAPI.post(user, %{"status" => "This is about 2hu"})
+ {:ok, activity2} = CommonAPI.post(user_two, %{"status" => "This is also about 2hu"})
+
+ results =
+ conn
+ |> get("/api/v1/search", %{"q" => "2hu", "account_id" => user.id})
+ |> json_response(200)
+
+ assert [%{"id" => activity_id1}] = results["statuses"]
+ assert activity_id1 == activity1.id
+ assert [_] = results["accounts"]
+
+ results =
+ conn
+ |> get("/api/v1/search", %{"q" => "2hu", "account_id" => user_two.id})
+ |> json_response(200)
+
+ assert [%{"id" => activity_id2}] = results["statuses"]
+ assert activity_id2 == activity2.id
+ end
+ end
+end
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index d7c800e83..995bd52c8 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -55,7 +55,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
test "a note with null content" do
note = insert(:note_activity)
- note_object = Object.normalize(note.data["object"])
+ note_object = Object.normalize(note)
data =
note_object.data
@@ -73,26 +73,27 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
test "a note activity" do
note = insert(:note_activity)
+ object_data = Object.normalize(note).data
user = User.get_cached_by_ap_id(note.data["actor"])
- convo_id = Utils.context_to_conversation_id(note.data["object"]["context"])
+ convo_id = Utils.context_to_conversation_id(object_data["context"])
status = StatusView.render("status.json", %{activity: note})
created_at =
- (note.data["object"]["published"] || "")
+ (object_data["published"] || "")
|> String.replace(~r/\.\d+Z/, ".000Z")
expected = %{
id: to_string(note.id),
- uri: note.data["object"]["id"],
+ uri: object_data["id"],
url: Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, note),
account: AccountView.render("account.json", %{user: user}),
in_reply_to_id: nil,
in_reply_to_account_id: nil,
card: nil,
reblog: nil,
- content: HtmlSanitizeEx.basic_html(note.data["object"]["content"]),
+ content: HtmlSanitizeEx.basic_html(object_data["content"]),
created_at: created_at,
reblogs_count: 0,
replies_count: 0,
@@ -103,14 +104,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
muted: false,
pinned: false,
sensitive: false,
- spoiler_text: HtmlSanitizeEx.basic_html(note.data["object"]["summary"]),
+ poll: nil,
+ spoiler_text: HtmlSanitizeEx.basic_html(object_data["summary"]),
visibility: "public",
media_attachments: [],
mentions: [],
tags: [
%{
- name: "#{note.data["object"]["tag"]}",
- url: "/tag/#{note.data["object"]["tag"]}"
+ name: "#{object_data["tag"]}",
+ url: "/tag/#{object_data["tag"]}"
}
],
application: %{
@@ -130,8 +132,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
local: true,
conversation_id: convo_id,
in_reply_to_account_acct: nil,
- content: %{"text/plain" => HtmlSanitizeEx.strip_tags(note.data["object"]["content"])},
- spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(note.data["object"]["summary"])}
+ content: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["content"])},
+ spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["summary"])}
}
}
@@ -201,10 +203,71 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
status = StatusView.render("status.json", %{activity: activity})
- actor = User.get_cached_by_ap_id(activity.actor)
-
assert status.mentions ==
- Enum.map([user, actor], fn u -> AccountView.render("mention.json", %{user: u}) end)
+ Enum.map([user], fn u -> AccountView.render("mention.json", %{user: u}) end)
+ end
+
+ test "create mentions from the 'to' field" do
+ %User{ap_id: recipient_ap_id} = insert(:user)
+ cc = insert_pair(:user) |> Enum.map(& &1.ap_id)
+
+ object =
+ insert(:note, %{
+ data: %{
+ "to" => [recipient_ap_id],
+ "cc" => cc
+ }
+ })
+
+ activity =
+ insert(:note_activity, %{
+ note: object,
+ recipients: [recipient_ap_id | cc]
+ })
+
+ assert length(activity.recipients) == 3
+
+ %{mentions: [mention] = mentions} = StatusView.render("status.json", %{activity: activity})
+
+ assert length(mentions) == 1
+ assert mention.url == recipient_ap_id
+ end
+
+ test "create mentions from the 'tag' field" do
+ recipient = insert(:user)
+ cc = insert_pair(:user) |> Enum.map(& &1.ap_id)
+
+ object =
+ insert(:note, %{
+ data: %{
+ "cc" => cc,
+ "tag" => [
+ %{
+ "href" => recipient.ap_id,
+ "name" => recipient.nickname,
+ "type" => "Mention"
+ },
+ %{
+ "href" => "https://example.com/search?tag=test",
+ "name" => "#test",
+ "type" => "Hashtag"
+ }
+ ]
+ }
+ })
+
+ activity =
+ insert(:note_activity, %{
+ note: object,
+ recipients: [recipient.ap_id | cc]
+ })
+
+ assert length(activity.recipients) == 3
+
+ %{mentions: [mention] = mentions} = StatusView.render("status.json", %{activity: activity})
+
+ assert length(mentions) == 1
+ assert mention.url == recipient.ap_id
end
test "attachments" do
@@ -341,4 +404,154 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
StatusView.render("card.json", %{page_url: page_url, rich_media: card})
end
end
+
+ describe "poll view" do
+ test "renders a poll" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Is Tenshi eating a corndog cute?",
+ "poll" => %{
+ "options" => ["absolutely!", "sure", "yes", "why are you even asking?"],
+ "expires_in" => 20
+ }
+ })
+
+ object = Object.normalize(activity)
+
+ expected = %{
+ emojis: [],
+ expired: false,
+ id: object.id,
+ multiple: false,
+ options: [
+ %{title: "absolutely!", votes_count: 0},
+ %{title: "sure", votes_count: 0},
+ %{title: "yes", votes_count: 0},
+ %{title: "why are you even asking?", votes_count: 0}
+ ],
+ voted: false,
+ votes_count: 0
+ }
+
+ result = StatusView.render("poll.json", %{object: object})
+ expires_at = result.expires_at
+ result = Map.delete(result, :expires_at)
+
+ assert result == expected
+
+ expires_at = NaiveDateTime.from_iso8601!(expires_at)
+ assert NaiveDateTime.diff(expires_at, NaiveDateTime.utc_now()) in 15..20
+ end
+
+ test "detects if it is multiple choice" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Which Mastodon developer is your favourite?",
+ "poll" => %{
+ "options" => ["Gargron", "Eugen"],
+ "expires_in" => 20,
+ "multiple" => true
+ }
+ })
+
+ object = Object.normalize(activity)
+
+ assert %{multiple: true} = StatusView.render("poll.json", %{object: object})
+ end
+
+ test "detects emoji" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "What's with the smug face?",
+ "poll" => %{
+ "options" => [":blank: sip", ":blank::blank: sip", ":blank::blank::blank: sip"],
+ "expires_in" => 20
+ }
+ })
+
+ object = Object.normalize(activity)
+
+ assert %{emojis: [%{shortcode: "blank"}]} =
+ StatusView.render("poll.json", %{object: object})
+ end
+
+ test "detects vote status" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Which input devices do you use?",
+ "poll" => %{
+ "options" => ["mouse", "trackball", "trackpoint"],
+ "multiple" => true,
+ "expires_in" => 20
+ }
+ })
+
+ object = Object.normalize(activity)
+
+ {:ok, _, object} = CommonAPI.vote(other_user, object, [1, 2])
+
+ result = StatusView.render("poll.json", %{object: object, for: other_user})
+
+ assert result[:voted] == true
+ assert Enum.at(result[:options], 1)[:votes_count] == 1
+ assert Enum.at(result[:options], 2)[:votes_count] == 1
+ end
+ end
+
+ test "embeds a relationship in the account" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "drink more water"
+ })
+
+ result = StatusView.render("status.json", %{activity: activity, for: other_user})
+
+ assert result[:account][:pleroma][:relationship] ==
+ AccountView.render("relationship.json", %{user: other_user, target: user})
+ end
+
+ test "embeds a relationship in the account in reposts" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "˙˙ɐʎns"
+ })
+
+ {:ok, activity, _object} = CommonAPI.repeat(activity.id, other_user)
+
+ result = StatusView.render("status.json", %{activity: activity, for: user})
+
+ assert result[:account][:pleroma][:relationship] ==
+ AccountView.render("relationship.json", %{user: user, target: other_user})
+
+ assert result[:reblog][:account][:pleroma][:relationship] ==
+ AccountView.render("relationship.json", %{user: user, target: user})
+ end
+
+ test "visibility/list" do
+ user = insert(:user)
+
+ {:ok, list} = Pleroma.List.create("foo", user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
+
+ status = StatusView.render("status.json", activity: activity)
+
+ assert status.visibility == "list"
+ end
end
diff --git a/test/web/media_proxy/media_proxy_controller_test.exs b/test/web/media_proxy/media_proxy_controller_test.exs
new file mode 100644
index 000000000..53b8f556b
--- /dev/null
+++ b/test/web/media_proxy/media_proxy_controller_test.exs
@@ -0,0 +1,73 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
+ use Pleroma.Web.ConnCase
+ import Mock
+ alias Pleroma.Config
+
+ setup do
+ media_proxy_config = Config.get([:media_proxy]) || []
+ on_exit(fn -> Config.put([:media_proxy], media_proxy_config) end)
+ :ok
+ end
+
+ test "it returns 404 when MediaProxy disabled", %{conn: conn} do
+ Config.put([:media_proxy, :enabled], false)
+
+ assert %Plug.Conn{
+ status: 404,
+ resp_body: "Not Found"
+ } = get(conn, "/proxy/hhgfh/eeeee")
+
+ assert %Plug.Conn{
+ status: 404,
+ resp_body: "Not Found"
+ } = get(conn, "/proxy/hhgfh/eeee/fff")
+ end
+
+ test "it returns 403 when signature invalidated", %{conn: conn} do
+ Config.put([:media_proxy, :enabled], true)
+ Config.put([Pleroma.Web.Endpoint, :secret_key_base], "00000000000")
+ path = URI.parse(Pleroma.Web.MediaProxy.encode_url("https://google.fn")).path
+ Config.put([Pleroma.Web.Endpoint, :secret_key_base], "000")
+
+ assert %Plug.Conn{
+ status: 403,
+ resp_body: "Forbidden"
+ } = get(conn, path)
+
+ assert %Plug.Conn{
+ status: 403,
+ resp_body: "Forbidden"
+ } = get(conn, "/proxy/hhgfh/eeee")
+
+ assert %Plug.Conn{
+ status: 403,
+ resp_body: "Forbidden"
+ } = get(conn, "/proxy/hhgfh/eeee/fff")
+ end
+
+ test "redirects on valid url when filename invalidated", %{conn: conn} do
+ Config.put([:media_proxy, :enabled], true)
+ Config.put([Pleroma.Web.Endpoint, :secret_key_base], "00000000000")
+ url = Pleroma.Web.MediaProxy.encode_url("https://google.fn/test.png")
+ invalid_url = String.replace(url, "test.png", "test-file.png")
+ response = get(conn, invalid_url)
+ html = "<html><body>You are being <a href=\"#{url}\">redirected</a>.</body></html>"
+ assert response.status == 302
+ assert response.resp_body == html
+ end
+
+ test "it performs ReverseProxy.call when signature valid", %{conn: conn} do
+ Config.put([:media_proxy, :enabled], true)
+ Config.put([Pleroma.Web.Endpoint, :secret_key_base], "00000000000")
+ url = Pleroma.Web.MediaProxy.encode_url("https://google.fn/test.png")
+
+ with_mock Pleroma.ReverseProxy,
+ call: fn _conn, _url, _opts -> %Plug.Conn{status: :success} end do
+ assert %Plug.Conn{status: :success} = get(conn, url)
+ end
+ end
+end
diff --git a/test/media_proxy_test.exs b/test/web/media_proxy/media_proxy_test.exs
index 0a02039a6..cb4807e0b 100644
--- a/test/media_proxy_test.exs
+++ b/test/web/media_proxy/media_proxy_test.exs
@@ -2,7 +2,7 @@
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.MediaProxyTest do
+defmodule Pleroma.Web.MediaProxyTest do
use ExUnit.Case
import Pleroma.Web.MediaProxy
alias Pleroma.Web.MediaProxy.MediaProxyController
@@ -70,14 +70,6 @@ defmodule Pleroma.MediaProxyTest do
assert decode_result(encoded) == url
end
- test "ensures urls are url-encoded" do
- assert decode_result(url("https://pleroma.social/Hello world.jpg")) ==
- "https://pleroma.social/Hello%20world.jpg"
-
- assert decode_result(url("https://pleroma.social/Hello%20world.jpg")) ==
- "https://pleroma.social/Hello%20world.jpg"
- end
-
test "validates signature" do
secret_key_base = Pleroma.Config.get([Pleroma.Web.Endpoint, :secret_key_base])
@@ -96,32 +88,30 @@ defmodule Pleroma.MediaProxyTest do
assert decode_url(sig, base64) == {:error, :invalid_signature}
end
- test "filename_matches matches url encoded paths" do
+ test "filename_matches preserves the encoded or decoded path" do
assert MediaProxyController.filename_matches(
- true,
- "/Hello%20world.jpg",
+ %{"filename" => "/Hello world.jpg"},
+ "/Hello world.jpg",
"http://pleroma.social/Hello world.jpg"
) == :ok
assert MediaProxyController.filename_matches(
- true,
+ %{"filename" => "/Hello%20world.jpg"},
"/Hello%20world.jpg",
"http://pleroma.social/Hello%20world.jpg"
) == :ok
- end
- test "filename_matches matches non-url encoded paths" do
assert MediaProxyController.filename_matches(
- true,
- "/Hello world.jpg",
- "http://pleroma.social/Hello%20world.jpg"
+ %{"filename" => "/my%2Flong%2Furl%2F2019%2F07%2FS.jpg"},
+ "/my%2Flong%2Furl%2F2019%2F07%2FS.jpg",
+ "http://pleroma.social/my%2Flong%2Furl%2F2019%2F07%2FS.jpg"
) == :ok
assert MediaProxyController.filename_matches(
- true,
- "/Hello world.jpg",
- "http://pleroma.social/Hello world.jpg"
- ) == :ok
+ %{"filename" => "/my%2Flong%2Furl%2F2019%2F07%2FS.jp"},
+ "/my%2Flong%2Furl%2F2019%2F07%2FS.jp",
+ "http://pleroma.social/my%2Flong%2Furl%2F2019%2F07%2FS.jpg"
+ ) == {:wrong_filename, "my%2Flong%2Furl%2F2019%2F07%2FS.jpg"}
end
test "uses the configured base_url" do
@@ -141,14 +131,50 @@ defmodule Pleroma.MediaProxyTest do
assert String.starts_with?(encoded, Pleroma.Config.get([:media_proxy, :base_url]))
end
- # https://git.pleroma.social/pleroma/pleroma/issues/580
- test "encoding S3 links (must preserve `%2F`)" do
+ # Some sites expect ASCII encoded characters in the URL to be preserved even if
+ # unnecessary.
+ # Issues: https://git.pleroma.social/pleroma/pleroma/issues/580
+ # https://git.pleroma.social/pleroma/pleroma/issues/1055
+ test "preserve ASCII encoding" do
url =
- "https://s3.amazonaws.com/example/test.png?X-Amz-Credential=your-access-key-id%2F20130721%2Fus-east-1%2Fs3%2Faws4_request"
+ "https://pleroma.com/%20/%21/%22/%23/%24/%25/%26/%27/%28/%29/%2A/%2B/%2C/%2D/%2E/%2F/%30/%31/%32/%33/%34/%35/%36/%37/%38/%39/%3A/%3B/%3C/%3D/%3E/%3F/%40/%41/%42/%43/%44/%45/%46/%47/%48/%49/%4A/%4B/%4C/%4D/%4E/%4F/%50/%51/%52/%53/%54/%55/%56/%57/%58/%59/%5A/%5B/%5C/%5D/%5E/%5F/%60/%61/%62/%63/%64/%65/%66/%67/%68/%69/%6A/%6B/%6C/%6D/%6E/%6F/%70/%71/%72/%73/%74/%75/%76/%77/%78/%79/%7A/%7B/%7C/%7D/%7E/%7F/%80/%81/%82/%83/%84/%85/%86/%87/%88/%89/%8A/%8B/%8C/%8D/%8E/%8F/%90/%91/%92/%93/%94/%95/%96/%97/%98/%99/%9A/%9B/%9C/%9D/%9E/%9F/%C2%A0/%A1/%A2/%A3/%A4/%A5/%A6/%A7/%A8/%A9/%AA/%AB/%AC/%C2%AD/%AE/%AF/%B0/%B1/%B2/%B3/%B4/%B5/%B6/%B7/%B8/%B9/%BA/%BB/%BC/%BD/%BE/%BF/%C0/%C1/%C2/%C3/%C4/%C5/%C6/%C7/%C8/%C9/%CA/%CB/%CC/%CD/%CE/%CF/%D0/%D1/%D2/%D3/%D4/%D5/%D6/%D7/%D8/%D9/%DA/%DB/%DC/%DD/%DE/%DF/%E0/%E1/%E2/%E3/%E4/%E5/%E6/%E7/%E8/%E9/%EA/%EB/%EC/%ED/%EE/%EF/%F0/%F1/%F2/%F3/%F4/%F5/%F6/%F7/%F8/%F9/%FA/%FB/%FC/%FD/%FE/%FF"
encoded = url(url)
assert decode_result(encoded) == url
end
+
+ # This includes unsafe/reserved characters which are not interpreted as part of the URL
+ # and would otherwise have to be ASCII encoded. It is our role to ensure the proxied URL
+ # is unmodified, so we are testing these characters anyway.
+ test "preserve non-unicode characters per RFC3986" do
+ url =
+ "https://pleroma.com/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-._~:/?#[]@!$&'()*+,;=|^`{}"
+
+ encoded = url(url)
+ assert decode_result(encoded) == url
+ end
+
+ test "preserve unicode characters" do
+ url = "https://ko.wikipedia.org/wiki/위키백과:대문"
+
+ 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
diff --git a/test/web/metadata/player_view_test.exs b/test/web/metadata/player_view_test.exs
new file mode 100644
index 000000000..742b0ed8b
--- /dev/null
+++ b/test/web/metadata/player_view_test.exs
@@ -0,0 +1,33 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Metadata.PlayerViewTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.Metadata.PlayerView
+
+ test "it renders audio tag" do
+ res =
+ PlayerView.render(
+ "player.html",
+ %{"mediaType" => "audio", "href" => "test-href"}
+ )
+ |> Phoenix.HTML.safe_to_string()
+
+ assert res ==
+ "<audio controls><source src=\"test-href\" type=\"audio\">Your browser does not support audio playback.</audio>"
+ end
+
+ test "it renders videos tag" do
+ res =
+ PlayerView.render(
+ "player.html",
+ %{"mediaType" => "video", "href" => "test-href"}
+ )
+ |> Phoenix.HTML.safe_to_string()
+
+ assert res ==
+ "<video controls loop><source src=\"test-href\" type=\"video\">Your browser does not support video playback.</video>"
+ end
+end
diff --git a/test/web/metadata/rel_me_test.exs b/test/web/metadata/rel_me_test.exs
index f66bf7834..3874e077b 100644
--- a/test/web/metadata/rel_me_test.exs
+++ b/test/web/metadata/rel_me_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.Metadata.Providers.RelMeTest do
use Pleroma.DataCase
import Pleroma.Factory
diff --git a/test/web/metadata/twitter_card_test.exs b/test/web/metadata/twitter_card_test.exs
new file mode 100644
index 000000000..0814006d2
--- /dev/null
+++ b/test/web/metadata/twitter_card_test.exs
@@ -0,0 +1,123 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.Endpoint
+ alias Pleroma.Web.Metadata.Providers.TwitterCard
+ alias Pleroma.Web.Metadata.Utils
+ alias Pleroma.Web.Router
+
+ test "it renders twitter card for user info" do
+ user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
+ avatar_url = Utils.attachment_url(User.avatar_url(user))
+ res = TwitterCard.build_tags(%{user: user})
+
+ assert res == [
+ {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
+ {:meta, [property: "twitter:description", content: "born 19 March 1994"], []},
+ {:meta, [property: "twitter:image", content: avatar_url], []},
+ {:meta, [property: "twitter:card", content: "summary"], []}
+ ]
+ end
+
+ test "it does not render attachments if post is nsfw" do
+ Pleroma.Config.put([Pleroma.Web.Metadata, :unfurl_nsfw], false)
+ user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "HI"})
+
+ note =
+ insert(:note, %{
+ data: %{
+ "actor" => user.ap_id,
+ "tag" => [],
+ "id" => "https://pleroma.gov/objects/whatever",
+ "content" => "pleroma in a nutshell",
+ "sensitive" => true,
+ "attachment" => [
+ %{
+ "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}]
+ },
+ %{
+ "url" => [
+ %{
+ "mediaType" => "application/octet-stream",
+ "href" => "https://pleroma.gov/fqa/badapple.sfc"
+ }
+ ]
+ },
+ %{
+ "url" => [
+ %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
+ ]
+ }
+ ]
+ }
+ })
+
+ result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
+
+ assert [
+ {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
+ {:meta, [property: "twitter:description", content: "“pleroma in a nutshell”"], []},
+ {:meta, [property: "twitter:image", content: "http://localhost:4001/images/avi.png"],
+ []},
+ {:meta, [property: "twitter:card", content: "summary_large_image"], []}
+ ] == result
+ end
+
+ test "it renders supported types of attachments and skips unknown types" do
+ user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "HI"})
+
+ note =
+ insert(:note, %{
+ data: %{
+ "actor" => user.ap_id,
+ "tag" => [],
+ "id" => "https://pleroma.gov/objects/whatever",
+ "content" => "pleroma in a nutshell",
+ "attachment" => [
+ %{
+ "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}]
+ },
+ %{
+ "url" => [
+ %{
+ "mediaType" => "application/octet-stream",
+ "href" => "https://pleroma.gov/fqa/badapple.sfc"
+ }
+ ]
+ },
+ %{
+ "url" => [
+ %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
+ ]
+ }
+ ]
+ }
+ })
+
+ result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
+
+ assert [
+ {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
+ {:meta, [property: "twitter:description", content: "“pleroma in a nutshell”"], []},
+ {:meta, [property: "twitter:card", content: "summary_large_image"], []},
+ {:meta, [property: "twitter:player", content: "https://pleroma.gov/tenshi.png"], []},
+ {:meta, [property: "twitter:card", content: "player"], []},
+ {:meta,
+ [
+ property: "twitter:player",
+ content: Router.Helpers.o_status_url(Endpoint, :notice_player, activity.id)
+ ], []},
+ {:meta, [property: "twitter:player:width", content: "480"], []},
+ {:meta, [property: "twitter:player:height", content: "480"], []}
+ ] == result
+ end
+end
diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs
index be1173513..d7f848bfa 100644
--- a/test/web/node_info_test.exs
+++ b/test/web/node_info_test.exs
@@ -83,4 +83,47 @@ defmodule Pleroma.Web.NodeInfoTest do
Pleroma.Config.put([:instance, :safe_dm_mentions], option)
end
+
+ test "it shows MRF transparency data if enabled", %{conn: conn} do
+ option = Pleroma.Config.get([:instance, :mrf_transparency])
+ Pleroma.Config.put([:instance, :mrf_transparency], true)
+
+ simple_config = %{"reject" => ["example.com"]}
+ Pleroma.Config.put(:mrf_simple, simple_config)
+
+ response =
+ conn
+ |> get("/nodeinfo/2.1.json")
+ |> json_response(:ok)
+
+ assert response["metadata"]["federation"]["mrf_simple"] == simple_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
+ option = Pleroma.Config.get([:instance, :mrf_transparency])
+ Pleroma.Config.put([:instance, :mrf_transparency], true)
+
+ exclusions = Pleroma.Config.get([:instance, :mrf_transparency_exclusions])
+ Pleroma.Config.put([:instance, :mrf_transparency_exclusions], ["other.site"])
+
+ simple_config = %{"reject" => ["example.com", "other.site"]}
+ expected_config = %{"reject" => ["example.com"]}
+
+ Pleroma.Config.put(:mrf_simple, simple_config)
+
+ response =
+ conn
+ |> get("/nodeinfo/2.1.json")
+ |> json_response(:ok)
+
+ assert response["metadata"]["federation"]["mrf_simple"] == expected_config
+ assert response["metadata"]["federation"]["exclusions"] == true
+
+ Pleroma.Config.put([:instance, :mrf_transparency], option)
+ Pleroma.Config.put([:instance, :mrf_transparency_exclusions], exclusions)
+ Pleroma.Config.put(:mrf_simple, %{})
+ end
end
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index 1c04ac9ad..aae34804d 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -10,6 +10,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
alias Pleroma.Registration
alias Pleroma.Repo
alias Pleroma.Web.OAuth.Authorization
+ alias Pleroma.Web.OAuth.OAuthController
alias Pleroma.Web.OAuth.Token
@oauth_config_path [:oauth2, :issue_new_refresh_token]
@@ -49,7 +50,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
%{
"response_type" => "code",
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => OAuthController.default_redirect_uri(app),
"scope" => "read"
}
)
@@ -72,7 +73,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"authorization" => %{
"scope" => "read follow",
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => OAuthController.default_redirect_uri(app),
"state" => "a_state"
}
}
@@ -98,11 +99,12 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
test "with user-bound registration, GET /oauth/<provider>/callback redirects to `redirect_uri` with `code`",
%{app: app, conn: conn} do
registration = insert(:registration)
+ redirect_uri = OAuthController.default_redirect_uri(app)
state_params = %{
"scope" => Enum.join(app.scopes, " "),
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => redirect_uri,
"state" => ""
}
@@ -121,7 +123,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
)
assert response = html_response(conn, 302)
- assert redirected_to(conn) =~ ~r/#{app.redirect_uris}\?code=.+/
+ assert redirected_to(conn) =~ ~r/#{redirect_uri}\?code=.+/
end
end
@@ -132,7 +134,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
state_params = %{
"scope" => "read write",
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => OAuthController.default_redirect_uri(app),
"state" => "a_state"
}
@@ -165,7 +167,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
state_params = %{
"scope" => Enum.join(app.scopes, " "),
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => OAuthController.default_redirect_uri(app),
"state" => ""
}
@@ -199,7 +201,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"authorization" => %{
"scopes" => app.scopes,
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => OAuthController.default_redirect_uri(app),
"state" => "a_state",
"nickname" => nil,
"email" => "john@doe.com"
@@ -218,6 +220,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
conn: conn
} do
registration = insert(:registration, user: nil, info: %{"nickname" => nil, "email" => nil})
+ redirect_uri = OAuthController.default_redirect_uri(app)
conn =
conn
@@ -229,7 +232,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"authorization" => %{
"scopes" => app.scopes,
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => redirect_uri,
"state" => "a_state",
"nickname" => "availablenick",
"email" => "available@email.com"
@@ -238,7 +241,36 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
)
assert response = html_response(conn, 302)
- assert redirected_to(conn) =~ ~r/#{app.redirect_uris}\?code=.+/
+ assert redirected_to(conn) =~ ~r/#{redirect_uri}\?code=.+/
+ end
+
+ test "with unlisted `redirect_uri`, POST /oauth/register?op=register results in HTTP 401",
+ %{
+ app: app,
+ conn: conn
+ } do
+ registration = insert(:registration, user: nil, info: %{"nickname" => nil, "email" => nil})
+ unlisted_redirect_uri = "http://cross-site-request.com"
+
+ conn =
+ conn
+ |> put_session(:registration_id, registration.id)
+ |> post(
+ "/oauth/register",
+ %{
+ "op" => "register",
+ "authorization" => %{
+ "scopes" => app.scopes,
+ "client_id" => app.client_id,
+ "redirect_uri" => unlisted_redirect_uri,
+ "state" => "a_state",
+ "nickname" => "availablenick",
+ "email" => "available@email.com"
+ }
+ }
+ )
+
+ assert response = html_response(conn, 401)
end
test "with invalid params, POST /oauth/register?op=register renders registration_details page",
@@ -254,7 +286,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"authorization" => %{
"scopes" => app.scopes,
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => OAuthController.default_redirect_uri(app),
"state" => "a_state",
"nickname" => "availablenickname",
"email" => "available@email.com"
@@ -286,6 +318,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
} do
user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt("testpassword"))
registration = insert(:registration, user: nil)
+ redirect_uri = OAuthController.default_redirect_uri(app)
conn =
conn
@@ -297,7 +330,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"authorization" => %{
"scopes" => app.scopes,
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => redirect_uri,
"state" => "a_state",
"name" => user.nickname,
"password" => "testpassword"
@@ -306,7 +339,37 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
)
assert response = html_response(conn, 302)
- assert redirected_to(conn) =~ ~r/#{app.redirect_uris}\?code=.+/
+ assert redirected_to(conn) =~ ~r/#{redirect_uri}\?code=.+/
+ end
+
+ test "with unlisted `redirect_uri`, POST /oauth/register?op=connect results in HTTP 401`",
+ %{
+ app: app,
+ conn: conn
+ } do
+ user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt("testpassword"))
+ registration = insert(:registration, user: nil)
+ unlisted_redirect_uri = "http://cross-site-request.com"
+
+ conn =
+ conn
+ |> put_session(:registration_id, registration.id)
+ |> post(
+ "/oauth/register",
+ %{
+ "op" => "connect",
+ "authorization" => %{
+ "scopes" => app.scopes,
+ "client_id" => app.client_id,
+ "redirect_uri" => unlisted_redirect_uri,
+ "state" => "a_state",
+ "name" => user.nickname,
+ "password" => "testpassword"
+ }
+ }
+ )
+
+ assert response = html_response(conn, 401)
end
test "with invalid params, POST /oauth/register?op=connect renders registration_details page",
@@ -322,7 +385,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"authorization" => %{
"scopes" => app.scopes,
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => OAuthController.default_redirect_uri(app),
"state" => "a_state",
"name" => user.nickname,
"password" => "wrong password"
@@ -358,7 +421,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
%{
"response_type" => "code",
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => OAuthController.default_redirect_uri(app),
"scope" => "read"
}
)
@@ -378,7 +441,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"authorization" => %{
"response_type" => "code",
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => OAuthController.default_redirect_uri(app),
"scope" => "read"
}
}
@@ -399,7 +462,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
%{
"response_type" => "code",
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => OAuthController.default_redirect_uri(app),
"scope" => "read",
"force_login" => "true"
}
@@ -408,7 +471,61 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
assert html_response(conn, 200) =~ ~s(type="submit")
end
- test "redirects to app if user is already authenticated", %{app: app, conn: conn} do
+ test "with existing authentication and non-OOB `redirect_uri`, redirects to app with `token` and `state` params",
+ %{
+ app: app,
+ conn: conn
+ } do
+ token = insert(:oauth_token, app_id: app.id)
+
+ conn =
+ conn
+ |> put_session(:oauth_token, token.token)
+ |> get(
+ "/oauth/authorize",
+ %{
+ "response_type" => "code",
+ "client_id" => app.client_id,
+ "redirect_uri" => OAuthController.default_redirect_uri(app),
+ "state" => "specific_client_state",
+ "scope" => "read"
+ }
+ )
+
+ assert URI.decode(redirected_to(conn)) ==
+ "https://redirect.url?access_token=#{token.token}&state=specific_client_state"
+ end
+
+ test "with existing authentication and unlisted non-OOB `redirect_uri`, redirects without credentials",
+ %{
+ app: app,
+ conn: conn
+ } do
+ unlisted_redirect_uri = "http://cross-site-request.com"
+ token = insert(:oauth_token, app_id: app.id)
+
+ conn =
+ conn
+ |> put_session(:oauth_token, token.token)
+ |> get(
+ "/oauth/authorize",
+ %{
+ "response_type" => "code",
+ "client_id" => app.client_id,
+ "redirect_uri" => unlisted_redirect_uri,
+ "state" => "specific_client_state",
+ "scope" => "read"
+ }
+ )
+
+ assert redirected_to(conn) == unlisted_redirect_uri
+ end
+
+ test "with existing authentication and OOB `redirect_uri`, redirects to app with `token` and `state` params",
+ %{
+ app: app,
+ conn: conn
+ } do
token = insert(:oauth_token, app_id: app.id)
conn =
@@ -419,12 +536,12 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
%{
"response_type" => "code",
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => "urn:ietf:wg:oauth:2.0:oob",
"scope" => "read"
}
)
- assert redirected_to(conn) == "https://redirect.url"
+ assert html_response(conn, 200) =~ "Authorization exists"
end
end
@@ -432,6 +549,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
test "redirects with oauth authorization" do
user = insert(:user)
app = insert(:oauth_app, scopes: ["read", "write", "follow"])
+ redirect_uri = OAuthController.default_redirect_uri(app)
conn =
build_conn()
@@ -440,14 +558,14 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"name" => user.nickname,
"password" => "test",
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => redirect_uri,
"scope" => "read write",
"state" => "statepassed"
}
})
target = redirected_to(conn)
- assert target =~ app.redirect_uris
+ assert target =~ redirect_uri
query = URI.parse(target).query |> URI.query_decoder() |> Map.new()
@@ -460,6 +578,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
test "returns 401 for wrong credentials", %{conn: conn} do
user = insert(:user)
app = insert(:oauth_app)
+ redirect_uri = OAuthController.default_redirect_uri(app)
result =
conn
@@ -468,7 +587,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"name" => user.nickname,
"password" => "wrong",
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => redirect_uri,
"state" => "statepassed",
"scope" => Enum.join(app.scopes, " ")
}
@@ -477,7 +596,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
# Keep the details
assert result =~ app.client_id
- assert result =~ app.redirect_uris
+ assert result =~ redirect_uri
# Error message
assert result =~ "Invalid Username/Password"
@@ -486,6 +605,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
test "returns 401 for missing scopes", %{conn: conn} do
user = insert(:user)
app = insert(:oauth_app)
+ redirect_uri = OAuthController.default_redirect_uri(app)
result =
conn
@@ -494,7 +614,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"name" => user.nickname,
"password" => "test",
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => redirect_uri,
"state" => "statepassed",
"scope" => ""
}
@@ -503,7 +623,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
# Keep the details
assert result =~ app.client_id
- assert result =~ app.redirect_uris
+ assert result =~ redirect_uri
# Error message
assert result =~ "This action is outside the authorized scopes"
@@ -512,6 +632,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
test "returns 401 for scopes beyond app scopes", %{conn: conn} do
user = insert(:user)
app = insert(:oauth_app, scopes: ["read", "write"])
+ redirect_uri = OAuthController.default_redirect_uri(app)
result =
conn
@@ -520,7 +641,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"name" => user.nickname,
"password" => "test",
"client_id" => app.client_id,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => redirect_uri,
"state" => "statepassed",
"scope" => "read write follow"
}
@@ -529,7 +650,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
# Keep the details
assert result =~ app.client_id
- assert result =~ app.redirect_uris
+ assert result =~ redirect_uri
# Error message
assert result =~ "This action is outside the authorized scopes"
@@ -548,7 +669,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|> post("/oauth/token", %{
"grant_type" => "authorization_code",
"code" => auth.token,
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => OAuthController.default_redirect_uri(app),
"client_id" => app.client_id,
"client_secret" => app.client_secret
})
@@ -602,7 +723,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|> post("/oauth/token", %{
"grant_type" => "authorization_code",
"code" => auth.token,
- "redirect_uri" => app.redirect_uris
+ "redirect_uri" => OAuthController.default_redirect_uri(app)
})
assert %{"access_token" => token, "scope" => scope} = json_response(conn, 200)
@@ -647,7 +768,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|> post("/oauth/token", %{
"grant_type" => "authorization_code",
"code" => auth.token,
- "redirect_uri" => app.redirect_uris
+ "redirect_uri" => OAuthController.default_redirect_uri(app)
})
assert resp = json_response(conn, 400)
@@ -726,7 +847,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|> post("/oauth/token", %{
"grant_type" => "authorization_code",
"code" => "Imobviouslyinvalid",
- "redirect_uri" => app.redirect_uris,
+ "redirect_uri" => OAuthController.default_redirect_uri(app),
"client_id" => app.client_id,
"client_secret" => app.client_secret
})
diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs
index 16ee02abb..a3a92ce5b 100644
--- a/test/web/ostatus/activity_representer_test.exs
+++ b/test/web/ostatus/activity_representer_test.exs
@@ -38,22 +38,23 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
test "a note activity" do
note_activity = insert(:note_activity)
+ object_data = Object.normalize(note_activity).data
user = User.get_cached_by_ap_id(note_activity.data["actor"])
expected = """
<activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
- <id>#{note_activity.data["object"]["id"]}</id>
+ <id>#{object_data["id"]}</id>
<title>New note by #{user.nickname}</title>
- <content type="html">#{note_activity.data["object"]["content"]}</content>
- <published>#{note_activity.data["object"]["published"]}</published>
- <updated>#{note_activity.data["object"]["published"]}</updated>
+ <content type="html">#{object_data["content"]}</content>
+ <published>#{object_data["published"]}</published>
+ <updated>#{object_data["published"]}</updated>
<ostatus:conversation ref="#{note_activity.data["context"]}">#{note_activity.data["context"]}</ostatus:conversation>
<link ref="#{note_activity.data["context"]}" rel="ostatus:conversation" />
- <summary>#{note_activity.data["object"]["summary"]}</summary>
- <link type="application/atom+xml" href="#{note_activity.data["object"]["id"]}" rel="self" />
- <link type="text/html" href="#{note_activity.data["object"]["id"]}" rel="alternate" />
+ <summary>#{object_data["summary"]}</summary>
+ <link type="application/atom+xml" href="#{object_data["id"]}" rel="self" />
+ <link type="text/html" href="#{object_data["id"]}" rel="alternate" />
<category term="2hu"/>
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
<link name="2hu" rel="emoji" href="corndog.png" />
@@ -106,7 +107,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
test "an announce activity" do
note = insert(:note_activity)
user = insert(:user)
- object = Object.get_cached_by_ap_id(note.data["object"]["id"])
+ object = Object.normalize(note)
{:ok, announce, _object} = ActivityPub.announce(user, object)
@@ -125,7 +126,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
<activity:verb>http://activitystrea.ms/schema/1.0/share</activity:verb>
<id>#{announce.data["id"]}</id>
<title>#{user.nickname} repeated a notice</title>
- <content type="html">RT #{note.data["object"]["content"]}</content>
+ <content type="html">RT #{object.data["content"]}</content>
<published>#{announce.data["published"]}</published>
<updated>#{announce.data["published"]}</updated>
<ostatus:conversation ref="#{announce.data["context"]}">#{announce.data["context"]}</ostatus:conversation>
diff --git a/test/web/ostatus/incoming_documents/delete_handling_test.exs b/test/web/ostatus/incoming_documents/delete_handling_test.exs
index ca6e61339..cd0447af7 100644
--- a/test/web/ostatus/incoming_documents/delete_handling_test.exs
+++ b/test/web/ostatus/incoming_documents/delete_handling_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
use Pleroma.DataCase
@@ -17,8 +21,9 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
test "it removes the mentioned activity" do
note = insert(:note_activity)
second_note = insert(:note_activity)
+ object = Object.normalize(note)
+ second_object = Object.normalize(second_note)
user = insert(:user)
- object = Object.get_by_ap_id(note.data["object"]["id"])
{:ok, like, _object} = Pleroma.Web.ActivityPub.ActivityPub.like(user, object)
@@ -26,16 +31,16 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
File.read!("test/fixtures/delete.xml")
|> String.replace(
"tag:mastodon.sdf.org,2017-06-10:objectId=310513:objectType=Status",
- note.data["object"]["id"]
+ object.data["id"]
)
{:ok, [delete]} = OStatus.handle_incoming(incoming)
refute Activity.get_by_id(note.id)
refute Activity.get_by_id(like.id)
- assert Object.get_by_ap_id(note.data["object"]["id"]).data["type"] == "Tombstone"
+ assert Object.get_by_ap_id(object.data["id"]).data["type"] == "Tombstone"
assert Activity.get_by_id(second_note.id)
- assert Object.get_by_ap_id(second_note.data["object"]["id"])
+ assert Object.get_by_ap_id(second_object.data["id"])
assert delete.data["type"] == "Delete"
end
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index 7441e5fce..3dd8c6491 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -12,6 +12,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
@@ -65,6 +72,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
test "gets a feed", %{conn: conn} do
note_activity = insert(:note_activity)
+ object = Object.normalize(note_activity)
user = User.get_cached_by_ap_id(note_activity.data["actor"])
conn =
@@ -72,7 +80,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|> put_req_header("content-type", "application/atom+xml")
|> get("/users/#{user.nickname}/feed.atom")
- assert response(conn, 200) =~ note_activity.data["object"]["content"]
+ assert response(conn, 200) =~ object.data["content"]
end
test "returns 404 for a missing feed", %{conn: conn} do
@@ -86,8 +94,9 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest 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-]+)$/, note_activity.data["object"]["id"]))
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
url = "/objects/#{uuid}"
conn =
@@ -106,7 +115,8 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
test "404s on private objects", %{conn: conn} do
note_activity = insert(:direct_note_activity)
- [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
+ object = Object.normalize(note_activity)
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
conn
|> get("/objects/#{uuid}")
@@ -131,8 +141,8 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
test "404s on deleted objects", %{conn: conn} do
note_activity = insert(:note_activity)
- [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
- object = Object.get_by_ap_id(note_activity.data["object"]["id"])
+ object = Object.normalize(note_activity)
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
conn
|> put_req_header("accept", "application/xml")
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index f6be16862..4e8f3a0fc 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -11,8 +11,10 @@ defmodule Pleroma.Web.OStatusTest do
alias Pleroma.User
alias Pleroma.Web.OStatus
alias Pleroma.Web.XML
- import Pleroma.Factory
+
import ExUnit.CaptureLog
+ import Mock
+ import Pleroma.Factory
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
@@ -28,7 +30,7 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming note - GS, Salmon" do
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity)
user = User.get_cached_by_ap_id(activity.data["actor"])
assert user.info.note_count == 1
@@ -51,7 +53,7 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming notes - GS, subscription" do
incoming = File.read!("test/fixtures/ostatus_incoming_post.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity)
assert activity.data["type"] == "Create"
assert object.data["type"] == "Note"
@@ -65,7 +67,7 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming notes with attachments - GS, subscription" do
incoming = File.read!("test/fixtures/incoming_websub_gnusocial_attachments.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity)
assert activity.data["type"] == "Create"
assert object.data["type"] == "Note"
@@ -78,7 +80,7 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming notes with tags" do
incoming = File.read!("test/fixtures/ostatus_incoming_post_tag.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity)
assert object.data["tag"] == ["nsfw"]
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
@@ -95,7 +97,7 @@ defmodule Pleroma.Web.OStatusTest do
incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity)
assert activity.data["type"] == "Create"
assert object.data["type"] == "Note"
@@ -107,7 +109,7 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming notes - Mastodon, with CW" do
incoming = File.read!("test/fixtures/mastodon-note-cw.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity)
assert activity.data["type"] == "Create"
assert object.data["type"] == "Note"
@@ -119,7 +121,7 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming unlisted messages, put public into cc" do
incoming = File.read!("test/fixtures/mastodon-note-unlisted.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity)
refute "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["cc"]
@@ -130,7 +132,7 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming retweets - Mastodon, with CW" do
incoming = File.read!("test/fixtures/cw_retweet.xml")
{:ok, [[_activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
- retweeted_object = Object.normalize(retweeted_activity.data["object"])
+ retweeted_object = Object.normalize(retweeted_activity)
assert retweeted_object.data["summary"] == "Hey."
end
@@ -138,7 +140,7 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming notes - GS, subscription, reply" do
incoming = File.read!("test/fixtures/ostatus_incoming_reply.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity)
assert activity.data["type"] == "Create"
assert object.data["type"] == "Note"
@@ -164,7 +166,7 @@ defmodule Pleroma.Web.OStatusTest do
refute activity.local
retweeted_activity = Activity.get_by_id(retweeted_activity.id)
- retweeted_object = Object.normalize(retweeted_activity.data["object"])
+ retweeted_object = Object.normalize(retweeted_activity)
assert retweeted_activity.data["type"] == "Create"
assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain"
refute retweeted_activity.local
@@ -176,18 +178,19 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming retweets - GS, subscription - local message" do
incoming = File.read!("test/fixtures/share-gs-local.xml")
note_activity = insert(:note_activity)
+ object = Object.normalize(note_activity)
user = User.get_cached_by_ap_id(note_activity.data["actor"])
incoming =
incoming
- |> String.replace("LOCAL_ID", note_activity.data["object"]["id"])
+ |> String.replace("LOCAL_ID", object.data["id"])
|> String.replace("LOCAL_USER", user.ap_id)
{:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
assert activity.data["type"] == "Announce"
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
- assert activity.data["object"] == retweeted_activity.data["object"]["id"]
+ assert activity.data["object"] == object.data["id"]
assert user.ap_id in activity.data["to"]
refute activity.local
@@ -202,7 +205,7 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming retweets - Mastodon, salmon" do
incoming = File.read!("test/fixtures/share.xml")
{:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
- retweeted_object = Object.normalize(retweeted_activity.data["object"])
+ retweeted_object = Object.normalize(retweeted_activity)
assert activity.data["type"] == "Announce"
assert activity.data["actor"] == "https://mastodon.social/users/lambadalambda"
@@ -251,25 +254,29 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming favorites with locally available object - GS, websub" do
note_activity = insert(:note_activity)
+ object = Object.normalize(note_activity)
incoming =
File.read!("test/fixtures/favorite_with_local_note.xml")
- |> String.replace("localid", note_activity.data["object"]["id"])
+ |> String.replace("localid", object.data["id"])
{:ok, [[activity, favorited_activity]]} = OStatus.handle_incoming(incoming)
assert activity.data["type"] == "Like"
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
- assert activity.data["object"] == favorited_activity.data["object"]["id"]
+ assert activity.data["object"] == object.data["id"]
refute activity.local
assert note_activity.id == favorited_activity.id
assert favorited_activity.local
end
- test "handle incoming replies" do
+ test_with_mock "handle incoming replies, fetching replied-to activities if we don't have them",
+ OStatus,
+ [:passthrough],
+ [] do
incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity, false)
assert activity.data["type"] == "Create"
assert object.data["type"] == "Note"
@@ -282,6 +289,23 @@ defmodule Pleroma.Web.OStatusTest do
assert object.data["id"] == "tag:gs.example.org:4040,2017-04-25:noticeId=55:objectType=note"
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
+
+ assert called(OStatus.fetch_activity_from_url(object.data["inReplyTo"], :_))
+ end
+
+ test_with_mock "handle incoming replies, not fetching replied-to activities beyond max_replies_depth",
+ OStatus,
+ [:passthrough],
+ [] do
+ incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml")
+
+ with_mock Pleroma.Web.Federator,
+ allowed_incoming_reply_depth?: fn _ -> false end do
+ {:ok, [activity]} = OStatus.handle_incoming(incoming)
+ object = Object.normalize(activity, false)
+
+ refute called(OStatus.fetch_activity_from_url(object.data["inReplyTo"], :_))
+ end
end
test "handle incoming follows" do
@@ -315,13 +339,14 @@ defmodule Pleroma.Web.OStatusTest do
"undo:tag:social.heldscal.la,2017-05-07:subscription:23211:person:44803:2017-05-07T09:54:48+00:00"
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
- assert is_map(activity.data["object"])
- assert activity.data["object"]["type"] == "Follow"
- assert activity.data["object"]["object"] == "https://pawoo.net/users/pekorino"
+ embedded_object = activity.data["object"]
+ assert is_map(embedded_object)
+ assert embedded_object["type"] == "Follow"
+ assert embedded_object["object"] == "https://pawoo.net/users/pekorino"
refute activity.local
follower = User.get_cached_by_ap_id(activity.data["actor"])
- followed = User.get_cached_by_ap_id(activity.data["object"]["object"])
+ followed = User.get_cached_by_ap_id(embedded_object["object"])
refute User.following?(follower, followed)
end
@@ -538,8 +563,7 @@ defmodule Pleroma.Web.OStatusTest do
test "Article objects are not representable" do
note_activity = insert(:note_activity)
-
- note_object = Object.normalize(note_activity.data["object"])
+ note_object = Object.normalize(note_activity)
note_data =
note_object.data
diff --git a/test/web/plugs/federating_plug_test.exs b/test/web/plugs/federating_plug_test.exs
index 612db7e32..c01e01124 100644
--- a/test/web/plugs/federating_plug_test.exs
+++ b/test/web/plugs/federating_plug_test.exs
@@ -5,12 +5,17 @@
defmodule Pleroma.Web.FederatingPlugTest do
use Pleroma.Web.ConnCase
- test "returns and halt the conn when federating is disabled" do
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:federating, false)
+ 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
- Application.put_env(:pleroma, :instance, instance)
+ test "returns and halt the conn when federating is disabled" do
+ Pleroma.Config.put([:instance, :federating], false)
conn =
build_conn()
@@ -18,15 +23,11 @@ defmodule Pleroma.Web.FederatingPlugTest do
assert conn.status == 404
assert conn.halted
-
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:federating, true)
-
- Application.put_env(:pleroma, :instance, instance)
end
test "does nothing when federating is enabled" do
+ Pleroma.Config.put([:instance, :federating], true)
+
conn =
build_conn()
|> Pleroma.Web.FederatingPlug.call(%{})
diff --git a/test/web/rel_me_test.exs b/test/web/rel_me_test.exs
index 5188f4de1..85515c432 100644
--- a/test/web/rel_me_test.exs
+++ b/test/web/rel_me_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.RelMeTest do
use ExUnit.Case, async: true
diff --git a/test/web/rich_media/helpers_test.exs b/test/web/rich_media/helpers_test.exs
index 53b0596f5..92198f3d9 100644
--- a/test/web/rich_media/helpers_test.exs
+++ b/test/web/rich_media/helpers_test.exs
@@ -1,14 +1,23 @@
+# 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.HelpersTest do
use Pleroma.DataCase
+ alias Pleroma.Config
alias Pleroma.Object
alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.RichMedia.Helpers
import Pleroma.Factory
import Tesla.Mock
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
@@ -21,11 +30,9 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
"content_type" => "text/markdown"
})
- Pleroma.Config.put([:rich_media, :enabled], true)
+ Config.put([:rich_media, :enabled], true)
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
-
- Pleroma.Config.put([:rich_media, :enabled], false)
end
test "refuses to crawl malformed URLs" do
@@ -37,11 +44,9 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
"content_type" => "text/markdown"
})
- Pleroma.Config.put([:rich_media, :enabled], true)
+ Config.put([:rich_media, :enabled], true)
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
-
- Pleroma.Config.put([:rich_media, :enabled], false)
end
test "crawls valid, complete URLs" do
@@ -49,16 +54,14 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "[test](http://example.com/ogp)",
+ "status" => "[test](https://example.com/ogp)",
"content_type" => "text/markdown"
})
- Pleroma.Config.put([:rich_media, :enabled], true)
+ Config.put([:rich_media, :enabled], true)
- assert %{page_url: "http://example.com/ogp", rich_media: _} =
+ assert %{page_url: "https://example.com/ogp", rich_media: _} =
Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
-
- Pleroma.Config.put([:rich_media, :enabled], false)
end
test "refuses to crawl URLs from posts marked sensitive" do
@@ -74,11 +77,9 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
assert object.data["sensitive"]
- Pleroma.Config.put([:rich_media, :enabled], true)
+ Config.put([:rich_media, :enabled], true)
assert %{} = Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
-
- Pleroma.Config.put([:rich_media, :enabled], false)
end
test "refuses to crawl URLs from posts tagged NSFW" do
@@ -93,10 +94,28 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
assert object.data["sensitive"]
- Pleroma.Config.put([:rich_media, :enabled], true)
+ Config.put([:rich_media, :enabled], true)
assert %{} = Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+ end
+
+ test "refuses to crawl URLs of private network from posts" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "http://127.0.0.1:4000/notice/9kCP7VNyPJXFOXDrgO"})
+
+ {:ok, activity2} = CommonAPI.post(user, %{"status" => "https://10.111.10.1/notice/9kCP7V"})
+ {:ok, activity3} = CommonAPI.post(user, %{"status" => "https://172.16.32.40/notice/9kCP7V"})
+ {:ok, activity4} = CommonAPI.post(user, %{"status" => "https://192.168.10.40/notice/9kCP7V"})
+ {:ok, activity5} = CommonAPI.post(user, %{"status" => "https://pleroma.local/notice/9kCP7V"})
+
+ Config.put([:rich_media, :enabled], true)
- Pleroma.Config.put([:rich_media, :enabled], false)
+ assert %{} = Helpers.fetch_data_for_activity(activity)
+ assert %{} = Helpers.fetch_data_for_activity(activity2)
+ assert %{} = Helpers.fetch_data_for_activity(activity3)
+ assert %{} = Helpers.fetch_data_for_activity(activity4)
+ assert %{} = Helpers.fetch_data_for_activity(activity5)
end
end
diff --git a/test/web/rich_media/parser_test.exs b/test/web/rich_media/parser_test.exs
index 47b127cf9..19c19e895 100644
--- a/test/web/rich_media/parser_test.exs
+++ b/test/web/rich_media/parser_test.exs
@@ -1,3 +1,7 @@
+# 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.ParserTest do
use ExUnit.Case, async: true
@@ -11,6 +15,21 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
%{
method: :get,
+ url: "http://example.com/non-ogp"
+ } ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/non_ogp_embed.html")}
+
+ %{
+ method: :get,
+ url: "http://example.com/ogp-missing-title"
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/rich_media/ogp-missing-title.html")
+ }
+
+ %{
+ method: :get,
url: "http://example.com/twitter-card"
} ->
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/twitter_card.html")}
@@ -38,12 +57,32 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
assert {:error, _} = Pleroma.Web.RichMedia.Parser.parse("http://example.com/empty")
end
+ test "doesn't just add a title" do
+ assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/non-ogp") ==
+ {:error, "Found metadata was invalid or incomplete: %{}"}
+ end
+
test "parses ogp" do
assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/ogp") ==
{:ok,
%{
image: "http://ia.media-imdb.com/images/rock.jpg",
title: "The Rock",
+ description:
+ "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
+ type: "video.movie",
+ url: "http://www.imdb.com/title/tt0117500/"
+ }}
+ end
+
+ test "falls back to <title> when ogp:title is missing" do
+ assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/ogp-missing-title") ==
+ {:ok,
+ %{
+ image: "http://ia.media-imdb.com/images/rock.jpg",
+ title: "The Rock (1996)",
+ description:
+ "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
type: "video.movie",
url: "http://www.imdb.com/title/tt0117500/"
}}
diff --git a/test/web/streamer_test.exs b/test/web/streamer_test.exs
index bfe18cb7f..4633d7765 100644
--- a/test/web/streamer_test.exs
+++ b/test/web/streamer_test.exs
@@ -11,6 +11,62 @@ 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
+
+ describe "user streams" do
+ setup do
+ GenServer.start(Streamer, %{}, name: Streamer)
+
+ on_exit(fn ->
+ if pid = Process.whereis(Streamer) do
+ Process.exit(pid, :kill)
+ end
+ end)
+
+ user = insert(:user)
+ notify = insert(:notification, user: user, activity: build(:note_activity))
+ {:ok, %{user: user, notify: notify}}
+ end
+
+ test "it sends notify to in the 'user' stream", %{user: user, notify: notify} do
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _}, 4_000
+ end)
+
+ Streamer.add_socket(
+ "user",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ Streamer.stream("user", notify)
+ Task.await(task)
+ end
+
+ test "it sends notify to in the 'user:notification' stream", %{user: user, notify: notify} do
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _}, 4_000
+ end)
+
+ Streamer.add_socket(
+ "user:notification",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ Streamer.stream("user:notification", notify)
+ Task.await(task)
+ end
+ end
+
test "it sends to public" do
user = insert(:user)
other_user = insert(:user)
@@ -68,6 +124,74 @@ defmodule Pleroma.Web.StreamerTest do
Task.await(task)
end
+ describe "thread_containment" do
+ test "it doesn't send to user if recipients invalid and thread containment is enabled" do
+ Pleroma.Config.put([:instance, :skip_thread_containment], false)
+ author = insert(:user)
+ user = insert(:user, following: [author.ap_id])
+
+ activity =
+ insert(:note_activity,
+ note:
+ insert(:note,
+ user: author,
+ data: %{"to" => ["TEST-FFF"]}
+ )
+ )
+
+ task = Task.async(fn -> refute_receive {:text, _}, 1_000 end)
+ fake_socket = %{transport_pid: task.pid, assigns: %{user: user}}
+ topics = %{"public" => [fake_socket]}
+ Streamer.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ end
+
+ test "it sends message if recipients invalid and thread containment is disabled" do
+ Pleroma.Config.put([:instance, :skip_thread_containment], true)
+ author = insert(:user)
+ user = insert(:user, following: [author.ap_id])
+
+ activity =
+ insert(:note_activity,
+ note:
+ insert(:note,
+ user: author,
+ data: %{"to" => ["TEST-FFF"]}
+ )
+ )
+
+ task = Task.async(fn -> assert_receive {:text, _}, 1_000 end)
+ fake_socket = %{transport_pid: task.pid, assigns: %{user: user}}
+ topics = %{"public" => [fake_socket]}
+ Streamer.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ end
+
+ test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do
+ Pleroma.Config.put([:instance, :skip_thread_containment], false)
+ author = insert(:user)
+ user = insert(:user, following: [author.ap_id], info: %{skip_thread_containment: true})
+
+ activity =
+ insert(:note_activity,
+ note:
+ insert(:note,
+ user: author,
+ data: %{"to" => ["TEST-FFF"]}
+ )
+ )
+
+ task = Task.async(fn -> assert_receive {:text, _}, 1_000 end)
+ fake_socket = %{transport_pid: task.pid, assigns: %{user: user}}
+ topics = %{"public" => [fake_socket]}
+ Streamer.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ end
+ end
+
test "it doesn't send to blocked users" do
user = insert(:user)
blocked_user = insert(:user)
@@ -232,4 +356,110 @@ defmodule Pleroma.Web.StreamerTest do
Task.await(task)
end
+
+ describe "direct streams" do
+ setup do
+ GenServer.start(Streamer, %{}, name: Streamer)
+
+ on_exit(fn ->
+ if pid = Process.whereis(Streamer) do
+ Process.exit(pid, :kill)
+ end
+ end)
+
+ :ok
+ end
+
+ test "it sends conversation update to the 'direct' stream", %{} do
+ user = insert(:user)
+ another_user = insert(:user)
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _received_event}, 4_000
+ end)
+
+ Streamer.add_socket(
+ "direct",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, _create_activity} =
+ CommonAPI.post(another_user, %{
+ "status" => "hey @#{user.nickname}",
+ "visibility" => "direct"
+ })
+
+ Task.await(task)
+ end
+
+ test "it doesn't send conversation update to the 'direct' streamj when the last message in the conversation is deleted" do
+ user = insert(:user)
+ another_user = insert(:user)
+
+ {:ok, create_activity} =
+ CommonAPI.post(another_user, %{
+ "status" => "hi @#{user.nickname}",
+ "visibility" => "direct"
+ })
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, received_event}, 4_000
+ assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
+
+ refute_receive {:text, _}, 4_000
+ end)
+
+ Streamer.add_socket(
+ "direct",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, _} = CommonAPI.delete(create_activity.id, another_user)
+
+ Task.await(task)
+ end
+
+ test "it sends conversation update to the 'direct' stream when a message is deleted" do
+ user = insert(:user)
+ another_user = insert(:user)
+
+ {:ok, create_activity} =
+ CommonAPI.post(another_user, %{
+ "status" => "hi @#{user.nickname}",
+ "visibility" => "direct"
+ })
+
+ {:ok, create_activity2} =
+ CommonAPI.post(another_user, %{
+ "status" => "hi @#{user.nickname}",
+ "in_reply_to_status_id" => create_activity.id,
+ "visibility" => "direct"
+ })
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, received_event}, 4_000
+ assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
+
+ assert_receive {:text, received_event}, 4_000
+
+ assert %{"event" => "conversation", "payload" => received_payload} =
+ Jason.decode!(received_event)
+
+ assert %{"last_status" => last_status} = Jason.decode!(received_payload)
+ assert last_status["id"] == to_string(create_activity.id)
+ end)
+
+ Streamer.add_socket(
+ "direct",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, _} = CommonAPI.delete(create_activity2.id, another_user)
+
+ Task.await(task)
+ end
+ end
end
diff --git a/test/web/twitter_api/password_controller_test.exs b/test/web/twitter_api/password_controller_test.exs
new file mode 100644
index 000000000..3a7246ea8
--- /dev/null
+++ b/test/web/twitter_api/password_controller_test.exs
@@ -0,0 +1,60 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.PasswordResetToken
+ alias Pleroma.Web.OAuth.Token
+ import Pleroma.Factory
+
+ describe "GET /api/pleroma/password_reset/token" do
+ test "it returns error when token invalid", %{conn: conn} do
+ response =
+ conn
+ |> get("/api/pleroma/password_reset/token")
+ |> html_response(:ok)
+
+ assert response =~ "<h2>Invalid Token</h2>"
+ end
+
+ test "it shows password reset form", %{conn: conn} do
+ user = insert(:user)
+ {:ok, token} = PasswordResetToken.create_token(user)
+
+ response =
+ conn
+ |> get("/api/pleroma/password_reset/#{token.token}")
+ |> html_response(:ok)
+
+ assert response =~ "<h2>Password Reset for #{user.nickname}</h2>"
+ end
+ end
+
+ describe "POST /api/pleroma/password_reset" do
+ test "it returns HTTP 200", %{conn: conn} do
+ user = insert(:user)
+ {:ok, token} = PasswordResetToken.create_token(user)
+ {:ok, _access_token} = Token.create_token(insert(:oauth_app), user, %{})
+
+ params = %{
+ "password" => "test",
+ password_confirmation: "test",
+ token: token.token
+ }
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> post("/api/pleroma/password_reset", %{data: params})
+ |> html_response(:ok)
+
+ assert response =~ "<h2>Password changed!</h2>"
+
+ user = refresh_record(user)
+ assert Comeonin.Pbkdf2.checkpw("test", user.password_hash)
+ assert length(Token.get_user_tokens(user)) == 0
+ end
+ end
+end
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index e194f14fb..de6177575 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -40,6 +40,18 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
user = refresh_record(user)
assert user.info.banner["type"] == "Image"
end
+
+ test "profile banner can be reset", %{conn: conn} do
+ user = insert(:user)
+
+ conn
+ |> assign(:user, user)
+ |> post(authenticated_twitter_api__path(conn, :update_banner), %{"banner" => ""})
+ |> json_response(200)
+
+ user = refresh_record(user)
+ assert user.info.banner == %{}
+ end
end
describe "POST /api/qvitter/update_background_image" do
@@ -54,6 +66,18 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
user = refresh_record(user)
assert user.info.background["type"] == "Image"
end
+
+ test "background can be reset", %{conn: conn} do
+ user = insert(:user)
+
+ conn
+ |> assign(:user, user)
+ |> post(authenticated_twitter_api__path(conn, :update_background), %{"img" => ""})
+ |> json_response(200)
+
+ user = refresh_record(user)
+ assert user.info.background == %{}
+ end
end
describe "POST /api/account/verify_credentials" do
@@ -144,41 +168,25 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:public, false)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :public], false)
conn
|> get("/api/statuses/public_timeline.json")
|> json_response(403)
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:public, true)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :public], true)
end
test "returns 200 to authenticated request when the instance is not public",
%{conn: conn, user: user} do
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:public, false)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :public], false)
conn
|> with_credentials(user.nickname, "test")
|> get("/api/statuses/public_timeline.json")
|> json_response(200)
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:public, true)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :public], true)
end
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
@@ -214,41 +222,25 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
setup [:valid_user]
test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:public, false)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :public], false)
conn
|> get("/api/statuses/public_and_external_timeline.json")
|> json_response(403)
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:public, true)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :public], true)
end
test "returns 200 to authenticated request when the instance is not public",
%{conn: conn, user: user} do
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:public, false)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :public], false)
conn
|> with_credentials(user.nickname, "test")
|> get("/api/statuses/public_and_external_timeline.json")
|> json_response(200)
- instance =
- Application.get_env(:pleroma, :instance)
- |> Keyword.put(:public, true)
-
- Application.put_env(:pleroma, :instance, instance)
+ Pleroma.Config.put([:instance, :public], true)
end
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
@@ -529,6 +521,38 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
for: current_user
})
end
+
+ test "muted user", %{conn: conn, user: current_user} do
+ other_user = insert(:user)
+
+ {:ok, current_user} = User.mute(current_user, other_user)
+
+ {:ok, _activity} =
+ ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
+
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> get("/api/qvitter/statuses/notifications.json")
+
+ assert json_response(conn, 200) == []
+ end
+
+ test "muted user with with_muted parameter", %{conn: conn, user: current_user} do
+ other_user = insert(:user)
+
+ {:ok, current_user} = User.mute(current_user, other_user)
+
+ {:ok, _activity} =
+ ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
+
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> get("/api/qvitter/statuses/notifications.json", %{"with_muted" => "true"})
+
+ assert length(json_response(conn, 200)) == 1
+ end
end
describe "POST /api/qvitter/statuses/notifications/read" do
@@ -853,6 +877,19 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert json_response(conn, 200) ==
UserView.render("show.json", %{user: current_user, for: current_user})
end
+
+ test "user avatar can be reset", %{conn: conn, user: current_user} do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/qvitter/update_avatar.json", %{img: ""})
+
+ current_user = User.get_cached_by_id(current_user.id)
+ assert current_user.avatar == nil
+
+ assert json_response(conn, 200) ==
+ UserView.render("show.json", %{user: current_user, for: current_user})
+ end
end
describe "GET /api/qvitter/mutes.json" do
@@ -924,7 +961,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
test "with credentials", %{conn: conn, user: current_user} do
note_activity = insert(:note_activity)
- object = Object.get_by_ap_id(note_activity.data["object"]["id"])
+ object = Object.normalize(note_activity)
ActivityPub.like(current_user, object)
conn =
@@ -1527,7 +1564,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
"hide_follows" => "false"
})
- user = Repo.get!(User, user.id)
+ user = refresh_record(user)
assert user.info.hide_follows == false
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
@@ -1580,6 +1617,29 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
+ test "it sets and un-sets skip_thread_containment", %{conn: conn} do
+ user = insert(:user)
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> post("/api/account/update_profile.json", %{"skip_thread_containment" => "true"})
+ |> json_response(200)
+
+ assert response["pleroma"]["skip_thread_containment"] == true
+ user = refresh_record(user)
+ assert user.info.skip_thread_containment
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> post("/api/account/update_profile.json", %{"skip_thread_containment" => "false"})
+ |> json_response(200)
+
+ assert response["pleroma"]["skip_thread_containment"] == false
+ refute refresh_record(user).info.skip_thread_containment
+ end
+
test "it locks an account", %{conn: conn} do
user = insert(:user)
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index d601c8f1f..cbe83852e 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -46,7 +46,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity)
expected_text =
"Hello again, <span class='h-card'><a data-user='#{mentioned_user.id}' class='u-url mention' href='shp'>@<span>shp</span></a></span>.&lt;script&gt;&lt;/script&gt;<br>This is on another :firefox: line. <a class='hashtag' data-tag='2hu' href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a> <a class='hashtag' data-tag='epic' href='http://localhost:4001/tag/epic' rel='tag'>#epic</a> <a class='hashtag' data-tag='phantasmagoric' href='http://localhost:4001/tag/phantasmagoric' rel='tag'>#phantasmagoric</a><br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>"
@@ -91,7 +91,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity)
input = %{
"status" => "Here's your (you).",
@@ -99,7 +99,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, reply = %Activity{}} = TwitterAPI.create_status(user, input)
- reply_object = Object.normalize(reply.data["object"])
+ reply_object = Object.normalize(reply)
assert get_in(reply.data, ["context"]) == get_in(activity.data, ["context"])
@@ -116,8 +116,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user, followed, _activity} = TwitterAPI.follow(user, %{"user_id" => followed.id})
assert User.ap_followers(followed) in user.following
- {:error, msg} = TwitterAPI.follow(user, %{"user_id" => followed.id})
- assert msg == "Could not follow user: #{followed.nickname} is already on your list."
+ {:ok, _, _, _} = TwitterAPI.follow(user, %{"user_id" => followed.id})
end
test "Follow another user using screen_name" do
@@ -132,8 +131,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
followed = User.get_cached_by_ap_id(followed.ap_id)
assert followed.info.follower_count == 1
- {:error, msg} = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
- assert msg == "Could not follow user: #{followed.nickname} is already on your list."
+ {:ok, _, _, _} = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
end
test "Unfollow another user using user_id" do
@@ -218,7 +216,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
assert ActivityView.render("activity.json", %{activity: updated_activity})["fave_num"] == 1
- object = Object.normalize(note_activity.data["object"])
+ object = Object.normalize(note_activity)
assert object.data["like_count"] == 1
@@ -226,7 +224,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, _status} = TwitterAPI.fav(other_user, note_activity.id)
- object = Object.normalize(note_activity.data["object"])
+ object = Object.normalize(note_activity)
assert object.data["like_count"] == 2
@@ -237,7 +235,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
test "it unfavorites a status, returns the updated activity" do
user = insert(:user)
note_activity = insert(:note_activity)
- object = Object.get_by_ap_id(note_activity.data["object"]["id"])
+ object = Object.normalize(note_activity)
{:ok, _like_activity, _object} = ActivityPub.like(user, object)
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index 2cd82b3e7..21324399f 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
use Pleroma.Web.ConnCase
@@ -102,7 +106,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
conn
|> assign(:user, user)
|> put("/api/pleroma/notification_settings", %{
- "remote" => false,
"followers" => false,
"bar" => 1
})
@@ -110,8 +113,12 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
user = Repo.get(User, user.id)
- assert %{"remote" => false, "local" => true, "followers" => false, "follows" => true} ==
- user.info.notification_settings
+ assert %{
+ "followers" => false,
+ "follows" => true,
+ "non_follows" => true,
+ "non_followers" => true
+ } == user.info.notification_settings
end
end
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 43bd77f78..56d861efb 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -126,7 +126,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
other_user = insert(:user, %{nickname: "shp"})
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity)
result = ActivityView.render("activity.json", activity: activity)
@@ -177,7 +177,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
user = insert(:user)
other_user = insert(:user, %{nickname: "shp"})
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity)
convo_id = Utils.context_to_conversation_id(object.data["context"])
@@ -351,7 +351,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"is_post_verb" => false,
"statusnet_html" => "deleted notice {{tag",
"text" => "deleted notice {{tag",
- "uri" => delete.data["object"],
+ "uri" => Object.normalize(delete).data["id"],
"user" => UserView.render("show.json", user: user)
}
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 74526673c..70c5a0b7f 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -99,7 +99,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
- "tags" => []
+ "tags" => [],
+ "skip_thread_containment" => false
},
"rights" => %{"admin" => false, "delete_others_notice" => false},
"role" => "member"
@@ -112,9 +113,11 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
as_user = UserView.render("show.json", %{user: user, for: user})
assert as_user["default_scope"] == user.info.default_scope
assert as_user["no_rich_text"] == user.info.no_rich_text
+ assert as_user["pleroma"]["notification_settings"] == user.info.notification_settings
as_stranger = UserView.render("show.json", %{user: user})
refute as_stranger["default_scope"]
refute as_stranger["no_rich_text"]
+ refute as_stranger["pleroma"]["notification_settings"]
end
test "A user for a given other follower", %{user: user} do
@@ -152,7 +155,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
- "tags" => []
+ "tags" => [],
+ "skip_thread_containment" => false
},
"rights" => %{"admin" => false, "delete_others_notice" => false},
"role" => "member"
@@ -197,7 +201,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
- "tags" => []
+ "tags" => [],
+ "skip_thread_containment" => false
},
"rights" => %{"admin" => false, "delete_others_notice" => false},
"role" => "member"
@@ -279,7 +284,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
- "tags" => []
+ "tags" => [],
+ "skip_thread_containment" => false
},
"rights" => %{"admin" => false, "delete_others_notice" => false},
"role" => "member"
diff --git a/test/web/web_finger/web_finger_controller_test.exs b/test/web/web_finger/web_finger_controller_test.exs
index 43fccfc7a..a14ed3126 100644
--- a/test/web/web_finger/web_finger_controller_test.exs
+++ b/test/web/web_finger/web_finger_controller_test.exs
@@ -10,6 +10,12 @@ 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
diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs
index 335c95b18..0578b4b8e 100644
--- a/test/web/web_finger/web_finger_test.exs
+++ b/test/web/web_finger/web_finger_test.exs
@@ -104,5 +104,16 @@ defmodule Pleroma.Web.WebFingerTest do
assert template == "http://status.alpicola.com/main/xrd?uri={uri}"
end
+
+ test "it works with idna domains as nickname" do
+ nickname = "lain@" <> to_string(:idna.encode("zetsubou.みんな"))
+
+ {:ok, _data} = WebFinger.finger(nickname)
+ end
+
+ test "it works with idna domains as link" do
+ ap_id = "https://" <> to_string(:idna.encode("zetsubou.みんな")) <> "/users/lain"
+ {:ok, _data} = WebFinger.finger(ap_id)
+ end
end
end
diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs
index f79745d58..aa7262beb 100644
--- a/test/web/websub/websub_controller_test.exs
+++ b/test/web/websub/websub_controller_test.exs
@@ -9,6 +9,16 @@ 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
+ end
+
test "websub subscription request", %{conn: conn} do
user = insert(:user)