summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/config/emoji.txt1
-rw-r--r--test/credo/check/consistency/file_location.ex2
-rw-r--r--test/fixtures/activitypub-client-post-activity.json1
-rw-r--r--test/fixtures/birthdays/misskey-user.json1
-rw-r--r--test/fixtures/bridgy/actor.json80
-rw-r--r--test/fixtures/config/temp.exported_from_db.secret.exs9
-rw-r--r--test/fixtures/config/temp.secret.exs6
-rw-r--r--test/fixtures/create-pleroma-reply-to-misskey-thread.json61
-rw-r--r--test/fixtures/guppe-actor.json26
-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/mastodon/collections/featured.json39
-rw-r--r--test/fixtures/modules/good_mrf.ex6
-rw-r--r--test/fixtures/modules/runtime_module.ex2
-rw-r--r--test/fixtures/owncast-note-with-attachment.json31
-rw-r--r--test/fixtures/peertube/actor-person.json121
-rw-r--r--test/fixtures/peertube/video-object-mpegURL-only.json413
-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/statuses/masto-note.json47
-rw-r--r--test/fixtures/statuses/note.json27
-rw-r--r--test/fixtures/tesla_mock/emoji-in-summary.json49
-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/lemmy-page.json17
-rw-r--r--test/fixtures/tesla_mock/lemmy-user.json27
-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/tesla_mock/xn--q9jyb4c_host_meta4
-rw-r--r--test/fixtures/users_mock/localhost.json41
-rw-r--r--test/fixtures/users_mock/masto_featured.json18
-rw-r--r--test/fixtures/users_mock/user.json42
-rw-r--r--test/fixtures/video.mp4bin0 -> 522216 bytes
-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.exs51
-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.exs6
-rw-r--r--test/mix/tasks/pleroma/ecto/rollback_test.exs4
-rw-r--r--test/mix/tasks/pleroma/ecto_test.exs2
-rw-r--r--test/mix/tasks/pleroma/email_test.exs20
-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.exs6
-rw-r--r--test/mix/tasks/pleroma/uploads_test.exs2
-rw-r--r--test/mix/tasks/pleroma/user_test.exs153
-rw-r--r--test/pleroma/activity/ir/topics_test.exs120
-rw-r--r--test/pleroma/activity/search_test.exs19
-rw-r--r--test/pleroma/activity_test.exs111
-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.exs47
-rw-r--r--test/pleroma/bbs/handler_test.exs8
-rw-r--r--test/pleroma/bookmark_test.exs2
-rw-r--r--test/pleroma/captcha_test.exs8
-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.exs256
-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.exs49
-rw-r--r--test/pleroma/config/transfer_task_test.exs89
-rw-r--r--test/pleroma/config_db_test.exs25
-rw-r--r--test/pleroma/config_test.exs38
-rw-r--r--test/pleroma/conversation/participation_test.exs22
-rw-r--r--test/pleroma/conversation_test.exs10
-rw-r--r--test/pleroma/docs/generator_test.exs8
-rw-r--r--test/pleroma/docs/translator/compiler_test.exs90
-rw-r--r--test/pleroma/earmark_renderer_test.exs79
-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.exs6
-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.exs181
-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.exs7
-rw-r--r--test/pleroma/hashtag_test.exs17
-rw-r--r--test/pleroma/healthcheck_test.exs2
-rw-r--r--test/pleroma/html_test.exs40
-rw-r--r--test/pleroma/http/adapter_helper/gun_test.exs15
-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.exs46
-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.exs38
-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.exs6
-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.exs113
-rw-r--r--test/pleroma/object/containment_test.exs2
-rw-r--r--test/pleroma/object/fetcher_test.exs303
-rw-r--r--test/pleroma/object/updater_test.exs76
-rw-r--r--test/pleroma/object_test.exs94
-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.exs35
-rw-r--r--test/pleroma/registration_test.exs2
-rw-r--r--test/pleroma/repo/migrations/autolinker_to_linkify_test.exs4
-rw-r--r--test/pleroma/repo/migrations/confirm_logged_in_users_test.exs40
-rw-r--r--test/pleroma/repo/migrations/deprecate_public_endpoint_test.exs60
-rw-r--r--test/pleroma/repo/migrations/fix_legacy_tags_test.exs2
-rw-r--r--test/pleroma/repo/migrations/fix_malformed_formatter_config_test.exs4
-rw-r--r--test/pleroma/repo/migrations/move_welcome_settings_test.exs2
-rw-r--r--test/pleroma/repo/migrations/rename_instance_chat_test.exs56
-rw-r--r--test/pleroma/repo_test.exs2
-rw-r--r--test/pleroma/report_note_test.exs25
-rw-r--r--test/pleroma/reverse_proxy_test.exs42
-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.exs13
-rw-r--r--test/pleroma/signature_test.exs7
-rw-r--r--test/pleroma/stats_test.exs2
-rw-r--r--test/pleroma/upload/filter/analyze_metadata_test.exs33
-rw-r--r--test/pleroma/upload/filter/anonymize_filename_test.exs7
-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.exs5
-rw-r--r--test/pleroma/upload_test.exs38
-rw-r--r--test/pleroma/uploaders/local_test.exs2
-rw-r--r--test/pleroma/uploaders/s3_test.exs23
-rw-r--r--test/pleroma/user/backup_test.exs71
-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.exs12
-rw-r--r--test/pleroma/user/welcome_chat_message_test.exs15
-rw-r--r--test/pleroma/user/welcome_email_test.exs12
-rw-r--r--test/pleroma/user/welcome_message_test.exs13
-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.exs16
-rw-r--r--test/pleroma/user_test.exs876
-rw-r--r--test/pleroma/utils_test.exs2
-rw-r--r--test/pleroma/web/activity_pub/activity_pub_controller_test.exs543
-rw-r--r--test/pleroma/web/activity_pub/activity_pub_test.exs404
-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.exs126
-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.exs101
-rw-r--r--test/pleroma/web/activity_pub/mrf/hellthread_policy_test.exs14
-rw-r--r--test/pleroma/web/activity_pub/mrf/keyword_policy_test.exs159
-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.exs14
-rw-r--r--test/pleroma/web/activity_pub/mrf/no_empty_policy_test.exs177
-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.exs22
-rw-r--r--test/pleroma/web/activity_pub/mrf/reject_non_public_test.exs10
-rw-r--r--test/pleroma/web/activity_pub/mrf/simple_policy_test.exs146
-rw-r--r--test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs132
-rw-r--r--test/pleroma/web/activity_pub/mrf/subchain_policy_test.exs6
-rw-r--r--test/pleroma/web/activity_pub/mrf/tag_policy_test.exs40
-rw-r--r--test/pleroma/web/activity_pub/mrf/user_allow_list_policy_test.exs6
-rw-r--r--test/pleroma/web/activity_pub/mrf/vocabulary_policy_test.exs16
-rw-r--r--test/pleroma/web/activity_pub/mrf_test.exs25
-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.exs28
-rw-r--r--test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs119
-rw-r--r--test/pleroma/web/activity_pub/object_validators/article_note_validator_test.exs35
-rw-r--r--test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs120
-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.exs8
-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.exs2
-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.exs37
-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.exs25
-rw-r--r--test/pleroma/web/activity_pub/publisher_test.exs80
-rw-r--r--test/pleroma/web/activity_pub/relay_test.exs4
-rw-r--r--test/pleroma/web/activity_pub/side_effects/delete_test.exs10
-rw-r--r--test/pleroma/web/activity_pub/side_effects_test.exs417
-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.exs182
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs27
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/answer_handling_test.exs8
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/article_handling_test.exs6
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/audio_handling_test.exs14
-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.exs4
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs8
-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.exs4
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/follow_handling_test.exs4
-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.exs275
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/page_handling_test.exs36
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs13
-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.exs47
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier_test.exs175
-rw-r--r--test/pleroma/web/activity_pub/utils_test.exs81
-rw-r--r--test/pleroma/web/activity_pub/views/object_view_test.exs22
-rw-r--r--test/pleroma/web/activity_pub/views/user_view_test.exs9
-rw-r--r--test/pleroma/web/activity_pub/visibility_test.exs71
-rw-r--r--test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs260
-rw-r--r--test/pleroma/web/admin_api/controllers/announcement_controller_test.exs281
-rw-r--r--test/pleroma/web/admin_api/controllers/chat_controller_test.exs10
-rw-r--r--test/pleroma/web/admin_api/controllers/config_controller_test.exs156
-rw-r--r--test/pleroma/web/admin_api/controllers/frontend_controller_test.exs16
-rw-r--r--test/pleroma/web/admin_api/controllers/instance_controller_test.exs80
-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.exs11
-rw-r--r--test/pleroma/web/admin_api/controllers/media_proxy_cache_controller_test.exs38
-rw-r--r--test/pleroma/web/admin_api/controllers/o_auth_app_controller_test.exs8
-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.exs37
-rw-r--r--test/pleroma/web/admin_api/controllers/status_controller_test.exs6
-rw-r--r--test/pleroma/web/admin_api/controllers/user_controller_test.exs483
-rw-r--r--test/pleroma/web/admin_api/search_test.exs18
-rw-r--r--test/pleroma/web/admin_api/views/account_view_test.exs16
-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.exs16
-rw-r--r--test/pleroma/web/auth/basic_auth_test.exs4
-rw-r--r--test/pleroma/web/auth/pleroma_authenticator_test.exs10
-rw-r--r--test/pleroma/web/auth/totp_authenticator_test.exs4
-rw-r--r--test/pleroma/web/common_api/utils_test.exs174
-rw-r--r--test/pleroma/web/common_api_test.exs384
-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.exs18
-rw-r--r--test/pleroma/web/feed/tag_controller_test.exs24
-rw-r--r--test/pleroma/web/feed/user_controller_test.exs40
-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.exs593
-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.exs44
-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.exs31
-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.exs464
-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.exs12
-rw-r--r--test/pleroma/web/mastodon_api/controllers/list_controller_test.exs17
-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.exs59
-rw-r--r--test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs71
-rw-r--r--test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs97
-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.exs6
-rw-r--r--test/pleroma/web/mastodon_api/controllers/search_controller_test.exs108
-rw-r--r--test/pleroma/web/mastodon_api/controllers/status_controller_test.exs472
-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.exs393
-rw-r--r--test/pleroma/web/mastodon_api/masto_fe_controller_test.exs86
-rw-r--r--test/pleroma/web/mastodon_api/mastodon_api_controller_test.exs2
-rw-r--r--test/pleroma/web/mastodon_api/mastodon_api_test.exs4
-rw-r--r--test/pleroma/web/mastodon_api/update_credentials_test.exs134
-rw-r--r--test/pleroma/web/mastodon_api/views/account_view_test.exs96
-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.exs64
-rw-r--r--test/pleroma/web/mastodon_api/views/poll_view_test.exs17
-rw-r--r--test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs5
-rw-r--r--test/pleroma/web/mastodon_api/views/status_view_test.exs89
-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.exs43
-rw-r--r--test/pleroma/web/media_proxy/invalidation_test.exs19
-rw-r--r--test/pleroma/web/media_proxy/media_proxy_controller_test.exs28
-rw-r--r--test/pleroma/web/media_proxy_test.exs7
-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.exs104
-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.exs104
-rw-r--r--test/pleroma/web/metadata/utils_test.exs54
-rw-r--r--test/pleroma/web/mongoose_im_controller_test.exs10
-rw-r--r--test/pleroma/web/node_info_test.exs146
-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.exs6
-rw-r--r--test/pleroma/web/o_auth/mfa_controller_test.exs6
-rw-r--r--test/pleroma/web/o_auth/o_auth_controller_test.exs44
-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.exs32
-rw-r--r--test/pleroma/web/pleroma_api/controllers/account_controller_test.exs90
-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.exs278
-rw-r--r--test/pleroma/web/pleroma_api/controllers/conversation_controller_test.exs4
-rw-r--r--test/pleroma/web/pleroma_api/controllers/emoji_file_controller_test.exs4
-rw-r--r--test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs5
-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.exs80
-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.exs4
-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.exs18
-rw-r--r--test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs6
-rw-r--r--test/pleroma/web/pleroma_api/views/chat_view_test.exs4
-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.exs6
-rw-r--r--test/pleroma/web/plugs/authentication_plug_test.exs4
-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.exs20
-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_public_or_authenticated_plug_test.exs9
-rw-r--r--test/pleroma/web/plugs/ensure_staff_privileged_plug_test.exs60
-rw-r--r--test/pleroma/web/plugs/ensure_user_token_assigns_plug_test.exs2
-rw-r--r--test/pleroma/web/plugs/federating_plug_test.exs6
-rw-r--r--test/pleroma/web/plugs/frontend_static_plug_test.exs33
-rw-r--r--test/pleroma/web/plugs/http_security_plug_test.exs21
-rw-r--r--test/pleroma/web/plugs/http_signature_plug_test.exs8
-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.exs40
-rw-r--r--test/pleroma/web/plugs/plug_helper_test.exs2
-rw-r--r--test/pleroma/web/plugs/rate_limiter_test.exs83
-rw-r--r--test/pleroma/web/plugs/remote_ip_test.exs14
-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.exs8
-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.exs58
-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.exs43
-rw-r--r--test/pleroma/web/rel_me_test.exs2
-rw-r--r--test/pleroma/web/rich_media/helpers_test.exs11
-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.exs6
-rw-r--r--test/pleroma/web/rich_media/parsers/twitter_card_test.exs2
-rw-r--r--test/pleroma/web/shout_channel_test.exs (renamed from test/pleroma/web/chat_channel_test.exs)12
-rw-r--r--test/pleroma/web/static_fe/static_fe_controller_test.exs15
-rw-r--r--test/pleroma/web/streamer_test.exs209
-rw-r--r--test/pleroma/web/twitter_api/controller_test.exs57
-rw-r--r--test/pleroma/web/twitter_api/password_controller_test.exs98
-rw-r--r--test/pleroma/web/twitter_api/remote_follow_controller_test.exs85
-rw-r--r--test/pleroma/web/twitter_api/twitter_api_test.exs17
-rw-r--r--test/pleroma/web/twitter_api/util_controller_test.exs713
-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.exs73
-rw-r--r--test/pleroma/workers/cron/digest_emails_worker_test.exs4
-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.exs34
-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.exs23
-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.ex6
-rw-r--r--test/support/cachex_proxy.ex2
-rw-r--r--test/support/captcha/mock.ex2
-rw-r--r--test/support/channel_case.ex18
-rw-r--r--test/support/cluster.ex4
-rw-r--r--test/support/conn_case.ex40
-rw-r--r--test/support/data_case.ex32
-rw-r--r--test/support/factory.ex225
-rw-r--r--test/support/helpers.ex13
-rw-r--r--test/support/http_request_mock.ex266
-rw-r--r--test/support/mocks.ex2
-rw-r--r--test/support/mrf_module_mock.ex4
-rw-r--r--test/support/null_cache.ex2
-rw-r--r--test/support/oban_helpers.ex2
-rw-r--r--test/support/websocket_client.ex34
-rw-r--r--test/test_helper.exs4
446 files changed, 16812 insertions, 3728 deletions
diff --git a/test/config/emoji.txt b/test/config/emoji.txt
new file mode 100644
index 000000000..14dd0c332
--- /dev/null
+++ b/test/config/emoji.txt
@@ -0,0 +1 @@
+external_emoji, https://example.com/emoji.png
diff --git a/test/credo/check/consistency/file_location.ex b/test/credo/check/consistency/file_location.ex
index 500983608..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-2020 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/activitypub-client-post-activity.json b/test/fixtures/activitypub-client-post-activity.json
index c985e072b..e592081bc 100644
--- a/test/fixtures/activitypub-client-post-activity.json
+++ b/test/fixtures/activitypub-client-post-activity.json
@@ -3,6 +3,7 @@
"type": "Create",
"object": {
"type": "Note",
+ "to": ["https://www.w3.org/ns/activitystreams#Public"],
"content": "It's a note"
},
"to": ["https://www.w3.org/ns/activitystreams#Public"]
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/bridgy/actor.json b/test/fixtures/bridgy/actor.json
new file mode 100644
index 000000000..5b2d8982b
--- /dev/null
+++ b/test/fixtures/bridgy/actor.json
@@ -0,0 +1,80 @@
+{
+ "id": "https://fed.brid.gy/jk.nipponalba.scot",
+ "url": "https://fed.brid.gy/r/https://jk.nipponalba.scot",
+ "urls": [
+ {
+ "value": "https://jk.nipponalba.scot"
+ },
+ {
+ "value": "https://social.nipponalba.scot/jk"
+ },
+ {
+ "value": "https://px.nipponalba.scot/jk"
+ }
+ ],
+ "@context": "https://www.w3.org/ns/activitystreams",
+ "type": "Person",
+ "name": "J K 🇯🇵🏴󠁧󠁢󠁳󠁣󠁴󠁿",
+ "image": [
+ {
+ "url": "https://jk.nipponalba.scot/images/profile.jpg",
+ "type": "Image",
+ "name": "profile picture"
+ }
+ ],
+ "tag": [
+ {
+ "type": "Tag",
+ "name": "Craft Beer"
+ },
+ {
+ "type": "Tag",
+ "name": "Single Malt Whisky"
+ },
+ {
+ "type": "Tag",
+ "name": "Homebrewing"
+ },
+ {
+ "type": "Tag",
+ "name": "Scottish Politics"
+ },
+ {
+ "type": "Tag",
+ "name": "Scottish History"
+ },
+ {
+ "type": "Tag",
+ "name": "Japanese History"
+ },
+ {
+ "type": "Tag",
+ "name": "Tech"
+ },
+ {
+ "type": "Tag",
+ "name": "Veganism"
+ },
+ {
+ "type": "Tag",
+ "name": "Cooking"
+ }
+ ],
+ "icon": [
+ {
+ "url": "https://jk.nipponalba.scot/images/profile.jpg",
+ "type": "Image",
+ "name": "profile picture"
+ }
+ ],
+ "preferredUsername": "jk.nipponalba.scot",
+ "summary": "",
+ "publicKey": {
+ "id": "jk.nipponalba.scot",
+ "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdarxwzxnNbJ2hneWOYHkYJowk\npyigQtxlUd0VjgSQHwxU9kWqfbrHBVADyTtcqi/4dAzQd3UnCI1TPNnn4LPZY9PW\noiWd3Zl1/EfLFxO7LU9GS7fcSLQkyj5JNhSlN3I8QPudZbybrgRDVZYooDe1D+52\n5KLGqC2ajrIVOiDRTQIDAQAB\n-----END PUBLIC KEY-----"
+ },
+ "inbox": "https://fed.brid.gy/jk.nipponalba.scot/inbox",
+ "outbox": "https://fed.brid.gy/jk.nipponalba.scot/outbox",
+ "following": "https://fed.brid.gy/jk.nipponalba.scot/following",
+ "followers": "https://fed.brid.gy/jk.nipponalba.scot/followers"
+}
diff --git a/test/fixtures/config/temp.exported_from_db.secret.exs b/test/fixtures/config/temp.exported_from_db.secret.exs
new file mode 100644
index 000000000..94782ec73
--- /dev/null
+++ b/test/fixtures/config/temp.exported_from_db.secret.exs
@@ -0,0 +1,9 @@
+# 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
+
+config :pleroma, :first_setting, key: "new value"
diff --git a/test/fixtures/config/temp.secret.exs b/test/fixtures/config/temp.secret.exs
index 621bc8cf6..e5709ba6f 100644
--- a/test/fixtures/config/temp.secret.exs
+++ b/test/fixtures/config/temp.secret.exs
@@ -1,15 +1,13 @@
# 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
-use Mix.Config
+import Config
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/guppe-actor.json b/test/fixtures/guppe-actor.json
new file mode 100644
index 000000000..d5829ee1f
--- /dev/null
+++ b/test/fixtures/guppe-actor.json
@@ -0,0 +1,26 @@
+{
+ "@context" : [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1"
+ ],
+ "followers" : "https://gup.pe/u/bernie2020/followers",
+ "following" : "https://gup.pe/u/bernie2020/following",
+ "icon" : {
+ "mediaType" : "image/jpeg",
+ "type" : "Image",
+ "url" : "https://gup.pe/f/guppe.png"
+ },
+ "id" : "https://gup.pe/u/bernie2020",
+ "inbox" : "https://gup.pe/u/bernie2020/inbox",
+ "liked" : "https://gup.pe/u/bernie2020/liked",
+ "name" : "Bernie2020 group",
+ "outbox" : "https://gup.pe/u/bernie2020/outbox",
+ "preferredUsername" : "Bernie2020",
+ "publicKey" : {
+ "id" : "https://gup.pe/u/bernie2020#main-key",
+ "owner" : "https://gup.pe/u/bernie2020",
+ "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAw4J8nSrdWWxFaipgWDhR\nbTFzHUGoFy7Gjdc6gg9ZWGWDm9ZU5Ct0C/4o72dXSWdyLbQGYMbWVHLI1LHWKSiC\nVtwIYoccQBaxfi5bCxsahWhhSNPfK8tVlySHvBy73ir8KUZm93eAYh1iE9x+Dk63\nInmi7wzjsqHSlu1KxPGYcnyxs+xxhlTUSd5LsPfO1b9sHMW+X4rEky7OC90veCdD\nsoHU+nCmf+2zJSlOrU7DAzqB4Axc9oS9Q5RlT3yARJQMeu6JyjJJP9CMbpGFbUNT\n5Gsw0km1Rc1rR4tUoz8pLUYtliEUK+/0EmHi2EHAT1ueEfMoGGbCaX/mCoMmAwYJ\nwIGYXmKn2/ARIJpw2XPmrKWXqa2AndOQdb3l44Sl3ej2rC/JQmimGCn7tbfKEZyC\n6mMkOYTIeBtyW/wXFc1+GzJxtvA3C9HjilE+O/7gLHfCLP6FRIxg/9kOLhEj64Ed\n5HZ3sylvifXXubS/lLZr6sZW6d9ICoYLZpFw9AoF2zaYWpvJqBrWinnCJzvbMCYj\nfq/RAkcQYSxkDOHquiGgbRZHGAMKLnz5fMKJIzBtdQojYCUmB14OArW+ITUE9i2a\nPAJaXEGZ+BHYp/0ScFaXwp5LIgT1S+sPKxWJU//77wQfs25i7NZHSN/jtXVmsFS6\nLFVw49LcWAz3J2Im+A+uSd8CAwEAAQ==\n-----END PUBLIC KEY-----\n"
+ },
+ "summary" : "I'm a group about Bernie2020. Follow me to get all the group posts. Tag me to share with the group. Create other groups by searching for or tagging @yourGroupName@gup.pe",
+ "type" : "Group"
+}
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/mastodon/collections/featured.json b/test/fixtures/mastodon/collections/featured.json
new file mode 100644
index 000000000..56f8f56fa
--- /dev/null
+++ b/test/fixtures/mastodon/collections/featured.json
@@ -0,0 +1,39 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://{{domain}}/schemas/litepub-0.1.jsonld",
+ {
+ "@language": "und"
+ }
+ ],
+ "id": "https://{{domain}}/users/{{nickname}}/collections/featured",
+ "orderedItems": [
+ {
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://{{domain}}/schemas/litepub-0.1.jsonld",
+ {
+ "@language": "und"
+ }
+ ],
+ "actor": "https://{{domain}}/users/{{nickname}}",
+ "attachment": [],
+ "attributedTo": "https://{{domain}}/users/{{nickname}}",
+ "cc": [
+ "https://{{domain}}/users/{{nickname}}/followers"
+ ],
+ "content": "",
+ "id": "https://{{domain}}/objects/{{object_id}}",
+ "published": "2021-02-12T15:13:43.915429Z",
+ "sensitive": false,
+ "source": "",
+ "summary": "",
+ "tag": [],
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "type": "Note"
+ }
+ ],
+ "type": "OrderedCollection"
+}
diff --git a/test/fixtures/modules/good_mrf.ex b/test/fixtures/modules/good_mrf.ex
index 39d0f14ec..3ddb74a83 100644
--- a/test/fixtures/modules/good_mrf.ex
+++ b/test/fixtures/modules/good_mrf.ex
@@ -1,5 +1,9 @@
+# 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
+ @behaviour Pleroma.Web.ActivityPub.MRF.Policy
@impl true
def filter(a), do: {:ok, a}
diff --git a/test/fixtures/modules/runtime_module.ex b/test/fixtures/modules/runtime_module.ex
index e348c499e..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-2020 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/peertube/actor-person.json b/test/fixtures/peertube/actor-person.json
new file mode 100644
index 000000000..8c387d455
--- /dev/null
+++ b/test/fixtures/peertube/actor-person.json
@@ -0,0 +1,121 @@
+{
+ "type": "Person",
+ "id": "https://peertube.stream/accounts/createurs",
+ "following": "https://peertube.stream/accounts/createurs/following",
+ "followers": "https://peertube.stream/accounts/createurs/followers",
+ "playlists": "https://peertube.stream/accounts/createurs/playlists",
+ "inbox": "https://peertube.stream/accounts/createurs/inbox",
+ "outbox": "https://peertube.stream/accounts/createurs/outbox",
+ "preferredUsername": "createurs",
+ "url": "https://peertube.stream/accounts/createurs",
+ "name": "Créateurs",
+ "endpoints": {
+ "sharedInbox": "https://peertube.stream/inbox"
+ },
+ "publicKey": {
+ "id": "https://peertube.stream/accounts/createurs#main-key",
+ "owner": "https://peertube.stream/accounts/createurs",
+ "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxqkQhbRYbA81+WTYjorR\n2lEMad3kYCnzDjGTLr4I92eanzFHxyELGnjzP6TpEvjOiB9NrCRrqU/iFPLdgrq2\nwIFcXPWdCq6Gcg7QLlaeMM0JoJmr0KTEhzg0XKCo96UsyTzaF4DISxqi8RyoyWeU\nEkgiOzlkdYTlouq3MlQH+p1PBAsNUQfIEUsU+l6k1vzbm8JRwlT+D1bNde4I/Lqs\n4uB5ru3zzInwZ2hz9+heiriNoGEBv74rZHYn966tZVX8iMGx2+m6okozEdEQbqCl\n0ekqDcd8P6CoFqqeeu8coh82OUtuFI/XsbetdWA55YQmSHyMiTsIwVbeoogIETbI\n4QIDAQAB\n-----END PUBLIC KEY-----"
+ },
+ "icon": {
+ "type": "Image",
+ "mediaType": "image/png",
+ "url": "https://peertube.stream/lazy-static/avatars/c27b672d-ad8f-498a-adbe-553af8da56f9.png"
+ },
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ {
+ "RsaSignature2017": "https://w3id.org/security#RsaSignature2017"
+ },
+ {
+ "pt": "https://joinpeertube.org/ns#",
+ "sc": "http://schema.org#",
+ "Hashtag": "as:Hashtag",
+ "uuid": "sc:identifier",
+ "category": "sc:category",
+ "licence": "sc:license",
+ "subtitleLanguage": "sc:subtitleLanguage",
+ "sensitive": "as:sensitive",
+ "language": "sc:inLanguage",
+ "isLiveBroadcast": "sc:isLiveBroadcast",
+ "liveSaveReplay": {
+ "@type": "sc:Boolean",
+ "@id": "pt:liveSaveReplay"
+ },
+ "permanentLive": {
+ "@type": "sc:Boolean",
+ "@id": "pt:permanentLive"
+ },
+ "Infohash": "pt:Infohash",
+ "Playlist": "pt:Playlist",
+ "PlaylistElement": "pt:PlaylistElement",
+ "originallyPublishedAt": "sc:datePublished",
+ "views": {
+ "@type": "sc:Number",
+ "@id": "pt:views"
+ },
+ "state": {
+ "@type": "sc:Number",
+ "@id": "pt:state"
+ },
+ "size": {
+ "@type": "sc:Number",
+ "@id": "pt:size"
+ },
+ "fps": {
+ "@type": "sc:Number",
+ "@id": "pt:fps"
+ },
+ "startTimestamp": {
+ "@type": "sc:Number",
+ "@id": "pt:startTimestamp"
+ },
+ "stopTimestamp": {
+ "@type": "sc:Number",
+ "@id": "pt:stopTimestamp"
+ },
+ "position": {
+ "@type": "sc:Number",
+ "@id": "pt:position"
+ },
+ "commentsEnabled": {
+ "@type": "sc:Boolean",
+ "@id": "pt:commentsEnabled"
+ },
+ "downloadEnabled": {
+ "@type": "sc:Boolean",
+ "@id": "pt:downloadEnabled"
+ },
+ "waitTranscoding": {
+ "@type": "sc:Boolean",
+ "@id": "pt:waitTranscoding"
+ },
+ "support": {
+ "@type": "sc:Text",
+ "@id": "pt:support"
+ },
+ "likes": {
+ "@id": "as:likes",
+ "@type": "@id"
+ },
+ "dislikes": {
+ "@id": "as:dislikes",
+ "@type": "@id"
+ },
+ "playlists": {
+ "@id": "pt:playlists",
+ "@type": "@id"
+ },
+ "shares": {
+ "@id": "as:shares",
+ "@type": "@id"
+ },
+ "comments": {
+ "@id": "as:comments",
+ "@type": "@id"
+ }
+ }
+ ],
+ "summary": null
+}
diff --git a/test/fixtures/peertube/video-object-mpegURL-only.json b/test/fixtures/peertube/video-object-mpegURL-only.json
new file mode 100644
index 000000000..7f26e89bf
--- /dev/null
+++ b/test/fixtures/peertube/video-object-mpegURL-only.json
@@ -0,0 +1,413 @@
+{
+ "type": "Create",
+ "id": "https://peertube.stream/videos/watch/abece3c3-b9c6-47f4-8040-f3eed8c602e6/activity",
+ "actor": "https://peertube.stream/accounts/createurs",
+ "object": {
+ "type": "Video",
+ "id": "https://peertube.stream/videos/watch/abece3c3-b9c6-47f4-8040-f3eed8c602e6",
+ "name": "Vu du 20/02/21 : \"Planète Mars 2050\"",
+ "duration": "PT385S",
+ "uuid": "abece3c3-b9c6-47f4-8040-f3eed8c602e6",
+ "tag": [
+ {
+ "type": "Hashtag",
+ "name": "France3"
+ },
+ {
+ "type": "Hashtag",
+ "name": "lezapping"
+ }
+ ],
+ "category": {
+ "identifier": "11",
+ "name": "News & Politics"
+ },
+ "language": {
+ "identifier": "fr",
+ "name": "French"
+ },
+ "views": 5,
+ "sensitive": false,
+ "waitTranscoding": false,
+ "isLiveBroadcast": false,
+ "liveSaveReplay": null,
+ "permanentLive": null,
+ "state": 1,
+ "commentsEnabled": true,
+ "downloadEnabled": false,
+ "published": "2021-02-20T17:04:54.278Z",
+ "originallyPublishedAt": "2021-02-19T23:00:00.000Z",
+ "updated": "2021-02-21T20:01:11.189Z",
+ "mediaType": "text/markdown",
+ "content": "Un regard impertinent et libre, orchestré par Patrick Menais et son équipe, sur le monde de l’image.\r\n\r\nEn avant-première du lundi au samedi à 17h00 sur Facebook, Twitter et YouTube.\r\n\r\nDu lundi au samedi à 20h00 sur France 3.\r\n\r\nhttps://www.facebook.com/vufrancetv\r\nhttps://twitter.com/VuFrancetv",
+ "support": "Suivre VU :\r\n- Twitter : https://twitter.com/vufrancetv\r\n- Facebook :https://www.facebook.com/vufrancetv/\r\n- Site : https://www.france.tv/france-3/vu/",
+ "subtitleLanguage": [],
+ "icon": [
+ {
+ "type": "Image",
+ "url": "https://peertube.stream/static/thumbnails/abece3c3-b9c6-47f4-8040-f3eed8c602e6.jpg",
+ "mediaType": "image/jpeg",
+ "width": 223,
+ "height": 122
+ },
+ {
+ "type": "Image",
+ "url": "https://peertube.stream/lazy-static/previews/abece3c3-b9c6-47f4-8040-f3eed8c602e6.jpg",
+ "mediaType": "image/jpeg",
+ "width": 850,
+ "height": 480
+ }
+ ],
+ "url": [
+ {
+ "type": "Link",
+ "mediaType": "text/html",
+ "href": "https://peertube.stream/videos/watch/abece3c3-b9c6-47f4-8040-f3eed8c602e6"
+ },
+ {
+ "type": "Link",
+ "mediaType": "application/x-mpegURL",
+ "href": "https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/master.m3u8",
+ "tag": [
+ {
+ "type": "Infohash",
+ "name": "00bfce9595e1655d8696b60e19ca25c34be5fa63"
+ },
+ {
+ "type": "Infohash",
+ "name": "256c21b65d5e0f944b4b79d8e0cbc55c9d906807"
+ },
+ {
+ "type": "Infohash",
+ "name": "fcd981098c484d0e328927c8fb21ecf986880b7e"
+ },
+ {
+ "type": "Infohash",
+ "name": "f7e01ac566e9fef91cd22514e6c3c256af7a9f5f"
+ },
+ {
+ "type": "Infohash",
+ "name": "42b421fc44d0dceb45ac3f6f6419b07fd570a232"
+ },
+ {
+ "type": "Infohash",
+ "name": "f876c6d6d49ce618a880ca223df54cb29f4b4bfd"
+ },
+ {
+ "type": "Link",
+ "name": "sha256",
+ "mediaType": "application/json",
+ "href": "https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/segments-sha256.json"
+ },
+ {
+ "type": "Link",
+ "mediaType": "video/mp4",
+ "href": "https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/abece3c3-b9c6-47f4-8040-f3eed8c602e6-1080-fragmented.mp4",
+ "height": 1080,
+ "size": 57888169,
+ "fps": 25
+ },
+ {
+ "type": "Link",
+ "rel": [
+ "metadata",
+ "video/mp4"
+ ],
+ "mediaType": "application/json",
+ "href": "https://peertube.stream/api/v1/videos/abece3c3-b9c6-47f4-8040-f3eed8c602e6/metadata/570040",
+ "height": 1080,
+ "fps": 25
+ },
+ {
+ "type": "Link",
+ "mediaType": "application/x-bittorrent",
+ "href": "https://peertube.stream/static/torrents/abece3c3-b9c6-47f4-8040-f3eed8c602e6-1080-hls.torrent",
+ "height": 1080
+ },
+ {
+ "type": "Link",
+ "mediaType": "application/x-bittorrent;x-scheme-handler/magnet",
+ "href": "magnet:?xs=https%3A%2F%2Fpeertube.stream%2Fstatic%2Ftorrents%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6-1080-hls.torrent&xt=urn:btih:68af82ebcd9df8335e407b755f38f5fd39c8a6a4&dn=Vu+du+20%2F02%2F21+%3A+%22Plan%C3%A8te+Mars+2050%22&tr=wss%3A%2F%2Fpeertube.stream%3A443%2Ftracker%2Fsocket&tr=https%3A%2F%2Fpeertube.stream%2Ftracker%2Fannounce&ws=https%3A%2F%2Fpeertube.stream%2Fstatic%2Fstreaming-playlists%2Fhls%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6-1080-fragmented.mp4",
+ "height": 1080
+ },
+ {
+ "type": "Link",
+ "mediaType": "video/mp4",
+ "href": "https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/abece3c3-b9c6-47f4-8040-f3eed8c602e6-720-fragmented.mp4",
+ "height": 720,
+ "size": 45165123,
+ "fps": 25
+ },
+ {
+ "type": "Link",
+ "rel": [
+ "metadata",
+ "video/mp4"
+ ],
+ "mediaType": "application/json",
+ "href": "https://peertube.stream/api/v1/videos/abece3c3-b9c6-47f4-8040-f3eed8c602e6/metadata/570056",
+ "height": 720,
+ "fps": 25
+ },
+ {
+ "type": "Link",
+ "mediaType": "application/x-bittorrent",
+ "href": "https://peertube.stream/static/torrents/abece3c3-b9c6-47f4-8040-f3eed8c602e6-720-hls.torrent",
+ "height": 720
+ },
+ {
+ "type": "Link",
+ "mediaType": "application/x-bittorrent;x-scheme-handler/magnet",
+ "href": "magnet:?xs=https%3A%2F%2Fpeertube.stream%2Fstatic%2Ftorrents%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6-720-hls.torrent&xt=urn:btih:8450928a4ffb2a4c5f927a163487c48c05f6e700&dn=Vu+du+20%2F02%2F21+%3A+%22Plan%C3%A8te+Mars+2050%22&tr=wss%3A%2F%2Fpeertube.stream%3A443%2Ftracker%2Fsocket&tr=https%3A%2F%2Fpeertube.stream%2Ftracker%2Fannounce&ws=https%3A%2F%2Fpeertube.stream%2Fstatic%2Fstreaming-playlists%2Fhls%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6-720-fragmented.mp4",
+ "height": 720
+ },
+ {
+ "type": "Link",
+ "mediaType": "video/mp4",
+ "href": "https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/abece3c3-b9c6-47f4-8040-f3eed8c602e6-480-fragmented.mp4",
+ "height": 480,
+ "size": 29618534,
+ "fps": 25
+ },
+ {
+ "type": "Link",
+ "rel": [
+ "metadata",
+ "video/mp4"
+ ],
+ "mediaType": "application/json",
+ "href": "https://peertube.stream/api/v1/videos/abece3c3-b9c6-47f4-8040-f3eed8c602e6/metadata/570042",
+ "height": 480,
+ "fps": 25
+ },
+ {
+ "type": "Link",
+ "mediaType": "application/x-bittorrent",
+ "href": "https://peertube.stream/static/torrents/abece3c3-b9c6-47f4-8040-f3eed8c602e6-480-hls.torrent",
+ "height": 480
+ },
+ {
+ "type": "Link",
+ "mediaType": "application/x-bittorrent;x-scheme-handler/magnet",
+ "href": "magnet:?xs=https%3A%2F%2Fpeertube.stream%2Fstatic%2Ftorrents%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6-480-hls.torrent&xt=urn:btih:39e11181db5f376aa78c94bffcb9ccf2f4bca715&dn=Vu+du+20%2F02%2F21+%3A+%22Plan%C3%A8te+Mars+2050%22&tr=wss%3A%2F%2Fpeertube.stream%3A443%2Ftracker%2Fsocket&tr=https%3A%2F%2Fpeertube.stream%2Ftracker%2Fannounce&ws=https%3A%2F%2Fpeertube.stream%2Fstatic%2Fstreaming-playlists%2Fhls%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6-480-fragmented.mp4",
+ "height": 480
+ },
+ {
+ "type": "Link",
+ "mediaType": "video/mp4",
+ "href": "https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/abece3c3-b9c6-47f4-8040-f3eed8c602e6-360-fragmented.mp4",
+ "height": 360,
+ "size": 21771466,
+ "fps": 25
+ },
+ {
+ "type": "Link",
+ "rel": [
+ "metadata",
+ "video/mp4"
+ ],
+ "mediaType": "application/json",
+ "href": "https://peertube.stream/api/v1/videos/abece3c3-b9c6-47f4-8040-f3eed8c602e6/metadata/570043",
+ "height": 360,
+ "fps": 25
+ },
+ {
+ "type": "Link",
+ "mediaType": "application/x-bittorrent",
+ "href": "https://peertube.stream/static/torrents/abece3c3-b9c6-47f4-8040-f3eed8c602e6-360-hls.torrent",
+ "height": 360
+ },
+ {
+ "type": "Link",
+ "mediaType": "application/x-bittorrent;x-scheme-handler/magnet",
+ "href": "magnet:?xs=https%3A%2F%2Fpeertube.stream%2Fstatic%2Ftorrents%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6-360-hls.torrent&xt=urn:btih:c33aa52822528e29ffd1a615ebe40450e4c61452&dn=Vu+du+20%2F02%2F21+%3A+%22Plan%C3%A8te+Mars+2050%22&tr=wss%3A%2F%2Fpeertube.stream%3A443%2Ftracker%2Fsocket&tr=https%3A%2F%2Fpeertube.stream%2Ftracker%2Fannounce&ws=https%3A%2F%2Fpeertube.stream%2Fstatic%2Fstreaming-playlists%2Fhls%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6-360-fragmented.mp4",
+ "height": 360
+ },
+ {
+ "type": "Link",
+ "mediaType": "video/mp4",
+ "href": "https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/abece3c3-b9c6-47f4-8040-f3eed8c602e6-240-fragmented.mp4",
+ "height": 240,
+ "size": 14856165,
+ "fps": 25
+ },
+ {
+ "type": "Link",
+ "rel": [
+ "metadata",
+ "video/mp4"
+ ],
+ "mediaType": "application/json",
+ "href": "https://peertube.stream/api/v1/videos/abece3c3-b9c6-47f4-8040-f3eed8c602e6/metadata/570057",
+ "height": 240,
+ "fps": 25
+ },
+ {
+ "type": "Link",
+ "mediaType": "application/x-bittorrent",
+ "href": "https://peertube.stream/static/torrents/abece3c3-b9c6-47f4-8040-f3eed8c602e6-240-hls.torrent",
+ "height": 240
+ },
+ {
+ "type": "Link",
+ "mediaType": "application/x-bittorrent;x-scheme-handler/magnet",
+ "href": "magnet:?xs=https%3A%2F%2Fpeertube.stream%2Fstatic%2Ftorrents%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6-240-hls.torrent&xt=urn:btih:157e4cc3e9f15c06e995d6c3388539fdda312771&dn=Vu+du+20%2F02%2F21+%3A+%22Plan%C3%A8te+Mars+2050%22&tr=wss%3A%2F%2Fpeertube.stream%3A443%2Ftracker%2Fsocket&tr=https%3A%2F%2Fpeertube.stream%2Ftracker%2Fannounce&ws=https%3A%2F%2Fpeertube.stream%2Fstatic%2Fstreaming-playlists%2Fhls%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6-240-fragmented.mp4",
+ "height": 240
+ },
+ {
+ "type": "Link",
+ "mediaType": "video/mp4",
+ "href": "https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/abece3c3-b9c6-47f4-8040-f3eed8c602e6-0-fragmented.mp4",
+ "height": 0,
+ "size": 6248765,
+ "fps": 0
+ },
+ {
+ "type": "Link",
+ "rel": [
+ "metadata",
+ "video/mp4"
+ ],
+ "mediaType": "application/json",
+ "href": "https://peertube.stream/api/v1/videos/abece3c3-b9c6-47f4-8040-f3eed8c602e6/metadata/570041",
+ "height": 0,
+ "fps": 0
+ },
+ {
+ "type": "Link",
+ "mediaType": "application/x-bittorrent",
+ "href": "https://peertube.stream/static/torrents/abece3c3-b9c6-47f4-8040-f3eed8c602e6-0-hls.torrent",
+ "height": 0
+ },
+ {
+ "type": "Link",
+ "mediaType": "application/x-bittorrent;x-scheme-handler/magnet",
+ "href": "magnet:?xs=https%3A%2F%2Fpeertube.stream%2Fstatic%2Ftorrents%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6-0-hls.torrent&xt=urn:btih:abc8dc58903d18cf7ec0c0cef92cc5ffe5cb0b5c&dn=Vu+du+20%2F02%2F21+%3A+%22Plan%C3%A8te+Mars+2050%22&tr=wss%3A%2F%2Fpeertube.stream%3A443%2Ftracker%2Fsocket&tr=https%3A%2F%2Fpeertube.stream%2Ftracker%2Fannounce&ws=https%3A%2F%2Fpeertube.stream%2Fstatic%2Fstreaming-playlists%2Fhls%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6%2Fabece3c3-b9c6-47f4-8040-f3eed8c602e6-0-fragmented.mp4",
+ "height": 0
+ }
+ ]
+ }
+ ],
+ "likes": "https://peertube.stream/videos/watch/abece3c3-b9c6-47f4-8040-f3eed8c602e6/likes",
+ "dislikes": "https://peertube.stream/videos/watch/abece3c3-b9c6-47f4-8040-f3eed8c602e6/dislikes",
+ "shares": "https://peertube.stream/videos/watch/abece3c3-b9c6-47f4-8040-f3eed8c602e6/announces",
+ "comments": "https://peertube.stream/videos/watch/abece3c3-b9c6-47f4-8040-f3eed8c602e6/comments",
+ "attributedTo": [
+ {
+ "type": "Person",
+ "id": "https://peertube.stream/accounts/createurs"
+ },
+ {
+ "type": "Group",
+ "id": "https://peertube.stream/video-channels/vu"
+ }
+ ],
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "cc": [
+ "https://peertube.stream/accounts/createurs/followers"
+ ]
+ },
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "cc": [
+ "https://peertube.stream/accounts/createurs/followers"
+ ],
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ {
+ "RsaSignature2017": "https://w3id.org/security#RsaSignature2017"
+ },
+ {
+ "pt": "https://joinpeertube.org/ns#",
+ "sc": "http://schema.org#",
+ "Hashtag": "as:Hashtag",
+ "uuid": "sc:identifier",
+ "category": "sc:category",
+ "licence": "sc:license",
+ "subtitleLanguage": "sc:subtitleLanguage",
+ "sensitive": "as:sensitive",
+ "language": "sc:inLanguage",
+ "isLiveBroadcast": "sc:isLiveBroadcast",
+ "liveSaveReplay": {
+ "@type": "sc:Boolean",
+ "@id": "pt:liveSaveReplay"
+ },
+ "permanentLive": {
+ "@type": "sc:Boolean",
+ "@id": "pt:permanentLive"
+ },
+ "Infohash": "pt:Infohash",
+ "Playlist": "pt:Playlist",
+ "PlaylistElement": "pt:PlaylistElement",
+ "originallyPublishedAt": "sc:datePublished",
+ "views": {
+ "@type": "sc:Number",
+ "@id": "pt:views"
+ },
+ "state": {
+ "@type": "sc:Number",
+ "@id": "pt:state"
+ },
+ "size": {
+ "@type": "sc:Number",
+ "@id": "pt:size"
+ },
+ "fps": {
+ "@type": "sc:Number",
+ "@id": "pt:fps"
+ },
+ "startTimestamp": {
+ "@type": "sc:Number",
+ "@id": "pt:startTimestamp"
+ },
+ "stopTimestamp": {
+ "@type": "sc:Number",
+ "@id": "pt:stopTimestamp"
+ },
+ "position": {
+ "@type": "sc:Number",
+ "@id": "pt:position"
+ },
+ "commentsEnabled": {
+ "@type": "sc:Boolean",
+ "@id": "pt:commentsEnabled"
+ },
+ "downloadEnabled": {
+ "@type": "sc:Boolean",
+ "@id": "pt:downloadEnabled"
+ },
+ "waitTranscoding": {
+ "@type": "sc:Boolean",
+ "@id": "pt:waitTranscoding"
+ },
+ "support": {
+ "@type": "sc:Text",
+ "@id": "pt:support"
+ },
+ "likes": {
+ "@id": "as:likes",
+ "@type": "@id"
+ },
+ "dislikes": {
+ "@id": "as:dislikes",
+ "@type": "@id"
+ },
+ "playlists": {
+ "@id": "pt:playlists",
+ "@type": "@id"
+ },
+ "shares": {
+ "@id": "as:shares",
+ "@type": "@id"
+ },
+ "comments": {
+ "@id": "as:comments",
+ "@type": "@id"
+ }
+ }
+ ]
+}
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/statuses/masto-note.json b/test/fixtures/statuses/masto-note.json
new file mode 100644
index 000000000..6b96de473
--- /dev/null
+++ b/test/fixtures/statuses/masto-note.json
@@ -0,0 +1,47 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ {
+ "ostatus": "http://ostatus.org#",
+ "atomUri": "ostatus:atomUri",
+ "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+ "conversation": "ostatus:conversation",
+ "sensitive": "as:sensitive",
+ "toot": "http://joinmastodon.org/ns#",
+ "votersCount": "toot:votersCount"
+ }
+ ],
+ "id": "https://example.com/users/{{nickname}}/statuses/{{status_id}}",
+ "type": "Note",
+ "summary": null,
+ "inReplyTo": null,
+ "published": "2021-02-24T12:40:49Z",
+ "url": "https://example.com/@{{nickname}}/{{status_id}}",
+ "attributedTo": "https://example.com/users/{{nickname}}",
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "cc": [
+ "https://example.com/users/{{nickname}}/followers"
+ ],
+ "sensitive": false,
+ "atomUri": "https://example.com/users/{{nickname}}/statuses/{{status_id}}",
+ "inReplyToAtomUri": null,
+ "conversation": "tag:example.com,2021-02-24:objectId=15:objectType=Conversation",
+ "content": "<p></p>",
+ "contentMap": {
+ "en": "<p></p>"
+ },
+ "attachment": [],
+ "tag": [],
+ "replies": {
+ "id": "https://example.com/users/{{nickname}}/statuses/{{status_id}}/replies",
+ "type": "Collection",
+ "first": {
+ "type": "CollectionPage",
+ "next": "https://example.com/users/{{nickname}}/statuses/{{status_id}}/replies?only_other_accounts=true&page=true",
+ "partOf": "https://example.com/users/{{nickname}}/statuses/{{status_id}}/replies",
+ "items": []
+ }
+ }
+}
diff --git a/test/fixtures/statuses/note.json b/test/fixtures/statuses/note.json
new file mode 100644
index 000000000..41735cbc5
--- /dev/null
+++ b/test/fixtures/statuses/note.json
@@ -0,0 +1,27 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://example.com/schemas/litepub-0.1.jsonld",
+ {
+ "@language": "und"
+ }
+ ],
+ "actor": "https://example.com/users/{{nickname}}",
+ "attachment": [],
+ "attributedTo": "https://example.com/users/{{nickname}}",
+ "cc": [
+ "https://example.com/users/{{nickname}}/followers"
+ ],
+ "content": "Content",
+ "context": "https://example.com/contexts/e4b180e1-7403-477f-aeb4-de57e7a3fe7f",
+ "conversation": "https://example.com/contexts/e4b180e1-7403-477f-aeb4-de57e7a3fe7f",
+ "id": "https://example.com/objects/{{object_id}}",
+ "published": "2019-12-15T22:00:05.279583Z",
+ "sensitive": false,
+ "summary": "",
+ "tag": [],
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "type": "Note"
+}
diff --git a/test/fixtures/tesla_mock/emoji-in-summary.json b/test/fixtures/tesla_mock/emoji-in-summary.json
new file mode 100644
index 000000000..f77c6e2e8
--- /dev/null
+++ b/test/fixtures/tesla_mock/emoji-in-summary.json
@@ -0,0 +1,49 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://patch.cx/schemas/litepub-0.1.jsonld",
+ {
+ "@language": "und"
+ }
+ ],
+ "actor": "https://patch.cx/users/rin",
+ "attachment": [],
+ "attributedTo": "https://patch.cx/users/rin",
+ "cc": [
+ "https://patch.cx/users/rin/followers"
+ ],
+ "content": ":joker_disapprove: <br><br>just grabbing a test fixture, nevermind me",
+ "context": "https://patch.cx/contexts/2c3ce4b4-18b1-4b1a-8965-3932027b5326",
+ "conversation": "https://patch.cx/contexts/2c3ce4b4-18b1-4b1a-8965-3932027b5326",
+ "id": "https://patch.cx/objects/a399c28e-c821-4820-bc3e-4afeb044c16f",
+ "published": "2021-03-22T16:54:46.461939Z",
+ "sensitive": null,
+ "source": ":joker_disapprove: \r\n\r\njust grabbing a test fixture, nevermind me",
+ "summary": ":joker_smile: ",
+ "tag": [
+ {
+ "icon": {
+ "type": "Image",
+ "url": "https://patch.cx/emoji/custom/joker_disapprove.png"
+ },
+ "id": "https://patch.cx/emoji/custom/joker_disapprove.png",
+ "name": ":joker_disapprove:",
+ "type": "Emoji",
+ "updated": "1970-01-01T00:00:00Z"
+ },
+ {
+ "icon": {
+ "type": "Image",
+ "url": "https://patch.cx/emoji/custom/joker_smile.png"
+ },
+ "id": "https://patch.cx/emoji/custom/joker_smile.png",
+ "name": ":joker_smile:",
+ "type": "Emoji",
+ "updated": "1970-01-01T00:00:00Z"
+ }
+ ],
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "type": "Note"
+}
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/lemmy-page.json b/test/fixtures/tesla_mock/lemmy-page.json
new file mode 100644
index 000000000..f07097a0e
--- /dev/null
+++ b/test/fixtures/tesla_mock/lemmy-page.json
@@ -0,0 +1,17 @@
+{
+ "commentsEnabled": true,
+ "sensitive": false,
+ "stickied": false,
+ "attributedTo": "https://enterprise.lemmy.ml/u/nutomic",
+ "summary": "Hello Federation!",
+ "url": "https://enterprise.lemmy.ml/pictrs/image/US52d9DPvf.jpg",
+ "image": {
+ "type": "Image",
+ "url": "https://enterprise.lemmy.ml/pictrs/image/lwFAcXHUjS.jpg"
+ },
+ "published": "2020-09-14T15:03:11.909105+00:00",
+ "to": "https://enterprise.lemmy.ml/c/main",
+ "@context": "https://www.w3.org/ns/activitystreams",
+ "id": "https://enterprise.lemmy.ml/post/3",
+ "type": "Page"
+}
diff --git a/test/fixtures/tesla_mock/lemmy-user.json b/test/fixtures/tesla_mock/lemmy-user.json
new file mode 100644
index 000000000..d0e9066ac
--- /dev/null
+++ b/test/fixtures/tesla_mock/lemmy-user.json
@@ -0,0 +1,27 @@
+{
+ "publicKey": {
+ "id": "https://enterprise.lemmy.ml/u/nutomic#main-key",
+ "owner": "https://enterprise.lemmy.ml/u/nutomic",
+ "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvfwAYPxp1gOk2HcCRoUd\nupoecvmnpzRc5Gu6/N3YQyOyRsrYuiYLNQq2cgM3kcU80ZeEetkwkYgXkRJOKu/b\nBWb7i1zt2tdr5k6lUdW8dfCyjht8ooFPQdov8J3QYHfgBHyUYxuCNfSujryxx2wu\nLQcdjRQa5NIWcomSO8OXmCF5/Yhg2XWCbtnlxEq6Y+AFddr1mAlTOy5pBr5d+xZz\njLw/U3CioNJ79yGi/sJhgp6IyJqtUSoN3b4BgRIEts2QVvn44W1rQy9wCbRYQrO1\nBcB9Wel4k3rJJK8uHg+LpHVMaZppkNaWGkMBhMbzr8qmIlcNWNi7cbMK/p5vyviy\nSwIDAQAB\n-----END PUBLIC KEY-----\n"
+ },
+ "inbox": "https://enterprise.lemmy.ml/u/nutomic/inbox",
+ "preferredUsername": "Nutomic",
+ "endpoints": {
+ "sharedInbox": "https://enterprise.lemmy.ml/inbox"
+ },
+ "summary": "some bio",
+ "icon": {
+ "type": "Image",
+ "url": "https://enterprise.lemmy.ml/pictrs/image/F6Z7QcWZRJ.jpg"
+ },
+ "image": {
+ "type": "Image",
+ "url": "https://enterprise.lemmy.ml:/pictrs/image/Q79N9oCDEG.png"
+ },
+ "published": "2020-09-14T14:54:53.080949+00:00",
+ "updated": "2020-10-14T10:58:28.139178+00:00",
+ "@context": "https://www.w3.org/ns/activitystreams",
+ "id": "https://enterprise.lemmy.ml/u/nutomic",
+ "type": "Person",
+ "name": "nutomic"
+}
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/tesla_mock/xn--q9jyb4c_host_meta b/test/fixtures/tesla_mock/xn--q9jyb4c_host_meta
deleted file mode 100644
index 45d260e55..000000000
--- a/test/fixtures/tesla_mock/xn--q9jyb4c_host_meta
+++ /dev/null
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
- <Link rel="lrdd" template="https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource={uri}" type="application/xrd+xml" />
-</XRD>
diff --git a/test/fixtures/users_mock/localhost.json b/test/fixtures/users_mock/localhost.json
deleted file mode 100644
index a49935db1..000000000
--- a/test/fixtures/users_mock/localhost.json
+++ /dev/null
@@ -1,41 +0,0 @@
-{
- "@context": [
- "https://www.w3.org/ns/activitystreams",
- "http://localhost:4001/schemas/litepub-0.1.jsonld",
- {
- "@language": "und"
- }
- ],
- "attachment": [],
- "endpoints": {
- "oauthAuthorizationEndpoint": "http://localhost:4001/oauth/authorize",
- "oauthRegistrationEndpoint": "http://localhost:4001/api/v1/apps",
- "oauthTokenEndpoint": "http://localhost:4001/oauth/token",
- "sharedInbox": "http://localhost:4001/inbox"
- },
- "followers": "http://localhost:4001/users/{{nickname}}/followers",
- "following": "http://localhost:4001/users/{{nickname}}/following",
- "icon": {
- "type": "Image",
- "url": "http://localhost:4001/media/4e914f5b84e4a259a3f6c2d2edc9ab642f2ab05f3e3d9c52c81fc2d984b3d51e.jpg"
- },
- "id": "http://localhost:4001/users/{{nickname}}",
- "image": {
- "type": "Image",
- "url": "http://localhost:4001/media/f739efddefeee49c6e67e947c4811fdc911785c16ae43da4c3684051fbf8da6a.jpg?name=f739efddefeee49c6e67e947c4811fdc911785c16ae43da4c3684051fbf8da6a.jpg"
- },
- "inbox": "http://localhost:4001/users/{{nickname}}/inbox",
- "manuallyApprovesFollowers": false,
- "name": "{{nickname}}",
- "outbox": "http://localhost:4001/users/{{nickname}}/outbox",
- "preferredUsername": "{{nickname}}",
- "publicKey": {
- "id": "http://localhost:4001/users/{{nickname}}#main-key",
- "owner": "http://localhost:4001/users/{{nickname}}",
- "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5DLtwGXNZElJyxFGfcVc\nXANhaMadj/iYYQwZjOJTV9QsbtiNBeIK54PJrYuU0/0YIdrvS1iqheX5IwXRhcwa\nhm3ZyLz7XeN9st7FBni4BmZMBtMpxAuYuu5p/jbWy13qAiYOhPreCx0wrWgm/lBD\n9mkgaxIxPooBE0S4ZWEJIDIV1Vft3AWcRUyWW1vIBK0uZzs6GYshbQZB952S0yo4\nFzI1hABGHncH8UvuFauh4EZ8tY7/X5I0pGRnDOcRN1dAht5w5yTA+6r5kebiFQjP\nIzN/eCO/a9Flrj9YGW7HDNtjSOH0A31PLRGlJtJO3yK57dnf5ppyCZGfL4emShQo\ncQIDAQAB\n-----END PUBLIC KEY-----\n\n"
- },
- "summary": "your friendly neighborhood pleroma developer<br>I like cute things and distributed systems, and really hate delete and redrafts",
- "tag": [],
- "type": "Person",
- "url": "http://localhost:4001/users/{{nickname}}"
-} \ No newline at end of file
diff --git a/test/fixtures/users_mock/masto_featured.json b/test/fixtures/users_mock/masto_featured.json
new file mode 100644
index 000000000..646a343ad
--- /dev/null
+++ b/test/fixtures/users_mock/masto_featured.json
@@ -0,0 +1,18 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ {
+ "ostatus": "http://ostatus.org#",
+ "atomUri": "ostatus:atomUri",
+ "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+ "conversation": "ostatus:conversation",
+ "sensitive": "as:sensitive",
+ "toot": "http://joinmastodon.org/ns#",
+ "votersCount": "toot:votersCount"
+ }
+ ],
+ "id": "https://{{domain}}/users/{{nickname}}/collections/featured",
+ "type": "OrderedCollection",
+ "totalItems": 0,
+ "orderedItems": []
+}
diff --git a/test/fixtures/users_mock/user.json b/test/fixtures/users_mock/user.json
new file mode 100644
index 000000000..c722a1145
--- /dev/null
+++ b/test/fixtures/users_mock/user.json
@@ -0,0 +1,42 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://example.com/schemas/litepub-0.1.jsonld",
+ {
+ "@language": "und"
+ }
+ ],
+ "attachment": [],
+ "endpoints": {
+ "oauthAuthorizationEndpoint": "https://example.com/oauth/authorize",
+ "oauthRegistrationEndpoint": "https://example.com/api/v1/apps",
+ "oauthTokenEndpoint": "https://example.com/oauth/token",
+ "sharedInbox": "https://example.com/inbox"
+ },
+ "followers": "https://example.com/users/{{nickname}}/followers",
+ "following": "https://example.com/users/{{nickname}}/following",
+ "icon": {
+ "type": "Image",
+ "url": "https://example.com/media/4e914f5b84e4a259a3f6c2d2edc9ab642f2ab05f3e3d9c52c81fc2d984b3d51e.jpg"
+ },
+ "id": "https://example.com/users/{{nickname}}",
+ "image": {
+ "type": "Image",
+ "url": "https://example.com/media/f739efddefeee49c6e67e947c4811fdc911785c16ae43da4c3684051fbf8da6a.jpg?name=f739efddefeee49c6e67e947c4811fdc911785c16ae43da4c3684051fbf8da6a.jpg"
+ },
+ "inbox": "https://example.com/users/{{nickname}}/inbox",
+ "manuallyApprovesFollowers": false,
+ "name": "{{nickname}}",
+ "outbox": "https://example.com/users/{{nickname}}/outbox",
+ "preferredUsername": "{{nickname}}",
+ "publicKey": {
+ "id": "https://example.com/users/{{nickname}}#main-key",
+ "owner": "https://example.com/users/{{nickname}}",
+ "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5DLtwGXNZElJyxFGfcVc\nXANhaMadj/iYYQwZjOJTV9QsbtiNBeIK54PJrYuU0/0YIdrvS1iqheX5IwXRhcwa\nhm3ZyLz7XeN9st7FBni4BmZMBtMpxAuYuu5p/jbWy13qAiYOhPreCx0wrWgm/lBD\n9mkgaxIxPooBE0S4ZWEJIDIV1Vft3AWcRUyWW1vIBK0uZzs6GYshbQZB952S0yo4\nFzI1hABGHncH8UvuFauh4EZ8tY7/X5I0pGRnDOcRN1dAht5w5yTA+6r5kebiFQjP\nIzN/eCO/a9Flrj9YGW7HDNtjSOH0A31PLRGlJtJO3yK57dnf5ppyCZGfL4emShQo\ncQIDAQAB\n-----END PUBLIC KEY-----\n\n"
+ },
+ "featured": "https://example.com/users/{{nickname}}/collections/featured",
+ "summary": "your friendly neighborhood pleroma developer<br>I like cute things and distributed systems, and really hate delete and redrafts",
+ "tag": [],
+ "type": "Person",
+ "url": "https://example.com/users/{{nickname}}"
+}
diff --git a/test/fixtures/video.mp4 b/test/fixtures/video.mp4
new file mode 100644
index 000000000..2021e3a5b
--- /dev/null
+++ b/test/fixtures/video.mp4
Binary files differ
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 c3e47b285..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-2020 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 71a84ac8e..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-2020 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 0280d208d..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-2020 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
@@ -188,15 +183,43 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
assert File.exists?(temp_file)
{:ok, file} = File.read(temp_file)
- header =
- if Code.ensure_loaded?(Config.Reader) do
- "import Config"
- else
- "use Mix.Config"
- end
-
assert file ==
- "#{header}\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n attachment_links: false,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n"
+ "import Config\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n attachment_links: false,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n"
+ end
+ end
+
+ describe "migrate_from_db/1" do
+ setup do: clear_config(:configurable_from_database, true)
+
+ setup do
+ insert_config_record(:pleroma, :setting_first, key: "value", key2: ["Activity"])
+ insert_config_record(:pleroma, :setting_second, key: "value2", key2: [Repo])
+
+ path = "test/instance_static"
+ file_path = Path.join(path, "temp.exported_from_db.secret.exs")
+
+ on_exit(fn -> File.rm!(file_path) end)
+
+ [file_path: file_path]
+ end
+
+ test "with path parameter", %{file_path: file_path} do
+ MixTask.run(["migrate_from_db", "--env", "temp", "--path", Path.dirname(file_path)])
+
+ file = File.read!(file_path)
+ assert file =~ "config :pleroma, :setting_first,"
+ assert file =~ "config :pleroma, :setting_second,"
+ end
+
+ test "release", %{file_path: file_path} do
+ clear_config(:release, true)
+ clear_config(:config_path, file_path)
+
+ MixTask.run(["migrate_from_db", "--env", "temp"])
+
+ file = File.read!(file_path)
+ assert file =~ "config :pleroma, :setting_first,"
+ assert file =~ "config :pleroma, :setting_second,"
end
end
diff --git a/test/mix/tasks/pleroma/count_statuses_test.exs b/test/mix/tasks/pleroma/count_statuses_test.exs
index 8fe3959ea..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-2020 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 eefb12426..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-2020 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 69dccb745..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-2020 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 548357508..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-2020 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
@@ -13,7 +13,7 @@ defmodule Mix.Tasks.Pleroma.Ecto.MigrateTest do
assert capture_log(fn ->
Mix.Tasks.Pleroma.Ecto.Migrate.run()
- end) =~ "[info] Already up"
+ end) =~ "[info] Migrations already up"
Logger.configure(level: level)
end
diff --git a/test/mix/tasks/pleroma/ecto/rollback_test.exs b/test/mix/tasks/pleroma/ecto/rollback_test.exs
index 9e39db8fa..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-2020 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
@@ -12,7 +12,7 @@ defmodule Mix.Tasks.Pleroma.Ecto.RollbackTest do
Logger.configure(level: :warn)
assert capture_log(fn ->
- Mix.Tasks.Pleroma.Ecto.Rollback.run()
+ Mix.Tasks.Pleroma.Ecto.Rollback.run(["--env", "test"])
end) =~ "[info] Rollback succesfully"
Logger.configure(level: level)
diff --git a/test/mix/tasks/pleroma/ecto_test.exs b/test/mix/tasks/pleroma/ecto_test.exs
index 3a028df83..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-2020 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 9523aefd8..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-2020 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
@@ -61,18 +61,18 @@ defmodule Mix.Tasks.Pleroma.EmailTest do
test "Sends confirmation emails" do
local_user1 =
insert(:user, %{
- confirmation_pending: true,
+ is_confirmed: false,
confirmation_token: "mytoken",
- deactivated: false,
+ is_active: true,
email: "local1@pleroma.com",
local: true
})
local_user2 =
insert(:user, %{
- confirmation_pending: true,
+ is_confirmed: false,
confirmation_token: "mytoken",
- deactivated: false,
+ is_active: true,
email: "local2@pleroma.com",
local: true
})
@@ -88,30 +88,30 @@ defmodule Mix.Tasks.Pleroma.EmailTest do
test "Does not send confirmation email to inappropriate users" do
# confirmed user
insert(:user, %{
- confirmation_pending: false,
+ is_confirmed: true,
confirmation_token: "mytoken",
- deactivated: false,
+ is_active: true,
email: "confirmed@pleroma.com",
local: true
})
# remote user
insert(:user, %{
- deactivated: false,
+ is_active: true,
email: "remote@not-pleroma.com",
local: false
})
# deactivated user =
insert(:user, %{
- deactivated: true,
+ is_active: false,
email: "deactivated@pleroma.com",
local: false
})
# invisible user
insert(:user, %{
- deactivated: false,
+ is_active: true,
email: "invisible@pleroma.com",
local: true,
invisible: true
diff --git a/test/mix/tasks/pleroma/emoji_test.exs b/test/mix/tasks/pleroma/emoji_test.exs
index 0fb8603ac..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-2020 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 6f9ec14cd..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-2020 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 1d2dde108..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-2020 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 e79dc0632..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-2020 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 b453ed1c6..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-2020 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 7040a0e4e..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-2020 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
@@ -12,7 +12,7 @@ defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
test "creates new dir" do
path = "test/fixtures/new_dir/"
file_path = path <> "robots.txt"
- Pleroma.Config.put([:instance, :static_dir], path)
+ clear_config([:instance, :static_dir], path)
on_exit(fn ->
{:ok, ["test/fixtures/new_dir/", "test/fixtures/new_dir/robots.txt"]} = File.rm_rf(path)
@@ -29,7 +29,7 @@ defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
test "to existance folder" do
path = "test/fixtures/"
file_path = path <> "robots.txt"
- Pleroma.Config.put([:instance, :static_dir], path)
+ clear_config([:instance, :static_dir], path)
on_exit(fn ->
:ok = File.rm(file_path)
diff --git a/test/mix/tasks/pleroma/uploads_test.exs b/test/mix/tasks/pleroma/uploads_test.exs
index d69e149a8..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-2020 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 de8ab27e5..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-2020 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
@@ -102,7 +102,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ " deleted"
- assert %{deactivated: true} = User.get_by_nickname(user.nickname)
+ assert %{is_active: false} = User.get_by_nickname(user.nickname)
assert called(Pleroma.Web.Federator.publish(:_))
end
@@ -114,7 +114,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
{:ok, post} = CommonAPI.post(user, %{status: "uguu"})
{:ok, post2} = CommonAPI.post(user2, %{status: "test"})
- obj = Object.normalize(post2)
+ obj = Object.normalize(post2, fetch: false)
{:ok, like_object, meta} = Pleroma.Web.ActivityPub.Builder.like(user, obj)
@@ -130,7 +130,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
clear_config([:instance, :federating], true)
- object = Object.normalize(post)
+ object = Object.normalize(post, fetch: false)
Object.prune(object)
with_mock Pleroma.Web.Federator,
@@ -140,7 +140,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ " deleted"
- assert %{deactivated: true} = User.get_by_nickname(user.nickname)
+ assert %{is_active: false} = User.get_by_nickname(user.nickname)
assert called(Pleroma.Web.Federator.publish(:_))
refute Pleroma.Repo.get(Pleroma.Activity, like_activity.id)
@@ -157,41 +157,8 @@ defmodule Mix.Tasks.Pleroma.UserTest do
end
end
- describe "running toggle_activated" do
- test "user is deactivated" do
- user = insert(:user)
-
- Mix.Tasks.Pleroma.User.run(["toggle_activated", user.nickname])
-
- assert_received {:mix_shell, :info, [message]}
- assert message =~ " deactivated"
-
- user = User.get_cached_by_nickname(user.nickname)
- assert user.deactivated
- end
-
- test "user is activated" do
- user = insert(:user, deactivated: true)
-
- Mix.Tasks.Pleroma.User.run(["toggle_activated", user.nickname])
-
- assert_received {:mix_shell, :info, [message]}
- assert message =~ " activated"
-
- user = User.get_cached_by_nickname(user.nickname)
- refute user.deactivated
- end
-
- test "no user to toggle" do
- Mix.Tasks.Pleroma.User.run(["toggle_activated", "nonexistent"])
-
- assert_received {:mix_shell, :error, [message]}
- assert message =~ "No user"
- end
- end
-
describe "running deactivate" do
- test "user is unsubscribed" do
+ test "active user is deactivated and unsubscribed" do
followed = insert(:user)
remote_followed = insert(:user, local: false)
user = insert(:user)
@@ -201,16 +168,26 @@ defmodule Mix.Tasks.Pleroma.UserTest do
Mix.Tasks.Pleroma.User.run(["deactivate", user.nickname])
- assert_received {:mix_shell, :info, [message]}
- assert message =~ "Deactivating"
-
# Note that the task has delay :timer.sleep(500)
assert_received {:mix_shell, :info, [message]}
- assert message =~ "Successfully unsubscribed"
+
+ assert message ==
+ "Successfully deactivated #{user.nickname} and unsubscribed all local followers"
user = User.get_cached_by_nickname(user.nickname)
assert Enum.empty?(Enum.filter(User.get_friends(user), & &1.local))
- assert user.deactivated
+ refute user.is_active
+ end
+
+ test "user is deactivated" do
+ %{id: id, nickname: nickname} = insert(:user, is_active: false)
+
+ assert :ok = Mix.Tasks.Pleroma.User.run(["deactivate", nickname])
+ assert_received {:mix_shell, :info, [message]}
+ assert message == "User #{nickname} already deactivated"
+
+ user = Repo.get(User, id)
+ refute user.is_active
end
test "no user to deactivate" do
@@ -238,7 +215,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert message =~ ~r/Admin status .* true/
assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r/Confirmation pending .* false/
+ assert message =~ ~r/Confirmation status.* true/
assert_received {:mix_shell, :info, [message]}
assert message =~ ~r/Locked status .* true/
@@ -250,7 +227,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert user.is_moderator
assert user.is_locked
assert user.is_admin
- refute user.confirmation_pending
+ assert user.is_confirmed
end
test "All statuses unset" do
@@ -259,7 +236,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
is_locked: true,
is_moderator: true,
is_admin: true,
- confirmation_pending: true
+ is_confirmed: false
)
Mix.Tasks.Pleroma.User.run([
@@ -275,7 +252,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert message =~ ~r/Admin status .* false/
assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r/Confirmation pending .* true/
+ assert message =~ ~r/Confirmation status.* false/
assert_received {:mix_shell, :info, [message]}
assert message =~ ~r/Locked status .* false/
@@ -287,7 +264,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
refute user.is_moderator
refute user.is_locked
refute user.is_admin
- assert user.confirmation_pending
+ refute user.is_confirmed
end
test "no user to set status" do
@@ -436,13 +413,6 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ "Invite for token #{invite.token} was revoked."
end
-
- test "it prints an error message when invite is not exist" do
- Mix.Tasks.Pleroma.User.run(["revoke_invite", "foo"])
-
- assert_received {:mix_shell, :error, [message]}
- assert message =~ "No invite found"
- end
end
describe "running delete_activities" do
@@ -464,27 +434,27 @@ defmodule Mix.Tasks.Pleroma.UserTest do
describe "running confirm" do
test "user is confirmed" do
- %{id: id, nickname: nickname} = insert(:user, confirmation_pending: false)
+ %{id: id, nickname: nickname} = insert(:user, is_confirmed: true)
assert :ok = Mix.Tasks.Pleroma.User.run(["confirm", nickname])
assert_received {:mix_shell, :info, [message]}
assert message == "#{nickname} doesn't need confirmation."
user = Repo.get(User, id)
- refute user.confirmation_pending
+ assert user.is_confirmed
refute user.confirmation_token
end
test "user is not confirmed" do
%{id: id, nickname: nickname} =
- insert(:user, confirmation_pending: true, confirmation_token: "some token")
+ insert(:user, is_confirmed: false, confirmation_token: "some token")
assert :ok = Mix.Tasks.Pleroma.User.run(["confirm", nickname])
assert_received {:mix_shell, :info, [message]}
assert message == "#{nickname} doesn't need confirmation."
user = Repo.get(User, id)
- refute user.confirmation_pending
+ assert user.is_confirmed
refute user.confirmation_token
end
@@ -496,6 +466,37 @@ defmodule Mix.Tasks.Pleroma.UserTest do
end
end
+ describe "running activate" do
+ test "user is activated" do
+ %{id: id, nickname: nickname} = insert(:user, is_active: true)
+
+ assert :ok = Mix.Tasks.Pleroma.User.run(["activate", nickname])
+ assert_received {:mix_shell, :info, [message]}
+ assert message == "User #{nickname} already activated"
+
+ user = Repo.get(User, id)
+ assert user.is_active
+ end
+
+ test "user is not activated" do
+ %{id: id, nickname: nickname} = insert(:user, is_active: false)
+
+ assert :ok = Mix.Tasks.Pleroma.User.run(["activate", nickname])
+ assert_received {:mix_shell, :info, [message]}
+ assert message == "Successfully activated #{nickname}"
+
+ user = Repo.get(User, id)
+ assert user.is_active
+ end
+
+ test "no user to activate" do
+ Mix.Tasks.Pleroma.User.run(["activate", "foo"])
+
+ assert_received {:mix_shell, :error, [message]}
+ assert message =~ "No user"
+ end
+ end
+
describe "search" do
test "it returns users matching" do
user = insert(:user)
@@ -579,29 +580,29 @@ defmodule Mix.Tasks.Pleroma.UserTest do
describe "bulk confirm and unconfirm" do
test "confirm all" do
- user1 = insert(:user, confirmation_pending: true)
- user2 = insert(:user, confirmation_pending: true)
+ user1 = insert(:user, is_confirmed: false)
+ user2 = insert(:user, is_confirmed: false)
- assert user1.confirmation_pending
- assert user2.confirmation_pending
+ refute user1.is_confirmed
+ refute user2.is_confirmed
Mix.Tasks.Pleroma.User.run(["confirm_all"])
user1 = User.get_cached_by_nickname(user1.nickname)
user2 = User.get_cached_by_nickname(user2.nickname)
- refute user1.confirmation_pending
- refute user2.confirmation_pending
+ assert user1.is_confirmed
+ assert user2.is_confirmed
end
test "unconfirm all" do
- user1 = insert(:user, confirmation_pending: false)
- user2 = insert(:user, confirmation_pending: false)
- admin = insert(:user, is_admin: true, confirmation_pending: false)
- mod = insert(:user, is_moderator: true, confirmation_pending: false)
+ user1 = insert(:user, is_confirmed: true)
+ user2 = insert(:user, is_confirmed: true)
+ admin = insert(:user, is_admin: true, is_confirmed: true)
+ mod = insert(:user, is_moderator: true, is_confirmed: true)
- refute user1.confirmation_pending
- refute user2.confirmation_pending
+ assert user1.is_confirmed
+ assert user2.is_confirmed
Mix.Tasks.Pleroma.User.run(["unconfirm_all"])
@@ -610,10 +611,10 @@ defmodule Mix.Tasks.Pleroma.UserTest do
admin = User.get_cached_by_nickname(admin.nickname)
mod = User.get_cached_by_nickname(mod.nickname)
- assert user1.confirmation_pending
- assert user2.confirmation_pending
- refute admin.confirmation_pending
- refute mod.confirmation_pending
+ refute user1.is_confirmed
+ refute user2.is_confirmed
+ assert admin.is_confirmed
+ assert mod.is_confirmed
end
end
end
diff --git a/test/pleroma/activity/ir/topics_test.exs b/test/pleroma/activity/ir/topics_test.exs
index b464822d9..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-2020 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
@@ -11,6 +11,31 @@ defmodule Pleroma.Activity.Ir.TopicsTest do
require Pleroma.Constants
+ import Mock
+
+ describe "chat message" do
+ test "Create produces no topics" do
+ activity = %Activity{
+ object: %Object{data: %{"type" => "ChatMessage"}},
+ data: %{"type" => "Create"}
+ }
+
+ assert [] == Topics.get_activity_topics(activity)
+ end
+
+ test "Delete produces user and user:pleroma_chat" do
+ activity = %Activity{
+ object: %Object{data: %{"type" => "ChatMessage"}},
+ data: %{"type" => "Delete"}
+ }
+
+ topics = Topics.get_activity_topics(activity)
+ assert [_, _] = topics
+ assert "user" in topics
+ assert "user:pleroma_chat" in topics
+ end
+ end
+
describe "poll answer" do
test "produce no topics" do
activity = %Activity{object: %Object{data: %{"type" => "Answer"}}}
@@ -33,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}
@@ -77,14 +102,13 @@ defmodule Pleroma.Activity.Ir.TopicsTest do
refute Enum.member?(topics, "public:local:media")
end
- test "converts tags to hash tags", %{activity: %{object: %{data: data} = object} = activity} do
- tagged_data = Map.put(data, "tag", ["foo", "bar"])
- activity = %{activity | object: %{object | data: tagged_data}}
-
- topics = Topics.get_activity_topics(activity)
+ test "converts tags to hash tags", %{activity: activity} do
+ with_mock(Object, [:passthrough], hashtags: fn _ -> ["foo", "bar"] end) do
+ topics = Topics.get_activity_topics(activity)
- assert Enum.member?(topics, "hashtag:foo")
- assert Enum.member?(topics, "hashtag:bar")
+ assert Enum.member?(topics, "hashtag:foo")
+ assert Enum.member?(topics, "hashtag:bar")
+ end
end
test "only converts strings to hash tags", %{
@@ -113,6 +137,55 @@ 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{
+ object: %Object{data: %{"attachment" => []}},
+ data: %{"type" => "Create", "to" => [Pleroma.Web.ActivityPub.Utils.as_local_public()]}
+ }
+
+ {:ok, activity: activity}
+ end
+
+ test "doesn't produce public topics", %{activity: activity} do
+ topics = Topics.get_activity_topics(activity)
+
+ refute Enum.member?(topics, "public")
+ end
+
+ test "produces public:local topics", %{activity: activity} do
+ topics = Topics.get_activity_topics(activity)
+
+ assert Enum.member?(topics, "public:local")
+ end
+
+ test "with no attachments doesn't produce public:media topics", %{activity: activity} do
+ topics = Topics.get_activity_topics(activity)
+
+ refute Enum.member?(topics, "public:media")
+ refute Enum.member?(topics, "public:local:media")
+ end
+ end
+
describe "public visibility create events with attachments" do
setup do
activity = %Activity{
@@ -151,9 +224,36 @@ defmodule Pleroma.Activity.Ir.TopicsTest do
end
end
+ describe "local-public visibility create events with attachments" do
+ setup do
+ activity = %Activity{
+ object: %Object{data: %{"attachment" => ["foo"]}},
+ data: %{"type" => "Create", "to" => [Pleroma.Web.ActivityPub.Utils.as_local_public()]}
+ }
+
+ {:ok, activity: activity}
+ end
+
+ test "do not produce public:media topics", %{activity: activity} do
+ topics = Topics.get_activity_topics(activity)
+
+ refute Enum.member?(topics, "public:media")
+ end
+
+ test "produces public:local:media topics", %{activity: activity} do
+ topics = Topics.get_activity_topics(activity)
+
+ assert Enum.member?(topics, "public:local:media")
+ end
+ end
+
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 49b7aa292..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-2020 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 105f9f766..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-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ActivityTest do
@@ -25,7 +25,7 @@ defmodule Pleroma.ActivityTest do
test "returns activities by it's objects AP ids" do
activity = insert(:note_activity)
- object_data = Object.normalize(activity).data
+ object_data = Object.normalize(activity, fetch: false).data
[found_activity] = Activity.get_all_create_by_object_ap_id(object_data["id"])
@@ -34,7 +34,7 @@ defmodule Pleroma.ActivityTest do
test "returns the activity that created an object" do
activity = insert(:note_activity)
- object_data = Object.normalize(activity).data
+ object_data = Object.normalize(activity, fetch: false).data
found_activity = Activity.get_create_by_object_ap_id(object_data["id"])
@@ -123,7 +123,8 @@ defmodule Pleroma.ActivityTest do
"type" => "Note",
"content" => "find me!",
"id" => "http://mastodon.example.org/users/admin/objects/1",
- "attributedTo" => "http://mastodon.example.org/users/admin"
+ "attributedTo" => "http://mastodon.example.org/users/admin",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"]
},
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
}
@@ -132,6 +133,7 @@ defmodule Pleroma.ActivityTest do
{:ok, japanese_activity} = Pleroma.Web.CommonAPI.post(user, %{status: "更新情報"})
{:ok, job} = Pleroma.Web.Federator.incoming_ap_doc(params)
{:ok, remote_activity} = ObanHelpers.perform(job)
+ remote_activity = Activity.get_by_id_with_object(remote_activity.id)
%{
japanese_activity: japanese_activity,
@@ -143,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
@@ -168,7 +171,7 @@ defmodule Pleroma.ActivityTest do
test "find only local statuses for unauthenticated users when `limit_to_local_content` is `:all`",
%{local_activity: local_activity} do
- Pleroma.Config.put([:instance, :limit_to_local_content], :all)
+ clear_config([:instance, :limit_to_local_content], :all)
assert [^local_activity] = Activity.search(nil, "find me")
end
@@ -177,7 +180,7 @@ defmodule Pleroma.ActivityTest do
local_activity: local_activity,
remote_activity: remote_activity
} do
- Pleroma.Config.put([:instance, :limit_to_local_content], false)
+ clear_config([:instance, :limit_to_local_content], false)
activities = Enum.sort_by(Activity.search(nil, "find me"), & &1.id)
@@ -254,4 +257,100 @@ defmodule Pleroma.ActivityTest do
assert %{id: ^id} = Activity.get_by_object_ap_id_with_object(obj_id)
end
+
+ test "add_by_params_query/3" do
+ user = insert(:user)
+
+ note = insert(:note_activity, user: user)
+
+ insert(:add_activity, user: user, note: note)
+ insert(:add_activity, user: user, note: note)
+ insert(:add_activity, user: user)
+
+ assert Repo.aggregate(Activity, :count, :id) == 4
+
+ add_query =
+ Activity.add_by_params_query(note.data["object"], user.ap_id, user.featured_address)
+
+ assert Repo.aggregate(add_query, :count, :id) == 2
+
+ Repo.delete_all(add_query)
+ assert Repo.aggregate(add_query, :count, :id) == 0
+
+ assert Repo.aggregate(Activity, :count, :id) == 2
+ end
+
+ 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 e3cca5487..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-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ApplicationRequirementsTest do
@@ -9,7 +9,6 @@ defmodule Pleroma.ApplicationRequirementsTest do
import Mock
alias Pleroma.ApplicationRequirements
- alias Pleroma.Config
alias Pleroma.Repo
describe "check_repo_pool_size!/1" do
@@ -36,13 +35,13 @@ defmodule Pleroma.ApplicationRequirementsTest do
setup do: clear_config([:welcome])
setup do: clear_config([Pleroma.Emails.Mailer])
- test "raises if welcome email enabled but mail disabled" do
- Pleroma.Config.put([:welcome, :email, :enabled], true)
- Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
+ test "warns if welcome email enabled but mail disabled" do
+ clear_config([:welcome, :email, :enabled], true)
+ clear_config([Pleroma.Emails.Mailer, :enabled], false)
- assert_raise Pleroma.ApplicationRequirements.VerifyError, "The mail disabled.", fn ->
- capture_log(&Pleroma.ApplicationRequirements.verify!/0)
- end
+ assert capture_log(fn ->
+ assert Pleroma.ApplicationRequirements.verify!() == :ok
+ end) =~ "Welcome emails will NOT be sent"
end
end
@@ -58,26 +57,24 @@ defmodule Pleroma.ApplicationRequirementsTest do
setup do: clear_config([:instance, :account_activation_required])
- test "raises if account confirmation is required but mailer isn't enable" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
- Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
+ test "warns if account confirmation is required but mailer isn't enabled" do
+ clear_config([:instance, :account_activation_required], true)
+ clear_config([Pleroma.Emails.Mailer, :enabled], false)
- assert_raise Pleroma.ApplicationRequirements.VerifyError,
- "Account activation enabled, but Mailer is disabled. Cannot send confirmation emails.",
- fn ->
- capture_log(&Pleroma.ApplicationRequirements.verify!/0)
- end
+ assert capture_log(fn ->
+ assert Pleroma.ApplicationRequirements.verify!() == :ok
+ end) =~ "Users will NOT be able to confirm their accounts"
end
test "doesn't do anything if account confirmation is disabled" do
- Pleroma.Config.put([:instance, :account_activation_required], false)
- Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
+ clear_config([:instance, :account_activation_required], false)
+ clear_config([Pleroma.Emails.Mailer, :enabled], false)
assert Pleroma.ApplicationRequirements.verify!() == :ok
end
test "doesn't do anything if account confirmation is required and mailer is enabled" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
- Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], true)
+ clear_config([:instance, :account_activation_required], true)
+ clear_config([Pleroma.Emails.Mailer, :enabled], true)
assert Pleroma.ApplicationRequirements.verify!() == :ok
end
end
@@ -93,7 +90,7 @@ defmodule Pleroma.ApplicationRequirementsTest do
setup do: clear_config([:database, :rum_enabled])
test "raises if rum is enabled and detects unapplied rum migrations" do
- Config.put([:database, :rum_enabled], true)
+ clear_config([:database, :rum_enabled], true)
with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
assert_raise ApplicationRequirements.VerifyError,
@@ -105,7 +102,7 @@ defmodule Pleroma.ApplicationRequirementsTest do
end
test "raises if rum is disabled and detects rum migrations" do
- Config.put([:database, :rum_enabled], false)
+ clear_config([:database, :rum_enabled], false)
with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
assert_raise ApplicationRequirements.VerifyError,
@@ -117,7 +114,7 @@ defmodule Pleroma.ApplicationRequirementsTest do
end
test "doesn't do anything if rum enabled and applied migrations" do
- Config.put([:database, :rum_enabled], true)
+ clear_config([:database, :rum_enabled], true)
with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
assert ApplicationRequirements.verify!() == :ok
@@ -125,7 +122,7 @@ defmodule Pleroma.ApplicationRequirementsTest do
end
test "doesn't do anything if rum disabled" do
- Config.put([:database, :rum_enabled], false)
+ clear_config([:database, :rum_enabled], false)
with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
assert ApplicationRequirements.verify!() == :ok
@@ -161,7 +158,7 @@ defmodule Pleroma.ApplicationRequirementsTest do
end
test "doesn't do anything if disabled" do
- Config.put([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true)
+ clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true)
assert :ok == ApplicationRequirements.verify!()
end
diff --git a/test/pleroma/bbs/handler_test.exs b/test/pleroma/bbs/handler_test.exs
index bba8fab0f..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-2020 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
@@ -54,7 +54,7 @@ defmodule Pleroma.BBS.HandlerTest do
)
assert activity.actor == user.ap_id
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert object.data["content"] == "this is a test post"
end
@@ -63,7 +63,7 @@ defmodule Pleroma.BBS.HandlerTest do
another_user = insert(:user)
{:ok, activity} = CommonAPI.post(another_user, %{status: "this is a test post"})
- activity_object = Object.normalize(activity)
+ activity_object = Object.normalize(activity, fetch: false)
output =
capture_io(fn ->
@@ -82,7 +82,7 @@ defmodule Pleroma.BBS.HandlerTest do
assert reply.actor == user.ap_id
- reply_object_data = Object.normalize(reply).data
+ reply_object_data = Object.normalize(reply, fetch: false).data
assert reply_object_data["content"] == "this is a reply"
assert reply_object_data["inReplyTo"] == activity_object.data["id"]
end
diff --git a/test/pleroma/bookmark_test.exs b/test/pleroma/bookmark_test.exs
index ef090d785..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-2020 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 bde3c72f7..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-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.CaptchaTest do
@@ -69,7 +69,7 @@ defmodule Pleroma.CaptchaTest do
describe "Captcha Wrapper" do
test "validate" do
- Pleroma.Config.put([Pleroma.Captcha, :enabled], true)
+ clear_config([Pleroma.Captcha, :enabled], true)
new = Captcha.new()
@@ -83,7 +83,7 @@ defmodule Pleroma.CaptchaTest do
end
test "doesn't validate invalid answer" do
- Pleroma.Config.put([Pleroma.Captcha, :enabled], true)
+ clear_config([Pleroma.Captcha, :enabled], true)
new = Captcha.new()
@@ -99,7 +99,7 @@ defmodule Pleroma.CaptchaTest do
end
test "nil answer_data" do
- Pleroma.Config.put([Pleroma.Captcha, :enabled], true)
+ clear_config([Pleroma.Captcha, :enabled], true)
new = Captcha.new()
diff --git a/test/pleroma/chat/message_reference_test.exs b/test/pleroma/chat/message_reference_test.exs
index aaa7c1ad4..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-2020 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 1dd04916c..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-2020 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 f52629f8a..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-2020 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)
@@ -87,13 +320,22 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
end
test "check_activity_expiration_config/0" do
- clear_config(Pleroma.ActivityExpiration, enabled: true)
+ clear_config([Pleroma.ActivityExpiration], enabled: true)
assert capture_log(fn ->
DeprecationWarnings.check_activity_expiration_config()
end) =~ "Your config is using old namespace for activity expiration configuration."
end
+ test "check_uploders_s3_public_endpoint/0" do
+ clear_config([Pleroma.Uploaders.S3], public_endpoint: "https://fake.amazonaws.com/bucket/")
+
+ assert capture_log(fn ->
+ DeprecationWarnings.check_uploders_s3_public_endpoint()
+ end) =~
+ "Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket."
+ end
+
describe "check_gun_pool_options/0" do
test "await_up_timeout" do
config = Config.get(:connections_pool)
@@ -137,4 +379,14 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
"Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings"
end
end
+
+ test "check_old_chat_shoutbox/0" do
+ clear_config([:instance, :chat_limit], 1_000)
+ clear_config([:chat, :enabled], true)
+
+ assert capture_log(fn ->
+ DeprecationWarnings.check_old_chat_shoutbox()
+ end) =~
+ "Your config is using the old namespace for the Shoutbox configuration."
+ end
end
diff --git a/test/pleroma/config/holder_test.exs b/test/pleroma/config/holder_test.exs
index abcaa27dd..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-2020 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 607572f4e..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-2020 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
new file mode 100644
index 000000000..4e0d4c838
--- /dev/null
+++ b/test/pleroma/config/release_runtime_provider_test.exs
@@ -0,0 +1,49 @@
+# 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
+
+ alias Pleroma.Config.ReleaseRuntimeProvider
+
+ describe "load/2" do
+ test "loads release defaults config and warns about non-existent runtime config" do
+ ExUnit.CaptureIO.capture_io(fn ->
+ merged = ReleaseRuntimeProvider.load([], [])
+ assert merged == Pleroma.Config.Holder.release_defaults()
+ end) =~
+ "!!! Config path is not declared! Please ensure it exists and that PLEROMA_CONFIG_PATH is unset or points to an existing file"
+ end
+
+ test "merged runtime config" do
+ merged =
+ ReleaseRuntimeProvider.load([], config_path: "test/fixtures/config/temp.secret.exs")
+
+ assert merged[:pleroma][:first_setting] == [key: "value", key2: [Pleroma.Repo]]
+ assert merged[:pleroma][:second_setting] == [key: "value2", key2: ["Activity"]]
+ end
+
+ test "merged exported config" do
+ ExUnit.CaptureIO.capture_io(fn ->
+ merged =
+ ReleaseRuntimeProvider.load([],
+ exported_config_path: "test/fixtures/config/temp.exported_from_db.secret.exs"
+ )
+
+ assert merged[:pleroma][:exported_config_merged]
+ end) =~
+ "!!! Config path is not declared! Please ensure it exists and that PLEROMA_CONFIG_PATH is unset or points to an existing file"
+ end
+
+ test "runtime config is merged with exported config" do
+ merged =
+ ReleaseRuntimeProvider.load([],
+ config_path: "test/fixtures/config/temp.secret.exs",
+ exported_config_path: "test/fixtures/config/temp.exported_from_db.secret.exs"
+ )
+
+ assert merged[:pleroma][:first_setting] == [key2: [Pleroma.Repo], key: "new value"]
+ end
+ end
+end
diff --git a/test/pleroma/config/transfer_task_test.exs b/test/pleroma/config/transfer_task_test.exs
index f53829e09..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-2020 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,32 +90,70 @@ 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
test "on reboot time key" do
- clear_config(:chat)
- insert(:config, key: :chat, value: [enabled: false])
- assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
+ clear_config(:shout)
+ insert(:config, key: :shout, value: [enabled: false])
+
+ # 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
- clear_config(:chat)
+ clear_config(:shout)
clear_config(Pleroma.Captcha)
- insert(:config, key: :chat, value: [enabled: false])
+ insert(:config, key: :shout, value: [enabled: false])
insert(:config, key: Pleroma.Captcha, value: [seconds_valid: 60])
refute String.contains?(
- 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 3895e2cda..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-2020 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 f524d90dd..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-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ConfigTest do
@@ -30,9 +30,9 @@ defmodule Pleroma.ConfigTest do
describe "nil values" do
setup do
- Pleroma.Config.put(:lorem, nil)
- Pleroma.Config.put(:ipsum, %{dolor: [sit: nil]})
- Pleroma.Config.put(:dolor, sit: %{amet: nil})
+ clear_config(:lorem, nil)
+ clear_config(:ipsum, %{dolor: [sit: nil]})
+ clear_config(:dolor, sit: %{amet: nil})
on_exit(fn -> Enum.each(~w(lorem ipsum dolor)a, &Pleroma.Config.delete/1) end)
end
@@ -57,9 +57,9 @@ defmodule Pleroma.ConfigTest do
end
test "get/1 when value is false" do
- Pleroma.Config.put([:instance, :false_test], false)
- Pleroma.Config.put([:instance, :nested], [])
- Pleroma.Config.put([:instance, :nested, :false_test], false)
+ clear_config([:instance, :false_test], false)
+ clear_config([:instance, :nested], [])
+ clear_config([:instance, :nested, :false_test], false)
assert Pleroma.Config.get([:instance, :false_test]) == false
assert Pleroma.Config.get([:instance, :nested, :false_test]) == false
@@ -81,40 +81,40 @@ defmodule Pleroma.ConfigTest do
end
test "get!/1 when value is false" do
- Pleroma.Config.put([:instance, :false_test], false)
- Pleroma.Config.put([:instance, :nested], [])
- Pleroma.Config.put([:instance, :nested, :false_test], false)
+ clear_config([:instance, :false_test], false)
+ clear_config([:instance, :nested], [])
+ clear_config([:instance, :nested, :false_test], false)
assert Pleroma.Config.get!([:instance, :false_test]) == false
assert Pleroma.Config.get!([:instance, :nested, :false_test]) == false
end
test "put/2 with a key" do
- Pleroma.Config.put(:config_test, true)
+ clear_config(:config_test, true)
assert Pleroma.Config.get(:config_test) == true
end
test "put/2 with a list of keys" do
- Pleroma.Config.put([:instance, :config_test], true)
- Pleroma.Config.put([:instance, :config_nested_test], [])
- Pleroma.Config.put([:instance, :config_nested_test, :x], true)
+ clear_config([:instance, :config_test], true)
+ clear_config([:instance, :config_nested_test], [])
+ clear_config([:instance, :config_nested_test, :x], true)
assert Pleroma.Config.get([:instance, :config_test]) == true
assert Pleroma.Config.get([:instance, :config_nested_test, :x]) == true
end
test "delete/1 with a key" do
- Pleroma.Config.put([:delete_me], :delete_me)
+ clear_config([:delete_me], :delete_me)
Pleroma.Config.delete([:delete_me])
assert Pleroma.Config.get([:delete_me]) == nil
end
test "delete/2 with a list of keys" do
- Pleroma.Config.put([:delete_me], hello: "world", world: "Hello")
+ clear_config([:delete_me], hello: "world", world: "Hello")
Pleroma.Config.delete([:delete_me, :world])
assert Pleroma.Config.get([:delete_me]) == [hello: "world"]
- Pleroma.Config.put([:delete_me, :delete_me], hello: "world", world: "Hello")
+ clear_config([:delete_me, :delete_me], hello: "world", world: "Hello")
Pleroma.Config.delete([:delete_me, :delete_me, :world])
assert Pleroma.Config.get([:delete_me, :delete_me]) == [hello: "world"]
@@ -123,8 +123,8 @@ defmodule Pleroma.ConfigTest do
end
test "fetch/1" do
- Pleroma.Config.put([:lorem], :ipsum)
- Pleroma.Config.put([:ipsum], dolor: :sit)
+ clear_config([:lorem], :ipsum)
+ clear_config([:ipsum], dolor: :sit)
assert Pleroma.Config.fetch([:lorem]) == {:ok, :ipsum}
assert Pleroma.Config.fetch(:lorem) == {:ok, :ipsum}
diff --git a/test/pleroma/conversation/participation_test.exs b/test/pleroma/conversation/participation_test.exs
index 122b10486..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-2020 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
@@ -175,8 +175,8 @@ defmodule Pleroma.Conversation.ParticipationTest do
assert [participation_one, participation_two] = Participation.for_user(user)
- object2 = Pleroma.Object.normalize(activity_two)
- object3 = Pleroma.Object.normalize(activity_three)
+ object2 = Pleroma.Object.normalize(activity_two, fetch: false)
+ object3 = Pleroma.Object.normalize(activity_three, fetch: false)
user = Repo.get(Pleroma.User, user.id)
@@ -359,4 +359,16 @@ defmodule Pleroma.Conversation.ParticipationTest do
assert Participation.unread_count(blocked) == 1
end
end
+
+ test "deletes a conversation" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{status: "Hey @#{other_user.nickname}.", visibility: "direct"})
+
+ assert [participation] = Participation.for_user(other_user)
+ assert {:ok, _} = Participation.delete(participation)
+ assert [] == Participation.for_user(other_user)
+ end
end
diff --git a/test/pleroma/conversation_test.exs b/test/pleroma/conversation_test.exs
index 359aa6840..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-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ConversationTest do
@@ -48,7 +48,7 @@ defmodule Pleroma.ConversationTest do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "Hey"})
- object = Pleroma.Object.normalize(activity)
+ object = Pleroma.Object.normalize(activity, fetch: false)
context = object.data["context"]
conversation = Conversation.get_for_ap_id(context)
@@ -64,7 +64,7 @@ defmodule Pleroma.ConversationTest do
{:ok, activity} =
CommonAPI.post(har, %{status: "Hey @#{jafnhar.nickname}", visibility: "direct"})
- object = Pleroma.Object.normalize(activity)
+ object = Pleroma.Object.normalize(activity, fetch: false)
context = object.data["context"]
conversation =
@@ -86,7 +86,7 @@ defmodule Pleroma.ConversationTest do
in_reply_to_status_id: activity.id
})
- object = Pleroma.Object.normalize(activity)
+ object = Pleroma.Object.normalize(activity, fetch: false)
context = object.data["context"]
conversation_two =
@@ -110,7 +110,7 @@ defmodule Pleroma.ConversationTest do
in_reply_to_status_id: activity.id
})
- object = Pleroma.Object.normalize(activity)
+ object = Pleroma.Object.normalize(activity, fetch: false)
context = object.data["context"]
conversation_three =
diff --git a/test/pleroma/docs/generator_test.exs b/test/pleroma/docs/generator_test.exs
index 43877244d..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-2020 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
@@ -23,7 +23,7 @@ defmodule Pleroma.Docs.GeneratorTest do
key: :filters,
type: {:list, :module},
description: "",
- suggestions: {:list_behaviour_implementations, Pleroma.Web.ActivityPub.MRF}
+ suggestions: {:list_behaviour_implementations, Pleroma.Web.ActivityPub.MRF.Policy}
},
%{
key: Pleroma.Upload,
@@ -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/earmark_renderer_test.exs b/test/pleroma/earmark_renderer_test.exs
deleted file mode 100644
index 73aaec7f4..000000000
--- a/test/pleroma/earmark_renderer_test.exs
+++ /dev/null
@@ -1,79 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.EarmarkRendererTest do
- use Pleroma.DataCase, async: true
-
- test "Paragraph" do
- code = ~s[Hello\n\nWorld!]
- result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
- assert result == "<p>Hello</p><p>World!</p>"
- end
-
- test "raw HTML" do
- code = ~s[<a href="http://example.org/">OwO</a><!-- what's this?-->]
- result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
- assert result == "<p>#{code}</p>"
- end
-
- test "rulers" do
- code = ~s[before\n\n-----\n\nafter]
- result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
- assert result == "<p>before</p><hr /><p>after</p>"
- end
-
- test "headings" do
- code = ~s[# h1\n## h2\n### h3\n]
- result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
- assert result == ~s[<h1>h1</h1><h2>h2</h2><h3>h3</h3>]
- end
-
- test "blockquote" do
- code = ~s[> whoms't are you quoting?]
- result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
- assert result == "<blockquote><p>whoms’t are you quoting?</p></blockquote>"
- end
-
- test "code" do
- code = ~s[`mix`]
- result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
- assert result == ~s[<p><code class="inline">mix</code></p>]
-
- code = ~s[``mix``]
- result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
- assert result == ~s[<p><code class="inline">mix</code></p>]
-
- code = ~s[```\nputs "Hello World"\n```]
- result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
- assert result == ~s[<pre><code class="">puts &quot;Hello World&quot;</code></pre>]
- end
-
- test "lists" do
- code = ~s[- one\n- two\n- three\n- four]
- result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
- assert result == "<ul><li>one</li><li>two</li><li>three</li><li>four</li></ul>"
-
- code = ~s[1. one\n2. two\n3. three\n4. four\n]
- result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
- assert result == "<ol><li>one</li><li>two</li><li>three</li><li>four</li></ol>"
- end
-
- test "delegated renderers" do
- code = ~s[a<br/>b]
- result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
- assert result == "<p>#{code}</p>"
-
- code = ~s[*aaaa~*]
- result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
- assert result == ~s[<p><em>aaaa~</em></p>]
-
- code = ~s[**aaaa~**]
- result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
- assert result == ~s[<p><strong>aaaa~</strong></p>]
-
- # strikethrought
- code = ~s[<del>aaaa~</del>]
- result = Earmark.as_html!(code, %Earmark.Options{renderer: Pleroma.EarmarkRenderer})
- assert result == ~s[<p><del>aaaa~</del></p>]
- end
-end
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 a8471e2e3..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-2020 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 3b6006854..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-2020 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 b7eb59ab0..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,15 +1,15 @@
# 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.EctoType.ActivityPub.ObjectValidators.RecipientsTest do
alias Pleroma.EctoType.ActivityPub.ObjectValidators.Recipients
use Pleroma.DataCase, async: true
- test "it asserts that all elements of the list are object ids" do
+ test "it only keeps elements that are valid object ids" do
list = ["https://lain.com/users/lain", "invalid"]
- assert :error == Recipients.cast(list)
+ assert {:ok, ["https://lain.com/users/lain"]} == Recipients.cast(list)
end
test "it works with a list" do
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 154363f68..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-2020 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 9aaf7b04f..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-2020 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 9e232d2a0..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-2020 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 bd21d8dec..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-2020 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 096d23ca6..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-2020 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 804039e7e..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-2020 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 158dfee06..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-2020 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 c99c9ef4c..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-2020 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 da9515902..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-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.FilterTest do
@@ -7,81 +7,120 @@ defmodule Pleroma.FilterTest do
import Pleroma.Factory
+ alias Oban.Job
alias Pleroma.Filter
- alias Pleroma.Repo
+
+ setup do
+ [user: insert(:user)]
+ end
describe "creating filters" do
- test "creating one filter" do
- user = insert(:user)
+ test "creation validation error", %{user: user} do
+ attrs = %{
+ user_id: user.id,
+ expires_in: 60
+ }
+
+ {:error, _} = Filter.create(attrs)
+
+ assert Repo.all(Job) == []
+ end
- query = %Filter{
+ test "use passed expires_at instead expires_in", %{user: user} do
+ now = NaiveDateTime.utc_now()
+
+ attrs = %{
user_id: user.id,
- filter_id: 42,
+ expires_at: now,
phrase: "knights",
- context: ["home"]
+ context: ["home"],
+ expires_in: 600
}
- {:ok, %Filter{} = filter} = Filter.create(query)
+ {:ok, %Filter{} = filter} = Filter.create(attrs)
+
result = Filter.get(filter.filter_id, user)
- assert query.phrase == result.phrase
- end
+ assert result.expires_at == NaiveDateTime.truncate(now, :second)
- test "creating one filter without a pre-defined filter_id" do
- user = insert(:user)
+ [job] = Repo.all(Job)
- query = %Filter{
+ assert DateTime.truncate(job.scheduled_at, :second) ==
+ now |> NaiveDateTime.truncate(:second) |> DateTime.from_naive!("Etc/UTC")
+ end
+
+ test "creating one filter", %{user: user} do
+ attrs = %{
user_id: user.id,
+ filter_id: 42,
phrase: "knights",
context: ["home"]
}
- {:ok, %Filter{} = filter} = Filter.create(query)
- # Should start at 1
- assert filter.filter_id == 1
+ {:ok, %Filter{} = filter} = Filter.create(attrs)
+ result = Filter.get(filter.filter_id, user)
+ assert attrs.phrase == result.phrase
end
- test "creating additional filters uses previous highest filter_id + 1" do
- user = insert(:user)
-
- query_one = %Filter{
+ test "creating with expired_at", %{user: user} do
+ attrs = %{
user_id: user.id,
filter_id: 42,
phrase: "knights",
+ context: ["home"],
+ expires_in: 60
+ }
+
+ {:ok, %Filter{} = filter} = Filter.create(attrs)
+ result = Filter.get(filter.filter_id, user)
+ assert attrs.phrase == result.phrase
+
+ assert [_] = Repo.all(Job)
+ end
+
+ test "creating one filter without a pre-defined filter_id", %{user: user} do
+ attrs = %{
+ user_id: user.id,
+ phrase: "knights",
context: ["home"]
}
- {:ok, %Filter{} = filter_one} = Filter.create(query_one)
+ {:ok, %Filter{} = filter} = Filter.create(attrs)
+ # Should start at 1
+ assert filter.filter_id == 1
+ end
+
+ test "creating additional filters uses previous highest filter_id + 1", %{user: user} do
+ filter1 = insert(:filter, user: user)
- query_two = %Filter{
+ attrs = %{
user_id: user.id,
# No filter_id
phrase: "who",
context: ["home"]
}
- {:ok, %Filter{} = filter_two} = Filter.create(query_two)
- assert filter_two.filter_id == filter_one.filter_id + 1
+ {:ok, %Filter{} = filter2} = Filter.create(attrs)
+ assert filter2.filter_id == filter1.filter_id + 1
end
- test "filter_id is unique per user" do
- user_one = insert(:user)
+ test "filter_id is unique per user", %{user: user_one} do
user_two = insert(:user)
- query_one = %Filter{
+ attrs1 = %{
user_id: user_one.id,
phrase: "knights",
context: ["home"]
}
- {:ok, %Filter{} = filter_one} = Filter.create(query_one)
+ {:ok, %Filter{} = filter_one} = Filter.create(attrs1)
- query_two = %Filter{
+ attrs2 = %{
user_id: user_two.id,
phrase: "who",
context: ["home"]
}
- {:ok, %Filter{} = filter_two} = Filter.create(query_two)
+ {:ok, %Filter{} = filter_two} = Filter.create(attrs2)
assert filter_one.filter_id == 1
assert filter_two.filter_id == 1
@@ -94,65 +133,61 @@ defmodule Pleroma.FilterTest do
end
end
- test "deleting a filter" do
- user = insert(:user)
+ test "deleting a filter", %{user: user} do
+ filter = insert(:filter, user: user)
- query = %Filter{
- user_id: user.id,
- filter_id: 0,
- phrase: "knights",
- context: ["home"]
- }
-
- {:ok, _filter} = Filter.create(query)
- {:ok, filter} = Filter.delete(query)
- assert is_nil(Repo.get(Filter, filter.filter_id))
+ assert Repo.get(Filter, filter.id)
+ {:ok, filter} = Filter.delete(filter)
+ refute Repo.get(Filter, filter.id)
end
- test "getting all filters by an user" do
- user = insert(:user)
-
- query_one = %Filter{
+ test "deleting a filter with expires_at is removing Oban job too", %{user: user} do
+ attrs = %{
user_id: user.id,
- filter_id: 1,
- phrase: "knights",
- context: ["home"]
+ phrase: "cofe",
+ context: ["home"],
+ expires_in: 600
}
- query_two = %Filter{
- user_id: user.id,
- filter_id: 2,
- phrase: "who",
- context: ["home"]
- }
+ {:ok, filter} = Filter.create(attrs)
+ assert %Job{id: job_id} = Pleroma.Workers.PurgeExpiredFilter.get_expiration(filter.id)
+ {:ok, _} = Filter.delete(filter)
- {:ok, filter_one} = Filter.create(query_one)
- {:ok, filter_two} = Filter.create(query_two)
- filters = Filter.get_filters(user)
- assert filter_one in filters
- assert filter_two in filters
+ assert Repo.get(Job, job_id) == nil
end
- test "updating a filter" do
- user = insert(:user)
+ test "getting all filters by an user", %{user: user} do
+ filter1 = insert(:filter, user: user)
+ filter2 = insert(:filter, user: user)
- query_one = %Filter{
- user_id: user.id,
- filter_id: 1,
- phrase: "knights",
- context: ["home"]
- }
+ filter_ids = user |> Filter.get_filters() |> collect_ids()
+
+ assert filter1.id in filter_ids
+ assert filter2.id in filter_ids
+ end
+
+ test "updating a filter", %{user: user} do
+ filter = insert(:filter, user: user)
changes = %{
phrase: "who",
context: ["home", "timeline"]
}
- {:ok, filter_one} = Filter.create(query_one)
- {:ok, filter_two} = Filter.update(filter_one, changes)
+ {:ok, updated_filter} = Filter.update(filter, changes)
+
+ assert filter != updated_filter
+ assert updated_filter.phrase == changes.phrase
+ assert updated_filter.context == changes.context
+ end
+
+ test "updating with error", %{user: user} do
+ filter = insert(:filter, user: user)
+
+ changes = %{
+ phrase: nil
+ }
- assert filter_one != filter_two
- assert filter_two.phrase == changes.phrase
- assert filter_two.context == changes.context
+ {:error, _} = Filter.update(filter, changes)
end
end
diff --git a/test/pleroma/following_relationship_test.exs b/test/pleroma/following_relationship_test.exs
index f0d2c3846..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-2020 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 5781a3f01..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-2020 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 223625857..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-2020 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 aea908fac..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-2020 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
@@ -7,7 +7,6 @@ defmodule Pleroma.Gun.ConnectionPoolTest do
import Mox
import ExUnit.CaptureLog
- alias Pleroma.Config
alias Pleroma.Gun.ConnectionPool
defp gun_mock(_) do
@@ -19,7 +18,6 @@ defmodule Pleroma.Gun.ConnectionPoolTest do
:ok
end
- setup :set_mox_from_context
setup :gun_mock
test "gives the same connection to 2 concurrent requests" do
@@ -48,9 +46,10 @@ 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
- Config.put([:connections_pool, :max_connections], 1)
+ clear_config([:connections_pool, :max_connections], 1)
# The supervisor needs a reboot to apply the new config setting
Process.exit(Process.whereis(Pleroma.Gun.ConnectionPool.WorkerSupervisor), :kill)
diff --git a/test/pleroma/hashtag_test.exs b/test/pleroma/hashtag_test.exs
new file mode 100644
index 000000000..8531b1879
--- /dev/null
+++ b/test/pleroma/hashtag_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.HashtagTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Hashtag
+
+ describe "changeset validations" do
+ test "ensure non-blank :name" do
+ changeset = Hashtag.changeset(%Hashtag{}, %{name: ""})
+
+ assert {:name, {"can't be blank", [validation: :required]}} in changeset.errors
+ end
+ end
+end
diff --git a/test/pleroma/healthcheck_test.exs b/test/pleroma/healthcheck_test.exs
index a1bc25d25..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-2020 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 9737f2458..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-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.HTMLTest do
@@ -17,6 +17,7 @@ defmodule Pleroma.HTMLTest do
this is a link with allowed "rel" attribute: <a href="http://example.com/" rel="tag">example.com</a>
this is a link with not allowed "rel" attribute: <a href="http://example.com/" rel="tag noallowed">example.com</a>
this is an image: <img src="http://example.com/image.jpg"><br />
+ this is an inline emoji: <img class="emoji" src="http://example.com/image.jpg"><br />
<script>alert('hacked')</script>
"""
@@ -24,6 +25,10 @@ defmodule Pleroma.HTMLTest do
<img src="http://example.com/image.jpg" onerror="alert('hacked')">
"""
+ @html_stillimage_sample """
+ <img class="still-image" src="http://example.com/image.jpg">
+ """
+
@html_span_class_sample """
<span class="animate-spin">hi</span>
"""
@@ -45,6 +50,7 @@ defmodule Pleroma.HTMLTest do
this is a link with allowed &quot;rel&quot; attribute: example.com
this is a link with not allowed &quot;rel&quot; attribute: example.com
this is an image:
+ this is an inline emoji:
alert(&#39;hacked&#39;)
"""
@@ -67,6 +73,7 @@ defmodule Pleroma.HTMLTest do
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/>
+ this is an inline emoji: <img class="emoji" src="http://example.com/image.jpg"/><br/>
alert(&#39;hacked&#39;)
"""
@@ -90,6 +97,15 @@ defmodule Pleroma.HTMLTest do
HTML.filter_tags(@html_span_class_sample, Pleroma.HTML.Scrubber.TwitterText)
end
+ test "does not allow images with invalid classes" do
+ expected = """
+ <img src="http://example.com/image.jpg"/>
+ """
+
+ assert expected ==
+ HTML.filter_tags(@html_stillimage_sample, Pleroma.HTML.Scrubber.TwitterText)
+ end
+
test "does allow microformats" do
expected = """
<span class="h-card"><a class="u-url mention">@<span>foo</span></a></span>
@@ -121,6 +137,7 @@ defmodule Pleroma.HTMLTest do
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/>
+ this is an inline emoji: <img class="emoji" src="http://example.com/image.jpg"/><br/>
alert(&#39;hacked&#39;)
"""
@@ -143,6 +160,15 @@ defmodule Pleroma.HTMLTest do
assert expected == HTML.filter_tags(@html_span_class_sample, Pleroma.HTML.Scrubber.Default)
end
+ test "does not allow images with invalid classes" do
+ expected = """
+ <img src="http://example.com/image.jpg"/>
+ """
+
+ assert expected ==
+ HTML.filter_tags(@html_stillimage_sample, Pleroma.HTML.Scrubber.TwitterText)
+ end
+
test "does allow microformats" do
expected = """
<span class="h-card"><a class="u-url mention">@<span>foo</span></a></span>
@@ -175,7 +201,7 @@ defmodule Pleroma.HTMLTest do
"I think I just found the best github repo https://github.com/komeiji-satori/Dress"
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
{:ok, url} = HTML.extract_first_external_url_from_object(object)
assert url == "https://github.com/komeiji-satori/Dress"
end
@@ -190,7 +216,7 @@ defmodule Pleroma.HTMLTest do
"@#{other_user.nickname} install misskey! https://github.com/syuilo/misskey/blob/develop/docs/setup.en.md"
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
{:ok, url} = HTML.extract_first_external_url_from_object(object)
assert url == "https://github.com/syuilo/misskey/blob/develop/docs/setup.en.md"
@@ -206,7 +232,7 @@ defmodule Pleroma.HTMLTest do
status: "#cofe https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
{:ok, url} = HTML.extract_first_external_url_from_object(object)
assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
@@ -222,7 +248,7 @@ defmodule Pleroma.HTMLTest do
content_type: "text/html"
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
{:ok, url} = HTML.extract_first_external_url_from_object(object)
assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
@@ -233,7 +259,7 @@ defmodule Pleroma.HTMLTest do
{:ok, activity} = CommonAPI.post(user, %{status: "\"http://cofe.com/?boomer=ok&foo=bar\""})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert {:ok, nil} = HTML.extract_first_external_url_from_object(object)
end
@@ -247,7 +273,7 @@ defmodule Pleroma.HTMLTest do
"<a href=\"https://pleroma.gov/media/d24caa3a498e21e0298377a9ca0149a4f4f8b767178aacf837542282e2d94fb1.png?name=image.png\" class=\"attachment\">image.png</a>"
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert {:ok, nil} = HTML.extract_first_external_url_from_object(object)
end
diff --git a/test/pleroma/http/adapter_helper/gun_test.exs b/test/pleroma/http/adapter_helper/gun_test.exs
index 487d2e7c1..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-2020 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
@@ -8,7 +8,6 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do
import Mox
- alias Pleroma.Config
alias Pleroma.HTTP.AdapterHelper.Gun
setup :verify_on_exit!
@@ -52,9 +51,7 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do
end
test "parses string proxy host & port" do
- proxy = Config.get([:http, :proxy_url])
- Config.put([:http, :proxy_url], "localhost:8123")
- on_exit(fn -> Config.put([:http, :proxy_url], proxy) end)
+ clear_config([:http, :proxy_url], "localhost:8123")
uri = URI.parse("https://some-domain.com")
opts = Gun.options([receive_conn: false], uri)
@@ -62,9 +59,7 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do
end
test "parses tuple proxy scheme host and port" do
- proxy = Config.get([:http, :proxy_url])
- Config.put([:http, :proxy_url], {:socks, 'localhost', 1234})
- on_exit(fn -> Config.put([:http, :proxy_url], proxy) end)
+ clear_config([:http, :proxy_url], {:socks, 'localhost', 1234})
uri = URI.parse("https://some-domain.com")
opts = Gun.options([receive_conn: false], uri)
@@ -72,9 +67,7 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do
end
test "passed opts have more weight than defaults" do
- proxy = Config.get([:http, :proxy_url])
- Config.put([:http, :proxy_url], {:socks5, 'localhost', 1234})
- on_exit(fn -> Config.put([:http, :proxy_url], proxy) end)
+ clear_config([:http, :proxy_url], {:socks5, 'localhost', 1234})
uri = URI.parse("https://some-domain.com")
opts = Gun.options([receive_conn: false, proxy: {'example.com', 4321}], uri)
diff --git a/test/pleroma/http/adapter_helper/hackney_test.exs b/test/pleroma/http/adapter_helper/hackney_test.exs
index f2361ff0b..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-2020 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 24d501ad5..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-2020 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 d0b00ca26..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-2020 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 fab909905..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-2020 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
@@ -34,24 +34,32 @@ defmodule Pleroma.HTTP.RequestBuilderTest do
describe "add_param/4" do
test "add file parameter" do
- %Request{
- body: %Tesla.Multipart{
- boundary: _,
- content_type_params: [],
- parts: [
- %Tesla.Multipart.Part{
- body: %File.Stream{
- line_or_bytes: 2048,
- modes: [:raw, :read_ahead, :read, :binary],
- path: "some-path/filename.png",
- raw: true
- },
- dispositions: [name: "filename.png", filename: "filename.png"],
- headers: []
- }
- ]
- }
- } = RequestBuilder.add_param(%Request{}, :file, "filename.png", "some-path/filename.png")
+ assert match?(
+ %Request{
+ body: %Tesla.Multipart{
+ boundary: _,
+ content_type_params: [],
+ parts: [
+ %Tesla.Multipart.Part{
+ body: %File.Stream{
+ line_or_bytes: 2048,
+ modes: [:raw, :read_ahead, :binary],
+ path: "some-path/filename.png",
+ raw: true
+ },
+ dispositions: [name: "filename.png", filename: "filename.png"],
+ headers: []
+ }
+ ]
+ }
+ },
+ RequestBuilder.add_param(
+ %Request{},
+ :file,
+ "filename.png",
+ "some-path/filename.png"
+ )
+ )
end
test "add key to body" do
diff --git a/test/pleroma/http/tzdata_test.exs b/test/pleroma/http/tzdata_test.exs
index 3e605d33b..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-2020 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 d394bb942..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-2020 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 2c6389e4f..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-2020 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 5d0ce6237..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-2020 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 10d71fb88..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-2020 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 4a7dbda71..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-2020 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
@@ -33,16 +33,18 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
test "refuses invalid requests" do
capture_log(fn ->
- assert {:error, {404, _}} = start_socket()
- assert {:error, {404, _}} = start_socket("?stream=ncjdk")
+ assert {:error, %WebSockex.RequestError{code: 404}} = start_socket()
+ assert {:error, %WebSockex.RequestError{code: 404}} = start_socket("?stream=ncjdk")
Process.sleep(30)
end)
end
test "requires authentication and a valid token for protected streams" do
capture_log(fn ->
- assert {:error, {401, _}} = start_socket("?stream=user&access_token=aaaaaaaaaaaa")
- assert {:error, {401, _}} = start_socket("?stream=user")
+ assert {:error, %WebSockex.RequestError{code: 401}} =
+ start_socket("?stream=user&access_token=aaaaaaaaaaaa")
+
+ assert {:error, %WebSockex.RequestError{code: 401}} = start_socket("?stream=user")
Process.sleep(30)
end)
end
@@ -91,7 +93,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
{:ok, token} = OAuth.Token.exchange_token(app, auth)
- %{user: user, token: token}
+ %{app: app, user: user, token: token}
end
test "accepts valid tokens", state do
@@ -102,7 +104,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
assert {:ok, _} = start_socket("?stream=user&access_token=#{token.token}")
capture_log(fn ->
- assert {:error, {401, _}} = start_socket("?stream=user")
+ assert {:error, %WebSockex.RequestError{code: 401}} = start_socket("?stream=user")
Process.sleep(30)
end)
end
@@ -111,7 +113,9 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
assert {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}")
capture_log(fn ->
- assert {:error, {401, _}} = start_socket("?stream=user:notification")
+ assert {:error, %WebSockex.RequestError{code: 401}} =
+ start_socket("?stream=user:notification")
+
Process.sleep(30)
end)
end
@@ -120,11 +124,27 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
assert {:ok, _} = start_socket("?stream=user", [{"Sec-WebSocket-Protocol", token.token}])
capture_log(fn ->
- assert {:error, {401, _}} =
+ assert {:error, %WebSockex.RequestError{code: 401}} =
start_socket("?stream=user", [{"Sec-WebSocket-Protocol", "I am a friend"}])
Process.sleep(30)
end)
end
+
+ test "disconnect when token is revoked", %{app: app, user: user, token: token} do
+ assert {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}")
+ assert {:ok, _} = start_socket("?stream=user&access_token=#{token.token}")
+
+ {:ok, auth} = OAuth.Authorization.create_authorization(app, user)
+
+ {:ok, token2} = OAuth.Token.exchange_token(app, auth)
+ assert {:ok, _} = start_socket("?stream=user&access_token=#{token2.token}")
+
+ OAuth.Token.Strategy.Revoke.revoke(token)
+
+ assert_receive {:close, _}
+ assert_receive {:close, _}
+ refute_receive {:close, _}
+ end
end
end
diff --git a/test/pleroma/job_queue_monitor_test.exs b/test/pleroma/job_queue_monitor_test.exs
index 65c1e9f29..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-2020 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 55a7aa1bc..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-2020 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 854e276f1..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-2020 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 3055f1ce2..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-2020 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 c3eaf40b6..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-2020 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 8c09bf447..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-2020 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 cd1f7d0af..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-2018 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.MFATest do
@@ -30,8 +30,8 @@ defmodule Pleroma.MFATest do
{:ok, [code1, code2]} = MFA.generate_backup_codes(user)
updated_user = refresh_record(user)
[hash1, hash2] = updated_user.multi_factor_authentication_settings.backup_codes
- assert Pbkdf2.verify_pass(code1, hash1)
- assert Pbkdf2.verify_pass(code2, hash2)
+ assert Pleroma.Password.Pbkdf2.verify_pass(code1, hash1)
+ assert Pleroma.Password.Pbkdf2.verify_pass(code2, hash2)
end
end
diff --git a/test/pleroma/migration_helper/notification_backfill_test.exs b/test/pleroma/migration_helper/notification_backfill_test.exs
index 6fe8a11ac..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-2020 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 d1e0e1e6b..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-2020 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 a6558f995..a000c0efd 100644
--- a/test/pleroma/notification_test.exs
+++ b/test/pleroma/notification_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.NotificationTest do
@@ -45,6 +45,20 @@ defmodule Pleroma.NotificationTest do
assert notification.type == "pleroma:report"
end
+ test "suppresses notification to reporter if reporter is an admin" do
+ reporting_admin = insert(:user, is_admin: true)
+ reported_user = insert(:user)
+ other_admin = insert(:user, is_admin: true)
+
+ {:ok, activity} = CommonAPI.report(reporting_admin, %{account_id: reported_user.id})
+
+ {:ok, [notification]} = Notification.create_notifications(activity)
+
+ refute notification.user_id == reporting_admin.id
+ assert notification.user_id == other_admin.id
+ assert notification.type == "pleroma:report"
+ end
+
test "creates a notification for an emoji reaction" do
user = insert(:user)
other_user = insert(:user)
@@ -113,6 +127,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
@@ -493,6 +542,25 @@ defmodule Pleroma.NotificationTest do
end
end
+ describe "destroy_multiple_from_types/2" do
+ test "clears all notifications of a certain type for a given user" do
+ report_activity = insert(:report_activity)
+ user1 = insert(:user, is_moderator: true, is_admin: true)
+ user2 = insert(:user, is_moderator: true, is_admin: true)
+ {:ok, _} = Notification.create_notifications(report_activity)
+
+ {:ok, _} =
+ CommonAPI.post(user2, %{
+ status: "hey @#{user1.nickname} !"
+ })
+
+ Notification.destroy_multiple_from_types(user1, ["pleroma:report"])
+
+ assert [%Pleroma.Notification{type: "mention"}] = Notification.for_user(user1)
+ assert [%Pleroma.Notification{type: "pleroma:report"}] = Notification.for_user(user2)
+ end
+ end
+
describe "set_read_up_to()" do
test "it sets all notifications as read up to a specified notification ID" do
user = insert(:user)
@@ -610,6 +678,8 @@ defmodule Pleroma.NotificationTest do
"actor" => user.ap_id,
"object" => %{
"type" => "Note",
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
"content" => "message with a Mention tag, but no explicit tagging",
"tag" => [
%{
@@ -641,6 +711,9 @@ defmodule Pleroma.NotificationTest do
"actor" => user.ap_id,
"object" => %{
"type" => "Note",
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "cc" => [other_user.ap_id],
"content" => "hi everyone",
"attributedTo" => user.ap_id
}
@@ -788,6 +861,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
@@ -937,6 +1034,7 @@ defmodule Pleroma.NotificationTest do
"cc" => [],
"object" => %{
"type" => "Note",
+ "id" => remote_user.ap_id <> "/objects/test",
"content" => "Hello!",
"tag" => [
%{
@@ -976,7 +1074,6 @@ defmodule Pleroma.NotificationTest do
assert Enum.empty?(Notification.for_user(local_user))
end
- @tag capture_log: true
test "move activity generates a notification" 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])
@@ -986,18 +1083,6 @@ defmodule Pleroma.NotificationTest do
User.follow(follower, old_user)
User.follow(other_follower, old_user)
- old_user_url = old_user.ap_id
-
- body =
- File.read!("test/fixtures/users_mock/localhost.json")
- |> String.replace("{{nickname}}", old_user.nickname)
- |> Jason.encode!()
-
- Tesla.Mock.mock(fn
- %{method: :get, url: ^old_user_url} ->
- %Tesla.Env{status: 200, body: body}
- end)
-
Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)
ObanHelpers.perform_all()
diff --git a/test/pleroma/object/containment_test.exs b/test/pleroma/object/containment_test.exs
index 90b6dccf2..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-2020 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 7df6af7fe..c8ad66ddb 100644
--- a/test/pleroma/object/fetcher_test.exs
+++ b/test/pleroma/object/fetcher_test.exs
@@ -1,12 +1,12 @@
# 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.Object.FetcherTest do
use Pleroma.DataCase
alias Pleroma.Activity
- alias Pleroma.Config
+ alias Pleroma.Instances
alias Pleroma.Object
alias Pleroma.Object.Fetcher
@@ -67,6 +67,14 @@ defmodule Pleroma.Object.FetcherTest do
%Tesla.Env{
status: 500
}
+
+ %{
+ method: :get,
+ url: "https://stereophonic.space/objects/02997b83-3ea7-4b63-94af-ef3aa2d4ed17"
+ } ->
+ %Tesla.Env{
+ status: 500
+ }
end)
:ok
@@ -87,20 +95,20 @@ defmodule Pleroma.Object.FetcherTest do
setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
test "it returns thread depth exceeded error if thread depth is exceeded" do
- Config.put([:instance, :federation_incoming_replies_max_depth], 0)
+ clear_config([:instance, :federation_incoming_replies_max_depth], 0)
assert {:error, "Max thread distance exceeded."} =
Fetcher.fetch_object_from_id(@ap_id, depth: 1)
end
test "it fetches object if max thread depth is restricted to 0 and depth is not specified" do
- Config.put([:instance, :federation_incoming_replies_max_depth], 0)
+ clear_config([:instance, :federation_incoming_replies_max_depth], 0)
assert {:ok, _} = Fetcher.fetch_object_from_id(@ap_id)
end
test "it fetches object if requested depth does not exceed max thread depth" do
- Config.put([:instance, :federation_incoming_replies_max_depth], 10)
+ clear_config([:instance, :federation_incoming_replies_max_depth], 10)
assert {:ok, _} = Fetcher.fetch_object_from_id(@ap_id, depth: 10)
end
@@ -125,8 +133,7 @@ defmodule Pleroma.Object.FetcherTest do
{:ok, object} =
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
- assert activity = Activity.get_create_by_object_ap_id(object.data["id"])
- assert activity.data["id"]
+ assert _activity = Activity.get_create_by_object_ap_id(object.data["id"])
{:ok, object_again} =
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
@@ -153,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
@@ -245,7 +263,7 @@ defmodule Pleroma.Object.FetcherTest do
Pleroma.Signature,
[:passthrough],
[] do
- Config.put([:activitypub, :sign_object_fetches], true)
+ clear_config([:activitypub, :sign_object_fetches], true)
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
@@ -256,11 +274,278 @@ defmodule Pleroma.Object.FetcherTest do
Pleroma.Signature,
[:passthrough],
[] do
- Config.put([:activitypub, :sign_object_fetches], false)
+ clear_config([:activitypub, :sign_object_fetches], false)
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
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 5d4e6fb84..d536e0b16 100644
--- a/test/pleroma/object_test.exs
+++ b/test/pleroma/object_test.exs
@@ -1,14 +1,17 @@
# 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.ObjectTest do
use Pleroma.DataCase
use Oban.Testing, repo: Pleroma.Repo
+
import ExUnit.CaptureLog
import Pleroma.Factory
import Tesla.Mock
+
alias Pleroma.Activity
+ alias Pleroma.Hashtag
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.Tests.ObanHelpers
@@ -78,8 +81,8 @@ defmodule Pleroma.ObjectTest do
setup do: clear_config([:instance, :cleanup_attachments])
test "Disabled via config" do
- Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
- Pleroma.Config.put([:instance, :cleanup_attachments], false)
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ clear_config([:instance, :cleanup_attachments], false)
file = %Plug.Upload{
content_type: "image/jpeg",
@@ -112,8 +115,8 @@ defmodule Pleroma.ObjectTest do
end
test "in subdirectories" do
- Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
- Pleroma.Config.put([:instance, :cleanup_attachments], true)
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ clear_config([:instance, :cleanup_attachments], true)
file = %Plug.Upload{
content_type: "image/jpeg",
@@ -146,9 +149,9 @@ defmodule Pleroma.ObjectTest do
end
test "with dedupe enabled" do
- Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
- Pleroma.Config.put([Pleroma.Upload, :filters], [Pleroma.Upload.Filter.Dedupe])
- Pleroma.Config.put([:instance, :cleanup_attachments], true)
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ clear_config([Pleroma.Upload, :filters], [Pleroma.Upload.Filter.Dedupe])
+ clear_config([:instance, :cleanup_attachments], true)
uploads_dir = Pleroma.Config.get!([Pleroma.Uploaders.Local, :uploads])
@@ -184,8 +187,8 @@ defmodule Pleroma.ObjectTest do
end
test "with objects that have legacy data.url attribute" do
- Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
- Pleroma.Config.put([:instance, :cleanup_attachments], true)
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ clear_config([:instance, :cleanup_attachments], true)
file = %Plug.Upload{
content_type: "image/jpeg",
@@ -220,9 +223,9 @@ defmodule Pleroma.ObjectTest do
end
test "With custom base_url" do
- Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
- Pleroma.Config.put([Pleroma.Upload, :base_url], "https://sub.domain.tld/dir/")
- Pleroma.Config.put([:instance, :cleanup_attachments], true)
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ clear_config([Pleroma.Upload, :base_url], "https://sub.domain.tld/dir/")
+ clear_config([:instance, :cleanup_attachments], true)
file = %Plug.Upload{
content_type: "image/jpeg",
@@ -256,23 +259,22 @@ defmodule Pleroma.ObjectTest do
end
describe "normalizer" do
- test "fetches unknown objects by default" do
- %Object{} =
- object = Object.normalize("http://mastodon.example.org/@admin/99541947525187367")
-
- assert object.data["url"] == "http://mastodon.example.org/@admin/99541947525187367"
+ @url "http://mastodon.example.org/@admin/99541947525187367"
+ test "does not fetch unknown objects by default" do
+ assert nil == Object.normalize(@url)
end
- test "fetches unknown objects when fetch_remote is explicitly true" do
- %Object{} =
- object = Object.normalize("http://mastodon.example.org/@admin/99541947525187367", true)
+ test "fetches unknown objects when fetch is explicitly true" do
+ %Object{} = object = Object.normalize(@url, fetch: true)
- assert object.data["url"] == "http://mastodon.example.org/@admin/99541947525187367"
+ assert object.data["url"] == @url
end
- test "does not fetch unknown objects when fetch_remote is false" do
+ test "does not fetch unknown objects when fetch is false" do
assert is_nil(
- Object.normalize("http://mastodon.example.org/@admin/99541947525187367", false)
+ Object.normalize(@url,
+ fetch: false
+ )
)
end
end
@@ -310,7 +312,10 @@ defmodule Pleroma.ObjectTest do
mock_modified: mock_modified
} do
%Object{} =
- object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
+ object =
+ Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d",
+ fetch: true
+ )
Object.set_cache(object)
@@ -332,7 +337,10 @@ defmodule Pleroma.ObjectTest do
test "returns the old object if refetch fails", %{mock_modified: mock_modified} do
%Object{} =
- object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
+ object =
+ Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d",
+ fetch: true
+ )
Object.set_cache(object)
@@ -355,7 +363,10 @@ defmodule Pleroma.ObjectTest do
mock_modified: mock_modified
} do
%Object{} =
- object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
+ object =
+ Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d",
+ fetch: true
+ )
Object.set_cache(object)
@@ -377,7 +388,10 @@ defmodule Pleroma.ObjectTest do
test "preserves internal fields on refetch", %{mock_modified: mock_modified} do
%Object{} =
- object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
+ object =
+ Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d",
+ fetch: true
+ )
Object.set_cache(object)
@@ -406,4 +420,28 @@ defmodule Pleroma.ObjectTest do
assert updated_object.data["like_count"] == 1
end
end
+
+ describe ":hashtags association" do
+ test "Hashtag records are created with Object record and updated on its change" do
+ user = insert(:user)
+
+ {:ok, %{object: object}} =
+ CommonAPI.post(user, %{status: "some text #hashtag1 #hashtag2 ..."})
+
+ assert [%Hashtag{name: "hashtag1"}, %Hashtag{name: "hashtag2"}] =
+ Enum.sort_by(object.hashtags, & &1.name)
+
+ {:ok, object} = Object.update_data(object, %{"tag" => []})
+
+ assert [] = object.hashtags
+
+ object = Object.get_by_id(object.id) |> Repo.preload(:hashtags)
+ assert [] = object.hashtags
+
+ {:ok, object} = Object.update_data(object, %{"tag" => ["abc", "def"]})
+
+ assert [%Hashtag{name: "abc"}, %Hashtag{name: "def"}] =
+ Enum.sort_by(object.hashtags, & &1.name)
+ end
+ end
end
diff --git a/test/pleroma/otp_version_test.exs b/test/pleroma/otp_version_test.exs
index 7d2538ec8..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-2020 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 5ee1e60ae..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-2020 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
new file mode 100644
index 000000000..02f59445c
--- /dev/null
+++ b/test/pleroma/password/pbkdf2_test.exs
@@ -0,0 +1,35 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Password.Pbkdf2Test do
+ use Pleroma.DataCase, async: true
+
+ alias Pleroma.Password.Pbkdf2, as: Password
+
+ test "it generates the same hash as pbkd2_elixir" do
+ # hash = Pbkdf2.hash_pwd_salt("password")
+ hash =
+ "$pbkdf2-sha512$1$QJpEYw8iBKcnY.4Rm0eCVw$UBPeWQ91RxSv3snxsb/ZzMeG/2aa03c541bbo8vQudREGNta5t8jBQrd00fyJp8RjaqfvgdZxy2rhSwljyu21g"
+
+ # Use the same randomly generated salt
+ salt = Password.decode64("QJpEYw8iBKcnY.4Rm0eCVw")
+
+ assert hash == Password.hash_pwd_salt("password", salt: salt)
+ end
+
+ @tag skip: "Works when Pbkd2 is present. Source: trust me bro"
+ test "Pbkdf2 can verify passwords generated with it" do
+ # Commented to prevent warnings.
+ # hash = Password.hash_pwd_salt("password")
+ # assert Pbkdf2.verify_pass("password", hash)
+ end
+
+ test "it verifies pbkdf2_elixir hashes" do
+ # hash = Pbkdf2.hash_pwd_salt("password")
+ hash =
+ "$pbkdf2-sha512$1$QJpEYw8iBKcnY.4Rm0eCVw$UBPeWQ91RxSv3snxsb/ZzMeG/2aa03c541bbo8vQudREGNta5t8jBQrd00fyJp8RjaqfvgdZxy2rhSwljyu21g"
+
+ assert Password.verify_pass("password", hash)
+ end
+end
diff --git a/test/pleroma/registration_test.exs b/test/pleroma/registration_test.exs
index 462ab452b..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-2020 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 84f520fe4..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-2020 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
@@ -37,7 +37,7 @@ defmodule Pleroma.Repo.Migrations.AutolinkerToLinkifyTest do
strip_prefix: false
]
- Pleroma.Config.put(Pleroma.Formatter, new_opts)
+ clear_config(Pleroma.Formatter, new_opts)
assert new_opts == Pleroma.Config.get(Pleroma.Formatter)
{text, _mentions, []} =
diff --git a/test/pleroma/repo/migrations/confirm_logged_in_users_test.exs b/test/pleroma/repo/migrations/confirm_logged_in_users_test.exs
new file mode 100644
index 000000000..a0731f5a4
--- /dev/null
+++ b/test/pleroma/repo/migrations/confirm_logged_in_users_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.Repo.Migrations.ConfirmLoggedInUsersTest do
+ alias Pleroma.Repo
+ alias Pleroma.User
+ use Pleroma.DataCase, async: true
+ import Ecto.Query
+ import Pleroma.Factory
+ import Pleroma.Tests.Helpers
+
+ setup_all do: require_migration("20201231185546_confirm_logged_in_users")
+
+ test "up/0 confirms unconfirmed but previously-logged-in users", %{migration: migration} do
+ insert_list(25, :oauth_token)
+ Repo.update_all(User, set: [is_confirmed: false])
+ insert_list(5, :user, is_confirmed: false)
+
+ count =
+ User
+ |> where(is_confirmed: false)
+ |> Repo.aggregate(:count)
+
+ assert count == 30
+
+ assert {25, nil} == migration.up()
+
+ count =
+ User
+ |> where(is_confirmed: false)
+ |> Repo.aggregate(:count)
+
+ assert count == 5
+ end
+
+ test "down/0 does nothing", %{migration: migration} do
+ assert :noop == migration.down()
+ end
+end
diff --git a/test/pleroma/repo/migrations/deprecate_public_endpoint_test.exs b/test/pleroma/repo/migrations/deprecate_public_endpoint_test.exs
new file mode 100644
index 000000000..d19ffd69b
--- /dev/null
+++ b/test/pleroma/repo/migrations/deprecate_public_endpoint_test.exs
@@ -0,0 +1,60 @@
+# 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.DeprecatePublicEndpointTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+ import Pleroma.Tests.Helpers
+ alias Pleroma.ConfigDB
+
+ setup do: clear_config(Pleroma.Upload)
+ setup do: clear_config(Pleroma.Uploaders.S3)
+ setup_all do: require_migration("20210113225652_deprecate_public_endpoint")
+
+ test "up/0 migrates public_endpoint to base_url", %{migration: migration} do
+ s3_values = [
+ public_endpoint: "https://coolhost.com/",
+ bucket: "secret_bucket"
+ ]
+
+ insert(:config, group: :pleroma, key: Pleroma.Uploaders.S3, value: s3_values)
+
+ upload_values = [
+ uploader: Pleroma.Uploaders.S3
+ ]
+
+ insert(:config, group: :pleroma, key: Pleroma.Upload, value: upload_values)
+
+ migration.up()
+
+ assert [bucket: "secret_bucket"] ==
+ ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Uploaders.S3}).value
+
+ assert [uploader: Pleroma.Uploaders.S3, base_url: "https://coolhost.com/"] ==
+ ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}).value
+ end
+
+ test "down/0 reverts base_url to public_endpoint", %{migration: migration} do
+ s3_values = [
+ bucket: "secret_bucket"
+ ]
+
+ insert(:config, group: :pleroma, key: Pleroma.Uploaders.S3, value: s3_values)
+
+ upload_values = [
+ uploader: Pleroma.Uploaders.S3,
+ base_url: "https://coolhost.com/"
+ ]
+
+ insert(:config, group: :pleroma, key: Pleroma.Upload, value: upload_values)
+
+ migration.down()
+
+ assert [bucket: "secret_bucket", public_endpoint: "https://coolhost.com/"] ==
+ ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Uploaders.S3}).value
+
+ assert [uploader: Pleroma.Uploaders.S3] ==
+ ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}).value
+ end
+end
diff --git a/test/pleroma/repo/migrations/fix_legacy_tags_test.exs b/test/pleroma/repo/migrations/fix_legacy_tags_test.exs
index adfed1142..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-2020 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 61528599a..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-2020 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
@@ -34,7 +34,7 @@ defmodule Pleroma.Repo.Migrations.FixMalformedFormatterConfigTest do
strip_prefix: false
]
- Pleroma.Config.put(Pleroma.Formatter, new_opts)
+ clear_config(Pleroma.Formatter, new_opts)
assert new_opts == Pleroma.Config.get(Pleroma.Formatter)
{text, _mentions, []} =
diff --git a/test/pleroma/repo/migrations/move_welcome_settings_test.exs b/test/pleroma/repo/migrations/move_welcome_settings_test.exs
index 5dbe9d7b0..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-2020 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
new file mode 100644
index 000000000..17c39fd27
--- /dev/null
+++ b/test/pleroma/repo/migrations/rename_instance_chat_test.exs
@@ -0,0 +1,56 @@
+# 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
+ import Pleroma.Tests.Helpers
+ alias Pleroma.ConfigDB
+
+ setup do: clear_config([:instance])
+ setup do: clear_config([:chat])
+ setup_all do: require_migration("20200806175913_rename_instance_chat")
+
+ describe "up/0" do
+ test "migrates chat settings to shout", %{migration: migration} do
+ insert(:config, group: :pleroma, key: :instance, value: [chat_limit: 6000])
+ insert(:config, group: :pleroma, key: :chat, value: [enabled: true])
+
+ assert migration.up() == :ok
+
+ assert ConfigDB.get_by_params(%{group: :pleroma, key: :chat}) == nil
+ assert ConfigDB.get_by_params(%{group: :pleroma, key: :instance}) == nil
+
+ assert ConfigDB.get_by_params(%{group: :pleroma, key: :shout}).value == [
+ limit: 6000,
+ enabled: true
+ ]
+ end
+
+ test "does nothing when chat settings are not set", %{migration: migration} do
+ assert migration.up() == :noop
+ assert ConfigDB.get_by_params(%{group: :pleroma, key: :chat}) == nil
+ assert ConfigDB.get_by_params(%{group: :pleroma, key: :shout}) == nil
+ end
+ end
+
+ describe "down/0" do
+ test "migrates shout settings back to instance and chat", %{migration: migration} do
+ insert(:config, group: :pleroma, key: :shout, value: [limit: 42, enabled: true])
+
+ assert migration.down() == :ok
+
+ assert ConfigDB.get_by_params(%{group: :pleroma, key: :chat}).value == [enabled: true]
+ assert ConfigDB.get_by_params(%{group: :pleroma, key: :instance}).value == [chat_limit: 42]
+ assert ConfigDB.get_by_params(%{group: :pleroma, key: :shout}) == nil
+ end
+
+ test "does nothing when shout settings are not set", %{migration: migration} do
+ assert migration.down() == :noop
+ assert ConfigDB.get_by_params(%{group: :pleroma, key: :chat}) == nil
+ assert ConfigDB.get_by_params(%{group: :pleroma, key: :instance}) == nil
+ assert ConfigDB.get_by_params(%{group: :pleroma, key: :shout}) == nil
+ end
+ end
+end
diff --git a/test/pleroma/repo_test.exs b/test/pleroma/repo_test.exs
index eaddef3a6..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-2020 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 cc4561eea..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-2020 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/reverse_proxy_test.exs b/test/pleroma/reverse_proxy_test.exs
index 0a2c169ce..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-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ReverseProxyTest do
@@ -18,24 +18,23 @@ defmodule Pleroma.ReverseProxyTest do
setup :verify_on_exit!
- defp user_agent_mock(user_agent, invokes) do
- json = Jason.encode!(%{"user-agent": user_agent})
-
+ defp request_mock(invokes) do
ClientMock
- |> expect(:request, fn :get, url, _, _, _ ->
+ |> expect(:request, fn :get, url, headers, _body, _opts ->
Registry.register(ClientMock, url, 0)
+ body = headers |> Enum.into(%{}) |> Jason.encode!()
{:ok, 200,
[
{"content-type", "application/json"},
- {"content-length", byte_size(json) |> to_string()}
- ], %{url: url}}
+ {"content-length", byte_size(body) |> to_string()}
+ ], %{url: url, body: body}}
end)
- |> expect(:stream_body, invokes, fn %{url: url} = client ->
+ |> expect(:stream_body, invokes, fn %{url: url, body: body} = client ->
case Registry.lookup(ClientMock, url) do
[{_, 0}] ->
Registry.update_value(ClientMock, url, &(&1 + 1))
- {:ok, json, client}
+ {:ok, body, client}
[{_, 1}] ->
Registry.unregister(ClientMock, url)
@@ -46,7 +45,7 @@ defmodule Pleroma.ReverseProxyTest do
describe "reverse proxy" do
test "do not track successful request", %{conn: conn} do
- user_agent_mock("hackney/1.15.1", 2)
+ request_mock(2)
url = "/success"
conn = ReverseProxy.call(conn, url)
@@ -56,18 +55,15 @@ defmodule Pleroma.ReverseProxyTest do
end
end
- describe "user-agent" do
- test "don't keep", %{conn: conn} do
- user_agent_mock("hackney/1.15.1", 2)
- conn = ReverseProxy.call(conn, "/user-agent")
- assert json_response(conn, 200) == %{"user-agent" => "hackney/1.15.1"}
- end
+ test "use Pleroma's user agent in the request; don't pass the client's", %{conn: conn} do
+ request_mock(2)
- test "keep", %{conn: conn} do
- user_agent_mock(Pleroma.Application.user_agent(), 2)
- conn = ReverseProxy.call(conn, "/user-agent-keep", keep_user_agent: true)
- assert json_response(conn, 200) == %{"user-agent" => Pleroma.Application.user_agent()}
- end
+ conn =
+ conn
+ |> Plug.Conn.put_req_header("user-agent", "fake/1.0")
+ |> ReverseProxy.call("/user-agent")
+
+ assert json_response(conn, 200) == %{"user-agent" => Pleroma.Application.user_agent()}
end
test "closed connection", %{conn: conn} do
@@ -114,7 +110,7 @@ defmodule Pleroma.ReverseProxyTest do
describe "max_body" do
test "length returns error if content-length more than option", %{conn: conn} do
- user_agent_mock("hackney/1.15.1", 0)
+ request_mock(0)
assert capture_log(fn ->
ReverseProxy.call(conn, "/huge-file", max_body_length: 4)
@@ -134,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 010594fcd..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-2020 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 6d70f1026..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-2020 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 7faa5660d..3a0927d3f 100644
--- a/test/pleroma/scheduled_activity_test.exs
+++ b/test/pleroma/scheduled_activity_test.exs
@@ -1,22 +1,21 @@
# 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.ScheduledActivityTest do
use Pleroma.DataCase
- alias Pleroma.DataCase
+
alias Pleroma.ScheduledActivity
+
import Pleroma.Factory
setup do: clear_config([ScheduledActivity, :enabled])
- setup context do
- DataCase.ensure_local_uploader(context)
- end
+ setup [:ensure_local_uploader]
describe "creation" do
test "scheduled activities with jobs when ScheduledActivity enabled" do
- Pleroma.Config.put([ScheduledActivity, :enabled], true)
+ clear_config([ScheduledActivity, :enabled], true)
user = insert(:user)
today =
@@ -35,7 +34,7 @@ defmodule Pleroma.ScheduledActivityTest do
end
test "scheduled activities without jobs when ScheduledActivity disabled" do
- Pleroma.Config.put([ScheduledActivity, :enabled], false)
+ clear_config([ScheduledActivity, :enabled], false)
user = insert(:user)
today =
diff --git a/test/pleroma/signature_test.exs b/test/pleroma/signature_test.exs
index a7a75aa4d..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-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.SignatureTest do
@@ -109,6 +109,11 @@ defmodule Pleroma.SignatureTest do
{:ok, "https://example.com/users/1234"}
end
+ test "it deduces the actor id for gotoSocial" do
+ assert Signature.key_id_to_actor_id("https://example.com/users/1234/main-key") ==
+ {:ok, "https://example.com/users/1234"}
+ end
+
test "it calls webfinger for 'acct:' accounts" do
with_mock(Pleroma.Web.WebFinger,
finger: fn _ -> %{"ap_id" => "https://gensokyo.2hu/users/raymoo"} end
diff --git a/test/pleroma/stats_test.exs b/test/pleroma/stats_test.exs
index 6c2fd5726..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-2020 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
new file mode 100644
index 000000000..b800a4a43
--- /dev/null
+++ b/test/pleroma/upload/filter/analyze_metadata_test.exs
@@ -0,0 +1,33 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Upload.Filter.AnalyzeMetadataTest do
+ use Pleroma.DataCase, async: true
+ alias Pleroma.Upload.Filter.AnalyzeMetadata
+
+ test "adds the dimensions and blurhash for images" do
+ upload = %Pleroma.Upload{
+ name: "an… image.jpg",
+ content_type: "image/jpeg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ tempfile: Path.absname("test/fixtures/image.jpg")
+ }
+
+ {:ok, :filtered, meta} = AnalyzeMetadata.filter(upload)
+
+ assert %{width: 1024, height: 768} = meta
+ assert meta.blurhash
+ end
+
+ test "adds the dimensions for videos" do
+ upload = %Pleroma.Upload{
+ name: "coolvideo.mp4",
+ content_type: "video/mp4",
+ path: Path.absname("test/fixtures/video.mp4"),
+ tempfile: Path.absname("test/fixtures/video.mp4")
+ }
+
+ assert {:ok, :filtered, %{width: 480, height: 480}} = AnalyzeMetadata.filter(upload)
+ end
+end
diff --git a/test/pleroma/upload/filter/anonymize_filename_test.exs b/test/pleroma/upload/filter/anonymize_filename_test.exs
index 7ef01ce91..9b94b91c3 100644
--- a/test/pleroma/upload/filter/anonymize_filename_test.exs
+++ b/test/pleroma/upload/filter/anonymize_filename_test.exs
@@ -1,11 +1,10 @@
# 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.Upload.Filter.AnonymizeFilenameTest do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.Upload
setup do
@@ -23,13 +22,13 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilenameTest do
setup do: clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text])
test "it replaces filename on pre-defined text", %{upload_file: upload_file} do
- Config.put([Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
+ clear_config([Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
{:ok, :filtered, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
assert name == "custom-file.png"
end
test "it replaces filename on pre-defined text expression", %{upload_file: upload_file} do
- Config.put([Upload.Filter.AnonymizeFilename, :text], "custom-file.{extension}")
+ clear_config([Upload.Filter.AnonymizeFilename, :text], "custom-file.{extension}")
{:ok, :filtered, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
assert name == "custom-file.jpg"
end
diff --git a/test/pleroma/upload/filter/dedupe_test.exs b/test/pleroma/upload/filter/dedupe_test.exs
index 6559cbb50..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-2020 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 b5a5ba18d..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-2020 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 fc2f68276..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-2020 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 6dee02e8b..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-2020 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 09394929c..706fc9ac7 100644
--- a/test/pleroma/upload/filter_test.exs
+++ b/test/pleroma/upload/filter_test.exs
@@ -1,17 +1,16 @@
# 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.Upload.FilterTest do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.Upload.Filter
setup do: clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text])
test "applies filters" do
- Config.put([Pleroma.Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
+ clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
File.cp!(
"test/fixtures/image.jpg",
diff --git a/test/pleroma/upload_test.exs b/test/pleroma/upload_test.exs
index f52d4dff6..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-2020 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
@@ -133,7 +135,7 @@ defmodule Pleroma.UploadTest do
assert %{"url" => [%{"href" => url}]} = data
- assert String.starts_with?(url, Pleroma.Web.base_url() <> "/media/")
+ assert String.starts_with?(url, Pleroma.Upload.base_url())
end
test "copies the file to the configured folder with deduping" do
@@ -148,8 +150,8 @@ defmodule Pleroma.UploadTest do
{:ok, data} = Upload.store(file, filters: [Pleroma.Upload.Filter.Dedupe])
assert List.first(data["url"])["href"] ==
- Pleroma.Web.base_url() <>
- "/media/e30397b58d226d6583ab5b8b3c5defb0c682bda5c31ef07a9f57c1c4986e3781.jpg"
+ Pleroma.Upload.base_url() <>
+ "e30397b58d226d6583ab5b8b3c5defb0c682bda5c31ef07a9f57c1c4986e3781.jpg"
end
test "copies the file to the configured folder without deduping" do
diff --git a/test/pleroma/uploaders/local_test.exs b/test/pleroma/uploaders/local_test.exs
index 5b377d580..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-2020 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 e7a013dd8..d870449b1 100644
--- a/test/pleroma/uploaders/s3_test.exs
+++ b/test/pleroma/uploaders/s3_test.exs
@@ -1,21 +1,21 @@
# 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.Uploaders.S3Test do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.Uploaders.S3
import Mock
import ExUnit.CaptureLog
- setup do:
- clear_config(Pleroma.Uploaders.S3,
- bucket: "test_bucket",
- public_endpoint: "https://s3.amazonaws.com"
- )
+ setup do
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3)
+ clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
+ clear_config([Pleroma.Uploaders.S3])
+ clear_config([Pleroma.Uploaders.S3, :bucket], "test_bucket")
+ end
describe "get_file/1" do
test "it returns path to local folder for files" do
@@ -26,12 +26,14 @@ defmodule Pleroma.Uploaders.S3Test do
end
test "it returns path without bucket when truncated_namespace set to ''" do
- Config.put([Pleroma.Uploaders.S3],
+ clear_config([Pleroma.Uploaders.S3],
bucket: "test_bucket",
- public_endpoint: "https://s3.amazonaws.com",
+ bucket_namespace: "myaccount",
truncated_namespace: ""
)
+ clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
+
assert S3.get_file("test_image.jpg") == {
:ok,
{:url, "https://s3.amazonaws.com/test_image.jpg"}
@@ -39,9 +41,8 @@ defmodule Pleroma.Uploaders.S3Test do
end
test "it returns path with bucket namespace when namespace is set" do
- Config.put([Pleroma.Uploaders.S3],
+ clear_config([Pleroma.Uploaders.S3],
bucket: "test_bucket",
- public_endpoint: "https://s3.amazonaws.com",
bucket_namespace: "family"
)
diff --git a/test/pleroma/user/backup_test.exs b/test/pleroma/user/backup_test.exs
index f68e4a029..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-2020 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
- Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
+ 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
@@ -53,7 +53,7 @@ defmodule Pleroma.User.BackupTest do
end
test "it process a backup record" do
- Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ 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)
@@ -75,9 +75,46 @@ 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
- Pleroma.Config.put([Backup, :limit_days], -1)
- Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ clear_config([Backup, :limit_days], -1)
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
user = insert(:user)
assert {:ok, job1} = Backup.create(user)
@@ -195,12 +232,8 @@ defmodule Pleroma.User.BackupTest do
describe "it uploads and deletes a backup archive" do
setup do
- clear_config(Pleroma.Uploaders.S3,
- bucket: "test_bucket",
- public_endpoint: "https://s3.amazonaws.com"
- )
-
- clear_config([Pleroma.Upload, :uploader])
+ clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
+ clear_config([Pleroma.Uploaders.S3, :bucket], "test_bucket")
user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"})
@@ -219,7 +252,8 @@ defmodule Pleroma.User.BackupTest do
end
test "S3", %{path: path, backup: backup} do
- Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3)
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3)
+ clear_config([Pleroma.Uploaders.S3, :streaming_enabled], false)
with_mock ExAws,
request: fn
@@ -229,13 +263,10 @@ defmodule Pleroma.User.BackupTest do
assert {:ok, %Pleroma.Upload{}} = Backup.upload(backup, path)
assert {:ok, _backup} = Backup.delete(backup)
end
-
- with_mock ExAws, request: fn %{http_method: :delete} -> {:ok, %{status_code: 204}} end do
- end
end
test "Local", %{path: path, backup: backup} do
- Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
assert {:ok, %Pleroma.Upload{}} = Backup.upload(backup, path)
assert {:ok, _backup} = Backup.delete(backup)
diff --git a/test/pleroma/user/import_test.exs b/test/pleroma/user/import_test.exs
index e198cdc08..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-2020 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 701130380..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-2020 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 e2f5c7d81..bd45d1bca 100644
--- a/test/pleroma/user/query_test.exs
+++ b/test/pleroma/user/query_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.User.QueryTest do
@@ -34,4 +34,14 @@ 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
end
diff --git a/test/pleroma/user/welcome_chat_message_test.exs b/test/pleroma/user/welcome_chat_message_test.exs
index fe26d6e4d..9f2cbdcc0 100644
--- a/test/pleroma/user/welcome_chat_message_test.exs
+++ b/test/pleroma/user/welcome_chat_message_test.exs
@@ -1,11 +1,10 @@
# 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.User.WelcomeChatMessageTest do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.User.WelcomeChatMessage
import Pleroma.Factory
@@ -17,10 +16,10 @@ defmodule Pleroma.User.WelcomeChatMessageTest do
welcome_user = insert(:user, name: "mewmew")
user = insert(:user)
- Config.put([:welcome, :chat_message, :enabled], true)
- Config.put([:welcome, :chat_message, :sender_nickname], welcome_user.nickname)
+ clear_config([:welcome, :chat_message, :enabled], true)
+ clear_config([:welcome, :chat_message, :sender_nickname], welcome_user.nickname)
- Config.put(
+ clear_config(
[:welcome, :chat_message, :message],
"Hello, welcome to Blob/Cat!"
)
@@ -28,8 +27,10 @@ defmodule Pleroma.User.WelcomeChatMessageTest do
{:ok, %Pleroma.Activity{} = activity} = WelcomeChatMessage.post_message(user)
assert user.ap_id in activity.recipients
- assert Pleroma.Object.normalize(activity).data["type"] == "ChatMessage"
- assert Pleroma.Object.normalize(activity).data["content"] == "Hello, welcome to Blob/Cat!"
+ assert Pleroma.Object.normalize(activity, fetch: false).data["type"] == "ChatMessage"
+
+ assert Pleroma.Object.normalize(activity, fetch: false).data["content"] ==
+ "Hello, welcome to Blob/Cat!"
end
end
end
diff --git a/test/pleroma/user/welcome_email_test.exs b/test/pleroma/user/welcome_email_test.exs
index d005d11b2..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-2020 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
@@ -18,15 +18,15 @@ defmodule Pleroma.User.WelcomeEmailTest do
test "send a welcome email" do
user = insert(:user, name: "Jimm")
- Config.put([:welcome, :email, :enabled], true)
- Config.put([:welcome, :email, :sender], "welcome@pleroma.app")
+ clear_config([:welcome, :email, :enabled], true)
+ clear_config([:welcome, :email, :sender], "welcome@pleroma.app")
- Config.put(
+ clear_config(
[:welcome, :email, :subject],
"Hello, welcome to pleroma: <%= instance_name %>"
)
- Config.put(
+ clear_config(
[:welcome, :email, :html],
"<h1>Hello <%= user.name %>.</h1> <p>Welcome to <%= instance_name %></p>"
)
@@ -44,7 +44,7 @@ defmodule Pleroma.User.WelcomeEmailTest do
html_body: "<h1>Hello #{user.name}.</h1> <p>Welcome to #{instance_name}</p>"
)
- Config.put([:welcome, :email, :sender], {"Pleroma App", "welcome@pleroma.app"})
+ clear_config([:welcome, :email, :sender], {"Pleroma App", "welcome@pleroma.app"})
{:ok, _job} = WelcomeEmail.send_email(user)
diff --git a/test/pleroma/user/welcome_message_test.exs b/test/pleroma/user/welcome_message_test.exs
index 3cd6f5cb7..0d4fe1a8b 100644
--- a/test/pleroma/user/welcome_message_test.exs
+++ b/test/pleroma/user/welcome_message_test.exs
@@ -1,11 +1,10 @@
# 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.User.WelcomeMessageTest do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.User.WelcomeMessage
import Pleroma.Factory
@@ -17,10 +16,10 @@ defmodule Pleroma.User.WelcomeMessageTest do
welcome_user = insert(:user)
user = insert(:user, name: "Jimm")
- Config.put([:welcome, :direct_message, :enabled], true)
- Config.put([:welcome, :direct_message, :sender_nickname], welcome_user.nickname)
+ clear_config([:welcome, :direct_message, :enabled], true)
+ clear_config([:welcome, :direct_message, :sender_nickname], welcome_user.nickname)
- Config.put(
+ clear_config(
[:welcome, :direct_message, :message],
"Hello. Welcome to Pleroma"
)
@@ -28,7 +27,9 @@ defmodule Pleroma.User.WelcomeMessageTest do
{:ok, %Pleroma.Activity{} = activity} = WelcomeMessage.post_message(user)
assert user.ap_id in activity.recipients
assert activity.data["directMessage"] == true
- assert Pleroma.Object.normalize(activity).data["content"] =~ "Hello. Welcome to Pleroma"
+
+ assert Pleroma.Object.normalize(activity, fetch: false).data["content"] =~
+ "Hello. Welcome to Pleroma"
end
end
end
diff --git a/test/pleroma/user_invite_token_test.exs b/test/pleroma/user_invite_token_test.exs
index 63f18f13c..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-2020 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 da4982065..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-2020 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 accb0b816..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-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.UserSearchTest do
@@ -18,7 +18,7 @@ defmodule Pleroma.UserSearchTest do
setup do: clear_config([:instance, :limit_to_local_content])
test "returns a resolved user as the first result" do
- Pleroma.Config.put([:instance, :limit_to_local_content], false)
+ clear_config([:instance, :limit_to_local_content], false)
user = insert(:user, %{nickname: "no_relation", ap_id: "https://lain.com/users/lain"})
_user = insert(:user, %{nickname: "com_user"})
@@ -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})
@@ -199,7 +207,7 @@ defmodule Pleroma.UserSearchTest do
end
test "find only local users for authenticated users when `limit_to_local_content` is `:all`" do
- Pleroma.Config.put([:instance, :limit_to_local_content], :all)
+ clear_config([:instance, :limit_to_local_content], :all)
%{id: id} = insert(:user, %{name: "lain"})
insert(:user, %{name: "ebn", nickname: "lain@mastodon.social", local: false})
@@ -209,7 +217,7 @@ defmodule Pleroma.UserSearchTest do
end
test "find all users for unauthenticated users when `limit_to_local_content` is `false`" do
- Pleroma.Config.put([:instance, :limit_to_local_content], false)
+ clear_config([:instance, :limit_to_local_content], false)
u1 = insert(:user, %{name: "lain"})
u2 = insert(:user, %{name: "ebn", nickname: "lain@mastodon.social", local: false})
diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs
index 40bbcad0b..a58c8f68b 100644
--- a/test/pleroma/user_test.exs
+++ b/test/pleroma/user_test.exs
@@ -1,10 +1,11 @@
# 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.UserTest do
alias Pleroma.Activity
alias Pleroma.Builders.UserBuilder
+ alias Pleroma.Notification
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.Tests.ObanHelpers
@@ -151,7 +152,7 @@ defmodule Pleroma.UserTest do
test "ap_id returns the activity pub id for the user" do
user = UserBuilder.build()
- expected_ap_id = "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
+ expected_ap_id = "#{Pleroma.Web.Endpoint.url()}/users/#{user.nickname}"
assert expected_ap_id == User.ap_id(user)
end
@@ -202,11 +203,11 @@ defmodule Pleroma.UserTest do
test "doesn't return follow requests for deactivated accounts" do
locked = insert(:user, is_locked: true)
- pending_follower = insert(:user, %{deactivated: true})
+ pending_follower = insert(:user, %{is_active: false})
CommonAPI.follow(pending_follower, locked)
- assert true == pending_follower.deactivated
+ refute pending_follower.is_active
assert [] = User.get_follow_requests(locked)
end
@@ -275,7 +276,7 @@ defmodule Pleroma.UserTest do
test "can't follow a deactivated users" do
user = insert(:user)
- followed = insert(:user, %{deactivated: true})
+ followed = insert(:user, %{is_active: false})
{:error, _} = User.follow(user, followed)
end
@@ -310,8 +311,8 @@ defmodule Pleroma.UserTest do
describe "unfollow/2" do
setup do: clear_config([:instance, :external_user_synchronization])
- test "unfollow with syncronizes external user" do
- Pleroma.Config.put([:instance, :external_user_synchronization], true)
+ test "unfollow with synchronizes external user" do
+ clear_config([:instance, :external_user_synchronization], true)
followed =
insert(:user,
@@ -396,7 +397,7 @@ defmodule Pleroma.UserTest do
user = insert(:user)
remote_user = insert(:user, %{local: false})
- Pleroma.Config.put([:instance, :autofollowed_nicknames], [
+ clear_config([:instance, :autofollowed_nicknames], [
user.nickname,
remote_user.nickname
])
@@ -413,7 +414,7 @@ defmodule Pleroma.UserTest do
user1 = insert(:user)
user2 = insert(:user)
- Pleroma.Config.put([:instance, :autofollowing_nicknames], [
+ clear_config([:instance, :autofollowing_nicknames], [
user1.nickname,
user2.nickname
])
@@ -428,9 +429,9 @@ defmodule Pleroma.UserTest do
test "it sends a welcome message if it is set" do
welcome_user = insert(:user)
- Pleroma.Config.put([:welcome, :direct_message, :enabled], true)
- Pleroma.Config.put([:welcome, :direct_message, :sender_nickname], welcome_user.nickname)
- Pleroma.Config.put([:welcome, :direct_message, :message], "Hello, this is a direct message")
+ clear_config([:welcome, :direct_message, :enabled], true)
+ clear_config([:welcome, :direct_message, :sender_nickname], welcome_user.nickname)
+ clear_config([:welcome, :direct_message, :message], "Hello, this is a direct message")
cng = User.register_changeset(%User{}, @full_user_data)
{:ok, registered_user} = User.register(cng)
@@ -438,15 +439,15 @@ defmodule Pleroma.UserTest do
activity = Repo.one(Pleroma.Activity)
assert registered_user.ap_id in activity.recipients
- assert Object.normalize(activity).data["content"] =~ "direct message"
+ assert Object.normalize(activity, fetch: false).data["content"] =~ "direct message"
assert activity.actor == welcome_user.ap_id
end
test "it sends a welcome chat message if it is set" do
welcome_user = insert(:user)
- Pleroma.Config.put([:welcome, :chat_message, :enabled], true)
- Pleroma.Config.put([:welcome, :chat_message, :sender_nickname], welcome_user.nickname)
- Pleroma.Config.put([:welcome, :chat_message, :message], "Hello, this is a chat message")
+ clear_config([:welcome, :chat_message, :enabled], true)
+ clear_config([:welcome, :chat_message, :sender_nickname], welcome_user.nickname)
+ clear_config([:welcome, :chat_message, :message], "Hello, this is a chat message")
cng = User.register_changeset(%User{}, @full_user_data)
{:ok, registered_user} = User.register(cng)
@@ -454,7 +455,7 @@ defmodule Pleroma.UserTest do
activity = Repo.one(Pleroma.Activity)
assert registered_user.ap_id in activity.recipients
- assert Object.normalize(activity).data["content"] =~ "chat message"
+ assert Object.normalize(activity, fetch: false).data["content"] =~ "chat message"
assert activity.actor == welcome_user.ap_id
end
@@ -480,12 +481,12 @@ defmodule Pleroma.UserTest do
)
test "it sends a welcome chat message when Simple policy applied to local instance" do
- Pleroma.Config.put([:mrf_simple, :media_nsfw], ["localhost"])
+ clear_config([:mrf_simple, :media_nsfw], [{"localhost", ""}])
welcome_user = insert(:user)
- Pleroma.Config.put([:welcome, :chat_message, :enabled], true)
- Pleroma.Config.put([:welcome, :chat_message, :sender_nickname], welcome_user.nickname)
- Pleroma.Config.put([:welcome, :chat_message, :message], "Hello, this is a chat message")
+ clear_config([:welcome, :chat_message, :enabled], true)
+ clear_config([:welcome, :chat_message, :sender_nickname], welcome_user.nickname)
+ clear_config([:welcome, :chat_message, :message], "Hello, this is a chat message")
cng = User.register_changeset(%User{}, @full_user_data)
{:ok, registered_user} = User.register(cng)
@@ -493,16 +494,16 @@ defmodule Pleroma.UserTest do
activity = Repo.one(Pleroma.Activity)
assert registered_user.ap_id in activity.recipients
- assert Object.normalize(activity).data["content"] =~ "chat message"
+ assert Object.normalize(activity, fetch: false).data["content"] =~ "chat message"
assert activity.actor == welcome_user.ap_id
end
test "it sends a welcome email message if it is set" do
welcome_user = insert(:user)
- Pleroma.Config.put([:welcome, :email, :enabled], true)
- Pleroma.Config.put([:welcome, :email, :sender], welcome_user.email)
+ clear_config([:welcome, :email, :enabled], true)
+ clear_config([:welcome, :email, :sender], welcome_user.email)
- Pleroma.Config.put(
+ clear_config(
[:welcome, :email, :subject],
"Hello, welcome to cool site: <%= instance_name %>"
)
@@ -522,7 +523,7 @@ defmodule Pleroma.UserTest do
end
test "it sends a confirm email" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_activation_required], true)
cng = User.register_changeset(%User{}, @full_user_data)
{:ok, registered_user} = User.register(cng)
@@ -551,8 +552,62 @@ defmodule Pleroma.UserTest do
)
end
+ test "it sends a registration confirmed email if no others will be sent" do
+ clear_config([:welcome, :email, :enabled], false)
+ clear_config([:instance, :account_activation_required], false)
+ clear_config([:instance, :account_approval_required], false)
+
+ {:ok, user} =
+ User.register_changeset(%User{}, @full_user_data)
+ |> User.register()
+
+ ObanHelpers.perform_all()
+
+ instance_name = Pleroma.Config.get([:instance, :name])
+ sender = Pleroma.Config.get([:instance, :notify_email])
+
+ assert_email_sent(
+ from: {instance_name, sender},
+ to: {user.name, user.email},
+ subject: "Account registered on #{instance_name}"
+ )
+ end
+
+ test "it fails gracefully with invalid email config" do
+ cng = User.register_changeset(%User{}, @full_user_data)
+
+ # Disable the mailer but enable all the things that want to send emails
+ clear_config([Pleroma.Emails.Mailer, :enabled], false)
+ clear_config([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_approval_required], true)
+ clear_config([:welcome, :email, :enabled], true)
+ clear_config([:welcome, :email, :sender], "lain@lain.com")
+
+ # The user is still created
+ assert {:ok, %User{nickname: "nick"}} = User.register(cng)
+
+ # No emails are sent
+ ObanHelpers.perform_all()
+ refute_email_sent()
+ end
+
+ test "it 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
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_activation_required], true)
@full_user_data
|> Map.keys()
@@ -565,7 +620,7 @@ defmodule Pleroma.UserTest do
end
test "it requires an name, nickname and password, bio and email are optional when account_activation_required is disabled" do
- Pleroma.Config.put([:instance, :account_activation_required], false)
+ clear_config([:instance, :account_activation_required], false)
@full_user_data
|> Map.keys()
@@ -578,9 +633,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
@@ -591,6 +647,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"])
@@ -599,6 +672,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)
@@ -614,14 +692,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
@@ -640,7 +718,7 @@ defmodule Pleroma.UserTest do
{:ok, user} = Repo.insert(changeset)
- refute user.confirmation_pending
+ assert user.is_confirmed
end
end
@@ -661,17 +739,17 @@ defmodule Pleroma.UserTest do
{:ok, user} = Repo.insert(changeset)
- assert user.confirmation_pending
+ refute user.is_confirmed
assert user.confirmation_token
end
test "it creates confirmed user if :confirmed option is given" do
- changeset = User.register_changeset(%User{}, @full_user_data, need_confirmation: false)
+ changeset = User.register_changeset(%User{}, @full_user_data, confirmed: true)
assert changeset.valid?
{:ok, user} = Repo.insert(changeset)
- refute user.confirmation_pending
+ assert user.is_confirmed
refute user.confirmation_token
end
end
@@ -694,7 +772,7 @@ defmodule Pleroma.UserTest do
{:ok, user} = Repo.insert(changeset)
- assert user.approval_pending
+ refute user.is_approved
assert user.registration_reason == "I'm a cool guy :)"
end
@@ -716,6 +794,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)
@@ -739,6 +865,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
@@ -1035,7 +1278,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
@@ -1313,14 +1556,14 @@ defmodule Pleroma.UserTest do
end
end
- describe ".deactivate" do
+ describe ".set_activation" do
test "can de-activate then re-activate a user" do
user = insert(:user)
- assert false == user.deactivated
- {:ok, user} = User.deactivate(user)
- assert true == user.deactivated
- {:ok, user} = User.deactivate(user, false)
- assert false == user.deactivated
+ assert user.is_active
+ {:ok, user} = User.set_activation(user, false)
+ refute user.is_active
+ {:ok, user} = User.set_activation(user, true)
+ assert user.is_active
end
test "hide a user from followers" do
@@ -1328,7 +1571,7 @@ defmodule Pleroma.UserTest do
user2 = insert(:user)
{:ok, user, user2} = User.follow(user, user2)
- {:ok, _user} = User.deactivate(user)
+ {:ok, _user} = User.set_activation(user, false)
user2 = User.get_cached_by_id(user2.id)
@@ -1344,7 +1587,7 @@ defmodule Pleroma.UserTest do
assert user2.following_count == 1
assert User.following_count(user2) == 1
- {:ok, _user} = User.deactivate(user)
+ {:ok, _user} = User.set_activation(user, false)
user2 = User.get_cached_by_id(user2.id)
@@ -1374,7 +1617,7 @@ defmodule Pleroma.UserTest do
user: user2
})
- {:ok, _user} = User.deactivate(user)
+ {:ok, _user} = User.set_activation(user, false)
assert [] == ActivityPub.fetch_public_activities(%{})
assert [] == Pleroma.Notification.for_user(user2)
@@ -1388,17 +1631,17 @@ defmodule Pleroma.UserTest do
describe "approve" do
test "approves a user" do
- user = insert(:user, approval_pending: true)
- assert true == user.approval_pending
+ user = insert(:user, is_approved: false)
+ refute user.is_approved
{:ok, user} = User.approve(user)
- assert false == user.approval_pending
+ assert user.is_approved
end
test "approves a list of users" do
unapproved_users = [
- insert(:user, approval_pending: true),
- insert(:user, approval_pending: true),
- insert(:user, approval_pending: true)
+ insert(:user, is_approved: false),
+ insert(:user, is_approved: false),
+ insert(:user, is_approved: false)
]
{:ok, users} = User.approve(unapproved_users)
@@ -1406,7 +1649,7 @@ defmodule Pleroma.UserTest do
assert Enum.count(users) == 3
Enum.each(users, fn user ->
- assert false == user.approval_pending
+ assert user.is_approved
end)
end
@@ -1414,7 +1657,7 @@ defmodule Pleroma.UserTest do
clear_config([:welcome, :email, :enabled], true)
clear_config([:welcome, :email, :sender], "tester@test.me")
- user = insert(:user, approval_pending: true)
+ user = insert(:user, is_approved: false)
welcome_user = insert(:user, email: "tester@test.me")
instance_name = Pleroma.Config.get([:instance, :name])
@@ -1432,7 +1675,7 @@ defmodule Pleroma.UserTest do
test "approving an approved user does not trigger post-register actions" do
clear_config([:welcome, :email, :enabled], true)
- user = insert(:user, approval_pending: false)
+ user = insert(:user, is_approved: true)
User.approve(user)
ObanHelpers.perform_all()
@@ -1443,17 +1686,17 @@ defmodule Pleroma.UserTest do
describe "confirm" do
test "confirms a user" do
- user = insert(:user, confirmation_pending: true)
- assert true == user.confirmation_pending
+ user = insert(:user, is_confirmed: false)
+ refute user.is_confirmed
{:ok, user} = User.confirm(user)
- assert false == user.confirmation_pending
+ assert user.is_confirmed
end
test "confirms a list of users" do
unconfirmed_users = [
- insert(:user, confirmation_pending: true),
- insert(:user, confirmation_pending: true),
- insert(:user, confirmation_pending: true)
+ insert(:user, is_confirmed: false),
+ insert(:user, is_confirmed: false),
+ insert(:user, is_confirmed: false)
]
{:ok, users} = User.confirm(unconfirmed_users)
@@ -1461,13 +1704,13 @@ defmodule Pleroma.UserTest do
assert Enum.count(users) == 3
Enum.each(users, fn user ->
- assert false == user.confirmation_pending
+ assert user.is_confirmed
end)
end
- test "sends approval emails when `approval_pending: true`" do
+ test "sends approval emails when `is_approved: false`" do
admin = insert(:user, is_admin: true)
- user = insert(:user, confirmation_pending: true, approval_pending: true)
+ user = insert(:user, is_confirmed: false, is_approved: false)
User.confirm(user)
ObanHelpers.perform_all()
@@ -1494,7 +1737,7 @@ defmodule Pleroma.UserTest do
end
test "confirming a confirmed user does not trigger post-register actions" do
- user = insert(:user, confirmation_pending: false, approval_pending: true)
+ user = insert(:user, is_confirmed: true, is_approved: false)
User.confirm(user)
ObanHelpers.perform_all()
@@ -1544,7 +1787,7 @@ defmodule Pleroma.UserTest do
follower = User.get_cached_by_id(follower.id)
refute User.following?(follower, user)
- assert %{deactivated: true} = User.get_by_id(user.id)
+ assert %{is_active: false} = User.get_by_id(user.id)
assert [] == User.get_follow_requests(locked_user)
@@ -1563,35 +1806,19 @@ defmodule Pleroma.UserTest do
end
end
- describe "delete/1 when confirmation is pending" do
- setup do
- user = insert(:user, confirmation_pending: true)
- {:ok, user: user}
- end
-
- test "deletes user from database when activation required", %{user: user} do
- clear_config([:instance, :account_activation_required], true)
-
- {:ok, job} = User.delete(user)
- {:ok, _} = ObanHelpers.perform(job)
-
- refute User.get_cached_by_id(user.id)
- refute User.get_by_id(user.id)
- end
-
- test "deactivates user when activation is not required", %{user: user} do
- clear_config([:instance, :account_activation_required], false)
+ test "delete/1 when confirmation is pending deletes the user" do
+ clear_config([:instance, :account_activation_required], true)
+ user = insert(:user, is_confirmed: false)
- {:ok, job} = User.delete(user)
- {:ok, _} = ObanHelpers.perform(job)
+ {:ok, job} = User.delete(user)
+ {:ok, _} = ObanHelpers.perform(job)
- assert %{deactivated: true} = User.get_cached_by_id(user.id)
- assert %{deactivated: true} = User.get_by_id(user.id)
- end
+ refute User.get_cached_by_id(user.id)
+ refute User.get_by_id(user.id)
end
test "delete/1 when approval is pending deletes the user" do
- user = insert(:user, approval_pending: true)
+ user = insert(:user, is_approved: false)
{:ok, job} = User.delete(user)
{:ok, _} = ObanHelpers.perform(job)
@@ -1616,17 +1843,16 @@ defmodule Pleroma.UserTest do
follower_count: 9,
following_count: 9001,
is_locked: true,
- confirmation_pending: true,
+ is_confirmed: true,
password_reset_pending: true,
- approval_pending: true,
+ is_approved: true,
registration_reason: "ahhhhh",
confirmation_token: "qqqq",
domain_blocks: ["lain.com"],
- deactivated: true,
+ is_active: false,
ap_enabled: true,
is_moderator: true,
is_admin: true,
- mastofe_settings: %{"a" => "b"},
mascot: %{"a" => "b"},
emoji: %{"a" => "b"},
pleroma_settings_store: %{"q" => "x"},
@@ -1646,8 +1872,8 @@ defmodule Pleroma.UserTest do
email: nil,
name: nil,
password_hash: nil,
- keys: nil,
- public_key: nil,
+ keys: "RSA begin buplic key",
+ public_key: "--PRIVATE KEYE--",
avatar: %{},
tags: [],
last_refreshed_at: nil,
@@ -1658,17 +1884,16 @@ defmodule Pleroma.UserTest do
follower_count: 0,
following_count: 0,
is_locked: false,
- confirmation_pending: false,
+ is_confirmed: true,
password_reset_pending: false,
- approval_pending: false,
+ is_approved: true,
registration_reason: nil,
confirmation_token: nil,
domain_blocks: [],
- deactivated: true,
+ is_active: false,
ap_enabled: false,
is_moderator: false,
is_admin: false,
- mastofe_settings: nil,
mascot: nil,
emoji: %{},
pleroma_settings_store: %{},
@@ -1679,6 +1904,56 @@ defmodule Pleroma.UserTest do
} = user
end
+ test "delete/1 purges a remote user" do
+ user =
+ insert(:user, %{
+ name: "qqqqqqq",
+ avatar: %{"a" => "b"},
+ banner: %{"a" => "b"},
+ local: false
+ })
+
+ {:ok, job} = User.delete(user)
+ {:ok, _} = ObanHelpers.perform(job)
+ user = User.get_by_id(user.id)
+
+ assert user.name == nil
+ assert user.avatar == %{}
+ assert user.banner == %{}
+ end
+
+ 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
@@ -1728,14 +2003,14 @@ defmodule Pleroma.UserTest do
setup do: clear_config([:instance, :account_activation_required])
test "return confirmation_pending for unconfirm user" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
- user = insert(:user, confirmation_pending: true)
+ clear_config([:instance, :account_activation_required], true)
+ user = insert(:user, is_confirmed: false)
assert User.account_status(user) == :confirmation_pending
end
test "return active for confirmed user" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
- user = insert(:user, confirmation_pending: false)
+ clear_config([:instance, :account_activation_required], true)
+ user = insert(:user, is_confirmed: true)
assert User.account_status(user) == :active
end
@@ -1750,15 +2025,15 @@ defmodule Pleroma.UserTest do
end
test "returns :deactivated for deactivated user" do
- user = insert(:user, local: true, confirmation_pending: false, deactivated: true)
+ user = insert(:user, local: true, is_confirmed: true, is_active: false)
assert User.account_status(user) == :deactivated
end
test "returns :approval_pending for unapproved user" do
- user = insert(:user, local: true, approval_pending: true)
+ user = insert(:user, local: true, is_approved: false)
assert User.account_status(user) == :approval_pending
- user = insert(:user, local: true, confirmation_pending: true, approval_pending: true)
+ user = insert(:user, local: true, is_confirmed: false, is_approved: false)
assert User.account_status(user) == :approval_pending
end
end
@@ -1813,34 +2088,27 @@ defmodule Pleroma.UserTest do
end
test "returns false when the account is unconfirmed and confirmation is required" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_activation_required], true)
- user = insert(:user, local: true, confirmation_pending: true)
+ user = insert(:user, local: true, is_confirmed: false)
other_user = insert(:user, local: true)
refute User.visible_for(user, other_user) == :visible
end
test "returns true when the account is unconfirmed and confirmation is required but the account is remote" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
-
- user = insert(:user, local: false, confirmation_pending: true)
- other_user = insert(:user, local: true)
-
- assert User.visible_for(user, other_user) == :visible
- end
+ clear_config([:instance, :account_activation_required], true)
- test "returns true when the account is unconfirmed and confirmation is not required" do
- user = insert(:user, local: true, confirmation_pending: true)
+ user = insert(:user, local: false, is_confirmed: false)
other_user = insert(:user, local: true)
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
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_activation_required], true)
- user = insert(:user, local: true, confirmation_pending: true)
+ 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
@@ -1854,9 +2122,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
@@ -1908,7 +2174,7 @@ defmodule Pleroma.UserTest do
users =
Enum.map(1..total, fn _ ->
- insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false)
+ insert(:user, last_digest_emailed_at: days_ago(20), is_active: true)
end)
inactive_users_ids =
@@ -1926,7 +2192,7 @@ defmodule Pleroma.UserTest do
users =
Enum.map(1..total, fn _ ->
- insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false)
+ insert(:user, last_digest_emailed_at: days_ago(20), is_active: true)
end)
{inactive, active} = Enum.split(users, trunc(total / 2))
@@ -1959,7 +2225,7 @@ defmodule Pleroma.UserTest do
users =
Enum.map(1..total, fn _ ->
- insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false)
+ insert(:user, last_digest_emailed_at: days_ago(20), is_active: true)
end)
[sender | recipients] = users
@@ -1997,21 +2263,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)
@@ -2022,6 +2273,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
@@ -2029,7 +2291,7 @@ defmodule Pleroma.UserTest do
user1 = insert(:user, local: false, ap_id: "http://localhost:4001/users/masto_closed")
user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2")
insert(:user, local: true)
- insert(:user, local: false, deactivated: true)
+ insert(:user, local: false, is_active: false)
{:ok, user1: user1, user2: user2}
end
@@ -2089,13 +2351,33 @@ defmodule Pleroma.UserTest do
assert {:ok, user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
assert %User{bio: "test-bio"} = User.get_cached_by_ap_id(user.ap_id)
end
+
+ test "removes report notifs when user isn't superuser any more" do
+ report_activity = insert(:report_activity)
+ user = insert(:user, is_moderator: true, is_admin: true)
+ {:ok, _} = Notification.create_notifications(report_activity)
+
+ assert [%Pleroma.Notification{type: "pleroma:report"}] = Notification.for_user(user)
+
+ {:ok, user} = user |> User.admin_api_update(%{is_moderator: false})
+ # is still superuser because still admin
+ assert [%Pleroma.Notification{type: "pleroma:report"}] = Notification.for_user(user)
+
+ {:ok, user} = user |> User.admin_api_update(%{is_moderator: true, is_admin: false})
+ # is still superuser because still moderator
+ assert [%Pleroma.Notification{type: "pleroma:report"}] = Notification.for_user(user)
+
+ {:ok, user} = user |> User.admin_api_update(%{is_moderator: false})
+ # is not a superuser any more
+ assert [] = Notification.for_user(user)
+ end
end
describe "following/followers synchronization" do
setup do: clear_config([:instance, :external_user_synchronization])
test "updates the counters normally on following/getting a follow when disabled" do
- Pleroma.Config.put([:instance, :external_user_synchronization], false)
+ clear_config([:instance, :external_user_synchronization], false)
user = insert(:user)
other_user =
@@ -2115,8 +2397,8 @@ 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
- Pleroma.Config.put([:instance, :external_user_synchronization], false)
+ test "synchronizes the counters with the remote instance for the followed when enabled" do
+ clear_config([:instance, :external_user_synchronization], false)
user = insert(:user)
@@ -2131,14 +2413,14 @@ defmodule Pleroma.UserTest do
assert other_user.following_count == 0
assert other_user.follower_count == 0
- Pleroma.Config.put([:instance, :external_user_synchronization], true)
+ clear_config([:instance, :external_user_synchronization], true)
{:ok, _user, other_user} = User.follow(user, other_user)
assert other_user.follower_count == 437
end
- test "syncronizes the counters with the remote instance for the follower when enabled" do
- Pleroma.Config.put([:instance, :external_user_synchronization], false)
+ test "synchronizes the counters with the remote instance for the follower when enabled" do
+ clear_config([:instance, :external_user_synchronization], false)
user = insert(:user)
@@ -2153,7 +2435,7 @@ defmodule Pleroma.UserTest do
assert other_user.following_count == 0
assert other_user.follower_count == 0
- Pleroma.Config.put([:instance, :external_user_synchronization], true)
+ clear_config([:instance, :external_user_synchronization], true)
{:ok, other_user, _user} = User.follow(other_user, user)
assert other_user.following_count == 152
@@ -2165,11 +2447,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)
@@ -2185,6 +2496,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
@@ -2200,43 +2530,43 @@ defmodule Pleroma.UserTest do
test "allows getting remote users by id no matter what :limit_to_local_content is set to", %{
remote_user: remote_user
} do
- Pleroma.Config.put([:instance, :limit_to_local_content], false)
+ clear_config([:instance, :limit_to_local_content], false)
assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
- Pleroma.Config.put([:instance, :limit_to_local_content], true)
+ clear_config([:instance, :limit_to_local_content], true)
assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
- Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ clear_config([:instance, :limit_to_local_content], :unauthenticated)
assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
end
test "disallows getting remote users by nickname without authentication when :limit_to_local_content is set to :unauthenticated",
%{remote_user: remote_user} do
- Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ clear_config([:instance, :limit_to_local_content], :unauthenticated)
assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
end
test "allows getting remote users by nickname with authentication when :limit_to_local_content is set to :unauthenticated",
%{remote_user: remote_user, local_user: local_user} do
- Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ clear_config([:instance, :limit_to_local_content], :unauthenticated)
assert %User{} = User.get_cached_by_nickname_or_id(remote_user.nickname, for: local_user)
end
test "disallows getting remote users by nickname when :limit_to_local_content is set to true",
%{remote_user: remote_user} do
- Pleroma.Config.put([:instance, :limit_to_local_content], true)
+ clear_config([:instance, :limit_to_local_content], true)
assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
end
test "allows getting local users by nickname no matter what :limit_to_local_content is set to",
%{local_user: local_user} do
- Pleroma.Config.put([:instance, :limit_to_local_content], false)
+ clear_config([:instance, :limit_to_local_content], false)
assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
- Pleroma.Config.put([:instance, :limit_to_local_content], true)
+ clear_config([:instance, :limit_to_local_content], true)
assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
- Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ clear_config([:instance, :limit_to_local_content], :unauthenticated)
assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
end
end
@@ -2255,6 +2585,36 @@ defmodule Pleroma.UserTest do
end
end
+ describe "local_nickname/1" do
+ test "returns nickname without host" do
+ assert User.local_nickname("@mentioned") == "mentioned"
+ assert User.local_nickname("a_local_nickname") == "a_local_nickname"
+ assert User.local_nickname("nickname@host.com") == "nickname"
+ end
+ end
+
+ describe "full_nickname/1" do
+ test "returns fully qualified nickname for local and remote users" do
+ local_user =
+ insert(:user, nickname: "local_user", ap_id: "https://somehost.com/users/local_user")
+
+ remote_user = insert(:user, nickname: "remote@host.com", local: false)
+
+ assert User.full_nickname(local_user) == "local_user@somehost.com"
+ assert User.full_nickname(remote_user) == "remote@host.com"
+ end
+
+ test "strips leading @ from mentions" do
+ assert User.full_nickname("@mentioned") == "mentioned"
+ assert User.full_nickname("@nickname@host.com") == "nickname@host.com"
+ end
+
+ test "does not modify nicknames" do
+ assert User.full_nickname("nickname") == "nickname"
+ assert User.full_nickname("nickname@host.com") == "nickname@host.com"
+ end
+ end
+
test "avatar fallback" do
user = insert(:user)
assert User.avatar_url(user) =~ "/images/avi.png"
@@ -2271,4 +2631,202 @@ defmodule Pleroma.UserTest do
user = insert(:user, ap_id: "https://lain.com/users/lain", nickname: "lain")
assert User.get_host(user) == "lain.com"
end
+
+ test "update_last_active_at/1" do
+ user = insert(:user)
+ assert is_nil(user.last_active_at)
+
+ test_started_at = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
+
+ assert {:ok, user} = User.update_last_active_at(user)
+
+ assert user.last_active_at >= test_started_at
+ assert user.last_active_at <= NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
+
+ last_active_at =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.add(-:timer.hours(24), :millisecond)
+ |> NaiveDateTime.truncate(:second)
+
+ assert {:ok, user} =
+ user
+ |> cast(%{last_active_at: last_active_at}, [:last_active_at])
+ |> User.update_and_set_cache()
+
+ assert user.last_active_at == last_active_at
+ assert {:ok, user} = User.update_last_active_at(user)
+ assert user.last_active_at >= test_started_at
+ assert user.last_active_at <= NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
+ end
+
+ test "active_user_count/1" do
+ insert(:user)
+ insert(:user, %{local: false})
+ 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(180) == 3
+ assert User.active_user_count(365) == 4
+ assert User.active_user_count(1000) == 5
+ end
+
+ describe "pins" do
+ setup do
+ user = insert(:user)
+
+ [user: user, object_id: object_id_from_created_activity(user)]
+ end
+
+ test "unique pins", %{user: user, object_id: object_id} do
+ assert {:ok, %{pinned_objects: %{^object_id => pinned_at1} = pins} = updated_user} =
+ User.add_pinned_object_id(user, object_id)
+
+ assert Enum.count(pins) == 1
+
+ assert {:ok, %{pinned_objects: %{^object_id => pinned_at2} = pins}} =
+ User.add_pinned_object_id(updated_user, object_id)
+
+ assert pinned_at1 == pinned_at2
+
+ assert Enum.count(pins) == 1
+ end
+
+ test "respects max_pinned_statuses limit", %{user: user, object_id: object_id} do
+ clear_config([:instance, :max_pinned_statuses], 1)
+ {:ok, updated} = User.add_pinned_object_id(user, object_id)
+
+ object_id2 = object_id_from_created_activity(user)
+
+ {:error, %{errors: errors}} = User.add_pinned_object_id(updated, object_id2)
+ assert Keyword.has_key?(errors, :pinned_objects)
+ end
+
+ test "remove_pinned_object_id/2", %{user: user, object_id: object_id} do
+ assert {:ok, updated} = User.add_pinned_object_id(user, object_id)
+
+ {:ok, after_remove} = User.remove_pinned_object_id(updated, object_id)
+ assert after_remove.pinned_objects == %{}
+ end
+ end
+
+ defp object_id_from_created_activity(user) do
+ %{id: id} = insert(:note_activity, user: user)
+ %{object: %{data: %{"id" => object_id}}} = Activity.get_by_id_with_object(id)
+ object_id
+ end
+
+ 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 460f7e0b5..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-2020 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 0063d0482..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-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.ActivityPubControllerTest do
@@ -7,7 +7,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
use Oban.Testing, repo: Pleroma.Repo
alias Pleroma.Activity
- alias Pleroma.Config
alias Pleroma.Delivery
alias Pleroma.Instances
alias Pleroma.Object
@@ -46,7 +45,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
test "with the relay disabled, it returns 404", %{conn: conn} do
- Config.put([:instance, :allow_relay], false)
+ clear_config([:instance, :allow_relay], false)
conn
|> get(activity_pub_path(conn, :relay))
@@ -54,7 +53,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
test "on non-federating instance, it returns 404", %{conn: conn} do
- Config.put([:instance, :federating], false)
+ clear_config([:instance, :federating], false)
user = insert(:user)
conn
@@ -75,7 +74,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
test "on non-federating instance, it returns 404", %{conn: conn} do
- Config.put([:instance, :federating], false)
+ clear_config([:instance, :federating], false)
user = insert(:user)
conn
@@ -219,7 +218,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
- object = Object.normalize(post, false)
+ object = Object.normalize(post, fetch: false)
uuid = String.split(object.data["id"], "/") |> List.last()
conn =
@@ -230,6 +229,45 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 404)
end
+ test "returns local-only objects when authenticated", %{conn: conn} do
+ user = insert(:user)
+ {:ok, post} = CommonAPI.post(user, %{status: "test", 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, user)
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/objects/#{uuid}")
+
+ 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
@@ -274,6 +312,30 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 200) == ObjectView.render("object.json", %{object: note})
end
+ test "does not cache authenticated response", %{conn: conn} do
+ user = insert(:user)
+ reader = insert(:user)
+
+ {:ok, post} =
+ CommonAPI.post(user, %{status: "test @#{reader.nickname}", visibility: "local"})
+
+ 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, 200)
+
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/objects/#{uuid}")
+ |> json_response(404)
+ end
+
test "it returns 404 for non-public messages", %{conn: conn} do
note = insert(:direct_note)
uuid = String.split(note.data["id"], "/") |> List.last()
@@ -286,6 +348,28 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 404)
end
+ test "returns visible non-public messages when authenticated", %{conn: conn} do
+ note = insert(:direct_note)
+ uuid = String.split(note.data["id"], "/") |> List.last()
+ user = User.get_by_ap_id(note.data["actor"])
+ marisa = insert(:user)
+
+ assert conn
+ |> assign(:user, marisa)
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/objects/#{uuid}")
+ |> json_response(404)
+
+ assert response =
+ conn
+ |> assign(:user, user)
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/objects/#{uuid}")
+ |> json_response(200)
+
+ assert response == ObjectView.render("object.json", %{object: note})
+ end
+
test "it returns 404 for tombstone objects", %{conn: conn} do
tombstone = insert(:tombstone)
uuid = String.split(tombstone.data["id"], "/") |> List.last()
@@ -359,6 +443,23 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 404)
end
+ test "returns local-only activities when authenticated", %{conn: conn} do
+ user = insert(:user)
+ {:ok, post} = CommonAPI.post(user, %{status: "test", visibility: "local"})
+
+ assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
+
+ uuid = String.split(post.data["id"], "/") |> List.last()
+
+ assert response =
+ conn
+ |> assign(:user, user)
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/activities/#{uuid}")
+
+ assert json_response(response, 200) == ObjectView.render("object.json", %{object: post})
+ end
+
test "it returns a json representation of the activity", %{conn: conn} do
activity = insert(:note_activity)
uuid = String.split(activity.data["id"], "/") |> List.last()
@@ -383,6 +484,28 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 404)
end
+ test "returns visible non-public messages when authenticated", %{conn: conn} do
+ note = insert(:direct_note_activity)
+ uuid = String.split(note.data["id"], "/") |> List.last()
+ user = User.get_by_ap_id(note.data["actor"])
+ marisa = insert(:user)
+
+ assert conn
+ |> assign(:user, marisa)
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/activities/#{uuid}")
+ |> json_response(404)
+
+ assert response =
+ conn
+ |> assign(:user, user)
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/activities/#{uuid}")
+ |> json_response(200)
+
+ assert response == ObjectView.render("object.json", %{object: note})
+ end
+
test "it caches a response", %{conn: conn} do
activity = insert(:note_activity)
uuid = String.split(activity.data["id"], "/") |> List.last()
@@ -461,7 +584,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
File.read!("test/fixtures/mastodon-post-activity.json")
|> Jason.decode!()
|> Map.put("actor", user.ap_id)
- |> put_in(["object", "attridbutedTo"], user.ap_id)
+ |> put_in(["object", "attributedTo"], user.ap_id)
conn =
conn
@@ -493,7 +616,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
test "accept follow activity", %{conn: conn} do
- Pleroma.Config.put([:instance, :federating], true)
+ clear_config([:instance, :federating], true)
relay = Relay.get_actor()
assert {:ok, %Activity{} = activity} = Relay.follow("https://relay.mastodon.host/actor")
@@ -539,7 +662,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
conn = put_req_header(conn, "content-type", "application/activity+json")
- Config.put([:instance, :federating], false)
+ clear_config([:instance, :federating], false)
conn
|> post("/inbox", data)
@@ -549,7 +672,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> post("/inbox", non_create_data)
|> json_response(403)
- Config.put([:instance, :federating], true)
+ clear_config([:instance, :federating], true)
ret_conn = post(conn, "/inbox", data)
assert "ok" == json_response(ret_conn, 200)
@@ -558,6 +681,186 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> post("/inbox", non_create_data)
|> json_response(400)
end
+
+ test "accepts Add/Remove activities", %{conn: conn} do
+ object_id = "c61d6733-e256-4fe1-ab13-1e369789423f"
+
+ status =
+ File.read!("test/fixtures/statuses/note.json")
+ |> String.replace("{{nickname}}", "lain")
+ |> String.replace("{{object_id}}", object_id)
+
+ object_url = "https://example.com/objects/#{object_id}"
+
+ user =
+ File.read!("test/fixtures/users_mock/user.json")
+ |> String.replace("{{nickname}}", "lain")
+
+ actor = "https://example.com/users/lain"
+
+ Tesla.Mock.mock(fn
+ %{
+ method: :get,
+ url: ^object_url
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: status,
+ headers: [{"content-type", "application/activity+json"}]
+ }
+
+ %{
+ method: :get,
+ url: ^actor
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: user,
+ headers: [{"content-type", "application/activity+json"}]
+ }
+
+ %{method: :get, url: "https://example.com/users/lain/collections/featured"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/users_mock/masto_featured.json"
+ |> File.read!()
+ |> String.replace("{{domain}}", "example.com")
+ |> String.replace("{{nickname}}", "lain"),
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ data = %{
+ "id" => "https://example.com/objects/d61d6733-e256-4fe1-ab13-1e369789423f",
+ "actor" => actor,
+ "object" => object_url,
+ "target" => "https://example.com/users/lain/collections/featured",
+ "type" => "Add",
+ "to" => [Pleroma.Constants.as_public()]
+ }
+
+ assert "ok" ==
+ conn
+ |> assign(:valid_signature, true)
+ |> put_req_header("content-type", "application/activity+json")
+ |> post("/inbox", data)
+ |> json_response(200)
+
+ ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
+ assert Activity.get_by_ap_id(data["id"])
+ user = User.get_cached_by_ap_id(data["actor"])
+ assert user.pinned_objects[data["object"]]
+
+ data = %{
+ "id" => "https://example.com/objects/d61d6733-e256-4fe1-ab13-1e369789423d",
+ "actor" => actor,
+ "object" => object_url,
+ "target" => "https://example.com/users/lain/collections/featured",
+ "type" => "Remove",
+ "to" => [Pleroma.Constants.as_public()]
+ }
+
+ assert "ok" ==
+ conn
+ |> assign(:valid_signature, true)
+ |> put_req_header("content-type", "application/activity+json")
+ |> post("/inbox", data)
+ |> json_response(200)
+
+ ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
+ user = refresh_record(user)
+ refute user.pinned_objects[data["object"]]
+ end
+
+ test "mastodon pin/unpin", %{conn: conn} do
+ status_id = "105786274556060421"
+
+ status =
+ File.read!("test/fixtures/statuses/masto-note.json")
+ |> String.replace("{{nickname}}", "lain")
+ |> String.replace("{{status_id}}", status_id)
+
+ status_url = "https://example.com/users/lain/statuses/#{status_id}"
+
+ user =
+ File.read!("test/fixtures/users_mock/user.json")
+ |> String.replace("{{nickname}}", "lain")
+
+ actor = "https://example.com/users/lain"
+
+ Tesla.Mock.mock(fn
+ %{
+ method: :get,
+ url: ^status_url
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: status,
+ headers: [{"content-type", "application/activity+json"}]
+ }
+
+ %{
+ method: :get,
+ url: ^actor
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: user,
+ headers: [{"content-type", "application/activity+json"}]
+ }
+
+ %{method: :get, url: "https://example.com/users/lain/collections/featured"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/users_mock/masto_featured.json"
+ |> File.read!()
+ |> String.replace("{{domain}}", "example.com")
+ |> String.replace("{{nickname}}", "lain"),
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ data = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "actor" => actor,
+ "object" => status_url,
+ "target" => "https://example.com/users/lain/collections/featured",
+ "type" => "Add"
+ }
+
+ assert "ok" ==
+ conn
+ |> assign(:valid_signature, true)
+ |> put_req_header("content-type", "application/activity+json")
+ |> post("/inbox", data)
+ |> json_response(200)
+
+ ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
+ assert Activity.get_by_object_ap_id_with_object(data["object"])
+ user = User.get_cached_by_ap_id(data["actor"])
+ assert user.pinned_objects[data["object"]]
+
+ data = %{
+ "actor" => actor,
+ "object" => status_url,
+ "target" => "https://example.com/users/lain/collections/featured",
+ "type" => "Remove"
+ }
+
+ assert "ok" ==
+ conn
+ |> assign(:valid_signature, true)
+ |> put_req_header("content-type", "application/activity+json")
+ |> post("/inbox", data)
+ |> json_response(200)
+
+ ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
+ assert Activity.get_by_object_ap_id_with_object(data["object"])
+ user = refresh_record(user)
+ refute user.pinned_objects[data["object"]]
+ end
end
describe "/users/:nickname/inbox" do
@@ -571,7 +874,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it inserts an incoming activity into the database", %{conn: conn, data: data} do
user = insert(:user)
- data = Map.put(data, "bcc", [user.ap_id])
+
+ data =
+ data
+ |> Map.put("bcc", [user.ap_id])
+ |> Kernel.put_in(["object", "bcc"], [user.ap_id])
conn =
conn
@@ -588,8 +895,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
user = insert(:user)
data =
- Map.put(data, "to", user.ap_id)
- |> Map.delete("cc")
+ data
+ |> Map.put("to", user.ap_id)
+ |> Map.put("cc", [])
+ |> Kernel.put_in(["object", "to"], user.ap_id)
+ |> Kernel.put_in(["object", "cc"], [])
conn =
conn
@@ -606,8 +916,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
user = insert(:user)
data =
- Map.put(data, "cc", user.ap_id)
- |> Map.delete("to")
+ data
+ |> Map.put("to", [])
+ |> Map.put("cc", user.ap_id)
+ |> Kernel.put_in(["object", "to"], [])
+ |> Kernel.put_in(["object", "cc"], user.ap_id)
conn =
conn
@@ -625,9 +938,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
user = insert(:user)
data =
- Map.put(data, "bcc", user.ap_id)
- |> Map.delete("to")
- |> Map.delete("cc")
+ data
+ |> Map.put("to", [])
+ |> Map.put("cc", [])
+ |> Map.put("bcc", user.ap_id)
+ |> Kernel.put_in(["object", "to"], [])
+ |> Kernel.put_in(["object", "cc"], [])
+ |> Kernel.put_in(["object", "bcc"], user.ap_id)
conn =
conn
@@ -712,7 +1029,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it returns a note activity in a collection", %{conn: conn} do
note_activity = insert(:direct_note_activity)
- note_object = Object.normalize(note_activity)
+ note_object = Object.normalize(note_activity, fetch: false)
user = User.get_cached_by_ap_id(hd(note_activity.data["to"]))
conn =
@@ -742,29 +1059,34 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert Instances.reachable?(sender_host)
end
+ @tag capture_log: true
test "it removes all follower collections but actor's", %{conn: conn} do
[actor, recipient] = insert_pair(:user)
- data =
- File.read!("test/fixtures/activitypub-client-post-activity.json")
- |> Jason.decode!()
+ to = [
+ recipient.ap_id,
+ recipient.follower_address,
+ "https://www.w3.org/ns/activitystreams#Public"
+ ]
- object = Map.put(data["object"], "attributedTo", actor.ap_id)
+ cc = [recipient.follower_address, actor.follower_address]
- data =
- data
- |> Map.put("id", Utils.generate_object_id())
- |> Map.put("actor", actor.ap_id)
- |> Map.put("object", object)
- |> Map.put("cc", [
- recipient.follower_address,
- actor.follower_address
- ])
- |> Map.put("to", [
- recipient.ap_id,
- recipient.follower_address,
- "https://www.w3.org/ns/activitystreams#Public"
- ])
+ data = %{
+ "@context" => ["https://www.w3.org/ns/activitystreams"],
+ "type" => "Create",
+ "id" => Utils.generate_activity_id(),
+ "to" => to,
+ "cc" => cc,
+ "actor" => actor.ap_id,
+ "object" => %{
+ "type" => "Note",
+ "to" => to,
+ "cc" => cc,
+ "content" => "It's a note",
+ "attributedTo" => actor.ap_id,
+ "id" => Utils.generate_object_id()
+ }
+ }
conn
|> assign(:valid_signature, true)
@@ -774,7 +1096,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
- activity = Activity.get_by_ap_id(data["id"])
+ assert activity = Activity.get_by_ap_id(data["id"])
assert activity.id
assert actor.follower_address in activity.recipients
@@ -906,7 +1228,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
"actor" => remote_actor,
"content" => "test report",
"id" => "https://#{remote_domain}/e3b12fd1-948c-446e-b93b-a5e67edbe1d8",
- "nickname" => reported_user.nickname,
"object" => [
reported_user.ap_id,
note.data["object"]
@@ -997,9 +1318,38 @@ 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)
+ note_object = Object.normalize(note_activity, fetch: false)
user = User.get_cached_by_ap_id(note_activity.data["actor"])
conn =
@@ -1023,6 +1373,31 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert response(conn, 200) =~ announce_activity.data["object"]
end
+
+ test "It returns poll Answers when authenticated", %{conn: conn} do
+ poller = insert(:user)
+ voter = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(poller, %{
+ status: "suya...",
+ poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
+ })
+
+ assert question = Object.normalize(activity, fetch: false)
+
+ {:ok, [activity], _object} = CommonAPI.vote(voter, question, [1])
+
+ assert outbox_get =
+ conn
+ |> assign(:user, voter)
+ |> put_req_header("accept", "application/activity+json")
+ |> get(voter.ap_id <> "/outbox?page=true")
+ |> json_response(200)
+
+ assert [answer_outbox] = outbox_get["orderedItems"]
+ assert answer_outbox["id"] == activity.data["id"]
+ end
end
describe "POST /users/:nickname/outbox (C2S)" do
@@ -1033,9 +1408,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
activity: %{
"@context" => "https://www.w3.org/ns/activitystreams",
"type" => "Create",
- "object" => %{"type" => "Note", "content" => "AP C2S test"},
- "to" => "https://www.w3.org/ns/activitystreams#Public",
- "cc" => []
+ "object" => %{
+ "type" => "Note",
+ "content" => "AP C2S test",
+ "to" => "https://www.w3.org/ns/activitystreams#Public",
+ "cc" => []
+ }
}
]
end
@@ -1073,7 +1451,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert Activity.get_by_ap_id(result["id"])
assert result["object"]
- assert %Object{data: object} = Object.normalize(result["object"])
+ assert %Object{data: object} = Object.normalize(result["object"], fetch: false)
assert object["content"] == activity["object"]["content"]
end
@@ -1109,7 +1487,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert Activity.get_by_ap_id(response["id"])
assert response["object"]
- assert %Object{data: response_object} = Object.normalize(response["object"])
+ assert %Object{data: response_object} = Object.normalize(response["object"], fetch: false)
assert response_object["sensitive"] == true
assert response_object["content"] == activity["object"]["content"]
@@ -1137,23 +1515,23 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it erects a tombstone when receiving a delete activity", %{conn: conn} do
note_activity = insert(:note_activity)
- note_object = Object.normalize(note_activity)
+ note_object = Object.normalize(note_activity, fetch: false)
user = User.get_cached_by_ap_id(note_activity.data["actor"])
data = %{
- type: "Delete",
- object: %{
- id: note_object.data["id"]
+ "type" => "Delete",
+ "object" => %{
+ "id" => note_object.data["id"]
}
}
- conn =
+ result =
conn
|> assign(:user, user)
|> put_req_header("content-type", "application/activity+json")
|> post("/users/#{user.nickname}/outbox", data)
+ |> json_response(201)
- result = json_response(conn, 201)
assert Activity.get_by_ap_id(result["id"])
assert object = Object.get_by_ap_id(note_object.data["id"])
@@ -1162,7 +1540,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it rejects delete activity of object from other actor", %{conn: conn} do
note_activity = insert(:note_activity)
- note_object = Object.normalize(note_activity)
+ note_object = Object.normalize(note_activity, fetch: false)
user = insert(:user)
data = %{
@@ -1178,12 +1556,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> put_req_header("content-type", "application/activity+json")
|> post("/users/#{user.nickname}/outbox", data)
- assert json_response(conn, 400)
+ assert json_response(conn, 403)
end
test "it increases like count when receiving a like action", %{conn: conn} do
note_activity = insert(:note_activity)
- note_object = Object.normalize(note_activity)
+ note_object = Object.normalize(note_activity, fetch: false)
user = User.get_cached_by_ap_id(note_activity.data["actor"])
data = %{
@@ -1240,13 +1618,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert cirno_outbox["attributedTo"] == nil
assert cirno_outbox["actor"] == cirno.ap_id
- assert cirno_object = Object.normalize(cirno_outbox["object"])
+ assert cirno_object = Object.normalize(cirno_outbox["object"], fetch: false)
assert cirno_object.data["actor"] == cirno.ap_id
assert cirno_object.data["attributedTo"] == cirno.ap_id
end
test "Character limitation", %{conn: conn, activity: activity} do
- Pleroma.Config.put([:instance, :limit], 5)
+ clear_config([:instance, :limit], 5)
user = insert(:user)
result =
@@ -1256,7 +1634,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> post("/users/#{user.nickname}/outbox", activity)
|> json_response(400)
- assert result == "Note is over the character limit"
+ assert result == "Character limit (5 characters) exceeded, contains 11 characters"
end
end
@@ -1275,7 +1653,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
test "on non-federating instance, it returns 404", %{conn: conn} do
- Config.put([:instance, :federating], false)
+ clear_config([:instance, :federating], false)
user = insert(:user)
conn
@@ -1296,7 +1674,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
test "on non-federating instance, it returns 404", %{conn: conn} do
- Config.put([:instance, :federating], false)
+ clear_config([:instance, :federating], false)
user = insert(:user)
conn
@@ -1503,7 +1881,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it tracks a signed object fetch", %{conn: conn} do
user = insert(:user, local: false)
activity = insert(:note_activity)
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url())
@@ -1519,7 +1897,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it tracks a signed activity fetch", %{conn: conn} do
user = insert(:user, local: false)
activity = insert(:note_activity)
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
activity_path = String.trim_leading(activity.data["id"], Pleroma.Web.Endpoint.url())
@@ -1536,7 +1914,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
user = insert(:user, local: false)
other_user = insert(:user, local: false)
activity = insert(:note_activity)
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url())
@@ -1560,7 +1938,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
user = insert(:user, local: false)
other_user = insert(:user, local: false)
activity = insert(:note_activity)
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
activity_path = String.trim_leading(activity.data["id"], Pleroma.Web.Endpoint.url())
@@ -1608,9 +1986,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
desc = "Description of the image"
image = %Plug.Upload{
- content_type: "bad/content-type",
+ content_type: "image/jpeg",
path: Path.absname("test/fixtures/image.jpg"),
- filename: "an_image.png"
+ filename: "an_image.jpg"
}
object =
@@ -1633,10 +2011,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
"object" => %{
"type" => "Note",
"content" => "AP C2S test, attachment",
- "attachment" => [object]
- },
- "to" => "https://www.w3.org/ns/activitystreams#Public",
- "cc" => []
+ "attachment" => [object],
+ "to" => "https://www.w3.org/ns/activitystreams#Public",
+ "cc" => []
+ }
}
activity_response =
@@ -1650,7 +2028,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert activity_response["actor"] == user.ap_id
assert %Object{data: %{"attachment" => [attachment]}} =
- Object.normalize(activity_response["object"])
+ Object.normalize(activity_response["object"], fetch: false)
assert attachment["type"] == "Document"
assert attachment["name"] == desc
@@ -1669,4 +2047,29 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> json_response(403)
end
end
+
+ test "pinned collection", %{conn: conn} do
+ clear_config([:instance, :max_pinned_statuses], 2)
+ user = insert(:user)
+ objects = insert_list(2, :note, user: user)
+
+ Enum.reduce(objects, user, fn %{data: %{"id" => object_id}}, user ->
+ {:ok, updated} = User.add_pinned_object_id(user, object_id)
+ updated
+ end)
+
+ %{nickname: nickname, featured_address: featured_address, pinned_objects: pinned_objects} =
+ refresh_record(user)
+
+ %{"id" => ^featured_address, "orderedItems" => items, "totalItems" => 2} =
+ conn
+ |> get("/users/#{nickname}/collections/featured")
+ |> json_response(200)
+
+ object_ids = Enum.map(items, & &1["id"])
+
+ assert Enum.all?(pinned_objects, fn {obj_id, _} ->
+ obj_id in object_ids
+ end)
+ end
end
diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs
index 9eb7ae86b..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-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.ActivityPubTest do
@@ -190,37 +190,288 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert user.accepts_chat_messages
end
+
+ test "works for guppe actors" do
+ user_id = "https://gup.pe/u/bernie2020"
+
+ Tesla.Mock.mock(fn
+ %{method: :get, url: ^user_id} ->
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/guppe-actor.json"),
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ {:ok, user} = ActivityPub.make_user_from_ap_id(user_id)
+
+ assert user.name == "Bernie2020 group"
+ assert user.actor_type == "Group"
+ end
+
+ test "works for bridgy actors" do
+ user_id = "https://fed.brid.gy/jk.nipponalba.scot"
+
+ Tesla.Mock.mock(fn
+ %{method: :get, url: ^user_id} ->
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/bridgy/actor.json"),
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ {:ok, user} = ActivityPub.make_user_from_ap_id(user_id)
+
+ assert user.actor_type == "Person"
+
+ assert user.avatar == %{
+ "type" => "Image",
+ "url" => [%{"href" => "https://jk.nipponalba.scot/images/profile.jpg"}]
+ }
+
+ assert user.banner == %{
+ "type" => "Image",
+ "url" => [%{"href" => "https://jk.nipponalba.scot/images/profile.jpg"}]
+ }
+ end
+
+ test "fetches user featured collection" do
+ ap_id = "https://example.com/users/lain"
+
+ featured_url = "https://example.com/users/lain/collections/featured"
+
+ user_data =
+ "test/fixtures/users_mock/user.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", "lain")
+ |> Jason.decode!()
+ |> Map.put("featured", featured_url)
+ |> Jason.encode!()
+
+ object_id = Ecto.UUID.generate()
+
+ featured_data =
+ "test/fixtures/mastodon/collections/featured.json"
+ |> File.read!()
+ |> String.replace("{{domain}}", "example.com")
+ |> String.replace("{{nickname}}", "lain")
+ |> String.replace("{{object_id}}", object_id)
+
+ object_url = "https://example.com/objects/#{object_id}"
+
+ object_data =
+ "test/fixtures/statuses/note.json"
+ |> File.read!()
+ |> String.replace("{{object_id}}", object_id)
+ |> String.replace("{{nickname}}", "lain")
+
+ Tesla.Mock.mock(fn
+ %{
+ method: :get,
+ url: ^ap_id
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: user_data,
+ headers: [{"content-type", "application/activity+json"}]
+ }
+
+ %{
+ method: :get,
+ url: ^featured_url
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: featured_data,
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ Tesla.Mock.mock_global(fn
+ %{
+ method: :get,
+ url: ^object_url
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: object_data,
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ {:ok, user} = ActivityPub.make_user_from_ap_id(ap_id)
+ Process.sleep(50)
+
+ assert user.featured_address == featured_url
+ assert Map.has_key?(user.pinned_objects, object_url)
+
+ in_db = Pleroma.User.get_by_ap_id(ap_id)
+ assert in_db.featured_address == featured_url
+ assert Map.has_key?(user.pinned_objects, object_url)
+
+ assert %{data: %{"id" => ^object_url}} = Object.get_by_ap_id(object_url)
+ end
+
+ 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
user = insert(:user)
- {:ok, status_one} = CommonAPI.post(user, %{status: ". #test"})
+ {:ok, status_one} = CommonAPI.post(user, %{status: ". #TEST"})
{:ok, status_two} = CommonAPI.post(user, %{status: ". #essais"})
- {:ok, status_three} = CommonAPI.post(user, %{status: ". #test #reject"})
+ {:ok, status_three} = CommonAPI.post(user, %{status: ". #test #Reject"})
- fetch_one = ActivityPub.fetch_activities([], %{type: "Create", tag: "test"})
+ {:ok, status_four} = CommonAPI.post(user, %{status: ". #Any1 #any2"})
+ {:ok, status_five} = CommonAPI.post(user, %{status: ". #Any2 #any1"})
- fetch_two = ActivityPub.fetch_activities([], %{type: "Create", tag: ["test", "essais"]})
+ for hashtag_timeline_strategy <- [:enabled, :disabled] do
+ clear_config([:features, :improved_hashtag_timeline], hashtag_timeline_strategy)
- fetch_three =
- ActivityPub.fetch_activities([], %{
- type: "Create",
- tag: ["test", "essais"],
- tag_reject: ["reject"]
- })
+ fetch_one = ActivityPub.fetch_activities([], %{type: "Create", tag: "test"})
- fetch_four =
- ActivityPub.fetch_activities([], %{
- type: "Create",
- tag: ["test"],
- tag_all: ["test", "reject"]
- })
+ fetch_two = ActivityPub.fetch_activities([], %{type: "Create", tag: ["TEST", "essais"]})
+
+ fetch_three =
+ ActivityPub.fetch_activities([], %{
+ type: "Create",
+ tag: ["test", "Essais"],
+ tag_reject: ["reject"]
+ })
- assert fetch_one == [status_one, status_three]
- assert fetch_two == [status_one, status_two, status_three]
- assert fetch_three == [status_one, status_two]
- assert fetch_four == [status_three]
+ fetch_four =
+ ActivityPub.fetch_activities([], %{
+ type: "Create",
+ tag: ["test"],
+ tag_all: ["test", "REJECT"]
+ })
+
+ # Testing that deduplication (if needed) is done on DB (not Ecto) level; :limit is important
+ fetch_five =
+ ActivityPub.fetch_activities([], %{
+ type: "Create",
+ tag: ["ANY1", "any2"],
+ limit: 2
+ })
+
+ fetch_six =
+ ActivityPub.fetch_activities([], %{
+ type: "Create",
+ tag: ["any1", "Any2"],
+ tag_all: [],
+ tag_reject: []
+ })
+
+ # Regression test: passing empty lists as filter options shouldn't affect the results
+ assert fetch_five == fetch_six
+
+ [fetch_one, fetch_two, fetch_three, fetch_four, fetch_five] =
+ Enum.map([fetch_one, fetch_two, fetch_three, fetch_four, fetch_five], fn statuses ->
+ Enum.map(statuses, fn s -> Repo.preload(s, object: :hashtags) end)
+ end)
+
+ assert fetch_one == [status_one, status_three]
+ assert fetch_two == [status_one, status_two, status_three]
+ assert fetch_three == [status_one, status_two]
+ assert fetch_four == [status_three]
+ assert fetch_five == [status_four, status_five]
+ end
end
describe "insertion" do
@@ -303,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
@@ -321,12 +571,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
}
{:ok, %Activity{} = activity} = ActivityPub.insert(data)
- object = Pleroma.Object.normalize(activity)
+ object = Pleroma.Object.normalize(activity, fetch: false)
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
@@ -344,7 +592,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
}
{:ok, %Activity{} = activity} = ActivityPub.insert(data)
- assert object = Object.normalize(activity)
+ assert object = Object.normalize(activity, fetch: false)
assert is_binary(object.data["id"])
end
end
@@ -622,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)
@@ -678,7 +952,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
{:ok, activity_two} = CommonAPI.post(blockee, %{status: "hey! @#{friend.nickname}"})
- assert object = Pleroma.Object.normalize(activity_two)
+ assert object = Pleroma.Object.normalize(activity_two, fetch: false)
data = %{
"actor" => friend.ap_id,
@@ -721,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"})
@@ -1061,15 +1350,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
test "it sets the default description depending on the configuration", %{test_file: file} do
clear_config([Pleroma.Upload, :default_description])
- Pleroma.Config.put([Pleroma.Upload, :default_description], nil)
+ clear_config([Pleroma.Upload, :default_description], nil)
{:ok, %Object{} = object} = ActivityPub.upload(file)
assert object.data["name"] == ""
- Pleroma.Config.put([Pleroma.Upload, :default_description], :filename)
+ clear_config([Pleroma.Upload, :default_description], :filename)
{:ok, %Object{} = object} = ActivityPub.upload(file)
assert object.data["name"] == "an_image.jpg"
- Pleroma.Config.put([Pleroma.Upload, :default_description], "unnamed attachment")
+ clear_config([Pleroma.Upload, :default_description], "unnamed attachment")
{:ok, %Object{} = object} = ActivityPub.upload(file)
assert object.data["name"] == "unnamed attachment"
end
@@ -1215,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)
@@ -1226,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
@@ -1239,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
@@ -1255,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" =>
@@ -1279,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,
@@ -1293,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
@@ -1320,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
@@ -1373,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,
@@ -1544,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,
@@ -1577,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 e7370d4ef..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-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.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 49bbc271d..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-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.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 6867c9853..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-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.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 19ea491c0..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-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.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
new file mode 100644
index 000000000..248190034
--- /dev/null
+++ b/test/pleroma/web/activity_pub/mrf/follow_bot_policy_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.ActivityPub.MRF.FollowBotPolicyTest do
+ use Pleroma.DataCase, async: true
+
+ alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.MRF.FollowBotPolicy
+
+ import Pleroma.Factory
+
+ describe "FollowBotPolicy" do
+ test "follows remote users" do
+ bot = insert(:user, actor_type: "Service")
+ remote_user = insert(:user, local: false)
+ clear_config([:mrf_follow_bot, :follower_nickname], bot.nickname)
+
+ message = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "to" => [remote_user.follower_address],
+ "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "type" => "Create",
+ "object" => %{
+ "content" => "Test post",
+ "type" => "Note",
+ "attributedTo" => remote_user.ap_id,
+ "inReplyTo" => nil
+ },
+ "actor" => remote_user.ap_id
+ }
+
+ refute User.following?(bot, remote_user)
+
+ assert User.get_follow_requests(remote_user) |> length == 0
+
+ FollowBotPolicy.filter(message)
+
+ assert User.get_follow_requests(remote_user) |> length == 1
+ end
+
+ test "does not follow users with #nobot in bio" do
+ bot = insert(:user, actor_type: "Service")
+ remote_user = insert(:user, %{local: false, bio: "go away bots! #nobot"})
+ clear_config([:mrf_follow_bot, :follower_nickname], bot.nickname)
+
+ message = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "to" => [remote_user.follower_address],
+ "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "type" => "Create",
+ "object" => %{
+ "content" => "I don't like follow bots",
+ "type" => "Note",
+ "attributedTo" => remote_user.ap_id,
+ "inReplyTo" => nil
+ },
+ "actor" => remote_user.ap_id
+ }
+
+ refute User.following?(bot, remote_user)
+
+ assert User.get_follow_requests(remote_user) |> length == 0
+
+ FollowBotPolicy.filter(message)
+
+ assert User.get_follow_requests(remote_user) |> length == 0
+ end
+
+ test "does not follow local users" do
+ bot = insert(:user, actor_type: "Service")
+ local_user = insert(:user, local: true)
+ clear_config([:mrf_follow_bot, :follower_nickname], bot.nickname)
+
+ message = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "to" => [local_user.follower_address],
+ "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "type" => "Create",
+ "object" => %{
+ "content" => "Hi I'm a local user",
+ "type" => "Note",
+ "attributedTo" => local_user.ap_id,
+ "inReplyTo" => nil
+ },
+ "actor" => local_user.ap_id
+ }
+
+ refute User.following?(bot, local_user)
+
+ assert User.get_follow_requests(local_user) |> length == 0
+
+ FollowBotPolicy.filter(message)
+
+ assert User.get_follow_requests(local_user) |> length == 0
+ end
+
+ test "does not follow users requiring follower approval" do
+ bot = insert(:user, actor_type: "Service")
+ remote_user = insert(:user, %{local: false, is_locked: true})
+ clear_config([:mrf_follow_bot, :follower_nickname], bot.nickname)
+
+ message = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "to" => [remote_user.follower_address],
+ "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "type" => "Create",
+ "object" => %{
+ "content" => "I don't like randos following me",
+ "type" => "Note",
+ "attributedTo" => remote_user.ap_id,
+ "inReplyTo" => nil
+ },
+ "actor" => remote_user.ap_id
+ }
+
+ refute User.following?(bot, remote_user)
+
+ assert User.get_follow_requests(remote_user) |> length == 0
+
+ FollowBotPolicy.filter(message)
+
+ assert User.get_follow_requests(remote_user) |> length == 0
+ end
+ end
+end
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 b5f401ad2..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-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.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
new file mode 100644
index 000000000..32991c966
--- /dev/null
+++ b/test/pleroma/web/activity_pub/mrf/hashtag_policy_test.exs
@@ -0,0 +1,101 @@
+# 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.HashtagPolicyTest do
+ use Oban.Testing, repo: Pleroma.Repo
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.ActivityPub.Transmogrifier
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+
+ test "it sets the sensitive property with relevant hashtags" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "#nsfw hey"})
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
+
+ assert modified["object"]["sensitive"]
+ end
+
+ test "it 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)
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "#cofe hey"})
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
+
+ refute modified["object"]["sensitive"]
+ end
+end
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 26f5bcdaa..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-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.MRF.HellthreadPolicyTest do
@@ -34,7 +34,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
setup do: clear_config(:mrf_hellthread)
test "doesn't die on chat messages" do
- Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
+ clear_config([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
user = insert(:user)
other_user = insert(:user)
@@ -48,7 +48,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
test "rejects the message if the recipient count is above reject_threshold", %{
message: message
} do
- Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
+ clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
assert {:reject, "[HellthreadPolicy] 3 recipients is over the limit of 2"} ==
filter(message)
@@ -57,7 +57,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
test "does not reject the message if the recipient count is below reject_threshold", %{
message: message
} do
- Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
+ clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
assert {:ok, ^message} = filter(message)
end
@@ -68,7 +68,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
user: user,
message: message
} do
- Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
+ clear_config([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
{:ok, message} = filter(message)
assert user.follower_address in message["to"]
@@ -78,14 +78,14 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
test "does not delist the message if the recipient count is below delist_threshold", %{
message: message
} do
- Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 4, reject_threshold: 0})
+ clear_config([:mrf_hellthread], %{delist_threshold: 4, reject_threshold: 0})
assert {:ok, ^message} = filter(message)
end
end
test "excludes follower collection and public URI from threshold count", %{message: message} do
- Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
+ clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
assert {:ok, ^message} = filter(message)
end
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 b3d0f3d90..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-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.MRF.KeywordPolicyTest do
@@ -10,12 +10,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
setup do: clear_config(:mrf_keyword)
setup do
- Pleroma.Config.put([:mrf_keyword], %{reject: [], federated_timeline_removal: [], replace: []})
+ clear_config([:mrf_keyword], %{reject: [], federated_timeline_removal: [], replace: []})
end
describe "rejecting based on keywords" do
test "rejects if string matches in content" do
- Pleroma.Config.put([:mrf_keyword, :reject], ["pun"])
+ clear_config([:mrf_keyword, :reject], ["pun"])
message = %{
"type" => "Create",
@@ -30,7 +30,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
end
test "rejects if string matches in summary" do
- Pleroma.Config.put([:mrf_keyword, :reject], ["pun"])
+ clear_config([:mrf_keyword, :reject], ["pun"])
message = %{
"type" => "Create",
@@ -45,7 +45,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
end
test "rejects if regex matches in content" do
- Pleroma.Config.put([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/])
+ clear_config([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/])
assert true ==
Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
@@ -63,7 +63,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
end
test "rejects if regex matches in summary" do
- Pleroma.Config.put([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/])
+ clear_config([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/])
assert true ==
Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
@@ -79,11 +79,59 @@ 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
test "delists if string matches in content" do
- Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], ["pun"])
+ clear_config([:mrf_keyword, :federated_timeline_removal], ["pun"])
message = %{
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
@@ -100,7 +148,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
end
test "delists if string matches in summary" do
- Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], ["pun"])
+ clear_config([:mrf_keyword, :federated_timeline_removal], ["pun"])
message = %{
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
@@ -117,7 +165,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
end
test "delists if regex matches in content" do
- Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/])
+ clear_config([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/])
assert true ==
Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
@@ -138,7 +186,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
end
test "delists if regex matches in summary" do
- Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/])
+ clear_config([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/])
assert true ==
Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
@@ -157,11 +205,36 @@ 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
test "replaces keyword if string matches in content" do
- Pleroma.Config.put([:mrf_keyword, :replace], [{"opensource", "free software"}])
+ clear_config([:mrf_keyword, :replace], [{"opensource", "free software"}])
message = %{
"type" => "Create",
@@ -174,7 +247,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
end
test "replaces keyword if string matches in summary" do
- Pleroma.Config.put([:mrf_keyword, :replace], [{"opensource", "free software"}])
+ clear_config([:mrf_keyword, :replace], [{"opensource", "free software"}])
message = %{
"type" => "Create",
@@ -187,7 +260,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
end
test "replaces keyword if regex matches in content" do
- Pleroma.Config.put([:mrf_keyword, :replace], [
+ clear_config([:mrf_keyword, :replace], [
{~r/open(-|\s)?source\s?(software)?/, "free software"}
])
@@ -205,7 +278,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
end
test "replaces keyword if regex matches in summary" do
- Pleroma.Config.put([:mrf_keyword, :replace], [
+ clear_config([:mrf_keyword, :replace], [
{~r/open(-|\s)?source\s?(software)?/, "free software"}
])
@@ -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 84362ce78..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-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.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 220309cc9..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-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.MRF.MentionPolicyTest do
@@ -23,7 +23,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do
describe "allow" do
test "empty" do
- Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
+ clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create"
@@ -33,7 +33,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do
end
test "to" do
- Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
+ clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create",
@@ -44,7 +44,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do
end
test "cc" do
- Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
+ clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create",
@@ -55,7 +55,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do
end
test "both" do
- Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
+ clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create",
@@ -69,7 +69,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do
describe "deny" do
test "to" do
- Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
+ clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create",
@@ -81,7 +81,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do
end
test "cc" do
- Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
+ clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create",
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
new file mode 100644
index 000000000..386ed395f
--- /dev/null
+++ b/test/pleroma/web/activity_pub/mrf/no_empty_policy_test.exs
@@ -0,0 +1,177 @@
+# 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.NoEmptyPolicyTest do
+ use Pleroma.DataCase
+ alias Pleroma.Web.ActivityPub.MRF.NoEmptyPolicy
+
+ setup_all do: clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.NoEmptyPolicy])
+
+ test "Notes with content are exempt" 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" => "this is a test post",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "type" => "Note"
+ },
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "type" => "Create"
+ }
+
+ assert NoEmptyPolicy.filter(message) == {:ok, message}
+ end
+
+ test "Polls are exempt" 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"],
+ "oneOf" => [
+ %{
+ "name" => "chocolate",
+ "replies" => %{"totalItems" => 0, "type" => "Collection"},
+ "type" => "Note"
+ },
+ %{
+ "name" => "vanilla",
+ "replies" => %{"totalItems" => 0, "type" => "Collection"},
+ "type" => "Note"
+ }
+ ],
+ "source" => "@user2",
+ "to" => [
+ "https://www.w3.org/ns/activitystreams#Public",
+ "http://localhost:4001/users/user2"
+ ],
+ "type" => "Question"
+ },
+ "to" => [
+ "https://www.w3.org/ns/activitystreams#Public",
+ "http://localhost:4001/users/user2"
+ ],
+ "type" => "Create"
+ }
+
+ assert NoEmptyPolicy.filter(message) == {:ok, message}
+ end
+
+ test "Notes with attachments are exempt" do
+ message = %{
+ "actor" => "http://localhost:4001/users/testuser",
+ "cc" => ["http://localhost:4001/users/testuser/followers"],
+ "object" => %{
+ "actor" => "http://localhost:4001/users/testuser",
+ "attachment" => [
+ %{
+ "actor" => "http://localhost:4001/users/testuser",
+ "mediaType" => "image/png",
+ "name" => "",
+ "type" => "Document",
+ "url" => [
+ %{
+ "href" =>
+ "http://localhost:4001/media/68ba231cf12e1382ce458f1979969f8ed5cc07ba198a02e653464abaf39bdb90.png",
+ "mediaType" => "image/png",
+ "type" => "Link"
+ }
+ ]
+ }
+ ],
+ "cc" => ["http://localhost:4001/users/testuser/followers"],
+ "source" => "@user2",
+ "to" => [
+ "https://www.w3.org/ns/activitystreams#Public",
+ "http://localhost:4001/users/user2"
+ ],
+ "type" => "Note"
+ },
+ "to" => [
+ "https://www.w3.org/ns/activitystreams#Public",
+ "http://localhost:4001/users/user2"
+ ],
+ "type" => "Create"
+ }
+
+ assert NoEmptyPolicy.filter(message) == {:ok, message}
+ end
+
+ test "Notes with only mentions are denied" 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" => "@user2",
+ "to" => [
+ "https://www.w3.org/ns/activitystreams#Public",
+ "http://localhost:4001/users/user2"
+ ],
+ "type" => "Note"
+ },
+ "to" => [
+ "https://www.w3.org/ns/activitystreams#Public",
+ "http://localhost:4001/users/user2"
+ ],
+ "type" => "Create"
+ }
+
+ assert NoEmptyPolicy.filter(message) == {:reject, "[NoEmptyPolicy]"}
+ end
+
+ test "Notes with no content are denied" 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" => "Create"
+ }
+
+ 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 d03456b34..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-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.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 5fccf7760..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-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.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 e8317b2af..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,10 +1,9 @@
# 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.MRF.ObjectAgePolicyTest do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.User
alias Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy
alias Pleroma.Web.ActivityPub.Visibility
@@ -23,6 +22,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
defp get_old_message do
File.read!("test/fixtures/mastodon-post-activity.json")
|> Jason.decode!()
+ |> Map.drop(["published"])
end
defp get_new_message do
@@ -39,7 +39,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
describe "with reject action" do
test "works with objects with empty to or cc fields" do
- Config.put([:mrf_object_age, :actions], [:reject])
+ clear_config([:mrf_object_age, :actions], [:reject])
data =
get_old_message()
@@ -50,7 +50,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
end
test "it rejects an old post" do
- Config.put([:mrf_object_age, :actions], [:reject])
+ clear_config([:mrf_object_age, :actions], [:reject])
data = get_old_message()
@@ -58,7 +58,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
end
test "it allows a new post" do
- Config.put([:mrf_object_age, :actions], [:reject])
+ clear_config([:mrf_object_age, :actions], [:reject])
data = get_new_message()
@@ -68,7 +68,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
describe "with delist action" do
test "works with objects with empty to or cc fields" do
- Config.put([:mrf_object_age, :actions], [:delist])
+ clear_config([:mrf_object_age, :actions], [:delist])
data =
get_old_message()
@@ -83,7 +83,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
end
test "it delists an old post" do
- Config.put([:mrf_object_age, :actions], [:delist])
+ clear_config([:mrf_object_age, :actions], [:delist])
data = get_old_message()
@@ -95,7 +95,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
end
test "it allows a new post" do
- Config.put([:mrf_object_age, :actions], [:delist])
+ clear_config([:mrf_object_age, :actions], [:delist])
data = get_new_message()
@@ -107,7 +107,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
describe "with strip_followers action" do
test "works with objects with empty to or cc fields" do
- Config.put([:mrf_object_age, :actions], [:strip_followers])
+ clear_config([:mrf_object_age, :actions], [:strip_followers])
data =
get_old_message()
@@ -123,7 +123,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
end
test "it strips followers collections from an old post" do
- Config.put([:mrf_object_age, :actions], [:strip_followers])
+ clear_config([:mrf_object_age, :actions], [:strip_followers])
data = get_old_message()
@@ -136,7 +136,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
end
test "it allows a new post" do
- Config.put([:mrf_object_age, :actions], [:strip_followers])
+ clear_config([:mrf_object_age, :actions], [:strip_followers])
data = get_new_message()
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 e08eb3ba6..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-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.MRF.RejectNonPublicTest do
@@ -49,7 +49,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
"type" => "Create"
}
- Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], true)
+ clear_config([:mrf_rejectnonpublic, :allow_followersonly], true)
assert {:ok, _message} = RejectNonPublic.filter(message)
end
@@ -63,7 +63,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
"type" => "Create"
}
- Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], false)
+ clear_config([:mrf_rejectnonpublic, :allow_followersonly], false)
assert {:reject, _} = RejectNonPublic.filter(message)
end
end
@@ -79,7 +79,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
"type" => "Create"
}
- Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], true)
+ clear_config([:mrf_rejectnonpublic, :allow_direct], true)
assert {:ok, _message} = RejectNonPublic.filter(message)
end
@@ -93,7 +93,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
"type" => "Create"
}
- Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], false)
+ clear_config([:mrf_rejectnonpublic, :allow_direct], false)
assert {:reject, _} = RejectNonPublic.filter(message)
end
end
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 d7dde62c4..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,11 +1,10 @@
# 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.MRF.SimplePolicyTest do
use Pleroma.DataCase
import Pleroma.Factory
- alias Pleroma.Config
alias Pleroma.Web.ActivityPub.MRF.SimplePolicy
alias Pleroma.Web.CommonAPI
@@ -25,7 +24,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
describe "when :media_removal" do
test "is empty" do
- Config.put([:mrf_simple, :media_removal], [])
+ clear_config([:mrf_simple, :media_removal], [])
media_message = build_media_message()
local_message = build_local_message()
@@ -34,7 +33,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "has a matching host" do
- Config.put([: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()
@@ -47,7 +46,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "match with wildcard domain" do
- Config.put([: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()
@@ -58,11 +57,21 @@ 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
test "is empty" do
- Config.put([:mrf_simple, :media_nsfw], [])
+ clear_config([:mrf_simple, :media_nsfw], [])
media_message = build_media_message()
local_message = build_local_message()
@@ -71,38 +80,40 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "has a matching host" do
- Config.put([: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()
assert SimplePolicy.filter(media_message) ==
- {:ok,
- media_message
- |> put_in(["object", "tag"], ["foo", "nsfw"])
- |> put_in(["object", "sensitive"], true)}
+ {:ok, put_in(media_message, ["object", "sensitive"], true)}
assert SimplePolicy.filter(local_message) == {:ok, local_message}
end
test "match with wildcard domain" do
- Config.put([: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()
assert SimplePolicy.filter(media_message) ==
- {:ok,
- media_message
- |> put_in(["object", "tag"], ["foo", "nsfw"])
- |> put_in(["object", "sensitive"], true)}
+ {:ok, put_in(media_message, ["object", "sensitive"], true)}
assert SimplePolicy.filter(local_message) == {:ok, local_message}
end
+
+ 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"],
@@ -113,7 +124,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
describe "when :report_removal" do
test "is empty" do
- Config.put([:mrf_simple, :report_removal], [])
+ clear_config([:mrf_simple, :report_removal], [])
report_message = build_report_message()
local_message = build_local_message()
@@ -122,7 +133,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "has a matching host" do
- Config.put([: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()
@@ -131,7 +142,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "match with wildcard domain" do
- Config.put([: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()
@@ -149,7 +160,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
describe "when :federated_timeline_removal" do
test "is empty" do
- Config.put([:mrf_simple, :federated_timeline_removal], [])
+ clear_config([:mrf_simple, :federated_timeline_removal], [])
{_, ftl_message} = build_ftl_actor_and_message()
local_message = build_local_message()
@@ -166,7 +177,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|> URI.parse()
|> Map.fetch!(:host)
- Config.put([: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)
@@ -187,7 +198,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|> URI.parse()
|> Map.fetch!(:host)
- Config.put([: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)
@@ -210,7 +224,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
ftl_message = Map.put(ftl_message, "cc", [])
- Config.put([: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"]
@@ -231,7 +247,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
describe "when :reject" do
test "is empty" do
- Config.put([:mrf_simple, :reject], [])
+ clear_config([:mrf_simple, :reject], [])
remote_message = build_remote_message()
@@ -239,7 +255,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "activity has a matching host" do
- Config.put([:mrf_simple, :reject], ["remote.instance"])
+ clear_config([:mrf_simple, :reject], [{"remote.instance", ""}])
remote_message = build_remote_message()
@@ -247,7 +263,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "activity matches with wildcard domain" do
- Config.put([:mrf_simple, :reject], ["*.remote.instance"])
+ clear_config([:mrf_simple, :reject], [{"*.remote.instance", ""}])
remote_message = build_remote_message()
@@ -255,17 +271,41 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "actor has a matching host" do
- Config.put([:mrf_simple, :reject], ["remote.instance"])
+ clear_config([:mrf_simple, :reject], [{"remote.instance", ""}])
remote_user = build_remote_user()
assert {:reject, _} = SimplePolicy.filter(remote_user)
end
+
+ test "reject Announce when object would be rejected" do
+ clear_config([:mrf_simple, :reject], [{"blocked.tld", ""}])
+
+ announce = %{
+ "type" => "Announce",
+ "actor" => "https://okay.tld/users/alice",
+ "object" => %{"type" => "Note", "actor" => "https://blocked.tld/users/bob"}
+ }
+
+ assert {:reject, _} = SimplePolicy.filter(announce)
+ end
+
+ test "reject by URI object" do
+ clear_config([:mrf_simple, :reject], [{"blocked.tld", ""}])
+
+ announce = %{
+ "type" => "Announce",
+ "actor" => "https://okay.tld/users/alice",
+ "object" => "https://blocked.tld/activities/1"
+ }
+
+ assert {:reject, _} = SimplePolicy.filter(announce)
+ end
end
describe "when :followers_only" do
test "is empty" do
- Config.put([:mrf_simple, :followers_only], [])
+ clear_config([:mrf_simple, :followers_only], [])
{_, ftl_message} = build_ftl_actor_and_message()
local_message = build_local_message()
@@ -305,7 +345,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|> URI.parse()
|> Map.fetch!(:host)
- Config.put([: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"]
@@ -323,7 +363,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
describe "when :accept" do
test "is empty" do
- Config.put([:mrf_simple, :accept], [])
+ clear_config([:mrf_simple, :accept], [])
local_message = build_local_message()
remote_message = build_remote_message()
@@ -333,7 +373,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "is not empty but activity doesn't have a matching host" do
- Config.put([:mrf_simple, :accept], ["non.matching.remote"])
+ clear_config([:mrf_simple, :accept], [{"non.matching.remote", ""}])
local_message = build_local_message()
remote_message = build_remote_message()
@@ -343,7 +383,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "activity has a matching host" do
- Config.put([:mrf_simple, :accept], ["remote.instance"])
+ clear_config([:mrf_simple, :accept], [{"remote.instance", ""}])
local_message = build_local_message()
remote_message = build_remote_message()
@@ -353,7 +393,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "activity matches with wildcard domain" do
- Config.put([:mrf_simple, :accept], ["*.remote.instance"])
+ clear_config([:mrf_simple, :accept], [{"*.remote.instance", ""}])
local_message = build_local_message()
remote_message = build_remote_message()
@@ -363,7 +403,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "actor has a matching host" do
- Config.put([:mrf_simple, :accept], ["remote.instance"])
+ clear_config([:mrf_simple, :accept], [{"remote.instance", ""}])
remote_user = build_remote_user()
@@ -373,7 +413,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
describe "when :avatar_removal" do
test "is empty" do
- Config.put([:mrf_simple, :avatar_removal], [])
+ clear_config([:mrf_simple, :avatar_removal], [])
remote_user = build_remote_user()
@@ -381,7 +421,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "is not empty but it doesn't have a matching host" do
- Config.put([:mrf_simple, :avatar_removal], ["non.matching.remote"])
+ clear_config([:mrf_simple, :avatar_removal], [{"non.matching.remote", ""}])
remote_user = build_remote_user()
@@ -389,7 +429,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "has a matching host" do
- Config.put([: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)
@@ -398,7 +438,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "match with wildcard domain" do
- Config.put([: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)
@@ -409,7 +449,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
describe "when :banner_removal" do
test "is empty" do
- Config.put([:mrf_simple, :banner_removal], [])
+ clear_config([:mrf_simple, :banner_removal], [])
remote_user = build_remote_user()
@@ -417,7 +457,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "is not empty but it doesn't have a matching host" do
- Config.put([:mrf_simple, :banner_removal], ["non.matching.remote"])
+ clear_config([:mrf_simple, :banner_removal], [{"non.matching.remote", ""}])
remote_user = build_remote_user()
@@ -425,7 +465,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "has a matching host" do
- Config.put([: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)
@@ -434,7 +474,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "match with wildcard domain" do
- Config.put([: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)
@@ -444,10 +484,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
describe "when :reject_deletes is empty" do
- setup do: Config.put([:mrf_simple, :reject_deletes], [])
+ setup do: clear_config([:mrf_simple, :reject_deletes], [])
test "it accepts deletions even from rejected servers" do
- Config.put([:mrf_simple, :reject], ["remote.instance"])
+ clear_config([:mrf_simple, :reject], [{"remote.instance", ""}])
deletion_message = build_remote_deletion_message()
@@ -455,7 +495,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "it accepts deletions even from non-whitelisted servers" do
- Config.put([:mrf_simple, :accept], ["non.matching.remote"])
+ clear_config([:mrf_simple, :accept], [{"non.matching.remote", ""}])
deletion_message = build_remote_deletion_message()
@@ -464,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: Config.put([: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
- Config.put([:mrf_simple, :reject], ["remote.instance"])
+ clear_config([:mrf_simple, :reject], [{"remote.instance", ""}])
deletion_message = build_remote_deletion_message()
@@ -475,7 +515,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
test "it accepts deletions even from non-whitelisted servers" do
- Config.put([:mrf_simple, :accept], ["non.matching.remote"])
+ clear_config([:mrf_simple, :accept], [{"non.matching.remote", ""}])
deletion_message = build_remote_deletion_message()
@@ -484,7 +524,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
describe "when :reject_deletes has a matching host" do
- setup do: Config.put([: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()
@@ -494,7 +534,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
end
describe "when :reject_deletes match with wildcard domain" do
- setup do: Config.put([: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()
@@ -505,7 +545,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
defp build_local_message do
%{
- "actor" => "#{Pleroma.Web.base_url()}/users/alice",
+ "actor" => "#{Pleroma.Web.Endpoint.url()}/users/alice",
"to" => [],
"cc" => []
}
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 3f8222736..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,35 +1,18 @@
# 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.MRF.StealEmojiPolicyTest do
use Pleroma.DataCase
alias Pleroma.Config
+ 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 = Path.join(Config.get([:instance, :static_dir]), "emoji/stolen")
- File.rm_rf!(emoji_path)
- File.mkdir!(emoji_path)
+ emoji_path = [:instance, :static_dir] |> Config.get() |> Path.join("emoji/stolen")
- Pleroma.Emoji.reload()
-
- on_exit(fn ->
- File.rm_rf!(emoji_path)
- end)
-
- :ok
- end
-
- test "does nothing by default" do
- installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
- refute "firedfox" in installed_emoji
+ Emoji.reload()
message = %{
"type" => "Create",
@@ -39,30 +22,101 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do
}
}
- assert {:ok, message} == StealEmojiPolicy.filter(message)
+ on_exit(fn ->
+ File.rm_rf!(emoji_path)
+ end)
- installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
- refute "firedfox" in installed_emoji
+ [message: message, path: emoji_path]
end
- test "Steals emoji on unknown shortcode from allowed remote host" do
- installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
- refute "firedfox" in installed_emoji
+ test "does nothing by default", %{message: message} do
+ refute "firedfox" in installed()
- message = %{
- "type" => "Create",
- "object" => %{
- "emoji" => [{"firedfox", "https://example.org/emoji/firedfox.png"}],
- "actor" => "https://example.org/users/admin"
- }
- }
+ assert {:ok, _message} = StealEmojiPolicy.filter(message)
+
+ refute "firedfox" in installed()
+ end
+
+ test "Steals emoji on unknown shortcode from allowed remote host", %{
+ message: message,
+ path: path
+ } 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)
- clear_config([:mrf_steal_emoji, :hosts], ["example.org"])
- clear_config([:mrf_steal_emoji, :size_limit], 284_468)
+ assert {:ok, _message} = StealEmojiPolicy.filter(message)
- assert {:ok, message} == StealEmojiPolicy.filter(message)
+ assert "firedfox" in installed()
+ assert File.exists?(path)
- installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
- assert "firedfox" in installed_emoji
+ assert path
+ |> Path.join("firedfox.png")
+ |> File.exists?()
end
+
+ test "reject regex shortcode", %{message: message} do
+ refute "firedfox" in installed()
+
+ clear_config(:mrf_steal_emoji,
+ hosts: ["example.org"],
+ size_limit: 284_468,
+ rejected_shortcodes: [~r/firedfox/]
+ )
+
+ assert {:ok, _message} = StealEmojiPolicy.filter(message)
+
+ 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)
+
+ refute "firedfox" in installed()
+ end
+
+ test "reject if host returns error", %{message: message} do
+ refute "firedfox" in installed()
+
+ Tesla.Mock.mock(fn %{method: :get, url: "https://example.org/emoji/firedfox.png"} ->
+ {:ok, %Tesla.Env{status: 404, body: "Not found"}}
+ end)
+
+ clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 284_468)
+
+ ExUnit.CaptureLog.capture_log(fn ->
+ assert {:ok, _message} = StealEmojiPolicy.filter(message)
+ end) =~ "MRF.StealEmojiPolicy: Failed to fetch https://example.org/emoji/firedfox.png"
+
+ refute "firedfox" in installed()
+ end
+
+ defp installed, do: Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
end
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 fff66cb7e..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-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.MRF.SubchainPolicyTest do
@@ -16,7 +16,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SubchainPolicyTest do
setup do: clear_config([:mrf_subchain, :match_actor])
test "it matches and processes subchains when the actor matches a configured target" do
- Pleroma.Config.put([:mrf_subchain, :match_actor], %{
+ clear_config([:mrf_subchain, :match_actor], %{
~r/^https:\/\/banned.com/s => [DropPolicy]
})
@@ -24,7 +24,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SubchainPolicyTest do
end
test "it doesn't match and process subchains when the actor doesn't match a configured target" do
- Pleroma.Config.put([:mrf_subchain, :match_actor], %{
+ clear_config([:mrf_subchain, :match_actor], %{
~r/^https:\/\/borked.com/s => [DropPolicy]
})
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 4f289739f..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-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.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
@@ -114,7 +132,25 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do
except_message = %{
"actor" => actor.ap_id,
"type" => "Create",
- "object" => %{"tag" => ["test", "nsfw"], "attachment" => ["file1"], "sensitive" => true}
+ "object" => %{"tag" => ["test"], "attachment" => ["file1"], "sensitive" => true}
+ }
+
+ assert TagPolicy.filter(message) == {:ok, except_message}
+ 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}
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 8e1ad5bc8..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-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.MRF.UserAllowListPolicyTest do
use Pleroma.DataCase
@@ -17,14 +17,14 @@ defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicyTest do
test "pass filter if allow list isn't empty and user in allow list" do
actor = insert(:user)
- Pleroma.Config.put([:mrf_user_allowlist], %{"localhost" => [actor.ap_id, "test-ap-id"]})
+ clear_config([:mrf_user_allowlist], %{"localhost" => [actor.ap_id, "test-ap-id"]})
message = %{"actor" => actor.ap_id}
assert UserAllowListPolicy.filter(message) == {:ok, message}
end
test "rejected if allow list isn't empty and user not in allow list" do
actor = insert(:user)
- Pleroma.Config.put([:mrf_user_allowlist], %{"localhost" => ["test-ap-id"]})
+ clear_config([:mrf_user_allowlist], %{"localhost" => ["test-ap-id"]})
message = %{"actor" => actor.ap_id}
assert {:reject, _} = UserAllowListPolicy.filter(message)
end
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 2bceb67ee..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-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.MRF.VocabularyPolicyTest do
@@ -11,7 +11,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
setup do: clear_config([:mrf_vocabulary, :accept])
test "it accepts based on parent activity type" do
- Pleroma.Config.put([:mrf_vocabulary, :accept], ["Like"])
+ clear_config([:mrf_vocabulary, :accept], ["Like"])
message = %{
"type" => "Like",
@@ -22,7 +22,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
end
test "it accepts based on child object type" do
- Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
+ clear_config([:mrf_vocabulary, :accept], ["Create", "Note"])
message = %{
"type" => "Create",
@@ -36,7 +36,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
end
test "it does not accept disallowed child objects" do
- Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
+ clear_config([:mrf_vocabulary, :accept], ["Create", "Note"])
message = %{
"type" => "Create",
@@ -50,7 +50,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
end
test "it does not accept disallowed parent types" do
- Pleroma.Config.put([:mrf_vocabulary, :accept], ["Announce", "Note"])
+ clear_config([:mrf_vocabulary, :accept], ["Announce", "Note"])
message = %{
"type" => "Create",
@@ -68,7 +68,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
setup do: clear_config([:mrf_vocabulary, :reject])
test "it rejects based on parent activity type" do
- Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
+ clear_config([:mrf_vocabulary, :reject], ["Like"])
message = %{
"type" => "Like",
@@ -79,7 +79,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
end
test "it rejects based on child object type" do
- Pleroma.Config.put([:mrf_vocabulary, :reject], ["Note"])
+ clear_config([:mrf_vocabulary, :reject], ["Note"])
message = %{
"type" => "Create",
@@ -93,7 +93,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
end
test "it passes through objects that aren't disallowed" do
- Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
+ clear_config([:mrf_vocabulary, :reject], ["Like"])
message = %{
"type" => "Announce",
diff --git a/test/pleroma/web/activity_pub/mrf_test.exs b/test/pleroma/web/activity_pub/mrf_test.exs
index 44a9cf086..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-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.MRFTest do
@@ -63,12 +63,26 @@ 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])
expected = %{
- mrf_policies: ["NoOpPolicy"],
+ mrf_policies: ["NoOpPolicy", "HashtagPolicy"],
+ mrf_hashtag: %{
+ federated_timeline_removal: [],
+ reject: [],
+ sensitive: ["nsfw"]
+ },
exclusions: false
}
@@ -79,8 +93,13 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
clear_config([:mrf, :policies], [MRFModuleMock])
expected = %{
- mrf_policies: ["MRFModuleMock"],
+ mrf_policies: ["MRFModuleMock", "HashtagPolicy"],
mrf_module_mock: "some config data",
+ mrf_hashtag: %{
+ federated_timeline_removal: [],
+ reject: [],
+ sensitive: ["nsfw"]
+ },
exclusions: false
}
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 bafa2a672..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-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.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 9613dea9b..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-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.ObjectValidators.AnnounceValidationTest do
@@ -18,7 +18,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidationTest do
announcer = insert(:user)
{:ok, post_activity} = CommonAPI.post(user, %{status: "uguu"})
- object = Object.normalize(post_activity, false)
+ object = Object.normalize(post_activity, fetch: false)
{:ok, valid_announce, []} = Builder.announce(announcer, object)
%{
@@ -33,6 +33,18 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidationTest do
assert {:ok, _object, _meta} = ObjectValidator.validate(valid_announce, [])
end
+ test "keeps announced object context", %{valid_announce: valid_announce} do
+ assert %Object{data: %{"context" => object_context}} =
+ Object.get_cached_by_ap_id(valid_announce["object"])
+
+ {:ok, %{"context" => context}, _} =
+ valid_announce
+ |> Map.put("context", "https://example.org/invalid_context_id")
+ |> ObjectValidator.validate([])
+
+ assert context == object_context
+ end
+
test "returns an error if the object can't be found", %{valid_announce: valid_announce} do
without_object =
valid_announce
@@ -51,16 +63,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidationTest do
assert {:object, {"can't find object", []}} in cng.errors
end
- test "returns an error if we don't have the actor", %{valid_announce: valid_announce} do
- nonexisting_actor =
- valid_announce
- |> Map.put("actor", "https://gensokyo.2hu/users/raymoo")
-
- {:error, cng} = ObjectValidator.validate(nonexisting_actor, [])
-
- assert {:actor, {"can't find user", []}} in cng.errors
- end
-
test "returns an error if the actor already announced the object", %{
valid_announce: valid_announce,
announcer: announcer,
@@ -81,7 +83,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidationTest do
{:ok, post_activity} =
CommonAPI.post(user, %{status: "a secret post", visibility: "private"})
- object = Object.normalize(post_activity, false)
+ object = Object.normalize(post_activity, fetch: false)
# Another user can't announce it
{:ok, announce, []} = Builder.announce(announcer, object, public: false)
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
new file mode 100644
index 000000000..c7a62be18
--- /dev/null
+++ b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs
@@ -0,0 +1,119 @@
+# 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.ArticleNotePageValidatorTest do
+ use Pleroma.DataCase, async: true
+
+ alias Pleroma.Web.ActivityPub.ObjectValidator
+ alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator
+ alias Pleroma.Web.ActivityPub.Utils
+
+ import Pleroma.Factory
+
+ describe "Notes" do
+ setup do
+ user = insert(:user)
+
+ note = %{
+ "id" => Utils.generate_activity_id(),
+ "type" => "Note",
+ "actor" => user.ap_id,
+ "to" => [user.follower_address],
+ "cc" => [],
+ "content" => "Hellow this is content.",
+ "context" => "xxx",
+ "summary" => "a post"
+ }
+
+ %{user: user, note: note}
+ end
+
+ 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
+end
diff --git a/test/pleroma/web/activity_pub/object_validators/article_note_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/article_note_validator_test.exs
deleted file mode 100644
index 1f992b397..000000000
--- a/test/pleroma/web/activity_pub/object_validators/article_note_validator_test.exs
+++ /dev/null
@@ -1,35 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidatorTest do
- use Pleroma.DataCase, async: true
-
- alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidator
- alias Pleroma.Web.ActivityPub.Utils
-
- import Pleroma.Factory
-
- describe "Notes" do
- setup do
- user = insert(:user)
-
- note = %{
- "id" => Utils.generate_activity_id(),
- "type" => "Note",
- "actor" => user.ap_id,
- "to" => [user.follower_address],
- "cc" => [],
- "content" => "Hellow this is content.",
- "context" => "xxx",
- "summary" => "a post"
- }
-
- %{user: user, note: note}
- end
-
- test "a basic note validates", %{note: note} do
- %{valid?: true} = ArticleNoteValidator.cast_and_validate(note)
- end
- end
-end
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 45e1d8852..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-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.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" => "",
@@ -27,6 +40,46 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
assert attachment.mediaType == "application/octet-stream"
end
+ test "works with an unknown but valid mime type" do
+ attachment = %{
+ "mediaType" => "x-custom/x-type",
+ "type" => "Document",
+ "url" => "https://example.org"
+ }
+
+ assert {:ok, attachment} =
+ AttachmentValidator.cast_and_validate(attachment)
+ |> Ecto.Changeset.apply_action(:insert)
+
+ assert attachment.mediaType == "x-custom/x-type"
+ end
+
+ test "works with invalid mime types" do
+ attachment = %{
+ "mediaType" => "x-customx-type",
+ "type" => "Document",
+ "url" => "https://example.org"
+ }
+
+ assert {:ok, attachment} =
+ AttachmentValidator.cast_and_validate(attachment)
+ |> Ecto.Changeset.apply_action(:insert)
+
+ assert attachment.mediaType == "application/octet-stream"
+
+ attachment = %{
+ "mediaType" => "https://example.org",
+ "type" => "Document",
+ "url" => "https://example.org"
+ }
+
+ assert {:ok, attachment} =
+ AttachmentValidator.cast_and_validate(attachment)
+ |> Ecto.Changeset.apply_action(:insert)
+
+ assert attachment.mediaType == "application/octet-stream"
+ end
+
test "it turns mastodon attachments into our attachments" do
attachment = %{
"url" =>
@@ -72,5 +125,70 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
assert attachment.mediaType == "image/jpeg"
end
+
+ test "it handles image dimensions" do
+ attachment = %{
+ "url" => [
+ %{
+ "type" => "Link",
+ "mediaType" => "image/jpeg",
+ "href" => "https://example.com/images/1.jpg",
+ "width" => 200,
+ "height" => 100
+ }
+ ],
+ "type" => "Document",
+ "name" => nil,
+ "mediaType" => "image/jpeg"
+ }
+
+ {:ok, attachment} =
+ AttachmentValidator.cast_and_validate(attachment)
+ |> Ecto.Changeset.apply_action(:insert)
+
+ assert [
+ %{
+ href: "https://example.com/images/1.jpg",
+ type: "Link",
+ mediaType: "image/jpeg",
+ width: 200,
+ height: 100
+ }
+ ] = attachment.url
+
+ assert attachment.mediaType == "image/jpeg"
+ end
+
+ 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 d133aeb1a..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-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.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 d7e299224..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-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.ObjectValidators.ChatValidationTest do
@@ -17,7 +17,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
user = insert(:user)
recipient = insert(:user)
{:ok, activity} = CommonAPI.post_chat_message(user, recipient, "hey")
- object = Object.normalize(activity, false)
+ object = Object.normalize(activity, fetch: false)
{:ok, create_data, _} = Builder.create(user, object.data, [recipient.ap_id])
@@ -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
@@ -149,7 +149,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
test "does not validate if the message is longer than the remote_limit", %{
valid_chat_message: valid_chat_message
} do
- Pleroma.Config.put([:instance, :remote_limit], 2)
+ clear_config([:instance, :remote_limit], 2)
refute match?({:ok, _object, _meta}, ObjectValidator.validate(valid_chat_message, []))
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 57de83c8a..ea4664859 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,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.ObjectValidators.DeleteValidationTest do
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 342cfeef8..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-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.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 0f77ac8df..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-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.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 4cda3742d..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-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.ObjectValidators.LikeValidationTest do
@@ -40,17 +40,30 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.LikeValidationTest do
assert LikeValidator.cast_and_validate(valid_like).valid?
end
- test "sets the 'to' field to the object actor if no recipients are given", %{
+ test "Add object actor from 'to' field if it doesn't owns the like", %{valid_like: valid_like} do
+ user = insert(:user)
+
+ object_actor = valid_like["actor"]
+
+ valid_like =
+ valid_like
+ |> Map.put("actor", user.ap_id)
+ |> Map.put("to", [])
+
+ {:ok, object, _meta} = ObjectValidator.validate(valid_like, [])
+ assert object_actor in object["to"]
+ end
+
+ test "Removes object actor from 'to' field if it owns the like", %{
valid_like: valid_like,
user: user
} do
- without_recipients =
+ valid_like =
valid_like
- |> Map.delete("to")
+ |> Map.put("to", [user.ap_id])
- {:ok, object, _meta} = ObjectValidator.validate(without_recipients, [])
-
- assert object["to"] == [user.ap_id]
+ {:ok, object, _meta} = ObjectValidator.validate(valid_like, [])
+ refute user.ap_id in object["to"]
end
test "sets the context field to the context of the object if no context is given", %{
@@ -66,16 +79,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.LikeValidationTest do
assert object["context"] == post_activity.data["context"]
end
- test "it errors when the actor is missing or not known", %{valid_like: valid_like} do
- without_actor = Map.delete(valid_like, "actor")
-
- refute LikeValidator.cast_and_validate(without_actor).valid?
-
- with_invalid_actor = Map.put(valid_like, "actor", "invalidactor")
-
- refute LikeValidator.cast_and_validate(with_invalid_actor).valid?
- end
-
test "it errors when the object is missing or not known", %{valid_like: valid_like} do
without_object = Map.delete(valid_like, "object")
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 69f5e8ac4..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-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.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 dc85d1ac3..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-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.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 2c4a50bfd..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-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.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 d568d825b..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-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.PipelineTest do
@@ -25,9 +25,6 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
MRFMock
|> expect(:pipeline_filter, fn o, m -> {:ok, o, m} end)
- ActivityPubMock
- |> expect(:persist, fn o, m -> {:ok, o, m} end)
-
SideEffectsMock
|> expect(:handle, fn o, m -> {:ok, o, m} end)
|> expect(:handle_after_transaction, fn m -> m end)
@@ -42,6 +39,9 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
activity_with_object = %{activity | data: Map.put(activity.data, "object", object)}
+ ActivityPubMock
+ |> expect(:persist, fn _, m -> {:ok, activity, m} end)
+
FederatorMock
|> expect(:publish, fn ^activity_with_object -> :ok end)
@@ -50,7 +50,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
assert {:ok, ^activity, ^meta} =
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(
- activity,
+ activity.data,
meta
)
end
@@ -59,6 +59,9 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
activity = insert(:note_activity)
meta = [local: true]
+ ActivityPubMock
+ |> expect(:persist, fn _, m -> {:ok, activity, m} end)
+
FederatorMock
|> expect(:publish, fn ^activity -> :ok end)
@@ -66,29 +69,35 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|> expect(:get, fn [:instance, :federating] -> true end)
assert {:ok, ^activity, ^meta} =
- Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
+ Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)
end
test "it goes through validation, filtering, persisting, side effects without federation for remote activities" do
activity = insert(:note_activity)
meta = [local: false]
+ ActivityPubMock
+ |> expect(:persist, fn _, m -> {:ok, activity, m} end)
+
ConfigMock
|> expect(:get, fn [:instance, :federating] -> true end)
assert {:ok, ^activity, ^meta} =
- Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
+ Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)
end
test "it goes through validation, filtering, persisting, side effects without federation for local activities if federation is deactivated" do
activity = insert(:note_activity)
meta = [local: true]
+ ActivityPubMock
+ |> expect(:persist, fn _, m -> {:ok, activity, m} end)
+
ConfigMock
|> expect(:get, fn [:instance, :federating] -> false end)
assert {:ok, ^activity, ^meta} =
- Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
+ Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)
end
end
end
diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs
index 3503d25b2..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-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.PublisherTest do
@@ -38,7 +38,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
},
%{
"rel" => "http://ostatus.org/schema/1.0/subscribe",
- "template" => "#{Pleroma.Web.base_url()}/ostatus_subscribe?acct={uri}"
+ "template" => "#{Pleroma.Web.Endpoint.url()}/ostatus_subscribe?acct={uri}"
}
]
@@ -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],
@@ -322,7 +396,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
actor = insert(:user)
note_activity = insert(:note_activity, user: actor)
- object = Object.normalize(note_activity)
+ object = Object.normalize(note_activity, fetch: false)
activity_path = String.trim_leading(note_activity.data["id"], Pleroma.Web.Endpoint.url())
object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url())
diff --git a/test/pleroma/web/activity_pub/relay_test.exs b/test/pleroma/web/activity_pub/relay_test.exs
index a7cd732bb..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-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.RelayTest do
@@ -148,7 +148,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
assert {:ok, %Activity{} = activity} = Relay.publish(note)
assert activity.data["type"] == "Announce"
assert activity.data["actor"] == service_actor.ap_id
- assert activity.data["to"] == [service_actor.follower_address]
+ assert service_actor.follower_address in activity.data["to"]
assert called(Pleroma.Web.Federator.publish(activity))
end
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 e4ad606a9..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-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.SideEffects.DeleteTest do
@@ -39,7 +39,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects.DeleteTest do
{:ok, _delete, _} = SideEffects.handle(delete)
ObanHelpers.perform_all()
- assert User.get_cached_by_ap_id(user.ap_id).deactivated
+ refute User.get_cached_by_ap_id(user.ap_id).is_active
end
end
@@ -51,7 +51,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects.DeleteTest do
{:ok, op} = CommonAPI.post(other_user, %{status: "big oof"})
{:ok, post} = CommonAPI.post(user, %{status: "hey", in_reply_to_id: op})
{:ok, favorite} = CommonAPI.favorite(user, post.id)
- object = Object.normalize(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)
@@ -93,7 +93,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects.DeleteTest do
user = User.get_by_id(user.id)
assert user.note_count == 0
- object = Object.normalize(op.data["object"], false)
+ object = Object.normalize(op.data["object"], fetch: false)
assert object.data["repliesCount"] == 0
end
@@ -124,7 +124,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects.DeleteTest do
user = User.get_by_id(user.id)
assert user.note_count == 0
- object = Object.normalize(op.data["object"], false)
+ object = Object.normalize(op.data["object"], fetch: false)
assert object.data["repliesCount"] == 0
end
diff --git a/test/pleroma/web/activity_pub/side_effects_test.exs b/test/pleroma/web/activity_pub/side_effects_test.exs
index 50af7a507..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-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.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,22 +462,38 @@ 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, confirmation_pending: true)
+ user = insert(:user, is_confirmed: false)
{:ok, delete_user_data, _meta} = Builder.delete(user, user.ap_id)
{:ok, delete_user, _meta} = ActivityPub.persist(delete_user_data, local: true)
{:ok, delete: delete_user, user: user}
end
- test "when activation is not required", %{delete: delete, user: user} do
- clear_config([:instance, :account_activation_required], false)
- {:ok, _, _} = SideEffects.handle(delete)
- ObanHelpers.perform_all()
-
- assert User.get_cached_by_id(user.id).deactivated
- end
-
test "when activation is required", %{delete: delete, user: user} do
clear_config([:instance, :account_activation_required], true)
{:ok, _, _} = SideEffects.handle(delete)
@@ -518,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 d356fcc72..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-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.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
new file mode 100644
index 000000000..a8a7edca5
--- /dev/null
+++ b/test/pleroma/web/activity_pub/transmogrifier/add_remove_handling_test.exs
@@ -0,0 +1,182 @@
+# 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
+
+ require Pleroma.Constants
+
+ import Pleroma.Factory
+
+ alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.Transmogrifier
+
+ test "it accepts Add/Remove activities" do
+ user =
+ "test/fixtures/users_mock/user.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", "lain")
+
+ object_id = "c61d6733-e256-4fe1-ab13-1e369789423f"
+
+ object =
+ "test/fixtures/statuses/note.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", "lain")
+ |> String.replace("{{object_id}}", object_id)
+
+ object_url = "https://example.com/objects/#{object_id}"
+
+ actor = "https://example.com/users/lain"
+
+ Tesla.Mock.mock(fn
+ %{
+ method: :get,
+ url: ^actor
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: user,
+ headers: [{"content-type", "application/activity+json"}]
+ }
+
+ %{
+ method: :get,
+ url: ^object_url
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: object,
+ headers: [{"content-type", "application/activity+json"}]
+ }
+
+ %{method: :get, url: "https://example.com/users/lain/collections/featured"} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/users_mock/masto_featured.json"
+ |> File.read!()
+ |> String.replace("{{domain}}", "example.com")
+ |> String.replace("{{nickname}}", "lain"),
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ message = %{
+ "id" => "https://example.com/objects/d61d6733-e256-4fe1-ab13-1e369789423f",
+ "actor" => actor,
+ "object" => object_url,
+ "target" => "https://example.com/users/lain/collections/featured",
+ "type" => "Add",
+ "to" => [Pleroma.Constants.as_public()],
+ "cc" => ["https://example.com/users/lain/followers"],
+ "bcc" => [],
+ "bto" => []
+ }
+
+ assert {:ok, activity} = Transmogrifier.handle_incoming(message)
+ assert activity.data == message
+ user = User.get_cached_by_ap_id(actor)
+ assert user.pinned_objects[object_url]
+
+ remove = %{
+ "id" => "http://localhost:400/objects/d61d6733-e256-4fe1-ab13-1e369789423d",
+ "actor" => actor,
+ "object" => object_url,
+ "target" => "https://example.com/users/lain/collections/featured",
+ "type" => "Remove",
+ "to" => [Pleroma.Constants.as_public()],
+ "cc" => ["https://example.com/users/lain/followers"],
+ "bcc" => [],
+ "bto" => []
+ }
+
+ assert {:ok, activity} = Transmogrifier.handle_incoming(remove)
+ assert activity.data == remove
+
+ user = refresh_record(user)
+ refute user.pinned_objects[object_url]
+ end
+
+ test "Add/Remove activities for remote users without featured address" do
+ user = insert(:user, local: false, domain: "example.com")
+
+ user =
+ user
+ |> Ecto.Changeset.change(featured_address: nil)
+ |> Repo.update!()
+
+ %{host: host} = URI.parse(user.ap_id)
+
+ user_data =
+ "test/fixtures/users_mock/user.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", user.nickname)
+
+ object_id = "c61d6733-e256-4fe1-ab13-1e369789423f"
+
+ object =
+ "test/fixtures/statuses/note.json"
+ |> File.read!()
+ |> String.replace("{{nickname}}", user.nickname)
+ |> String.replace("{{object_id}}", object_id)
+
+ object_url = "https://#{host}/objects/#{object_id}"
+
+ actor = "https://#{host}/users/#{user.nickname}"
+
+ featured = "https://#{host}/users/#{user.nickname}/collections/featured"
+
+ Tesla.Mock.mock(fn
+ %{
+ method: :get,
+ url: ^actor
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: user_data,
+ headers: [{"content-type", "application/activity+json"}]
+ }
+
+ %{
+ method: :get,
+ url: ^object_url
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: object,
+ headers: [{"content-type", "application/activity+json"}]
+ }
+
+ %{method: :get, url: ^featured} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ "test/fixtures/users_mock/masto_featured.json"
+ |> File.read!()
+ |> String.replace("{{domain}}", "#{host}")
+ |> String.replace("{{nickname}}", user.nickname),
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ message = %{
+ "id" => "https://#{host}/objects/d61d6733-e256-4fe1-ab13-1e369789423f",
+ "actor" => actor,
+ "object" => object_url,
+ "target" => "https://#{host}/users/#{user.nickname}/collections/featured",
+ "type" => "Add",
+ "to" => [Pleroma.Constants.as_public()],
+ "cc" => ["https://#{host}/users/#{user.nickname}/followers"],
+ "bcc" => [],
+ "bto" => []
+ }
+
+ assert {:ok, activity} = Transmogrifier.handle_incoming(message)
+ assert activity.data == message
+ user = User.get_cached_by_ap_id(actor)
+ assert user.pinned_objects[object_url]
+ end
+end
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 c06bbc5e9..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-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.AnnounceHandlingTest do
@@ -130,7 +130,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do
assert data["id"] ==
"http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
- object = Object.normalize(data["object"])
+ object = Object.normalize(data["object"], fetch: false)
assert object.data["id"] == "http://mastodon.example.org/@admin/99541947525187368"
assert object.data["content"] == "this is a private toot"
@@ -150,27 +150,4 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do
assert {:error, _e} = Transmogrifier.handle_incoming(data)
end
-
- test "it does not clobber the addressing on announce activities" do
- user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
-
- data =
- File.read!("test/fixtures/mastodon-announce.json")
- |> Jason.decode!()
- |> Map.put("object", Object.normalize(activity).data["id"])
- |> Map.put("to", ["http://mastodon.example.org/users/admin/followers"])
- |> Map.put("cc", [])
-
- _user =
- insert(:user,
- local: false,
- ap_id: data["actor"],
- follower_address: "http://mastodon.example.org/users/admin/followers"
- )
-
- {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
-
- assert data["to"] == ["http://mastodon.example.org/users/admin/followers"]
- end
end
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 a1c2ba28a..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-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.AnswerHandlingTest do
@@ -26,7 +26,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnswerHandlingTest do
poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert object.data["repliesCount"] == nil
data =
@@ -37,7 +37,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnswerHandlingTest do
|> Kernel.put_in(["object", "to"], user.ap_id)
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
- answer_object = Object.normalize(activity)
+ answer_object = Object.normalize(activity, fetch: false)
assert answer_object.data["type"] == "Answer"
assert answer_object.data["inReplyTo"] == object.data["id"]
@@ -62,7 +62,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnswerHandlingTest do
poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
})
- poll_object = Object.normalize(poll_activity)
+ poll_object = Object.normalize(poll_activity, fetch: false)
# TODO: Replace with CommonAPI vote creation when implemented
data =
File.read!("test/fixtures/mastodon-vote.json")
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 b0ae804c5..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-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.ArticleHandlingTest do
@@ -25,7 +25,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ArticleHandlingTest do
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
- object = Object.normalize(data["object"])
+ object = Object.normalize(data["object"], fetch: false)
assert object.data["name"] == "The end is near: Mastodon plans to drop OStatus support"
@@ -75,7 +75,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ArticleHandlingTest do
data = File.read!("test/fixtures/prismo-url-map.json") |> Jason.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
- object = Object.normalize(data["object"])
+ object = Object.normalize(data["object"], fetch: false)
assert object.data["url"] == "https://prismo.news/posts/83"
end
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 7a2ac5d4d..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-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.AudioHandlingTest do
@@ -24,6 +24,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
"actor" => "http://mastodon.example.org/users/admin",
"object" => %{
"type" => "Audio",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "cc" => [],
"id" => "http://mastodon.example.org/users/admin/listens/1234",
"attributedTo" => "http://mastodon.example.org/users/admin",
"title" => "lain radio episode 1",
@@ -35,7 +37,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert object.data["title"] == "lain radio episode 1"
assert object.data["artist"] == "lain"
@@ -57,11 +59,13 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
- assert object = Object.normalize(activity, false)
+ assert object = Object.normalize(activity, fetch: false)
assert object.data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
- assert object.data["cc"] == []
+ assert object.data["cc"] == [
+ "https://channels.tests.funkwhale.audio/federation/actors/compositions/followers"
+ ]
assert object.data["url"] == "https://channels.tests.funkwhale.audio/library/tracks/74"
@@ -69,8 +73,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
%{
"mediaType" => "audio/ogg",
"type" => "Link",
- "name" => nil,
- "blurhash" => nil,
"url" => [
%{
"href" =>
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 6adad88f5..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-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.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 2adaa1ade..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-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.ChatMessageTest do
@@ -134,7 +134,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageTest do
ap_id: data["actor"],
local: false,
last_refreshed_at: DateTime.utc_now(),
- deactivated: true
+ is_active: false
)
_recipient = insert(:user, ap_id: List.first(data["to"]), local: true)
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 1f9e73ff8..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-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.DeleteHandlingTest do
@@ -40,7 +40,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do
assert actor == deleting_user.ap_id
# Objects are replaced by a tombstone object.
- object = Object.normalize(activity.data["object"])
+ object = Object.normalize(activity.data["object"], fetch: false)
assert object.data["type"] == "Tombstone"
end
@@ -48,7 +48,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do
activity = insert(:note_activity)
{:ok, object} =
- Object.normalize(activity.data["object"])
+ Object.normalize(activity.data["object"], fetch: false)
|> Repo.delete()
# TODO: mock cachex
@@ -97,7 +97,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do
{:ok, _} = Transmogrifier.handle_incoming(data)
ObanHelpers.perform_all()
- assert User.get_cached_by_ap_id(ap_id).deactivated
+ refute User.get_cached_by_ap_id(ap_id).is_active
end
test "it fails for incoming user deletes with spoofed origin" 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 1ebf6b1e8..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-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.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 d7c55cfbe..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-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.EventHandlingTest do
@@ -31,7 +31,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.EventHandlingTest do
)
assert object.data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
- assert object.data["cc"] == []
+ assert object.data["cc"] == ["https://mobilizon.org/@tcit/followers"]
assert object.data["url"] ==
"https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39"
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 985c26def..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-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.FollowHandlingTest do
@@ -133,7 +133,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
end
test "it rejects incoming follow requests from blocked users when deny_follow_blocked is enabled" do
- Pleroma.Config.put([:user, :deny_follow_blocked], true)
+ clear_config([:user, :deny_follow_blocked], true)
user = insert(:user)
{:ok, target} = User.get_or_fetch("http://mastodon.example.org/users/admin")
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 35211b8f2..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-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.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 b4a006aec..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-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.NoteHandlingTest do
@@ -10,11 +10,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.Transmogrifier
+ alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI
import Mock
import Pleroma.Factory
- import ExUnit.CaptureLog
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
@@ -28,7 +28,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
data = File.read!("test/fixtures/kroeg-array-less-emoji.json") |> Jason.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
- object = Object.normalize(data["object"])
+ object = Object.normalize(data["object"], fetch: false)
assert object.data["emoji"] == %{
"icon_e_smile" => "https://puckipedia.com/forum/images/smilies/icon_e_smile.png"
@@ -37,39 +37,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
data = File.read!("test/fixtures/kroeg-array-less-hashtag.json") |> Jason.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
- object = Object.normalize(data["object"])
-
- assert "test" in object.data["tag"]
- end
-
- test "it cleans up incoming notices which are not really DMs" do
- user = insert(:user)
- other_user = insert(:user)
-
- to = [user.ap_id, other_user.ap_id]
-
- data =
- File.read!("test/fixtures/mastodon-post-activity.json")
- |> Jason.decode!()
- |> Map.put("to", to)
- |> Map.put("cc", [])
+ object = Object.normalize(data["object"], fetch: false)
- object =
- data["object"]
- |> Map.put("to", to)
- |> Map.put("cc", [])
-
- data = Map.put(data, "object", object)
-
- {:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
-
- assert data["to"] == []
- assert data["cc"] == to
-
- object_data = Object.normalize(activity).data
-
- assert object_data["to"] == []
- assert object_data["cc"] == to
+ assert "test" in Object.tags(object)
+ assert Object.hashtags(object) == ["test"]
end
test "it ignores an incoming notice if we already have it" do
@@ -78,7 +49,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
data =
File.read!("test/fixtures/mastodon-post-activity.json")
|> Jason.decode!()
- |> Map.put("object", Object.normalize(activity).data)
+ |> Map.put("object", Object.normalize(activity, fetch: false).data)
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
@@ -97,7 +68,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
data = Map.put(data, "object", object)
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
- returned_object = Object.normalize(returned_activity, false)
+ returned_object = Object.normalize(returned_activity, fetch: false)
assert %Activity{} =
Activity.get_create_by_object_ap_id(
@@ -123,7 +94,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
allowed_thread_distance?: fn _ -> false end do
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
- returned_object = Object.normalize(returned_activity, false)
+ returned_object = Object.normalize(returned_activity, fetch: false)
refute Activity.get_create_by_object_ap_id(
"tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
@@ -146,15 +117,13 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
data
|> Map.put("object", object)
- assert capture_log(fn ->
- {:ok, _returned_activity} = Transmogrifier.handle_incoming(data)
- end) =~ "[warn] Couldn't fetch \"https://404.site/whatever\", error: nil"
+ assert {:ok, _returned_activity} = Transmogrifier.handle_incoming(data)
end
test "it does not work for deactivated users" do
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!()
- insert(:user, ap_id: data["actor"], deactivated: true)
+ insert(:user, ap_id: data["actor"], is_active: false)
assert {:error, _} = Transmogrifier.handle_incoming(data)
end
@@ -173,13 +142,13 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
assert data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
assert data["cc"] == [
- "http://mastodon.example.org/users/admin/followers",
- "http://localtesting.pleroma.lol/users/lain"
+ "http://localtesting.pleroma.lol/users/lain",
+ "http://mastodon.example.org/users/admin/followers"
]
assert data["actor"] == "http://mastodon.example.org/users/admin"
- object_data = Object.normalize(data["object"]).data
+ object_data = Object.normalize(data["object"], fetch: false).data
assert object_data["id"] ==
"http://mastodon.example.org/users/admin/statuses/99512778738411822"
@@ -187,8 +156,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
assert object_data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
assert object_data["cc"] == [
- "http://mastodon.example.org/users/admin/followers",
- "http://localtesting.pleroma.lol/users/lain"
+ "http://localtesting.pleroma.lol/users/lain",
+ "http://mastodon.example.org/users/admin/followers"
]
assert object_data["actor"] == "http://mastodon.example.org/users/admin"
@@ -209,7 +178,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
- object_data = Object.normalize(data["object"], false).data
+ object_data = Object.normalize(data["object"], fetch: false).data
assert object_data["sensitive"] == true
end
@@ -218,16 +187,34 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Jason.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
- object = Object.normalize(data["object"])
+ object = Object.normalize(data["object"], fetch: false)
+
+ assert match?(
+ %{
+ "href" => "http://localtesting.pleroma.lol/users/lain",
+ "name" => "@lain@localtesting.pleroma.lol",
+ "type" => "Mention"
+ },
+ Enum.at(object.data["tag"], 0)
+ )
+
+ assert match?(
+ %{
+ "href" => "http://mastodon.example.org/tags/moo",
+ "name" => "#moo",
+ "type" => "Hashtag"
+ },
+ Enum.at(object.data["tag"], 1)
+ )
- assert Enum.at(object.data["tag"], 2) == "moo"
+ assert "moo" == Enum.at(object.data["tag"], 2)
end
test "it works for incoming notices with contentMap" do
data = File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Jason.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
- object = Object.normalize(data["object"])
+ object = Object.normalize(data["object"], fetch: false)
assert object.data["content"] ==
"<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>"
@@ -237,7 +224,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
data = File.read!("test/fixtures/kroeg-post-activity.json") |> Jason.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
- object = Object.normalize(data["object"])
+ object = Object.normalize(data["object"], fetch: false)
assert object.data["content"] ==
"<p>henlo from my Psion netBook</p><p>message sent from my Psion netBook</p>"
@@ -274,13 +261,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
File.read!("test/fixtures/mastodon-post-activity.json")
|> Jason.decode!()
|> Map.put("actor", user.ap_id)
- |> Map.put("to", nil)
|> Map.put("cc", nil)
object =
data["object"]
|> Map.put("attributedTo", user.ap_id)
- |> Map.put("to", nil)
|> Map.put("cc", nil)
|> Map.put("id", user.ap_id <> "/activities/12345678")
@@ -288,8 +273,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
- assert !is_nil(data["to"])
- assert !is_nil(data["cc"])
+ refute is_nil(data["cc"])
end
test "it strips internal likes" do
@@ -308,9 +292,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
object = Map.put(data["object"], "likes", likes)
data = Map.put(data, "object", object)
- {:ok, %Activity{object: object}} = Transmogrifier.handle_incoming(data)
+ {:ok, %Activity{} = activity} = Transmogrifier.handle_incoming(data)
+
+ object = Object.normalize(activity)
- refute Map.has_key?(object.data, "likes")
+ assert object.data["likes"] == []
end
test "it strips internal reactions" do
@@ -328,70 +314,46 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
end
test "it correctly processes messages with non-array to field" do
- user = insert(:user)
+ data =
+ File.read!("test/fixtures/mastodon-post-activity.json")
+ |> Poison.decode!()
+ |> Map.put("to", "https://www.w3.org/ns/activitystreams#Public")
+ |> put_in(["object", "to"], "https://www.w3.org/ns/activitystreams#Public")
- message = %{
- "@context" => "https://www.w3.org/ns/activitystreams",
- "to" => "https://www.w3.org/ns/activitystreams#Public",
- "type" => "Create",
- "object" => %{
- "content" => "blah blah blah",
- "type" => "Note",
- "attributedTo" => user.ap_id,
- "inReplyTo" => nil
- },
- "actor" => user.ap_id
- }
+ assert {:ok, activity} = Transmogrifier.handle_incoming(data)
- assert {:ok, activity} = Transmogrifier.handle_incoming(message)
+ assert [
+ "http://localtesting.pleroma.lol/users/lain",
+ "http://mastodon.example.org/users/admin/followers"
+ ] == activity.data["cc"]
assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["to"]
end
test "it correctly processes messages with non-array cc field" do
- user = insert(:user)
-
- message = %{
- "@context" => "https://www.w3.org/ns/activitystreams",
- "to" => user.follower_address,
- "cc" => "https://www.w3.org/ns/activitystreams#Public",
- "type" => "Create",
- "object" => %{
- "content" => "blah blah blah",
- "type" => "Note",
- "attributedTo" => user.ap_id,
- "inReplyTo" => nil
- },
- "actor" => user.ap_id
- }
+ data =
+ File.read!("test/fixtures/mastodon-post-activity.json")
+ |> Poison.decode!()
+ |> Map.put("cc", "http://mastodon.example.org/users/admin/followers")
+ |> put_in(["object", "cc"], "http://mastodon.example.org/users/admin/followers")
- assert {:ok, activity} = Transmogrifier.handle_incoming(message)
+ assert {:ok, activity} = Transmogrifier.handle_incoming(data)
- assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["cc"]
- assert [user.follower_address] == activity.data["to"]
+ assert ["http://mastodon.example.org/users/admin/followers"] == activity.data["cc"]
+ assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["to"]
end
test "it correctly processes messages with weirdness in address fields" do
- user = insert(:user)
-
- message = %{
- "@context" => "https://www.w3.org/ns/activitystreams",
- "to" => [nil, user.follower_address],
- "cc" => ["https://www.w3.org/ns/activitystreams#Public", ["¿"]],
- "type" => "Create",
- "object" => %{
- "content" => "…",
- "type" => "Note",
- "attributedTo" => user.ap_id,
- "inReplyTo" => nil
- },
- "actor" => user.ap_id
- }
+ data =
+ File.read!("test/fixtures/mastodon-post-activity.json")
+ |> Poison.decode!()
+ |> Map.put("cc", ["http://mastodon.example.org/users/admin/followers", ["¿"]])
+ |> put_in(["object", "cc"], ["http://mastodon.example.org/users/admin/followers", ["¿"]])
- assert {:ok, activity} = Transmogrifier.handle_incoming(message)
+ assert {:ok, activity} = Transmogrifier.handle_incoming(data)
- assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["cc"]
- assert [user.follower_address] == activity.data["to"]
+ assert ["http://mastodon.example.org/users/admin/followers"] == activity.data["cc"]
+ assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["to"]
end
end
@@ -415,9 +377,13 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
data: data,
items: items
} do
- Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 10)
+ clear_config([:instance, :federation_incoming_replies_max_depth], 10)
- {:ok, _activity} = Transmogrifier.handle_incoming(data)
+ {:ok, activity} = Transmogrifier.handle_incoming(data)
+
+ object = Object.normalize(activity.data["object"])
+
+ assert object.data["replies"] == items
for id <- items do
job_args = %{"op" => "fetch_remote", "id" => id, "depth" => 1}
@@ -427,7 +393,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
test "does NOT schedule background fetching of `replies` beyond max thread depth limit allows",
%{data: data} do
- Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
+ clear_config([:instance, :federation_incoming_replies_max_depth], 0)
{:ok, _activity} = Transmogrifier.handle_incoming(data)
@@ -440,45 +406,38 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
setup do
- user = insert(:user)
-
- {:ok, activity} = CommonAPI.post(user, %{status: "post1"})
-
- {:ok, reply1} =
- CommonAPI.post(user, %{status: "reply1", in_reply_to_status_id: activity.id})
-
- {:ok, reply2} =
- CommonAPI.post(user, %{status: "reply2", in_reply_to_status_id: activity.id})
-
- replies_uris = Enum.map([reply1, reply2], fn a -> a.object.data["id"] end)
-
- {:ok, federation_output} = Transmogrifier.prepare_outgoing(activity.data)
+ replies = %{
+ "type" => "Collection",
+ "items" => [Utils.generate_object_id(), Utils.generate_object_id()]
+ }
- Repo.delete(activity.object)
- Repo.delete(activity)
+ activity =
+ File.read!("test/fixtures/mastodon-post-activity.json")
+ |> Poison.decode!()
+ |> Kernel.put_in(["object", "replies"], replies)
- %{federation_output: federation_output, replies_uris: replies_uris}
+ %{activity: activity}
end
test "schedules background fetching of `replies` items if max thread depth limit allows", %{
- federation_output: federation_output,
- replies_uris: replies_uris
+ activity: activity
} do
- Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 1)
+ clear_config([:instance, :federation_incoming_replies_max_depth], 1)
- {:ok, _activity} = Transmogrifier.handle_incoming(federation_output)
+ assert {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(activity)
+ object = Object.normalize(data["object"])
- for id <- replies_uris do
+ for id <- object.data["replies"] do
job_args = %{"op" => "fetch_remote", "id" => id, "depth" => 1}
assert_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker, args: job_args)
end
end
test "does NOT schedule background fetching of `replies` beyond max thread depth limit allows",
- %{federation_output: federation_output} do
- Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
+ %{activity: activity} do
+ clear_config([:instance, :federation_incoming_replies_max_depth], 0)
- {:ok, _activity} = Transmogrifier.handle_incoming(federation_output)
+ {:ok, _activity} = Transmogrifier.handle_incoming(activity)
assert all_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker) == []
end
@@ -496,6 +455,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
"object" => %{
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
"cc" => [],
+ "id" => Utils.generate_object_id(),
"type" => "Note",
"content" => "Hi",
"inReplyTo" => nil,
@@ -520,6 +480,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
"object" => %{
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
"cc" => [],
+ "id" => Utils.generate_object_id(),
"type" => "Note",
"content" => "Hi",
"inReplyTo" => nil,
@@ -551,7 +512,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
end
test "returns object with inReplyTo when denied incoming reply", %{data: data} do
- Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
+ clear_config([:instance, :federation_incoming_replies_max_depth], 0)
object_with_reply =
Map.put(data["object"], "inReplyTo", "https://shitposter.club/notice/2827873")
@@ -585,7 +546,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
"https://mstdn.io/users/mayuutann/statuses/99568293732299394"
)
- Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 5)
+ clear_config([:instance, :federation_incoming_replies_max_depth], 5)
modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
assert modified_object["inReplyTo"] ==
@@ -725,7 +686,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
in_reply_to_status_id: id1
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
replies_uris = Enum.map([self_reply1, self_reply2], fn a -> a.object.data["id"] end)
assert %{"type" => "Collection", "items" => ^replies_uris} =
@@ -746,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
new file mode 100644
index 000000000..d50c7f4ef
--- /dev/null
+++ b/test/pleroma/web/activity_pub/transmogrifier/page_handling_test.exs
@@ -0,0 +1,36 @@
+# 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.PageHandlingTest do
+ use Oban.Testing, repo: Pleroma.Repo
+ use Pleroma.DataCase
+
+ alias Pleroma.Object.Fetcher
+
+ test "Lemmy Page" do
+ Tesla.Mock.mock(fn
+ %{url: "https://enterprise.lemmy.ml/post/3"} ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/activity+json"}],
+ body: File.read!("test/fixtures/tesla_mock/lemmy-page.json")
+ }
+
+ %{url: "https://enterprise.lemmy.ml/u/nutomic"} ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/activity+json"}],
+ body: File.read!("test/fixtures/tesla_mock/lemmy-user.json")
+ }
+ end)
+
+ {:ok, object} = Fetcher.fetch_object_from_id("https://enterprise.lemmy.ml/post/3")
+
+ assert object.data["summary"] == "Hello Federation!"
+ assert object.data["published"] == "2020-09-14T15:03:11.909105Z"
+
+ # WAT
+ assert object.data["url"] == "https://enterprise.lemmy.ml/pictrs/image/US52d9DPvf.jpg"
+ end
+end
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 47f92cf4d..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-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.QuestionHandlingTest do
@@ -22,7 +22,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.QuestionHandlingTest do
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
- object = Object.normalize(activity, false)
+ object = Object.normalize(activity, fetch: false)
assert object.data["url"] == "https://mastodon.sdf.org/@rinpatch/102070944809637304"
@@ -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"]) ==
@@ -65,10 +63,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.QuestionHandlingTest do
{:ok, reply_activity} = CommonAPI.post(user, %{status: "hewwo", in_reply_to_id: activity.id})
- reply_object = Object.normalize(reply_activity, false)
+ 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
@@ -101,7 +98,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.QuestionHandlingTest do
|> Kernel.put_in(["object", "oneOf"], options)
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
- object = Object.normalize(activity, false)
+ object = Object.normalize(activity, fetch: false)
assert Enum.sort(object.data["oneOf"]) == Enum.sort(options)
end
@@ -147,7 +144,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.QuestionHandlingTest do
|> Kernel.put_in(["object", "tag"], tag)
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
- object = Object.normalize(activity, false)
+ object = Object.normalize(activity, fetch: false)
assert object.data["oneOf"] == options
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 851236758..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-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.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 107121ef8..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-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.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 8ed5e5e90..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-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.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 57411fafa..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-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.VideoHandlingTest do
@@ -24,7 +24,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
- assert object = Object.normalize(activity, false)
+ assert object = Object.normalize(activity, fetch: false)
assert object.data["content"] == nil
end
@@ -34,7 +34,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
- assert object = Object.normalize(activity, false)
+ assert object = Object.normalize(activity, fetch: false)
assert object.data["content"] ==
"<p>Après avoir mené avec un certain succès la campagne « Dégooglisons Internet » en 2014, l’association Framasoft annonce fin 2019 arrêter progressivement un certain nombre de ses services alternatifs aux GAFAM. Pourquoi ?</p><p>Transcription par @aprilorg ici : <a href=\"https://www.april.org/deframasoftisons-internet-pierre-yves-gosset-framasoft\">https://www.april.org/deframasoftisons-internet-pierre-yves-gosset-framasoft</a></p>"
@@ -53,14 +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"
+ "type" => "Link",
+ "width" => 480
}
]
}
@@ -70,20 +69,19 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
- assert object = Object.normalize(activity, false)
+ assert object = Object.normalize(activity, fetch: false)
assert object.data["attachment"] == [
%{
"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"
+ "type" => "Link",
+ "height" => 1080
}
]
}
@@ -92,4 +90,33 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
assert object.data["url"] ==
"https://framatube.org/videos/watch/6050732a-8a7a-43d4-a6cd-809525a1d206"
end
+
+ test "it works for peertube videos with only their mpegURL map" do
+ data =
+ File.read!("test/fixtures/peertube/video-object-mpegURL-only.json")
+ |> Jason.decode!()
+
+ {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
+
+ assert object = Object.normalize(activity, fetch: false)
+
+ assert object.data["attachment"] == [
+ %{
+ "type" => "Link",
+ "mediaType" => "video/mp4",
+ "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",
+ "height" => 1080
+ }
+ ]
+ }
+ ]
+
+ assert object.data["url"] ==
+ "https://peertube.stream/videos/watch/abece3c3-b9c6-47f4-8040-f3eed8c602e6"
+ end
end
diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs
index 66ea7664a..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-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.TransmogrifierTest do
@@ -11,6 +11,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
alias Pleroma.Web.ActivityPub.Transmogrifier
+ alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.AdminAPI.AccountView
alias Pleroma.Web.CommonAPI
@@ -56,11 +57,11 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
other_user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "test post"})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
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})
@@ -106,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
@@ -153,23 +170,13 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
end
end
- test "it adds the sensitive property" do
- user = insert(:user)
-
- {:ok, activity} = CommonAPI.post(user, %{status: "#nsfw hey"})
- {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
-
- assert modified["object"]["sensitive"]
- end
-
test "it adds the json-ld context and the conversation property" do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
- assert modified["@context"] ==
- Pleroma.Web.ActivityPub.Utils.make_json_ld_header()["@context"]
+ assert modified["@context"] == Utils.make_json_ld_header()["@context"]
assert modified["object"]["conversation"] == modified["context"]
end
@@ -202,7 +209,20 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
test "it strips internal fields" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{status: "#2hu :firefox:"})
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ status: "#2hu :firefox:",
+ generator: %{type: "Application", name: "TestClient", url: "https://pleroma.social"}
+ })
+
+ # Ensure injected application data made it into the activity
+ # as we don't have a Token to derive it from, otherwise it will
+ # be nil and the test will pass
+ assert %{
+ type: "Application",
+ name: "TestClient",
+ url: "https://pleroma.social"
+ } == activity.object.data["generator"]
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
@@ -212,7 +232,7 @@ 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
test "it strips internal fields of article" do
@@ -226,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
@@ -281,6 +300,43 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, _modified} = Transmogrifier.prepare_outgoing(activity.data)
end
+
+ test "custom emoji urls are URI encoded" do
+ # :dinosaur: filename has a space -> dino walking.gif
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "everybody do the dinosaur :dinosaur:"})
+
+ {:ok, prepared} = Transmogrifier.prepare_outgoing(activity.data)
+
+ assert length(prepared["object"]["tag"]) == 1
+
+ url = prepared["object"]["tag"] |> List.first() |> Map.get("icon") |> Map.get("url")
+
+ 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
@@ -426,7 +482,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
end)
}
- fixed_object = Transmogrifier.fix_explicit_addressing(object)
+ fixed_object = Transmogrifier.fix_explicit_addressing(object, user.follower_address)
assert Enum.all?(explicitly_mentioned_actors, &(&1 in fixed_object["to"]))
refute "https://social.beepboop.ga/users/dirb" in fixed_object["to"]
assert "https://social.beepboop.ga/users/dirb" in fixed_object["cc"]
@@ -439,7 +495,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
"cc" => []
}
- fixed_object = Transmogrifier.fix_explicit_addressing(object)
+ fixed_object = Transmogrifier.fix_explicit_addressing(object, user.follower_address)
assert user.follower_address in fixed_object["to"]
refute user.follower_address in fixed_object["cc"]
end
@@ -453,7 +509,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
"cc" => [user.follower_address, recipient.follower_address]
}
- fixed_object = Transmogrifier.fix_explicit_addressing(object)
+ fixed_object = Transmogrifier.fix_explicit_addressing(object, user.follower_address)
assert user.follower_address in fixed_object["cc"]
refute recipient.follower_address in fixed_object["cc"]
@@ -504,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 2263b6091..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-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.UtilsTest do
@@ -165,7 +165,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
{:ok, votes, object} = CommonAPI.vote(other_user, object, [0, 1])
assert Enum.sort(Utils.get_existing_votes(other_user.ap_id, object)) == Enum.sort(votes)
end
@@ -183,7 +183,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
{:ok, [vote], object} = CommonAPI.vote(other_user, object, [0])
{:ok, _activity} = CommonAPI.favorite(user, activity.id)
[fetched_vote] = Utils.get_existing_votes(other_user.ap_id, object)
@@ -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
@@ -242,7 +256,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
test "updates likes" do
user = insert(:user)
activity = insert(:note_activity)
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert {:ok, updated_object} =
Utils.update_element_in_object(
@@ -302,7 +316,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
describe "get_existing_like/2" do
test "fetches existing like" do
note_activity = insert(:note_activity)
- assert object = Object.normalize(note_activity)
+ assert object = Object.normalize(note_activity, fetch: false)
user = insert(:user)
refute Utils.get_existing_like(user.ap_id, object)
@@ -320,7 +334,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
test "fetches existing announce" do
note_activity = insert(:note_activity)
- assert object = Object.normalize(note_activity)
+ assert object = Object.normalize(note_activity, fetch: false)
actor = insert(:user)
{:ok, announce} = CommonAPI.repeat(note_activity.id, actor)
@@ -412,10 +426,9 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
describe "lazy_put_activity_defaults/2" do
test "returns map with id and published data" do
note_activity = insert(:note_activity)
- object = Object.normalize(note_activity)
+ 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)
@@ -431,7 +443,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
test "returns activity data with object" do
note_activity = insert(:note_activity)
- object = Object.normalize(note_activity)
+ object = Object.normalize(note_activity, fetch: false)
res =
Utils.lazy_put_activity_defaults(%{
@@ -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 f0389845d..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-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.ObjectViewTest do
@@ -24,7 +24,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
test "renders a note activity" do
note = insert(:note_activity)
- object = Object.normalize(note)
+ object = Object.normalize(note, fetch: false)
result = ObjectView.render("object.json", %{object: note})
@@ -56,7 +56,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
test "renders a like activity" do
note = insert(:note_activity)
- object = Object.normalize(note)
+ object = Object.normalize(note, fetch: false)
user = insert(:user)
{:ok, like_activity} = CommonAPI.favorite(user, note.id)
@@ -70,7 +70,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
test "renders an announce activity" do
note = insert(:note_activity)
- object = Object.normalize(note)
+ object = Object.normalize(note, fetch: false)
user = insert(:user)
{:ok, announce_activity} = CommonAPI.repeat(note.id, user)
@@ -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 5702c1b6f..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-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.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 1ec41aa19..8c4c06a95 100644
--- a/test/pleroma/web/activity_pub/visibility_test.exs
+++ b/test/pleroma/web/activity_pub/visibility_test.exs
@@ -1,11 +1,12 @@
# 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.VisibilityTest do
use Pleroma.DataCase, async: true
alias Pleroma.Activity
+ alias Pleroma.Object
alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
@@ -107,7 +108,7 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
assert Visibility.is_list?(list)
end
- test "visible_for_user?", %{
+ test "visible_for_user? Activity", %{
public: public,
private: private,
direct: direct,
@@ -149,10 +150,76 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
refute Visibility.visible_for_user?(private, unrelated)
refute Visibility.visible_for_user?(direct, unrelated)
+ # Public and unlisted visible for unauthenticated
+
+ assert Visibility.visible_for_user?(public, nil)
+ assert Visibility.visible_for_user?(unlisted, nil)
+ refute Visibility.visible_for_user?(private, nil)
+ refute Visibility.visible_for_user?(direct, nil)
+
# Visible for a list member
assert Visibility.visible_for_user?(list, unrelated)
end
+ test "visible_for_user? Object", %{
+ public: public,
+ private: private,
+ direct: direct,
+ unlisted: unlisted,
+ user: user,
+ mentioned: mentioned,
+ following: following,
+ unrelated: unrelated,
+ list: list
+ } do
+ public = Object.normalize(public)
+ private = Object.normalize(private)
+ unlisted = Object.normalize(unlisted)
+ direct = Object.normalize(direct)
+ list = Object.normalize(list)
+
+ # All visible to author
+
+ assert Visibility.visible_for_user?(public, user)
+ assert Visibility.visible_for_user?(private, user)
+ assert Visibility.visible_for_user?(unlisted, user)
+ assert Visibility.visible_for_user?(direct, user)
+ assert Visibility.visible_for_user?(list, user)
+
+ # All visible to a mentioned user
+
+ assert Visibility.visible_for_user?(public, mentioned)
+ assert Visibility.visible_for_user?(private, mentioned)
+ assert Visibility.visible_for_user?(unlisted, mentioned)
+ assert Visibility.visible_for_user?(direct, mentioned)
+ assert Visibility.visible_for_user?(list, mentioned)
+
+ # DM not visible for just follower
+
+ assert Visibility.visible_for_user?(public, following)
+ assert Visibility.visible_for_user?(private, following)
+ assert Visibility.visible_for_user?(unlisted, following)
+ refute Visibility.visible_for_user?(direct, following)
+ refute Visibility.visible_for_user?(list, following)
+
+ # Public and unlisted visible for unrelated user
+
+ assert Visibility.visible_for_user?(public, unrelated)
+ assert Visibility.visible_for_user?(unlisted, unrelated)
+ refute Visibility.visible_for_user?(private, unrelated)
+ refute Visibility.visible_for_user?(direct, unrelated)
+
+ # Public and unlisted visible for unauthenticated
+
+ assert Visibility.visible_for_user?(public, nil)
+ assert Visibility.visible_for_user?(unlisted, nil)
+ refute Visibility.visible_for_user?(private, nil)
+ refute Visibility.visible_for_user?(direct, nil)
+
+ # Visible for a list member
+ # assert Visibility.visible_for_user?(list, unrelated)
+ end
+
test "doesn't die when the user doesn't exist",
%{
direct: direct,
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 90b25b782..d83f7f011 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,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.AdminAPI.AdminAPIControllerTest do
@@ -46,104 +46,47 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert json_response(conn, 200)
end
- describe "with [:auth, :enforce_oauth_admin_scope_usage]," do
- setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], true)
+ 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}"
- 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(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(conn, :forbidden)
- end
+ 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(conn, 200)
end
- end
- describe "unless [:auth, :enforce_oauth_admin_scope_usage]," do
- setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
+ for good_token <- [good_token1, good_token2, good_token3] do
+ conn =
+ build_conn()
+ |> assign(:user, nil)
+ |> assign(:token, good_token)
+ |> get(url)
- test "GET /api/pleroma/admin/users/:nickname requires " <>
- "read:accounts or 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"])
- good_token4 = insert(:oauth_token, user: admin, scopes: ["read:accounts"])
- good_token5 = insert(:oauth_token, user: admin, scopes: ["read"])
-
- good_tokens = [good_token1, good_token2, good_token3, good_token4, good_token5]
-
- bad_token1 = insert(:oauth_token, user: admin, scopes: ["read:accounts:partial"])
- bad_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts:partial"])
- bad_token3 = nil
-
- for good_token <- good_tokens do
- conn =
- build_conn()
- |> assign(:user, admin)
- |> assign(:token, good_token)
- |> get(url)
-
- assert json_response(conn, 200)
- end
-
- for good_token <- good_tokens 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(conn, :forbidden)
- end
+ 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(conn, :forbidden)
end
end
@@ -324,9 +267,7 @@ 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
@@ -405,13 +346,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
setup do
user = insert(:user)
- date1 = (DateTime.to_unix(DateTime.utc_now()) + 2000) |> DateTime.from_unix!()
- date2 = (DateTime.to_unix(DateTime.utc_now()) + 1000) |> DateTime.from_unix!()
- date3 = (DateTime.to_unix(DateTime.utc_now()) + 3000) |> DateTime.from_unix!()
-
- insert(:note_activity, user: user, published: date1)
- insert(:note_activity, user: user, published: date2)
- insert(:note_activity, user: user, published: date3)
+ insert(:note_activity, user: user)
+ insert(:note_activity, user: user)
+ insert(:note_activity, user: user)
%{user: user}
end
@@ -419,23 +356,22 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
test "renders user's statuses", %{conn: conn, user: user} do
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses")
- assert json_response(conn, 200) |> length() == 3
+ assert %{"total" => 3, "activities" => activities} = json_response(conn, 200)
+ assert length(activities) == 3
end
test "renders user's statuses with pagination", %{conn: conn, user: user} do
- conn1 = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=1&page=1")
-
- response1 = json_response(conn1, 200)
-
- assert response1 |> length() == 1
-
- conn2 = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=1&page=2")
-
- response2 = json_response(conn2, 200)
+ %{"total" => 3, "activities" => [activity1]} =
+ conn
+ |> get("/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=1&page=1")
+ |> json_response(200)
- assert response2 |> length() == 1
+ %{"total" => 3, "activities" => [activity2]} =
+ conn
+ |> get("/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=1&page=2")
+ |> json_response(200)
- refute response1 == response2
+ refute activity1 == activity2
end
test "doesn't return private statuses by default", %{conn: conn, user: user} do
@@ -443,9 +379,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
{:ok, _public_status} = CommonAPI.post(user, %{status: "public", visibility: "public"})
- conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses")
+ %{"total" => 4, "activities" => activities} =
+ conn
+ |> get("/api/pleroma/admin/users/#{user.nickname}/statuses")
+ |> json_response(200)
- assert json_response(conn, 200) |> length() == 4
+ assert length(activities) == 4
end
test "returns private statuses with godmode on", %{conn: conn, user: user} do
@@ -453,9 +392,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
{:ok, _public_status} = CommonAPI.post(user, %{status: "public", visibility: "public"})
- conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?godmode=true")
+ %{"total" => 5, "activities" => activities} =
+ conn
+ |> get("/api/pleroma/admin/users/#{user.nickname}/statuses?godmode=true")
+ |> json_response(200)
- assert json_response(conn, 200) |> length() == 5
+ assert length(activities) == 5
end
test "excludes reblogs by default", %{conn: conn, user: user} do
@@ -463,13 +405,17 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
{:ok, activity} = CommonAPI.post(user, %{status: "."})
{:ok, %Activity{}} = CommonAPI.repeat(activity.id, other_user)
- conn_res = get(conn, "/api/pleroma/admin/users/#{other_user.nickname}/statuses")
- assert json_response(conn_res, 200) |> length() == 0
-
- conn_res =
- get(conn, "/api/pleroma/admin/users/#{other_user.nickname}/statuses?with_reblogs=true")
+ assert %{"total" => 0, "activities" => []} ==
+ conn
+ |> get("/api/pleroma/admin/users/#{other_user.nickname}/statuses")
+ |> json_response(200)
- assert json_response(conn_res, 200) |> length() == 1
+ assert %{"total" => 1, "activities" => [_]} =
+ conn
+ |> get(
+ "/api/pleroma/admin/users/#{other_user.nickname}/statuses?with_reblogs=true"
+ )
+ |> json_response(200)
end
end
@@ -852,49 +798,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
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)
-
- ret_conn = get(conn, "/api/pleroma/admin/instances/archae.me/statuses")
-
- response = json_response(ret_conn, 200)
-
- assert length(response) == 2
-
- ret_conn = get(conn, "/api/pleroma/admin/instances/test.com/statuses")
-
- response = json_response(ret_conn, 200)
-
- assert length(response) == 1
-
- ret_conn = get(conn, "/api/pleroma/admin/instances/nonexistent.com/statuses")
-
- response = json_response(ret_conn, 200)
-
- assert Enum.empty?(response)
-
- CommonAPI.repeat(activity.id, user)
-
- ret_conn = get(conn, "/api/pleroma/admin/instances/archae.me/statuses")
- response = json_response(ret_conn, 200)
- assert length(response) == 2
-
- ret_conn = get(conn, "/api/pleroma/admin/instances/archae.me/statuses?with_reblogs=true")
- response = json_response(ret_conn, 200)
- assert length(response) == 3
- end
- end
-
describe "PATCH /confirm_email" do
test "it confirms emails of two users", %{conn: conn, admin: admin} do
- [first_user, second_user] = insert_pair(:user, confirmation_pending: true)
+ [first_user, second_user] = insert_pair(:user, is_confirmed: false)
- assert first_user.confirmation_pending == true
- assert second_user.confirmation_pending == true
+ refute first_user.is_confirmed
+ refute second_user.is_confirmed
ret_conn =
patch(conn, "/api/pleroma/admin/users/confirm_email", %{
@@ -906,21 +815,22 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert ret_conn.status == 200
- assert first_user.confirmation_pending == true
- assert second_user.confirmation_pending == true
+ first_user = User.get_by_id(first_user.id)
+ second_user = User.get_by_id(second_user.id)
+
+ assert first_user.is_confirmed
+ assert second_user.is_confirmed
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
end
describe "PATCH /resend_confirmation_email" do
test "it resend emails for two users", %{conn: conn, admin: admin} do
- [first_user, second_user] = insert_pair(:user, confirmation_pending: true)
+ [first_user, second_user] = insert_pair(:user, is_confirmed: false)
ret_conn =
patch(conn, "/api/pleroma/admin/users/resend_confirmation_email", %{
@@ -935,9 +845,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()
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..5b8148c05
--- /dev/null
+++ b/test/pleroma/web/admin_api/controllers/announcement_controller_test.exs
@@ -0,0 +1,281 @@
+# 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
+
+ import Pleroma.Factory
+
+ 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
+
+ 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 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 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 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 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 "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 dead1c09e..0ef7c367b 100644
--- a/test/pleroma/web/admin_api/controllers/chat_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/chat_controller_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.AdminAPI.ChatControllerTest do
@@ -36,7 +36,7 @@ defmodule Pleroma.Web.AdminAPI.ChatControllerTest do
{:ok, message} =
CommonAPI.post_chat_message(user, recipient, "Hello darkness my old friend")
- object = Object.normalize(message, false)
+ object = Object.normalize(message, fetch: false)
chat = Chat.get(user.id, recipient.ap_id)
recipient_chat = Chat.get(recipient.id, user.ap_id)
@@ -53,7 +53,7 @@ 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)
@@ -143,7 +143,7 @@ defmodule Pleroma.Web.AdminAPI.ChatControllerTest do
recipient = insert(:user)
{:ok, message} = CommonAPI.post_chat_message(user, recipient, "Yo")
- object = Object.normalize(message, false)
+ object = Object.normalize(message, fetch: false)
chat = Chat.get(user.id, recipient.ap_id)
cm_ref = MessageReference.for_chat_and_object(chat, object)
@@ -183,7 +183,7 @@ defmodule Pleroma.Web.AdminAPI.ChatControllerTest do
recipient = insert(:user)
{:ok, message} = CommonAPI.post_chat_message(user, recipient, "Yo")
- object = Object.normalize(message, false)
+ object = Object.normalize(message, fetch: false)
chat = Chat.get(user.id, recipient.ap_id)
cm_ref = MessageReference.for_chat_and_object(chat, object)
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 df5d74d45..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-2020 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
@@ -8,7 +8,6 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
import ExUnit.CaptureLog
import Pleroma.Factory
- alias Pleroma.Config
alias Pleroma.ConfigDB
setup do
@@ -27,12 +26,12 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
setup do: clear_config(:configurable_from_database, true)
test "when configuration from database is off", %{conn: conn} do
- Config.put(:configurable_from_database, false)
+ clear_config(:configurable_from_database, false)
conn = get(conn, "/api/pleroma/admin/config")
assert json_response_and_validate_schema(conn, 400) ==
%{
- "error" => "To use this endpoint you need to enable configuration from database."
+ "error" => "You must enable configurable_from_database in your config file."
}
end
@@ -171,7 +170,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|> post("/api/pleroma/admin/config", %{"configs" => []})
assert json_response_and_validate_schema(conn, 400) ==
- %{"error" => "To use this endpoint you need to enable configuration from database."}
+ %{"error" => "You must enable configurable_from_database in your config file."}
end
describe "POST /api/pleroma/admin/config" do
@@ -318,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 =
@@ -334,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"]
}
]
})
@@ -354,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
@@ -410,8 +409,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
end
test "saving config which need pleroma reboot", %{conn: conn} do
- chat = Config.get(:chat)
- on_exit(fn -> Config.put(:chat, chat) end)
+ clear_config([:shout, :enabled], true)
assert conn
|> put_req_header("content-type", "application/json")
@@ -419,7 +417,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
"/api/pleroma/admin/config",
%{
configs: [
- %{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]}
+ %{group: ":pleroma", key: ":shout", value: [%{"tuple" => [":enabled", true]}]}
]
}
)
@@ -428,7 +426,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
%{
"db" => [":enabled"],
"group" => ":pleroma",
- "key" => ":chat",
+ "key" => ":shout",
"value" => [%{"tuple" => [":enabled", true]}]
}
],
@@ -456,8 +454,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
end
test "update setting which need reboot, don't change reboot flag until reboot", %{conn: conn} do
- chat = Config.get(:chat)
- on_exit(fn -> Config.put(:chat, chat) end)
+ clear_config([:shout, :enabled], true)
assert conn
|> put_req_header("content-type", "application/json")
@@ -465,7 +462,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
"/api/pleroma/admin/config",
%{
configs: [
- %{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]}
+ %{group: ":pleroma", key: ":shout", value: [%{"tuple" => [":enabled", true]}]}
]
}
)
@@ -474,7 +471,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
%{
"db" => [":enabled"],
"group" => ":pleroma",
- "key" => ":chat",
+ "key" => ":shout",
"value" => [%{"tuple" => [":enabled", true]}]
}
],
@@ -1413,6 +1410,79 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
"need_reboot" => false
}
end
+
+ test "custom instance thumbnail", %{conn: conn} do
+ clear_config([:instance])
+
+ params = %{
+ "group" => ":pleroma",
+ "key" => ":instance",
+ "value" => [
+ %{
+ "tuple" => [
+ ":instance_thumbnail",
+ "https://example.com/media/new_thumbnail.jpg"
+ ]
+ }
+ ]
+ }
+
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/pleroma/admin/config", %{"configs" => [params]})
+ |> json_response_and_validate_schema(200) ==
+ %{
+ "configs" => [
+ %{
+ "db" => [":instance_thumbnail"],
+ "group" => ":pleroma",
+ "key" => ":instance",
+ "value" => params["value"]
+ }
+ ],
+ "need_reboot" => false
+ }
+
+ assert conn
+ |> get("/api/v1/instance")
+ |> json_response_and_validate_schema(200)
+ |> Map.take(["thumbnail"]) ==
+ %{"thumbnail" => "https://example.com/media/new_thumbnail.jpg"}
+ end
+
+ test "Concurrent Limiter", %{conn: conn} do
+ clear_config([ConcurrentLimiter])
+
+ params = %{
+ "group" => ":pleroma",
+ "key" => "ConcurrentLimiter",
+ "value" => [
+ %{
+ "tuple" => [
+ "Pleroma.Web.RichMedia.Helpers",
+ [
+ %{"tuple" => [":max_running", 6]},
+ %{"tuple" => [":max_waiting", 6]}
+ ]
+ ]
+ },
+ %{
+ "tuple" => [
+ "Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy",
+ [
+ %{"tuple" => [":max_running", 7]},
+ %{"tuple" => [":max_waiting", 7]}
+ ]
+ ]
+ }
+ ]
+ }
+
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/pleroma/admin/config", %{"configs" => [params]})
+ |> json_response_and_validate_schema(200)
+ end
end
describe "GET /api/pleroma/admin/config/descriptions" do
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 94873f6db..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-2020 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
@@ -42,6 +42,20 @@ defmodule Pleroma.Web.AdminAPI.FrontendControllerTest do
refute Enum.any?(response, fn frontend -> frontend["installed"] == true end)
end
+
+ test "it lists available frontends when no frontend folder was created yet", %{conn: conn} do
+ File.rm_rf(@dir)
+
+ response =
+ conn
+ |> get("/api/pleroma/admin/frontends")
+ |> json_response_and_validate_schema(:ok)
+
+ assert Enum.map(response, & &1["name"]) ==
+ Enum.map(Config.get([:frontends, :available]), fn {_, map} -> map["name"] end)
+
+ refute Enum.any?(response, fn frontend -> frontend["installed"] == true end)
+ end
end
describe "POST /api/pleroma/admin/frontends/install" 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..72436cd83
--- /dev/null
+++ b/test/pleroma/web/admin_api/controllers/instance_controller_test.exs
@@ -0,0 +1,80 @@
+# 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
+ 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
+ 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
+ end
+
+ test "DELETE /instances/:instance", %{conn: conn} do
+ 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)
+ 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 ce867dd0e..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-2020 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 ab186c5e7..b9d48a4b6 100644
--- a/test/pleroma/web/admin_api/controllers/invite_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/invite_controller_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.AdminAPI.InviteControllerTest do
@@ -7,7 +7,6 @@ defmodule Pleroma.Web.AdminAPI.InviteControllerTest do
import Pleroma.Factory
- alias Pleroma.Config
alias Pleroma.Repo
alias Pleroma.UserInviteToken
@@ -119,8 +118,8 @@ defmodule Pleroma.Web.AdminAPI.InviteControllerTest do
setup do: clear_config([:instance, :invites_enabled])
test "it returns 500 if `invites_enabled` is not enabled", %{conn: conn} do
- Config.put([:instance, :registrations_open], false)
- Config.put([:instance, :invites_enabled], false)
+ clear_config([:instance, :registrations_open], false)
+ clear_config([:instance, :invites_enabled], false)
conn =
conn
@@ -138,8 +137,8 @@ defmodule Pleroma.Web.AdminAPI.InviteControllerTest do
end
test "it returns 500 if `registrations_open` is enabled", %{conn: conn} do
- Config.put([:instance, :registrations_open], true)
- Config.put([:instance, :invites_enabled], true)
+ clear_config([:instance, :registrations_open], true)
+ clear_config([:instance, :invites_enabled], true)
conn =
conn
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 62fb9592a..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-2020 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
@@ -21,9 +21,9 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|> assign(:user, admin)
|> assign(:token, token)
- Config.put([:media_proxy, :enabled], true)
- Config.put([:media_proxy, :invalidation, :enabled], true)
- Config.put([:media_proxy, :invalidation, :provider], MediaProxy.Invalidation.Script)
+ clear_config([:media_proxy, :enabled], true)
+ clear_config([:media_proxy, :invalidation, :enabled], true)
+ clear_config([:media_proxy, :invalidation, :provider], MediaProxy.Invalidation.Script)
{:ok, %{admin: admin, token: token, conn: conn}}
end
@@ -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 f388375d1..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-2020 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
@@ -8,7 +8,7 @@ defmodule Pleroma.Web.AdminAPI.OAuthAppControllerTest do
import Pleroma.Factory
- alias Pleroma.Web
+ alias Pleroma.Web.Endpoint
setup do
admin = insert(:user, is_admin: true)
@@ -36,7 +36,7 @@ defmodule Pleroma.Web.AdminAPI.OAuthAppControllerTest do
end
test "success", %{conn: conn} do
- base_url = Web.base_url()
+ base_url = Endpoint.url()
app_name = "Trusted app"
response =
@@ -58,7 +58,7 @@ defmodule Pleroma.Web.AdminAPI.OAuthAppControllerTest do
end
test "with trusted", %{conn: conn} do
- base_url = Web.base_url()
+ base_url = Endpoint.url()
app_name = "Trusted app"
response =
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 379067a62..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-2020 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 2ab2f2f6d..6fd3fbe5a 100644
--- a/test/pleroma/web/admin_api/controllers/report_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/report_controller_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.AdminAPI.ReportControllerTest do
@@ -54,6 +54,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")
@@ -204,9 +230,7 @@ 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
@@ -305,7 +329,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
@@ -365,7 +389,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 40714c8a4..8bb96ca87 100644
--- a/test/pleroma/web/admin_api/controllers/status_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/status_controller_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.AdminAPI.StatusControllerTest do
@@ -47,8 +47,8 @@ defmodule Pleroma.Web.AdminAPI.StatusControllerTest do
assert account["id"] == actor.id
assert account["nickname"] == actor.nickname
- assert account["deactivated"] == actor.deactivated
- assert account["confirmation_pending"] == actor.confirmation_pending
+ assert account["is_active"] == actor.is_active
+ assert account["is_confirmed"] == actor.is_confirmed
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 5705306c7..79971be06 100644
--- a/test/pleroma/web/admin_api/controllers/user_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/user_controller_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.AdminAPI.UserControllerTest do
@@ -14,9 +14,9 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
alias Pleroma.Repo
alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
- alias Pleroma.Web
alias Pleroma.Web.ActivityPub.Relay
alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.Endpoint
alias Pleroma.Web.MediaProxy
setup_all do
@@ -44,107 +44,50 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn = get(build_conn(), "/api/pleroma/admin/users/#{user.nickname}?admin_token=password123")
- assert json_response(conn, 200)
+ assert json_response_and_validate_schema(conn, 200)
end
- describe "with [:auth, :enforce_oauth_admin_scope_usage]," do
- setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], true)
-
- 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(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}"
- for good_token <- [good_token1, good_token2, good_token3] do
- conn =
- build_conn()
- |> assign(:user, nil)
- |> assign(:token, good_token)
- |> get(url)
+ 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"])
- assert json_response(conn, :forbidden)
- end
+ 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 bad_token <- [bad_token1, bad_token2, bad_token3] do
- conn =
- build_conn()
- |> assign(:user, admin)
- |> assign(:token, bad_token)
- |> get(url)
+ 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(conn, :forbidden)
- end
+ assert json_response_and_validate_schema(conn, 200)
end
- end
-
- describe "unless [:auth, :enforce_oauth_admin_scope_usage]," do
- setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
-
- test "GET /api/pleroma/admin/users/:nickname requires " <>
- "read:accounts or 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"])
- good_token4 = insert(:oauth_token, user: admin, scopes: ["read:accounts"])
- good_token5 = insert(:oauth_token, user: admin, scopes: ["read"])
-
- good_tokens = [good_token1, good_token2, good_token3, good_token4, good_token5]
-
- bad_token1 = insert(:oauth_token, user: admin, scopes: ["read:accounts:partial"])
- bad_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts:partial"])
- bad_token3 = nil
-
- for good_token <- good_tokens do
- conn =
- build_conn()
- |> assign(:user, admin)
- |> assign(:token, good_token)
- |> get(url)
- assert json_response(conn, 200)
- end
-
- for good_token <- good_tokens do
- conn =
- build_conn()
- |> assign(:user, nil)
- |> assign(:token, good_token)
- |> get(url)
+ 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
+ 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)
+ 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(conn, :forbidden)
- end
+ assert json_response_and_validate_schema(conn, :forbidden)
end
end
@@ -169,7 +112,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
assert user.note_count == 1
assert user.follower_count == 1
assert user.following_count == 1
- refute user.deactivated
+ assert user.is_active
with_mock Pleroma.Web.Federator,
publish: fn _ -> nil end,
@@ -181,17 +124,17 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
ObanHelpers.perform_all()
- assert User.get_by_nickname(user.nickname).deactivated
+ refute User.get_by_nickname(user.nickname).is_active
log_entry = Repo.one(ModerationLog)
assert ModerationLog.get_log_entry_message(log_entry) ==
"@#{admin.nickname} deleted users: @#{user.nickname}"
- assert json_response(conn, 200) == [user.nickname]
+ assert json_response_and_validate_schema(conn, 200) == [user.nickname]
user = Repo.get(User, user.id)
- assert user.deactivated
+ refute user.is_active
assert user.avatar == %{}
assert user.banner == %{}
@@ -209,28 +152,30 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
user_one = insert(:user)
user_two = insert(:user)
- conn =
+ response =
conn
|> put_req_header("accept", "application/json")
+ |> put_req_header("content-type", "application/json")
|> delete("/api/pleroma/admin/users", %{
nicknames: [user_one.nickname, user_two.nickname]
})
+ |> json_response_and_validate_schema(200)
log_entry = Repo.one(ModerationLog)
assert ModerationLog.get_log_entry_message(log_entry) ==
"@#{admin.nickname} deleted users: @#{user_one.nickname}, @#{user_two.nickname}"
- response = json_response(conn, 200)
assert response -- [user_one.nickname, user_two.nickname] == []
end
end
describe "/api/pleroma/admin/users" do
test "Create", %{conn: conn} do
- conn =
+ response =
conn
|> put_req_header("accept", "application/json")
+ |> put_req_header("content-type", "application/json")
|> post("/api/pleroma/admin/users", %{
"users" => [
%{
@@ -245,8 +190,9 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
}
]
})
+ |> json_response_and_validate_schema(200)
+ |> Enum.map(&Map.get(&1, "type"))
- response = json_response(conn, 200) |> Enum.map(&Map.get(&1, "type"))
assert response == ["success", "success"]
log_entry = Repo.one(ModerationLog)
@@ -260,6 +206,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn =
conn
|> put_req_header("accept", "application/json")
+ |> put_req_header("content-type", "application/json")
|> post("/api/pleroma/admin/users", %{
"users" => [
%{
@@ -270,7 +217,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
]
})
- assert json_response(conn, 409) == [
+ assert json_response_and_validate_schema(conn, 409) == [
%{
"code" => 409,
"data" => %{
@@ -289,6 +236,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn =
conn
|> put_req_header("accept", "application/json")
+ |> put_req_header("content-type", "application/json")
|> post("/api/pleroma/admin/users", %{
"users" => [
%{
@@ -299,7 +247,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
]
})
- assert json_response(conn, 409) == [
+ assert json_response_and_validate_schema(conn, 409) == [
%{
"code" => 409,
"data" => %{
@@ -318,6 +266,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn =
conn
|> put_req_header("accept", "application/json")
+ |> put_req_header("content-type", "application/json")
|> post("/api/pleroma/admin/users", %{
"users" => [
%{
@@ -333,7 +282,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
]
})
- assert json_response(conn, 409) == [
+ assert json_response_and_validate_schema(conn, 409) == [
%{
"code" => 409,
"data" => %{
@@ -364,7 +313,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}")
- assert user_response(user) == json_response(conn, 200)
+ assert user_response(user) == json_response_and_validate_schema(conn, 200)
end
test "when the user doesn't exist", %{conn: conn} do
@@ -372,7 +321,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}")
- assert %{"error" => "Not found"} == json_response(conn, 404)
+ assert %{"error" => "Not found"} == json_response_and_validate_schema(conn, 404)
end
end
@@ -383,6 +332,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn
|> put_req_header("accept", "application/json")
+ |> put_req_header("content-type", "application/json")
|> post("/api/pleroma/admin/users/follow", %{
"follower" => follower.nickname,
"followed" => user.nickname
@@ -409,6 +359,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn
|> put_req_header("accept", "application/json")
+ |> put_req_header("content-type", "application/json")
|> post("/api/pleroma/admin/users/unfollow", %{
"follower" => follower.nickname,
"followed" => user.nickname
@@ -429,30 +380,28 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
describe "GET /api/pleroma/admin/users" do
test "renders users array for the first page", %{conn: conn, admin: admin} do
user = insert(:user, local: false, tags: ["foo", "bar"])
- user2 = insert(:user, approval_pending: true, registration_reason: "I'm a chill dude")
+ user2 = insert(:user, is_approved: false, registration_reason: "I'm a chill dude")
conn = get(conn, "/api/pleroma/admin/users?page=1")
- users =
- [
- user_response(
- admin,
- %{"roles" => %{"admin" => true, "moderator" => false}}
- ),
- user_response(user, %{"local" => false, "tags" => ["foo", "bar"]}),
- user_response(
- user2,
- %{
- "local" => true,
- "approval_pending" => true,
- "registration_reason" => "I'm a chill dude",
- "actor_type" => "Person"
- }
- )
- ]
- |> Enum.sort_by(& &1["nickname"])
+ users = [
+ user_response(
+ user2,
+ %{
+ "local" => true,
+ "is_approved" => false,
+ "registration_reason" => "I'm a chill dude",
+ "actor_type" => "Person"
+ }
+ ),
+ user_response(user, %{"local" => false, "tags" => ["foo", "bar"]}),
+ user_response(
+ admin,
+ %{"roles" => %{"admin" => true, "moderator" => false}}
+ )
+ ]
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 3,
"page_size" => 50,
"users" => users
@@ -460,14 +409,14 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
end
test "pagination works correctly with service users", %{conn: conn} do
- service1 = User.get_or_create_service_actor_by_ap_id(Web.base_url() <> "/meido", "meido")
+ service1 = User.get_or_create_service_actor_by_ap_id(Endpoint.url() <> "/meido", "meido")
insert_list(25, :user)
assert %{"count" => 26, "page_size" => 10, "users" => users1} =
conn
|> get("/api/pleroma/admin/users?page=1&filters=", %{page_size: "10"})
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
assert Enum.count(users1) == 10
assert service1 not in users1
@@ -475,7 +424,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
assert %{"count" => 26, "page_size" => 10, "users" => users2} =
conn
|> get("/api/pleroma/admin/users?page=2&filters=", %{page_size: "10"})
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
assert Enum.count(users2) == 10
assert service1 not in users2
@@ -483,7 +432,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
assert %{"count" => 26, "page_size" => 10, "users" => users3} =
conn
|> get("/api/pleroma/admin/users?page=3&filters=", %{page_size: "10"})
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
assert Enum.count(users3) == 6
assert service1 not in users3
@@ -494,7 +443,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn = get(conn, "/api/pleroma/admin/users?page=2")
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 2,
"page_size" => 50,
"users" => []
@@ -506,7 +455,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn = get(conn, "/api/pleroma/admin/users?query=bo")
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 1,
"page_size" => 50,
"users" => [user_response(user, %{"local" => true})]
@@ -519,7 +468,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn = get(conn, "/api/pleroma/admin/users?query=domain.com")
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 1,
"page_size" => 50,
"users" => [user_response(user)]
@@ -532,7 +481,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn = get(conn, "/api/pleroma/admin/users?query=nickname@domain.com")
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 1,
"page_size" => 50,
"users" => [user_response(user)]
@@ -545,7 +494,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn = get(conn, "/api/pleroma/admin/users?name=display")
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 1,
"page_size" => 50,
"users" => [user_response(user)]
@@ -558,7 +507,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn = get(conn, "/api/pleroma/admin/users?email=email@example.com")
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 1,
"page_size" => 50,
"users" => [user_response(user)]
@@ -571,18 +520,18 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn1 = get(conn, "/api/pleroma/admin/users?query=a&page_size=1&page=1")
- assert json_response(conn1, 200) == %{
+ assert json_response_and_validate_schema(conn1, 200) == %{
"count" => 2,
"page_size" => 1,
- "users" => [user_response(user)]
+ "users" => [user_response(user2)]
}
conn2 = get(conn, "/api/pleroma/admin/users?query=a&page_size=1&page=2")
- assert json_response(conn2, 200) == %{
+ assert json_response_and_validate_schema(conn2, 200) == %{
"count" => 2,
"page_size" => 1,
- "users" => [user_response(user2)]
+ "users" => [user_response(user)]
}
end
@@ -599,7 +548,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|> assign(:token, token)
|> get("/api/pleroma/admin/users?query=bo&filters=local")
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 1,
"page_size" => 50,
"users" => [user_response(user)]
@@ -614,20 +563,18 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn = get(conn, "/api/pleroma/admin/users?filters=local")
- users =
- [
- user_response(user),
- user_response(admin, %{
- "roles" => %{"admin" => true, "moderator" => false}
- }),
- user_response(old_admin, %{
- "deactivated" => false,
- "roles" => %{"admin" => true, "moderator" => false}
- })
- ]
- |> Enum.sort_by(& &1["nickname"])
+ users = [
+ user_response(user),
+ user_response(admin, %{
+ "roles" => %{"admin" => true, "moderator" => false}
+ }),
+ user_response(old_admin, %{
+ "is_active" => true,
+ "roles" => %{"admin" => true, "moderator" => false}
+ })
+ ]
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 3,
"page_size" => 50,
"users" => users
@@ -635,25 +582,24 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
end
test "only unconfirmed users", %{conn: conn} do
- sad_user = insert(:user, nickname: "sadboy", confirmation_pending: true)
- old_user = insert(:user, nickname: "oldboy", confirmation_pending: true)
+ sad_user = insert(:user, nickname: "sadboy", is_confirmed: false)
+ old_user = insert(:user, nickname: "oldboy", is_confirmed: false)
- insert(:user, nickname: "happyboy", approval_pending: false)
- insert(:user, confirmation_pending: false)
+ insert(:user, nickname: "happyboy", is_approved: true)
+ insert(:user, is_confirmed: true)
result =
conn
|> get("/api/pleroma/admin/users?filters=unconfirmed")
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
users =
Enum.map([old_user, sad_user], fn user ->
user_response(user, %{
- "confirmation_pending" => true,
- "approval_pending" => false
+ "is_confirmed" => false,
+ "is_approved" => true
})
end)
- |> Enum.sort_by(& &1["nickname"])
assert result == %{"count" => 2, "page_size" => 50, "users" => users}
end
@@ -662,22 +608,22 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
user =
insert(:user,
nickname: "sadboy",
- approval_pending: true,
+ is_approved: false,
registration_reason: "Plz let me in!"
)
- insert(:user, nickname: "happyboy", approval_pending: false)
+ insert(:user, nickname: "happyboy", is_approved: true)
conn = get(conn, "/api/pleroma/admin/users?filters=need_approval")
users = [
user_response(
user,
- %{"approval_pending" => true, "registration_reason" => "Plz let me in!"}
+ %{"is_approved" => false, "registration_reason" => "Plz let me in!"}
)
]
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 1,
"page_size" => 50,
"users" => users
@@ -691,20 +637,18 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn = get(conn, "/api/pleroma/admin/users?filters=is_admin")
- users =
- [
- user_response(admin, %{
- "deactivated" => false,
- "roles" => %{"admin" => true, "moderator" => false}
- }),
- user_response(second_admin, %{
- "deactivated" => false,
- "roles" => %{"admin" => true, "moderator" => false}
- })
- ]
- |> Enum.sort_by(& &1["nickname"])
+ users = [
+ user_response(second_admin, %{
+ "is_active" => true,
+ "roles" => %{"admin" => true, "moderator" => false}
+ }),
+ user_response(admin, %{
+ "is_active" => true,
+ "roles" => %{"admin" => true, "moderator" => false}
+ })
+ ]
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 2,
"page_size" => 50,
"users" => users
@@ -718,12 +662,12 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn = get(conn, "/api/pleroma/admin/users?filters=is_moderator")
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 1,
"page_size" => 50,
"users" => [
user_response(moderator, %{
- "deactivated" => false,
+ "is_active" => true,
"roles" => %{"admin" => false, "moderator" => true}
})
]
@@ -739,16 +683,14 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
response =
conn
- |> get(user_path(conn, :list), %{actor_types: ["Person"]})
- |> json_response(200)
+ |> get(user_path(conn, :index), %{actor_types: ["Person"]})
+ |> json_response_and_validate_schema(200)
- users =
- [
- user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}}),
- user_response(user1),
- user_response(user2)
- ]
- |> Enum.sort_by(& &1["nickname"])
+ users = [
+ user_response(user2),
+ user_response(user1),
+ user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}})
+ ]
assert response == %{"count" => 3, "page_size" => 50, "users" => users}
end
@@ -762,17 +704,15 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
response =
conn
- |> get(user_path(conn, :list), %{actor_types: ["Person", "Service"]})
- |> json_response(200)
+ |> get(user_path(conn, :index), %{actor_types: ["Person", "Service"]})
+ |> json_response_and_validate_schema(200)
- users =
- [
- user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}}),
- user_response(user1),
- user_response(user2),
- user_response(user_service, %{"actor_type" => "Service"})
- ]
- |> Enum.sort_by(& &1["nickname"])
+ users = [
+ user_response(user2),
+ user_response(user1),
+ user_response(user_service, %{"actor_type" => "Service"}),
+ user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}})
+ ]
assert response == %{"count" => 4, "page_size" => 50, "users" => users}
end
@@ -785,8 +725,8 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
response =
conn
- |> get(user_path(conn, :list), %{actor_types: ["Service"]})
- |> json_response(200)
+ |> get(user_path(conn, :index), %{actor_types: ["Service"]})
+ |> json_response_and_validate_schema(200)
users = [user_response(user_service, %{"actor_type" => "Service"})]
@@ -801,14 +741,12 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn = get(conn, "/api/pleroma/admin/users?tags[]=first&tags[]=second")
- users =
- [
- user_response(user1, %{"tags" => ["first"]}),
- user_response(user2, %{"tags" => ["second"]})
- ]
- |> Enum.sort_by(& &1["nickname"])
+ users = [
+ user_response(user2, %{"tags" => ["second"]}),
+ user_response(user1, %{"tags" => ["first"]})
+ ]
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 2,
"page_size" => 50,
"users" => users
@@ -816,8 +754,8 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
end
test "`active` filters out users pending approval", %{token: token} do
- insert(:user, approval_pending: true)
- %{id: user_id} = insert(:user, approval_pending: false)
+ insert(:user, is_approved: false)
+ %{id: user_id} = insert(:user, is_approved: true)
%{id: admin_id} = token.user
conn =
@@ -830,19 +768,19 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
"count" => 2,
"page_size" => 50,
"users" => [
- %{"id" => ^admin_id},
- %{"id" => ^user_id}
+ %{"id" => ^user_id},
+ %{"id" => ^admin_id}
]
- } = json_response(conn, 200)
+ } = json_response_and_validate_schema(conn, 200)
end
test "it works with multiple filters" do
admin = insert(:user, nickname: "john", is_admin: true)
token = insert(:oauth_admin_token, user: admin)
- user = insert(:user, nickname: "bob", local: false, deactivated: true)
+ user = insert(:user, nickname: "bob", local: false, is_active: false)
- insert(:user, nickname: "ken", local: true, deactivated: true)
- insert(:user, nickname: "bobb", local: false, deactivated: false)
+ insert(:user, nickname: "ken", local: true, is_active: false)
+ insert(:user, nickname: "bobb", local: false, is_active: true)
conn =
build_conn()
@@ -850,7 +788,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|> assign(:token, token)
|> get("/api/pleroma/admin/users?filters=deactivated,external")
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 1,
"page_size" => 50,
"users" => [user_response(user)]
@@ -862,7 +800,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
conn = get(conn, "/api/pleroma/admin/users")
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 1,
"page_size" => 50,
"users" => [
@@ -873,18 +811,19 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
end
test "PATCH /api/pleroma/admin/users/activate", %{admin: admin, conn: conn} do
- user_one = insert(:user, deactivated: true)
- user_two = insert(:user, deactivated: true)
+ user_one = insert(:user, is_active: false)
+ user_two = insert(:user, is_active: false)
conn =
- patch(
- conn,
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch(
"/api/pleroma/admin/users/activate",
%{nicknames: [user_one.nickname, user_two.nickname]}
)
- response = json_response(conn, 200)
- assert Enum.map(response["users"], & &1["deactivated"]) == [false, false]
+ response = json_response_and_validate_schema(conn, 200)
+ assert Enum.map(response["users"], & &1["is_active"]) == [true, true]
log_entry = Repo.one(ModerationLog)
@@ -893,18 +832,19 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
end
test "PATCH /api/pleroma/admin/users/deactivate", %{admin: admin, conn: conn} do
- user_one = insert(:user, deactivated: false)
- user_two = insert(:user, deactivated: false)
+ user_one = insert(:user, is_active: true)
+ user_two = insert(:user, is_active: true)
conn =
- patch(
- conn,
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch(
"/api/pleroma/admin/users/deactivate",
%{nicknames: [user_one.nickname, user_two.nickname]}
)
- response = json_response(conn, 200)
- assert Enum.map(response["users"], & &1["deactivated"]) == [true, true]
+ response = json_response_and_validate_schema(conn, 200)
+ assert Enum.map(response["users"], & &1["is_active"]) == [false, false]
log_entry = Repo.one(ModerationLog)
@@ -913,18 +853,19 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
end
test "PATCH /api/pleroma/admin/users/approve", %{admin: admin, conn: conn} do
- user_one = insert(:user, approval_pending: true)
- user_two = insert(:user, approval_pending: true)
+ user_one = insert(:user, is_approved: false)
+ user_two = insert(:user, is_approved: false)
conn =
- patch(
- conn,
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch(
"/api/pleroma/admin/users/approve",
%{nicknames: [user_one.nickname, user_two.nickname]}
)
- response = json_response(conn, 200)
- assert Enum.map(response["users"], & &1["approval_pending"]) == [false, false]
+ response = json_response_and_validate_schema(conn, 200)
+ assert Enum.map(response["users"], & &1["is_approved"]) == [true, true]
log_entry = Repo.one(ModerationLog)
@@ -932,15 +873,68 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
"@#{admin.nickname} approved users: @#{user_one.nickname}, @#{user_two.nickname}"
end
+ test "PATCH /api/pleroma/admin/users/suggest", %{admin: admin, conn: conn} do
+ user1 = insert(:user, is_suggested: false)
+ user2 = insert(:user, is_suggested: false)
+
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch(
+ "/api/pleroma/admin/users/suggest",
+ %{nicknames: [user1.nickname, user2.nickname]}
+ )
+ |> json_response_and_validate_schema(200)
+
+ 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} added suggested users: @#{user1.nickname}, @#{user2.nickname}"
+ end
+
+ test "PATCH /api/pleroma/admin/users/unsuggest", %{admin: admin, conn: conn} do
+ user1 = insert(:user, is_suggested: true)
+ user2 = insert(:user, is_suggested: true)
+
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> 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])
+
+ refute user1.is_suggested
+ refute user2.is_suggested
+
+ log_entry = Repo.one(ModerationLog)
+
+ assert ModerationLog.get_log_entry_message(log_entry) ==
+ "@#{admin.nickname} removed suggested users: @#{user1.nickname}, @#{user2.nickname}"
+ end
+
test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation", %{admin: admin, conn: conn} do
user = insert(:user)
- conn = patch(conn, "/api/pleroma/admin/users/#{user.nickname}/toggle_activation")
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> patch("/api/pleroma/admin/users/#{user.nickname}/toggle_activation")
- assert json_response(conn, 200) ==
+ assert json_response_and_validate_schema(conn, 200) ==
user_response(
user,
- %{"deactivated" => !user.deactivated}
+ %{"is_active" => !user.is_active}
)
log_entry = Repo.one(ModerationLog)
@@ -951,19 +945,22 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
defp user_response(user, attrs \\ %{}) do
%{
- "deactivated" => user.deactivated,
+ "is_active" => user.is_active,
"id" => user.id,
+ "email" => user.email,
"nickname" => user.nickname,
"roles" => %{"admin" => false, "moderator" => false},
"local" => user.local,
"tags" => [],
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(user.name || user.nickname),
- "confirmation_pending" => false,
- "approval_pending" => false,
+ "is_confirmed" => true,
+ "is_approved" => true,
+ "is_suggested" => false,
"url" => user.ap_id,
"registration_reason" => nil,
- "actor_type" => "Person"
+ "actor_type" => "Person",
+ "created_at" => CommonAPI.Utils.to_masto_date(user.inserted_at)
}
|> Map.merge(attrs)
end
diff --git a/test/pleroma/web/admin_api/search_test.exs b/test/pleroma/web/admin_api/search_test.exs
index fdf22a8e6..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-2020 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
@@ -47,9 +47,9 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
end
test "it returns active/deactivated users" do
- insert(:user, deactivated: true)
- insert(:user, deactivated: true)
- insert(:user, deactivated: false)
+ insert(:user, is_active: false)
+ insert(:user, is_active: false)
+ insert(:user, is_active: true)
{:ok, _results, active_count} =
Search.user(%{
@@ -70,7 +70,7 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
test "it returns specific user" do
insert(:user)
insert(:user)
- user = insert(:user, nickname: "bob", local: true, deactivated: false)
+ user = insert(:user, nickname: "bob", local: true, is_active: true)
{:ok, _results, total_count} = Search.user(%{query: ""})
@@ -151,9 +151,9 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
{:ok, [^user_service], 1} = Search.user(%{actor_types: ["Service"]})
{:ok, [^user_application], 1} = Search.user(%{actor_types: ["Application"]})
- {:ok, [^user1, ^user2], 2} = Search.user(%{actor_types: ["Person"]})
+ {:ok, [^user2, ^user1], 2} = Search.user(%{actor_types: ["Person"]})
- {:ok, [^user_service, ^user1, ^user2], 3} =
+ {:ok, [^user2, ^user1, ^user_service], 3} =
Search.user(%{actor_types: ["Person", "Service"]})
end
@@ -182,7 +182,7 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
end
test "it returns unapproved user" do
- unapproved = insert(:user, approval_pending: true)
+ unapproved = insert(:user, is_approved: false)
insert(:user)
insert(:user)
@@ -193,7 +193,7 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
end
test "it returns unconfirmed user" do
- unconfirmed = insert(:user, confirmation_pending: true)
+ unconfirmed = insert(:user, is_confirmed: false)
insert(:user)
insert(:user)
diff --git a/test/pleroma/web/admin_api/views/account_view_test.exs b/test/pleroma/web/admin_api/views/account_view_test.exs
new file mode 100644
index 000000000..aecaf086c
--- /dev/null
+++ b/test/pleroma/web/admin_api/views/account_view_test.exs
@@ -0,0 +1,16 @@
+# 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.AccountViewTest do
+ use Pleroma.DataCase, async: true
+ import Pleroma.Factory
+ alias Pleroma.Web.AdminAPI.AccountView
+
+ describe "show.json" do
+ test "renders the user's email" do
+ user = insert(:user, email: "yolo@yolofam.tld")
+ assert %{"email" => "yolo@yolofam.tld"} = AccountView.render("show.json", %{user: user})
+ end
+ end
+end
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 a4748990e..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-2020 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 3914751b5..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-2020 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 f00e834fc..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-2020 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 498554060..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-2020 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 862eb8051..bac796cd2 100644
--- a/test/pleroma/web/auth/authenticator_test.exs
+++ b/test/pleroma/web/auth/authenticator_test.exs
@@ -1,42 +1,42 @@
# 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.Auth.AuthenticatorTest do
use Pleroma.Web.ConnCase, async: true
- alias Pleroma.Web.Auth.Authenticator
+ alias Pleroma.Web.Auth.Helpers
import Pleroma.Factory
describe "fetch_user/1" do
test "returns user by name" do
user = insert(:user)
- assert Authenticator.fetch_user(user.nickname) == user
+ assert Helpers.fetch_user(user.nickname) == user
end
test "returns user by email" do
user = insert(:user)
- assert Authenticator.fetch_user(user.email) == user
+ assert Helpers.fetch_user(user.email) == user
end
test "returns nil" do
- assert Authenticator.fetch_user("email") == nil
+ assert Helpers.fetch_user("email") == nil
end
end
describe "fetch_credentials/1" do
test "returns name and password from authorization params" do
params = %{"authorization" => %{"name" => "test", "password" => "test-pass"}}
- assert Authenticator.fetch_credentials(params) == {:ok, {"test", "test-pass"}}
+ assert Helpers.fetch_credentials(params) == {:ok, {"test", "test-pass"}}
end
test "returns name and password with grant_type 'password'" do
params = %{"grant_type" => "password", "username" => "test", "password" => "test-pass"}
- assert Authenticator.fetch_credentials(params) == {:ok, {"test", "test-pass"}}
+ assert Helpers.fetch_credentials(params) == {:ok, {"test", "test-pass"}}
end
test "returns error" do
- assert Authenticator.fetch_credentials(%{}) == {:error, :invalid_credentials}
+ assert Helpers.fetch_credentials(%{}) == {:error, :invalid_credentials}
end
end
end
diff --git a/test/pleroma/web/auth/basic_auth_test.exs b/test/pleroma/web/auth/basic_auth_test.exs
index e56c1e1e8..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-2020 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
@@ -11,7 +11,7 @@ defmodule Pleroma.Web.Auth.BasicAuthTest do
conn: conn
} do
user = insert(:user)
- assert Pbkdf2.verify_pass("test", user.password_hash)
+ assert Pleroma.Password.Pbkdf2.verify_pass("test", user.password_hash)
basic_auth_contents =
(URI.encode_www_form(user.nickname) <> ":" <> URI.encode_www_form("test"))
diff --git a/test/pleroma/web/auth/pleroma_authenticator_test.exs b/test/pleroma/web/auth/pleroma_authenticator_test.exs
index 4539ffe87..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-2020 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
@@ -11,7 +11,13 @@ defmodule Pleroma.Web.Auth.PleromaAuthenticatorTest do
setup do
password = "testpassword"
name = "AgentSmith"
- user = insert(:user, nickname: name, password_hash: Pbkdf2.hash_pwd_salt(password))
+
+ user =
+ insert(:user,
+ nickname: name,
+ password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password)
+ )
+
{:ok, [user: user, name: name, password: password]}
end
diff --git a/test/pleroma/web/auth/totp_authenticator_test.exs b/test/pleroma/web/auth/totp_authenticator_test.exs
index 7f99d62bf..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-2020 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
@@ -34,7 +34,7 @@ defmodule Pleroma.Web.Auth.TOTPAuthenticatorTest do
hashed_codes =
backup_codes
- |> Enum.map(&Pbkdf2.hash_pwd_salt(&1))
+ |> Enum.map(&Pleroma.Password.Pbkdf2.hash_pwd_salt(&1))
user =
insert(:user,
diff --git a/test/pleroma/web/common_api/utils_test.exs b/test/pleroma/web/common_api/utils_test.exs
index 4d6c9ea26..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-2020 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,27 +159,116 @@ 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
- 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")
+ describe "format_input/3 with markdown" do
+ test "Paragraph" do
+ code = ~s[Hello\n\nWorld!]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == "<p>Hello</p><p>World!</p>"
+ end
+
+ test "links" do
+ code = "https://en.wikipedia.org/wiki/Animal_Crossing_(video_game)"
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[<p><a href="#{code}">#{code}</a></p>]
+
+ code = "https://github.com/pragdave/earmark/"
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[<p><a href="#{code}">#{code}</a></p>]
+ end
+
+ test "link with local mention" do
+ insert(:user, %{nickname: "lain"})
+
+ code = "https://example.com/@lain"
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[<p><a href="#{code}">#{code}</a></p>]
+ end
+
+ test "local mentions" do
+ mario = insert(:user, %{nickname: "mario"})
+ luigi = insert(:user, %{nickname: "luigi"})
+
+ code = "@mario @luigi yo what's up?"
+ {result, _, []} = Utils.format_input(code, "text/markdown")
+
+ assert result ==
+ ~s[<p><span class="h-card"><a class="u-url mention" data-user="#{mario.id}" href="#{mario.ap_id}" rel="ugc">@<span>mario</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{luigi.id}" href="#{luigi.ap_id}" rel="ugc">@<span>luigi</span></a></span> yo what’s up?</p>]
+ end
+
+ test "remote mentions" do
+ mario = insert(:user, %{nickname: "mario@mushroom.world", local: false})
+ luigi = insert(:user, %{nickname: "luigi@mushroom.world", local: false})
+
+ code = "@mario@mushroom.world @luigi@mushroom.world yo what's up?"
+ {result, _, []} = Utils.format_input(code, "text/markdown")
+
+ assert result ==
+ ~s[<p><span class="h-card"><a class="u-url mention" data-user="#{mario.id}" href="#{mario.ap_id}" rel="ugc">@<span>mario</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{luigi.id}" href="#{luigi.ap_id}" rel="ugc">@<span>luigi</span></a></span> yo what’s up?</p>]
+ end
+
+ test "raw HTML" do
+ code = ~s[<a href="http://example.org/">OwO</a><!-- what's this?-->]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[<a href="http://example.org/">OwO</a>]
+ end
+
+ test "rulers" do
+ code = ~s[before\n\n-----\n\nafter]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == "<p>before</p><hr/><p>after</p>"
+ end
+
+ test "blockquote" do
+ code = ~s[> whoms't are you quoting?]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == "<blockquote><p>whoms’t are you quoting?</p></blockquote>"
+ end
+
+ test "code" do
+ code = ~s[`mix`]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[<p><code class="inline">mix</code></p>]
- assert conversation_id == object.id
+ code = ~s[``mix``]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[<p><code class="inline">mix</code></p>]
+
+ code = ~s[```\nputs "Hello World"\n```]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[<pre><code>puts &quot;Hello World&quot;</code></pre>]
+
+ code = ~s[ <div>\n </div>]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[<pre><code>&lt;div&gt;\n&lt;/div&gt;</code></pre>]
+ end
+
+ test "lists" do
+ code = ~s[- one\n- two\n- three\n- four]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == "<ul><li>one</li><li>two</li><li>three</li><li>four</li></ul>"
+
+ code = ~s[1. one\n2. two\n3. three\n4. four\n]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == "<ol><li>one</li><li>two</li><li>three</li><li>four</li></ol>"
end
- test "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")
+ test "delegated renderers" do
+ code = ~s[*aaaa~*]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[<p><em>aaaa~</em></p>]
+
+ code = ~s[**aaaa~**]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[<p><strong>aaaa~</strong></p>]
- assert conversation_id == object.id
+ # strikethrough
+ code = ~s[~~aaaa~~~]
+ {result, [], []} = Utils.format_input(code, "text/markdown")
+ assert result == ~s[<p><del>aaaa</del>~</p>]
end
end
@@ -204,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
@@ -214,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
@@ -222,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
@@ -412,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)
@@ -564,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 585b2c174..9d52bd93e 100644
--- a/test/pleroma/web/common_api_test.exs
+++ b/test/pleroma/web/common_api_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.CommonAPITest do
@@ -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
@@ -25,6 +26,11 @@ defmodule Pleroma.Web.CommonAPITest do
require Pleroma.Constants
+ setup_all do
+ Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
setup do: clear_config([:instance, :safe_dm_mentions])
setup do: clear_config([:instance, :limit])
setup do: clear_config([:instance, :max_pinned_statuses])
@@ -39,19 +45,27 @@ defmodule Pleroma.Web.CommonAPITest do
poll: %{expires_in: 600, options: ["reimu", "marisa"]}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
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
@@ -60,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
@@ -67,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
@@ -174,7 +196,7 @@ defmodule Pleroma.Web.CommonAPITest do
assert other_user.ap_id not in activity.recipients
- object = Object.normalize(activity, false)
+ object = Object.normalize(activity, fetch: false)
assert object.data["content"] == "uguu<br/>uguuu"
end
@@ -194,12 +216,10 @@ defmodule Pleroma.Web.CommonAPITest do
assert other_user.ap_id not in activity.recipients
- object = Object.normalize(activity, false)
+ 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
@@ -215,7 +235,7 @@ defmodule Pleroma.Web.CommonAPITest do
assert activity.data["type"] == "Create"
assert activity.local
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert object.data["type"] == "ChatMessage"
assert object.data["to"] == [recipient.ap_id]
@@ -234,7 +254,7 @@ defmodule Pleroma.Web.CommonAPITest do
end
test "it reject messages over the local limit" do
- Pleroma.Config.put([:instance, :chat_limit], 2)
+ clear_config([:instance, :chat_limit], 2)
author = insert(:user)
recipient = insert(:user)
@@ -281,7 +301,7 @@ defmodule Pleroma.Web.CommonAPITest do
clear_config([:instance, :federating], true)
- Object.normalize(post, false)
+ Object.normalize(post, fetch: false)
|> Object.prune()
with_mock Pleroma.Web.Federator,
@@ -475,7 +495,7 @@ defmodule Pleroma.Web.CommonAPITest do
jafnhar = insert(:user)
tridi = insert(:user)
- Pleroma.Config.put([:instance, :safe_dm_mentions], true)
+ clear_config([:instance, :safe_dm_mentions], true)
{:ok, activity} =
CommonAPI.post(har, %{
@@ -491,21 +511,55 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "#2hu #2HU"})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
- assert object.data["tag"] == ["2hu"]
+ assert Object.tags(object) == ["2hu"]
end
test "it adds emoji in the object" do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: ":firefox:"})
- assert Object.normalize(activity).data["emoji"]["firefox"]
+ assert Object.normalize(activity, fetch: false).data["emoji"]["firefox"]
end
describe "posting" do
+ test "it adds an emoji on an external site" do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey :external_emoji:"})
+
+ assert %{"external_emoji" => url} = Object.normalize(activity).data["emoji"]
+ assert url == "https://example.com/emoji.png"
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey :blank:"})
+
+ assert %{"blank" => url} = Object.normalize(activity).data["emoji"]
+ assert url == "#{Pleroma.Web.Endpoint.url()}/emoji/blank.png"
+ end
+
+ test "it copies emoji from the subject of the parent post" do
+ %Object{} =
+ object =
+ Object.normalize("https://patch.cx/objects/a399c28e-c821-4820-bc3e-4afeb044c16f",
+ fetch: true
+ )
+
+ activity = Activity.get_create_by_object_ap_id(object.data["id"])
+ user = insert(:user)
+
+ {:ok, reply_activity} =
+ CommonAPI.post(user, %{
+ in_reply_to_id: activity.id,
+ status: ":joker_disapprove:",
+ spoiler_text: ":joker_smile:"
+ })
+
+ assert Object.normalize(reply_activity).data["emoji"]["joker_smile"]
+ refute Object.normalize(reply_activity).data["emoji"]["joker_disapprove"]
+ end
+
test "deactivated users can't post" do
- user = insert(:user, deactivated: true)
+ user = insert(:user, is_active: false)
assert {:error, _} = CommonAPI.post(user, %{status: "ye"})
end
@@ -539,10 +593,10 @@ defmodule Pleroma.Web.CommonAPITest do
content_type: "text/html"
})
- object = Object.normalize(activity)
+ 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
@@ -556,10 +610,10 @@ defmodule Pleroma.Web.CommonAPITest do
content_type: "text/markdown"
})
- object = Object.normalize(activity)
+ 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["content"] == "<p><b>2hu</b></p>"
+ assert object.data["source"]["content"] == post
end
test "it does not allow replies to direct messages that are not direct messages themselves" do
@@ -629,7 +683,7 @@ defmodule Pleroma.Web.CommonAPITest do
end
test "it validates character limits are correctly enforced" do
- Pleroma.Config.put([:instance, :limit], 5)
+ clear_config([:instance, :limit], 5)
user = insert(:user)
@@ -639,6 +693,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)
@@ -731,6 +811,22 @@ defmodule Pleroma.Web.CommonAPITest do
refute Visibility.visible_for_user?(announce_activity, nil)
end
+ test "author can repeat own private statuses" do
+ author = insert(:user)
+ follower = insert(:user)
+ CommonAPI.follow(follower, author)
+
+ {:ok, activity} = CommonAPI.post(author, %{status: "cofe", visibility: "private"})
+
+ {:ok, %Activity{} = announce_activity} = CommonAPI.repeat(activity.id, author)
+
+ assert Visibility.is_private?(announce_activity)
+ refute Visibility.visible_for_user?(announce_activity, nil)
+
+ assert Visibility.visible_for_user?(activity, follower)
+ assert {:error, :not_found} = CommonAPI.repeat(activity.id, follower)
+ end
+
test "favoriting a status" do
user = insert(:user)
other_user = insert(:user)
@@ -764,7 +860,7 @@ defmodule Pleroma.Web.CommonAPITest do
describe "pinned statuses" do
setup do
- Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
+ clear_config([:instance, :max_pinned_statuses], 1)
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"})
@@ -772,13 +868,17 @@ defmodule Pleroma.Web.CommonAPITest do
[user: user, activity: activity]
end
+ test "activity not found error", %{user: user} do
+ assert {:error, :not_found} = CommonAPI.pin("id", user)
+ end
+
test "pin status", %{user: user, activity: activity} do
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
- id = activity.id
+ %{data: %{"id" => object_id}} = Object.normalize(activity)
user = refresh_record(user)
- assert %User{pinned_activities: [^id]} = user
+ assert user.pinned_objects |> Map.keys() == [object_id]
end
test "pin poll", %{user: user} do
@@ -790,10 +890,11 @@ defmodule Pleroma.Web.CommonAPITest do
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
- id = activity.id
+ %{data: %{"id" => object_id}} = Object.normalize(activity)
+
user = refresh_record(user)
- assert %User{pinned_activities: [^id]} = user
+ assert user.pinned_objects |> Map.keys() == [object_id]
end
test "unlisted statuses can be pinned", %{user: user} do
@@ -804,7 +905,7 @@ defmodule Pleroma.Web.CommonAPITest do
test "only self-authored can be pinned", %{activity: activity} do
user = insert(:user)
- assert {:error, "Could not pin"} = CommonAPI.pin(activity.id, user)
+ assert {:error, :ownership_error} = CommonAPI.pin(activity.id, user)
end
test "max pinned statuses", %{user: user, activity: activity_one} do
@@ -814,8 +915,12 @@ defmodule Pleroma.Web.CommonAPITest do
user = refresh_record(user)
- assert {:error, "You have already pinned the maximum number of statuses"} =
- CommonAPI.pin(activity_two.id, user)
+ assert {:error, :pinned_statuses_limit_reached} = CommonAPI.pin(activity_two.id, user)
+ end
+
+ test "only public can be pinned", %{user: user} do
+ {:ok, activity} = CommonAPI.post(user, %{status: "private status", visibility: "private"})
+ {:error, :visibility_error} = CommonAPI.pin(activity.id, user)
end
test "unpin status", %{user: user, activity: activity} do
@@ -829,7 +934,7 @@ defmodule Pleroma.Web.CommonAPITest do
user = refresh_record(user)
- assert %User{pinned_activities: []} = user
+ assert user.pinned_objects == %{}
end
test "should unpin when deleting a status", %{user: user, activity: activity} do
@@ -841,7 +946,40 @@ defmodule Pleroma.Web.CommonAPITest do
user = refresh_record(user)
- assert %User{pinned_activities: []} = user
+ assert user.pinned_objects == %{}
+ end
+
+ test "ephemeral activity won't be deleted if was pinned", %{user: user} do
+ {:ok, activity} = CommonAPI.post(user, %{status: "Hello!", expires_in: 601})
+
+ assert Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
+
+ {:ok, _activity} = CommonAPI.pin(activity.id, user)
+ refute Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
+
+ user = refresh_record(user)
+ {:ok, _} = CommonAPI.unpin(activity.id, user)
+
+ # recreates expiration job on unpin
+ assert Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
+ end
+
+ test "ephemeral activity deletion job won't be deleted on pinning error", %{
+ user: user,
+ activity: activity
+ } do
+ clear_config([:instance, :max_pinned_statuses], 1)
+
+ {:ok, _activity} = CommonAPI.pin(activity.id, user)
+
+ {:ok, activity2} = CommonAPI.post(user, %{status: "another status", expires_in: 601})
+
+ assert Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity2.id)
+
+ user = refresh_record(user)
+ {:error, :pinned_statuses_limit_reached} = CommonAPI.pin(activity2.id, user)
+
+ assert Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity2.id)
end
end
@@ -962,10 +1100,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 = %{
@@ -976,7 +1115,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})
@@ -998,6 +1137,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, %{
@@ -1010,10 +1150,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 activity_id == activity.data["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 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
@@ -1105,6 +1271,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)
@@ -1211,7 +1389,7 @@ defmodule Pleroma.Web.CommonAPITest do
poll: %{options: ["Yes", "No"], expires_in: 20}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
{:ok, _, object} = CommonAPI.vote(other_user, object, [0])
@@ -1231,7 +1409,7 @@ defmodule Pleroma.Web.CommonAPITest do
length: 180_000
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert object.data["title"] == "lain radio episode 1"
@@ -1250,7 +1428,7 @@ defmodule Pleroma.Web.CommonAPITest do
visibility: "private"
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert object.data["title"] == "lain radio episode 1"
@@ -1401,4 +1579,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 d0cae3d42..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-2020 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 46c7bad1c..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-2020 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 67001add7..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-2020 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
@@ -56,7 +56,7 @@ defmodule Pleroma.Web.FederatorTest do
activity: activity,
relay_mock: relay_mock
} do
- Pleroma.Config.put([:instance, :allow_relay], false)
+ clear_config([:instance, :allow_relay], false)
with_mocks([relay_mock]) do
Federator.publish(activity)
@@ -123,7 +123,8 @@ defmodule Pleroma.Web.FederatorTest do
"type" => "Note",
"content" => "hi world!",
"id" => "http://mastodon.example.org/users/admin/objects/1",
- "attributedTo" => "http://mastodon.example.org/users/admin"
+ "attributedTo" => "http://mastodon.example.org/users/admin",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"]
},
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
}
@@ -145,19 +146,20 @@ defmodule Pleroma.Web.FederatorTest do
"type" => "Note",
"content" => "hi world!",
"id" => "http://mastodon.example.org/users/admin/objects/1",
- "attributedTo" => "http://mastodon.example.org/users/admin"
+ "attributedTo" => "http://mastodon.example.org/users/admin",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"]
},
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
}
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
- Pleroma.Config.put([:mrf_keyword, :reject], ["lain"])
+ clear_config([:mrf_keyword, :reject], ["lain"])
- Pleroma.Config.put(
+ clear_config(
[:mrf, :policies],
Pleroma.Web.ActivityPub.MRF.KeywordPolicy
)
@@ -167,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 b4abcf6f2..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-2020 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
@@ -8,7 +8,6 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
import Pleroma.Factory
import SweetXml
- alias Pleroma.Config
alias Pleroma.Object
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Feed.FeedView
@@ -16,7 +15,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
setup do: clear_config([:feed])
test "gets a feed (ATOM)", %{conn: conn} do
- Config.put(
+ clear_config(
[:feed, :post_title],
%{max_length: 25, omission: "..."}
)
@@ -24,7 +23,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
user = insert(:user)
{:ok, activity1} = CommonAPI.post(user, %{status: "yeah #PleromaArt"})
- object = Object.normalize(activity1)
+ object = Object.normalize(activity1, fetch: false)
object_data =
Map.put(object.data, "attachment", [
@@ -64,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
@@ -83,7 +81,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
end
test "gets a feed (RSS)", %{conn: conn} do
- Config.put(
+ clear_config(
[:feed, :post_title],
%{max_length: 25, omission: "..."}
)
@@ -91,7 +89,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
user = insert(:user)
{:ok, activity1} = CommonAPI.post(user, %{status: "yeah #PleromaArt"})
- object = Object.normalize(activity1)
+ object = Object.normalize(activity1, fetch: false)
object_data =
Map.put(object.data, "attachment", [
@@ -128,10 +126,10 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
"These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
assert xpath(xml, ~x"//channel/link/text()") ==
- '#{Pleroma.Web.base_url()}/tags/pleromaart.rss'
+ '#{Pleroma.Web.Endpoint.url()}/tags/pleromaart.rss'
assert xpath(xml, ~x"//channel/webfeeds:logo/text()") ==
- '#{Pleroma.Web.base_url()}/static/logo.svg'
+ '#{Pleroma.Web.Endpoint.url()}/static/logo.svg'
assert xpath(xml, ~x"//channel/item/title/text()"l) == [
'42 This is :moominmamm...',
@@ -139,16 +137,16 @@ 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) == [
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4"
]
- obj1 = Object.normalize(activity1)
- obj2 = Object.normalize(activity2)
+ obj1 = Object.normalize(activity1, fetch: false)
+ obj2 = Object.normalize(activity2, fetch: false)
assert xpath(xml, ~x"//channel/item/description/text()"sl) == [
HtmlEntities.decode(FeedView.activity_content(obj2.data)),
diff --git a/test/pleroma/web/feed/user_controller_test.exs b/test/pleroma/web/feed/user_controller_test.exs
index 16f002717..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-2020 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
@@ -8,7 +8,6 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
import Pleroma.Factory
import SweetXml
- alias Pleroma.Config
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.CommonAPI
@@ -20,7 +19,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
setup do: clear_config([:feed])
setup do
- Config.put(
+ clear_config(
[:feed, :post_title],
%{max_length: 15, omission: "..."}
)
@@ -58,7 +57,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
)
note_activity2 = insert(:note_activity, note: note2)
- object = Object.normalize(note_activity)
+ object = Object.normalize(note_activity, fetch: false)
[user: user, object: object, max_id: note_activity2.id]
end
@@ -75,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"])
@@ -91,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
@@ -106,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"])
@@ -122,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
@@ -197,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", %{
@@ -218,7 +230,9 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|> get("/users/#{user.nickname}")
assert conn.status == 302
- assert redirected_to(conn) == "#{Pleroma.Web.base_url()}/users/#{user.nickname}/feed.atom"
+
+ assert redirected_to(conn) ==
+ "#{Pleroma.Web.Endpoint.url()}/users/#{user.nickname}/feed.atom"
end
test "with non-html / non-json format, it returns error when user is not found", %{conn: conn} do
@@ -236,7 +250,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
setup do: clear_config([:instance, :public])
test "returns 404 for user feed", %{conn: conn} do
- Config.put([:instance, :public], false)
+ clear_config([:instance, :public], false)
user = insert(:user)
{:ok, _} = CommonAPI.post(user, %{status: "test"})
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 cc7b3cf8b..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-2020 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
@@ -29,6 +33,45 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|> json_response_and_validate_schema(404)
end
+ test "relationship field" do
+ %{conn: conn, user: user} = oauth_access(["read"])
+
+ other_user = insert(:user)
+
+ response =
+ conn
+ |> get("/api/v1/accounts/#{other_user.id}")
+ |> json_response_and_validate_schema(200)
+
+ assert response["id"] == other_user.id
+ assert response["pleroma"]["relationship"] == %{}
+
+ assert %{"pleroma" => %{"relationship" => %{"following" => false, "followed_by" => false}}} =
+ conn
+ |> get("/api/v1/accounts/#{other_user.id}?with_relationships=true")
+ |> json_response_and_validate_schema(200)
+
+ {:ok, _, %{id: other_id}} = User.follow(user, other_user)
+
+ assert %{
+ "id" => ^other_id,
+ "pleroma" => %{"relationship" => %{"following" => true, "followed_by" => false}}
+ } =
+ conn
+ |> get("/api/v1/accounts/#{other_id}?with_relationships=true")
+ |> json_response_and_validate_schema(200)
+
+ {:ok, _, _} = User.follow(other_user, user)
+
+ assert %{
+ "id" => ^other_id,
+ "pleroma" => %{"relationship" => %{"following" => true, "followed_by" => true}}
+ } =
+ conn
+ |> get("/api/v1/accounts/#{other_id}?with_relationships=true")
+ |> json_response_and_validate_schema(200)
+ end
+
test "works by nickname" do
user = insert(:user)
@@ -126,7 +169,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
end
test "returns 404 for deactivated user", %{conn: conn} do
- user = insert(:user, deactivated: true)
+ user = insert(:user, is_active: false)
assert %{"error" => "Can't find user"} =
conn
@@ -256,7 +299,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
end
test "deactivated user", %{conn: conn} do
- user = insert(:user, deactivated: true)
+ user = insert(:user, is_active: false)
assert %{"error" => "Can't find user"} ==
conn
@@ -365,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
@@ -475,11 +523,11 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
{:ok, post_2} = CommonAPI.post(user, %{status: "second post"})
response_1 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1")
- assert [res] = json_response(response_1, 200)
+ assert [res] = json_response_and_validate_schema(response_1, 200)
assert res["id"] == post_2.id
response_2 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1&max_id=#{res["id"]}")
- assert [res] = json_response(response_2, 200)
+ assert [res] = json_response_and_validate_schema(response_2, 200)
assert res["id"] == post_1.id
refute response_1 == response_2
@@ -590,6 +638,45 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
assert [%{"id" => ^user_id}] = json_response_and_validate_schema(conn, 200)
end
+ test "following with relationship", %{conn: conn, user: user} do
+ other_user = insert(:user)
+ {:ok, %{id: id}, _} = User.follow(other_user, user)
+
+ assert [
+ %{
+ "id" => ^id,
+ "pleroma" => %{
+ "relationship" => %{
+ "id" => ^id,
+ "following" => false,
+ "followed_by" => true
+ }
+ }
+ }
+ ] =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/followers?with_relationships=true")
+ |> json_response_and_validate_schema(200)
+
+ {:ok, _, _} = User.follow(user, other_user)
+
+ assert [
+ %{
+ "id" => ^id,
+ "pleroma" => %{
+ "relationship" => %{
+ "id" => ^id,
+ "following" => true,
+ "followed_by" => true
+ }
+ }
+ }
+ ] =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/followers?with_relationships=true")
+ |> json_response_and_validate_schema(200)
+ end
+
test "getting followers, hide_followers", %{user: user, conn: conn} do
other_user = insert(:user, hide_followers: true)
{:ok, _user, _other_user} = User.follow(user, other_user)
@@ -631,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)
@@ -660,6 +745,24 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
assert id == to_string(other_user.id)
end
+ test "following with relationship", %{conn: conn, user: user} do
+ other_user = insert(:user)
+ {:ok, user, other_user} = User.follow(user, other_user)
+
+ conn = get(conn, "/api/v1/accounts/#{user.id}/following?with_relationships=true")
+
+ id = other_user.id
+
+ assert [
+ %{
+ "id" => ^id,
+ "pleroma" => %{
+ "relationship" => %{"id" => ^id, "following" => true, "followed_by" => false}
+ }
+ }
+ ] = json_response_and_validate_schema(conn, 200)
+ end
+
test "getting following, hide_follows, other user requesting" do
user = insert(:user, hide_follows: true)
other_user = insert(:user)
@@ -785,7 +888,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
assert [] ==
conn
|> get("/api/v1/timelines/home")
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
assert %{"showing_reblogs" => true} =
conn
@@ -793,10 +896,16 @@ 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")
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
end
test "following with reblogs" do
@@ -814,7 +923,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
assert [%{"id" => ^reblog_id}] =
conn
|> get("/api/v1/timelines/home")
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
assert %{"showing_reblogs" => false} =
conn
@@ -822,10 +931,39 @@ 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(200)
+ |> 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
@@ -902,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
@@ -923,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)
@@ -1007,7 +1208,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
assert %{"error" => "{\"email\":[\"Invalid email\"]}"} =
json_response_and_validate_schema(conn, 400)
- Pleroma.Config.put([User, :email_blacklist], [])
+ clear_config([User, :email_blacklist], [])
conn =
build_conn()
@@ -1027,8 +1228,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
user = Repo.preload(token_from_db, :user).user
assert user
- refute user.confirmation_pending
- refute user.approval_pending
+ assert user.is_confirmed
+ assert user.is_approved
end
test "registers but does not log in with :account_activation_required", %{conn: conn} do
@@ -1088,7 +1289,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
refute response["token_type"]
user = Repo.get_by(User, email: "lain@example.org")
- assert user.confirmation_pending
+ refute user.is_confirmed
end
test "registers but does not log in with :account_approval_required", %{conn: conn} do
@@ -1150,7 +1351,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
user = Repo.get_by(User, email: "lain@example.org")
- assert user.approval_pending
+ refute user.is_approved
assert user.registration_reason == "I'm a cool dude, bro"
end
@@ -1471,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"])
@@ -1565,31 +1889,27 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
result =
conn
- |> assign(:user, user)
|> get("/api/v1/mutes")
|> json_response_and_validate_schema(200)
- assert [id1, id2, id3] == Enum.map(result, & &1["id"])
+ assert [id3, id2, id1] == Enum.map(result, & &1["id"])
result =
conn
- |> assign(:user, user)
|> get("/api/v1/mutes?limit=1")
|> json_response_and_validate_schema(200)
- assert [%{"id" => ^id1}] = result
+ assert [%{"id" => ^id3}] = result
result =
conn
- |> assign(:user, user)
|> get("/api/v1/mutes?since_id=#{id1}")
|> json_response_and_validate_schema(200)
- assert [%{"id" => ^id2}, %{"id" => ^id3}] = result
+ assert [%{"id" => ^id3}, %{"id" => ^id2}] = result
result =
conn
- |> assign(:user, user)
|> get("/api/v1/mutes?since_id=#{id1}&max_id=#{id3}")
|> json_response_and_validate_schema(200)
@@ -1597,11 +1917,43 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
result =
conn
- |> assign(:user, user)
|> get("/api/v1/mutes?since_id=#{id1}&limit=1")
|> json_response_and_validate_schema(200)
- assert [%{"id" => ^id2}] = result
+ assert [%{"id" => ^id3}] = result
+ end
+
+ test "list of mutes with with_relationships parameter" do
+ %{user: user, conn: conn} = oauth_access(["read:mutes"])
+ %{id: id1} = other_user1 = insert(:user)
+ %{id: id2} = other_user2 = insert(:user)
+ %{id: id3} = other_user3 = insert(:user)
+
+ {:ok, _, _} = User.follow(other_user1, user)
+ {:ok, _, _} = User.follow(other_user2, user)
+ {:ok, _, _} = User.follow(other_user3, user)
+
+ {:ok, _} = User.mute(user, other_user1)
+ {:ok, _} = User.mute(user, other_user2)
+ {:ok, _} = User.mute(user, other_user3)
+
+ assert [
+ %{
+ "id" => ^id3,
+ "pleroma" => %{"relationship" => %{"muting" => true, "followed_by" => true}}
+ },
+ %{
+ "id" => ^id2,
+ "pleroma" => %{"relationship" => %{"muting" => true, "followed_by" => true}}
+ },
+ %{
+ "id" => ^id1,
+ "pleroma" => %{"relationship" => %{"muting" => true, "followed_by" => true}}
+ }
+ ] =
+ conn
+ |> get("/api/v1/mutes?with_relationships=true")
+ |> json_response_and_validate_schema(200)
end
test "getting a list of blocks" do
@@ -1620,7 +1972,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|> get("/api/v1/blocks")
|> json_response_and_validate_schema(200)
- assert [id1, id2, id3] == Enum.map(result, & &1["id"])
+ assert [id3, id2, id1] == Enum.map(result, & &1["id"])
result =
conn
@@ -1628,7 +1980,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|> get("/api/v1/blocks?limit=1")
|> json_response_and_validate_schema(200)
- assert [%{"id" => ^id1}] = result
+ assert [%{"id" => ^id3}] = result
result =
conn
@@ -1636,7 +1988,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|> get("/api/v1/blocks?since_id=#{id1}")
|> json_response_and_validate_schema(200)
- assert [%{"id" => ^id2}, %{"id" => ^id3}] = result
+ assert [%{"id" => ^id3}, %{"id" => ^id2}] = result
result =
conn
@@ -1652,6 +2004,177 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|> get("/api/v1/blocks?since_id=#{id1}&limit=1")
|> json_response_and_validate_schema(200)
- assert [%{"id" => ^id2}] = result
+ assert [%{"id" => ^id3}] = result
+
+ conn_res =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/blocks?limit=2")
+
+ next_url =
+ ~r{<.+?(?<link>/api[^>]+)>; rel=\"next\"}
+ |> Regex.named_captures(get_resp_header(conn_res, "link") |> Enum.at(0))
+ |> Map.get("link")
+
+ result =
+ conn_res
+ |> json_response_and_validate_schema(200)
+
+ assert [%{"id" => ^id3}, %{"id" => ^id2}] = result
+
+ result =
+ conn
+ |> assign(:user, user)
+ |> get(next_url)
+ |> json_response_and_validate_schema(200)
+
+ 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 a0b8b126c..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-2020 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
@@ -12,25 +12,56 @@ defmodule Pleroma.Web.MastodonAPI.AppControllerTest do
import Pleroma.Factory
test "apps/verify_credentials", %{conn: conn} do
- token = insert(:oauth_token)
+ user_bound_token = insert(:oauth_token)
+ app_bound_token = insert(:oauth_token, user: nil)
+ refute app_bound_token.user
+
+ for token <- [app_bound_token, user_bound_token] do
+ conn =
+ conn
+ |> put_req_header("authorization", "Bearer #{token.token}")
+ |> get("/api/v1/apps/verify_credentials")
+
+ app = Repo.preload(token, :app).app
+
+ expected = %{
+ "name" => app.client_name,
+ "website" => app.website,
+ "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
+ }
+
+ assert expected == json_response_and_validate_schema(conn, 200)
+ end
+ end
+
+ test "creates an oauth app", %{conn: conn} do
+ app_attrs = build(:oauth_app)
conn =
conn
- |> put_req_header("authorization", "Bearer #{token.token}")
- |> get("/api/v1/apps/verify_credentials")
+ |> 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.preload(token, :app).app
+ [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", %{conn: conn} do
+ test "creates an oauth app with a user", %{conn: conn} do
user = insert(:user)
app_attrs = build(:oauth_app)
@@ -56,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 ce957054b..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-2020 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, deactivated: true, 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 a03513e06..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-2020 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
@@ -214,7 +214,34 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
res_conn = get(conn, "/api/v1/statuses/#{direct.id}/context")
- assert %{"ancestors" => [], "descendants" => []} == json_response(res_conn, 200)
+ assert %{"ancestors" => [], "descendants" => []} ==
+ json_response_and_validate_schema(res_conn, 200)
+ end
+
+ test "Removes a conversation", %{user: user_one, conn: conn} do
+ user_two = insert(:user)
+ token = insert(:oauth_token, user: user_one, scopes: ["read:statuses", "write:conversations"])
+
+ {:ok, _direct} = create_direct_message(user_one, [user_two])
+ {:ok, _direct} = create_direct_message(user_one, [user_two])
+
+ assert [%{"id" => conv1_id}, %{"id" => conv2_id}] =
+ conn
+ |> assign(:token, token)
+ |> get("/api/v1/conversations")
+ |> json_response_and_validate_schema(200)
+
+ assert %{} =
+ conn
+ |> assign(:token, token)
+ |> delete("/api/v1/conversations/#{conv1_id}")
+ |> json_response_and_validate_schema(200)
+
+ assert [%{"id" => ^conv2_id}] =
+ conn
+ |> assign(:token, token)
+ |> get("/api/v1/conversations")
+ |> json_response_and_validate_schema(200)
end
defp create_direct_message(sender, recips) 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 ab0027f90..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-2020 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 b10aa6966..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-2020 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 e639cdde1..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,152 +1,410 @@
# 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.MastodonAPI.FilterControllerTest do
- use Pleroma.Web.ConnCase, async: true
+ use Pleroma.Web.ConnCase, async: false
+ use Oban.Testing, repo: Pleroma.Repo
- alias Pleroma.Web.MastodonAPI.FilterView
+ import Mock
+ import Pleroma.Factory
- test "creating a filter" do
- %{conn: conn} = oauth_access(["write:filters"])
+ alias Pleroma.Filter
+ alias Pleroma.Repo
+ alias Pleroma.Workers.PurgeExpiredFilter
- filter = %Pleroma.Filter{
- phrase: "knights",
- context: ["home"]
- }
-
- conn =
+ test "non authenticated creation request", %{conn: conn} do
+ response =
conn
|> put_req_header("content-type", "application/json")
- |> post("/api/v1/filters", %{"phrase" => filter.phrase, context: filter.context})
-
- assert response = json_response_and_validate_schema(conn, 200)
- assert response["phrase"] == filter.phrase
- assert response["context"] == filter.context
- assert response["irreversible"] == false
- assert response["id"] != nil
- assert response["id"] != ""
+ |> post("/api/v1/filters", %{"phrase" => "knights", context: ["home"]})
+ |> json_response(403)
+
+ assert response["error"] == "Invalid credentials."
+ end
+
+ describe "creating" do
+ setup do: oauth_access(["write:filters"])
+
+ test "a common filter", %{conn: conn, user: user} do
+ params = %{
+ phrase: "knights",
+ context: ["home"],
+ irreversible: true
+ }
+
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/filters", params)
+ |> json_response_and_validate_schema(200)
+
+ assert response["phrase"] == params.phrase
+ assert response["context"] == params.context
+ assert response["irreversible"] == true
+ assert response["id"] != nil
+ assert response["id"] != ""
+ assert response["expires_at"] == nil
+
+ filter = Filter.get(response["id"], user)
+ assert filter.hide == true
+ end
+
+ test "a filter with expires_in", %{conn: conn, user: user} do
+ in_seconds = 600
+
+ response =
+ 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
+ assert response["expires_at"] == "2017-03-17T17:19:58.000Z"
+
+ filter = Filter.get(response["id"], user)
+
+ id = filter.id
+
+ assert_enqueued(
+ worker: PurgeExpiredFilter,
+ args: %{filter_id: filter.id}
+ )
+
+ assert {:ok, %{id: ^id}} =
+ perform_job(PurgeExpiredFilter, %{
+ filter_id: filter.id
+ })
+
+ assert Repo.aggregate(Filter, :count, :id) == 0
+ end
end
test "fetching a list of filters" do
%{user: user, conn: conn} = oauth_access(["read:filters"])
- query_one = %Pleroma.Filter{
- user_id: user.id,
- filter_id: 1,
- phrase: "knights",
- context: ["home"]
- }
+ %{filter_id: id1} = insert(:filter, user: user)
+ %{filter_id: id2} = insert(:filter, user: user)
- query_two = %Pleroma.Filter{
- user_id: user.id,
- filter_id: 2,
- phrase: "who",
- context: ["home"]
- }
+ id1 = to_string(id1)
+ id2 = to_string(id2)
- {:ok, filter_one} = Pleroma.Filter.create(query_one)
- {:ok, filter_two} = Pleroma.Filter.create(query_two)
+ assert [%{"id" => ^id2}, %{"id" => ^id1}] =
+ conn
+ |> get("/api/v1/filters")
+ |> json_response_and_validate_schema(200)
+ end
+
+ test "fetching a list of filters without token", %{conn: conn} do
+ insert(:filter)
response =
conn
|> get("/api/v1/filters")
- |> json_response_and_validate_schema(200)
-
- assert response ==
- render_json(
- FilterView,
- "index.json",
- filters: [filter_two, filter_one]
- )
+ |> json_response(403)
+
+ assert response["error"] == "Invalid credentials."
end
test "get a filter" do
%{user: user, conn: conn} = oauth_access(["read:filters"])
# check whole_word false
- query = %Pleroma.Filter{
- user_id: user.id,
- filter_id: 2,
- phrase: "knight",
- context: ["home"],
- whole_word: false
- }
-
- {:ok, filter} = Pleroma.Filter.create(query)
+ filter = insert(:filter, user: user, whole_word: false)
- conn = get(conn, "/api/v1/filters/#{filter.filter_id}")
+ resp1 =
+ conn |> get("/api/v1/filters/#{filter.filter_id}") |> json_response_and_validate_schema(200)
- assert response = json_response_and_validate_schema(conn, 200)
- assert response["whole_word"] == false
+ assert resp1["whole_word"] == false
# check whole_word true
- %{user: user, conn: conn} = oauth_access(["read:filters"])
-
- query = %Pleroma.Filter{
- user_id: user.id,
- filter_id: 3,
- phrase: "knight",
- context: ["home"],
- whole_word: true
- }
+ filter = insert(:filter, user: user, whole_word: true)
- {:ok, filter} = Pleroma.Filter.create(query)
+ resp2 =
+ conn |> get("/api/v1/filters/#{filter.filter_id}") |> json_response_and_validate_schema(200)
- conn = get(conn, "/api/v1/filters/#{filter.filter_id}")
-
- assert response = json_response_and_validate_schema(conn, 200)
- assert response["whole_word"] == true
+ assert resp2["whole_word"] == true
end
- test "update a filter" do
- %{user: user, conn: conn} = oauth_access(["write:filters"])
+ test "get a filter not_found error" do
+ filter = insert(:filter)
+ %{conn: conn} = oauth_access(["read:filters"])
- query = %Pleroma.Filter{
- user_id: user.id,
- filter_id: 2,
- phrase: "knight",
- context: ["home"],
- hide: true,
- whole_word: true
- }
+ response =
+ conn |> get("/api/v1/filters/#{filter.filter_id}") |> json_response_and_validate_schema(404)
- {:ok, _filter} = Pleroma.Filter.create(query)
+ assert response["error"] == "Record not found"
+ end
+
+ describe "updating a filter" do
+ setup do: oauth_access(["write:filters"])
+
+ test "common" do
+ %{conn: conn, user: user} = oauth_access(["write:filters"])
+
+ filter =
+ insert(:filter,
+ user: user,
+ hide: true,
+ whole_word: true
+ )
+
+ params = %{
+ phrase: "nii",
+ context: ["public"],
+ irreversible: false
+ }
+
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> put("/api/v1/filters/#{filter.filter_id}", params)
+ |> json_response_and_validate_schema(200)
+
+ assert response["phrase"] == params.phrase
+ assert response["context"] == params.context
+ assert response["irreversible"] == false
+ assert response["whole_word"] == true
+ end
+
+ test "with adding expires_at", %{conn: conn, user: user} do
+ filter = insert(:filter, user: user)
+ in_seconds = 600
+
+ response =
+ 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"] == "2017-03-17T17:19:58.000Z"
+
+ filter = Filter.get(response["id"], user)
+
+ id = filter.id
+
+ assert_enqueued(
+ worker: PurgeExpiredFilter,
+ args: %{filter_id: id}
+ )
+
+ assert {:ok, %{id: ^id}} =
+ perform_job(PurgeExpiredFilter, %{
+ filter_id: id
+ })
+
+ assert Repo.aggregate(Filter, :count, :id) == 0
+ end
+
+ test "with removing expires_at", %{conn: conn, user: user} do
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/filters", %{
+ phrase: "cofe",
+ context: ["home"],
+ expires_in: 600
+ })
+ |> json_response_and_validate_schema(200)
+
+ filter = Filter.get(response["id"], user)
+
+ assert_enqueued(
+ worker: PurgeExpiredFilter,
+ args: %{filter_id: filter.id}
+ )
+
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> put("/api/v1/filters/#{filter.filter_id}", %{
+ phrase: "nii",
+ context: ["public"],
+ expires_in: nil,
+ whole_word: true
+ })
+ |> json_response_and_validate_schema(200)
+
+ refute_enqueued(
+ worker: PurgeExpiredFilter,
+ args: %{filter_id: filter.id}
+ )
+
+ assert response["irreversible"] == false
+ assert response["whole_word"] == true
+ assert response["expires_at"] == nil
+ end
+
+ test "expires_at is the same in create and update so job is in db", %{conn: conn, user: user} do
+ resp1 =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/filters", %{
+ phrase: "cofe",
+ context: ["home"],
+ expires_in: 600
+ })
+ |> json_response_and_validate_schema(200)
+
+ filter = Filter.get(resp1["id"], user)
+
+ assert_enqueued(
+ worker: PurgeExpiredFilter,
+ args: %{filter_id: filter.id}
+ )
+
+ job = PurgeExpiredFilter.get_expiration(filter.id)
+
+ resp2 =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> put("/api/v1/filters/#{filter.filter_id}", %{
+ phrase: "nii",
+ context: ["public"]
+ })
+ |> json_response_and_validate_schema(200)
+
+ updated_filter = Filter.get(resp2["id"], user)
+
+ assert_enqueued(
+ worker: PurgeExpiredFilter,
+ args: %{filter_id: updated_filter.id}
+ )
+
+ after_update = PurgeExpiredFilter.get_expiration(updated_filter.id)
+
+ assert resp1["expires_at"] == resp2["expires_at"]
+
+ assert job.scheduled_at == after_update.scheduled_at
+ end
+
+ test "updating expires_at updates oban job too", %{conn: conn, user: user} do
+ resp1 =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/filters", %{
+ phrase: "cofe",
+ context: ["home"],
+ expires_in: 600
+ })
+ |> json_response_and_validate_schema(200)
+
+ filter = Filter.get(resp1["id"], user)
+
+ assert_enqueued(
+ worker: PurgeExpiredFilter,
+ args: %{filter_id: filter.id}
+ )
+
+ job = PurgeExpiredFilter.get_expiration(filter.id)
+
+ resp2 =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> put("/api/v1/filters/#{filter.filter_id}", %{
+ phrase: "nii",
+ context: ["public"],
+ expires_in: 300
+ })
+ |> json_response_and_validate_schema(200)
+
+ updated_filter = Filter.get(resp2["id"], user)
+
+ assert_enqueued(
+ worker: PurgeExpiredFilter,
+ args: %{filter_id: updated_filter.id}
+ )
+
+ after_update = PurgeExpiredFilter.get_expiration(updated_filter.id)
+
+ refute resp1["expires_at"] == resp2["expires_at"]
+
+ refute job.scheduled_at == after_update.scheduled_at
+ end
+ end
- new = %Pleroma.Filter{
- phrase: "nii",
- context: ["home"]
- }
+ test "update filter without token", %{conn: conn} do
+ filter = insert(:filter)
- conn =
+ response =
conn
|> put_req_header("content-type", "application/json")
- |> put("/api/v1/filters/#{query.filter_id}", %{
- phrase: new.phrase,
- context: new.context
+ |> put("/api/v1/filters/#{filter.filter_id}", %{
+ phrase: "nii",
+ context: ["public"]
})
+ |> json_response(403)
- assert response = json_response_and_validate_schema(conn, 200)
- assert response["phrase"] == new.phrase
- assert response["context"] == new.context
- assert response["irreversible"] == true
- assert response["whole_word"] == true
+ assert response["error"] == "Invalid credentials."
end
- test "delete a filter" do
- %{user: user, conn: conn} = oauth_access(["write:filters"])
-
- query = %Pleroma.Filter{
- user_id: user.id,
- filter_id: 2,
- phrase: "knight",
- context: ["home"]
- }
+ describe "delete a filter" do
+ setup do: oauth_access(["write:filters"])
+
+ test "common", %{conn: conn, user: user} do
+ filter = insert(:filter, user: user)
+
+ assert conn
+ |> delete("/api/v1/filters/#{filter.filter_id}")
+ |> json_response_and_validate_schema(200) == %{}
+
+ assert Repo.all(Filter) == []
+ end
+
+ test "with expires_at", %{conn: conn, user: user} do
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/filters", %{
+ phrase: "cofe",
+ context: ["home"],
+ expires_in: 600
+ })
+ |> json_response_and_validate_schema(200)
+
+ filter = Filter.get(response["id"], user)
+
+ assert_enqueued(
+ worker: PurgeExpiredFilter,
+ args: %{filter_id: filter.id}
+ )
+
+ assert conn
+ |> delete("/api/v1/filters/#{filter.filter_id}")
+ |> json_response_and_validate_schema(200) == %{}
+
+ refute_enqueued(
+ worker: PurgeExpiredFilter,
+ args: %{filter_id: filter.id}
+ )
+
+ assert Repo.all(Filter) == []
+ assert Repo.all(Oban.Job) == []
+ end
+ end
- {:ok, filter} = Pleroma.Filter.create(query)
+ test "delete a filter without token", %{conn: conn} do
+ filter = insert(:filter)
- conn = delete(conn, "/api/v1/filters/#{filter.filter_id}")
+ response =
+ conn
+ |> delete("/api/v1/filters/#{filter.filter_id}")
+ |> json_response(403)
- assert json_response_and_validate_schema(conn, 200) == %{}
+ assert response["error"] == "Invalid credentials."
end
end
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 f0a466212..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-2020 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 71a170240..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-2020 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
@@ -14,14 +14,15 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
assert result = json_response_and_validate_schema(conn, 200)
email = Pleroma.Config.get([:instance, :email])
- thumbnail = Pleroma.Web.base_url() <> Pleroma.Config.get([:instance, :instance_thumbnail])
- background = Pleroma.Web.base_url() <> Pleroma.Config.get([:instance, :background_image])
+ thumbnail = Pleroma.Web.Endpoint.url() <> Pleroma.Config.get([:instance, :instance_thumbnail])
+ background = Pleroma.Web.Endpoint.url() <> Pleroma.Config.get([:instance, :background_image])
# Note: not checking for "max_toot_chars" since it's optional
assert %{
"uri" => _,
"title" => _,
"description" => _,
+ "short_description" => _,
"version" => _,
"email" => from_config_email,
"urls" => %{
@@ -38,7 +39,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
"background_upload_limit" => _,
"banner_upload_limit" => _,
"background_image" => from_config_background,
- "chat_limit" => _,
+ "shout_limit" => _,
"description_limit" => _
} = result
@@ -47,6 +48,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
assert result["pleroma"]["metadata"]["federation"]
assert result["pleroma"]["metadata"]["fields_limits"]
assert result["pleroma"]["vapid_public_key"]
+ assert result["pleroma"]["stats"]["mau"] == 0
assert email == from_config_email
assert thumbnail == from_config_thumbnail
@@ -57,7 +59,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
user = insert(:user, %{local: true})
user2 = insert(:user, %{local: true})
- {:ok, _user2} = User.deactivate(user2, !user2.deactivated)
+ {:ok, _user2} = User.set_activation(user2, false)
insert(:user, %{local: false, nickname: "u@peer1.com"})
insert(:user, %{local: false, nickname: "u@peer2.com"})
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 01f64cfcc..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-2020 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
@@ -55,30 +55,39 @@ defmodule Pleroma.Web.MastodonAPI.ListControllerTest do
test "adding users to a list" do
%{user: user, conn: conn} = oauth_access(["write:lists"])
other_user = insert(:user)
+ third_user = insert(:user)
{:ok, list} = Pleroma.List.create("name", user)
assert %{} ==
conn
|> put_req_header("content-type", "application/json")
- |> post("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]})
+ |> post("/api/v1/lists/#{list.id}/accounts", %{
+ "account_ids" => [other_user.id, third_user.id]
+ })
|> json_response_and_validate_schema(:ok)
%Pleroma.List{following: following} = Pleroma.List.get(list.id, user)
- assert following == [other_user.follower_address]
+ assert length(following) == 2
+ assert other_user.follower_address in following
+ assert third_user.follower_address in following
end
test "removing users from a list, body params" do
%{user: user, conn: conn} = oauth_access(["write:lists"])
other_user = insert(:user)
third_user = insert(:user)
+ fourth_user = insert(:user)
{:ok, list} = Pleroma.List.create("name", user)
{:ok, list} = Pleroma.List.follow(list, other_user)
{:ok, list} = Pleroma.List.follow(list, third_user)
+ {:ok, list} = Pleroma.List.follow(list, fourth_user)
assert %{} ==
conn
|> put_req_header("content-type", "application/json")
- |> delete("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]})
+ |> delete("/api/v1/lists/#{list.id}/accounts", %{
+ "account_ids" => [other_user.id, fourth_user.id]
+ })
|> json_response_and_validate_schema(:ok)
%Pleroma.List{following: following} = Pleroma.List.get(list.id, user)
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 ee944a67c..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-2020 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 d2bd57515..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,10 +1,12 @@
# 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.MastodonAPI.MediaControllerTest do
use Pleroma.Web.ConnCase
+ import ExUnit.CaptureLog
+
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
@@ -67,6 +69,59 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
object = Object.get_by_id(media["id"])
assert object.data["actor"] == user.ap_id
end
+
+ test "/api/v2/media, upload_limit", %{conn: conn, user: user} do
+ desc = "Description of the binary"
+
+ upload_limit = Config.get([:instance, :upload_limit]) * 8 + 8
+
+ assert :ok ==
+ File.write(Path.absname("test/tmp/large_binary.data"), <<0::size(upload_limit)>>)
+
+ large_binary = %Plug.Upload{
+ content_type: nil,
+ path: Path.absname("test/tmp/large_binary.data"),
+ filename: "large_binary.data"
+ }
+
+ assert capture_log(fn ->
+ assert %{"error" => "file_too_large"} =
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/v2/media", %{
+ "file" => large_binary,
+ "description" => desc
+ })
+ |> json_response_and_validate_schema(400)
+ end) =~
+ "[error] Elixir.Pleroma.Upload store (using Pleroma.Uploaders.Local) failed: :file_too_large"
+
+ clear_config([:instance, :upload_limit], upload_limit)
+
+ assert response =
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/v2/media", %{
+ "file" => large_binary,
+ "description" => desc
+ })
+ |> json_response_and_validate_schema(202)
+
+ assert media_id = response["id"]
+
+ %{conn: conn} = oauth_access(["read:media"], user: user)
+
+ media =
+ conn
+ |> get("/api/v1/media/#{media_id}")
+ |> json_response_and_validate_schema(200)
+
+ assert media["type"] == "unknown"
+ assert media["description"] == desc
+ assert media["id"]
+
+ assert :ok == File.rm(Path.absname("test/tmp/large_binary.data"))
+ end
end
describe "Update media description" do
@@ -140,7 +195,7 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
conn
|> get("/api/v1/media/#{object.id}")
- |> json_response(403)
+ |> json_response_and_validate_schema(403)
end
end
end
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 9ac8488f6..403628488 100644
--- a/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/notification_controller_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.MastodonAPI.NotificationControllerTest do
@@ -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)
@@ -103,6 +101,25 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
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 +131,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 +423,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 +438,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 +460,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 +470,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)
@@ -555,24 +587,11 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
assert length(json_response_and_validate_schema(conn, 200)) == 1
end
- @tag capture_log: true
test "see move notifications" do
old_user = insert(:user)
new_user = insert(:user, also_known_as: [old_user.ap_id])
%{user: follower, conn: conn} = oauth_access(["read:notifications"])
- old_user_url = old_user.ap_id
-
- body =
- File.read!("test/fixtures/users_mock/localhost.json")
- |> String.replace("{{nickname}}", old_user.nickname)
- |> Jason.encode!()
-
- Tesla.Mock.mock(fn
- %{method: :get, url: ^old_user_url} ->
- %Tesla.Env{status: 200, body: body}
- end)
-
User.follow(follower, old_user)
Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)
Pleroma.Tests.ObanHelpers.perform_all()
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 95e27623d..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-2020 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
@@ -20,7 +20,7 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
poll: %{options: ["what Mastodon't", "n't what Mastodoes"], expires_in: 20}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
conn = get(conn, "/api/v1/polls/#{object.id}")
@@ -39,7 +39,7 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
visibility: "private"
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
conn = get(conn, "/api/v1/polls/#{object.id}")
@@ -47,6 +47,78 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
end
end
+ test "own_votes" do
+ %{conn: conn} = oauth_access(["write:statuses", "read:statuses"])
+
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(other_user, %{
+ status: "A very delicious sandwich",
+ poll: %{
+ options: ["Lettuce", "Grilled Bacon", "Tomato"],
+ expires_in: 20,
+ multiple: true
+ }
+ })
+
+ object = Object.normalize(activity, fetch: false)
+
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0, 2]})
+ |> json_response_and_validate_schema(200)
+
+ object = Object.get_by_id(object.id)
+
+ assert [
+ %{
+ "name" => "Lettuce",
+ "replies" => %{"totalItems" => 1, "type" => "Collection"},
+ "type" => "Note"
+ },
+ %{
+ "name" => "Grilled Bacon",
+ "replies" => %{"totalItems" => 0, "type" => "Collection"},
+ "type" => "Note"
+ },
+ %{
+ "name" => "Tomato",
+ "replies" => %{"totalItems" => 1, "type" => "Collection"},
+ "type" => "Note"
+ }
+ ] == object.data["anyOf"]
+
+ assert %{"replies" => %{"totalItems" => 0}} =
+ Enum.find(object.data["anyOf"], fn %{"name" => name} -> name == "Grilled Bacon" end)
+
+ Enum.each(["Lettuce", "Tomato"], fn title ->
+ %{"replies" => %{"totalItems" => total_items}} =
+ Enum.find(object.data["anyOf"], fn %{"name" => name} -> name == title end)
+
+ assert total_items == 1
+ end)
+
+ assert %{
+ "own_votes" => own_votes,
+ "voted" => true
+ } =
+ conn
+ |> get("/api/v1/polls/#{object.id}")
+ |> json_response_and_validate_schema(200)
+
+ assert 0 in own_votes
+ assert 2 in own_votes
+ # for non authenticated user
+ response =
+ build_conn()
+ |> get("/api/v1/polls/#{object.id}")
+ |> json_response_and_validate_schema(200)
+
+ refute Map.has_key?(response, "own_votes")
+ refute Map.has_key?(response, "voted")
+ end
+
describe "POST /api/v1/polls/:id/votes" do
setup do: oauth_access(["write:statuses"])
@@ -63,14 +135,13 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
- conn =
- conn
- |> put_req_header("content-type", "application/json")
- |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0, 1, 2]})
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0, 1, 2]})
+ |> json_response_and_validate_schema(200)
- assert json_response_and_validate_schema(conn, 200)
object = Object.get_by_id(object.id)
assert Enum.all?(object.data["anyOf"], fn %{"replies" => %{"totalItems" => total_items}} ->
@@ -85,7 +156,7 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
poll: %{options: ["Yes", "No"], expires_in: 20}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert conn
|> put_req_header("content-type", "application/json")
@@ -106,7 +177,7 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
poll: %{options: ["half empty", "half full"], expires_in: 20}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert conn
|> put_req_header("content-type", "application/json")
@@ -129,7 +200,7 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
poll: %{options: ["Yes", "No"], expires_in: 20}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
conn =
conn
@@ -158,7 +229,7 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
visibility: "private"
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
conn =
conn
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 322eb475c..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-2020 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 1ff871c89..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-2020 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
@@ -55,7 +55,7 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityControllerTest do
end
test "updates a scheduled activity" do
- Pleroma.Config.put([ScheduledActivity, :enabled], true)
+ clear_config([ScheduledActivity, :enabled], true)
%{user: user, conn: conn} = oauth_access(["write:statuses"])
scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
@@ -103,7 +103,7 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityControllerTest do
end
test "deletes a scheduled activity" do
- Pleroma.Config.put([ScheduledActivity, :enabled], true)
+ clear_config([ScheduledActivity, :enabled], true)
%{user: user, conn: conn} = oauth_access(["write:statuses"])
scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
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 1045ab265..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,13 +1,13 @@
# 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.MastodonAPI.SearchControllerTest do
use Pleroma.Web.ConnCase
alias Pleroma.Object
- alias Pleroma.Web
alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.Endpoint
import Pleroma.Factory
import ExUnit.CaptureLog
import Tesla.Mock
@@ -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"})
@@ -61,7 +62,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
assert account["id"] == to_string(user_three.id)
assert results["hashtags"] == [
- %{"name" => "private", "url" => "#{Web.base_url()}/tag/private"}
+ %{"name" => "private", "url" => "#{Endpoint.url()}/tag/private"}
]
[status] = results["statuses"]
@@ -72,13 +73,58 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|> json_response_and_validate_schema(200)
assert results["hashtags"] == [
- %{"name" => "天子", "url" => "#{Web.base_url()}/tag/天子"}
+ %{"name" => "天子", "url" => "#{Endpoint.url()}/tag/天子"}
]
[status] = results["statuses"]
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 =
@@ -87,8 +133,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|> json_response_and_validate_schema(200)
assert results["hashtags"] == [
- %{"name" => "explicit", "url" => "#{Web.base_url()}/tag/explicit"},
- %{"name" => "hashtags", "url" => "#{Web.base_url()}/tag/hashtags"}
+ %{"name" => "explicit", "url" => "#{Endpoint.url()}/tag/explicit"},
+ %{"name" => "hashtags", "url" => "#{Endpoint.url()}/tag/hashtags"}
]
results =
@@ -97,9 +143,9 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|> json_response_and_validate_schema(200)
assert results["hashtags"] == [
- %{"name" => "john", "url" => "#{Web.base_url()}/tag/john"},
- %{"name" => "doe", "url" => "#{Web.base_url()}/tag/doe"},
- %{"name" => "JohnDoe", "url" => "#{Web.base_url()}/tag/JohnDoe"}
+ %{"name" => "john", "url" => "#{Endpoint.url()}/tag/john"},
+ %{"name" => "doe", "url" => "#{Endpoint.url()}/tag/doe"},
+ %{"name" => "JohnDoe", "url" => "#{Endpoint.url()}/tag/JohnDoe"}
]
results =
@@ -108,9 +154,9 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|> json_response_and_validate_schema(200)
assert results["hashtags"] == [
- %{"name" => "accident", "url" => "#{Web.base_url()}/tag/accident"},
- %{"name" => "prone", "url" => "#{Web.base_url()}/tag/prone"},
- %{"name" => "AccidentProne", "url" => "#{Web.base_url()}/tag/AccidentProne"}
+ %{"name" => "accident", "url" => "#{Endpoint.url()}/tag/accident"},
+ %{"name" => "prone", "url" => "#{Endpoint.url()}/tag/prone"},
+ %{"name" => "AccidentProne", "url" => "#{Endpoint.url()}/tag/AccidentProne"}
]
results =
@@ -119,35 +165,29 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|> json_response_and_validate_schema(200)
assert results["hashtags"] == [
- %{"name" => "shpuld", "url" => "#{Web.base_url()}/tag/shpuld"}
+ %{"name" => "shpuld", "url" => "#{Endpoint.url()}/tag/shpuld"}
]
results =
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)
assert results["hashtags"] == [
- %{"name" => "nascar", "url" => "#{Web.base_url()}/tag/nascar"},
- %{"name" => "ban", "url" => "#{Web.base_url()}/tag/ban"},
- %{"name" => "display", "url" => "#{Web.base_url()}/tag/display"},
- %{"name" => "confederate", "url" => "#{Web.base_url()}/tag/confederate"},
- %{"name" => "flag", "url" => "#{Web.base_url()}/tag/flag"},
- %{"name" => "all", "url" => "#{Web.base_url()}/tag/all"},
- %{"name" => "events", "url" => "#{Web.base_url()}/tag/events"},
- %{"name" => "properties", "url" => "#{Web.base_url()}/tag/properties"},
+ %{"name" => "nascar", "url" => "#{Endpoint.url()}/tag/nascar"},
+ %{"name" => "ban", "url" => "#{Endpoint.url()}/tag/ban"},
+ %{"name" => "display", "url" => "#{Endpoint.url()}/tag/display"},
+ %{"name" => "confederate", "url" => "#{Endpoint.url()}/tag/confederate"},
+ %{"name" => "flag", "url" => "#{Endpoint.url()}/tag/flag"},
+ %{"name" => "all", "url" => "#{Endpoint.url()}/tag/all"},
+ %{"name" => "events", "url" => "#{Endpoint.url()}/tag/events"},
+ %{"name" => "properties", "url" => "#{Endpoint.url()}/tag/properties"},
%{
"name" => "NascarBanDisplayConfederateFlagAllEventsProperties",
"url" =>
- "#{Web.base_url()}/tag/NascarBanDisplayConfederateFlagAllEventsProperties"
+ "#{Endpoint.url()}/tag/NascarBanDisplayConfederateFlagAllEventsProperties"
}
]
end
@@ -156,15 +196,13 @@ 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)
assert results["hashtags"] == [
- %{"name" => "text", "url" => "#{Web.base_url()}/tag/text"},
- %{"name" => "with", "url" => "#{Web.base_url()}/tag/with"}
+ %{"name" => "text", "url" => "#{Endpoint.url()}/tag/text"},
+ %{"name" => "with", "url" => "#{Endpoint.url()}/tag/with"}
]
end
@@ -309,7 +347,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
})
capture_log(fn ->
- q = Object.normalize(activity).data["id"]
+ q = Object.normalize(activity, fetch: false).data["id"]
results =
conn
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 de542e5df..dbb840574 100644
--- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/status_controller_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.MastodonAPI.StatusControllerTest do
@@ -7,15 +7,17 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
use Oban.Testing, repo: Pleroma.Repo
alias Pleroma.Activity
- alias Pleroma.Config
alias Pleroma.Conversation.Participation
+ alias Pleroma.ModerationLog
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.ScheduledActivity
alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI
+ alias Pleroma.Workers.ScheduledActivityWorker
import Pleroma.Factory
@@ -29,7 +31,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
setup do: oauth_access(["write:statuses"])
test "posting a status does not increment reblog_count when relaying", %{conn: conn} do
- Config.put([:instance, :federating], true)
+ clear_config([:instance, :federating], true)
Config.get([:instance, :allow_relay], true)
response =
@@ -82,6 +84,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
"sensitive" => 0
})
+ # Idempotency plug response means detection fail
assert %{"id" => second_id} = json_response(conn_two, 200)
assert id == second_id
@@ -151,8 +154,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
end
test "Get MRF reason when posting a status is rejected by one", %{conn: conn} do
- Config.put([:mrf_keyword, :reject], ["GNO"])
- Config.put([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy])
+ clear_config([:mrf_keyword, :reject], ["GNO"])
+ clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy])
assert %{"error" => "[KeywordPolicy] Matches with rejected keyword"} =
conn
@@ -260,10 +263,12 @@ 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 =
conn
+ |> assign(:user, refresh_record(conn.assigns.user))
|> put_req_header("content-type", "application/json")
|> post("/api/v1/statuses", %{
"status" =>
@@ -282,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
@@ -357,6 +363,69 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
assert activity.data["to"] == [user2.ap_id]
assert activity.data["cc"] == []
end
+
+ test "discloses application metadata when enabled" do
+ user = insert(:user, disclose_client: true)
+ %{user: _user, token: token, conn: conn} = oauth_access(["write:statuses"], user: user)
+
+ %Pleroma.Web.OAuth.Token{
+ app: %Pleroma.Web.OAuth.App{
+ client_name: app_name,
+ website: app_website
+ }
+ } = token
+
+ result =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
+ "status" => "cofe is my copilot"
+ })
+
+ assert %{
+ "content" => "cofe is my copilot"
+ } = json_response_and_validate_schema(result, 200)
+
+ activity = result.assigns.activity.id
+
+ result =
+ conn
+ |> get("api/v1/statuses/#{activity}")
+
+ assert %{
+ "content" => "cofe is my copilot",
+ "application" => %{
+ "name" => ^app_name,
+ "website" => ^app_website
+ }
+ } = json_response_and_validate_schema(result, 200)
+ end
+
+ test "hides application metadata when disabled" do
+ user = insert(:user, disclose_client: false)
+ %{user: _user, token: _token, conn: conn} = oauth_access(["write:statuses"], user: user)
+
+ result =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
+ "status" => "club mate is my wingman"
+ })
+
+ assert %{"content" => "club mate is my wingman"} =
+ json_response_and_validate_schema(result, 200)
+
+ activity = result.assigns.activity.id
+
+ result =
+ conn
+ |> get("api/v1/statuses/#{activity}")
+
+ assert %{
+ "content" => "club mate is my wingman",
+ "application" => nil
+ } = json_response_and_validate_schema(result, 200)
+ end
end
describe "posting scheduled statuses" do
@@ -383,6 +452,31 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
assert [] == Repo.all(Activity)
end
+ test "with expiration" do
+ %{conn: conn} = oauth_access(["write:statuses", "read:statuses"])
+
+ scheduled_at =
+ NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(6), :millisecond)
+ |> NaiveDateTime.to_iso8601()
+ |> Kernel.<>("Z")
+
+ assert %{"id" => status_id, "params" => %{"expires_in" => 300}} =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
+ "status" => "scheduled",
+ "scheduled_at" => scheduled_at,
+ "expires_in" => 300
+ })
+ |> json_response_and_validate_schema(200)
+
+ assert %{"id" => ^status_id, "params" => %{"expires_in" => 300}} =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> get("/api/v1/scheduled_statuses/#{status_id}")
+ |> json_response_and_validate_schema(200)
+ end
+
test "ignores nil values", %{conn: conn} do
conn =
conn
@@ -516,7 +610,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
end)
assert NaiveDateTime.diff(NaiveDateTime.from_iso8601!(response["poll"]["expires_at"]), time) in 420..430
- refute response["poll"]["expred"]
+ assert response["poll"]["expired"] == false
question = Object.get_by_id(response["poll"]["id"])
@@ -592,6 +686,44 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
%{"error" => error} = json_response_and_validate_schema(conn, 422)
assert error == "Expiration date is too far in the future"
end
+
+ test "scheduled poll", %{conn: conn} do
+ clear_config([ScheduledActivity, :enabled], true)
+
+ scheduled_at =
+ NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(6), :millisecond)
+ |> NaiveDateTime.to_iso8601()
+ |> Kernel.<>("Z")
+
+ %{"id" => scheduled_id} =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
+ "status" => "very cool poll",
+ "poll" => %{
+ "options" => ~w(a b c),
+ "expires_in" => 420
+ },
+ "scheduled_at" => scheduled_at
+ })
+ |> json_response_and_validate_schema(200)
+
+ assert {:ok, %{id: activity_id}} =
+ perform_job(ScheduledActivityWorker, %{
+ activity_id: scheduled_id
+ })
+
+ refute_enqueued(worker: ScheduledActivityWorker)
+
+ object =
+ Activity
+ |> Repo.get(activity_id)
+ |> Object.normalize()
+
+ assert object.data["content"] == "very cool poll"
+ assert object.data["type"] == "Question"
+ assert length(object.data["oneOf"]) == 3
+ end
end
test "get a status" do
@@ -800,7 +932,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
test "when you created it" do
%{user: author, conn: conn} = oauth_access(["write:statuses"])
activity = insert(:note_activity, user: author)
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
content = object.data["content"]
source = object.data["source"]
@@ -839,30 +971,40 @@ 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 an admin", %{conn: conn} do
+ activity = insert(:note_activity)
+ user = insert(:user, is_admin: 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)
+ assert ModerationLog |> Repo.one() |> ModerationLog.get_log_entry_message() ==
+ "@#{user.nickname} deleted status ##{activity.id}"
+
+ refute Activity.get_by_id(activity.id)
+ end
+
+ test "when you're a moderator", %{conn: conn} do
+ activity = insert(:note_activity)
+ user = insert(:user, is_moderator: true)
+
res_conn =
conn
- |> assign(:user, moderator)
- |> assign(:token, insert(:oauth_token, user: moderator, scopes: ["write:statuses"]))
- |> delete("/api/v1/statuses/#{activity2.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)
- refute Activity.get_by_id(activity1.id)
- refute Activity.get_by_id(activity2.id)
+ assert ModerationLog |> Repo.one() |> ModerationLog.get_log_entry_message() ==
+ "@#{user.nickname} deleted status ##{activity.id}"
+
+ refute Activity.get_by_id(activity.id)
end
end
@@ -954,6 +1096,23 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
assert to_string(activity.id) == id
end
+
+ test "author can reblog own private status", %{conn: conn, user: user} do
+ {:ok, activity} = CommonAPI.post(user, %{status: "cofe", visibility: "private"})
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/#{activity.id}/reblog")
+
+ assert %{
+ "reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1},
+ "reblogged" => true,
+ "visibility" => "private"
+ } = json_response_and_validate_schema(conn, 200)
+
+ assert to_string(activity.id) == id
+ end
end
describe "unreblogging" do
@@ -1066,20 +1225,27 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
setup do: clear_config([:instance, :max_pinned_statuses], 1)
test "pin status", %{conn: conn, user: user, activity: activity} do
- id_str = to_string(activity.id)
+ id = activity.id
- assert %{"id" => ^id_str, "pinned" => true} =
+ assert %{"id" => ^id, "pinned" => true} =
conn
|> put_req_header("content-type", "application/json")
|> post("/api/v1/statuses/#{activity.id}/pin")
|> json_response_and_validate_schema(200)
- assert [%{"id" => ^id_str, "pinned" => true}] =
+ assert [%{"id" => ^id, "pinned" => true}] =
conn
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
|> json_response_and_validate_schema(200)
end
+ test "non authenticated user", %{activity: activity} do
+ assert build_conn()
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/#{activity.id}/pin")
+ |> json_response(403) == %{"error" => "Invalid credentials."}
+ end
+
test "/pin: returns 400 error when activity is not public", %{conn: conn, user: user} do
{:ok, dm} = CommonAPI.post(user, %{status: "test", visibility: "direct"})
@@ -1088,7 +1254,18 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|> put_req_header("content-type", "application/json")
|> post("/api/v1/statuses/#{dm.id}/pin")
- assert json_response_and_validate_schema(conn, 400) == %{"error" => "Could not pin"}
+ assert json_response_and_validate_schema(conn, 422) == %{
+ "error" => "Non-public status cannot be pinned"
+ }
+ end
+
+ test "pin by another user", %{activity: activity} do
+ %{conn: conn} = oauth_access(["write:accounts"])
+
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/#{activity.id}/pin")
+ |> json_response(422) == %{"error" => "Someone else's status cannot be pinned"}
end
test "unpin status", %{conn: conn, user: user, activity: activity} do
@@ -1109,13 +1286,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|> json_response_and_validate_schema(200)
end
- test "/unpin: returns 400 error when activity is not exist", %{conn: conn} do
- conn =
- conn
- |> put_req_header("content-type", "application/json")
- |> post("/api/v1/statuses/1/unpin")
-
- assert json_response_and_validate_schema(conn, 400) == %{"error" => "Could not unpin"}
+ test "/unpin: returns 404 error when activity doesn't exist", %{conn: conn} do
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/1/unpin")
+ |> json_response_and_validate_schema(404) == %{"error" => "Record not found"}
end
test "max pinned statuses", %{conn: conn, user: user, activity: activity_one} do
@@ -1187,7 +1362,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
describe "cards" do
setup do
- Config.put([:rich_media, :enabled], true)
+ clear_config([:rich_media, :enabled], true)
oauth_access(["read:statuses"])
end
@@ -1374,7 +1549,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
activity = Activity.get_by_id_with_object(id)
- assert Object.normalize(activity).data["inReplyTo"] == Object.normalize(replied_to).data["id"]
+ assert Object.normalize(activity, fetch: false).data["inReplyTo"] ==
+ Object.normalize(replied_to, fetch: false).data["id"]
+
assert Activity.get_in_reply_to_activity(activity).id == replied_to.id
# Reblog from the third user
@@ -1397,7 +1574,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|> assign(:token, insert(:oauth_token, user: user3, scopes: ["read:statuses"]))
|> get("api/v1/timelines/home")
- [reblogged_activity] = json_response(conn3, 200)
+ [reblogged_activity] = json_response_and_validate_schema(conn3, 200)
assert reblogged_activity["reblog"]["in_reply_to_id"] == replied_to.id
@@ -1737,23 +1914,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)
+
+ assert %Activity{id: ^id, data: %{"to" => [^local]}} = Activity.get_by_id(id)
+ end
- local = Pleroma.Constants.as_local_public()
+ 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(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
@@ -1826,4 +2030,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 4bb085750..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-2020 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 c3471266a..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-2020 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 655e35ac6..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-2020 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
@@ -90,6 +90,65 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
}
] = result
end
+
+ test "filtering", %{conn: conn, user: user} do
+ local_user = insert(:user)
+ {:ok, user, local_user} = User.follow(user, local_user)
+ {:ok, local_activity} = CommonAPI.post(local_user, %{status: "Status"})
+ with_media = create_with_media_activity(local_user)
+
+ remote_user = insert(:user, local: false)
+ {:ok, _user, remote_user} = User.follow(user, remote_user)
+ remote_activity = create_remote_activity(remote_user)
+
+ without_filter_ids =
+ conn
+ |> get("/api/v1/timelines/home")
+ |> json_response_and_validate_schema(200)
+ |> Enum.map(& &1["id"])
+
+ assert local_activity.id in without_filter_ids
+ assert remote_activity.id in without_filter_ids
+ assert with_media.id in without_filter_ids
+
+ only_local_ids =
+ conn
+ |> get("/api/v1/timelines/home?local=true")
+ |> json_response_and_validate_schema(200)
+ |> Enum.map(& &1["id"])
+
+ assert local_activity.id in only_local_ids
+ refute remote_activity.id in only_local_ids
+ assert with_media.id in only_local_ids
+
+ only_local_media_ids =
+ conn
+ |> get("/api/v1/timelines/home?local=true&only_media=true")
+ |> json_response_and_validate_schema(200)
+ |> Enum.map(& &1["id"])
+
+ refute local_activity.id in only_local_media_ids
+ refute remote_activity.id in only_local_media_ids
+ assert with_media.id in only_local_media_ids
+
+ remote_ids =
+ conn
+ |> get("/api/v1/timelines/home?remote=true")
+ |> json_response_and_validate_schema(200)
+ |> Enum.map(& &1["id"])
+
+ refute local_activity.id in remote_ids
+ assert remote_activity.id in remote_ids
+ refute with_media.id in remote_ids
+
+ assert conn
+ |> get("/api/v1/timelines/home?remote=true&only_media=true")
+ |> json_response_and_validate_schema(200) == []
+
+ assert conn
+ |> get("/api/v1/timelines/home?remote=true&local=true")
+ |> json_response_and_validate_schema(200) == []
+ end
end
describe "public" do
@@ -98,27 +157,80 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "test"})
+ with_media = create_with_media_activity(user)
+
+ remote = insert(:note_activity, local: false)
+
+ assert conn
+ |> get("/api/v1/timelines/public?local=False")
+ |> json_response_and_validate_schema(:ok)
+ |> length == 3
+
+ local_ids =
+ conn
+ |> get("/api/v1/timelines/public?local=True")
+ |> json_response_and_validate_schema(:ok)
+ |> Enum.map(& &1["id"])
+
+ assert activity.id in local_ids
+ assert with_media.id in local_ids
+ refute remote.id in local_ids
+
+ local_ids =
+ conn
+ |> get("/api/v1/timelines/public?local=True")
+ |> json_response_and_validate_schema(:ok)
+ |> Enum.map(& &1["id"])
+
+ assert activity.id in local_ids
+ assert with_media.id in local_ids
+ refute remote.id in local_ids
+
+ local_ids =
+ conn
+ |> get("/api/v1/timelines/public?local=True&only_media=true")
+ |> json_response_and_validate_schema(:ok)
+ |> Enum.map(& &1["id"])
+
+ refute activity.id in local_ids
+ assert with_media.id in local_ids
+ refute remote.id in local_ids
- _activity = insert(:note_activity, local: false)
+ local_ids =
+ conn
+ |> get("/api/v1/timelines/public?local=1")
+ |> json_response_and_validate_schema(:ok)
+ |> Enum.map(& &1["id"])
- conn = get(conn, "/api/v1/timelines/public?local=False")
+ assert activity.id in local_ids
+ assert with_media.id in local_ids
+ refute remote.id in local_ids
- assert length(json_response_and_validate_schema(conn, :ok)) == 2
+ remote_id = remote.id
- conn = get(build_conn(), "/api/v1/timelines/public?local=True")
+ assert [%{"id" => ^remote_id}] =
+ conn
+ |> get("/api/v1/timelines/public?remote=true")
+ |> json_response_and_validate_schema(:ok)
- assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok)
+ with_media_id = with_media.id
- conn = get(build_conn(), "/api/v1/timelines/public?local=1")
+ assert [%{"id" => ^with_media_id}] =
+ conn
+ |> get("/api/v1/timelines/public?only_media=true")
+ |> json_response_and_validate_schema(:ok)
- assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok)
+ assert conn
+ |> get("/api/v1/timelines/public?remote=true&only_media=true")
+ |> json_response_and_validate_schema(:ok) == []
# does not contain repeats
{:ok, _} = CommonAPI.repeat(activity.id, user)
- conn = get(build_conn(), "/api/v1/timelines/public?local=true")
-
- assert [_] = json_response_and_validate_schema(conn, :ok)
+ assert [_, _] =
+ conn
+ |> get("/api/v1/timelines/public?local=true")
+ |> json_response_and_validate_schema(:ok)
end
test "the public timeline includes only public statuses for an authenticated user" do
@@ -161,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)
@@ -237,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
@@ -544,6 +715,77 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
}
] = result
end
+
+ test "filtering", %{user: user, conn: conn} do
+ {:ok, list} = Pleroma.List.create("name", user)
+
+ local_user = insert(:user)
+ {:ok, local_activity} = CommonAPI.post(local_user, %{status: "Marisa is stupid."})
+ with_media = create_with_media_activity(local_user)
+ {:ok, list} = Pleroma.List.follow(list, local_user)
+
+ remote_user = insert(:user, local: false)
+ remote_activity = create_remote_activity(remote_user)
+ {:ok, list} = Pleroma.List.follow(list, remote_user)
+
+ all_ids =
+ conn
+ |> get("/api/v1/timelines/list/#{list.id}")
+ |> json_response_and_validate_schema(200)
+ |> Enum.map(& &1["id"])
+
+ assert local_activity.id in all_ids
+ assert with_media.id in all_ids
+ assert remote_activity.id in all_ids
+
+ only_local_ids =
+ conn
+ |> get("/api/v1/timelines/list/#{list.id}?local=true")
+ |> json_response_and_validate_schema(200)
+ |> Enum.map(& &1["id"])
+
+ assert local_activity.id in only_local_ids
+ assert with_media.id in only_local_ids
+ refute remote_activity.id in only_local_ids
+
+ only_local_media_ids =
+ conn
+ |> get("/api/v1/timelines/list/#{list.id}?local=true&only_media=true")
+ |> json_response_and_validate_schema(200)
+ |> Enum.map(& &1["id"])
+
+ refute local_activity.id in only_local_media_ids
+ assert with_media.id in only_local_media_ids
+ refute remote_activity.id in only_local_media_ids
+
+ remote_ids =
+ conn
+ |> get("/api/v1/timelines/list/#{list.id}?remote=true")
+ |> json_response_and_validate_schema(200)
+ |> Enum.map(& &1["id"])
+
+ refute local_activity.id in remote_ids
+ refute with_media.id in remote_ids
+ assert remote_activity.id in remote_ids
+
+ assert conn
+ |> get("/api/v1/timelines/list/#{list.id}?remote=true&only_media=true")
+ |> json_response_and_validate_schema(200) == []
+
+ only_media_ids =
+ conn
+ |> get("/api/v1/timelines/list/#{list.id}?only_media=true")
+ |> json_response_and_validate_schema(200)
+ |> Enum.map(& &1["id"])
+
+ refute local_activity.id in only_media_ids
+ assert with_media.id in only_media_ids
+ refute remote_activity.id in only_media_ids
+
+ assert conn
+ |> get("/api/v1/timelines/list/#{list.id}?only_media=true&local=true&remote=true")
+ |> json_response_and_validate_schema(200) == []
+ end
end
describe "hashtag" do
@@ -554,19 +796,85 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
following = insert(:user)
{:ok, activity} = CommonAPI.post(following, %{status: "test #2hu"})
+ with_media = create_with_media_activity(following)
- nconn = get(conn, "/api/v1/timelines/tag/2hu")
+ remote = insert(:user, local: false)
+ remote_activity = create_remote_activity(remote)
- assert [%{"id" => id}] = json_response_and_validate_schema(nconn, :ok)
+ all_ids =
+ conn
+ |> get("/api/v1/timelines/tag/2hu")
+ |> json_response_and_validate_schema(:ok)
+ |> Enum.map(& &1["id"])
- assert id == to_string(activity.id)
+ assert activity.id in all_ids
+ assert with_media.id in all_ids
+ assert remote_activity.id in all_ids
# works for different capitalization too
- nconn = get(conn, "/api/v1/timelines/tag/2HU")
+ all_ids =
+ conn
+ |> get("/api/v1/timelines/tag/2HU")
+ |> json_response_and_validate_schema(:ok)
+ |> Enum.map(& &1["id"])
+
+ assert activity.id in all_ids
+ assert with_media.id in all_ids
+ assert remote_activity.id in all_ids
+
+ local_ids =
+ conn
+ |> get("/api/v1/timelines/tag/2hu?local=true")
+ |> json_response_and_validate_schema(:ok)
+ |> Enum.map(& &1["id"])
- assert [%{"id" => id}] = json_response_and_validate_schema(nconn, :ok)
+ assert activity.id in local_ids
+ assert with_media.id in local_ids
+ refute remote_activity.id in local_ids
- assert id == to_string(activity.id)
+ remote_ids =
+ conn
+ |> get("/api/v1/timelines/tag/2hu?remote=true")
+ |> json_response_and_validate_schema(:ok)
+ |> Enum.map(& &1["id"])
+
+ refute activity.id in remote_ids
+ refute with_media.id in remote_ids
+ assert remote_activity.id in remote_ids
+
+ media_ids =
+ conn
+ |> get("/api/v1/timelines/tag/2hu?only_media=true")
+ |> json_response_and_validate_schema(:ok)
+ |> Enum.map(& &1["id"])
+
+ refute activity.id in media_ids
+ assert with_media.id in media_ids
+ refute remote_activity.id in media_ids
+
+ media_local_ids =
+ conn
+ |> get("/api/v1/timelines/tag/2hu?only_media=true&local=true")
+ |> json_response_and_validate_schema(:ok)
+ |> Enum.map(& &1["id"])
+
+ refute activity.id in media_local_ids
+ assert with_media.id in media_local_ids
+ refute remote_activity.id in media_local_ids
+
+ ids =
+ conn
+ |> get("/api/v1/timelines/tag/2hu?only_media=true&local=true&remote=true")
+ |> json_response_and_validate_schema(:ok)
+ |> Enum.map(& &1["id"])
+
+ refute activity.id in ids
+ refute with_media.id in ids
+ refute remote_activity.id in ids
+
+ assert conn
+ |> get("/api/v1/timelines/tag/2hu?only_media=true&remote=true")
+ |> json_response_and_validate_schema(:ok) == []
end
test "multi-hashtag timeline", %{conn: conn} do
@@ -636,7 +944,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
end
end
- describe "hashtag timeline handling of :restrict_unauthenticated setting" do
+ describe "hashtag timeline handling of restrict_unauthenticated setting" do
setup do
user = insert(:user)
{:ok, activity1} = CommonAPI.post(user, %{status: "test #tag1"})
@@ -656,10 +964,10 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
%{conn: auth_conn} = oauth_access(["read:statuses"])
res_conn = get(auth_conn, "#{base_uri}?local=true")
- assert length(json_response(res_conn, 200)) == 1
+ assert length(json_response_and_validate_schema(res_conn, 200)) == 1
res_conn = get(auth_conn, "#{base_uri}?local=false")
- assert length(json_response(res_conn, 200)) == 2
+ assert length(json_response_and_validate_schema(res_conn, 200)) == 2
end
test "with default settings on private instances, returns 403 for unauthenticated users", %{
@@ -673,7 +981,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
for local <- [true, false] do
res_conn = get(conn, "#{base_uri}?local=#{local}")
- assert json_response(res_conn, :unauthorized) == error_response
+ assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
end
ensure_authenticated_access(base_uri)
@@ -690,7 +998,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
for local <- [true, false] do
res_conn = get(conn, "#{base_uri}?local=#{local}")
- assert json_response(res_conn, :unauthorized) == error_response
+ assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
end
ensure_authenticated_access(base_uri)
@@ -702,10 +1010,10 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
clear_config([:restrict_unauthenticated, :timelines, :federated], true)
res_conn = get(conn, "#{base_uri}?local=true")
- assert length(json_response(res_conn, 200)) == 1
+ assert length(json_response_and_validate_schema(res_conn, 200)) == 1
res_conn = get(conn, "#{base_uri}?local=false")
- assert json_response(res_conn, :unauthorized) == error_response
+ assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
ensure_authenticated_access(base_uri)
end
@@ -717,13 +1025,46 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
clear_config([:restrict_unauthenticated, :timelines, :federated], false)
res_conn = get(conn, "#{base_uri}?local=true")
- assert json_response(res_conn, :unauthorized) == error_response
+ assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
# Note: local activities get delivered as part of federated timeline
res_conn = get(conn, "#{base_uri}?local=false")
- assert length(json_response(res_conn, 200)) == 2
+ assert length(json_response_and_validate_schema(res_conn, 200)) == 2
ensure_authenticated_access(base_uri)
end
end
+
+ defp create_remote_activity(user) do
+ obj =
+ insert(:note, %{
+ data: %{
+ "to" => [
+ "https://www.w3.org/ns/activitystreams#Public",
+ User.ap_followers(user)
+ ]
+ },
+ user: user
+ })
+
+ insert(:note_activity, %{
+ note: obj,
+ recipients: [
+ "https://www.w3.org/ns/activitystreams#Public",
+ User.ap_followers(user)
+ ],
+ user: user,
+ local: false
+ })
+ end
+
+ defp create_with_media_activity(user) do
+ obj = insert(:attachment_note, user: user)
+
+ insert(:note_activity, %{
+ note: obj,
+ recipients: ["https://www.w3.org/ns/activitystreams#Public", User.ap_followers(user)],
+ user: user
+ })
+ end
end
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 b9cd050df..000000000
--- a/test/pleroma/web/mastodon_api/masto_fe_controller_test.exs
+++ /dev/null
@@ -1,86 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.MastodonAPI.MastoFEControllerTest do
- use Pleroma.Web.ConnCase
-
- alias Pleroma.Config
- 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 _result = 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
- Config.put([:instance, :public], false)
-
- conn = get(conn, path)
-
- assert conn.status == 302
- assert redirected_to(conn) == "/web/login"
- end
-
- test "does not redirect logged in users to the login page", %{conn: conn, path: path} do
- {: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 be5bf68a3..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-2020 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 cf7f464be..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-2020 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
@@ -16,7 +16,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
describe "follow/3" do
test "returns error when followed user is deactivated" do
follower = insert(:user)
- user = insert(:user, local: true, deactivated: true)
+ user = insert(:user, local: true, is_active: false)
assert {:error, _error} = MastodonAPI.follow(follower, user)
end
diff --git a/test/pleroma/web/mastodon_api/update_credentials_test.exs b/test/pleroma/web/mastodon_api/update_credentials_test.exs
index e3e437a19..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-2020 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 f9afd0afc..692ec8c92 100644
--- a/test/pleroma/web/mastodon_api/views/account_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/account_view_test.exs
@@ -1,11 +1,10 @@
# 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.MastodonAPI.AccountViewTest do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.User
alias Pleroma.UserRelationship
alias Pleroma.Web.CommonAPI
@@ -74,15 +73,18 @@ 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"],
background_image: "https://example.com/images/asuka_hospital.png",
favicon: nil,
- confirmation_pending: false,
+ is_confirmed: true,
tags: [],
is_admin: false,
is_moderator: false,
+ is_suggested: false,
hide_favorites: true,
hide_followers: false,
hide_follows: false,
@@ -173,15 +175,18 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
},
fields: []
},
+ fqn: "shp@shitposter.club",
+ last_status_at: nil,
pleroma: %{
ap_id: user.ap_id,
also_known_as: [],
background_image: nil,
favicon: nil,
- confirmation_pending: false,
+ is_confirmed: true,
tags: [],
is_admin: false,
is_moderator: false,
+ is_suggested: false,
hide_favorites: true,
hide_followers: false,
hide_follows: false,
@@ -211,7 +216,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
test "Represent a deactivated user for an admin" do
admin = insert(:user, is_admin: true)
- deactivated_user = insert(:user, deactivated: true)
+ deactivated_user = insert(:user, is_active: false)
represented = AccountView.render("show.json", %{user: deactivated_user, for: admin})
assert represented[:pleroma][:deactivated] == true
end
@@ -267,10 +272,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
@@ -292,6 +299,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)
}
@@ -467,6 +475,57 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
%{user: user, for: user}
)[:pleroma][:unread_notifications_count] == 7
end
+
+ test "shows email only to the account owner" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ user = User.get_cached_by_ap_id(user.ap_id)
+
+ assert AccountView.render(
+ "show.json",
+ %{user: user, for: other_user}
+ )[:pleroma][:email] == nil
+
+ assert AccountView.render(
+ "show.json",
+ %{user: user, for: user}
+ )[:pleroma][:email] == user.email
+ end
+ end
+
+ describe "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
@@ -556,17 +615,17 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
)
with media_preview_enabled <- [false, true] do
- Config.put([:media_preview_proxy, :enabled], media_preview_enabled)
+ clear_config([:media_preview_proxy, :enabled], media_preview_enabled)
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|> Enum.all?(fn
{key, url} when key in [:avatar, :avatar_static, :header, :header_static] ->
- String.starts_with?(url, Pleroma.Web.base_url())
+ String.starts_with?(url, Pleroma.Web.Endpoint.url())
{:emojis, emojis} ->
Enum.all?(emojis, fn %{url: url, static_url: static_url} ->
- String.starts_with?(url, Pleroma.Web.base_url()) &&
- String.starts_with?(static_url, Pleroma.Web.base_url())
+ String.starts_with?(url, Pleroma.Web.Endpoint.url()) &&
+ String.starts_with?(static_url, Pleroma.Web.Endpoint.url())
end)
_ ->
@@ -575,4 +634,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 f02253b68..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-2020 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 377941332..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-2020 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 a0bec758f..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-2020 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 9de11a87e..d3d74f5cd 100644
--- a/test/pleroma/web/mastodon_api/views/notification_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/notification_view_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.MastodonAPI.NotificationViewTest do
@@ -44,7 +44,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
{:ok, [notification]} = Notification.create_notifications(activity)
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
chat = Chat.get(recipient.id, user.ap_id)
cm_ref = MessageReference.for_chat_and_object(chat, object)
@@ -144,24 +144,11 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
refute Repo.one(Notification)
end
- @tag capture_log: true
test "Move notification" do
old_user = insert(:user)
new_user = insert(:user, also_known_as: [old_user.ap_id])
follower = insert(:user)
- old_user_url = old_user.ap_id
-
- body =
- File.read!("test/fixtures/users_mock/localhost.json")
- |> String.replace("{{nickname}}", old_user.nickname)
- |> Jason.encode!()
-
- Tesla.Mock.mock(fn
- %{method: :get, url: ^old_user_url} ->
- %Tesla.Env{status: 200, body: body}
- end)
-
User.follow(follower, old_user)
Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)
Pleroma.Tests.ObanHelpers.perform_all()
@@ -209,6 +196,27 @@ 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
reporting_user = insert(:user)
reported_user = insert(:user)
@@ -229,6 +237,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 c655ca438..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-2020 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
@@ -29,7 +29,7 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do
}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
expected = %{
emojis: [],
@@ -42,7 +42,6 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do
%{title: "yes", votes_count: 0},
%{title: "why are you even asking?", votes_count: 0}
],
- voted: false,
votes_count: 0,
voters_count: 0
}
@@ -72,7 +71,7 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do
voter = insert(:user)
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
{:ok, _votes, object} = CommonAPI.vote(voter, object, [0, 1])
@@ -98,7 +97,7 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do
}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert %{emojis: [%{shortcode: "blank"}]} = PollView.render("show.json", %{object: object})
end
@@ -117,19 +116,21 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do
}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
{:ok, _, object} = CommonAPI.vote(other_user, object, [1, 2])
result = PollView.render("show.json", %{object: object, for: other_user})
assert result[:voted] == true
+ assert 1 in result[:own_votes]
+ assert 2 in result[:own_votes]
assert Enum.at(result[:options], 1)[:votes_count] == 1
assert Enum.at(result[:options], 2)[:votes_count] == 1
end
test "does not crash on polls with no end date" do
- object = Object.normalize("https://skippers-bin.com/notes/7x9tmrp97i")
+ object = Object.normalize("https://skippers-bin.com/notes/7x9tmrp97i", fetch: true)
result = PollView.render("show.json", %{object: object})
assert result[:expires_at] == nil
@@ -153,7 +154,7 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do
}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert %{
options: [
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 c41ac7f7f..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-2020 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
@@ -58,7 +58,8 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do
sensitive: true,
spoiler_text: "spoiler",
text: "hi",
- visibility: "unlisted"
+ visibility: "unlisted",
+ expires_in: nil
},
scheduled_at: Utils.to_masto_date(scheduled_activity.scheduled_at)
}
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 fa9066716..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-2020 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
@@ -61,7 +62,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
{:ok, activity} = CommonAPI.post(user, %{status: "yo"})
activity
- |> Object.normalize(false)
+ |> Object.normalize(fetch: false)
|> Object.update_data(%{"reactions" => %{"☕" => [user.ap_id], "x" => 1}})
activity = Activity.get_by_id(activity.id)
@@ -204,7 +205,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
test "a note with null content" do
note = insert(:note_activity)
- note_object = Object.normalize(note)
+ note_object = Object.normalize(note, fetch: false)
data =
note_object.data
@@ -223,10 +224,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
test "a note activity" do
note = insert(:note_activity)
- object_data = Object.normalize(note).data
+ 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,
@@ -262,14 +264,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
mentions: [],
tags: [
%{
- name: "#{object_data["tag"]}",
- url: "/tag/#{object_data["tag"]}"
+ name: "#{hd(object_data["tag"])}",
+ url: "http://localhost:4001/tag/#{hd(object_data["tag"])}"
}
],
- application: %{
- name: "Web",
- website: nil
- },
+ application: nil,
language: nil,
emojis: [
%{
@@ -282,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"])},
@@ -289,7 +289,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
direct_conversation_id: nil,
thread_muted: false,
emoji_reactions: [],
- parent_visible: false
+ parent_visible: false,
+ pinned_at: nil
}
}
@@ -461,7 +462,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
"url" => [
%{
"mediaType" => "image/png",
- "href" => "someurl"
+ "href" => "someurl",
+ "width" => 200,
+ "height" => 100
}
],
"blurhash" => "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn",
@@ -477,6 +480,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
text_url: "someurl",
description: nil,
pleroma: %{mime_type: "image/png"},
+ meta: %{original: %{width: 200, height: 100, aspect: 2}},
blurhash: "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn"
}
@@ -585,9 +589,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
]
assert StatusView.build_tags(object_tags) == [
- %{name: "fediverse", url: "/tag/fediverse"},
- %{name: "mastodon", url: "/tag/mastodon"},
- %{name: "nextcloud", url: "/tag/nextcloud"}
+ %{name: "fediverse", url: "http://localhost:4001/tag/fediverse"},
+ %{name: "mastodon", url: "http://localhost:4001/tag/mastodon"},
+ %{name: "nextcloud", url: "http://localhost:4001/tag/nextcloud"}
]
end
end
@@ -707,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 c2bb535c5..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-2020 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 c81010423..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-2020 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 6940a4539..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-2020 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
@@ -8,13 +8,16 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.ScriptTest do
import ExUnit.CaptureLog
- test "it logger error when script not found" do
+ test "it logs error when script is not found" do
assert capture_log(fn ->
- assert Invalidation.Script.purge(
- ["http://example.com/media/example.jpg"],
- script_path: "./example"
- ) == {:error, "%ErlangError{original: :enoent}"}
- end) =~ "Error while cache purge: %ErlangError{original: :enoent}"
+ assert {:error, msg} =
+ Invalidation.Script.purge(
+ ["http://example.com/media/example.jpg"],
+ script_path: "./example"
+ )
+
+ assert msg =~ ~r/%ErlangError{original: :enoent(, reason: nil)?}/
+ end) =~ ~r/Error while cache purge: %ErlangError{original: :enoent(, reason: nil)?}/
capture_log(fn ->
assert Invalidation.Script.purge(
@@ -23,4 +26,30 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.ScriptTest do
) == {:error, "\"not found script path\""}
end)
end
+
+ describe "url formatting" do
+ setup do
+ urls = [
+ "https://bikeshed.party/media/foo.png",
+ "http://safe.millennial.space/proxy/wheeeee.gif",
+ "https://lain.com/proxy/mediafile.mp4?foo&bar=true",
+ "http://localhost:4000/media/upload.jpeg"
+ ]
+
+ [urls: urls]
+ end
+
+ test "with invalid formatter", %{urls: urls} do
+ assert urls == Invalidation.Script.maybe_format_urls(urls, nil)
+ end
+
+ test "with :htcacheclean formatter", %{urls: urls} do
+ assert [
+ "https://bikeshed.party:443/media/foo.png?",
+ "http://safe.millennial.space:80/proxy/wheeeee.gif?",
+ "https://lain.com:443/proxy/mediafile.mp4?foo&bar=true",
+ "http://localhost:4000/media/upload.jpeg?"
+ ] == Invalidation.Script.maybe_format_urls(urls, :htcacheclean)
+ end
+ end
end
diff --git a/test/pleroma/web/media_proxy/invalidation_test.exs b/test/pleroma/web/media_proxy/invalidation_test.exs
index b7be36b47..6196c69be 100644
--- a/test/pleroma/web/media_proxy/invalidation_test.exs
+++ b/test/pleroma/web/media_proxy/invalidation_test.exs
@@ -1,11 +1,10 @@
# 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.MediaProxy.InvalidationTest do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.Web.MediaProxy.Invalidation
import ExUnit.CaptureLog
@@ -16,11 +15,11 @@ defmodule Pleroma.Web.MediaProxy.InvalidationTest do
describe "Invalidation.Http" do
test "perform request to clear cache" do
- Config.put([:media_proxy, :enabled], false)
- Config.put([:media_proxy, :invalidation, :enabled], true)
- Config.put([:media_proxy, :invalidation, :provider], Invalidation.Http)
+ clear_config([:media_proxy, :enabled], false)
+ clear_config([:media_proxy, :invalidation, :enabled], true)
+ clear_config([:media_proxy, :invalidation, :provider], Invalidation.Http)
- Config.put([Invalidation.Http], method: :purge, headers: [{"x-refresh", 1}])
+ clear_config([Invalidation.Http], method: :purge, headers: [{"x-refresh", 1}])
image_url = "http://example.com/media/example.jpg"
Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
@@ -43,10 +42,10 @@ defmodule Pleroma.Web.MediaProxy.InvalidationTest do
describe "Invalidation.Script" do
test "run script to clear cache" do
- Config.put([:media_proxy, :enabled], false)
- Config.put([:media_proxy, :invalidation, :enabled], true)
- Config.put([:media_proxy, :invalidation, :provider], Invalidation.Script)
- Config.put([Invalidation.Script], script_path: "purge-nginx")
+ clear_config([:media_proxy, :enabled], false)
+ clear_config([:media_proxy, :invalidation, :enabled], true)
+ clear_config([:media_proxy, :invalidation, :provider], Invalidation.Script)
+ clear_config([Invalidation.Script], script_path: "purge-nginx")
image_url = "http://example.com/media/example.jpg"
Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
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 65cf2a01b..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-2020 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
@@ -33,7 +33,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
end
test "it returns 403 for invalid signature", %{conn: conn, url: url} do
- Pleroma.Config.put([Pleroma.Web.Endpoint, :secret_key_base], "000")
+ clear_config([Pleroma.Web.Endpoint, :secret_key_base], "000")
%{path: path} = URI.parse(url)
assert %Conn{
@@ -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
@@ -128,7 +126,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
end
test "it returns 403 for invalid signature", %{conn: conn, url: url} do
- Pleroma.Config.put([Pleroma.Web.Endpoint, :secret_key_base], "000")
+ clear_config([Pleroma.Web.Endpoint, :secret_key_base], "000")
%{path: path} = URI.parse(url)
assert %Conn{
@@ -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 0e6df826c..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-2020 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
@@ -11,8 +11,7 @@ defmodule Pleroma.Web.MediaProxyTest do
alias Pleroma.Web.MediaProxy
defp decode_result(encoded) do
- [_, "proxy", sig, base64 | _] = URI.parse(encoded).path |> String.split("/")
- {:ok, decoded} = MediaProxy.decode_url(sig, base64)
+ {:ok, decoded} = MediaProxy.decode_url(encoded)
decoded
end
@@ -42,7 +41,7 @@ defmodule Pleroma.Web.MediaProxyTest do
assert String.starts_with?(
encoded,
- Config.get([:media_proxy, :base_url], Pleroma.Web.base_url())
+ Config.get([:media_proxy, :base_url], Pleroma.Web.Endpoint.url())
)
assert String.ends_with?(encoded, "/logo.png")
diff --git a/test/pleroma/web/metadata/player_view_test.exs b/test/pleroma/web/metadata/player_view_test.exs
index 6d22317d2..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-2020 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 c7359e00b..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-2020 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 218540e6c..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-2020 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
@@ -22,7 +22,12 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
"attachment" => [
%{
"url" => [
- %{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}
+ %{
+ "mediaType" => "image/png",
+ "href" => "https://pleroma.gov/tenshi.png",
+ "height" => 1024,
+ "width" => 1280
+ }
]
},
%{
@@ -35,7 +40,12 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
},
%{
"url" => [
- %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
+ %{
+ "mediaType" => "video/webm",
+ "href" => "https://pleroma.gov/about/juche.webm",
+ "height" => 600,
+ "width" => 800
+ }
]
},
%{
@@ -55,18 +65,22 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
assert Enum.all?(
[
{:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []},
+ {:meta, [property: "og:image:width", content: "1280"], []},
+ {:meta, [property: "og:image:height", content: "1024"], []},
{:meta,
[property: "og:audio", content: "http://www.gnu.org/music/free-software-song.au"],
[]},
{:meta, [property: "og:video", content: "https://pleroma.gov/about/juche.webm"],
- []}
+ []},
+ {:meta, [property: "og:video:width", content: "800"], []},
+ {:meta, [property: "og:video:height", content: "600"], []}
],
fn element -> element in result end
)
end
test "it does not render attachments if post is nsfw" do
- Pleroma.Config.put([Pleroma.Web.Metadata, :unfurl_nsfw], false)
+ clear_config([Pleroma.Web.Metadata, :unfurl_nsfw], false)
user = insert(:user, avatar: %{"url" => [%{"href" => "https://pleroma.gov/tenshi.png"}]})
note =
@@ -93,4 +107,84 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
refute {:meta, [property: "og:image", content: "https://misskey.microsoft/corndog.png"], []} in result
end
+
+ test "video attachments have image thumbnail with WxH metadata with Preview Proxy enabled" do
+ clear_config([:media_proxy, :enabled], true)
+ clear_config([:media_preview_proxy, :enabled], true)
+ user = insert(:user)
+
+ note =
+ insert(:note, %{
+ data: %{
+ "actor" => user.ap_id,
+ "id" => "https://pleroma.gov/objects/whatever",
+ "content" => "test video post",
+ "sensitive" => false,
+ "attachment" => [
+ %{
+ "url" => [
+ %{
+ "mediaType" => "video/webm",
+ "href" => "https://pleroma.gov/about/juche.webm",
+ "height" => 600,
+ "width" => 800
+ }
+ ]
+ }
+ ]
+ }
+ })
+
+ result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
+
+ assert {:meta, [property: "og:image:width", content: "800"], []} in result
+ assert {:meta, [property: "og:image:height", content: "600"], []} in result
+
+ assert {:meta,
+ [
+ property: "og:image",
+ content:
+ "http://localhost:4001/proxy/preview/LzAnlke-l5oZbNzWsrHfprX1rGw/aHR0cHM6Ly9wbGVyb21hLmdvdi9hYm91dC9qdWNoZS53ZWJt/juche.webm"
+ ], []} in result
+ end
+
+ test "video attachments have no image thumbnail with Preview Proxy disabled" do
+ clear_config([:media_proxy, :enabled], true)
+ clear_config([:media_preview_proxy, :enabled], false)
+ user = insert(:user)
+
+ note =
+ insert(:note, %{
+ data: %{
+ "actor" => user.ap_id,
+ "id" => "https://pleroma.gov/objects/whatever",
+ "content" => "test video post",
+ "sensitive" => false,
+ "attachment" => [
+ %{
+ "url" => [
+ %{
+ "mediaType" => "video/webm",
+ "href" => "https://pleroma.gov/about/juche.webm",
+ "height" => 600,
+ "width" => 800
+ }
+ ]
+ }
+ ]
+ }
+ })
+
+ result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
+
+ refute {:meta, [property: "og:image:width", content: "800"], []} in result
+ refute {:meta, [property: "og:image:height", content: "600"], []} in result
+
+ refute {:meta,
+ [
+ property: "og:image",
+ content:
+ "http://localhost:4001/proxy/preview/LzAnlke-l5oZbNzWsrHfprX1rGw/aHR0cHM6Ly9wbGVyb21hLmdvdi9hYm91dC9qdWNoZS53ZWJt/juche.webm"
+ ], []} in result
+ end
end
diff --git a/test/pleroma/web/metadata/providers/rel_me_test.exs b/test/pleroma/web/metadata/providers/rel_me_test.exs
index ae449c052..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-2020 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 52399fdc8..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-2020 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 10931b5ba..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-2020 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
@@ -9,6 +9,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
alias Pleroma.User
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Endpoint
+ alias Pleroma.Web.MediaProxy
alias Pleroma.Web.Metadata.Providers.TwitterCard
alias Pleroma.Web.Metadata.Utils
alias Pleroma.Web.Router
@@ -17,14 +18,14 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
test "it renders twitter card for user info" do
user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
- avatar_url = Utils.attachment_url(User.avatar_url(user))
+ avatar_url = MediaProxy.preview_url(User.avatar_url(user))
res = TwitterCard.build_tags(%{user: user})
assert res == [
- {: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
@@ -38,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"
}
})
@@ -45,16 +47,46 @@ 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
test "it renders avatar not attachment if post is nsfw and unfurl_nsfw is disabled" do
- Pleroma.Config.put([Pleroma.Web.Metadata, :unfurl_nsfw], false)
+ clear_config([Pleroma.Web.Metadata, :unfurl_nsfw], false)
user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
{:ok, activity} = CommonAPI.post(user, %{status: "HI"})
@@ -64,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" => [
@@ -90,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
@@ -108,10 +141,18 @@ 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" => [
%{
- "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}]
+ "url" => [
+ %{
+ "mediaType" => "image/png",
+ "href" => "https://pleroma.gov/tenshi.png",
+ "height" => 1024,
+ "width" => 1280
+ }
+ ]
},
%{
"url" => [
@@ -123,7 +164,12 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
},
%{
"url" => [
- %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
+ %{
+ "mediaType" => "video/webm",
+ "href" => "https://pleroma.gov/about/juche.webm",
+ "height" => 600,
+ "width" => 800
+ }
]
}
]
@@ -133,18 +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: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: "480"], []},
- {:meta, [property: "twitter:player:height", content: "480"], []}
+ {:meta, [name: "twitter:player:width", content: "800"], []},
+ {:meta, [name: "twitter:player:height", content: "600"], []},
+ {:meta,
+ [
+ name: "twitter:player:stream",
+ content: "https://pleroma.gov/about/juche.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 3794db766..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-2020 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 4590e1296..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-2020 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
@@ -9,7 +9,7 @@ defmodule Pleroma.Web.MongooseIMControllerTest do
test "/user_exists", %{conn: conn} do
_user = insert(:user, nickname: "lain")
_remote_user = insert(:user, nickname: "alice", local: false)
- _deactivated_user = insert(:user, nickname: "konata", deactivated: true)
+ _deactivated_user = insert(:user, nickname: "konata", is_active: false)
res =
conn
@@ -41,13 +41,13 @@ defmodule Pleroma.Web.MongooseIMControllerTest do
end
test "/check_password", %{conn: conn} do
- user = insert(:user, password_hash: Pbkdf2.hash_pwd_salt("cool"))
+ user = insert(:user, password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("cool"))
_deactivated_user =
insert(:user,
nickname: "konata",
- deactivated: true,
- password_hash: Pbkdf2.hash_pwd_salt("cool")
+ is_active: false,
+ password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("cool")
)
res =
diff --git a/test/pleroma/web/node_info_test.exs b/test/pleroma/web/node_info_test.exs
index 06b33607f..247ad7501 100644
--- a/test/pleroma/web/node_info_test.exs
+++ b/test/pleroma/web/node_info_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.NodeInfoTest do
@@ -7,8 +7,6 @@ defmodule Pleroma.Web.NodeInfoTest do
import Pleroma.Factory
- alias Pleroma.Config
-
setup do: clear_config([:mrf_simple])
setup do: clear_config(:instance)
@@ -93,7 +91,7 @@ defmodule Pleroma.Web.NodeInfoTest do
assert "safe_dm_mentions" in response["metadata"]["features"]
- Config.put([:instance, :safe_dm_mentions], false)
+ clear_config([:instance, :safe_dm_mentions], false)
response =
conn
@@ -107,7 +105,7 @@ defmodule Pleroma.Web.NodeInfoTest do
setup do: clear_config([:instance, :federating])
test "it shows if federation is enabled/disabled", %{conn: conn} do
- Config.put([:instance, :federating], true)
+ clear_config([:instance, :federating], true)
response =
conn
@@ -116,7 +114,7 @@ defmodule Pleroma.Web.NodeInfoTest do
assert response["metadata"]["federation"]["enabled"] == true
- Config.put([:instance, :federating], false)
+ clear_config([:instance, :federating], false)
response =
conn
@@ -152,37 +150,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
- assert response["metadata"]["federation"]["mrf_simple"] == simple_config
+ test "shows extra information in the quarantined_info field for relevant entries", %{
+ conn: conn
+ } do
+ clear_config([:mrf, :transparency], true)
+
+ 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"]}
+
+ 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"}
+ }
+ }
- 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_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 24d7049f1..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-2020 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 d1920962c..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-2020 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 63b1c0eb8..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-2020 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
@@ -18,7 +18,7 @@ defmodule Pleroma.Web.OAuth.LDAPAuthorizationTest do
@tag @skip
test "authorizes the existing user using LDAP credentials" do
password = "testpassword"
- user = insert(:user, password_hash: Pbkdf2.hash_pwd_salt(password))
+ user = insert(:user, password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password))
app = insert(:oauth_app, scopes: ["read", "write"])
host = Pleroma.Config.get([:ldap, :host]) |> to_charlist
@@ -101,7 +101,7 @@ defmodule Pleroma.Web.OAuth.LDAPAuthorizationTest do
@tag @skip
test "disallow authorization for wrong LDAP credentials" do
password = "testpassword"
- user = insert(:user, password_hash: Pbkdf2.hash_pwd_salt(password))
+ user = insert(:user, password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password))
app = insert(:oauth_app, scopes: ["read", "write"])
host = Pleroma.Config.get([:ldap, :host]) |> to_charlist
diff --git a/test/pleroma/web/o_auth/mfa_controller_test.exs b/test/pleroma/web/o_auth/mfa_controller_test.exs
index bc50d8d18..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-2018 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
@@ -20,7 +20,7 @@ defmodule Pleroma.Web.OAuth.MFAControllerTest do
insert(:user,
multi_factor_authentication_settings: %MFA.Settings{
enabled: true,
- backup_codes: [Pbkdf2.hash_pwd_salt("test-code")],
+ backup_codes: [Pleroma.Password.Pbkdf2.hash_pwd_salt("test-code")],
totp: %MFA.Settings.TOTP{secret: otp_secret, confirmed: true}
}
)
@@ -246,7 +246,7 @@ defmodule Pleroma.Web.OAuth.MFAControllerTest do
hashed_codes =
backup_codes
- |> Enum.map(&Pbkdf2.hash_pwd_salt(&1))
+ |> Enum.map(&Pleroma.Password.Pbkdf2.hash_pwd_salt(&1))
user =
insert(:user,
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 ac22856ea..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-2020 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
@@ -316,7 +316,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
app: app,
conn: conn
} do
- user = insert(:user, password_hash: Pbkdf2.hash_pwd_salt("testpassword"))
+ user = insert(:user, password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("testpassword"))
registration = insert(:registration, user: nil)
redirect_uri = OAuthController.default_redirect_uri(app)
@@ -347,7 +347,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
app: app,
conn: conn
} do
- user = insert(:user, password_hash: Pbkdf2.hash_pwd_salt("testpassword"))
+ user = insert(:user, password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("testpassword"))
registration = insert(:registration, user: nil)
unlisted_redirect_uri = "http://cross-site-request.com"
@@ -790,7 +790,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
test "issues a token for `password` grant_type with valid credentials, with full permissions by default" do
password = "testpassword"
- user = insert(:user, password_hash: Pbkdf2.hash_pwd_salt(password))
+ user = insert(:user, password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password))
app = insert(:oauth_app, scopes: ["read", "write"])
@@ -805,10 +805,12 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"client_secret" => app.client_secret
})
- assert %{"access_token" => token} = json_response(conn, 200)
+ assert %{"id" => id, "access_token" => access_token} = json_response(conn, 200)
- token = Repo.get_by(Token, token: token)
+ token = Repo.get_by(Token, token: access_token)
assert token
+ assert token.id == id
+ assert token.token == access_token
assert token.scopes == app.scopes
end
@@ -818,7 +820,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
user =
insert(:user,
- password_hash: Pbkdf2.hash_pwd_salt(password),
+ password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password),
multi_factor_authentication_settings: %MFA.Settings{
enabled: true,
totp: %MFA.Settings.TOTP{secret: otp_secret, confirmed: true}
@@ -923,12 +925,12 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
end
test "rejects token exchange for valid credentials belonging to unconfirmed user and confirmation is required" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_activation_required], true)
password = "testpassword"
{:ok, user} =
- insert(:user, password_hash: Pbkdf2.hash_pwd_salt(password))
- |> User.confirmation_changeset(need_confirmation: true)
+ insert(:user, password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password))
+ |> User.confirmation_changeset(set_confirmation: false)
|> User.update_and_set_cache()
refute Pleroma.User.account_status(user) == :active
@@ -955,8 +957,8 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
user =
insert(:user,
- password_hash: Pbkdf2.hash_pwd_salt(password),
- deactivated: true
+ password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password),
+ is_active: false
)
app = insert(:oauth_app)
@@ -983,7 +985,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
user =
insert(:user,
- password_hash: Pbkdf2.hash_pwd_salt(password),
+ password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password),
password_reset_pending: true
)
@@ -1007,13 +1009,13 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
end
test "rejects token exchange for user with confirmation_pending set to true" do
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_activation_required], true)
password = "testpassword"
user =
insert(:user,
- password_hash: Pbkdf2.hash_pwd_salt(password),
- confirmation_pending: true
+ password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password),
+ is_confirmed: false
)
app = insert(:oauth_app, scopes: ["read", "write"])
@@ -1038,7 +1040,11 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
test "rejects token exchange for valid credentials belonging to an unapproved user" do
password = "testpassword"
- user = insert(:user, password_hash: Pbkdf2.hash_pwd_salt(password), approval_pending: true)
+ user =
+ insert(:user,
+ password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password),
+ is_approved: false
+ )
refute Pleroma.User.account_status(user) == :active
@@ -1082,7 +1088,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
setup do: clear_config([:oauth2, :issue_new_refresh_token])
test "issues a new access token with keep fresh token" do
- Pleroma.Config.put([:oauth2, :issue_new_refresh_token], true)
+ clear_config([:oauth2, :issue_new_refresh_token], true)
user = insert(:user)
app = insert(:oauth_app, scopes: ["read", "write"])
@@ -1121,7 +1127,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
end
test "issues a new access token with new fresh token" do
- Pleroma.Config.put([:oauth2, :issue_new_refresh_token], false)
+ clear_config([:oauth2, :issue_new_refresh_token], false)
user = insert(:user)
app = insert(:oauth_app, scopes: ["read", "write"])
diff --git a/test/pleroma/web/o_auth/token/utils_test.exs b/test/pleroma/web/o_auth/token/utils_test.exs
index 3444692ec..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-2020 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 866f1c00a..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-2020 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 65b2c22db..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-2020 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
@@ -72,7 +72,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
test "redirects to /notice/id for html format", %{conn: conn} do
note_activity = insert(:note_activity)
- object = Object.normalize(note_activity)
+ object = Object.normalize(note_activity, fetch: false)
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
url = "/objects/#{uuid}"
@@ -82,7 +82,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
test "404s on private objects", %{conn: conn} do
note_activity = insert(:direct_note_activity)
- object = Object.normalize(note_activity)
+ object = Object.normalize(note_activity, fetch: false)
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
conn
@@ -133,7 +133,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
conn: conn
} do
note_activity = insert(:note_activity)
- expected_redirect_url = Object.normalize(note_activity).data["id"]
+ expected_redirect_url = Object.normalize(note_activity, fetch: false).data["id"]
redirect_url =
conn
@@ -144,13 +144,19 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
assert redirect_url == expected_redirect_url
end
- test "returns a 404 on remote notice when json requested", %{conn: conn} do
+ test "redirects to a proper object URL when json requested and the object is remote", %{
+ conn: conn
+ } do
note_activity = insert(:note_activity, local: false)
+ expected_redirect_url = Object.normalize(note_activity, fetch: false).data["id"]
- conn
- |> put_req_header("accept", "application/activity+json")
- |> get("/notice/#{note_activity.id}")
- |> response(404)
+ redirect_url =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/notice/#{note_activity.id}")
+ |> redirected_to()
+
+ assert redirect_url == expected_redirect_url
end
test "500s when actor not found", %{conn: conn} do
@@ -176,7 +182,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|> response(200)
assert resp =~
- "<meta content=\"#{Pleroma.Web.base_url()}/notice/#{note_activity.id}\" property=\"og:url\">"
+ "<meta content=\"#{Pleroma.Web.Endpoint.url()}/notice/#{note_activity.id}\" property=\"og:url\">"
user = insert(:user)
@@ -230,7 +236,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
describe "GET /notice/:id/embed_player" do
setup do
note_activity = insert(:note_activity)
- object = Pleroma.Object.normalize(note_activity)
+ object = Pleroma.Object.normalize(note_activity, fetch: false)
object_data =
Map.put(object.data, "attachment", [
@@ -287,7 +293,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
test "404s when attachment is empty", %{conn: conn} do
note_activity = insert(:note_activity)
- object = Pleroma.Object.normalize(note_activity)
+ object = Pleroma.Object.normalize(note_activity, fetch: false)
object_data = Map.put(object.data, "attachment", [])
object
@@ -301,7 +307,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
test "404s when attachment isn't audio or video", %{conn: conn} do
note_activity = insert(:note_activity)
- object = Pleroma.Object.normalize(note_activity)
+ object = Pleroma.Object.normalize(note_activity, fetch: false)
object_data =
Map.put(object.data, "attachment", [
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 07909d48b..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-2020 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
@@ -17,10 +17,10 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
setup do
{:ok, user} =
insert(:user)
- |> User.confirmation_changeset(need_confirmation: true)
+ |> User.confirmation_changeset(set_confirmation: false)
|> User.update_and_set_cache()
- assert user.confirmation_pending
+ refute user.is_confirmed
[user: user]
end
@@ -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 f1941f6dd..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-2020 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 415c3decd..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-2020 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
@@ -22,7 +22,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
{:ok, create} = CommonAPI.post_chat_message(other_user, user, "sup")
{:ok, _create} = CommonAPI.post_chat_message(other_user, user, "sup part 2")
{:ok, chat} = Chat.get_or_create(user.id, other_user.ap_id)
- object = Object.normalize(create, false)
+ object = Object.normalize(create, fetch: false)
cm_ref = MessageReference.for_chat_and_object(chat, object)
assert cm_ref.unread == true
@@ -52,7 +52,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
{:ok, create} = CommonAPI.post_chat_message(other_user, user, "sup")
{:ok, _create} = CommonAPI.post_chat_message(other_user, user, "sup part 2")
{:ok, chat} = Chat.get_or_create(user.id, other_user.ap_id)
- object = Object.normalize(create, false)
+ object = Object.normalize(create, fetch: false)
cm_ref = MessageReference.for_chat_and_object(chat, object)
assert cm_ref.unread == true
@@ -158,7 +158,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
{:ok, other_message} = CommonAPI.post_chat_message(recipient, user, "nico nico ni")
- object = Object.normalize(message, false)
+ object = Object.normalize(message, fetch: false)
chat = Chat.get(user.id, recipient.ap_id)
@@ -176,7 +176,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
assert %{data: %{"type" => "Tombstone"}} = Object.get_by_id(object.id)
# Deleting other people's messages just removes the reference
- object = Object.normalize(other_message, false)
+ object = Object.normalize(other_message, fetch: false)
cm_ref = MessageReference.for_chat_and_object(chat, object)
result =
@@ -211,12 +211,12 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
assert String.match?(
next,
- ~r(#{api_endpoint}.*/messages\?id=.*&limit=\d+&max_id=.*; rel=\"next\"$)
+ ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*; rel=\"next\"$)
)
assert String.match?(
prev,
- ~r(#{api_endpoint}.*/messages\?id=.*&limit=\d+&min_id=.*; rel=\"prev\"$)
+ ~r(#{api_endpoint}.*/messages\?limit=\d+&min_id=.*; rel=\"prev\"$)
)
assert length(result) == 20
@@ -229,12 +229,12 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
assert String.match?(
next,
- ~r(#{api_endpoint}.*/messages\?id=.*&limit=\d+&max_id=.*; rel=\"next\"$)
+ ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*; rel=\"next\"$)
)
assert String.match?(
prev,
- ~r(#{api_endpoint}.*/messages\?id=.*&limit=\d+&max_id=.*&min_id=.*; rel=\"prev\"$)
+ ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*&min_id=.*; rel=\"prev\"$)
)
assert length(result) == 10
@@ -304,139 +304,165 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
end
end
- describe "GET /api/v1/pleroma/chats" do
- setup do: oauth_access(["read:chats"])
-
- test "it does not return chats with deleted users", %{conn: conn, user: user} do
- recipient = insert(:user)
- {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
-
- Pleroma.Repo.delete(recipient)
- User.invalidate_cache(recipient)
-
- result =
- conn
- |> get("/api/v1/pleroma/chats")
- |> json_response_and_validate_schema(200)
-
- assert length(result) == 0
- end
-
- test "it does not return chats with users you blocked", %{conn: conn, user: user} do
- recipient = insert(:user)
-
- {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
-
- result =
- conn
- |> get("/api/v1/pleroma/chats")
- |> json_response_and_validate_schema(200)
-
- assert length(result) == 1
-
- User.block(user, recipient)
-
- result =
- conn
- |> get("/api/v1/pleroma/chats")
- |> json_response_and_validate_schema(200)
-
- assert length(result) == 0
- end
-
- test "it does not return chats with users you muted", %{conn: conn, user: user} do
- recipient = insert(:user)
-
- {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
-
- result =
- conn
- |> get("/api/v1/pleroma/chats")
- |> json_response_and_validate_schema(200)
-
- assert length(result) == 1
+ for tested_endpoint <- ["/api/v1/pleroma/chats", "/api/v2/pleroma/chats"] do
+ describe "GET #{tested_endpoint}" do
+ setup do: oauth_access(["read:chats"])
- User.mute(user, recipient)
-
- result =
- conn
- |> get("/api/v1/pleroma/chats")
- |> json_response_and_validate_schema(200)
-
- assert length(result) == 0
-
- result =
- conn
- |> get("/api/v1/pleroma/chats?with_muted=true")
- |> json_response_and_validate_schema(200)
-
- assert length(result) == 1
- end
-
- test "it returns all chats", %{conn: conn, user: user} do
- Enum.each(1..30, fn _ ->
+ test "it does not return chats with deleted users", %{conn: conn, user: user} do
recipient = insert(:user)
{:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
- end)
- result =
- conn
- |> get("/api/v1/pleroma/chats")
- |> json_response_and_validate_schema(200)
+ Pleroma.Repo.delete(recipient)
+ User.invalidate_cache(recipient)
- assert length(result) == 30
- end
+ result =
+ conn
+ |> get(unquote(tested_endpoint))
+ |> json_response_and_validate_schema(200)
- test "it return a list of chats the current user is participating in, in descending order of updates",
- %{conn: conn, user: user} do
- har = insert(:user)
- jafnhar = insert(:user)
- tridi = insert(:user)
+ assert length(result) == 0
+ end
- {:ok, chat_1} = Chat.get_or_create(user.id, har.ap_id)
- {:ok, chat_1} = time_travel(chat_1, -3)
- {:ok, chat_2} = Chat.get_or_create(user.id, jafnhar.ap_id)
- {:ok, _chat_2} = time_travel(chat_2, -2)
- {:ok, chat_3} = Chat.get_or_create(user.id, tridi.ap_id)
- {:ok, chat_3} = time_travel(chat_3, -1)
+ test "it does not return chats with users you blocked", %{conn: conn, user: user} do
+ recipient = insert(:user)
- # bump the second one
- {:ok, chat_2} = Chat.bump_or_create(user.id, jafnhar.ap_id)
+ {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
- result =
- conn
- |> get("/api/v1/pleroma/chats")
- |> json_response_and_validate_schema(200)
+ result =
+ conn
+ |> get(unquote(tested_endpoint))
+ |> json_response_and_validate_schema(200)
- ids = Enum.map(result, & &1["id"])
+ assert length(result) == 1
- assert ids == [
- chat_2.id |> to_string(),
- chat_3.id |> to_string(),
- chat_1.id |> to_string()
- ]
- end
+ User.block(user, recipient)
- test "it is not affected by :restrict_unauthenticated setting (issue #1973)", %{
- conn: conn,
- user: user
- } do
- clear_config([:restrict_unauthenticated, :profiles, :local], true)
- clear_config([:restrict_unauthenticated, :profiles, :remote], true)
+ result =
+ conn
+ |> get(unquote(tested_endpoint))
+ |> json_response_and_validate_schema(200)
- user2 = insert(:user)
- user3 = insert(:user, local: false)
+ assert length(result) == 0
+ end
- {:ok, _chat_12} = Chat.get_or_create(user.id, user2.ap_id)
- {:ok, _chat_13} = Chat.get_or_create(user.id, user3.ap_id)
+ test "it does not return chats with users you muted", %{conn: conn, user: user} do
+ recipient = insert(:user)
- result =
- conn
- |> get("/api/v1/pleroma/chats")
- |> json_response_and_validate_schema(200)
+ {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
- account_ids = Enum.map(result, &get_in(&1, ["account", "id"]))
- assert Enum.sort(account_ids) == Enum.sort([user2.id, user3.id])
+ result =
+ conn
+ |> get(unquote(tested_endpoint))
+ |> json_response_and_validate_schema(200)
+
+ assert length(result) == 1
+
+ User.mute(user, recipient)
+
+ result =
+ conn
+ |> get(unquote(tested_endpoint))
+ |> json_response_and_validate_schema(200)
+
+ assert length(result) == 0
+
+ result =
+ conn
+ |> get("#{unquote(tested_endpoint)}?with_muted=true")
+ |> json_response_and_validate_schema(200)
+
+ assert length(result) == 1
+ end
+
+ if tested_endpoint == "/api/v1/pleroma/chats" do
+ test "it returns all chats", %{conn: conn, user: user} do
+ Enum.each(1..30, fn _ ->
+ recipient = insert(:user)
+ {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
+ end)
+
+ result =
+ conn
+ |> get(unquote(tested_endpoint))
+ |> json_response_and_validate_schema(200)
+
+ assert length(result) == 30
+ end
+ else
+ test "it paginates chats", %{conn: conn, user: user} do
+ Enum.each(1..30, fn _ ->
+ recipient = insert(:user)
+ {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
+ end)
+
+ result =
+ conn
+ |> get(unquote(tested_endpoint))
+ |> json_response_and_validate_schema(200)
+
+ assert length(result) == 20
+ last_id = List.last(result)["id"]
+
+ result =
+ conn
+ |> get(unquote(tested_endpoint) <> "?max_id=#{last_id}")
+ |> json_response_and_validate_schema(200)
+
+ assert length(result) == 10
+ end
+ end
+
+ test "it return a list of chats the current user is participating in, in descending order of updates",
+ %{conn: conn, user: user} do
+ har = insert(:user)
+ jafnhar = insert(:user)
+ tridi = insert(:user)
+
+ {:ok, chat_1} = Chat.get_or_create(user.id, har.ap_id)
+ {:ok, chat_1} = time_travel(chat_1, -3)
+ {:ok, chat_2} = Chat.get_or_create(user.id, jafnhar.ap_id)
+ {:ok, _chat_2} = time_travel(chat_2, -2)
+ {:ok, chat_3} = Chat.get_or_create(user.id, tridi.ap_id)
+ {:ok, chat_3} = time_travel(chat_3, -1)
+
+ # bump the second one
+ {:ok, chat_2} = Chat.bump_or_create(user.id, jafnhar.ap_id)
+
+ result =
+ conn
+ |> get(unquote(tested_endpoint))
+ |> json_response_and_validate_schema(200)
+
+ ids = Enum.map(result, & &1["id"])
+
+ assert ids == [
+ chat_2.id |> to_string(),
+ chat_3.id |> to_string(),
+ chat_1.id |> to_string()
+ ]
+ end
+
+ test "it is not affected by :restrict_unauthenticated setting (issue #1973)", %{
+ conn: conn,
+ user: user
+ } do
+ clear_config([:restrict_unauthenticated, :profiles, :local], true)
+ clear_config([:restrict_unauthenticated, :profiles, :remote], true)
+
+ user2 = insert(:user)
+ user3 = insert(:user, local: false)
+
+ {:ok, _chat_12} = Chat.get_or_create(user.id, user2.ap_id)
+ {:ok, _chat_13} = Chat.get_or_create(user.id, user3.ap_id)
+
+ result =
+ conn
+ |> get(unquote(tested_endpoint))
+ |> json_response_and_validate_schema(200)
+
+ account_ids = Enum.map(result, &get_in(&1, ["account", "id"]))
+ assert Enum.sort(account_ids) == Enum.sort([user2.id, user3.id])
+ end
end
end
end
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 c8c2433ae..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-2020 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
@@ -104,7 +104,7 @@ defmodule Pleroma.Web.PleromaAPI.ConversationControllerTest do
[participation] = Participation.for_user(user)
participation = Repo.preload(participation, :recipients)
- assert user in participation.recipients
+ assert refresh_record(user) in participation.recipients
assert other_user in participation.recipients
end
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 6fbdaec7a..200ce3b68 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,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.PleromaAPI.EmojiFileControllerTest do
@@ -13,8 +13,6 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
Pleroma.Config.get!([:instance, :static_dir]),
"emoji"
)
- setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
-
setup do: clear_config([:instance, :public], true)
setup do
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 d9385389b..d1fd1cbb0 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-2020 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
@@ -13,7 +13,6 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
Pleroma.Config.get!([:instance, :static_dir]),
"emoji"
)
- setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
setup do: clear_config([:instance, :public], true)
@@ -31,7 +30,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
end
test "GET /api/pleroma/emoji/packs when :public: false", %{conn: conn} do
- Config.put([:instance, :public], false)
+ clear_config([:instance, :public], false)
conn |> get("/api/pleroma/emoji/packs") |> json_response_and_validate_schema(200)
end
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 bda9c20c6..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-2020 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 13491ed9c..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-2020 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 5f8fa03f6..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-2020 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 03af4d70c..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-2020 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
new file mode 100644
index 000000000..7940564b7
--- /dev/null
+++ b/test/pleroma/web/pleroma_api/controllers/report_controller_test.exs
@@ -0,0 +1,80 @@
+# 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.ReportControllerTest do
+ use Pleroma.Web.ConnCase, async: true
+
+ import Pleroma.Factory
+
+ alias Pleroma.Web.CommonAPI
+
+ describe "GET /api/v0/pleroma/reports" do
+ test "returns list of own reports" do
+ %{conn: reporter_conn, user: reporter} = oauth_access(["read:reports"])
+ %{conn: reported_conn, user: reported} = oauth_access(["read:reports"])
+ activity = insert(:note_activity, user: reported)
+
+ {:ok, %{id: report_id}} =
+ CommonAPI.report(reporter, %{
+ account_id: reported.id,
+ comment: "You stole my sandwich!",
+ status_ids: [activity.id]
+ })
+
+ assert reported_response =
+ reported_conn
+ |> get("/api/v0/pleroma/reports")
+ |> json_response_and_validate_schema(:ok)
+
+ assert reported_response == %{"reports" => [], "total" => 0}
+
+ assert reporter_response =
+ reporter_conn
+ |> get("/api/v0/pleroma/reports")
+ |> json_response_and_validate_schema(:ok)
+
+ assert %{"reports" => [report], "total" => 1} = reporter_response
+ assert report["id"] == report_id
+ refute report["notes"]
+ end
+ end
+
+ describe "GET /api/v0/pleroma/reports/:id" do
+ test "returns report by its id" do
+ %{conn: reporter_conn, user: reporter} = oauth_access(["read:reports"])
+ %{conn: reported_conn, user: reported} = oauth_access(["read:reports"])
+ activity = insert(:note_activity, user: reported)
+
+ {:ok, %{id: report_id}} =
+ CommonAPI.report(reporter, %{
+ account_id: reported.id,
+ comment: "You stole my sandwich!",
+ status_ids: [activity.id]
+ })
+
+ assert reported_conn
+ |> get("/api/v0/pleroma/reports/#{report_id}")
+ |> json_response_and_validate_schema(:not_found)
+
+ assert response =
+ reporter_conn
+ |> get("/api/v0/pleroma/reports/#{report_id}")
+ |> json_response_and_validate_schema(:ok)
+
+ assert response["id"] == report_id
+ refute response["notes"]
+ end
+
+ test "returns 404 when report id is invalid" do
+ %{conn: conn, user: _user} = oauth_access(["read:reports"])
+
+ assert response =
+ conn
+ |> get("/api/v0/pleroma/reports/0")
+ |> json_response_and_validate_schema(:not_found)
+
+ assert response == %{"error" => "Record not found"}
+ end
+ end
+end
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 4ab6d9132..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-2020 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 8d4e0104a..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-2020 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 d83d33912..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-2020 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
@@ -83,7 +83,7 @@ defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
assert %{"error" => "Insufficient permissions: follow | write:follows."} ==
json_response(conn, 403)
else
- assert json_response(conn, 200)
+ assert json_response_and_validate_schema(conn, 200)
end
end
end
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
new file mode 100644
index 000000000..a86688bc4
--- /dev/null
+++ b/test/pleroma/web/pleroma_api/views/backup_view_test.exs
@@ -0,0 +1,18 @@
+# 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.BackupViewTest do
+ use Pleroma.DataCase, async: true
+ alias Pleroma.User.Backup
+ alias Pleroma.Web.PleromaAPI.BackupView
+ import Pleroma.Factory
+
+ test "it renders the ID" do
+ user = insert(:user)
+ backup = Backup.new(user)
+
+ result = BackupView.render("show.json", backup: backup)
+ assert result.id == backup.id
+ end
+end
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 93eef00a2..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-2020 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
@@ -31,7 +31,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageReferenceViewTest do
chat = Chat.get(user.id, recipient.ap_id)
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
cm_ref = MessageReference.for_chat_and_object(chat, object)
@@ -58,7 +58,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageReferenceViewTest do
media_id: upload.id
)
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
cm_ref = MessageReference.for_chat_and_object(chat, object)
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 b60b597e8..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-2020 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
@@ -35,7 +35,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatViewTest do
{:ok, chat_message_creation} = CommonAPI.post_chat_message(user, recipient, "hello")
- chat_message = Object.normalize(chat_message_creation, false)
+ chat_message = Object.normalize(chat_message_creation, fetch: false)
{:ok, chat} = Chat.get_or_create(user.id, recipient.ap_id)
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 113b8f690..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-2020 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 23498badf..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-2020 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
@@ -35,7 +35,7 @@ defmodule Pleroma.Web.Plugs.AdminSecretAuthenticationPlugTest do
end
test "with `admin_token` query parameter", %{conn: conn} do
- Pleroma.Config.put(:admin_token, "password123")
+ clear_config(:admin_token, "password123")
conn =
%{conn | params: %{"admin_token" => "wrong_password"}}
@@ -54,7 +54,7 @@ defmodule Pleroma.Web.Plugs.AdminSecretAuthenticationPlugTest do
end
test "with `x-admin-token` HTTP header", %{conn: conn} do
- Pleroma.Config.put(:admin_token, "☕️")
+ clear_config(:admin_token, "☕️")
conn =
conn
diff --git a/test/pleroma/web/plugs/authentication_plug_test.exs b/test/pleroma/web/plugs/authentication_plug_test.exs
index 3dedd38b2..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-2020 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
@@ -17,7 +17,7 @@ defmodule Pleroma.Web.Plugs.AuthenticationPlugTest do
user = %User{
id: 1,
name: "dude",
- password_hash: Pbkdf2.hash_pwd_salt("guy")
+ password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("guy")
}
conn =
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 2d6af228c..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-2020 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 c775787ca..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-2020 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 0e5fa6f36..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-2020 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
@@ -179,4 +179,22 @@ defmodule Pleroma.Web.Plugs.CacheTest do
|> send_resp(:im_a_teapot, "🥤")
|> sent_resp()
end
+
+ test "ignores if skip_cache is assigned" do
+ assert @miss_resp ==
+ conn(:get, "/")
+ |> assign(:skip_cache, true)
+ |> Cache.call(%{query_params: false, ttl: nil})
+ |> put_resp_content_type("cofe/hot")
+ |> send_resp(:ok, "cofe")
+ |> sent_resp()
+
+ assert @miss_resp ==
+ conn(:get, "/")
+ |> assign(:skip_cache, true)
+ |> Cache.call(%{query_params: false, ttl: nil})
+ |> put_resp_content_type("cofe/hot")
+ |> send_resp(:ok, "cofe")
+ |> sent_resp()
+ end
end
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 92ff19282..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-2020 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_public_or_authenticated_plug_test.exs b/test/pleroma/web/plugs/ensure_public_or_authenticated_plug_test.exs
index 9f15f5c93..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,18 +1,17 @@
# 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.Plugs.EnsurePublicOrAuthenticatedPlugTest do
use Pleroma.Web.ConnCase
- alias Pleroma.Config
alias Pleroma.User
alias Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug
setup do: clear_config([:instance, :public])
test "it halts if not public and no user is assigned", %{conn: conn} do
- Config.put([:instance, :public], false)
+ clear_config([:instance, :public], false)
conn =
conn
@@ -23,7 +22,7 @@ defmodule Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlugTest do
end
test "it continues if public", %{conn: conn} do
- Config.put([:instance, :public], true)
+ clear_config([:instance, :public], true)
ret_conn =
conn
@@ -33,7 +32,7 @@ defmodule Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlugTest do
end
test "it continues if a user is assigned, even if not public", %{conn: conn} do
- Config.put([:instance, :public], false)
+ clear_config([:instance, :public], false)
conn =
conn
diff --git a/test/pleroma/web/plugs/ensure_staff_privileged_plug_test.exs b/test/pleroma/web/plugs/ensure_staff_privileged_plug_test.exs
new file mode 100644
index 000000000..c684714b8
--- /dev/null
+++ b/test/pleroma/web/plugs/ensure_staff_privileged_plug_test.exs
@@ -0,0 +1,60 @@
+# 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.EnsureStaffPrivilegedPlugTest do
+ use Pleroma.Web.ConnCase, async: true
+
+ alias Pleroma.Web.Plugs.EnsureStaffPrivilegedPlug
+ 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 = EnsureStaffPrivilegedPlug.call(conn, %{})
+
+ assert conn == ret_conn
+ end
+
+ test "accepts a user that is a moderator when :privileged_staff is enabled" do
+ clear_config([:instance, :privileged_staff], true)
+ user = insert(:user, is_moderator: true)
+
+ conn = assign(build_conn(), :user, user)
+
+ ret_conn = EnsureStaffPrivilegedPlug.call(conn, %{})
+
+ assert conn == ret_conn
+ end
+
+ test "denies a user that is a moderator when :privileged_staff is disabled" do
+ clear_config([:instance, :privileged_staff], false)
+ user = insert(:user, is_moderator: true)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> EnsureStaffPrivilegedPlug.call(%{})
+
+ assert conn.status == 403
+ end
+
+ test "denies a user that isn't a staff member" do
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> EnsureStaffPrivilegedPlug.call(%{})
+
+ assert conn.status == 403
+ end
+
+ test "denies when a user isn't set" do
+ conn = EnsureStaffPrivilegedPlug.call(build_conn(), %{})
+
+ assert conn.status == 403
+ end
+end
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 9592820c7..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-2020 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 a4652f6c5..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-2020 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
@@ -8,7 +8,7 @@ defmodule Pleroma.Web.Plugs.FederatingPlugTest do
setup do: clear_config([:instance, :federating])
test "returns and halt the conn when federating is disabled" do
- Pleroma.Config.put([:instance, :federating], false)
+ clear_config([:instance, :federating], false)
conn =
build_conn()
@@ -19,7 +19,7 @@ defmodule Pleroma.Web.Plugs.FederatingPlugTest do
end
test "does nothing when federating is enabled" do
- Pleroma.Config.put([:instance, :federating], true)
+ clear_config([:instance, :federating], true)
conn =
build_conn()
diff --git a/test/pleroma/web/plugs/frontend_static_plug_test.exs b/test/pleroma/web/plugs/frontend_static_plug_test.exs
index 8b7b022fc..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-2020 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
@@ -74,4 +74,35 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
assert %Plug.Conn{status: :success} = get(conn, url)
end
end
+
+ test "api routes are detected correctly" do
+ # If this test fails we have probably added something
+ # new that should be in /api/ instead
+ expected_routes = [
+ "api",
+ "main",
+ "ostatus_subscribe",
+ "oauth",
+ "objects",
+ "activities",
+ "notice",
+ "users",
+ "tags",
+ "mailer",
+ "inbox",
+ "relay",
+ "internal",
+ ".well-known",
+ "nodeinfo",
+ "manifest.json",
+ "auth",
+ "proxy",
+ "phoenix",
+ "test",
+ "user_exists",
+ "check_password"
+ ]
+
+ assert expected_routes == Pleroma.Web.Router.get_api_routes()
+ end
end
diff --git a/test/pleroma/web/plugs/http_security_plug_test.exs b/test/pleroma/web/plugs/http_security_plug_test.exs
index df2b5ebb3..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-2020 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
@@ -72,6 +72,21 @@ defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do
assert csp =~ "media-src 'self' https:;"
assert csp =~ "img-src 'self' data: blob: https:;"
end
+
+ test "it sets the Service-Worker-Allowed header", %{conn: conn} do
+ clear_config([:http_security, :enabled], true)
+ clear_config([:frontends, :primary], %{"name" => "fedi-fe", "ref" => "develop"})
+
+ clear_config([:frontends, :available], %{
+ "fedi-fe" => %{
+ "name" => "fedi-fe",
+ "custom-http-headers" => [{"service-worker-allowed", "/"}]
+ }
+ })
+
+ conn = get(conn, "/api/v1/instance")
+ assert Conn.get_resp_header(conn, "service-worker-allowed") == ["/"]
+ end
end
describe "img-src and media-src" do
diff --git a/test/pleroma/web/plugs/http_signature_plug_test.exs b/test/pleroma/web/plugs/http_signature_plug_test.exs
index e6cbde803..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-2020 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
@@ -32,11 +32,7 @@ defmodule Pleroma.Web.Plugs.HTTPSignaturePlugTest do
describe "requires a signature when `authorized_fetch_mode` is enabled" do
setup do
- Pleroma.Config.put([:activitypub, :authorized_fetch_mode], true)
-
- on_exit(fn ->
- Pleroma.Config.put([:activitypub, :authorized_fetch_mode], false)
- end)
+ clear_config([:activitypub, :authorized_fetch_mode], true)
params = %{"actor" => "http://mastodon.example.org/users/admin"}
conn = build_conn(:get, "/doesntmattter", params) |> put_format("activity+json")
diff --git a/test/pleroma/web/plugs/idempotency_plug_test.exs b/test/pleroma/web/plugs/idempotency_plug_test.exs
index ed8b3fc1a..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-2020 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 5b30011d3..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-2020 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 0ad3c2929..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-2020 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 1186cdb14..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-2020 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 982a70bf9..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-2020 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
@@ -169,42 +169,4 @@ defmodule Pleroma.Web.Plugs.OAuthScopesPlugTest do
assert f.(["admin:read"], ["write", "admin"]) == ["admin:read"]
end
end
-
- describe "transform_scopes/2" do
- setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage])
-
- setup do
- {:ok, %{f: &OAuthScopesPlug.transform_scopes/2}}
- end
-
- test "with :admin option, prefixes all requested scopes with `admin:` " <>
- "and [optionally] keeps only prefixed scopes, " <>
- "depending on `[:auth, :enforce_oauth_admin_scope_usage]` setting",
- %{f: f} do
- Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], false)
-
- assert f.(["read"], %{admin: true}) == ["admin:read", "read"]
-
- assert f.(["read", "write"], %{admin: true}) == [
- "admin:read",
- "read",
- "admin:write",
- "write"
- ]
-
- Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], true)
-
- assert f.(["read:accounts"], %{admin: true}) == ["admin:read:accounts"]
-
- assert f.(["read", "write:reports"], %{admin: true}) == [
- "admin:read",
- "admin:write:reports"
- ]
- end
-
- test "with no supported options, returns unmodified scopes", %{f: f} do
- assert f.(["read"], %{}) == ["read"]
- assert f.(["read", "write"], %{}) == ["read", "write"]
- end
- end
end
diff --git a/test/pleroma/web/plugs/plug_helper_test.exs b/test/pleroma/web/plugs/plug_helper_test.exs
index 670d699f0..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-2020 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 249c78b37..19cee8aee 100644
--- a/test/pleroma/web/plugs/rate_limiter_test.exs
+++ b/test/pleroma/web/plugs/rate_limiter_test.exs
@@ -1,12 +1,11 @@
# 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.Plugs.RateLimiterTest do
use Pleroma.Web.ConnCase
alias Phoenix.ConnTest
- alias Pleroma.Config
alias Pleroma.Web.Plugs.RateLimiter
alias Plug.Conn
@@ -22,8 +21,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
setup do: clear_config([Pleroma.Web.Plugs.RemoteIp, :enabled])
test "config is required for plug to work" do
- Config.put([:rate_limit, @limiter_name], {1, 1})
- Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([:rate_limit, @limiter_name], {1, 1})
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
assert %{limits: {1, 1}, name: :test_init, opts: [name: :test_init]} ==
[name: @limiter_name]
@@ -54,40 +53,45 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
scale = 80
limit = 5
- Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
- Config.put([:rate_limit, limiter_name], {scale, limit})
+ 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
test "`bucket_name` option overrides default bucket name" do
limiter_name = :test_bucket_name
- Config.put([:rate_limit, limiter_name], {1000, 5})
- Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([:rate_limit, limiter_name], {1000, 5})
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
base_bucket_name = "#{limiter_name}:group1"
plug_opts = RateLimiter.init(name: limiter_name, bucket_name: base_bucket_name)
@@ -101,8 +105,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
test "`params` option allows different queries to be tracked independently" do
limiter_name = :test_params
- Config.put([:rate_limit, limiter_name], {1000, 5})
- Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([:rate_limit, limiter_name], {1000, 5})
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
plug_opts = RateLimiter.init(name: limiter_name, params: ["id"])
@@ -117,8 +121,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
test "it supports combination of options modifying bucket name" do
limiter_name = :test_options_combo
- Config.put([:rate_limit, limiter_name], {1000, 5})
- Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([:rate_limit, limiter_name], {1000, 5})
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
base_bucket_name = "#{limiter_name}:group1"
@@ -138,10 +142,11 @@ 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
- Config.put([:rate_limit, limiter_name], [{1000, 5}, {1, 10}])
- Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([:rate_limit, limiter_name], [{1000, 5}, {1, 10}])
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
plug_opts = RateLimiter.init(name: limiter_name)
@@ -175,13 +180,14 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
:ok
end
+ @tag :erratic
test "can have limits separate from unauthenticated connections" do
limiter_name = :test_authenticated1
scale = 50
limit = 5
- Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
- Config.put([:rate_limit, limiter_name], [{1000, 1}, {scale, limit}])
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([:rate_limit, limiter_name], [{1000, 1}, {scale, limit}])
plug_opts = RateLimiter.init(name: limiter_name)
@@ -200,10 +206,11 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
assert conn.halted
end
+ @tag :erratic
test "different users are counted independently" do
limiter_name = :test_authenticated2
- Config.put([:rate_limit, limiter_name], [{1, 10}, {1000, 5}])
- Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([:rate_limit, limiter_name], [{1, 10}, {1000, 5}])
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
plug_opts = RateLimiter.init(name: limiter_name)
@@ -232,8 +239,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
test "doesn't crash due to a race condition when multiple requests are made at the same time and the bucket is not yet initialized" do
limiter_name = :test_race_condition
- Pleroma.Config.put([:rate_limit, limiter_name], {1000, 5})
- Pleroma.Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+ clear_config([:rate_limit, limiter_name], {1000, 5})
+ clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
opts = RateLimiter.init(name: limiter_name)
@@ -260,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 0bdb4c168..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-2020 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
@@ -26,7 +26,7 @@ defmodule Pleroma.Web.Plugs.RemoteIpTest do
)
test "disabled" do
- Pleroma.Config.put(RemoteIp, enabled: false)
+ clear_config(RemoteIp, enabled: false)
%{remote_ip: remote_ip} = conn(:get, "/")
@@ -48,7 +48,7 @@ defmodule Pleroma.Web.Plugs.RemoteIpTest do
end
test "custom headers" do
- Pleroma.Config.put(RemoteIp, enabled: true, headers: ["cf-connecting-ip"])
+ clear_config(RemoteIp, enabled: true, headers: ["cf-connecting-ip"])
conn =
conn(:get, "/")
@@ -73,7 +73,7 @@ defmodule Pleroma.Web.Plugs.RemoteIpTest do
refute conn.remote_ip == {1, 1, 1, 1}
- Pleroma.Config.put([RemoteIp, :proxies], ["173.245.48.0/20"])
+ clear_config([RemoteIp, :proxies], ["173.245.48.0/20"])
conn =
conn(:get, "/")
@@ -84,7 +84,7 @@ defmodule Pleroma.Web.Plugs.RemoteIpTest do
end
test "proxies set without CIDR format" do
- Pleroma.Config.put([RemoteIp, :proxies], ["173.245.48.1"])
+ clear_config([RemoteIp, :proxies], ["173.245.48.1"])
conn =
conn(:get, "/")
@@ -95,8 +95,8 @@ defmodule Pleroma.Web.Plugs.RemoteIpTest do
end
test "proxies set `nonsensical` CIDR" do
- Pleroma.Config.put([RemoteIp, :reserved], ["127.0.0.0/8"])
- Pleroma.Config.put([RemoteIp, :proxies], ["10.0.0.3/24"])
+ clear_config([RemoteIp, :reserved], ["127.0.0.0/8"])
+ clear_config([RemoteIp, :proxies], ["10.0.0.3/24"])
conn =
conn(:get, "/")
diff --git a/test/pleroma/web/plugs/set_format_plug_test.exs b/test/pleroma/web/plugs/set_format_plug_test.exs
index e95d751fa..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-2020 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 773f48a5b..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-2020 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 21417d0e7..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-2020 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 bae9208ec..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-2020 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 e9c9e5f3e..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-2020 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
@@ -20,9 +20,9 @@ defmodule Pleroma.Web.Plugs.UserEnabledPlugTest do
test "with a user that's not confirmed and a config requiring confirmation, it removes that user",
%{conn: conn} do
- Pleroma.Config.put([:instance, :account_activation_required], true)
+ clear_config([:instance, :account_activation_required], true)
- user = insert(:user, confirmation_pending: true)
+ user = insert(:user, is_confirmed: false)
conn =
conn
@@ -33,7 +33,7 @@ defmodule Pleroma.Web.Plugs.UserEnabledPlugTest do
end
test "with a user that is deactivated, it removes that user", %{conn: conn} do
- user = insert(:user, deactivated: true)
+ user = insert(:user, is_active: false)
conn =
conn
diff --git a/test/pleroma/web/plugs/user_fetcher_plug_test.exs b/test/pleroma/web/plugs/user_fetcher_plug_test.exs
index b4f875d2d..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-2020 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 b550568c1..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-2020 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
new file mode 100644
index 000000000..742f04fea
--- /dev/null
+++ b/test/pleroma/web/plugs/user_tracking_plug_test.exs
@@ -0,0 +1,58 @@
+# 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.UserTrackingPlugTest do
+ use Pleroma.Web.ConnCase, async: true
+
+ import Pleroma.Factory
+
+ alias Pleroma.Web.Plugs.UserTrackingPlug
+
+ test "updates last_active_at for a new user", %{conn: conn} do
+ user = insert(:user)
+
+ assert is_nil(user.last_active_at)
+
+ test_started_at = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
+
+ %{assigns: %{user: user}} =
+ conn
+ |> assign(:user, user)
+ |> UserTrackingPlug.call(%{})
+
+ assert user.last_active_at >= test_started_at
+ assert user.last_active_at <= NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
+ end
+
+ test "doesn't update last_active_at if it was updated recently", %{conn: conn} do
+ last_active_at =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.add(-:timer.hours(1), :millisecond)
+ |> NaiveDateTime.truncate(:second)
+
+ user = insert(:user, %{last_active_at: last_active_at})
+
+ %{assigns: %{user: user}} =
+ conn
+ |> assign(:user, user)
+ |> UserTrackingPlug.call(%{})
+
+ assert user.last_active_at == last_active_at
+ end
+
+ test "skips updating last_active_at if user ID is nil", %{conn: conn} do
+ %{assigns: %{user: user}} =
+ conn
+ |> assign(:user, %Pleroma.User{})
+ |> UserTrackingPlug.call(%{})
+
+ assert is_nil(user.last_active_at)
+ end
+
+ test "does nothing if user is not present", %{conn: conn} do
+ %{assigns: assigns} = UserTrackingPlug.call(conn, %{})
+
+ refute Map.has_key?(assigns, :user)
+ end
+end
diff --git a/test/pleroma/web/preload/providers/instance_test.exs b/test/pleroma/web/preload/providers/instance_test.exs
index 6033899b0..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-2020 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 3b1f2f1aa..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-2020 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 6be03af79..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-2020 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 326a67963..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-2020 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
@@ -118,7 +118,7 @@ defmodule Pleroma.Web.Push.ImplTest do
"<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert Impl.format_body(
%{
@@ -137,7 +137,7 @@ defmodule Pleroma.Web.Push.ImplTest do
user = insert(:user, nickname: "Bob")
other_user = insert(:user)
{:ok, _, _, activity} = CommonAPI.follow(user, other_user)
- object = Object.normalize(activity, false)
+ object = Object.normalize(activity, fetch: false)
assert Impl.format_body(%{activity: activity, type: "follow"}, user, object) ==
"@Bob has followed you"
@@ -156,7 +156,7 @@ defmodule Pleroma.Web.Push.ImplTest do
})
{:ok, announce_activity} = CommonAPI.repeat(activity.id, user)
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert Impl.format_body(%{activity: announce_activity}, user, object) ==
"@#{user.nickname} repeated: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
@@ -175,7 +175,7 @@ defmodule Pleroma.Web.Push.ImplTest do
})
{:ok, activity} = CommonAPI.favorite(user, activity.id)
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert Impl.format_body(%{activity: activity, type: "favourite"}, user, object) ==
"@Bob has favorited your post"
@@ -193,7 +193,7 @@ defmodule Pleroma.Web.Push.ImplTest do
})
{:ok, activity} = CommonAPI.react_with_emoji(activity.id, user, "👍")
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert Impl.format_body(%{activity: activity, type: "pleroma:emoji_reaction"}, user, object) ==
"@Bob reacted with 👍"
@@ -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")
@@ -221,7 +236,7 @@ defmodule Pleroma.Web.Push.ImplTest do
recipient = insert(:user)
{:ok, chat} = CommonAPI.post_chat_message(user, recipient, "hey")
- object = Object.normalize(chat, false)
+ object = Object.normalize(chat, fetch: false)
[notification] = Notification.for_user(recipient)
res = Impl.build_content(notification, user, object)
@@ -245,7 +260,7 @@ defmodule Pleroma.Web.Push.ImplTest do
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
{:ok, chat} = CommonAPI.post_chat_message(user, recipient, nil, media_id: upload.id)
- object = Object.normalize(chat, false)
+ object = Object.normalize(chat, fetch: false)
[notification] = Notification.for_user(recipient)
res = Impl.build_content(notification, user, object)
@@ -271,7 +286,7 @@ defmodule Pleroma.Web.Push.ImplTest do
notif = insert(:notification, user: user2, activity: activity)
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert Impl.build_content(notif, actor, object) == %{
body: "New Direct Message"
@@ -286,7 +301,7 @@ defmodule Pleroma.Web.Push.ImplTest do
notif = insert(:notification, user: user2, activity: activity, type: "mention")
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert Impl.build_content(notif, actor, object) == %{
body: "New Mention"
@@ -297,7 +312,7 @@ defmodule Pleroma.Web.Push.ImplTest do
notif = insert(:notification, user: user2, activity: activity, type: "favourite")
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert Impl.build_content(notif, actor, object) == %{
body: "New Favorite"
@@ -320,7 +335,7 @@ defmodule Pleroma.Web.Push.ImplTest do
notif = insert(:notification, user: user2, activity: activity)
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert Impl.build_content(notif, actor, object) == %{
body:
@@ -338,7 +353,7 @@ defmodule Pleroma.Web.Push.ImplTest do
notif = insert(:notification, user: user2, activity: activity, type: "mention")
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert Impl.build_content(notif, actor, object) == %{
body:
@@ -351,7 +366,7 @@ defmodule Pleroma.Web.Push.ImplTest do
notif = insert(:notification, user: user2, activity: activity, type: "favourite")
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert Impl.build_content(notif, actor, object) == %{
body: "@Bob has favorited your post",
diff --git a/test/pleroma/web/rel_me_test.exs b/test/pleroma/web/rel_me_test.exs
index 811cb0893..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-2020 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 4c9ee77d0..630b3ca95 100644
--- a/test/pleroma/web/rich_media/helpers_test.exs
+++ b/test/pleroma/web/rich_media/helpers_test.exs
@@ -1,11 +1,10 @@
# 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.RichMedia.HelpersTest do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.RichMedia.Helpers
@@ -29,7 +28,7 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
content_type: "text/markdown"
})
- Config.put([:rich_media, :enabled], true)
+ clear_config([:rich_media, :enabled], true)
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
end
@@ -43,7 +42,7 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
content_type: "text/markdown"
})
- Config.put([:rich_media, :enabled], true)
+ clear_config([:rich_media, :enabled], true)
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
end
@@ -57,7 +56,7 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
content_type: "text/markdown"
})
- Config.put([:rich_media, :enabled], true)
+ clear_config([:rich_media, :enabled], true)
assert %{page_url: "https://example.com/ogp", rich_media: _} =
Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
@@ -74,7 +73,7 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
{:ok, activity4} = CommonAPI.post(user, %{status: "https://192.168.10.40/notice/9kCP7V"})
{:ok, activity5} = CommonAPI.post(user, %{status: "https://pleroma.local/notice/9kCP7V"})
- Config.put([:rich_media, :enabled], true)
+ clear_config([:rich_media, :enabled], true)
assert %{} = Helpers.fetch_data_for_activity(activity)
assert %{} = Helpers.fetch_data_for_activity(activity2)
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 242521138..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-2020 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 6d00c2af5..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-2020 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
@@ -133,13 +133,13 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
assert Parser.parse("http://example.com/oembed") ==
{:ok,
%{
- "author_name" => "‮‭‬bees‬",
+ "author_name" => "\u202E\u202D\u202Cbees\u202C",
"author_url" => "https://www.flickr.com/photos/bees/",
"cache_age" => 3600,
"flickr_type" => "photo",
"height" => "768",
"html" =>
- "<a data-flickr-embed=\"true\" href=\"https://www.flickr.com/photos/bees/2362225867/\" title=\"Bacon Lollys by ‮‭‬bees‬, on Flickr\"><img src=\"https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_b.jpg\" width=\"1024\" height=\"768\" alt=\"Bacon Lollys\"></a><script async src=\"https://embedr.flickr.com/assets/client-code.js\" charset=\"utf-8\"></script>",
+ "<a data-flickr-embed=\"true\" href=\"https://www.flickr.com/photos/bees/2362225867/\" title=\"Bacon Lollys by \u202E\u202D\u202Cbees\u202C, on Flickr\"><img src=\"https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_b.jpg\" width=\"1024\" height=\"768\" alt=\"Bacon Lollys\"></a><script async src=\"https://embedr.flickr.com/assets/client-code.js\" charset=\"utf-8\"></script>",
"license" => "All Rights Reserved",
"license_id" => 0,
"provider_name" => "Flickr",
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 219f005a2..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-2020 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/chat_channel_test.exs b/test/pleroma/web/shout_channel_test.exs
index 32170873d..e1de80593 100644
--- a/test/pleroma/web/chat_channel_test.exs
+++ b/test/pleroma/web/shout_channel_test.exs
@@ -1,10 +1,10 @@
# 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.ChatChannelTest do
+defmodule Pleroma.Web.ShoutChannelTest do
use Pleroma.Web.ChannelCase
- alias Pleroma.Web.ChatChannel
+ alias Pleroma.Web.ShoutChannel
alias Pleroma.Web.UserSocket
import Pleroma.Factory
@@ -14,7 +14,7 @@ defmodule Pleroma.Web.ChatChannelTest do
{:ok, _, socket} =
socket(UserSocket, "", %{user_name: user.nickname})
- |> subscribe_and_join(ChatChannel, "chat:public")
+ |> subscribe_and_join(ShoutChannel, "chat:public")
{:ok, socket: socket}
end
@@ -25,7 +25,7 @@ defmodule Pleroma.Web.ChatChannelTest do
end
describe "message lengths" do
- setup do: clear_config([:instance, :chat_limit])
+ setup do: clear_config([:shout, :limit])
test "it ignores messages of length zero", %{socket: socket} do
push(socket, "new_msg", %{"text" => ""})
@@ -33,7 +33,7 @@ defmodule Pleroma.Web.ChatChannelTest do
end
test "it ignores messages above a certain length", %{socket: socket} do
- Pleroma.Config.put([:instance, :chat_limit], 2)
+ clear_config([:shout, :limit], 2)
push(socket, "new_msg", %{"text" => "123"})
refute_broadcast("new_msg", %{text: "123"})
end
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 19506f1d8..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-2020 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
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
alias Pleroma.Activity
alias Pleroma.Web.ActivityPub.Transmogrifier
+ alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
@@ -185,16 +186,16 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
test "302 for remote cached status", %{conn: conn, user: user} do
message = %{
"@context" => "https://www.w3.org/ns/activitystreams",
- "to" => user.follower_address,
- "cc" => "https://www.w3.org/ns/activitystreams#Public",
"type" => "Create",
+ "actor" => user.ap_id,
"object" => %{
+ "to" => user.follower_address,
+ "cc" => "https://www.w3.org/ns/activitystreams#Public",
+ "id" => Utils.generate_object_id(),
"content" => "blah blah blah",
"type" => "Note",
- "attributedTo" => user.ap_id,
- "inReplyTo" => nil
- },
- "actor" => user.ap_id
+ "attributedTo" => user.ap_id
+ }
}
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
diff --git a/test/pleroma/web/streamer_test.exs b/test/pleroma/web/streamer_test.exs
index ad66ddc9d..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-2020 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
@@ -266,7 +266,7 @@ defmodule Pleroma.Web.StreamerTest do
{:ok, create_activity} =
CommonAPI.post_chat_message(other_user, user, "hey cirno", idempotency_key: "123")
- object = Object.normalize(create_activity, false)
+ object = Object.normalize(create_activity, fetch: false)
chat = Chat.get(user.id, other_user.ap_id)
cm_ref = MessageReference.for_chat_and_object(chat, object)
cm_ref = %{cm_ref | chat: chat, object: object}
@@ -284,7 +284,7 @@ defmodule Pleroma.Web.StreamerTest do
other_user = insert(:user)
{:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey cirno")
- object = Object.normalize(create_activity, false)
+ object = Object.normalize(create_activity, fetch: false)
chat = Chat.get(user.id, other_user.ap_id)
cm_ref = MessageReference.for_chat_and_object(chat, object)
cm_ref = %{cm_ref | chat: chat, object: object}
@@ -383,19 +383,8 @@ defmodule Pleroma.Web.StreamerTest do
user: user,
token: oauth_token
} do
- user_url = user.ap_id
user2 = insert(:user)
- body =
- File.read!("test/fixtures/users_mock/localhost.json")
- |> String.replace("{{nickname}}", user.nickname)
- |> Jason.encode!()
-
- Tesla.Mock.mock_global(fn
- %{method: :get, url: ^user_url} ->
- %Tesla.Env{status: 200, body: body}
- end)
-
Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
{:ok, _follower, _followed, follow_activity} = CommonAPI.follow(user2, user)
@@ -409,20 +398,9 @@ defmodule Pleroma.Web.StreamerTest do
token: oauth_token
} do
user_id = user.id
- user_url = user.ap_id
other_user = insert(:user)
other_user_id = other_user.id
- body =
- File.read!("test/fixtures/users_mock/localhost.json")
- |> String.replace("{{nickname}}", user.nickname)
- |> Jason.encode!()
-
- Tesla.Mock.mock_global(fn
- %{method: :get, url: ^user_url} ->
- %Tesla.Env{status: 200, body: body}
- end)
-
Streamer.get_topic_and_add_socket("user", user, oauth_token)
{:ok, _follower, _followed, _follow_activity} = CommonAPI.follow(user, other_user)
@@ -464,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
@@ -506,11 +509,59 @@ 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
test "it filters to user if recipients invalid and thread containment is enabled" do
- Pleroma.Config.put([:instance, :skip_thread_containment], false)
+ clear_config([:instance, :skip_thread_containment], false)
author = insert(:user)
%{user: user, token: oauth_token} = oauth_access(["read"])
User.follow(user, author, :follow_accept)
@@ -531,7 +582,7 @@ defmodule Pleroma.Web.StreamerTest do
end
test "it sends message if recipients invalid and thread containment is disabled" do
- Pleroma.Config.put([:instance, :skip_thread_containment], true)
+ clear_config([:instance, :skip_thread_containment], true)
author = insert(:user)
%{user: user, token: oauth_token} = oauth_access(["read"])
User.follow(user, author, :follow_accept)
@@ -553,7 +604,7 @@ defmodule Pleroma.Web.StreamerTest do
end
test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do
- Pleroma.Config.put([:instance, :skip_thread_containment], false)
+ clear_config([:instance, :skip_thread_containment], false)
author = insert(:user)
user = insert(:user, skip_thread_containment: true)
%{token: oauth_token} = oauth_access(["read"], user: user)
@@ -794,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
@@ -835,4 +887,105 @@ defmodule Pleroma.Web.StreamerTest do
assert last_status["id"] == to_string(create_activity.id)
end
end
+
+ describe "stop streaming if token got revoked" do
+ setup do
+ child_proc = fn start, finalize ->
+ fn ->
+ start.()
+
+ receive do
+ {StreamerTest, :ready} ->
+ assert_receive {:render_with_user, _, "update.json", _}
+
+ receive do
+ {StreamerTest, :revoked} -> finalize.()
+ end
+ end
+ end
+ end
+
+ starter = fn user, token ->
+ fn -> Streamer.get_topic_and_add_socket("user", user, token) end
+ end
+
+ hit = fn -> assert_receive :close end
+ miss = fn -> refute_receive :close end
+
+ send_all = fn tasks, thing -> Enum.each(tasks, &send(&1.pid, thing)) end
+
+ %{
+ child_proc: child_proc,
+ starter: starter,
+ hit: hit,
+ miss: miss,
+ send_all: send_all
+ }
+ end
+
+ test "do not revoke other tokens", %{
+ child_proc: child_proc,
+ starter: starter,
+ hit: hit,
+ miss: miss,
+ send_all: send_all
+ } do
+ %{user: user, token: token} = oauth_access(["read"])
+ %{token: token2} = oauth_access(["read"], user: user)
+ %{user: user2, token: user2_token} = oauth_access(["read"])
+
+ post_user = insert(:user)
+ CommonAPI.follow(user, post_user)
+ CommonAPI.follow(user2, post_user)
+
+ tasks = [
+ Task.async(child_proc.(starter.(user, token), hit)),
+ Task.async(child_proc.(starter.(user, token2), miss)),
+ Task.async(child_proc.(starter.(user2, user2_token), miss))
+ ]
+
+ {:ok, _} =
+ CommonAPI.post(post_user, %{
+ status: "hi"
+ })
+
+ send_all.(tasks, {StreamerTest, :ready})
+
+ Pleroma.Web.OAuth.Token.Strategy.Revoke.revoke(token)
+
+ send_all.(tasks, {StreamerTest, :revoked})
+
+ Enum.each(tasks, &Task.await/1)
+ end
+
+ test "revoke all streams for this token", %{
+ child_proc: child_proc,
+ starter: starter,
+ hit: hit,
+ send_all: send_all
+ } do
+ %{user: user, token: token} = oauth_access(["read"])
+
+ post_user = insert(:user)
+ CommonAPI.follow(user, post_user)
+
+ tasks = [
+ Task.async(child_proc.(starter.(user, token), hit)),
+ Task.async(child_proc.(starter.(user, token), hit))
+ ]
+
+ {:ok, _} =
+ CommonAPI.post(post_user, %{
+ status: "hi"
+ })
+
+ send_all.(tasks, {StreamerTest, :ready})
+
+ Pleroma.Web.OAuth.Token.Strategy.Revoke.revoke(token)
+
+ send_all.(tasks, {StreamerTest, :revoked})
+
+ Enum.each(tasks, &Task.await/1)
+ end
+ end
end
diff --git a/test/pleroma/web/twitter_api/controller_test.exs b/test/pleroma/web/twitter_api/controller_test.exs
index b3ca67637..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-2020 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
@@ -7,67 +7,18 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
alias Pleroma.Repo
alias Pleroma.User
- alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OAuth.Token
import Pleroma.Factory
- describe "POST /api/qvitter/statuses/notifications/read" do
- test "without valid credentials", %{conn: conn} do
- conn = post(conn, "/api/qvitter/statuses/notifications/read", %{"latest_id" => 1_234_567})
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials, without any params" do
- %{conn: conn} = oauth_access(["write:notifications"])
-
- conn = post(conn, "/api/qvitter/statuses/notifications/read")
-
- assert json_response(conn, 400) == %{
- "error" => "You need to specify latest_id",
- "request" => "/api/qvitter/statuses/notifications/read"
- }
- end
-
- test "with credentials, with params" do
- %{user: current_user, conn: conn} =
- oauth_access(["read:notifications", "write:notifications"])
-
- other_user = insert(:user)
-
- {:ok, _activity} =
- CommonAPI.post(other_user, %{
- status: "Hey @#{current_user.nickname}"
- })
-
- response_conn =
- conn
- |> get("/api/v1/notifications")
-
- [notification] = json_response(response_conn, 200)
-
- assert notification["pleroma"]["is_seen"] == false
-
- response_conn =
- conn
- |> post("/api/qvitter/statuses/notifications/read", %{"latest_id" => notification["id"]})
-
- [notification] = response = json_response(response_conn, 200)
-
- assert length(response) == 1
-
- assert notification["pleroma"]["is_seen"] == true
- end
- end
-
describe "GET /api/account/confirm_email/:id/:token" do
setup do
{:ok, user} =
insert(:user)
- |> User.confirmation_changeset(need_confirmation: true)
+ |> User.confirmation_changeset(set_confirmation: false)
|> Repo.update()
- assert user.confirmation_pending
+ refute user.is_confirmed
[user: user]
end
@@ -83,7 +34,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
user = User.get_cached_by_id(user.id)
- refute user.confirmation_pending
+ assert user.is_confirmed
refute user.confirmation_token
end
diff --git a/test/pleroma/web/twitter_api/password_controller_test.exs b/test/pleroma/web/twitter_api/password_controller_test.exs
index c1f5bc5c7..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-2020 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
@@ -92,7 +96,7 @@ defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
assert response =~ "<h2>Password changed!</h2>"
user = refresh_record(user)
- assert Pbkdf2.verify_pass("test", user.password_hash)
+ assert Pleroma.Password.Pbkdf2.verify_pass("test", user.password_hash)
assert Enum.empty?(Token.get_user_tokens(user))
end
@@ -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 dfe5b02be..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-2020 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
@@ -27,6 +27,16 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
body: File.read!("test/fixtures/tesla_mock/status.emelie.json")
}
+ %{method: :get, url: "https://mastodon.social/users/emelie/collections/featured"} ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/activity+json"}],
+ body:
+ File.read!("test/fixtures/users_mock/masto_featured.json")
+ |> String.replace("{{domain}}", "mastodon.social")
+ |> String.replace("{{nickname}}", "emelie")
+ }
+
%{method: :get, url: "https://mastodon.social/users/emelie"} ->
%Tesla.Env{
status: 200,
@@ -52,6 +62,16 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
headers: [{"content-type", "application/activity+json"}],
body: File.read!("test/fixtures/tesla_mock/emelie.json")
}
+
+ %{method: :get, url: "https://mastodon.social/users/emelie/collections/featured"} ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/activity+json"}],
+ body:
+ File.read!("test/fixtures/users_mock/masto_featured.json")
+ |> String.replace("{{domain}}", "mastodon.social")
+ |> String.replace("{{nickname}}", "emelie")
+ }
end)
response =
@@ -70,6 +90,16 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
headers: [{"content-type", "application/activity+json"}],
body: File.read!("test/fixtures/tesla_mock/emelie.json")
}
+
+ %{method: :get, url: "https://mastodon.social/users/emelie/collections/featured"} ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/activity+json"}],
+ body:
+ File.read!("test/fixtures/users_mock/masto_featured.json")
+ |> String.replace("{{domain}}", "mastodon.social")
+ |> String.replace("{{nickname}}", "emelie")
+ }
end)
user = insert(:user)
@@ -141,7 +171,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
end
test "returns error when user is deactivated", %{conn: conn} do
- user = insert(:user, deactivated: true)
+ user = insert(:user, is_active: false)
user2 = insert(:user)
response =
@@ -154,7 +184,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
end
test "returns error when user is blocked", %{conn: conn} do
- Pleroma.Config.put([:user, :deny_follow_blocked], true)
+ clear_config([:user, :deny_follow_blocked], true)
user = insert(:user)
user2 = insert(:user)
@@ -365,7 +395,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
end
test "returns error when user is blocked", %{conn: conn} do
- Pleroma.Config.put([:user, :deny_follow_blocked], true)
+ clear_config([:user, :deny_follow_blocked], true)
user = insert(:user)
user2 = insert(:user)
{:ok, _user_block} = Pleroma.User.block(user2, user)
@@ -380,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 5586a9a13..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-2020 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
@@ -46,12 +46,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
end
test "it sends confirmation email if :account_activation_required is specified in instance config" do
- setting = Pleroma.Config.get([:instance, :account_activation_required])
-
- unless setting do
- Pleroma.Config.put([:instance, :account_activation_required], true)
- on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
- end
+ clear_config([:instance, :account_activation_required], true)
data = %{
:username => "lain",
@@ -65,7 +60,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user} = TwitterAPI.register_user(data)
ObanHelpers.perform_all()
- assert user.confirmation_pending
+ refute user.is_confirmed
email = Pleroma.Emails.UserEmail.account_confirmation_email(user)
@@ -97,7 +92,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user} = TwitterAPI.register_user(data)
ObanHelpers.perform_all()
- assert user.approval_pending
+ refute user.is_approved
user_email = Pleroma.Emails.UserEmail.approval_pending_email(user)
admin_email = Pleroma.Emails.AdminEmail.new_unapproved_registration(admin, user)
@@ -144,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 60f2fb052..a4da23635 100644
--- a/test/pleroma/web/twitter_api/util_controller_test.exs
+++ b/test/pleroma/web/twitter_api/util_controller_test.exs
@@ -1,12 +1,11 @@
# 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.TwitterAPI.UtilControllerTest do
use Pleroma.Web.ConnCase
use Oban.Testing, repo: Pleroma.Repo
- alias Pleroma.Config
alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
@@ -26,11 +25,10 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
test "it updates notification settings", %{user: user, conn: conn} do
conn
- |> put("/api/pleroma/notification_settings", %{
- "block_from_strangers" => true,
- "bar" => 1
- })
- |> json_response(:ok)
+ |> put(
+ "/api/pleroma/notification_settings?#{URI.encode_query(%{block_from_strangers: true})}"
+ )
+ |> json_response_and_validate_schema(:ok)
user = refresh_record(user)
@@ -42,8 +40,10 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
test "it updates notification settings to enable hiding contents", %{user: user, conn: conn} do
conn
- |> put("/api/pleroma/notification_settings", %{"hide_notification_contents" => "1"})
- |> json_response(:ok)
+ |> put(
+ "/api/pleroma/notification_settings?#{URI.encode_query(%{hide_notification_contents: 1})}"
+ )
+ |> json_response_and_validate_schema(:ok)
user = refresh_record(user)
@@ -66,12 +66,12 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
}
]
- Config.put(:frontend_configurations, config)
+ clear_config(:frontend_configurations, config)
response =
conn
|> get("/api/pleroma/frontend_configurations")
- |> json_response(:ok)
+ |> json_response_and_validate_schema(:ok)
assert response == Jason.encode!(config |> Enum.into(%{})) |> Jason.decode!()
end
@@ -82,7 +82,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
emoji =
conn
|> get("/api/pleroma/emoji")
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
assert Enum.all?(emoji, fn
{_key,
@@ -99,25 +99,25 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
setup do: clear_config([:instance, :healthcheck])
test "returns 503 when healthcheck disabled", %{conn: conn} do
- Config.put([:instance, :healthcheck], false)
+ clear_config([:instance, :healthcheck], false)
response =
conn
|> get("/api/pleroma/healthcheck")
- |> json_response(503)
+ |> json_response_and_validate_schema(503)
assert response == %{}
end
test "returns 200 when healthcheck enabled and all ok", %{conn: conn} do
- Config.put([:instance, :healthcheck], true)
+ clear_config([:instance, :healthcheck], true)
with_mock Pleroma.Healthcheck,
system_info: fn -> %Pleroma.Healthcheck{healthy: true} end do
response =
conn
|> get("/api/pleroma/healthcheck")
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
assert %{
"active" => _,
@@ -130,14 +130,14 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
end
test "returns 503 when healthcheck enabled and health is false", %{conn: conn} do
- Config.put([:instance, :healthcheck], true)
+ clear_config([:instance, :healthcheck], true)
with_mock Pleroma.Healthcheck,
system_info: fn -> %Pleroma.Healthcheck{healthy: false} end do
response =
conn
|> get("/api/pleroma/healthcheck")
- |> json_response(503)
+ |> json_response_and_validate_schema(503)
assert %{
"active" => _,
@@ -156,15 +156,15 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
test "with valid permissions and password, it disables the account", %{conn: conn, user: user} do
response =
conn
- |> post("/api/pleroma/disable_account", %{"password" => "test"})
- |> json_response(:ok)
+ |> post("/api/pleroma/disable_account?password=test")
+ |> json_response_and_validate_schema(:ok)
assert response == %{"status" => "success"}
ObanHelpers.perform_all()
user = User.get_cached_by_id(user.id)
- assert user.deactivated == true
+ refute user.is_active
end
test "with valid permissions and invalid password, it returns an error", %{conn: conn} do
@@ -172,13 +172,13 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
response =
conn
- |> post("/api/pleroma/disable_account", %{"password" => "test1"})
- |> json_response(:ok)
+ |> post("/api/pleroma/disable_account?password=test1")
+ |> json_response_and_validate_schema(:ok)
assert response == %{"error" => "Invalid password."}
user = User.get_cached_by_id(user.id)
- refute user.deactivated
+ assert user.is_active
end
end
@@ -233,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
@@ -253,54 +349,93 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
conn =
conn
|> assign(:token, nil)
- |> post("/api/pleroma/change_email")
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/change_email", %{password: "hi", email: "test@test.com"})
- assert json_response(conn, 403) == %{"error" => "Insufficient permissions: write:accounts."}
+ assert json_response_and_validate_schema(conn, 403) == %{
+ "error" => "Insufficient permissions: write:accounts."
+ }
end
test "with proper permissions and invalid password", %{conn: conn} do
conn =
- post(conn, "/api/pleroma/change_email", %{
- "password" => "hi",
- "email" => "test@test.com"
- })
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/change_email", %{password: "hi", email: "test@test.com"})
- assert json_response(conn, 200) == %{"error" => "Invalid password."}
+ assert json_response_and_validate_schema(conn, 200) == %{"error" => "Invalid password."}
end
test "with proper permissions, valid password and invalid email", %{
conn: conn
} do
conn =
- post(conn, "/api/pleroma/change_email", %{
- "password" => "test",
- "email" => "foobar"
- })
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/change_email", %{password: "test", email: "foobar"})
- assert json_response(conn, 200) == %{"error" => "Email has invalid format."}
+ assert json_response_and_validate_schema(conn, 200) == %{
+ "error" => "Email has invalid format."
+ }
end
test "with proper permissions, valid password and no email", %{
conn: conn
} do
conn =
- post(conn, "/api/pleroma/change_email", %{
- "password" => "test"
- })
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/change_email", %{password: "test"})
- assert json_response(conn, 200) == %{"error" => "Email can't be blank."}
+ assert %{"error" => "Missing field: email."} = json_response_and_validate_schema(conn, 400)
end
- test "with proper permissions, valid password and blank email", %{
- conn: conn
- } do
+ 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 =
- post(conn, "/api/pleroma/change_email", %{
- "password" => "test",
- "email" => ""
- })
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/change_email", %{password: "test", email: ""})
- assert json_response(conn, 200) == %{"error" => "Email can't be blank."}
+ assert json_response_and_validate_schema(conn, 200) == %{"error" => "Email can't be blank."}
+ end
+
+ test "with proper permissions, valid password and 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", %{
@@ -309,24 +444,24 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
user = insert(:user)
conn =
- post(conn, "/api/pleroma/change_email", %{
- "password" => "test",
- "email" => user.email
- })
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/change_email", %{password: "test", email: user.email})
- assert json_response(conn, 200) == %{"error" => "Email has already been taken."}
+ assert json_response_and_validate_schema(conn, 200) == %{
+ "error" => "Email has already been taken."
+ }
end
test "with proper permissions, valid password and valid email", %{
conn: conn
} do
conn =
- post(conn, "/api/pleroma/change_email", %{
- "password" => "test",
- "email" => "cofe@foobar.com"
- })
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/change_email", %{password: "test", email: "cofe@foobar.com"})
- assert json_response(conn, 200) == %{"status" => "success"}
+ assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
end
end
@@ -337,20 +472,29 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
conn =
conn
|> assign(:token, nil)
- |> post("/api/pleroma/change_password")
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/change_password", %{
+ "password" => "hi",
+ "new_password" => "newpass",
+ "new_password_confirmation" => "newpass"
+ })
- assert json_response(conn, 403) == %{"error" => "Insufficient permissions: write:accounts."}
+ assert json_response_and_validate_schema(conn, 403) == %{
+ "error" => "Insufficient permissions: write:accounts."
+ }
end
test "with proper permissions and invalid password", %{conn: conn} do
conn =
- post(conn, "/api/pleroma/change_password", %{
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/change_password", %{
"password" => "hi",
"new_password" => "newpass",
"new_password_confirmation" => "newpass"
})
- assert json_response(conn, 200) == %{"error" => "Invalid password."}
+ assert json_response_and_validate_schema(conn, 200) == %{"error" => "Invalid password."}
end
test "with proper permissions, valid password and new password and confirmation not matching",
@@ -358,13 +502,15 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
conn: conn
} do
conn =
- post(conn, "/api/pleroma/change_password", %{
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/change_password", %{
"password" => "test",
"new_password" => "newpass",
"new_password_confirmation" => "notnewpass"
})
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"error" => "New password does not match confirmation."
}
end
@@ -373,13 +519,15 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
conn: conn
} do
conn =
- post(conn, "/api/pleroma/change_password", %{
- "password" => "test",
- "new_password" => "",
- "new_password_confirmation" => ""
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/change_password", %{
+ password: "test",
+ new_password: "",
+ new_password_confirmation: ""
})
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"error" => "New password can't be blank."
}
end
@@ -389,15 +537,20 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
user: user
} do
conn =
- post(conn, "/api/pleroma/change_password", %{
- "password" => "test",
- "new_password" => "newpass",
- "new_password_confirmation" => "newpass"
- })
-
- assert json_response(conn, 200) == %{"status" => "success"}
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post(
+ "/api/pleroma/change_password",
+ %{
+ password: "test",
+ new_password: "newpass",
+ new_password_confirmation: "newpass"
+ }
+ )
+
+ assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
fetched_user = User.get_cached_by_id(user.id)
- assert Pbkdf2.verify_pass("newpass", fetched_user.password_hash) == true
+ assert Pleroma.Password.Pbkdf2.verify_pass("newpass", fetched_user.password_hash) == true
end
end
@@ -410,28 +563,420 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|> assign(:token, nil)
|> post("/api/pleroma/delete_account")
- assert json_response(conn, 403) ==
+ assert json_response_and_validate_schema(conn, 403) ==
%{"error" => "Insufficient permissions: write:accounts."}
end
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(ret_conn, 200) == %{"error" => "Invalid password."}
+ assert json_response_and_validate_schema(ret_conn, 200) == %{
+ "error" => "Invalid password."
+ }
end
end
- test "with proper permissions and valid password", %{conn: conn, user: user} do
- conn = post(conn, "/api/pleroma/delete_account", %{"password" => "test"})
+ 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"}
+
+ user = User.get_by_id(user.id)
+ refute user.is_active
+ assert user.name == nil
+ 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(conn, 200) == %{"status" => "success"}
+ assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
user = User.get_by_id(user.id)
- assert user.deactivated == true
+ 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 00f9e72ec..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-2020 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 8dbbd18b4..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-2020 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 ce9eb0650..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-2020 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.base_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 cdb84ae1e..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-2020 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
@@ -17,7 +17,7 @@ defmodule Pleroma.Web.WebFingerTest do
test "returns a link to the xml lrdd" do
host_info = WebFinger.host_meta()
- assert String.contains?(host_info, Pleroma.Web.base_url())
+ assert String.contains?(host_info, Pleroma.Web.Endpoint.url())
end
end
@@ -45,6 +45,26 @@ defmodule Pleroma.Web.WebFingerTest do
assert {:error, _} = WebFinger.finger("pleroma.social")
end
+ test "returns error when there is no content-type header" do
+ Tesla.Mock.mock(fn
+ %{url: "https://social.heldscal.la/.well-known/host-meta"} ->
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
+ }}
+
+ %{
+ url:
+ "https://social.heldscal.la/.well-known/webfinger?resource=acct:invalid_content@social.heldscal.la"
+ } ->
+ {:ok, %Tesla.Env{status: 200, body: ""}}
+ end)
+
+ user = "invalid_content@social.heldscal.la"
+ assert {:error, {:content_type, nil}} = WebFinger.finger(user)
+ end
+
test "returns error when fails parse xml or json" do
user = "invalid_content@social.heldscal.la"
assert {:error, %Jason.DecodeError{}} = WebFinger.finger(user)
@@ -100,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
@@ -113,5 +133,52 @@ defmodule Pleroma.Web.WebFingerTest do
ap_id = "https://" <> to_string(:idna.encode("zetsubou.みんな")) <> "/users/lain"
{:ok, _data} = WebFinger.finger(ap_id)
end
+
+ test "respects json content-type" do
+ Tesla.Mock.mock(fn
+ %{
+ url:
+ "https://mastodon.social/.well-known/webfinger?resource=acct:emelie@mastodon.social"
+ } ->
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/webfinger_emelie.json"),
+ headers: [{"content-type", "application/jrd+json"}]
+ }}
+
+ %{url: "https://mastodon.social/.well-known/host-meta"} ->
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
+ }}
+ end)
+
+ {:ok, _data} = WebFinger.finger("emelie@mastodon.social")
+ end
+
+ test "respects xml content-type" do
+ Tesla.Mock.mock(fn
+ %{
+ url: "https://pawoo.net/.well-known/webfinger?resource=acct:pekorino@pawoo.net"
+ } ->
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.xml"),
+ headers: [{"content-type", "application/xrd+xml"}]
+ }}
+
+ %{url: "https://pawoo.net/.well-known/host-meta"} ->
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta")
+ }}
+ end)
+
+ {:ok, _data} = WebFinger.finger("pekorino@pawoo.net")
+ end
end
end
diff --git a/test/pleroma/workers/cron/digest_emails_worker_test.exs b/test/pleroma/workers/cron/digest_emails_worker_test.exs
index 65887192e..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-2020 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
@@ -14,7 +14,7 @@ defmodule Pleroma.Workers.Cron.DigestEmailsWorkerTest do
setup do: clear_config([:email_notifications, :digest])
setup do
- Pleroma.Config.put([:email_notifications, :digest], %{
+ clear_config([:email_notifications, :digest], %{
active: true,
inactivity_threshold: 7,
interval: 7
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 e00ed6745..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-2020 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 b5938776d..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-2020 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
new file mode 100644
index 000000000..e8d45aaaa
--- /dev/null
+++ b/test/pleroma/workers/purge_expired_filter_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.Workers.PurgeExpiredFilterTest do
+ use Pleroma.DataCase, async: true
+ use Oban.Testing, repo: Repo
+
+ import Pleroma.Factory
+
+ test "purges expired filter" do
+ %{id: user_id} = insert(:user)
+
+ {:ok, %{id: id}} =
+ Pleroma.Filter.create(%{
+ user_id: user_id,
+ phrase: "cofe",
+ context: ["home"],
+ expires_in: 600
+ })
+
+ assert_enqueued(
+ worker: Pleroma.Workers.PurgeExpiredFilter,
+ args: %{filter_id: id}
+ )
+
+ assert {:ok, %{id: ^id}} =
+ perform_job(Pleroma.Workers.PurgeExpiredFilter, %{
+ filter_id: id
+ })
+
+ assert Repo.aggregate(Pleroma.Filter, :count, :id) == 0
+ end
+end
diff --git a/test/pleroma/workers/purge_expired_token_test.exs b/test/pleroma/workers/purge_expired_token_test.exs
index fb7708c3f..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-2020 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 f3eddf7b1..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-2020 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
@@ -11,10 +11,9 @@ defmodule Pleroma.Workers.ScheduledActivityWorkerTest do
import Pleroma.Factory
import ExUnit.CaptureLog
- setup do: clear_config([ScheduledActivity, :enabled])
+ setup do: clear_config([ScheduledActivity, :enabled], true)
test "creates a status from the scheduled activity" do
- Pleroma.Config.put([ScheduledActivity, :enabled], true)
user = insert(:user)
naive_datetime =
@@ -32,18 +31,22 @@ defmodule Pleroma.Workers.ScheduledActivityWorkerTest do
params: %{status: "hi"}
)
- ScheduledActivityWorker.perform(%Oban.Job{args: %{"activity_id" => scheduled_activity.id}})
+ {:ok, %{id: activity_id}} =
+ ScheduledActivityWorker.perform(%Oban.Job{args: %{"activity_id" => scheduled_activity.id}})
refute Repo.get(ScheduledActivity, scheduled_activity.id)
- activity = Repo.all(Pleroma.Activity) |> Enum.find(&(&1.actor == user.ap_id))
- assert Pleroma.Object.normalize(activity).data["content"] == "hi"
- end
- test "adds log message if ScheduledActivity isn't find" do
- Pleroma.Config.put([ScheduledActivity, :enabled], true)
+ object =
+ Pleroma.Activity
+ |> Repo.get(activity_id)
+ |> Pleroma.Object.normalize()
+
+ assert object.data["content"] == "hi"
+ end
+ test "error message for non-existent scheduled activity" do
assert capture_log([level: :error], fn ->
ScheduledActivityWorker.perform(%Oban.Job{args: %{"activity_id" => 42}})
- end) =~ "Couldn't find scheduled activity"
+ end) =~ "Couldn't find scheduled activity: 42"
end
end
diff --git a/test/pleroma/xml_builder_test.exs b/test/pleroma/xml_builder_test.exs
index a4c73359d..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-2020 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 46388f92c..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-2020 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 0c687c029..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
@@ -7,7 +11,7 @@ defmodule Pleroma.Builders.UserBuilder do
email: "test@example.org",
name: "Test Name",
nickname: "testname",
- password_hash: Pbkdf2.hash_pwd_salt("test"),
+ password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("test"),
bio: "A tester.",
ap_id: "some id",
last_digest_emailed_at: NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
diff --git a/test/support/cachex_proxy.ex b/test/support/cachex_proxy.ex
index e296b5c6a..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-2020 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 2ed2ba3b4..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-2020 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 f4696adb3..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-2020 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
@@ -30,19 +30,5 @@ defmodule Pleroma.Web.ChannelCase do
end
end
- setup tags do
- :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
-
- if tags[:async] do
- Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache)
- Mox.set_mox_private()
- else
- Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
- Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy)
- Mox.set_mox_global()
- Pleroma.DataCase.clear_cachex()
- end
-
- :ok
- end
+ setup tags, do: Pleroma.DataCase.setup_multi_process_mode(tags)
end
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 f20e3d955..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-2020 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
@@ -19,6 +19,8 @@ defmodule Pleroma.Web.ConnCase do
use ExUnit.CaseTemplate
+ alias Pleroma.DataCase
+
using do
quote do
# Import conveniences for testing with connections
@@ -65,13 +67,11 @@ defmodule Pleroma.Web.ConnCase do
end
defp json_response_and_validate_schema(
- %{
- private: %{
- open_api_spex: %{operation_id: op_id, operation_lookup: lookup, spec: spec}
- }
- } = conn,
+ %{private: %{operation_id: op_id}} = conn,
status
) do
+ {spec, lookup} = OpenApiSpex.Plug.PutApiSpec.get_spec_and_operation_lookup(conn)
+
content_type =
conn
|> Plug.Conn.get_resp_header("content-type")
@@ -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
@@ -116,27 +114,9 @@ defmodule Pleroma.Web.ConnCase do
end
setup tags do
- :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
-
- if tags[:async] do
- Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache)
- Mox.set_mox_private()
- else
- Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
- Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy)
- Mox.set_mox_global()
- Pleroma.DataCase.clear_cachex()
- end
-
- if tags[:needs_streamer] do
- start_supervised(%{
- id: Pleroma.Web.Streamer.registry(),
- start:
- {Registry, :start_link, [[keys: :duplicate, name: Pleroma.Web.Streamer.registry()]]}
- })
- end
-
- Pleroma.DataCase.stub_pipeline()
+ DataCase.setup_multi_process_mode(tags)
+ DataCase.setup_streamer(tags)
+ DataCase.stub_pipeline()
Mox.verify_on_exit!()
diff --git a/test/support/data_case.ex b/test/support/data_case.ex
index 0b41f0f63..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-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.DataCase do
@@ -18,6 +18,8 @@ defmodule Pleroma.DataCase do
use ExUnit.CaseTemplate
+ import Pleroma.Tests.Helpers, only: [clear_config: 2]
+
using do
quote do
alias Pleroma.Repo
@@ -62,7 +64,7 @@ defmodule Pleroma.DataCase do
end)
end
- setup tags do
+ def setup_multi_process_mode(tags) do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
if tags[:async] do
@@ -70,11 +72,16 @@ defmodule Pleroma.DataCase do
Mox.set_mox_private()
else
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
- Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy)
+
Mox.set_mox_global()
+ Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy)
clear_cachex()
end
+ :ok
+ end
+
+ def setup_streamer(tags) do
if tags[:needs_streamer] do
start_supervised(%{
id: Pleroma.Web.Streamer.registry(),
@@ -83,6 +90,12 @@ defmodule Pleroma.DataCase do
})
end
+ :ok
+ end
+
+ setup tags do
+ setup_multi_process_mode(tags)
+ setup_streamer(tags)
stub_pipeline()
Mox.verify_on_exit!()
@@ -105,17 +118,10 @@ defmodule Pleroma.DataCase do
end
def ensure_local_uploader(context) do
- test_uploader = Map.get(context, :uploader, Pleroma.Uploaders.Local)
- uploader = Pleroma.Config.get([Pleroma.Upload, :uploader])
- filters = Pleroma.Config.get([Pleroma.Upload, :filters])
-
- Pleroma.Config.put([Pleroma.Upload, :uploader], test_uploader)
- Pleroma.Config.put([Pleroma.Upload, :filters], [])
+ test_uploader = Map.get(context, :uploader) || Pleroma.Uploaders.Local
- on_exit(fn ->
- Pleroma.Config.put([Pleroma.Upload, :uploader], uploader)
- Pleroma.Config.put([Pleroma.Upload, :filters], filters)
- end)
+ clear_config([Pleroma.Upload, :uploader], test_uploader)
+ clear_config([Pleroma.Upload, :filters], [])
:ok
end
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 8eb07dc3c..09f02458c 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -1,12 +1,24 @@
# 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.Factory do
use ExMachina.Ecto, repo: Pleroma.Repo
+
+ require Pleroma.Constants
+
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)
@@ -25,39 +37,46 @@ 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"),
nickname: sequence(:nickname, &"nick#{&1}"),
- password_hash: Pbkdf2.hash_pwd_salt("test"),
+ password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("test"),
bio: sequence(:bio, &"Tester Number #{&1}"),
is_discoverable: true,
last_digest_emailed_at: NaiveDateTime.utc_now(),
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 =
if attrs[:local] == false do
- base_domain = Enum.random(["domain1.com", "domain2.com", "domain3.com"])
+ base_domain = attrs[:domain] || Enum.random(["domain1.com", "domain2.com", "domain3.com"])
ap_id = "https://#{base_domain}/users/#{user.nickname}"
%{
ap_id: ap_id,
follower_address: ap_id <> "/followers",
- following_address: ap_id <> "/following"
+ following_address: ap_id <> "/following",
+ featured_address: ap_id <> "/collections/featured"
}
else
%{
ap_id: User.ap_id(user),
follower_address: User.ap_followers(user),
- following_address: User.ap_following(user)
+ following_address: User.ap_following(user),
+ featured_address: User.ap_featured_collection(user)
}
end
+ attrs = Map.delete(attrs, :domain)
+
user
|> Map.put(:raw_bio, user.bio)
|> Map.merge(urls)
@@ -104,6 +123,54 @@ 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)
+
+ data = %{
+ "attachment" =>
+ Stream.repeatedly(fn -> attachment_data(user.ap_id, attrs[:href]) end)
+ |> Enum.take(length)
+ }
+
+ build(:note, Map.put(attrs, :data, data))
+ end
+
+ defp attachment_data(ap_id, href) do
+ href = href || sequence(:href, &"#{Pleroma.Web.Endpoint.url()}/media/#{&1}.jpg")
+
+ %{
+ "url" => [
+ %{
+ "href" => href,
+ "type" => "Link",
+ "mediaType" => "image/jpeg"
+ }
+ ],
+ "name" => "some name",
+ "type" => "Document",
+ "actor" => ap_id,
+ "mediaType" => "image/jpeg"
+ }
+ 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}")
@@ -153,8 +220,8 @@ defmodule Pleroma.Factory do
end
def article_factory do
- note_factory()
- |> Map.put("type", "Article")
+ %Pleroma.Object{data: data} = note_factory()
+ %Pleroma.Object{data: Map.merge(data, %{"type" => "Article"})}
end
def tombstone_factory do
@@ -170,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)
@@ -190,6 +289,72 @@ defmodule Pleroma.Factory do
}
end
+ def add_activity_factory(attrs \\ %{}) do
+ featured_collection_activity(attrs, "Add")
+ end
+
+ def remove_activity_factor(attrs \\ %{}) do
+ featured_collection_activity(attrs, "Remove")
+ end
+
+ defp featured_collection_activity(attrs, type) do
+ user = attrs[:user] || insert(:user)
+ note = attrs[:note] || insert(:note, user: user)
+
+ data_attrs =
+ attrs
+ |> Map.get(:data_attrs, %{})
+ |> Map.put(:type, type)
+
+ attrs = Map.drop(attrs, [:user, :note, :data_attrs])
+
+ data =
+ %{
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
+ "target" => user.featured_address,
+ "object" => note.data["object"],
+ "actor" => note.data["actor"],
+ "type" => "Add",
+ "to" => [Pleroma.Constants.as_public()],
+ "cc" => [user.follower_address]
+ }
+ |> Map.merge(data_attrs)
+
+ %Pleroma.Activity{
+ data: data,
+ actor: data["actor"],
+ recipients: data["to"]
+ }
+ |> Map.merge(attrs)
+ end
+
+ def 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)
@@ -259,7 +424,7 @@ defmodule Pleroma.Factory do
def like_activity_factory(attrs \\ %{}) do
note_activity = attrs[:note_activity] || insert(:note_activity)
- object = Object.normalize(note_activity)
+ object = Object.normalize(note_activity, fetch: false)
user = insert(:user)
data =
@@ -319,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}"),
@@ -455,7 +647,20 @@ defmodule Pleroma.Factory do
%Pleroma.Filter{
user: build(:user),
filter_id: sequence(:filter_id, & &1),
- phrase: "cofe"
+ phrase: "cofe",
+ 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 15e8cbd9d..0bd487f39 100644
--- a/test/support/helpers.ex
+++ b/test/support/helpers.ex
@@ -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.Tests.Helpers do
@@ -8,6 +8,8 @@ defmodule Pleroma.Tests.Helpers do
"""
alias Pleroma.Config
+ require Logger
+
defmacro clear_config(config_path) do
quote do
clear_config(unquote(config_path)) do
@@ -18,6 +20,7 @@ defmodule Pleroma.Tests.Helpers do
defmacro clear_config(config_path, do: yield) do
quote do
initial_setting = Config.fetch(unquote(config_path))
+
unquote(yield)
on_exit(fn ->
@@ -35,6 +38,14 @@ defmodule Pleroma.Tests.Helpers do
end
defmacro clear_config(config_path, temp_setting) do
+ # NOTE: `clear_config([section, key], value)` != `clear_config([section], key: value)` (!)
+ # Displaying a warning to prevent unintentional clearing of all but one keys in section
+ if Keyword.keyword?(temp_setting) and length(temp_setting) == 1 do
+ Logger.warn(
+ "Please change `clear_config([section], key: value)` to `clear_config([section, key], value)`"
+ )
+ end
+
quote do
clear_config(unquote(config_path)) do
Config.put(unquote(config_path), unquote(temp_setting))
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index 93464ebff..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-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule HttpRequestMock do
@@ -89,6 +89,18 @@ defmodule HttpRequestMock do
}}
end
+ def get("https://mastodon.sdf.org/users/rinpatch/collections/featured", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body:
+ File.read!("test/fixtures/users_mock/masto_featured.json")
+ |> String.replace("{{domain}}", "mastodon.sdf.org")
+ |> String.replace("{{nickname}}", "rinpatch"),
+ headers: [{"content-type", "application/activity+json"}]
+ }}
+ end
+
def get("https://patch.cx/objects/tesla_mock/poll_attachment", _, _, _) do
{:ok,
%Tesla.Env{
@@ -122,7 +134,7 @@ defmodule HttpRequestMock do
%Tesla.Env{
status: 200,
body: File.read!("test/fixtures/tesla_mock/mike@osada.macgirvin.com.json"),
- headers: activitypub_object_headers()
+ headers: [{"content-type", "application/jrd+json"}]
}}
end
@@ -187,7 +199,8 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
+ body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml"),
+ headers: [{"content-type", "application/xrd+xml"}]
}}
end
@@ -275,6 +288,15 @@ defmodule HttpRequestMock do
}}
end
+ def get("https://peertube.stream/accounts/createurs", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/peertube/actor-person.json"),
+ headers: activitypub_object_headers()
+ }}
+ end
+
def get("https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3", _, _, _) do
{:ok,
%Tesla.Env{
@@ -402,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{
@@ -517,22 +531,6 @@ defmodule HttpRequestMock do
}}
end
- def get("http://zetsubou.xn--q9jyb4c/.well-known/host-meta", _, _, _) do
- {:ok,
- %Tesla.Env{
- status: 200,
- body: File.read!("test/fixtures/tesla_mock/xn--q9jyb4c_host_meta")
- }}
- end
-
- def get("https://zetsubou.xn--q9jyb4c/.well-known/host-meta", _, _, _) do
- {:ok,
- %Tesla.Env{
- status: 200,
- body: File.read!("test/fixtures/tesla_mock/xn--q9jyb4c_host_meta")
- }}
- end
-
def get("http://pleroma.soykaf.com/.well-known/host-meta", _, _, _) do
{:ok,
%Tesla.Env{
@@ -719,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{
@@ -750,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
@@ -777,7 +784,8 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml")
+ body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml"),
+ headers: [{"content-type", "application/xrd+xml"}]
}}
end
@@ -787,10 +795,10 @@ defmodule HttpRequestMock do
_,
[{"accept", "application/xrd+xml,application/jrd+json"}]
) do
- {:ok, %Tesla.Env{status: 200, body: ""}}
+ {:ok, %Tesla.Env{status: 200, body: "", headers: [{"content-type", "application/jrd+json"}]}}
end
- def get("http://framatube.org/.well-known/host-meta", _, _, _) do
+ def get("https://framatube.org/.well-known/host-meta", _, _, _) do
{:ok,
%Tesla.Env{
status: 200,
@@ -799,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"}]
@@ -807,7 +815,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- headers: [{"content-type", "application/json"}],
+ headers: [{"content-type", "application/jrd+json"}],
body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
}}
end
@@ -834,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,
@@ -842,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,
@@ -850,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,
@@ -867,7 +875,7 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- headers: [{"content-type", "application/json"}],
+ headers: [{"content-type", "application/jrd+json"}],
body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
}}
end
@@ -910,6 +918,18 @@ defmodule HttpRequestMock do
}}
end
+ def get("https://mastodon.social/users/lambadalambda/collections/featured", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body:
+ File.read!("test/fixtures/users_mock/masto_featured.json")
+ |> String.replace("{{domain}}", "mastodon.social")
+ |> String.replace("{{nickname}}", "lambadalambda"),
+ headers: activitypub_object_headers()
+ }}
+ end
+
def get("https://apfed.club/channel/indio", _, _, _) do
{:ok,
%Tesla.Env{
@@ -1056,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",
_,
@@ -1065,7 +1093,8 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/lain.xml")
+ body: File.read!("test/fixtures/lain.xml"),
+ headers: [{"content-type", "application/xrd+xml"}]
}}
end
@@ -1078,7 +1107,16 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/lain.xml")
+ body: File.read!("test/fixtures/lain.xml"),
+ headers: [{"content-type", "application/xrd+xml"}]
+ }}
+ end
+
+ def get("http://zetsubou.xn--q9jyb4c/.well-known/host-meta", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
}}
end
@@ -1095,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
@@ -1144,7 +1233,8 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
+ body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml"),
+ headers: [{"content-type", "application/xrd+xml"}]
}}
end
@@ -1272,11 +1362,93 @@ defmodule HttpRequestMock do
}}
end
+ def get("https://patch.cx/objects/a399c28e-c821-4820-bc3e-4afeb044c16f", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/emoji-in-summary.json"),
+ headers: activitypub_object_headers()
+ }}
+ end
+
+ def get("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
@@ -1342,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.
@@ -1359,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 442ff5b71..d167996bd 100644
--- a/test/support/mocks.ex
+++ b/test/support/mocks.ex
@@ -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
Mox.defmock(Pleroma.CachexMock, for: Pleroma.Caching)
diff --git a/test/support/mrf_module_mock.ex b/test/support/mrf_module_mock.ex
index 028ea542a..616fc720e 100644
--- a/test/support/mrf_module_mock.ex
+++ b/test/support/mrf_module_mock.ex
@@ -1,9 +1,9 @@
# 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 MRFModuleMock do
- @behaviour Pleroma.Web.ActivityPub.MRF
+ @behaviour Pleroma.Web.ActivityPub.MRF.Policy
@impl true
def filter(message), do: {:ok, message}
diff --git a/test/support/null_cache.ex b/test/support/null_cache.ex
index c63df6a39..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-2020 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 2468f66dc..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-2020 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 8c9d4b2b4..7163bbd41 100644
--- a/test/support/websocket_client.ex
+++ b/test/support/websocket_client.ex
@@ -1,22 +1,21 @@
# 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.Integration.WebsocketClient do
# https://github.com/phoenixframework/phoenix/blob/master/test/support/websocket_client.exs
+ use WebSockex
+
@doc """
Starts the WebSocket server for given ws URL. Received Socket.Message's
are forwarded to the sender pid
"""
def start_link(sender, url, headers \\ []) do
- :crypto.start()
- :ssl.start()
-
- :websocket_client.start_link(
- String.to_charlist(url),
+ WebSockex.start_link(
+ url,
__MODULE__,
- [sender],
+ %{sender: sender},
extra_headers: headers
)
end
@@ -36,27 +35,32 @@ defmodule Pleroma.Integration.WebsocketClient do
end
@doc false
- def init([sender], _conn_state) do
- {:ok, %{sender: sender}}
+ @impl true
+ def handle_frame(frame, state) do
+ send(state.sender, frame)
+ {:ok, state}
end
- @doc false
- def websocket_handle(frame, _conn_state, state) do
- send(state.sender, frame)
+ @impl true
+ def handle_disconnect(conn_status, state) do
+ send(state.sender, {:close, conn_status})
{:ok, state}
end
@doc false
- def websocket_info({:text, msg}, _conn_state, state) do
+ @impl true
+ def handle_info({:text, msg}, state) do
{:reply, {:text, msg}, state}
end
- def websocket_info(:close, _conn_state, _state) do
+ @impl true
+ def handle_info(:close, _state) do
{:close, <<>>, "done"}
end
@doc false
- def websocket_terminate(_reason, _conn_state, _state) do
+ @impl true
+ def terminate(_reason, _state) do
:ok
end
end
diff --git a/test/test_helper.exs b/test/test_helper.exs
index ee880e226..60a61484f 100644
--- a/test/test_helper.exs
+++ b/test/test_helper.exs
@@ -1,9 +1,9 @@
# 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
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)