summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>2022-12-23 17:05:05 +0100
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>2022-12-23 17:05:05 +0100
commit7d68d64d633a8ba43965a6f93d22cb0ae76027e0 (patch)
tree6c00d45be1aa1fe63ffff71bc2153cdff34e104f /test
parentd8e326467c30b95c5164f6e29512057dce3c2077 (diff)
parent6bce88b9e7876d32ea9146a580454053f0ef3790 (diff)
downloadpleroma-7d68d64d633a8ba43965a6f93d22cb0ae76027e0.tar.gz
pleroma-7d68d64d633a8ba43965a6f93d22cb0ae76027e0.zip
Merge back 2.4.5
Diffstat (limited to 'test')
-rw-r--r--test/credo/check/consistency/file_location.ex2
-rw-r--r--test/fixtures/birthdays/misskey-user.json1
-rw-r--r--test/fixtures/config/temp.exported_from_db.secret.exs4
-rw-r--r--test/fixtures/config/temp.secret.exs4
-rw-r--r--test/fixtures/create-pleroma-reply-to-misskey-thread.json61
-rw-r--r--test/fixtures/image_with_caption-abstract.jpgbin0 -> 697 bytes
-rw-r--r--test/fixtures/image_with_imagedescription_and_caption-abstract.jpgbin0 -> 823 bytes
-rw-r--r--test/fixtures/image_with_imagedescription_and_caption-abstract_whitespaces.jpgbin0 -> 785 bytes
-rw-r--r--test/fixtures/image_with_no_description.jpgbin0 -> 631 bytes
-rw-r--r--test/fixtures/mastodon/collections/external_featured.json14
-rw-r--r--test/fixtures/modules/good_mrf.ex4
-rw-r--r--test/fixtures/modules/runtime_module.ex2
-rw-r--r--test/fixtures/owncast-note-with-attachment.json31
-rw-r--r--test/fixtures/roadhouse-create-activity.json109
-rw-r--r--test/fixtures/rsa_keys/key_1.pem27
-rw-r--r--test/fixtures/rsa_keys/key_2.pem27
-rw-r--r--test/fixtures/rsa_keys/key_3.pem27
-rw-r--r--test/fixtures/rsa_keys/key_4.pem27
-rw-r--r--test/fixtures/rsa_keys/key_5.pem27
-rw-r--r--test/fixtures/soapbox_no_mentions_in_content.json79
-rw-r--r--test/fixtures/tesla_mock/framatube.org_host_meta2
-rw-r--r--test/fixtures/tesla_mock/gleasonator-AG3RzWfwEKKrY63qj2.json35
-rw-r--r--test/fixtures/tesla_mock/helene@p.helene.moe.json50
-rw-r--r--test/fixtures/tesla_mock/https___lm.kazv.moe_users_mewmew.xml1
-rw-r--r--test/fixtures/tesla_mock/lm.kazv.moe_host_meta1
-rw-r--r--test/fixtures/tesla_mock/macgirvin@gleasonator.com.json41
-rw-r--r--test/fixtures/tesla_mock/mametsuko@mk.absturztau.be.json65
-rw-r--r--test/fixtures/tesla_mock/mewmew@lm.kazv.moe.json1
-rw-r--r--test/fixtures/tesla_mock/mk.absturztau.be-93e7nm8wqg-activity.json1
-rw-r--r--test/fixtures/tesla_mock/mk.absturztau.be-93e7nm8wqg.json44
-rw-r--r--test/fixtures/tesla_mock/p.helene.moe-AM7S6vZQmL6pI9TgPY.json36
-rw-r--r--test/fixtures/tesla_mock/status.alpicola.com_host_meta2
-rw-r--r--test/fixtures/webfinger/masto-host-meta.xml4
-rw-r--r--test/fixtures/webfinger/masto-user.json92
-rw-r--r--test/fixtures/webfinger/masto-webfinger.json23
-rw-r--r--test/fixtures/webfinger/pleroma-host-meta.xml1
-rw-r--r--test/fixtures/webfinger/pleroma-user.json58
-rw-r--r--test/fixtures/webfinger/pleroma-webfinger.json27
-rw-r--r--test/mix/pleroma_test.exs2
-rw-r--r--test/mix/tasks/pleroma/app_test.exs2
-rw-r--r--test/mix/tasks/pleroma/config_test.exs10
-rw-r--r--test/mix/tasks/pleroma/count_statuses_test.exs2
-rw-r--r--test/mix/tasks/pleroma/database_test.exs2
-rw-r--r--test/mix/tasks/pleroma/digest_test.exs10
-rw-r--r--test/mix/tasks/pleroma/ecto/migrate_test.exs4
-rw-r--r--test/mix/tasks/pleroma/ecto/rollback_test.exs2
-rw-r--r--test/mix/tasks/pleroma/ecto_test.exs2
-rw-r--r--test/mix/tasks/pleroma/email_test.exs2
-rw-r--r--test/mix/tasks/pleroma/emoji_test.exs2
-rw-r--r--test/mix/tasks/pleroma/frontend_test.exs2
-rw-r--r--test/mix/tasks/pleroma/instance_test.exs11
-rw-r--r--test/mix/tasks/pleroma/refresh_counter_cache_test.exs2
-rw-r--r--test/mix/tasks/pleroma/relay_test.exs2
-rw-r--r--test/mix/tasks/pleroma/robots_txt_test.exs2
-rw-r--r--test/mix/tasks/pleroma/uploads_test.exs2
-rw-r--r--test/mix/tasks/pleroma/user_test.exs2
-rw-r--r--test/pleroma/activity/ir/topics_test.exs29
-rw-r--r--test/pleroma/activity/search_test.exs19
-rw-r--r--test/pleroma/activity_test.exs77
-rw-r--r--test/pleroma/announcement_read_relationship_test.exs40
-rw-r--r--test/pleroma/announcement_test.exs98
-rw-r--r--test/pleroma/application_requirements_test.exs2
-rw-r--r--test/pleroma/bbs/handler_test.exs2
-rw-r--r--test/pleroma/bookmark_test.exs2
-rw-r--r--test/pleroma/captcha_test.exs2
-rw-r--r--test/pleroma/chat/message_reference_test.exs2
-rw-r--r--test/pleroma/chat_test.exs2
-rw-r--r--test/pleroma/config/deprecation_warnings_test.exs235
-rw-r--r--test/pleroma/config/holder_test.exs2
-rw-r--r--test/pleroma/config/loader_test.exs3
-rw-r--r--test/pleroma/config/release_runtime_provider_test.exs4
-rw-r--r--test/pleroma/config/transfer_task_test.exs81
-rw-r--r--test/pleroma/config_db_test.exs25
-rw-r--r--test/pleroma/config_test.exs2
-rw-r--r--test/pleroma/conversation/participation_test.exs6
-rw-r--r--test/pleroma/conversation_test.exs2
-rw-r--r--test/pleroma/docs/generator_test.exs6
-rw-r--r--test/pleroma/docs/translator/compiler_test.exs90
-rw-r--r--test/pleroma/ecto_type/activity_pub/object_validators/date_time_test.exs2
-rw-r--r--test/pleroma/ecto_type/activity_pub/object_validators/object_id_test.exs2
-rw-r--r--test/pleroma/ecto_type/activity_pub/object_validators/recipients_test.exs2
-rw-r--r--test/pleroma/ecto_type/activity_pub/object_validators/safe_text_test.exs2
-rw-r--r--test/pleroma/emails/admin_email_test.exs8
-rw-r--r--test/pleroma/emails/mailer_test.exs2
-rw-r--r--test/pleroma/emails/user_email_test.exs14
-rw-r--r--test/pleroma/emoji/formatter_test.exs2
-rw-r--r--test/pleroma/emoji/loader_test.exs2
-rw-r--r--test/pleroma/emoji/pack_test.exs2
-rw-r--r--test/pleroma/emoji_test.exs3
-rw-r--r--test/pleroma/filter_test.exs2
-rw-r--r--test/pleroma/following_relationship_test.exs2
-rw-r--r--test/pleroma/formatter_test.exs101
-rw-r--r--test/pleroma/frontend_test.exs2
-rw-r--r--test/pleroma/gun/connection_pool_test.exs3
-rw-r--r--test/pleroma/hashtag_test.exs2
-rw-r--r--test/pleroma/healthcheck_test.exs2
-rw-r--r--test/pleroma/html_test.exs2
-rw-r--r--test/pleroma/http/adapter_helper/gun_test.exs2
-rw-r--r--test/pleroma/http/adapter_helper/hackney_test.exs2
-rw-r--r--test/pleroma/http/adapter_helper_test.exs2
-rw-r--r--test/pleroma/http/ex_aws_test.exs2
-rw-r--r--test/pleroma/http/request_builder_test.exs2
-rw-r--r--test/pleroma/http/tzdata_test.exs2
-rw-r--r--test/pleroma/http_test.exs2
-rw-r--r--test/pleroma/instances/instance_test.exs33
-rw-r--r--test/pleroma/instances_test.exs2
-rw-r--r--test/pleroma/integration/federation_test.exs2
-rw-r--r--test/pleroma/integration/mastodon_websocket_test.exs2
-rw-r--r--test/pleroma/job_queue_monitor_test.exs2
-rw-r--r--test/pleroma/keys_test.exs2
-rw-r--r--test/pleroma/list_test.exs2
-rw-r--r--test/pleroma/marker_test.exs2
-rw-r--r--test/pleroma/mfa/backup_codes_test.exs2
-rw-r--r--test/pleroma/mfa/totp_test.exs2
-rw-r--r--test/pleroma/mfa_test.exs2
-rw-r--r--test/pleroma/migration_helper/notification_backfill_test.exs2
-rw-r--r--test/pleroma/moderation_log_test.exs6
-rw-r--r--test/pleroma/notification_test.exs79
-rw-r--r--test/pleroma/object/containment_test.exs2
-rw-r--r--test/pleroma/object/fetcher_test.exs281
-rw-r--r--test/pleroma/object/updater_test.exs76
-rw-r--r--test/pleroma/object_test.exs2
-rw-r--r--test/pleroma/otp_version_test.exs2
-rw-r--r--test/pleroma/pagination_test.exs2
-rw-r--r--test/pleroma/password/pbkdf2_test.exs2
-rw-r--r--test/pleroma/registration_test.exs2
-rw-r--r--test/pleroma/repo/migrations/autolinker_to_linkify_test.exs2
-rw-r--r--test/pleroma/repo/migrations/confirm_logged_in_users_test.exs2
-rw-r--r--test/pleroma/repo/migrations/deprecate_public_endpoint_test.exs2
-rw-r--r--test/pleroma/repo/migrations/fix_legacy_tags_test.exs2
-rw-r--r--test/pleroma/repo/migrations/fix_malformed_formatter_config_test.exs2
-rw-r--r--test/pleroma/repo/migrations/move_welcome_settings_test.exs2
-rw-r--r--test/pleroma/repo/migrations/rename_instance_chat_test.exs4
-rw-r--r--test/pleroma/repo_test.exs2
-rw-r--r--test/pleroma/report_note_test.exs25
-rw-r--r--test/pleroma/resilience_test.exs103
-rw-r--r--test/pleroma/reverse_proxy_test.exs4
-rw-r--r--test/pleroma/runtime_test.exs2
-rw-r--r--test/pleroma/safe_jsonb_set_test.exs2
-rw-r--r--test/pleroma/scheduled_activity_test.exs2
-rw-r--r--test/pleroma/signature_test.exs2
-rw-r--r--test/pleroma/stats_test.exs2
-rw-r--r--test/pleroma/upload/filter/analyze_metadata_test.exs2
-rw-r--r--test/pleroma/upload/filter/anonymize_filename_test.exs2
-rw-r--r--test/pleroma/upload/filter/dedupe_test.exs2
-rw-r--r--test/pleroma/upload/filter/exiftool/read_description_test.exs117
-rw-r--r--test/pleroma/upload/filter/exiftool/strip_location_test.exs (renamed from test/pleroma/upload/filter/exiftool_test.exs)8
-rw-r--r--test/pleroma/upload/filter/mogrifun_test.exs2
-rw-r--r--test/pleroma/upload/filter/mogrify_test.exs2
-rw-r--r--test/pleroma/upload/filter_test.exs2
-rw-r--r--test/pleroma/upload_test.exs32
-rw-r--r--test/pleroma/uploaders/local_test.exs2
-rw-r--r--test/pleroma/uploaders/s3_test.exs2
-rw-r--r--test/pleroma/user/backup_test.exs47
-rw-r--r--test/pleroma/user/import_test.exs2
-rw-r--r--test/pleroma/user/notification_setting_test.exs2
-rw-r--r--test/pleroma/user/query_test.exs73
-rw-r--r--test/pleroma/user/welcome_chat_message_test.exs2
-rw-r--r--test/pleroma/user/welcome_email_test.exs2
-rw-r--r--test/pleroma/user/welcome_message_test.exs2
-rw-r--r--test/pleroma/user_invite_token_test.exs2
-rw-r--r--test/pleroma/user_relationship_test.exs12
-rw-r--r--test/pleroma/user_search_test.exs10
-rw-r--r--test/pleroma/user_test.exs599
-rw-r--r--test/pleroma/utils_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/activity_pub_controller_test.exs52
-rw-r--r--test/pleroma/web/activity_pub/activity_pub_test.exs198
-rw-r--r--test/pleroma/web/activity_pub/builder_test.exs48
-rw-r--r--test/pleroma/web/activity_pub/mrf/activity_expiration_policy_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/mrf/anti_followbot_policy_test.exs59
-rw-r--r--test/pleroma/web/activity_pub/mrf/anti_link_spam_policy_test.exs35
-rw-r--r--test/pleroma/web/activity_pub/mrf/ensure_re_prepended_test.exs53
-rw-r--r--test/pleroma/web/activity_pub/mrf/follow_bot_policy_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/mrf/force_bot_unlisted_policy_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/mrf/force_mentions_in_content_test.exs259
-rw-r--r--test/pleroma/web/activity_pub/mrf/hashtag_policy_test.exs72
-rw-r--r--test/pleroma/web/activity_pub/mrf/hellthread_policy_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/mrf/keyword_policy_test.exs133
-rw-r--r--test/pleroma/web/activity_pub/mrf/media_proxy_warming_policy_test.exs46
-rw-r--r--test/pleroma/web/activity_pub/mrf/mention_policy_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/mrf/no_empty_policy_test.exs25
-rw-r--r--test/pleroma/web/activity_pub/mrf/no_placeholder_text_policy_test.exs43
-rw-r--r--test/pleroma/web/activity_pub/mrf/normalize_markup_test.exs61
-rw-r--r--test/pleroma/web/activity_pub/mrf/object_age_policy_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/mrf/reject_non_public_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/mrf/simple_policy_test.exs93
-rw-r--r--test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs31
-rw-r--r--test/pleroma/web/activity_pub/mrf/subchain_policy_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/mrf/tag_policy_test.exs38
-rw-r--r--test/pleroma/web/activity_pub/mrf/user_allow_list_policy_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/mrf/vocabulary_policy_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/mrf_test.exs11
-rw-r--r--test/pleroma/web/activity_pub/object_validators/accept_validation_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs86
-rw-r--r--test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs47
-rw-r--r--test/pleroma/web/activity_pub/object_validators/block_validation_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs4
-rw-r--r--test/pleroma/web/activity_pub/object_validators/create_generic_validator_test.exs62
-rw-r--r--test/pleroma/web/activity_pub/object_validators/delete_validation_test.exs19
-rw-r--r--test/pleroma/web/activity_pub/object_validators/emoji_react_handling_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/object_validators/like_validation_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/object_validators/reject_validation_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/object_validators/undo_handling_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/object_validators/update_handling_test.exs128
-rw-r--r--test/pleroma/web/activity_pub/pipeline_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/publisher_test.exs76
-rw-r--r--test/pleroma/web/activity_pub/relay_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/side_effects/delete_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/side_effects_test.exs407
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/accept_handling_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/add_remove_handling_test.exs16
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/answer_handling_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/article_handling_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/audio_handling_test.exs8
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/block_handling_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/chat_message_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs33
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/event_handling_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/follow_handling_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/like_handling_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs40
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/page_handling_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs5
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/reject_handling_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/undo_handling_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/user_update_handling_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/video_handling_test.exs17
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier_test.exs123
-rw-r--r--test/pleroma/web/activity_pub/utils_test.exs67
-rw-r--r--test/pleroma/web/activity_pub/views/object_view_test.exs16
-rw-r--r--test/pleroma/web/activity_pub/views/user_view_test.exs9
-rw-r--r--test/pleroma/web/activity_pub/visibility_test.exs2
-rw-r--r--test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs309
-rw-r--r--test/pleroma/web/admin_api/controllers/announcement_controller_test.exs375
-rw-r--r--test/pleroma/web/admin_api/controllers/chat_controller_test.exs46
-rw-r--r--test/pleroma/web/admin_api/controllers/config_controller_test.exs62
-rw-r--r--test/pleroma/web/admin_api/controllers/frontend_controller_test.exs2
-rw-r--r--test/pleroma/web/admin_api/controllers/instance_controller_test.exs92
-rw-r--r--test/pleroma/web/admin_api/controllers/instance_document_controller_test.exs4
-rw-r--r--test/pleroma/web/admin_api/controllers/invite_controller_test.exs74
-rw-r--r--test/pleroma/web/admin_api/controllers/media_proxy_cache_controller_test.exs32
-rw-r--r--test/pleroma/web/admin_api/controllers/o_auth_app_controller_test.exs2
-rw-r--r--test/pleroma/web/admin_api/controllers/relay_controller_test.exs2
-rw-r--r--test/pleroma/web/admin_api/controllers/report_controller_test.exs108
-rw-r--r--test/pleroma/web/admin_api/controllers/status_controller_test.exs46
-rw-r--r--test/pleroma/web/admin_api/controllers/user_controller_test.exs322
-rw-r--r--test/pleroma/web/admin_api/search_test.exs2
-rw-r--r--test/pleroma/web/admin_api/views/account_view_test.exs2
-rw-r--r--test/pleroma/web/admin_api/views/moderation_log_view_test.exs2
-rw-r--r--test/pleroma/web/admin_api/views/report_view_test.exs2
-rw-r--r--test/pleroma/web/api_spec/schema_examples_test.exs2
-rw-r--r--test/pleroma/web/auth/auth_controller_test.exs2
-rw-r--r--test/pleroma/web/auth/authenticator_test.exs2
-rw-r--r--test/pleroma/web/auth/basic_auth_test.exs2
-rw-r--r--test/pleroma/web/auth/pleroma_authenticator_test.exs2
-rw-r--r--test/pleroma/web/auth/totp_authenticator_test.exs2
-rw-r--r--test/pleroma/web/common_api/utils_test.exs91
-rw-r--r--test/pleroma/web/common_api_test.exs257
-rw-r--r--test/pleroma/web/endpoint/metrics_exporter_test.exs2
-rw-r--r--test/pleroma/web/fallback_test.exs2
-rw-r--r--test/pleroma/web/federator_test.exs6
-rw-r--r--test/pleroma/web/feed/tag_controller_test.exs7
-rw-r--r--test/pleroma/web/feed/user_controller_test.exs29
-rw-r--r--test/pleroma/web/gettext_test.exs173
-rw-r--r--test/pleroma/web/manifest_controller_test.exs17
-rw-r--r--test/pleroma/web/mastodon_api/controllers/account_controller_test.exs393
-rw-r--r--test/pleroma/web/mastodon_api/controllers/announcement_controller_test.exs169
-rw-r--r--test/pleroma/web/mastodon_api/controllers/app_controller_test.exs30
-rw-r--r--test/pleroma/web/mastodon_api/controllers/auth_controller_test.exs159
-rw-r--r--test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/controllers/custom_emoji_controller_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/controllers/directory_controller_test.exs50
-rw-r--r--test/pleroma/web/mastodon_api/controllers/domain_block_controller_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/controllers/filter_controller_test.exs57
-rw-r--r--test/pleroma/web/mastodon_api/controllers/follow_request_controller_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs3
-rw-r--r--test/pleroma/web/mastodon_api/controllers/list_controller_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/controllers/media_controller_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs102
-rw-r--r--test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/controllers/report_controller_test.exs39
-rw-r--r--test/pleroma/web/mastodon_api/controllers/scheduled_activity_controller_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/controllers/search_controller_test.exs60
-rw-r--r--test/pleroma/web/mastodon_api/controllers/status_controller_test.exs266
-rw-r--r--test/pleroma/web/mastodon_api/controllers/subscription_controller_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs69
-rw-r--r--test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs61
-rw-r--r--test/pleroma/web/mastodon_api/masto_fe_controller_test.exs85
-rw-r--r--test/pleroma/web/mastodon_api/mastodon_api_controller_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/mastodon_api_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/update_credentials_test.exs134
-rw-r--r--test/pleroma/web/mastodon_api/views/account_view_test.exs213
-rw-r--r--test/pleroma/web/mastodon_api/views/conversation_view_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/views/list_view_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/views/marker_view_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/views/notification_view_test.exs55
-rw-r--r--test/pleroma/web/mastodon_api/views/poll_view_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/views/status_view_test.exs60
-rw-r--r--test/pleroma/web/mastodon_api/views/subscription_view_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/views/suggestion_view_test.exs34
-rw-r--r--test/pleroma/web/media_proxy/invalidation/http_test.exs2
-rw-r--r--test/pleroma/web/media_proxy/invalidation/script_test.exs2
-rw-r--r--test/pleroma/web/media_proxy/invalidation_test.exs2
-rw-r--r--test/pleroma/web/media_proxy/media_proxy_controller_test.exs24
-rw-r--r--test/pleroma/web/media_proxy_test.exs2
-rw-r--r--test/pleroma/web/metadata/player_view_test.exs2
-rw-r--r--test/pleroma/web/metadata/providers/feed_test.exs2
-rw-r--r--test/pleroma/web/metadata/providers/open_graph_test.exs2
-rw-r--r--test/pleroma/web/metadata/providers/rel_me_test.exs2
-rw-r--r--test/pleroma/web/metadata/providers/restrict_indexing_test.exs2
-rw-r--r--test/pleroma/web/metadata/providers/twitter_card_test.exs83
-rw-r--r--test/pleroma/web/metadata/utils_test.exs54
-rw-r--r--test/pleroma/web/mongoose_im_controller_test.exs2
-rw-r--r--test/pleroma/web/node_info_test.exs153
-rw-r--r--test/pleroma/web/o_auth/app_test.exs14
-rw-r--r--test/pleroma/web/o_auth/authorization_test.exs2
-rw-r--r--test/pleroma/web/o_auth/ldap_authorization_test.exs2
-rw-r--r--test/pleroma/web/o_auth/mfa_controller_test.exs2
-rw-r--r--test/pleroma/web/o_auth/o_auth_controller_test.exs2
-rw-r--r--test/pleroma/web/o_auth/token/utils_test.exs2
-rw-r--r--test/pleroma/web/o_auth/token_test.exs2
-rw-r--r--test/pleroma/web/o_status/o_status_controller_test.exs2
-rw-r--r--test/pleroma/web/pleroma_api/controllers/account_controller_test.exs86
-rw-r--r--test/pleroma/web/pleroma_api/controllers/app_controller_test.exs53
-rw-r--r--test/pleroma/web/pleroma_api/controllers/backup_controller_test.exs24
-rw-r--r--test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs2
-rw-r--r--test/pleroma/web/pleroma_api/controllers/conversation_controller_test.exs2
-rw-r--r--test/pleroma/web/pleroma_api/controllers/emoji_file_controller_test.exs32
-rw-r--r--test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs66
-rw-r--r--test/pleroma/web/pleroma_api/controllers/emoji_reaction_controller_test.exs2
-rw-r--r--test/pleroma/web/pleroma_api/controllers/instances_controller_test.exs2
-rw-r--r--test/pleroma/web/pleroma_api/controllers/mascot_controller_test.exs2
-rw-r--r--test/pleroma/web/pleroma_api/controllers/notification_controller_test.exs2
-rw-r--r--test/pleroma/web/pleroma_api/controllers/report_controller_test.exs2
-rw-r--r--test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs2
-rw-r--r--test/pleroma/web/pleroma_api/controllers/settings_controller_test.exs126
-rw-r--r--test/pleroma/web/pleroma_api/controllers/two_factor_authentication_controller_test.exs2
-rw-r--r--test/pleroma/web/pleroma_api/controllers/user_import_controller_test.exs2
-rw-r--r--test/pleroma/web/pleroma_api/views/app_view_test.exs21
-rw-r--r--test/pleroma/web/pleroma_api/views/backup_view_test.exs2
-rw-r--r--test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs2
-rw-r--r--test/pleroma/web/pleroma_api/views/chat_view_test.exs2
-rw-r--r--test/pleroma/web/pleroma_api/views/scrobble_view_test.exs2
-rw-r--r--test/pleroma/web/plugs/admin_secret_authentication_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/authentication_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/basic_auth_decoder_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/cache_control_test.exs2
-rw-r--r--test/pleroma/web/plugs/cache_test.exs2
-rw-r--r--test/pleroma/web/plugs/digest_plug_test.exs4
-rw-r--r--test/pleroma/web/plugs/ensure_authenticated_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/ensure_privileged_plug_test.exs96
-rw-r--r--test/pleroma/web/plugs/ensure_public_or_authenticated_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/ensure_user_token_assigns_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/federating_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/frontend_static_plug_test.exs6
-rw-r--r--test/pleroma/web/plugs/http_security_plug_test.exs6
-rw-r--r--test/pleroma/web/plugs/http_signature_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/idempotency_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/instance_static_test.exs2
-rw-r--r--test/pleroma/web/plugs/mapped_signature_to_identity_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/o_auth_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/o_auth_scopes_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/plug_helper_test.exs2
-rw-r--r--test/pleroma/web/plugs/rate_limiter_test.exs48
-rw-r--r--test/pleroma/web/plugs/remote_ip_test.exs2
-rw-r--r--test/pleroma/web/plugs/set_format_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/set_locale_plug_test.exs126
-rw-r--r--test/pleroma/web/plugs/set_user_session_id_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/uploaded_media_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/user_enabled_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/user_fetcher_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/user_is_admin_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/user_is_staff_plug_test.exs47
-rw-r--r--test/pleroma/web/plugs/user_tracking_plug_test.exs2
-rw-r--r--test/pleroma/web/preload/providers/instance_test.exs2
-rw-r--r--test/pleroma/web/preload/providers/timeline_test.exs2
-rw-r--r--test/pleroma/web/preload/providers/user_test.exs2
-rw-r--r--test/pleroma/web/push/impl_test.exs17
-rw-r--r--test/pleroma/web/rel_me_test.exs2
-rw-r--r--test/pleroma/web/rich_media/helpers_test.exs2
-rw-r--r--test/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs6
-rw-r--r--test/pleroma/web/rich_media/parser_test.exs2
-rw-r--r--test/pleroma/web/rich_media/parsers/twitter_card_test.exs2
-rw-r--r--test/pleroma/web/shout_channel_test.exs2
-rw-r--r--test/pleroma/web/static_fe/static_fe_controller_test.exs2
-rw-r--r--test/pleroma/web/streamer_test.exs76
-rw-r--r--test/pleroma/web/twitter_api/controller_test.exs2
-rw-r--r--test/pleroma/web/twitter_api/password_controller_test.exs96
-rw-r--r--test/pleroma/web/twitter_api/remote_follow_controller_test.exs49
-rw-r--r--test/pleroma/web/twitter_api/twitter_api_test.exs6
-rw-r--r--test/pleroma/web/twitter_api/util_controller_test.exs549
-rw-r--r--test/pleroma/web/uploader_controller_test.exs2
-rw-r--r--test/pleroma/web/views/error_view_test.exs2
-rw-r--r--test/pleroma/web/web_finger/web_finger_controller_test.exs35
-rw-r--r--test/pleroma/web/web_finger_test.exs10
-rw-r--r--test/pleroma/workers/cron/digest_emails_worker_test.exs2
-rw-r--r--test/pleroma/workers/cron/new_users_digest_worker_test.exs2
-rw-r--r--test/pleroma/workers/publisher_worker_test.exs40
-rw-r--r--test/pleroma/workers/purge_expired_activity_test.exs2
-rw-r--r--test/pleroma/workers/purge_expired_filter_test.exs4
-rw-r--r--test/pleroma/workers/purge_expired_token_test.exs2
-rw-r--r--test/pleroma/workers/receiver_worker_test.exs25
-rw-r--r--test/pleroma/workers/scheduled_activity_worker_test.exs2
-rw-r--r--test/pleroma/xml_builder_test.exs2
-rw-r--r--test/support/api_spec_helpers.ex6
-rw-r--r--test/support/builders/activity_builder.ex4
-rw-r--r--test/support/builders/user_builder.ex4
-rw-r--r--test/support/cachex_proxy.ex2
-rw-r--r--test/support/captcha/mock.ex2
-rw-r--r--test/support/channel_case.ex2
-rw-r--r--test/support/cluster.ex4
-rw-r--r--test/support/conn_case.ex6
-rw-r--r--test/support/data_case.ex2
-rw-r--r--test/support/factory.ex131
-rw-r--r--test/support/helpers.ex2
-rw-r--r--test/support/http_request_mock.ex177
-rw-r--r--test/support/mocks.ex2
-rw-r--r--test/support/mrf_module_mock.ex2
-rw-r--r--test/support/null_cache.ex2
-rw-r--r--test/support/oban_helpers.ex2
-rw-r--r--test/support/websocket_client.ex2
-rw-r--r--test/test_helper.exs4
428 files changed, 11137 insertions, 1486 deletions
diff --git a/test/credo/check/consistency/file_location.ex b/test/credo/check/consistency/file_location.ex
index abc55fffc..d6a62bfd2 100644
--- a/test/credo/check/consistency/file_location.ex
+++ b/test/credo/check/consistency/file_location.ex
@@ -1,7 +1,7 @@
# Pleroma: A lightweight social networking server
# Originally taken from
# https://github.com/VeryBigThings/elixir_common/blob/master/lib/vbt/credo/check/consistency/file_location.ex
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Credo.Check.Consistency.FileLocation do
diff --git a/test/fixtures/birthdays/misskey-user.json b/test/fixtures/birthdays/misskey-user.json
new file mode 100644
index 000000000..4ffee3910
--- /dev/null
+++ b/test/fixtures/birthdays/misskey-user.json
@@ -0,0 +1 @@
+{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","Hashtag":"as:Hashtag","quoteUrl":"as:quoteUrl","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji","featured":"toot:featured","discoverable":"toot:discoverable","schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value","misskey":"https://misskey.io/ns#","_misskey_content":"misskey:_misskey_content","_misskey_quote":"misskey:_misskey_quote","_misskey_reaction":"misskey:_misskey_reaction","_misskey_votes":"misskey:_misskey_votes","_misskey_talk":"misskey:_misskey_talk","isCat":"misskey:isCat","vcard":"http://www.w3.org/2006/vcard/ns#"}],"type":"Person","id":"https://misskey.io/users/8dhi2ne167","inbox":"https://misskey.io/users/8dhi2ne167/inbox","outbox":"https://misskey.io/users/8dhi2ne167/outbox","followers":"https://misskey.io/users/8dhi2ne167/followers","following":"https://misskey.io/users/8dhi2ne167/following","sharedInbox":"https://misskey.io/inbox","endpoints":{"sharedInbox":"https://misskey.io/inbox"},"url":"https://misskey.io/@mkljczk","preferredUsername":"mkljczk","name":null,"summary":null,"icon":null,"image":null,"tag":[],"manuallyApprovesFollowers":false,"discoverable":true,"publicKey":{"id":"https://misskey.io/users/8dhi2ne167#main-key","type":"Key","owner":"https://misskey.io/users/8dhi2ne167","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA7CI3Ol1M0TDdLL+E8Uhd\nJ8l/RTEtxl39MKxsqSCZr9itf/EBn4dGTifK9LN3XZD2fjmX4hdwaxndp2HYVDqn\ndc6O57u8dHxFv9wTwXQrLzEonOzbrBec6WB42ZpkFHi4XEyqg8iYGu5Yy7ttXJ21\nOfWqi+eytttcTErKuu4z8MX1L1IlmpfSmH1trMyDZLFMRqVJ0416/qI0K3l3cmIf\n8cuWbJ57UxVbYxp9242der/3vrNIU24rAouYQYe1atUgFPKil3w8dCY7magy36Wg\nOXC1hdRsFcsVW54/3cSQ9fc/+1HIg16/zlS+AWb4dVDhrAUJLYIBrkMPRnu/cDuI\ndvyL+KtZUxhDBoSO0JLrd1+GZGt0WD+mfutCugJS8IGlWQmGq8WRmM2vYfZgEYkq\nCv4392VSsWvg4iluKz0eX+8l7QKHseJwGBvk89Txlz6f7QkooBXYuuyHZS1ZLZBW\nfooK+RNAquDU+cVUu1gVt1V5yt3IxF1qvMRtlElNJKN5NUJT9/K2YcVX6UoMXhDd\noSOpARqPm9E2pdjI62pAOBbCplMSoBprhoCYm0iozf9QhNyUBGWDcTsFDDgqOwy4\nYjGQ5jsnCrkhSzRkTViWD+Pgw+Ar4fxcjySGUf0x7HkNfteDPSdLMD8J2vTJXfoB\nGAQQmGMZmFgONC62FrDphlsCAwEAAQ==\n-----END PUBLIC KEY-----\n"},"isCat":true,"vcard:bday":"2001-02-12"} \ No newline at end of file
diff --git a/test/fixtures/config/temp.exported_from_db.secret.exs b/test/fixtures/config/temp.exported_from_db.secret.exs
index dda5d0fa6..94782ec73 100644
--- a/test/fixtures/config/temp.exported_from_db.secret.exs
+++ b/test/fixtures/config/temp.exported_from_db.secret.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
import Config
config :pleroma, exported_config_merged: true
diff --git a/test/fixtures/config/temp.secret.exs b/test/fixtures/config/temp.secret.exs
index 9c5c88d98..e5709ba6f 100644
--- a/test/fixtures/config/temp.secret.exs
+++ b/test/fixtures/config/temp.secret.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
import Config
@@ -8,8 +8,6 @@ config :pleroma, :first_setting, key: "value", key2: [Pleroma.Repo]
config :pleroma, :second_setting, key: "value2", key2: ["Activity"]
-config :quack, level: :info
-
config :pleroma, Pleroma.Repo, pool: Ecto.Adapters.SQL.Sandbox
config :postgrex, :json_library, Poison
diff --git a/test/fixtures/create-pleroma-reply-to-misskey-thread.json b/test/fixtures/create-pleroma-reply-to-misskey-thread.json
new file mode 100644
index 000000000..0c31efa76
--- /dev/null
+++ b/test/fixtures/create-pleroma-reply-to-misskey-thread.json
@@ -0,0 +1,61 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://p.helene.moe/schemas/litepub-0.1.jsonld",
+ {
+ "@language": "und"
+ }
+ ],
+ "actor": "https://p.helene.moe/users/helene",
+ "attachment": [],
+ "attributedTo": "https://p.helene.moe/users/helene",
+ "cc": [
+ "https://p.helene.moe/users/helene/followers"
+ ],
+ "context": "https://p.helene.moe/contexts/cc324643-5583-4c3f-91d2-c6ed37db159d",
+ "conversation": "https://p.helene.moe/contexts/cc324643-5583-4c3f-91d2-c6ed37db159d",
+ "directMessage": false,
+ "id": "https://p.helene.moe/activities/5f80db86-a9bb-4883-9845-fbdbd1478f3a",
+ "object": {
+ "actor": "https://p.helene.moe/users/helene",
+ "attachment": [],
+ "attributedTo": "https://p.helene.moe/users/helene",
+ "cc": [
+ "https://p.helene.moe/users/helene/followers"
+ ],
+ "content": "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"AHntpQ4T3J4OSnpgMC\" href=\"https://mk.absturztau.be/@mametsuko\" rel=\"ugc\">@<span>mametsuko</span></a></span> meow",
+ "context": "https://p.helene.moe/contexts/cc324643-5583-4c3f-91d2-c6ed37db159d",
+ "conversation": "https://p.helene.moe/contexts/cc324643-5583-4c3f-91d2-c6ed37db159d",
+ "id": "https://p.helene.moe/objects/fd5910ac-d9dc-412e-8d1d-914b203296c4",
+ "inReplyTo": "https://mk.absturztau.be/notes/93e7nm8wqg",
+ "published": "2022-08-02T13:46:58.403996Z",
+ "sensitive": null,
+ "source": "@mametsuko@mk.absturztau.be meow",
+ "summary": "",
+ "tag": [
+ {
+ "href": "https://mk.absturztau.be/users/8ozbzjs3o8",
+ "name": "@mametsuko@mk.absturztau.be",
+ "type": "Mention"
+ }
+ ],
+ "to": [
+ "https://mk.absturztau.be/users/8ozbzjs3o8",
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "type": "Note"
+ },
+ "published": "2022-08-02T13:46:58.403883Z",
+ "tag": [
+ {
+ "href": "https://mk.absturztau.be/users/8ozbzjs3o8",
+ "name": "@mametsuko@mk.absturztau.be",
+ "type": "Mention"
+ }
+ ],
+ "to": [
+ "https://mk.absturztau.be/users/8ozbzjs3o8",
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "type": "Create"
+} \ No newline at end of file
diff --git a/test/fixtures/image_with_caption-abstract.jpg b/test/fixtures/image_with_caption-abstract.jpg
new file mode 100644
index 000000000..f982ffa81
--- /dev/null
+++ b/test/fixtures/image_with_caption-abstract.jpg
Binary files differ
diff --git a/test/fixtures/image_with_imagedescription_and_caption-abstract.jpg b/test/fixtures/image_with_imagedescription_and_caption-abstract.jpg
new file mode 100644
index 000000000..c82a269ef
--- /dev/null
+++ b/test/fixtures/image_with_imagedescription_and_caption-abstract.jpg
Binary files differ
diff --git a/test/fixtures/image_with_imagedescription_and_caption-abstract_whitespaces.jpg b/test/fixtures/image_with_imagedescription_and_caption-abstract_whitespaces.jpg
new file mode 100644
index 000000000..a232fd2a1
--- /dev/null
+++ b/test/fixtures/image_with_imagedescription_and_caption-abstract_whitespaces.jpg
Binary files differ
diff --git a/test/fixtures/image_with_no_description.jpg b/test/fixtures/image_with_no_description.jpg
new file mode 100644
index 000000000..ec6fc4be8
--- /dev/null
+++ b/test/fixtures/image_with_no_description.jpg
Binary files differ
diff --git a/test/fixtures/mastodon/collections/external_featured.json b/test/fixtures/mastodon/collections/external_featured.json
new file mode 100644
index 000000000..be5302cf8
--- /dev/null
+++ b/test/fixtures/mastodon/collections/external_featured.json
@@ -0,0 +1,14 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://{{domain}}/schemas/litepub-0.1.jsonld",
+ {
+ "@language": "und"
+ }
+ ],
+ "id": "https://{{domain}}/users/{{nickname}}/collections/featured",
+ "orderedItems": [
+ "https://{{domain}}/objects/{{object_id}}"
+ ],
+ "type": "OrderedCollection"
+}
diff --git a/test/fixtures/modules/good_mrf.ex b/test/fixtures/modules/good_mrf.ex
index 5afa1c1d1..3ddb74a83 100644
--- a/test/fixtures/modules/good_mrf.ex
+++ b/test/fixtures/modules/good_mrf.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Fixtures.Modules.GoodMRF do
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
diff --git a/test/fixtures/modules/runtime_module.ex b/test/fixtures/modules/runtime_module.ex
index 940b58a1b..d28dd2f1a 100644
--- a/test/fixtures/modules/runtime_module.ex
+++ b/test/fixtures/modules/runtime_module.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Fixtures.Modules.RuntimeModule do
diff --git a/test/fixtures/owncast-note-with-attachment.json b/test/fixtures/owncast-note-with-attachment.json
new file mode 100644
index 000000000..68cb6bbf7
--- /dev/null
+++ b/test/fixtures/owncast-note-with-attachment.json
@@ -0,0 +1,31 @@
+{
+ "attachment": {
+ "content": "Live stream preview",
+ "type": "Image",
+ "url": "https://owncast.localhost.localdomain/preview.gif?us=KjfNX387gm"
+ },
+ "attributedTo": "https://owncast.localhost.localdomain/federation/user/streamer",
+ "audience": "https://www.w3.org/ns/activitystreams#Public",
+ "content": "<p>I've gone live!</p><p></p><p><a class=\"hashtag\" href=\"https://directory.owncast.online/tags/owncast\">#owncast</a> <a class=\"hashtag\" href=\"https://directory.owncast.online/tags/streaming\">#streaming</a></p><a href=\"https://owncast.localhost.localdomain\">https://owncast.localhost.localdomain</a>",
+ "id": "https://owncast.localhost.localdomain/federation/KjBNuq8ng",
+ "published": "2022-04-17T15:42:03Z",
+ "tag": [
+ {
+ "href": "https://directory.owncast.online/tags/owncast",
+ "name": "#owncast",
+ "type": "Hashtag"
+ },
+ {
+ "href": "https://directory.owncast.online/tags/streaming",
+ "name": "#streaming",
+ "type": "Hashtag"
+ },
+ {
+ "href": "https://directory.owncast.online/tags/owncast",
+ "name": "#owncast",
+ "type": "Hashtag"
+ }
+ ],
+ "to": "https://www.w3.org/ns/activitystreams#Public",
+ "type": "Note"
+}
diff --git a/test/fixtures/roadhouse-create-activity.json b/test/fixtures/roadhouse-create-activity.json
new file mode 100644
index 000000000..c082f84d7
--- /dev/null
+++ b/test/fixtures/roadhouse-create-activity.json
@@ -0,0 +1,109 @@
+{
+ "@context":[
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ {
+ "zot":"https://macgirvin.com/apschema#",
+ "toot":"http://joinmastodon.org/ns#",
+ "ostatus":"http://ostatus.org#",
+ "schema":"http://schema.org#",
+ "litepub":"http://litepub.social/ns#",
+ "sm":"http://smithereen.software/ns#",
+ "conversation":"ostatus:conversation",
+ "manuallyApprovesFollowers":"as:manuallyApprovesFollowers",
+ "oauthRegistrationEndpoint":"litepub:oauthRegistrationEndpoint",
+ "sensitive":"as:sensitive",
+ "movedTo":"as:movedTo",
+ "copiedTo":"as:copiedTo",
+ "alsoKnownAs":"as:alsoKnownAs",
+ "EmojiReact":"as:EmojiReact",
+ "commentPolicy":"zot:commentPolicy",
+ "topicalCollection":"zot:topicalCollection",
+ "eventRepeat":"zot:eventRepeat",
+ "emojiReaction":"zot:emojiReaction",
+ "expires":"zot:expires",
+ "directMessage":"zot:directMessage",
+ "Category":"zot:Category",
+ "replyTo":"zot:replyTo",
+ "PropertyValue":"schema:PropertyValue",
+ "value":"schema:value",
+ "discoverable":"toot:discoverable",
+ "wall":"sm:wall",
+ "capabilities":"litepub:capabilities",
+ "acceptsJoins":"litepub:acceptsJoins"
+ }
+ ],
+ "type":"Create",
+ "id":"https://macgirvin.com/activity/ce9ce740-e1cb-4a75-aa4e-9e923555870d",
+ "published":"2022-02-02T04:41:46Z",
+ "context":"https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb",
+ "conversation":"https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb",
+ "actor":"https://macgirvin.com/channel/mike",
+ "replyTo":"https://macgirvin.com/channel/mike",
+ "url":"https://macgirvin.com/activity/ce9ce740-e1cb-4a75-aa4e-9e923555870d",
+ "object":{
+ "type":"Note",
+ "id":"https://macgirvin.com/item/ce9ce740-e1cb-4a75-aa4e-9e923555870d",
+ "published":"2022-02-02T04:41:46Z",
+ "attributedTo":"https://macgirvin.com/channel/mike",
+ "inReplyTo":"https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb",
+ "context":"https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb",
+ "conversation":"https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb",
+ "content":"The Accepts should get through now. Now to figure out why the comments are failing.",
+ "source":{
+ "content":"The Accepts should get through now. Now to figure out why the comments are failing.",
+ "mediaType":"text/x-multicode"
+ },
+ "replyTo":"https://macgirvin.com/channel/mike",
+ "url":"https://macgirvin.com/item/ce9ce740-e1cb-4a75-aa4e-9e923555870d",
+ "tag":[
+ {
+ "type":"Mention",
+ "href":"https://gleasonator.com/users/macgirvin",
+ "name":"@macgirvin@gleasonator.com"
+ },
+ {
+ "type":"Mention",
+ "href":"https://gleasonator.com/users/alex",
+ "name":"@alex@gleasonator.com"
+ }
+ ],
+ "to":[
+ "https://www.w3.org/ns/activitystreams#Public",
+ "https://gleasonator.com/users/alex",
+ "https://gleasonator.com/users/macgirvin"
+ ],
+ "cc":[
+ "https://macgirvin.com/followers/mike",
+ "https://gleasonator.com/users/macgirvin/followers"
+ ]
+ },
+ "tag":[
+ {
+ "type":"Mention",
+ "href":"https://gleasonator.com/users/macgirvin",
+ "name":"@macgirvin@gleasonator.com"
+ },
+ {
+ "type":"Mention",
+ "href":"https://gleasonator.com/users/alex",
+ "name":"@alex@gleasonator.com"
+ }
+ ],
+ "to":[
+ "https://www.w3.org/ns/activitystreams#Public",
+ "https://gleasonator.com/users/alex",
+ "https://gleasonator.com/users/macgirvin"
+ ],
+ "cc":[
+ "https://macgirvin.com/followers/mike",
+ "https://gleasonator.com/users/macgirvin/followers"
+ ],
+ "signature":{
+ "type":"RsaSignature2017",
+ "nonce":"544080164a412f0592f8257094a870a0177276f4a04cc4410974f5e8fa277a14",
+ "creator":"https://macgirvin.com/channel/mike",
+ "created":"2022-02-02T04:41:46Z",
+ "signatureValue":"BkHEdRkki/DGHctiI6BWyQdn0i9ip+7rFiqqlLgotgQzwA8wzcmyvFIRm8Z+3OqrbzkNyQLCmx4qHvkqWyNrR0eSSJPaBryYvTLpLBz5F5PSpHOI5x4kRGVaI2S1Po+pUMWgchyyQ8ylqdLVHe0FnqId7vFVo9uj4jWydU5wPGlbb5nvnRMQGGyPqzCJ69lopMgCRCUNgbOz6hYVU0Mhqgi9BDjs1crbRLoGexz87tu7FeGEmtyfz8/SBGrDy+X+U3ahykwqd7ggcptsYVu5BY7BfREOLNZE8BwapUCg+QSw9PJv7dLJytdh0kUrzpuAPNbugx7y662FALmHZlxcIC1IVwbPOwEiosDm6wXsOiIyTvnNFcvDre/B1corB2yt5wmO3Cu5jINvp4+aBTheGIKMxBvpJXywpWe6C0VBqfNZSreJtDwp9lHd6D1+L4V6hUCOqiCcqmLT/GI5TOR+EhSpJ02TOkuu+/8hyIfO6ec3uK98y8suyidckbfM60jrbvZh2s/kF9WlDsE9K+Jlyd9Xx3mI5jU+4MXo1MDA57zYpsXw0S+v++rvnOw8CkQr/opVdIRSCG+UB3VRinpgjwW1UQcdAI+fiVaAwqr45MgnIEaQdk13skJUfUl06D9IxKxhu7yNW1tR621w/HN+358qVQWWBoj+1ZhCG3Thjug="
+ }
+}
diff --git a/test/fixtures/rsa_keys/key_1.pem b/test/fixtures/rsa_keys/key_1.pem
new file mode 100644
index 000000000..3da357500
--- /dev/null
+++ b/test/fixtures/rsa_keys/key_1.pem
@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEowIBAAKCAQEA2gdPJM5bWarGZ6QujfQ296l1yEQohS5fdtnxYQc+RXuS1gqZ
+R/jVGHG25o4tmwyCLClyREU1CBTOCQBsg+BSehXlxNR9fiB4KaVQW9MMNa2vhHuG
+f7HLdILiC+SPPTV1Bi8LCpxJowiSpnFPP4BDDeRKib7nOxll9Ln9gEpUueKKabsQ
+EQKCmEJYhIz/8g5R0Qz+6VjASdejDjTEdZbr/rwyldRRjIklyeZ3lBzB/c8/51wn
+HT2Dt0r9NiapxYC3oNhbE2A+4FU9pZTqS8yc3KqWZAy74snaRO9QQSednKlOJpXP
+V3vwWo5CxuSNLttV7zRcrqeYOkIVNF4dQ/bHzQIDAQABAoIBADTCfglnEj4BkF92
+IHnjdgW6cTEUJUYNMba+CKY1LYF85Mx85hi/gzmWEu95yllxznJHWUpiAPJCrpUJ
+EDldaDf44pAd53xE+S8CvQ5rZNH8hLOnfKWb7aL1JSRBm9PxAq+LZL2dkkgsg+hZ
+FRdFv3Q2IT9x/dyUSdLNyyVnV1dfoya/7zOFc7+TwqlofznzrlBgNoAe8Lb4AN/q
+itormPxskqATiq11XtP4F6eQ556eRgHCBxmktx/rRDl6f9G9dvjRQOA2qZlHQdFq
+kjOZsrvItL46LdVoLPOdCYG+3HFeKoDUR1NNXEkt66eqmEhLY4MgzGUT1wqXWk7N
+XowZc9UCgYEA+L5h4PhANiY5Kd+PkRI8zTlJMv8hFqLK17Q0p9eL+mAyOgXjH9so
+QutJf4wU+h6ESDxH+1tCjCN307uUqT7YnT2zHf3b6GcmA+t6ewxfxOY2nJ82HENq
+hK1aodnPTvRRRqCGfrx9qUHRTarTzi+2u86zH+KoMHSiuzn4VpQhg4MCgYEA4GOL
+1tLR9+hyfYuMFo2CtQjp3KpJeGNKEqc33vFD05xJQX+m5THamBv8vzdVlVrMh/7j
+iV85mlA7HaaP+r5DGwtonw9bqY76lYRgJJprsS5lHcRnXsDmU4Ne8RdB3dHNsT5P
+n4P6v8y4jaT638iJ/qLt4e8itOBlZwS//VIglm8CgYEA7KXD3RKRlHK9A7drkOs2
+6VBM8bWEN1LdhGYvilcpFyUZ49XiBVatcS0EGdKdym/qDgc7vElQgJ7ly4y0nGfs
+EXy3whrYcrxfkG8hcZuOKXeUEWHvSuhgmKWMilr8PfN2t6jVDBIrwzGY/Tk+lPUT
+9o1qITW0KZVtlI5MU6JOWB0CgYAHwwnETZibxbuoIhqfcRezYXKNgop2EqEuUgB5
+wsjA2igijuLcDMRt/JHan3RjbTekAKooR1X7w4i39toGJ2y008kzr1lRXTPH1kNp
+ILpW767pv7B/s5aEDwhKuK47mRVPa0Nf1jXnSpKbu7g943b6ivJFnXsK3LRFQwHN
+JnkgGwKBgGUleQVd2GPr1dkqLVOF/s2aNB/+h2b1WFWwq0YTnW81OLwAcUVE4p58
+3GQgz8PCsWbNdTb9yFY5fq0fXgi0+T54FEoZWH09DrOepA433llAwI6sq7egrFdr
+kKQttZMzs6ST9q/IOF4wgqSnBjjTC06vKSkNAlXJz+LMvIRMeBr0
+-----END RSA PRIVATE KEY-----
diff --git a/test/fixtures/rsa_keys/key_2.pem b/test/fixtures/rsa_keys/key_2.pem
new file mode 100644
index 000000000..7a8e8e670
--- /dev/null
+++ b/test/fixtures/rsa_keys/key_2.pem
@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEpQIBAAKCAQEAwu0VqVGRVDW09V3zZ0+08K9HMKivIzIInO0xim3jbfVcg8r1
+sR7vNLorYAB6TDDlXYAWKx1OxUMZusbOigrpQd+5wy8VdCogDD7qk4bbZ+NjXkuD
+ETzrQsGWUXe+IdeH8L0Zh0bGjbarCuA0qAeY1TEteGl+Qwo2dsrBUH7yKmWO6Mz9
+XfPshrIDOGo4QNyVfEBNGq2K9eRrQUHeAPcM2/qu4ZAZRK+VCifDZrF8ZNpoAsnS
+R2mJDhOBUMvI/ZaxOc2ry4EzwcS4uBaM2wONkGWDaqO6jNAQflaX7vtzOAeJB7Dt
+VKXUUcZAGN7uI3c2mG5IKGMhTYUtUdrzmqmtZwIDAQABAoIBAQCHBJfTf3dt4AGn
+T9twfSp06MQj9UPS2i5THI0LONCm8qSReX0zoZzJZgbzaYFM0zWczUMNvDA6vR7O
+XDTmM2acxW4zv6JZo3Ata0sqwuepDz1eLGnt/8dppxQK/ClL4bH8088h/6k6sgPJ
+9cEjfpejXHwFgvT9VM6i/BBpRHVTXWuJqwpDtg+bleQNN3L3RapluDd7BGiKoCwQ
+cCTKd+lxTu9gVJkbRTI/Jn3kV+rnedYxHTxVp5cU1qIabsJWBcdDz25mRHupxQsn
+JbQR4+ZnRLeAsC6WJZtEJz2KjXgBaYroHbGZY3KcGW95ILqiCJoJJugbW1eABKnN
+Q5k8XVspAoGBAPzGJBZuX3c0quorhMIpREmGq2vS6VCQwLhH5qayYYH1LiPDfpdq
+69lOROxZodzLxBgTf5z/a5kBF+eNKvOqfZJeRTxmllxxO1MuJQuRLi/b7BHHLuyN
+Eea+YwtehA0T0CbD2hydefARNDruor2BLvt/kt6qEoIFiPauTsMfXP39AoGBAMVp
+8argtnB+vsk5Z7rpQ4b9gF5QxfNbA0Hpg5wUUdYrUjFr50KWt1iowj6AOVp/EYgr
+xRfvOQdYODDH7R5cjgMbwvtpHo39Zwq7ewaiT1sJXnpGmCDVh+pdTHePC5OOXnxN
+0USK3M4KjltjVqJo7xPPElgJvCejudD47mtHMaQzAoGBAIFQ/PVc0goyL55NVUXf
+xse21cv7wtEsvOuKHT361FegD1LMmN7uHGq32BryYBSNSmzmzMqNAYbtQEV9uxOd
+jVBsWg9kjFgOtcMAQIOCapahdExEEoWCRj49+H3AhN4L3Nl4KQWqqs9efdIIc8lv
+ZZHU2lZ/u6g5HLDWzASW7wQhAoGAdERPRrqN+HdNWinrA9Q6JxjKL8IWs5rYsksb
+biMxh5eAEwdf7oHhfd/2duUB4mCQLMjKjawgxEia33AAIS+VnBMPpQ5mJm4l79Y3
+QNL7Nbyw3gcRtdTM9aT5Ujj3MnJZB5C1PU8jeF4TNZOuBH0UwW/ld+BT5myxFXhm
+wtvtSq0CgYEA19b0/7il4Em6uiLOmYUuqaUoFhUPqzjaS6OM/lRAw12coWv/8/1P
+cwaNZHNMW9Me/bNH3zcOTz0lxnYp2BeRehjFYVPRuS1GU7uwqKtlL2wCPptTfAhN
+aJWIplzUCTg786u+sdNZ0umWRuCLoUpsKTgP/yt4RglzEcfxAuBDljk=
+-----END RSA PRIVATE KEY-----
diff --git a/test/fixtures/rsa_keys/key_3.pem b/test/fixtures/rsa_keys/key_3.pem
new file mode 100644
index 000000000..fbd25c80f
--- /dev/null
+++ b/test/fixtures/rsa_keys/key_3.pem
@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEpQIBAAKCAQEA0GvzqZ3r78GLa7guGn+palKRLGru4D4jnriHgfrUAJrdLyZ5
+9d0zAA4qnS2L6YAMoPPBhBUtIV5e2sn1+rwTClWU3dm3FyBAeqdeIBKN+04AyrUc
+HXYaZtOPJXCTeytzoSQE359Tq6+xwgoHlUWSWxQF51/z/PDQcUvqFjJqAtdiDchd
+3CiFRtdjegyxXGnqvPmBix+vEjDytcVydfch+R1Twf6f5EL7a1jFVWNGcratYBEl
+nqOWKI2fBu/WA8QlrcVW5zmtZo9aJ6IrFddQgQTxPk/mEHgCzv8tbCRI9TxiXeYH
+YqxZFYBW40xbZQwGRjaYHJlIRYp9+TOynW9OZQIDAQABAoIBAQC97cIMDbdVsyAk
+N6D70N5H35ofygqJGtdG6o3B6xuKuZVaREvbu4mgQUigF0Nqs5/OhJMSlGGeCOuT
+oXug1Abd4gNY7++jCWb43tAtlfsAyaJ7FvPZ/SguEBhgW+hp07z5WWN/jSeoSuFI
+G++xHcczbFm88XncRG8O78kQFTz5/DlQYkFXfbqpuS3BqxnrACpDCUfrUwZNYFIp
+CUNq21jdifhHwlS0K3PX8A5HdOYeVnVHaE78LGE4oJVHwcokELv+PYqarWZq/a6L
+vKU3yn2+4pj2WO490iGQaRKVM35vrtjdVxiWEIUiFc3Jg5fKZA3wuHXoF1N1DpPO
+BO6Att55AoGBAP/nC2szmDcnU5Sh8LDeQbL+FpSBwOmFnmel5uqbjKnDzf9emPQu
+NFUls1N9OGgyUq08TnmcY/7wLZzcu7Y9XOUURuYtx9nGRs4RmE2VEBhK1r7CkDIx
+oOb+NtdqnPtQASAxCHszoGCFxpuV7UVoo2SRgc+M4ceX128arvBUtvdrAoGBANCA
+RuO3eelkXaJoCeogEUVWXZ6QmPeYzbMD4vg2DM0ynUbReyuEIIhn+SR7tehlj5ie
+4T3ixVdur6k+YUdiFhUYgXaHBJWHoHl1lrU3ZON8n7AeEk9ft6gg4L07ouj78UMZ
+sArJIlU5mLnW02zbV9XryU39dIgpQREqC0bIOtVvAoGBAORv1JKq6Rt7ALJy6VCJ
+5y4ogfGp7pLHk8NEpuERYDz/rLllMbbwNAk6cV17L8pb+c/pQMhwohcnQiCALxUc
+q/tW4X+CqJ+vzu8PZ90Bzu9Qh2iceGpGQTNTBZPA+UeigI7DFqYcTPM9GDE1YiyO
+nyUcezvSsI4i7s6gjD+/7+DnAoGABm3+QaV1z/m1XX3B2IN2pOG971bcML54kW2s
+QSVBjc5ixT1OhBAGBM7YAwUBnhILtJQptAPbPBAAwMJYs5/VuH7R9zrArG/LRhOX
+Oy1jIhTEw+SZgfMcscWZyJwfMPob/Yq8QAjl0yT8jbaPPIsjEUi9I3eOcWh8RjA6
+ussP7WcCgYEAm3yvJR9z6QGoQQwtDbwjyZPYOSgK9wFS/65aupi6cm/Qk2N1YaLY
+q2amNrzNsIc9vQwYGEHUwogn4MieHk96V7m2f0Hx9EHCMwizU9EiS6oyiLVowTG6
+YsBgSzcpnt0Vkgil4CQks5uQoan0tubEUQ5DI79lLnb02n4o46iAYK0=
+-----END RSA PRIVATE KEY-----
diff --git a/test/fixtures/rsa_keys/key_4.pem b/test/fixtures/rsa_keys/key_4.pem
new file mode 100644
index 000000000..f72b29fb1
--- /dev/null
+++ b/test/fixtures/rsa_keys/key_4.pem
@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEpQIBAAKCAQEAw6MLRbP/henX2JxwdMkQlskKghBoMyUPu9kZpUQ9yYfIm9I4
+a3gEfzef75jKLOSf+BkZulvEUGjC+VnkpV3s+OZCSq81Ykv5PHuTqbj8Cn/dEt/g
+lBXxPcOBKWqa+1cDX6QVIVJsBihLB/1b64H3U96Yu9+knmXvT1Az5MFA2KtSq7HJ
+O+GJNn0EMI7xwPz/atUGlMLrhzwS4UDpw9CAaRPojplJYl4K1JMCFTgTt3hJILXZ
+tw1MKTeeyWzNiuQRBQJuCnqfvsBYsasIlHWfqIL/uBzcGHHCIK5ZW9luntJXyLVj
+zzaF7etIJk1uddM2wnqOOaVyqbssZXGt7Tb9IQIDAQABAoIBAH5QJRUKFK8Xvp9C
+0nD06NsSTtCPW1e6VCBLGf3Uw7f9DY9d+cOZp/2jooYGNnMp4gdD3ZKvcV8hZNGu
+Mqx6qmhB8wdZfLRMrU1Z1Is+vqzgxZJMLiouyKXCNwDQreQd2DXGMUZkew62sUsl
+UFYMge4KyL50tUr4Mb0Z4YePJxk804tcqgw0n+D0lR7ZKhSqoQpoMqEiO+27Yw7E
+Txj/MKH8f/ZJ6LBLRISOdBOrxonHqqeYWchczykCwojOZc3bIlWZGhg727dFTHDC
+yrj3/zsZ2hy+TQsucCFY0RljIbacmHvrF/VqfhTIhg98H0F27V/jiPGsdKhptyst
+E9iQVMkCgYEA42ge4H2Wl42sRh61GOrOgzzr0WZS54bF5skMxiGGnLwnb82rwUBt
+xw94PRORJbV9l+2fkxbfiW0uzornfN8OBHSB64Pcjzzbl5Qm+eaDOiuTLtakYOWQ
+/ipGqw8iE4J9iRteZCo8GnMxWbTkYCporTlFDTeYguXmwR4yCXtlCbMCgYEA3DxM
+7R5HMUWRe64ucdekMh742McS8q/X5jdN9iFGy0M8P1WTyspSlaPDXgjaO4XqpRqg
+djkL993kCDvOAiDl6Tpdiu1iFcOaRLb19Tj1pm8sKdk6X4d10U9lFri4NVYCmvVi
+yOahUYFK/k5bA+1o+KU9Pi82H36H3WNeF4evC9sCgYEAs1zNdc04uQKiTZAs0KFr
+DzI+4aOuYjT35ObQr3mD/h2dkV6MSNmzfF1kPfAv/KkgjXN7+H0DBRbb40bF/MTF
+/peSXZtcnJGote7Bqzu4Z2o1Ja1ga5jF+uKHaKZ//xleQIUYtzJkw4v18cZulrb8
+ZxyTrTAbl6sTjWBuoPH1qGcCgYEAsQNahR9X81dKJpGKTQAYvhw8wOfI5/zD2ArN
+g62dXBRPYUxkPJM/q3xzs6oD1eG+BjQPktYpM3FKLf/7haRxhnLd6qL/uiR8Ywx3
+RkEg2EP0yDIMA+o5nSFmS8vuaxgVgf0HCBiuwnbcEuhhqRdxzp/pSIjjxI6LnzqV
+zu3EmQ8CgYEAhq8Uhvw+79tK7q2PCjDbiucA0n/4a3aguuvRoEh7F93Pf6VGZmT+
+Yld54Cd4P5ATI3r5YdD+JBuvgNMOTVPCaD/WpjbJKnrpNEXtXRQD6LzAXZDNk0sF
+IO9i4gjhBolRykWn10khoPdxw/34FWBP5SxU1JYk75NQXvI3TD+5xbU=
+-----END RSA PRIVATE KEY-----
diff --git a/test/fixtures/rsa_keys/key_5.pem b/test/fixtures/rsa_keys/key_5.pem
new file mode 100644
index 000000000..49342b54e
--- /dev/null
+++ b/test/fixtures/rsa_keys/key_5.pem
@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEpgIBAAKCAQEA0jdKtMkgqnEGO3dn4OKxtggfFDzv+ddXToO0cdPXkUgPajCo
+UGPunz+A1KmkAmLY0Vwk0tkOmKK8GFHek/5zQ+1N2FHBi19fbwlJk7hzh5OiYRhu
+YZi0d6LsqEMKhDk6NqIeiFmOe2YHgklVvZV0hebvHlHLgzDhYrDltSPe33UZa3MS
+g2Knf4WQAjLOo2BAb+oyj/UNXeAqaMGcOr6/kAHPcODW2EGhF3H3umFLv7t/Kq5i
+WPBgarbCGPR5qq9SW5ZIjS3Sz0dl105Grw8wU23CC/2IBZ5vNiu+bkmLEoh/KpX2
+YBILoLmwtVX0Qxc15CrpOi12p+/4pLR8kuEowQIDAQABAoIBAQDMDQ3AJMdHisSQ
+7pvvyDzWRFXesDQE4YmG1gNOxmImTLthyW9n8UjMXbjxNOXVxxtNRdMcs8MeWECa
+nsWeBEzgr7VzeBCV9/LL9kjsUgwamyzwcOWcaL0ssAJmZgUMSfx+0akvkzbiAyzg
+w8ytZSihXYPYe28/ni/5O1sOFI6feenOnJ9NSmVUA24c9TTJGNQs7XRUMZ8f9wt6
+KwRmYeNDKyqH7NvLmmKoDp6m7bMDQxWArVTAoRWTVApnj35iLQtmSi8DBdw6xSzQ
+fKpUe/B4iQmMNxUW7KmolOvCIS5wcYZJE+/j7xshA2GGnOpx4aC+N+w2GSX4Bz/q
+OnYSpGUBAoGBAOwnSeg17xlZqmd86qdiCxg0hRtAjwrd7btYq6nkK+t9woXgcV99
+FBS3nLbk/SIdXCW8vHFJTmld60j2q2kdestYBdHznwNZJ4Ee8JhamzcC64wY7O0x
+RameO/6uoKS4C3VF+Zc9CCPfZOqYujkGvSqbTjFZWuFtDp0GHDk+qEIRAoGBAOPh
++PCB2QkGgiujSPmuCT5PTuNylAug3D4ZdMRKpQb9Rnzlia1Rpdrihq+PvB2vwa+S
+mB6dgb0E7M2AyEMVu5buris0mVpRdmEeLCXR8mYJ48kOslIGArEStXDetfbRaXdK
+7vf4APq2d78AQYldU2fYlo754Dh/3MZIguzpqMuxAoGBAIDJqG/AQiYkFV+c62ff
+e0d3FQRYv+ngQE9Eu1HKwv0Jt7VFQu8din8F56yC013wfxmBhY+Ot/mUo8VF6RNJ
+ZXdSCNKINzcfPwEW+4VLHIzyxbzAty1gCqrHRdbOK4PJb05EnCqTuUW/Bg0+v4hs
+GWwMCKe3IG4CCM8vzuKVPjPRAoGBANYCQtJDb3q9ZQPsTb1FxyKAQprx4Lzm7c9Y
+AsPRQhhFRaxHuLtPQU5FjK1VdBoBFAl5x2iBDPVhqa348pml0E0Xi/PBav9aH61n
+M5i1CUrwoL4SEj9bq61133XHgeXwlnZUpgW0H99T+zMh32pMfea5jfNqETueQMzq
+DiLF8SKRAoGBAOFlU0kRZmAx3Y4rhygp1ydPBt5+zfDaGINRWEN7QWjhX2QQan3C
+SnXZlP3POXLessKxdCpBDq/RqVQhLea6KJMfP3F0YbohfWHt96WjiriJ0d0ZYVhu
+34aUM2UGGG0Kia9OVvftESBaXk02vrY9zU3LAVAv0eLgIADm1kpj85v7
+-----END RSA PRIVATE KEY-----
diff --git a/test/fixtures/soapbox_no_mentions_in_content.json b/test/fixtures/soapbox_no_mentions_in_content.json
new file mode 100644
index 000000000..03b4b8ee4
--- /dev/null
+++ b/test/fixtures/soapbox_no_mentions_in_content.json
@@ -0,0 +1,79 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://gleasonator.com/schemas/litepub-0.1.jsonld",
+ {
+ "@language": "und"
+ }
+ ],
+ "actor": "https://gleasonator.com/users/alex",
+ "attachment": [
+ {
+ "blurhash": "b15#-6_3~l%eDkNraAM#HYMf",
+ "height": 2147,
+ "mediaType": "image/png",
+ "name": "",
+ "type": "Document",
+ "url": "https://media.gleasonator.com/2df1c9cc26c35028db65848143971da0c5a6e04dbd423b194bb018b6c601db9b.png",
+ "width": 966
+ },
+ {
+ "blurhash": "b168EX~q~W-;DiM{VtIUD%Io",
+ "height": 2147,
+ "mediaType": "image/png",
+ "name": "",
+ "type": "Document",
+ "url": "https://media.gleasonator.com/22b42b4cddc1aecc7e2d3dc20bcdd66d5c4e44c2bef119de948e95a587e36b66.png",
+ "width": 966
+ }
+ ],
+ "attributedTo": "https://gleasonator.com/users/alex",
+ "cc": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "content": "<p>Haha yeah, you can control who you reply to.</p>",
+ "context": "https://gleasonator.com/contexts/ba6c8bd9-ac4d-479e-9bd9-5bf570068ae7",
+ "conversation": "https://gleasonator.com/contexts/ba6c8bd9-ac4d-479e-9bd9-5bf570068ae7",
+ "id": "https://gleasonator.com/objects/02af65fe-04f8-46bc-9b1e-31dfe76eaffd",
+ "inReplyTo": "https://shitposter.club/objects/c686d811-4368-48e1-ba11-82c129f93165",
+ "published": "2022-01-19T03:37:35.976545Z",
+ "sensitive": false,
+ "source": "Haha yeah, you can control who you reply to.",
+ "summary": "",
+ "tag": [
+ {
+ "href": "https://lain.com/users/lain",
+ "name": "@lain@lain.com",
+ "type": "Mention"
+ },
+ {
+ "href": "https://shitposter.club/users/coolboymew",
+ "name": "@coolboymew@shitposter.club",
+ "type": "Mention"
+ },
+ {
+ "href": "https://shitposter.club/users/dielan",
+ "name": "@dielan@shitposter.club",
+ "type": "Mention"
+ },
+ {
+ "href": "https://tuusin.misono-ya.info/users/hakui",
+ "name": "@hakui@tuusin.misono-ya.info",
+ "type": "Mention"
+ },
+ {
+ "href": "https://xyzzy.link/users/fence",
+ "name": "@fence@xyzzy.link",
+ "type": "Mention"
+ }
+ ],
+ "to": [
+ "https://shitposter.club/users/dielan",
+ "https://gleasonator.com/users/alex/followers",
+ "https://shitposter.club/users/coolboymew",
+ "https://xyzzy.link/users/fence",
+ "https://tuusin.misono-ya.info/users/hakui",
+ "https://lain.com/users/lain"
+ ],
+ "type": "Note"
+}
diff --git a/test/fixtures/tesla_mock/framatube.org_host_meta b/test/fixtures/tesla_mock/framatube.org_host_meta
index 91516ff6d..02e25bd64 100644
--- a/test/fixtures/tesla_mock/framatube.org_host_meta
+++ b/test/fixtures/tesla_mock/framatube.org_host_meta
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
-<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><hm:Host xmlns:hm="http://host-meta.net/xrd/1.0">framatube.org</hm:Host><Link rel="lrdd" template="http://framatube.org/main/xrd?uri={uri}"><Title>Resource Descriptor</Title></Link></XRD>
+<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><hm:Host xmlns:hm="http://host-meta.net/xrd/1.0">framatube.org</hm:Host><Link rel="lrdd" template="https://framatube.org/main/xrd?uri={uri}"><Title>Resource Descriptor</Title></Link></XRD>
diff --git a/test/fixtures/tesla_mock/gleasonator-AG3RzWfwEKKrY63qj2.json b/test/fixtures/tesla_mock/gleasonator-AG3RzWfwEKKrY63qj2.json
new file mode 100644
index 000000000..62d7bb9ae
--- /dev/null
+++ b/test/fixtures/tesla_mock/gleasonator-AG3RzWfwEKKrY63qj2.json
@@ -0,0 +1,35 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://gleasonator.com/schemas/litepub-0.1.jsonld",
+ {
+ "@language": "und"
+ }
+ ],
+ "actor": "https://gleasonator.com/users/macgirvin",
+ "attachment": [],
+ "attributedTo": "https://gleasonator.com/users/macgirvin",
+ "cc": [
+ "https://gleasonator.com/users/macgirvin/followers"
+ ],
+ "content": "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"9v5bmRalQvjOy0ECcC\" href=\"https://gleasonator.com/users/alex\" rel=\"ugc\">@<span>alex</span></a></span> Any idea why my posts are failing? I sent an Accept/Follow from <a href=\"http://macgirvin.com\" rel=\"ugc\">macgirvin.com</a> at 2022-02-02T04:06:01Z and it vanished into space. As do all my comments to you. <br><br>2022-02-02T04:06:01Z:LOG_INFO:d5c4aa7f6a:Queue.php:435:deliver: deliver: queue post returned 200 from <a href=\"https://gleasonator.com/users/macgirvin/inbox\" rel=\"ugc\">https://gleasonator.com/users/macgirvin/inbox</a><br><br>It&#39;s OK if I&#39;m blocked, but if that&#39;s the case, I shouldn&#39;t be able to send a follow to that address should I?",
+ "context": "https://gleasonator.com/contexts/b7f01f94-bc92-4d89-a085-0ffc211b0e42",
+ "conversation": "https://gleasonator.com/contexts/b7f01f94-bc92-4d89-a085-0ffc211b0e42",
+ "id": "https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb",
+ "published": "2022-02-02T04:14:10.965833Z",
+ "sensitive": false,
+ "source": "@alex Any idea why my posts are failing? I sent an Accept/Follow from macgirvin.com at 2022-02-02T04:06:01Z and it vanished into space. As do all my comments to you. \n\n2022-02-02T04:06:01Z:LOG_INFO:d5c4aa7f6a:Queue.php:435:deliver: deliver: queue post returned 200 from https://gleasonator.com/users/macgirvin/inbox\n\nIt's OK if I'm blocked, but if that's the case, I shouldn't be able to send a follow to that address should I?",
+ "summary": "",
+ "tag": [
+ {
+ "href": "https://gleasonator.com/users/alex",
+ "name": "@alex",
+ "type": "Mention"
+ }
+ ],
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public",
+ "https://gleasonator.com/users/alex"
+ ],
+ "type": "Note"
+}
diff --git a/test/fixtures/tesla_mock/helene@p.helene.moe.json b/test/fixtures/tesla_mock/helene@p.helene.moe.json
new file mode 100644
index 000000000..d7444817f
--- /dev/null
+++ b/test/fixtures/tesla_mock/helene@p.helene.moe.json
@@ -0,0 +1,50 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://p.helene.moe/schemas/litepub-0.1.jsonld",
+ {
+ "@language": "und"
+ }
+ ],
+ "alsoKnownAs": [],
+ "attachment": [
+ {
+ "name": "Timezone",
+ "type": "PropertyValue",
+ "value": "UTC+2 (Paris/Berlin)"
+ }
+ ],
+ "capabilities": {
+ "acceptsChatMessages": true
+ },
+ "discoverable": true,
+ "endpoints": {
+ "oauthAuthorizationEndpoint": "https://p.helene.moe/oauth/authorize",
+ "oauthRegistrationEndpoint": "https://p.helene.moe/api/v1/apps",
+ "oauthTokenEndpoint": "https://p.helene.moe/oauth/token",
+ "sharedInbox": "https://p.helene.moe/inbox",
+ "uploadMedia": "https://p.helene.moe/api/ap/upload_media"
+ },
+ "featured": "https://p.helene.moe/users/helene/collections/featured",
+ "followers": "https://p.helene.moe/users/helene/followers",
+ "following": "https://p.helene.moe/users/helene/following",
+ "icon": {
+ "type": "Image",
+ "url": "https://p.helene.moe/media/9a39209daa5a66b7ebb0547b08bf8360aa9d8d65a4ffba2603c6ffbe6aecb432.jpg"
+ },
+ "id": "https://p.helene.moe/users/helene",
+ "inbox": "https://p.helene.moe/users/helene/inbox",
+ "manuallyApprovesFollowers": false,
+ "name": "Hélène",
+ "outbox": "https://p.helene.moe/users/helene/outbox",
+ "preferredUsername": "helene",
+ "publicKey": {
+ "id": "https://p.helene.moe/users/helene#main-key",
+ "owner": "https://p.helene.moe/users/helene",
+ "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtoSBPU/VS2Kx3f6ap3zv\nZVacJsgUfaoFb3c2ii/FRh9RmRVlarq8sJXcjsQt1e0oxWaWJaIDDwyKZPt6hXae\nrY/AiGGeNu+NA+BtY7l7+9Yu67HUyT62+1qAwYHKBXX3fLOPs/YmQI0Tt0c4wKAG\nKEkiYsRizghgpzUC6jqdKV71DJkUZ8yhckCGb2fLko1ajbWEssdaP51aLsyRMyC2\nuzeWrxtD4O/HG0ea4S6y5X6hnsAHIK4Y3nnyIQ6pn4tOsl3HgqkjXE9MmZSvMCFx\nBq89TfZrVXNa2gSZdZLdbbJstzEScQWNt1p6tA6rM+e4JXYGr+rMdF3G+jV7afI2\nFQIDAQAB\n-----END PUBLIC KEY-----\n\n"
+ },
+ "summary": "I can speak: Français, English, Deutsch (nicht sehr gut), 日本語 (not very well)",
+ "tag": [],
+ "type": "Person",
+ "url": "https://p.helene.moe/users/helene"
+} \ No newline at end of file
diff --git a/test/fixtures/tesla_mock/https___lm.kazv.moe_users_mewmew.xml b/test/fixtures/tesla_mock/https___lm.kazv.moe_users_mewmew.xml
new file mode 100644
index 000000000..b9e8dbbf5
--- /dev/null
+++ b/test/fixtures/tesla_mock/https___lm.kazv.moe_users_mewmew.xml
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Subject>acct:mewmew@lm.kazv.moe</Subject><Alias>https://lm.kazv.moe/users/mewmew</Alias><Alias>https://lm.kazv.moe/users/tester</Alias><Alias>https://lm.kazv.moe/users/testuser</Alias><Link href="https://lm.kazv.moe/users/mewmew" rel="http://webfinger.net/rel/profile-page" type="text/html" /><Link href="https://lm.kazv.moe/users/mewmew" rel="self" type="application/activity+json" /><Link href="https://lm.kazv.moe/users/mewmew" rel="self" type="application/ld+json; profile=&quot;https://www.w3.org/ns/activitystreams&quot;" /><Link rel="http://ostatus.org/schema/1.0/subscribe" template="https://lm.kazv.moe/ostatus_subscribe?acct={uri}" /></XRD>
diff --git a/test/fixtures/tesla_mock/lm.kazv.moe_host_meta b/test/fixtures/tesla_mock/lm.kazv.moe_host_meta
new file mode 100644
index 000000000..02e6f055e
--- /dev/null
+++ b/test/fixtures/tesla_mock/lm.kazv.moe_host_meta
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" template="https://lm.kazv.moe/.well-known/webfinger?resource={uri}" type="application/xrd+xml" /></XRD>
diff --git a/test/fixtures/tesla_mock/macgirvin@gleasonator.com.json b/test/fixtures/tesla_mock/macgirvin@gleasonator.com.json
new file mode 100644
index 000000000..9d7d47d40
--- /dev/null
+++ b/test/fixtures/tesla_mock/macgirvin@gleasonator.com.json
@@ -0,0 +1,41 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://gleasonator.com/schemas/litepub-0.1.jsonld",
+ {
+ "@language": "und"
+ }
+ ],
+ "alsoKnownAs": [],
+ "attachment": [],
+ "capabilities": {
+ "acceptsChatMessages": true
+ },
+ "discoverable": false,
+ "endpoints": {
+ "oauthAuthorizationEndpoint": "https://gleasonator.com/oauth/authorize",
+ "oauthRegistrationEndpoint": "https://gleasonator.com/api/v1/apps",
+ "oauthTokenEndpoint": "https://gleasonator.com/oauth/token",
+ "sharedInbox": "https://gleasonator.com/inbox",
+ "uploadMedia": "https://gleasonator.com/api/ap/upload_media"
+ },
+ "featured": "https://gleasonator.com/users/macgirvin/collections/featured",
+ "followers": "https://gleasonator.com/users/macgirvin/followers",
+ "following": "https://gleasonator.com/users/macgirvin/following",
+ "id": "https://gleasonator.com/users/macgirvin",
+ "inbox": "https://gleasonator.com/users/macgirvin/inbox",
+ "manuallyApprovesFollowers": false,
+ "name": "macgirvin",
+ "outbox": "https://gleasonator.com/users/macgirvin/outbox",
+ "preferredUsername": "macgirvin",
+ "publicKey": {
+ "id": "https://gleasonator.com/users/macgirvin#main-key",
+ "owner": "https://gleasonator.com/users/macgirvin",
+ "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0AUMgsQu87tLwoJjZfZu\nsj7NV0qt/THdK8aw4Ha2GZfNkwrep99AZ8gmCI+rr+N5vyETAARzG5/Qzr5bNTUx\nsc1fxFemhhi6sxzAv4qZ5AgvWQ4YPFWizSp5ZY1jpPHLOeF2IftMf8CwVI82PtD0\n7m7T6iUYA4vfvMp9LxVrzQA+CAtpsQxAejTGCt37yM9T2mEWqfmJQQHRIQ4brKBL\nI82sNbzk1cbTwCfH7vRNS/l1ND+vaUGGkDKtpRl56BLmt4picYL0avc+8oO7ebpc\n/zUoS8OOi+mpEzjv7TBrSirYEIGvIh3TKHWSPrpHpQTqj9xBQBy+AxXTWahQEO2M\ndQIDAQAB\n-----END PUBLIC KEY-----\n\n"
+ },
+ "summary": "",
+ "tag": [],
+ "type": "Person",
+ "url": "https://gleasonator.com/users/macgirvin",
+ "vcard:bday": null
+}
diff --git a/test/fixtures/tesla_mock/mametsuko@mk.absturztau.be.json b/test/fixtures/tesla_mock/mametsuko@mk.absturztau.be.json
new file mode 100644
index 000000000..d8c13f775
--- /dev/null
+++ b/test/fixtures/tesla_mock/mametsuko@mk.absturztau.be.json
@@ -0,0 +1,65 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ {
+ "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+ "sensitive": "as:sensitive",
+ "Hashtag": "as:Hashtag",
+ "quoteUrl": "as:quoteUrl",
+ "toot": "http://joinmastodon.org/ns#",
+ "Emoji": "toot:Emoji",
+ "featured": "toot:featured",
+ "discoverable": "toot:discoverable",
+ "schema": "http://schema.org#",
+ "PropertyValue": "schema:PropertyValue",
+ "value": "schema:value",
+ "misskey": "https://misskey-hub.net/ns#",
+ "_misskey_content": "misskey:_misskey_content",
+ "_misskey_quote": "misskey:_misskey_quote",
+ "_misskey_reaction": "misskey:_misskey_reaction",
+ "_misskey_votes": "misskey:_misskey_votes",
+ "_misskey_talk": "misskey:_misskey_talk",
+ "isCat": "misskey:isCat",
+ "vcard": "http://www.w3.org/2006/vcard/ns#"
+ }
+ ],
+ "type": "Person",
+ "id": "https://mk.absturztau.be/users/8ozbzjs3o8",
+ "inbox": "https://mk.absturztau.be/users/8ozbzjs3o8/inbox",
+ "outbox": "https://mk.absturztau.be/users/8ozbzjs3o8/outbox",
+ "followers": "https://mk.absturztau.be/users/8ozbzjs3o8/followers",
+ "following": "https://mk.absturztau.be/users/8ozbzjs3o8/following",
+ "featured": "https://mk.absturztau.be/users/8ozbzjs3o8/collections/featured",
+ "sharedInbox": "https://mk.absturztau.be/inbox",
+ "endpoints": {
+ "sharedInbox": "https://mk.absturztau.be/inbox"
+ },
+ "url": "https://mk.absturztau.be/@mametsuko",
+ "preferredUsername": "mametsuko",
+ "name": "mametschko",
+ "summary": "<p><span>nya, ich bin eine Brotperson</span></p>",
+ "icon": {
+ "type": "Image",
+ "url": "https://mk.absturztau.be/files/webpublic-3b5594f4-fa52-4548-b4e3-c379ae2143ed",
+ "sensitive": false,
+ "name": null
+ },
+ "image": {
+ "type": "Image",
+ "url": "https://mk.absturztau.be/files/webpublic-0d03b03d-b14b-4916-ac3d-8a137118ec84",
+ "sensitive": false,
+ "name": null
+ },
+ "tag": [],
+ "manuallyApprovesFollowers": true,
+ "discoverable": false,
+ "publicKey": {
+ "id": "https://mk.absturztau.be/users/8ozbzjs3o8#main-key",
+ "type": "Key",
+ "owner": "https://mk.absturztau.be/users/8ozbzjs3o8",
+ "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAuN/S1spBGmh8FXI1Bt16\nXB7Cc0QutBp7UPgmDNHjOfsq0zrF4g3L1UBxvrpU0XX77XPMCd9yPvGwAYURH2mv\ntIcYuE+R90VLDmBu5MTVthcG2D874eCZ2rD2YsEYmN5AjTX7QBIqCck+qDhVWkkM\nEZ6S5Ht6IJ5Of74eKffXElQI/C6QB+9uEDOmPk0jCzgI5gw7xvJqFj/DIF4kUUAu\nA89JqaFZzZlkrSrj4cr48bLN/YOmpdaHu0BKHaDSHct4+MqlixqovgdB6RboCEDw\ne4Aeav7+Q0Y9oGIvuggg0Q+nCubnVNnaPyzd817tpPVzyZmTts+DKyDuv90SX3nR\nsPaNa5Ty60eqplUk4b7X1gSvuzBJUFBxTVV84WnjwoeoydaS6rSyjCDPGLBjaByc\nFyWMMEb/zlQyhLZfBlvT7k96wRSsMszh2hDALWmgYIhq/jNwINvALJ1GKLNHHKZ4\nyz2LnxVpRm2rWrZzbvtcnSQOt3LaPSZn8Wgwv4buyHF02iuVuIamZVtKexsE1Ixl\nIi9qa3AKEc5gOzYXhRhvHaruzoCehUbb/UHC5c8Tto8L5G1xYzjLP3qj3PT9w/wM\n+k1Ra/4JhuAnVFROOoOmx9rIELLHH7juY2nhM7plGhyt1M5gysgqEloij8QzyQU2\nZK1YlAERG2XFO6br8omhcmECAwEAAQ==\n-----END PUBLIC KEY-----\n"
+ },
+ "isCat": true,
+ "vcard:Address": "Vienna, Austria"
+} \ No newline at end of file
diff --git a/test/fixtures/tesla_mock/mewmew@lm.kazv.moe.json b/test/fixtures/tesla_mock/mewmew@lm.kazv.moe.json
new file mode 100644
index 000000000..8d2c3e1e7
--- /dev/null
+++ b/test/fixtures/tesla_mock/mewmew@lm.kazv.moe.json
@@ -0,0 +1 @@
+{"@context":["https://www.w3.org/ns/activitystreams","https://lm.kazv.moe/schemas/litepub-0.1.jsonld",{"@language":"und"}],"alsoKnownAs":["https://lm.kazv.moe/users/tester","https://lm.kazv.moe/users/testuser"],"attachment":[],"capabilities":{"acceptsChatMessages":true},"discoverable":false,"endpoints":{"oauthAuthorizationEndpoint":"https://lm.kazv.moe/oauth/authorize","oauthRegistrationEndpoint":"https://lm.kazv.moe/api/v1/apps","oauthTokenEndpoint":"https://lm.kazv.moe/oauth/token","sharedInbox":"https://lm.kazv.moe/inbox","uploadMedia":"https://lm.kazv.moe/api/ap/upload_media"},"featured":"https://lm.kazv.moe/users/mewmew/collections/featured","followers":"https://lm.kazv.moe/users/mewmew/followers","following":"https://lm.kazv.moe/users/mewmew/following","id":"https://lm.kazv.moe/users/mewmew","inbox":"https://lm.kazv.moe/users/mewmew/inbox","manuallyApprovesFollowers":false,"name":"mew","outbox":"https://lm.kazv.moe/users/mewmew/outbox","preferredUsername":"mewmew","publicKey":{"id":"https://lm.kazv.moe/users/mewmew#main-key","owner":"https://lm.kazv.moe/users/mewmew","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0nT3IVUwx799FSJyJEOY\n5D2c5zgtt2Z+BD9417eVLmVQF5fJlWgcKS4pbFc76zkYoBkZtV7XbzvN9KTNulpa\nUGNOM0/UdEoQLB8xbVCMm0ABUU8vbTWoMTxp93bfVHBz+33FPYdH1JHX4TCU/mJF\nX4UJMvFmMn5BFjSQm9GG6Eq2j6SAUsaTa8+Rrd8FzS6zb/dk3N/Llz0tfsZYS0sq\nEy9OYhsKOQ6eegULFJOF3Hz04vzwftmeXFsbb3aO2zKz3uAMYZglWHNBYJAePBtJ\ng362kqdJwgT14TFnZ0K2ziDPbkRULG1Kke/lsqw2rPF6Q6P4PeO1shCEDthoDoID\newIDAQAB\n-----END PUBLIC KEY-----\n\n"},"summary":"","tag":[],"type":"Person","url":"https://lm.kazv.moe/users/mewmew"}
diff --git a/test/fixtures/tesla_mock/mk.absturztau.be-93e7nm8wqg-activity.json b/test/fixtures/tesla_mock/mk.absturztau.be-93e7nm8wqg-activity.json
new file mode 100644
index 000000000..b45ab78e4
--- /dev/null
+++ b/test/fixtures/tesla_mock/mk.absturztau.be-93e7nm8wqg-activity.json
@@ -0,0 +1 @@
+{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","Hashtag":"as:Hashtag","quoteUrl":"as:quoteUrl","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji","featured":"toot:featured","discoverable":"toot:discoverable","schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value","misskey":"https://misskey-hub.net/ns#","_misskey_content":"misskey:_misskey_content","_misskey_quote":"misskey:_misskey_quote","_misskey_reaction":"misskey:_misskey_reaction","_misskey_votes":"misskey:_misskey_votes","_misskey_talk":"misskey:_misskey_talk","isCat":"misskey:isCat","vcard":"http://www.w3.org/2006/vcard/ns#"}],"id":"https://mk.absturztau.be/notes/93e7nm8wqg/activity","actor":"https://mk.absturztau.be/users/8ozbzjs3o8","type":"Create","published":"2022-08-01T11:06:49.568Z","object":{"id":"https://mk.absturztau.be/notes/93e7nm8wqg","type":"Note","attributedTo":"https://mk.absturztau.be/users/8ozbzjs3o8","summary":null,"content":"<p><span>meow</span></p>","_misskey_content":"meow","published":"2022-08-01T11:06:49.568Z","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://mk.absturztau.be/users/8ozbzjs3o8/followers"],"inReplyTo":null,"attachment":[],"sensitive":false,"tag":[]},"to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://mk.absturztau.be/users/8ozbzjs3o8/followers"]} \ No newline at end of file
diff --git a/test/fixtures/tesla_mock/mk.absturztau.be-93e7nm8wqg.json b/test/fixtures/tesla_mock/mk.absturztau.be-93e7nm8wqg.json
new file mode 100644
index 000000000..1b931a9a4
--- /dev/null
+++ b/test/fixtures/tesla_mock/mk.absturztau.be-93e7nm8wqg.json
@@ -0,0 +1,44 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ {
+ "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+ "sensitive": "as:sensitive",
+ "Hashtag": "as:Hashtag",
+ "quoteUrl": "as:quoteUrl",
+ "toot": "http://joinmastodon.org/ns#",
+ "Emoji": "toot:Emoji",
+ "featured": "toot:featured",
+ "discoverable": "toot:discoverable",
+ "schema": "http://schema.org#",
+ "PropertyValue": "schema:PropertyValue",
+ "value": "schema:value",
+ "misskey": "https://misskey-hub.net/ns#",
+ "_misskey_content": "misskey:_misskey_content",
+ "_misskey_quote": "misskey:_misskey_quote",
+ "_misskey_reaction": "misskey:_misskey_reaction",
+ "_misskey_votes": "misskey:_misskey_votes",
+ "_misskey_talk": "misskey:_misskey_talk",
+ "isCat": "misskey:isCat",
+ "vcard": "http://www.w3.org/2006/vcard/ns#"
+ }
+ ],
+ "id": "https://mk.absturztau.be/notes/93e7nm8wqg",
+ "type": "Note",
+ "attributedTo": "https://mk.absturztau.be/users/8ozbzjs3o8",
+ "summary": null,
+ "content": "<p><span>meow</span></p>",
+ "_misskey_content": "meow",
+ "published": "2022-08-01T11:06:49.568Z",
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "cc": [
+ "https://mk.absturztau.be/users/8ozbzjs3o8/followers"
+ ],
+ "inReplyTo": null,
+ "attachment": [],
+ "sensitive": false,
+ "tag": []
+} \ No newline at end of file
diff --git a/test/fixtures/tesla_mock/p.helene.moe-AM7S6vZQmL6pI9TgPY.json b/test/fixtures/tesla_mock/p.helene.moe-AM7S6vZQmL6pI9TgPY.json
new file mode 100644
index 000000000..a1ef5e20b
--- /dev/null
+++ b/test/fixtures/tesla_mock/p.helene.moe-AM7S6vZQmL6pI9TgPY.json
@@ -0,0 +1,36 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://p.helene.moe/schemas/litepub-0.1.jsonld",
+ {
+ "@language": "und"
+ }
+ ],
+ "actor": "https://p.helene.moe/users/helene",
+ "attachment": [],
+ "attributedTo": "https://p.helene.moe/users/helene",
+ "cc": [
+ "https://p.helene.moe/users/helene/followers"
+ ],
+ "content": "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"AHntpQ4T3J4OSnpgMC\" href=\"https://mk.absturztau.be/@mametsuko\" rel=\"ugc\">@<span>mametsuko</span></a></span> meow",
+ "context": "https://p.helene.moe/contexts/cc324643-5583-4c3f-91d2-c6ed37db159d",
+ "conversation": "https://p.helene.moe/contexts/cc324643-5583-4c3f-91d2-c6ed37db159d",
+ "id": "https://p.helene.moe/objects/fd5910ac-d9dc-412e-8d1d-914b203296c4",
+ "inReplyTo": "https://mk.absturztau.be/notes/93e7nm8wqg",
+ "published": "2022-08-02T13:46:58.403996Z",
+ "sensitive": null,
+ "source": "@mametsuko@mk.absturztau.be meow",
+ "summary": "",
+ "tag": [
+ {
+ "href": "https://mk.absturztau.be/users/8ozbzjs3o8",
+ "name": "@mametsuko@mk.absturztau.be",
+ "type": "Mention"
+ }
+ ],
+ "to": [
+ "https://mk.absturztau.be/users/8ozbzjs3o8",
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "type": "Note"
+} \ No newline at end of file
diff --git a/test/fixtures/tesla_mock/status.alpicola.com_host_meta b/test/fixtures/tesla_mock/status.alpicola.com_host_meta
index 6948c30ea..78155f644 100644
--- a/test/fixtures/tesla_mock/status.alpicola.com_host_meta
+++ b/test/fixtures/tesla_mock/status.alpicola.com_host_meta
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
-<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><hm:Host xmlns:hm="http://host-meta.net/xrd/1.0">status.alpicola.com</hm:Host><Link rel="lrdd" template="http://status.alpicola.com/main/xrd?uri={uri}"><Title>Resource Descriptor</Title></Link></XRD> \ No newline at end of file
+<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><hm:Host xmlns:hm="http://host-meta.net/xrd/1.0">status.alpicola.com</hm:Host><Link rel="lrdd" template="https://status.alpicola.com/main/xrd?uri={uri}"><Title>Resource Descriptor</Title></Link></XRD>
diff --git a/test/fixtures/webfinger/masto-host-meta.xml b/test/fixtures/webfinger/masto-host-meta.xml
new file mode 100644
index 000000000..f432a27c3
--- /dev/null
+++ b/test/fixtures/webfinger/masto-host-meta.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
+ <Link rel="lrdd" template="https://{{domain}}/.well-known/webfinger?resource={uri}"/>
+</XRD>
diff --git a/test/fixtures/webfinger/masto-user.json b/test/fixtures/webfinger/masto-user.json
new file mode 100644
index 000000000..1702de011
--- /dev/null
+++ b/test/fixtures/webfinger/masto-user.json
@@ -0,0 +1,92 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ {
+ "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+ "toot": "http://joinmastodon.org/ns#",
+ "featured": {
+ "@id": "toot:featured",
+ "@type": "@id"
+ },
+ "featuredTags": {
+ "@id": "toot:featuredTags",
+ "@type": "@id"
+ },
+ "alsoKnownAs": {
+ "@id": "as:alsoKnownAs",
+ "@type": "@id"
+ },
+ "movedTo": {
+ "@id": "as:movedTo",
+ "@type": "@id"
+ },
+ "schema": "http://schema.org#",
+ "PropertyValue": "schema:PropertyValue",
+ "value": "schema:value",
+ "IdentityProof": "toot:IdentityProof",
+ "discoverable": "toot:discoverable",
+ "Device": "toot:Device",
+ "Ed25519Signature": "toot:Ed25519Signature",
+ "Ed25519Key": "toot:Ed25519Key",
+ "Curve25519Key": "toot:Curve25519Key",
+ "EncryptedMessage": "toot:EncryptedMessage",
+ "publicKeyBase64": "toot:publicKeyBase64",
+ "deviceId": "toot:deviceId",
+ "claim": {
+ "@type": "@id",
+ "@id": "toot:claim"
+ },
+ "fingerprintKey": {
+ "@type": "@id",
+ "@id": "toot:fingerprintKey"
+ },
+ "identityKey": {
+ "@type": "@id",
+ "@id": "toot:identityKey"
+ },
+ "devices": {
+ "@type": "@id",
+ "@id": "toot:devices"
+ },
+ "messageFranking": "toot:messageFranking",
+ "messageType": "toot:messageType",
+ "cipherText": "toot:cipherText",
+ "suspended": "toot:suspended",
+ "focalPoint": {
+ "@container": "@list",
+ "@id": "toot:focalPoint"
+ }
+ }
+ ],
+ "id": "https://{{domain}}/users/{{nickname}}",
+ "type": "Person",
+ "following": "https://{{domain}}/users/{{nickname}}/following",
+ "followers": "https://{{domain}}/users/{{nickname}}/followers",
+ "inbox": "https://{{domain}}/users/{{nickname}}/inbox",
+ "outbox": "https://{{domain}}/users/{{nickname}}/outbox",
+ "featured": "https://{{domain}}/users/{{nickname}}/collections/featured",
+ "featuredTags": "https://{{domain}}/users/{{nickname}}/collections/tags",
+ "preferredUsername": "{{nickname}}",
+ "name": "Name Name",
+ "summary": "<p>Summary</p>",
+ "url": "https://{{domain}}/@{{nickname}}",
+ "manuallyApprovesFollowers": false,
+ "discoverable": false,
+ "devices": "https://{{domain}}/users/{{nickname}}/collections/devices",
+ "publicKey": {
+ "id": "https://{{domain}}/users/{{nickname}}#main-key",
+ "owner": "https://{{domain}}/users/{{nickname}}",
+ "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvwDujxmxoYHs64MyVB3L\nG5ZyBxV3ufaMRBFu42bkcTpISq1WwZ+3Zb6CI8zOO+nM+Q2llrVRYjZa4ZFnOLvM\nTq/Kf+Zf5wy2aCRer88gX+MsJOAtItSi412y0a/rKOuFaDYLOLeTkRvmGLgZWbsr\nZJOp+YWb3zQ5qsIOInkc5BwI172tMsGeFtsnbNApPV4lrmtTGaJ8RiM8MR7XANBO\nfOHggSt1+eAIKGIsCmINEMzs1mG9D75xKtC/sM8GfbvBclQcBstGkHAEj1VHPW0c\nh6Bok5/QQppicyb8UA1PAA9bznSFtKlYE4xCH8rlCDSDTBRtdnBWHKcj619Ujz4Q\nawIDAQAB\n-----END PUBLIC KEY-----\n"
+ },
+ "tag": [],
+ "attachment": [],
+ "endpoints": {
+ "sharedInbox": "https://{{domain}}/inbox"
+ },
+ "icon": {
+ "type": "Image",
+ "mediaType": "image/jpeg",
+ "url": "https://s3.wasabisys.com/merp/accounts/avatars/000/000/001/original/6fdd3eee632af247.jpg"
+ }
+}
diff --git a/test/fixtures/webfinger/masto-webfinger.json b/test/fixtures/webfinger/masto-webfinger.json
new file mode 100644
index 000000000..561be3fff
--- /dev/null
+++ b/test/fixtures/webfinger/masto-webfinger.json
@@ -0,0 +1,23 @@
+{
+ "subject": "acct:{{nickname}}@{{domain}}",
+ "aliases": [
+ "https://{{subdomain}}/@{{nickname}}",
+ "https://{{subdomain}}/users/{{nickname}}"
+ ],
+ "links": [
+ {
+ "rel": "http://webfinger.net/rel/profile-page",
+ "type": "text/html",
+ "href": "https://{{subdomain}}/@{{nickname}}"
+ },
+ {
+ "rel": "self",
+ "type": "application/activity+json",
+ "href": "https://{{subdomain}}/users/{{nickname}}"
+ },
+ {
+ "rel": "http://ostatus.org/schema/1.0/subscribe",
+ "template": "https://{{subdomain}}/authorize_interaction?uri={uri}"
+ }
+ ]
+}
diff --git a/test/fixtures/webfinger/pleroma-host-meta.xml b/test/fixtures/webfinger/pleroma-host-meta.xml
new file mode 100644
index 000000000..88c274a1a
--- /dev/null
+++ b/test/fixtures/webfinger/pleroma-host-meta.xml
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" template="https://{{domain}}/.well-known/webfinger?resource={uri}" type="application/xrd+xml" /></XRD>
diff --git a/test/fixtures/webfinger/pleroma-user.json b/test/fixtures/webfinger/pleroma-user.json
new file mode 100644
index 000000000..b822db46c
--- /dev/null
+++ b/test/fixtures/webfinger/pleroma-user.json
@@ -0,0 +1,58 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://{{domain}}/schemas/litepub-0.1.jsonld",
+ {
+ "@language": "und"
+ }
+ ],
+ "alsoKnownAs": [],
+ "attachment": [],
+ "capabilities": {
+ "acceptsChatMessages": true
+ },
+ "discoverable": true,
+ "endpoints": {
+ "oauthAuthorizationEndpoint": "https://{{domain}}/oauth/authorize",
+ "oauthRegistrationEndpoint": "https://{{domain}}/api/v1/apps",
+ "oauthTokenEndpoint": "https://{{domain}}/oauth/token",
+ "sharedInbox": "https://{{domain}}/inbox",
+ "uploadMedia": "https://{{domain}}/api/ap/upload_media"
+ },
+ "followers": "https://{{domain}}/users/{{nickname}}/followers",
+ "following": "https://{{domain}}/users/{{nickname}}/following",
+ "icon": {
+ "type": "Image",
+ "url": "https://{{domain}}/media/a932a27f158b63c3a97e3a57d5384f714a82249274c6fc66c9eca581b4fd8af2.jpg"
+ },
+ "id": "https://{{domain}}/users/{{nickname}}",
+ "image": {
+ "type": "Image",
+ "url": "https://{{domain}}/media/db15f476d0ad14488db4762b7800479e6ef67b1824f8b9ea5c1fa05b7525c5b7.jpg"
+ },
+ "inbox": "https://{{domain}}/users/{{nickname}}/inbox",
+ "manuallyApprovesFollowers": false,
+ "name": "{{nickname}} :verified:",
+ "outbox": "https://{{domain}}/users/{{nickname}}/outbox",
+ "preferredUsername": "{{nickname}}",
+ "publicKey": {
+ "id": "https://{{domain}}/users/{{nickname}}#main-key",
+ "owner": "https://{{domain}}/users/{{nickname}}",
+ "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu4XOAopC4nRIxNlHlt60\n//nCicuedu5wvLGIoQ+KUM2u7/PhLrrTDEqr1A7yQL95S0X8ryYtALgFLI5A54ww\nqjMIbIGAs44lEmDLMEd+XI+XxREE8wdsFpb4QQzWug0DTyqlMouTU25k0tfKh1rF\n4PMJ3uBSjDTAGgFvLNyFWTiVVgChbTNgGOmrEBucRl4NmKzQ69/FIUwENV88oQSU\n3bWvQTEH9rWH1rCLpkmQwdRiWfnhFX/4EUqXukfgoskvenKR8ff3nYhElDqFoE0e\nqUnIW1OZceyl8JewVLcL6m0/wdKeosTsfrcWc8DKfnRYQcBGNoBEq9GrOHDU0q2v\nyQIDAQAB\n-----END PUBLIC KEY-----\n\n"
+ },
+ "summary": "Pleroma BE dev",
+ "tag": [
+ {
+ "icon": {
+ "type": "Image",
+ "url": "https://{{domain}}/emoji/mine/6143373a807b1ae7.png"
+ },
+ "id": "https://{{domain}}/emoji/mine/6143373a807b1ae7.png",
+ "name": ":verified:",
+ "type": "Emoji",
+ "updated": "1970-01-01T00:00:00Z"
+ }
+ ],
+ "type": "Person",
+ "url": "https://{{domain}}/users/{{nickname}}"
+}
diff --git a/test/fixtures/webfinger/pleroma-webfinger.json b/test/fixtures/webfinger/pleroma-webfinger.json
new file mode 100644
index 000000000..8f075eaaf
--- /dev/null
+++ b/test/fixtures/webfinger/pleroma-webfinger.json
@@ -0,0 +1,27 @@
+{
+ "aliases": [
+ "https://{{subdomain}}/users/{{nickname}}"
+ ],
+ "links": [
+ {
+ "href": "https://{{subdomain}}/users/{{nickname}}",
+ "rel": "http://webfinger.net/rel/profile-page",
+ "type": "text/html"
+ },
+ {
+ "href": "https://{{subdomain}}/users/{{nickname}}",
+ "rel": "self",
+ "type": "application/activity+json"
+ },
+ {
+ "href": "https://{{subdomain}}/users/{{nickname}}",
+ "rel": "self",
+ "type": "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
+ },
+ {
+ "rel": "http://ostatus.org/schema/1.0/subscribe",
+ "template": "https://{{subdomain}}/ostatus_subscribe?acct={uri}"
+ }
+ ],
+ "subject": "acct:{{nickname}}@{{domain}}"
+}
diff --git a/test/mix/pleroma_test.exs b/test/mix/pleroma_test.exs
index af62cc1d9..c981ee9b9 100644
--- a/test/mix/pleroma_test.exs
+++ b/test/mix/pleroma_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.PleromaTest do
diff --git a/test/mix/tasks/pleroma/app_test.exs b/test/mix/tasks/pleroma/app_test.exs
index 9eabd32af..f35447edc 100644
--- a/test/mix/tasks/pleroma/app_test.exs
+++ b/test/mix/tasks/pleroma/app_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.AppTest do
diff --git a/test/mix/tasks/pleroma/config_test.exs b/test/mix/tasks/pleroma/config_test.exs
index 2b8252db7..cf6d74907 100644
--- a/test/mix/tasks/pleroma/config_test.exs
+++ b/test/mix/tasks/pleroma/config_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.ConfigTest do
@@ -49,7 +49,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
describe "migrate_to_db/1" do
setup do
clear_config(:configurable_from_database, true)
- clear_config([:quack, :level])
end
@tag capture_log: true
@@ -72,14 +71,12 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
config1 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"})
config2 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":second_setting"})
- config3 = ConfigDB.get_by_params(%{group: ":quack", key: ":level"})
refute ConfigDB.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"})
refute ConfigDB.get_by_params(%{group: ":postgrex", key: ":json_library"})
refute ConfigDB.get_by_params(%{group: ":pleroma", key: ":database"})
assert config1.value == [key: "value", key2: [Repo]]
assert config2.value == [key: "value2", key2: ["Activity"]]
- assert config3.value == :info
end
test "config table is truncated before migration" do
@@ -108,7 +105,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
test "settings are migrated to file and deleted from db", %{temp_file: temp_file} do
insert_config_record(:pleroma, :setting_first, key: "value", key2: ["Activity"])
insert_config_record(:pleroma, :setting_second, key: "value2", key2: [Repo])
- insert_config_record(:quack, :level, :info)
MixTask.run(["migrate_from_db", "--env", "temp", "-d"])
@@ -117,7 +113,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
file = File.read!(temp_file)
assert file =~ "config :pleroma, :setting_first,"
assert file =~ "config :pleroma, :setting_second,"
- assert file =~ "config :quack, :level, :info"
end
test "load a settings with large values and pass to file", %{temp_file: temp_file} do
@@ -199,7 +194,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
setup do
insert_config_record(:pleroma, :setting_first, key: "value", key2: ["Activity"])
insert_config_record(:pleroma, :setting_second, key: "value2", key2: [Repo])
- insert_config_record(:quack, :level, :info)
path = "test/instance_static"
file_path = Path.join(path, "temp.exported_from_db.secret.exs")
@@ -215,7 +209,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
file = File.read!(file_path)
assert file =~ "config :pleroma, :setting_first,"
assert file =~ "config :pleroma, :setting_second,"
- assert file =~ "config :quack, :level, :info"
end
test "release", %{file_path: file_path} do
@@ -227,7 +220,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
file = File.read!(file_path)
assert file =~ "config :pleroma, :setting_first,"
assert file =~ "config :pleroma, :setting_second,"
- assert file =~ "config :quack, :level, :info"
end
end
diff --git a/test/mix/tasks/pleroma/count_statuses_test.exs b/test/mix/tasks/pleroma/count_statuses_test.exs
index 80ec206b8..2fd515c39 100644
--- a/test/mix/tasks/pleroma/count_statuses_test.exs
+++ b/test/mix/tasks/pleroma/count_statuses_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.CountStatusesTest do
diff --git a/test/mix/tasks/pleroma/database_test.exs b/test/mix/tasks/pleroma/database_test.exs
index 7a1a759da..fbc939171 100644
--- a/test/mix/tasks/pleroma/database_test.exs
+++ b/test/mix/tasks/pleroma/database_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.DatabaseTest do
diff --git a/test/mix/tasks/pleroma/digest_test.exs b/test/mix/tasks/pleroma/digest_test.exs
index 4a9e461a9..d2a8606c7 100644
--- a/test/mix/tasks/pleroma/digest_test.exs
+++ b/test/mix/tasks/pleroma/digest_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.DigestTest do
@@ -53,7 +53,13 @@ defmodule Mix.Tasks.Pleroma.DigestTest do
assert_email_sent(
to: {user2.name, user2.email},
- html_body: ~r/here is what you've missed!/i
+ html_body:
+ Regex.compile!(
+ "here is what you've missed!"
+ |> Phoenix.HTML.html_escape()
+ |> Phoenix.HTML.safe_to_string(),
+ "i"
+ )
)
end
end
diff --git a/test/mix/tasks/pleroma/ecto/migrate_test.exs b/test/mix/tasks/pleroma/ecto/migrate_test.exs
index 3bfdde1c0..912471f60 100644
--- a/test/mix/tasks/pleroma/ecto/migrate_test.exs
+++ b/test/mix/tasks/pleroma/ecto/migrate_test.exs
@@ -1,6 +1,6 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-onl
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.Ecto.MigrateTest do
use Pleroma.DataCase
diff --git a/test/mix/tasks/pleroma/ecto/rollback_test.exs b/test/mix/tasks/pleroma/ecto/rollback_test.exs
index f8a37bd49..9d1a02ae2 100644
--- a/test/mix/tasks/pleroma/ecto/rollback_test.exs
+++ b/test/mix/tasks/pleroma/ecto/rollback_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.Ecto.RollbackTest do
diff --git a/test/mix/tasks/pleroma/ecto_test.exs b/test/mix/tasks/pleroma/ecto_test.exs
index 0164da5a8..8c99eeefe 100644
--- a/test/mix/tasks/pleroma/ecto_test.exs
+++ b/test/mix/tasks/pleroma/ecto_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.EctoTest do
diff --git a/test/mix/tasks/pleroma/email_test.exs b/test/mix/tasks/pleroma/email_test.exs
index ce68b88de..20b76ae3a 100644
--- a/test/mix/tasks/pleroma/email_test.exs
+++ b/test/mix/tasks/pleroma/email_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.EmailTest do
diff --git a/test/mix/tasks/pleroma/emoji_test.exs b/test/mix/tasks/pleroma/emoji_test.exs
index bd20f285c..2e10bbdc8 100644
--- a/test/mix/tasks/pleroma/emoji_test.exs
+++ b/test/mix/tasks/pleroma/emoji_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.EmojiTest do
diff --git a/test/mix/tasks/pleroma/frontend_test.exs b/test/mix/tasks/pleroma/frontend_test.exs
index aa4b25ebb..6d09f8e36 100644
--- a/test/mix/tasks/pleroma/frontend_test.exs
+++ b/test/mix/tasks/pleroma/frontend_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.FrontendTest do
diff --git a/test/mix/tasks/pleroma/instance_test.exs b/test/mix/tasks/pleroma/instance_test.exs
index 5a5a68053..b1c10e03c 100644
--- a/test/mix/tasks/pleroma/instance_test.exs
+++ b/test/mix/tasks/pleroma/instance_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.InstanceTest do
@@ -67,7 +67,9 @@ defmodule Mix.Tasks.Pleroma.InstanceTest do
"test/uploads",
"--static-dir",
"./test/../test/instance/static/",
- "--strip-uploads",
+ "--strip-uploads-location",
+ "y",
+ "--read-uploads-description",
"y",
"--dedupe-uploads",
"n",
@@ -91,7 +93,10 @@ defmodule Mix.Tasks.Pleroma.InstanceTest do
assert generated_config =~ "password: \"dbpass\""
assert generated_config =~ "configurable_from_database: true"
assert generated_config =~ "http: [ip: {127, 0, 0, 1}, port: 4000]"
- assert generated_config =~ "filters: [Pleroma.Upload.Filter.Exiftool]"
+
+ assert generated_config =~
+ "filters: [Pleroma.Upload.Filter.Exiftool.StripLocation, Pleroma.Upload.Filter.Exiftool.ReadDescription]"
+
assert File.read!(tmp_path() <> "setup.psql") == generated_setup_psql()
assert File.exists?(Path.expand("./test/instance/static/robots.txt"))
end
diff --git a/test/mix/tasks/pleroma/refresh_counter_cache_test.exs b/test/mix/tasks/pleroma/refresh_counter_cache_test.exs
index fe9e5cfeb..66ffba40b 100644
--- a/test/mix/tasks/pleroma/refresh_counter_cache_test.exs
+++ b/test/mix/tasks/pleroma/refresh_counter_cache_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.RefreshCounterCacheTest do
diff --git a/test/mix/tasks/pleroma/relay_test.exs b/test/mix/tasks/pleroma/relay_test.exs
index db75b3630..351fa9f4e 100644
--- a/test/mix/tasks/pleroma/relay_test.exs
+++ b/test/mix/tasks/pleroma/relay_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.RelayTest do
diff --git a/test/mix/tasks/pleroma/robots_txt_test.exs b/test/mix/tasks/pleroma/robots_txt_test.exs
index 028aa4ccc..4426fe526 100644
--- a/test/mix/tasks/pleroma/robots_txt_test.exs
+++ b/test/mix/tasks/pleroma/robots_txt_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
diff --git a/test/mix/tasks/pleroma/uploads_test.exs b/test/mix/tasks/pleroma/uploads_test.exs
index a7d15e0fa..d4ea89501 100644
--- a/test/mix/tasks/pleroma/uploads_test.exs
+++ b/test/mix/tasks/pleroma/uploads_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.UploadsTest do
diff --git a/test/mix/tasks/pleroma/user_test.exs b/test/mix/tasks/pleroma/user_test.exs
index a2178bbd1..4fdf6912b 100644
--- a/test/mix/tasks/pleroma/user_test.exs
+++ b/test/mix/tasks/pleroma/user_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.UserTest do
diff --git a/test/pleroma/activity/ir/topics_test.exs b/test/pleroma/activity/ir/topics_test.exs
index 299fcae9d..d299fea63 100644
--- a/test/pleroma/activity/ir/topics_test.exs
+++ b/test/pleroma/activity/ir/topics_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Activity.Ir.TopicsTest do
@@ -58,7 +58,7 @@ defmodule Pleroma.Activity.Ir.TopicsTest do
setup do
activity = %Activity{
object: %Object{data: %{"type" => "Note"}},
- data: %{"to" => [Pleroma.Constants.as_public()]}
+ data: %{"to" => [Pleroma.Constants.as_public()], "type" => "Create"}
}
{:ok, activity: activity}
@@ -137,6 +137,25 @@ defmodule Pleroma.Activity.Ir.TopicsTest do
end
end
+ describe "public visibility Announces" do
+ setup do
+ activity = %Activity{
+ object: %Object{data: %{"attachment" => []}},
+ data: %{"type" => "Announce", "to" => [Pleroma.Constants.as_public()]}
+ }
+
+ {:ok, activity: activity}
+ end
+
+ test "does not generate public topics", %{activity: activity} do
+ topics = Topics.get_activity_topics(activity)
+
+ refute "public" in topics
+ refute "public:remote" in topics
+ refute "public:local" in topics
+ end
+ end
+
describe "local-public visibility create events" do
setup do
activity = %Activity{
@@ -230,7 +249,11 @@ defmodule Pleroma.Activity.Ir.TopicsTest do
describe "non-public visibility" do
test "produces direct topic" do
- activity = %Activity{object: %Object{data: %{"type" => "Note"}}, data: %{"to" => []}}
+ activity = %Activity{
+ object: %Object{data: %{"type" => "Note"}},
+ data: %{"to" => [], "type" => "Create"}
+ }
+
topics = Topics.get_activity_topics(activity)
assert Enum.member?(topics, "direct")
diff --git a/test/pleroma/activity/search_test.exs b/test/pleroma/activity/search_test.exs
index 657fbc627..3b5fd2c3c 100644
--- a/test/pleroma/activity/search_test.exs
+++ b/test/pleroma/activity/search_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Activity.SearchTest do
@@ -18,6 +18,23 @@ defmodule Pleroma.Activity.SearchTest do
assert result.id == post.id
end
+ test "it finds local-only posts for authenticated users" do
+ user = insert(:user)
+ reader = insert(:user)
+ {:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes", visibility: "local"})
+
+ [result] = Search.search(reader, "wednesday")
+
+ assert result.id == post.id
+ end
+
+ test "it does not find local-only posts for anonymous users" do
+ user = insert(:user)
+ {:ok, _post} = CommonAPI.post(user, %{status: "it's wednesday my dudes", visibility: "local"})
+
+ assert [] = Search.search(nil, "wednesday")
+ end
+
test "using plainto_tsquery on postgres < 11" do
old_version = :persistent_term.get({Pleroma.Repo, :postgres_version})
:persistent_term.put({Pleroma.Repo, :postgres_version}, 10.0)
diff --git a/test/pleroma/activity_test.exs b/test/pleroma/activity_test.exs
index 4f9144f91..a48a68837 100644
--- a/test/pleroma/activity_test.exs
+++ b/test/pleroma/activity_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ActivityTest do
@@ -145,6 +145,7 @@ defmodule Pleroma.ActivityTest do
setup do: clear_config([:instance, :limit_to_local_content])
+ @tag :skip_on_mac
test "finds utf8 text in statuses", %{
japanese_activity: japanese_activity,
user: user
@@ -278,4 +279,78 @@ defmodule Pleroma.ActivityTest do
assert Repo.aggregate(Activity, :count, :id) == 2
end
+
+ describe "associated_object_id() sql function" do
+ test "with json object" do
+ %{rows: [[object_id]]} =
+ Ecto.Adapters.SQL.query!(
+ Pleroma.Repo,
+ """
+ select associated_object_id('{"object": {"id":"foobar"}}'::jsonb);
+ """
+ )
+
+ assert object_id == "foobar"
+ end
+
+ test "with string object" do
+ %{rows: [[object_id]]} =
+ Ecto.Adapters.SQL.query!(
+ Pleroma.Repo,
+ """
+ select associated_object_id('{"object": "foobar"}'::jsonb);
+ """
+ )
+
+ assert object_id == "foobar"
+ end
+
+ test "with array object" do
+ %{rows: [[object_id]]} =
+ Ecto.Adapters.SQL.query!(
+ Pleroma.Repo,
+ """
+ select associated_object_id('{"object": ["foobar", {}]}'::jsonb);
+ """
+ )
+
+ assert object_id == "foobar"
+ end
+
+ test "invalid" do
+ %{rows: [[object_id]]} =
+ Ecto.Adapters.SQL.query!(
+ Pleroma.Repo,
+ """
+ select associated_object_id('{"object": {}}'::jsonb);
+ """
+ )
+
+ assert is_nil(object_id)
+ end
+
+ test "invalid object id" do
+ %{rows: [[object_id]]} =
+ Ecto.Adapters.SQL.query!(
+ Pleroma.Repo,
+ """
+ select associated_object_id('{"object": {"id": 123}}'::jsonb);
+ """
+ )
+
+ assert is_nil(object_id)
+ end
+
+ test "no object field" do
+ %{rows: [[object_id]]} =
+ Ecto.Adapters.SQL.query!(
+ Pleroma.Repo,
+ """
+ select associated_object_id('{}'::jsonb);
+ """
+ )
+
+ assert is_nil(object_id)
+ end
+ end
end
diff --git a/test/pleroma/announcement_read_relationship_test.exs b/test/pleroma/announcement_read_relationship_test.exs
new file mode 100644
index 000000000..5fd4ffbef
--- /dev/null
+++ b/test/pleroma/announcement_read_relationship_test.exs
@@ -0,0 +1,40 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.AnnouncementReadRelationshipTest do
+ alias Pleroma.AnnouncementReadRelationship
+
+ use Pleroma.DataCase, async: true
+
+ import Pleroma.Factory
+
+ setup do
+ {:ok, user: insert(:user), announcement: insert(:announcement)}
+ end
+
+ describe "mark_read/2" do
+ test "should insert relationship", %{user: user, announcement: announcement} do
+ {:ok, _} = AnnouncementReadRelationship.mark_read(user, announcement)
+
+ assert AnnouncementReadRelationship.exists?(user, announcement)
+ end
+ end
+
+ describe "mark_unread/2" do
+ test "should delete relationship", %{user: user, announcement: announcement} do
+ {:ok, _} = AnnouncementReadRelationship.mark_read(user, announcement)
+
+ assert :ok = AnnouncementReadRelationship.mark_unread(user, announcement)
+ refute AnnouncementReadRelationship.exists?(user, announcement)
+ end
+
+ test "should not fail if relationship does not exist", %{
+ user: user,
+ announcement: announcement
+ } do
+ assert :ok = AnnouncementReadRelationship.mark_unread(user, announcement)
+ refute AnnouncementReadRelationship.exists?(user, announcement)
+ end
+ end
+end
diff --git a/test/pleroma/announcement_test.exs b/test/pleroma/announcement_test.exs
new file mode 100644
index 000000000..a007c3718
--- /dev/null
+++ b/test/pleroma/announcement_test.exs
@@ -0,0 +1,98 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.AnnouncementTest do
+ alias Pleroma.Announcement
+
+ use Pleroma.DataCase, async: true
+
+ import Pleroma.Factory
+
+ describe "list_all_visible_when/1" do
+ setup do: {:ok, time: NaiveDateTime.utc_now()}
+
+ test "with no start or end time", %{time: time} do
+ _announcement = insert(:announcement)
+
+ assert [_] = Announcement.list_all_visible_when(time)
+ end
+
+ test "with start time before current", %{time: time} do
+ before_now = NaiveDateTime.add(time, -10, :second)
+
+ _announcement = insert(:announcement, %{starts_at: before_now})
+
+ assert [_] = Announcement.list_all_visible_when(time)
+ end
+
+ test "with start time after current", %{time: time} do
+ after_now = NaiveDateTime.add(time, 10, :second)
+
+ _announcement = insert(:announcement, %{starts_at: after_now})
+
+ assert [] = Announcement.list_all_visible_when(time)
+ end
+
+ test "with end time after current", %{time: time} do
+ after_now = NaiveDateTime.add(time, 10, :second)
+
+ _announcement = insert(:announcement, %{ends_at: after_now})
+
+ assert [_] = Announcement.list_all_visible_when(time)
+ end
+
+ test "with end time before current", %{time: time} do
+ before_now = NaiveDateTime.add(time, -10, :second)
+
+ _announcement = insert(:announcement, %{ends_at: before_now})
+
+ assert [] = Announcement.list_all_visible_when(time)
+ end
+
+ test "with both start and end time", %{time: time} do
+ before_now = NaiveDateTime.add(time, -10, :second)
+ after_now = NaiveDateTime.add(time, 10, :second)
+
+ _announcement = insert(:announcement, %{starts_at: before_now, ends_at: after_now})
+
+ assert [_] = Announcement.list_all_visible_when(time)
+ end
+
+ test "with both start and end time, current not in the range", %{time: time} do
+ before_now = NaiveDateTime.add(time, -10, :second)
+ after_now = NaiveDateTime.add(time, 10, :second)
+
+ _announcement = insert(:announcement, %{starts_at: after_now, ends_at: before_now})
+
+ assert [] = Announcement.list_all_visible_when(time)
+ end
+ end
+
+ describe "announcements formatting" do
+ test "it formats links" do
+ raw = "something on https://pleroma.social ."
+ announcement = insert(:announcement, %{data: %{"content" => raw}})
+
+ assert announcement.rendered["content"] =~ ~r(<a.+?https://pleroma.social)
+ assert announcement.data["content"] == raw
+ end
+
+ test "it formats mentions" do
+ user = insert(:user)
+ raw = "something on @#{user.nickname} ."
+ announcement = insert(:announcement, %{data: %{"content" => raw}})
+
+ assert announcement.rendered["content"] =~ ~r(<a.+?#{user.nickname})
+ assert announcement.data["content"] == raw
+ end
+
+ test "it formats tags" do
+ raw = "something on #mew ."
+ announcement = insert(:announcement, %{data: %{"content" => raw}})
+
+ assert announcement.rendered["content"] =~ ~r(<a.+?#mew)
+ assert announcement.data["content"] == raw
+ end
+ end
+end
diff --git a/test/pleroma/application_requirements_test.exs b/test/pleroma/application_requirements_test.exs
index a54c37968..2f5b049a3 100644
--- a/test/pleroma/application_requirements_test.exs
+++ b/test/pleroma/application_requirements_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ApplicationRequirementsTest do
diff --git a/test/pleroma/bbs/handler_test.exs b/test/pleroma/bbs/handler_test.exs
index 3990f8286..aea3b6ead 100644
--- a/test/pleroma/bbs/handler_test.exs
+++ b/test/pleroma/bbs/handler_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.BBS.HandlerTest do
diff --git a/test/pleroma/bookmark_test.exs b/test/pleroma/bookmark_test.exs
index 9f64a01c2..57144ded3 100644
--- a/test/pleroma/bookmark_test.exs
+++ b/test/pleroma/bookmark_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.BookmarkTest do
diff --git a/test/pleroma/captcha_test.exs b/test/pleroma/captcha_test.exs
index fcb585112..ec4c713f8 100644
--- a/test/pleroma/captcha_test.exs
+++ b/test/pleroma/captcha_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.CaptchaTest do
diff --git a/test/pleroma/chat/message_reference_test.exs b/test/pleroma/chat/message_reference_test.exs
index c8db3b450..ffbc1a614 100644
--- a/test/pleroma/chat/message_reference_test.exs
+++ b/test/pleroma/chat/message_reference_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Chat.MessageReferenceTest do
diff --git a/test/pleroma/chat_test.exs b/test/pleroma/chat_test.exs
index a5fd1e02e..d18b3ff75 100644
--- a/test/pleroma/chat_test.exs
+++ b/test/pleroma/chat_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ChatTest do
diff --git a/test/pleroma/config/deprecation_warnings_test.exs b/test/pleroma/config/deprecation_warnings_test.exs
index ccf86634f..f3453ddb0 100644
--- a/test/pleroma/config/deprecation_warnings_test.exs
+++ b/test/pleroma/config/deprecation_warnings_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Config.DeprecationWarningsTest do
@@ -11,6 +11,239 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
alias Pleroma.Config
alias Pleroma.Config.DeprecationWarnings
+ describe "filter exiftool" do
+ test "gives warning when still used" do
+ clear_config(
+ [Pleroma.Upload, :filters],
+ [Pleroma.Upload.Filter.Exiftool]
+ )
+
+ assert capture_log(fn -> DeprecationWarnings.check_exiftool_filter() end) =~
+ """
+ !!!DEPRECATION WARNING!!!
+ Your config is using Exiftool as a filter instead of Exiftool.StripLocation. This should work for now, but you are advised to change to the new configuration to prevent possible issues later:
+
+ ```
+ config :pleroma, Pleroma.Upload,
+ filters: [Pleroma.Upload.Filter.Exiftool]
+ ```
+
+ Is now
+
+
+ ```
+ config :pleroma, Pleroma.Upload,
+ filters: [Pleroma.Upload.Filter.Exiftool.StripLocation]
+ ```
+ """
+ end
+
+ test "changes setting to exiftool strip location" do
+ clear_config(
+ [Pleroma.Upload, :filters],
+ [Pleroma.Upload.Filter.Exiftool, Pleroma.Upload.Filter.Exiftool.ReadDescription]
+ )
+
+ expected_config = [
+ Pleroma.Upload.Filter.Exiftool.StripLocation,
+ Pleroma.Upload.Filter.Exiftool.ReadDescription
+ ]
+
+ capture_log(fn -> DeprecationWarnings.warn() end)
+
+ assert Config.get([Pleroma.Upload]) |> Keyword.get(:filters, []) == expected_config
+ end
+
+ test "doesn't give a warning with correct config" do
+ clear_config(
+ [Pleroma.Upload, :filters],
+ [
+ Pleroma.Upload.Filter.Exiftool.StripLocation,
+ Pleroma.Upload.Filter.Exiftool.ReadDescription
+ ]
+ )
+
+ assert capture_log(fn -> DeprecationWarnings.check_exiftool_filter() end) == ""
+ end
+ end
+
+ describe "simple policy tuples" do
+ test "gives warning when there are still strings" do
+ clear_config([:mrf_simple],
+ media_removal: ["some.removal"],
+ media_nsfw: ["some.nsfw"],
+ federated_timeline_removal: ["some.tl.removal"],
+ report_removal: ["some.report.removal"],
+ reject: ["some.reject"],
+ followers_only: ["some.followers.only"],
+ accept: ["some.accept"],
+ avatar_removal: ["some.avatar.removal"],
+ banner_removal: ["some.banner.removal"],
+ reject_deletes: ["some.reject.deletes"]
+ )
+
+ assert capture_log(fn -> DeprecationWarnings.check_simple_policy_tuples() end) =~
+ """
+ !!!DEPRECATION WARNING!!!
+ Your config is using strings in the SimplePolicy configuration instead of tuples. They should work for now, but you are advised to change to the new configuration to prevent possible issues later:
+
+ ```
+ config :pleroma, :mrf_simple,
+ media_removal: ["instance.tld"],
+ media_nsfw: ["instance.tld"],
+ federated_timeline_removal: ["instance.tld"],
+ report_removal: ["instance.tld"],
+ reject: ["instance.tld"],
+ followers_only: ["instance.tld"],
+ accept: ["instance.tld"],
+ avatar_removal: ["instance.tld"],
+ banner_removal: ["instance.tld"],
+ reject_deletes: ["instance.tld"]
+ ```
+
+ Is now
+
+
+ ```
+ config :pleroma, :mrf_simple,
+ media_removal: [{"instance.tld", "Reason for media removal"}],
+ media_nsfw: [{"instance.tld", "Reason for media nsfw"}],
+ federated_timeline_removal: [{"instance.tld", "Reason for federated timeline removal"}],
+ report_removal: [{"instance.tld", "Reason for report removal"}],
+ reject: [{"instance.tld", "Reason for reject"}],
+ followers_only: [{"instance.tld", "Reason for followers only"}],
+ accept: [{"instance.tld", "Reason for accept"}],
+ avatar_removal: [{"instance.tld", "Reason for avatar removal"}],
+ banner_removal: [{"instance.tld", "Reason for banner removal"}],
+ reject_deletes: [{"instance.tld", "Reason for reject deletes"}]
+ ```
+ """
+ end
+
+ test "transforms config to tuples" do
+ clear_config([:mrf_simple],
+ media_removal: ["some.removal", {"some.other.instance", "Some reason"}]
+ )
+
+ expected_config = [
+ {:media_removal, [{"some.removal", ""}, {"some.other.instance", "Some reason"}]}
+ ]
+
+ capture_log(fn -> DeprecationWarnings.warn() end)
+
+ assert Config.get([:mrf_simple]) == expected_config
+ end
+
+ test "doesn't give a warning with correct config" do
+ clear_config([:mrf_simple],
+ media_removal: [{"some.removal", ""}, {"some.other.instance", "Some reason"}]
+ )
+
+ assert capture_log(fn -> DeprecationWarnings.check_simple_policy_tuples() end) == ""
+ end
+ end
+
+ describe "quarantined_instances tuples" do
+ test "gives warning when there are still strings" do
+ clear_config([:instance, :quarantined_instances], [
+ {"domain.com", "some reason"},
+ "somedomain.tld"
+ ])
+
+ assert capture_log(fn -> DeprecationWarnings.check_quarantined_instances_tuples() end) =~
+ """
+ !!!DEPRECATION WARNING!!!
+ Your config is using strings in the quarantined_instances configuration instead of tuples. They should work for now, but you are advised to change to the new configuration to prevent possible issues later:
+
+ ```
+ config :pleroma, :instance,
+ quarantined_instances: ["instance.tld"]
+ ```
+
+ Is now
+
+
+ ```
+ config :pleroma, :instance,
+ quarantined_instances: [{"instance.tld", "Reason for quarantine"}]
+ ```
+ """
+ end
+
+ test "transforms config to tuples" do
+ clear_config([:instance, :quarantined_instances], [
+ {"domain.com", "some reason"},
+ "some.tld"
+ ])
+
+ expected_config = [{"domain.com", "some reason"}, {"some.tld", ""}]
+
+ capture_log(fn -> DeprecationWarnings.warn() end)
+
+ assert Config.get([:instance, :quarantined_instances]) == expected_config
+ end
+
+ test "doesn't give a warning with correct config" do
+ clear_config([:instance, :quarantined_instances], [
+ {"domain.com", "some reason"},
+ {"some.tld", ""}
+ ])
+
+ assert capture_log(fn -> DeprecationWarnings.check_quarantined_instances_tuples() end) == ""
+ end
+ end
+
+ describe "transparency_exclusions tuples" do
+ test "gives warning when there are still strings" do
+ clear_config([:mrf, :transparency_exclusions], [
+ {"domain.com", "some reason"},
+ "somedomain.tld"
+ ])
+
+ assert capture_log(fn -> DeprecationWarnings.check_transparency_exclusions_tuples() end) =~
+ """
+ !!!DEPRECATION WARNING!!!
+ Your config is using strings in the transparency_exclusions configuration instead of tuples. They should work for now, but you are advised to change to the new configuration to prevent possible issues later:
+
+ ```
+ config :pleroma, :mrf,
+ transparency_exclusions: ["instance.tld"]
+ ```
+
+ Is now
+
+
+ ```
+ config :pleroma, :mrf,
+ transparency_exclusions: [{"instance.tld", "Reason to exlude transparency"}]
+ ```
+ """
+ end
+
+ test "transforms config to tuples" do
+ clear_config([:mrf, :transparency_exclusions], [
+ {"domain.com", "some reason"},
+ "some.tld"
+ ])
+
+ expected_config = [{"domain.com", "some reason"}, {"some.tld", ""}]
+
+ capture_log(fn -> DeprecationWarnings.warn() end)
+
+ assert Config.get([:mrf, :transparency_exclusions]) == expected_config
+ end
+
+ test "doesn't give a warning with correct config" do
+ clear_config([:mrf, :transparency_exclusions], [
+ {"domain.com", "some reason"},
+ {"some.tld", ""}
+ ])
+
+ assert capture_log(fn -> DeprecationWarnings.check_transparency_exclusions_tuples() end) ==
+ ""
+ end
+ end
+
test "check_old_mrf_config/0" do
clear_config([:instance, :rewrite_policy], [])
clear_config([:instance, :mrf_transparency], true)
diff --git a/test/pleroma/config/holder_test.exs b/test/pleroma/config/holder_test.exs
index ca4c38995..e801da5cf 100644
--- a/test/pleroma/config/holder_test.exs
+++ b/test/pleroma/config/holder_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Config.HolderTest do
diff --git a/test/pleroma/config/loader_test.exs b/test/pleroma/config/loader_test.exs
index b34fd70da..784817d49 100644
--- a/test/pleroma/config/loader_test.exs
+++ b/test/pleroma/config/loader_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Config.LoaderTest do
@@ -11,7 +11,6 @@ defmodule Pleroma.Config.LoaderTest do
config = Loader.read("test/fixtures/config/temp.secret.exs")
assert config[:pleroma][:first_setting][:key] == "value"
assert config[:pleroma][:first_setting][:key2] == [Pleroma.Repo]
- assert config[:quack][:level] == :info
end
test "filter_group/2" do
diff --git a/test/pleroma/config/release_runtime_provider_test.exs b/test/pleroma/config/release_runtime_provider_test.exs
index 6578d3268..4e0d4c838 100644
--- a/test/pleroma/config/release_runtime_provider_test.exs
+++ b/test/pleroma/config/release_runtime_provider_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Config.ReleaseRuntimeProviderTest do
use ExUnit.Case, async: true
diff --git a/test/pleroma/config/transfer_task_test.exs b/test/pleroma/config/transfer_task_test.exs
index 7d51fd84c..6295fa888 100644
--- a/test/pleroma/config/transfer_task_test.exs
+++ b/test/pleroma/config/transfer_task_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Config.TransferTaskTest do
@@ -15,13 +15,11 @@ defmodule Pleroma.Config.TransferTaskTest do
test "transfer config values from db to env" do
refute Application.get_env(:pleroma, :test_key)
refute Application.get_env(:idna, :test_key)
- refute Application.get_env(:quack, :test_key)
refute Application.get_env(:postgrex, :test_key)
initial = Application.get_env(:logger, :level)
insert(:config, key: :test_key, value: [live: 2, com: 3])
insert(:config, group: :idna, key: :test_key, value: [live: 15, com: 35])
- insert(:config, group: :quack, key: :test_key, value: [:test_value1, :test_value2])
insert(:config, group: :postgrex, key: :test_key, value: :value)
insert(:config, group: :logger, key: :level, value: :debug)
@@ -29,36 +27,32 @@ defmodule Pleroma.Config.TransferTaskTest do
assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
- assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
assert Application.get_env(:logger, :level) == :debug
assert Application.get_env(:postgrex, :test_key) == :value
on_exit(fn ->
Application.delete_env(:pleroma, :test_key)
Application.delete_env(:idna, :test_key)
- Application.delete_env(:quack, :test_key)
Application.delete_env(:postgrex, :test_key)
Application.put_env(:logger, :level, initial)
end)
end
test "transfer config values for 1 group and some keys" do
- level = Application.get_env(:quack, :level)
- meta = Application.get_env(:quack, :meta)
+ level = Application.get_env(:somegroup, :level)
+ meta = Application.get_env(:somegroup, :meta)
- insert(:config, group: :quack, key: :level, value: :info)
- insert(:config, group: :quack, key: :meta, value: [:none])
+ insert(:config, group: :somegroup, key: :level, value: :info)
+ insert(:config, group: :somegroup, key: :meta, value: [:none])
TransferTask.start_link([])
- assert Application.get_env(:quack, :level) == :info
- assert Application.get_env(:quack, :meta) == [:none]
- default = Pleroma.Config.Holder.default_config(:quack, :webhook_url)
- assert Application.get_env(:quack, :webhook_url) == default
+ assert Application.get_env(:somegroup, :level) == :info
+ assert Application.get_env(:somegroup, :meta) == [:none]
on_exit(fn ->
- Application.put_env(:quack, :level, level)
- Application.put_env(:quack, :meta, meta)
+ Application.put_env(:somegroup, :level, level)
+ Application.put_env(:somegroup, :meta, meta)
end)
end
@@ -79,7 +73,16 @@ defmodule Pleroma.Config.TransferTaskTest do
describe "pleroma restart" do
setup do
- on_exit(fn -> Restarter.Pleroma.refresh() end)
+ on_exit(fn ->
+ Restarter.Pleroma.refresh()
+
+ # Restarter.Pleroma.refresh/0 is an asynchronous call.
+ # A GenServer will first finish the previous call before starting a new one.
+ # Here we do a synchronous call.
+ # That way we are sure that the previous call has finished before we continue.
+ # See https://stackoverflow.com/questions/51361856/how-to-use-task-await-with-genserver
+ Restarter.Pleroma.rebooted?()
+ end)
end
test "don't restart if no reboot time settings were changed" do
@@ -87,7 +90,15 @@ defmodule Pleroma.Config.TransferTaskTest do
insert(:config, key: :emoji, value: [groups: [a: 1, b: 2]])
refute String.contains?(
- capture_log(fn -> TransferTask.start_link([]) end),
+ capture_log(fn ->
+ TransferTask.start_link([])
+
+ # TransferTask.start_link/1 is an asynchronous call.
+ # A GenServer will first finish the previous call before starting a new one.
+ # Here we do a synchronous call.
+ # That way we are sure that the previous call has finished before we continue.
+ Restarter.Pleroma.rebooted?()
+ end),
"pleroma restarted"
)
end
@@ -95,13 +106,35 @@ defmodule Pleroma.Config.TransferTaskTest do
test "on reboot time key" do
clear_config(:shout)
insert(:config, key: :shout, value: [enabled: false])
- assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
+
+ # Note that we don't actually restart Pleroma.
+ # See module Restarter.Pleroma
+ assert capture_log(fn ->
+ TransferTask.start_link([])
+
+ # TransferTask.start_link/1 is an asynchronous call.
+ # A GenServer will first finish the previous call before starting a new one.
+ # Here we do a synchronous call.
+ # That way we are sure that the previous call has finished before we continue.
+ Restarter.Pleroma.rebooted?()
+ end) =~ "pleroma restarted"
end
test "on reboot time subkey" do
clear_config(Pleroma.Captcha)
insert(:config, key: Pleroma.Captcha, value: [seconds_valid: 60])
- assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
+
+ # Note that we don't actually restart Pleroma.
+ # See module Restarter.Pleroma
+ assert capture_log(fn ->
+ TransferTask.start_link([])
+
+ # TransferTask.start_link/1 is an asynchronous call.
+ # A GenServer will first finish the previous call before starting a new one.
+ # Here we do a synchronous call.
+ # That way we are sure that the previous call has finished before we continue.
+ Restarter.Pleroma.rebooted?()
+ end) =~ "pleroma restarted"
end
test "don't restart pleroma on reboot time key and subkey if there is false flag" do
@@ -112,7 +145,15 @@ defmodule Pleroma.Config.TransferTaskTest do
insert(:config, key: Pleroma.Captcha, value: [seconds_valid: 60])
refute String.contains?(
- capture_log(fn -> TransferTask.load_and_update_env([], false) end),
+ capture_log(fn ->
+ TransferTask.load_and_update_env([], false)
+
+ # TransferTask.start_link/1 is an asynchronous call.
+ # A GenServer will first finish the previous call before starting a new one.
+ # Here we do a synchronous call.
+ # That way we are sure that the previous call has finished before we continue.
+ Restarter.Pleroma.rebooted?()
+ end),
"pleroma restarted"
)
end
diff --git a/test/pleroma/config_db_test.exs b/test/pleroma/config_db_test.exs
index d42123fb4..8eb0ab4cf 100644
--- a/test/pleroma/config_db_test.exs
+++ b/test/pleroma/config_db_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ConfigDBTest do
@@ -16,13 +16,13 @@ defmodule Pleroma.ConfigDBTest do
test "get_all_as_keyword/0" do
saved = insert(:config)
- insert(:config, group: ":quack", key: ":level", value: :info)
- insert(:config, group: ":quack", key: ":meta", value: [:none])
+ insert(:config, group: ":goose", key: ":level", value: :info)
+ insert(:config, group: ":goose", key: ":meta", value: [:none])
insert(:config,
- group: ":quack",
+ group: ":goose",
key: ":webhook_url",
- value: "https://hooks.slack.com/services/KEY/some_val"
+ value: "https://gander.com/"
)
config = ConfigDB.get_all_as_keyword()
@@ -31,9 +31,9 @@ defmodule Pleroma.ConfigDBTest do
{saved.key, saved.value}
]
- assert config[:quack][:level] == :info
- assert config[:quack][:meta] == [:none]
- assert config[:quack][:webhook_url] == "https://hooks.slack.com/services/KEY/some_val"
+ assert config[:goose][:level] == :info
+ assert config[:goose][:meta] == [:none]
+ assert config[:goose][:webhook_url] == "https://gander.com/"
end
describe "update_or_create/1" do
@@ -238,10 +238,11 @@ defmodule Pleroma.ConfigDBTest do
end
test "ssl options" do
- assert ConfigDB.to_elixir_types([":tlsv1", ":tlsv1.1", ":tlsv1.2"]) == [
+ assert ConfigDB.to_elixir_types([":tlsv1", ":tlsv1.1", ":tlsv1.2", ":tlsv1.3"]) == [
:tlsv1,
:"tlsv1.1",
- :"tlsv1.2"
+ :"tlsv1.2",
+ :"tlsv1.3"
]
end
@@ -266,10 +267,6 @@ defmodule Pleroma.ConfigDBTest do
assert ConfigDB.to_elixir_types("ExSyslogger") == ExSyslogger
end
- test "Quack.Logger module" do
- assert ConfigDB.to_elixir_types("Quack.Logger") == Quack.Logger
- end
-
test "Swoosh.Adapters modules" do
assert ConfigDB.to_elixir_types("Swoosh.Adapters.SMTP") == Swoosh.Adapters.SMTP
assert ConfigDB.to_elixir_types("Swoosh.Adapters.AmazonSES") == Swoosh.Adapters.AmazonSES
diff --git a/test/pleroma/config_test.exs b/test/pleroma/config_test.exs
index 3158a2ec8..697cf3223 100644
--- a/test/pleroma/config_test.exs
+++ b/test/pleroma/config_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ConfigTest do
diff --git a/test/pleroma/conversation/participation_test.exs b/test/pleroma/conversation/participation_test.exs
index a25e17c95..a84437677 100644
--- a/test/pleroma/conversation/participation_test.exs
+++ b/test/pleroma/conversation/participation_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Conversation.ParticipationTest do
@@ -122,11 +122,11 @@ defmodule Pleroma.Conversation.ParticipationTest do
end
test "it marks a participation as read" do
- participation = insert(:participation, %{read: false})
+ participation = insert(:participation, %{updated_at: ~N[2017-07-17 17:09:58], read: false})
{:ok, updated_participation} = Participation.mark_as_read(participation)
assert updated_participation.read
- assert updated_participation.updated_at == participation.updated_at
+ assert :gt = NaiveDateTime.compare(updated_participation.updated_at, participation.updated_at)
end
test "it marks a participation as unread" do
diff --git a/test/pleroma/conversation_test.exs b/test/pleroma/conversation_test.exs
index 1a947606d..94897e7ea 100644
--- a/test/pleroma/conversation_test.exs
+++ b/test/pleroma/conversation_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ConversationTest do
diff --git a/test/pleroma/docs/generator_test.exs b/test/pleroma/docs/generator_test.exs
index 8574c1d5e..5e41d6ccb 100644
--- a/test/pleroma/docs/generator_test.exs
+++ b/test/pleroma/docs/generator_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Docs.GeneratorTest do
@@ -86,7 +86,7 @@ defmodule Pleroma.Docs.GeneratorTest do
key: :versions,
type: {:list, :atom},
description: "List of TLS version to use",
- suggestions: [:tlsv1, ":tlsv1.1", ":tlsv1.2"]
+ suggestions: [:tlsv1, ":tlsv1.1", ":tlsv1.2", ":tlsv1.3"]
}
]
},
@@ -213,7 +213,7 @@ defmodule Pleroma.Docs.GeneratorTest do
test "suggestion for tls versions" do
[%{children: children} | _] = Generator.convert_to_strings(@descriptions)
child = Enum.at(children, 8)
- assert child[:suggestions] == [":tlsv1", ":tlsv1.1", ":tlsv1.2"]
+ assert child[:suggestions] == [":tlsv1", ":tlsv1.1", ":tlsv1.2", ":tlsv1.3"]
end
test "subgroup with module name" do
diff --git a/test/pleroma/docs/translator/compiler_test.exs b/test/pleroma/docs/translator/compiler_test.exs
new file mode 100644
index 000000000..d6c3cdd40
--- /dev/null
+++ b/test/pleroma/docs/translator/compiler_test.exs
@@ -0,0 +1,90 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Docs.Translator.CompilerTest do
+ use ExUnit.Case, async: true
+
+ alias Pleroma.Docs.Translator.Compiler
+
+ @descriptions [
+ %{
+ key: "1",
+ label: "1",
+ description: "2",
+ children: [
+ %{
+ key: "3",
+ label: "3",
+ description: "4"
+ },
+ %{
+ key: "5",
+ label: "5",
+ description: "6"
+ }
+ ]
+ },
+ %{
+ key: "7",
+ label: "7",
+ description: "8",
+ children: [
+ %{
+ key: "9",
+ description: "9",
+ children: [
+ %{
+ key: "10",
+ description: "10",
+ children: [
+ %{key: "11", description: "11"},
+ %{description: "12"}
+ ]
+ }
+ ]
+ },
+ %{
+ label: "13"
+ }
+ ]
+ },
+ %{
+ group: "14",
+ label: "14"
+ },
+ %{
+ group: "15",
+ key: "15",
+ label: "15"
+ },
+ %{
+ group: {":subgroup", "16"},
+ label: "16"
+ }
+ ]
+
+ describe "extract_strings/1" do
+ test "it extracts all labels and descriptions" do
+ strings = Compiler.extract_strings(@descriptions)
+ assert length(strings) == 16
+
+ assert {["1"], "label", "1"} in strings
+ assert {["1"], "description", "2"} in strings
+ assert {["1", "3"], "label", "3"} in strings
+ assert {["1", "3"], "description", "4"} in strings
+ assert {["1", "5"], "label", "5"} in strings
+ assert {["1", "5"], "description", "6"} in strings
+ assert {["7"], "label", "7"} in strings
+ assert {["7"], "description", "8"} in strings
+ assert {["7", "9"], "description", "9"} in strings
+ assert {["7", "9", "10"], "description", "10"} in strings
+ assert {["7", "9", "10", "11"], "description", "11"} in strings
+ assert {["7", "9", "10", nil], "description", "12"} in strings
+ assert {["7", nil], "label", "13"} in strings
+ assert {["14"], "label", "14"} in strings
+ assert {["15-15"], "label", "15"} in strings
+ assert {["16"], "label", "16"} in strings
+ end
+ end
+end
diff --git a/test/pleroma/ecto_type/activity_pub/object_validators/date_time_test.exs b/test/pleroma/ecto_type/activity_pub/object_validators/date_time_test.exs
index 259fd6a5f..74441d1e8 100644
--- a/test/pleroma/ecto_type/activity_pub/object_validators/date_time_test.exs
+++ b/test/pleroma/ecto_type/activity_pub/object_validators/date_time_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.DateTimeTest do
diff --git a/test/pleroma/ecto_type/activity_pub/object_validators/object_id_test.exs b/test/pleroma/ecto_type/activity_pub/object_validators/object_id_test.exs
index 1a4c2dfcb..38bca41cf 100644
--- a/test/pleroma/ecto_type/activity_pub/object_validators/object_id_test.exs
+++ b/test/pleroma/ecto_type/activity_pub/object_validators/object_id_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectIDTest do
diff --git a/test/pleroma/ecto_type/activity_pub/object_validators/recipients_test.exs b/test/pleroma/ecto_type/activity_pub/object_validators/recipients_test.exs
index 4cdafa898..366039f25 100644
--- a/test/pleroma/ecto_type/activity_pub/object_validators/recipients_test.exs
+++ b/test/pleroma/ecto_type/activity_pub/object_validators/recipients_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.RecipientsTest do
diff --git a/test/pleroma/ecto_type/activity_pub/object_validators/safe_text_test.exs b/test/pleroma/ecto_type/activity_pub/object_validators/safe_text_test.exs
index 7002eca30..2d13eb691 100644
--- a/test/pleroma/ecto_type/activity_pub/object_validators/safe_text_test.exs
+++ b/test/pleroma/ecto_type/activity_pub/object_validators/safe_text_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.SafeTextTest do
diff --git a/test/pleroma/emails/admin_email_test.exs b/test/pleroma/emails/admin_email_test.exs
index 04c907697..a10b7cfa7 100644
--- a/test/pleroma/emails/admin_email_test.exs
+++ b/test/pleroma/emails/admin_email_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Emails.AdminEmailTest do
@@ -27,11 +27,7 @@ defmodule Pleroma.Emails.AdminEmailTest do
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<p>\n<a href=\"http://localhost:4001/pleroma/admin/#/reports/index\">View Reports in AdminFE</a>\n"
+ "<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<p>\n<a href=\"http://localhost:4001/pleroma/admin/#/reports/index\">View Reports in AdminFE</a>\n"
end
test "it works when the reporter is a remote user without email" do
diff --git a/test/pleroma/emails/mailer_test.exs b/test/pleroma/emails/mailer_test.exs
index a8e1553e5..7a718c653 100644
--- a/test/pleroma/emails/mailer_test.exs
+++ b/test/pleroma/emails/mailer_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Emails.MailerTest do
diff --git a/test/pleroma/emails/user_email_test.exs b/test/pleroma/emails/user_email_test.exs
index 21fd06ea6..7061148b0 100644
--- a/test/pleroma/emails/user_email_test.exs
+++ b/test/pleroma/emails/user_email_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Emails.UserEmailTest do
@@ -56,4 +56,16 @@ defmodule Pleroma.Emails.UserEmailTest do
assert email.subject == "Your account is awaiting approval"
assert email.html_body =~ "Awaiting Approval"
end
+
+ test "email i18n" do
+ user = insert(:user, language: "en_test")
+ email = UserEmail.approval_pending_email(user)
+ assert email.subject == "xxYour account is awaiting approvalxx"
+ end
+
+ test "email i18n should fallback to default locale if user language is unsupported" do
+ user = insert(:user, language: "unsupported")
+ email = UserEmail.approval_pending_email(user)
+ assert email.subject == "Your account is awaiting approval"
+ end
end
diff --git a/test/pleroma/emoji/formatter_test.exs b/test/pleroma/emoji/formatter_test.exs
index 3942f609f..7bacea361 100644
--- a/test/pleroma/emoji/formatter_test.exs
+++ b/test/pleroma/emoji/formatter_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Emoji.FormatterTest do
diff --git a/test/pleroma/emoji/loader_test.exs b/test/pleroma/emoji/loader_test.exs
index de89e3bc4..717424fc8 100644
--- a/test/pleroma/emoji/loader_test.exs
+++ b/test/pleroma/emoji/loader_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Emoji.LoaderTest do
diff --git a/test/pleroma/emoji/pack_test.exs b/test/pleroma/emoji/pack_test.exs
index ac7535412..18b99da75 100644
--- a/test/pleroma/emoji/pack_test.exs
+++ b/test/pleroma/emoji/pack_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Emoji.PackTest do
diff --git a/test/pleroma/emoji_test.exs b/test/pleroma/emoji_test.exs
index 027a8132f..18063c223 100644
--- a/test/pleroma/emoji_test.exs
+++ b/test/pleroma/emoji_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.EmojiTest do
@@ -20,6 +20,7 @@ defmodule Pleroma.EmojiTest do
assert Emoji.is_unicode_emoji?("🤰")
assert Emoji.is_unicode_emoji?("❤️")
assert Emoji.is_unicode_emoji?("🏳️‍⚧️")
+ assert Emoji.is_unicode_emoji?("🫵")
# Additionally, we accept regional indicators.
assert Emoji.is_unicode_emoji?("🇵")
diff --git a/test/pleroma/filter_test.exs b/test/pleroma/filter_test.exs
index 19ad6b8c0..6d33cd22b 100644
--- a/test/pleroma/filter_test.exs
+++ b/test/pleroma/filter_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.FilterTest do
diff --git a/test/pleroma/following_relationship_test.exs b/test/pleroma/following_relationship_test.exs
index 37452996b..70e443161 100644
--- a/test/pleroma/following_relationship_test.exs
+++ b/test/pleroma/following_relationship_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.FollowingRelationshipTest do
diff --git a/test/pleroma/formatter_test.exs b/test/pleroma/formatter_test.exs
index 7f54638fb..5e431f6c9 100644
--- a/test/pleroma/formatter_test.exs
+++ b/test/pleroma/formatter_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.FormatterTest do
@@ -151,13 +151,7 @@ defmodule Pleroma.FormatterTest do
assert length(mentions) == 3
expected_text =
- ~s(<span class="h-card"><a class="u-url mention" data-user="#{gsimg.id}" href="#{
- gsimg.ap_id
- }" rel="ugc">@<span>gsimg</span></a></span> According to <span class="h-card"><a class="u-url mention" data-user="#{
- archaeme.id
- }" href="#{"https://archeme/@archa_eme_"}" rel="ugc">@<span>archa_eme_</span></a></span>, that is @daggsy. Also hello <span class="h-card"><a class="u-url mention" data-user="#{
- archaeme_remote.id
- }" href="#{archaeme_remote.ap_id}" rel="ugc">@<span>archaeme</span></a></span>)
+ ~s(<span class="h-card"><a class="u-url mention" data-user="#{gsimg.id}" href="#{gsimg.ap_id}" rel="ugc">@<span>gsimg</span></a></span> According to <span class="h-card"><a class="u-url mention" data-user="#{archaeme.id}" href="#{"https://archeme/@archa_eme_"}" rel="ugc">@<span>archa_eme_</span></a></span>, that is @daggsy. Also hello <span class="h-card"><a class="u-url mention" data-user="#{archaeme_remote.id}" href="#{archaeme_remote.ap_id}" rel="ugc">@<span>archaeme</span></a></span>)
assert expected_text == text
end
@@ -172,9 +166,7 @@ defmodule Pleroma.FormatterTest do
assert length(mentions) == 1
expected_text =
- ~s(<span class="h-card"><a class="u-url mention" data-user="#{mike.id}" href="#{
- mike.ap_id
- }" rel="ugc">@<span>mike</span></a></span> test)
+ ~s(<span class="h-card"><a class="u-url mention" data-user="#{mike.id}" href="#{mike.ap_id}" rel="ugc">@<span>mike</span></a></span> test)
assert expected_text == text
end
@@ -210,13 +202,7 @@ defmodule Pleroma.FormatterTest do
assert mentions == [{"@#{user.nickname}", user}, {"@#{other_user.nickname}", other_user}]
assert expected_text ==
- ~s(<span class="h-card"><a class="u-url mention" data-user="#{user.id}" href="#{
- user.ap_id
- }" rel="ugc">@<span>#{user.nickname}</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{
- other_user.id
- }" href="#{other_user.ap_id}" rel="ugc">@<span>#{other_user.nickname}</span></a></span> hey dudes i hate <span class="h-card"><a class="u-url mention" data-user="#{
- third_user.id
- }" href="#{third_user.ap_id}" rel="ugc">@<span>#{third_user.nickname}</span></a></span>)
+ ~s(<span class="h-card"><a class="u-url mention" data-user="#{user.id}" href="#{user.ap_id}" rel="ugc">@<span>#{user.nickname}</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{other_user.id}" href="#{other_user.ap_id}" rel="ugc">@<span>#{other_user.nickname}</span></a></span> hey dudes i hate <span class="h-card"><a class="u-url mention" data-user="#{third_user.id}" href="#{third_user.ap_id}" rel="ugc">@<span>#{third_user.nickname}</span></a></span>)
end
test "given the 'safe_mention' option, it will still work without any mention" do
@@ -284,6 +270,34 @@ defmodule Pleroma.FormatterTest do
assert {^expected_text, ^expected_mentions, []} = Formatter.linkify(text)
end
+
+ test "correctly parses mentions in html" do
+ text = "<p>@lain hello</p>"
+ lain = insert(:user, %{nickname: "lain"})
+
+ {text, mentions, []} = Formatter.linkify(text)
+
+ assert length(mentions) == 1
+
+ expected_text =
+ ~s(<p><span class="h-card"><a class="u-url mention" data-user="#{lain.id}" href="#{lain.ap_id}" rel="ugc">@<span>lain</span></a></span> hello</p>)
+
+ assert expected_text == text
+ end
+
+ test "correctly parses mentions on the last line of html" do
+ text = "<p>Hello</p><p>@lain</p>"
+ lain = insert(:user, %{nickname: "lain"})
+
+ {text, mentions, []} = Formatter.linkify(text)
+
+ assert length(mentions) == 1
+
+ expected_text =
+ ~s(<p>Hello</p><p><span class="h-card"><a class="u-url mention" data-user="#{lain.id}" href="#{lain.ap_id}" rel="ugc">@<span>lain</span></a></span></p>)
+
+ assert expected_text == text
+ end
end
describe ".parse_tags" do
@@ -299,6 +313,57 @@ defmodule Pleroma.FormatterTest do
assert {_text, [], ^expected_tags} = Formatter.linkify(text)
end
+
+ test "parses tags in html" do
+ text = "<p>This is a #test</p>"
+
+ expected_tags = [
+ {"#test", "test"}
+ ]
+
+ assert {_text, [], ^expected_tags} = Formatter.linkify(text)
+ end
+
+ test "parses mulitple tags in html" do
+ text = "<p>#tag1 #tag2 #tag3 #tag4</p>"
+
+ expected_tags = [
+ {"#tag1", "tag1"},
+ {"#tag2", "tag2"},
+ {"#tag3", "tag3"},
+ {"#tag4", "tag4"}
+ ]
+
+ assert {_text, [], ^expected_tags} = Formatter.linkify(text)
+ end
+
+ test "parses tags on the last line of html" do
+ text = "<p>This is a</p><p>#test</p>"
+
+ expected_tags = [
+ {"#test", "test"}
+ ]
+
+ assert {_text, [], ^expected_tags} = Formatter.linkify(text)
+ end
+
+ test "parses mulitple tags on mulitple lines in html" do
+ text =
+ "<p>testing...</p><p>#tag1 #tag2 #tag3 #tag4</p><p>paragraph</p><p>#tag5 #tag6 #tag7 #tag8</p>"
+
+ expected_tags = [
+ {"#tag1", "tag1"},
+ {"#tag2", "tag2"},
+ {"#tag3", "tag3"},
+ {"#tag4", "tag4"},
+ {"#tag5", "tag5"},
+ {"#tag6", "tag6"},
+ {"#tag7", "tag7"},
+ {"#tag8", "tag8"}
+ ]
+
+ assert {_text, [], ^expected_tags} = Formatter.linkify(text)
+ end
end
test "it escapes HTML in plain text" do
diff --git a/test/pleroma/frontend_test.exs b/test/pleroma/frontend_test.exs
index 1b50a031d..c89c56c8c 100644
--- a/test/pleroma/frontend_test.exs
+++ b/test/pleroma/frontend_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.FrontendTest do
diff --git a/test/pleroma/gun/connection_pool_test.exs b/test/pleroma/gun/connection_pool_test.exs
index 4b3158625..e0c9e9904 100644
--- a/test/pleroma/gun/connection_pool_test.exs
+++ b/test/pleroma/gun/connection_pool_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Gun.ConnectionPoolTest do
@@ -46,6 +46,7 @@ defmodule Pleroma.Gun.ConnectionPoolTest do
end
end
+ @tag :erratic
test "connection limit is respected with concurrent requests" do
clear_config([:connections_pool, :max_connections]) do
clear_config([:connections_pool, :max_connections], 1)
diff --git a/test/pleroma/hashtag_test.exs b/test/pleroma/hashtag_test.exs
index 0264dea0b..8531b1879 100644
--- a/test/pleroma/hashtag_test.exs
+++ b/test/pleroma/hashtag_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.HashtagTest do
diff --git a/test/pleroma/healthcheck_test.exs b/test/pleroma/healthcheck_test.exs
index 469e5b397..dc540c9be 100644
--- a/test/pleroma/healthcheck_test.exs
+++ b/test/pleroma/healthcheck_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.HealthcheckTest do
diff --git a/test/pleroma/html_test.exs b/test/pleroma/html_test.exs
index a1e4bf457..b99689903 100644
--- a/test/pleroma/html_test.exs
+++ b/test/pleroma/html_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.HTMLTest do
diff --git a/test/pleroma/http/adapter_helper/gun_test.exs b/test/pleroma/http/adapter_helper/gun_test.exs
index cfb68557d..7515f4e79 100644
--- a/test/pleroma/http/adapter_helper/gun_test.exs
+++ b/test/pleroma/http/adapter_helper/gun_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.HTTP.AdapterHelper.GunTest do
diff --git a/test/pleroma/http/adapter_helper/hackney_test.exs b/test/pleroma/http/adapter_helper/hackney_test.exs
index 85150a65c..35d6c49a9 100644
--- a/test/pleroma/http/adapter_helper/hackney_test.exs
+++ b/test/pleroma/http/adapter_helper/hackney_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.HTTP.AdapterHelper.HackneyTest do
diff --git a/test/pleroma/http/adapter_helper_test.exs b/test/pleroma/http/adapter_helper_test.exs
index 3c8c89164..e3c78f317 100644
--- a/test/pleroma/http/adapter_helper_test.exs
+++ b/test/pleroma/http/adapter_helper_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.HTTP.AdapterHelperTest do
diff --git a/test/pleroma/http/ex_aws_test.exs b/test/pleroma/http/ex_aws_test.exs
index 4cbc440bd..2bf3415b8 100644
--- a/test/pleroma/http/ex_aws_test.exs
+++ b/test/pleroma/http/ex_aws_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.HTTP.ExAwsTest do
diff --git a/test/pleroma/http/request_builder_test.exs b/test/pleroma/http/request_builder_test.exs
index 433beaac1..0f1ec7468 100644
--- a/test/pleroma/http/request_builder_test.exs
+++ b/test/pleroma/http/request_builder_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.HTTP.RequestBuilderTest do
diff --git a/test/pleroma/http/tzdata_test.exs b/test/pleroma/http/tzdata_test.exs
index 1161bfaef..9c260fbf7 100644
--- a/test/pleroma/http/tzdata_test.exs
+++ b/test/pleroma/http/tzdata_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.HTTP.TzdataTest do
diff --git a/test/pleroma/http_test.exs b/test/pleroma/http_test.exs
index e6a6d31b3..de359e599 100644
--- a/test/pleroma/http_test.exs
+++ b/test/pleroma/http_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.HTTPTest do
diff --git a/test/pleroma/instances/instance_test.exs b/test/pleroma/instances/instance_test.exs
index bacc0b19b..861519bce 100644
--- a/test/pleroma/instances/instance_test.exs
+++ b/test/pleroma/instances/instance_test.exs
@@ -1,11 +1,13 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Instances.InstanceTest do
alias Pleroma.Instances
alias Pleroma.Instances.Instance
alias Pleroma.Repo
+ alias Pleroma.Tests.ObanHelpers
+ alias Pleroma.Web.CommonAPI
use Pleroma.DataCase
@@ -158,4 +160,33 @@ defmodule Pleroma.Instances.InstanceTest do
"Instance.scrape_favicon(\"#{url}\") ignored unreachable host"
end
end
+
+ test "delete_users_and_activities/1 deletes remote instance users and activities" do
+ [mario, luigi, _peach, wario] =
+ users = [
+ insert(:user, nickname: "mario@mushroom.kingdom", name: "Mario"),
+ insert(:user, nickname: "luigi@mushroom.kingdom", name: "Luigi"),
+ insert(:user, nickname: "peach@mushroom.kingdom", name: "Peach"),
+ insert(:user, nickname: "wario@greedville.biz", name: "Wario")
+ ]
+
+ {:ok, post1} = CommonAPI.post(mario, %{status: "letsa go!"})
+ {:ok, post2} = CommonAPI.post(luigi, %{status: "itsa me... luigi"})
+ {:ok, post3} = CommonAPI.post(wario, %{status: "WHA-HA-HA!"})
+
+ {:ok, job} = Instance.delete_users_and_activities("mushroom.kingdom")
+ :ok = ObanHelpers.perform(job)
+
+ [mario, luigi, peach, wario] = Repo.reload(users)
+
+ refute mario.is_active
+ refute luigi.is_active
+ refute peach.is_active
+ refute peach.name == "Peach"
+
+ assert wario.is_active
+ assert wario.name == "Wario"
+
+ assert [nil, nil, %{}] = Repo.reload([post1, post2, post3])
+ end
end
diff --git a/test/pleroma/instances_test.exs b/test/pleroma/instances_test.exs
index 03f9e4e97..96fa9cffe 100644
--- a/test/pleroma/instances_test.exs
+++ b/test/pleroma/instances_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.InstancesTest do
diff --git a/test/pleroma/integration/federation_test.exs b/test/pleroma/integration/federation_test.exs
index da433e2c0..5b00ba5ba 100644
--- a/test/pleroma/integration/federation_test.exs
+++ b/test/pleroma/integration/federation_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Integration.FederationTest do
diff --git a/test/pleroma/integration/mastodon_websocket_test.exs b/test/pleroma/integration/mastodon_websocket_test.exs
index d44033842..9be0445c0 100644
--- a/test/pleroma/integration/mastodon_websocket_test.exs
+++ b/test/pleroma/integration/mastodon_websocket_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Integration.MastodonWebsocketTest do
diff --git a/test/pleroma/job_queue_monitor_test.exs b/test/pleroma/job_queue_monitor_test.exs
index eebf602c5..f2056990f 100644
--- a/test/pleroma/job_queue_monitor_test.exs
+++ b/test/pleroma/job_queue_monitor_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.JobQueueMonitorTest do
diff --git a/test/pleroma/keys_test.exs b/test/pleroma/keys_test.exs
index 9a15bf06e..1db36de8b 100644
--- a/test/pleroma/keys_test.exs
+++ b/test/pleroma/keys_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.KeysTest do
diff --git a/test/pleroma/list_test.exs b/test/pleroma/list_test.exs
index 7e66ad385..a68146b0d 100644
--- a/test/pleroma/list_test.exs
+++ b/test/pleroma/list_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ListTest do
diff --git a/test/pleroma/marker_test.exs b/test/pleroma/marker_test.exs
index 5f87a1c38..819dde9be 100644
--- a/test/pleroma/marker_test.exs
+++ b/test/pleroma/marker_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.MarkerTest do
diff --git a/test/pleroma/mfa/backup_codes_test.exs b/test/pleroma/mfa/backup_codes_test.exs
index 59f984e32..d05d735cf 100644
--- a/test/pleroma/mfa/backup_codes_test.exs
+++ b/test/pleroma/mfa/backup_codes_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.MFA.BackupCodesTest do
diff --git a/test/pleroma/mfa/totp_test.exs b/test/pleroma/mfa/totp_test.exs
index 828993866..56e4f48ed 100644
--- a/test/pleroma/mfa/totp_test.exs
+++ b/test/pleroma/mfa/totp_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.MFA.TOTPTest do
diff --git a/test/pleroma/mfa_test.exs b/test/pleroma/mfa_test.exs
index 76ba1a99d..e9c0c8837 100644
--- a/test/pleroma/mfa_test.exs
+++ b/test/pleroma/mfa_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.MFATest do
diff --git a/test/pleroma/migration_helper/notification_backfill_test.exs b/test/pleroma/migration_helper/notification_backfill_test.exs
index fd253b530..6d47bb6a8 100644
--- a/test/pleroma/migration_helper/notification_backfill_test.exs
+++ b/test/pleroma/migration_helper/notification_backfill_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.MigrationHelper.NotificationBackfillTest do
diff --git a/test/pleroma/moderation_log_test.exs b/test/pleroma/moderation_log_test.exs
index c6c170c45..584b8708b 100644
--- a/test/pleroma/moderation_log_test.exs
+++ b/test/pleroma/moderation_log_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ModerationLogTest do
@@ -236,9 +236,7 @@ defmodule Pleroma.ModerationLogTest do
log = Repo.get(ModerationLog, log2.id)
assert log.data["message"] ==
- "@#{moderator.nickname} added note 'look at this' to report ##{report.id} on user @#{
- user.nickname
- }"
+ "@#{moderator.nickname} added note 'look at this' to report ##{report.id} on user @#{user.nickname}"
end
test "logging status sensitivity update", %{moderator: moderator} do
diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs
index 5c2be9b5c..d33da8efa 100644
--- a/test/pleroma/notification_test.exs
+++ b/test/pleroma/notification_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.NotificationTest do
- use Pleroma.DataCase
+ use Pleroma.DataCase, async: false
import Pleroma.Factory
import Mock
@@ -32,20 +32,26 @@ defmodule Pleroma.NotificationTest do
refute {:ok, [nil]} == Notification.create_notifications(activity)
end
- test "creates a notification for a report" do
+ test "creates a report notification only for privileged users" do
reporting_user = insert(:user)
reported_user = insert(:user)
- {:ok, moderator_user} = insert(:user) |> User.admin_api_update(%{is_moderator: true})
+ moderator_user = insert(:user, is_moderator: true)
- {:ok, activity} = CommonAPI.report(reporting_user, %{account_id: reported_user.id})
+ clear_config([:instance, :moderator_privileges], [])
+ {:ok, activity1} = CommonAPI.report(reporting_user, %{account_id: reported_user.id})
+ {:ok, []} = Notification.create_notifications(activity1)
- {:ok, [notification]} = Notification.create_notifications(activity)
+ clear_config([:instance, :moderator_privileges], [:reports_manage_reports])
+ {:ok, activity2} = CommonAPI.report(reporting_user, %{account_id: reported_user.id})
+ {:ok, [notification]} = Notification.create_notifications(activity2)
assert notification.user_id == moderator_user.id
assert notification.type == "pleroma:report"
end
- test "suppresses notification to reporter if reporter is an admin" do
+ test "suppresses notifications for own reports" do
+ clear_config([:instance, :admin_privileges], [:reports_manage_reports])
+
reporting_admin = insert(:user, is_admin: true)
reported_user = insert(:user)
other_admin = insert(:user, is_admin: true)
@@ -127,6 +133,41 @@ defmodule Pleroma.NotificationTest do
subscriber_notifications = Notification.for_user(subscriber)
assert Enum.empty?(subscriber_notifications)
end
+
+ test "it sends edited notifications to those who repeated a status" do
+ user = insert(:user)
+ repeated_user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity_one} =
+ CommonAPI.post(user, %{
+ status: "hey @#{other_user.nickname}!"
+ })
+
+ {:ok, _activity_two} = CommonAPI.repeat(activity_one.id, repeated_user)
+
+ {:ok, _edit_activity} =
+ CommonAPI.update(user, activity_one, %{
+ status: "hey @#{other_user.nickname}! mew mew"
+ })
+
+ assert [%{type: "reblog"}] = Notification.for_user(user)
+ assert [%{type: "update"}] = Notification.for_user(repeated_user)
+ assert [%{type: "mention"}] = Notification.for_user(other_user)
+ end
+ end
+
+ test "create_poll_notifications/1" do
+ [user1, user2, user3, _, _] = insert_list(5, :user)
+ question = insert(:question, user: user1)
+ activity = insert(:question_activity, question: question)
+
+ {:ok, _, _} = CommonAPI.vote(user2, question, [0])
+ {:ok, _, _} = CommonAPI.vote(user3, question, [1])
+
+ {:ok, notifications} = Notification.create_poll_notifications(activity)
+
+ assert [user2.id, user3.id, user1.id] == Enum.map(notifications, & &1.user_id)
end
describe "CommonApi.post/2 notification-related functionality" do
@@ -826,6 +867,30 @@ defmodule Pleroma.NotificationTest do
assert [other_user] == enabled_receivers
assert [] == disabled_receivers
end
+
+ test "it sends edited notifications to those who repeated a status" do
+ user = insert(:user)
+ repeated_user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity_one} =
+ CommonAPI.post(user, %{
+ status: "hey @#{other_user.nickname}!"
+ })
+
+ {:ok, _activity_two} = CommonAPI.repeat(activity_one.id, repeated_user)
+
+ {:ok, edit_activity} =
+ CommonAPI.update(user, activity_one, %{
+ status: "hey @#{other_user.nickname}! mew mew"
+ })
+
+ {enabled_receivers, _disabled_receivers} =
+ Notification.get_notified_from_activity(edit_activity)
+
+ assert repeated_user in enabled_receivers
+ assert other_user not in enabled_receivers
+ end
end
describe "notification lifecycle" do
diff --git a/test/pleroma/object/containment_test.exs b/test/pleroma/object/containment_test.exs
index fb2fb7d49..cf906ef47 100644
--- a/test/pleroma/object/containment_test.exs
+++ b/test/pleroma/object/containment_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Object.ContainmentTest do
diff --git a/test/pleroma/object/fetcher_test.exs b/test/pleroma/object/fetcher_test.exs
index bd0a6e497..c8ad66ddb 100644
--- a/test/pleroma/object/fetcher_test.exs
+++ b/test/pleroma/object/fetcher_test.exs
@@ -1,11 +1,12 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Object.FetcherTest do
use Pleroma.DataCase
alias Pleroma.Activity
+ alias Pleroma.Instances
alias Pleroma.Object
alias Pleroma.Object.Fetcher
@@ -159,6 +160,17 @@ defmodule Pleroma.Object.FetcherTest do
"https://patch.cx/media/03ca3c8b4ac3ddd08bf0f84be7885f2f88de0f709112131a22d83650819e36c2.json"
)
end
+
+ test "it resets instance reachability on successful fetch" do
+ id = "http://mastodon.example.org/@admin/99541947525187367"
+ Instances.set_consistently_unreachable(id)
+ refute Instances.reachable?(id)
+
+ {:ok, _object} =
+ Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
+
+ assert Instances.reachable?(id)
+ end
end
describe "implementation quirks" do
@@ -269,4 +281,271 @@ defmodule Pleroma.Object.FetcherTest do
refute called(Pleroma.Signature.sign(:_, :_))
end
end
+
+ describe "refetching" do
+ setup do
+ object1 = %{
+ "id" => "https://mastodon.social/1",
+ "actor" => "https://mastodon.social/users/emelie",
+ "attributedTo" => "https://mastodon.social/users/emelie",
+ "type" => "Note",
+ "content" => "test 1",
+ "bcc" => [],
+ "bto" => [],
+ "cc" => [],
+ "to" => [],
+ "summary" => ""
+ }
+
+ object2 = %{
+ "id" => "https://mastodon.social/2",
+ "actor" => "https://mastodon.social/users/emelie",
+ "attributedTo" => "https://mastodon.social/users/emelie",
+ "type" => "Note",
+ "content" => "test 2",
+ "bcc" => [],
+ "bto" => [],
+ "cc" => [],
+ "to" => [],
+ "summary" => "",
+ "formerRepresentations" => %{
+ "type" => "OrderedCollection",
+ "orderedItems" => [
+ %{
+ "type" => "Note",
+ "content" => "orig 2",
+ "actor" => "https://mastodon.social/users/emelie",
+ "attributedTo" => "https://mastodon.social/users/emelie",
+ "bcc" => [],
+ "bto" => [],
+ "cc" => [],
+ "to" => [],
+ "summary" => ""
+ }
+ ],
+ "totalItems" => 1
+ }
+ }
+
+ mock(fn
+ %{
+ method: :get,
+ url: "https://mastodon.social/1"
+ } ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/activity+json"}],
+ body: Jason.encode!(object1)
+ }
+
+ %{
+ method: :get,
+ url: "https://mastodon.social/2"
+ } ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/activity+json"}],
+ body: Jason.encode!(object2)
+ }
+
+ %{
+ method: :get,
+ url: "https://mastodon.social/users/emelie/collections/featured"
+ } ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/activity+json"}],
+ body:
+ Jason.encode!(%{
+ "id" => "https://mastodon.social/users/emelie/collections/featured",
+ "type" => "OrderedCollection",
+ "actor" => "https://mastodon.social/users/emelie",
+ "attributedTo" => "https://mastodon.social/users/emelie",
+ "orderedItems" => [],
+ "totalItems" => 0
+ })
+ }
+
+ env ->
+ apply(HttpRequestMock, :request, [env])
+ end)
+
+ %{object1: object1, object2: object2}
+ end
+
+ test "it keeps formerRepresentations if remote does not have this attr", %{object1: object1} do
+ full_object1 =
+ object1
+ |> Map.merge(%{
+ "formerRepresentations" => %{
+ "type" => "OrderedCollection",
+ "orderedItems" => [
+ %{
+ "type" => "Note",
+ "content" => "orig 2",
+ "actor" => "https://mastodon.social/users/emelie",
+ "attributedTo" => "https://mastodon.social/users/emelie",
+ "bcc" => [],
+ "bto" => [],
+ "cc" => [],
+ "to" => [],
+ "summary" => ""
+ }
+ ],
+ "totalItems" => 1
+ }
+ })
+
+ {:ok, o} = Object.create(full_object1)
+
+ assert {:ok, refetched} = Fetcher.refetch_object(o)
+
+ assert %{"formerRepresentations" => %{"orderedItems" => [%{"content" => "orig 2"}]}} =
+ refetched.data
+ end
+
+ test "it uses formerRepresentations from remote if possible", %{object2: object2} do
+ {:ok, o} = Object.create(object2)
+
+ assert {:ok, refetched} = Fetcher.refetch_object(o)
+
+ assert %{"formerRepresentations" => %{"orderedItems" => [%{"content" => "orig 2"}]}} =
+ refetched.data
+ end
+
+ test "it replaces formerRepresentations with the one from remote", %{object2: object2} do
+ full_object2 =
+ object2
+ |> Map.merge(%{
+ "content" => "mew mew #def",
+ "formerRepresentations" => %{
+ "type" => "OrderedCollection",
+ "orderedItems" => [
+ %{"type" => "Note", "content" => "mew mew 2"}
+ ],
+ "totalItems" => 1
+ }
+ })
+
+ {:ok, o} = Object.create(full_object2)
+
+ assert {:ok, refetched} = Fetcher.refetch_object(o)
+
+ assert %{
+ "content" => "test 2",
+ "formerRepresentations" => %{"orderedItems" => [%{"content" => "orig 2"}]}
+ } = refetched.data
+ end
+
+ test "it adds to formerRepresentations if the remote does not have one and the object has changed",
+ %{object1: object1} do
+ full_object1 =
+ object1
+ |> Map.merge(%{
+ "content" => "mew mew #def",
+ "formerRepresentations" => %{
+ "type" => "OrderedCollection",
+ "orderedItems" => [
+ %{"type" => "Note", "content" => "mew mew 1"}
+ ],
+ "totalItems" => 1
+ }
+ })
+
+ {:ok, o} = Object.create(full_object1)
+
+ assert {:ok, refetched} = Fetcher.refetch_object(o)
+
+ assert %{
+ "content" => "test 1",
+ "formerRepresentations" => %{
+ "orderedItems" => [
+ %{"content" => "mew mew #def"},
+ %{"content" => "mew mew 1"}
+ ],
+ "totalItems" => 2
+ }
+ } = refetched.data
+ end
+ end
+
+ describe "fetch with history" do
+ setup do
+ object2 = %{
+ "id" => "https://mastodon.social/2",
+ "actor" => "https://mastodon.social/users/emelie",
+ "attributedTo" => "https://mastodon.social/users/emelie",
+ "type" => "Note",
+ "content" => "test 2",
+ "bcc" => [],
+ "bto" => [],
+ "cc" => ["https://mastodon.social/users/emelie/followers"],
+ "to" => [],
+ "summary" => "",
+ "formerRepresentations" => %{
+ "type" => "OrderedCollection",
+ "orderedItems" => [
+ %{
+ "type" => "Note",
+ "content" => "orig 2",
+ "actor" => "https://mastodon.social/users/emelie",
+ "attributedTo" => "https://mastodon.social/users/emelie",
+ "bcc" => [],
+ "bto" => [],
+ "cc" => ["https://mastodon.social/users/emelie/followers"],
+ "to" => [],
+ "summary" => ""
+ }
+ ],
+ "totalItems" => 1
+ }
+ }
+
+ mock(fn
+ %{
+ method: :get,
+ url: "https://mastodon.social/2"
+ } ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/activity+json"}],
+ body: Jason.encode!(object2)
+ }
+
+ %{
+ method: :get,
+ url: "https://mastodon.social/users/emelie/collections/featured"
+ } ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/activity+json"}],
+ body:
+ Jason.encode!(%{
+ "id" => "https://mastodon.social/users/emelie/collections/featured",
+ "type" => "OrderedCollection",
+ "actor" => "https://mastodon.social/users/emelie",
+ "attributedTo" => "https://mastodon.social/users/emelie",
+ "orderedItems" => [],
+ "totalItems" => 0
+ })
+ }
+
+ env ->
+ apply(HttpRequestMock, :request, [env])
+ end)
+
+ %{object2: object2}
+ end
+
+ test "it gets history", %{object2: object2} do
+ {:ok, object} = Fetcher.fetch_object_from_id(object2["id"])
+
+ assert %{
+ "formerRepresentations" => %{
+ "type" => "OrderedCollection",
+ "orderedItems" => [%{}]
+ }
+ } = object.data
+ end
+ end
end
diff --git a/test/pleroma/object/updater_test.exs b/test/pleroma/object/updater_test.exs
new file mode 100644
index 000000000..7e9b44823
--- /dev/null
+++ b/test/pleroma/object/updater_test.exs
@@ -0,0 +1,76 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Object.UpdaterTest do
+ use Pleroma.DataCase
+ use Oban.Testing, repo: Pleroma.Repo
+
+ import Pleroma.Factory
+
+ alias Pleroma.Object.Updater
+
+ describe "make_update_object_data/3" do
+ setup do
+ note = insert(:note)
+ %{original_data: note.data}
+ end
+
+ test "it makes an updated field", %{original_data: original_data} do
+ new_data = Map.put(original_data, "content", "new content")
+
+ date = Pleroma.Web.ActivityPub.Utils.make_date()
+ update_object_data = Updater.make_update_object_data(original_data, new_data, date)
+ assert %{"updated" => ^date} = update_object_data
+ end
+
+ test "it creates formerRepresentations", %{original_data: original_data} do
+ new_data = Map.put(original_data, "content", "new content")
+
+ date = Pleroma.Web.ActivityPub.Utils.make_date()
+ update_object_data = Updater.make_update_object_data(original_data, new_data, date)
+
+ history_item = original_data |> Map.drop(["id", "formerRepresentations"])
+
+ assert %{
+ "formerRepresentations" => %{
+ "totalItems" => 1,
+ "orderedItems" => [^history_item]
+ }
+ } = update_object_data
+ end
+ end
+
+ describe "make_new_object_data_from_update_object/2" do
+ test "it reuses formerRepresentations if it exists" do
+ %{data: original_data} = insert(:note)
+
+ new_data =
+ original_data
+ |> Map.put("content", "edited")
+
+ date = Pleroma.Web.ActivityPub.Utils.make_date()
+ update_object_data = Updater.make_update_object_data(original_data, new_data, date)
+
+ history = update_object_data["formerRepresentations"]["orderedItems"]
+
+ update_object_data =
+ update_object_data
+ |> put_in(
+ ["formerRepresentations", "orderedItems"],
+ history ++ [Map.put(original_data, "summary", "additional summary")]
+ )
+ |> put_in(["formerRepresentations", "totalItems"], length(history) + 1)
+
+ %{
+ updated_data: updated_data,
+ updated: updated,
+ used_history_in_new_object?: used_history_in_new_object?
+ } = Updater.make_new_object_data_from_update_object(original_data, update_object_data)
+
+ assert updated
+ assert used_history_in_new_object?
+ assert updated_data["formerRepresentations"] == update_object_data["formerRepresentations"]
+ end
+ end
+end
diff --git a/test/pleroma/object_test.exs b/test/pleroma/object_test.exs
index 8320660a5..d536e0b16 100644
--- a/test/pleroma/object_test.exs
+++ b/test/pleroma/object_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ObjectTest do
diff --git a/test/pleroma/otp_version_test.exs b/test/pleroma/otp_version_test.exs
index 736d440af..642cd1310 100644
--- a/test/pleroma/otp_version_test.exs
+++ b/test/pleroma/otp_version_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.OTPVersionTest do
diff --git a/test/pleroma/pagination_test.exs b/test/pleroma/pagination_test.exs
index bc26c8b46..f241a21d5 100644
--- a/test/pleroma/pagination_test.exs
+++ b/test/pleroma/pagination_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.PaginationTest do
diff --git a/test/pleroma/password/pbkdf2_test.exs b/test/pleroma/password/pbkdf2_test.exs
index e55348f9a..02f59445c 100644
--- a/test/pleroma/password/pbkdf2_test.exs
+++ b/test/pleroma/password/pbkdf2_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Password.Pbkdf2Test do
diff --git a/test/pleroma/registration_test.exs b/test/pleroma/registration_test.exs
index 6e4ad9487..89992ec26 100644
--- a/test/pleroma/registration_test.exs
+++ b/test/pleroma/registration_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.RegistrationTest do
diff --git a/test/pleroma/repo/migrations/autolinker_to_linkify_test.exs b/test/pleroma/repo/migrations/autolinker_to_linkify_test.exs
index a7d4d493c..52a606368 100644
--- a/test/pleroma/repo/migrations/autolinker_to_linkify_test.exs
+++ b/test/pleroma/repo/migrations/autolinker_to_linkify_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Repo.Migrations.AutolinkerToLinkifyTest do
diff --git a/test/pleroma/repo/migrations/confirm_logged_in_users_test.exs b/test/pleroma/repo/migrations/confirm_logged_in_users_test.exs
index 99d17f62a..a0731f5a4 100644
--- a/test/pleroma/repo/migrations/confirm_logged_in_users_test.exs
+++ b/test/pleroma/repo/migrations/confirm_logged_in_users_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Repo.Migrations.ConfirmLoggedInUsersTest do
diff --git a/test/pleroma/repo/migrations/deprecate_public_endpoint_test.exs b/test/pleroma/repo/migrations/deprecate_public_endpoint_test.exs
index 2ffc1b145..d19ffd69b 100644
--- a/test/pleroma/repo/migrations/deprecate_public_endpoint_test.exs
+++ b/test/pleroma/repo/migrations/deprecate_public_endpoint_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Repo.Migrations.DeprecatePublicEndpointTest do
diff --git a/test/pleroma/repo/migrations/fix_legacy_tags_test.exs b/test/pleroma/repo/migrations/fix_legacy_tags_test.exs
index 0a1d1d0bb..21fdee1ab 100644
--- a/test/pleroma/repo/migrations/fix_legacy_tags_test.exs
+++ b/test/pleroma/repo/migrations/fix_legacy_tags_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Repo.Migrations.FixLegacyTagsTest do
diff --git a/test/pleroma/repo/migrations/fix_malformed_formatter_config_test.exs b/test/pleroma/repo/migrations/fix_malformed_formatter_config_test.exs
index 65c9961b0..4c45adb4b 100644
--- a/test/pleroma/repo/migrations/fix_malformed_formatter_config_test.exs
+++ b/test/pleroma/repo/migrations/fix_malformed_formatter_config_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Repo.Migrations.FixMalformedFormatterConfigTest do
diff --git a/test/pleroma/repo/migrations/move_welcome_settings_test.exs b/test/pleroma/repo/migrations/move_welcome_settings_test.exs
index 1da6b8a04..3e485c3ad 100644
--- a/test/pleroma/repo/migrations/move_welcome_settings_test.exs
+++ b/test/pleroma/repo/migrations/move_welcome_settings_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Repo.Migrations.MoveWelcomeSettingsTest do
diff --git a/test/pleroma/repo/migrations/rename_instance_chat_test.exs b/test/pleroma/repo/migrations/rename_instance_chat_test.exs
index acd45600c..17c39fd27 100644
--- a/test/pleroma/repo/migrations/rename_instance_chat_test.exs
+++ b/test/pleroma/repo/migrations/rename_instance_chat_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Repo.Migrations.RenameInstanceChatTest do
use Pleroma.DataCase
import Pleroma.Factory
diff --git a/test/pleroma/repo_test.exs b/test/pleroma/repo_test.exs
index 9e14bdbd1..9c0f5d028 100644
--- a/test/pleroma/repo_test.exs
+++ b/test/pleroma/repo_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.RepoTest do
diff --git a/test/pleroma/report_note_test.exs b/test/pleroma/report_note_test.exs
index 2620560a0..e2028a3ba 100644
--- a/test/pleroma/report_note_test.exs
+++ b/test/pleroma/report_note_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ReportNoteTest do
@@ -13,4 +13,27 @@ defmodule Pleroma.ReportNoteTest do
assert {:ok, note} = ReportNote.create(user.id, report.id, "naughty boy")
assert note.content == "naughty boy"
end
+
+ test "create/3 with very long content" do
+ user = insert(:user)
+ report = insert(:report_activity)
+
+ very_long_content = """
+ ] pwgen 25 15
+ eJ9eeceiquoolei2queeLeimi aiN9ie2iokie8chush7aiph5N ulaNgaighoPiequaipuzoog8F
+ Ohphei0hee6hoo0wah4Aasah9 ziel3Yo3eew4neiy3ekiesh8u ue9ShahTh7oongoPheeneijah
+ ohGheeCh6aloque0Neviopou3 ush2oobohxeec4aequeich3Oo Ze3eighoowiojadohch8iCa1n
+ Yu4yieBie9eengoich8fae4th chohqu6exooSiibogh3iefeez peephahtaik9quie5mohD9nee
+ eeQuur3rie5mei8ieng6iesie wei1meinguv0Heidoov8Ibaed deemo2Poh6ohc3eiBeez1uox2
+ ] pwgen 25 15
+ eJ9eeceiquoolei2queeLeimi aiN9ie2iokie8chush7aiph5N ulaNgaighoPiequaipuzoog8F
+ Ohphei0hee6hoo0wah4Aasah9 ziel3Yo3eew4neiy3ekiesh8u ue9ShahTh7oongoPheeneijah
+ ohGheeCh6aloque0Neviopou3 ush2oobohxeec4aequeich3Oo Ze3eighoowiojadohch8iCa1n
+ Yu4yieBie9eengoich8fae4th chohqu6exooSiibogh3iefeez peephahtaik9quie5mohD9nee
+ eeQuur3rie5mei8ieng6iesie wei1meinguv0Heidoov8Ibaed deemo2Poh6ohc3eiBeez1uox2
+ """
+
+ assert {:ok, note} = ReportNote.create(user.id, report.id, very_long_content)
+ assert note.content == very_long_content
+ end
end
diff --git a/test/pleroma/resilience_test.exs b/test/pleroma/resilience_test.exs
new file mode 100644
index 000000000..9dc5d0dd6
--- /dev/null
+++ b/test/pleroma/resilience_test.exs
@@ -0,0 +1,103 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.ResilienceTest do
+ use Pleroma.Web.ConnCase, async: true
+
+ import Pleroma.Factory
+
+ alias Pleroma.Activity
+ alias Pleroma.Repo
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.MastodonAPI.StatusView
+
+ setup do
+ # user = insert(:user)
+ %{user: user, conn: conn} = oauth_access(["write", "read"])
+ other_user = insert(:user)
+
+ {:ok, post_one} = CommonAPI.post(user, %{status: "Here is a post"})
+ {:ok, like} = CommonAPI.favorite(other_user, post_one.id)
+
+ %{
+ user: user,
+ other_user: other_user,
+ post_one: post_one,
+ like: like,
+ conn: conn
+ }
+ end
+
+ test "after destruction of like activities, things still work", %{
+ user: user,
+ post_one: post,
+ other_user: other_user,
+ conn: conn,
+ like: like
+ } do
+ post = Repo.get(Activity, post.id)
+
+ # Rendering the liked status
+ rendered_for_user = StatusView.render("show.json", %{activity: post, for: user})
+ assert rendered_for_user.favourites_count == 1
+
+ rendered_for_other_user = StatusView.render("show.json", %{activity: post, for: other_user})
+ assert rendered_for_other_user.favourites_count == 1
+ assert rendered_for_other_user.favourited
+
+ # Getting the favourited by
+ [liking_user] =
+ conn
+ |> get("/api/v1/statuses/#{post.id}/favourited_by")
+ |> json_response(200)
+
+ assert liking_user["id"] == other_user.id
+
+ # We have one notification
+ [notification] =
+ conn
+ |> get("/api/v1/notifications")
+ |> json_response(200)
+
+ assert notification["type"] == "favourite"
+
+ # Destroying the like
+ Repo.delete(like)
+ post = Repo.get(Activity, post.id)
+
+ # Rendering the liked status
+ rendered_for_user = StatusView.render("show.json", %{activity: post, for: user})
+ assert rendered_for_user.favourites_count == 1
+
+ rendered_for_other_user = StatusView.render("show.json", %{activity: post, for: other_user})
+ assert rendered_for_other_user.favourites_count == 1
+ assert rendered_for_other_user.favourited
+
+ # Getting the favourited by
+ [liking_user] =
+ conn
+ |> get("/api/v1/statuses/#{post.id}/favourited_by")
+ |> json_response(200)
+
+ assert liking_user["id"] == other_user.id
+
+ # Notification is removed
+
+ assert [] ==
+ conn
+ |> get("/api/v1/notifications")
+ |> json_response(200)
+
+ # Favoriting again doesn't hurt
+ {:ok, _like_two} = CommonAPI.favorite(other_user, post.id)
+
+ post = Repo.get(Activity, post.id)
+
+ # Rendering the liked status
+ rendered_for_user = StatusView.render("show.json", %{activity: post, for: user})
+ assert rendered_for_user.favourites_count == 1
+
+ # General fallout: Can't unfavorite stuff anymore. Acceptable for remote users.
+ end
+end
diff --git a/test/pleroma/reverse_proxy_test.exs b/test/pleroma/reverse_proxy_test.exs
index a4dd8e99a..0bd4db8d1 100644
--- a/test/pleroma/reverse_proxy_test.exs
+++ b/test/pleroma/reverse_proxy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ReverseProxyTest do
@@ -130,7 +130,7 @@ defmodule Pleroma.ReverseProxyTest do
assert capture_log(fn ->
ReverseProxy.call(conn, "/stream-bytes/50", max_body_length: 30)
end) =~
- "[warn] Elixir.Pleroma.ReverseProxy request to /stream-bytes/50 failed while reading/chunking: :body_too_large"
+ "Elixir.Pleroma.ReverseProxy request to /stream-bytes/50 failed while reading/chunking: :body_too_large"
end
end
diff --git a/test/pleroma/runtime_test.exs b/test/pleroma/runtime_test.exs
index b9e769602..6b8d2050c 100644
--- a/test/pleroma/runtime_test.exs
+++ b/test/pleroma/runtime_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.RuntimeTest do
diff --git a/test/pleroma/safe_jsonb_set_test.exs b/test/pleroma/safe_jsonb_set_test.exs
index 69d696c1b..ab1bba941 100644
--- a/test/pleroma/safe_jsonb_set_test.exs
+++ b/test/pleroma/safe_jsonb_set_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.SafeJsonbSetTest do
diff --git a/test/pleroma/scheduled_activity_test.exs b/test/pleroma/scheduled_activity_test.exs
index ef91e9bce..3a0927d3f 100644
--- a/test/pleroma/scheduled_activity_test.exs
+++ b/test/pleroma/scheduled_activity_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ScheduledActivityTest do
diff --git a/test/pleroma/signature_test.exs b/test/pleroma/signature_test.exs
index e3ae36b46..b849cbee7 100644
--- a/test/pleroma/signature_test.exs
+++ b/test/pleroma/signature_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.SignatureTest do
diff --git a/test/pleroma/stats_test.exs b/test/pleroma/stats_test.exs
index fd3195969..37a085afc 100644
--- a/test/pleroma/stats_test.exs
+++ b/test/pleroma/stats_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.StatsTest do
diff --git a/test/pleroma/upload/filter/analyze_metadata_test.exs b/test/pleroma/upload/filter/analyze_metadata_test.exs
index 4b636a684..b800a4a43 100644
--- a/test/pleroma/upload/filter/analyze_metadata_test.exs
+++ b/test/pleroma/upload/filter/analyze_metadata_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Upload.Filter.AnalyzeMetadataTest do
diff --git a/test/pleroma/upload/filter/anonymize_filename_test.exs b/test/pleroma/upload/filter/anonymize_filename_test.exs
index 9387c1abc..9b94b91c3 100644
--- a/test/pleroma/upload/filter/anonymize_filename_test.exs
+++ b/test/pleroma/upload/filter/anonymize_filename_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Upload.Filter.AnonymizeFilenameTest do
diff --git a/test/pleroma/upload/filter/dedupe_test.exs b/test/pleroma/upload/filter/dedupe_test.exs
index f00ba12f9..29c181509 100644
--- a/test/pleroma/upload/filter/dedupe_test.exs
+++ b/test/pleroma/upload/filter/dedupe_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Upload.Filter.DedupeTest do
diff --git a/test/pleroma/upload/filter/exiftool/read_description_test.exs b/test/pleroma/upload/filter/exiftool/read_description_test.exs
new file mode 100644
index 000000000..7389fda47
--- /dev/null
+++ b/test/pleroma/upload/filter/exiftool/read_description_test.exs
@@ -0,0 +1,117 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Upload.Filter.Exiftool.ReadDescriptionTest do
+ use Pleroma.DataCase, async: true
+ alias Pleroma.Upload.Filter
+
+ @uploads %Pleroma.Upload{
+ name: "image_with_imagedescription_and_caption-abstract.jpg",
+ content_type: "image/jpeg",
+ path: Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
+ tempfile: Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
+ description: nil
+ }
+
+ test "keeps description when not empty" do
+ uploads = %Pleroma.Upload{
+ name: "image_with_imagedescription_and_caption-abstract.jpg",
+ content_type: "image/jpeg",
+ path: Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
+ tempfile:
+ Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
+ description: "Some description"
+ }
+
+ assert Filter.Exiftool.ReadDescription.filter(uploads) ==
+ {:ok, :noop}
+ end
+
+ test "otherwise returns ImageDescription when present" do
+ uploads_after = %Pleroma.Upload{
+ name: "image_with_imagedescription_and_caption-abstract.jpg",
+ content_type: "image/jpeg",
+ path: Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
+ tempfile:
+ Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
+ description: "a descriptive white pixel"
+ }
+
+ assert Filter.Exiftool.ReadDescription.filter(@uploads) ==
+ {:ok, :filtered, uploads_after}
+ end
+
+ test "otherwise returns iptc:Caption-Abstract when present" do
+ upload = %Pleroma.Upload{
+ name: "image_with_caption-abstract.jpg",
+ content_type: "image/jpeg",
+ path: Path.absname("test/fixtures/image_with_caption-abstract.jpg"),
+ tempfile: Path.absname("test/fixtures/image_with_caption-abstract.jpg"),
+ description: nil
+ }
+
+ upload_after = %Pleroma.Upload{
+ name: "image_with_caption-abstract.jpg",
+ content_type: "image/jpeg",
+ path: Path.absname("test/fixtures/image_with_caption-abstract.jpg"),
+ tempfile: Path.absname("test/fixtures/image_with_caption-abstract.jpg"),
+ description: "an abstract white pixel"
+ }
+
+ assert Filter.Exiftool.ReadDescription.filter(upload) ==
+ {:ok, :filtered, upload_after}
+ end
+
+ test "otherwise returns nil" do
+ uploads = %Pleroma.Upload{
+ name: "image_with_no_description.jpg",
+ content_type: "image/jpeg",
+ path: Path.absname("test/fixtures/image_with_no_description.jpg"),
+ tempfile: Path.absname("test/fixtures/image_with_no_description.jpg"),
+ description: nil
+ }
+
+ assert Filter.Exiftool.ReadDescription.filter(uploads) ==
+ {:ok, :filtered, uploads}
+ end
+
+ test "Return nil when image description from EXIF data exceeds the maximum length" do
+ clear_config([:instance, :description_limit], 5)
+
+ assert Filter.Exiftool.ReadDescription.filter(@uploads) ==
+ {:ok, :filtered, @uploads}
+ end
+
+ test "Ignores content with only whitespace" do
+ uploads = %Pleroma.Upload{
+ name: "non-existant.jpg",
+ content_type: "image/jpeg",
+ path:
+ Path.absname(
+ "test/fixtures/image_with_imagedescription_and_caption-abstract_whitespaces.jpg"
+ ),
+ tempfile:
+ Path.absname(
+ "test/fixtures/image_with_imagedescription_and_caption-abstract_whitespaces.jpg"
+ ),
+ description: nil
+ }
+
+ assert Filter.Exiftool.ReadDescription.filter(uploads) ==
+ {:ok, :filtered, uploads}
+ end
+
+ test "Return nil when image description from EXIF data can't be read" do
+ uploads = %Pleroma.Upload{
+ name: "non-existant.jpg",
+ content_type: "image/jpeg",
+ path: Path.absname("test/fixtures/non-existant.jpg"),
+ tempfile: Path.absname("test/fixtures/non-existant_tmp.jpg"),
+ description: nil
+ }
+
+ assert Filter.Exiftool.ReadDescription.filter(uploads) ==
+ {:ok, :filtered, uploads}
+ end
+end
diff --git a/test/pleroma/upload/filter/exiftool_test.exs b/test/pleroma/upload/filter/exiftool/strip_location_test.exs
index cfbe34be8..7e1541f60 100644
--- a/test/pleroma/upload/filter/exiftool_test.exs
+++ b/test/pleroma/upload/filter/exiftool/strip_location_test.exs
@@ -1,8 +1,8 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Upload.Filter.ExiftoolTest do
+defmodule Pleroma.Upload.Filter.Exiftool.StripLocationTest do
use Pleroma.DataCase, async: true
alias Pleroma.Upload.Filter
@@ -21,7 +21,7 @@ defmodule Pleroma.Upload.Filter.ExiftoolTest do
tempfile: Path.absname("test/fixtures/DSCN0010_tmp.jpg")
}
- assert Filter.Exiftool.filter(upload) == {:ok, :filtered}
+ assert Filter.Exiftool.StripLocation.filter(upload) == {:ok, :filtered}
{exif_original, 0} = System.cmd("exiftool", ["test/fixtures/DSCN0010.jpg"])
{exif_filtered, 0} = System.cmd("exiftool", ["test/fixtures/DSCN0010_tmp.jpg"])
@@ -37,6 +37,6 @@ defmodule Pleroma.Upload.Filter.ExiftoolTest do
content_type: "image/webp"
}
- assert Filter.Exiftool.filter(upload) == {:ok, :noop}
+ assert Filter.Exiftool.StripLocation.filter(upload) == {:ok, :noop}
end
end
diff --git a/test/pleroma/upload/filter/mogrifun_test.exs b/test/pleroma/upload/filter/mogrifun_test.exs
index d2b183e90..bf9b65589 100644
--- a/test/pleroma/upload/filter/mogrifun_test.exs
+++ b/test/pleroma/upload/filter/mogrifun_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Upload.Filter.MogrifunTest do
diff --git a/test/pleroma/upload/filter/mogrify_test.exs b/test/pleroma/upload/filter/mogrify_test.exs
index d62cd83b4..208da57ca 100644
--- a/test/pleroma/upload/filter/mogrify_test.exs
+++ b/test/pleroma/upload/filter/mogrify_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Upload.Filter.MogrifyTest do
diff --git a/test/pleroma/upload/filter_test.exs b/test/pleroma/upload/filter_test.exs
index f0053ed9b..706fc9ac7 100644
--- a/test/pleroma/upload/filter_test.exs
+++ b/test/pleroma/upload/filter_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Upload.FilterTest do
diff --git a/test/pleroma/upload_test.exs b/test/pleroma/upload_test.exs
index f1ab82a57..6584c2def 100644
--- a/test/pleroma/upload_test.exs
+++ b/test/pleroma/upload_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.UploadTest do
@@ -49,20 +49,22 @@ defmodule Pleroma.UploadTest do
test "it returns file" do
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
- assert Upload.store(@upload_file) ==
- {:ok,
- %{
- "name" => "image.jpg",
- "type" => "Document",
- "mediaType" => "image/jpeg",
- "url" => [
- %{
- "href" => "http://localhost:4001/media/post-process-file.jpg",
- "mediaType" => "image/jpeg",
- "type" => "Link"
- }
- ]
- }}
+ assert {:ok, result} = Upload.store(@upload_file)
+
+ assert result ==
+ %{
+ "id" => result["id"],
+ "name" => "image.jpg",
+ "type" => "Document",
+ "mediaType" => "image/jpeg",
+ "url" => [
+ %{
+ "href" => "http://localhost:4001/media/post-process-file.jpg",
+ "mediaType" => "image/jpeg",
+ "type" => "Link"
+ }
+ ]
+ }
Task.await(Agent.get(TestUploaderSuccess, fn task_pid -> task_pid end))
end
diff --git a/test/pleroma/uploaders/local_test.exs b/test/pleroma/uploaders/local_test.exs
index 0a5952f50..a2b7f5c24 100644
--- a/test/pleroma/uploaders/local_test.exs
+++ b/test/pleroma/uploaders/local_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Uploaders.LocalTest do
diff --git a/test/pleroma/uploaders/s3_test.exs b/test/pleroma/uploaders/s3_test.exs
index 2711e2c8d..d870449b1 100644
--- a/test/pleroma/uploaders/s3_test.exs
+++ b/test/pleroma/uploaders/s3_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Uploaders.S3Test do
diff --git a/test/pleroma/user/backup_test.exs b/test/pleroma/user/backup_test.exs
index b16152876..5c9b94000 100644
--- a/test/pleroma/user/backup_test.exs
+++ b/test/pleroma/user/backup_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.User.BackupTest do
@@ -22,15 +22,15 @@ defmodule Pleroma.User.BackupTest do
clear_config([Pleroma.Emails.Mailer, :enabled], true)
end
- test "it requries enabled email" do
+ test "it does not requrie enabled email" do
clear_config([Pleroma.Emails.Mailer, :enabled], false)
user = insert(:user)
- assert {:error, "Backups require enabled email"} == Backup.create(user)
+ assert {:ok, _} = Backup.create(user)
end
- test "it requries user's email" do
+ test "it does not require user's email" do
user = insert(:user, %{email: nil})
- assert {:error, "Email is required"} == Backup.create(user)
+ assert {:ok, _} = Backup.create(user)
end
test "it creates a backup record and an Oban job" do
@@ -75,6 +75,43 @@ defmodule Pleroma.User.BackupTest do
)
end
+ test "it does not send an email if the user does not have an email" do
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ %{id: user_id} = user = insert(:user, %{email: nil})
+
+ assert {:ok, %Oban.Job{args: %{"backup_id" => backup_id} = args}} = Backup.create(user)
+ assert {:ok, backup} = perform_job(BackupWorker, args)
+ assert backup.file_size > 0
+ assert %Backup{id: ^backup_id, processed: true, user_id: ^user_id} = backup
+
+ assert_no_email_sent()
+ end
+
+ test "it does not send an email if mailer is not on" do
+ clear_config([Pleroma.Emails.Mailer, :enabled], false)
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ %{id: user_id} = user = insert(:user)
+
+ assert {:ok, %Oban.Job{args: %{"backup_id" => backup_id} = args}} = Backup.create(user)
+ assert {:ok, backup} = perform_job(BackupWorker, args)
+ assert backup.file_size > 0
+ assert %Backup{id: ^backup_id, processed: true, user_id: ^user_id} = backup
+
+ assert_no_email_sent()
+ end
+
+ test "it does not send an email if the user has an empty email" do
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ %{id: user_id} = user = insert(:user, %{email: ""})
+
+ assert {:ok, %Oban.Job{args: %{"backup_id" => backup_id} = args}} = Backup.create(user)
+ assert {:ok, backup} = perform_job(BackupWorker, args)
+ assert backup.file_size > 0
+ assert %Backup{id: ^backup_id, processed: true, user_id: ^user_id} = backup
+
+ assert_no_email_sent()
+ end
+
test "it removes outdated backups after creating a fresh one" do
clear_config([Backup, :limit_days], -1)
clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
diff --git a/test/pleroma/user/import_test.exs b/test/pleroma/user/import_test.exs
index a84fce337..b4efd4bb0 100644
--- a/test/pleroma/user/import_test.exs
+++ b/test/pleroma/user/import_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.User.ImportTest do
diff --git a/test/pleroma/user/notification_setting_test.exs b/test/pleroma/user/notification_setting_test.exs
index 6cb8803d9..da3c810f0 100644
--- a/test/pleroma/user/notification_setting_test.exs
+++ b/test/pleroma/user/notification_setting_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.User.NotificationSettingTest do
diff --git a/test/pleroma/user/query_test.exs b/test/pleroma/user/query_test.exs
index 357016e3e..30a4637f2 100644
--- a/test/pleroma/user/query_test.exs
+++ b/test/pleroma/user/query_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.User.QueryTest do
- use Pleroma.DataCase, async: true
+ use Pleroma.DataCase, async: false
alias Pleroma.Repo
alias Pleroma.User
@@ -34,4 +34,73 @@ defmodule Pleroma.User.QueryTest do
assert %{internal: true} |> Query.build() |> Repo.aggregate(:count) == 2
end
end
+
+ test "is_suggested param" do
+ _user1 = insert(:user, is_suggested: false)
+ user2 = insert(:user, is_suggested: true)
+
+ assert [^user2] =
+ %{is_suggested: true}
+ |> User.Query.build()
+ |> Repo.all()
+ end
+
+ describe "is_privileged param" do
+ setup do
+ %{
+ user: insert(:user, local: true, is_admin: false, is_moderator: false),
+ moderator_user: insert(:user, local: true, is_admin: false, is_moderator: true),
+ admin_user: insert(:user, local: true, is_admin: true, is_moderator: false),
+ admin_moderator_user: insert(:user, local: true, is_admin: true, is_moderator: true),
+ remote_user: insert(:user, local: false, is_admin: true, is_moderator: true),
+ non_active_user:
+ insert(:user, local: true, is_admin: true, is_moderator: true, is_active: false)
+ }
+ end
+
+ test "doesn't return any users when there are no privileged roles" do
+ clear_config([:instance, :admin_privileges], [])
+ clear_config([:instance, :moderator_privileges], [])
+
+ assert [] = User.Query.build(%{is_privileged: :cofe}) |> Repo.all()
+ end
+
+ test "returns moderator users if they are privileged", %{
+ moderator_user: moderator_user,
+ admin_moderator_user: admin_moderator_user
+ } do
+ clear_config([:instance, :admin_privileges], [])
+ clear_config([:instance, :moderator_privileges], [:cofe])
+
+ assert [_, _] = User.Query.build(%{is_privileged: :cofe}) |> Repo.all()
+ assert moderator_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all())
+ assert admin_moderator_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all())
+ end
+
+ test "returns admin users if they are privileged", %{
+ admin_user: admin_user,
+ admin_moderator_user: admin_moderator_user
+ } do
+ clear_config([:instance, :admin_privileges], [:cofe])
+ clear_config([:instance, :moderator_privileges], [])
+
+ assert [_, _] = User.Query.build(%{is_privileged: :cofe}) |> Repo.all()
+ assert admin_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all())
+ assert admin_moderator_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all())
+ end
+
+ test "returns admin and moderator users if they are both privileged", %{
+ moderator_user: moderator_user,
+ admin_user: admin_user,
+ admin_moderator_user: admin_moderator_user
+ } do
+ clear_config([:instance, :admin_privileges], [:cofe])
+ clear_config([:instance, :moderator_privileges], [:cofe])
+
+ assert [_, _, _] = User.Query.build(%{is_privileged: :cofe}) |> Repo.all()
+ assert admin_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all())
+ assert moderator_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all())
+ assert admin_moderator_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all())
+ end
+ end
end
diff --git a/test/pleroma/user/welcome_chat_message_test.exs b/test/pleroma/user/welcome_chat_message_test.exs
index 42a45fa19..9f2cbdcc0 100644
--- a/test/pleroma/user/welcome_chat_message_test.exs
+++ b/test/pleroma/user/welcome_chat_message_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.User.WelcomeChatMessageTest do
diff --git a/test/pleroma/user/welcome_email_test.exs b/test/pleroma/user/welcome_email_test.exs
index c3d383a7f..a7b932c7e 100644
--- a/test/pleroma/user/welcome_email_test.exs
+++ b/test/pleroma/user/welcome_email_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.User.WelcomeEmailTest do
diff --git a/test/pleroma/user/welcome_message_test.exs b/test/pleroma/user/welcome_message_test.exs
index 28afde943..0d4fe1a8b 100644
--- a/test/pleroma/user/welcome_message_test.exs
+++ b/test/pleroma/user/welcome_message_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.User.WelcomeMessageTest do
diff --git a/test/pleroma/user_invite_token_test.exs b/test/pleroma/user_invite_token_test.exs
index 233d4e864..3a384b3c0 100644
--- a/test/pleroma/user_invite_token_test.exs
+++ b/test/pleroma/user_invite_token_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.UserInviteTokenTest do
diff --git a/test/pleroma/user_relationship_test.exs b/test/pleroma/user_relationship_test.exs
index b2b074607..7d205a746 100644
--- a/test/pleroma/user_relationship_test.exs
+++ b/test/pleroma/user_relationship_test.exs
@@ -1,12 +1,13 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.UserRelationshipTest do
alias Pleroma.UserRelationship
- use Pleroma.DataCase, async: true
+ use Pleroma.DataCase, async: false
+ import Mock
import Pleroma.Factory
describe "*_exists?/2" do
@@ -79,7 +80,12 @@ defmodule Pleroma.UserRelationshipTest do
end
test "if record already exists, returns it", %{users: [user1, user2]} do
- user_block = UserRelationship.create_block(user1, user2)
+ user_block =
+ with_mock NaiveDateTime, [:passthrough], utc_now: fn -> ~N[2017-03-17 17:09:58] end do
+ {:ok, %{inserted_at: ~N[2017-03-17 17:09:58]}} =
+ UserRelationship.create_block(user1, user2)
+ end
+
assert user_block == UserRelationship.create_block(user1, user2)
end
end
diff --git a/test/pleroma/user_search_test.exs b/test/pleroma/user_search_test.exs
index 69167bb0c..1deab6888 100644
--- a/test/pleroma/user_search_test.exs
+++ b/test/pleroma/user_search_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.UserSearchTest do
@@ -65,6 +65,14 @@ defmodule Pleroma.UserSearchTest do
assert found_user.id == user.id
end
+ test "excludes deactivated users from results" do
+ user = insert(:user, %{nickname: "john t1000"})
+ insert(:user, %{is_active: false, nickname: "john t800"})
+
+ [found_user] = User.search("john")
+ assert found_user.id == user.id
+ end
+
# Note: as in Mastodon, `is_discoverable` doesn't anyhow relate to user searchability
test "includes non-discoverable users in results" do
insert(:user, %{nickname: "john 3000", is_discoverable: false})
diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs
index a6421890b..c92850a78 100644
--- a/test/pleroma/user_test.exs
+++ b/test/pleroma/user_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.UserTest do
@@ -13,7 +13,7 @@ defmodule Pleroma.UserTest do
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.CommonAPI
- use Pleroma.DataCase
+ use Pleroma.DataCase, async: false
use Oban.Testing, repo: Pleroma.Repo
import Pleroma.Factory
@@ -311,7 +311,7 @@ defmodule Pleroma.UserTest do
describe "unfollow/2" do
setup do: clear_config([:instance, :external_user_synchronization])
- test "unfollow with syncronizes external user" do
+ test "unfollow with synchronizes external user" do
clear_config([:instance, :external_user_synchronization], true)
followed =
@@ -473,15 +473,10 @@ defmodule Pleroma.UserTest do
reject_deletes: []
)
- setup do:
- clear_config(:mrf,
- policies: [
- Pleroma.Web.ActivityPub.MRF.SimplePolicy
- ]
- )
+ setup do: clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
test "it sends a welcome chat message when Simple policy applied to local instance" do
- clear_config([:mrf_simple, :media_nsfw], ["localhost"])
+ clear_config([:mrf_simple, :media_nsfw], [{"localhost", ""}])
welcome_user = insert(:user)
clear_config([:welcome, :chat_message, :enabled], true)
@@ -591,6 +586,21 @@ defmodule Pleroma.UserTest do
refute_email_sent()
end
+ test "it works when the registering user does not provide an email" do
+ clear_config([Pleroma.Emails.Mailer, :enabled], false)
+ clear_config([:instance, :account_activation_required], false)
+ clear_config([:instance, :account_approval_required], true)
+
+ cng = User.register_changeset(%User{}, @full_user_data |> Map.put(:email, ""))
+
+ # The user is still created
+ assert {:ok, %User{nickname: "nick"}} = User.register(cng)
+
+ # No emails are sent
+ ObanHelpers.perform_all()
+ refute_email_sent()
+ end
+
test "it requires an email, name, nickname and password, bio is optional when account_activation_required is enabled" do
clear_config([:instance, :account_activation_required], true)
@@ -618,9 +628,10 @@ defmodule Pleroma.UserTest do
end
test "it restricts certain nicknames" do
+ clear_config([User, :restricted_nicknames], ["about"])
[restricted_name | _] = Pleroma.Config.get([User, :restricted_nicknames])
- assert is_bitstring(restricted_name)
+ assert is_binary(restricted_name)
params =
@full_user_data
@@ -631,6 +642,23 @@ defmodule Pleroma.UserTest do
refute changeset.valid?
end
+ test "it is case-insensitive when restricting nicknames" do
+ clear_config([User, :restricted_nicknames], ["about"])
+ [restricted_name | _] = Pleroma.Config.get([User, :restricted_nicknames])
+
+ assert is_binary(restricted_name)
+
+ restricted_upcase_name = String.upcase(restricted_name)
+
+ params =
+ @full_user_data
+ |> Map.put(:nickname, restricted_upcase_name)
+
+ changeset = User.register_changeset(%User{}, params)
+
+ refute changeset.valid?
+ end
+
test "it blocks blacklisted email domains" do
clear_config([User, :email_blacklist], ["trolling.world"])
@@ -639,6 +667,11 @@ defmodule Pleroma.UserTest do
changeset = User.register_changeset(%User{}, params)
refute changeset.valid?
+ # Block with case-insensitive match
+ params = Map.put(@full_user_data, :email, "troll@TrOlLing.wOrld")
+ changeset = User.register_changeset(%User{}, params)
+ refute changeset.valid?
+
# Block with subdomain match
params = Map.put(@full_user_data, :email, "troll@gnomes.trolling.world")
changeset = User.register_changeset(%User{}, params)
@@ -654,14 +687,14 @@ defmodule Pleroma.UserTest do
assert changeset.valid?
end
- test "it sets the password_hash and ap_id" do
+ test "it sets the password_hash, ap_id, private key and followers collection address" do
changeset = User.register_changeset(%User{}, @full_user_data)
assert changeset.valid?
assert is_binary(changeset.changes[:password_hash])
+ assert is_binary(changeset.changes[:keys])
assert changeset.changes[:ap_id] == User.ap_id(%User{nickname: @full_user_data.nickname})
-
assert changeset.changes.follower_address == "#{changeset.changes.ap_id}/followers"
end
@@ -756,6 +789,54 @@ defmodule Pleroma.UserTest do
end
end
+ describe "user registration, with :birthday_required and :birthday_min_age" do
+ @full_user_data %{
+ bio: "A guy",
+ name: "my name",
+ nickname: "nick",
+ password: "test",
+ password_confirmation: "test",
+ email: "email@example.com"
+ }
+
+ setup do
+ clear_config([:instance, :birthday_required], true)
+ clear_config([:instance, :birthday_min_age], 18 * 365)
+ end
+
+ test "it passes when correct birth date is provided" do
+ today = Date.utc_today()
+ birthday = Date.add(today, -19 * 365)
+
+ params =
+ @full_user_data
+ |> Map.put(:birthday, birthday)
+
+ changeset = User.register_changeset(%User{}, params)
+
+ assert changeset.valid?
+ end
+
+ test "it fails when birth date is not provided" do
+ changeset = User.register_changeset(%User{}, @full_user_data)
+
+ refute changeset.valid?
+ end
+
+ test "it fails when provided invalid birth date" do
+ today = Date.utc_today()
+ birthday = Date.add(today, -17 * 365)
+
+ params =
+ @full_user_data
+ |> Map.put(:birthday, birthday)
+
+ changeset = User.register_changeset(%User{}, params)
+
+ refute changeset.valid?
+ end
+ end
+
describe "get_or_fetch/1" do
test "gets an existing user by nickname" do
user = insert(:user)
@@ -779,6 +860,123 @@ defmodule Pleroma.UserTest do
freshed_user = refresh_record(user)
assert freshed_user == fetched_user
end
+
+ test "gets an existing user by nickname starting with http" do
+ user = insert(:user, nickname: "httpssome")
+ {:ok, fetched_user} = User.get_or_fetch("httpssome")
+
+ assert user == fetched_user
+ end
+ end
+
+ describe "get_or_fetch/1 remote users with tld, while BE is runned on subdomain" do
+ setup do: clear_config([Pleroma.Web.WebFinger, :update_nickname_on_user_fetch], true)
+
+ test "for mastodon" do
+ Tesla.Mock.mock(fn
+ %{url: "https://example.com/.well-known/host-meta"} ->
+ %Tesla.Env{
+ status: 302,
+ headers: [{"location", "https://sub.example.com/.well-known/host-meta"}]
+ }
+
+ %{url: "https://sub.example.com/.well-known/host-meta"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/masto-host-meta.xml"
+ |> File.read!()
+ |> String.replace("{{domain}}", "sub.example.com")
+ }
+
+ %{url: "https://sub.example.com/.well-known/webfinger?resource=acct:a@example.com"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/masto-webfinger.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", "a")
+ |> String.replace("{{domain}}", "example.com")
+ |> String.replace("{{subdomain}}", "sub.example.com"),
+ headers: [{"content-type", "application/jrd+json"}]
+ }
+
+ %{url: "https://sub.example.com/users/a"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/masto-user.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", "a")
+ |> String.replace("{{domain}}", "sub.example.com"),
+ headers: [{"content-type", "application/activity+json"}]
+ }
+
+ %{url: "https://sub.example.com/users/a/collections/featured"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ File.read!("test/fixtures/users_mock/masto_featured.json")
+ |> String.replace("{{domain}}", "sub.example.com")
+ |> String.replace("{{nickname}}", "a"),
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ ap_id = "a@example.com"
+ {:ok, fetched_user} = User.get_or_fetch(ap_id)
+
+ assert fetched_user.ap_id == "https://sub.example.com/users/a"
+ assert fetched_user.nickname == "a@example.com"
+ end
+
+ test "for pleroma" do
+ Tesla.Mock.mock(fn
+ %{url: "https://example.com/.well-known/host-meta"} ->
+ %Tesla.Env{
+ status: 302,
+ headers: [{"location", "https://sub.example.com/.well-known/host-meta"}]
+ }
+
+ %{url: "https://sub.example.com/.well-known/host-meta"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/pleroma-host-meta.xml"
+ |> File.read!()
+ |> String.replace("{{domain}}", "sub.example.com")
+ }
+
+ %{url: "https://sub.example.com/.well-known/webfinger?resource=acct:a@example.com"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/pleroma-webfinger.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", "a")
+ |> String.replace("{{domain}}", "example.com")
+ |> String.replace("{{subdomain}}", "sub.example.com"),
+ headers: [{"content-type", "application/jrd+json"}]
+ }
+
+ %{url: "https://sub.example.com/users/a"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/webfinger/pleroma-user.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", "a")
+ |> String.replace("{{domain}}", "sub.example.com"),
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ ap_id = "a@example.com"
+ {:ok, fetched_user} = User.get_or_fetch(ap_id)
+
+ assert fetched_user.ap_id == "https://sub.example.com/users/a"
+ assert fetched_user.nickname == "a@example.com"
+ end
end
describe "fetching a user from nickname or trying to build one" do
@@ -1075,7 +1273,7 @@ defmodule Pleroma.UserTest do
user = insert(:user)
muted_user = insert(:user)
- {:ok, _user_relationships} = User.mute(user, muted_user, %{expires_in: 60})
+ {:ok, _user_relationships} = User.mute(user, muted_user, %{duration: 60})
assert User.mutes?(user, muted_user)
worker = Pleroma.Workers.MuteExpireWorker
@@ -1650,7 +1848,6 @@ defmodule Pleroma.UserTest do
ap_enabled: true,
is_moderator: true,
is_admin: true,
- mastofe_settings: %{"a" => "b"},
mascot: %{"a" => "b"},
emoji: %{"a" => "b"},
pleroma_settings_store: %{"q" => "x"},
@@ -1692,7 +1889,6 @@ defmodule Pleroma.UserTest do
ap_enabled: false,
is_moderator: false,
is_admin: false,
- mastofe_settings: nil,
mascot: nil,
emoji: %{},
pleroma_settings_store: %{},
@@ -1721,6 +1917,38 @@ defmodule Pleroma.UserTest do
assert user.banner == %{}
end
+ describe "set_suggestion" do
+ test "suggests a user" do
+ user = insert(:user, is_suggested: false)
+ refute user.is_suggested
+ {:ok, user} = User.set_suggestion(user, true)
+ assert user.is_suggested
+ end
+
+ test "suggests a list of users" do
+ unsuggested_users = [
+ insert(:user, is_suggested: false),
+ insert(:user, is_suggested: false),
+ insert(:user, is_suggested: false)
+ ]
+
+ {:ok, users} = User.set_suggestion(unsuggested_users, true)
+
+ assert Enum.count(users) == 3
+
+ Enum.each(users, fn user ->
+ assert user.is_suggested
+ end)
+ end
+
+ test "unsuggests a user" do
+ user = insert(:user, is_suggested: true)
+ assert user.is_suggested
+ {:ok, user} = User.set_suggestion(user, false)
+ refute user.is_suggested
+ end
+ end
+
test "get_public_key_for_ap_id fetches a user that's not in the db" do
assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
end
@@ -1805,31 +2033,82 @@ defmodule Pleroma.UserTest do
end
end
- describe "superuser?/1" do
+ describe "privileged?/1" do
+ setup do
+ clear_config([:instance, :admin_privileges], [:cofe, :suya])
+ clear_config([:instance, :moderator_privileges], [:cofe, :suya])
+ end
+
test "returns false for unprivileged users" do
user = insert(:user, local: true)
- refute User.superuser?(user)
+ refute User.privileged?(user, :cofe)
end
test "returns false for remote users" do
user = insert(:user, local: false)
remote_admin_user = insert(:user, local: false, is_admin: true)
- refute User.superuser?(user)
- refute User.superuser?(remote_admin_user)
+ refute User.privileged?(user, :cofe)
+ refute User.privileged?(remote_admin_user, :cofe)
end
- test "returns true for local moderators" do
+ test "returns true for local moderators if, and only if, they are privileged" do
user = insert(:user, local: true, is_moderator: true)
- assert User.superuser?(user)
+ assert User.privileged?(user, :cofe)
+
+ clear_config([:instance, :moderator_privileges], [])
+
+ refute User.privileged?(user, :cofe)
end
- test "returns true for local admins" do
+ test "returns true for local admins if, and only if, they are privileged" do
user = insert(:user, local: true, is_admin: true)
- assert User.superuser?(user)
+ assert User.privileged?(user, :cofe)
+
+ clear_config([:instance, :admin_privileges], [])
+
+ refute User.privileged?(user, :cofe)
+ end
+ end
+
+ describe "privileges/1" do
+ setup do
+ clear_config([:instance, :moderator_privileges], [:cofe, :only_moderator])
+ clear_config([:instance, :admin_privileges], [:cofe, :only_admin])
+ end
+
+ test "returns empty list for users without roles" do
+ user = insert(:user, local: true)
+
+ assert [] == User.privileges(user)
+ end
+
+ test "returns list of privileges for moderators" do
+ moderator = insert(:user, is_moderator: true, local: true)
+
+ assert [:cofe, :only_moderator] == User.privileges(moderator) |> Enum.sort()
+ end
+
+ test "returns list of privileges for admins" do
+ admin = insert(:user, is_admin: true, local: true)
+
+ assert [:cofe, :only_admin] == User.privileges(admin) |> Enum.sort()
+ end
+
+ test "returns list of unique privileges for users who are both moderator and admin" do
+ moderator_admin = insert(:user, is_moderator: true, is_admin: true, local: true)
+
+ assert [:cofe, :only_admin, :only_moderator] ==
+ User.privileges(moderator_admin) |> Enum.sort()
+ end
+
+ test "returns empty list for remote users" do
+ remote_moderator_admin = insert(:user, is_moderator: true, is_admin: true, local: false)
+
+ assert [] == User.privileges(remote_moderator_admin)
end
end
@@ -1872,13 +2151,77 @@ defmodule Pleroma.UserTest do
assert User.visible_for(user, other_user) == :visible
end
- test "returns true when the account is unconfirmed and being viewed by a privileged account (confirmation required)" do
+ test "returns true when the account is unconfirmed and being viewed by a privileged account (privilege :users_manage_activation_state, confirmation required)" do
clear_config([:instance, :account_activation_required], true)
+ clear_config([:instance, :admin_privileges], [:users_manage_activation_state])
user = insert(:user, local: true, is_confirmed: false)
other_user = insert(:user, local: true, is_admin: true)
assert User.visible_for(user, other_user) == :visible
+
+ clear_config([:instance, :admin_privileges], [])
+
+ refute User.visible_for(user, other_user) == :visible
+ end
+ end
+
+ describe "all_users_with_privilege/1" do
+ setup do
+ %{
+ user: insert(:user, local: true, is_admin: false, is_moderator: false),
+ moderator_user: insert(:user, local: true, is_admin: false, is_moderator: true),
+ admin_user: insert(:user, local: true, is_admin: true, is_moderator: false),
+ admin_moderator_user: insert(:user, local: true, is_admin: true, is_moderator: true),
+ remote_user: insert(:user, local: false, is_admin: true, is_moderator: true),
+ non_active_user:
+ insert(:user, local: true, is_admin: true, is_moderator: true, is_active: false)
+ }
+ end
+
+ test "doesn't return any users when there are no privileged roles" do
+ clear_config([:instance, :admin_privileges], [])
+ clear_config([:instance, :moderator_privileges], [])
+
+ assert [] = User.Query.build(%{is_privileged: :cofe}) |> Repo.all()
+ end
+
+ test "returns moderator users if they are privileged", %{
+ moderator_user: moderator_user,
+ admin_moderator_user: admin_moderator_user
+ } do
+ clear_config([:instance, :admin_privileges], [])
+ clear_config([:instance, :moderator_privileges], [:cofe])
+
+ assert [_, _] = User.Query.build(%{is_privileged: :cofe}) |> Repo.all()
+ assert moderator_user in User.all_users_with_privilege(:cofe)
+ assert admin_moderator_user in User.all_users_with_privilege(:cofe)
+ end
+
+ test "returns admin users if they are privileged", %{
+ admin_user: admin_user,
+ admin_moderator_user: admin_moderator_user
+ } do
+ clear_config([:instance, :admin_privileges], [:cofe])
+ clear_config([:instance, :moderator_privileges], [])
+
+ assert [_, _] = User.Query.build(%{is_privileged: :cofe}) |> Repo.all()
+ assert admin_user in User.all_users_with_privilege(:cofe)
+ assert admin_moderator_user in User.all_users_with_privilege(:cofe)
+ end
+
+ test "returns admin and moderator users if they are both privileged", %{
+ moderator_user: moderator_user,
+ admin_user: admin_user,
+ admin_moderator_user: admin_moderator_user
+ } do
+ clear_config([:instance, :admin_privileges], [:cofe])
+ clear_config([:instance, :moderator_privileges], [:cofe])
+
+ assert [_, _, _] = User.Query.build(%{is_privileged: :cofe}) |> Repo.all()
+ assert admin_user in User.all_users_with_privilege(:cofe)
+ assert moderator_user in User.all_users_with_privilege(:cofe)
+ assert admin_moderator_user in User.all_users_with_privilege(:cofe)
end
end
@@ -1889,9 +2232,7 @@ defmodule Pleroma.UserTest do
bio = "A.k.a. @nick@domain.com"
expected_text =
- ~s(A.k.a. <span class="h-card"><a class="u-url mention" data-user="#{remote_user.id}" href="#{
- remote_user.ap_id
- }" rel="ugc">@<span>nick@domain.com</span></a></span>)
+ ~s(A.k.a. <span class="h-card"><a class="u-url mention" data-user="#{remote_user.id}" href="#{remote_user.ap_id}" rel="ugc">@<span>nick@domain.com</span></a></span>)
assert expected_text == User.parse_bio(bio, user)
end
@@ -2032,21 +2373,6 @@ defmodule Pleroma.UserTest do
end
end
- describe "ensure_keys_present" do
- test "it creates keys for a user and stores them in info" do
- user = insert(:user)
- refute is_binary(user.keys)
- {:ok, user} = User.ensure_keys_present(user)
- assert is_binary(user.keys)
- end
-
- test "it doesn't create keys if there already are some" do
- user = insert(:user, keys: "xxx")
- {:ok, user} = User.ensure_keys_present(user)
- assert user.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)
@@ -2057,6 +2383,17 @@ defmodule Pleroma.UserTest do
assert user.ap_id in ap_ids
assert user_two.ap_id in ap_ids
end
+
+ test "it returns a list of AP ids in the same order" do
+ user = insert(:user)
+ user_two = insert(:user)
+ user_three = insert(:user)
+
+ ap_ids =
+ User.get_ap_ids_by_nicknames([user.nickname, user_three.nickname, user_two.nickname])
+
+ assert [user.ap_id, user_three.ap_id, user_two.ap_id] == ap_ids
+ end
end
describe "sync followers count" do
@@ -2170,7 +2507,7 @@ defmodule Pleroma.UserTest do
assert other_user.follower_count == 1
end
- test "syncronizes the counters with the remote instance for the followed when enabled" do
+ test "synchronizes the counters with the remote instance for the followed when enabled" do
clear_config([:instance, :external_user_synchronization], false)
user = insert(:user)
@@ -2192,7 +2529,7 @@ defmodule Pleroma.UserTest do
assert other_user.follower_count == 437
end
- test "syncronizes the counters with the remote instance for the follower when enabled" do
+ test "synchronizes the counters with the remote instance for the follower when enabled" do
clear_config([:instance, :external_user_synchronization], false)
user = insert(:user)
@@ -2220,11 +2557,40 @@ defmodule Pleroma.UserTest do
[user: insert(:user)]
end
- test "blank email returns error", %{user: user} do
+ test "blank email returns error if we require an email on registration", %{user: user} do
+ orig_account_activation_required =
+ Pleroma.Config.get([:instance, :account_activation_required])
+
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+
+ on_exit(fn ->
+ Pleroma.Config.put(
+ [:instance, :account_activation_required],
+ orig_account_activation_required
+ )
+ end)
+
assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, "")
assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, nil)
end
+ test "blank email should be fine if we do not require an email on registration", %{user: user} do
+ orig_account_activation_required =
+ Pleroma.Config.get([:instance, :account_activation_required])
+
+ Pleroma.Config.put([:instance, :account_activation_required], false)
+
+ on_exit(fn ->
+ Pleroma.Config.put(
+ [:instance, :account_activation_required],
+ orig_account_activation_required
+ )
+ end)
+
+ assert {:ok, %User{email: nil}} = User.change_email(user, "")
+ assert {:ok, %User{email: nil}} = User.change_email(user, nil)
+ end
+
test "non unique email returns error", %{user: user} do
%{email: email} = insert(:user)
@@ -2240,6 +2606,25 @@ defmodule Pleroma.UserTest do
test "changes email", %{user: user} do
assert {:ok, %User{email: "cofe@cofe.party"}} = User.change_email(user, "cofe@cofe.party")
end
+
+ test "adds email", %{user: user} do
+ orig_account_activation_required =
+ Pleroma.Config.get([:instance, :account_activation_required])
+
+ Pleroma.Config.put([:instance, :account_activation_required], false)
+
+ on_exit(fn ->
+ Pleroma.Config.put(
+ [:instance, :account_activation_required],
+ orig_account_activation_required
+ )
+ end)
+
+ assert {:ok, _} = User.change_email(user, "")
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+
+ assert {:ok, %User{email: "cofe2@cofe.party"}} = User.change_email(user, "cofe2@cofe.party")
+ end
end
describe "get_cached_by_nickname_or_id" do
@@ -2387,13 +2772,16 @@ defmodule Pleroma.UserTest do
test "active_user_count/1" do
insert(:user)
insert(:user, %{local: false})
- insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), weeks: -5)})
- insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), weeks: -3)})
insert(:user, %{last_active_at: NaiveDateTime.utc_now()})
+ insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), days: -15)})
+ insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), weeks: -6)})
+ insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), months: -7)})
+ insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), years: -2)})
assert User.active_user_count() == 2
- assert User.active_user_count(6) == 3
- assert User.active_user_count(1) == 1
+ assert User.active_user_count(180) == 3
+ assert User.active_user_count(365) == 4
+ assert User.active_user_count(1000) == 5
end
describe "pins" do
@@ -2440,4 +2828,115 @@ defmodule Pleroma.UserTest do
%{object: %{data: %{"id" => object_id}}} = Activity.get_by_id_with_object(id)
object_id
end
+
+ describe "add_alias/2" do
+ test "should add alias for another user" do
+ user = insert(:user)
+ user2 = insert(:user)
+
+ assert {:ok, user_updated} = user |> User.add_alias(user2)
+
+ assert user_updated.also_known_as |> length() == 1
+ assert user2.ap_id in user_updated.also_known_as
+ end
+
+ test "should add multiple aliases" do
+ user = insert(:user)
+ user2 = insert(:user)
+ user3 = insert(:user)
+
+ assert {:ok, user} = user |> User.add_alias(user2)
+ assert {:ok, user_updated} = user |> User.add_alias(user3)
+
+ assert user_updated.also_known_as |> length() == 2
+ assert user2.ap_id in user_updated.also_known_as
+ assert user3.ap_id in user_updated.also_known_as
+ end
+
+ test "should not add duplicate aliases" do
+ user = insert(:user)
+ user2 = insert(:user)
+
+ assert {:ok, user} = user |> User.add_alias(user2)
+
+ assert {:ok, user_updated} = user |> User.add_alias(user2)
+
+ assert user_updated.also_known_as |> length() == 1
+ assert user2.ap_id in user_updated.also_known_as
+ end
+ end
+
+ describe "alias_users/1" do
+ test "should get aliases for a user" do
+ user = insert(:user)
+ user2 = insert(:user, also_known_as: [user.ap_id])
+
+ aliases = user2 |> User.alias_users()
+
+ assert aliases |> length() == 1
+
+ alias_user = aliases |> Enum.at(0)
+
+ assert alias_user.ap_id == user.ap_id
+ end
+ end
+
+ describe "delete_alias/2" do
+ test "should delete existing alias" do
+ user = insert(:user)
+ user2 = insert(:user, also_known_as: [user.ap_id])
+
+ assert {:ok, user_updated} = user2 |> User.delete_alias(user)
+
+ assert user_updated.also_known_as == []
+ end
+
+ test "should report error on non-existing alias" do
+ user = insert(:user)
+ user2 = insert(:user)
+ user3 = insert(:user, also_known_as: [user.ap_id])
+
+ assert {:error, :no_such_alias} = user3 |> User.delete_alias(user2)
+
+ user3_updated = User.get_cached_by_ap_id(user3.ap_id)
+
+ assert user3_updated.also_known_as |> length() == 1
+ assert user.ap_id in user3_updated.also_known_as
+ end
+ end
+
+ describe "account endorsements" do
+ test "it pins people" do
+ user = insert(:user)
+ pinned_user = insert(:user)
+
+ {:ok, _pinned_user, _user} = User.follow(user, pinned_user)
+
+ refute User.endorses?(user, pinned_user)
+
+ {:ok, _user_relationship} = User.endorse(user, pinned_user)
+
+ assert User.endorses?(user, pinned_user)
+ end
+
+ test "it unpins users" do
+ user = insert(:user)
+ pinned_user = insert(:user)
+
+ {:ok, _pinned_user, _user} = User.follow(user, pinned_user)
+ {:ok, _user_relationship} = User.endorse(user, pinned_user)
+ {:ok, _user_pin} = User.unendorse(user, pinned_user)
+
+ refute User.endorses?(user, pinned_user)
+ end
+
+ test "it doesn't pin users you do not follow" do
+ user = insert(:user)
+ pinned_user = insert(:user)
+
+ assert {:error, _message} = User.endorse(user, pinned_user)
+
+ refute User.endorses?(user, pinned_user)
+ end
+ end
end
diff --git a/test/pleroma/utils_test.exs b/test/pleroma/utils_test.exs
index c593a9490..cd225e82c 100644
--- a/test/pleroma/utils_test.exs
+++ b/test/pleroma/utils_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.UtilsTest do
diff --git a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs
index 511405624..ef91066c1 100644
--- a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
@@ -247,6 +247,27 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(response, 200) == ObjectView.render("object.json", %{object: object})
end
+ test "does not return local-only objects for remote users", %{conn: conn} do
+ user = insert(:user)
+ reader = insert(:user, local: false)
+
+ {:ok, post} =
+ CommonAPI.post(user, %{status: "test @#{reader.nickname}", visibility: "local"})
+
+ assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
+
+ object = Object.normalize(post, fetch: false)
+ uuid = String.split(object.data["id"], "/") |> List.last()
+
+ assert response =
+ conn
+ |> assign(:user, reader)
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/objects/#{uuid}")
+
+ json_response(response, 404)
+ end
+
test "it returns a json representation of the object with accept application/json", %{
conn: conn
} do
@@ -1297,6 +1318,35 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert outbox_endpoint == result["id"]
end
+ test "it returns a local note activity when authenticated as local user", %{conn: conn} do
+ user = insert(:user)
+ reader = insert(:user)
+ {:ok, note_activity} = CommonAPI.post(user, %{status: "mew mew", visibility: "local"})
+ ap_id = note_activity.data["id"]
+
+ resp =
+ conn
+ |> assign(:user, reader)
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/users/#{user.nickname}/outbox?page=true")
+ |> json_response(200)
+
+ assert %{"orderedItems" => [%{"id" => ^ap_id}]} = resp
+ end
+
+ test "it does not return a local note activity when unauthenticated", %{conn: conn} do
+ user = insert(:user)
+ {:ok, _note_activity} = CommonAPI.post(user, %{status: "mew mew", visibility: "local"})
+
+ resp =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/users/#{user.nickname}/outbox?page=true")
+ |> json_response(200)
+
+ assert %{"orderedItems" => []} = resp
+ end
+
test "it returns a note activity in a collection", %{conn: conn} do
note_activity = insert(:note_activity)
note_object = Object.normalize(note_activity, fetch: false)
diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs
index 64e12066e..fc6fc039d 100644
--- a/test/pleroma/web/activity_pub/activity_pub_test.exs
+++ b/test/pleroma/web/activity_pub/activity_pub_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
@@ -312,6 +312,103 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert %{data: %{"id" => ^object_url}} = Object.get_by_ap_id(object_url)
end
+
+ test "fetches user featured collection without embedded object" do
+ ap_id = "https://example.com/users/lain"
+
+ featured_url = "https://example.com/users/lain/collections/featured"
+
+ user_data =
+ "test/fixtures/users_mock/user.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", "lain")
+ |> Jason.decode!()
+ |> Map.put("featured", featured_url)
+ |> Jason.encode!()
+
+ object_id = Ecto.UUID.generate()
+
+ featured_data =
+ "test/fixtures/mastodon/collections/external_featured.json"
+ |> File.read!()
+ |> String.replace("{{domain}}", "example.com")
+ |> String.replace("{{nickname}}", "lain")
+ |> String.replace("{{object_id}}", object_id)
+
+ object_url = "https://example.com/objects/#{object_id}"
+
+ object_data =
+ "test/fixtures/statuses/note.json"
+ |> File.read!()
+ |> String.replace("{{object_id}}", object_id)
+ |> String.replace("{{nickname}}", "lain")
+
+ Tesla.Mock.mock(fn
+ %{
+ method: :get,
+ url: ^ap_id
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: user_data,
+ headers: [{"content-type", "application/activity+json"}]
+ }
+
+ %{
+ method: :get,
+ url: ^featured_url
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: featured_data,
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ Tesla.Mock.mock_global(fn
+ %{
+ method: :get,
+ url: ^object_url
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: object_data,
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ {:ok, user} = ActivityPub.make_user_from_ap_id(ap_id)
+ Process.sleep(50)
+
+ assert user.featured_address == featured_url
+ assert Map.has_key?(user.pinned_objects, object_url)
+
+ in_db = Pleroma.User.get_by_ap_id(ap_id)
+ assert in_db.featured_address == featured_url
+ assert Map.has_key?(user.pinned_objects, object_url)
+
+ assert %{data: %{"id" => ^object_url}} = Object.get_by_ap_id(object_url)
+ end
+
+ test "fetches user birthday information from misskey" do
+ user_id = "https://misskey.io/@mkljczk"
+
+ Tesla.Mock.mock(fn
+ %{
+ method: :get,
+ url: ^user_id
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/birthdays/misskey-user.json"),
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ {:ok, user} = ActivityPub.make_user_from_ap_id(user_id)
+
+ assert user.birthday == ~D[2001-02-12]
+ end
end
test "it fetches the appropriate tag-restricted posts" do
@@ -457,7 +554,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert activity.data["ok"] == data["ok"]
assert activity.data["id"] == given_id
assert activity.data["context"] == "blabla"
- assert activity.data["context_id"]
end
test "adds a context when none is there" do
@@ -479,8 +575,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert is_binary(activity.data["context"])
assert is_binary(object.data["context"])
- assert activity.data["context_id"]
- assert object.data["context_id"]
end
test "adds an id to a given object if it lacks one and is a note and inserts it to the object database" do
@@ -776,6 +870,32 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert Enum.member?(activities, activity_one)
end
+ test "doesn't return activities from deactivated users" do
+ _user = insert(:user)
+ deactivated = insert(:user)
+ active = insert(:user)
+ {:ok, activity_one} = CommonAPI.post(deactivated, %{status: "hey!"})
+ {:ok, activity_two} = CommonAPI.post(active, %{status: "yay!"})
+ {:ok, _updated_user} = User.set_activation(deactivated, false)
+
+ activities = ActivityPub.fetch_activities([], %{})
+
+ refute Enum.member?(activities, activity_one)
+ assert Enum.member?(activities, activity_two)
+ end
+
+ test "always see your own posts even when they address people you block" do
+ user = insert(:user)
+ blockee = insert(:user)
+
+ {:ok, _} = User.block(user, blockee)
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey! @#{blockee.nickname}"})
+
+ activities = ActivityPub.fetch_activities([], %{blocking_user: user})
+
+ assert Enum.member?(activities, activity)
+ end
+
test "doesn't return transitive interactions concerning blocked users" do
blocker = insert(:user)
blockee = insert(:user)
@@ -875,6 +995,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
refute repeat_activity in activities
end
+ test "see your own posts even when they adress actors from blocked domains" do
+ user = insert(:user)
+
+ domain = "dogwhistle.zone"
+ domain_user = insert(:user, %{ap_id: "https://#{domain}/@pundit"})
+
+ {:ok, user} = User.block_domain(user, domain)
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey! @#{domain_user.nickname}"})
+
+ activities = ActivityPub.fetch_activities([], %{blocking_user: user})
+
+ assert Enum.member?(activities, activity)
+ end
+
test "does return activities from followed users on blocked domains" do
domain = "meanies.social"
domain_user = insert(:user, %{ap_id: "https://#{domain}/@pundit"})
@@ -1369,6 +1504,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
reporter_ap_id = reporter.ap_id
target_ap_id = target_account.ap_id
activity_ap_id = activity.data["id"]
+ object_ap_id = activity.object.data["id"]
activity_with_object = Activity.get_by_ap_id_with_object(activity_ap_id)
@@ -1380,6 +1516,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
reported_activity: activity,
content: content,
activity_ap_id: activity_ap_id,
+ object_ap_id: object_ap_id,
activity_with_object: activity_with_object,
reporter_ap_id: reporter_ap_id,
target_ap_id: target_ap_id
@@ -1393,7 +1530,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
target_account: target_account,
reported_activity: reported_activity,
content: content,
- activity_ap_id: activity_ap_id,
+ object_ap_id: object_ap_id,
activity_with_object: activity_with_object,
reporter_ap_id: reporter_ap_id,
target_ap_id: target_ap_id
@@ -1409,7 +1546,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
note_obj = %{
"type" => "Note",
- "id" => activity_ap_id,
+ "id" => object_ap_id,
"content" => content,
"published" => activity_with_object.object.data["published"],
"actor" =>
@@ -1433,6 +1570,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
context: context,
target_account: target_account,
reported_activity: reported_activity,
+ object_ap_id: object_ap_id,
content: content
},
Utils,
@@ -1447,8 +1585,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
content: content
})
- new_data =
- put_in(activity.data, ["object"], [target_account.ap_id, reported_activity.data["id"]])
+ new_data = put_in(activity.data, ["object"], [target_account.ap_id, object_ap_id])
assert_called(Utils.maybe_federate(%{activity | data: new_data}))
end
@@ -1474,7 +1611,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
})
assert Repo.aggregate(Activity, :count, :id) == 1
- assert Repo.aggregate(Object, :count, :id) == 2
+ assert Repo.aggregate(Object, :count, :id) == 1
assert Repo.aggregate(Notification, :count, :id) == 0
end
end
@@ -1527,7 +1664,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end
describe "fetch_follow_information_for_user" do
- test "syncronizes following/followers counters" do
+ test "synchronizes following/followers counters" do
user =
insert(:user,
local: false,
@@ -1698,9 +1835,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
"target" => ^new_ap_id,
"type" => "Move"
},
- local: true
+ local: true,
+ recipients: recipients
} = activity
+ assert old_user.follower_address in recipients
+
params = %{
"op" => "move_following",
"origin_id" => old_user.id,
@@ -1731,6 +1871,42 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert {:error, "Target account must have the origin in `alsoKnownAs`"} =
ActivityPub.move(old_user, new_user)
end
+
+ test "do not move remote user following relationships" do
+ %{ap_id: old_ap_id} = old_user = insert(:user)
+ %{ap_id: new_ap_id} = new_user = insert(:user, also_known_as: [old_ap_id])
+ follower_remote = insert(:user, local: false)
+
+ User.follow(follower_remote, old_user)
+
+ assert User.following?(follower_remote, old_user)
+
+ assert {:ok, activity} = ActivityPub.move(old_user, new_user)
+
+ assert %Activity{
+ actor: ^old_ap_id,
+ data: %{
+ "actor" => ^old_ap_id,
+ "object" => ^old_ap_id,
+ "target" => ^new_ap_id,
+ "type" => "Move"
+ },
+ local: true
+ } = activity
+
+ params = %{
+ "op" => "move_following",
+ "origin_id" => old_user.id,
+ "target_id" => new_user.id
+ }
+
+ assert_enqueued(worker: Pleroma.Workers.BackgroundWorker, args: params)
+
+ Pleroma.Workers.BackgroundWorker.perform(%Oban.Job{args: params})
+
+ assert User.following?(follower_remote, old_user)
+ refute User.following?(follower_remote, new_user)
+ end
end
test "doesn't retrieve replies activities with exclude_replies" do
diff --git a/test/pleroma/web/activity_pub/builder_test.exs b/test/pleroma/web/activity_pub/builder_test.exs
new file mode 100644
index 000000000..eb175a1be
--- /dev/null
+++ b/test/pleroma/web/activity_pub/builder_test.exs
@@ -0,0 +1,48 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.BuilderTest do
+ alias Pleroma.Web.ActivityPub.Builder
+ alias Pleroma.Web.CommonAPI.ActivityDraft
+ use Pleroma.DataCase
+
+ import Pleroma.Factory
+
+ describe "note/1" do
+ test "returns note data" do
+ user = insert(:user)
+ note = insert(:note)
+ user2 = insert(:user)
+ user3 = insert(:user)
+
+ draft = %ActivityDraft{
+ user: user,
+ to: [user2.ap_id],
+ context: "2hu",
+ content_html: "<h1>This is :moominmamma: note</h1>",
+ in_reply_to: note.id,
+ tags: [name: "jimm"],
+ summary: "test summary",
+ cc: [user3.ap_id],
+ extra: %{"custom_tag" => "test"}
+ }
+
+ expected = %{
+ "actor" => user.ap_id,
+ "attachment" => [],
+ "cc" => [user3.ap_id],
+ "content" => "<h1>This is :moominmamma: note</h1>",
+ "context" => "2hu",
+ "sensitive" => false,
+ "summary" => "test summary",
+ "tag" => ["jimm"],
+ "to" => [user2.ap_id],
+ "type" => "Note",
+ "custom_tag" => "test"
+ }
+
+ assert {:ok, ^expected, []} = Builder.note(draft)
+ end
+ end
+end
diff --git a/test/pleroma/web/activity_pub/mrf/activity_expiration_policy_test.exs b/test/pleroma/web/activity_pub/mrf/activity_expiration_policy_test.exs
index 47b07fdd9..817eba3f5 100644
--- a/test/pleroma/web/activity_pub/mrf/activity_expiration_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/activity_expiration_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicyTest do
diff --git a/test/pleroma/web/activity_pub/mrf/anti_followbot_policy_test.exs b/test/pleroma/web/activity_pub/mrf/anti_followbot_policy_test.exs
index d5af3a9b6..732a5a7f3 100644
--- a/test/pleroma/web/activity_pub/mrf/anti_followbot_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/anti_followbot_policy_test.exs
@@ -1,11 +1,12 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicyTest do
use Pleroma.DataCase, async: true
import Pleroma.Factory
+ alias Pleroma.User
alias Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy
describe "blocking based on attributes" do
@@ -38,21 +39,55 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicyTest do
assert {:reject, "[AntiFollowbotPolicy]" <> _} = AntiFollowbotPolicy.filter(message)
end
+
+ test "matches followbots by actor_type" do
+ actor = insert(:user, %{actor_type: "Service"})
+ target = insert(:user)
+
+ message = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "type" => "Follow",
+ "actor" => actor.ap_id,
+ "object" => target.ap_id,
+ "id" => "https://example.com/activities/1234"
+ }
+
+ assert {:reject, "[AntiFollowbotPolicy]" <> _} = AntiFollowbotPolicy.filter(message)
+ end
end
- test "it allows non-followbots" do
- actor = insert(:user)
- target = insert(:user)
+ describe "it allows" do
+ test "non-followbots" do
+ actor = insert(:user)
+ target = insert(:user)
- message = %{
- "@context" => "https://www.w3.org/ns/activitystreams",
- "type" => "Follow",
- "actor" => actor.ap_id,
- "object" => target.ap_id,
- "id" => "https://example.com/activities/1234"
- }
+ message = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "type" => "Follow",
+ "actor" => actor.ap_id,
+ "object" => target.ap_id,
+ "id" => "https://example.com/activities/1234"
+ }
- {:ok, _} = AntiFollowbotPolicy.filter(message)
+ {:ok, _} = AntiFollowbotPolicy.filter(message)
+ end
+
+ test "bots if the target follows the bots" do
+ actor = insert(:user, %{actor_type: "Service"})
+ target = insert(:user)
+
+ User.follow(target, actor)
+
+ message = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "type" => "Follow",
+ "actor" => actor.ap_id,
+ "object" => target.ap_id,
+ "id" => "https://example.com/activities/1234"
+ }
+
+ {:ok, _} = AntiFollowbotPolicy.filter(message)
+ end
end
test "it gracefully handles nil display names" do
diff --git a/test/pleroma/web/activity_pub/mrf/anti_link_spam_policy_test.exs b/test/pleroma/web/activity_pub/mrf/anti_link_spam_policy_test.exs
index 5b990451c..303d7ca1e 100644
--- a/test/pleroma/web/activity_pub/mrf/anti_link_spam_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/anti_link_spam_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
import Pleroma.Factory
import ExUnit.CaptureLog
+ alias Pleroma.Web.ActivityPub.MRF
alias Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy
@linkless_message %{
@@ -49,15 +50,39 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
assert user.note_count == 0
+ message = %{
+ "type" => "Create",
+ "actor" => user.ap_id,
+ "object" => %{
+ "formerRepresentations" => %{
+ "type" => "OrderedCollection",
+ "orderedItems" => [
+ %{
+ "content" => "<a href='https://example.com'>hi world!</a>"
+ }
+ ]
+ },
+ "content" => "mew"
+ }
+ }
+
+ {:reject, _} = MRF.filter_one(AntiLinkSpamPolicy, message)
+ end
+
+ test "it allows posts with links for local users" do
+ user = insert(:user)
+
+ assert user.note_count == 0
+
message =
@linkful_message
|> Map.put("actor", user.ap_id)
- {:reject, _} = AntiLinkSpamPolicy.filter(message)
+ {:ok, _message} = AntiLinkSpamPolicy.filter(message)
end
- test "it allows posts with links for local users" do
- user = insert(:user)
+ test "it disallows posts with links in history" do
+ user = insert(:user, local: false)
assert user.note_count == 0
@@ -65,7 +90,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
@linkful_message
|> Map.put("actor", user.ap_id)
- {:ok, _message} = AntiLinkSpamPolicy.filter(message)
+ {:reject, _} = AntiLinkSpamPolicy.filter(message)
end
end
diff --git a/test/pleroma/web/activity_pub/mrf/ensure_re_prepended_test.exs b/test/pleroma/web/activity_pub/mrf/ensure_re_prepended_test.exs
index 89439b65f..859e6f1e9 100644
--- a/test/pleroma/web/activity_pub/mrf/ensure_re_prepended_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/ensure_re_prepended_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrependedTest do
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrependedTest do
alias Pleroma.Activity
alias Pleroma.Object
+ alias Pleroma.Web.ActivityPub.MRF
alias Pleroma.Web.ActivityPub.MRF.EnsureRePrepended
describe "rewrites summary" do
@@ -35,10 +36,58 @@ defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrependedTest do
assert {:ok, res} = EnsureRePrepended.filter(message)
assert res["object"]["summary"] == "re: object-summary"
end
+
+ test "it adds `re:` to history" do
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "summary" => "object-summary",
+ "inReplyTo" => %Activity{object: %Object{data: %{"summary" => "object-summary"}}},
+ "formerRepresentations" => %{
+ "orderedItems" => [
+ %{
+ "summary" => "object-summary",
+ "inReplyTo" => %Activity{object: %Object{data: %{"summary" => "object-summary"}}}
+ }
+ ]
+ }
+ }
+ }
+
+ assert {:ok, res} = MRF.filter_one(EnsureRePrepended, message)
+ assert res["object"]["summary"] == "re: object-summary"
+
+ assert Enum.at(res["object"]["formerRepresentations"]["orderedItems"], 0)["summary"] ==
+ "re: object-summary"
+ end
+
+ test "it accepts Updates" do
+ message = %{
+ "type" => "Update",
+ "object" => %{
+ "summary" => "object-summary",
+ "inReplyTo" => %Activity{object: %Object{data: %{"summary" => "object-summary"}}},
+ "formerRepresentations" => %{
+ "orderedItems" => [
+ %{
+ "summary" => "object-summary",
+ "inReplyTo" => %Activity{object: %Object{data: %{"summary" => "object-summary"}}}
+ }
+ ]
+ }
+ }
+ }
+
+ assert {:ok, res} = MRF.filter_one(EnsureRePrepended, message)
+ assert res["object"]["summary"] == "re: object-summary"
+
+ assert Enum.at(res["object"]["formerRepresentations"]["orderedItems"], 0)["summary"] ==
+ "re: object-summary"
+ end
end
describe "skip filter" do
- test "it skip if type isn't 'Create'" do
+ test "it skip if type isn't 'Create' or 'Update'" do
message = %{
"type" => "Annotation",
"object" => %{"summary" => "object-summary"}
diff --git a/test/pleroma/web/activity_pub/mrf/follow_bot_policy_test.exs b/test/pleroma/web/activity_pub/mrf/follow_bot_policy_test.exs
index a61562558..248190034 100644
--- a/test/pleroma/web/activity_pub/mrf/follow_bot_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/follow_bot_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.FollowBotPolicyTest do
diff --git a/test/pleroma/web/activity_pub/mrf/force_bot_unlisted_policy_test.exs b/test/pleroma/web/activity_pub/mrf/force_bot_unlisted_policy_test.exs
index e3325d144..d1e900164 100644
--- a/test/pleroma/web/activity_pub/mrf/force_bot_unlisted_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/force_bot_unlisted_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicyTest do
diff --git a/test/pleroma/web/activity_pub/mrf/force_mentions_in_content_test.exs b/test/pleroma/web/activity_pub/mrf/force_mentions_in_content_test.exs
new file mode 100644
index 000000000..b349a4bb7
--- /dev/null
+++ b/test/pleroma/web/activity_pub/mrf/force_mentions_in_content_test.exs
@@ -0,0 +1,259 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionsInContentTest do
+ use Pleroma.DataCase
+ require Pleroma.Constants
+
+ alias Pleroma.Constants
+ alias Pleroma.Object
+ alias Pleroma.Web.ActivityPub.MRF
+ alias Pleroma.Web.ActivityPub.MRF.ForceMentionsInContent
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+
+ test "adds mentions to post content" do
+ [lain, coolboymew, dielan, hakui, fence] = [
+ insert(:user, ap_id: "https://lain.com/users/lain", nickname: "lain@lain.com", local: false),
+ insert(:user,
+ ap_id: "https://shitposter.club/users/coolboymew",
+ nickname: "coolboymew@shitposter.club",
+ local: false
+ ),
+ insert(:user,
+ ap_id: "https://shitposter.club/users/dielan",
+ nickname: "dielan@shitposter.club",
+ local: false
+ ),
+ insert(:user,
+ ap_id: "https://tuusin.misono-ya.info/users/hakui",
+ nickname: "hakui@tuusin.misono-ya.info",
+ local: false
+ ),
+ insert(:user,
+ ap_id: "https://xyzzy.link/users/fence",
+ nickname: "fence@xyzzy.link",
+ local: false
+ )
+ ]
+
+ object = File.read!("test/fixtures/soapbox_no_mentions_in_content.json") |> Jason.decode!()
+
+ activity = %{
+ "type" => "Create",
+ "actor" => "https://gleasonator.com/users/alex",
+ "object" => object
+ }
+
+ {:ok, %{"object" => %{"content" => filtered}}} = ForceMentionsInContent.filter(activity)
+
+ assert filtered ==
+ "<p><span class=\"recipients-inline\"><span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{dielan.id}\" href=\"https://shitposter.club/users/dielan\" rel=\"ugc\">@<span>dielan</span></a></span> <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{coolboymew.id}\" href=\"https://shitposter.club/users/coolboymew\" rel=\"ugc\">@<span>coolboymew</span></a></span> <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{fence.id}\" href=\"https://xyzzy.link/users/fence\" rel=\"ugc\">@<span>fence</span></a></span> <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{hakui.id}\" href=\"https://tuusin.misono-ya.info/users/hakui\" rel=\"ugc\">@<span>hakui</span></a></span> <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{lain.id}\" href=\"https://lain.com/users/lain\" rel=\"ugc\">@<span>lain</span></a></span> </span>Haha yeah, you can control who you reply to.</p>"
+ end
+
+ test "the replied-to user is sorted to the left" do
+ [mario, luigi, wario] = [
+ insert(:user, nickname: "mario"),
+ insert(:user, nickname: "luigi"),
+ insert(:user, nickname: "wario")
+ ]
+
+ {:ok, post1} = CommonAPI.post(mario, %{status: "Letsa go!"})
+
+ {:ok, post2} =
+ CommonAPI.post(luigi, %{status: "Oh yaah", in_reply_to_id: post1.id, to: [mario.ap_id]})
+
+ activity = %{
+ "type" => "Create",
+ "actor" => wario.ap_id,
+ "object" => %{
+ "type" => "Note",
+ "actor" => wario.ap_id,
+ "content" => "WHA-HA!",
+ "to" => [
+ mario.ap_id,
+ luigi.ap_id,
+ Constants.as_public()
+ ],
+ "inReplyTo" => Object.normalize(post2).data["id"]
+ }
+ }
+
+ {:ok, %{"object" => %{"content" => filtered}}} = ForceMentionsInContent.filter(activity)
+
+ assert filtered ==
+ "<span class=\"recipients-inline\"><span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{luigi.id}\" href=\"#{luigi.ap_id}\" rel=\"ugc\">@<span>luigi</span></a></span> <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{mario.id}\" href=\"#{mario.ap_id}\" rel=\"ugc\">@<span>mario</span></a></span> </span>WHA-HA!"
+ end
+
+ test "don't mention self" do
+ mario = insert(:user, nickname: "mario")
+
+ {:ok, post} = CommonAPI.post(mario, %{status: "Mama mia"})
+
+ activity = %{
+ "type" => "Create",
+ "actor" => mario.ap_id,
+ "object" => %{
+ "type" => "Note",
+ "actor" => mario.ap_id,
+ "content" => "I'ma tired...",
+ "to" => [
+ mario.ap_id,
+ Constants.as_public()
+ ],
+ "inReplyTo" => Object.normalize(post).data["id"]
+ }
+ }
+
+ {:ok, %{"object" => %{"content" => filtered}}} = ForceMentionsInContent.filter(activity)
+ assert filtered == "I'ma tired..."
+ end
+
+ test "don't mention in top-level posts" do
+ mario = insert(:user, nickname: "mario")
+ luigi = insert(:user, nickname: "luigi")
+
+ {:ok, post} = CommonAPI.post(mario, %{status: "Letsa go"})
+
+ activity = %{
+ "type" => "Create",
+ "actor" => mario.ap_id,
+ "object" => %{
+ "type" => "Note",
+ "actor" => mario.ap_id,
+ "content" => "Mama mia!",
+ "to" => [
+ luigi.ap_id,
+ Constants.as_public()
+ ],
+ "quoteUrl" => Object.normalize(post).data["id"]
+ }
+ }
+
+ {:ok, %{"object" => %{"content" => filtered}}} = ForceMentionsInContent.filter(activity)
+ assert filtered == "Mama mia!"
+ end
+
+ test "with markdown formatting" do
+ mario = insert(:user, nickname: "mario")
+ luigi = insert(:user, nickname: "luigi")
+
+ {:ok, post} = CommonAPI.post(luigi, %{status: "Mama mia"})
+
+ activity = %{
+ "type" => "Create",
+ "actor" => mario.ap_id,
+ "object" => %{
+ "type" => "Note",
+ "actor" => mario.ap_id,
+ "content" => "<p>I'ma tired...</p>",
+ "to" => [
+ luigi.ap_id,
+ Constants.as_public()
+ ],
+ "inReplyTo" => Object.normalize(post).data["id"]
+ }
+ }
+
+ {:ok, %{"object" => %{"content" => filtered}}} = ForceMentionsInContent.filter(activity)
+
+ assert filtered ==
+ "<p><span class=\"recipients-inline\"><span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{luigi.id}\" href=\"#{luigi.ap_id}\" rel=\"ugc\">@<span>luigi</span></a></span> </span>I'ma tired...</p>"
+ end
+
+ test "aware of history" do
+ mario = insert(:user, nickname: "mario")
+ wario = insert(:user, nickname: "wario")
+
+ {:ok, post1} = CommonAPI.post(mario, %{status: "Letsa go!"})
+
+ activity = %{
+ "type" => "Create",
+ "actor" => wario.ap_id,
+ "object" => %{
+ "type" => "Note",
+ "actor" => wario.ap_id,
+ "content" => "WHA-HA!",
+ "to" => [
+ mario.ap_id,
+ Constants.as_public()
+ ],
+ "inReplyTo" => post1.object.data["id"],
+ "formerRepresentations" => %{
+ "orderedItems" => [
+ %{
+ "type" => "Note",
+ "actor" => wario.ap_id,
+ "content" => "WHA-HA!",
+ "to" => [
+ mario.ap_id,
+ Constants.as_public()
+ ],
+ "inReplyTo" => post1.object.data["id"]
+ }
+ ]
+ }
+ }
+ }
+
+ expected =
+ "<span class=\"recipients-inline\"><span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{mario.id}\" href=\"#{mario.ap_id}\" rel=\"ugc\">@<span>mario</span></a></span> </span>WHA-HA!"
+
+ assert {:ok,
+ %{
+ "object" => %{
+ "content" => ^expected,
+ "formerRepresentations" => %{"orderedItems" => [%{"content" => ^expected}]}
+ }
+ }} = MRF.filter_one(ForceMentionsInContent, activity)
+ end
+
+ test "works with Updates" do
+ mario = insert(:user, nickname: "mario")
+ wario = insert(:user, nickname: "wario")
+
+ {:ok, post1} = CommonAPI.post(mario, %{status: "Letsa go!"})
+
+ activity = %{
+ "type" => "Update",
+ "actor" => wario.ap_id,
+ "object" => %{
+ "type" => "Note",
+ "actor" => wario.ap_id,
+ "content" => "WHA-HA!",
+ "to" => [
+ mario.ap_id,
+ Constants.as_public()
+ ],
+ "inReplyTo" => post1.object.data["id"],
+ "formerRepresentations" => %{
+ "orderedItems" => [
+ %{
+ "type" => "Note",
+ "actor" => wario.ap_id,
+ "content" => "WHA-HA!",
+ "to" => [
+ mario.ap_id,
+ Constants.as_public()
+ ],
+ "inReplyTo" => post1.object.data["id"]
+ }
+ ]
+ }
+ }
+ }
+
+ expected =
+ "<span class=\"recipients-inline\"><span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{mario.id}\" href=\"#{mario.ap_id}\" rel=\"ugc\">@<span>mario</span></a></span> </span>WHA-HA!"
+
+ assert {:ok,
+ %{
+ "object" => %{
+ "content" => ^expected,
+ "formerRepresentations" => %{"orderedItems" => [%{"content" => ^expected}]}
+ }
+ }} = MRF.filter_one(ForceMentionsInContent, activity)
+ end
+end
diff --git a/test/pleroma/web/activity_pub/mrf/hashtag_policy_test.exs b/test/pleroma/web/activity_pub/mrf/hashtag_policy_test.exs
index 13415bb79..32991c966 100644
--- a/test/pleroma/web/activity_pub/mrf/hashtag_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/hashtag_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.HashtagPolicyTest do
@@ -20,6 +20,76 @@ defmodule Pleroma.Web.ActivityPub.MRF.HashtagPolicyTest do
assert modified["object"]["sensitive"]
end
+ test "it is history-aware" do
+ activity = %{
+ "type" => "Create",
+ "object" => %{
+ "content" => "hey",
+ "tag" => []
+ }
+ }
+
+ activity_data =
+ activity
+ |> put_in(
+ ["object", "formerRepresentations"],
+ %{
+ "type" => "OrderedCollection",
+ "orderedItems" => [
+ Map.put(
+ activity["object"],
+ "tag",
+ [%{"type" => "Hashtag", "name" => "#nsfw"}]
+ )
+ ]
+ }
+ )
+
+ {:ok, modified} =
+ Pleroma.Web.ActivityPub.MRF.filter_one(
+ Pleroma.Web.ActivityPub.MRF.HashtagPolicy,
+ activity_data
+ )
+
+ refute modified["object"]["sensitive"]
+ assert Enum.at(modified["object"]["formerRepresentations"]["orderedItems"], 0)["sensitive"]
+ end
+
+ test "it works with Update" do
+ activity = %{
+ "type" => "Update",
+ "object" => %{
+ "content" => "hey",
+ "tag" => []
+ }
+ }
+
+ activity_data =
+ activity
+ |> put_in(
+ ["object", "formerRepresentations"],
+ %{
+ "type" => "OrderedCollection",
+ "orderedItems" => [
+ Map.put(
+ activity["object"],
+ "tag",
+ [%{"type" => "Hashtag", "name" => "#nsfw"}]
+ )
+ ]
+ }
+ )
+
+ {:ok, modified} =
+ Pleroma.Web.ActivityPub.MRF.filter_one(
+ Pleroma.Web.ActivityPub.MRF.HashtagPolicy,
+ activity_data
+ )
+
+ refute modified["object"]["sensitive"]
+ assert Enum.at(modified["object"]["formerRepresentations"]["orderedItems"], 0)["sensitive"]
+ end
+
test "it doesn't sets the sensitive property with irrelevant hashtags" do
user = insert(:user)
diff --git a/test/pleroma/web/activity_pub/mrf/hellthread_policy_test.exs b/test/pleroma/web/activity_pub/mrf/hellthread_policy_test.exs
index 439672479..3ab723052 100644
--- a/test/pleroma/web/activity_pub/mrf/hellthread_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/hellthread_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
diff --git a/test/pleroma/web/activity_pub/mrf/keyword_policy_test.exs b/test/pleroma/web/activity_pub/mrf/keyword_policy_test.exs
index 8af4c5efa..a0e77d7b9 100644
--- a/test/pleroma/web/activity_pub/mrf/keyword_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/keyword_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
@@ -79,6 +79,54 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
KeywordPolicy.filter(message)
end)
end
+
+ test "rejects if string matches in history" do
+ clear_config([:mrf_keyword, :reject], ["pun"])
+
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "content" => "just a daily reminder that compLAINer is a good",
+ "summary" => "",
+ "formerRepresentations" => %{
+ "type" => "OrderedCollection",
+ "orderedItems" => [
+ %{
+ "content" => "just a daily reminder that compLAINer is a good pun",
+ "summary" => ""
+ }
+ ]
+ }
+ }
+ }
+
+ assert {:reject, "[KeywordPolicy] Matches with rejected keyword"} =
+ KeywordPolicy.filter(message)
+ end
+
+ test "rejects Updates" do
+ clear_config([:mrf_keyword, :reject], ["pun"])
+
+ message = %{
+ "type" => "Update",
+ "object" => %{
+ "content" => "just a daily reminder that compLAINer is a good",
+ "summary" => "",
+ "formerRepresentations" => %{
+ "type" => "OrderedCollection",
+ "orderedItems" => [
+ %{
+ "content" => "just a daily reminder that compLAINer is a good pun",
+ "summary" => ""
+ }
+ ]
+ }
+ }
+ }
+
+ assert {:reject, "[KeywordPolicy] Matches with rejected keyword"} =
+ KeywordPolicy.filter(message)
+ end
end
describe "delisting from ftl based on keywords" do
@@ -157,6 +205,31 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
not (["https://www.w3.org/ns/activitystreams#Public"] == result["to"])
end)
end
+
+ test "delists if string matches in history" do
+ clear_config([:mrf_keyword, :federated_timeline_removal], ["pun"])
+
+ message = %{
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "type" => "Create",
+ "object" => %{
+ "content" => "just a daily reminder that compLAINer is a good",
+ "summary" => "",
+ "formerRepresentations" => %{
+ "orderedItems" => [
+ %{
+ "content" => "just a daily reminder that compLAINer is a good pun",
+ "summary" => ""
+ }
+ ]
+ }
+ }
+ }
+
+ {:ok, result} = KeywordPolicy.filter(message)
+ assert ["https://www.w3.org/ns/activitystreams#Public"] == result["cc"]
+ refute ["https://www.w3.org/ns/activitystreams#Public"] == result["to"]
+ end
end
describe "replacing keywords" do
@@ -221,5 +294,63 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
result == "ZFS is free software"
end)
end
+
+ test "replaces keyword if string matches in history" do
+ clear_config([:mrf_keyword, :replace], [{"opensource", "free software"}])
+
+ message = %{
+ "type" => "Create",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "object" => %{
+ "content" => "ZFS is opensource",
+ "summary" => "",
+ "formerRepresentations" => %{
+ "type" => "OrderedCollection",
+ "orderedItems" => [
+ %{"content" => "ZFS is opensource mew mew", "summary" => ""}
+ ]
+ }
+ }
+ }
+
+ {:ok,
+ %{
+ "object" => %{
+ "content" => "ZFS is free software",
+ "formerRepresentations" => %{
+ "orderedItems" => [%{"content" => "ZFS is free software mew mew"}]
+ }
+ }
+ }} = KeywordPolicy.filter(message)
+ end
+
+ test "replaces keyword in Updates" do
+ clear_config([:mrf_keyword, :replace], [{"opensource", "free software"}])
+
+ message = %{
+ "type" => "Update",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "object" => %{
+ "content" => "ZFS is opensource",
+ "summary" => "",
+ "formerRepresentations" => %{
+ "type" => "OrderedCollection",
+ "orderedItems" => [
+ %{"content" => "ZFS is opensource mew mew", "summary" => ""}
+ ]
+ }
+ }
+ }
+
+ {:ok,
+ %{
+ "object" => %{
+ "content" => "ZFS is free software",
+ "formerRepresentations" => %{
+ "orderedItems" => [%{"content" => "ZFS is free software mew mew"}]
+ }
+ }
+ }} = KeywordPolicy.filter(message)
+ end
end
end
diff --git a/test/pleroma/web/activity_pub/mrf/media_proxy_warming_policy_test.exs b/test/pleroma/web/activity_pub/mrf/media_proxy_warming_policy_test.exs
index 96e715d0d..6557c3a98 100644
--- a/test/pleroma/web/activity_pub/mrf/media_proxy_warming_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/media_proxy_warming_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do
use Pleroma.Tests.Helpers
alias Pleroma.HTTP
+ alias Pleroma.Web.ActivityPub.MRF
alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
import Mock
@@ -22,6 +23,25 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do
}
}
+ @message_with_history %{
+ "type" => "Create",
+ "object" => %{
+ "type" => "Note",
+ "content" => "content",
+ "formerRepresentations" => %{
+ "orderedItems" => [
+ %{
+ "type" => "Note",
+ "content" => "content",
+ "attachment" => [
+ %{"url" => [%{"href" => "http://example.com/image.jpg"}]}
+ ]
+ }
+ ]
+ }
+ }
+ }
+
setup do: clear_config([:media_proxy, :enabled], true)
test "it prefetches media proxy URIs" do
@@ -50,4 +70,28 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do
refute called(HTTP.get(:_, :_, :_))
end
end
+
+ test "history-aware" do
+ Tesla.Mock.mock(fn %{method: :get, url: "http://example.com/image.jpg"} ->
+ {:ok, %Tesla.Env{status: 200, body: ""}}
+ end)
+
+ with_mock HTTP, get: fn _, _, _ -> {:ok, []} end do
+ MRF.filter_one(MediaProxyWarmingPolicy, @message_with_history)
+
+ assert called(HTTP.get(:_, :_, :_))
+ end
+ end
+
+ test "works with Updates" do
+ Tesla.Mock.mock(fn %{method: :get, url: "http://example.com/image.jpg"} ->
+ {:ok, %Tesla.Env{status: 200, body: ""}}
+ end)
+
+ with_mock HTTP, get: fn _, _, _ -> {:ok, []} end do
+ MRF.filter_one(MediaProxyWarmingPolicy, @message_with_history |> Map.put("type", "Update"))
+
+ assert called(HTTP.get(:_, :_, :_))
+ end
+ end
end
diff --git a/test/pleroma/web/activity_pub/mrf/mention_policy_test.exs b/test/pleroma/web/activity_pub/mrf/mention_policy_test.exs
index 80ddcacbe..6dcae44a0 100644
--- a/test/pleroma/web/activity_pub/mrf/mention_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/mention_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do
diff --git a/test/pleroma/web/activity_pub/mrf/no_empty_policy_test.exs b/test/pleroma/web/activity_pub/mrf/no_empty_policy_test.exs
index fbcf68414..386ed395f 100644
--- a/test/pleroma/web/activity_pub/mrf/no_empty_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/no_empty_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.NoEmptyPolicyTest do
@@ -151,4 +151,27 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoEmptyPolicyTest do
assert NoEmptyPolicy.filter(message) == {:reject, "[NoEmptyPolicy]"}
end
+
+ test "works with Update" do
+ message = %{
+ "actor" => "http://localhost:4001/users/testuser",
+ "cc" => ["http://localhost:4001/users/testuser/followers"],
+ "object" => %{
+ "actor" => "http://localhost:4001/users/testuser",
+ "attachment" => [],
+ "cc" => ["http://localhost:4001/users/testuser/followers"],
+ "source" => "",
+ "to" => [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "type" => "Note"
+ },
+ "to" => [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "type" => "Update"
+ }
+
+ assert NoEmptyPolicy.filter(message) == {:reject, "[NoEmptyPolicy]"}
+ end
end
diff --git a/test/pleroma/web/activity_pub/mrf/no_placeholder_text_policy_test.exs b/test/pleroma/web/activity_pub/mrf/no_placeholder_text_policy_test.exs
index 81a6e0f50..3533c2bc8 100644
--- a/test/pleroma/web/activity_pub/mrf/no_placeholder_text_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/no_placeholder_text_policy_test.exs
@@ -1,9 +1,10 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicyTest do
use Pleroma.DataCase, async: true
+ alias Pleroma.Web.ActivityPub.MRF
alias Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicy
test "it clears content object" do
@@ -20,6 +21,46 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicyTest do
assert res["object"]["content"] == ""
end
+ test "history-aware" do
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "content" => ".",
+ "attachment" => "image",
+ "formerRepresentations" => %{
+ "orderedItems" => [%{"content" => ".", "attachment" => "image"}]
+ }
+ }
+ }
+
+ assert {:ok, res} = MRF.filter_one(NoPlaceholderTextPolicy, message)
+
+ assert %{
+ "content" => "",
+ "formerRepresentations" => %{"orderedItems" => [%{"content" => ""}]}
+ } = res["object"]
+ end
+
+ test "works with Updates" do
+ message = %{
+ "type" => "Update",
+ "object" => %{
+ "content" => ".",
+ "attachment" => "image",
+ "formerRepresentations" => %{
+ "orderedItems" => [%{"content" => ".", "attachment" => "image"}]
+ }
+ }
+ }
+
+ assert {:ok, res} = MRF.filter_one(NoPlaceholderTextPolicy, message)
+
+ assert %{
+ "content" => "",
+ "formerRepresentations" => %{"orderedItems" => [%{"content" => ""}]}
+ } = res["object"]
+ end
+
@messages [
%{
"type" => "Create",
diff --git a/test/pleroma/web/activity_pub/mrf/normalize_markup_test.exs b/test/pleroma/web/activity_pub/mrf/normalize_markup_test.exs
index edc330b6c..66a8f4e44 100644
--- a/test/pleroma/web/activity_pub/mrf/normalize_markup_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/normalize_markup_test.exs
@@ -1,9 +1,10 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkupTest do
use Pleroma.DataCase, async: true
+ alias Pleroma.Web.ActivityPub.MRF
alias Pleroma.Web.ActivityPub.MRF.NormalizeMarkup
@html_sample """
@@ -16,24 +17,58 @@ defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkupTest do
<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 &quot;rel&quot; attribute: <a href="http://example.com/" rel="tag">example.com</a>
- this is a link with not allowed &quot;rel&quot; attribute: <a href="http://example.com/">example.com</a>
- this is an image: <img src="http://example.com/image.jpg"/><br/>
- alert(&#39;hacked&#39;)
- """
+ @expected """
+ <b>this is in bold</b>
+ <p>this is a paragraph</p>
+ this is a linebreak<br/>
+ this is a link with allowed &quot;rel&quot; attribute: <a href="http://example.com/" rel="tag">example.com</a>
+ this is a link with not allowed &quot;rel&quot; attribute: <a href="http://example.com/">example.com</a>
+ this is an image: <img src="http://example.com/image.jpg"/><br/>
+ alert(&#39;hacked&#39;)
+ """
+ test "it filter html tags" do
message = %{"type" => "Create", "object" => %{"content" => @html_sample}}
assert {:ok, res} = NormalizeMarkup.filter(message)
- assert res["object"]["content"] == expected
+ assert res["object"]["content"] == @expected
+ end
+
+ test "history-aware" do
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "content" => @html_sample,
+ "formerRepresentations" => %{"orderedItems" => [%{"content" => @html_sample}]}
+ }
+ }
+
+ assert {:ok, res} = MRF.filter_one(NormalizeMarkup, message)
+
+ assert %{
+ "content" => @expected,
+ "formerRepresentations" => %{"orderedItems" => [%{"content" => @expected}]}
+ } = res["object"]
+ end
+
+ test "works with Updates" do
+ message = %{
+ "type" => "Update",
+ "object" => %{
+ "content" => @html_sample,
+ "formerRepresentations" => %{"orderedItems" => [%{"content" => @html_sample}]}
+ }
+ }
+
+ assert {:ok, res} = MRF.filter_one(NormalizeMarkup, message)
+
+ assert %{
+ "content" => @expected,
+ "formerRepresentations" => %{"orderedItems" => [%{"content" => @expected}]}
+ } = res["object"]
end
- test "it skips filter if type isn't `Create`" do
+ test "it skips filter if type isn't `Create` or `Update`" do
message = %{"type" => "Note", "object" => %{}}
assert {:ok, res} = NormalizeMarkup.filter(message)
diff --git a/test/pleroma/web/activity_pub/mrf/object_age_policy_test.exs b/test/pleroma/web/activity_pub/mrf/object_age_policy_test.exs
index 2f649a0a4..7a67645aa 100644
--- a/test/pleroma/web/activity_pub/mrf/object_age_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/object_age_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
diff --git a/test/pleroma/web/activity_pub/mrf/reject_non_public_test.exs b/test/pleroma/web/activity_pub/mrf/reject_non_public_test.exs
index 63c68d798..0ad60a3b0 100644
--- a/test/pleroma/web/activity_pub/mrf/reject_non_public_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/reject_non_public_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
diff --git a/test/pleroma/web/activity_pub/mrf/simple_policy_test.exs b/test/pleroma/web/activity_pub/mrf/simple_policy_test.exs
index 0b0143d09..57fc00af5 100644
--- a/test/pleroma/web/activity_pub/mrf/simple_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/simple_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
@@ -33,7 +33,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "has a matching host" do
- clear_config([:mrf_simple, :media_removal], ["remote.instance"])
+ clear_config([:mrf_simple, :media_removal], [{"remote.instance", "Some reason"}])
media_message = build_media_message()
local_message = build_local_message()
@@ -46,7 +46,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "match with wildcard domain" do
- clear_config([:mrf_simple, :media_removal], ["*.remote.instance"])
+ clear_config([:mrf_simple, :media_removal], [{"*.remote.instance", "Whatever reason"}])
media_message = build_media_message()
local_message = build_local_message()
@@ -57,6 +57,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
assert SimplePolicy.filter(local_message) == {:ok, local_message}
end
+
+ test "works with Updates" do
+ clear_config([:mrf_simple, :media_removal], [{"remote.instance", "Some reason"}])
+ media_message = build_media_message(type: "Update")
+
+ assert SimplePolicy.filter(media_message) ==
+ {:ok,
+ media_message
+ |> Map.put("object", Map.delete(media_message["object"], "attachment"))}
+ end
end
describe "when :media_nsfw" do
@@ -70,7 +80,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "has a matching host" do
- clear_config([:mrf_simple, :media_nsfw], ["remote.instance"])
+ clear_config([:mrf_simple, :media_nsfw], [{"remote.instance", "Whetever"}])
media_message = build_media_message()
local_message = build_local_message()
@@ -81,7 +91,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "match with wildcard domain" do
- clear_config([:mrf_simple, :media_nsfw], ["*.remote.instance"])
+ clear_config([:mrf_simple, :media_nsfw], [{"*.remote.instance", "yeah yeah"}])
media_message = build_media_message()
local_message = build_local_message()
@@ -90,12 +100,20 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
assert SimplePolicy.filter(local_message) == {:ok, local_message}
end
+
+ test "works with Updates" do
+ clear_config([:mrf_simple, :media_nsfw], [{"remote.instance", "Whetever"}])
+ media_message = build_media_message(type: "Update")
+
+ assert SimplePolicy.filter(media_message) ==
+ {:ok, put_in(media_message, ["object", "sensitive"], true)}
+ end
end
- defp build_media_message do
+ defp build_media_message(opts \\ []) do
%{
"actor" => "https://remote.instance/users/bob",
- "type" => "Create",
+ "type" => opts[:type] || "Create",
"object" => %{
"attachment" => [%{}],
"tag" => ["foo"],
@@ -115,7 +133,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "has a matching host" do
- clear_config([:mrf_simple, :report_removal], ["remote.instance"])
+ clear_config([:mrf_simple, :report_removal], [{"remote.instance", "muh"}])
report_message = build_report_message()
local_message = build_local_message()
@@ -124,7 +142,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "match with wildcard domain" do
- clear_config([:mrf_simple, :report_removal], ["*.remote.instance"])
+ clear_config([:mrf_simple, :report_removal], [{"*.remote.instance", "suya"}])
report_message = build_report_message()
local_message = build_local_message()
@@ -159,7 +177,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|> URI.parse()
|> Map.fetch!(:host)
- clear_config([:mrf_simple, :federated_timeline_removal], [ftl_message_actor_host])
+ clear_config([:mrf_simple, :federated_timeline_removal], [{ftl_message_actor_host, "uwu"}])
local_message = build_local_message()
assert {:ok, ftl_message} = SimplePolicy.filter(ftl_message)
@@ -180,7 +198,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|> URI.parse()
|> Map.fetch!(:host)
- clear_config([:mrf_simple, :federated_timeline_removal], ["*." <> ftl_message_actor_host])
+ clear_config([:mrf_simple, :federated_timeline_removal], [
+ {"*." <> ftl_message_actor_host, "owo"}
+ ])
+
local_message = build_local_message()
assert {:ok, ftl_message} = SimplePolicy.filter(ftl_message)
@@ -203,7 +224,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
ftl_message = Map.put(ftl_message, "cc", [])
- clear_config([:mrf_simple, :federated_timeline_removal], [ftl_message_actor_host])
+ clear_config([:mrf_simple, :federated_timeline_removal], [
+ {ftl_message_actor_host, "spiderwaifu goes 88w88"}
+ ])
assert {:ok, ftl_message} = SimplePolicy.filter(ftl_message)
refute "https://www.w3.org/ns/activitystreams#Public" in ftl_message["to"]
@@ -232,7 +255,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "activity has a matching host" do
- clear_config([:mrf_simple, :reject], ["remote.instance"])
+ clear_config([:mrf_simple, :reject], [{"remote.instance", ""}])
remote_message = build_remote_message()
@@ -240,7 +263,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "activity matches with wildcard domain" do
- clear_config([:mrf_simple, :reject], ["*.remote.instance"])
+ clear_config([:mrf_simple, :reject], [{"*.remote.instance", ""}])
remote_message = build_remote_message()
@@ -248,7 +271,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "actor has a matching host" do
- clear_config([:mrf_simple, :reject], ["remote.instance"])
+ clear_config([:mrf_simple, :reject], [{"remote.instance", ""}])
remote_user = build_remote_user()
@@ -256,7 +279,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "reject Announce when object would be rejected" do
- clear_config([:mrf_simple, :reject], ["blocked.tld"])
+ clear_config([:mrf_simple, :reject], [{"blocked.tld", ""}])
announce = %{
"type" => "Announce",
@@ -268,7 +291,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "reject by URI object" do
- clear_config([:mrf_simple, :reject], ["blocked.tld"])
+ clear_config([:mrf_simple, :reject], [{"blocked.tld", ""}])
announce = %{
"type" => "Announce",
@@ -322,7 +345,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|> URI.parse()
|> Map.fetch!(:host)
- clear_config([:mrf_simple, :followers_only], [actor_domain])
+ clear_config([:mrf_simple, :followers_only], [{actor_domain, ""}])
assert {:ok, new_activity} = SimplePolicy.filter(activity)
assert actor.follower_address in new_activity["cc"]
@@ -350,7 +373,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "is not empty but activity doesn't have a matching host" do
- clear_config([:mrf_simple, :accept], ["non.matching.remote"])
+ clear_config([:mrf_simple, :accept], [{"non.matching.remote", ""}])
local_message = build_local_message()
remote_message = build_remote_message()
@@ -360,7 +383,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "activity has a matching host" do
- clear_config([:mrf_simple, :accept], ["remote.instance"])
+ clear_config([:mrf_simple, :accept], [{"remote.instance", ""}])
local_message = build_local_message()
remote_message = build_remote_message()
@@ -370,7 +393,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "activity matches with wildcard domain" do
- clear_config([:mrf_simple, :accept], ["*.remote.instance"])
+ clear_config([:mrf_simple, :accept], [{"*.remote.instance", ""}])
local_message = build_local_message()
remote_message = build_remote_message()
@@ -380,7 +403,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "actor has a matching host" do
- clear_config([:mrf_simple, :accept], ["remote.instance"])
+ clear_config([:mrf_simple, :accept], [{"remote.instance", ""}])
remote_user = build_remote_user()
@@ -398,7 +421,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "is not empty but it doesn't have a matching host" do
- clear_config([:mrf_simple, :avatar_removal], ["non.matching.remote"])
+ clear_config([:mrf_simple, :avatar_removal], [{"non.matching.remote", ""}])
remote_user = build_remote_user()
@@ -406,7 +429,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "has a matching host" do
- clear_config([:mrf_simple, :avatar_removal], ["remote.instance"])
+ clear_config([:mrf_simple, :avatar_removal], [{"remote.instance", ""}])
remote_user = build_remote_user()
{:ok, filtered} = SimplePolicy.filter(remote_user)
@@ -415,7 +438,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "match with wildcard domain" do
- clear_config([:mrf_simple, :avatar_removal], ["*.remote.instance"])
+ clear_config([:mrf_simple, :avatar_removal], [{"*.remote.instance", ""}])
remote_user = build_remote_user()
{:ok, filtered} = SimplePolicy.filter(remote_user)
@@ -434,7 +457,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "is not empty but it doesn't have a matching host" do
- clear_config([:mrf_simple, :banner_removal], ["non.matching.remote"])
+ clear_config([:mrf_simple, :banner_removal], [{"non.matching.remote", ""}])
remote_user = build_remote_user()
@@ -442,7 +465,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "has a matching host" do
- clear_config([:mrf_simple, :banner_removal], ["remote.instance"])
+ clear_config([:mrf_simple, :banner_removal], [{"remote.instance", ""}])
remote_user = build_remote_user()
{:ok, filtered} = SimplePolicy.filter(remote_user)
@@ -451,7 +474,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "match with wildcard domain" do
- clear_config([:mrf_simple, :banner_removal], ["*.remote.instance"])
+ clear_config([:mrf_simple, :banner_removal], [{"*.remote.instance", ""}])
remote_user = build_remote_user()
{:ok, filtered} = SimplePolicy.filter(remote_user)
@@ -464,7 +487,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
setup do: clear_config([:mrf_simple, :reject_deletes], [])
test "it accepts deletions even from rejected servers" do
- clear_config([:mrf_simple, :reject], ["remote.instance"])
+ clear_config([:mrf_simple, :reject], [{"remote.instance", ""}])
deletion_message = build_remote_deletion_message()
@@ -472,7 +495,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "it accepts deletions even from non-whitelisted servers" do
- clear_config([:mrf_simple, :accept], ["non.matching.remote"])
+ clear_config([:mrf_simple, :accept], [{"non.matching.remote", ""}])
deletion_message = build_remote_deletion_message()
@@ -481,10 +504,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
describe "when :reject_deletes is not empty but it doesn't have a matching host" do
- setup do: clear_config([:mrf_simple, :reject_deletes], ["non.matching.remote"])
+ setup do: clear_config([:mrf_simple, :reject_deletes], [{"non.matching.remote", ""}])
test "it accepts deletions even from rejected servers" do
- clear_config([:mrf_simple, :reject], ["remote.instance"])
+ clear_config([:mrf_simple, :reject], [{"remote.instance", ""}])
deletion_message = build_remote_deletion_message()
@@ -492,7 +515,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "it accepts deletions even from non-whitelisted servers" do
- clear_config([:mrf_simple, :accept], ["non.matching.remote"])
+ clear_config([:mrf_simple, :accept], [{"non.matching.remote", ""}])
deletion_message = build_remote_deletion_message()
@@ -501,7 +524,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
describe "when :reject_deletes has a matching host" do
- setup do: clear_config([:mrf_simple, :reject_deletes], ["remote.instance"])
+ setup do: clear_config([:mrf_simple, :reject_deletes], [{"remote.instance", ""}])
test "it rejects the deletion" do
deletion_message = build_remote_deletion_message()
@@ -511,7 +534,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
describe "when :reject_deletes match with wildcard domain" do
- setup do: clear_config([:mrf_simple, :reject_deletes], ["*.remote.instance"])
+ setup do: clear_config([:mrf_simple, :reject_deletes], [{"*.remote.instance", ""}])
test "it rejects the deletion" do
deletion_message = build_remote_deletion_message()
diff --git a/test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs b/test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs
index bae57f29a..89d32352f 100644
--- a/test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do
@@ -9,11 +9,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do
alias Pleroma.Emoji
alias Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy
- setup_all do
- Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
- :ok
- end
-
setup do
emoji_path = [:instance, :static_dir] |> Config.get() |> Path.join("emoji/stolen")
@@ -49,6 +44,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do
refute "firedfox" in installed()
refute File.exists?(path)
+ Tesla.Mock.mock(fn %{method: :get, url: "https://example.org/emoji/firedfox.png"} ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/image.jpg")}
+ end)
+
clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 284_468)
assert {:ok, _message} = StealEmojiPolicy.filter(message)
@@ -61,7 +60,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do
|> File.exists?()
end
- test "reject shortcode", %{message: message} do
+ test "reject regex shortcode", %{message: message} do
refute "firedfox" in installed()
clear_config(:mrf_steal_emoji,
@@ -75,9 +74,27 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do
refute "firedfox" in installed()
end
+ test "reject string shortcode", %{message: message} do
+ refute "firedfox" in installed()
+
+ clear_config(:mrf_steal_emoji,
+ hosts: ["example.org"],
+ size_limit: 284_468,
+ rejected_shortcodes: ["firedfox"]
+ )
+
+ assert {:ok, _message} = StealEmojiPolicy.filter(message)
+
+ refute "firedfox" in installed()
+ end
+
test "reject if size is above the limit", %{message: message} do
refute "firedfox" in installed()
+ Tesla.Mock.mock(fn %{method: :get, url: "https://example.org/emoji/firedfox.png"} ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/image.jpg")}
+ end)
+
clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 50_000)
assert {:ok, _message} = StealEmojiPolicy.filter(message)
diff --git a/test/pleroma/web/activity_pub/mrf/subchain_policy_test.exs b/test/pleroma/web/activity_pub/mrf/subchain_policy_test.exs
index 4f5cc466c..8cbeef9e9 100644
--- a/test/pleroma/web/activity_pub/mrf/subchain_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/subchain_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.SubchainPolicyTest do
diff --git a/test/pleroma/web/activity_pub/mrf/tag_policy_test.exs b/test/pleroma/web/activity_pub/mrf/tag_policy_test.exs
index faaadff79..a0db8df54 100644
--- a/test/pleroma/web/activity_pub/mrf/tag_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/tag_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do
@@ -99,6 +99,24 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do
assert TagPolicy.filter(message) == {:ok, except_message}
end
+
+ test "removes attachments in Updates" do
+ actor = insert(:user, tags: ["mrf_tag:media-strip"])
+
+ message = %{
+ "actor" => actor.ap_id,
+ "type" => "Update",
+ "object" => %{"attachment" => ["file1"]}
+ }
+
+ except_message = %{
+ "actor" => actor.ap_id,
+ "type" => "Update",
+ "object" => %{}
+ }
+
+ assert TagPolicy.filter(message) == {:ok, except_message}
+ end
end
describe "mrf_tag:media-force-nsfw" do
@@ -119,5 +137,23 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do
assert TagPolicy.filter(message) == {:ok, except_message}
end
+
+ test "Mark as sensitive on presence of attachments in Updates" do
+ actor = insert(:user, tags: ["mrf_tag:media-force-nsfw"])
+
+ message = %{
+ "actor" => actor.ap_id,
+ "type" => "Update",
+ "object" => %{"tag" => ["test"], "attachment" => ["file1"]}
+ }
+
+ except_message = %{
+ "actor" => actor.ap_id,
+ "type" => "Update",
+ "object" => %{"tag" => ["test"], "attachment" => ["file1"], "sensitive" => true}
+ }
+
+ assert TagPolicy.filter(message) == {:ok, except_message}
+ end
end
end
diff --git a/test/pleroma/web/activity_pub/mrf/user_allow_list_policy_test.exs b/test/pleroma/web/activity_pub/mrf/user_allow_list_policy_test.exs
index f0432ea42..d02af3bd0 100644
--- a/test/pleroma/web/activity_pub/mrf/user_allow_list_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/user_allow_list_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicyTest do
use Pleroma.DataCase
diff --git a/test/pleroma/web/activity_pub/mrf/vocabulary_policy_test.exs b/test/pleroma/web/activity_pub/mrf/vocabulary_policy_test.exs
index 87d1d79b5..68c18cfe1 100644
--- a/test/pleroma/web/activity_pub/mrf/vocabulary_policy_test.exs
+++ b/test/pleroma/web/activity_pub/mrf/vocabulary_policy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
diff --git a/test/pleroma/web/activity_pub/mrf_test.exs b/test/pleroma/web/activity_pub/mrf_test.exs
index 61d308b97..8d14e976a 100644
--- a/test/pleroma/web/activity_pub/mrf_test.exs
+++ b/test/pleroma/web/activity_pub/mrf_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRFTest do
@@ -63,6 +63,15 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
end
end
+ describe "instance_list_from_tuples/1" do
+ test "returns a list of instances from a list of {instance, reason} tuples" do
+ list = [{"some.tld", "a reason"}, {"other.tld", "another reason"}]
+ expected = ["some.tld", "other.tld"]
+
+ assert MRF.instance_list_from_tuples(list) == expected
+ end
+ end
+
describe "describe/0" do
test "it works as expected with noop policy" do
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.NoOpPolicy])
diff --git a/test/pleroma/web/activity_pub/object_validators/accept_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/accept_validation_test.exs
index ddb302f6e..70d851948 100644
--- a/test/pleroma/web/activity_pub/object_validators/accept_validation_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/accept_validation_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectValidators.AcceptValidationTest do
diff --git a/test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs
index 20964e855..5b2fcb26d 100644
--- a/test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidationTest do
diff --git a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs
index 917009912..38ea6f1d0 100644
--- a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs
@@ -1,10 +1,11 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest do
use Pleroma.DataCase, async: true
+ alias Pleroma.Web.ActivityPub.ObjectValidator
alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator
alias Pleroma.Web.ActivityPub.Utils
@@ -31,6 +32,89 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest
test "a basic note validates", %{note: note} do
%{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
end
+
+ test "a note from factory validates" do
+ note = insert(:note)
+ %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note.data)
+ end
+ end
+
+ describe "Note with history" do
+ setup do
+ user = insert(:user)
+ {:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew :dinosaur:"})
+ {:ok, edit} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "edited :blank:"})
+
+ {:ok, %{"object" => external_rep}} =
+ Pleroma.Web.ActivityPub.Transmogrifier.prepare_outgoing(edit.data)
+
+ %{external_rep: external_rep}
+ end
+
+ test "edited note", %{external_rep: external_rep} do
+ assert %{"formerRepresentations" => %{"orderedItems" => [%{"tag" => [_]}]}} = external_rep
+
+ {:ok, validate_res, []} = ObjectValidator.validate(external_rep, [])
+
+ assert %{"formerRepresentations" => %{"orderedItems" => [%{"emoji" => %{"dinosaur" => _}}]}} =
+ validate_res
+ end
+
+ test "edited note, badly-formed formerRepresentations", %{external_rep: external_rep} do
+ external_rep = Map.put(external_rep, "formerRepresentations", %{})
+
+ assert {:error, _} = ObjectValidator.validate(external_rep, [])
+ end
+
+ test "edited note, badly-formed history item", %{external_rep: external_rep} do
+ history_item =
+ Enum.at(external_rep["formerRepresentations"]["orderedItems"], 0)
+ |> Map.put("type", "Foo")
+
+ external_rep =
+ put_in(
+ external_rep,
+ ["formerRepresentations", "orderedItems"],
+ [history_item]
+ )
+
+ assert {:error, _} = ObjectValidator.validate(external_rep, [])
+ end
+ end
+
+ test "a Note from Roadhouse validates" do
+ insert(:user, ap_id: "https://macgirvin.com/channel/mike")
+
+ %{"object" => note} =
+ "test/fixtures/roadhouse-create-activity.json"
+ |> File.read!()
+ |> Jason.decode!()
+
+ %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
+ end
+
+ test "a note with an attachment should work", _ do
+ insert(:user, %{ap_id: "https://owncast.localhost.localdomain/federation/user/streamer"})
+
+ note =
+ "test/fixtures/owncast-note-with-attachment.json"
+ |> File.read!()
+ |> Jason.decode!()
+
+ %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
+ end
+
+ test "a Note without replies/first/items validates" do
+ insert(:user, ap_id: "https://mastodon.social/users/emelie")
+
+ note =
+ "test/fixtures/tesla_mock/status.emelie.json"
+ |> File.read!()
+ |> Jason.decode!()
+ |> pop_in(["replies", "first", "items"])
+ |> elem(1)
+
+ %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
end
test "a Note without replies/first/items validates" do
diff --git a/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs
index a72460296..77f2044e9 100644
--- a/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
@@ -11,6 +11,19 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
import Pleroma.Factory
describe "attachments" do
+ test "fails without url" do
+ attachment = %{
+ "mediaType" => "",
+ "name" => "",
+ "summary" => "298p3RG7j27tfsZ9RQ.jpg",
+ "type" => "Document"
+ }
+
+ assert {:error, _cng} =
+ AttachmentValidator.cast_and_validate(attachment)
+ |> Ecto.Changeset.apply_action(:insert)
+ end
+
test "works with honkerific attachments" do
attachment = %{
"mediaType" => "",
@@ -145,5 +158,37 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
assert attachment.mediaType == "image/jpeg"
end
+
+ test "it transforms image dimentions to our internal format" do
+ attachment = %{
+ "type" => "Document",
+ "name" => "Hello world",
+ "url" => "https://media.example.tld/1.jpg",
+ "width" => 880,
+ "height" => 960,
+ "mediaType" => "image/jpeg",
+ "blurhash" => "eTKL26+HDjcEIBVl;ds+K6t301W.t7nit7y1E,R:v}ai4nXSt7V@of"
+ }
+
+ expected = %AttachmentValidator{
+ type: "Document",
+ name: "Hello world",
+ mediaType: "image/jpeg",
+ blurhash: "eTKL26+HDjcEIBVl;ds+K6t301W.t7nit7y1E,R:v}ai4nXSt7V@of",
+ url: [
+ %AttachmentValidator.UrlObjectValidator{
+ type: "Link",
+ mediaType: "image/jpeg",
+ href: "https://media.example.tld/1.jpg",
+ width: 880,
+ height: 960
+ }
+ ]
+ }
+
+ {:ok, ^expected} =
+ AttachmentValidator.cast_and_validate(attachment)
+ |> Ecto.Changeset.apply_action(:insert)
+ end
end
end
diff --git a/test/pleroma/web/activity_pub/object_validators/block_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/block_validation_test.exs
index ad6190892..24e8864f7 100644
--- a/test/pleroma/web/activity_pub/object_validators/block_validation_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/block_validation_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectValidators.BlockValidationTest do
diff --git a/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs
index 320854187..8192efe97 100644
--- a/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
@@ -68,7 +68,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
test "validates for a basic object we build", %{valid_chat_message: valid_chat_message} do
assert {:ok, object, _meta} = ObjectValidator.validate(valid_chat_message, [])
- assert Map.put(valid_chat_message, "attachment", nil) == object
+ assert valid_chat_message == object
assert match?(%{"firefox" => _}, object["emoji"])
end
diff --git a/test/pleroma/web/activity_pub/object_validators/create_generic_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/create_generic_validator_test.exs
new file mode 100644
index 000000000..e771260c9
--- /dev/null
+++ b/test/pleroma/web/activity_pub/object_validators/create_generic_validator_test.exs
@@ -0,0 +1,62 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidatorTest do
+ use Pleroma.DataCase, async: true
+
+ alias Pleroma.Web.ActivityPub.ObjectValidator
+ alias Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidator
+ alias Pleroma.Web.ActivityPub.Utils
+
+ import Pleroma.Factory
+
+ test "a Create/Note from Roadhouse validates" do
+ insert(:user, ap_id: "https://macgirvin.com/channel/mike")
+
+ note_activity =
+ "test/fixtures/roadhouse-create-activity.json"
+ |> File.read!()
+ |> Jason.decode!()
+
+ # Build metadata
+ {:ok, object_data} = ObjectValidator.cast_and_apply(note_activity["object"])
+ meta = [object_data: ObjectValidator.stringify_keys(object_data)]
+
+ assert %{valid?: true} = CreateGenericValidator.cast_and_validate(note_activity, meta)
+ end
+
+ test "a Create/Note with mismatched context uses the Note's context" do
+ user = insert(:user)
+
+ note = %{
+ "id" => Utils.generate_object_id(),
+ "type" => "Note",
+ "actor" => user.ap_id,
+ "to" => [user.follower_address],
+ "cc" => [],
+ "content" => "Hello world",
+ "context" => Utils.generate_context_id()
+ }
+
+ note_activity = %{
+ "id" => Utils.generate_activity_id(),
+ "type" => "Create",
+ "actor" => note["actor"],
+ "to" => note["to"],
+ "cc" => note["cc"],
+ "object" => note,
+ "published" => DateTime.utc_now() |> DateTime.to_iso8601(),
+ "context" => Utils.generate_context_id()
+ }
+
+ # Build metadata
+ {:ok, object_data} = ObjectValidator.cast_and_apply(note_activity["object"])
+ meta = [object_data: ObjectValidator.stringify_keys(object_data)]
+
+ validated = CreateGenericValidator.cast_and_validate(note_activity, meta)
+
+ assert validated.valid?
+ assert {:context, note["context"]} in validated.changes
+ end
+end
diff --git a/test/pleroma/web/activity_pub/object_validators/delete_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/delete_validation_test.exs
index 7ae4399ed..bbb31516c 100644
--- a/test/pleroma/web/activity_pub/object_validators/delete_validation_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/delete_validation_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidationTest do
- use Pleroma.DataCase, async: true
+ use Pleroma.DataCase, async: false
alias Pleroma.Object
alias Pleroma.Web.ActivityPub.Builder
@@ -90,17 +90,26 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidationTest do
assert {:actor, {"is not allowed to modify object", []}} in cng.errors
end
- test "it's valid if the actor of the object is a local superuser",
+ test "it's only valid if the actor of the object is a privileged local user",
%{valid_post_delete: valid_post_delete} do
+ clear_config([:instance, :moderator_privileges], [:messages_delete])
+
user =
insert(:user, local: true, is_moderator: true, ap_id: "https://gensokyo.2hu/users/raymoo")
- valid_other_actor =
+ post_delete_with_moderator_actor =
valid_post_delete
|> Map.put("actor", user.ap_id)
- {:ok, _, meta} = ObjectValidator.validate(valid_other_actor, [])
+ {:ok, _, meta} = ObjectValidator.validate(post_delete_with_moderator_actor, [])
+
assert meta[:do_not_federate]
+
+ clear_config([:instance, :moderator_privileges], [])
+
+ {:error, cng} = ObjectValidator.validate(post_delete_with_moderator_actor, [])
+
+ assert {:actor, {"is not allowed to modify object", []}} in cng.errors
end
end
end
diff --git a/test/pleroma/web/activity_pub/object_validators/emoji_react_handling_test.exs b/test/pleroma/web/activity_pub/object_validators/emoji_react_handling_test.exs
index 7fd98266a..bbdb09c4c 100644
--- a/test/pleroma/web/activity_pub/object_validators/emoji_react_handling_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/emoji_react_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactHandlingTest do
diff --git a/test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs
index d2a9b72a5..371368e0e 100644
--- a/test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectValidators.FollowValidationTest do
diff --git a/test/pleroma/web/activity_pub/object_validators/like_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/like_validation_test.exs
index e9ad817f1..ebc181a6d 100644
--- a/test/pleroma/web/activity_pub/object_validators/like_validation_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/like_validation_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectValidators.LikeValidationTest do
diff --git a/test/pleroma/web/activity_pub/object_validators/reject_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/reject_validation_test.exs
index 562656a5f..7afab4247 100644
--- a/test/pleroma/web/activity_pub/object_validators/reject_validation_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/reject_validation_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectValidators.RejectValidationTest do
diff --git a/test/pleroma/web/activity_pub/object_validators/undo_handling_test.exs b/test/pleroma/web/activity_pub/object_validators/undo_handling_test.exs
index 505ca2d2f..db95b8e3c 100644
--- a/test/pleroma/web/activity_pub/object_validators/undo_handling_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/undo_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectValidators.UndoHandlingTest do
diff --git a/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs b/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs
index 15e4a82cd..a09dbf5c6 100644
--- a/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectValidators.UpdateHandlingTest do
@@ -32,7 +32,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.UpdateHandlingTest do
test "returns an error if the object can't be updated by the actor", %{
valid_update: valid_update
} do
- other_user = insert(:user)
+ other_user = insert(:user, local: false)
update =
valid_update
@@ -40,5 +40,129 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.UpdateHandlingTest do
assert {:error, _cng} = ObjectValidator.validate(update, [])
end
+
+ test "validates as long as the object is same-origin with the actor", %{
+ valid_update: valid_update
+ } do
+ other_user = insert(:user)
+
+ update =
+ valid_update
+ |> Map.put("actor", other_user.ap_id)
+
+ assert {:ok, _update, []} = ObjectValidator.validate(update, [])
+ end
+
+ test "validates if the object is not of an Actor type" do
+ note = insert(:note)
+ updated_note = note.data |> Map.put("content", "edited content")
+ other_user = insert(:user)
+
+ {:ok, update, _} = Builder.update(other_user, updated_note)
+
+ assert {:ok, _update, _} = ObjectValidator.validate(update, [])
+ end
+ end
+
+ describe "update note" do
+ test "converts object into Pleroma's format" do
+ mastodon_tags = [
+ %{
+ "icon" => %{
+ "mediaType" => "image/png",
+ "type" => "Image",
+ "url" => "https://somewhere.org/emoji/url/1.png"
+ },
+ "id" => "https://somewhere.org/emoji/1",
+ "name" => ":some_emoji:",
+ "type" => "Emoji",
+ "updated" => "2021-04-07T11:00:00Z"
+ }
+ ]
+
+ user = insert(:user)
+ note = insert(:note, user: user)
+
+ updated_note =
+ note.data
+ |> Map.put("content", "edited content")
+ |> Map.put("tag", mastodon_tags)
+
+ {:ok, update, _} = Builder.update(user, updated_note)
+
+ assert {:ok, _update, meta} = ObjectValidator.validate(update, [])
+
+ assert %{"emoji" => %{"some_emoji" => "https://somewhere.org/emoji/url/1.png"}} =
+ meta[:object_data]
+ end
+
+ test "returns no object_data in meta for a local Update" do
+ user = insert(:user)
+ note = insert(:note, user: user)
+
+ updated_note =
+ note.data
+ |> Map.put("content", "edited content")
+
+ {:ok, update, _} = Builder.update(user, updated_note)
+
+ assert {:ok, _update, meta} = ObjectValidator.validate(update, local: true)
+ assert is_nil(meta[:object_data])
+ end
+
+ test "returns object_data in meta for a remote Update" do
+ user = insert(:user)
+ note = insert(:note, user: user)
+
+ updated_note =
+ note.data
+ |> Map.put("content", "edited content")
+
+ {:ok, update, _} = Builder.update(user, updated_note)
+
+ assert {:ok, _update, meta} = ObjectValidator.validate(update, local: false)
+ assert meta[:object_data]
+
+ assert {:ok, _update, meta} = ObjectValidator.validate(update, [])
+ assert meta[:object_data]
+ end
+ end
+
+ describe "update with history" do
+ setup do
+ user = insert(:user)
+ {:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew :dinosaur:"})
+ {:ok, edit} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "edited :blank:"})
+ {:ok, external_rep} = Pleroma.Web.ActivityPub.Transmogrifier.prepare_outgoing(edit.data)
+ %{external_rep: external_rep}
+ end
+
+ test "edited note", %{external_rep: external_rep} do
+ {:ok, _validate_res, meta} = ObjectValidator.validate(external_rep, [])
+
+ assert %{"formerRepresentations" => %{"orderedItems" => [%{"emoji" => %{"dinosaur" => _}}]}} =
+ meta[:object_data]
+ end
+
+ test "edited note, badly-formed formerRepresentations", %{external_rep: external_rep} do
+ external_rep = put_in(external_rep, ["object", "formerRepresentations"], %{})
+
+ assert {:error, _} = ObjectValidator.validate(external_rep, [])
+ end
+
+ test "edited note, badly-formed history item", %{external_rep: external_rep} do
+ history_item =
+ Enum.at(external_rep["object"]["formerRepresentations"]["orderedItems"], 0)
+ |> Map.put("type", "Foo")
+
+ external_rep =
+ put_in(
+ external_rep,
+ ["object", "formerRepresentations", "orderedItems"],
+ [history_item]
+ )
+
+ assert {:error, _} = ObjectValidator.validate(external_rep, [])
+ end
end
end
diff --git a/test/pleroma/web/activity_pub/pipeline_test.exs b/test/pleroma/web/activity_pub/pipeline_test.exs
index e606fa3d1..5b65d1014 100644
--- a/test/pleroma/web/activity_pub/pipeline_test.exs
+++ b/test/pleroma/web/activity_pub/pipeline_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.PipelineTest do
diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs
index 89f3ad411..e2db3d575 100644
--- a/test/pleroma/web/activity_pub/publisher_test.exs
+++ b/test/pleroma/web/activity_pub/publisher_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.PublisherTest do
@@ -267,6 +267,80 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
end
describe "publish/2" do
+ test_with_mock "doesn't publish a non-public activity to quarantined instances.",
+ Pleroma.Web.Federator.Publisher,
+ [:passthrough],
+ [] do
+ Config.put([:instance, :quarantined_instances], [{"domain.com", "some reason"}])
+
+ follower =
+ insert(:user, %{
+ local: false,
+ inbox: "https://domain.com/users/nick1/inbox",
+ ap_enabled: true
+ })
+
+ actor = insert(:user, follower_address: follower.ap_id)
+
+ {:ok, follower, actor} = Pleroma.User.follow(follower, actor)
+ actor = refresh_record(actor)
+
+ note_activity =
+ insert(:followers_only_note_activity,
+ user: actor,
+ recipients: [follower.ap_id]
+ )
+
+ res = Publisher.publish(actor, note_activity)
+
+ assert res == :ok
+
+ assert not called(
+ Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
+ inbox: "https://domain.com/users/nick1/inbox",
+ actor_id: actor.id,
+ id: note_activity.data["id"]
+ })
+ )
+ end
+
+ test_with_mock "Publishes a non-public activity to non-quarantined instances.",
+ Pleroma.Web.Federator.Publisher,
+ [:passthrough],
+ [] do
+ Config.put([:instance, :quarantined_instances], [{"somedomain.com", "some reason"}])
+
+ follower =
+ insert(:user, %{
+ local: false,
+ inbox: "https://domain.com/users/nick1/inbox",
+ ap_enabled: true
+ })
+
+ actor = insert(:user, follower_address: follower.ap_id)
+
+ {:ok, follower, actor} = Pleroma.User.follow(follower, actor)
+ actor = refresh_record(actor)
+
+ note_activity =
+ insert(:followers_only_note_activity,
+ user: actor,
+ recipients: [follower.ap_id]
+ )
+
+ res = Publisher.publish(actor, note_activity)
+
+ assert res == :ok
+
+ assert called(
+ Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
+ inbox: "https://domain.com/users/nick1/inbox",
+ actor_id: actor.id,
+ id: note_activity.data["id"]
+ })
+ )
+ end
+
test_with_mock "publishes an activity with BCC to all relevant peers.",
Pleroma.Web.Federator.Publisher,
[:passthrough],
diff --git a/test/pleroma/web/activity_pub/relay_test.exs b/test/pleroma/web/activity_pub/relay_test.exs
index d6de7d61e..ec9b0f09a 100644
--- a/test/pleroma/web/activity_pub/relay_test.exs
+++ b/test/pleroma/web/activity_pub/relay_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.RelayTest do
diff --git a/test/pleroma/web/activity_pub/side_effects/delete_test.exs b/test/pleroma/web/activity_pub/side_effects/delete_test.exs
index 20f0d4b70..9a2703c4c 100644
--- a/test/pleroma/web/activity_pub/side_effects/delete_test.exs
+++ b/test/pleroma/web/activity_pub/side_effects/delete_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.SideEffects.DeleteTest do
diff --git a/test/pleroma/web/activity_pub/side_effects_test.exs b/test/pleroma/web/activity_pub/side_effects_test.exs
index 13167f50a..b24831e85 100644
--- a/test/pleroma/web/activity_pub/side_effects_test.exs
+++ b/test/pleroma/web/activity_pub/side_effects_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
@@ -88,6 +88,16 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
assert User.blocks?(user, blocked)
end
+ test "it updates following relationship", %{user: user, blocked: blocked, block: block} do
+ {:ok, _, _} = SideEffects.handle(block)
+
+ refute Pleroma.FollowingRelationship.get(user, blocked)
+ assert User.get_follow_state(user, blocked) == nil
+ assert User.get_follow_state(blocked, user) == nil
+ assert User.get_follow_state(user, blocked, nil) == nil
+ assert User.get_follow_state(blocked, user, nil) == nil
+ end
+
test "it blocks but does not unfollow if the relevant setting is set", %{
user: user,
blocked: blocked,
@@ -108,7 +118,10 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
describe "update users" do
setup do
user = insert(:user, local: false)
- {:ok, update_data, []} = Builder.update(user, %{"id" => user.ap_id, "name" => "new name!"})
+
+ {:ok, update_data, []} =
+ Builder.update(user, %{"id" => user.ap_id, "type" => "Person", "name" => "new name!"})
+
{:ok, update, _meta} = ActivityPub.persist(update_data, local: true)
%{user: user, update_data: update_data, update: update}
@@ -130,6 +143,298 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
end
end
+ describe "update notes" do
+ setup do
+ make_time = fn ->
+ Pleroma.Web.ActivityPub.Utils.make_date()
+ end
+
+ user = insert(:user)
+ note = insert(:note, user: user, data: %{"published" => make_time.()})
+ _note_activity = insert(:note_activity, note: note)
+
+ updated_note =
+ note.data
+ |> Map.put("summary", "edited summary")
+ |> Map.put("content", "edited content")
+ |> Map.put("updated", make_time.())
+
+ {:ok, update_data, []} = Builder.update(user, updated_note)
+ {:ok, update, _meta} = ActivityPub.persist(update_data, local: true)
+
+ %{
+ user: user,
+ note: note,
+ object_id: note.id,
+ update_data: update_data,
+ update: update,
+ updated_note: updated_note
+ }
+ end
+
+ test "it updates the note", %{
+ object_id: object_id,
+ update: update,
+ updated_note: updated_note
+ } do
+ {:ok, _, _} = SideEffects.handle(update, object_data: updated_note)
+ updated_time = updated_note["updated"]
+
+ new_note = Pleroma.Object.get_by_id(object_id)
+
+ assert %{
+ "summary" => "edited summary",
+ "content" => "edited content",
+ "updated" => ^updated_time
+ } = new_note.data
+ end
+
+ test "it rejects updates with no updated attribute in object", %{
+ object_id: object_id,
+ update: update,
+ updated_note: updated_note
+ } do
+ old_note = Pleroma.Object.get_by_id(object_id)
+ updated_note = Map.drop(updated_note, ["updated"])
+ {:ok, _, _} = SideEffects.handle(update, object_data: updated_note)
+ new_note = Pleroma.Object.get_by_id(object_id)
+ assert old_note.data == new_note.data
+ end
+
+ test "it rejects updates with updated attribute older than what we have in the original object",
+ %{
+ object_id: object_id,
+ update: update,
+ updated_note: updated_note
+ } do
+ old_note = Pleroma.Object.get_by_id(object_id)
+ {:ok, creation_time, _} = DateTime.from_iso8601(old_note.data["published"])
+
+ updated_note =
+ Map.put(updated_note, "updated", DateTime.to_iso8601(DateTime.add(creation_time, -10)))
+
+ {:ok, _, _} = SideEffects.handle(update, object_data: updated_note)
+ new_note = Pleroma.Object.get_by_id(object_id)
+ assert old_note.data == new_note.data
+ end
+
+ test "it rejects updates with updated attribute older than the last Update", %{
+ object_id: object_id,
+ update: update,
+ updated_note: updated_note
+ } do
+ old_note = Pleroma.Object.get_by_id(object_id)
+ {:ok, creation_time, _} = DateTime.from_iso8601(old_note.data["published"])
+
+ updated_note =
+ Map.put(updated_note, "updated", DateTime.to_iso8601(DateTime.add(creation_time, +10)))
+
+ {:ok, _, _} = SideEffects.handle(update, object_data: updated_note)
+
+ old_note = Pleroma.Object.get_by_id(object_id)
+ {:ok, update_time, _} = DateTime.from_iso8601(old_note.data["updated"])
+
+ updated_note =
+ Map.put(updated_note, "updated", DateTime.to_iso8601(DateTime.add(update_time, -5)))
+
+ {:ok, _, _} = SideEffects.handle(update, object_data: updated_note)
+
+ new_note = Pleroma.Object.get_by_id(object_id)
+ assert old_note.data == new_note.data
+ end
+
+ test "it updates using object_data", %{
+ object_id: object_id,
+ update: update,
+ updated_note: updated_note
+ } do
+ updated_note = Map.put(updated_note, "summary", "mew mew")
+ {:ok, _, _} = SideEffects.handle(update, object_data: updated_note)
+ new_note = Pleroma.Object.get_by_id(object_id)
+ assert %{"summary" => "mew mew", "content" => "edited content"} = new_note.data
+ end
+
+ test "it records the original note in formerRepresentations", %{
+ note: note,
+ object_id: object_id,
+ update: update,
+ updated_note: updated_note
+ } do
+ {:ok, _, _} = SideEffects.handle(update, object_data: updated_note)
+ %{data: new_note} = Pleroma.Object.get_by_id(object_id)
+ assert %{"summary" => "edited summary", "content" => "edited content"} = new_note
+
+ assert [Map.drop(note.data, ["id", "formerRepresentations"])] ==
+ new_note["formerRepresentations"]["orderedItems"]
+
+ assert new_note["formerRepresentations"]["totalItems"] == 1
+ end
+
+ test "it puts the original note at the front of formerRepresentations", %{
+ user: user,
+ note: note,
+ object_id: object_id,
+ update: update,
+ updated_note: updated_note
+ } do
+ {:ok, _, _} = SideEffects.handle(update, object_data: updated_note)
+ %{data: first_edit} = Pleroma.Object.get_by_id(object_id)
+
+ second_updated_note =
+ note.data
+ |> Map.put("summary", "edited summary 2")
+ |> Map.put("content", "edited content 2")
+ |> Map.put(
+ "updated",
+ first_edit["updated"]
+ |> DateTime.from_iso8601()
+ |> elem(1)
+ |> DateTime.add(10)
+ |> DateTime.to_iso8601()
+ )
+
+ {:ok, second_update_data, []} = Builder.update(user, second_updated_note)
+ {:ok, update, _meta} = ActivityPub.persist(second_update_data, local: true)
+ {:ok, _, _} = SideEffects.handle(update, object_data: second_updated_note)
+ %{data: new_note} = Pleroma.Object.get_by_id(object_id)
+ assert %{"summary" => "edited summary 2", "content" => "edited content 2"} = new_note
+
+ original_version = Map.drop(note.data, ["id", "formerRepresentations"])
+ first_edit = Map.drop(first_edit, ["id", "formerRepresentations"])
+
+ assert [first_edit, original_version] ==
+ new_note["formerRepresentations"]["orderedItems"]
+
+ assert new_note["formerRepresentations"]["totalItems"] == 2
+ end
+
+ test "it does not prepend to formerRepresentations if no actual changes are made", %{
+ note: note,
+ object_id: object_id,
+ update: update,
+ updated_note: updated_note
+ } do
+ {:ok, _, _} = SideEffects.handle(update, object_data: updated_note)
+ %{data: first_edit} = Pleroma.Object.get_by_id(object_id)
+
+ updated_note =
+ updated_note
+ |> Map.put(
+ "updated",
+ first_edit["updated"]
+ |> DateTime.from_iso8601()
+ |> elem(1)
+ |> DateTime.add(10)
+ |> DateTime.to_iso8601()
+ )
+
+ {:ok, _, _} = SideEffects.handle(update, object_data: updated_note)
+ %{data: new_note} = Pleroma.Object.get_by_id(object_id)
+ assert %{"summary" => "edited summary", "content" => "edited content"} = new_note
+
+ original_version = Map.drop(note.data, ["id", "formerRepresentations"])
+
+ assert [original_version] ==
+ new_note["formerRepresentations"]["orderedItems"]
+
+ assert new_note["formerRepresentations"]["totalItems"] == 1
+ end
+ end
+
+ describe "update questions" do
+ setup do
+ user = insert(:user)
+
+ question =
+ insert(:question,
+ user: user,
+ data: %{"published" => Pleroma.Web.ActivityPub.Utils.make_date()}
+ )
+
+ %{user: user, data: question.data, id: question.id}
+ end
+
+ test "allows updating choice count without generating edit history", %{
+ user: user,
+ data: data,
+ id: id
+ } do
+ new_choices =
+ data["oneOf"]
+ |> Enum.map(fn choice -> put_in(choice, ["replies", "totalItems"], 5) end)
+
+ updated_question =
+ data
+ |> Map.put("oneOf", new_choices)
+ |> Map.put("updated", Pleroma.Web.ActivityPub.Utils.make_date())
+
+ {:ok, update_data, []} = Builder.update(user, updated_question)
+ {:ok, update, _meta} = ActivityPub.persist(update_data, local: true)
+
+ {:ok, _, _} = SideEffects.handle(update, object_data: updated_question)
+
+ %{data: new_question} = Pleroma.Object.get_by_id(id)
+
+ assert [%{"replies" => %{"totalItems" => 5}}, %{"replies" => %{"totalItems" => 5}}] =
+ new_question["oneOf"]
+
+ refute Map.has_key?(new_question, "formerRepresentations")
+ end
+
+ test "allows updating choice count without updated field", %{
+ user: user,
+ data: data,
+ id: id
+ } do
+ new_choices =
+ data["oneOf"]
+ |> Enum.map(fn choice -> put_in(choice, ["replies", "totalItems"], 5) end)
+
+ updated_question =
+ data
+ |> Map.put("oneOf", new_choices)
+
+ {:ok, update_data, []} = Builder.update(user, updated_question)
+ {:ok, update, _meta} = ActivityPub.persist(update_data, local: true)
+
+ {:ok, _, _} = SideEffects.handle(update, object_data: updated_question)
+
+ %{data: new_question} = Pleroma.Object.get_by_id(id)
+
+ assert [%{"replies" => %{"totalItems" => 5}}, %{"replies" => %{"totalItems" => 5}}] =
+ new_question["oneOf"]
+
+ refute Map.has_key?(new_question, "formerRepresentations")
+ end
+
+ test "allows updating choice count with updated field same as the creation date", %{
+ user: user,
+ data: data,
+ id: id
+ } do
+ new_choices =
+ data["oneOf"]
+ |> Enum.map(fn choice -> put_in(choice, ["replies", "totalItems"], 5) end)
+
+ updated_question =
+ data
+ |> Map.put("oneOf", new_choices)
+ |> Map.put("updated", data["published"])
+
+ {:ok, update_data, []} = Builder.update(user, updated_question)
+ {:ok, update, _meta} = ActivityPub.persist(update_data, local: true)
+
+ {:ok, _, _} = SideEffects.handle(update, object_data: updated_question)
+
+ %{data: new_question} = Pleroma.Object.get_by_id(id)
+
+ assert [%{"replies" => %{"totalItems" => 5}}, %{"replies" => %{"totalItems" => 5}}] =
+ new_question["oneOf"]
+
+ refute Map.has_key?(new_question, "formerRepresentations")
+ end
+ end
+
describe "EmojiReact objects" do
setup do
poster = insert(:user)
@@ -157,6 +462,30 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
end
end
+ describe "Question objects" do
+ setup do
+ user = insert(:user)
+ question = build(:question, user: user)
+ question_activity = build(:question_activity, question: question)
+ activity_data = Map.put(question_activity.data, "object", question.data["id"])
+ meta = [object_data: question.data, local: false]
+
+ {:ok, activity, meta} = ActivityPub.persist(activity_data, meta)
+
+ %{activity: activity, meta: meta}
+ end
+
+ test "enqueues the poll end", %{activity: activity, meta: meta} do
+ {:ok, activity, meta} = SideEffects.handle(activity, meta)
+
+ assert_enqueued(
+ worker: Pleroma.Workers.PollWorker,
+ args: %{op: "poll_end", activity_id: activity.id},
+ scheduled_at: NaiveDateTime.from_iso8601!(meta[:object_data]["closed"])
+ )
+ end
+ end
+
describe "delete users with confirmation pending" do
setup do
user = insert(:user, is_confirmed: false)
@@ -510,12 +839,80 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
]) do
{:ok, announce, _} = SideEffects.handle(announce)
- assert called(
- Pleroma.Web.Streamer.stream(["user", "list", "public", "public:local"], announce)
- )
+ assert called(Pleroma.Web.Streamer.stream(["user", "list"], announce))
assert called(Pleroma.Web.Push.send(:_))
end
end
end
+
+ describe "removing a follower" do
+ setup do
+ user = insert(:user)
+ followed = insert(:user)
+
+ {:ok, _, _, follow_activity} = CommonAPI.follow(user, followed)
+
+ {:ok, reject_data, []} = Builder.reject(followed, follow_activity)
+ {:ok, reject, _meta} = ActivityPub.persist(reject_data, local: true)
+
+ %{user: user, followed: followed, reject: reject}
+ end
+
+ test "", %{user: user, followed: followed, reject: reject} do
+ assert User.following?(user, followed)
+ assert Pleroma.FollowingRelationship.get(user, followed)
+
+ {:ok, _, _} = SideEffects.handle(reject)
+
+ refute User.following?(user, followed)
+ refute Pleroma.FollowingRelationship.get(user, followed)
+ assert User.get_follow_state(user, followed) == nil
+ assert User.get_follow_state(user, followed, nil) == nil
+ end
+ end
+
+ describe "removing a follower from remote" do
+ setup do
+ user = insert(:user)
+ followed = insert(:user, local: false)
+
+ # Mock a local-to-remote follow
+ {:ok, follow_data, []} = Builder.follow(user, followed)
+
+ follow_data =
+ follow_data
+ |> Map.put("state", "accept")
+
+ {:ok, follow, _meta} = ActivityPub.persist(follow_data, local: true)
+ {:ok, _, _} = SideEffects.handle(follow)
+
+ # Mock a remote-to-local accept
+ {:ok, accept_data, _} = Builder.accept(followed, follow)
+ {:ok, accept, _} = ActivityPub.persist(accept_data, local: false)
+ {:ok, _, _} = SideEffects.handle(accept)
+
+ # Mock a remote-to-local reject
+ {:ok, reject_data, []} = Builder.reject(followed, follow)
+ {:ok, reject, _meta} = ActivityPub.persist(reject_data, local: false)
+
+ %{user: user, followed: followed, reject: reject}
+ end
+
+ test "", %{user: user, followed: followed, reject: reject} do
+ assert User.following?(user, followed)
+ assert Pleroma.FollowingRelationship.get(user, followed)
+
+ {:ok, _, _} = SideEffects.handle(reject)
+
+ refute User.following?(user, followed)
+ refute Pleroma.FollowingRelationship.get(user, followed)
+
+ assert Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(user, followed).data["state"] ==
+ "reject"
+
+ assert User.get_follow_state(user, followed) == nil
+ assert User.get_follow_state(user, followed, nil) == nil
+ end
+ end
end
diff --git a/test/pleroma/web/activity_pub/transmogrifier/accept_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/accept_handling_test.exs
index 58490076d..968fd4ede 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/accept_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/accept_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do
diff --git a/test/pleroma/web/activity_pub/transmogrifier/add_remove_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/add_remove_handling_test.exs
index fc7757125..a8a7edca5 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/add_remove_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/add_remove_handling_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.ActivityPub.Transmogrifier.AddRemoveHandlingTest do
use Oban.Testing, repo: Pleroma.Repo
use Pleroma.DataCase, async: true
@@ -67,7 +71,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AddRemoveHandlingTest do
"target" => "https://example.com/users/lain/collections/featured",
"type" => "Add",
"to" => [Pleroma.Constants.as_public()],
- "cc" => ["https://example.com/users/lain/followers"]
+ "cc" => ["https://example.com/users/lain/followers"],
+ "bcc" => [],
+ "bto" => []
}
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
@@ -82,7 +88,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AddRemoveHandlingTest do
"target" => "https://example.com/users/lain/collections/featured",
"type" => "Remove",
"to" => [Pleroma.Constants.as_public()],
- "cc" => ["https://example.com/users/lain/followers"]
+ "cc" => ["https://example.com/users/lain/followers"],
+ "bcc" => [],
+ "bto" => []
}
assert {:ok, activity} = Transmogrifier.handle_incoming(remove)
@@ -161,7 +169,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AddRemoveHandlingTest do
"target" => "https://#{host}/users/#{user.nickname}/collections/featured",
"type" => "Add",
"to" => [Pleroma.Constants.as_public()],
- "cc" => ["https://#{host}/users/#{user.nickname}/followers"]
+ "cc" => ["https://#{host}/users/#{user.nickname}/followers"],
+ "bcc" => [],
+ "bto" => []
}
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
diff --git a/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs
index 524acddaf..9521cc0ab 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do
diff --git a/test/pleroma/web/activity_pub/transmogrifier/answer_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/answer_handling_test.exs
index 9c2ef547b..39a1598a8 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/answer_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/answer_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnswerHandlingTest do
diff --git a/test/pleroma/web/activity_pub/transmogrifier/article_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/article_handling_test.exs
index 5dbc5eb95..252492013 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/article_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/article_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.ArticleHandlingTest do
diff --git a/test/pleroma/web/activity_pub/transmogrifier/audio_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/audio_handling_test.exs
index a929f828d..d1eb21a0c 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/audio_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/audio_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
@@ -73,16 +73,12 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
%{
"mediaType" => "audio/ogg",
"type" => "Link",
- "name" => nil,
- "blurhash" => nil,
"url" => [
%{
"href" =>
"https://channels.tests.funkwhale.audio/api/v1/listen/3901e5d8-0445-49d5-9711-e096cf32e515/?upload=42342395-0208-4fee-a38d-259a6dae0871&download=false",
"mediaType" => "audio/ogg",
- "type" => "Link",
- "width" => nil,
- "height" => nil
+ "type" => "Link"
}
]
}
diff --git a/test/pleroma/web/activity_pub/transmogrifier/block_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/block_handling_test.exs
index 70da06d2e..c9a20b1ae 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/block_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/block_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.BlockHandlingTest do
diff --git a/test/pleroma/web/activity_pub/transmogrifier/chat_message_test.exs b/test/pleroma/web/activity_pub/transmogrifier/chat_message_test.exs
index 958675835..c798a0fc9 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/chat_message_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/chat_message_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageTest do
diff --git a/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs
index b7160bf58..4a7ff5158 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do
diff --git a/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs
index 20424ee82..9d99df27c 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiReactHandlingTest do
@@ -37,6 +37,37 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiReactHandlingTest do
assert match?([["👌", _]], object.data["reactions"])
end
+ test "it works for incoming unqualified emoji reactions" do
+ user = insert(:user)
+ other_user = insert(:user, local: false)
+ {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
+
+ # woman detective emoji, unqualified
+ unqualified_emoji = [0x1F575, 0x200D, 0x2640] |> List.to_string()
+
+ data =
+ File.read!("test/fixtures/emoji-reaction.json")
+ |> Jason.decode!()
+ |> Map.put("object", activity.data["object"])
+ |> Map.put("actor", other_user.ap_id)
+ |> Map.put("content", unqualified_emoji)
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+
+ assert data["actor"] == other_user.ap_id
+ assert data["type"] == "EmojiReact"
+ assert data["id"] == "http://mastodon.example.org/users/admin#reactions/2"
+ assert data["object"] == activity.data["object"]
+ # woman detective emoji, fully qualified
+ emoji = [0x1F575, 0xFE0F, 0x200D, 0x2640, 0xFE0F] |> List.to_string()
+ assert data["content"] == emoji
+
+ object = Object.get_by_ap_id(data["object"])
+
+ assert object.data["reaction_count"] == 1
+ assert match?([[emoji, _]], object.data["reactions"])
+ end
+
test "it reject invalid emoji reactions" do
user = insert(:user)
other_user = insert(:user, local: false)
diff --git a/test/pleroma/web/activity_pub/transmogrifier/event_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/event_handling_test.exs
index 14f5f704a..6372aa89a 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/event_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/event_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.EventHandlingTest do
diff --git a/test/pleroma/web/activity_pub/transmogrifier/follow_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/follow_handling_test.exs
index 604444a4c..3c07926e6 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/follow_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/follow_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
diff --git a/test/pleroma/web/activity_pub/transmogrifier/like_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/like_handling_test.exs
index 57d74349a..c02f66d77 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/like_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/like_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.LikeHandlingTest do
diff --git a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs
index 1846b2291..7c406fbd0 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
@@ -707,4 +707,42 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
}
]
end
+
+ test "the standalone note uses its own ID when context is missing" do
+ insert(:user, ap_id: "https://mk.absturztau.be/users/8ozbzjs3o8")
+
+ activity =
+ "test/fixtures/tesla_mock/mk.absturztau.be-93e7nm8wqg-activity.json"
+ |> File.read!()
+ |> Jason.decode!()
+
+ {:ok, %Activity{} = modified} = Transmogrifier.handle_incoming(activity)
+ object = Object.normalize(modified, fetch: false)
+
+ assert object.data["context"] == object.data["id"]
+ assert modified.data["context"] == object.data["id"]
+ end
+
+ test "the reply note uses its parent's ID when context is missing and reply is unreachable" do
+ insert(:user, ap_id: "https://mk.absturztau.be/users/8ozbzjs3o8")
+
+ activity =
+ "test/fixtures/tesla_mock/mk.absturztau.be-93e7nm8wqg-activity.json"
+ |> File.read!()
+ |> Jason.decode!()
+
+ object =
+ activity["object"]
+ |> Map.put("inReplyTo", "https://404.site/object/went-to-buy-milk")
+
+ activity =
+ activity
+ |> Map.put("object", object)
+
+ {:ok, %Activity{} = modified} = Transmogrifier.handle_incoming(activity)
+ object = Object.normalize(modified, fetch: false)
+
+ assert object.data["context"] == object.data["inReplyTo"]
+ assert modified.data["context"] == object.data["inReplyTo"]
+ end
end
diff --git a/test/pleroma/web/activity_pub/transmogrifier/page_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/page_handling_test.exs
index 4ac71e066..d50c7f4ef 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/page_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/page_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.PageHandlingTest do
diff --git a/test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs
index 32cf51e59..d31070546 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.QuestionHandlingTest do
@@ -33,8 +33,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.QuestionHandlingTest do
assert object.data["context"] ==
"tag:mastodon.sdf.org,2019-05-10:objectId=15095122:objectType=Conversation"
- assert object.data["context_id"]
-
assert object.data["anyOf"] == []
assert Enum.sort(object.data["oneOf"]) ==
@@ -68,7 +66,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.QuestionHandlingTest do
reply_object = Object.normalize(reply_activity, fetch: false)
assert reply_object.data["context"] == object.data["context"]
- assert reply_object.data["context_id"] == object.data["context_id"]
end
test "Mastodon Question activity with HTML tags in plaintext" do
diff --git a/test/pleroma/web/activity_pub/transmogrifier/reject_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/reject_handling_test.exs
index 355e664d4..11562422d 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/reject_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/reject_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.RejectHandlingTest do
diff --git a/test/pleroma/web/activity_pub/transmogrifier/undo_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/undo_handling_test.exs
index f6e40722c..846d25cbe 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/undo_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/undo_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.UndoHandlingTest do
diff --git a/test/pleroma/web/activity_pub/transmogrifier/user_update_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/user_update_handling_test.exs
index b1a064772..da46f063a 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/user_update_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/user_update_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.UserUpdateHandlingTest do
diff --git a/test/pleroma/web/activity_pub/transmogrifier/video_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/video_handling_test.exs
index 62b4a2cb3..57b517100 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/video_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/video_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
@@ -53,16 +53,13 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
%{
"type" => "Link",
"mediaType" => "video/mp4",
- "name" => nil,
- "blurhash" => nil,
"url" => [
%{
"href" =>
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
"mediaType" => "video/mp4",
"type" => "Link",
- "width" => nil,
- "height" => nil
+ "width" => 480
}
]
}
@@ -78,16 +75,13 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
%{
"type" => "Link",
"mediaType" => "video/mp4",
- "name" => nil,
- "blurhash" => nil,
"url" => [
%{
"href" =>
"https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4",
"mediaType" => "video/mp4",
"type" => "Link",
- "width" => nil,
- "height" => nil
+ "height" => 1080
}
]
}
@@ -110,16 +104,13 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
%{
"type" => "Link",
"mediaType" => "video/mp4",
- "name" => nil,
- "blurhash" => nil,
"url" => [
%{
"href" =>
"https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/abece3c3-b9c6-47f4-8040-f3eed8c602e6-1080-fragmented.mp4",
"mediaType" => "video/mp4",
"type" => "Link",
- "width" => nil,
- "height" => nil
+ "height" => 1080
}
]
}
diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs
index 5a3b57acb..6b4636d22 100644
--- a/test/pleroma/web/activity_pub/transmogrifier_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
@@ -61,7 +61,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
note_obj = %{
"type" => "Note",
- "id" => activity.data["id"],
+ "id" => activity.object.data["id"],
"content" => "test post",
"published" => object.data["published"],
"actor" => AccountView.render("show.json", %{user: user, skip_visibility_check: true})
@@ -107,6 +107,22 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert activity.data["target"] == new_user.ap_id
assert activity.data["type"] == "Move"
end
+
+ test "it fixes both the Create and object contexts in a reply" do
+ insert(:user, ap_id: "https://mk.absturztau.be/users/8ozbzjs3o8")
+ insert(:user, ap_id: "https://p.helene.moe/users/helene")
+
+ create_activity =
+ "test/fixtures/create-pleroma-reply-to-misskey-thread.json"
+ |> File.read!()
+ |> Jason.decode!()
+
+ assert {:ok, %Activity{} = activity} = Transmogrifier.handle_incoming(create_activity)
+
+ object = Object.normalize(activity, fetch: false)
+
+ assert activity.data["context"] == object.data["context"]
+ end
end
describe "prepare outgoing" do
@@ -216,7 +232,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert is_nil(modified["object"]["like_count"])
assert is_nil(modified["object"]["announcements"])
assert is_nil(modified["object"]["announcement_count"])
- assert is_nil(modified["object"]["context_id"])
assert is_nil(modified["object"]["generator"])
end
@@ -231,7 +246,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert is_nil(modified["object"]["like_count"])
assert is_nil(modified["object"]["announcements"])
assert is_nil(modified["object"]["announcement_count"])
- assert is_nil(modified["object"]["context_id"])
assert is_nil(modified["object"]["likes"])
end
@@ -301,6 +315,28 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert url == "http://localhost:4001/emoji/dino%20walking.gif"
end
+
+ test "Updates of Notes are handled" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "everybody do the dinosaur :dinosaur:"})
+ {:ok, update} = CommonAPI.update(user, activity, %{status: "mew mew :blank:"})
+
+ {:ok, prepared} = Transmogrifier.prepare_outgoing(update.data)
+
+ assert %{
+ "content" => "mew mew :blank:",
+ "tag" => [%{"name" => ":blank:", "type" => "Emoji"}],
+ "formerRepresentations" => %{
+ "orderedItems" => [
+ %{
+ "content" => "everybody do the dinosaur :dinosaur:",
+ "tag" => [%{"name" => ":dinosaur:", "type" => "Emoji"}]
+ }
+ ]
+ }
+ } = prepared["object"]
+ end
end
describe "user upgrade" do
@@ -524,4 +560,83 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
)
end
end
+
+ describe "fix_attachments/1" do
+ test "puts dimensions into attachment url field" do
+ object = %{
+ "attachment" => [
+ %{
+ "type" => "Document",
+ "name" => "Hello world",
+ "url" => "https://media.example.tld/1.jpg",
+ "width" => 880,
+ "height" => 960,
+ "mediaType" => "image/jpeg",
+ "blurhash" => "eTKL26+HDjcEIBVl;ds+K6t301W.t7nit7y1E,R:v}ai4nXSt7V@of"
+ }
+ ]
+ }
+
+ expected = %{
+ "attachment" => [
+ %{
+ "type" => "Document",
+ "name" => "Hello world",
+ "url" => [
+ %{
+ "type" => "Link",
+ "mediaType" => "image/jpeg",
+ "href" => "https://media.example.tld/1.jpg",
+ "width" => 880,
+ "height" => 960
+ }
+ ],
+ "mediaType" => "image/jpeg",
+ "blurhash" => "eTKL26+HDjcEIBVl;ds+K6t301W.t7nit7y1E,R:v}ai4nXSt7V@of"
+ }
+ ]
+ }
+
+ assert Transmogrifier.fix_attachments(object) == expected
+ end
+ end
+
+ describe "prepare_object/1" do
+ test "it processes history" do
+ original = %{
+ "formerRepresentations" => %{
+ "orderedItems" => [
+ %{
+ "generator" => %{},
+ "emoji" => %{"blobcat" => "http://localhost:4001/emoji/blobcat.png"}
+ }
+ ]
+ }
+ }
+
+ processed = Transmogrifier.prepare_object(original)
+
+ history_item = Enum.at(processed["formerRepresentations"]["orderedItems"], 0)
+
+ refute Map.has_key?(history_item, "generator")
+
+ assert [%{"name" => ":blobcat:"}] = history_item["tag"]
+ end
+
+ test "it works when there is no or bad history" do
+ original = %{
+ "formerRepresentations" => %{
+ "items" => [
+ %{
+ "generator" => %{},
+ "emoji" => %{"blobcat" => "http://localhost:4001/emoji/blobcat.png"}
+ }
+ ]
+ }
+ }
+
+ processed = Transmogrifier.prepare_object(original)
+ assert processed["formerRepresentations"] == original["formerRepresentations"]
+ end
+ end
end
diff --git a/test/pleroma/web/activity_pub/utils_test.exs b/test/pleroma/web/activity_pub/utils_test.exs
index ee3e1014e..e7d1e01c4 100644
--- a/test/pleroma/web/activity_pub/utils_test.exs
+++ b/test/pleroma/web/activity_pub/utils_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.UtilsTest do
@@ -213,6 +213,20 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
assert refresh_record(follow_activity).data["state"] == "accept"
assert refresh_record(follow_activity_two).data["state"] == "accept"
end
+
+ test "also updates the state of accepted follows" do
+ user = insert(:user)
+ follower = insert(:user)
+
+ {:ok, _, _, follow_activity} = CommonAPI.follow(follower, user)
+ {:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user)
+
+ {:ok, follow_activity_two} =
+ Utils.update_follow_state_for_all(follow_activity_two, "reject")
+
+ assert refresh_record(follow_activity).data["state"] == "reject"
+ assert refresh_record(follow_activity_two).data["state"] == "reject"
+ end
end
describe "update_follow_state/2" do
@@ -415,7 +429,6 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
object = Object.normalize(note_activity, fetch: false)
res = Utils.lazy_put_activity_defaults(%{"context" => object.data["id"]})
assert res["context"] == object.data["id"]
- assert res["context_id"] == object.id
assert res["id"]
assert res["published"]
end
@@ -423,7 +436,6 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
test "returns map with fake id and published data" do
assert %{
"context" => "pleroma:fakecontext",
- "context_id" => -1,
"id" => "pleroma:fakeid",
"published" => _
} = Utils.lazy_put_activity_defaults(%{}, true)
@@ -440,13 +452,11 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
})
assert res["context"] == object.data["id"]
- assert res["context_id"] == object.id
assert res["id"]
assert res["published"]
assert res["object"]["id"]
assert res["object"]["published"]
assert res["object"]["context"] == object.data["id"]
- assert res["object"]["context_id"] == object.id
end
end
@@ -463,7 +473,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
content = "foobar"
target_ap_id = target_account.ap_id
- activity_ap_id = activity.data["id"]
+ object_ap_id = activity.object.data["id"]
res =
Utils.make_flag_data(
@@ -479,7 +489,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
note_obj = %{
"type" => "Note",
- "id" => activity_ap_id,
+ "id" => object_ap_id,
"content" => content,
"published" => activity.object.data["published"],
"actor" =>
@@ -494,6 +504,49 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
"state" => "open"
} = res
end
+
+ test "returns map with Flag object with a non-Create Activity" do
+ reporter = insert(:user)
+ posting_account = insert(:user)
+ target_account = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(posting_account, %{status: "foobar"})
+ {:ok, like} = CommonAPI.favorite(target_account, activity.id)
+ context = Utils.generate_context_id()
+ content = "foobar"
+
+ target_ap_id = target_account.ap_id
+ object_ap_id = activity.object.data["id"]
+
+ res =
+ Utils.make_flag_data(
+ %{
+ actor: reporter,
+ context: context,
+ account: target_account,
+ statuses: [%{"id" => like.data["id"]}],
+ content: content
+ },
+ %{}
+ )
+
+ note_obj = %{
+ "type" => "Note",
+ "id" => object_ap_id,
+ "content" => content,
+ "published" => activity.object.data["published"],
+ "actor" =>
+ AccountView.render("show.json", %{user: posting_account, skip_visibility_check: true})
+ }
+
+ assert %{
+ "type" => "Flag",
+ "content" => ^content,
+ "context" => ^context,
+ "object" => [^target_ap_id, ^note_obj],
+ "state" => "open"
+ } = res
+ end
end
describe "add_announce_to_object/2" do
diff --git a/test/pleroma/web/activity_pub/views/object_view_test.exs b/test/pleroma/web/activity_pub/views/object_view_test.exs
index 923515dec..d94878e31 100644
--- a/test/pleroma/web/activity_pub/views/object_view_test.exs
+++ b/test/pleroma/web/activity_pub/views/object_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
@@ -81,4 +81,18 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
assert result["object"] == object.data["id"]
assert result["type"] == "Announce"
end
+
+ test "renders an undo announce activity" do
+ note = insert(:note_activity)
+ user = insert(:user)
+
+ {:ok, announce} = CommonAPI.repeat(note.id, user)
+ {:ok, undo} = CommonAPI.unrepeat(note.id, user)
+
+ result = ObjectView.render("object.json", %{object: undo})
+
+ assert result["id"] == undo.data["id"]
+ assert result["object"] == announce.data["id"]
+ assert result["type"] == "Undo"
+ end
end
diff --git a/test/pleroma/web/activity_pub/views/user_view_test.exs b/test/pleroma/web/activity_pub/views/user_view_test.exs
index f2de4d332..5f03c019e 100644
--- a/test/pleroma/web/activity_pub/views/user_view_test.exs
+++ b/test/pleroma/web/activity_pub/views/user_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.UserViewTest do
@@ -12,7 +12,6 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
test "Renders a user, including the public key" do
user = insert(:user)
- {:ok, user} = User.ensure_keys_present(user)
result = UserView.render("user.json", %{user: user})
@@ -55,7 +54,6 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
test "Does not add an avatar image if the user hasn't set one" do
user = insert(:user)
- {:ok, user} = User.ensure_keys_present(user)
result = UserView.render("user.json", %{user: user})
refute result["icon"]
@@ -67,8 +65,6 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
banner: %{"url" => [%{"href" => "https://somebanner"}]}
)
- {:ok, user} = User.ensure_keys_present(user)
-
result = UserView.render("user.json", %{user: user})
assert result["icon"]["url"] == "https://someurl"
assert result["image"]["url"] == "https://somebanner"
@@ -89,7 +85,6 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
describe "endpoints" do
test "local users have a usable endpoints structure" do
user = insert(:user)
- {:ok, user} = User.ensure_keys_present(user)
result = UserView.render("user.json", %{user: user})
@@ -105,7 +100,6 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
test "remote users have an empty endpoints structure" do
user = insert(:user, local: false)
- {:ok, user} = User.ensure_keys_present(user)
result = UserView.render("user.json", %{user: user})
@@ -115,7 +109,6 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
test "instance users do not expose oAuth endpoints" do
user = insert(:user, nickname: nil, local: true)
- {:ok, user} = User.ensure_keys_present(user)
result = UserView.render("user.json", %{user: user})
diff --git a/test/pleroma/web/activity_pub/visibility_test.exs b/test/pleroma/web/activity_pub/visibility_test.exs
index 23485225d..8c4c06a95 100644
--- a/test/pleroma/web/activity_pub/visibility_test.exs
+++ b/test/pleroma/web/activity_pub/visibility_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.VisibilityTest do
diff --git a/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs b/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs
index 8cd9f939b..e1ab50542 100644
--- a/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
- use Pleroma.Web.ConnCase
+ use Pleroma.Web.ConnCase, async: false
use Oban.Testing, repo: Pleroma.Repo
import ExUnit.CaptureLog
@@ -92,18 +92,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
describe "PUT /api/pleroma/admin/users/tag" do
setup %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [:users_manage_tags])
+
user1 = insert(:user, %{tags: ["x"]})
user2 = insert(:user, %{tags: ["y"]})
user3 = insert(:user, %{tags: ["unchanged"]})
- conn =
- conn
- |> put_req_header("accept", "application/json")
- |> put(
- "/api/pleroma/admin/users/tag?nicknames[]=#{user1.nickname}&nicknames[]=" <>
- "#{user2.nickname}&tags[]=foo&tags[]=bar"
- )
-
%{conn: conn, user1: user1, user2: user2, user3: user3}
end
@@ -113,6 +107,14 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
user1: user1,
user2: user2
} do
+ conn =
+ conn
+ |> put_req_header("accept", "application/json")
+ |> put(
+ "/api/pleroma/admin/users/tag?nicknames[]=#{user1.nickname}&nicknames[]=" <>
+ "#{user2.nickname}&tags[]=foo&tags[]=bar"
+ )
+
assert empty_json_response(conn)
assert User.get_cached_by_id(user1.id).tags == ["x", "foo", "bar"]
assert User.get_cached_by_id(user2.id).tags == ["y", "foo", "bar"]
@@ -130,26 +132,43 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"@#{admin.nickname} added tags: #{tags} to users: #{users}"
end
- test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
+ test "it does not modify tags of not specified users", %{
+ conn: conn,
+ user1: user1,
+ user2: user2,
+ user3: user3
+ } do
+ conn =
+ conn
+ |> put_req_header("accept", "application/json")
+ |> put(
+ "/api/pleroma/admin/users/tag?nicknames[]=#{user1.nickname}&nicknames[]=" <>
+ "#{user2.nickname}&tags[]=foo&tags[]=bar"
+ )
+
assert empty_json_response(conn)
assert User.get_cached_by_id(user3.id).tags == ["unchanged"]
end
+
+ test "it requires privileged role :users_manage_tags", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ response =
+ conn
+ |> put_req_header("accept", "application/json")
+ |> put("/api/pleroma/admin/users/tag?nicknames[]=nickname&tags[]=foo&tags[]=bar")
+
+ assert json_response(response, :forbidden)
+ end
end
describe "DELETE /api/pleroma/admin/users/tag" do
setup %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [:users_manage_tags])
user1 = insert(:user, %{tags: ["x"]})
user2 = insert(:user, %{tags: ["y", "z"]})
user3 = insert(:user, %{tags: ["unchanged"]})
- conn =
- conn
- |> put_req_header("accept", "application/json")
- |> delete(
- "/api/pleroma/admin/users/tag?nicknames[]=#{user1.nickname}&nicknames[]=" <>
- "#{user2.nickname}&tags[]=x&tags[]=z"
- )
-
%{conn: conn, user1: user1, user2: user2, user3: user3}
end
@@ -159,6 +178,14 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
user1: user1,
user2: user2
} do
+ conn =
+ conn
+ |> put_req_header("accept", "application/json")
+ |> delete(
+ "/api/pleroma/admin/users/tag?nicknames[]=#{user1.nickname}&nicknames[]=" <>
+ "#{user2.nickname}&tags[]=x&tags[]=z"
+ )
+
assert empty_json_response(conn)
assert User.get_cached_by_id(user1.id).tags == []
assert User.get_cached_by_id(user2.id).tags == ["y"]
@@ -176,10 +203,34 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"@#{admin.nickname} removed tags: #{tags} from users: #{users}"
end
- test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
+ test "it does not modify tags of not specified users", %{
+ conn: conn,
+ user1: user1,
+ user2: user2,
+ user3: user3
+ } do
+ conn =
+ conn
+ |> put_req_header("accept", "application/json")
+ |> delete(
+ "/api/pleroma/admin/users/tag?nicknames[]=#{user1.nickname}&nicknames[]=" <>
+ "#{user2.nickname}&tags[]=x&tags[]=z"
+ )
+
assert empty_json_response(conn)
assert User.get_cached_by_id(user3.id).tags == ["unchanged"]
end
+
+ test "it requires privileged role :users_manage_tags", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ response =
+ conn
+ |> put_req_header("accept", "application/json")
+ |> delete("/api/pleroma/admin/users/tag?nicknames[]=nickname&tags[]=foo&tags[]=bar")
+
+ assert json_response(response, :forbidden)
+ end
end
describe "/api/pleroma/admin/users/:nickname/permission_group" do
@@ -267,27 +318,42 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
log_entry = Repo.one(ModerationLog)
assert ModerationLog.get_log_entry_message(log_entry) ==
- "@#{admin.nickname} revoked admin role from @#{user_one.nickname}, @#{
- user_two.nickname
- }"
+ "@#{admin.nickname} revoked admin role from @#{user_one.nickname}, @#{user_two.nickname}"
end
end
- test "/api/pleroma/admin/users/:nickname/password_reset", %{conn: conn} do
- user = insert(:user)
+ describe "/api/pleroma/admin/users/:nickname/password_reset" do
+ test "it returns a password reset link", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [:users_manage_credentials])
- conn =
- conn
- |> put_req_header("accept", "application/json")
- |> get("/api/pleroma/admin/users/#{user.nickname}/password_reset")
+ user = insert(:user)
+
+ conn =
+ conn
+ |> put_req_header("accept", "application/json")
+ |> get("/api/pleroma/admin/users/#{user.nickname}/password_reset")
+
+ resp = json_response(conn, 200)
+
+ assert Regex.match?(~r/(http:\/\/|https:\/\/)/, resp["link"])
+ end
- resp = json_response(conn, 200)
+ test "it requires privileged role :users_manage_credentials", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
- assert Regex.match?(~r/(http:\/\/|https:\/\/)/, resp["link"])
+ response =
+ conn
+ |> put_req_header("accept", "application/json")
+ |> get("/api/pleroma/admin/users/nickname/password_reset")
+
+ assert json_response(response, :forbidden)
+ end
end
describe "PUT disable_mfa" do
test "returns 200 and disable 2fa", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [:users_manage_credentials])
+
user =
insert(:user,
multi_factor_authentication_settings: %MFA.Settings{
@@ -309,6 +375,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
test "returns 404 if user not found", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [:users_manage_credentials])
+
response =
conn
|> put("/api/pleroma/admin/users/disable_mfa", %{nickname: "nickname"})
@@ -316,6 +384,16 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert response == %{"error" => "Not found"}
end
+
+ test "it requires privileged role :users_manage_credentials", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ response =
+ conn
+ |> put("/api/pleroma/admin/users/disable_mfa", %{nickname: "nickname"})
+
+ assert json_response(response, :forbidden)
+ end
end
describe "GET /api/pleroma/admin/restart" do
@@ -346,6 +424,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
describe "GET /api/pleroma/admin/users/:nickname/statuses" do
setup do
+ clear_config([:instance, :admin_privileges], [:messages_read])
+
user = insert(:user)
insert(:note_activity, user: user)
@@ -362,6 +442,14 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert length(activities) == 3
end
+ test "it requires privileged role :messages_read", %{conn: conn, user: user} do
+ clear_config([:instance, :admin_privileges], [])
+
+ conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses")
+
+ assert json_response(conn, :forbidden)
+ end
+
test "renders user's statuses with pagination", %{conn: conn, user: user} do
%{"total" => 3, "activities" => [activity1]} =
conn
@@ -423,20 +511,31 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
describe "GET /api/pleroma/admin/users/:nickname/chats" do
setup do
+ clear_config([:instance, :admin_privileges], [:messages_read])
+
user = insert(:user)
+
+ %{user: user}
+ end
+
+ test "renders user's chats", %{conn: conn, user: user} do
recipients = insert_list(3, :user)
Enum.each(recipients, fn recipient ->
CommonAPI.post_chat_message(user, recipient, "yo")
end)
- %{user: user}
+ conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/chats")
+
+ assert json_response(conn, 200) |> length() == 3
end
- test "renders user's chats", %{conn: conn, user: user} do
+ test "it requires privileged role :messages_read", %{conn: conn, user: user} do
+ clear_config([:instance, :admin_privileges], [])
+
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/chats")
- assert json_response(conn, 200) |> length() == 3
+ assert json_response(conn, :forbidden)
end
end
@@ -473,6 +572,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
describe "GET /api/pleroma/admin/moderation_log" do
setup do
+ clear_config([:instance, :admin_privileges], [:moderation_log_read])
moderator = insert(:user, is_moderator: true)
%{moderator: moderator}
@@ -677,6 +777,15 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert get_in(first_entry, ["data", "message"]) ==
"@#{moderator.nickname} unfollowed relay: https://example.org/relay"
end
+
+ test "it requires privileged role :moderation_log_read", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ assert conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> get("/api/pleroma/admin/moderation_log")
+ |> json_response(:forbidden)
+ end
end
test "gets a remote users when [:instance, :limit_to_local_content] is set to :unauthenticated",
@@ -690,6 +799,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
describe "GET /users/:nickname/credentials" do
test "gets the user credentials", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [:users_manage_credentials])
user = insert(:user)
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials")
@@ -698,6 +808,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
test "returns 403 if requested by a non-admin" do
+ clear_config([:instance, :admin_privileges], [:users_manage_credentials])
user = insert(:user)
conn =
@@ -707,6 +818,16 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert json_response(conn, :forbidden)
end
+
+ test "it requires privileged role :users_manage_credentials", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ response =
+ conn
+ |> get("/api/pleroma/admin/users/nickname/credentials")
+
+ assert json_response(response, :forbidden)
+ end
end
describe "PATCH /users/:nickname/credentials" do
@@ -716,6 +837,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
test "changes password and email", %{conn: conn, admin: admin, user: user} do
+ clear_config([:instance, :admin_privileges], [:users_manage_credentials])
+
assert user.password_reset_pending == false
conn =
@@ -758,6 +881,19 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert json_response(conn, :forbidden)
end
+ test "returns 403 if not privileged with :users_manage_credentials", %{conn: conn, user: user} do
+ clear_config([:instance, :admin_privileges], [])
+
+ conn =
+ patch(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials", %{
+ "password" => "new_password",
+ "email" => "new_email@example.com",
+ "name" => "new_name"
+ })
+
+ assert json_response(conn, :forbidden)
+ end
+
test "changes actor type from permitted list", %{conn: conn, user: user} do
assert user.actor_type == "Person"
@@ -786,6 +922,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
describe "PATCH /users/:nickname/force_password_reset" do
test "sets password_reset_pending to true", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [:users_manage_credentials])
user = insert(:user)
assert user.password_reset_pending == false
@@ -798,44 +935,21 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert User.get_by_id(user.id).password_reset_pending == true
end
- end
-
- describe "instances" do
- test "GET /instances/:instance/statuses", %{conn: conn} do
- user = insert(:user, local: false, ap_id: "https://archae.me/users/archaeme")
- user2 = insert(:user, local: false, ap_id: "https://test.com/users/test")
- insert_pair(:note_activity, user: user)
- activity = insert(:note_activity, user: user2)
-
- %{"total" => 2, "activities" => activities} =
- conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
-
- assert length(activities) == 2
-
- %{"total" => 1, "activities" => [_]} =
- conn |> get("/api/pleroma/admin/instances/test.com/statuses") |> json_response(200)
-
- %{"total" => 0, "activities" => []} =
- conn |> get("/api/pleroma/admin/instances/nonexistent.com/statuses") |> json_response(200)
- CommonAPI.repeat(activity.id, user)
+ test "it requires privileged role :users_manage_credentials", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
- %{"total" => 2, "activities" => activities} =
- conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
-
- assert length(activities) == 2
-
- %{"total" => 3, "activities" => activities} =
+ response =
conn
- |> get("/api/pleroma/admin/instances/archae.me/statuses?with_reblogs=true")
- |> json_response(200)
+ |> patch("/api/pleroma/admin/users/force_password_reset", %{nickname: "nickname"})
- assert length(activities) == 3
+ assert json_response(response, :forbidden)
end
end
describe "PATCH /confirm_email" do
test "it confirms emails of two users", %{conn: conn, admin: admin} do
+ clear_config([:instance, :admin_privileges], [:users_manage_credentials])
[first_user, second_user] = insert_pair(:user, is_confirmed: false)
refute first_user.is_confirmed
@@ -860,14 +974,23 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
log_entry = Repo.one(ModerationLog)
assert ModerationLog.get_log_entry_message(log_entry) ==
- "@#{admin.nickname} confirmed email for users: @#{first_user.nickname}, @#{
- second_user.nickname
- }"
+ "@#{admin.nickname} confirmed email for users: @#{first_user.nickname}, @#{second_user.nickname}"
+ end
+
+ test "it requires privileged role :users_manage_credentials", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ response =
+ conn
+ |> patch("/api/pleroma/admin/users/confirm_email", %{nicknames: ["nickname"]})
+
+ assert json_response(response, :forbidden)
end
end
describe "PATCH /resend_confirmation_email" do
test "it resend emails for two users", %{conn: conn, admin: admin} do
+ clear_config([:instance, :admin_privileges], [:users_manage_credentials])
[first_user, second_user] = insert_pair(:user, is_confirmed: false)
ret_conn =
@@ -883,9 +1006,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
log_entry = Repo.one(ModerationLog)
assert ModerationLog.get_log_entry_message(log_entry) ==
- "@#{admin.nickname} re-sent confirmation email for users: @#{first_user.nickname}, @#{
- second_user.nickname
- }"
+ "@#{admin.nickname} re-sent confirmation email for users: @#{first_user.nickname}, @#{second_user.nickname}"
ObanHelpers.perform_all()
@@ -895,9 +1016,23 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|> Swoosh.Email.put_private(:hackney_options, ssl_options: [versions: [:"tlsv1.2"]])
|> assert_email_sent()
end
+
+ test "it requires privileged role :users_manage_credentials", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ response =
+ conn
+ |> patch("/api/pleroma/admin/users/resend_confirmation_email", %{nicknames: ["nickname"]})
+
+ assert json_response(response, :forbidden)
+ end
end
describe "/api/pleroma/admin/stats" do
+ setup do
+ clear_config([:instance, :admin_privileges], [:statistics_read])
+ end
+
test "status visibility count", %{conn: conn} do
user = insert(:user)
CommonAPI.post(user, %{visibility: "public", status: "hey"})
@@ -930,6 +1065,14 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert %{"direct" => 0, "private" => 1, "public" => 0, "unlisted" => 1} =
response["status_visibility"]
end
+
+ test "it requires privileged role :statistics_read", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ assert conn
+ |> get("/api/pleroma/admin/stats", instance: "lain.wired")
+ |> json_response(:forbidden)
+ end
end
describe "/api/pleroma/backups" do
@@ -998,6 +1141,34 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert Repo.aggregate(Pleroma.User.Backup, :count) == 2
end
end
+
+ describe "POST /api/v1/pleroma/admin/reload_emoji" do
+ setup do
+ clear_config([:instance, :admin_privileges], [:emoji_manage_emoji])
+
+ admin = insert(:user, is_admin: true)
+ token = insert(:oauth_admin_token, user: admin)
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> assign(:token, token)
+
+ {:ok, %{conn: conn, admin: admin}}
+ end
+
+ test "it requires privileged role :emoji_manage_emoji", %{conn: conn} do
+ assert conn
+ |> post("/api/v1/pleroma/admin/reload_emoji")
+ |> json_response(200)
+
+ clear_config([:instance, :admin_privileges], [])
+
+ assert conn
+ |> post("/api/v1/pleroma/admin/reload_emoji")
+ |> json_response(:forbidden)
+ end
+ end
end
# Needed for testing
diff --git a/test/pleroma/web/admin_api/controllers/announcement_controller_test.exs b/test/pleroma/web/admin_api/controllers/announcement_controller_test.exs
new file mode 100644
index 000000000..cf60bcad5
--- /dev/null
+++ b/test/pleroma/web/admin_api/controllers/announcement_controller_test.exs
@@ -0,0 +1,375 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.AdminAPI.AnnouncementControllerTest do
+ use Pleroma.Web.ConnCase, async: false
+
+ import Pleroma.Factory
+
+ setup do
+ clear_config([:instance, :admin_privileges], [:announcements_manage_announcements])
+ admin = insert(:user, is_admin: true)
+ token = insert(:oauth_admin_token, user: admin)
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> assign(:token, token)
+
+ {:ok, %{admin: admin, token: token, conn: conn}}
+ end
+
+ describe "GET /api/v1/pleroma/admin/announcements" do
+ test "it lists all announcements", %{conn: conn} do
+ %{id: id} = insert(:announcement)
+
+ response =
+ conn
+ |> get("/api/v1/pleroma/admin/announcements")
+ |> json_response_and_validate_schema(:ok)
+
+ assert [%{"id" => ^id}] = response
+ end
+
+ test "it requires privileged role :announcements_manage_announcements", %{conn: conn} do
+ conn
+ |> get("/api/v1/pleroma/admin/announcements")
+ |> json_response_and_validate_schema(:ok)
+
+ clear_config([:instance, :admin_privileges], [])
+
+ conn
+ |> get("/api/v1/pleroma/admin/announcements")
+ |> json_response(:forbidden)
+ end
+
+ test "it paginates announcements", %{conn: conn} do
+ _announcements = Enum.map(0..20, fn _ -> insert(:announcement) end)
+
+ response =
+ conn
+ |> get("/api/v1/pleroma/admin/announcements")
+ |> json_response_and_validate_schema(:ok)
+
+ assert length(response) == 20
+ end
+
+ test "it paginates announcements with custom params", %{conn: conn} do
+ announcements = Enum.map(0..20, fn _ -> insert(:announcement) end)
+
+ response =
+ conn
+ |> get("/api/v1/pleroma/admin/announcements", limit: 5, offset: 7)
+ |> json_response_and_validate_schema(:ok)
+
+ assert length(response) == 5
+ assert Enum.at(response, 0)["id"] == Enum.at(announcements, 7).id
+ end
+
+ test "it returns empty list with out-of-bounds offset", %{conn: conn} do
+ _announcements = Enum.map(0..20, fn _ -> insert(:announcement) end)
+
+ response =
+ conn
+ |> get("/api/v1/pleroma/admin/announcements", offset: 21)
+ |> json_response_and_validate_schema(:ok)
+
+ assert [] = response
+ end
+
+ test "it rejects invalid pagination params", %{conn: conn} do
+ conn
+ |> get("/api/v1/pleroma/admin/announcements", limit: 0)
+ |> json_response_and_validate_schema(400)
+
+ conn
+ |> get("/api/v1/pleroma/admin/announcements", limit: -1)
+ |> json_response_and_validate_schema(400)
+
+ conn
+ |> get("/api/v1/pleroma/admin/announcements", offset: -1)
+ |> json_response_and_validate_schema(400)
+ end
+ end
+
+ describe "GET /api/v1/pleroma/admin/announcements/:id" do
+ test "it displays one announcement", %{conn: conn} do
+ %{id: id} = insert(:announcement)
+
+ response =
+ conn
+ |> get("/api/v1/pleroma/admin/announcements/#{id}")
+ |> json_response_and_validate_schema(:ok)
+
+ assert %{"id" => ^id} = response
+ end
+
+ test "it requires privileged role :announcements_manage_announcements", %{conn: conn} do
+ %{id: id} = insert(:announcement)
+
+ conn
+ |> get("/api/v1/pleroma/admin/announcements/#{id}")
+ |> json_response_and_validate_schema(:ok)
+
+ clear_config([:instance, :admin_privileges], [])
+
+ conn
+ |> get("/api/v1/pleroma/admin/announcements/#{id}")
+ |> json_response(:forbidden)
+ end
+
+ test "it returns not found for non-existent id", %{conn: conn} do
+ %{id: id} = insert(:announcement)
+
+ _response =
+ conn
+ |> get("/api/v1/pleroma/admin/announcements/#{id}xxx")
+ |> json_response_and_validate_schema(:not_found)
+ end
+ end
+
+ describe "DELETE /api/v1/pleroma/admin/announcements/:id" do
+ test "it deletes specified announcement", %{conn: conn} do
+ %{id: id} = insert(:announcement)
+
+ _response =
+ conn
+ |> delete("/api/v1/pleroma/admin/announcements/#{id}")
+ |> json_response_and_validate_schema(:ok)
+ end
+
+ test "it requires privileged role :announcements_manage_announcements", %{conn: conn} do
+ %{id: id} = insert(:announcement)
+
+ conn
+ |> delete("/api/v1/pleroma/admin/announcements/#{id}")
+ |> json_response_and_validate_schema(:ok)
+
+ clear_config([:instance, :admin_privileges], [])
+
+ conn
+ |> delete("/api/v1/pleroma/admin/announcements/#{id}")
+ |> json_response(:forbidden)
+ end
+
+ test "it returns not found for non-existent id", %{conn: conn} do
+ %{id: id} = insert(:announcement)
+
+ _response =
+ conn
+ |> delete("/api/v1/pleroma/admin/announcements/#{id}xxx")
+ |> json_response_and_validate_schema(:not_found)
+
+ assert %{id: ^id} = Pleroma.Announcement.get_by_id(id)
+ end
+ end
+
+ describe "PATCH /api/v1/pleroma/admin/announcements/:id" do
+ test "it returns not found for non-existent id", %{conn: conn} do
+ %{id: id} = insert(:announcement)
+
+ _response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch("/api/v1/pleroma/admin/announcements/#{id}xxx", %{})
+ |> json_response_and_validate_schema(:not_found)
+
+ assert %{id: ^id} = Pleroma.Announcement.get_by_id(id)
+ end
+
+ test "it updates a field", %{conn: conn} do
+ %{id: id} = insert(:announcement)
+
+ now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
+ starts_at = NaiveDateTime.add(now, -10, :second)
+
+ _response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch("/api/v1/pleroma/admin/announcements/#{id}", %{
+ starts_at: NaiveDateTime.to_iso8601(starts_at)
+ })
+ |> json_response_and_validate_schema(:ok)
+
+ new = Pleroma.Announcement.get_by_id(id)
+
+ assert NaiveDateTime.compare(new.starts_at, starts_at) == :eq
+ end
+
+ test "it requires privileged role :announcements_manage_announcements", %{conn: conn} do
+ %{id: id} = insert(:announcement)
+
+ now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
+ starts_at = NaiveDateTime.add(now, -10, :second)
+
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch("/api/v1/pleroma/admin/announcements/#{id}", %{
+ starts_at: NaiveDateTime.to_iso8601(starts_at)
+ })
+ |> json_response_and_validate_schema(:ok)
+
+ clear_config([:instance, :admin_privileges], [])
+
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch("/api/v1/pleroma/admin/announcements/#{id}", %{
+ starts_at: NaiveDateTime.to_iso8601(starts_at)
+ })
+ |> json_response(:forbidden)
+ end
+
+ test "it updates with time with utc timezone", %{conn: conn} do
+ %{id: id} = insert(:announcement)
+
+ now = DateTime.now("Etc/UTC") |> elem(1) |> DateTime.truncate(:second)
+ starts_at = DateTime.add(now, -10, :second)
+
+ _response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch("/api/v1/pleroma/admin/announcements/#{id}", %{
+ starts_at: DateTime.to_iso8601(starts_at)
+ })
+ |> json_response_and_validate_schema(:ok)
+
+ new = Pleroma.Announcement.get_by_id(id)
+
+ assert DateTime.compare(new.starts_at, starts_at) == :eq
+ end
+
+ test "it updates a data field", %{conn: conn} do
+ %{id: id} = announcement = insert(:announcement, data: %{"all_day" => true})
+
+ assert announcement.data["all_day"] == true
+
+ new_content = "new content"
+
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch("/api/v1/pleroma/admin/announcements/#{id}", %{
+ content: new_content
+ })
+ |> json_response_and_validate_schema(:ok)
+
+ assert response["content"] == new_content
+ assert response["all_day"] == true
+
+ new = Pleroma.Announcement.get_by_id(id)
+
+ assert new.data["content"] == new_content
+ assert new.data["all_day"] == true
+ end
+
+ test "it nullifies a nullable field", %{conn: conn} do
+ now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
+ starts_at = NaiveDateTime.add(now, -10, :second)
+
+ %{id: id} = insert(:announcement, starts_at: starts_at)
+
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch("/api/v1/pleroma/admin/announcements/#{id}", %{
+ starts_at: nil
+ })
+ |> json_response_and_validate_schema(:ok)
+
+ assert response["starts_at"] == nil
+
+ new = Pleroma.Announcement.get_by_id(id)
+
+ assert new.starts_at == nil
+ end
+ end
+
+ describe "POST /api/v1/pleroma/admin/announcements" do
+ test "it creates an announcement", %{conn: conn} do
+ content = "test post announcement api"
+
+ now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
+ starts_at = NaiveDateTime.add(now, -10, :second)
+ ends_at = NaiveDateTime.add(now, 10, :second)
+
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/pleroma/admin/announcements", %{
+ "content" => content,
+ "starts_at" => NaiveDateTime.to_iso8601(starts_at),
+ "ends_at" => NaiveDateTime.to_iso8601(ends_at),
+ "all_day" => true
+ })
+ |> json_response_and_validate_schema(:ok)
+
+ assert %{"content" => ^content, "all_day" => true} = response
+
+ announcement = Pleroma.Announcement.get_by_id(response["id"])
+
+ assert not is_nil(announcement)
+
+ assert NaiveDateTime.compare(announcement.starts_at, starts_at) == :eq
+ assert NaiveDateTime.compare(announcement.ends_at, ends_at) == :eq
+ end
+
+ test "it requires privileged role :announcements_manage_announcements", %{conn: conn} do
+ content = "test post announcement api"
+
+ now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
+ starts_at = NaiveDateTime.add(now, -10, :second)
+ ends_at = NaiveDateTime.add(now, 10, :second)
+
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/pleroma/admin/announcements", %{
+ "content" => content,
+ "starts_at" => NaiveDateTime.to_iso8601(starts_at),
+ "ends_at" => NaiveDateTime.to_iso8601(ends_at),
+ "all_day" => true
+ })
+ |> json_response_and_validate_schema(:ok)
+
+ clear_config([:instance, :admin_privileges], [])
+
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/pleroma/admin/announcements", %{
+ "content" => content,
+ "starts_at" => NaiveDateTime.to_iso8601(starts_at),
+ "ends_at" => NaiveDateTime.to_iso8601(ends_at),
+ "all_day" => true
+ })
+ |> json_response(:forbidden)
+ end
+
+ test "creating with time with utc timezones", %{conn: conn} do
+ content = "test post announcement api"
+
+ now = DateTime.now("Etc/UTC") |> elem(1) |> DateTime.truncate(:second)
+ starts_at = DateTime.add(now, -10, :second)
+ ends_at = DateTime.add(now, 10, :second)
+
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/pleroma/admin/announcements", %{
+ "content" => content,
+ "starts_at" => DateTime.to_iso8601(starts_at),
+ "ends_at" => DateTime.to_iso8601(ends_at),
+ "all_day" => true
+ })
+ |> json_response_and_validate_schema(:ok)
+
+ assert %{"content" => ^content, "all_day" => true} = response
+
+ announcement = Pleroma.Announcement.get_by_id(response["id"])
+
+ assert not is_nil(announcement)
+
+ assert DateTime.compare(announcement.starts_at, starts_at) == :eq
+ assert DateTime.compare(announcement.ends_at, ends_at) == :eq
+ end
+ end
+end
diff --git a/test/pleroma/web/admin_api/controllers/chat_controller_test.exs b/test/pleroma/web/admin_api/controllers/chat_controller_test.exs
index 0e8f7beef..1b5c31b7d 100644
--- a/test/pleroma/web/admin_api/controllers/chat_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/chat_controller_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.ChatControllerTest do
- use Pleroma.Web.ConnCase, async: true
+ use Pleroma.Web.ConnCase, async: false
import Pleroma.Factory
@@ -27,7 +27,10 @@ defmodule Pleroma.Web.AdminAPI.ChatControllerTest do
end
describe "DELETE /api/pleroma/admin/chats/:id/messages/:message_id" do
- setup do: admin_setup()
+ setup do
+ clear_config([:instance, :admin_privileges], [:messages_delete])
+ admin_setup()
+ end
test "it deletes a message from the chat", %{conn: conn, admin: admin} do
user = insert(:user)
@@ -53,17 +56,29 @@ defmodule Pleroma.Web.AdminAPI.ChatControllerTest do
log_entry = Repo.one(ModerationLog)
assert ModerationLog.get_log_entry_message(log_entry) ==
- "@#{admin.nickname} deleted chat message ##{cm_ref.id}"
+ "@#{admin.nickname} deleted chat message ##{message.id}"
assert result["id"] == cm_ref.id
refute MessageReference.get_by_id(cm_ref.id)
refute MessageReference.get_by_id(recipient_cm_ref.id)
assert %{data: %{"type" => "Tombstone"}} = Object.get_by_id(object.id)
end
+
+ test "it requires privileged role :messages_delete", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> delete("/api/pleroma/admin/chats/some_id/messages/some_ref_id")
+ |> json_response(:forbidden)
+ end
end
describe "GET /api/pleroma/admin/chats/:id/messages" do
- setup do: admin_setup()
+ setup do
+ clear_config([:instance, :admin_privileges], [:messages_read])
+ admin_setup()
+ end
test "it paginates", %{conn: conn} do
user = insert(:user)
@@ -114,10 +129,21 @@ defmodule Pleroma.Web.AdminAPI.ChatControllerTest do
assert length(result) == 3
end
+
+ test "it requires privileged role :messages_read", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ conn = get(conn, "/api/pleroma/admin/chats/some_id/messages")
+
+ assert json_response(conn, :forbidden)
+ end
end
describe "GET /api/pleroma/admin/chats/:id" do
- setup do: admin_setup()
+ setup do
+ clear_config([:instance, :admin_privileges], [:messages_read])
+ admin_setup()
+ end
test "it returns a chat", %{conn: conn} do
user = insert(:user)
@@ -135,6 +161,14 @@ defmodule Pleroma.Web.AdminAPI.ChatControllerTest do
assert %{} = result["receiver"]
refute result["account"]
end
+
+ test "it requires privileged role :messages_read", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ conn = get(conn, "/api/pleroma/admin/chats/some_id")
+
+ assert json_response(conn, :forbidden)
+ end
end
describe "unauthorized chat moderation" do
diff --git a/test/pleroma/web/admin_api/controllers/config_controller_test.exs b/test/pleroma/web/admin_api/controllers/config_controller_test.exs
index 7c786c389..9ef7c0c46 100644
--- a/test/pleroma/web/admin_api/controllers/config_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/config_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
@@ -317,14 +317,14 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
end
test "save configs setting without explicit key", %{conn: conn} do
- level = Application.get_env(:quack, :level)
- meta = Application.get_env(:quack, :meta)
- webhook_url = Application.get_env(:quack, :webhook_url)
+ adapter = Application.get_env(:http, :adapter)
+ send_user_agent = Application.get_env(:http, :send_user_agent)
+ user_agent = Application.get_env(:http, :user_agent)
on_exit(fn ->
- Application.put_env(:quack, :level, level)
- Application.put_env(:quack, :meta, meta)
- Application.put_env(:quack, :webhook_url, webhook_url)
+ Application.put_env(:http, :adapter, adapter)
+ Application.put_env(:http, :send_user_agent, send_user_agent)
+ Application.put_env(:http, :user_agent, user_agent)
end)
conn =
@@ -333,19 +333,19 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|> post("/api/pleroma/admin/config", %{
configs: [
%{
- group: ":quack",
- key: ":level",
- value: ":info"
+ group: ":http",
+ key: ":adapter",
+ value: [":someval"]
},
%{
- group: ":quack",
- key: ":meta",
- value: [":none"]
+ group: ":http",
+ key: ":send_user_agent",
+ value: true
},
%{
- group: ":quack",
- key: ":webhook_url",
- value: "https://hooks.slack.com/services/KEY"
+ group: ":http",
+ key: ":user_agent",
+ value: [":default"]
}
]
})
@@ -353,30 +353,30 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
assert json_response_and_validate_schema(conn, 200) == %{
"configs" => [
%{
- "group" => ":quack",
- "key" => ":level",
- "value" => ":info",
- "db" => [":level"]
+ "group" => ":http",
+ "key" => ":adapter",
+ "value" => [":someval"],
+ "db" => [":adapter"]
},
%{
- "group" => ":quack",
- "key" => ":meta",
- "value" => [":none"],
- "db" => [":meta"]
+ "group" => ":http",
+ "key" => ":send_user_agent",
+ "value" => true,
+ "db" => [":send_user_agent"]
},
%{
- "group" => ":quack",
- "key" => ":webhook_url",
- "value" => "https://hooks.slack.com/services/KEY",
- "db" => [":webhook_url"]
+ "group" => ":http",
+ "key" => ":user_agent",
+ "value" => [":default"],
+ "db" => [":user_agent"]
}
],
"need_reboot" => false
}
- assert Application.get_env(:quack, :level) == :info
- assert Application.get_env(:quack, :meta) == [:none]
- assert Application.get_env(:quack, :webhook_url) == "https://hooks.slack.com/services/KEY"
+ assert Application.get_env(:http, :adapter) == [:someval]
+ assert Application.get_env(:http, :send_user_agent) == true
+ assert Application.get_env(:http, :user_agent) == [:default]
end
test "saving config with partial update", %{conn: conn} do
diff --git a/test/pleroma/web/admin_api/controllers/frontend_controller_test.exs b/test/pleroma/web/admin_api/controllers/frontend_controller_test.exs
index 200682ba9..38a23b224 100644
--- a/test/pleroma/web/admin_api/controllers/frontend_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/frontend_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.FrontendControllerTest do
diff --git a/test/pleroma/web/admin_api/controllers/instance_controller_test.exs b/test/pleroma/web/admin_api/controllers/instance_controller_test.exs
new file mode 100644
index 000000000..6cca623f3
--- /dev/null
+++ b/test/pleroma/web/admin_api/controllers/instance_controller_test.exs
@@ -0,0 +1,92 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.AdminAPI.InstanceControllerTest do
+ use Pleroma.Web.ConnCase, async: false
+ use Oban.Testing, repo: Pleroma.Repo
+
+ import Pleroma.Factory
+
+ alias Pleroma.Repo
+ alias Pleroma.Tests.ObanHelpers
+ alias Pleroma.Web.CommonAPI
+
+ setup_all do
+ Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+
+ :ok
+ end
+
+ setup do
+ admin = insert(:user, is_admin: true)
+ token = insert(:oauth_admin_token, user: admin)
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> assign(:token, token)
+
+ {:ok, %{admin: admin, token: token, conn: conn}}
+ end
+
+ test "GET /instances/:instance/statuses", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [:messages_read])
+ user = insert(:user, local: false, ap_id: "https://archae.me/users/archaeme")
+ user2 = insert(:user, local: false, ap_id: "https://test.com/users/test")
+ insert_pair(:note_activity, user: user)
+ activity = insert(:note_activity, user: user2)
+
+ %{"total" => 2, "activities" => activities} =
+ conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
+
+ assert length(activities) == 2
+
+ %{"total" => 1, "activities" => [_]} =
+ conn |> get("/api/pleroma/admin/instances/test.com/statuses") |> json_response(200)
+
+ %{"total" => 0, "activities" => []} =
+ conn |> get("/api/pleroma/admin/instances/nonexistent.com/statuses") |> json_response(200)
+
+ CommonAPI.repeat(activity.id, user)
+
+ %{"total" => 2, "activities" => activities} =
+ conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
+
+ assert length(activities) == 2
+
+ %{"total" => 3, "activities" => activities} =
+ conn
+ |> get("/api/pleroma/admin/instances/archae.me/statuses?with_reblogs=true")
+ |> json_response(200)
+
+ assert length(activities) == 3
+
+ clear_config([:instance, :admin_privileges], [])
+
+ conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(:forbidden)
+ end
+
+ test "DELETE /instances/:instance", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [:instances_delete])
+ user = insert(:user, nickname: "lain@lain.com")
+ post = insert(:note_activity, user: user)
+
+ response =
+ conn
+ |> delete("/api/pleroma/admin/instances/lain.com")
+ |> json_response(200)
+
+ [:ok] = ObanHelpers.perform_all()
+
+ assert response == "lain.com"
+ refute Repo.reload(user).is_active
+ refute Repo.reload(post)
+
+ clear_config([:instance, :admin_privileges], [])
+
+ conn
+ |> delete("/api/pleroma/admin/instances/lain.com")
+ |> json_response(:forbidden)
+ end
+end
diff --git a/test/pleroma/web/admin_api/controllers/instance_document_controller_test.exs b/test/pleroma/web/admin_api/controllers/instance_document_controller_test.exs
index e100f6929..9511dccea 100644
--- a/test/pleroma/web/admin_api/controllers/instance_document_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/instance_document_controller_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.InstanceDocumentControllerTest do
- use Pleroma.Web.ConnCase, async: true
+ use Pleroma.Web.ConnCase
import Pleroma.Factory
@dir "test/tmp/instance_static"
diff --git a/test/pleroma/web/admin_api/controllers/invite_controller_test.exs b/test/pleroma/web/admin_api/controllers/invite_controller_test.exs
index 6366061c8..8051cb2e9 100644
--- a/test/pleroma/web/admin_api/controllers/invite_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/invite_controller_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.InviteControllerTest do
- use Pleroma.Web.ConnCase, async: true
+ use Pleroma.Web.ConnCase, async: false
import Pleroma.Factory
@@ -23,8 +23,25 @@ defmodule Pleroma.Web.AdminAPI.InviteControllerTest do
end
describe "POST /api/pleroma/admin/users/email_invite, with valid config" do
- setup do: clear_config([:instance, :registrations_open], false)
- setup do: clear_config([:instance, :invites_enabled], true)
+ setup do
+ clear_config([:instance, :registrations_open], false)
+ clear_config([:instance, :invites_enabled], true)
+ clear_config([:instance, :admin_privileges], [:users_manage_invites])
+ end
+
+ test "returns 403 if not privileged with :users_manage_invites", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json;charset=utf-8")
+ |> post("/api/pleroma/admin/users/email_invite", %{
+ email: "foo@bar.com",
+ name: "J. D."
+ })
+
+ assert json_response(conn, :forbidden)
+ end
test "sends invitation and returns 204", %{admin: admin, conn: conn} do
recipient_email = "foo@bar.com"
@@ -114,8 +131,11 @@ defmodule Pleroma.Web.AdminAPI.InviteControllerTest do
end
describe "POST /api/pleroma/admin/users/email_invite, with invalid config" do
- setup do: clear_config([:instance, :registrations_open])
- setup do: clear_config([:instance, :invites_enabled])
+ setup do
+ clear_config([:instance, :registrations_open])
+ clear_config([:instance, :invites_enabled])
+ clear_config([:instance, :admin_privileges], [:users_manage_invites])
+ end
test "it returns 500 if `invites_enabled` is not enabled", %{conn: conn} do
clear_config([:instance, :registrations_open], false)
@@ -157,6 +177,21 @@ defmodule Pleroma.Web.AdminAPI.InviteControllerTest do
end
describe "POST /api/pleroma/admin/users/invite_token" do
+ setup do
+ clear_config([:instance, :admin_privileges], [:users_manage_invites])
+ end
+
+ test "returns 403 if not privileged with :users_manage_invites", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/pleroma/admin/users/invite_token")
+
+ assert json_response(conn, :forbidden)
+ end
+
test "without options", %{conn: conn} do
conn =
conn
@@ -221,6 +256,18 @@ defmodule Pleroma.Web.AdminAPI.InviteControllerTest do
end
describe "GET /api/pleroma/admin/users/invites" do
+ setup do
+ clear_config([:instance, :admin_privileges], [:users_manage_invites])
+ end
+
+ test "returns 403 if not privileged with :users_manage_invites", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ conn = get(conn, "/api/pleroma/admin/users/invites")
+
+ assert json_response(conn, :forbidden)
+ end
+
test "no invites", %{conn: conn} do
conn = get(conn, "/api/pleroma/admin/users/invites")
@@ -249,6 +296,21 @@ defmodule Pleroma.Web.AdminAPI.InviteControllerTest do
end
describe "POST /api/pleroma/admin/users/revoke_invite" do
+ setup do
+ clear_config([:instance, :admin_privileges], [:users_manage_invites])
+ end
+
+ test "returns 403 if not privileged with :users_manage_invites", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/pleroma/admin/users/revoke_invite", %{"token" => "foo"})
+
+ assert json_response(conn, :forbidden)
+ end
+
test "with token", %{conn: conn} do
{:ok, invite} = UserInviteToken.create_invite()
diff --git a/test/pleroma/web/admin_api/controllers/media_proxy_cache_controller_test.exs b/test/pleroma/web/admin_api/controllers/media_proxy_cache_controller_test.exs
index 5d872901e..852334a57 100644
--- a/test/pleroma/web/admin_api/controllers/media_proxy_cache_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/media_proxy_cache_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
@@ -47,30 +47,34 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
assert response["page_size"] == 2
assert response["count"] == 5
- assert response["urls"] == [
- "http://localhost:4001/media/fb1f4d.jpg",
- "http://localhost:4001/media/a688346.jpg"
- ]
+ results = response["urls"]
response =
conn
|> get("/api/pleroma/admin/media_proxy_caches?page_size=2&page=2")
|> json_response_and_validate_schema(200)
- assert response["urls"] == [
- "http://localhost:4001/media/gb1f44.jpg",
- "http://localhost:4001/media/tb13f47.jpg"
- ]
-
assert response["page_size"] == 2
assert response["count"] == 5
+ results = results ++ response["urls"]
+
response =
conn
|> get("/api/pleroma/admin/media_proxy_caches?page_size=2&page=3")
|> json_response_and_validate_schema(200)
- assert response["urls"] == ["http://localhost:4001/media/wb1f46.jpg"]
+ results = results ++ response["urls"]
+
+ assert results |> Enum.sort() ==
+ [
+ "http://localhost:4001/media/wb1f46.jpg",
+ "http://localhost:4001/media/gb1f44.jpg",
+ "http://localhost:4001/media/tb13f47.jpg",
+ "http://localhost:4001/media/fb1f4d.jpg",
+ "http://localhost:4001/media/a688346.jpg"
+ ]
+ |> Enum.sort()
end
test "search banned MediaProxy URLs", %{conn: conn} do
@@ -88,9 +92,9 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|> get("/api/pleroma/admin/media_proxy_caches?page_size=2&query=F44")
|> json_response_and_validate_schema(200)
- assert response["urls"] == [
- "http://localhost:4001/media/gb1f44.jpg",
- "http://localhost:4001/media/ff44b1f4d.jpg"
+ assert response["urls"] |> Enum.sort() == [
+ "http://localhost:4001/media/ff44b1f4d.jpg",
+ "http://localhost:4001/media/gb1f44.jpg"
]
assert response["page_size"] == 2
diff --git a/test/pleroma/web/admin_api/controllers/o_auth_app_controller_test.exs b/test/pleroma/web/admin_api/controllers/o_auth_app_controller_test.exs
index d9b25719a..80646dd25 100644
--- a/test/pleroma/web/admin_api/controllers/o_auth_app_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/o_auth_app_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.OAuthAppControllerTest do
diff --git a/test/pleroma/web/admin_api/controllers/relay_controller_test.exs b/test/pleroma/web/admin_api/controllers/relay_controller_test.exs
index 11a480cc0..1da0fcd65 100644
--- a/test/pleroma/web/admin_api/controllers/relay_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/relay_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.RelayControllerTest do
diff --git a/test/pleroma/web/admin_api/controllers/report_controller_test.exs b/test/pleroma/web/admin_api/controllers/report_controller_test.exs
index 6a2986b5f..aee26d80a 100644
--- a/test/pleroma/web/admin_api/controllers/report_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/report_controller_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
- use Pleroma.Web.ConnCase, async: true
+ use Pleroma.Web.ConnCase, async: false
import Pleroma.Factory
@@ -26,6 +26,20 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
end
describe "GET /api/pleroma/admin/reports/:id" do
+ setup do
+ clear_config([:instance, :admin_privileges], [:reports_manage_reports])
+ end
+
+ test "returns 403 if not privileged with :reports_manage_reports", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ conn =
+ conn
+ |> get("/api/pleroma/admin/reports/report_id")
+
+ assert json_response(conn, :forbidden)
+ end
+
test "returns report by its id", %{conn: conn} do
[reporter, target_user] = insert_pair(:user)
activity = insert(:note_activity, user: target_user)
@@ -54,6 +68,32 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
assert notes["content"] == "this is an admin note"
end
+ test "renders reported content even if the status is deleted", %{conn: conn} do
+ [reporter, target_user] = insert_pair(:user)
+ activity = insert(:note_activity, user: target_user)
+ activity = Activity.normalize(activity)
+
+ {:ok, %{id: report_id}} =
+ CommonAPI.report(reporter, %{
+ account_id: target_user.id,
+ comment: "I feel offended",
+ status_ids: [activity.id]
+ })
+
+ CommonAPI.delete(activity.id, target_user)
+
+ response =
+ conn
+ |> get("/api/pleroma/admin/reports/#{report_id}")
+ |> json_response_and_validate_schema(:ok)
+
+ assert response["id"] == report_id
+
+ assert [status] = response["statuses"]
+ assert activity.object.data["id"] == status["uri"]
+ assert activity.object.data["content"] == status["content"]
+ end
+
test "returns 404 when report id is invalid", %{conn: conn} do
conn = get(conn, "/api/pleroma/admin/reports/test")
@@ -63,6 +103,8 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
describe "PATCH /api/pleroma/admin/reports" do
setup do
+ clear_config([:instance, :admin_privileges], [:reports_manage_reports])
+
[reporter, target_user] = insert_pair(:user)
activity = insert(:note_activity, user: target_user)
@@ -86,6 +128,24 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
}
end
+ test "returns 403 if not privileged with :reports_manage_reports", %{
+ conn: conn,
+ id: id,
+ admin: admin
+ } do
+ clear_config([:instance, :admin_privileges], [])
+
+ conn =
+ conn
+ |> assign(:token, insert(:oauth_token, user: admin, scopes: ["admin:write:reports"]))
+ |> put_req_header("content-type", "application/json")
+ |> patch("/api/pleroma/admin/reports", %{
+ "reports" => [%{"state" => "resolved", "id" => id}]
+ })
+
+ assert json_response(conn, :forbidden)
+ end
+
test "requires admin:write:reports scope", %{conn: conn, id: id, admin: admin} do
read_token = insert(:oauth_token, user: admin, scopes: ["admin:read"])
write_token = insert(:oauth_token, user: admin, scopes: ["admin:write:reports"])
@@ -204,13 +264,25 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
"@#{admin.nickname} updated report ##{id} (on user @#{activity.user_actor.nickname}) with 'resolved' state"
assert ModerationLog.get_log_entry_message(second_log_entry) ==
- "@#{admin.nickname} updated report ##{second_report_id} (on user @#{
- second_activity.user_actor.nickname
- }) with 'closed' state"
+ "@#{admin.nickname} updated report ##{second_report_id} (on user @#{second_activity.user_actor.nickname}) with 'closed' state"
end
end
describe "GET /api/pleroma/admin/reports" do
+ setup do
+ clear_config([:instance, :admin_privileges], [:reports_manage_reports])
+ end
+
+ test "returns 403 if not privileged with :reports_manage_reports", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ conn =
+ conn
+ |> get(report_path(conn, :index))
+
+ assert json_response(conn, :forbidden)
+ end
+
test "returns empty response when no reports created", %{conn: conn} do
response =
conn
@@ -305,7 +377,7 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
|> get("/api/pleroma/admin/reports")
assert json_response(conn, :forbidden) ==
- %{"error" => "User is not an admin."}
+ %{"error" => "User is not a staff member."}
end
test "returns 403 when requested by anonymous" do
@@ -319,6 +391,8 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
describe "POST /api/pleroma/admin/reports/:id/notes" do
setup %{conn: conn, admin: admin} do
+ clear_config([:instance, :admin_privileges], [:reports_manage_reports])
+
[reporter, target_user] = insert_pair(:user)
activity = insert(:note_activity, user: target_user)
@@ -347,6 +421,25 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
}
end
+ test "returns 403 if not privileged with :reports_manage_reports", %{
+ conn: conn,
+ report_id: report_id
+ } do
+ clear_config([:instance, :admin_privileges], [])
+
+ post_conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/pleroma/admin/reports/#{report_id}/notes", %{
+ content: "this is disgusting2!"
+ })
+
+ delete_conn = delete(conn, "/api/pleroma/admin/reports/#{report_id}/notes/note.id")
+
+ assert json_response(post_conn, :forbidden)
+ assert json_response(delete_conn, :forbidden)
+ end
+
test "it creates report note", %{admin_id: admin_id, report_id: report_id} do
assert [note, _] = Repo.all(ReportNote)
@@ -365,7 +458,8 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
[note, _] = notes
assert note["user"]["nickname"] == admin.nickname
- assert note["content"] == "this is disgusting!"
+ # We use '=~' because the order of the notes isn't guaranteed
+ assert note["content"] =~ "this is disgusting"
assert note["created_at"]
assert response["total"] == 1
end
diff --git a/test/pleroma/web/admin_api/controllers/status_controller_test.exs b/test/pleroma/web/admin_api/controllers/status_controller_test.exs
index 3fdf23ba2..8908a2812 100644
--- a/test/pleroma/web/admin_api/controllers/status_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/status_controller_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.StatusControllerTest do
- use Pleroma.Web.ConnCase, async: true
+ use Pleroma.Web.ConnCase, async: false
import Pleroma.Factory
@@ -26,6 +26,10 @@ defmodule Pleroma.Web.AdminAPI.StatusControllerTest do
end
describe "GET /api/pleroma/admin/statuses/:id" do
+ setup do
+ clear_config([:instance, :admin_privileges], [:messages_read])
+ end
+
test "not found", %{conn: conn} do
assert conn
|> get("/api/pleroma/admin/statuses/not_found")
@@ -50,10 +54,17 @@ defmodule Pleroma.Web.AdminAPI.StatusControllerTest do
assert account["is_active"] == actor.is_active
assert account["is_confirmed"] == actor.is_confirmed
end
+
+ test "denies reading activity when not privileged", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ assert conn |> get("/api/pleroma/admin/statuses/some_id") |> json_response(:forbidden)
+ end
end
describe "PUT /api/pleroma/admin/statuses/:id" do
setup do
+ clear_config([:instance, :admin_privileges], [:messages_delete])
activity = insert(:note_activity)
%{id: activity.id}
@@ -122,10 +133,20 @@ defmodule Pleroma.Web.AdminAPI.StatusControllerTest do
assert %{"error" => "test - Invalid value for enum."} =
json_response_and_validate_schema(conn, :bad_request)
end
+
+ test "it requires privileged role :messages_delete", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> put("/api/pleroma/admin/statuses/some_id", %{})
+ |> json_response(:forbidden)
+ end
end
describe "DELETE /api/pleroma/admin/statuses/:id" do
setup do
+ clear_config([:instance, :admin_privileges], [:messages_delete])
activity = insert(:note_activity)
%{id: activity.id}
@@ -149,9 +170,22 @@ defmodule Pleroma.Web.AdminAPI.StatusControllerTest do
assert json_response_and_validate_schema(conn, :not_found) == %{"error" => "Not found"}
end
+
+ test "it requires privileged role :messages_delete", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> delete("/api/pleroma/admin/statuses/some_id")
+ |> json_response(:forbidden)
+ end
end
describe "GET /api/pleroma/admin/statuses" do
+ setup do
+ clear_config([:instance, :admin_privileges], [:messages_read])
+ end
+
test "returns all public and unlisted statuses", %{conn: conn, admin: admin} do
blocked = insert(:user)
user = insert(:user)
@@ -197,5 +231,13 @@ defmodule Pleroma.Web.AdminAPI.StatusControllerTest do
conn = get(conn, "/api/pleroma/admin/statuses?godmode=true")
assert json_response_and_validate_schema(conn, 200) |> length() == 3
end
+
+ test "it requires privileged role :messages_read", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ conn = get(conn, "/api/pleroma/admin/statuses")
+
+ assert json_response(conn, :forbidden)
+ end
end
end
diff --git a/test/pleroma/web/admin_api/controllers/user_controller_test.exs b/test/pleroma/web/admin_api/controllers/user_controller_test.exs
index d9da34f6e..bb9dcb4aa 100644
--- a/test/pleroma/web/admin_api/controllers/user_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/user_controller_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.UserControllerTest do
- use Pleroma.Web.ConnCase
+ use Pleroma.Web.ConnCase, async: false
use Oban.Testing, repo: Pleroma.Repo
import Mock
@@ -38,6 +38,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
end
test "with valid `admin_token` query parameter, skips OAuth scopes check" do
+ clear_config([:instance, :admin_privileges], [:users_read])
clear_config([:admin_token], "password123")
user = insert(:user)
@@ -47,53 +48,10 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
assert json_response_and_validate_schema(conn, 200)
end
- test "GET /api/pleroma/admin/users/:nickname requires admin:read:accounts or broader scope",
- %{admin: admin} do
- user = insert(:user)
- url = "/api/pleroma/admin/users/#{user.nickname}"
-
- good_token1 = insert(:oauth_token, user: admin, scopes: ["admin"])
- good_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read"])
- good_token3 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts"])
-
- bad_token1 = insert(:oauth_token, user: admin, scopes: ["read:accounts"])
- bad_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts:partial"])
- bad_token3 = nil
-
- for good_token <- [good_token1, good_token2, good_token3] do
- conn =
- build_conn()
- |> assign(:user, admin)
- |> assign(:token, good_token)
- |> get(url)
-
- assert json_response_and_validate_schema(conn, 200)
- end
-
- for good_token <- [good_token1, good_token2, good_token3] do
- conn =
- build_conn()
- |> assign(:user, nil)
- |> assign(:token, good_token)
- |> get(url)
-
- assert json_response(conn, :forbidden)
- end
-
- for bad_token <- [bad_token1, bad_token2, bad_token3] do
- conn =
- build_conn()
- |> assign(:user, admin)
- |> assign(:token, bad_token)
- |> get(url)
-
- assert json_response_and_validate_schema(conn, :forbidden)
- end
- end
-
describe "DELETE /api/pleroma/admin/users" do
test "single user", %{admin: admin, conn: conn} do
clear_config([:instance, :federating], true)
+ clear_config([:instance, :admin_privileges], [:users_delete])
user =
insert(:user,
@@ -149,6 +107,8 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
end
test "multiple users", %{admin: admin, conn: conn} do
+ clear_config([:instance, :admin_privileges], [:users_delete])
+
user_one = insert(:user)
user_two = insert(:user)
@@ -168,6 +128,17 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
assert response -- [user_one.nickname, user_two.nickname] == []
end
+
+ test "Needs privileged role", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ response =
+ conn
+ |> put_req_header("accept", "application/json")
+ |> delete("/api/pleroma/admin/users?nickname=nickname")
+
+ assert json_response(response, :forbidden)
+ end
end
describe "/api/pleroma/admin/users" do
@@ -307,7 +278,19 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
end
end
- describe "/api/pleroma/admin/users/:nickname" do
+ describe "GET /api/pleroma/admin/users/:nickname" do
+ setup do
+ clear_config([:instance, :admin_privileges], [:users_read])
+ end
+
+ test "returns 403 if not privileged with :users_read", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ conn = get(conn, "/api/pleroma/admin/users/user.nickname")
+
+ assert json_response(conn, :forbidden)
+ end
+
test "Show", %{conn: conn} do
user = insert(:user)
@@ -323,6 +306,50 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
assert %{"error" => "Not found"} == json_response_and_validate_schema(conn, 404)
end
+
+ test "requires admin:read:accounts or broader scope",
+ %{admin: admin} do
+ user = insert(:user)
+ url = "/api/pleroma/admin/users/#{user.nickname}"
+
+ good_token1 = insert(:oauth_token, user: admin, scopes: ["admin"])
+ good_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read"])
+ good_token3 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts"])
+
+ bad_token1 = insert(:oauth_token, user: admin, scopes: ["read:accounts"])
+ bad_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts:partial"])
+ bad_token3 = nil
+
+ for good_token <- [good_token1, good_token2, good_token3] do
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> assign(:token, good_token)
+ |> get(url)
+
+ assert json_response_and_validate_schema(conn, 200)
+ end
+
+ for good_token <- [good_token1, good_token2, good_token3] do
+ conn =
+ build_conn()
+ |> assign(:user, nil)
+ |> assign(:token, good_token)
+ |> get(url)
+
+ assert json_response(conn, :forbidden)
+ end
+
+ for bad_token <- [bad_token1, bad_token2, bad_token3] do
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> assign(:token, bad_token)
+ |> get(url)
+
+ assert json_response_and_validate_schema(conn, :forbidden)
+ end
+ end
end
describe "/api/pleroma/admin/users/follow" do
@@ -378,6 +405,18 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
end
describe "GET /api/pleroma/admin/users" do
+ setup do
+ clear_config([:instance, :admin_privileges], [:users_read])
+ end
+
+ test "returns 403 if not privileged with :users_read", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ conn = get(conn, "/api/pleroma/admin/users?page=1")
+
+ assert json_response(conn, :forbidden)
+ end
+
test "renders users array for the first page", %{conn: conn, admin: admin} do
user = insert(:user, local: false, tags: ["foo", "bar"])
user2 = insert(:user, is_approved: false, registration_reason: "I'm a chill dude")
@@ -810,87 +849,201 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
end
end
- test "PATCH /api/pleroma/admin/users/activate", %{admin: admin, conn: conn} do
- user_one = insert(:user, is_active: false)
- user_two = insert(:user, is_active: false)
+ test "PATCH /api/pleroma/admin/users/approve", %{admin: admin, conn: conn} do
+ clear_config([:instance, :admin_privileges], [:users_manage_invites])
+
+ user_one = insert(:user, is_approved: false)
+ user_two = insert(:user, is_approved: false)
conn =
conn
|> put_req_header("content-type", "application/json")
|> patch(
- "/api/pleroma/admin/users/activate",
+ "/api/pleroma/admin/users/approve",
%{nicknames: [user_one.nickname, user_two.nickname]}
)
response = json_response_and_validate_schema(conn, 200)
- assert Enum.map(response["users"], & &1["is_active"]) == [true, true]
+ assert Enum.map(response["users"], & &1["is_approved"]) == [true, true]
log_entry = Repo.one(ModerationLog)
assert ModerationLog.get_log_entry_message(log_entry) ==
- "@#{admin.nickname} activated users: @#{user_one.nickname}, @#{user_two.nickname}"
+ "@#{admin.nickname} approved users: @#{user_one.nickname}, @#{user_two.nickname}"
end
- test "PATCH /api/pleroma/admin/users/deactivate", %{admin: admin, conn: conn} do
- user_one = insert(:user, is_active: true)
- user_two = insert(:user, is_active: true)
+ test "PATCH /api/pleroma/admin/users/approve returns 403 if not privileged with :users_manage_invites",
+ %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
conn =
conn
|> put_req_header("content-type", "application/json")
|> patch(
- "/api/pleroma/admin/users/deactivate",
- %{nicknames: [user_one.nickname, user_two.nickname]}
+ "/api/pleroma/admin/users/approve",
+ %{nicknames: ["user_one.nickname", "user_two.nickname"]}
)
- response = json_response_and_validate_schema(conn, 200)
- assert Enum.map(response["users"], & &1["is_active"]) == [false, false]
-
- log_entry = Repo.one(ModerationLog)
-
- assert ModerationLog.get_log_entry_message(log_entry) ==
- "@#{admin.nickname} deactivated users: @#{user_one.nickname}, @#{user_two.nickname}"
+ assert json_response(conn, :forbidden)
end
- test "PATCH /api/pleroma/admin/users/approve", %{admin: admin, conn: conn} do
- user_one = insert(:user, is_approved: false)
- user_two = insert(:user, is_approved: false)
+ test "PATCH /api/pleroma/admin/users/suggest", %{admin: admin, conn: conn} do
+ user1 = insert(:user, is_suggested: false)
+ user2 = insert(:user, is_suggested: false)
- conn =
+ response =
conn
|> put_req_header("content-type", "application/json")
|> patch(
- "/api/pleroma/admin/users/approve",
- %{nicknames: [user_one.nickname, user_two.nickname]}
+ "/api/pleroma/admin/users/suggest",
+ %{nicknames: [user1.nickname, user2.nickname]}
)
+ |> json_response_and_validate_schema(200)
- response = json_response_and_validate_schema(conn, 200)
- assert Enum.map(response["users"], & &1["is_approved"]) == [true, true]
+ assert Enum.map(response["users"], & &1["is_suggested"]) == [true, true]
+ [user1, user2] = Repo.reload!([user1, user2])
+
+ assert user1.is_suggested
+ assert user2.is_suggested
log_entry = Repo.one(ModerationLog)
assert ModerationLog.get_log_entry_message(log_entry) ==
- "@#{admin.nickname} approved users: @#{user_one.nickname}, @#{user_two.nickname}"
+ "@#{admin.nickname} added suggested users: @#{user1.nickname}, @#{user2.nickname}"
end
- test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation", %{admin: admin, conn: conn} do
- user = insert(:user)
+ test "PATCH /api/pleroma/admin/users/unsuggest", %{admin: admin, conn: conn} do
+ user1 = insert(:user, is_suggested: true)
+ user2 = insert(:user, is_suggested: true)
- conn =
+ response =
conn
|> put_req_header("content-type", "application/json")
- |> patch("/api/pleroma/admin/users/#{user.nickname}/toggle_activation")
+ |> patch(
+ "/api/pleroma/admin/users/unsuggest",
+ %{nicknames: [user1.nickname, user2.nickname]}
+ )
+ |> json_response_and_validate_schema(200)
+
+ assert Enum.map(response["users"], & &1["is_suggested"]) == [false, false]
+ [user1, user2] = Repo.reload!([user1, user2])
- assert json_response_and_validate_schema(conn, 200) ==
- user_response(
- user,
- %{"is_active" => !user.is_active}
- )
+ refute user1.is_suggested
+ refute user2.is_suggested
log_entry = Repo.one(ModerationLog)
assert ModerationLog.get_log_entry_message(log_entry) ==
- "@#{admin.nickname} deactivated users: @#{user.nickname}"
+ "@#{admin.nickname} removed suggested users: @#{user1.nickname}, @#{user2.nickname}"
+ end
+
+ describe "user activation" do
+ test "PATCH /api/pleroma/admin/users/activate", %{admin: admin, conn: conn} do
+ clear_config([:instance, :admin_privileges], [:users_manage_activation_state])
+
+ user_one = insert(:user, is_active: false)
+ user_two = insert(:user, is_active: false)
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch(
+ "/api/pleroma/admin/users/activate",
+ %{nicknames: [user_one.nickname, user_two.nickname]}
+ )
+
+ response = json_response_and_validate_schema(conn, 200)
+ assert Enum.map(response["users"], & &1["is_active"]) == [true, true]
+
+ log_entry = Repo.one(ModerationLog)
+
+ assert ModerationLog.get_log_entry_message(log_entry) ==
+ "@#{admin.nickname} activated users: @#{user_one.nickname}, @#{user_two.nickname}"
+ end
+
+ test "PATCH /api/pleroma/admin/users/deactivate", %{admin: admin, conn: conn} do
+ clear_config([:instance, :admin_privileges], [:users_manage_activation_state])
+
+ user_one = insert(:user, is_active: true)
+ user_two = insert(:user, is_active: true)
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch(
+ "/api/pleroma/admin/users/deactivate",
+ %{nicknames: [user_one.nickname, user_two.nickname]}
+ )
+
+ response = json_response_and_validate_schema(conn, 200)
+ assert Enum.map(response["users"], & &1["is_active"]) == [false, false]
+
+ log_entry = Repo.one(ModerationLog)
+
+ assert ModerationLog.get_log_entry_message(log_entry) ==
+ "@#{admin.nickname} deactivated users: @#{user_one.nickname}, @#{user_two.nickname}"
+ end
+
+ test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation", %{admin: admin, conn: conn} do
+ clear_config([:instance, :admin_privileges], [:users_manage_activation_state])
+
+ user = insert(:user)
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch("/api/pleroma/admin/users/#{user.nickname}/toggle_activation")
+
+ assert json_response_and_validate_schema(conn, 200) ==
+ user_response(
+ user,
+ %{"is_active" => !user.is_active}
+ )
+
+ log_entry = Repo.one(ModerationLog)
+
+ assert ModerationLog.get_log_entry_message(log_entry) ==
+ "@#{admin.nickname} deactivated users: @#{user.nickname}"
+ end
+
+ test "it requires privileged role :statuses_activation to activate", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch(
+ "/api/pleroma/admin/users/activate",
+ %{nicknames: ["user_one.nickname", "user_two.nickname"]}
+ )
+
+ assert json_response(conn, :forbidden)
+ end
+
+ test "it requires privileged role :statuses_activation to deactivate", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch(
+ "/api/pleroma/admin/users/deactivate",
+ %{nicknames: ["user_one.nickname", "user_two.nickname"]}
+ )
+
+ assert json_response(conn, :forbidden)
+ end
+
+ test "it requires privileged role :statuses_activation to toggle activation", %{conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch("/api/pleroma/admin/users/user.nickname/toggle_activation")
+
+ assert json_response(conn, :forbidden)
+ end
end
defp user_response(user, attrs \\ %{}) do
@@ -906,6 +1059,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
"display_name" => HTML.strip_tags(user.name || user.nickname),
"is_confirmed" => true,
"is_approved" => true,
+ "is_suggested" => false,
"url" => user.ap_id,
"registration_reason" => nil,
"actor_type" => "Person",
diff --git a/test/pleroma/web/admin_api/search_test.exs b/test/pleroma/web/admin_api/search_test.exs
index 2335c5228..e19316775 100644
--- a/test/pleroma/web/admin_api/search_test.exs
+++ b/test/pleroma/web/admin_api/search_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.SearchTest do
diff --git a/test/pleroma/web/admin_api/views/account_view_test.exs b/test/pleroma/web/admin_api/views/account_view_test.exs
index 025726c73..aecaf086c 100644
--- a/test/pleroma/web/admin_api/views/account_view_test.exs
+++ b/test/pleroma/web/admin_api/views/account_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.AccountViewTest do
diff --git a/test/pleroma/web/admin_api/views/moderation_log_view_test.exs b/test/pleroma/web/admin_api/views/moderation_log_view_test.exs
index 4efe4c4c8..3a317da35 100644
--- a/test/pleroma/web/admin_api/views/moderation_log_view_test.exs
+++ b/test/pleroma/web/admin_api/views/moderation_log_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.ModerationLogViewTest do
use Pleroma.DataCase, async: true
diff --git a/test/pleroma/web/admin_api/views/report_view_test.exs b/test/pleroma/web/admin_api/views/report_view_test.exs
index 093e2d95d..9637c2b90 100644
--- a/test/pleroma/web/admin_api/views/report_view_test.exs
+++ b/test/pleroma/web/admin_api/views/report_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.ReportViewTest do
diff --git a/test/pleroma/web/api_spec/schema_examples_test.exs b/test/pleroma/web/api_spec/schema_examples_test.exs
index 981890d77..0938d867f 100644
--- a/test/pleroma/web/api_spec/schema_examples_test.exs
+++ b/test/pleroma/web/api_spec/schema_examples_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ApiSpec.SchemaExamplesTest do
diff --git a/test/pleroma/web/auth/auth_controller_test.exs b/test/pleroma/web/auth/auth_controller_test.exs
index a869389e3..cb6d71006 100644
--- a/test/pleroma/web/auth/auth_controller_test.exs
+++ b/test/pleroma/web/auth/auth_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Auth.AuthControllerTest do
diff --git a/test/pleroma/web/auth/authenticator_test.exs b/test/pleroma/web/auth/authenticator_test.exs
index 26779df03..bac796cd2 100644
--- a/test/pleroma/web/auth/authenticator_test.exs
+++ b/test/pleroma/web/auth/authenticator_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Auth.AuthenticatorTest do
diff --git a/test/pleroma/web/auth/basic_auth_test.exs b/test/pleroma/web/auth/basic_auth_test.exs
index 2816aae4c..9d9fdfd16 100644
--- a/test/pleroma/web/auth/basic_auth_test.exs
+++ b/test/pleroma/web/auth/basic_auth_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Auth.BasicAuthTest do
diff --git a/test/pleroma/web/auth/pleroma_authenticator_test.exs b/test/pleroma/web/auth/pleroma_authenticator_test.exs
index b1397c523..7f6d63ff3 100644
--- a/test/pleroma/web/auth/pleroma_authenticator_test.exs
+++ b/test/pleroma/web/auth/pleroma_authenticator_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Auth.PleromaAuthenticatorTest do
diff --git a/test/pleroma/web/auth/totp_authenticator_test.exs b/test/pleroma/web/auth/totp_authenticator_test.exs
index ac4209f2d..09a157c51 100644
--- a/test/pleroma/web/auth/totp_authenticator_test.exs
+++ b/test/pleroma/web/auth/totp_authenticator_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Auth.TOTPAuthenticatorTest do
diff --git a/test/pleroma/web/common_api/utils_test.exs b/test/pleroma/web/common_api/utils_test.exs
index b0e567ff0..b538c5979 100644
--- a/test/pleroma/web/common_api/utils_test.exs
+++ b/test/pleroma/web/common_api/utils_test.exs
@@ -1,10 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.CommonAPI.UtilsTest do
alias Pleroma.Builders.UserBuilder
- alias Pleroma.Object
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.CommonAPI.ActivityDraft
alias Pleroma.Web.CommonAPI.Utils
@@ -160,11 +159,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{output, _, _} = Utils.format_input(text, "text/markdown")
assert output ==
- ~s(<p><strong>hello world</strong></p><p><em>another <span class="h-card"><a class="u-url mention" data-user="#{
- user.id
- }" href="http://foo.com/user__test" rel="ugc">@<span>user__test</span></a></span> and <span class="h-card"><a class="u-url mention" data-user="#{
- user.id
- }" href="http://foo.com/user__test" rel="ugc">@<span>user__test</span></a></span> <a href="http://google.com" rel="ugc">google.com</a> paragraph</em></p>)
+ ~s(<p><strong>hello world</strong></p><p><em>another <span class="h-card"><a class="u-url mention" data-user="#{user.id}" href="http://foo.com/user__test" rel="ugc">@<span>user__test</span></a></span> and <span class="h-card"><a class="u-url mention" data-user="#{user.id}" href="http://foo.com/user__test" rel="ugc">@<span>user__test</span></a></span> <a href="http://google.com" rel="ugc">google.com</a> paragraph</em></p>)
end
end
@@ -201,11 +196,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{result, _, []} = Utils.format_input(code, "text/markdown")
assert result ==
- ~s[<p><span class="h-card"><a class="u-url mention" data-user="#{mario.id}" href="#{
- mario.ap_id
- }" rel="ugc">@<span>mario</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{
- luigi.id
- }" href="#{luigi.ap_id}" rel="ugc">@<span>luigi</span></a></span> yo what’s up?</p>]
+ ~s[<p><span class="h-card"><a class="u-url mention" data-user="#{mario.id}" href="#{mario.ap_id}" rel="ugc">@<span>mario</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{luigi.id}" href="#{luigi.ap_id}" rel="ugc">@<span>luigi</span></a></span> yo what’s up?</p>]
end
test "remote mentions" do
@@ -216,11 +207,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{result, _, []} = Utils.format_input(code, "text/markdown")
assert result ==
- ~s[<p><span class="h-card"><a class="u-url mention" data-user="#{mario.id}" href="#{
- mario.ap_id
- }" rel="ugc">@<span>mario</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{
- luigi.id
- }" href="#{luigi.ap_id}" rel="ugc">@<span>luigi</span></a></span> yo what’s up?</p>]
+ ~s[<p><span class="h-card"><a class="u-url mention" data-user="#{mario.id}" href="#{mario.ap_id}" rel="ugc">@<span>mario</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{luigi.id}" href="#{luigi.ap_id}" rel="ugc">@<span>luigi</span></a></span> yo what’s up?</p>]
end
test "raw HTML" do
@@ -285,22 +272,6 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
end
end
- describe "context_to_conversation_id" do
- test "creates a mapping object" do
- conversation_id = Utils.context_to_conversation_id("random context")
- object = Object.get_by_ap_id("random context")
-
- assert conversation_id == object.id
- end
-
- test "returns an existing mapping for an existing object" do
- {:ok, object} = Object.context_mapping("random context") |> Repo.insert()
- conversation_id = Utils.context_to_conversation_id("random context")
-
- assert conversation_id == object.id
- end
- end
-
describe "formats date to asctime" do
test "when date is in ISO 8601 format" do
date = DateTime.utc_now() |> DateTime.to_iso8601()
@@ -321,7 +292,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert capture_log(fn ->
assert Utils.date_to_asctime(date) == expected
- end) =~ "[warn] Date #{date} in wrong format, must be ISO 8601"
+ end) =~ "Date #{date} in wrong format, must be ISO 8601"
end
test "when date is a Unix timestamp" do
@@ -331,7 +302,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert capture_log(fn ->
assert Utils.date_to_asctime(date) == expected
- end) =~ "[warn] Date #{date} in wrong format, must be ISO 8601"
+ end) =~ "Date #{date} in wrong format, must be ISO 8601"
end
test "when date is nil" do
@@ -339,13 +310,13 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert capture_log(fn ->
assert Utils.date_to_asctime(nil) == expected
- end) =~ "[warn] Date in wrong format, must be ISO 8601"
+ end) =~ "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) =~ "Date foo in wrong format, must be ISO 8601"
end
end
@@ -529,17 +500,6 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
end
end
- describe "conversation_id_to_context/1" do
- test "returns id" do
- object = insert(:note)
- assert Utils.conversation_id_to_context(object.id) == object.data["id"]
- end
-
- test "returns error if object not found" do
- assert Utils.conversation_id_to_context("123") == {:error, "No such conversation"}
- end
- end
-
describe "maybe_notify_mentioned_recipients/2" do
test "returns recipients when activity is not `Create`" do
activity = insert(:like_activity)
@@ -681,41 +641,6 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
end
end
- describe "make_note_data/1" do
- test "returns note data" do
- user = insert(:user)
- note = insert(:note)
- user2 = insert(:user)
- user3 = insert(:user)
-
- draft = %ActivityDraft{
- user: user,
- to: [user2.ap_id],
- context: "2hu",
- content_html: "<h1>This is :moominmamma: note</h1>",
- in_reply_to: note.id,
- tags: [name: "jimm"],
- summary: "test summary",
- cc: [user3.ap_id],
- extra: %{"custom_tag" => "test"}
- }
-
- assert Utils.make_note_data(draft) == %{
- "actor" => user.ap_id,
- "attachment" => [],
- "cc" => [user3.ap_id],
- "content" => "<h1>This is :moominmamma: note</h1>",
- "context" => "2hu",
- "sensitive" => false,
- "summary" => "test summary",
- "tag" => ["jimm"],
- "to" => [user2.ap_id],
- "type" => "Note",
- "custom_tag" => "test"
- }
- end
- end
-
describe "maybe_add_attachments/3" do
test "returns parsed results when attachment_links is false" do
assert Utils.maybe_add_attachments(
diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs
index a5dfd3934..44355c26d 100644
--- a/test/pleroma/web/common_api_test.exs
+++ b/test/pleroma/web/common_api_test.exs
@@ -1,10 +1,10 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.CommonAPITest do
use Oban.Testing, repo: Pleroma.Repo
- use Pleroma.DataCase
+ use Pleroma.DataCase, async: false
alias Pleroma.Activity
alias Pleroma.Chat
@@ -18,6 +18,7 @@ defmodule Pleroma.Web.CommonAPITest do
alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.AdminAPI.AccountView
alias Pleroma.Web.CommonAPI
+ alias Pleroma.Workers.PollWorker
import Pleroma.Factory
import Mock
@@ -48,15 +49,23 @@ defmodule Pleroma.Web.CommonAPITest do
assert object.data["type"] == "Question"
assert object.data["oneOf"] |> length() == 2
+
+ assert_enqueued(
+ worker: PollWorker,
+ args: %{op: "poll_end", activity_id: activity.id},
+ scheduled_at: NaiveDateTime.from_iso8601!(object.data["closed"])
+ )
end
end
describe "blocking" do
setup do
blocker = insert(:user)
- blocked = insert(:user)
- User.follow(blocker, blocked)
- User.follow(blocked, blocker)
+ blocked = insert(:user, local: false)
+ CommonAPI.follow(blocker, blocked)
+ CommonAPI.follow(blocked, blocker)
+ CommonAPI.accept_follow_request(blocker, blocked)
+ CommonAPI.accept_follow_request(blocked, blocked)
%{blocker: blocker, blocked: blocked}
end
@@ -65,6 +74,9 @@ defmodule Pleroma.Web.CommonAPITest do
with_mock Pleroma.Web.Federator,
publish: fn _ -> nil end do
+ assert User.get_follow_state(blocker, blocked) == :follow_accept
+ refute is_nil(Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(blocker, blocked))
+
assert {:ok, block} = CommonAPI.block(blocker, blocked)
assert block.local
@@ -72,6 +84,11 @@ defmodule Pleroma.Web.CommonAPITest do
refute User.following?(blocker, blocked)
refute User.following?(blocked, blocker)
+ refute User.get_follow_state(blocker, blocked)
+
+ assert %{data: %{"state" => "reject"}} =
+ Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(blocker, blocked)
+
assert called(Pleroma.Web.Federator.publish(block))
end
end
@@ -202,9 +219,7 @@ defmodule Pleroma.Web.CommonAPITest do
object = Object.normalize(activity, fetch: false)
assert object.data["content"] ==
- "<a href=\"https://example.org\" rel=\"ugc\">https://example.org</a> is the site of <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{
- other_user.id
- }\" href=\"#{other_user.ap_id}\" rel=\"ugc\">@<span>#{other_user.nickname}</span></a></span> <a class=\"hashtag\" data-tag=\"2hu\" href=\"http://localhost:4001/tag/2hu\">#2hu</a>"
+ "<a href=\"https://example.org\" rel=\"ugc\">https://example.org</a> is the site of <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{other_user.id}\" href=\"#{other_user.ap_id}\" rel=\"ugc\">@<span>#{other_user.nickname}</span></a></span> <a class=\"hashtag\" data-tag=\"2hu\" href=\"http://localhost:4001/tag/2hu\">#2hu</a>"
end
test "it posts a chat message" do
@@ -316,7 +331,7 @@ defmodule Pleroma.Web.CommonAPITest do
refute Activity.get_by_id(post.id)
end
- test "it does not allow a user to delete their posts" do
+ test "it does not allow a user to delete posts from another user" do
user = insert(:user)
other_user = insert(:user)
@@ -326,7 +341,8 @@ defmodule Pleroma.Web.CommonAPITest do
assert Activity.get_by_id(post.id)
end
- test "it allows moderators to delete other user's posts" do
+ test "it allows privileged users to delete other user's posts" do
+ clear_config([:instance, :moderator_privileges], [:messages_delete])
user = insert(:user)
moderator = insert(:user, is_moderator: true)
@@ -338,19 +354,20 @@ defmodule Pleroma.Web.CommonAPITest do
refute Activity.get_by_id(post.id)
end
- test "it allows admins to delete other user's posts" do
+ test "it doesn't allow unprivileged mods or admins to delete other user's posts" do
+ clear_config([:instance, :admin_privileges], [])
+ clear_config([:instance, :moderator_privileges], [])
user = insert(:user)
- moderator = insert(:user, is_admin: true)
+ moderator = insert(:user, is_moderator: true, is_admin: true)
{:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
- assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
- assert delete.local
-
- refute Activity.get_by_id(post.id)
+ assert {:error, "Could not delete"} = CommonAPI.delete(post.id, moderator)
+ assert Activity.get_by_id(post.id)
end
- test "superusers deleting non-local posts won't federate the delete" do
+ test "privileged users deleting non-local posts won't federate the delete" do
+ clear_config([:instance, :admin_privileges], [:messages_delete])
# This is the user of the ingested activity
_user =
insert(:user,
@@ -359,7 +376,7 @@ defmodule Pleroma.Web.CommonAPITest do
last_refreshed_at: NaiveDateTime.utc_now()
)
- moderator = insert(:user, is_admin: true)
+ admin = insert(:user, is_admin: true)
data =
File.read!("test/fixtures/mastodon-post-activity.json")
@@ -369,7 +386,7 @@ defmodule Pleroma.Web.CommonAPITest do
with_mock Pleroma.Web.Federator,
publish: fn _ -> nil end do
- assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
+ assert {:ok, delete} = CommonAPI.delete(post.id, admin)
assert delete.local
refute called(Pleroma.Web.Federator.publish(:_))
end
@@ -581,7 +598,7 @@ defmodule Pleroma.Web.CommonAPITest do
object = Object.normalize(activity, fetch: false)
assert object.data["content"] == "<p><b>2hu</b></p>alert(&#39;xss&#39;)"
- assert object.data["source"] == post
+ assert object.data["source"]["content"] == post
end
test "it filters out obviously bad tags when accepting a post as Markdown" do
@@ -598,7 +615,7 @@ defmodule Pleroma.Web.CommonAPITest do
object = Object.normalize(activity, fetch: false)
assert object.data["content"] == "<p><b>2hu</b></p>"
- assert object.data["source"] == post
+ assert object.data["source"]["content"] == post
end
test "it does not allow replies to direct messages that are not direct messages themselves" do
@@ -678,6 +695,32 @@ defmodule Pleroma.Web.CommonAPITest do
assert {:ok, _activity} = CommonAPI.post(user, %{status: "12345"})
end
+ test "it validates media attachment limits are correctly enforced" do
+ clear_config([:instance, :max_media_attachments], 4)
+
+ user = insert(:user)
+
+ file = %Plug.Upload{
+ content_type: "image/jpeg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
+
+ assert {:error, "Too many attachments"} =
+ CommonAPI.post(user, %{
+ status: "",
+ media_ids: List.duplicate(upload.id, 5)
+ })
+
+ assert {:ok, _activity} =
+ CommonAPI.post(user, %{
+ status: "",
+ media_ids: [upload.id]
+ })
+ end
+
test "it can handle activities that expire" do
user = insert(:user)
@@ -1059,10 +1102,11 @@ defmodule Pleroma.Web.CommonAPITest do
target_user = insert(:user)
{:ok, activity} = CommonAPI.post(target_user, %{status: "foobar"})
+ activity = Activity.normalize(activity)
reporter_ap_id = reporter.ap_id
target_ap_id = target_user.ap_id
- activity_ap_id = activity.data["id"]
+ reported_object_ap_id = activity.object.data["id"]
comment = "foobar"
report_data = %{
@@ -1073,7 +1117,7 @@ defmodule Pleroma.Web.CommonAPITest do
note_obj = %{
"type" => "Note",
- "id" => activity_ap_id,
+ "id" => reported_object_ap_id,
"content" => "foobar",
"published" => activity.object.data["published"],
"actor" => AccountView.render("show.json", %{user: target_user})
@@ -1095,6 +1139,7 @@ defmodule Pleroma.Web.CommonAPITest do
test "updates report state" do
[reporter, target_user] = insert_pair(:user)
activity = insert(:note_activity, user: target_user)
+ object = Object.normalize(activity)
{:ok, %Activity{id: report_id}} =
CommonAPI.report(reporter, %{
@@ -1107,10 +1152,36 @@ defmodule Pleroma.Web.CommonAPITest do
assert report.data["state"] == "resolved"
- [reported_user, activity_id] = report.data["object"]
+ [reported_user, object_id] = report.data["object"]
+
+ assert reported_user == target_user.ap_id
+ assert object_id == object.data["id"]
+ end
+
+ test "updates report state, don't strip when report_strip_status is false" do
+ clear_config([:instance, :report_strip_status], false)
+
+ [reporter, target_user] = insert_pair(:user)
+ activity = insert(:note_activity, user: target_user)
+
+ {:ok, %Activity{id: report_id, data: report_data}} =
+ CommonAPI.report(reporter, %{
+ account_id: target_user.id,
+ comment: "I feel offended",
+ status_ids: [activity.id]
+ })
+
+ {:ok, report} = CommonAPI.update_report_state(report_id, "resolved")
+
+ assert report.data["state"] == "resolved"
+
+ [reported_user, reported_activity] = report.data["object"]
assert reported_user == target_user.ap_id
- assert activity_id == activity.data["id"]
+ assert is_map(reported_activity)
+
+ assert reported_activity["content"] ==
+ report_data["object"] |> Enum.at(1) |> Map.get("content")
end
test "does not update report state when state is unsupported" do
@@ -1202,6 +1273,18 @@ defmodule Pleroma.Web.CommonAPITest do
refute User.subscribed_to?(follower, followed)
end
+ test "also unpins a user" do
+ [follower, followed] = insert_pair(:user)
+ {:ok, follower, followed, _} = CommonAPI.follow(follower, followed)
+ {:ok, _endorsement} = User.endorse(follower, followed)
+
+ assert User.endorses?(follower, followed)
+
+ {:ok, follower} = CommonAPI.unfollow(follower, followed)
+
+ refute User.endorses?(follower, followed)
+ end
+
test "cancels a pending follow for a local user" do
follower = insert(:user)
followed = insert(:user, is_locked: true)
@@ -1498,4 +1581,128 @@ defmodule Pleroma.Web.CommonAPITest do
end
end
end
+
+ describe "update/3" do
+ test "updates a post" do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1"})
+
+ {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2"})
+
+ updated_object = Object.normalize(updated)
+ assert updated_object.data["content"] == "updated 2"
+ assert Map.get(updated_object.data, "summary", "") == ""
+ assert Map.has_key?(updated_object.data, "updated")
+ end
+
+ test "does not change visibility" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1", visibility: "private"})
+
+ {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2"})
+
+ updated_object = Object.normalize(updated)
+ assert updated_object.data["content"] == "updated 2"
+ assert Map.get(updated_object.data, "summary", "") == ""
+ assert Visibility.get_visibility(updated_object) == "private"
+ assert Visibility.get_visibility(updated) == "private"
+ end
+
+ test "updates a post with emoji" do
+ [{emoji1, _}, {emoji2, _} | _] = Pleroma.Emoji.get_all()
+
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1 :#{emoji1}:"})
+
+ {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2 :#{emoji2}:"})
+
+ updated_object = Object.normalize(updated)
+ assert updated_object.data["content"] == "updated 2 :#{emoji2}:"
+ assert %{^emoji2 => _} = updated_object.data["emoji"]
+ end
+
+ test "updates a post with emoji and federate properly" do
+ [{emoji1, _}, {emoji2, _} | _] = Pleroma.Emoji.get_all()
+
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1 :#{emoji1}:"})
+
+ clear_config([:instance, :federating], true)
+
+ with_mock Pleroma.Web.Federator,
+ publish: fn _p -> nil end do
+ {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2 :#{emoji2}:"})
+
+ assert updated.data["object"]["content"] == "updated 2 :#{emoji2}:"
+ assert %{^emoji2 => _} = updated.data["object"]["emoji"]
+
+ assert called(Pleroma.Web.Federator.publish(updated))
+ end
+ end
+
+ test "editing a post that copied a remote title with remote emoji should keep that emoji" do
+ remote_emoji_uri = "https://remote.org/emoji.png"
+
+ note =
+ insert(
+ :note,
+ data: %{
+ "summary" => ":remoteemoji:",
+ "emoji" => %{
+ "remoteemoji" => remote_emoji_uri
+ },
+ "tag" => [
+ %{
+ "type" => "Emoji",
+ "name" => "remoteemoji",
+ "icon" => %{"url" => remote_emoji_uri}
+ }
+ ]
+ }
+ )
+
+ note_activity = insert(:note_activity, note: note)
+
+ user = insert(:user)
+
+ {:ok, reply} =
+ CommonAPI.post(user, %{
+ status: "reply",
+ spoiler_text: ":remoteemoji:",
+ in_reply_to_id: note_activity.id
+ })
+
+ assert reply.object.data["emoji"]["remoteemoji"] == remote_emoji_uri
+
+ {:ok, edit} =
+ CommonAPI.update(user, reply, %{status: "reply mew mew", spoiler_text: ":remoteemoji:"})
+
+ edited_note = Pleroma.Object.normalize(edit)
+
+ assert edited_note.data["emoji"]["remoteemoji"] == remote_emoji_uri
+ end
+
+ test "respects MRF" do
+ user = insert(:user)
+
+ clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy])
+ clear_config([:mrf_keyword, :replace], [{"updated", "mewmew"}])
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "updated 1"})
+ assert Object.normalize(activity).data["summary"] == "mewmew 1"
+
+ {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2"})
+
+ updated_object = Object.normalize(updated)
+ assert updated_object.data["content"] == "mewmew 2"
+ assert Map.get(updated_object.data, "summary", "") == ""
+ assert Map.has_key?(updated_object.data, "updated")
+ end
+ end
end
diff --git a/test/pleroma/web/endpoint/metrics_exporter_test.exs b/test/pleroma/web/endpoint/metrics_exporter_test.exs
index 376e82149..ad236d4cb 100644
--- a/test/pleroma/web/endpoint/metrics_exporter_test.exs
+++ b/test/pleroma/web/endpoint/metrics_exporter_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Endpoint.MetricsExporterTest do
diff --git a/test/pleroma/web/fallback_test.exs b/test/pleroma/web/fallback_test.exs
index 512baf813..6d11d4f37 100644
--- a/test/pleroma/web/fallback_test.exs
+++ b/test/pleroma/web/fallback_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.FallbackTest do
diff --git a/test/pleroma/web/federator_test.exs b/test/pleroma/web/federator_test.exs
index 372b6a73a..41d1c5d5e 100644
--- a/test/pleroma/web/federator_test.exs
+++ b/test/pleroma/web/federator_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.FederatorTest do
@@ -153,7 +153,7 @@ defmodule Pleroma.Web.FederatorTest do
}
assert {:ok, job} = Federator.incoming_ap_doc(params)
- assert {:error, :origin_containment_failed} = ObanHelpers.perform(job)
+ assert {:cancel, :origin_containment_failed} = ObanHelpers.perform(job)
end
test "it does not crash if MRF rejects the post" do
@@ -169,7 +169,7 @@ defmodule Pleroma.Web.FederatorTest do
|> Jason.decode!()
assert {:ok, job} = Federator.incoming_ap_doc(params)
- assert {:error, _} = ObanHelpers.perform(job)
+ assert {:cancel, _} = ObanHelpers.perform(job)
end
end
end
diff --git a/test/pleroma/web/feed/tag_controller_test.exs b/test/pleroma/web/feed/tag_controller_test.exs
index 140cdb8bf..58ab8f137 100644
--- a/test/pleroma/web/feed/tag_controller_test.exs
+++ b/test/pleroma/web/feed/tag_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Feed.TagControllerTest do
@@ -63,7 +63,6 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
]
assert xpath(xml, ~x"//feed/entry/author/name/text()"ls) == [user.nickname, user.nickname]
- assert xpath(xml, ~x"//feed/entry/author/id/text()"ls) == [user.ap_id, user.ap_id]
conn =
conn
@@ -138,8 +137,8 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
]
assert xpath(xml, ~x"//channel/item/pubDate/text()"sl) == [
- FeedView.pub_date(activity2.data["published"]),
- FeedView.pub_date(activity1.data["published"])
+ FeedView.to_rfc2822(activity2.data["published"]),
+ FeedView.to_rfc2822(activity1.data["published"])
]
assert xpath(xml, ~x"//channel/item/enclosure/@url"sl) == [
diff --git a/test/pleroma/web/feed/user_controller_test.exs b/test/pleroma/web/feed/user_controller_test.exs
index 6f6ff433f..de32d3d4b 100644
--- a/test/pleroma/web/feed/user_controller_test.exs
+++ b/test/pleroma/web/feed/user_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Feed.UserControllerTest do
@@ -74,7 +74,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|> SweetXml.parse()
|> SweetXml.xpath(~x"//entry/title/text()"l)
- assert activity_titles == ['42 &amp; Thi...', 'This &amp; t...']
+ assert activity_titles == ['2hu', '2hu & as']
assert resp =~ FeedView.escape(object.data["content"])
assert resp =~ FeedView.escape(object.data["summary"])
assert resp =~ FeedView.escape(object.data["context"])
@@ -90,7 +90,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|> SweetXml.parse()
|> SweetXml.xpath(~x"//entry/title/text()"l)
- assert activity_titles == ['This &amp; t...']
+ assert activity_titles == ['2hu & as']
end
test "gets a rss feed", %{conn: conn, user: user, object: object, max_id: max_id} do
@@ -105,7 +105,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|> SweetXml.parse()
|> SweetXml.xpath(~x"//item/title/text()"l)
- assert activity_titles == ['42 &amp; Thi...', 'This &amp; t...']
+ assert activity_titles == ['2hu', '2hu & as']
assert resp =~ FeedView.escape(object.data["content"])
assert resp =~ FeedView.escape(object.data["summary"])
assert resp =~ FeedView.escape(object.data["context"])
@@ -121,7 +121,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|> SweetXml.parse()
|> SweetXml.xpath(~x"//item/title/text()"l)
- assert activity_titles == ['This &amp; t...']
+ assert activity_titles == ['2hu & as']
end
test "returns 404 for a missing feed", %{conn: conn} do
@@ -196,13 +196,26 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
).resp_body
end
- test "with html format, it returns error when user is not found", %{conn: conn} do
+ test "with html format, it falls back to frontend when user is remote", %{conn: conn} do
+ user = insert(:user, local: false)
+
+ {:ok, _} = CommonAPI.post(user, %{status: "test"})
+
+ response =
+ conn
+ |> get("/users/#{user.nickname}")
+ |> response(200)
+
+ assert response =~ "</html>"
+ end
+
+ test "with html format, it falls back to frontend when user is not found", %{conn: conn} do
response =
conn
|> get("/users/jimm")
- |> json_response(404)
+ |> response(200)
- assert response == %{"error" => "Not found"}
+ assert response =~ "</html>"
end
test "with non-html / non-json format, it redirects to user feed in atom format", %{
diff --git a/test/pleroma/web/gettext_test.exs b/test/pleroma/web/gettext_test.exs
new file mode 100644
index 000000000..e186f1ab3
--- /dev/null
+++ b/test/pleroma/web/gettext_test.exs
@@ -0,0 +1,173 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.GettextTest do
+ use ExUnit.Case
+
+ require Pleroma.Web.Gettext
+
+ test "put_locales/1: set the first in the list to Gettext's locale" do
+ Pleroma.Web.Gettext.put_locales(["zh_Hans", "en_test"])
+
+ assert "zh_Hans" == Gettext.get_locale(Pleroma.Web.Gettext)
+ end
+
+ test "with_locales/2: reset locale on exit" do
+ old_first_locale = Gettext.get_locale(Pleroma.Web.Gettext)
+ old_locales = Pleroma.Web.Gettext.get_locales()
+
+ Pleroma.Web.Gettext.with_locales ["zh_Hans", "en_test"] do
+ assert "zh_Hans" == Gettext.get_locale(Pleroma.Web.Gettext)
+ assert ["zh_Hans", "en_test"] == Pleroma.Web.Gettext.get_locales()
+ end
+
+ assert old_first_locale == Gettext.get_locale(Pleroma.Web.Gettext)
+ assert old_locales == Pleroma.Web.Gettext.get_locales()
+ end
+
+ describe "handle_missing_translation/5" do
+ test "fallback to next locale if some translation is not available" do
+ Pleroma.Web.Gettext.with_locales ["x_unsupported", "en_test"] do
+ assert "xxYour account is awaiting approvalxx" ==
+ Pleroma.Web.Gettext.dpgettext(
+ "static_pages",
+ "approval pending email subject",
+ "Your account is awaiting approval"
+ )
+ end
+ end
+
+ test "putting en locale at the front should not make gettext fallback unexpectedly" do
+ Pleroma.Web.Gettext.with_locales ["en", "en_test"] do
+ assert "Your account is awaiting approval" ==
+ Pleroma.Web.Gettext.dpgettext(
+ "static_pages",
+ "approval pending email subject",
+ "Your account is awaiting approval"
+ )
+ end
+ end
+
+ test "duplicated locale in list should not result in infinite loops" do
+ Pleroma.Web.Gettext.with_locales ["x_unsupported", "x_unsupported", "en_test"] do
+ assert "xxYour account is awaiting approvalxx" ==
+ Pleroma.Web.Gettext.dpgettext(
+ "static_pages",
+ "approval pending email subject",
+ "Your account is awaiting approval"
+ )
+ end
+ end
+
+ test "direct interpolation" do
+ Pleroma.Web.Gettext.with_locales ["en_test"] do
+ assert "xxYour digest from some instancexx" ==
+ Pleroma.Web.Gettext.dpgettext(
+ "static_pages",
+ "digest email subject",
+ "Your digest from %{instance_name}",
+ instance_name: "some instance"
+ )
+ end
+ end
+
+ test "fallback with interpolation" do
+ Pleroma.Web.Gettext.with_locales ["x_unsupported", "en_test"] do
+ assert "xxYour digest from some instancexx" ==
+ Pleroma.Web.Gettext.dpgettext(
+ "static_pages",
+ "digest email subject",
+ "Your digest from %{instance_name}",
+ instance_name: "some instance"
+ )
+ end
+ end
+
+ test "fallback to msgid" do
+ Pleroma.Web.Gettext.with_locales ["x_unsupported"] do
+ assert "Your digest from some instance" ==
+ Pleroma.Web.Gettext.dpgettext(
+ "static_pages",
+ "digest email subject",
+ "Your digest from %{instance_name}",
+ instance_name: "some instance"
+ )
+ end
+ end
+ end
+
+ describe "handle_missing_plural_translation/7" do
+ test "direct interpolation" do
+ Pleroma.Web.Gettext.with_locales ["en_test"] do
+ assert "xx1 New Followerxx" ==
+ Pleroma.Web.Gettext.dpngettext(
+ "static_pages",
+ "new followers count header",
+ "%{count} New Follower",
+ "%{count} New Followers",
+ 1,
+ count: 1
+ )
+
+ assert "xx5 New Followersxx" ==
+ Pleroma.Web.Gettext.dpngettext(
+ "static_pages",
+ "new followers count header",
+ "%{count} New Follower",
+ "%{count} New Followers",
+ 5,
+ count: 5
+ )
+ end
+ end
+
+ test "fallback with interpolation" do
+ Pleroma.Web.Gettext.with_locales ["x_unsupported", "en_test"] do
+ assert "xx1 New Followerxx" ==
+ Pleroma.Web.Gettext.dpngettext(
+ "static_pages",
+ "new followers count header",
+ "%{count} New Follower",
+ "%{count} New Followers",
+ 1,
+ count: 1
+ )
+
+ assert "xx5 New Followersxx" ==
+ Pleroma.Web.Gettext.dpngettext(
+ "static_pages",
+ "new followers count header",
+ "%{count} New Follower",
+ "%{count} New Followers",
+ 5,
+ count: 5
+ )
+ end
+ end
+
+ test "fallback to msgid" do
+ Pleroma.Web.Gettext.with_locales ["x_unsupported"] do
+ assert "1 New Follower" ==
+ Pleroma.Web.Gettext.dpngettext(
+ "static_pages",
+ "new followers count header",
+ "%{count} New Follower",
+ "%{count} New Followers",
+ 1,
+ count: 1
+ )
+
+ assert "5 New Followers" ==
+ Pleroma.Web.Gettext.dpngettext(
+ "static_pages",
+ "new followers count header",
+ "%{count} New Follower",
+ "%{count} New Followers",
+ 5,
+ count: 5
+ )
+ end
+ end
+ end
+end
diff --git a/test/pleroma/web/manifest_controller_test.exs b/test/pleroma/web/manifest_controller_test.exs
new file mode 100644
index 000000000..f442708a8
--- /dev/null
+++ b/test/pleroma/web/manifest_controller_test.exs
@@ -0,0 +1,17 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ManifestControllerTest do
+ use Pleroma.Web.ConnCase
+
+ setup do
+ clear_config([:instance, :name], "Manifest Test")
+ clear_config([:manifest, :theme_color], "#ff0000")
+ end
+
+ test "manifest.json", %{conn: conn} do
+ conn = get(conn, "/manifest.json")
+ assert %{"name" => "Manifest Test", "theme_color" => "#ff0000"} = json_response(conn, 200)
+ end
+end
diff --git a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
index 9ffdda5b3..958b7f76f 100644
--- a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
@@ -1,16 +1,20 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
use Pleroma.Web.ConnCase
+ alias Pleroma.Object
alias Pleroma.Repo
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
+ alias Pleroma.UserRelationship
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.InternalFetchActor
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OAuth.Token
+ alias Pleroma.Web.Plugs.SetLocalePlug
import Pleroma.Factory
@@ -404,13 +408,18 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
assert id_two == to_string(activity.id)
end
- test "unimplemented pinned statuses feature", %{conn: conn} do
- note = insert(:note_activity)
- user = User.get_cached_by_ap_id(note.data["actor"])
+ test "gets local-only statuses for authenticated users", %{user: _user, conn: conn} do
+ user_one = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user_one, %{status: "HI!!!", visibility: "local"})
- conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?pinned=true")
+ resp =
+ conn
+ |> get("/api/v1/accounts/#{user_one.id}/statuses")
+ |> json_response_and_validate_schema(200)
- assert json_response_and_validate_schema(conn, 200) == []
+ assert [%{"id" => id}] = resp
+ assert id == to_string(activity.id)
end
test "gets an users media, excludes reblogs", %{conn: conn} do
@@ -709,9 +718,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
assert [%{"id" => ^follower2_id}, %{"id" => ^follower1_id}] =
conn
|> get(
- "/api/v1/accounts/#{user.id}/followers?id=#{user.id}&limit=20&max_id=#{
- follower3_id
- }"
+ "/api/v1/accounts/#{user.id}/followers?id=#{user.id}&limit=20&max_id=#{follower3_id}"
)
|> json_response_and_validate_schema(200)
@@ -889,6 +896,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|> post("/api/v1/accounts/#{followed.id}/follow", %{reblogs: true})
|> json_response_and_validate_schema(200)
+ assert %{"showing_reblogs" => true} =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/accounts/#{followed.id}/follow", %{reblogs: "1"})
+ |> json_response_and_validate_schema(200)
+
assert [%{"id" => ^reblog_id}] =
conn
|> get("/api/v1/timelines/home")
@@ -918,12 +931,41 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|> post("/api/v1/accounts/#{followed.id}/follow", %{reblogs: false})
|> json_response_and_validate_schema(200)
+ assert %{"showing_reblogs" => false} =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/accounts/#{followed.id}/follow", %{reblogs: "0"})
+ |> json_response_and_validate_schema(200)
+
assert [] ==
conn
|> get("/api/v1/timelines/home")
|> json_response_and_validate_schema(200)
end
+ test "following with subscription and unsubscribing" do
+ %{conn: conn} = oauth_access(["follow"])
+ followed = insert(:user)
+
+ assert %{"subscribing" => true} =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/accounts/#{followed.id}/follow", %{notify: true})
+ |> json_response_and_validate_schema(200)
+
+ assert %{"subscribing" => true} =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/accounts/#{followed.id}/follow", %{notify: "1"})
+ |> json_response_and_validate_schema(200)
+
+ assert %{"subscribing" => false} =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/accounts/#{followed.id}/follow", %{notify: false})
+ |> json_response_and_validate_schema(200)
+ end
+
test "following / unfollowing errors", %{user: user, conn: conn} do
# self follow
conn_res = post(conn, "/api/v1/accounts/#{user.id}/follow")
@@ -998,6 +1040,40 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
assert %{"id" => _id, "muting" => false, "muting_notifications" => false} =
json_response_and_validate_schema(conn, 200)
end
+
+ test "expiring", %{conn: conn, user: user} do
+ other_user = insert(:user)
+
+ conn =
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/v1/accounts/#{other_user.id}/mute", %{"duration" => "86400"})
+
+ assert %{"id" => _id, "muting" => true} = json_response_and_validate_schema(conn, 200)
+
+ mute_expires_at = UserRelationship.get_mute_expire_date(user, other_user)
+
+ assert DateTime.diff(
+ mute_expires_at,
+ DateTime.utc_now() |> DateTime.add(24 * 60 * 60)
+ ) in -3..3
+ end
+
+ test "falls back to expires_in", %{conn: conn, user: user} do
+ other_user = insert(:user)
+
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/v1/accounts/#{other_user.id}/mute", %{"expires_in" => "86400"})
+ |> json_response_and_validate_schema(200)
+
+ mute_expires_at = UserRelationship.get_mute_expire_date(user, other_user)
+
+ assert DateTime.diff(
+ mute_expires_at,
+ DateTime.utc_now() |> DateTime.add(24 * 60 * 60)
+ ) in -3..3
+ end
end
describe "pinned statuses" do
@@ -1019,6 +1095,35 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
end
end
+ test "view pinned private statuses" do
+ user = insert(:user)
+ reader = insert(:user)
+
+ # Create a private status and pin it
+ {:ok, %{id: activity_id} = activity} =
+ CommonAPI.post(user, %{status: "psst", visibility: "private"})
+
+ %{data: %{"id" => object_ap_id}} = Object.normalize(activity)
+ {:ok, _} = User.add_pinned_object_id(user, object_ap_id)
+
+ %{conn: conn} = oauth_access(["read:statuses"], user: reader)
+
+ # A non-follower can't see the pinned status
+ assert [] ==
+ conn
+ |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
+ |> json_response_and_validate_schema(200)
+
+ # Follow the user, then the pinned status can be seen
+ CommonAPI.follow(reader, user)
+ ObanHelpers.perform_all()
+
+ assert [%{"id" => ^activity_id, "pinned" => true}] =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
+ |> json_response_and_validate_schema(200)
+ end
+
test "blocking / unblocking a user" do
%{conn: conn} = oauth_access(["follow"])
other_user = insert(:user)
@@ -1567,6 +1672,129 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
end
end
+ describe "create account with required birth date" do
+ setup %{conn: conn} do
+ clear_config([:instance, :birthday_required], true)
+ clear_config([:instance, :birthday_min_age], 18 * 365)
+
+ app_token = insert(:oauth_token, user: nil)
+
+ conn =
+ conn
+ |> put_req_header("authorization", "Bearer " <> app_token.token)
+ |> put_req_header("content-type", "multipart/form-data")
+
+ [conn: conn]
+ end
+
+ test "creates an account if provided valid birth date", %{conn: conn} do
+ birthday =
+ Date.utc_today()
+ |> Date.add(-19 * 365)
+ |> Date.to_string()
+
+ params = %{
+ username: "mkljczk",
+ email: "mkljczk@example.org",
+ password: "dupa.8",
+ agreement: true,
+ birthday: birthday
+ }
+
+ res =
+ conn
+ |> post("/api/v1/accounts", params)
+
+ assert json_response_and_validate_schema(res, 200)
+ end
+
+ test "returns an error if missing birth date", %{conn: conn} do
+ params = %{
+ username: "mkljczk",
+ email: "mkljczk@example.org",
+ password: "dupa.8",
+ agreement: true
+ }
+
+ res =
+ conn
+ |> post("/api/v1/accounts", params)
+
+ assert json_response_and_validate_schema(res, 400) == %{
+ "error" => "{\"birthday\":[\"can't be blank\"]}"
+ }
+ end
+ end
+
+ describe "create account with language" do
+ setup %{conn: conn} do
+ app_token = insert(:oauth_token, user: nil)
+
+ conn =
+ conn
+ |> put_req_header("authorization", "Bearer " <> app_token.token)
+ |> put_req_header("content-type", "multipart/form-data")
+ |> put_req_cookie(SetLocalePlug.frontend_language_cookie_name(), "zh-Hans")
+ |> SetLocalePlug.call([])
+
+ [conn: conn]
+ end
+
+ test "creates an account with language parameter", %{conn: conn} do
+ params = %{
+ username: "foo",
+ email: "foo@example.org",
+ password: "dupa.8",
+ agreement: true,
+ language: "ru"
+ }
+
+ res =
+ conn
+ |> post("/api/v1/accounts", params)
+
+ assert json_response_and_validate_schema(res, 200)
+
+ assert %{language: "ru"} = Pleroma.User.get_by_nickname("foo")
+ end
+
+ test "language parameter should be normalized", %{conn: conn} do
+ params = %{
+ username: "foo",
+ email: "foo@example.org",
+ password: "dupa.8",
+ agreement: true,
+ language: "ru-RU"
+ }
+
+ res =
+ conn
+ |> post("/api/v1/accounts", params)
+
+ assert json_response_and_validate_schema(res, 200)
+
+ assert %{language: "ru_RU"} = Pleroma.User.get_by_nickname("foo")
+ end
+
+ test "createing an account without language parameter should fallback to cookie/header language",
+ %{conn: conn} do
+ params = %{
+ username: "foo2",
+ email: "foo2@example.org",
+ password: "dupa.8",
+ agreement: true
+ }
+
+ res =
+ conn
+ |> post("/api/v1/accounts", params)
+
+ assert json_response_and_validate_schema(res, 200)
+
+ assert %{language: "zh_Hans"} = Pleroma.User.get_by_nickname("foo2")
+ end
+ end
+
describe "GET /api/v1/accounts/:id/lists - account_lists" do
test "returns lists to which the account belongs" do
%{user: user, conn: conn} = oauth_access(["read:lists"])
@@ -1802,4 +2030,151 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
assert [%{"id" => ^id1}] = result
end
+
+ test "account lookup", %{conn: conn} do
+ %{nickname: acct} = insert(:user, %{nickname: "nickname"})
+ %{nickname: acct_two} = insert(:user, %{nickname: "nickname@notlocaldoma.in"})
+
+ result =
+ conn
+ |> get("/api/v1/accounts/lookup?acct=#{acct}")
+ |> json_response_and_validate_schema(200)
+
+ assert %{"acct" => ^acct} = result
+
+ result =
+ conn
+ |> get("/api/v1/accounts/lookup?acct=#{acct_two}")
+ |> json_response_and_validate_schema(200)
+
+ assert %{"acct" => ^acct_two} = result
+
+ _result =
+ conn
+ |> get("/api/v1/accounts/lookup?acct=unexisting_nickname")
+ |> json_response_and_validate_schema(404)
+ end
+
+ test "create a note on a user" do
+ %{conn: conn} = oauth_access(["write:accounts", "read:follows"])
+ other_user = insert(:user)
+
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/accounts/#{other_user.id}/note", %{
+ "comment" => "Example note"
+ })
+
+ assert [%{"note" => "Example note"}] =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> get("/api/v1/accounts/relationships?id=#{other_user.id}")
+ |> json_response_and_validate_schema(200)
+ end
+
+ describe "account endorsements" do
+ setup do: oauth_access(["read:accounts", "write:accounts", "write:follows"])
+
+ setup do: clear_config([:instance, :max_endorsed_users], 1)
+
+ test "pin account", %{user: user, conn: conn} do
+ %{id: id1} = other_user1 = insert(:user)
+
+ CommonAPI.follow(user, other_user1)
+
+ assert %{"id" => ^id1, "endorsed" => true} =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/accounts/#{id1}/pin")
+ |> json_response_and_validate_schema(200)
+
+ assert [%{"id" => ^id1}] =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> get("/api/v1/endorsements")
+ |> json_response_and_validate_schema(200)
+ end
+
+ test "unpin account", %{user: user, conn: conn} do
+ %{id: id1} = other_user1 = insert(:user)
+
+ CommonAPI.follow(user, other_user1)
+ User.endorse(user, other_user1)
+
+ assert %{"id" => ^id1, "endorsed" => false} =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/accounts/#{id1}/unpin")
+ |> json_response_and_validate_schema(200)
+
+ assert [] =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> get("/api/v1/endorsements")
+ |> json_response_and_validate_schema(200)
+ end
+
+ test "max pinned accounts", %{user: user, conn: conn} do
+ %{id: id1} = other_user1 = insert(:user)
+ %{id: id2} = other_user2 = insert(:user)
+
+ CommonAPI.follow(user, other_user1)
+ CommonAPI.follow(user, other_user2)
+
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/accounts/#{id1}/pin")
+ |> json_response_and_validate_schema(200)
+
+ assert %{"error" => "You have already pinned the maximum number of users"} =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{id2}/pin")
+ |> json_response_and_validate_schema(400)
+ end
+ end
+
+ describe "remove from followers" do
+ setup do: oauth_access(["follow"])
+
+ test "removing user from followers", %{conn: conn, user: user} do
+ %{id: other_user_id} = other_user = insert(:user)
+
+ CommonAPI.follow(other_user, user)
+
+ assert %{"id" => ^other_user_id, "followed_by" => false} =
+ conn
+ |> post("/api/v1/accounts/#{other_user_id}/remove_from_followers")
+ |> json_response_and_validate_schema(200)
+
+ refute User.following?(other_user, user)
+ end
+
+ test "removing remote user from followers", %{conn: conn, user: user} do
+ %{id: other_user_id} = other_user = insert(:user, local: false)
+
+ CommonAPI.follow(other_user, user)
+
+ assert User.following?(other_user, user)
+
+ assert %{"id" => ^other_user_id, "followed_by" => false} =
+ conn
+ |> post("/api/v1/accounts/#{other_user_id}/remove_from_followers")
+ |> json_response_and_validate_schema(200)
+
+ refute User.following?(other_user, user)
+ end
+
+ test "removing user from followers errors", %{user: user, conn: conn} do
+ # self remove
+ conn_res = post(conn, "/api/v1/accounts/#{user.id}/remove_from_followers")
+
+ assert %{"error" => "Can not unfollow yourself"} =
+ json_response_and_validate_schema(conn_res, 400)
+
+ # remove non existing user
+ conn_res = post(conn, "/api/v1/accounts/doesntexist/remove_from_followers")
+ assert %{"error" => "Record not found"} = json_response_and_validate_schema(conn_res, 404)
+ end
+ end
end
diff --git a/test/pleroma/web/mastodon_api/controllers/announcement_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/announcement_controller_test.exs
new file mode 100644
index 000000000..60c9978c2
--- /dev/null
+++ b/test/pleroma/web/mastodon_api/controllers/announcement_controller_test.exs
@@ -0,0 +1,169 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.AnnouncementControllerTest do
+ use Pleroma.Web.ConnCase
+
+ import Pleroma.Factory
+
+ alias Pleroma.Announcement
+ alias Pleroma.AnnouncementReadRelationship
+
+ describe "GET /api/v1/announcements" do
+ setup do
+ %{conn: conn} = oauth_access([])
+ {:ok, conn: conn}
+ end
+
+ test "it does not allow guests", %{conn: conn} do
+ _response =
+ conn
+ |> assign(:token, nil)
+ |> get("/api/v1/announcements")
+ |> json_response_and_validate_schema(:forbidden)
+ end
+
+ test "it allows users with scopes" do
+ %{conn: conn} = oauth_access(["read:accounts"])
+
+ _response =
+ conn
+ |> get("/api/v1/announcements")
+ |> json_response_and_validate_schema(:ok)
+ end
+
+ test "it lists all announcements", %{conn: conn} do
+ %{id: id} = insert(:announcement)
+
+ response =
+ conn
+ |> get("/api/v1/announcements")
+ |> json_response_and_validate_schema(:ok)
+
+ assert [%{"id" => ^id}] = response
+ end
+
+ test "it returns time with utc timezone", %{conn: conn} do
+ start_time =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.add(-999_999, :second)
+ |> NaiveDateTime.truncate(:second)
+
+ end_time =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.add(999_999, :second)
+ |> NaiveDateTime.truncate(:second)
+
+ %{id: id} = insert(:announcement, %{starts_at: start_time, ends_at: end_time})
+
+ response =
+ conn
+ |> get("/api/v1/announcements")
+ |> json_response_and_validate_schema(:ok)
+
+ assert [%{"id" => ^id}] = [announcement] = response
+
+ assert String.ends_with?(announcement["starts_at"], "Z")
+ assert String.ends_with?(announcement["ends_at"], "Z")
+ end
+
+ test "it does not list announcements starting after current time", %{conn: conn} do
+ time = NaiveDateTime.utc_now() |> NaiveDateTime.add(999_999, :second)
+ insert(:announcement, starts_at: time)
+
+ response =
+ conn
+ |> get("/api/v1/announcements")
+ |> json_response_and_validate_schema(:ok)
+
+ assert [] = response
+ end
+
+ test "it does not list announcements ending before current time", %{conn: conn} do
+ time = NaiveDateTime.utc_now() |> NaiveDateTime.add(-999_999, :second)
+ insert(:announcement, ends_at: time)
+
+ response =
+ conn
+ |> get("/api/v1/announcements")
+ |> json_response_and_validate_schema(:ok)
+
+ assert [] = response
+ end
+
+ test "when authenticated, also expose read property", %{conn: conn} do
+ %{id: id} = insert(:announcement)
+
+ response =
+ conn
+ |> get("/api/v1/announcements")
+ |> json_response_and_validate_schema(:ok)
+
+ assert [%{"id" => ^id, "read" => false}] = response
+ end
+
+ test "when authenticated and announcement is read by user" do
+ %{id: id} = announcement = insert(:announcement)
+ user = insert(:user)
+
+ AnnouncementReadRelationship.mark_read(user, announcement)
+
+ %{conn: conn} = oauth_access(["read:accounts"], user: user)
+
+ response =
+ conn
+ |> get("/api/v1/announcements")
+ |> json_response_and_validate_schema(:ok)
+
+ assert [%{"id" => ^id, "read" => true}] = response
+ end
+ end
+
+ describe "POST /api/v1/announcements/:id/dismiss" do
+ setup do: oauth_access(["write:accounts"])
+
+ test "it requires auth", %{conn: conn} do
+ %{id: id} = insert(:announcement)
+
+ _response =
+ conn
+ |> assign(:token, nil)
+ |> post("/api/v1/announcements/#{id}/dismiss")
+ |> json_response_and_validate_schema(:forbidden)
+ end
+
+ test "it requires write:accounts oauth scope" do
+ %{id: id} = insert(:announcement)
+
+ %{conn: conn} = oauth_access(["read:accounts"])
+
+ _response =
+ conn
+ |> post("/api/v1/announcements/#{id}/dismiss")
+ |> json_response_and_validate_schema(:forbidden)
+ end
+
+ test "it gives 404 for non-existent announcements", %{conn: conn} do
+ %{id: id} = insert(:announcement)
+
+ _response =
+ conn
+ |> post("/api/v1/announcements/#{id}xxx/dismiss")
+ |> json_response_and_validate_schema(:not_found)
+ end
+
+ test "it marks announcement as read", %{user: user, conn: conn} do
+ %{id: id} = announcement = insert(:announcement)
+
+ refute Announcement.read_by?(announcement, user)
+
+ _response =
+ conn
+ |> post("/api/v1/announcements/#{id}/dismiss")
+ |> json_response_and_validate_schema(:ok)
+
+ assert Announcement.read_by?(announcement, user)
+ end
+ end
+end
diff --git a/test/pleroma/web/mastodon_api/controllers/app_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/app_controller_test.exs
index 76d81b942..bc9d4048c 100644
--- a/test/pleroma/web/mastodon_api/controllers/app_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/app_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.AppControllerTest do
@@ -35,6 +35,33 @@ defmodule Pleroma.Web.MastodonAPI.AppControllerTest do
end
test "creates an oauth app", %{conn: conn} do
+ app_attrs = build(:oauth_app)
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/apps", %{
+ client_name: app_attrs.client_name,
+ redirect_uris: app_attrs.redirect_uris
+ })
+
+ [app] = Repo.all(App)
+
+ expected = %{
+ "name" => app.client_name,
+ "website" => app.website,
+ "client_id" => app.client_id,
+ "client_secret" => app.client_secret,
+ "id" => app.id |> to_string(),
+ "redirect_uri" => app.redirect_uris,
+ "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
+ }
+
+ assert expected == json_response_and_validate_schema(conn, 200)
+ assert app.user_id == nil
+ end
+
+ test "creates an oauth app with a user", %{conn: conn} do
user = insert(:user)
app_attrs = build(:oauth_app)
@@ -60,5 +87,6 @@ defmodule Pleroma.Web.MastodonAPI.AppControllerTest do
}
assert expected == json_response_and_validate_schema(conn, 200)
+ assert app.user_id == user.id
end
end
diff --git a/test/pleroma/web/mastodon_api/controllers/auth_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/auth_controller_test.exs
deleted file mode 100644
index 1872dfd59..000000000
--- a/test/pleroma/web/mastodon_api/controllers/auth_controller_test.exs
+++ /dev/null
@@ -1,159 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.MastodonAPI.AuthControllerTest do
- use Pleroma.Web.ConnCase, async: true
-
- alias Pleroma.Config
- alias Pleroma.Repo
- alias Pleroma.Tests.ObanHelpers
-
- import Pleroma.Factory
- import Swoosh.TestAssertions
-
- describe "GET /web/login" do
- setup %{conn: conn} do
- session_opts = [
- store: :cookie,
- key: "_test",
- signing_salt: "cooldude"
- ]
-
- conn =
- conn
- |> Plug.Session.call(Plug.Session.init(session_opts))
- |> fetch_session()
-
- test_path = "/web/statuses/test"
- %{conn: conn, path: test_path}
- end
-
- test "redirects to the saved path after log in", %{conn: conn, path: path} do
- app = insert(:oauth_app, client_name: "Mastodon-Local", redirect_uris: ".")
- auth = insert(:oauth_authorization, app: app)
-
- conn =
- conn
- |> put_session(:return_to, path)
- |> get("/web/login", %{code: auth.token})
-
- assert conn.status == 302
- assert redirected_to(conn) =~ path
- end
-
- test "redirects to the getting-started page when referer is not present", %{conn: conn} do
- app = insert(:oauth_app, client_name: "Mastodon-Local", redirect_uris: ".")
- auth = insert(:oauth_authorization, app: app)
-
- conn = get(conn, "/web/login", %{code: auth.token})
-
- assert conn.status == 302
- assert redirected_to(conn) =~ "/web/getting-started"
- end
- end
-
- describe "POST /auth/password, with valid parameters" do
- setup %{conn: conn} do
- user = insert(:user)
- conn = post(conn, "/auth/password?email=#{user.email}")
- %{conn: conn, user: user}
- end
-
- test "it returns 204", %{conn: conn} do
- assert empty_json_response(conn)
- end
-
- test "it creates a PasswordResetToken record for user", %{user: user} do
- token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
- assert token_record
- end
-
- test "it sends an email to user", %{user: user} do
- ObanHelpers.perform_all()
- token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
-
- email = Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
- notify_email = Config.get([:instance, :notify_email])
- instance_name = Config.get([:instance, :name])
-
- assert_email_sent(
- from: {instance_name, notify_email},
- to: {user.name, user.email},
- html_body: email.html_body
- )
- end
- end
-
- describe "POST /auth/password, with nickname" do
- test "it returns 204", %{conn: conn} do
- user = insert(:user)
-
- assert conn
- |> post("/auth/password?nickname=#{user.nickname}")
- |> empty_json_response()
-
- ObanHelpers.perform_all()
- token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
-
- email = Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
- notify_email = Config.get([:instance, :notify_email])
- instance_name = Config.get([:instance, :name])
-
- assert_email_sent(
- from: {instance_name, notify_email},
- to: {user.name, user.email},
- html_body: email.html_body
- )
- end
-
- test "it doesn't fail when a user has no email", %{conn: conn} do
- user = insert(:user, %{email: nil})
-
- assert conn
- |> post("/auth/password?nickname=#{user.nickname}")
- |> empty_json_response()
- end
- end
-
- describe "POST /auth/password, with invalid parameters" do
- setup do
- user = insert(:user)
- {:ok, user: user}
- end
-
- test "it returns 204 when user is not found", %{conn: conn, user: user} do
- conn = post(conn, "/auth/password?email=nonexisting_#{user.email}")
-
- assert empty_json_response(conn)
- end
-
- test "it returns 204 when user is not local", %{conn: conn, user: user} do
- {:ok, user} = Repo.update(Ecto.Changeset.change(user, local: false))
- conn = post(conn, "/auth/password?email=#{user.email}")
-
- assert empty_json_response(conn)
- end
-
- test "it returns 204 when user is deactivated", %{conn: conn, user: user} do
- {:ok, user} = Repo.update(Ecto.Changeset.change(user, is_active: false, local: true))
- conn = post(conn, "/auth/password?email=#{user.email}")
-
- assert empty_json_response(conn)
- end
- end
-
- describe "DELETE /auth/sign_out" do
- test "redirect to root page", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> delete("/auth/sign_out")
-
- assert conn.status == 302
- assert redirected_to(conn) == "/"
- end
- end
-end
diff --git a/test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs
index 00797a9ea..ae9a6dd63 100644
--- a/test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
diff --git a/test/pleroma/web/mastodon_api/controllers/custom_emoji_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/custom_emoji_controller_test.exs
index cbb1d54a6..bcd3f61d9 100644
--- a/test/pleroma/web/mastodon_api/controllers/custom_emoji_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/custom_emoji_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.CustomEmojiControllerTest do
diff --git a/test/pleroma/web/mastodon_api/controllers/directory_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/directory_controller_test.exs
new file mode 100644
index 000000000..f90ef96f9
--- /dev/null
+++ b/test/pleroma/web/mastodon_api/controllers/directory_controller_test.exs
@@ -0,0 +1,50 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.DirectoryControllerTest do
+ use Pleroma.Web.ConnCase, async: true
+ alias Pleroma.Web.CommonAPI
+ import Pleroma.Factory
+
+ test "GET /api/v1/directory with :profile_directory disabled returns empty array", %{conn: conn} do
+ clear_config([:instance, :profile_directory], false)
+
+ insert(:user, is_discoverable: true)
+ insert(:user, is_discoverable: true)
+
+ result =
+ conn
+ |> get("/api/v1/directory")
+ |> json_response_and_validate_schema(200)
+
+ assert result == []
+ end
+
+ test "GET /api/v1/directory returns discoverable users only", %{conn: conn} do
+ %{id: user_id} = insert(:user, is_discoverable: true)
+ insert(:user, is_discoverable: false)
+
+ result =
+ conn
+ |> get("/api/v1/directory")
+ |> json_response_and_validate_schema(200)
+
+ assert [%{"id" => ^user_id}] = result
+ end
+
+ test "GET /api/v1/directory returns users sorted by most recent statuses", %{conn: conn} do
+ insert(:user, is_discoverable: true)
+ %{id: user_id} = user = insert(:user, is_discoverable: true)
+ insert(:user, is_discoverable: true)
+
+ {:ok, _activity} = CommonAPI.post(user, %{status: "yay i'm discoverable"})
+
+ result =
+ conn
+ |> get("/api/v1/directory?order=active")
+ |> json_response_and_validate_schema(200)
+
+ assert [%{"id" => ^user_id} | _tail] = result
+ end
+end
diff --git a/test/pleroma/web/mastodon_api/controllers/domain_block_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/domain_block_controller_test.exs
index 0c3a7c0cf..2c22108f8 100644
--- a/test/pleroma/web/mastodon_api/controllers/domain_block_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/domain_block_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do
diff --git a/test/pleroma/web/mastodon_api/controllers/filter_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/filter_controller_test.exs
index 98ab9e717..faa35f199 100644
--- a/test/pleroma/web/mastodon_api/controllers/filter_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/filter_controller_test.exs
@@ -1,11 +1,12 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do
- use Pleroma.Web.ConnCase, async: true
+ use Pleroma.Web.ConnCase, async: false
use Oban.Testing, repo: Pleroma.Repo
+ import Mock
import Pleroma.Factory
alias Pleroma.Filter
@@ -53,23 +54,19 @@ defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do
in_seconds = 600
response =
- conn
- |> put_req_header("content-type", "application/json")
- |> post("/api/v1/filters", %{
- "phrase" => "knights",
- context: ["home"],
- expires_in: in_seconds
- })
- |> json_response_and_validate_schema(200)
+ with_mock NaiveDateTime, [:passthrough], utc_now: fn -> ~N[2017-03-17 17:09:58] end do
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/filters", %{
+ "phrase" => "knights",
+ context: ["home"],
+ expires_in: in_seconds
+ })
+ |> json_response_and_validate_schema(200)
+ end
assert response["irreversible"] == false
-
- expires_at =
- NaiveDateTime.utc_now()
- |> NaiveDateTime.add(in_seconds)
- |> Pleroma.Web.CommonAPI.Utils.to_masto_date()
-
- assert response["expires_at"] == expires_at
+ assert response["expires_at"] == "2017-03-17T17:19:58.000Z"
filter = Filter.get(response["id"], user)
@@ -181,22 +178,20 @@ defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do
in_seconds = 600
response =
- conn
- |> put_req_header("content-type", "application/json")
- |> put("/api/v1/filters/#{filter.filter_id}", %{
- phrase: "nii",
- context: ["public"],
- expires_in: in_seconds,
- irreversible: true
- })
- |> json_response_and_validate_schema(200)
+ with_mock NaiveDateTime, [:passthrough], utc_now: fn -> ~N[2017-03-17 17:09:58] end do
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> put("/api/v1/filters/#{filter.filter_id}", %{
+ phrase: "nii",
+ context: ["public"],
+ expires_in: in_seconds,
+ irreversible: true
+ })
+ |> json_response_and_validate_schema(200)
+ end
assert response["irreversible"] == true
-
- assert response["expires_at"] ==
- NaiveDateTime.utc_now()
- |> NaiveDateTime.add(in_seconds)
- |> Pleroma.Web.CommonAPI.Utils.to_masto_date()
+ assert response["expires_at"] == "2017-03-17T17:19:58.000Z"
filter = Filter.get(response["id"], user)
diff --git a/test/pleroma/web/mastodon_api/controllers/follow_request_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/follow_request_controller_test.exs
index 069ffb3d6..ff01b549c 100644
--- a/test/pleroma/web/mastodon_api/controllers/follow_request_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/follow_request_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
diff --git a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs
index e76cbc75b..13e3ffc0a 100644
--- a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
@@ -22,6 +22,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
"uri" => _,
"title" => _,
"description" => _,
+ "short_description" => _,
"version" => _,
"email" => from_config_email,
"urls" => %{
diff --git a/test/pleroma/web/mastodon_api/controllers/list_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/list_controller_test.exs
index 28099837e..430b8b89d 100644
--- a/test/pleroma/web/mastodon_api/controllers/list_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/list_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.ListControllerTest do
diff --git a/test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs
index 53aebe8e4..d8f7b2638 100644
--- a/test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
diff --git a/test/pleroma/web/mastodon_api/controllers/media_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/media_controller_test.exs
index ff988a7fd..79d52bb2f 100644
--- a/test/pleroma/web/mastodon_api/controllers/media_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/media_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
diff --git a/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs
index 2615912a8..1524df98f 100644
--- a/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
- use Pleroma.Web.ConnCase
+ use Pleroma.Web.ConnCase, async: false
alias Pleroma.Notification
alias Pleroma.Repo
@@ -44,9 +44,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|> get("/api/v1/notifications")
expected_response =
- "hi <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{user.id}\" href=\"#{
- user.ap_id
- }\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
+ "hi <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{user.id}\" href=\"#{user.ap_id}\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
assert [%{"status" => %{"content" => response}} | _rest] =
json_response_and_validate_schema(conn, 200)
@@ -76,12 +74,15 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
end
test "by default, does not contain pleroma:report" do
- %{user: user, conn: conn} = oauth_access(["read:notifications"])
+ clear_config([:instance, :moderator_privileges], [:reports_manage_reports])
+
+ user = insert(:user)
other_user = insert(:user)
third_user = insert(:user)
- user
- |> User.admin_api_update(%{is_moderator: true})
+ {:ok, user} = user |> User.admin_api_update(%{is_moderator: true})
+
+ %{conn: conn} = oauth_access(["read:notifications"], user: user)
{:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
@@ -103,6 +104,58 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
assert [_] = result
end
+ test "Pleroma:report is hidden for non-privileged users" do
+ clear_config([:instance, :moderator_privileges], [:reports_manage_reports])
+
+ user = insert(:user)
+ other_user = insert(:user)
+ third_user = insert(:user)
+
+ {:ok, user} = user |> User.admin_api_update(%{is_moderator: true})
+
+ %{conn: conn} = oauth_access(["read:notifications"], user: user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
+
+ {:ok, _report} =
+ CommonAPI.report(third_user, %{account_id: other_user.id, status_ids: [activity.id]})
+
+ result =
+ conn
+ |> get("/api/v1/notifications?include_types[]=pleroma:report")
+ |> json_response_and_validate_schema(200)
+
+ assert [_] = result
+
+ clear_config([:instance, :moderator_privileges], [])
+
+ result =
+ conn
+ |> get("/api/v1/notifications?include_types[]=pleroma:report")
+ |> json_response_and_validate_schema(200)
+
+ assert [] == result
+ end
+
+ test "excludes mentions from blockers when blockers_visible is false" do
+ clear_config([:activitypub, :blockers_visible], false)
+
+ %{user: user, conn: conn} = oauth_access(["read:notifications"])
+ blocker = insert(:user)
+
+ {:ok, _} = CommonAPI.block(blocker, user)
+ {:ok, activity} = CommonAPI.post(blocker, %{status: "hi @#{user.nickname}"})
+
+ {:ok, [_notification]} = Notification.create_notifications(activity)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/notifications")
+
+ assert [] == json_response_and_validate_schema(conn, 200)
+ end
+
test "getting a single notification" do
%{user: user, conn: conn} = oauth_access(["read:notifications"])
other_user = insert(:user)
@@ -114,9 +167,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
conn = get(conn, "/api/v1/notifications/#{notification.id}")
expected_response =
- "hi <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{user.id}\" href=\"#{
- user.ap_id
- }\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
+ "hi <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{user.id}\" href=\"#{user.ap_id}\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
assert %{"status" => %{"content" => response}} = json_response_and_validate_schema(conn, 200)
assert response == expected_response
@@ -408,7 +459,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
assert [%{"id" => ^reblog_notification_id}] = json_response_and_validate_schema(conn_res, 200)
end
- test "filters notifications using include_types" do
+ test "filters notifications using types" do
%{user: user, conn: conn} = oauth_access(["read:notifications"])
other_user = insert(:user)
@@ -423,21 +474,21 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
reblog_notification_id = get_notification_id_by_activity(reblog_activity)
follow_notification_id = get_notification_id_by_activity(follow_activity)
- conn_res = get(conn, "/api/v1/notifications?include_types[]=follow")
+ conn_res = get(conn, "/api/v1/notifications?types[]=follow")
assert [%{"id" => ^follow_notification_id}] = json_response_and_validate_schema(conn_res, 200)
- conn_res = get(conn, "/api/v1/notifications?include_types[]=mention")
+ conn_res = get(conn, "/api/v1/notifications?types[]=mention")
assert [%{"id" => ^mention_notification_id}] =
json_response_and_validate_schema(conn_res, 200)
- conn_res = get(conn, "/api/v1/notifications?include_types[]=favourite")
+ conn_res = get(conn, "/api/v1/notifications?types[]=favourite")
assert [%{"id" => ^favorite_notification_id}] =
json_response_and_validate_schema(conn_res, 200)
- conn_res = get(conn, "/api/v1/notifications?include_types[]=reblog")
+ conn_res = get(conn, "/api/v1/notifications?types[]=reblog")
assert [%{"id" => ^reblog_notification_id}] = json_response_and_validate_schema(conn_res, 200)
@@ -445,7 +496,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
assert length(result) == 4
- query = params_to_query(%{include_types: ["follow", "mention", "favourite", "reblog"]})
+ query = params_to_query(%{types: ["follow", "mention", "favourite", "reblog"]})
result =
conn
@@ -455,6 +506,23 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
assert length(result) == 4
end
+ test "filtering falls back to include_types" do
+ %{user: user, conn: conn} = oauth_access(["read:notifications"])
+ other_user = insert(:user)
+
+ {:ok, _activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"})
+ {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
+ {:ok, _activity} = CommonAPI.favorite(other_user, create_activity.id)
+ {:ok, _activity} = CommonAPI.repeat(create_activity.id, other_user)
+ {:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user)
+
+ follow_notification_id = get_notification_id_by_activity(follow_activity)
+
+ conn_res = get(conn, "/api/v1/notifications?include_types[]=follow")
+
+ assert [%{"id" => ^follow_notification_id}] = json_response_and_validate_schema(conn_res, 200)
+ end
+
test "destroy multiple" do
%{user: user, conn: conn} = oauth_access(["read:notifications", "write:notifications"])
other_user = insert(:user)
diff --git a/test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs
index da0a631a9..7912b1d5f 100644
--- a/test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
diff --git a/test/pleroma/web/mastodon_api/controllers/report_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/report_controller_test.exs
index fcfc4a48a..c7aa76122 100644
--- a/test/pleroma/web/mastodon_api/controllers/report_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/report_controller_test.exs
@@ -1,10 +1,12 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
use Pleroma.Web.ConnCase, async: true
+ alias Pleroma.Activity
+ alias Pleroma.Repo
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
@@ -27,6 +29,41 @@ defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
|> json_response_and_validate_schema(200)
end
+ test "submit a report with a fake Create", %{
+ conn: conn
+ } do
+ target_user = insert(:user)
+
+ note = insert(:note, user: target_user)
+
+ activity_params = %{
+ "object" => note.data["id"],
+ "actor" => note.data["actor"],
+ "to" => note.data["to"] || [],
+ "cc" => note.data["cc"] || [],
+ "type" => "Create"
+ }
+
+ {:ok, fake_activity} =
+ Repo.insert(%Activity{
+ data: activity_params,
+ recipients: activity_params["to"] ++ activity_params["cc"],
+ local: true,
+ actor: activity_params["actor"]
+ })
+
+ assert %{"action_taken" => false, "id" => _} =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/reports", %{
+ "account_id" => target_user.id,
+ "status_ids" => [fake_activity.id],
+ "comment" => "bad status!",
+ "forward" => "false"
+ })
+ |> json_response_and_validate_schema(200)
+ end
+
test "submit a report with statuses and comment", %{
conn: conn,
target_user: target_user,
diff --git a/test/pleroma/web/mastodon_api/controllers/scheduled_activity_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/scheduled_activity_controller_test.exs
index b28e3df56..21f2ea6f5 100644
--- a/test/pleroma/web/mastodon_api/controllers/scheduled_activity_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/scheduled_activity_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.ScheduledActivityControllerTest do
diff --git a/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs
index 7b0bbd8bd..0a9240b70 100644
--- a/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
@@ -37,6 +37,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
end
end
+ @tag :skip_on_mac
test "search", %{conn: conn} do
user = insert(:user)
user_two = insert(:user, %{nickname: "shp@shitposter.club"})
@@ -79,6 +80,51 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
assert status["id"] == to_string(activity.id)
end
+ test "search local-only status as an authenticated user" do
+ user = insert(:user)
+ %{conn: conn} = oauth_access(["read:search"])
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{status: "This is about 2hu private 天子", visibility: "local"})
+
+ results =
+ conn
+ |> get("/api/v2/search?#{URI.encode_query(%{q: "2hu"})}")
+ |> json_response_and_validate_schema(200)
+
+ [status] = results["statuses"]
+ assert status["id"] == to_string(activity.id)
+ end
+
+ test "search local-only status as an unauthenticated user" do
+ user = insert(:user)
+ %{conn: conn} = oauth_access([])
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{status: "This is about 2hu private 天子", visibility: "local"})
+
+ results =
+ conn
+ |> get("/api/v2/search?#{URI.encode_query(%{q: "2hu"})}")
+ |> json_response_and_validate_schema(200)
+
+ assert [] = results["statuses"]
+ end
+
+ test "search local-only status as an anonymous user" do
+ user = insert(:user)
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{status: "This is about 2hu private 天子", visibility: "local"})
+
+ results =
+ build_conn()
+ |> get("/api/v2/search?#{URI.encode_query(%{q: "2hu"})}")
+ |> json_response_and_validate_schema(200)
+
+ assert [] = results["statuses"]
+ end
+
@tag capture_log: true
test "constructs hashtags from search query", %{conn: conn} do
results =
@@ -125,13 +171,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
results =
conn
|> get(
- "/api/v2/search?#{
- URI.encode_query(%{
- q:
- "https://www.washingtonpost.com/sports/2020/06/10/" <>
- "nascar-ban-display-confederate-flag-all-events-properties/"
- })
- }"
+ "/api/v2/search?#{URI.encode_query(%{q: "https://www.washingtonpost.com/sports/2020/06/10/" <> "nascar-ban-display-confederate-flag-all-events-properties/"})}"
)
|> json_response_and_validate_schema(200)
@@ -156,9 +196,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
results =
conn
|> get(
- "/api/v2/search?#{
- URI.encode_query(%{q: "#some #text #with #hashtags", limit: 2, offset: 1})
- }"
+ "/api/v2/search?#{URI.encode_query(%{q: "#some #text #with #hashtags", limit: 2, offset: 1})}"
)
|> json_response_and_validate_schema(200)
diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
index d478a81ee..5bae2cd00 100644
--- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
@@ -1,13 +1,14 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
- use Pleroma.Web.ConnCase
+ use Pleroma.Web.ConnCase, async: false
use Oban.Testing, repo: Pleroma.Repo
alias Pleroma.Activity
alias Pleroma.Conversation.Participation
+ alias Pleroma.ModerationLog
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.ScheduledActivity
@@ -16,6 +17,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI
+ alias Pleroma.Workers.ScheduledActivityWorker
import Pleroma.Factory
@@ -261,6 +263,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|> Map.put("url", nil)
|> Map.put("uri", nil)
|> Map.put("created_at", nil)
+ |> Kernel.put_in(["pleroma", "context"], nil)
|> Kernel.put_in(["pleroma", "conversation_id"], nil)
fake_conn =
@@ -284,6 +287,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|> Map.put("url", nil)
|> Map.put("uri", nil)
|> Map.put("created_at", nil)
+ |> Kernel.put_in(["pleroma", "context"], nil)
|> Kernel.put_in(["pleroma", "conversation_id"], nil)
assert real_status == fake_status
@@ -705,11 +709,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|> json_response_and_validate_schema(200)
assert {:ok, %{id: activity_id}} =
- perform_job(Pleroma.Workers.ScheduledActivityWorker, %{
+ perform_job(ScheduledActivityWorker, %{
activity_id: scheduled_id
})
- assert Repo.all(Oban.Job) == []
+ refute_enqueued(worker: ScheduledActivityWorker)
object =
Activity
@@ -967,30 +971,23 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
assert Activity.get_by_id(activity.id) == activity
end
- test "when you're an admin or moderator", %{conn: conn} do
- activity1 = insert(:note_activity)
- activity2 = insert(:note_activity)
- admin = insert(:user, is_admin: true)
- moderator = insert(:user, is_moderator: true)
+ test "when you're privileged to", %{conn: conn} do
+ clear_config([:instance, :moderator_privileges], [:messages_delete])
+ activity = insert(:note_activity)
+ user = insert(:user, is_moderator: true)
res_conn =
conn
- |> assign(:user, admin)
- |> assign(:token, insert(:oauth_token, user: admin, scopes: ["write:statuses"]))
- |> delete("/api/v1/statuses/#{activity1.id}")
+ |> assign(:user, user)
+ |> assign(:token, insert(:oauth_token, user: user, scopes: ["write:statuses"]))
+ |> delete("/api/v1/statuses/#{activity.id}")
assert %{} = json_response_and_validate_schema(res_conn, 200)
- res_conn =
- conn
- |> assign(:user, moderator)
- |> assign(:token, insert(:oauth_token, user: moderator, scopes: ["write:statuses"]))
- |> delete("/api/v1/statuses/#{activity2.id}")
-
- assert %{} = json_response_and_validate_schema(res_conn, 200)
+ assert ModerationLog |> Repo.one() |> ModerationLog.get_log_entry_message() ==
+ "@#{user.nickname} deleted status ##{activity.id}"
- refute Activity.get_by_id(activity1.id)
- refute Activity.get_by_id(activity2.id)
+ refute Activity.get_by_id(activity.id)
end
end
@@ -1900,23 +1897,50 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|> json_response_and_validate_schema(:ok)
end
- test "posting a local only status" do
- %{user: _user, conn: conn} = oauth_access(["write:statuses"])
+ describe "local-only statuses" do
+ test "posting a local only status" do
+ %{user: _user, conn: conn} = oauth_access(["write:statuses"])
- conn_one =
- conn
- |> put_req_header("content-type", "application/json")
- |> post("/api/v1/statuses", %{
- "status" => "cofe",
- "visibility" => "local"
- })
+ conn_one =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
+ "status" => "cofe",
+ "visibility" => "local"
+ })
+
+ local = Utils.as_local_public()
+
+ assert %{"content" => "cofe", "id" => id, "visibility" => "local"} =
+ json_response_and_validate_schema(conn_one, 200)
- local = Utils.as_local_public()
+ assert %Activity{id: ^id, data: %{"to" => [^local]}} = Activity.get_by_id(id)
+ end
+
+ test "other users can read local-only posts" do
+ user = insert(:user)
+ %{user: _reader, conn: conn} = oauth_access(["read:statuses"])
- assert %{"content" => "cofe", "id" => id, "visibility" => "local"} =
- json_response_and_validate_schema(conn_one, 200)
+ {:ok, activity} = CommonAPI.post(user, %{status: "#2hu #2HU", visibility: "local"})
- assert %Activity{id: ^id, data: %{"to" => [^local]}} = Activity.get_by_id(id)
+ received =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}")
+ |> json_response_and_validate_schema(:ok)
+
+ assert received["id"] == activity.id
+ end
+
+ test "anonymous users cannot see local-only posts" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "#2hu #2HU", visibility: "local"})
+
+ _received =
+ build_conn()
+ |> get("/api/v1/statuses/#{activity.id}")
+ |> json_response_and_validate_schema(:not_found)
+ end
end
describe "muted reactions" do
@@ -1989,4 +2013,178 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
} = result
end
end
+
+ describe "get status history" do
+ setup do
+ %{conn: build_conn()}
+ end
+
+ test "unedited post", %{conn: conn} do
+ activity = insert(:note_activity)
+
+ conn = get(conn, "/api/v1/statuses/#{activity.id}/history")
+
+ assert [_] = json_response_and_validate_schema(conn, 200)
+ end
+
+ test "edited post", %{conn: conn} do
+ note =
+ insert(
+ :note,
+ data: %{
+ "formerRepresentations" => %{
+ "type" => "OrderedCollection",
+ "orderedItems" => [
+ %{
+ "type" => "Note",
+ "content" => "mew mew 2",
+ "summary" => "title 2"
+ },
+ %{
+ "type" => "Note",
+ "content" => "mew mew 1",
+ "summary" => "title 1"
+ }
+ ],
+ "totalItems" => 2
+ }
+ }
+ )
+
+ activity = insert(:note_activity, note: note)
+
+ conn = get(conn, "/api/v1/statuses/#{activity.id}/history")
+
+ assert [%{"spoiler_text" => "title 1"}, %{"spoiler_text" => "title 2"}, _] =
+ json_response_and_validate_schema(conn, 200)
+ end
+ end
+
+ describe "get status source" do
+ setup do
+ %{conn: build_conn()}
+ end
+
+ test "it returns the source", %{conn: conn} do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "mew mew #abc", spoiler_text: "#def"})
+
+ conn = get(conn, "/api/v1/statuses/#{activity.id}/source")
+
+ id = activity.id
+
+ assert %{"id" => ^id, "text" => "mew mew #abc", "spoiler_text" => "#def"} =
+ json_response_and_validate_schema(conn, 200)
+ end
+ end
+
+ describe "update status" do
+ setup do
+ oauth_access(["write:statuses"])
+ end
+
+ test "it updates the status" do
+ %{conn: conn, user: user} = oauth_access(["write:statuses", "read:statuses"])
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "mew mew #abc", spoiler_text: "#def"})
+
+ conn
+ |> get("/api/v1/statuses/#{activity.id}")
+ |> json_response_and_validate_schema(200)
+
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> put("/api/v1/statuses/#{activity.id}", %{
+ "status" => "edited",
+ "spoiler_text" => "lol"
+ })
+ |> json_response_and_validate_schema(200)
+
+ assert response["content"] == "edited"
+ assert response["spoiler_text"] == "lol"
+
+ response =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}")
+ |> json_response_and_validate_schema(200)
+
+ assert response["content"] == "edited"
+ assert response["spoiler_text"] == "lol"
+ end
+
+ test "it updates the attachments", %{conn: conn, user: user} do
+ attachment = insert(:attachment, user: user)
+ attachment_id = to_string(attachment.id)
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "mew mew #abc", spoiler_text: "#def"})
+
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> put("/api/v1/statuses/#{activity.id}", %{
+ "status" => "mew mew #abc",
+ "spoiler_text" => "#def",
+ "media_ids" => [attachment_id]
+ })
+ |> json_response_and_validate_schema(200)
+
+ assert [%{"id" => ^attachment_id}] = response["media_attachments"]
+ end
+
+ test "it does not update visibility", %{conn: conn, user: user} do
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ status: "mew mew #abc",
+ spoiler_text: "#def",
+ visibility: "private"
+ })
+
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> put("/api/v1/statuses/#{activity.id}", %{
+ "status" => "edited",
+ "spoiler_text" => "lol"
+ })
+ |> json_response_and_validate_schema(200)
+
+ assert response["visibility"] == "private"
+ end
+
+ test "it refuses to update when original post is not by the user", %{conn: conn} do
+ another_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(another_user, %{status: "mew mew #abc", spoiler_text: "#def"})
+
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> put("/api/v1/statuses/#{activity.id}", %{
+ "status" => "edited",
+ "spoiler_text" => "lol"
+ })
+ |> json_response_and_validate_schema(:forbidden)
+ end
+
+ test "it returns 404 if the user cannot see the post", %{conn: conn} do
+ another_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(another_user, %{
+ status: "mew mew #abc",
+ spoiler_text: "#def",
+ visibility: "private"
+ })
+
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> put("/api/v1/statuses/#{activity.id}", %{
+ "status" => "edited",
+ "spoiler_text" => "lol"
+ })
+ |> json_response_and_validate_schema(:not_found)
+ end
+ end
end
diff --git a/test/pleroma/web/mastodon_api/controllers/subscription_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/subscription_controller_test.exs
index 5a3f93d2d..ce7cfa9c7 100644
--- a/test/pleroma/web/mastodon_api/controllers/subscription_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/subscription_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
diff --git a/test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs
index 168966fc9..c0f3d5a2a 100644
--- a/test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs
@@ -1,11 +1,14 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
use Pleroma.Web.ConnCase, async: true
+ alias Pleroma.UserRelationship
+ alias Pleroma.Web.CommonAPI
+ import Pleroma.Factory
- setup do: oauth_access(["read"])
+ setup do: oauth_access(["read", "write"])
test "returns empty result", %{conn: conn} do
res =
@@ -15,4 +18,66 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
assert res == []
end
+
+ test "returns v2 suggestions", %{conn: conn} do
+ %{id: user_id} = insert(:user, is_suggested: true)
+
+ res =
+ conn
+ |> get("/api/v2/suggestions")
+ |> json_response_and_validate_schema(200)
+
+ assert [%{"source" => "staff", "account" => %{"id" => ^user_id}}] = res
+ end
+
+ test "returns v2 suggestions excluding dismissed accounts", %{conn: conn} do
+ %{id: user_id} = insert(:user, is_suggested: true)
+
+ conn
+ |> delete("/api/v1/suggestions/#{user_id}")
+ |> json_response_and_validate_schema(200)
+
+ res =
+ conn
+ |> get("/api/v2/suggestions")
+ |> json_response_and_validate_schema(200)
+
+ assert [] = res
+ end
+
+ test "returns v2 suggestions excluding blocked accounts", %{conn: conn, user: blocker} do
+ blocked = insert(:user, is_suggested: true)
+ {:ok, _} = CommonAPI.block(blocker, blocked)
+
+ res =
+ conn
+ |> get("/api/v2/suggestions")
+ |> json_response_and_validate_schema(200)
+
+ assert [] = res
+ end
+
+ test "returns v2 suggestions excluding followed accounts", %{conn: conn, user: follower} do
+ followed = insert(:user, is_suggested: true)
+ {:ok, _, _, _} = CommonAPI.follow(follower, followed)
+
+ res =
+ conn
+ |> get("/api/v2/suggestions")
+ |> json_response_and_validate_schema(200)
+
+ assert [] = res
+ end
+
+ test "dismiss suggestion", %{conn: conn, user: source} do
+ target = insert(:user, is_suggested: true)
+
+ res =
+ conn
+ |> delete("/api/v1/suggestions/#{target.id}")
+ |> json_response_and_validate_schema(200)
+
+ assert res == %{}
+ assert UserRelationship.exists?(:suggestion_dismiss, source, target)
+ end
end
diff --git a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs
index 6abc55ea6..b13a8033b 100644
--- a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
@@ -273,6 +273,24 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
[%{"id" => ^reply_from_me}, %{"id" => ^activity_id}] = response
end
+ test "doesn't return posts from users who blocked you when :blockers_visible is disabled" do
+ clear_config([:activitypub, :blockers_visible], false)
+
+ %{conn: conn, user: blockee} = oauth_access(["read:statuses"])
+ blocker = insert(:user)
+ {:ok, _} = User.block(blocker, blockee)
+
+ conn = assign(conn, :user, blockee)
+
+ {:ok, _} = CommonAPI.post(blocker, %{status: "hey!"})
+
+ response =
+ get(conn, "/api/v1/timelines/public")
+ |> json_response_and_validate_schema(200)
+
+ assert length(response) == 0
+ end
+
test "doesn't return replies if follow is posting with users from blocked domain" do
%{conn: conn, user: blocker} = oauth_access(["read:statuses"])
friend = insert(:user)
@@ -349,6 +367,47 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
}
] = result
end
+
+ test "should return local-only posts for authenticated users" do
+ user = insert(:user)
+ %{user: _reader, conn: conn} = oauth_access(["read:statuses"])
+
+ {:ok, %{id: id}} = CommonAPI.post(user, %{status: "#2hu #2HU", visibility: "local"})
+
+ result =
+ conn
+ |> get("/api/v1/timelines/public")
+ |> json_response_and_validate_schema(200)
+
+ assert [%{"id" => ^id}] = result
+ end
+
+ test "should not return local-only posts for users without read:statuses" do
+ user = insert(:user)
+ %{user: _reader, conn: conn} = oauth_access([])
+
+ {:ok, _activity} = CommonAPI.post(user, %{status: "#2hu #2HU", visibility: "local"})
+
+ result =
+ conn
+ |> get("/api/v1/timelines/public")
+ |> json_response_and_validate_schema(200)
+
+ assert [] = result
+ end
+
+ test "should not return local-only posts for anonymous users" do
+ user = insert(:user)
+
+ {:ok, _activity} = CommonAPI.post(user, %{status: "#2hu #2HU", visibility: "local"})
+
+ result =
+ build_conn()
+ |> get("/api/v1/timelines/public")
+ |> json_response_and_validate_schema(200)
+
+ assert [] = result
+ end
end
defp local_and_remote_activities do
diff --git a/test/pleroma/web/mastodon_api/masto_fe_controller_test.exs b/test/pleroma/web/mastodon_api/masto_fe_controller_test.exs
deleted file mode 100644
index e679d781a..000000000
--- a/test/pleroma/web/mastodon_api/masto_fe_controller_test.exs
+++ /dev/null
@@ -1,85 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.MastodonAPI.MastoFEControllerTest do
- use Pleroma.Web.ConnCase
-
- alias Pleroma.User
-
- import Pleroma.Factory
-
- setup do: clear_config([:instance, :public])
-
- test "put settings", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> assign(:token, insert(:oauth_token, user: user, scopes: ["write:accounts"]))
- |> put("/api/web/settings", %{"data" => %{"programming" => "socks"}})
-
- assert %{} = json_response(conn, 200)
-
- user = User.get_cached_by_ap_id(user.ap_id)
- assert user.mastofe_settings == %{"programming" => "socks"}
- end
-
- describe "index/2 redirections" do
- setup %{conn: conn} do
- session_opts = [
- store: :cookie,
- key: "_test",
- signing_salt: "cooldude"
- ]
-
- conn =
- conn
- |> Plug.Session.call(Plug.Session.init(session_opts))
- |> fetch_session()
-
- test_path = "/web/statuses/test"
- %{conn: conn, path: test_path}
- end
-
- test "redirects not logged-in users to the login page", %{conn: conn, path: path} do
- conn = get(conn, path)
-
- assert conn.status == 302
- assert redirected_to(conn) == "/web/login"
- end
-
- test "redirects not logged-in users to the login page on private instances", %{
- conn: conn,
- path: path
- } do
- clear_config([:instance, :public], false)
-
- conn = get(conn, path)
-
- assert conn.status == 302
- assert redirected_to(conn) == "/web/login"
- end
-
- test "does not redirect logged in users to the login page", %{conn: conn, path: path} do
- {:ok, app} = Pleroma.Web.MastodonAPI.AuthController.local_mastofe_app()
- token = insert(:oauth_token, app: app, scopes: ["read"])
-
- conn =
- conn
- |> assign(:user, token.user)
- |> assign(:token, token)
- |> get(path)
-
- assert conn.status == 200
- end
-
- test "saves referer path to session", %{conn: conn, path: path} do
- conn = get(conn, path)
- return_to = Plug.Conn.get_session(conn, :return_to)
-
- assert return_to == path
- end
- end
-end
diff --git a/test/pleroma/web/mastodon_api/mastodon_api_controller_test.exs b/test/pleroma/web/mastodon_api/mastodon_api_controller_test.exs
index c6332bd3e..622c5e3d5 100644
--- a/test/pleroma/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
diff --git a/test/pleroma/web/mastodon_api/mastodon_api_test.exs b/test/pleroma/web/mastodon_api/mastodon_api_test.exs
index 402bfd76f..250a20352 100644
--- a/test/pleroma/web/mastodon_api/mastodon_api_test.exs
+++ b/test/pleroma/web/mastodon_api/mastodon_api_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
diff --git a/test/pleroma/web/mastodon_api/update_credentials_test.exs b/test/pleroma/web/mastodon_api/update_credentials_test.exs
index cfbe6cf0e..d5fac7e25 100644
--- a/test/pleroma/web/mastodon_api/update_credentials_test.exs
+++ b/test/pleroma/web/mastodon_api/update_credentials_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
@@ -35,8 +35,8 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|> assign(:user, user)
|> patch("/api/v1/accounts/update_credentials", %{
"pleroma_settings_store" => %{
- masto_fe: %{
- theme: "bla"
+ soapbox_fe: %{
+ themeMode: "bla"
}
}
})
@@ -46,7 +46,7 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
assert user_data["pleroma"]["settings_store"] ==
%{
"pleroma_fe" => %{"theme" => "bla"},
- "masto_fe" => %{"theme" => "bla"}
+ "soapbox_fe" => %{"themeMode" => "bla"}
}
user = Repo.get(User, user_data["id"])
@@ -60,8 +60,8 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|> assign(:user, user)
|> patch("/api/v1/accounts/update_credentials", %{
"pleroma_settings_store" => %{
- masto_fe: %{
- theme: "blub"
+ soapbox_fe: %{
+ themeMode: "blub"
}
}
})
@@ -71,7 +71,7 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
assert user_data["pleroma"]["settings_store"] ==
%{
"pleroma_fe" => %{"theme" => "bla"},
- "masto_fe" => %{"theme" => "blub"}
+ "soapbox_fe" => %{"themeMode" => "blub"}
}
assert_called(Pleroma.Web.Federator.publish(:_))
@@ -88,9 +88,7 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
assert user_data = json_response_and_validate_schema(conn, 200)
assert user_data["note"] ==
- ~s(I drink <a class="hashtag" data-tag="cofe" href="http://localhost:4001/tag/cofe">#cofe</a> with <span class="h-card"><a class="u-url mention" data-user="#{
- user2.id
- }" href="#{user2.ap_id}" rel="ugc">@<span>#{user2.nickname}</span></a></span><br/><br/>suya..)
+ ~s(I drink <a class="hashtag" data-tag="cofe" href="http://localhost:4001/tag/cofe">#cofe</a> with <span class="h-card"><a class="u-url mention" data-user="#{user2.id}" href="#{user2.ap_id}" rel="ugc">@<span>#{user2.nickname}</span></a></span><br/><br/>suya..)
assert user_data["source"]["note"] == raw_bio
@@ -261,6 +259,34 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
assert user.avatar == nil
end
+ test "updates the user's avatar, upload_limit, returns a HTTP 413", %{conn: conn, user: user} do
+ upload_limit = Config.get([:instance, :upload_limit]) * 8 + 8
+
+ assert :ok ==
+ File.write(Path.absname("test/tmp/large_binary.data"), <<0::size(upload_limit)>>)
+
+ new_avatar_oversized = %Plug.Upload{
+ content_type: nil,
+ path: Path.absname("test/tmp/large_binary.data"),
+ filename: "large_binary.data"
+ }
+
+ assert user.avatar == %{}
+
+ res =
+ patch(conn, "/api/v1/accounts/update_credentials", %{"avatar" => new_avatar_oversized})
+
+ assert user_response = json_response_and_validate_schema(res, 413)
+ assert user_response["avatar"] != User.avatar_url(user)
+
+ user = User.get_by_id(user.id)
+ assert user.avatar == %{}
+
+ clear_config([:instance, :upload_limit], upload_limit)
+
+ assert :ok == File.rm(Path.absname("test/tmp/large_binary.data"))
+ end
+
test "updates the user's banner", %{user: user, conn: conn} do
new_header = %Plug.Upload{
content_type: "image/jpeg",
@@ -280,6 +306,32 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
assert user.banner == nil
end
+ test "updates the user's banner, upload_limit, returns a HTTP 413", %{conn: conn, user: user} do
+ upload_limit = Config.get([:instance, :upload_limit]) * 8 + 8
+
+ assert :ok ==
+ File.write(Path.absname("test/tmp/large_binary.data"), <<0::size(upload_limit)>>)
+
+ new_header_oversized = %Plug.Upload{
+ content_type: nil,
+ path: Path.absname("test/tmp/large_binary.data"),
+ filename: "large_binary.data"
+ }
+
+ res =
+ patch(conn, "/api/v1/accounts/update_credentials", %{"header" => new_header_oversized})
+
+ assert user_response = json_response_and_validate_schema(res, 413)
+ assert user_response["header"] != User.banner_url(user)
+
+ user = User.get_by_id(user.id)
+ assert user.banner == %{}
+
+ clear_config([:instance, :upload_limit], upload_limit)
+
+ assert :ok == File.rm(Path.absname("test/tmp/large_binary.data"))
+ end
+
test "updates the user's background", %{conn: conn, user: user} do
new_header = %Plug.Upload{
content_type: "image/jpeg",
@@ -303,6 +355,34 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
assert user.background == nil
end
+ test "updates the user's background, upload_limit, returns a HTTP 413", %{
+ conn: conn,
+ user: user
+ } do
+ upload_limit = Config.get([:instance, :upload_limit]) * 8 + 8
+
+ assert :ok ==
+ File.write(Path.absname("test/tmp/large_binary.data"), <<0::size(upload_limit)>>)
+
+ new_background_oversized = %Plug.Upload{
+ content_type: nil,
+ path: Path.absname("test/tmp/large_binary.data"),
+ filename: "large_binary.data"
+ }
+
+ res =
+ patch(conn, "/api/v1/accounts/update_credentials", %{
+ "pleroma_background_image" => new_background_oversized
+ })
+
+ assert user_response = json_response_and_validate_schema(res, 413)
+ assert user.background == %{}
+
+ clear_config([:instance, :upload_limit], upload_limit)
+
+ assert :ok == File.rm(Path.absname("test/tmp/large_binary.data"))
+ end
+
test "requires 'write:accounts' permission" do
token1 = insert(:oauth_token, scopes: ["read"])
token2 = insert(:oauth_token, scopes: ["write", "follow"])
@@ -372,6 +452,40 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
]
end
+ test "updates birth date", %{conn: conn} do
+ res =
+ patch(conn, "/api/v1/accounts/update_credentials", %{
+ "birthday" => "2001-02-12"
+ })
+
+ assert user_data = json_response_and_validate_schema(res, 200)
+ assert user_data["pleroma"]["birthday"] == "2001-02-12"
+ end
+
+ test "updates the user's show_birthday status", %{conn: conn} do
+ res =
+ patch(conn, "/api/v1/accounts/update_credentials", %{
+ "show_birthday" => true
+ })
+
+ assert user_data = json_response_and_validate_schema(res, 200)
+ assert user_data["source"]["pleroma"]["show_birthday"] == true
+ end
+
+ test "unsets birth date", %{conn: conn} do
+ patch(conn, "/api/v1/accounts/update_credentials", %{
+ "birthday" => "2001-02-12"
+ })
+
+ res =
+ patch(conn, "/api/v1/accounts/update_credentials", %{
+ "birthday" => ""
+ })
+
+ assert user_data = json_response_and_validate_schema(res, 200)
+ assert user_data["pleroma"]["birthday"] == nil
+ end
+
test "emojis in fields labels", %{conn: conn} do
fields = [
%{"name" => ":firefox:", "value" => "is best 2hu"},
diff --git a/test/pleroma/web/mastodon_api/views/account_view_test.exs b/test/pleroma/web/mastodon_api/views/account_view_test.exs
index 60881756d..3bb4970ca 100644
--- a/test/pleroma/web/mastodon_api/views/account_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/account_view_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
- use Pleroma.DataCase
+ use Pleroma.DataCase, async: false
alias Pleroma.User
alias Pleroma.UserRelationship
@@ -74,6 +74,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
fields: []
},
fqn: "shp@shitposter.club",
+ last_status_at: nil,
pleroma: %{
ap_id: user.ap_id,
also_known_as: ["https://shitposter.zone/users/shp"],
@@ -83,6 +84,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
tags: [],
is_admin: false,
is_moderator: false,
+ privileges: [],
+ is_suggested: false,
hide_favorites: true,
hide_followers: false,
hide_follows: false,
@@ -97,6 +100,147 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
assert expected == AccountView.render("show.json", %{user: user, skip_visibility_check: true})
end
+ describe "roles and privileges" do
+ setup do
+ clear_config([:instance, :moderator_privileges], [:cofe, :only_moderator])
+ clear_config([:instance, :admin_privileges], [:cofe, :only_admin])
+
+ %{
+ user: insert(:user),
+ moderator: insert(:user, is_moderator: true),
+ admin: insert(:user, is_admin: true),
+ moderator_admin: insert(:user, is_moderator: true, is_admin: true),
+ user_no_show_roles: insert(:user, show_role: false),
+ moderator_admin_no_show_roles:
+ insert(:user, is_moderator: true, is_admin: true, show_role: false)
+ }
+ end
+
+ test "shows roles and privileges when show_role: true", %{
+ user: user,
+ moderator: moderator,
+ admin: admin,
+ moderator_admin: moderator_admin,
+ user_no_show_roles: user_no_show_roles,
+ moderator_admin_no_show_roles: moderator_admin_no_show_roles
+ } do
+ assert %{pleroma: %{is_moderator: false, is_admin: false}} =
+ AccountView.render("show.json", %{user: user, skip_visibility_check: true})
+
+ assert [] ==
+ AccountView.render("show.json", %{user: user, skip_visibility_check: true})[
+ :pleroma
+ ][:privileges]
+ |> Enum.sort()
+
+ assert %{pleroma: %{is_moderator: true, is_admin: false}} =
+ AccountView.render("show.json", %{user: moderator, skip_visibility_check: true})
+
+ assert [:cofe, :only_moderator] ==
+ AccountView.render("show.json", %{user: moderator, skip_visibility_check: true})[
+ :pleroma
+ ][:privileges]
+ |> Enum.sort()
+
+ assert %{pleroma: %{is_moderator: false, is_admin: true}} =
+ AccountView.render("show.json", %{user: admin, skip_visibility_check: true})
+
+ assert [:cofe, :only_admin] ==
+ AccountView.render("show.json", %{user: admin, skip_visibility_check: true})[
+ :pleroma
+ ][:privileges]
+ |> Enum.sort()
+
+ assert %{pleroma: %{is_moderator: true, is_admin: true}} =
+ AccountView.render("show.json", %{
+ user: moderator_admin,
+ skip_visibility_check: true
+ })
+
+ assert [:cofe, :only_admin, :only_moderator] ==
+ AccountView.render("show.json", %{
+ user: moderator_admin,
+ skip_visibility_check: true
+ })[:pleroma][:privileges]
+ |> Enum.sort()
+
+ refute match?(
+ %{pleroma: %{is_moderator: _}},
+ AccountView.render("show.json", %{
+ user: user_no_show_roles,
+ skip_visibility_check: true
+ })
+ )
+
+ refute match?(
+ %{pleroma: %{is_admin: _}},
+ AccountView.render("show.json", %{
+ user: user_no_show_roles,
+ skip_visibility_check: true
+ })
+ )
+
+ refute match?(
+ %{pleroma: %{privileges: _}},
+ AccountView.render("show.json", %{
+ user: user_no_show_roles,
+ skip_visibility_check: true
+ })
+ )
+
+ refute match?(
+ %{pleroma: %{is_moderator: _}},
+ AccountView.render("show.json", %{
+ user: moderator_admin_no_show_roles,
+ skip_visibility_check: true
+ })
+ )
+
+ refute match?(
+ %{pleroma: %{is_admin: _}},
+ AccountView.render("show.json", %{
+ user: moderator_admin_no_show_roles,
+ skip_visibility_check: true
+ })
+ )
+
+ refute match?(
+ %{pleroma: %{privileges: _}},
+ AccountView.render("show.json", %{
+ user: moderator_admin_no_show_roles,
+ skip_visibility_check: true
+ })
+ )
+ end
+
+ test "shows roles and privileges when viewing own account, even when show_role: false", %{
+ user_no_show_roles: user_no_show_roles,
+ moderator_admin_no_show_roles: moderator_admin_no_show_roles
+ } do
+ assert %{pleroma: %{is_moderator: false, is_admin: false, privileges: []}} =
+ AccountView.render("show.json", %{
+ user: user_no_show_roles,
+ skip_visibility_check: true,
+ for: user_no_show_roles
+ })
+
+ assert %{
+ pleroma: %{
+ is_moderator: true,
+ is_admin: true,
+ privileges: privileges
+ }
+ } =
+ AccountView.render("show.json", %{
+ user: moderator_admin_no_show_roles,
+ skip_visibility_check: true,
+ for: moderator_admin_no_show_roles
+ })
+
+ assert [:cofe, :only_admin, :only_moderator] == privileges |> Enum.sort()
+ end
+ end
+
describe "favicon" do
setup do
[user: insert(:user)]
@@ -174,6 +318,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
fields: []
},
fqn: "shp@shitposter.club",
+ last_status_at: nil,
pleroma: %{
ap_id: user.ap_id,
also_known_as: [],
@@ -183,6 +328,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
tags: [],
is_admin: false,
is_moderator: false,
+ privileges: [],
+ is_suggested: false,
hide_favorites: true,
hide_followers: false,
hide_follows: false,
@@ -210,8 +357,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
assert represented.url == "https://channels.tests.funkwhale.audio/channels/compositions"
end
- test "Represent a deactivated user for an admin" do
- admin = insert(:user, is_admin: true)
+ test "Represent a deactivated user for a privileged user" do
+ clear_config([:instance, :moderator_privileges], [:users_manage_activation_state])
+
+ admin = insert(:user, is_moderator: true)
deactivated_user = insert(:user, is_active: false)
represented = AccountView.render("show.json", %{user: deactivated_user, for: admin})
assert represented[:pleroma][:deactivated] == true
@@ -268,10 +417,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
muting: false,
muting_notifications: false,
subscribing: false,
+ notifying: false,
requested: false,
domain_blocking: false,
showing_reblogs: true,
- endorsed: false
+ endorsed: false,
+ note: ""
}
test "represent a relationship for the following and followed user" do
@@ -293,6 +444,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
muting: true,
muting_notifications: true,
subscribing: true,
+ notifying: true,
showing_reblogs: false,
id: to_string(other_user.id)
}
@@ -487,6 +639,40 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
end
end
+ describe "hiding birthday" do
+ test "doesn't show birthday if hidden" do
+ user =
+ insert(:user, %{
+ birthday: "2001-02-12",
+ show_birthday: false
+ })
+
+ other_user = insert(:user)
+
+ user = User.get_cached_by_ap_id(user.ap_id)
+
+ assert AccountView.render(
+ "show.json",
+ %{user: user, for: other_user}
+ )[:birthday] == nil
+ end
+
+ test "shows hidden birthday to the account owner" do
+ user =
+ insert(:user, %{
+ birthday: "2001-02-12",
+ show_birthday: false
+ })
+
+ user = User.get_cached_by_ap_id(user.ap_id)
+
+ assert AccountView.render(
+ "show.json",
+ %{user: user, for: user}
+ )[:birthday] == nil
+ end
+ end
+
describe "follow requests counter" do
test "shows zero when no follow requests are pending" do
user = insert(:user)
@@ -593,4 +779,21 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|> assert()
end
end
+
+ test "renders mute expiration date" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _user_relationships} =
+ User.mute(user, other_user, %{notifications: true, duration: 24 * 60 * 60})
+
+ %{
+ mute_expires_at: mute_expires_at
+ } = AccountView.render("show.json", %{user: other_user, for: user, mutes: true})
+
+ assert DateTime.diff(
+ mute_expires_at,
+ DateTime.utc_now() |> DateTime.add(24 * 60 * 60)
+ ) in -3..3
+ end
end
diff --git a/test/pleroma/web/mastodon_api/views/conversation_view_test.exs b/test/pleroma/web/mastodon_api/views/conversation_view_test.exs
index 9639e95d2..d9529c346 100644
--- a/test/pleroma/web/mastodon_api/views/conversation_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/conversation_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do
diff --git a/test/pleroma/web/mastodon_api/views/list_view_test.exs b/test/pleroma/web/mastodon_api/views/list_view_test.exs
index a62495ebb..bbf87bab2 100644
--- a/test/pleroma/web/mastodon_api/views/list_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/list_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.ListViewTest do
diff --git a/test/pleroma/web/mastodon_api/views/marker_view_test.exs b/test/pleroma/web/mastodon_api/views/marker_view_test.exs
index 8d8c16f6c..43f8c4302 100644
--- a/test/pleroma/web/mastodon_api/views/marker_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/marker_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.MarkerViewTest do
diff --git a/test/pleroma/web/mastodon_api/views/notification_view_test.exs b/test/pleroma/web/mastodon_api/views/notification_view_test.exs
index 496a688d1..6ea894691 100644
--- a/test/pleroma/web/mastodon_api/views/notification_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/notification_view_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
- use Pleroma.DataCase
+ use Pleroma.DataCase, async: false
alias Pleroma.Activity
alias Pleroma.Chat
@@ -196,10 +196,33 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
test_notifications_rendering([notification], user, [expected])
end
+ test "Poll notification" do
+ user = insert(:user)
+ activity = insert(:question_activity, user: user)
+ {:ok, [notification]} = Notification.create_poll_notifications(activity)
+
+ expected = %{
+ id: to_string(notification.id),
+ pleroma: %{is_seen: false, is_muted: false},
+ type: "poll",
+ account:
+ AccountView.render("show.json", %{
+ user: user,
+ for: user
+ }),
+ status: StatusView.render("show.json", %{activity: activity, for: user}),
+ created_at: Utils.to_masto_date(notification.inserted_at)
+ }
+
+ test_notifications_rendering([notification], user, [expected])
+ end
+
test "Report notification" do
+ clear_config([:instance, :moderator_privileges], [:reports_manage_reports])
+
reporting_user = insert(:user)
reported_user = insert(:user)
- {:ok, moderator_user} = insert(:user) |> User.admin_api_update(%{is_moderator: true})
+ moderator_user = insert(:user, is_moderator: true)
{:ok, activity} = CommonAPI.report(reporting_user, %{account_id: reported_user.id})
{:ok, [notification]} = Notification.create_notifications(activity)
@@ -216,6 +239,32 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
test_notifications_rendering([notification], moderator_user, [expected])
end
+ test "Edit notification" do
+ user = insert(:user)
+ repeat_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "mew"})
+ {:ok, _} = CommonAPI.repeat(activity.id, repeat_user)
+ {:ok, update} = CommonAPI.update(user, activity, %{status: "mew mew"})
+
+ user = Pleroma.User.get_by_ap_id(user.ap_id)
+ activity = Pleroma.Activity.normalize(activity)
+ update = Pleroma.Activity.normalize(update)
+
+ {:ok, [notification]} = Notification.create_notifications(update)
+
+ expected = %{
+ id: to_string(notification.id),
+ pleroma: %{is_seen: false, is_muted: false},
+ type: "update",
+ account: AccountView.render("show.json", %{user: user, for: repeat_user}),
+ created_at: Utils.to_masto_date(notification.inserted_at),
+ status: StatusView.render("show.json", %{activity: activity, for: repeat_user})
+ }
+
+ test_notifications_rendering([notification], repeat_user, [expected])
+ end
+
test "muted notification" do
user = insert(:user)
another_user = insert(:user)
diff --git a/test/pleroma/web/mastodon_api/views/poll_view_test.exs b/test/pleroma/web/mastodon_api/views/poll_view_test.exs
index 224b26cb9..a73d862fd 100644
--- a/test/pleroma/web/mastodon_api/views/poll_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/poll_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.PollViewTest do
diff --git a/test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs b/test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs
index e323f3a1f..e5e510d33 100644
--- a/test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do
diff --git a/test/pleroma/web/mastodon_api/views/status_view_test.exs b/test/pleroma/web/mastodon_api/views/status_view_test.exs
index 9dfdf8bf0..f76b115b7 100644
--- a/test/pleroma/web/mastodon_api/views/status_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/status_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
@@ -14,10 +14,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
alias Pleroma.User
alias Pleroma.UserRelationship
alias Pleroma.Web.CommonAPI
- alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.MastodonAPI.StatusView
+ require Bitwise
+
import Pleroma.Factory
import Tesla.Mock
import OpenApiSpex.TestAssertions
@@ -226,7 +227,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
object_data = Object.normalize(note, fetch: false).data
user = User.get_cached_by_ap_id(note.data["actor"])
- convo_id = Utils.context_to_conversation_id(object_data["context"])
+ convo_id = :erlang.crc32(object_data["context"]) |> Bitwise.band(Bitwise.bnot(0x8000_0000))
status = StatusView.render("show.json", %{activity: note})
@@ -246,6 +247,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
content: HTML.filter_tags(object_data["content"]),
text: nil,
created_at: created_at,
+ edited_at: nil,
reblogs_count: 0,
replies_count: 0,
favourites_count: 0,
@@ -279,6 +281,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
pleroma: %{
local: true,
conversation_id: convo_id,
+ context: object_data["context"],
in_reply_to_account_acct: nil,
content: %{"text/plain" => HTML.strip_tags(object_data["content"])},
spoiler_text: %{"text/plain" => HTML.strip_tags(object_data["summary"])},
@@ -708,4 +711,55 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
status = StatusView.render("show.json", activity: visible, for: poster)
assert status.pleroma.parent_visible
end
+
+ test "it shows edited_at" do
+ poster = insert(:user)
+
+ {:ok, post} = CommonAPI.post(poster, %{status: "hey"})
+
+ status = StatusView.render("show.json", activity: post)
+ refute status.edited_at
+
+ {:ok, _} = CommonAPI.update(poster, post, %{status: "mew mew"})
+ edited = Pleroma.Activity.normalize(post)
+
+ status = StatusView.render("show.json", activity: edited)
+ assert status.edited_at
+ end
+
+ test "with a source object" do
+ note =
+ insert(:note,
+ data: %{"source" => %{"content" => "object source", "mediaType" => "text/markdown"}}
+ )
+
+ activity = insert(:note_activity, note: note)
+
+ status = StatusView.render("show.json", activity: activity, with_source: true)
+ assert status.text == "object source"
+ end
+
+ describe "source.json" do
+ test "with a source object, renders both source and content type" do
+ note =
+ insert(:note,
+ data: %{"source" => %{"content" => "object source", "mediaType" => "text/markdown"}}
+ )
+
+ activity = insert(:note_activity, note: note)
+
+ status = StatusView.render("source.json", activity: activity)
+ assert status.text == "object source"
+ assert status.content_type == "text/markdown"
+ end
+
+ test "with a source string, renders source and put text/plain as the content type" do
+ note = insert(:note, data: %{"source" => "string source"})
+ activity = insert(:note_activity, note: note)
+
+ status = StatusView.render("source.json", activity: activity)
+ assert status.text == "string source"
+ assert status.content_type == "text/plain"
+ end
+ end
end
diff --git a/test/pleroma/web/mastodon_api/views/subscription_view_test.exs b/test/pleroma/web/mastodon_api/views/subscription_view_test.exs
index 04b440389..fd4cd962a 100644
--- a/test/pleroma/web/mastodon_api/views/subscription_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/subscription_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.SubscriptionViewTest do
diff --git a/test/pleroma/web/mastodon_api/views/suggestion_view_test.exs b/test/pleroma/web/mastodon_api/views/suggestion_view_test.exs
new file mode 100644
index 000000000..b0db41047
--- /dev/null
+++ b/test/pleroma/web/mastodon_api/views/suggestion_view_test.exs
@@ -0,0 +1,34 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.SuggestionViewTest do
+ use Pleroma.DataCase, async: true
+ import Pleroma.Factory
+ alias Pleroma.Web.MastodonAPI.SuggestionView, as: View
+
+ test "show.json" do
+ user = insert(:user, is_suggested: true)
+ json = View.render("show.json", %{user: user, source: :staff, skip_visibility_check: true})
+
+ assert json.source == :staff
+ assert json.account.id == user.id
+ end
+
+ test "index.json" do
+ user1 = insert(:user, is_suggested: true)
+ user2 = insert(:user, is_suggested: true)
+ user3 = insert(:user, is_suggested: true)
+
+ [suggestion1, suggestion2, suggestion3] =
+ View.render("index.json", %{
+ users: [user1, user2, user3],
+ source: :staff,
+ skip_visibility_check: true
+ })
+
+ assert suggestion1.source == :staff
+ assert suggestion2.account.id == user2.id
+ assert suggestion3.account.url == user3.ap_id
+ end
+end
diff --git a/test/pleroma/web/media_proxy/invalidation/http_test.exs b/test/pleroma/web/media_proxy/invalidation/http_test.exs
index a15103c89..b920242fd 100644
--- a/test/pleroma/web/media_proxy/invalidation/http_test.exs
+++ b/test/pleroma/web/media_proxy/invalidation/http_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MediaProxy.Invalidation.HttpTest do
diff --git a/test/pleroma/web/media_proxy/invalidation/script_test.exs b/test/pleroma/web/media_proxy/invalidation/script_test.exs
index a6f88114f..3e8fd751d 100644
--- a/test/pleroma/web/media_proxy/invalidation/script_test.exs
+++ b/test/pleroma/web/media_proxy/invalidation/script_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MediaProxy.Invalidation.ScriptTest do
diff --git a/test/pleroma/web/media_proxy/invalidation_test.exs b/test/pleroma/web/media_proxy/invalidation_test.exs
index c77b8c94a..6196c69be 100644
--- a/test/pleroma/web/media_proxy/invalidation_test.exs
+++ b/test/pleroma/web/media_proxy/invalidation_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MediaProxy.InvalidationTest do
diff --git a/test/pleroma/web/media_proxy/media_proxy_controller_test.exs b/test/pleroma/web/media_proxy/media_proxy_controller_test.exs
index 2a449e56d..5246bf0c4 100644
--- a/test/pleroma/web/media_proxy/media_proxy_controller_test.exs
+++ b/test/pleroma/web/media_proxy/media_proxy_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
@@ -81,9 +81,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
missing_dependencies = Pleroma.Helpers.MediaHelper.missing_dependencies()
assert missing_dependencies == [],
- "Error: missing dependencies (please refer to `docs/installation`): #{
- inspect(missing_dependencies)
- }"
+ "Error: missing dependencies (please refer to `docs/installation`): #{inspect(missing_dependencies)}"
end
setup do
@@ -160,7 +158,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
media_proxy_url: media_proxy_url
} do
Tesla.Mock.mock(fn
- %{method: "head", url: ^media_proxy_url} ->
+ %{method: "HEAD", url: ^media_proxy_url} ->
%Tesla.Env{status: 500, body: ""}
end)
@@ -175,7 +173,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
media_proxy_url: media_proxy_url
} do
Tesla.Mock.mock(fn
- %{method: "head", url: ^media_proxy_url} ->
+ %{method: "HEAD", url: ^media_proxy_url} ->
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "application/pdf"}]}
end)
@@ -195,7 +193,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
clear_config([:media_preview_proxy, :min_content_length], 1_000_000_000)
Tesla.Mock.mock(fn
- %{method: "head", url: ^media_proxy_url} ->
+ %{method: "HEAD", url: ^media_proxy_url} ->
%Tesla.Env{
status: 200,
body: "",
@@ -220,7 +218,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
media_proxy_url: media_proxy_url
} do
Tesla.Mock.mock(fn
- %{method: "head", url: ^media_proxy_url} ->
+ %{method: "HEAD", url: ^media_proxy_url} ->
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/gif"}]}
end)
@@ -238,7 +236,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
media_proxy_url: media_proxy_url
} do
Tesla.Mock.mock(fn
- %{method: "head", url: ^media_proxy_url} ->
+ %{method: "HEAD", url: ^media_proxy_url} ->
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
end)
@@ -258,7 +256,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
clear_config([:media_preview_proxy, :min_content_length], 100_000)
Tesla.Mock.mock(fn
- %{method: "head", url: ^media_proxy_url} ->
+ %{method: "HEAD", url: ^media_proxy_url} ->
%Tesla.Env{
status: 200,
body: "",
@@ -280,7 +278,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
assert_dependencies_installed()
Tesla.Mock.mock(fn
- %{method: "head", url: ^media_proxy_url} ->
+ %{method: "HEAD", url: ^media_proxy_url} ->
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/png"}]}
%{method: :get, url: ^media_proxy_url} ->
@@ -302,7 +300,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
assert_dependencies_installed()
Tesla.Mock.mock(fn
- %{method: "head", url: ^media_proxy_url} ->
+ %{method: "HEAD", url: ^media_proxy_url} ->
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
%{method: :get, url: ^media_proxy_url} ->
@@ -322,7 +320,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
media_proxy_url: media_proxy_url
} do
Tesla.Mock.mock(fn
- %{method: "head", url: ^media_proxy_url} ->
+ %{method: "HEAD", url: ^media_proxy_url} ->
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
%{method: :get, url: ^media_proxy_url} ->
diff --git a/test/pleroma/web/media_proxy_test.exs b/test/pleroma/web/media_proxy_test.exs
index d97874f3a..ffab1247f 100644
--- a/test/pleroma/web/media_proxy_test.exs
+++ b/test/pleroma/web/media_proxy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MediaProxyTest do
diff --git a/test/pleroma/web/metadata/player_view_test.exs b/test/pleroma/web/metadata/player_view_test.exs
index 58caf6efd..7daa2f693 100644
--- a/test/pleroma/web/metadata/player_view_test.exs
+++ b/test/pleroma/web/metadata/player_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Metadata.PlayerViewTest do
diff --git a/test/pleroma/web/metadata/providers/feed_test.exs b/test/pleroma/web/metadata/providers/feed_test.exs
index 013d42498..e593453da 100644
--- a/test/pleroma/web/metadata/providers/feed_test.exs
+++ b/test/pleroma/web/metadata/providers/feed_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Metadata.Providers.FeedTest do
diff --git a/test/pleroma/web/metadata/providers/open_graph_test.exs b/test/pleroma/web/metadata/providers/open_graph_test.exs
index 28ca8839c..b7ce95f7d 100644
--- a/test/pleroma/web/metadata/providers/open_graph_test.exs
+++ b/test/pleroma/web/metadata/providers/open_graph_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
diff --git a/test/pleroma/web/metadata/providers/rel_me_test.exs b/test/pleroma/web/metadata/providers/rel_me_test.exs
index 0db6e7d22..cce4f3607 100644
--- a/test/pleroma/web/metadata/providers/rel_me_test.exs
+++ b/test/pleroma/web/metadata/providers/rel_me_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Metadata.Providers.RelMeTest do
diff --git a/test/pleroma/web/metadata/providers/restrict_indexing_test.exs b/test/pleroma/web/metadata/providers/restrict_indexing_test.exs
index aa253e5e2..70aa5f462 100644
--- a/test/pleroma/web/metadata/providers/restrict_indexing_test.exs
+++ b/test/pleroma/web/metadata/providers/restrict_indexing_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Metadata.Providers.RestrictIndexingTest do
diff --git a/test/pleroma/web/metadata/providers/twitter_card_test.exs b/test/pleroma/web/metadata/providers/twitter_card_test.exs
index 1b8d27cda..be4cfbe7b 100644
--- a/test/pleroma/web/metadata/providers/twitter_card_test.exs
+++ b/test/pleroma/web/metadata/providers/twitter_card_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
@@ -22,10 +22,10 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
res = TwitterCard.build_tags(%{user: user})
assert res == [
- {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
- {:meta, [property: "twitter:description", content: "born 19 March 1994"], []},
- {:meta, [property: "twitter:image", content: avatar_url], []},
- {:meta, [property: "twitter:card", content: "summary"], []}
+ {:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
+ {:meta, [name: "twitter:description", content: "born 19 March 1994"], []},
+ {:meta, [name: "twitter:image", content: avatar_url], []},
+ {:meta, [name: "twitter:card", content: "summary"], []}
]
end
@@ -39,6 +39,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
"actor" => user.ap_id,
"tag" => [],
"id" => "https://pleroma.gov/objects/whatever",
+ "summary" => "",
"content" => "pleroma in a nutshell"
}
})
@@ -46,11 +47,41 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
assert [
- {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
- {:meta, [property: "twitter:description", content: "pleroma in a nutshell"], []},
- {:meta, [property: "twitter:image", content: "http://localhost:4001/images/avi.png"],
+ {:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
+ {:meta, [name: "twitter:description", content: "pleroma in a nutshell"], []},
+ {:meta, [name: "twitter:image", content: "http://localhost:4001/images/avi.png"],
[]},
- {:meta, [property: "twitter:card", content: "summary"], []}
+ {:meta, [name: "twitter:card", content: "summary"], []}
+ ] == result
+ end
+
+ test "it uses summary as description if post has one" 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",
+ "summary" => "Public service announcement on caffeine consumption",
+ "content" => "cofe"
+ }
+ })
+
+ result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
+
+ assert [
+ {:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
+ {:meta,
+ [
+ name: "twitter:description",
+ content: "Public service announcement on caffeine consumption"
+ ], []},
+ {:meta, [name: "twitter:image", content: "http://localhost:4001/images/avi.png"],
+ []},
+ {:meta, [name: "twitter:card", content: "summary"], []}
] == result
end
@@ -65,6 +96,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
"actor" => user.ap_id,
"tag" => [],
"id" => "https://pleroma.gov/objects/whatever",
+ "summary" => "",
"content" => "pleroma in a nutshell",
"sensitive" => true,
"attachment" => [
@@ -91,11 +123,11 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
assert [
- {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
- {:meta, [property: "twitter:description", content: "pleroma in a nutshell"], []},
- {:meta, [property: "twitter:image", content: "http://localhost:4001/images/avi.png"],
+ {:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
+ {:meta, [name: "twitter:description", content: "pleroma in a nutshell"], []},
+ {:meta, [name: "twitter:image", content: "http://localhost:4001/images/avi.png"],
[]},
- {:meta, [property: "twitter:card", content: "summary"], []}
+ {:meta, [name: "twitter:card", content: "summary"], []}
] == result
end
@@ -109,6 +141,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
"actor" => user.ap_id,
"tag" => [],
"id" => "https://pleroma.gov/objects/whatever",
+ "summary" => "",
"content" => "pleroma in a nutshell",
"attachment" => [
%{
@@ -146,26 +179,26 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
assert [
- {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
- {:meta, [property: "twitter:description", content: "pleroma in a nutshell"], []},
- {:meta, [property: "twitter:card", content: "summary_large_image"], []},
- {:meta, [property: "twitter:player", content: "https://pleroma.gov/tenshi.png"], []},
- {:meta, [property: "twitter:player:width", content: "1280"], []},
- {:meta, [property: "twitter:player:height", content: "1024"], []},
- {:meta, [property: "twitter:card", content: "player"], []},
+ {:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
+ {:meta, [name: "twitter:description", content: "pleroma in a nutshell"], []},
+ {:meta, [name: "twitter:card", content: "summary_large_image"], []},
+ {:meta, [name: "twitter:player", content: "https://pleroma.gov/tenshi.png"], []},
+ {:meta, [name: "twitter:player:width", content: "1280"], []},
+ {:meta, [name: "twitter:player:height", content: "1024"], []},
+ {:meta, [name: "twitter:card", content: "player"], []},
{:meta,
[
- property: "twitter:player",
+ name: "twitter:player",
content: Router.Helpers.o_status_url(Endpoint, :notice_player, activity.id)
], []},
- {:meta, [property: "twitter:player:width", content: "800"], []},
- {:meta, [property: "twitter:player:height", content: "600"], []},
+ {:meta, [name: "twitter:player:width", content: "800"], []},
+ {:meta, [name: "twitter:player:height", content: "600"], []},
{:meta,
[
- property: "twitter:player:stream",
+ name: "twitter:player:stream",
content: "https://pleroma.gov/about/juche.webm"
], []},
- {:meta, [property: "twitter:player:stream:content_type", content: "video/webm"], []}
+ {:meta, [name: "twitter:player:stream:content_type", content: "video/webm"], []}
] == result
end
end
diff --git a/test/pleroma/web/metadata/utils_test.exs b/test/pleroma/web/metadata/utils_test.exs
index 074bd2e2f..85ef6033a 100644
--- a/test/pleroma/web/metadata/utils_test.exs
+++ b/test/pleroma/web/metadata/utils_test.exs
@@ -1,14 +1,14 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Metadata.UtilsTest do
- use Pleroma.DataCase, async: true
+ use Pleroma.DataCase, async: false
import Pleroma.Factory
alias Pleroma.Web.Metadata.Utils
describe "scrub_html_and_truncate/1" do
- test "it returns text without encode HTML" do
+ test "it returns content text without encode HTML if summary is nil" do
user = insert(:user)
note =
@@ -16,12 +16,60 @@ defmodule Pleroma.Web.Metadata.UtilsTest do
data: %{
"actor" => user.ap_id,
"id" => "https://pleroma.gov/objects/whatever",
+ "summary" => nil,
"content" => "Pleroma's really cool!"
}
})
assert Utils.scrub_html_and_truncate(note) == "Pleroma's really cool!"
end
+
+ test "it returns context text without encode HTML if summary is empty" do
+ user = insert(:user)
+
+ note =
+ insert(:note, %{
+ data: %{
+ "actor" => user.ap_id,
+ "id" => "https://pleroma.gov/objects/whatever",
+ "summary" => "",
+ "content" => "Pleroma's really cool!"
+ }
+ })
+
+ assert Utils.scrub_html_and_truncate(note) == "Pleroma's really cool!"
+ end
+
+ test "it returns summary text without encode HTML if summary is filled" do
+ user = insert(:user)
+
+ note =
+ insert(:note, %{
+ data: %{
+ "actor" => user.ap_id,
+ "id" => "https://pleroma.gov/objects/whatever",
+ "summary" => "Public service announcement on caffeine consumption",
+ "content" => "cofe"
+ }
+ })
+
+ assert Utils.scrub_html_and_truncate(note) ==
+ "Public service announcement on caffeine consumption"
+ end
+
+ test "it does not return old content after editing" do
+ user = insert(:user)
+
+ {:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew #def"})
+
+ object = Pleroma.Object.normalize(activity)
+ assert Utils.scrub_html_and_truncate(object) == "mew mew #def"
+
+ {:ok, update} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "mew mew #abc"})
+ update = Pleroma.Activity.normalize(update)
+ object = Pleroma.Object.normalize(update)
+ assert Utils.scrub_html_and_truncate(object) == "mew mew #abc"
+ end
end
describe "scrub_html_and_truncate/2" do
diff --git a/test/pleroma/web/mongoose_im_controller_test.exs b/test/pleroma/web/mongoose_im_controller_test.exs
index 43c4dfa33..46726fb62 100644
--- a/test/pleroma/web/mongoose_im_controller_test.exs
+++ b/test/pleroma/web/mongoose_im_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MongooseIMControllerTest do
diff --git a/test/pleroma/web/node_info_test.exs b/test/pleroma/web/node_info_test.exs
index ee6fdaae8..f474220be 100644
--- a/test/pleroma/web/node_info_test.exs
+++ b/test/pleroma/web/node_info_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.NodeInfoTest do
- use Pleroma.Web.ConnCase
+ use Pleroma.Web.ConnCase, async: false
import Pleroma.Factory
@@ -40,6 +40,19 @@ defmodule Pleroma.Web.NodeInfoTest do
assert admin.ap_id in result["metadata"]["staffAccounts"]
end
+ test "nodeinfo shows roles and privileges", %{conn: conn} do
+ clear_config([:instance, :moderator_privileges], [:cofe])
+ clear_config([:instance, :admin_privileges], [:suya, :cofe])
+
+ conn =
+ conn
+ |> get("/nodeinfo/2.1.json")
+
+ assert result = json_response(conn, 200)
+
+ assert %{"admin" => ["suya", "cofe"], "moderator" => ["cofe"]} == result["metadata"]["roles"]
+ end
+
test "nodeinfo shows restricted nicknames", %{conn: conn} do
conn =
conn
@@ -150,37 +163,127 @@ defmodule Pleroma.Web.NodeInfoTest do
)
end
- test "it shows MRF transparency data if enabled", %{conn: conn} do
- clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
- clear_config([:mrf, :transparency], true)
+ describe "Quarantined instances" do
+ setup do
+ clear_config([:mrf, :transparency], true)
+ quarantined_instances = [{"example.com", "reason to quarantine"}]
+ clear_config([:instance, :quarantined_instances], quarantined_instances)
+ end
- simple_config = %{"reject" => ["example.com"]}
- clear_config(:mrf_simple, simple_config)
+ test "shows quarantined instances data if enabled", %{conn: conn} do
+ expected_config = ["example.com"]
- response =
- conn
- |> get("/nodeinfo/2.1.json")
- |> json_response(:ok)
+ response =
+ conn
+ |> get("/nodeinfo/2.1.json")
+ |> json_response(:ok)
+
+ assert response["metadata"]["federation"]["quarantined_instances"] == expected_config
+ end
+
+ test "shows extra information in the quarantined_info field for relevant entries", %{
+ conn: conn
+ } do
+ clear_config([:mrf, :transparency], true)
- assert response["metadata"]["federation"]["mrf_simple"] == simple_config
+ expected_config = %{
+ "quarantined_instances" => %{
+ "example.com" => %{"reason" => "reason to quarantine"}
+ }
+ }
+
+ response =
+ conn
+ |> get("/nodeinfo/2.1.json")
+ |> json_response(:ok)
+
+ assert response["metadata"]["federation"]["quarantined_instances_info"] == expected_config
+ end
end
- test "it performs exclusions from MRF transparency data if configured", %{conn: conn} do
- clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
- clear_config([:mrf, :transparency], true)
- clear_config([:mrf, :transparency_exclusions], ["other.site"])
+ describe "MRF SimplePolicy" do
+ setup do
+ clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
+ clear_config([:mrf, :transparency], true)
+ end
- simple_config = %{"reject" => ["example.com", "other.site"]}
- clear_config(:mrf_simple, simple_config)
+ test "shows MRF transparency data if enabled", %{conn: conn} do
+ simple_config = %{"reject" => [{"example.com", ""}]}
+ clear_config(:mrf_simple, simple_config)
- expected_config = %{"reject" => ["example.com"]}
+ expected_config = %{"reject" => ["example.com"]}
- response =
- conn
- |> get("/nodeinfo/2.1.json")
- |> json_response(:ok)
+ response =
+ conn
+ |> get("/nodeinfo/2.1.json")
+ |> json_response(:ok)
+
+ assert response["metadata"]["federation"]["mrf_simple"] == expected_config
+ end
+
+ test "performs exclusions from MRF transparency data if configured", %{conn: conn} do
+ clear_config([:mrf, :transparency_exclusions], [
+ {"other.site", "We don't want them to know"}
+ ])
+
+ simple_config = %{"reject" => [{"example.com", ""}, {"other.site", ""}]}
+ clear_config(:mrf_simple, simple_config)
+
+ expected_config = %{"reject" => ["example.com"]}
- assert response["metadata"]["federation"]["mrf_simple"] == expected_config
- assert response["metadata"]["federation"]["exclusions"] == true
+ response =
+ conn
+ |> get("/nodeinfo/2.1.json")
+ |> json_response(:ok)
+
+ assert response["metadata"]["federation"]["mrf_simple"] == expected_config
+ assert response["metadata"]["federation"]["exclusions"] == true
+ end
+
+ test "shows extra information in the mrf_simple_info field for relevant entries", %{
+ conn: conn
+ } do
+ simple_config = %{
+ media_removal: [{"no.media", "LEEWWWDD >//<"}],
+ media_nsfw: [],
+ federated_timeline_removal: [{"no.ftl", ""}],
+ report_removal: [],
+ reject: [
+ {"example.instance", "Some reason"},
+ {"uwu.owo", "awoo to much"},
+ {"no.reason", ""}
+ ],
+ followers_only: [],
+ accept: [],
+ avatar_removal: [],
+ banner_removal: [],
+ reject_deletes: [
+ {"peak.me", "I want to peak at what they don't want me to see, eheh"}
+ ]
+ }
+
+ clear_config(:mrf_simple, simple_config)
+
+ clear_config([:mrf, :transparency_exclusions], [
+ {"peak.me", "I don't want them to know"}
+ ])
+
+ expected_config = %{
+ "media_removal" => %{
+ "no.media" => %{"reason" => "LEEWWWDD >//<"}
+ },
+ "reject" => %{
+ "example.instance" => %{"reason" => "Some reason"},
+ "uwu.owo" => %{"reason" => "awoo to much"}
+ }
+ }
+
+ response =
+ conn
+ |> get("/nodeinfo/2.1.json")
+ |> json_response(:ok)
+
+ assert response["metadata"]["federation"]["mrf_simple_info"] == expected_config
+ end
end
end
diff --git a/test/pleroma/web/o_auth/app_test.exs b/test/pleroma/web/o_auth/app_test.exs
index fc2f0d940..96a67de6b 100644
--- a/test/pleroma/web/o_auth/app_test.exs
+++ b/test/pleroma/web/o_auth/app_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OAuth.AppTest do
@@ -41,4 +41,16 @@ defmodule Pleroma.Web.OAuth.AppTest do
assert error.type == :unique
end
end
+
+ test "get_user_apps/1" do
+ user = insert(:user)
+
+ apps = [
+ insert(:oauth_app, user_id: user.id),
+ insert(:oauth_app, user_id: user.id),
+ insert(:oauth_app, user_id: user.id)
+ ]
+
+ assert Enum.sort(App.get_user_apps(user)) == Enum.sort(apps)
+ end
end
diff --git a/test/pleroma/web/o_auth/authorization_test.exs b/test/pleroma/web/o_auth/authorization_test.exs
index fc1c04c4c..a44265615 100644
--- a/test/pleroma/web/o_auth/authorization_test.exs
+++ b/test/pleroma/web/o_auth/authorization_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OAuth.AuthorizationTest do
diff --git a/test/pleroma/web/o_auth/ldap_authorization_test.exs b/test/pleroma/web/o_auth/ldap_authorization_test.exs
index 61b9ce6b7..5ab8236b5 100644
--- a/test/pleroma/web/o_auth/ldap_authorization_test.exs
+++ b/test/pleroma/web/o_auth/ldap_authorization_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OAuth.LDAPAuthorizationTest do
diff --git a/test/pleroma/web/o_auth/mfa_controller_test.exs b/test/pleroma/web/o_auth/mfa_controller_test.exs
index 17bbde85b..62404c768 100644
--- a/test/pleroma/web/o_auth/mfa_controller_test.exs
+++ b/test/pleroma/web/o_auth/mfa_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OAuth.MFAControllerTest do
diff --git a/test/pleroma/web/o_auth/o_auth_controller_test.exs b/test/pleroma/web/o_auth/o_auth_controller_test.exs
index 0fdd5b8e9..f41d6a322 100644
--- a/test/pleroma/web/o_auth/o_auth_controller_test.exs
+++ b/test/pleroma/web/o_auth/o_auth_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OAuth.OAuthControllerTest do
diff --git a/test/pleroma/web/o_auth/token/utils_test.exs b/test/pleroma/web/o_auth/token/utils_test.exs
index d2e7a0904..e688ad750 100644
--- a/test/pleroma/web/o_auth/token/utils_test.exs
+++ b/test/pleroma/web/o_auth/token/utils_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OAuth.Token.UtilsTest do
diff --git a/test/pleroma/web/o_auth/token_test.exs b/test/pleroma/web/o_auth/token_test.exs
index 8c0858ebc..5a6ab85be 100644
--- a/test/pleroma/web/o_auth/token_test.exs
+++ b/test/pleroma/web/o_auth/token_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OAuth.TokenTest do
diff --git a/test/pleroma/web/o_status/o_status_controller_test.exs b/test/pleroma/web/o_status/o_status_controller_test.exs
index 81d669837..36e581f5e 100644
--- a/test/pleroma/web/o_status/o_status_controller_test.exs
+++ b/test/pleroma/web/o_status/o_status_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OStatus.OStatusControllerTest do
diff --git a/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs
index 9f14c5577..8f000760f 100644
--- a/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
@@ -174,9 +174,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
response =
conn
|> get(
- "/api/v1/pleroma/accounts/#{user.id}/favourites?since_id=#{third_activity.id}&max_id=#{
- seventh_activity.id
- }"
+ "/api/v1/pleroma/accounts/#{user.id}/favourites?since_id=#{third_activity.id}&max_id=#{seventh_activity.id}"
)
|> json_response_and_validate_schema(:ok)
@@ -281,4 +279,84 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
assert %{"error" => "Record not found"} = json_response_and_validate_schema(conn, 404)
end
end
+
+ describe "account endorsements" do
+ test "returns a list of pinned accounts", %{conn: conn} do
+ %{id: id1} = user1 = insert(:user)
+ %{id: id2} = user2 = insert(:user)
+ %{id: id3} = user3 = insert(:user)
+
+ CommonAPI.follow(user1, user2)
+ CommonAPI.follow(user1, user3)
+
+ User.endorse(user1, user2)
+ User.endorse(user1, user3)
+
+ [%{"id" => ^id2}, %{"id" => ^id3}] =
+ conn
+ |> get("/api/v1/pleroma/accounts/#{id1}/endorsements")
+ |> json_response_and_validate_schema(200)
+ end
+
+ test "returns 404 error when specified user is not exist", %{conn: conn} do
+ conn = get(conn, "/api/v1/pleroma/accounts/test/endorsements")
+
+ assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}
+ end
+ end
+
+ describe "birthday reminders" do
+ test "returns a list of friends having birthday on specified day" do
+ %{user: user, conn: conn} = oauth_access(["read:accounts"])
+
+ %{id: id1} =
+ user1 =
+ insert(:user, %{
+ birthday: "2001-02-12",
+ show_birthday: true
+ })
+
+ user2 =
+ insert(:user, %{
+ birthday: "2001-02-14",
+ show_birthday: true
+ })
+
+ user3 = insert(:user)
+
+ CommonAPI.follow(user, user1)
+ CommonAPI.follow(user, user2)
+ CommonAPI.follow(user, user3)
+
+ [%{"id" => ^id1}] =
+ conn
+ |> get("/api/v1/pleroma/birthdays?day=12&month=2")
+ |> json_response_and_validate_schema(:ok)
+ end
+
+ test "the list doesn't list friends with hidden birth date" do
+ %{user: user, conn: conn} = oauth_access(["read:accounts"])
+
+ user1 =
+ insert(:user, %{
+ birthday: "2001-02-12",
+ show_birthday: false
+ })
+
+ %{id: id2} =
+ user2 =
+ insert(:user, %{
+ birthday: "2001-02-12",
+ show_birthday: true
+ })
+
+ CommonAPI.follow(user, user1)
+ CommonAPI.follow(user, user2)
+
+ [%{"id" => ^id2}] =
+ conn
+ |> get("/api/v1/pleroma/birthdays?day=12&month=2")
+ |> json_response_and_validate_schema(:ok)
+ end
+ end
end
diff --git a/test/pleroma/web/pleroma_api/controllers/app_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/app_controller_test.exs
new file mode 100644
index 000000000..f630875d5
--- /dev/null
+++ b/test/pleroma/web/pleroma_api/controllers/app_controller_test.exs
@@ -0,0 +1,53 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.PleromaAPI.AppControllerTest do
+ use Pleroma.Web.ConnCase, async: true
+
+ alias Pleroma.Web.OAuth.App
+ alias Pleroma.Web.Push
+
+ import Pleroma.Factory
+
+ test "apps", %{conn: conn} do
+ user = insert(:user)
+ app_attrs = build(:oauth_app)
+
+ creation =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> assign(:user, user)
+ |> post("/api/v1/apps", %{
+ client_name: app_attrs.client_name,
+ redirect_uris: app_attrs.redirect_uris
+ })
+
+ [app] = App.get_user_apps(user)
+
+ expected = %{
+ "name" => app.client_name,
+ "website" => app.website,
+ "client_id" => app.client_id,
+ "client_secret" => app.client_secret,
+ "id" => app.id |> to_string(),
+ "redirect_uri" => app.redirect_uris,
+ "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
+ }
+
+ assert expected == json_response_and_validate_schema(creation, 200)
+
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> assign(:user, user)
+ |> assign(:token, insert(:oauth_token, user: user, scopes: ["read", "follow"]))
+ |> get("/api/v1/pleroma/apps")
+ |> json_response_and_validate_schema(200)
+
+ [apps] = response
+
+ assert length(response) == 1
+ assert apps["client_id"] == app.client_id
+ end
+end
diff --git a/test/pleroma/web/pleroma_api/controllers/backup_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/backup_controller_test.exs
index 3ee660a05..a758925b7 100644
--- a/test/pleroma/web/pleroma_api/controllers/backup_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/backup_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do
@@ -11,7 +11,7 @@ defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do
setup do
clear_config([Pleroma.Upload, :uploader])
clear_config([Backup, :limit_days])
- oauth_access(["read:accounts"])
+ oauth_access(["read:backups"])
end
test "GET /api/v1/pleroma/backups", %{user: user, conn: conn} do
@@ -82,4 +82,24 @@ defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do
|> post("/api/v1/pleroma/backups")
|> json_response_and_validate_schema(400)
end
+
+ test "Backup without email address" do
+ user = Pleroma.Factory.insert(:user, email: nil)
+ %{conn: conn} = oauth_access(["read:backups"], user: user)
+
+ assert is_nil(user.email)
+
+ assert [
+ %{
+ "content_type" => "application/zip",
+ "url" => _url,
+ "file_size" => 0,
+ "processed" => false,
+ "inserted_at" => _
+ }
+ ] =
+ conn
+ |> post("/api/v1/pleroma/backups")
+ |> json_response_and_validate_schema(:ok)
+ end
end
diff --git a/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs
index 99b0d43a7..aa40c6f44 100644
--- a/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
use Pleroma.Web.ConnCase
diff --git a/test/pleroma/web/pleroma_api/controllers/conversation_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/conversation_controller_test.exs
index 54f2c5a58..c8dd74b03 100644
--- a/test/pleroma/web/pleroma_api/controllers/conversation_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/conversation_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.ConversationControllerTest do
diff --git a/test/pleroma/web/pleroma_api/controllers/emoji_file_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/emoji_file_controller_test.exs
index 547391249..540b452c7 100644
--- a/test/pleroma/web/pleroma_api/controllers/emoji_file_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/emoji_file_controller_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
- use Pleroma.Web.ConnCase
+ use Pleroma.Web.ConnCase, async: false
import Mock
import Tesla.Mock
@@ -30,6 +30,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
describe "POST/PATCH/DELETE /api/pleroma/emoji/packs/files?name=:name" do
setup do
+ clear_config([:instance, :admin_privileges], [:emoji_manage_emoji])
pack_file = "#{@emoji_path}/test_pack/pack.json"
original_content = File.read!(pack_file)
@@ -377,5 +378,32 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
})
|> json_response_and_validate_schema(:bad_request)
end
+
+ test "it requires privileged role :emoji_manage_emoji", %{admin_conn: admin_conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ assert admin_conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/emoji/packs/files?name=test_pack", %{
+ file: %Plug.Upload{
+ filename: "shortcode.png",
+ path: "#{Pleroma.Config.get([:instance, :static_dir])}/add/shortcode.png"
+ }
+ })
+ |> json_response(:forbidden)
+
+ assert admin_conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> patch("/api/pleroma/emoji/packs/files?name=test_pack", %{
+ shortcode: "blank",
+ new_filename: "dir_2/blank_3.png"
+ })
+ |> json_response(:forbidden)
+
+ assert admin_conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> delete("/api/pleroma/emoji/packs/files?name=test_pack&shortcode=blank3")
+ |> json_response(:forbidden)
+ end
end
end
diff --git a/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs
index d1ba067b8..1d5240639 100644
--- a/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
@@ -99,6 +99,10 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
end
describe "GET /api/pleroma/emoji/packs/remote" do
+ setup do
+ clear_config([:instance, :admin_privileges], [:emoji_manage_emoji])
+ end
+
test "shareable instance", %{admin_conn: admin_conn, conn: conn} do
resp =
conn
@@ -136,6 +140,14 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
"error" => "The requested instance does not support sharing emoji packs"
}
end
+
+ test "it requires privileged role :emoji_manage_emoji", %{admin_conn: admin_conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ assert admin_conn
+ |> get("/api/pleroma/emoji/packs/remote?url=https://example.com")
+ |> json_response(:forbidden)
+ end
end
describe "GET /api/pleroma/emoji/packs/archive?name=:name" do
@@ -170,6 +182,10 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
end
describe "POST /api/pleroma/emoji/packs/download" do
+ setup do
+ clear_config([:instance, :admin_privileges], [:emoji_manage_emoji])
+ end
+
test "shared pack from remote and non shared from fallback-src", %{
admin_conn: admin_conn,
conn: conn
@@ -344,10 +360,24 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
"The pack was not set as shared and there is no fallback src to download from"
}
end
+
+ test "it requires privileged role :emoji_manage_emoji", %{admin_conn: conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ assert conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/emoji/packs/download", %{
+ url: "https://example.com",
+ name: "test_pack",
+ as: "test_pack2"
+ })
+ |> json_response(:forbidden)
+ end
end
describe "PATCH/update /api/pleroma/emoji/pack?name=:name" do
setup do
+ clear_config([:instance, :admin_privileges], [:emoji_manage_emoji])
pack_file = "#{@emoji_path}/test_pack/pack.json"
original_content = File.read!(pack_file)
@@ -435,9 +465,25 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
"error" => "The fallback archive does not have all files specified in pack.json"
}
end
+
+ test "it requires privileged role :emoji_manage_emoji", %{
+ admin_conn: conn,
+ new_data: new_data
+ } do
+ clear_config([:instance, :admin_privileges], [])
+
+ assert conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> patch("/api/pleroma/emoji/pack?name=test_pack", %{metadata: new_data})
+ |> json_response(:forbidden)
+ end
end
describe "POST/DELETE /api/pleroma/emoji/pack?name=:name" do
+ setup do
+ clear_config([:instance, :admin_privileges], [:emoji_manage_emoji])
+ end
+
test "returns an error on creates pack when file system not writable", %{
admin_conn: admin_conn
} do
@@ -520,6 +566,18 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
"error" => "pack name cannot be empty"
}
end
+
+ test "it requires privileged role :emoji_manage_emoji", %{admin_conn: admin_conn} do
+ clear_config([:instance, :admin_privileges], [])
+
+ assert admin_conn
+ |> post("/api/pleroma/emoji/pack?name= ")
+ |> json_response(:forbidden)
+
+ assert admin_conn
+ |> delete("/api/pleroma/emoji/pack?name= ")
+ |> json_response(:forbidden)
+ end
end
test "deleting nonexisting pack", %{admin_conn: admin_conn} do
@@ -578,6 +636,12 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
"blank2" => "blank.png",
"foo" => "blank.png"
}
+
+ clear_config([:instance, :admin_privileges], [])
+
+ assert admin_conn
+ |> get("/api/pleroma/emoji/packs/import")
+ |> json_response(:forbidden)
end
describe "GET /api/pleroma/emoji/pack?name=:name" do
diff --git a/test/pleroma/web/pleroma_api/controllers/emoji_reaction_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/emoji_reaction_controller_test.exs
index 28483985c..77c75b560 100644
--- a/test/pleroma/web/pleroma_api/controllers/emoji_reaction_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/emoji_reaction_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do
diff --git a/test/pleroma/web/pleroma_api/controllers/instances_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/instances_controller_test.exs
index 54cf9d083..365d26ab1 100644
--- a/test/pleroma/web/pleroma_api/controllers/instances_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/instances_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaApi.InstancesControllerTest do
diff --git a/test/pleroma/web/pleroma_api/controllers/mascot_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/mascot_controller_test.exs
index 0011ddd54..b72569d4b 100644
--- a/test/pleroma/web/pleroma_api/controllers/mascot_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/mascot_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
diff --git a/test/pleroma/web/pleroma_api/controllers/notification_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/notification_controller_test.exs
index 08f374908..b8c7964f9 100644
--- a/test/pleroma/web/pleroma_api/controllers/notification_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/notification_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.NotificationControllerTest do
diff --git a/test/pleroma/web/pleroma_api/controllers/report_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/report_controller_test.exs
index c507aeca0..7940564b7 100644
--- a/test/pleroma/web/pleroma_api/controllers/report_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/report_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.ReportControllerTest do
diff --git a/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs
index d4546f442..908ce962d 100644
--- a/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do
diff --git a/test/pleroma/web/pleroma_api/controllers/settings_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/settings_controller_test.exs
new file mode 100644
index 000000000..e3c752d53
--- /dev/null
+++ b/test/pleroma/web/pleroma_api/controllers/settings_controller_test.exs
@@ -0,0 +1,126 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.PleromaAPI.SettingsControllerTest do
+ use Pleroma.Web.ConnCase
+
+ import Pleroma.Factory
+
+ describe "GET /api/v1/pleroma/settings/:app" do
+ setup do
+ oauth_access(["read:accounts"])
+ end
+
+ test "it gets empty settings", %{conn: conn} do
+ response =
+ conn
+ |> get("/api/v1/pleroma/settings/pleroma-fe")
+ |> json_response_and_validate_schema(:ok)
+
+ assert response == %{}
+ end
+
+ test "it gets settings", %{conn: conn, user: user} do
+ response =
+ conn
+ |> assign(
+ :user,
+ struct(user,
+ pleroma_settings_store: %{
+ "pleroma-fe" => %{
+ "foo" => "bar"
+ }
+ }
+ )
+ )
+ |> get("/api/v1/pleroma/settings/pleroma-fe")
+ |> json_response_and_validate_schema(:ok)
+
+ assert %{"foo" => "bar"} == response
+ end
+ end
+
+ describe "POST /api/v1/pleroma/settings/:app" do
+ setup do
+ settings = %{
+ "foo" => "bar",
+ "nested" => %{
+ "1" => "2"
+ }
+ }
+
+ user =
+ insert(
+ :user,
+ %{
+ pleroma_settings_store: %{
+ "pleroma-fe" => settings
+ }
+ }
+ )
+
+ %{conn: conn} = oauth_access(["write:accounts"], user: user)
+
+ %{conn: conn, user: user, settings: settings}
+ end
+
+ test "it adds keys", %{conn: conn} do
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch("/api/v1/pleroma/settings/pleroma-fe", %{
+ "foo" => "edited",
+ "bar" => "new",
+ "nested" => %{"3" => "4"}
+ })
+ |> json_response_and_validate_schema(:ok)
+
+ assert response == %{
+ "foo" => "edited",
+ "bar" => "new",
+ "nested" => %{
+ "1" => "2",
+ "3" => "4"
+ }
+ }
+ end
+
+ test "it removes keys", %{conn: conn} do
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch("/api/v1/pleroma/settings/pleroma-fe", %{
+ "foo" => nil,
+ "bar" => nil,
+ "nested" => %{
+ "1" => nil,
+ "3" => nil
+ }
+ })
+ |> json_response_and_validate_schema(:ok)
+
+ assert response == %{
+ "nested" => %{}
+ }
+ end
+
+ test "it does not override settings for other apps", %{
+ conn: conn,
+ user: user,
+ settings: settings
+ } do
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch("/api/v1/pleroma/settings/admin-fe", %{"foo" => "bar"})
+ |> json_response_and_validate_schema(:ok)
+
+ user = Pleroma.User.get_by_id(user.id)
+
+ assert user.pleroma_settings_store == %{
+ "pleroma-fe" => settings,
+ "admin-fe" => %{"foo" => "bar"}
+ }
+ end
+ end
+end
diff --git a/test/pleroma/web/pleroma_api/controllers/two_factor_authentication_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/two_factor_authentication_controller_test.exs
index 24074f4e5..aa44cf473 100644
--- a/test/pleroma/web/pleroma_api/controllers/two_factor_authentication_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/two_factor_authentication_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.TwoFactorAuthenticationControllerTest do
diff --git a/test/pleroma/web/pleroma_api/controllers/user_import_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/user_import_controller_test.exs
index d977bc3a2..52a62e416 100644
--- a/test/pleroma/web/pleroma_api/controllers/user_import_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/user_import_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
diff --git a/test/pleroma/web/pleroma_api/views/app_view_test.exs b/test/pleroma/web/pleroma_api/views/app_view_test.exs
new file mode 100644
index 000000000..255b8e549
--- /dev/null
+++ b/test/pleroma/web/pleroma_api/views/app_view_test.exs
@@ -0,0 +1,21 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.PleromaAPI.AppViewTest do
+ use Pleroma.DataCase, async: true
+ alias Pleroma.Web.PleromaAPI.AppView
+ import Pleroma.Factory
+
+ test "index.json" do
+ apps = [
+ insert(:oauth_app),
+ insert(:oauth_app),
+ insert(:oauth_app)
+ ]
+
+ results = AppView.render("index.json", %{apps: apps})
+
+ assert [%{client_id: _, client_secret: _}, _, _] = results
+ end
+end
diff --git a/test/pleroma/web/pleroma_api/views/backup_view_test.exs b/test/pleroma/web/pleroma_api/views/backup_view_test.exs
index 9b4298dd1..a86688bc4 100644
--- a/test/pleroma/web/pleroma_api/views/backup_view_test.exs
+++ b/test/pleroma/web/pleroma_api/views/backup_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.BackupViewTest do
diff --git a/test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs b/test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs
index 6deaa2102..017c9c5c0 100644
--- a/test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs
+++ b/test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.ChatMessageReferenceViewTest do
diff --git a/test/pleroma/web/pleroma_api/views/chat_view_test.exs b/test/pleroma/web/pleroma_api/views/chat_view_test.exs
index 5456c2de0..405f1b6b7 100644
--- a/test/pleroma/web/pleroma_api/views/chat_view_test.exs
+++ b/test/pleroma/web/pleroma_api/views/chat_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.ChatViewTest do
diff --git a/test/pleroma/web/pleroma_api/views/scrobble_view_test.exs b/test/pleroma/web/pleroma_api/views/scrobble_view_test.exs
index 382051f6f..7d547ec3a 100644
--- a/test/pleroma/web/pleroma_api/views/scrobble_view_test.exs
+++ b/test/pleroma/web/pleroma_api/views/scrobble_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.ScrobbleViewTest do
diff --git a/test/pleroma/web/plugs/admin_secret_authentication_plug_test.exs b/test/pleroma/web/plugs/admin_secret_authentication_plug_test.exs
index 79561afb7..8337969fe 100644
--- a/test/pleroma/web/plugs/admin_secret_authentication_plug_test.exs
+++ b/test/pleroma/web/plugs/admin_secret_authentication_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.AdminSecretAuthenticationPlugTest do
diff --git a/test/pleroma/web/plugs/authentication_plug_test.exs b/test/pleroma/web/plugs/authentication_plug_test.exs
index 118ab302a..41fdb93bc 100644
--- a/test/pleroma/web/plugs/authentication_plug_test.exs
+++ b/test/pleroma/web/plugs/authentication_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.AuthenticationPlugTest do
diff --git a/test/pleroma/web/plugs/basic_auth_decoder_plug_test.exs b/test/pleroma/web/plugs/basic_auth_decoder_plug_test.exs
index e90078eb5..099216734 100644
--- a/test/pleroma/web/plugs/basic_auth_decoder_plug_test.exs
+++ b/test/pleroma/web/plugs/basic_auth_decoder_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.BasicAuthDecoderPlugTest do
diff --git a/test/pleroma/web/plugs/cache_control_test.exs b/test/pleroma/web/plugs/cache_control_test.exs
index 263961897..b41472dc8 100644
--- a/test/pleroma/web/plugs/cache_control_test.exs
+++ b/test/pleroma/web/plugs/cache_control_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.CacheControlTest do
diff --git a/test/pleroma/web/plugs/cache_test.exs b/test/pleroma/web/plugs/cache_test.exs
index 4e729cafb..0c119528d 100644
--- a/test/pleroma/web/plugs/cache_test.exs
+++ b/test/pleroma/web/plugs/cache_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.CacheTest do
diff --git a/test/pleroma/web/plugs/digest_plug_test.exs b/test/pleroma/web/plugs/digest_plug_test.exs
index 629c28c93..19f8a6f49 100644
--- a/test/pleroma/web/plugs/digest_plug_test.exs
+++ b/test/pleroma/web/plugs/digest_plug_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.Plugs.DigestPlugTest do
use ExUnit.Case, async: true
use Plug.Test
diff --git a/test/pleroma/web/plugs/ensure_authenticated_plug_test.exs b/test/pleroma/web/plugs/ensure_authenticated_plug_test.exs
index 6b3ee3d87..da6b29f0b 100644
--- a/test/pleroma/web/plugs/ensure_authenticated_plug_test.exs
+++ b/test/pleroma/web/plugs/ensure_authenticated_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.EnsureAuthenticatedPlugTest do
diff --git a/test/pleroma/web/plugs/ensure_privileged_plug_test.exs b/test/pleroma/web/plugs/ensure_privileged_plug_test.exs
new file mode 100644
index 000000000..4b6679b66
--- /dev/null
+++ b/test/pleroma/web/plugs/ensure_privileged_plug_test.exs
@@ -0,0 +1,96 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Plugs.EnsurePrivilegedPlugTest do
+ use Pleroma.Web.ConnCase, async: true
+
+ alias Pleroma.Web.Plugs.EnsurePrivilegedPlug
+ import Pleroma.Factory
+
+ test "denies a user that isn't moderator or admin" do
+ clear_config([:instance, :admin_privileges], [])
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> EnsurePrivilegedPlug.call(:cofe)
+
+ assert conn.status == 403
+ end
+
+ test "accepts an admin that is privileged" do
+ clear_config([:instance, :admin_privileges], [:cofe])
+ user = insert(:user, is_admin: true)
+ conn = assign(build_conn(), :user, user)
+
+ ret_conn = EnsurePrivilegedPlug.call(conn, :cofe)
+
+ assert conn == ret_conn
+ end
+
+ test "denies an admin that isn't privileged" do
+ clear_config([:instance, :admin_privileges], [:suya])
+ user = insert(:user, is_admin: true)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> EnsurePrivilegedPlug.call(:cofe)
+
+ assert conn.status == 403
+ end
+
+ test "accepts a moderator that is privileged" do
+ clear_config([:instance, :moderator_privileges], [:cofe])
+ user = insert(:user, is_moderator: true)
+ conn = assign(build_conn(), :user, user)
+
+ ret_conn = EnsurePrivilegedPlug.call(conn, :cofe)
+
+ assert conn == ret_conn
+ end
+
+ test "denies a moderator that isn't privileged" do
+ clear_config([:instance, :moderator_privileges], [:suya])
+ user = insert(:user, is_moderator: true)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> EnsurePrivilegedPlug.call(:cofe)
+
+ assert conn.status == 403
+ end
+
+ test "accepts for a privileged role even if other role isn't privileged" do
+ clear_config([:instance, :admin_privileges], [:cofe])
+ clear_config([:instance, :moderator_privileges], [])
+ user = insert(:user, is_admin: true, is_moderator: true)
+ conn = assign(build_conn(), :user, user)
+
+ ret_conn = EnsurePrivilegedPlug.call(conn, :cofe)
+
+ # privileged through admin role
+ assert conn == ret_conn
+
+ clear_config([:instance, :admin_privileges], [])
+ clear_config([:instance, :moderator_privileges], [:cofe])
+ user = insert(:user, is_admin: true, is_moderator: true)
+ conn = assign(build_conn(), :user, user)
+
+ ret_conn = EnsurePrivilegedPlug.call(conn, :cofe)
+
+ # privileged through moderator role
+ assert conn == ret_conn
+ end
+
+ test "denies when no user is set" do
+ conn =
+ build_conn()
+ |> EnsurePrivilegedPlug.call(:cofe)
+
+ assert conn.status == 403
+ end
+end
diff --git a/test/pleroma/web/plugs/ensure_public_or_authenticated_plug_test.exs b/test/pleroma/web/plugs/ensure_public_or_authenticated_plug_test.exs
index 75c3b5784..35edaa825 100644
--- a/test/pleroma/web/plugs/ensure_public_or_authenticated_plug_test.exs
+++ b/test/pleroma/web/plugs/ensure_public_or_authenticated_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlugTest do
diff --git a/test/pleroma/web/plugs/ensure_user_token_assigns_plug_test.exs b/test/pleroma/web/plugs/ensure_user_token_assigns_plug_test.exs
index 28ec67158..f98ed0f2e 100644
--- a/test/pleroma/web/plugs/ensure_user_token_assigns_plug_test.exs
+++ b/test/pleroma/web/plugs/ensure_user_token_assigns_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.EnsureUserTokenAssignsPlugTest do
diff --git a/test/pleroma/web/plugs/federating_plug_test.exs b/test/pleroma/web/plugs/federating_plug_test.exs
index 01ecd2a1e..627749c18 100644
--- a/test/pleroma/web/plugs/federating_plug_test.exs
+++ b/test/pleroma/web/plugs/federating_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.FederatingPlugTest do
diff --git a/test/pleroma/web/plugs/frontend_static_plug_test.exs b/test/pleroma/web/plugs/frontend_static_plug_test.exs
index 4152cdefe..ab31c5f22 100644
--- a/test/pleroma/web/plugs/frontend_static_plug_test.exs
+++ b/test/pleroma/web/plugs/frontend_static_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
@@ -94,10 +94,10 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
"internal",
".well-known",
"nodeinfo",
- "web",
+ "manifest.json",
"auth",
- "embed",
"proxy",
+ "phoenix",
"test",
"user_exists",
"check_password"
diff --git a/test/pleroma/web/plugs/http_security_plug_test.exs b/test/pleroma/web/plugs/http_security_plug_test.exs
index 4e7befdd5..c79170382 100644
--- a/test/pleroma/web/plugs/http_security_plug_test.exs
+++ b/test/pleroma/web/plugs/http_security_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do
@@ -59,9 +59,9 @@ defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do
assert csp =~ ~r|report-uri https://endpoint.com;report-to csp-endpoint;|
- [reply_to] = Conn.get_resp_header(conn, "reply-to")
+ [report_to] = Conn.get_resp_header(conn, "report-to")
- assert reply_to ==
+ assert report_to ==
"{\"endpoints\":[{\"url\":\"https://endpoint.com\"}],\"group\":\"csp-endpoint\",\"max-age\":10886400}"
end
diff --git a/test/pleroma/web/plugs/http_signature_plug_test.exs b/test/pleroma/web/plugs/http_signature_plug_test.exs
index 56ef6b06f..2d8fba3cd 100644
--- a/test/pleroma/web/plugs/http_signature_plug_test.exs
+++ b/test/pleroma/web/plugs/http_signature_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.HTTPSignaturePlugTest do
diff --git a/test/pleroma/web/plugs/idempotency_plug_test.exs b/test/pleroma/web/plugs/idempotency_plug_test.exs
index dd8cda664..cc55d341f 100644
--- a/test/pleroma/web/plugs/idempotency_plug_test.exs
+++ b/test/pleroma/web/plugs/idempotency_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.IdempotencyPlugTest do
diff --git a/test/pleroma/web/plugs/instance_static_test.exs b/test/pleroma/web/plugs/instance_static_test.exs
index 46f2ca6b1..f91021a16 100644
--- a/test/pleroma/web/plugs/instance_static_test.exs
+++ b/test/pleroma/web/plugs/instance_static_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.InstanceStaticTest do
diff --git a/test/pleroma/web/plugs/mapped_signature_to_identity_plug_test.exs b/test/pleroma/web/plugs/mapped_signature_to_identity_plug_test.exs
index 00ce6492d..33eff1bc5 100644
--- a/test/pleroma/web/plugs/mapped_signature_to_identity_plug_test.exs
+++ b/test/pleroma/web/plugs/mapped_signature_to_identity_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.MappedSignatureToIdentityPlugTest do
diff --git a/test/pleroma/web/plugs/o_auth_plug_test.exs b/test/pleroma/web/plugs/o_auth_plug_test.exs
index 9e4be5559..8917eadd1 100644
--- a/test/pleroma/web/plugs/o_auth_plug_test.exs
+++ b/test/pleroma/web/plugs/o_auth_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.OAuthPlugTest do
diff --git a/test/pleroma/web/plugs/o_auth_scopes_plug_test.exs b/test/pleroma/web/plugs/o_auth_scopes_plug_test.exs
index 9f6d3dc71..05d0973d8 100644
--- a/test/pleroma/web/plugs/o_auth_scopes_plug_test.exs
+++ b/test/pleroma/web/plugs/o_auth_scopes_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.OAuthScopesPlugTest do
diff --git a/test/pleroma/web/plugs/plug_helper_test.exs b/test/pleroma/web/plugs/plug_helper_test.exs
index 346113628..935d0200b 100644
--- a/test/pleroma/web/plugs/plug_helper_test.exs
+++ b/test/pleroma/web/plugs/plug_helper_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.PlugHelperTest do
diff --git a/test/pleroma/web/plugs/rate_limiter_test.exs b/test/pleroma/web/plugs/rate_limiter_test.exs
index d007e3f26..19cee8aee 100644
--- a/test/pleroma/web/plugs/rate_limiter_test.exs
+++ b/test/pleroma/web/plugs/rate_limiter_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.RateLimiterTest do
@@ -53,32 +53,37 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
scale = 80
limit = 5
- clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {127, 0, 0, 1})
clear_config([:rate_limit, limiter_name], {scale, limit})
plug_opts = RateLimiter.init(name: limiter_name)
conn = build_conn(:get, "/")
- for i <- 1..5 do
- conn = RateLimiter.call(conn, plug_opts)
- assert {^i, _} = RateLimiter.inspect_bucket(conn, limiter_name, plug_opts)
- Process.sleep(10)
+ for _ <- 1..5 do
+ conn_limited = RateLimiter.call(conn, plug_opts)
+
+ refute conn_limited.status == Conn.Status.code(:too_many_requests)
+ refute conn_limited.resp_body
+ refute conn_limited.halted
end
- conn = RateLimiter.call(conn, plug_opts)
- assert %{"error" => "Throttled"} = ConnTest.json_response(conn, :too_many_requests)
- assert conn.halted
+ conn_limited = RateLimiter.call(conn, plug_opts)
+ assert %{"error" => "Throttled"} = ConnTest.json_response(conn_limited, :too_many_requests)
+ assert conn_limited.halted
- Process.sleep(50)
+ expire_ttl(conn, limiter_name)
- conn = build_conn(:get, "/")
+ for _ <- 1..5 do
+ conn_limited = RateLimiter.call(conn, plug_opts)
- conn = RateLimiter.call(conn, plug_opts)
- assert {1, 4} = RateLimiter.inspect_bucket(conn, limiter_name, plug_opts)
+ refute conn_limited.status == Conn.Status.code(:too_many_requests)
+ refute conn_limited.resp_body
+ refute conn_limited.halted
+ end
- refute conn.status == Conn.Status.code(:too_many_requests)
- refute conn.resp_body
- refute conn.halted
+ conn_limited = RateLimiter.call(conn, plug_opts)
+ assert %{"error" => "Throttled"} = ConnTest.json_response(conn_limited, :too_many_requests)
+ assert conn_limited.halted
end
describe "options" do
@@ -137,6 +142,7 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
end
describe "unauthenticated users" do
+ @tag :erratic
test "are restricted based on remote IP" do
limiter_name = :test_unauthenticated
clear_config([:rate_limit, limiter_name], [{1000, 5}, {1, 10}])
@@ -174,6 +180,7 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
:ok
end
+ @tag :erratic
test "can have limits separate from unauthenticated connections" do
limiter_name = :test_authenticated1
@@ -199,6 +206,7 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
assert conn.halted
end
+ @tag :erratic
test "different users are counted independently" do
limiter_name = :test_authenticated2
clear_config([:rate_limit, limiter_name], [{1, 10}, {1000, 5}])
@@ -259,4 +267,12 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
refute {:err, :not_found} == RateLimiter.inspect_bucket(conn, limiter_name, opts)
end
+
+ def expire_ttl(%{remote_ip: remote_ip} = _conn, bucket_name_root) do
+ bucket_name = "anon:#{bucket_name_root}" |> String.to_atom()
+ key_name = "ip::#{remote_ip |> Tuple.to_list() |> Enum.join(".")}"
+
+ {:ok, bucket_value} = Cachex.get(bucket_name, key_name)
+ Cachex.put(bucket_name, key_name, bucket_value, ttl: -1)
+ end
end
diff --git a/test/pleroma/web/plugs/remote_ip_test.exs b/test/pleroma/web/plugs/remote_ip_test.exs
index 4d98de2bd..aea0940f4 100644
--- a/test/pleroma/web/plugs/remote_ip_test.exs
+++ b/test/pleroma/web/plugs/remote_ip_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.RemoteIpTest do
diff --git a/test/pleroma/web/plugs/set_format_plug_test.exs b/test/pleroma/web/plugs/set_format_plug_test.exs
index 21043f698..4d64fdde6 100644
--- a/test/pleroma/web/plugs/set_format_plug_test.exs
+++ b/test/pleroma/web/plugs/set_format_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.SetFormatPlugTest do
diff --git a/test/pleroma/web/plugs/set_locale_plug_test.exs b/test/pleroma/web/plugs/set_locale_plug_test.exs
index 5261e67ae..4f664f84e 100644
--- a/test/pleroma/web/plugs/set_locale_plug_test.exs
+++ b/test/pleroma/web/plugs/set_locale_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.SetLocalePlugTest do
@@ -16,7 +16,7 @@ defmodule Pleroma.Web.Plugs.SetLocalePlugTest do
|> SetLocalePlug.call([])
assert "en" == Gettext.get_locale()
- assert %{locale: "en"} == conn.assigns
+ assert %{locale: "en"} = conn.assigns
end
test "use supported locale from `accept-language`" do
@@ -30,7 +30,125 @@ defmodule Pleroma.Web.Plugs.SetLocalePlugTest do
|> SetLocalePlug.call([])
assert "ru" == Gettext.get_locale()
- assert %{locale: "ru"} == conn.assigns
+ assert %{locale: "ru"} = conn.assigns
+ end
+
+ test "fallback to the general language if a variant is not supported" do
+ conn =
+ :get
+ |> conn("/cofe")
+ |> Conn.put_req_header(
+ "accept-language",
+ "ru-CA;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 supported locale with specifiers from `accept-language`" do
+ conn =
+ :get
+ |> conn("/cofe")
+ |> Conn.put_req_header(
+ "accept-language",
+ "zh-Hans;q=0.9, en;q=0.8, *;q=0.5"
+ )
+ |> SetLocalePlug.call([])
+
+ assert "zh_Hans" == Gettext.get_locale()
+ assert %{locale: "zh_Hans"} = conn.assigns
+ end
+
+ test "it assigns all supported locales" do
+ conn =
+ :get
+ |> conn("/cofe")
+ |> Conn.put_req_header(
+ "accept-language",
+ "ru, fr-CH, fr;q=0.9, en;q=0.8, x-unsupported;q=0.8, *;q=0.5"
+ )
+ |> SetLocalePlug.call([])
+
+ assert "ru" == Gettext.get_locale()
+ assert %{locale: "ru", locales: ["ru", "fr", "en"]} = conn.assigns
+ end
+
+ test "it assigns all supported locales in cookie" do
+ conn =
+ :get
+ |> conn("/cofe")
+ |> put_req_cookie(SetLocalePlug.frontend_language_cookie_name(), "zh-Hans,uk,zh-Hant")
+ |> Conn.put_req_header(
+ "accept-language",
+ "ru, fr-CH, fr;q=0.9, en;q=0.8, x-unsupported;q=0.8, *;q=0.5"
+ )
+ |> SetLocalePlug.call([])
+
+ assert "zh_Hans" == Gettext.get_locale()
+
+ assert %{locale: "zh_Hans", locales: ["zh_Hans", "uk", "zh_Hant", "ru", "fr", "en"]} =
+ conn.assigns
+ end
+
+ test "fallback to some variant of the language if the unqualified language is not supported" do
+ conn =
+ :get
+ |> conn("/cofe")
+ |> Conn.put_req_header(
+ "accept-language",
+ "zh;q=0.9, en;q=0.8, *;q=0.5"
+ )
+ |> SetLocalePlug.call([])
+
+ assert "zh_" <> _ = Gettext.get_locale()
+ assert %{locale: "zh_" <> _} = conn.assigns
+ end
+
+ test "use supported locale from cookie" do
+ conn =
+ :get
+ |> conn("/cofe")
+ |> put_req_cookie(SetLocalePlug.frontend_language_cookie_name(), "zh-Hans")
+ |> Conn.put_req_header(
+ "accept-language",
+ "ru, fr-CH, fr;q=0.9, en;q=0.8, *;q=0.5"
+ )
+ |> SetLocalePlug.call([])
+
+ assert "zh_Hans" == Gettext.get_locale()
+ assert %{locale: "zh_Hans"} = conn.assigns
+ end
+
+ test "fallback to supported locale from `accept-language` if locale in cookie not supported" do
+ conn =
+ :get
+ |> conn("/cofe")
+ |> put_req_cookie(SetLocalePlug.frontend_language_cookie_name(), "x-nonexist")
+ |> 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 "fallback to default if nothing is supported" do
+ conn =
+ :get
+ |> conn("/cofe")
+ |> put_req_cookie(SetLocalePlug.frontend_language_cookie_name(), "x-nonexist")
+ |> Conn.put_req_header(
+ "accept-language",
+ "x-nonexist"
+ )
+ |> SetLocalePlug.call([])
+
+ assert "en" == Gettext.get_locale()
+ assert %{locale: "en"} = conn.assigns
end
test "use default locale if locale from `accept-language` is not supported" do
@@ -41,6 +159,6 @@ defmodule Pleroma.Web.Plugs.SetLocalePlugTest do
|> SetLocalePlug.call([])
assert "en" == Gettext.get_locale()
- assert %{locale: "en"} == conn.assigns
+ assert %{locale: "en"} = conn.assigns
end
end
diff --git a/test/pleroma/web/plugs/set_user_session_id_plug_test.exs b/test/pleroma/web/plugs/set_user_session_id_plug_test.exs
index 9814c80d8..cbb7e643d 100644
--- a/test/pleroma/web/plugs/set_user_session_id_plug_test.exs
+++ b/test/pleroma/web/plugs/set_user_session_id_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.SetUserSessionIdPlugTest do
diff --git a/test/pleroma/web/plugs/uploaded_media_plug_test.exs b/test/pleroma/web/plugs/uploaded_media_plug_test.exs
index 75f313282..ec46b0537 100644
--- a/test/pleroma/web/plugs/uploaded_media_plug_test.exs
+++ b/test/pleroma/web/plugs/uploaded_media_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.UploadedMediaPlugTest do
diff --git a/test/pleroma/web/plugs/user_enabled_plug_test.exs b/test/pleroma/web/plugs/user_enabled_plug_test.exs
index 999c6c49c..3243bc47a 100644
--- a/test/pleroma/web/plugs/user_enabled_plug_test.exs
+++ b/test/pleroma/web/plugs/user_enabled_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.UserEnabledPlugTest do
diff --git a/test/pleroma/web/plugs/user_fetcher_plug_test.exs b/test/pleroma/web/plugs/user_fetcher_plug_test.exs
index 902bee642..6ffa50f40 100644
--- a/test/pleroma/web/plugs/user_fetcher_plug_test.exs
+++ b/test/pleroma/web/plugs/user_fetcher_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.UserFetcherPlugTest do
diff --git a/test/pleroma/web/plugs/user_is_admin_plug_test.exs b/test/pleroma/web/plugs/user_is_admin_plug_test.exs
index 58996d5a4..4fc4153b5 100644
--- a/test/pleroma/web/plugs/user_is_admin_plug_test.exs
+++ b/test/pleroma/web/plugs/user_is_admin_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.UserIsAdminPlugTest do
diff --git a/test/pleroma/web/plugs/user_is_staff_plug_test.exs b/test/pleroma/web/plugs/user_is_staff_plug_test.exs
new file mode 100644
index 000000000..921703876
--- /dev/null
+++ b/test/pleroma/web/plugs/user_is_staff_plug_test.exs
@@ -0,0 +1,47 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Plugs.UserIsStaffPlugTest do
+ use Pleroma.Web.ConnCase, async: true
+
+ alias Pleroma.Web.Plugs.UserIsStaffPlug
+ import Pleroma.Factory
+
+ test "accepts a user that is an admin" do
+ user = insert(:user, is_admin: true)
+
+ conn = assign(build_conn(), :user, user)
+
+ ret_conn = UserIsStaffPlug.call(conn, %{})
+
+ assert conn == ret_conn
+ end
+
+ test "accepts a user that is a moderator" do
+ user = insert(:user, is_moderator: true)
+
+ conn = assign(build_conn(), :user, user)
+
+ ret_conn = UserIsStaffPlug.call(conn, %{})
+
+ assert conn == ret_conn
+ end
+
+ test "denies a user that isn't a staff member" do
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> UserIsStaffPlug.call(%{})
+
+ assert conn.status == 403
+ end
+
+ test "denies when a user isn't set" do
+ conn = UserIsStaffPlug.call(build_conn(), %{})
+
+ assert conn.status == 403
+ end
+end
diff --git a/test/pleroma/web/plugs/user_tracking_plug_test.exs b/test/pleroma/web/plugs/user_tracking_plug_test.exs
index 8e9d59b99..742f04fea 100644
--- a/test/pleroma/web/plugs/user_tracking_plug_test.exs
+++ b/test/pleroma/web/plugs/user_tracking_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.UserTrackingPlugTest do
diff --git a/test/pleroma/web/preload/providers/instance_test.exs b/test/pleroma/web/preload/providers/instance_test.exs
index a401475ee..92a28576d 100644
--- a/test/pleroma/web/preload/providers/instance_test.exs
+++ b/test/pleroma/web/preload/providers/instance_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Preload.Providers.InstanceTest do
diff --git a/test/pleroma/web/preload/providers/timeline_test.exs b/test/pleroma/web/preload/providers/timeline_test.exs
index 2ae2ca5fb..162aabd4a 100644
--- a/test/pleroma/web/preload/providers/timeline_test.exs
+++ b/test/pleroma/web/preload/providers/timeline_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Preload.Providers.TimelineTest do
diff --git a/test/pleroma/web/preload/providers/user_test.exs b/test/pleroma/web/preload/providers/user_test.exs
index b7017ac20..e8ef8a9f0 100644
--- a/test/pleroma/web/preload/providers/user_test.exs
+++ b/test/pleroma/web/preload/providers/user_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Preload.Providers.UserTest do
diff --git a/test/pleroma/web/push/impl_test.exs b/test/pleroma/web/push/impl_test.exs
index b3ca1a337..2eee0acd9 100644
--- a/test/pleroma/web/push/impl_test.exs
+++ b/test/pleroma/web/push/impl_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Push.ImplTest do
@@ -202,6 +202,21 @@ defmodule Pleroma.Web.Push.ImplTest do
"New Reaction"
end
+ test "renders title and body for update activity" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "lorem ipsum"})
+
+ {:ok, activity} = CommonAPI.update(user, activity, %{status: "edited status"})
+ object = Object.normalize(activity, fetch: false)
+
+ assert Impl.format_body(%{activity: activity, type: "update"}, user, object) ==
+ "@#{user.nickname} edited a status"
+
+ assert Impl.format_title(%{activity: activity, type: "update"}) ==
+ "New Update"
+ end
+
test "renders title for create activity with direct visibility" do
user = insert(:user, nickname: "Bob")
diff --git a/test/pleroma/web/rel_me_test.exs b/test/pleroma/web/rel_me_test.exs
index 313b163b5..3cfced9df 100644
--- a/test/pleroma/web/rel_me_test.exs
+++ b/test/pleroma/web/rel_me_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.RelMeTest do
diff --git a/test/pleroma/web/rich_media/helpers_test.exs b/test/pleroma/web/rich_media/helpers_test.exs
index 689854fb6..630b3ca95 100644
--- a/test/pleroma/web/rich_media/helpers_test.exs
+++ b/test/pleroma/web/rich_media/helpers_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.RichMedia.HelpersTest do
diff --git a/test/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs b/test/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs
index df3ea3e99..59b3330ba 100644
--- a/test/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs
+++ b/test/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrlTest do
@@ -66,9 +66,7 @@ defmodule Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrlTest do
end
defp construct_s3_url(timestamp, valid_till) do
- "https://pleroma.s3.ap-southeast-1.amazonaws.com/sachin%20%281%29%20_a%20-%25%2Aasdasd%20BNN%20bnnn%20.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIBLWWK6RGDQXDLJQ%2F20190716%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=#{
- timestamp
- }&X-Amz-Expires=#{valid_till}&X-Amz-Signature=04ffd6b98634f4b1bbabc62e0fac4879093cd54a6eed24fe8eb38e8369526bbf&X-Amz-SignedHeaders=host"
+ "https://pleroma.s3.ap-southeast-1.amazonaws.com/sachin%20%281%29%20_a%20-%25%2Aasdasd%20BNN%20bnnn%20.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIBLWWK6RGDQXDLJQ%2F20190716%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=#{timestamp}&X-Amz-Expires=#{valid_till}&X-Amz-Signature=04ffd6b98634f4b1bbabc62e0fac4879093cd54a6eed24fe8eb38e8369526bbf&X-Amz-SignedHeaders=host"
end
defp construct_metadata(timestamp, valid_till, url) do
diff --git a/test/pleroma/web/rich_media/parser_test.exs b/test/pleroma/web/rich_media/parser_test.exs
index 2fe7f1b0b..ffdc4e5d7 100644
--- a/test/pleroma/web/rich_media/parser_test.exs
+++ b/test/pleroma/web/rich_media/parser_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.RichMedia.ParserTest do
diff --git a/test/pleroma/web/rich_media/parsers/twitter_card_test.exs b/test/pleroma/web/rich_media/parsers/twitter_card_test.exs
index 2aacd29a3..e84a4e50a 100644
--- a/test/pleroma/web/rich_media/parsers/twitter_card_test.exs
+++ b/test/pleroma/web/rich_media/parsers/twitter_card_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do
diff --git a/test/pleroma/web/shout_channel_test.exs b/test/pleroma/web/shout_channel_test.exs
index 5c86efe9f..e1de80593 100644
--- a/test/pleroma/web/shout_channel_test.exs
+++ b/test/pleroma/web/shout_channel_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ShoutChannelTest do
diff --git a/test/pleroma/web/static_fe/static_fe_controller_test.exs b/test/pleroma/web/static_fe/static_fe_controller_test.exs
index 5752cffda..2fae83305 100644
--- a/test/pleroma/web/static_fe/static_fe_controller_test.exs
+++ b/test/pleroma/web/static_fe/static_fe_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
diff --git a/test/pleroma/web/streamer_test.exs b/test/pleroma/web/streamer_test.exs
index 7c4b9e288..8b0c84164 100644
--- a/test/pleroma/web/streamer_test.exs
+++ b/test/pleroma/web/streamer_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.StreamerTest do
@@ -442,6 +442,31 @@ defmodule Pleroma.Web.StreamerTest do
"state" => "follow_accept"
} = Jason.decode!(payload)
end
+
+ test "it streams edits in the 'user' stream", %{user: user, token: oauth_token} do
+ sender = insert(:user)
+ {:ok, _, _, _} = CommonAPI.follow(user, sender)
+
+ {:ok, activity} = CommonAPI.post(sender, %{status: "hey"})
+
+ Streamer.get_topic_and_add_socket("user", user, oauth_token)
+ {:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"})
+ create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"])
+
+ assert_receive {:render_with_user, _, "status_update.json", ^create}
+ refute Streamer.filtered_by_user?(user, edited)
+ end
+
+ test "it streams own edits in the 'user' stream", %{user: user, token: oauth_token} do
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
+
+ Streamer.get_topic_and_add_socket("user", user, oauth_token)
+ {:ok, edited} = CommonAPI.update(user, activity, %{status: "mew mew"})
+ create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"])
+
+ assert_receive {:render_with_user, _, "status_update.json", ^create}
+ refute Streamer.filtered_by_user?(user, edited)
+ end
end
describe "public streams" do
@@ -484,6 +509,54 @@ defmodule Pleroma.Web.StreamerTest do
assert_receive {:text, event}
assert %{"event" => "delete", "payload" => ^activity_id} = Jason.decode!(event)
end
+
+ test "it streams edits in the 'public' stream" do
+ sender = insert(:user)
+
+ Streamer.get_topic_and_add_socket("public", nil, nil)
+ {:ok, activity} = CommonAPI.post(sender, %{status: "hey"})
+ assert_receive {:text, _}
+
+ {:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"})
+
+ edited = Pleroma.Activity.normalize(edited)
+
+ %{id: activity_id} = Pleroma.Activity.get_create_by_object_ap_id(edited.object.data["id"])
+
+ assert_receive {:text, event}
+ assert %{"event" => "status.update", "payload" => payload} = Jason.decode!(event)
+ assert %{"id" => ^activity_id} = Jason.decode!(payload)
+ refute Streamer.filtered_by_user?(sender, edited)
+ end
+
+ test "it streams multiple edits in the 'public' stream correctly" do
+ sender = insert(:user)
+
+ Streamer.get_topic_and_add_socket("public", nil, nil)
+ {:ok, activity} = CommonAPI.post(sender, %{status: "hey"})
+ assert_receive {:text, _}
+
+ {:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"})
+
+ edited = Pleroma.Activity.normalize(edited)
+
+ %{id: activity_id} = Pleroma.Activity.get_create_by_object_ap_id(edited.object.data["id"])
+
+ assert_receive {:text, event}
+ assert %{"event" => "status.update", "payload" => payload} = Jason.decode!(event)
+ assert %{"id" => ^activity_id} = Jason.decode!(payload)
+ refute Streamer.filtered_by_user?(sender, edited)
+
+ {:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew 2"})
+
+ edited = Pleroma.Activity.normalize(edited)
+
+ %{id: activity_id} = Pleroma.Activity.get_create_by_object_ap_id(edited.object.data["id"])
+ assert_receive {:text, event}
+ assert %{"event" => "status.update", "payload" => payload} = Jason.decode!(event)
+ assert %{"id" => ^activity_id, "content" => "mew mew 2"} = Jason.decode!(payload)
+ refute Streamer.filtered_by_user?(sender, edited)
+ end
end
describe "thread_containment/2" do
@@ -772,6 +845,7 @@ defmodule Pleroma.Web.StreamerTest do
refute_receive _
end
+ @tag :erratic
test "it sends conversation update to the 'direct' stream when a message is deleted", %{
user: user,
token: oauth_token
diff --git a/test/pleroma/web/twitter_api/controller_test.exs b/test/pleroma/web/twitter_api/controller_test.exs
index bca9e2dad..495d371d2 100644
--- a/test/pleroma/web/twitter_api/controller_test.exs
+++ b/test/pleroma/web/twitter_api/controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.TwitterAPI.ControllerTest do
diff --git a/test/pleroma/web/twitter_api/password_controller_test.exs b/test/pleroma/web/twitter_api/password_controller_test.exs
index cf99e2434..26cca1345 100644
--- a/test/pleroma/web/twitter_api/password_controller_test.exs
+++ b/test/pleroma/web/twitter_api/password_controller_test.exs
@@ -1,14 +1,18 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
use Pleroma.Web.ConnCase
+ alias Pleroma.Config
alias Pleroma.PasswordResetToken
+ alias Pleroma.Repo
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
alias Pleroma.Web.OAuth.Token
import Pleroma.Factory
+ import Swoosh.TestAssertions
describe "GET /api/pleroma/password_reset/token" do
test "it returns error when token invalid", %{conn: conn} do
@@ -116,4 +120,94 @@ defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
assert User.get_by_id(user.id).password_reset_pending == false
end
end
+
+ describe "POST /auth/password, with valid parameters" do
+ setup %{conn: conn} do
+ user = insert(:user)
+ conn = post(conn, "/auth/password?email=#{user.email}")
+ %{conn: conn, user: user}
+ end
+
+ test "it returns 204", %{conn: conn} do
+ assert empty_json_response(conn)
+ end
+
+ test "it creates a PasswordResetToken record for user", %{user: user} do
+ token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
+ assert token_record
+ end
+
+ test "it sends an email to user", %{user: user} do
+ ObanHelpers.perform_all()
+ token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
+
+ email = Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
+ notify_email = Config.get([:instance, :notify_email])
+ instance_name = Config.get([:instance, :name])
+
+ assert_email_sent(
+ from: {instance_name, notify_email},
+ to: {user.name, user.email},
+ html_body: email.html_body
+ )
+ end
+ end
+
+ describe "POST /auth/password, with nickname" do
+ test "it returns 204", %{conn: conn} do
+ user = insert(:user)
+
+ assert conn
+ |> post("/auth/password?nickname=#{user.nickname}")
+ |> empty_json_response()
+
+ ObanHelpers.perform_all()
+ token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
+
+ email = Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
+ notify_email = Config.get([:instance, :notify_email])
+ instance_name = Config.get([:instance, :name])
+
+ assert_email_sent(
+ from: {instance_name, notify_email},
+ to: {user.name, user.email},
+ html_body: email.html_body
+ )
+ end
+
+ test "it doesn't fail when a user has no email", %{conn: conn} do
+ user = insert(:user, %{email: nil})
+
+ assert conn
+ |> post("/auth/password?nickname=#{user.nickname}")
+ |> empty_json_response()
+ end
+ end
+
+ describe "POST /auth/password, with invalid parameters" do
+ setup do
+ user = insert(:user)
+ {:ok, user: user}
+ end
+
+ test "it returns 204 when user is not found", %{conn: conn, user: user} do
+ conn = post(conn, "/auth/password?email=nonexisting_#{user.email}")
+
+ assert empty_json_response(conn)
+ end
+
+ test "it returns 204 when user is not local", %{conn: conn, user: user} do
+ {:ok, user} = Repo.update(Ecto.Changeset.change(user, local: false))
+ conn = post(conn, "/auth/password?email=#{user.email}")
+
+ assert empty_json_response(conn)
+ end
+
+ test "it returns 204 when user is deactivated", %{conn: conn, user: user} do
+ {:ok, user} = Repo.update(Ecto.Changeset.change(user, is_active: false, local: true))
+ conn = post(conn, "/auth/password?email=#{user.email}")
+
+ assert empty_json_response(conn)
+ end
+ end
end
diff --git a/test/pleroma/web/twitter_api/remote_follow_controller_test.exs b/test/pleroma/web/twitter_api/remote_follow_controller_test.exs
index fa3b29006..1194e0afe 100644
--- a/test/pleroma/web/twitter_api/remote_follow_controller_test.exs
+++ b/test/pleroma/web/twitter_api/remote_follow_controller_test.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
- use Pleroma.Web.ConnCase
+ use Pleroma.Web.ConnCase, async: true
alias Pleroma.MFA
alias Pleroma.MFA.TOTP
@@ -410,4 +410,49 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
assert response =~ "Error following account"
end
end
+
+ describe "avatar url" do
+ test "without media proxy" do
+ clear_config([:media_proxy, :enabled], false)
+
+ user =
+ insert(:user, %{
+ local: false,
+ avatar: %{"url" => [%{"href" => "https://remote.org/avatar.png"}]}
+ })
+
+ avatar_url = Pleroma.Web.TwitterAPI.RemoteFollowView.avatar_url(user)
+
+ assert avatar_url == "https://remote.org/avatar.png"
+ end
+
+ test "with media proxy" do
+ clear_config([:media_proxy, :enabled], true)
+
+ user =
+ insert(:user, %{
+ local: false,
+ avatar: %{"url" => [%{"href" => "https://remote.org/avatar.png"}]}
+ })
+
+ avatar_url = Pleroma.Web.TwitterAPI.RemoteFollowView.avatar_url(user)
+ url = Pleroma.Web.Endpoint.url()
+
+ assert String.starts_with?(avatar_url, url)
+ end
+
+ test "local avatar is not proxied" do
+ clear_config([:media_proxy, :enabled], true)
+
+ user =
+ insert(:user, %{
+ local: true,
+ avatar: %{"url" => [%{"href" => "#{Pleroma.Web.Endpoint.url()}/localuser/avatar.png"}]}
+ })
+
+ avatar_url = Pleroma.Web.TwitterAPI.RemoteFollowView.avatar_url(user)
+
+ assert avatar_url == "#{Pleroma.Web.Endpoint.url()}/localuser/avatar.png"
+ end
+ end
end
diff --git a/test/pleroma/web/twitter_api/twitter_api_test.exs b/test/pleroma/web/twitter_api/twitter_api_test.exs
index 85629be04..b3cd80146 100644
--- a/test/pleroma/web/twitter_api/twitter_api_test.exs
+++ b/test/pleroma/web/twitter_api/twitter_api_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
@@ -139,9 +139,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user2} = TwitterAPI.register_user(data2)
expected_text =
- ~s(<span class="h-card"><a class="u-url mention" data-user="#{user1.id}" href="#{
- user1.ap_id
- }" rel="ugc">@<span>john</span></a></span> test)
+ ~s(<span class="h-card"><a class="u-url mention" data-user="#{user1.id}" href="#{user1.ap_id}" rel="ugc">@<span>john</span></a></span> test)
assert user2.bio == expected_text
end
diff --git a/test/pleroma/web/twitter_api/util_controller_test.exs b/test/pleroma/web/twitter_api/util_controller_test.exs
index f030483d8..a4da23635 100644
--- a/test/pleroma/web/twitter_api/util_controller_test.exs
+++ b/test/pleroma/web/twitter_api/util_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
@@ -26,11 +26,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
test "it updates notification settings", %{user: user, conn: conn} do
conn
|> put(
- "/api/pleroma/notification_settings?#{
- URI.encode_query(%{
- block_from_strangers: true
- })
- }"
+ "/api/pleroma/notification_settings?#{URI.encode_query(%{block_from_strangers: true})}"
)
|> json_response_and_validate_schema(:ok)
@@ -45,11 +41,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
test "it updates notification settings to enable hiding contents", %{user: user, conn: conn} do
conn
|> put(
- "/api/pleroma/notification_settings?#{
- URI.encode_query(%{
- hide_notification_contents: 1
- })
- }"
+ "/api/pleroma/notification_settings?#{URI.encode_query(%{hide_notification_contents: 1})}"
)
|> json_response_and_validate_schema(:ok)
@@ -241,6 +233,102 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
end
end
+ describe "POST /main/ostatus - remote_subscribe/2 - with statuses" do
+ setup do: clear_config([:instance, :federating], true)
+
+ test "renders subscribe form", %{conn: conn} do
+ user = insert(:user)
+ status = insert(:note_activity, %{user: user})
+ status_id = status.id
+
+ assert is_binary(status_id)
+
+ response =
+ conn
+ |> post("/main/ostatus", %{"status_id" => status_id, "profile" => ""})
+ |> response(:ok)
+
+ refute response =~ "Could not find status"
+ assert response =~ "Interacting with"
+ end
+
+ test "renders subscribe form with error when status not found", %{conn: conn} do
+ response =
+ conn
+ |> post("/main/ostatus", %{"status_id" => "somerandomid", "profile" => ""})
+ |> response(:ok)
+
+ assert response =~ "Could not find status"
+ refute response =~ "Interacting with"
+ end
+
+ test "it redirect to webfinger url", %{conn: conn} do
+ user = insert(:user)
+ status = insert(:note_activity, %{user: user})
+ status_id = status.id
+ status_ap_id = status.data["object"]
+
+ assert is_binary(status_id)
+ assert is_binary(status_ap_id)
+
+ user2 = insert(:user, ap_id: "shp@social.heldscal.la")
+
+ conn =
+ conn
+ |> post("/main/ostatus", %{
+ "status" => %{"status_id" => status_id, "profile" => user2.ap_id}
+ })
+
+ assert redirected_to(conn) ==
+ "https://social.heldscal.la/main/ostatussub?profile=#{status_ap_id}"
+ end
+
+ test "it renders form with error when status not found", %{conn: conn} do
+ user2 = insert(:user, ap_id: "shp@social.heldscal.la")
+
+ response =
+ conn
+ |> post("/main/ostatus", %{
+ "status" => %{"status_id" => "somerandomid", "profile" => user2.ap_id}
+ })
+ |> response(:ok)
+
+ assert response =~ "Something went wrong."
+ end
+ end
+
+ describe "GET /main/ostatus - show_subscribe_form/2" do
+ setup do: clear_config([:instance, :federating], true)
+
+ test "it works with users", %{conn: conn} do
+ user = insert(:user)
+
+ response =
+ conn
+ |> get("/main/ostatus", %{"nickname" => user.nickname})
+ |> response(:ok)
+
+ refute response =~ "Could not find user"
+ assert response =~ "Remotely follow #{user.nickname}"
+ end
+
+ test "it works with statuses", %{conn: conn} do
+ user = insert(:user)
+ status = insert(:note_activity, %{user: user})
+ status_id = status.id
+
+ assert is_binary(status_id)
+
+ response =
+ conn
+ |> get("/main/ostatus", %{"status_id" => status_id})
+ |> response(:ok)
+
+ refute response =~ "Could not find status"
+ assert response =~ "Interacting with"
+ end
+ end
+
test "it returns new captcha", %{conn: conn} do
with_mock Pleroma.Captcha,
new: fn -> "test_captcha" end do
@@ -302,9 +390,22 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
assert %{"error" => "Missing field: email."} = json_response_and_validate_schema(conn, 400)
end
- test "with proper permissions, valid password and blank email", %{
- conn: conn
- } do
+ test "with proper permissions, valid password and blank email, when instance requires user email",
+ %{
+ conn: conn
+ } do
+ orig_account_activation_required =
+ Pleroma.Config.get([:instance, :account_activation_required])
+
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+
+ on_exit(fn ->
+ Pleroma.Config.put(
+ [:instance, :account_activation_required],
+ orig_account_activation_required
+ )
+ end)
+
conn =
conn
|> put_req_header("content-type", "multipart/form-data")
@@ -313,6 +414,30 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
assert json_response_and_validate_schema(conn, 200) == %{"error" => "Email can't be blank."}
end
+ test "with proper permissions, valid password and blank email, when instance does not require user email",
+ %{
+ conn: conn
+ } do
+ orig_account_activation_required =
+ Pleroma.Config.get([:instance, :account_activation_required])
+
+ Pleroma.Config.put([:instance, :account_activation_required], false)
+
+ on_exit(fn ->
+ Pleroma.Config.put(
+ [:instance, :account_activation_required],
+ orig_account_activation_required
+ )
+ end)
+
+ conn =
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/change_email", %{password: "test", email: ""})
+
+ assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
+ end
+
test "with proper permissions, valid password and non unique email", %{
conn: conn
} do
@@ -444,7 +569,10 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
test "with proper permissions and wrong or missing password", %{conn: conn} do
for params <- [%{"password" => "hi"}, %{}] do
- ret_conn = post(conn, "/api/pleroma/delete_account", params)
+ ret_conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/pleroma/delete_account", params)
assert json_response_and_validate_schema(ret_conn, 200) == %{
"error" => "Invalid password."
@@ -452,8 +580,12 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
end
end
- test "with proper permissions and valid password", %{conn: conn, user: user} do
- conn = post(conn, "/api/pleroma/delete_account?password=test")
+ test "with proper permissions and valid password (URL query)", %{conn: conn, user: user} do
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/pleroma/delete_account?password=test")
+
ObanHelpers.perform_all()
assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
@@ -463,5 +595,388 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
assert user.bio == ""
assert user.password_hash == nil
end
+
+ test "with proper permissions and valid password (JSON body)", %{conn: conn, user: user} do
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/pleroma/delete_account", %{password: "test"})
+
+ ObanHelpers.perform_all()
+ assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
+
+ user = User.get_by_id(user.id)
+ refute user.is_active
+ assert user.name == nil
+ assert user.bio == ""
+ assert user.password_hash == nil
+ end
+ end
+
+ describe "POST /api/pleroma/move_account" do
+ setup do: oauth_access(["write:accounts"])
+
+ test "without permissions", %{conn: conn} do
+ target_user = insert(:user)
+ target_nick = target_user |> User.full_nickname()
+
+ conn =
+ conn
+ |> assign(:token, nil)
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/move_account", %{
+ "password" => "hi",
+ "target_account" => target_nick
+ })
+
+ assert json_response_and_validate_schema(conn, 403) == %{
+ "error" => "Insufficient permissions: write:accounts."
+ }
+ end
+
+ test "with proper permissions and invalid password", %{conn: conn} do
+ target_user = insert(:user)
+ target_nick = target_user |> User.full_nickname()
+
+ conn =
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/move_account", %{
+ "password" => "hi",
+ "target_account" => target_nick
+ })
+
+ assert json_response_and_validate_schema(conn, 200) == %{"error" => "Invalid password."}
+ end
+
+ test "with proper permissions, valid password and target account does not alias it",
+ %{
+ conn: conn
+ } do
+ target_user = insert(:user)
+ target_nick = target_user |> User.full_nickname()
+
+ conn =
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/move_account", %{
+ "password" => "test",
+ "target_account" => target_nick
+ })
+
+ assert json_response_and_validate_schema(conn, 200) == %{
+ "error" => "Target account must have the origin in `alsoKnownAs`"
+ }
+ end
+
+ test "with proper permissions, valid password and target account does not exist",
+ %{
+ conn: conn
+ } do
+ target_nick = "not_found@mastodon.social"
+
+ conn =
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/move_account", %{
+ "password" => "test",
+ "target_account" => target_nick
+ })
+
+ assert json_response_and_validate_schema(conn, 404) == %{
+ "error" => "Target account not found."
+ }
+ end
+
+ test "with proper permissions, valid password, remote target account aliases it and local cache does not exist",
+ %{} do
+ user = insert(:user, ap_id: "https://lm.kazv.moe/users/testuser")
+ %{user: _user, conn: conn} = oauth_access(["write:accounts"], user: user)
+
+ target_nick = "mewmew@lm.kazv.moe"
+
+ conn =
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/move_account", %{
+ "password" => "test",
+ "target_account" => target_nick
+ })
+
+ assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
+ end
+
+ test "with proper permissions, valid password, remote target account aliases it and local cache does not aliases it",
+ %{} do
+ user = insert(:user, ap_id: "https://lm.kazv.moe/users/testuser")
+ %{user: _user, conn: conn} = oauth_access(["write:accounts"], user: user)
+
+ target_user =
+ insert(
+ :user,
+ ap_id: "https://lm.kazv.moe/users/mewmew",
+ nickname: "mewmew@lm.kazv.moe",
+ local: false
+ )
+
+ target_nick = target_user |> User.full_nickname()
+
+ conn =
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/move_account", %{
+ "password" => "test",
+ "target_account" => target_nick
+ })
+
+ assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
+ end
+
+ test "with proper permissions, valid password, remote target account does not aliases it and local cache aliases it",
+ %{
+ user: user,
+ conn: conn
+ } do
+ target_user =
+ insert(
+ :user,
+ ap_id: "https://lm.kazv.moe/users/mewmew",
+ nickname: "mewmew@lm.kazv.moe",
+ local: false,
+ also_known_as: [user.ap_id]
+ )
+
+ target_nick = target_user |> User.full_nickname()
+
+ conn =
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/move_account", %{
+ "password" => "test",
+ "target_account" => target_nick
+ })
+
+ assert json_response_and_validate_schema(conn, 200) == %{
+ "error" => "Target account must have the origin in `alsoKnownAs`"
+ }
+ end
+
+ test "with proper permissions, valid password and target account aliases it", %{
+ conn: conn,
+ user: user
+ } do
+ target_user = insert(:user, also_known_as: [user.ap_id])
+ target_nick = target_user |> User.full_nickname()
+ follower = insert(:user)
+
+ User.follow(follower, user)
+
+ assert User.following?(follower, user)
+
+ conn =
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post(
+ "/api/pleroma/move_account",
+ %{
+ password: "test",
+ target_account: target_nick
+ }
+ )
+
+ assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
+
+ params = %{
+ "op" => "move_following",
+ "origin_id" => user.id,
+ "target_id" => target_user.id
+ }
+
+ assert_enqueued(worker: Pleroma.Workers.BackgroundWorker, args: params)
+
+ Pleroma.Workers.BackgroundWorker.perform(%Oban.Job{args: params})
+
+ refute User.following?(follower, user)
+ assert User.following?(follower, target_user)
+ end
+
+ test "prefix nickname by @ should work", %{
+ conn: conn,
+ user: user
+ } do
+ target_user = insert(:user, also_known_as: [user.ap_id])
+ target_nick = target_user |> User.full_nickname()
+ follower = insert(:user)
+
+ User.follow(follower, user)
+
+ assert User.following?(follower, user)
+
+ conn =
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post(
+ "/api/pleroma/move_account",
+ %{
+ password: "test",
+ target_account: "@" <> target_nick
+ }
+ )
+
+ assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
+
+ params = %{
+ "op" => "move_following",
+ "origin_id" => user.id,
+ "target_id" => target_user.id
+ }
+
+ assert_enqueued(worker: Pleroma.Workers.BackgroundWorker, args: params)
+
+ Pleroma.Workers.BackgroundWorker.perform(%Oban.Job{args: params})
+
+ refute User.following?(follower, user)
+ assert User.following?(follower, target_user)
+ end
+ end
+
+ describe "GET /api/pleroma/aliases" do
+ setup do: oauth_access(["read:accounts"])
+
+ test "without permissions", %{conn: conn} do
+ conn =
+ conn
+ |> assign(:token, nil)
+ |> get("/api/pleroma/aliases")
+
+ assert json_response_and_validate_schema(conn, 403) == %{
+ "error" => "Insufficient permissions: read:accounts."
+ }
+ end
+
+ test "with permissions", %{
+ conn: conn
+ } do
+ assert %{"aliases" => []} =
+ conn
+ |> get("/api/pleroma/aliases")
+ |> json_response_and_validate_schema(200)
+ end
+
+ test "with permissions and aliases", %{} do
+ user = insert(:user)
+ user2 = insert(:user)
+
+ assert {:ok, user} = user |> User.add_alias(user2)
+
+ %{user: _user, conn: conn} = oauth_access(["read:accounts"], user: user)
+
+ assert %{"aliases" => aliases} =
+ conn
+ |> get("/api/pleroma/aliases")
+ |> json_response_and_validate_schema(200)
+
+ assert aliases == [user2 |> User.full_nickname()]
+ end
+ end
+
+ describe "PUT /api/pleroma/aliases" do
+ setup do: oauth_access(["write:accounts"])
+
+ test "without permissions", %{conn: conn} do
+ conn =
+ conn
+ |> assign(:token, nil)
+ |> put_req_header("content-type", "application/json")
+ |> put("/api/pleroma/aliases", %{alias: "none"})
+
+ assert json_response_and_validate_schema(conn, 403) == %{
+ "error" => "Insufficient permissions: write:accounts."
+ }
+ end
+
+ test "with permissions, no alias param", %{
+ conn: conn
+ } do
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> put("/api/pleroma/aliases", %{})
+
+ assert %{"error" => "Missing field: alias."} = json_response_and_validate_schema(conn, 400)
+ end
+
+ test "with permissions, with alias param", %{
+ conn: conn
+ } do
+ user2 = insert(:user)
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> put("/api/pleroma/aliases", %{alias: user2 |> User.full_nickname()})
+
+ assert json_response_and_validate_schema(conn, 200) == %{
+ "status" => "success"
+ }
+ end
+ end
+
+ describe "DELETE /api/pleroma/aliases" do
+ setup do
+ alias_user = insert(:user)
+ non_alias_user = insert(:user)
+ user = insert(:user, also_known_as: [alias_user.ap_id])
+
+ oauth_access(["write:accounts"], user: user)
+ |> Map.put(:alias_user, alias_user)
+ |> Map.put(:non_alias_user, non_alias_user)
+ end
+
+ test "without permissions", %{conn: conn} do
+ conn =
+ conn
+ |> assign(:token, nil)
+ |> put_req_header("content-type", "application/json")
+ |> delete("/api/pleroma/aliases", %{alias: "none"})
+
+ assert json_response_and_validate_schema(conn, 403) == %{
+ "error" => "Insufficient permissions: write:accounts."
+ }
+ end
+
+ test "with permissions, no alias param", %{conn: conn} do
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> delete("/api/pleroma/aliases", %{})
+
+ assert %{"error" => "Missing field: alias."} = json_response_and_validate_schema(conn, 400)
+ end
+
+ test "with permissions, account does not have such alias", %{
+ conn: conn,
+ non_alias_user: non_alias_user
+ } do
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> delete("/api/pleroma/aliases", %{alias: non_alias_user |> User.full_nickname()})
+
+ assert %{"error" => "Account has no such alias."} =
+ json_response_and_validate_schema(conn, 404)
+ end
+
+ test "with permissions, account does have such alias", %{
+ conn: conn,
+ alias_user: alias_user
+ } do
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> delete("/api/pleroma/aliases", %{alias: alias_user |> User.full_nickname()})
+
+ assert %{"status" => "success"} = json_response_and_validate_schema(conn, 200)
+ end
end
end
diff --git a/test/pleroma/web/uploader_controller_test.exs b/test/pleroma/web/uploader_controller_test.exs
index fc278004e..17d5152b7 100644
--- a/test/pleroma/web/uploader_controller_test.exs
+++ b/test/pleroma/web/uploader_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.UploaderControllerTest do
diff --git a/test/pleroma/web/views/error_view_test.exs b/test/pleroma/web/views/error_view_test.exs
index 42da8f458..b4a651f6b 100644
--- a/test/pleroma/web/views/error_view_test.exs
+++ b/test/pleroma/web/views/error_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ErrorViewTest do
diff --git a/test/pleroma/web/web_finger/web_finger_controller_test.exs b/test/pleroma/web/web_finger/web_finger_controller_test.exs
index 2421c5800..5e3ac26f9 100644
--- a/test/pleroma/web/web_finger/web_finger_controller_test.exs
+++ b/test/pleroma/web/web_finger/web_finger_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
@@ -24,9 +24,7 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
assert response.status == 200
assert response.resp_body ==
- ~s(<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" template="#{
- Pleroma.Web.Endpoint.url()
- }/.well-known/webfinger?resource={uri}" type="application/xrd+xml" /></XRD>)
+ ~s(<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" template="#{Pleroma.Web.Endpoint.url()}/.well-known/webfinger?resource={uri}" type="application/xrd+xml" /></XRD>)
end
test "Webfinger JRD" do
@@ -50,6 +48,35 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
]
end
+ test "reach user on tld, while pleroma is runned on subdomain" do
+ Pleroma.Web.Endpoint.config_change(
+ [{Pleroma.Web.Endpoint, url: [host: "sub.example.com"]}],
+ []
+ )
+
+ clear_config([Pleroma.Web.Endpoint, :url, :host], "sub.example.com")
+
+ clear_config([Pleroma.Web.WebFinger, :domain], "example.com")
+
+ user = insert(:user, ap_id: "https://sub.example.com/users/bobby", nickname: "bobby")
+
+ response =
+ build_conn()
+ |> put_req_header("accept", "application/jrd+json")
+ |> get("/.well-known/webfinger?resource=acct:#{user.nickname}@example.com")
+ |> json_response(200)
+
+ assert response["subject"] == "acct:#{user.nickname}@example.com"
+ assert response["aliases"] == ["https://sub.example.com/users/#{user.nickname}"]
+
+ on_exit(fn ->
+ Pleroma.Web.Endpoint.config_change(
+ [{Pleroma.Web.Endpoint, url: [host: "localhost"]}],
+ []
+ )
+ end)
+ end
+
test "it returns 404 when user isn't found (JSON)" do
result =
build_conn()
diff --git a/test/pleroma/web/web_finger_test.exs b/test/pleroma/web/web_finger_test.exs
index 0a36d57e6..fafef54fe 100644
--- a/test/pleroma/web/web_finger_test.exs
+++ b/test/pleroma/web/web_finger_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.WebFingerTest do
@@ -47,7 +47,7 @@ defmodule Pleroma.Web.WebFingerTest do
test "returns error when there is no content-type header" do
Tesla.Mock.mock(fn
- %{url: "http://social.heldscal.la/.well-known/host-meta"} ->
+ %{url: "https://social.heldscal.la/.well-known/host-meta"} ->
{:ok,
%Tesla.Env{
status: 200,
@@ -120,7 +120,7 @@ defmodule Pleroma.Web.WebFingerTest do
test "it gets the xrd endpoint for statusnet" do
{:ok, template} = WebFinger.find_lrdd_template("status.alpicola.com")
- assert template == "http://status.alpicola.com/main/xrd?uri={uri}"
+ assert template == "https://status.alpicola.com/main/xrd?uri={uri}"
end
test "it works with idna domains as nickname" do
@@ -147,7 +147,7 @@ defmodule Pleroma.Web.WebFingerTest do
headers: [{"content-type", "application/jrd+json"}]
}}
- %{url: "http://mastodon.social/.well-known/host-meta"} ->
+ %{url: "https://mastodon.social/.well-known/host-meta"} ->
{:ok,
%Tesla.Env{
status: 200,
@@ -170,7 +170,7 @@ defmodule Pleroma.Web.WebFingerTest do
headers: [{"content-type", "application/xrd+xml"}]
}}
- %{url: "http://pawoo.net/.well-known/host-meta"} ->
+ %{url: "https://pawoo.net/.well-known/host-meta"} ->
{:ok,
%Tesla.Env{
status: 200,
diff --git a/test/pleroma/workers/cron/digest_emails_worker_test.exs b/test/pleroma/workers/cron/digest_emails_worker_test.exs
index b3ca6235b..851f4d63a 100644
--- a/test/pleroma/workers/cron/digest_emails_worker_test.exs
+++ b/test/pleroma/workers/cron/digest_emails_worker_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.Cron.DigestEmailsWorkerTest do
diff --git a/test/pleroma/workers/cron/new_users_digest_worker_test.exs b/test/pleroma/workers/cron/new_users_digest_worker_test.exs
index f9ef265c2..84914876c 100644
--- a/test/pleroma/workers/cron/new_users_digest_worker_test.exs
+++ b/test/pleroma/workers/cron/new_users_digest_worker_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.Cron.NewUsersDigestWorkerTest do
diff --git a/test/pleroma/workers/publisher_worker_test.exs b/test/pleroma/workers/publisher_worker_test.exs
new file mode 100644
index 000000000..13372bf49
--- /dev/null
+++ b/test/pleroma/workers/publisher_worker_test.exs
@@ -0,0 +1,40 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Workers.PublisherWorkerTest do
+ use Pleroma.DataCase, async: true
+ use Oban.Testing, repo: Pleroma.Repo
+
+ import Pleroma.Factory
+
+ alias Pleroma.Object
+ alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.ActivityPub.Builder
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.Federator
+
+ describe "Oban job priority:" do
+ setup do
+ user = insert(:user)
+
+ {:ok, post} = CommonAPI.post(user, %{status: "Regrettable post"})
+ object = Object.normalize(post, fetch: false)
+ {:ok, delete_data, _meta} = Builder.delete(user, object.data["id"])
+ {:ok, delete, _meta} = ActivityPub.persist(delete_data, local: true)
+
+ %{
+ post: post,
+ delete: delete
+ }
+ end
+
+ test "Deletions are lower priority", %{delete: delete} do
+ assert {:ok, %Oban.Job{priority: 3}} = Federator.publish(delete)
+ end
+
+ test "Creates are normal priority", %{post: post} do
+ assert {:ok, %Oban.Job{priority: 0}} = Federator.publish(post)
+ end
+ end
+end
diff --git a/test/pleroma/workers/purge_expired_activity_test.exs b/test/pleroma/workers/purge_expired_activity_test.exs
index 98f30f61f..0372f54ca 100644
--- a/test/pleroma/workers/purge_expired_activity_test.exs
+++ b/test/pleroma/workers/purge_expired_activity_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.PurgeExpiredActivityTest do
diff --git a/test/pleroma/workers/purge_expired_filter_test.exs b/test/pleroma/workers/purge_expired_filter_test.exs
index d10586be9..e8d45aaaa 100644
--- a/test/pleroma/workers/purge_expired_filter_test.exs
+++ b/test/pleroma/workers/purge_expired_filter_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Workers.PurgeExpiredFilterTest do
use Pleroma.DataCase, async: true
use Oban.Testing, repo: Repo
diff --git a/test/pleroma/workers/purge_expired_token_test.exs b/test/pleroma/workers/purge_expired_token_test.exs
index 00cbd40cd..d891eb8bb 100644
--- a/test/pleroma/workers/purge_expired_token_test.exs
+++ b/test/pleroma/workers/purge_expired_token_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.PurgeExpiredTokenTest do
diff --git a/test/pleroma/workers/receiver_worker_test.exs b/test/pleroma/workers/receiver_worker_test.exs
new file mode 100644
index 000000000..283beee4d
--- /dev/null
+++ b/test/pleroma/workers/receiver_worker_test.exs
@@ -0,0 +1,25 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Workers.ReceiverWorkerTest do
+ use Pleroma.DataCase, async: true
+ use Oban.Testing, repo: Pleroma.Repo
+
+ import Mock
+ import Pleroma.Factory
+
+ alias Pleroma.Workers.ReceiverWorker
+
+ test "it ignores MRF reject" do
+ params = insert(:note).data
+
+ with_mock Pleroma.Web.ActivityPub.Transmogrifier,
+ handle_incoming: fn _ -> {:reject, "MRF"} end do
+ assert {:cancel, "MRF"} =
+ ReceiverWorker.perform(%Oban.Job{
+ args: %{"op" => "incoming_ap_doc", "params" => params}
+ })
+ end
+ end
+end
diff --git a/test/pleroma/workers/scheduled_activity_worker_test.exs b/test/pleroma/workers/scheduled_activity_worker_test.exs
index 5558d5b5f..4b3dfb99e 100644
--- a/test/pleroma/workers/scheduled_activity_worker_test.exs
+++ b/test/pleroma/workers/scheduled_activity_worker_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.ScheduledActivityWorkerTest do
diff --git a/test/pleroma/xml_builder_test.exs b/test/pleroma/xml_builder_test.exs
index 9aae32cdc..be9d8dd34 100644
--- a/test/pleroma/xml_builder_test.exs
+++ b/test/pleroma/xml_builder_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.XmlBuilderTest do
diff --git a/test/support/api_spec_helpers.ex b/test/support/api_spec_helpers.ex
index 36d6a8b81..df5132357 100644
--- a/test/support/api_spec_helpers.ex
+++ b/test/support/api_spec_helpers.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Tests.ApiSpecHelpers do
@@ -29,9 +29,7 @@ defmodule Pleroma.Tests.ApiSpecHelpers do
end)
flunk(
- "Value does not conform to schema #{schema.title}: #{Enum.join(errors, "\n")}\n#{
- inspect(value)
- }"
+ "Value does not conform to schema #{schema.title}: #{Enum.join(errors, "\n")}\n#{inspect(value)}"
)
end
end
diff --git a/test/support/builders/activity_builder.ex b/test/support/builders/activity_builder.ex
index 7c4950bfa..f1ca3951b 100644
--- a/test/support/builders/activity_builder.ex
+++ b/test/support/builders/activity_builder.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Builders.ActivityBuilder do
alias Pleroma.Web.ActivityPub.ActivityPub
diff --git a/test/support/builders/user_builder.ex b/test/support/builders/user_builder.ex
index 6bccbb35a..d6af30612 100644
--- a/test/support/builders/user_builder.ex
+++ b/test/support/builders/user_builder.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Builders.UserBuilder do
alias Pleroma.Repo
alias Pleroma.User
diff --git a/test/support/cachex_proxy.ex b/test/support/cachex_proxy.ex
index de1f1c766..83ae5610f 100644
--- a/test/support/cachex_proxy.ex
+++ b/test/support/cachex_proxy.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.CachexProxy do
diff --git a/test/support/captcha/mock.ex b/test/support/captcha/mock.ex
index 175ade131..53e000ed6 100644
--- a/test/support/captcha/mock.ex
+++ b/test/support/captcha/mock.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Captcha.Mock do
diff --git a/test/support/channel_case.ex b/test/support/channel_case.ex
index 1fbf6f100..8cb23f5ab 100644
--- a/test/support/channel_case.ex
+++ b/test/support/channel_case.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ChannelCase do
diff --git a/test/support/cluster.ex b/test/support/cluster.ex
index 524194cf4..1c923fb0c 100644
--- a/test/support/cluster.ex
+++ b/test/support/cluster.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Cluster do
@moduledoc """
Facilities for managing a cluster of slave VM's for federated testing.
diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex
index deee98599..f010fec33 100644
--- a/test/support/conn_case.ex
+++ b/test/support/conn_case.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ConnCase do
@@ -102,9 +102,7 @@ defmodule Pleroma.Web.ConnCase do
end)
flunk(
- "Response does not conform to schema of #{op_id} operation: #{
- Enum.join(errors, "\n")
- }\n#{inspect(json)}"
+ "Response does not conform to schema of #{op_id} operation: #{Enum.join(errors, "\n")}\n#{inspect(json)}"
)
end
end
diff --git a/test/support/data_case.ex b/test/support/data_case.ex
index 0ee2aa4a2..3c9cab061 100644
--- a/test/support/data_case.ex
+++ b/test/support/data_case.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.DataCase do
diff --git a/test/support/factory.ex b/test/support/factory.ex
index c267dba4e..09f02458c 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Factory do
@@ -10,6 +10,15 @@ defmodule Pleroma.Factory do
alias Pleroma.Object
alias Pleroma.User
+ @rsa_keys [
+ "test/fixtures/rsa_keys/key_1.pem",
+ "test/fixtures/rsa_keys/key_2.pem",
+ "test/fixtures/rsa_keys/key_3.pem",
+ "test/fixtures/rsa_keys/key_4.pem",
+ "test/fixtures/rsa_keys/key_5.pem"
+ ]
+ |> Enum.map(&File.read!/1)
+
def participation_factory do
conversation = insert(:conversation)
user = insert(:user)
@@ -28,6 +37,8 @@ defmodule Pleroma.Factory do
end
def user_factory(attrs \\ %{}) do
+ pem = Enum.random(@rsa_keys)
+
user = %User{
name: sequence(:name, &"Test テスト User #{&1}"),
email: sequence(:email, &"user#{&1}@example.com"),
@@ -39,7 +50,8 @@ defmodule Pleroma.Factory do
last_refreshed_at: NaiveDateTime.utc_now(),
notification_settings: %Pleroma.User.NotificationSetting{},
multi_factor_authentication_settings: %Pleroma.MFA.Settings{},
- ap_enabled: true
+ ap_enabled: true,
+ keys: pem
}
urls =
@@ -111,6 +123,18 @@ defmodule Pleroma.Factory do
}
end
+ def attachment_factory(attrs \\ %{}) do
+ user = attrs[:user] || insert(:user)
+
+ data =
+ attachment_data(user.ap_id, nil)
+ |> Map.put("id", Pleroma.Web.ActivityPub.Utils.generate_object_id())
+
+ %Pleroma.Object{
+ data: merge_attributes(data, Map.get(attrs, :data, %{}))
+ }
+ end
+
def attachment_note_factory(attrs \\ %{}) do
user = attrs[:user] || insert(:user)
{length, attrs} = Map.pop(attrs, :length, 1)
@@ -142,6 +166,11 @@ defmodule Pleroma.Factory do
}
end
+ def followers_only_note_factory(attrs \\ %{}) do
+ %Pleroma.Object{data: data} = note_factory(attrs)
+ %Pleroma.Object{data: Map.merge(data, %{"to" => [data["actor"] <> "/followers"]})}
+ end
+
def audio_factory(attrs \\ %{}) do
text = sequence(:text, &"lain radio episode #{&1}")
@@ -208,6 +237,38 @@ defmodule Pleroma.Factory do
}
end
+ def question_factory(attrs \\ %{}) do
+ user = attrs[:user] || insert(:user)
+
+ data = %{
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
+ "type" => "Question",
+ "actor" => user.ap_id,
+ "attributedTo" => user.ap_id,
+ "attachment" => [],
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "cc" => [user.follower_address],
+ "context" => Pleroma.Web.ActivityPub.Utils.generate_context_id(),
+ "closed" => DateTime.utc_now() |> DateTime.add(86_400) |> DateTime.to_iso8601(),
+ "oneOf" => [
+ %{
+ "type" => "Note",
+ "name" => "chocolate",
+ "replies" => %{"totalItems" => 0, "type" => "Collection"}
+ },
+ %{
+ "type" => "Note",
+ "name" => "vanilla",
+ "replies" => %{"totalItems" => 0, "type" => "Collection"}
+ }
+ ]
+ }
+
+ %Pleroma.Object{
+ data: merge_attributes(data, Map.get(attrs, :data, %{}))
+ }
+ end
+
def direct_note_activity_factory do
dm = insert(:direct_note)
@@ -267,6 +328,33 @@ defmodule Pleroma.Factory do
|> Map.merge(attrs)
end
+ def followers_only_note_activity_factory(attrs \\ %{}) do
+ user = attrs[:user] || insert(:user)
+ note = insert(:followers_only_note, user: user)
+
+ data_attrs = attrs[:data_attrs] || %{}
+ attrs = Map.drop(attrs, [:user, :note, :data_attrs])
+
+ data =
+ %{
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
+ "type" => "Create",
+ "actor" => note.data["actor"],
+ "to" => note.data["to"],
+ "object" => note.data,
+ "published" => DateTime.utc_now() |> DateTime.to_iso8601(),
+ "context" => note.data["context"]
+ }
+ |> Map.merge(data_attrs)
+
+ %Pleroma.Activity{
+ data: data,
+ actor: data["actor"],
+ recipients: data["to"]
+ }
+ |> Map.merge(attrs)
+ end
+
def note_activity_factory(attrs \\ %{}) do
user = attrs[:user] || insert(:user)
note = attrs[:note] || insert(:note, user: user)
@@ -396,6 +484,33 @@ defmodule Pleroma.Factory do
}
end
+ def question_activity_factory(attrs \\ %{}) do
+ user = attrs[:user] || insert(:user)
+ question = attrs[:question] || insert(:question, user: user)
+
+ data_attrs = attrs[:data_attrs] || %{}
+ attrs = Map.drop(attrs, [:user, :question, :data_attrs])
+
+ data =
+ %{
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
+ "type" => "Create",
+ "actor" => question.data["actor"],
+ "to" => question.data["to"],
+ "object" => question.data["id"],
+ "published" => DateTime.utc_now() |> DateTime.to_iso8601(),
+ "context" => question.data["context"]
+ }
+ |> Map.merge(data_attrs)
+
+ %Pleroma.Activity{
+ data: data,
+ actor: data["actor"],
+ recipients: data["to"]
+ }
+ |> Map.merge(attrs)
+ end
+
def oauth_app_factory do
%Pleroma.Web.OAuth.App{
client_name: sequence(:client_name, &"Some client #{&1}"),
@@ -536,4 +651,16 @@ defmodule Pleroma.Factory do
context: ["home"]
}
end
+
+ def announcement_factory(params \\ %{}) do
+ data = Map.get(params, :data, %{})
+
+ {_, params} = Map.pop(params, :data)
+
+ %Pleroma.Announcement{
+ data: Map.merge(%{"content" => "test announcement", "all_day" => false}, data)
+ }
+ |> Map.merge(params)
+ |> Pleroma.Announcement.add_rendered_properties()
+ end
end
diff --git a/test/support/helpers.ex b/test/support/helpers.ex
index 34f1505d0..0bd487f39 100644
--- a/test/support/helpers.ex
+++ b/test/support/helpers.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Tests.Helpers do
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index 8807c2d14..b0cf613ac 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule HttpRequestMock do
@@ -424,14 +424,6 @@ defmodule HttpRequestMock do
{:error, :nxdomain}
end
- def get("http://osada.macgirvin.com/.well-known/host-meta", _, _, _) do
- {:ok,
- %Tesla.Env{
- status: 404,
- body: ""
- }}
- end
-
def get("https://osada.macgirvin.com/.well-known/host-meta", _, _, _) do
{:ok,
%Tesla.Env{
@@ -725,6 +717,15 @@ defmodule HttpRequestMock do
}}
end
+ def get(
+ "https://mastodon.social/.well-known/webfinger?resource=acct:not_found@mastodon.social",
+ _,
+ _,
+ [{"accept", "application/xrd+xml,application/jrd+json"}]
+ ) do
+ {:ok, %Tesla.Env{status: 404}}
+ end
+
def get("http://gs.example.org/.well-known/host-meta", _, _, _) do
{:ok,
%Tesla.Env{
@@ -756,7 +757,7 @@ defmodule HttpRequestMock do
{:ok, %Tesla.Env{status: 406, body: ""}}
end
- def get("http://squeet.me/.well-known/host-meta", _, _, _) do
+ def get("https://squeet.me/.well-known/host-meta", _, _, _) do
{:ok,
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
end
@@ -797,7 +798,7 @@ defmodule HttpRequestMock do
{:ok, %Tesla.Env{status: 200, body: "", headers: [{"content-type", "application/jrd+json"}]}}
end
- def get("http://framatube.org/.well-known/host-meta", _, _, _) do
+ def get("https://framatube.org/.well-known/host-meta", _, _, _) do
{:ok,
%Tesla.Env{
status: 200,
@@ -806,7 +807,7 @@ defmodule HttpRequestMock do
end
def get(
- "http://framatube.org/main/xrd?uri=acct:framasoft@framatube.org",
+ "https://framatube.org/main/xrd?uri=acct:framasoft@framatube.org",
_,
_,
[{"accept", "application/xrd+xml,application/jrd+json"}]
@@ -841,7 +842,7 @@ defmodule HttpRequestMock do
}}
end
- def get("http://status.alpicola.com/.well-known/host-meta", _, _, _) do
+ def get("https://status.alpicola.com/.well-known/host-meta", _, _, _) do
{:ok,
%Tesla.Env{
status: 200,
@@ -849,7 +850,7 @@ defmodule HttpRequestMock do
}}
end
- def get("http://macgirvin.com/.well-known/host-meta", _, _, _) do
+ def get("https://macgirvin.com/.well-known/host-meta", _, _, _) do
{:ok,
%Tesla.Env{
status: 200,
@@ -857,7 +858,7 @@ defmodule HttpRequestMock do
}}
end
- def get("http://gerzilla.de/.well-known/host-meta", _, _, _) do
+ def get("https://gerzilla.de/.well-known/host-meta", _, _, _) do
{:ok,
%Tesla.Env{
status: 200,
@@ -1075,6 +1076,14 @@ defmodule HttpRequestMock do
}}
end
+ def get("https://404.site" <> _, _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 404,
+ body: ""
+ }}
+ end
+
def get(
"https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=acct:lain@zetsubou.xn--q9jyb4c",
_,
@@ -1124,6 +1133,57 @@ defmodule HttpRequestMock do
}}
end
+ def get("http://lm.kazv.moe/.well-known/host-meta", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/lm.kazv.moe_host_meta")
+ }}
+ end
+
+ def get("https://lm.kazv.moe/.well-known/host-meta", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/lm.kazv.moe_host_meta")
+ }}
+ end
+
+ def get(
+ "https://lm.kazv.moe/.well-known/webfinger?resource=acct:mewmew@lm.kazv.moe",
+ _,
+ _,
+ [{"accept", "application/xrd+xml,application/jrd+json"}]
+ ) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/https___lm.kazv.moe_users_mewmew.xml"),
+ headers: [{"content-type", "application/xrd+xml"}]
+ }}
+ end
+
+ def get("https://lm.kazv.moe/users/mewmew", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/mewmew@lm.kazv.moe.json"),
+ headers: activitypub_object_headers()
+ }}
+ end
+
+ def get("https://lm.kazv.moe/users/mewmew/collections/featured", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body:
+ File.read!("test/fixtures/users_mock/masto_featured.json")
+ |> String.replace("{{domain}}", "lm.kazv.moe")
+ |> String.replace("{{nickname}}", "mewmew"),
+ headers: [{"content-type", "application/activity+json"}]
+ }}
+ end
+
def get("https://info.pleroma.site/activity.json", _, _, [
{"accept", "application/activity+json"}
]) do
@@ -1311,11 +1371,84 @@ defmodule HttpRequestMock do
}}
end
+ def get("https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/gleasonator-AG3RzWfwEKKrY63qj2.json"),
+ headers: activitypub_object_headers()
+ }}
+ end
+
+ def get("https://gleasonator.com/users/macgirvin", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/macgirvin@gleasonator.com.json"),
+ headers: activitypub_object_headers()
+ }}
+ end
+
+ def get("https://gleasonator.com/users/macgirvin/collections/featured", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body:
+ File.read!("test/fixtures/users_mock/masto_featured.json")
+ |> String.replace("{{domain}}", "gleasonator.com")
+ |> String.replace("{{nickname}}", "macgirvin"),
+ headers: activitypub_object_headers()
+ }}
+ end
+
+ def get("https://mk.absturztau.be/users/8ozbzjs3o8", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/mametsuko@mk.absturztau.be.json"),
+ headers: activitypub_object_headers()
+ }}
+ end
+
+ def get("https://p.helene.moe/users/helene", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/helene@p.helene.moe.json"),
+ headers: activitypub_object_headers()
+ }}
+ end
+
+ def get("https://mk.absturztau.be/notes/93e7nm8wqg", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/mk.absturztau.be-93e7nm8wqg.json"),
+ headers: activitypub_object_headers()
+ }}
+ end
+
+ def get("https://mk.absturztau.be/notes/93e7nm8wqg/activity", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/mk.absturztau.be-93e7nm8wqg-activity.json"),
+ headers: activitypub_object_headers()
+ }}
+ end
+
+ def get("https://p.helene.moe/objects/fd5910ac-d9dc-412e-8d1d-914b203296c4", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/p.helene.moe-AM7S6vZQmL6pI9TgPY.json"),
+ headers: activitypub_object_headers()
+ }}
+ end
+
def get(url, query, body, headers) do
{:error,
- "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
- inspect(headers)
- }"}
+ "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}
end
# POST Requests
@@ -1381,9 +1514,7 @@ defmodule HttpRequestMock do
def post(url, query, body, headers) do
{:error,
- "Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{
- inspect(headers)
- }"}
+ "Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}
end
# Most of the rich media mocks are missing HEAD requests, so we just return 404.
@@ -1398,8 +1529,6 @@ defmodule HttpRequestMock do
def head(url, query, body, headers) do
{:error,
- "Mock response not implemented for HEAD #{inspect(url)}, #{query}, #{inspect(body)}, #{
- inspect(headers)
- }"}
+ "Mock response not implemented for HEAD #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}
end
end
diff --git a/test/support/mocks.ex b/test/support/mocks.ex
index fd8f825b3..d167996bd 100644
--- a/test/support/mocks.ex
+++ b/test/support/mocks.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
Mox.defmock(Pleroma.CachexMock, for: Pleroma.Caching)
diff --git a/test/support/mrf_module_mock.ex b/test/support/mrf_module_mock.ex
index 4d21d7fe0..616fc720e 100644
--- a/test/support/mrf_module_mock.ex
+++ b/test/support/mrf_module_mock.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule MRFModuleMock do
diff --git a/test/support/null_cache.ex b/test/support/null_cache.ex
index 47c10ebb6..9f1d45f1d 100644
--- a/test/support/null_cache.ex
+++ b/test/support/null_cache.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.NullCache do
diff --git a/test/support/oban_helpers.ex b/test/support/oban_helpers.ex
index 9b6e5256e..94170a0f8 100644
--- a/test/support/oban_helpers.ex
+++ b/test/support/oban_helpers.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Tests.ObanHelpers do
diff --git a/test/support/websocket_client.ex b/test/support/websocket_client.ex
index 70d331999..7163bbd41 100644
--- a/test/support/websocket_client.ex
+++ b/test/support/websocket_client.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Integration.WebsocketClient do
diff --git a/test/test_helper.exs b/test/test_helper.exs
index 0c9783076..60a61484f 100644
--- a/test/test_helper.exs
+++ b/test/test_helper.exs
@@ -1,9 +1,9 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
os_exclude = if :os.type() == {:unix, :darwin}, do: [skip_on_mac: true], else: []
-ExUnit.start(exclude: [:federated | os_exclude])
+ExUnit.start(exclude: [:federated, :erratic] ++ os_exclude)
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, :manual)