Fix merge conflicts with upstream
This commit is contained in:
commit
dc4814f0cd
240 changed files with 4616 additions and 1584 deletions
|
|
@ -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"]
|
||||
|
|
|
|||
5
test/fixtures/config/temp.exported_from_db.secret.exs
vendored
Normal file
5
test/fixtures/config/temp.exported_from_db.secret.exs
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import Config
|
||||
|
||||
config :pleroma, exported_config_merged: true
|
||||
|
||||
config :pleroma, :first_setting, key: "new value"
|
||||
2
test/fixtures/config/temp.secret.exs
vendored
2
test/fixtures/config/temp.secret.exs
vendored
|
|
@ -2,7 +2,7 @@
|
|||
# Copyright © 2017-2021 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]
|
||||
|
||||
|
|
|
|||
39
test/fixtures/mastodon/collections/featured.json
vendored
Normal file
39
test/fixtures/mastodon/collections/featured.json
vendored
Normal file
|
|
@ -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"
|
||||
}
|
||||
47
test/fixtures/statuses/masto-note.json
vendored
Normal file
47
test/fixtures/statuses/masto-note.json
vendored
Normal file
|
|
@ -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": []
|
||||
}
|
||||
}
|
||||
}
|
||||
27
test/fixtures/statuses/note.json
vendored
Normal file
27
test/fixtures/statuses/note.json
vendored
Normal file
|
|
@ -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"
|
||||
}
|
||||
18
test/fixtures/users_mock/masto_featured.json
vendored
Normal file
18
test/fixtures/users_mock/masto_featured.json
vendored
Normal file
|
|
@ -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": []
|
||||
}
|
||||
42
test/fixtures/users_mock/user.json
vendored
Normal file
42
test/fixtures/users_mock/user.json
vendored
Normal file
|
|
@ -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}}"
|
||||
}
|
||||
|
|
@ -188,15 +188,8 @@ 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
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
@ -254,4 +256,26 @@ 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
|
||||
end
|
||||
|
|
|
|||
|
|
@ -35,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
|
||||
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
|
||||
|
||||
|
|
@ -57,15 +57,13 @@ 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
|
||||
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
|
||||
|
|
|
|||
|
|
@ -146,4 +146,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
|
||||
|
|
|
|||
45
test/pleroma/config/release_runtime_provider_test.exs
Normal file
45
test/pleroma/config/release_runtime_provider_test.exs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
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
|
||||
|
|
@ -93,8 +93,8 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
end
|
||||
|
||||
test "on reboot time key" do
|
||||
clear_config(:chat)
|
||||
insert(:config, key: :chat, value: [enabled: false])
|
||||
clear_config(:shout)
|
||||
insert(:config, key: :shout, value: [enabled: false])
|
||||
assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
|
||||
end
|
||||
|
||||
|
|
@ -105,10 +105,10 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
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?(
|
||||
|
|
|
|||
|
|
@ -1,79 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
defmodule Pleroma.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 "Hello World"</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
|
||||
|
|
@ -6,10 +6,10 @@ 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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -624,6 +624,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" => [
|
||||
%{
|
||||
|
|
@ -655,6 +657,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
|
||||
}
|
||||
|
|
@ -951,6 +956,7 @@ defmodule Pleroma.NotificationTest do
|
|||
"cc" => [],
|
||||
"object" => %{
|
||||
"type" => "Note",
|
||||
"id" => remote_user.ap_id <> "/objects/test",
|
||||
"content" => "Hello!",
|
||||
"tag" => [
|
||||
%{
|
||||
|
|
|
|||
|
|
@ -66,6 +66,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
|
||||
|
|
@ -124,8 +132,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")
|
||||
|
|
|
|||
52
test/pleroma/repo/migrations/rename_instance_chat_test.exs
Normal file
52
test/pleroma/repo/migrations/rename_instance_chat_test.exs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
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
|
||||
19
test/pleroma/upload/filter/analyze_metadata_test.exs
Normal file
19
test/pleroma/upload/filter/analyze_metadata_test.exs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# 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.AnalyzeMetadataTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
alias Pleroma.Upload.Filter.AnalyzeMetadata
|
||||
|
||||
test "adds the image dimensions" 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")
|
||||
}
|
||||
|
||||
assert {:ok, :filtered, %{width: 1024, height: 768}} = AnalyzeMetadata.filter(upload)
|
||||
end
|
||||
end
|
||||
|
|
@ -151,7 +151,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
|
||||
|
|
@ -572,6 +572,24 @@ defmodule Pleroma.UserTest do
|
|||
)
|
||||
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 requires an email, name, nickname and password, bio is optional when account_activation_required is enabled" do
|
||||
clear_config([:instance, :account_activation_required], true)
|
||||
|
||||
|
|
@ -2336,4 +2354,49 @@ defmodule Pleroma.UserTest do
|
|||
assert User.active_user_count(6) == 3
|
||||
assert User.active_user_count(1) == 1
|
||||
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
|
||||
end
|
||||
|
|
|
|||
|
|
@ -539,7 +539,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
|
||||
|
|
@ -636,6 +636,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
|
||||
|
|
@ -649,7 +829,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
|
||||
|
|
@ -666,8 +850,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
|
||||
|
|
@ -684,8 +871,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
|
||||
|
|
@ -703,9 +893,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
|
||||
|
|
@ -820,29 +1014,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)
|
||||
|
|
@ -852,7 +1051,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
|
||||
|
|
@ -984,7 +1183,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"]
|
||||
|
|
@ -1772,4 +1970,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
|
||||
|
|
|
|||
|
|
@ -235,6 +235,83 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
"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
|
||||
end
|
||||
|
||||
test "it fetches the appropriate tag-restricted posts" do
|
||||
|
|
|
|||
|
|
@ -254,6 +254,30 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|
||||
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
|
||||
|
|
@ -498,7 +522,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" => []
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,5 +72,38 @@ 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
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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}"
|
||||
}
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,172 @@
|
|||
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"]
|
||||
}
|
||||
|
||||
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"]
|
||||
}
|
||||
|
||||
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"]
|
||||
}
|
||||
|
||||
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
|
||||
|
|
@ -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",
|
||||
|
|
@ -61,7 +63,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
|
|||
|
||||
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"
|
||||
|
||||
|
|
@ -76,7 +80,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
|
|||
"href" =>
|
||||
"https://channels.tests.funkwhale.audio/api/v1/listen/3901e5d8-0445-49d5-9711-e096cf32e515/?upload=42342395-0208-4fee-a38d-259a6dae0871&download=false",
|
||||
"mediaType" => "audio/ogg",
|
||||
"type" => "Link"
|
||||
"type" => "Link",
|
||||
"width" => nil,
|
||||
"height" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -43,36 +43,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
assert Object.hashtags(object) == ["test"]
|
||||
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 =
|
||||
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, fetch: false).data
|
||||
|
||||
assert object_data["to"] == []
|
||||
assert object_data["cc"] == to
|
||||
end
|
||||
|
||||
test "it ignores an incoming notice if we already have it" do
|
||||
activity = insert(:note_activity)
|
||||
|
||||
|
|
@ -147,9 +117,7 @@ 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
|
||||
|
|
@ -174,8 +142,8 @@ 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"
|
||||
|
|
@ -188,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"
|
||||
|
|
@ -221,8 +189,25 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
object = Object.normalize(data["object"], fetch: false)
|
||||
|
||||
assert Enum.at(Object.tags(object), 2) == "moo"
|
||||
assert Object.hashtags(object) == ["moo"]
|
||||
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 "moo" == Enum.at(object.data["tag"], 2)
|
||||
end
|
||||
|
||||
test "it works for incoming notices with contentMap" do
|
||||
|
|
@ -276,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")
|
||||
|
||||
|
|
@ -290,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
|
||||
|
|
@ -310,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)
|
||||
|
||||
refute Map.has_key?(object.data, "likes")
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert object.data["likes"] == []
|
||||
end
|
||||
|
||||
test "it strips internal reactions" do
|
||||
|
|
@ -330,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)
|
||||
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")
|
||||
|
||||
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
|
||||
}
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||
|
||||
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)
|
||||
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", ["¿"]])
|
||||
|
||||
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
|
||||
}
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -419,7 +379,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
} do
|
||||
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}
|
||||
|
|
@ -442,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)
|
||||
replies = %{
|
||||
"type" => "Collection",
|
||||
"items" => [Utils.generate_object_id(), Utils.generate_object_id()]
|
||||
}
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "post1"})
|
||||
activity =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Kernel.put_in(["object", "replies"], replies)
|
||||
|
||||
{: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)
|
||||
|
||||
Repo.delete(activity.object)
|
||||
Repo.delete(activity)
|
||||
|
||||
%{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
|
||||
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
|
||||
%{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
|
||||
|
|
@ -498,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,
|
||||
|
|
@ -522,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,
|
||||
|
|
|
|||
|
|
@ -60,7 +60,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
|
|||
"href" =>
|
||||
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
"type" => "Link",
|
||||
"width" => nil,
|
||||
"height" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -83,7 +85,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
|
|||
"href" =>
|
||||
"https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
"type" => "Link",
|
||||
"width" => nil,
|
||||
"height" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -113,7 +117,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
|
|||
"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"
|
||||
"type" => "Link",
|
||||
"width" => nil,
|
||||
"height" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
@ -159,8 +160,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
{: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
|
||||
|
|
@ -446,7 +446,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"]
|
||||
|
|
@ -459,7 +459,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
|
||||
|
|
@ -473,7 +473,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"]
|
||||
|
|
|
|||
|
|
@ -409,7 +409,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
end
|
||||
|
||||
test "saving config which need pleroma reboot", %{conn: conn} do
|
||||
clear_config([:chat, :enabled], true)
|
||||
clear_config([:shout, :enabled], true)
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|
|
@ -417,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]}]}
|
||||
]
|
||||
}
|
||||
)
|
||||
|
|
@ -426,7 +426,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
%{
|
||||
"db" => [":enabled"],
|
||||
"group" => ":pleroma",
|
||||
"key" => ":chat",
|
||||
"key" => ":shout",
|
||||
"value" => [%{"tuple" => [":enabled", true]}]
|
||||
}
|
||||
],
|
||||
|
|
@ -454,7 +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
|
||||
clear_config([:chat, :enabled], true)
|
||||
clear_config([:shout, :enabled], true)
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|
|
@ -462,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]}]}
|
||||
]
|
||||
}
|
||||
)
|
||||
|
|
@ -471,7 +471,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
%{
|
||||
"db" => [":enabled"],
|
||||
"group" => ":pleroma",
|
||||
"key" => ":chat",
|
||||
"key" => ":shout",
|
||||
"value" => [%{"tuple" => [":enabled", true]}]
|
||||
}
|
||||
],
|
||||
|
|
|
|||
|
|
@ -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 =
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -411,7 +411,7 @@ 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)
|
||||
|
||||
|
|
|
|||
|
|
@ -168,6 +168,123 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
end
|
||||
end
|
||||
|
||||
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>]
|
||||
|
||||
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 "Hello World"</code></pre>]
|
||||
|
||||
code = ~s[ <div>\n </div>]
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == ~s[<pre><code><div>\n</div></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 "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>]
|
||||
|
||||
# strikethrough
|
||||
code = ~s[~~aaaa~~~]
|
||||
{result, [], []} = Utils.format_input(code, "text/markdown")
|
||||
assert result == ~s[<p><del>aaaa</del>~</p>]
|
||||
end
|
||||
end
|
||||
|
||||
describe "context_to_conversation_id" do
|
||||
test "creates a mapping object" do
|
||||
conversation_id = Utils.context_to_conversation_id("random context")
|
||||
|
|
|
|||
|
|
@ -519,7 +519,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
{:ok, activity} = CommonAPI.post(user, %{status: "hey :blank:"})
|
||||
|
||||
assert %{"blank" => url} = Object.normalize(activity).data["emoji"]
|
||||
assert url == "#{Pleroma.Web.base_url()}/emoji/blank.png"
|
||||
assert url == "#{Pleroma.Web.Endpoint.url()}/emoji/blank.png"
|
||||
end
|
||||
|
||||
test "it copies emoji from the subject of the parent post" do
|
||||
|
|
@ -539,8 +539,8 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
spoiler_text: ":joker_smile:"
|
||||
})
|
||||
|
||||
assert Object.normalize(reply_activity).data["emoji"][":joker_smile:"]
|
||||
refute Object.normalize(reply_activity).data["emoji"][":joker_disapprove:"]
|
||||
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
|
||||
|
|
@ -597,7 +597,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
|
||||
assert object.data["content"] == "<p><b>2hu</b></p>"
|
||||
assert object.data["source"] == post
|
||||
end
|
||||
|
||||
|
|
@ -827,13 +827,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
|
||||
|
|
@ -845,10 +849,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
|
||||
|
|
@ -859,7 +864,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
|
||||
|
|
@ -869,8 +874,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
|
||||
|
|
@ -884,7 +893,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
|
||||
|
|
@ -896,7 +905,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
|
||||
|
||||
|
|
|
|||
|
|
@ -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,7 +146,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"]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,10 +127,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...',
|
||||
|
|
|
|||
|
|
@ -217,7 +217,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
|
||||
|
|
|
|||
|
|
@ -514,11 +514,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
|
||||
|
|
@ -881,7 +881,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
|
||||
|
|
@ -892,7 +892,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)
|
||||
end
|
||||
|
||||
test "following with reblogs" do
|
||||
|
|
@ -910,7 +910,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
|
||||
|
|
@ -921,7 +921,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert [] ==
|
||||
conn
|
||||
|> get("/api/v1/timelines/home")
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "following / unfollowing errors", %{user: user, conn: conn} do
|
||||
|
|
|
|||
|
|
@ -214,7 +214,8 @@ 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
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ 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 %{
|
||||
|
|
@ -38,7 +38,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
|
||||
|
||||
|
|
|
|||
|
|
@ -140,7 +140,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
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ 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
|
||||
|
|
@ -61,7 +61,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,7 +72,7 @@ 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"]
|
||||
|
|
@ -87,8 +87,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 +97,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 +108,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,7 +119,7 @@ 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 =
|
||||
|
|
@ -136,18 +136,18 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|> 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
|
||||
|
|
@ -163,8 +163,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
|> 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
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
@ -81,6 +82,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
|
||||
|
||||
|
|
@ -1209,20 +1211,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"})
|
||||
|
||||
|
|
@ -1231,7 +1240,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
|
||||
|
|
@ -1252,13 +1272,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
|
||||
|
|
@ -1542,7 +1560,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
|
||||
|
||||
|
|
@ -1893,10 +1911,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
"visibility" => "local"
|
||||
})
|
||||
|
||||
local = Pleroma.Constants.as_local_public()
|
||||
local = Utils.as_local_public()
|
||||
|
||||
assert %{"content" => "cofe", "id" => id, "visibility" => "local"} =
|
||||
json_response(conn_one, 200)
|
||||
json_response_and_validate_schema(conn_one, 200)
|
||||
|
||||
assert %Activity{id: ^id, data: %{"to" => [^local]}} = Activity.get_by_id(id)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -905,10 +905,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", %{
|
||||
|
|
@ -922,7 +922,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)
|
||||
|
|
@ -939,7 +939,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)
|
||||
|
|
@ -951,10 +951,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
|
||||
|
|
@ -966,11 +966,11 @@ 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
|
||||
|
|
|
|||
85
test/pleroma/web/mastodon_api/masto_fe_controller_test.exs
Normal file
85
test/pleroma/web/mastodon_api/masto_fe_controller_test.exs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.MastoFEControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.User
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do: clear_config([:instance, :public])
|
||||
|
||||
test "put settings", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, insert(:oauth_token, user: user, scopes: ["write:accounts"]))
|
||||
|> put("/api/web/settings", %{"data" => %{"programming" => "socks"}})
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
assert user.mastofe_settings == %{"programming" => "socks"}
|
||||
end
|
||||
|
||||
describe "index/2 redirections" do
|
||||
setup %{conn: conn} do
|
||||
session_opts = [
|
||||
store: :cookie,
|
||||
key: "_test",
|
||||
signing_salt: "cooldude"
|
||||
]
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> Plug.Session.call(Plug.Session.init(session_opts))
|
||||
|> fetch_session()
|
||||
|
||||
test_path = "/web/statuses/test"
|
||||
%{conn: conn, path: test_path}
|
||||
end
|
||||
|
||||
test "redirects not logged-in users to the login page", %{conn: conn, path: path} do
|
||||
conn = get(conn, path)
|
||||
|
||||
assert conn.status == 302
|
||||
assert redirected_to(conn) == "/web/login"
|
||||
end
|
||||
|
||||
test "redirects not logged-in users to the login page on private instances", %{
|
||||
conn: conn,
|
||||
path: path
|
||||
} do
|
||||
clear_config([:instance, :public], false)
|
||||
|
||||
conn = get(conn, path)
|
||||
|
||||
assert conn.status == 302
|
||||
assert redirected_to(conn) == "/web/login"
|
||||
end
|
||||
|
||||
test "does not redirect logged in users to the login page", %{conn: conn, path: path} do
|
||||
{:ok, app} = Pleroma.Web.MastodonAPI.AuthController.local_mastofe_app()
|
||||
token = insert(:oauth_token, app: app, scopes: ["read"])
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, token.user)
|
||||
|> assign(:token, token)
|
||||
|> get(path)
|
||||
|
||||
assert conn.status == 200
|
||||
end
|
||||
|
||||
test "saves referer path to session", %{conn: conn, path: path} do
|
||||
conn = get(conn, path)
|
||||
return_to = Plug.Conn.get_session(conn, :return_to)
|
||||
|
||||
assert return_to == path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -468,6 +468,23 @@ 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 "follow requests counter" do
|
||||
|
|
@ -562,12 +579,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
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)
|
||||
|
||||
_ ->
|
||||
|
|
|
|||
|
|
@ -286,7 +286,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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -458,7 +459,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",
|
||||
|
|
@ -474,6 +477,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"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,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")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -182,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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -100,6 +100,6 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
|||
"check_password"
|
||||
]
|
||||
|
||||
assert expected_routes == Pleroma.Web.get_api_routes()
|
||||
assert expected_routes == Pleroma.Web.Router.get_api_routes()
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
# Copyright © 2017-2021 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, "shout: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
|
||||
clear_config([:instance, :chat_limit], 2)
|
||||
clear_config([:shout, :limit], 2)
|
||||
push(socket, "new_msg", %{"text" => "123"})
|
||||
refute_broadcast("new_msg", %{text: "123"})
|
||||
end
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -7,59 +7,10 @@ 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} =
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -25,11 +25,14 @@ 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)
|
||||
|
||||
|
|
@ -41,8 +44,14 @@ 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)
|
||||
|
||||
|
|
@ -70,7 +79,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
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
|
||||
|
|
@ -81,7 +90,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,
|
||||
|
|
@ -103,7 +112,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/healthcheck")
|
||||
|> json_response(503)
|
||||
|> json_response_and_validate_schema(503)
|
||||
|
||||
assert response == %{}
|
||||
end
|
||||
|
|
@ -116,7 +125,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/healthcheck")
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert %{
|
||||
"active" => _,
|
||||
|
|
@ -136,7 +145,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/healthcheck")
|
||||
|> json_response(503)
|
||||
|> json_response_and_validate_schema(503)
|
||||
|
||||
assert %{
|
||||
"active" => _,
|
||||
|
|
@ -155,8 +164,8 @@ 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()
|
||||
|
|
@ -171,8 +180,8 @@ 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)
|
||||
|
|
@ -252,54 +261,61 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
conn =
|
||||
conn
|
||||
|> assign(:token, nil)
|
||||
|> post("/api/pleroma/change_email")
|
||||
|> post(
|
||||
"/api/pleroma/change_email?#{
|
||||
URI.encode_query(%{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"
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_email?#{
|
||||
URI.encode_query(%{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"
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_email?#{URI.encode_query(%{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 = post(conn, "/api/pleroma/change_email?#{URI.encode_query(%{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
|
||||
conn =
|
||||
post(conn, "/api/pleroma/change_email", %{
|
||||
"password" => "test",
|
||||
"email" => ""
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_email?#{URI.encode_query(%{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 non unique email", %{
|
||||
|
|
@ -308,24 +324,28 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
post(conn, "/api/pleroma/change_email", %{
|
||||
"password" => "test",
|
||||
"email" => user.email
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_email?#{URI.encode_query(%{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"
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_email?#{
|
||||
URI.encode_query(%{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
|
||||
|
||||
|
|
@ -336,20 +356,35 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
conn =
|
||||
conn
|
||||
|> assign(:token, nil)
|
||||
|> post("/api/pleroma/change_password")
|
||||
|> post(
|
||||
"/api/pleroma/change_password?#{
|
||||
URI.encode_query(%{
|
||||
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", %{
|
||||
"password" => "hi",
|
||||
"new_password" => "newpass",
|
||||
"new_password_confirmation" => "newpass"
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_password?#{
|
||||
URI.encode_query(%{
|
||||
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",
|
||||
|
|
@ -357,13 +392,18 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
conn: conn
|
||||
} do
|
||||
conn =
|
||||
post(conn, "/api/pleroma/change_password", %{
|
||||
"password" => "test",
|
||||
"new_password" => "newpass",
|
||||
"new_password_confirmation" => "notnewpass"
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_password?#{
|
||||
URI.encode_query(%{
|
||||
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
|
||||
|
|
@ -372,13 +412,14 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
conn: conn
|
||||
} do
|
||||
conn =
|
||||
post(conn, "/api/pleroma/change_password", %{
|
||||
"password" => "test",
|
||||
"new_password" => "",
|
||||
"new_password_confirmation" => ""
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_password?#{
|
||||
URI.encode_query(%{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
|
||||
|
|
@ -388,13 +429,18 @@ 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"
|
||||
})
|
||||
post(
|
||||
conn,
|
||||
"/api/pleroma/change_password?#{
|
||||
URI.encode_query(%{
|
||||
password: "test",
|
||||
new_password: "newpass",
|
||||
new_password_confirmation: "newpass"
|
||||
})
|
||||
}"
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == %{"status" => "success"}
|
||||
assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
|
||||
fetched_user = User.get_cached_by_id(user.id)
|
||||
assert Pleroma.Password.Pbkdf2.verify_pass("newpass", fetched_user.password_hash) == true
|
||||
end
|
||||
|
|
@ -409,7 +455,7 @@ 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
|
||||
|
||||
|
|
@ -417,14 +463,16 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
for params <- [%{"password" => "hi"}, %{}] do
|
||||
ret_conn = post(conn, "/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"})
|
||||
conn = post(conn, "/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)
|
||||
refute user.is_active
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
|||
|
||||
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()
|
||||
Pleroma.Web.Endpoint.url()
|
||||
}/.well-known/webfinger?resource={uri}" type="application/xrd+xml" /></XRD>)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
defmodule Pleroma.Factory do
|
||||
use ExMachina.Ecto, repo: Pleroma.Repo
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
|
||||
|
|
@ -41,23 +44,27 @@ defmodule Pleroma.Factory do
|
|||
|
||||
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)
|
||||
|
|
@ -184,8 +191,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
|
||||
|
|
@ -221,6 +228,45 @@ 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 note_activity_factory(attrs \\ %{}) do
|
||||
user = attrs[:user] || insert(:user)
|
||||
note = attrs[:note] || insert(:note, user: user)
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
@ -905,6 +917,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{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue