Merge branch 'develop' into tests/mastodon_api_controller.ex
[akkoma] / test / web / node_info_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.NodeInfoTest do
6 use Pleroma.Web.ConnCase
7
8 import Pleroma.Factory
9
10 test "GET /.well-known/nodeinfo", %{conn: conn} do
11 links =
12 conn
13 |> get("/.well-known/nodeinfo")
14 |> json_response(200)
15 |> Map.fetch!("links")
16
17 Enum.each(links, fn link ->
18 href = Map.fetch!(link, "href")
19
20 conn
21 |> get(href)
22 |> json_response(200)
23 end)
24 end
25
26 test "nodeinfo shows staff accounts", %{conn: conn} do
27 moderator = insert(:user, %{local: true, info: %{is_moderator: true}})
28 admin = insert(:user, %{local: true, info: %{is_admin: true}})
29
30 conn =
31 conn
32 |> get("/nodeinfo/2.1.json")
33
34 assert result = json_response(conn, 200)
35
36 assert moderator.ap_id in result["metadata"]["staffAccounts"]
37 assert admin.ap_id in result["metadata"]["staffAccounts"]
38 end
39
40 test "nodeinfo shows restricted nicknames", %{conn: conn} do
41 conn =
42 conn
43 |> get("/nodeinfo/2.1.json")
44
45 assert result = json_response(conn, 200)
46
47 assert Pleroma.Config.get([Pleroma.User, :restricted_nicknames]) ==
48 result["metadata"]["restrictedNicknames"]
49 end
50
51 test "returns software.repository field in nodeinfo 2.1", %{conn: conn} do
52 conn
53 |> get("/.well-known/nodeinfo")
54 |> json_response(200)
55
56 conn =
57 conn
58 |> get("/nodeinfo/2.1.json")
59
60 assert result = json_response(conn, 200)
61 assert Pleroma.Application.repository() == result["software"]["repository"]
62 end
63
64 test "it returns the safe_dm_mentions feature if enabled", %{conn: conn} do
65 option = Pleroma.Config.get([:instance, :safe_dm_mentions])
66 Pleroma.Config.put([:instance, :safe_dm_mentions], true)
67
68 response =
69 conn
70 |> get("/nodeinfo/2.1.json")
71 |> json_response(:ok)
72
73 assert "safe_dm_mentions" in response["metadata"]["features"]
74
75 Pleroma.Config.put([:instance, :safe_dm_mentions], false)
76
77 response =
78 conn
79 |> get("/nodeinfo/2.1.json")
80 |> json_response(:ok)
81
82 refute "safe_dm_mentions" in response["metadata"]["features"]
83
84 Pleroma.Config.put([:instance, :safe_dm_mentions], option)
85 end
86
87 test "it shows MRF transparency data if enabled", %{conn: conn} do
88 config = Pleroma.Config.get([:instance, :rewrite_policy])
89 Pleroma.Config.put([:instance, :rewrite_policy], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
90
91 option = Pleroma.Config.get([:instance, :mrf_transparency])
92 Pleroma.Config.put([:instance, :mrf_transparency], true)
93
94 simple_config = %{"reject" => ["example.com"]}
95 Pleroma.Config.put(:mrf_simple, simple_config)
96
97 response =
98 conn
99 |> get("/nodeinfo/2.1.json")
100 |> json_response(:ok)
101
102 assert response["metadata"]["federation"]["mrf_simple"] == simple_config
103
104 Pleroma.Config.put([:instance, :rewrite_policy], config)
105 Pleroma.Config.put([:instance, :mrf_transparency], option)
106 Pleroma.Config.put(:mrf_simple, %{})
107 end
108
109 test "it performs exclusions from MRF transparency data if configured", %{conn: conn} do
110 config = Pleroma.Config.get([:instance, :rewrite_policy])
111 Pleroma.Config.put([:instance, :rewrite_policy], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
112
113 option = Pleroma.Config.get([:instance, :mrf_transparency])
114 Pleroma.Config.put([:instance, :mrf_transparency], true)
115
116 exclusions = Pleroma.Config.get([:instance, :mrf_transparency_exclusions])
117 Pleroma.Config.put([:instance, :mrf_transparency_exclusions], ["other.site"])
118
119 simple_config = %{"reject" => ["example.com", "other.site"]}
120 expected_config = %{"reject" => ["example.com"]}
121
122 Pleroma.Config.put(:mrf_simple, simple_config)
123
124 response =
125 conn
126 |> get("/nodeinfo/2.1.json")
127 |> json_response(:ok)
128
129 assert response["metadata"]["federation"]["mrf_simple"] == expected_config
130 assert response["metadata"]["federation"]["exclusions"] == true
131
132 Pleroma.Config.put([:instance, :rewrite_policy], config)
133 Pleroma.Config.put([:instance, :mrf_transparency], option)
134 Pleroma.Config.put([:instance, :mrf_transparency_exclusions], exclusions)
135 Pleroma.Config.put(:mrf_simple, %{})
136 end
137 end