From 4a6855d9eedf07159520b2205c554c891e70c7d4 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sun, 1 Jan 2017 03:10:08 +0300
Subject: Provide plaintext representations of content/cw in MastoAPI
---
test/web/mastodon_api/status_view_test.exs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 8db92ac16..db2fdc2f6 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -101,7 +101,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
muted: false,
pinned: false,
sensitive: false,
- spoiler_text: note.data["object"]["summary"],
+ spoiler_text: HtmlSanitizeEx.basic_html(note.data["object"]["summary"]),
visibility: "public",
media_attachments: [],
mentions: [],
@@ -126,7 +126,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
],
pleroma: %{
local: true,
- conversation_id: convo_id
+ conversation_id: convo_id,
+ content: %{"text/plain" => HtmlSanitizeEx.strip_tags(note.data["object"]["content"])},
+ spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(note.data["object"]["summary"])}
}
}
--
cgit v1.2.3
From 6be0ab1e55e2e9f0c1e6f937631cfd3da899bc79 Mon Sep 17 00:00:00 2001
From: lain
Date: Sun, 2 Dec 2018 17:35:32 +0100
Subject: Hide network in ap.
---
.../activity_pub/activity_pub_controller_test.exs | 28 ++++++++++++++++++++++
1 file changed, 28 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 1c24b348c..d8c5badb8 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -145,6 +145,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert result["first"]["orderedItems"] == [user.ap_id]
end
+ test "it returns returns empty if the user has 'hide_network' set", %{conn: conn} do
+ user = insert(:user)
+ user_two = insert(:user, %{info: %{hide_network: true}})
+ User.follow(user, user_two)
+
+ result =
+ conn
+ |> get("/users/#{user_two.nickname}/followers")
+ |> json_response(200)
+
+ assert result["first"]["orderedItems"] == []
+ assert result["totalItems"] == 1
+ end
+
test "it works for more than 10 users", %{conn: conn} do
user = insert(:user)
@@ -186,6 +200,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert result["first"]["orderedItems"] == [user_two.ap_id]
end
+ test "it returns returns empty if the user has 'hide_network' set", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_network: true}})
+ user_two = insert(:user)
+ User.follow(user, user_two)
+
+ result =
+ conn
+ |> get("/users/#{user.nickname}/following")
+ |> json_response(200)
+
+ assert result["first"]["orderedItems"] == []
+ assert result["totalItems"] == 1
+ end
+
test "it works for more than 10 users", %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From 2a639de9b30aacd44b8ba648b872ad6cb7ab1d6c Mon Sep 17 00:00:00 2001
From: lain
Date: Sun, 2 Dec 2018 17:48:00 +0100
Subject: MastodonApi: Implement hide_network.
---
.../mastodon_api/mastodon_api_controller_test.exs | 24 ++++++++++++++++++++++
1 file changed, 24 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 7042a6ace..9333b709e 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1002,6 +1002,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert id == to_string(user.id)
end
+ test "getting followers, hide_network", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user, %{info: %{hide_network: true}})
+ {:ok, user} = User.follow(user, other_user)
+
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{other_user.id}/followers")
+
+ assert [] == json_response(conn, 200)
+ end
+
test "getting following", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
@@ -1015,6 +1027,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert id == to_string(other_user.id)
end
+ test "getting following, hide_network", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_network: true}})
+ other_user = insert(:user)
+ {:ok, user} = User.follow(user, other_user)
+
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/following")
+
+ assert [] == json_response(conn, 200)
+ end
+
test "following / unfollowing a user", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
--
cgit v1.2.3
From 8c9a4e8b403d4575400f239dd87dab2ae7ecec6c Mon Sep 17 00:00:00 2001
From: lain
Date: Sun, 2 Dec 2018 18:14:13 +0100
Subject: TwitterAPI: Implement hide_network.
---
.../twitter_api/twitter_api_controller_test.exs | 59 ++++++++++++++++++++++
1 file changed, 59 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 89c176da7..8655105f3 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -855,6 +855,48 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
result = json_response(conn, 200)
assert Enum.sort(expected) == Enum.sort(result)
end
+
+ test "it returns a given user's followers with user_id", %{conn: conn} do
+ user = insert(:user)
+ follower_one = insert(:user)
+ follower_two = insert(:user)
+ not_follower = insert(:user)
+
+ {:ok, follower_one} = User.follow(follower_one, user)
+ {:ok, follower_two} = User.follow(follower_two, user)
+
+ conn =
+ conn
+ |> assign(:user, not_follower)
+ |> get("/api/statuses/followers", %{"user_id" => user.id})
+
+ assert MapSet.equal?(
+ MapSet.new(json_response(conn, 200)),
+ MapSet.new(
+ UserView.render("index.json", %{
+ users: [follower_one, follower_two],
+ for: not_follower
+ })
+ )
+ )
+ end
+
+ test "it returns empty for a hidden network", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_network: true}})
+ follower_one = insert(:user)
+ follower_two = insert(:user)
+ not_follower = insert(:user)
+
+ {:ok, follower_one} = User.follow(follower_one, user)
+ {:ok, follower_two} = User.follow(follower_two, user)
+
+ conn =
+ conn
+ |> assign(:user, not_follower)
+ |> get("/api/statuses/followers", %{"user_id" => user.id})
+
+ assert [] == json_response(conn, 200)
+ end
end
describe "GET /api/statuses/friends" do
@@ -899,6 +941,23 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
)
end
+ test "it returns empty for a hidden network", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_network: true}})
+ followed_one = insert(:user)
+ followed_two = insert(:user)
+ not_followed = insert(:user)
+
+ {:ok, user} = User.follow(user, followed_one)
+ {:ok, user} = User.follow(user, followed_two)
+
+ conn =
+ conn
+ |> assign(:user, not_followed)
+ |> get("/api/statuses/friends", %{"user_id" => user.id})
+
+ assert [] == json_response(conn, 200)
+ end
+
test "it returns a given user's friends with screen_name", %{conn: conn} do
user = insert(:user)
followed_one = insert(:user)
--
cgit v1.2.3
From ec34de0c1fd58942c8ecefddef92696750b70420 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Sun, 2 Dec 2018 16:58:38 +0300
Subject: WebSub fix test
---
test/web/websub/websub_test.exs | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
(limited to 'test')
diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs
index da7bc9112..0b8bfda2d 100644
--- a/test/web/websub/websub_test.exs
+++ b/test/web/websub/websub_test.exs
@@ -10,6 +10,18 @@ defmodule Pleroma.Web.WebsubTest do
alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription}
import Pleroma.Factory
alias Pleroma.Web.Router.Helpers
+ import Tesla.Mock
+
+ setup do
+ mock fn
+ %{method: :get, url: "https://mastodon.social/users/lambadalambda.atom"} ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}
+ %{method: :post, url: "http://example.org/needs_refresh"} ->
+ %Tesla.Env{status: 200, body: ""}
+ end
+
+ :ok
+ end
test "a verification of a request that is accepted" do
sub = insert(:websub_subscription)
@@ -26,8 +38,8 @@ defmodule Pleroma.Web.WebsubTest do
assert String.to_integer(seconds) > 0
{:ok,
- %HTTPoison.Response{
- status_code: 200,
+ %Tesla.Env{
+ status: 200,
body: challenge
}}
end
@@ -41,8 +53,8 @@ defmodule Pleroma.Web.WebsubTest do
getter = fn _path, _headers, _options ->
{:ok,
- %HTTPoison.Response{
- status_code: 500,
+ %Tesla.Env{
+ status: 500,
body: ""
}}
end
@@ -113,12 +125,7 @@ defmodule Pleroma.Web.WebsubTest do
test "discovers the hub and canonical url" do
topic = "https://mastodon.social/users/lambadalambda.atom"
- getter = fn ^topic ->
- doc = File.read!("test/fixtures/lambadalambda.atom")
- {:ok, %{status_code: 200, body: doc}}
- end
-
- {:ok, discovered} = Websub.gather_feed_data(topic, getter)
+ {:ok, discovered} = Websub.gather_feed_data(topic)
expected = %{
"hub" => "https://mastodon.social/api/push",
@@ -158,7 +165,7 @@ defmodule Pleroma.Web.WebsubTest do
websub.id
)
- {:ok, %{status_code: 202}}
+ {:ok, %{status: 202}}
end
task = Task.async(fn -> Websub.request_subscription(websub, poster) end)
@@ -209,6 +216,7 @@ defmodule Pleroma.Web.WebsubTest do
insert(:websub_client_subscription, %{
valid_until: NaiveDateTime.add(now, 2 * day),
topic: "http://example.org/still_good",
+ hub: "http://example.org/still_good",
state: "accepted"
})
@@ -216,6 +224,7 @@ defmodule Pleroma.Web.WebsubTest do
insert(:websub_client_subscription, %{
valid_until: NaiveDateTime.add(now, day - 100),
topic: "http://example.org/needs_refresh",
+ hub: "http://example.org/needs_refresh",
state: "accepted"
})
--
cgit v1.2.3
From 87109482f336422186981c80eb3c3023637f09e8 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Sun, 2 Dec 2018 17:08:36 +0300
Subject: status_code -> status
---
test/web/websub/websub_test.exs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs
index 0b8bfda2d..f3d2da81a 100644
--- a/test/web/websub/websub_test.exs
+++ b/test/web/websub/websub_test.exs
@@ -184,7 +184,7 @@ defmodule Pleroma.Web.WebsubTest do
websub = insert(:websub_client_subscription, %{hub: hub, topic: topic})
poster = fn ^hub, {:form, _data}, _headers ->
- {:ok, %{status_code: 202}}
+ {:ok, %{status: 202}}
end
{:error, websub} = Websub.request_subscription(websub, poster, 1000)
@@ -193,7 +193,7 @@ defmodule Pleroma.Web.WebsubTest do
websub = insert(:websub_client_subscription, %{hub: hub, topic: topic})
poster = fn ^hub, {:form, _data}, _headers ->
- {:ok, %{status_code: 400}}
+ {:ok, %{status: 400}}
end
{:error, websub} = Websub.request_subscription(websub, poster, 1000)
--
cgit v1.2.3
From c508d41c349c3034211f41281cfe60c70a020575 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Sun, 2 Dec 2018 18:17:26 +0300
Subject: add http requests mock
---
test/support/http_request_mock.ex | 80 +++++++++++++++++++++++++++++++++++++++
test/web/salmon/salmon_test.exs | 5 +++
test/web/websub/websub_test.exs | 8 +---
3 files changed, 86 insertions(+), 7 deletions(-)
create mode 100644 test/support/http_request_mock.ex
(limited to 'test')
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
new file mode 100644
index 000000000..c3501c6cf
--- /dev/null
+++ b/test/support/http_request_mock.ex
@@ -0,0 +1,80 @@
+defmodule HttpRequestMock do
+ def request(
+ %Tesla.Env{
+ url: url,
+ method: method,
+ headers: headers,
+ query: query,
+ body: body
+ } = _env
+ ) do
+ with {:ok, res} <- apply(__MODULE__, method, [url, query, body, headers]) do
+ res
+ else
+ {_, r} = error ->
+ IO.warn(r)
+ error
+ end
+ end
+
+ # GET Requests
+ #
+ def get(url, query \\ [], body \\ [], headers \\ [])
+
+ def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _, _, _) do
+ {:ok, %Tesla.Env{
+ status: 200,
+ body: File.read!(
+ "test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
+ )}}
+ end
+
+ def get("https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211", _, _, _) do
+ {:ok, %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")}}
+ end
+
+ def get("http://social.heldscal.la/.well-known/host-meta", _, _, _) do
+ {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/httpoison_mock/social.heldscal.la_host_meta")}}
+ end
+
+ def get("https://social.heldscal.la/.well-known/host-meta", _, _, _) do
+ {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/httpoison_mock/social.heldscal.la_host_meta")}}
+ end
+
+ def get("https://mastodon.social/users/lambadalambda.atom", _, _, _) do
+ {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}}
+ end
+
+ def get("https://social.heldscal.la/user/23211", _, _, [Accept: "application/activity+json"]) do
+ {:ok,
+ Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)
+ }
+ end
+
+ def get(url, query, body, headers) do
+ {:error,
+ "Not implemented the mock response for get #{inspect(url)}, #{query}, #{inspect(body)}, #{
+ inspect(headers)
+ }"}
+ end
+
+
+ # POST Requests
+ #
+
+ def post(url, query \\ [], body \\ [], headers \\ [])
+
+ def post("http://example.org/needs_refresh", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: ""
+ }}
+ end
+
+ def post(url, _query, _body, _headers) do
+ {:error, "Not implemented the mock response for post #{inspect(url)}"}
+ end
+end
diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs
index 1b39b4b2d..3285c11f0 100644
--- a/test/web/salmon/salmon_test.exs
+++ b/test/web/salmon/salmon_test.exs
@@ -3,6 +3,7 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
alias Pleroma.Web.Salmon
alias Pleroma.{Repo, Activity, User}
import Pleroma.Factory
+ import Tesla.Mock
@magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
@@ -10,6 +11,10 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
@magickey_friendica "RSA.AMwa8FUs2fWEjX0xN7yRQgegQffhBpuKNC6fa5VNSVorFjGZhRrlPMn7TQOeihlc9lBz2OsHlIedbYn2uJ7yCs0.AQAB"
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
test "decodes a salmon" do
{:ok, salmon} = File.read("test/fixtures/salmon.xml")
{:ok, doc} = Salmon.decode_and_validate(@magickey, salmon)
diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs
index f3d2da81a..47d1a88e1 100644
--- a/test/web/websub/websub_test.exs
+++ b/test/web/websub/websub_test.exs
@@ -13,13 +13,7 @@ defmodule Pleroma.Web.WebsubTest do
import Tesla.Mock
setup do
- mock fn
- %{method: :get, url: "https://mastodon.social/users/lambadalambda.atom"} ->
- %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}
- %{method: :post, url: "http://example.org/needs_refresh"} ->
- %Tesla.Env{status: 200, body: ""}
- end
-
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok
end
--
cgit v1.2.3
From 6cfdc11e32faf84263e4c5d7b15f193ba1b832ae Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Sun, 2 Dec 2018 22:05:28 +0300
Subject: update test
---
.../httpoison_mock/framatube.org_host_meta | 2 +
test/fixtures/httpoison_mock/gerzilla.de_host_meta | 10 +
.../fixtures/httpoison_mock/gnusocial.de_host_meta | 2 +
test/support/http_request_mock.ex | 374 ++++++++++++++++++++-
test/web/ostatus/ostatus_test.exs | 6 +
test/web/salmon/salmon_test.exs | 1 +
test/web/web_finger/web_finger_test.exs | 6 +
7 files changed, 383 insertions(+), 18 deletions(-)
create mode 100644 test/fixtures/httpoison_mock/framatube.org_host_meta
create mode 100644 test/fixtures/httpoison_mock/gerzilla.de_host_meta
create mode 100644 test/fixtures/httpoison_mock/gnusocial.de_host_meta
(limited to 'test')
diff --git a/test/fixtures/httpoison_mock/framatube.org_host_meta b/test/fixtures/httpoison_mock/framatube.org_host_meta
new file mode 100644
index 000000000..91516ff6d
--- /dev/null
+++ b/test/fixtures/httpoison_mock/framatube.org_host_meta
@@ -0,0 +1,2 @@
+
+framatube.org Resource Descriptor
diff --git a/test/fixtures/httpoison_mock/gerzilla.de_host_meta b/test/fixtures/httpoison_mock/gerzilla.de_host_meta
new file mode 100644
index 000000000..fae8f37eb
--- /dev/null
+++ b/test/fixtures/httpoison_mock/gerzilla.de_host_meta
@@ -0,0 +1,10 @@
+
+
+ gerzilla.de
+
+
+
+
+
diff --git a/test/fixtures/httpoison_mock/gnusocial.de_host_meta b/test/fixtures/httpoison_mock/gnusocial.de_host_meta
new file mode 100644
index 000000000..a4affb102
--- /dev/null
+++ b/test/fixtures/httpoison_mock/gnusocial.de_host_meta
@@ -0,0 +1,2 @@
+
+gnusocial.de Resource Descriptor
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index c3501c6cf..64c3d11b3 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -1,4 +1,6 @@
defmodule HttpRequestMock do
+ require Logger
+
def request(
%Tesla.Env{
url: url,
@@ -12,7 +14,7 @@ defmodule HttpRequestMock do
res
else
{_, r} = error ->
- IO.warn(r)
+ Logger.warn(r)
error
end
end
@@ -21,46 +23,382 @@ defmodule HttpRequestMock do
#
def get(url, query \\ [], body \\ [], headers \\ [])
+ def get("https://pleroma.soykaf.com/users/lain/feed.atom", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml"
+ )
+ }}
+ end
+
+ def get(url, _, _, Accept: "application/xrd+xml,application/jrd+json")
+ when url in [
+ "https://pleroma.soykaf.com/.well-known/webfinger?resource=acct:https://pleroma.soykaf.com/users/lain",
+ "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain"
+ ] do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml")
+ }}
+ end
+
+ def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml"
+ )
+ }}
+ end
+
+ def get(
+ "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",
+ _,
+ _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml")
+ }}
+ end
+
+ def get("https://shitposter.club/notice/2827873", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body:
+ File.read!("test/fixtures/httpoison_mock/https___shitposter.club_notice_2827873.html")
+ }}
+ end
+
+ def get("https://shitposter.club/api/statuses/show/2827873.atom", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml"
+ )
+ }}
+ end
+
+ def get("https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b", _, _, _) do
+ {:ok, %Tesla.Env{status: 200}}
+ end
+
+ def get("https://shitposter.club/api/statuses/user_timeline/5381.atom", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/spc_5381.atom")
+ }}
+ end
+
+ def get(
+ "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",
+ _,
+ _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/spc_5381_xrd.xml")
+ }}
+ end
+
+ def get("http://shitposter.club/.well-known/host-meta", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/shitposter.club_host_meta")
+ }}
+ end
+
+ def get("https://shitposter.club/api/statuses/show/7369654.atom", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/7369654.atom")
+ }}
+ end
+
+ def get("https://shitposter.club/notice/4027863", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/7369654.html")
+ }}
+ end
+
+ def get("https://social.sakamoto.gq/users/eal/feed.atom", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/sakamoto_eal_feed.atom")
+ }}
+ end
+
+ def get("http://social.sakamoto.gq/.well-known/host-meta", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/social.sakamoto.gq_host_meta")
+ }}
+ end
+
+ def get(
+ "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",
+ _,
+ _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml")
+ }}
+ end
+
+ def get("https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056", _, _,
+ Accept: "application/atom+xml"
+ ) do
+ {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/httpoison_mock/sakamoto.atom")}}
+ end
+
+ def get("http://mastodon.social/.well-known/host-meta", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/mastodon.social_host_meta")
+ }}
+ end
+
+ def get(
+ "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",
+ _,
+ _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml"
+ )
+ }}
+ end
+
+ def get("http://gs.example.org/.well-known/host-meta", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/gs.example.org_host_meta")
+ }}
+ end
+
+ def get(
+ "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",
+ _,
+ _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml"
+ )
+ }}
+ end
+
+ def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml"
+ )
+ }}
+ end
+
+ def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml"
+ )
+ }}
+ end
+
+ def get("http://squeet.me/.well-known/host-meta", _, _, _) do
+ {:ok,
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/httpoison_mock/squeet.me_host_meta")}}
+ end
+
+ def get("https://squeet.me/xrd?uri=lain@squeet.me", _, _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml")
+ }}
+ end
+
+ def get(
+ "https://social.heldscal.la/.well-known/webfinger?resource=shp@social.heldscal.la",
+ _,
+ _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml")
+ }}
+ end
+
+ def get("http://framatube.org/.well-known/host-meta", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/framatube.org_host_meta")
+ }}
+ end
+
+ def get("http://framatube.org/main/xrd?uri=framasoft@framatube.org", _, _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/json"}],
+ body: File.read!("test/fixtures/httpoison_mock/framasoft@framatube.org.json")
+ }}
+ end
+
+ def get("http://gnusocial.de/.well-known/host-meta", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/gnusocial.de_host_meta")
+ }}
+ end
+
+ def get("http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de", _, _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/winterdienst_webfinger.json")
+ }}
+ end
+
+ def get("http://status.alpicola.com/.well-known/host-meta", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/status.alpicola.com_host_meta")
+ }}
+ end
+
+ def get("http://macgirvin.com/.well-known/host-meta", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/macgirvin.com_host_meta")
+ }}
+ end
+
+ def get("http://gerzilla.de/.well-known/host-meta", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/gerzilla.de_host_meta")
+ }}
+ end
+
+ def get("https://gerzilla.de/xrd/?uri=kaniini@gerzilla.de", _, _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-type", "application/json"}],
+ body: File.read!("test/fixtures/httpoison_mock/kaniini@gerzilla.de.json")
+ }}
+ end
+
def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _, _, _) do
- {:ok, %Tesla.Env{
- status: 200,
- body: File.read!(
- "test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
- )}}
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
+ )
+ }}
end
- def get("https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211", _, _, _) do
- {:ok, %Tesla.Env{
- status: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")}}
+ def get(
+ "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
+ _,
+ _,
+ _
+ ) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")
+ }}
end
def get("http://social.heldscal.la/.well-known/host-meta", _, _, _) do
- {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/httpoison_mock/social.heldscal.la_host_meta")}}
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/social.heldscal.la_host_meta")
+ }}
end
def get("https://social.heldscal.la/.well-known/host-meta", _, _, _) do
- {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/httpoison_mock/social.heldscal.la_host_meta")}}
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/social.heldscal.la_host_meta")
+ }}
end
def get("https://mastodon.social/users/lambadalambda.atom", _, _, _) do
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}}
end
- def get("https://social.heldscal.la/user/23211", _, _, [Accept: "application/activity+json"]) do
- {:ok,
- Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)
- }
+ def get("https://social.heldscal.la/user/23211", _, _, Accept: "application/activity+json") do
+ {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
end
def get(url, query, body, headers) do
{:error,
"Not implemented the mock response for get #{inspect(url)}, #{query}, #{inspect(body)}, #{
- inspect(headers)
+ inspect(headers)
}"}
end
-
# POST Requests
#
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index 32bf6691b..83525456b 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -5,6 +5,12 @@ defmodule Pleroma.Web.OStatusTest do
alias Pleroma.{Object, Repo, User, Activity}
import Pleroma.Factory
import ExUnit.CaptureLog
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
test "don't insert create notes twice" do
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs
index 3285c11f0..23ccc038e 100644
--- a/test/web/salmon/salmon_test.exs
+++ b/test/web/salmon/salmon_test.exs
@@ -15,6 +15,7 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok
end
+
test "decodes a salmon" do
{:ok, salmon} = File.read("test/fixtures/salmon.xml")
{:ok, doc} = Salmon.decode_and_validate(@magickey, salmon)
diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs
index 28d429565..32eff9b7c 100644
--- a/test/web/web_finger/web_finger_test.exs
+++ b/test/web/web_finger/web_finger_test.exs
@@ -2,6 +2,12 @@ defmodule Pleroma.Web.WebFingerTest do
use Pleroma.DataCase
alias Pleroma.Web.WebFinger
import Pleroma.Factory
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
describe "host meta" do
test "returns a link to the xml lrdd" do
--
cgit v1.2.3
From 80bfdb4e7d3e339a1e47330c0de0fe7af9c00ab1 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Mon, 3 Dec 2018 18:53:22 +0300
Subject: update test
---
test/support/http_request_mock.ex | 120 ++++++++++++++++++++++++++
test/web/activity_pub/activity_pub_test.exs | 6 ++
test/web/activity_pub/transmogrifier_test.exs | 7 ++
3 files changed, 133 insertions(+)
(limited to 'test')
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index 64c3d11b3..4a4566e84 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -23,6 +23,126 @@ defmodule HttpRequestMock do
#
def get(url, query \\ [], body \\ [], headers \\ [])
+ def get("https://prismo.news/@mxb", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___prismo.news__mxb.json")
+ }}
+ end
+
+ def get("https://hubzilla.example.org/channel/kaniini",
+ _, _, [Accept: "application/activity+json"]) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/kaniini@hubzilla.example.org.json")
+ }}
+ end
+
+ def get("https://niu.moe/users/rye", _, _, [Accept: "application/activity+json"]) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/rye.json")
+ }}
+ end
+
+ def get("http://mastodon.example.org/users/admin/statuses/100787282858396771", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!(
+ "test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json"
+ )
+ }}
+ end
+
+ def get("https://puckipedia.com/", _, _, [Accept: "application/activity+json"]) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/puckipedia.com.json")
+ }}
+ end
+
+
+ def get("https://peertube.moe/accounts/7even", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/7even.json")
+ }}
+ end
+
+ def get("https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/peertube.moe-vid.json")
+ }}
+ end
+
+ def get("https://baptiste.gelez.xyz/@/BaptisteGelez", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/baptiste.gelex.xyz-user.json")
+ }}
+ end
+
+ def get("https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/baptiste.gelex.xyz-article.json")
+ }}
+ end
+
+
+ def get("http://mastodon.example.org/users/admin", _, _, [Accept: "application/activity+json"]) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/admin@mastdon.example.org.json")
+ }}
+ end
+
+ def get("http://mastodon.example.org/@admin/99541947525187367",
+ _, _, [Accept: "application/activity+json"]) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/mastodon-note-object.json")
+ }}
+ end
+
+ def get("https://shitposter.club/notice/7369654", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/7369654.html")
+ }}
+ end
+
+ def get("https://mstdn.io/users/mayuutann", _, _, [Accept: "application/activity+json"]) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/mayumayu.json")
+ }}
+ end
+
+ def get("https://mstdn.io/users/mayuutann/statuses/99568293732299394",
+ _, _, [Accept: "application/activity+json"]) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/mayumayupost.json")
+ }}
+ end
+
+
def get("https://pleroma.soykaf.com/users/lain/feed.atom", _, _, _) do
{:ok,
%Tesla.Env{
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 1d561d38d..90f11ecd4 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -7,6 +7,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
alias Pleroma.Builders.ActivityBuilder
import Pleroma.Factory
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
describe "building a user from his ap id" do
test "it returns a user" do
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index e74b8f9a1..faba80354 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -12,6 +12,13 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
import Pleroma.Factory
alias Pleroma.Web.CommonAPI
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
describe "handle_incoming" do
test "it ignores an incoming notice if we already have it" do
activity = insert(:note_activity)
--
cgit v1.2.3
From 7ec64ac33f52d2f5072b56f2f8eb5e9ce498e00f Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Mon, 3 Dec 2018 21:37:55 +0300
Subject: update test
---
test/support/http_request_mock.ex | 61 ++++++++++++++++------
test/web/http_sigs/http_sig_test.exs | 6 +++
.../mastodon_api/mastodon_api_controller_test.exs | 6 +++
test/web/mastodon_api/status_view_test.exs | 6 +++
test/web/ostatus/activity_representer_test.exs | 6 +++
test/web/ostatus/ostatus_controller_test.exs | 6 +++
6 files changed, 75 insertions(+), 16 deletions(-)
(limited to 'test')
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index 4a4566e84..f44e9a1c6 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -23,6 +23,34 @@ defmodule HttpRequestMock do
#
def get(url, query \\ [], body \\ [], headers \\ [])
+ def get("http://gs.example.org:4040/index.php/user/1", _, _, Accept: "application/activity+json") do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: "{\"id\": 1}"
+ }}
+ end
+
+ def get("https://squeet.me/xrd/?uri=lain@squeet.me", _, _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml")
+ }}
+ end
+
+ def get("https://mst3k.interlinked.me/users/luciferMysticus", _, _,
+ Accept: "application/activity+json"
+ ) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/lucifermysticus.json")
+ }}
+ end
+
def get("https://prismo.news/@mxb", _, _, _) do
{:ok,
%Tesla.Env{
@@ -31,8 +59,9 @@ defmodule HttpRequestMock do
}}
end
- def get("https://hubzilla.example.org/channel/kaniini",
- _, _, [Accept: "application/activity+json"]) do
+ def get("https://hubzilla.example.org/channel/kaniini", _, _,
+ Accept: "application/activity+json"
+ ) do
{:ok,
%Tesla.Env{
status: 200,
@@ -40,7 +69,7 @@ defmodule HttpRequestMock do
}}
end
- def get("https://niu.moe/users/rye", _, _, [Accept: "application/activity+json"]) do
+ def get("https://niu.moe/users/rye", _, _, Accept: "application/activity+json") do
{:ok,
%Tesla.Env{
status: 200,
@@ -52,13 +81,14 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!(
- "test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json"
- )
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json"
+ )
}}
end
- def get("https://puckipedia.com/", _, _, [Accept: "application/activity+json"]) do
+ def get("https://puckipedia.com/", _, _, Accept: "application/activity+json") do
{:ok,
%Tesla.Env{
status: 200,
@@ -66,7 +96,6 @@ defmodule HttpRequestMock do
}}
end
-
def get("https://peertube.moe/accounts/7even", _, _, _) do
{:ok,
%Tesla.Env{
@@ -99,8 +128,7 @@ defmodule HttpRequestMock do
}}
end
-
- def get("http://mastodon.example.org/users/admin", _, _, [Accept: "application/activity+json"]) do
+ def get("http://mastodon.example.org/users/admin", _, _, Accept: "application/activity+json") do
{:ok,
%Tesla.Env{
status: 200,
@@ -108,8 +136,9 @@ defmodule HttpRequestMock do
}}
end
- def get("http://mastodon.example.org/@admin/99541947525187367",
- _, _, [Accept: "application/activity+json"]) do
+ def get("http://mastodon.example.org/@admin/99541947525187367", _, _,
+ Accept: "application/activity+json"
+ ) do
{:ok,
%Tesla.Env{
status: 200,
@@ -125,7 +154,7 @@ defmodule HttpRequestMock do
}}
end
- def get("https://mstdn.io/users/mayuutann", _, _, [Accept: "application/activity+json"]) do
+ def get("https://mstdn.io/users/mayuutann", _, _, Accept: "application/activity+json") do
{:ok,
%Tesla.Env{
status: 200,
@@ -133,8 +162,9 @@ defmodule HttpRequestMock do
}}
end
- def get("https://mstdn.io/users/mayuutann/statuses/99568293732299394",
- _, _, [Accept: "application/activity+json"]) do
+ def get("https://mstdn.io/users/mayuutann/statuses/99568293732299394", _, _,
+ Accept: "application/activity+json"
+ ) do
{:ok,
%Tesla.Env{
status: 200,
@@ -142,7 +172,6 @@ defmodule HttpRequestMock do
}}
end
-
def get("https://pleroma.soykaf.com/users/lain/feed.atom", _, _, _) do
{:ok,
%Tesla.Env{
diff --git a/test/web/http_sigs/http_sig_test.exs b/test/web/http_sigs/http_sig_test.exs
index b2bf8d61b..2e189d583 100644
--- a/test/web/http_sigs/http_sig_test.exs
+++ b/test/web/http_sigs/http_sig_test.exs
@@ -4,6 +4,12 @@ defmodule Pleroma.Web.HTTPSignaturesTest do
use Pleroma.DataCase
alias Pleroma.Web.HTTPSignatures
import Pleroma.Factory
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
@private_key hd(:public_key.pem_decode(File.read!("test/web/http_sigs/priv.key")))
|> :public_key.pem_entry_decode()
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 098acb59f..7cd98cde8 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -8,6 +8,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
import Pleroma.Factory
import ExUnit.CaptureLog
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
test "the home timeline", %{conn: conn} do
user = insert(:user)
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 31554a07d..9e69b3189 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -6,6 +6,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
alias Pleroma.Web.OStatus
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
test "a note with null content" do
note = insert(:note_activity)
diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs
index 8bf3bc775..a351510d8 100644
--- a/test/web/ostatus/activity_representer_test.exs
+++ b/test/web/ostatus/activity_representer_test.exs
@@ -7,6 +7,12 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
alias Pleroma.Web.OStatus
import Pleroma.Factory
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
test "an external note activity" do
incoming = File.read!("test/fixtures/mastodon-note-cw.xml")
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index e81adde68..6327a524e 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -4,6 +4,12 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
alias Pleroma.{User, Repo}
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OStatus.ActivityRepresenter
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
test "decodes a salmon", %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From a9e4a975866c33553c477667c431187590329447 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Tue, 4 Dec 2018 14:01:39 +0300
Subject: update test
---
test/formatter_test.exs | 4 ++
test/support/http_request_mock.ex | 67 +++++++++++++++++++++++++++
test/user_test.exs | 5 ++
test/web/activity_pub/transmogrifier_test.exs | 7 +--
test/web/ostatus/ostatus_controller_test.exs | 5 +-
test/web/ostatus/ostatus_test.exs | 5 +-
6 files changed, 82 insertions(+), 11 deletions(-)
(limited to 'test')
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index e4da84c10..d5c74a321 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -4,6 +4,10 @@ defmodule Pleroma.FormatterTest do
use Pleroma.DataCase
import Pleroma.Factory
+ setup_all do
+ Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
describe ".add_hashtag_links" do
test "turns hashtags into links" do
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index f44e9a1c6..80b84d591 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -22,6 +22,73 @@ defmodule HttpRequestMock do
# GET Requests
#
def get(url, query \\ [], body \\ [], headers \\ [])
+ def get("https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191",
+ _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
+ }}
+ end
+
+ def get("https://pawoo.net/users/pekorino.atom", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.atom")
+ }}
+ end
+
+ def get("https://pawoo.net/.well-known/webfinger?resource=acct:https://pawoo.net/users/pekorino",
+ _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
+ }}
+ end
+
+ def get("https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/18330.atom", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/atarifrosch_feed.xml")
+ }}
+ end
+
+ def get("https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=acct:https://social.stopwatchingus-heidelberg.de/user/18330",
+ _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/atarifrosch_webfinger.xml")
+ }}
+ end
+
+ def get("https://mamot.fr/users/Skruyb.atom", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom")
+ }}
+ end
+
+ def get("https://mamot.fr/.well-known/webfinger?resource=acct:https://mamot.fr/users/Skruyb",
+ _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
+ }}
+ end
+
+ def get("https://social.heldscal.la/.well-known/webfinger?resource=nonexistant@social.heldscal.la", _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/nonexistant@social.heldscal.la.xml")
+ }}
+ end
def get("http://gs.example.org:4040/index.php/user/1", _, _, Accept: "application/activity+json") do
{:ok,
diff --git a/test/user_test.exs b/test/user_test.exs
index 62104df90..d097eb171 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -9,6 +9,11 @@ defmodule Pleroma.UserTest do
import Pleroma.Factory
import Ecto.Query
+ setup_all do
+ Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
test "ap_id returns the activity pub id for the user" do
user = UserBuilder.build()
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index faba80354..eeb0cb5cf 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -11,11 +11,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
import Pleroma.Factory
alias Pleroma.Web.CommonAPI
-
- import Tesla.Mock
-
- setup do
- mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ setup_all do
+ Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok
end
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index 6327a524e..411e89e94 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -4,10 +4,9 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
alias Pleroma.{User, Repo}
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OStatus.ActivityRepresenter
- import Tesla.Mock
- setup do
- mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ setup_all do
+ Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok
end
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index 83525456b..f3268e83d 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -5,10 +5,9 @@ defmodule Pleroma.Web.OStatusTest do
alias Pleroma.{Object, Repo, User, Activity}
import Pleroma.Factory
import ExUnit.CaptureLog
- import Tesla.Mock
- setup do
- mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ setup_all do
+ Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok
end
--
cgit v1.2.3
From 5c6d47614dfd72566a91ac58223902e71ebdf1d3 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Tue, 4 Dec 2018 16:39:08 +0300
Subject: all tests passed
---
test/support/http_request_mock.ex | 29 +++++++++++++++-------
.../activity_pub/activity_pub_controller_test.exs | 5 +++-
test/web/federator_test.exs | 5 ++++
3 files changed, 29 insertions(+), 10 deletions(-)
(limited to 'test')
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index 80b84d591..c1b1c8589 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -14,7 +14,7 @@ defmodule HttpRequestMock do
res
else
{_, r} = error ->
- Logger.warn(r)
+ #Logger.warn(r)
error
end
end
@@ -22,6 +22,25 @@ defmodule HttpRequestMock do
# GET Requests
#
def get(url, query \\ [], body \\ [], headers \\ [])
+
+ def get("https://osada.macgirvin.com/channel/mike", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!(
+ "test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json"
+ )
+ }}
+ end
+
+ def get("https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com", _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json")
+ }}
+ end
+
def get("https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191",
_, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
{:ok,
@@ -90,14 +109,6 @@ defmodule HttpRequestMock do
}}
end
- def get("http://gs.example.org:4040/index.php/user/1", _, _, Accept: "application/activity+json") do
- {:ok,
- %Tesla.Env{
- status: 200,
- body: "{\"id\": 1}"
- }}
- end
-
def get("https://squeet.me/xrd/?uri=lain@squeet.me", _, _,
Accept: "application/xrd+xml,application/jrd+json"
) do
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 1c24b348c..414759110 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -4,7 +4,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
alias Pleroma.Web.ActivityPub.{UserView, ObjectView}
alias Pleroma.{Repo, User}
alias Pleroma.Activity
-
+ setup_all do
+ Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
describe "/relay" do
test "with the relay active, it returns the relay user", %{conn: conn} do
res =
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 02e1ca76e..87bf73dbd 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -5,6 +5,11 @@ defmodule Pleroma.Web.FederatorTest do
import Pleroma.Factory
import Mock
+ setup_all do
+ Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
test "enqueues an element according to priority" do
queue = [%{item: 1, priority: 2}]
--
cgit v1.2.3
From dd8aee332cf939f1a76f60a95b117ab90530178b Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Tue, 4 Dec 2018 17:48:55 +0300
Subject: formatting the code
---
test/formatter_test.exs | 1 +
test/support/http_request_mock.ex | 60 ++++++++++++++++------
.../activity_pub/activity_pub_controller_test.exs | 2 +
test/web/activity_pub/transmogrifier_test.exs | 1 +
4 files changed, 49 insertions(+), 15 deletions(-)
(limited to 'test')
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index d5c74a321..5d745510f 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -4,6 +4,7 @@ defmodule Pleroma.FormatterTest do
use Pleroma.DataCase
import Pleroma.Factory
+
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index c1b1c8589..391342ad7 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -14,7 +14,7 @@ defmodule HttpRequestMock do
res
else
{_, r} = error ->
- #Logger.warn(r)
+ # Logger.warn(r)
error
end
end
@@ -27,13 +27,17 @@ defmodule HttpRequestMock do
{:ok,
%Tesla.Env{
status: 200,
- body: File.read!(
- "test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json"
- )
+ body:
+ File.read!("test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json")
}}
end
- def get("https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com", _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
+ def get(
+ "https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com",
+ _,
+ _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
{:ok,
%Tesla.Env{
status: 200,
@@ -41,8 +45,12 @@ defmodule HttpRequestMock do
}}
end
- def get("https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191",
- _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
+ def get(
+ "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191",
+ _,
+ _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
{:ok,
%Tesla.Env{
status: 200,
@@ -58,8 +66,12 @@ defmodule HttpRequestMock do
}}
end
- def get("https://pawoo.net/.well-known/webfinger?resource=acct:https://pawoo.net/users/pekorino",
- _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
+ def get(
+ "https://pawoo.net/.well-known/webfinger?resource=acct:https://pawoo.net/users/pekorino",
+ _,
+ _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
{:ok,
%Tesla.Env{
status: 200,
@@ -67,7 +79,12 @@ defmodule HttpRequestMock do
}}
end
- def get("https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/18330.atom", _, _, _) do
+ def get(
+ "https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/18330.atom",
+ _,
+ _,
+ _
+ ) do
{:ok,
%Tesla.Env{
status: 200,
@@ -75,8 +92,12 @@ defmodule HttpRequestMock do
}}
end
- def get("https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=acct:https://social.stopwatchingus-heidelberg.de/user/18330",
- _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
+ def get(
+ "https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=acct:https://social.stopwatchingus-heidelberg.de/user/18330",
+ _,
+ _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
{:ok,
%Tesla.Env{
status: 200,
@@ -92,8 +113,12 @@ defmodule HttpRequestMock do
}}
end
- def get("https://mamot.fr/.well-known/webfinger?resource=acct:https://mamot.fr/users/Skruyb",
- _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
+ def get(
+ "https://mamot.fr/.well-known/webfinger?resource=acct:https://mamot.fr/users/Skruyb",
+ _,
+ _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
{:ok,
%Tesla.Env{
status: 200,
@@ -101,7 +126,12 @@ defmodule HttpRequestMock do
}}
end
- def get("https://social.heldscal.la/.well-known/webfinger?resource=nonexistant@social.heldscal.la", _, _, [Accept: "application/xrd+xml,application/jrd+json"]) do
+ def get(
+ "https://social.heldscal.la/.well-known/webfinger?resource=nonexistant@social.heldscal.la",
+ _,
+ _,
+ Accept: "application/xrd+xml,application/jrd+json"
+ ) do
{:ok,
%Tesla.Env{
status: 200,
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 414759110..980f43553 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -4,10 +4,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
alias Pleroma.Web.ActivityPub.{UserView, ObjectView}
alias Pleroma.{Repo, User}
alias Pleroma.Activity
+
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok
end
+
describe "/relay" do
test "with the relay active, it returns the relay user", %{conn: conn} do
res =
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index eeb0cb5cf..fa526a222 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -11,6 +11,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
import Pleroma.Factory
alias Pleroma.Web.CommonAPI
+
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok
--
cgit v1.2.3
From 50e72f6c4851d50b27f213b34b5d383b9e8aabb9 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Tue, 4 Dec 2018 17:51:49 +0300
Subject: remove httpoison_mock
---
test/support/httpoison_mock.ex | 883 -----------------------------------------
1 file changed, 883 deletions(-)
delete mode 100644 test/support/httpoison_mock.ex
(limited to 'test')
diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex
deleted file mode 100644
index e7344500f..000000000
--- a/test/support/httpoison_mock.ex
+++ /dev/null
@@ -1,883 +0,0 @@
-defmodule HTTPoisonMock do
- alias HTTPoison.Response
-
- def process_request_options(options), do: options
-
- def get(url, body \\ [], headers \\ [])
-
- def get("https://prismo.news/@mxb", _, _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___prismo.news__mxb.json")
- }}
- end
-
- def get("https://osada.macgirvin.com/channel/mike", _, _) do
- {:ok,
- %Response{
- status_code: 200,
- body:
- File.read!("test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json")
- }}
- end
-
- def get(
- "https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com",
- _,
- _
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json")
- }}
- end
-
- def get("https://info.pleroma.site/activity.json", _, _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https__info.pleroma.site_activity.json")
- }}
- end
-
- def get("https://info.pleroma.site/activity2.json", _, _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https__info.pleroma.site_activity2.json")
- }}
- end
-
- def get("https://info.pleroma.site/activity3.json", _, _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https__info.pleroma.site_activity3.json")
- }}
- end
-
- def get("https://info.pleroma.site/activity4.json", _, _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https__info.pleroma.site_activity4.json")
- }}
- end
-
- def get("https://info.pleroma.site/actor.json", _, _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___info.pleroma.site_actor.json")
- }}
- end
-
- def get("https://puckipedia.com/", [Accept: "application/activity+json"], _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/puckipedia.com.json")
- }}
- end
-
- def get(
- "https://gerzilla.de/.well-known/webfinger?resource=acct:kaniini@gerzilla.de",
- [Accept: "application/xrd+xml,application/jrd+json"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/kaniini@gerzilla.de.json")
- }}
- end
-
- def get(
- "https://framatube.org/.well-known/webfinger?resource=acct:framasoft@framatube.org",
- [Accept: "application/xrd+xml,application/jrd+json"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/framasoft@framatube.org.json")
- }}
- end
-
- def get(
- "https://gnusocial.de/.well-known/webfinger?resource=acct:winterdienst@gnusocial.de",
- [Accept: "application/xrd+xml,application/jrd+json"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/winterdienst_webfinger.json")
- }}
- end
-
- def get(
- "https://social.heldscal.la/.well-known/webfinger",
- [Accept: "application/xrd+xml,application/jrd+json"],
- params: [resource: "nonexistant@social.heldscal.la"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 500,
- body: File.read!("test/fixtures/httpoison_mock/nonexistant@social.heldscal.la.xml")
- }}
- end
-
- def get(
- "https://social.heldscal.la/.well-known/webfinger?resource=shp@social.heldscal.la",
- [Accept: "application/xrd+xml,application/jrd+json"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml")
- }}
- end
-
- def get(
- "https://social.heldscal.la/.well-known/webfinger",
- [Accept: "application/xrd+xml,application/jrd+json"],
- params: [resource: "shp@social.heldscal.la"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml")
- }}
- end
-
- def get(
- "https://social.heldscal.la/.well-known/webfinger",
- [Accept: "application/xrd+xml,application/jrd+json"],
- params: [resource: "https://social.heldscal.la/user/23211"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")
- }}
- end
-
- def get(
- "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
- [Accept: "application/xrd+xml,application/jrd+json"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")
- }}
- end
-
- def get(
- "https://social.heldscal.la/.well-known/webfinger",
- [Accept: "application/xrd+xml,application/jrd+json"],
- params: [resource: "https://social.heldscal.la/user/29191"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
- }}
- end
-
- def get(
- "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191",
- [Accept: "application/xrd+xml,application/jrd+json"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
- }}
- end
-
- def get(
- "https://mastodon.social/.well-known/webfinger",
- [Accept: "application/xrd+xml,application/jrd+json"],
- params: [resource: "https://mastodon.social/users/lambadalambda"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body:
- File.read!(
- "test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml"
- )
- }}
- end
-
- def get(
- "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",
- [Accept: "application/xrd+xml,application/jrd+json"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body:
- File.read!(
- "test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml"
- )
- }}
- end
-
- def get(
- "https://shitposter.club/.well-known/webfinger",
- [Accept: "application/xrd+xml,application/jrd+json"],
- params: [resource: "https://shitposter.club/user/1"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml")
- }}
- end
-
- def get(
- "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",
- [Accept: "application/xrd+xml,application/jrd+json"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml")
- }}
- end
-
- def get(
- "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",
- [Accept: "application/xrd+xml,application/jrd+json"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/spc_5381_xrd.xml")
- }}
- end
-
- def get(
- "http://gs.example.org/.well-known/webfinger",
- [Accept: "application/xrd+xml,application/jrd+json"],
- params: [resource: "http://gs.example.org:4040/index.php/user/1"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body:
- File.read!(
- "test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml"
- )
- }}
- end
-
- def get(
- "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",
- [Accept: "application/xrd+xml,application/jrd+json"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body:
- File.read!(
- "test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml"
- )
- }}
- end
-
- def get(
- "https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=https://social.stopwatchingus-heidelberg.de/user/18330",
- [Accept: "application/xrd+xml,application/jrd+json"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/atarifrosch_webfinger.xml")
- }}
- end
-
- def get(
- "https://pleroma.soykaf.com/.well-known/webfinger",
- [Accept: "application/xrd+xml,application/jrd+json"],
- params: [resource: "https://pleroma.soykaf.com/users/lain"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml")
- }}
- end
-
- def get(
- "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain",
- [Accept: "application/xrd+xml,application/jrd+json"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml")
- }}
- end
-
- def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _body, _headers) do
- {:ok,
- %Response{
- status_code: 200,
- body:
- File.read!(
- "test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml"
- )
- }}
- end
-
- def get("https://shitposter.club/api/statuses/user_timeline/5381.atom", _body, _headers) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/spc_5381.atom")
- }}
- end
-
- def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _body, _headers) do
- {:ok,
- %Response{
- status_code: 200,
- body:
- File.read!(
- "test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
- )
- }}
- end
-
- def get("https://mastodon.social/users/lambadalambda.atom", _body, _headers) do
- {:ok,
- %Response{
- status_code: 200,
- body:
- File.read!(
- "test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.atom"
- )
- }}
- end
-
- def get(
- "https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/18330.atom",
- _body,
- _headers
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/atarifrosch_feed.xml")
- }}
- end
-
- def get("https://pleroma.soykaf.com/users/lain/feed.atom", _body, _headers) do
- {:ok,
- %Response{
- status_code: 200,
- body:
- File.read!(
- "test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml"
- )
- }}
- end
-
- def get("https://social.sakamoto.gq/users/eal/feed.atom", _body, _headers) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/sakamoto_eal_feed.atom")
- }}
- end
-
- def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _body, _headers) do
- {:ok,
- %Response{
- status_code: 200,
- body:
- File.read!(
- "test/fixtures/httpoison_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml"
- )
- }}
- end
-
- def get("https://shitposter.club/notice/2827873", _body, _headers) do
- {:ok,
- %Response{
- status_code: 200,
- body:
- File.read!("test/fixtures/httpoison_mock/https___shitposter.club_notice_2827873.html")
- }}
- end
-
- def get("https://shitposter.club/api/statuses/show/2827873.atom", _body, _headers) do
- {:ok,
- %Response{
- status_code: 200,
- body:
- File.read!(
- "test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml"
- )
- }}
- end
-
- def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _body, _headers) do
- {:ok,
- %Response{
- status_code: 200,
- body:
- File.read!(
- "test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml"
- )
- }}
- end
-
- def post(
- "https://social.heldscal.la/main/push/hub",
- {:form, _data},
- "Content-type": "application/x-www-form-urlencoded"
- ) do
- {:ok,
- %Response{
- status_code: 202
- }}
- end
-
- def get("http://mastodon.example.org/users/admin/statuses/100787282858396771", _, _) do
- {:ok,
- %Response{
- status_code: 200,
- body:
- File.read!(
- "test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json"
- )
- }}
- end
-
- def get(
- "https://pawoo.net/.well-known/webfinger",
- [Accept: "application/xrd+xml,application/jrd+json"],
- params: [resource: "https://pawoo.net/users/pekorino"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
- }}
- end
-
- def get(
- "https://pawoo.net/.well-known/webfinger?resource=https://pawoo.net/users/pekorino",
- [Accept: "application/xrd+xml,application/jrd+json"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
- }}
- end
-
- def get("https://pawoo.net/users/pekorino.atom", _, _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.atom")
- }}
- end
-
- def get(
- "https://mamot.fr/.well-known/webfinger",
- [Accept: "application/xrd+xml,application/jrd+json"],
- params: [resource: "https://mamot.fr/users/Skruyb"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
- }}
- end
-
- def get(
- "https://mamot.fr/.well-known/webfinger?resource=https://mamot.fr/users/Skruyb",
- [Accept: "application/xrd+xml,application/jrd+json"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
- }}
- end
-
- def get(
- "https://social.sakamoto.gq/.well-known/webfinger",
- [Accept: "application/xrd+xml,application/jrd+json"],
- params: [resource: "https://social.sakamoto.gq/users/eal"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml")
- }}
- end
-
- def get(
- "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",
- [Accept: "application/xrd+xml,application/jrd+json"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml")
- }}
- end
-
- def get(
- "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/shp",
- [Accept: "application/xrd+xml,application/jrd+json"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/shp@pleroma.soykaf.com.webfigner")
- }}
- end
-
- def get(
- "https://squeet.me/xrd/?uri=lain@squeet.me",
- [Accept: "application/xrd+xml,application/jrd+json"],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml")
- }}
- end
-
- def get("https://mamot.fr/users/Skruyb.atom", _, _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom")
- }}
- end
-
- def get(
- "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056",
- [Accept: "application/atom+xml"],
- _
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/sakamoto.atom")
- }}
- end
-
- def get("https://pleroma.soykaf.com/users/shp/feed.atom", _, _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/shp@pleroma.soykaf.com.feed")
- }}
- end
-
- def get("http://social.heldscal.la/.well-known/host-meta", [], follow_redirect: true) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/social.heldscal.la_host_meta")
- }}
- end
-
- def get("http://status.alpicola.com/.well-known/host-meta", [], follow_redirect: true) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/status.alpicola.com_host_meta")
- }}
- end
-
- def get("http://macgirvin.com/.well-known/host-meta", [], follow_redirect: true) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/macgirvin.com_host_meta")
- }}
- end
-
- def get("http://mastodon.social/.well-known/host-meta", [], follow_redirect: true) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/mastodon.social_host_meta")
- }}
- end
-
- def get("http://shitposter.club/.well-known/host-meta", [], follow_redirect: true) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/shitposter.club_host_meta")
- }}
- end
-
- def get("http://pleroma.soykaf.com/.well-known/host-meta", [], follow_redirect: true) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/pleroma.soykaf.com_host_meta")
- }}
- end
-
- def get("http://social.sakamoto.gq/.well-known/host-meta", [], follow_redirect: true) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/social.sakamoto.gq_host_meta")
- }}
- end
-
- def get("http://gs.example.org/.well-known/host-meta", [], follow_redirect: true) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/gs.example.org_host_meta")
- }}
- end
-
- def get("http://pawoo.net/.well-known/host-meta", [], follow_redirect: true) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/pawoo.net_host_meta")
- }}
- end
-
- def get("http://mamot.fr/.well-known/host-meta", [], follow_redirect: true) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/mamot.fr_host_meta")
- }}
- end
-
- def get("http://mastodon.xyz/.well-known/host-meta", [], follow_redirect: true) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/mastodon.xyz_host_meta")
- }}
- end
-
- def get("http://social.wxcafe.net/.well-known/host-meta", [], follow_redirect: true) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/social.wxcafe.net_host_meta")
- }}
- end
-
- def get("http://squeet.me/.well-known/host-meta", [], follow_redirect: true) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/squeet.me_host_meta")
- }}
- end
-
- def get(
- "http://social.stopwatchingus-heidelberg.de/.well-known/host-meta",
- [],
- follow_redirect: true
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body:
- File.read!("test/fixtures/httpoison_mock/social.stopwatchingus-heidelberg.de_host_meta")
- }}
- end
-
- def get("http://mastodon.example.org/users/admin", [Accept: "application/activity+json"], _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/admin@mastdon.example.org.json")
- }}
- end
-
- def get(
- "https://hubzilla.example.org/channel/kaniini",
- [Accept: "application/activity+json"],
- _
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/kaniini@hubzilla.example.org.json")
- }}
- end
-
- def get("https://masto.quad.moe/users/_HellPie", [Accept: "application/activity+json"], _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/hellpie.json")
- }}
- end
-
- def get("https://niu.moe/users/rye", [Accept: "application/activity+json"], _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/rye.json")
- }}
- end
-
- def get("https://n1u.moe/users/rye", [Accept: "application/activity+json"], _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/rye.json")
- }}
- end
-
- def get(
- "https://mst3k.interlinked.me/users/luciferMysticus",
- [Accept: "application/activity+json"],
- _
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/lucifermysticus.json")
- }}
- end
-
- def get("https://mstdn.io/users/mayuutann", [Accept: "application/activity+json"], _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/mayumayu.json")
- }}
- end
-
- def get(
- "http://mastodon.example.org/@admin/99541947525187367",
- [Accept: "application/activity+json"],
- _
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/mastodon-note-object.json")
- }}
- end
-
- def get(
- "https://mstdn.io/users/mayuutann/statuses/99568293732299394",
- [Accept: "application/activity+json"],
- _
- ) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/mayumayupost.json")
- }}
- end
-
- def get("https://shitposter.club/notice/7369654", _, _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/7369654.html")
- }}
- end
-
- def get("https://shitposter.club/api/statuses/show/7369654.atom", _body, _headers) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/7369654.atom")
- }}
- end
-
- def get("https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/", _, _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/baptiste.gelex.xyz-article.json")
- }}
- end
-
- def get("https://baptiste.gelez.xyz/@/BaptisteGelez", _, _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/baptiste.gelex.xyz-user.json")
- }}
- end
-
- def get("https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3", _, _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/peertube.moe-vid.json")
- }}
- end
-
- def get("https://peertube.moe/accounts/7even", _, _) do
- {:ok,
- %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/7even.json")
- }}
- end
-
- def get(url, body, headers) do
- {:error,
- "Not implemented the mock response for get #{inspect(url)}, #{inspect(body)}, #{
- inspect(headers)
- }"}
- end
-
- def post(url, _body, _headers) do
- {:error, "Not implemented the mock response for post #{inspect(url)}"}
- end
-
- def post(url, _body, _headers, _options) do
- {:error, "Not implemented the mock response for post #{inspect(url)}"}
- end
-end
--
cgit v1.2.3
From 826fc446d56b48b67e97144c74bbf74109fb8168 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Tue, 4 Dec 2018 18:35:57 +0300
Subject: [#210] TwitterAPI: implemented /api/media/metadata/create to allow
uploads description (alt text) setting.
---
test/web/twitter_api/twitter_api_controller_test.exs | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index a6495ffc1..8faa4b58e 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1253,4 +1253,24 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert [user.id, user_two.id, user_three.id] == Enum.map(resp, fn %{"id" => id} -> id end)
end
end
+
+ describe "POST /api/media/metadata/create" do
+ test "it updates `data[name]` of referenced Object with provided value", %{conn: conn} do
+ user = insert(:user)
+ object = insert(:note)
+ description = "Informative description of the image. Initial: #{object.data["name"]}}"
+
+ _conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/media/metadata/create.json", %{
+ "media_id" => object.id,
+ "alt_text" => %{"text" => description}
+ })
+ |> json_response(:no_content)
+
+ object = Repo.get!(Object, object.id)
+ assert object.data["name"] == description
+ end
+ end
end
--
cgit v1.2.3
From 44ab3dbe2c3d25a1772b99679653eaf96d4fbd8b Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Tue, 4 Dec 2018 19:45:09 +0300
Subject: [#210] Refactoring.
---
test/web/twitter_api/twitter_api_controller_test.exs | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 8faa4b58e..21e844124 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1260,14 +1260,13 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
object = insert(:note)
description = "Informative description of the image. Initial: #{object.data["name"]}}"
- _conn =
- conn
- |> assign(:user, user)
- |> post("/api/media/metadata/create.json", %{
- "media_id" => object.id,
- "alt_text" => %{"text" => description}
- })
- |> json_response(:no_content)
+ conn
+ |> assign(:user, user)
+ |> post("/api/media/metadata/create.json", %{
+ "media_id" => object.id,
+ "alt_text" => %{"text" => description}
+ })
+ |> json_response(:no_content)
object = Repo.get!(Object, object.id)
assert object.data["name"] == description
--
cgit v1.2.3
From a9e3e387c9798a810f82bbf92023b4d29abffbe5 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Tue, 4 Dec 2018 19:43:00 +0300
Subject: add test
---
test/http_test.exs | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644 test/http_test.exs
(limited to 'test')
diff --git a/test/http_test.exs b/test/http_test.exs
new file mode 100644
index 000000000..62f3ccb30
--- /dev/null
+++ b/test/http_test.exs
@@ -0,0 +1,55 @@
+defmodule Pleroma.HTTPTest do
+ use Pleroma.DataCase
+ import Tesla.Mock
+
+ setup do
+ mock(fn
+ %{
+ method: :get,
+ url: "http://example.com/hello",
+ headers: [{"content-type", "application/json"}]
+ } ->
+ json(%{"my" => "data"})
+
+ %{method: :get, url: "http://example.com/hello"} ->
+ %Tesla.Env{status: 200, body: "hello"}
+
+ %{method: :post, url: "http://example.com/world"} ->
+ %Tesla.Env{status: 200, body: "world"}
+ end)
+
+ :ok
+ end
+
+ describe "get/1" do
+ test "returns successfully result" do
+ assert Pleroma.HTTP.get("http://example.com/hello") == {
+ :ok,
+ %Tesla.Env{status: 200, body: "hello"}
+ }
+ end
+ end
+
+ describe "get/2 (with headers)" do
+ test "returns successfully result for json content-type" do
+ assert Pleroma.HTTP.get("http://example.com/hello", [{"content-type", "application/json"}]) ==
+ {
+ :ok,
+ %Tesla.Env{
+ status: 200,
+ body: "{\"my\":\"data\"}",
+ headers: [{"content-type", "application/json"}]
+ }
+ }
+ end
+ end
+
+ describe "post/2" do
+ test "returns successfully result" do
+ assert Pleroma.HTTP.post("http://example.com/world", "") == {
+ :ok,
+ %Tesla.Env{status: 200, body: "world"}
+ }
+ end
+ end
+end
--
cgit v1.2.3
From 0f061bea0c217de8560ca235500959a463dd17ef Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Wed, 5 Dec 2018 03:41:32 +0000
Subject: tests: add regression test for bug #408
---
test/user_test.exs | 12 ++++++++++++
1 file changed, 12 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index d097eb171..3d2f7f4e0 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -149,6 +149,18 @@ defmodule Pleroma.UserTest do
assert changeset.changes.follower_address == "#{changeset.changes.ap_id}/followers"
end
+
+ test "it ensures info is not nil" do
+ changeset = User.register_changeset(%User{}, @full_user_data)
+
+ assert changeset.valid?
+
+ {:ok, user} =
+ changeset
+ |> Repo.insert()
+
+ refute is_nil(user.info)
+ end
end
describe "fetching a user from nickname or trying to build one" do
--
cgit v1.2.3
From 53797d19c5e8463388862eaa20931c8cb78d66a6 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Wed, 5 Dec 2018 11:56:31 +0300
Subject: [#210] Test update (replaced bang- with non-bang method).
---
test/web/twitter_api/twitter_api_controller_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 21e844124..478763de7 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1268,7 +1268,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
})
|> json_response(:no_content)
- object = Repo.get!(Object, object.id)
+ object = Repo.get(Object, object.id)
assert object.data["name"] == description
end
end
--
cgit v1.2.3
From 848151f7cbf372d008c178d13c9a74942164c955 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Wed, 5 Dec 2018 13:37:06 +0300
Subject: [#210] [TwitterAPI] Made actor be stored for uploads. Added ownership
check to `update_media` action. Added controller tests for `upload` and
`update_media` actions. Refactoring.
---
test/support/data_case.ex | 17 ++++++
test/upload_test.exs | 17 +-----
.../mastodon_api/mastodon_api_controller_test.exs | 2 +-
.../twitter_api/twitter_api_controller_test.exs | 67 ++++++++++++++++++++--
test/web/twitter_api/twitter_api_test.exs | 3 +-
5 files changed, 84 insertions(+), 22 deletions(-)
(limited to 'test')
diff --git a/test/support/data_case.ex b/test/support/data_case.ex
index 8eff0fd94..9dde6b5e5 100644
--- a/test/support/data_case.ex
+++ b/test/support/data_case.ex
@@ -36,6 +36,23 @@ defmodule Pleroma.DataCase do
:ok
end
+ def ensure_local_uploader(_context) do
+ uploader = Pleroma.Config.get([Pleroma.Upload, :uploader])
+ filters = Pleroma.Config.get([Pleroma.Upload, :filters])
+
+ unless uploader == Pleroma.Uploaders.Local || filters != [] do
+ Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+ Pleroma.Config.put([Pleroma.Upload, :filters], [])
+
+ on_exit(fn ->
+ Pleroma.Config.put([Pleroma.Upload, :uploader], uploader)
+ Pleroma.Config.put([Pleroma.Upload, :filters], filters)
+ end)
+ end
+
+ :ok
+ end
+
@doc """
A helper that transform changeset errors to a map of messages.
diff --git a/test/upload_test.exs b/test/upload_test.exs
index b2ce755d2..f2cad4cf0 100644
--- a/test/upload_test.exs
+++ b/test/upload_test.exs
@@ -3,22 +3,7 @@ defmodule Pleroma.UploadTest do
use Pleroma.DataCase
describe "Storing a file with the Local uploader" do
- setup do
- uploader = Pleroma.Config.get([Pleroma.Upload, :uploader])
- filters = Pleroma.Config.get([Pleroma.Upload, :filters])
-
- unless uploader == Pleroma.Uploaders.Local || filters != [] do
- Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
- Pleroma.Config.put([Pleroma.Upload, :filters], [])
-
- on_exit(fn ->
- Pleroma.Config.put([Pleroma.Upload, :uploader], uploader)
- Pleroma.Config.put([Pleroma.Upload, :filters], filters)
- end)
- end
-
- :ok
- end
+ setup [:ensure_local_uploader]
test "returns a media url" do
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 098acb59f..b5839cff1 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -804,7 +804,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
}
media =
- TwitterAPI.upload(file, "json")
+ TwitterAPI.upload(file, user, "json")
|> Poison.decode!()
{:ok, image_post} =
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 478763de7..c07dc6912 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1254,15 +1254,74 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
end
- describe "POST /api/media/metadata/create" do
- test "it updates `data[name]` of referenced Object with provided value", %{conn: conn} do
+ describe "POST /api/media/upload" do
+ setup context do
+ Pleroma.DataCase.ensure_local_uploader(context)
+ end
+
+ test "it performs the upload and sets `data[actor]` with AP id of uploader user", %{
+ conn: conn
+ } do
user = insert(:user)
+
+ upload_filename = "test/fixtures/image_tmp.jpg"
+ File.cp!("test/fixtures/image.jpg", upload_filename)
+
+ file = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname(upload_filename),
+ filename: "image.jpg"
+ }
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> put_req_header("content-type", "application/octet-stream")
+ |> post("/api/media/upload", %{
+ "media" => file
+ })
+ |> json_response(:ok)
+
+ assert response["media_id"]
+ object = Repo.get(Object, response["media_id"])
+ assert object
+ assert object.data["actor"] == User.ap_id(user)
+ end
+ end
+
+ describe "POST /api/media/metadata/create" do
+ setup do
object = insert(:note)
- description = "Informative description of the image. Initial: #{object.data["name"]}}"
+ user = User.get_by_ap_id(object.data["actor"])
+ %{object: object, user: user}
+ end
+
+ test "it returns :forbidden status on attempt to modify someone else's upload", %{
+ conn: conn,
+ object: object
+ } do
+ initial_description = object.data["name"]
+ another_user = insert(:user)
+
+ conn
+ |> assign(:user, another_user)
+ |> post("/api/media/metadata/create", %{"media_id" => object.id})
+ |> json_response(:forbidden)
+
+ object = Repo.get(Object, object.id)
+ assert object.data["name"] == initial_description
+ end
+
+ test "it updates `data[name]` of referenced Object with provided value", %{
+ conn: conn,
+ object: object,
+ user: user
+ } do
+ description = "Informative description of the image. Initial value: #{object.data["name"]}}"
conn
|> assign(:user, user)
- |> post("/api/media/metadata/create.json", %{
+ |> post("/api/media/metadata/create", %{
"media_id" => object.id,
"alt_text" => %{"text" => description}
})
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 28230699f..e34fbbabd 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -182,13 +182,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
end
test "upload a file" do
+ user = insert(:user)
file = %Plug.Upload{
content_type: "image/jpg",
path: Path.absname("test/fixtures/image.jpg"),
filename: "an_image.jpg"
}
- response = TwitterAPI.upload(file)
+ response = TwitterAPI.upload(file, user)
assert is_binary(response)
end
--
cgit v1.2.3
From ba345e4c293449871f443669b73c262403237620 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Wed, 5 Dec 2018 13:43:00 +0300
Subject: [#210] Formatting fix.
---
test/web/twitter_api/twitter_api_test.exs | 1 +
1 file changed, 1 insertion(+)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index e34fbbabd..032701705 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -183,6 +183,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
test "upload a file" do
user = insert(:user)
+
file = %Plug.Upload{
content_type: "image/jpg",
path: Path.absname("test/fixtures/image.jpg"),
--
cgit v1.2.3
From c524c50509d47fe04f2dc48b30ef1c3d6f6d2ffd Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Wed, 5 Dec 2018 17:29:49 +0300
Subject: fix/273
---
test/plugs/oauth_plug_test.exs | 56 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
create mode 100644 test/plugs/oauth_plug_test.exs
(limited to 'test')
diff --git a/test/plugs/oauth_plug_test.exs b/test/plugs/oauth_plug_test.exs
new file mode 100644
index 000000000..4dd12f207
--- /dev/null
+++ b/test/plugs/oauth_plug_test.exs
@@ -0,0 +1,56 @@
+defmodule Pleroma.Plugs.OAuthPlugTest do
+ use Pleroma.Web.ConnCase, async: true
+
+ alias Pleroma.Plugs.OAuthPlug
+ import Pleroma.Factory
+
+ @session_opts [
+ store: :cookie,
+ key: "_test",
+ signing_salt: "cooldude"
+ ]
+
+ setup %{conn: conn} do
+ user = insert(:user)
+ {:ok, %{token: token}} = Pleroma.Web.OAuth.Token.create_token(insert(:oauth_app), user)
+ %{user: user, token: token, conn: conn}
+ end
+
+ test "with valid token(uppercase), it assigns the user", %{conn: conn} = opts do
+ conn =
+ conn
+ |> put_req_header("authorization", "BEARER #{opts[:token]}")
+ |> OAuthPlug.call(%{})
+
+ assert conn.assigns[:user] == opts[:user]
+ end
+
+ test "with valid token(downcase), it assigns the user", %{conn: conn} = opts do
+ conn =
+ conn
+ |> put_req_header("authorization", "bearer #{opts[:token]}")
+ |> OAuthPlug.call(%{})
+
+ assert conn.assigns[:user] == opts[:user]
+ end
+
+ test "with invalid token, it not assigns the user", %{conn: conn} do
+ conn =
+ conn
+ |> put_req_header("authorization", "bearer TTTTT")
+ |> OAuthPlug.call(%{})
+
+ refute conn.assigns[:user]
+ end
+
+ test "when token is missed but token in session, it assigns the user", %{conn: conn} = opts do
+ conn =
+ conn
+ |> Plug.Session.call(Plug.Session.init(@session_opts))
+ |> fetch_session()
+ |> put_session(:oauth_token, opts[:token])
+ |> OAuthPlug.call(%{})
+
+ assert conn.assigns[:user] == opts[:user]
+ end
+end
--
cgit v1.2.3
From 839526a9134ba85c0a45fe85740d04a54076224c Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 5 Dec 2018 19:22:40 +0100
Subject: TwitterAPI: Add network hiding.
---
.../twitter_api/twitter_api_controller_test.exs | 24 ++++++++++++++++++++++
1 file changed, 24 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 8655105f3..6836019a5 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1024,6 +1024,30 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
+ test "it sets and un-sets hide_network", %{conn: conn} do
+ user = insert(:user)
+
+ conn
+ |> assign(:user, user)
+ |> post("/api/account/update_profile.json", %{
+ "hide_network" => "true"
+ })
+
+ user = Repo.get!(User, user.id)
+ assert user.info.hide_network == true
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/account/update_profile.json", %{
+ "hide_network" => "false"
+ })
+
+ user = Repo.get!(User, user.id)
+ assert user.info.hide_network == false
+ assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
+ end
+
test "it locks an account", %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From 812b20d49f1ef31cf1582e17c74ef68cacd8d912 Mon Sep 17 00:00:00 2001
From: Vald
Date: Thu, 6 Dec 2018 01:27:08 +0530
Subject: resolved formatter_test failures
---
test/formatter_test.exs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
(limited to 'test')
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index 5d745510f..84d826295 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -15,7 +15,7 @@ defmodule Pleroma.FormatterTest do
text = "I love #cofe and #2hu"
expected_text =
- "I love #cofe and #2hu "
+ "I love #cofe and #2hu "
tags = Formatter.parse_tags(text)
@@ -128,9 +128,9 @@ defmodule Pleroma.FormatterTest do
Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
expected_text =
- "@gsimg According to @gsimg According to @archaeme , that is @daggsy. Also hello @archaeme , that is @daggsy. Also hello @archaeme "
@@ -150,7 +150,7 @@ defmodule Pleroma.FormatterTest do
Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
expected_text =
- "@mike test"
+ "@mike test"
assert expected_text == Formatter.finalize({subs, text})
end
@@ -166,7 +166,7 @@ defmodule Pleroma.FormatterTest do
assert length(subs) == 1
Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
- expected_text = "@o hi"
+ expected_text = "@o hi"
assert expected_text == Formatter.finalize({subs, text})
end
--
cgit v1.2.3
From 743a09132bb6f9d3ecd6404e4a20e6a08598d8a7 Mon Sep 17 00:00:00 2001
From: Vald
Date: Thu, 6 Dec 2018 01:28:52 +0530
Subject: linting
---
test/formatter_test.exs | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
(limited to 'test')
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index 84d826295..abb9d882c 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -128,11 +128,11 @@ defmodule Pleroma.FormatterTest do
Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
expected_text =
- "@gsimg According to @archaeme , that is @daggsy. Also hello @archaeme "
+ "@gsimg According to @archaeme , that is @daggsy. Also hello @archaeme "
assert expected_text == Formatter.finalize({subs, text})
end
@@ -166,7 +166,9 @@ defmodule Pleroma.FormatterTest do
assert length(subs) == 1
Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
- expected_text = "@o hi"
+ expected_text =
+ "@o hi"
+
assert expected_text == Formatter.finalize({subs, text})
end
--
cgit v1.2.3
From fdac215091332d5f7df818855b62e600870d6786 Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 5 Dec 2018 21:14:06 +0100
Subject: TwitterAPI: Show users their own network.
---
.../twitter_api/twitter_api_controller_test.exs | 38 ++++++++++++++++++++++
1 file changed, 38 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 6836019a5..61fcb23d8 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -897,6 +897,25 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert [] == json_response(conn, 200)
end
+
+ test "it returns the followers for a hidden network if requested by the user themselves", %{
+ conn: conn
+ } do
+ user = insert(:user, %{info: %{hide_network: true}})
+ follower_one = insert(:user)
+ follower_two = insert(:user)
+ not_follower = insert(:user)
+
+ {:ok, follower_one} = User.follow(follower_one, user)
+ {:ok, follower_two} = User.follow(follower_two, user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/statuses/followers", %{"user_id" => user.id})
+
+ refute [] == json_response(conn, 200)
+ end
end
describe "GET /api/statuses/friends" do
@@ -958,6 +977,25 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert [] == json_response(conn, 200)
end
+ test "it returns friends for a hidden network if the user themselves request it", %{
+ conn: conn
+ } do
+ user = insert(:user, %{info: %{hide_network: true}})
+ followed_one = insert(:user)
+ followed_two = insert(:user)
+ not_followed = insert(:user)
+
+ {:ok, user} = User.follow(user, followed_one)
+ {:ok, user} = User.follow(user, followed_two)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/statuses/friends", %{"user_id" => user.id})
+
+ refute [] == json_response(conn, 200)
+ end
+
test "it returns a given user's friends with screen_name", %{conn: conn} do
user = insert(:user)
followed_one = insert(:user)
--
cgit v1.2.3
From 911a877576f1f2036fe2c7a7f22cf634ca3e5234 Mon Sep 17 00:00:00 2001
From: Vald
Date: Thu, 6 Dec 2018 01:46:30 +0530
Subject: resolved api and controller test failures
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 6 +++---
test/web/twitter_api/twitter_api_controller_test.exs | 2 +-
test/web/twitter_api/twitter_api_test.exs | 6 +++---
3 files changed, 7 insertions(+), 7 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 7cd98cde8..eb483afdf 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -590,7 +590,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> get("/api/v1/notifications")
expected_response =
- "hi @#{user.nickname} "
+ "hi @#{user.nickname} "
assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
assert response == expected_response
@@ -611,7 +611,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> get("/api/v1/notifications/#{notification.id}")
expected_response =
- "hi @#{user.nickname} "
+ "hi @#{user.nickname} "
assert %{"status" => %{"content" => response}} = json_response(conn, 200)
assert response == expected_response
@@ -1271,7 +1271,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert user = json_response(conn, 200)
assert user["note"] ==
- "I drink #cofe with #cofe with @#{user2.nickname} "
end
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index a6495ffc1..e799a0518 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -969,7 +969,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert user.name == "new name"
assert user.bio ==
- "hi @#{user2.nickname} "
+ "hi @#{user2.nickname} "
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 28230699f..76de68783 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -10,7 +10,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
test "create a status" do
user = insert(:user)
- _mentioned_user = insert(:user, %{nickname: "shp", ap_id: "shp"})
+ mentioned_user = insert(:user, %{nickname: "shp", ap_id: "shp"})
object_data = %{
"type" => "Image",
@@ -35,7 +35,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
expected_text =
- "Hello again, @shp .<script></script> This is on another :moominmamma: line. #2hu #epic #phantasmagoric image.jpg "
+ "Hello again, @shp .<script></script> This is on another :moominmamma: line. #2hu #epic #phantasmagoric image.jpg "
assert get_in(activity.data, ["object", "content"]) == expected_text
assert get_in(activity.data, ["object", "type"]) == "Note"
@@ -281,7 +281,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user2} = TwitterAPI.register_user(data2)
expected_text =
- "@john test"
+ "@john test"
assert user2.bio == expected_text
end
--
cgit v1.2.3
From 028904c33321a17f0f04c1a43dcf3eaeeeb80c1c Mon Sep 17 00:00:00 2001
From: Vald
Date: Thu, 6 Dec 2018 01:46:53 +0530
Subject: lint
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 6 +++---
test/web/twitter_api/twitter_api_controller_test.exs | 4 +++-
2 files changed, 6 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index eb483afdf..b5da2044a 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1271,9 +1271,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert user = json_response(conn, 200)
assert user["note"] ==
- "I drink #cofe with @#{user2.nickname} "
+ "I drink #cofe with @#{user2.nickname} "
end
test "updates the user's locking status", %{conn: conn} do
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index e799a0518..77a89ba06 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -969,7 +969,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert user.name == "new name"
assert user.bio ==
- "hi @#{user2.nickname} "
+ "hi @#{
+ user2.nickname
+ } "
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
--
cgit v1.2.3
From 3c8ffe7ed326f4c0bc515f35c905b405e90391b0 Mon Sep 17 00:00:00 2001
From: Vald
Date: Thu, 6 Dec 2018 01:54:04 +0530
Subject: resolved activity view test
---
test/web/twitter_api/views/activity_view_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 5cef06f88..bc36b0e90 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -47,7 +47,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"repeated" => false,
"statusnet_conversation_id" => convo_id,
"statusnet_html" =>
- "Hey @shp !",
+ "Hey @shp !",
"tags" => [],
"text" => "Hey @shp!",
"uri" => activity.data["object"]["id"],
--
cgit v1.2.3
From 3ea4476445a5e9b6ec1625d7caa537f79254e9d0 Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 5 Dec 2018 21:25:06 +0100
Subject: MastodonAPI: Show users their own network.
---
.../mastodon_api/mastodon_api_controller_test.exs | 26 ++++++++++++++++++++++
1 file changed, 26 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 9333b709e..0b20daff3 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1014,6 +1014,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [] == json_response(conn, 200)
end
+ test "getting followers, hide_network, same user requesting", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user, %{info: %{hide_network: true}})
+ {:ok, user} = User.follow(user, other_user)
+
+ conn =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/accounts/#{other_user.id}/followers")
+
+ refute [] == json_response(conn, 200)
+ end
+
test "getting following", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
@@ -1039,6 +1052,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [] == json_response(conn, 200)
end
+ test "getting following, hide_network, same user requesting", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_network: true}})
+ other_user = insert(:user)
+ {:ok, user} = User.follow(user, other_user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/#{user.id}/following")
+
+ refute [] == json_response(conn, 200)
+ end
+
test "following / unfollowing a user", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
--
cgit v1.2.3
From 3e90f688f14310e92fe9343f2680c58d74f71cb6 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Thu, 6 Dec 2018 10:26:17 +0300
Subject: [#210] Mastodon: actor storing for media uploads, ownership check to
update_media. Refactoring.
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index b5839cff1..d952cecc8 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -2,7 +2,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
use Pleroma.Web.ConnCase
alias Pleroma.Web.TwitterAPI.TwitterAPI
- alias Pleroma.{Repo, User, Activity, Notification}
+ alias Pleroma.{Repo, User, Object, Activity, Notification}
alias Pleroma.Web.{OStatus, CommonAPI}
alias Pleroma.Web.ActivityPub.ActivityPub
@@ -959,6 +959,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert media["type"] == "image"
assert media["description"] == desc
+ assert media["id"]
+
+ object = Repo.get(Object, media["id"])
+ assert object.data["actor"] == User.ap_id(user)
end
test "hashtag timeline", %{conn: conn} do
--
cgit v1.2.3
From 7b194873895f510b3e31b00643b4570ba04cb728 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Thu, 6 Dec 2018 20:06:50 +0300
Subject: [#394] Added `users.tags` and admin routes to tag and untag users.
Added tests.
---
test/web/admin_api/admin_api_controller_test.exs | 56 ++++++++++++++++++++++++
1 file changed, 56 insertions(+)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 9634ad7c5..6c86ea143 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -37,6 +37,62 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
end
+ describe "/api/pleroma/admin//users/tag" do
+ setup do
+ admin = insert(:user, info: %{is_admin: true})
+ user1 = insert(:user, %{tags: ["x"]})
+ user2 = insert(:user, %{tags: ["y"]})
+ user3 = insert(:user, %{tags: ["unchanged"]})
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> put_req_header("accept", "application/json")
+ |> put("/api/pleroma/admin/users/tag?nicknames[]=#{user1.nickname}&nicknames[]=#{user2.nickname}&tags[]=foo&tags[]=bar")
+
+ %{conn: conn, user1: user1, user2: user2, user3: user3}
+ end
+
+ test "it appends specified tags to users with specified nicknames", %{conn: conn, user1: user1, user2: user2} do
+ assert json_response(conn, :no_content)
+ assert Repo.get(User, user1.id).tags == ["x", "foo", "bar"]
+ assert Repo.get(User, user2.id).tags == ["y", "foo", "bar"]
+ end
+
+ test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
+ assert json_response(conn, :no_content)
+ assert Repo.get(User, user3.id).tags == ["unchanged"]
+ end
+ end
+
+ describe "/api/pleroma/admin//users/untag" do
+ setup do
+ admin = insert(:user, info: %{is_admin: true})
+ user1 = insert(:user, %{tags: ["x"]})
+ user2 = insert(:user, %{tags: ["y", "z"]})
+ user3 = insert(:user, %{tags: ["unchanged"]})
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> put_req_header("accept", "application/json")
+ |> put("/api/pleroma/admin/users/untag?nicknames[]=#{user1.nickname}&nicknames[]=#{user2.nickname}&tags[]=x&tags[]=z")
+
+ %{conn: conn, user1: user1, user2: user2, user3: user3}
+ end
+
+ test "it removes specified tags from users with specified nicknames", %{conn: conn, user1: user1, user2: user2} do
+ assert json_response(conn, :no_content)
+ assert Repo.get(User, user1.id).tags == []
+ assert Repo.get(User, user2.id).tags == ["y"]
+ end
+
+ test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
+ assert json_response(conn, :no_content)
+ assert Repo.get(User, user3.id).tags == ["unchanged"]
+ end
+ end
+
describe "/api/pleroma/admin/permission_group" do
test "GET is giving user_info" do
admin = insert(:user, info: %{is_admin: true})
--
cgit v1.2.3
From 22830c8fc99669362e59e6632bc9072b64550cb7 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Thu, 6 Dec 2018 20:13:07 +0300
Subject: [#394] Formatting fix.
---
test/web/admin_api/admin_api_controller_test.exs | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 6c86ea143..55aa7418b 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -48,12 +48,20 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
build_conn()
|> assign(:user, admin)
|> put_req_header("accept", "application/json")
- |> put("/api/pleroma/admin/users/tag?nicknames[]=#{user1.nickname}&nicknames[]=#{user2.nickname}&tags[]=foo&tags[]=bar")
+ |> put(
+ "/api/pleroma/admin/users/tag?nicknames[]=#{user1.nickname}&nicknames[]=#{
+ user2.nickname
+ }&tags[]=foo&tags[]=bar"
+ )
%{conn: conn, user1: user1, user2: user2, user3: user3}
end
- test "it appends specified tags to users with specified nicknames", %{conn: conn, user1: user1, user2: user2} do
+ test "it appends specified tags to users with specified nicknames", %{
+ conn: conn,
+ user1: user1,
+ user2: user2
+ } do
assert json_response(conn, :no_content)
assert Repo.get(User, user1.id).tags == ["x", "foo", "bar"]
assert Repo.get(User, user2.id).tags == ["y", "foo", "bar"]
@@ -76,12 +84,20 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
build_conn()
|> assign(:user, admin)
|> put_req_header("accept", "application/json")
- |> put("/api/pleroma/admin/users/untag?nicknames[]=#{user1.nickname}&nicknames[]=#{user2.nickname}&tags[]=x&tags[]=z")
+ |> put(
+ "/api/pleroma/admin/users/untag?nicknames[]=#{user1.nickname}&nicknames[]=#{
+ user2.nickname
+ }&tags[]=x&tags[]=z"
+ )
%{conn: conn, user1: user1, user2: user2, user3: user3}
end
- test "it removes specified tags from users with specified nicknames", %{conn: conn, user1: user1, user2: user2} do
+ test "it removes specified tags from users with specified nicknames", %{
+ conn: conn,
+ user1: user1,
+ user2: user2
+ } do
assert json_response(conn, :no_content)
assert Repo.get(User, user1.id).tags == []
assert Repo.get(User, user2.id).tags == ["y"]
--
cgit v1.2.3
From abbf347dc7de80d2c09d461fd39f9959f8b666b9 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Thu, 6 Dec 2018 20:38:52 +0300
Subject: [#394] View tests fix.
---
test/web/mastodon_api/account_view_test.exs | 6 ++++--
test/web/twitter_api/views/user_view_test.exs | 12 ++++++++----
2 files changed, 12 insertions(+), 6 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index a2d3a2547..d6c9f58c8 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -54,7 +54,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
note: "",
privacy: "public",
sensitive: false
- }
+ },
+ tags: []
}
assert expected == AccountView.render("account.json", %{user: user})
@@ -91,7 +92,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
note: "",
privacy: "public",
sensitive: false
- }
+ },
+ tags: []
}
assert expected == AccountView.render("account.json", %{user: user})
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index e69ca24a9..0bd06f256 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -96,7 +96,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "fields" => []
+ "fields" => [],
+ "tags" => []
}
assert represented == UserView.render("show.json", %{user: user})
@@ -137,7 +138,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "fields" => []
+ "fields" => [],
+ "tags" => []
}
assert represented == UserView.render("show.json", %{user: user, for: follower})
@@ -179,7 +181,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "fields" => []
+ "fields" => [],
+ "tags" => []
}
assert represented == UserView.render("show.json", %{user: follower, for: user})
@@ -228,7 +231,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "fields" => []
+ "fields" => [],
+ "tags" => []
}
blocker = Repo.get(User, blocker.id)
--
cgit v1.2.3
From 7a2162bbcb2e3a64ed6b56229311aa9fd487351a Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Thu, 6 Dec 2018 22:26:25 +0300
Subject: [#394] User view (Twitter & Mastadon API): wrapped "tags" in
"pleroma" map.
---
test/web/mastodon_api/account_view_test.exs | 4 ++--
test/web/twitter_api/views/user_view_test.exs | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index d6c9f58c8..3cb9b9c5b 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -55,7 +55,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
privacy: "public",
sensitive: false
},
- tags: []
+ pleroma: %{tags: []}
}
assert expected == AccountView.render("account.json", %{user: user})
@@ -93,7 +93,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
privacy: "public",
sensitive: false
},
- tags: []
+ pleroma: %{tags: []}
}
assert expected == AccountView.render("account.json", %{user: user})
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 0bd06f256..9898c217d 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -97,7 +97,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"default_scope" => "public",
"no_rich_text" => false,
"fields" => [],
- "tags" => []
+ "pleroma" => %{"tags" => []}
}
assert represented == UserView.render("show.json", %{user: user})
@@ -139,7 +139,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"default_scope" => "public",
"no_rich_text" => false,
"fields" => [],
- "tags" => []
+ "pleroma" => %{"tags" => []}
}
assert represented == UserView.render("show.json", %{user: user, for: follower})
@@ -182,7 +182,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"default_scope" => "public",
"no_rich_text" => false,
"fields" => [],
- "tags" => []
+ "pleroma" => %{"tags" => []}
}
assert represented == UserView.render("show.json", %{user: follower, for: user})
@@ -232,7 +232,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"default_scope" => "public",
"no_rich_text" => false,
"fields" => [],
- "tags" => []
+ "pleroma" => %{"tags" => []}
}
blocker = Repo.get(User, blocker.id)
--
cgit v1.2.3
From 6ed5044c4e1889a51a1dc6015b602759b83fc3b7 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Fri, 7 Dec 2018 11:04:39 +0300
Subject: [#394] Refactoring (using Ecto.Multi; "untag" route change).
---
test/web/admin_api/admin_api_controller_test.exs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 55aa7418b..ba3b77fb6 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -37,7 +37,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
end
- describe "/api/pleroma/admin//users/tag" do
+ describe "PUT /api/pleroma/admin/users/tag" do
setup do
admin = insert(:user, info: %{is_admin: true})
user1 = insert(:user, %{tags: ["x"]})
@@ -73,7 +73,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
end
- describe "/api/pleroma/admin//users/untag" do
+ describe "DELETE /api/pleroma/admin/users/tag" do
setup do
admin = insert(:user, info: %{is_admin: true})
user1 = insert(:user, %{tags: ["x"]})
@@ -84,8 +84,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
build_conn()
|> assign(:user, admin)
|> put_req_header("accept", "application/json")
- |> put(
- "/api/pleroma/admin/users/untag?nicknames[]=#{user1.nickname}&nicknames[]=#{
+ |> delete(
+ "/api/pleroma/admin/users/tag?nicknames[]=#{user1.nickname}&nicknames[]=#{
user2.nickname
}&tags[]=x&tags[]=z"
)
--
cgit v1.2.3
From bdc8112e4031a17c39a570bc8fc4bb6b8c35f9aa Mon Sep 17 00:00:00 2001
From: href
Date: Fri, 7 Dec 2018 21:44:04 +0100
Subject: Media proxy: fix url encoding
---
test/media_proxy_test.exs | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
(limited to 'test')
diff --git a/test/media_proxy_test.exs b/test/media_proxy_test.exs
index d71f9f13a..cb455ca79 100644
--- a/test/media_proxy_test.exs
+++ b/test/media_proxy_test.exs
@@ -1,6 +1,7 @@
defmodule Pleroma.MediaProxyTest do
use ExUnit.Case
import Pleroma.Web.MediaProxy
+ alias Pleroma.Web.MediaProxy.MediaProxyController
describe "when enabled" do
setup do
@@ -65,6 +66,14 @@ defmodule Pleroma.MediaProxyTest do
assert decode_result(encoded) == url
end
+ test "ensures urls are url-encoded" do
+ assert decode_result(url("https://pleroma.social/Hello world.jpg")) ==
+ "https://pleroma.social/Hello%20world.jpg"
+
+ assert decode_result(url("https://pleroma.social/Hello%20world.jpg")) ==
+ "https://pleroma.social/Hello%20world.jpg"
+ end
+
test "validates signature" do
secret_key_base = Pleroma.Config.get([Pleroma.Web.Endpoint, :secret_key_base])
@@ -83,6 +92,34 @@ defmodule Pleroma.MediaProxyTest do
assert decode_url(sig, base64) == {:error, :invalid_signature}
end
+ test "filename_matches matches url encoded paths" do
+ assert MediaProxyController.filename_matches(
+ true,
+ "/Hello%20world.jpg",
+ "http://pleroma.social/Hello world.jpg"
+ ) == :ok
+
+ assert MediaProxyController.filename_matches(
+ true,
+ "/Hello%20world.jpg",
+ "http://pleroma.social/Hello%20world.jpg"
+ ) == :ok
+ end
+
+ test "filename_matches matches non-url encoded paths" do
+ assert MediaProxyController.filename_matches(
+ true,
+ "/Hello world.jpg",
+ "http://pleroma.social/Hello%20world.jpg"
+ ) == :ok
+
+ assert MediaProxyController.filename_matches(
+ true,
+ "/Hello world.jpg",
+ "http://pleroma.social/Hello world.jpg"
+ ) == :ok
+ end
+
test "uses the configured base_url" do
base_url = Pleroma.Config.get([:media_proxy, :base_url])
--
cgit v1.2.3
From 9442588ae9b049ae1b152b082842e4c13fa49ebb Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Thu, 6 Dec 2018 21:50:34 +0300
Subject: fix hashtags in api response
---
test/web/mastodon_api/status_view_test.exs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 9e69b3189..d10d59d6c 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -24,7 +24,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
note
|> Map.put(:data, data)
- user = User.get_cached_by_ap_id(note.data["actor"])
+ User.get_cached_by_ap_id(note.data["actor"])
status = StatusView.render("status.json", %{activity: note})
@@ -62,7 +62,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
visibility: "public",
media_attachments: [],
mentions: [],
- tags: [],
+ tags: note.data["object"]["tag"],
application: %{
name: "Web",
website: nil
--
cgit v1.2.3
From 9ba4a1c5fe1cbc6f028f04be9c953a189a08bd09 Mon Sep 17 00:00:00 2001
From: raeno
Date: Mon, 10 Dec 2018 01:01:43 +0400
Subject: Fixes #415. Properly handle nil and empty string by User.parse_bio
---
test/web/twitter_api/twitter_api_test.exs | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 05f832de0..522cfd11d 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -246,7 +246,24 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
"nickname" => "lain",
"email" => "lain@wired.jp",
"fullname" => "lain iwakura",
- "bio" => "close the world.",
+ "password" => "bear",
+ "confirm" => "bear"
+ }
+
+ {:ok, user} = TwitterAPI.register_user(data)
+
+ fetched_user = Repo.get_by(User, nickname: "lain")
+
+ assert UserView.render("show.json", %{user: user}) ==
+ UserView.render("show.json", %{user: fetched_user})
+ end
+
+ test "it registers a new user with empty string in bio and returns the user." do
+ data = %{
+ "nickname" => "lain",
+ "email" => "lain@wired.jp",
+ "fullname" => "lain iwakura",
+ "bio" => "",
"password" => "bear",
"confirm" => "bear"
}
--
cgit v1.2.3
From c81c74d84715b25447840cf8536ac4ba0a4e98f1 Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 10 Dec 2018 19:13:53 +0100
Subject: Treat warnings as errors outside of tests.
---
test/support/builders/activity_builder.ex | 1 -
test/support/http_request_mock.ex | 2 +-
test/support/websub_mock.ex | 5 +++++
test/web/websub/websub_test.exs | 6 ------
4 files changed, 6 insertions(+), 8 deletions(-)
create mode 100644 test/support/websub_mock.ex
(limited to 'test')
diff --git a/test/support/builders/activity_builder.ex b/test/support/builders/activity_builder.ex
index eb72d5ba9..6e5a8e059 100644
--- a/test/support/builders/activity_builder.ex
+++ b/test/support/builders/activity_builder.ex
@@ -1,5 +1,4 @@
defmodule Pleroma.Builders.ActivityBuilder do
- alias Pleroma.Builders.UserBuilder
alias Pleroma.Web.ActivityPub.ActivityPub
def build(data \\ %{}, opts \\ %{}) do
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index 391342ad7..6f98fc5d0 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -13,7 +13,7 @@ defmodule HttpRequestMock do
with {:ok, res} <- apply(__MODULE__, method, [url, query, body, headers]) do
res
else
- {_, r} = error ->
+ {_, _r} = error ->
# Logger.warn(r)
error
end
diff --git a/test/support/websub_mock.ex b/test/support/websub_mock.ex
new file mode 100644
index 000000000..0cba0b740
--- /dev/null
+++ b/test/support/websub_mock.ex
@@ -0,0 +1,5 @@
+defmodule Pleroma.Web.WebsubMock do
+ def verify(sub) do
+ {:ok, sub}
+ end
+end
diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs
index 47d1a88e1..fd559743f 100644
--- a/test/web/websub/websub_test.exs
+++ b/test/web/websub/websub_test.exs
@@ -1,9 +1,3 @@
-defmodule Pleroma.Web.WebsubMock do
- def verify(sub) do
- {:ok, sub}
- end
-end
-
defmodule Pleroma.Web.WebsubTest do
use Pleroma.DataCase
alias Pleroma.Web.Websub
--
cgit v1.2.3
From 89b3729afa130a62a47ed6372350ebfc5acb4064 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Tue, 11 Dec 2018 15:31:52 +0300
Subject: fix warnings
---
test/filter_test.exs | 5 +-
test/list_test.exs | 5 +-
test/notification_test.exs | 8 +-
test/plugs/user_is_admin_plug_test.exs | 6 +-
test/support/conn_case.ex | 1 +
test/support/data_case.ex | 1 +
test/support/helpers.ex | 25 ++++++
test/user_test.exs | 37 +++++++--
.../activity_pub/activity_pub_controller_test.exs | 8 +-
test/web/activity_pub/activity_pub_test.exs | 2 +-
test/web/activity_pub/transmogrifier_test.exs | 13 ++-
test/web/admin_api/admin_api_controller_test.exs | 2 -
test/web/http_sigs/http_sig_test.exs | 5 --
test/web/mastodon_api/list_view_test.exs | 1 -
.../mastodon_api/mastodon_api_controller_test.exs | 28 ++++---
test/web/mastodon_api/mastodon_socket_test.exs | 2 -
test/web/oauth/authorization_test.exs | 2 +-
test/web/oauth/token_test.exs | 4 +-
test/web/ostatus/ostatus_controller_test.exs | 76 ++++++-----------
test/web/ostatus/ostatus_test.exs | 2 +-
test/web/retry_queue_test.exs | 2 +-
test/web/salmon/salmon_test.exs | 11 ++-
.../representers/activity_representer_test.exs | 1 -
.../twitter_api/twitter_api_controller_test.exs | 94 ++++++++++++----------
test/web/twitter_api/twitter_api_test.exs | 1 -
.../twitter_api/views/notification_view_test.exs | 5 +-
test/web/twitter_api/views/user_view_test.exs | 3 +-
27 files changed, 185 insertions(+), 165 deletions(-)
create mode 100644 test/support/helpers.ex
(limited to 'test')
diff --git a/test/filter_test.exs b/test/filter_test.exs
index 509c15317..2b31bcc08 100644
--- a/test/filter_test.exs
+++ b/test/filter_test.exs
@@ -1,9 +1,8 @@
defmodule Pleroma.FilterTest do
- alias Pleroma.{User, Repo}
+ alias Pleroma.Repo
use Pleroma.DataCase
import Pleroma.Factory
- import Ecto.Query
describe "creating filters" do
test "creating one filter" do
@@ -99,7 +98,7 @@ defmodule Pleroma.FilterTest do
context: ["home"]
}
- {:ok, filter} = Pleroma.Filter.create(query)
+ {:ok, _filter} = Pleroma.Filter.create(query)
{:ok, filter} = Pleroma.Filter.delete(query)
assert is_nil(Repo.get(Pleroma.Filter, filter.filter_id))
end
diff --git a/test/list_test.exs b/test/list_test.exs
index 19eef8f6b..2ab822815 100644
--- a/test/list_test.exs
+++ b/test/list_test.exs
@@ -1,9 +1,8 @@
defmodule Pleroma.ListTest do
- alias Pleroma.{User, Repo}
+ alias Pleroma.Repo
use Pleroma.DataCase
import Pleroma.Factory
- import Ecto.Query
test "creating a list" do
user = insert(:user)
@@ -32,7 +31,7 @@ defmodule Pleroma.ListTest do
user = insert(:user)
other_user = insert(:user)
{:ok, list} = Pleroma.List.create("title", user)
- {:ok, %{following: following}} = Pleroma.List.follow(list, other_user)
+ {:ok, %{following: _following}} = Pleroma.List.follow(list, other_user)
{:ok, %{following: following}} = Pleroma.List.unfollow(list, other_user)
assert [] == following
end
diff --git a/test/notification_test.exs b/test/notification_test.exs
index a36ed5bb8..385210793 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -127,12 +127,12 @@ defmodule Pleroma.NotificationTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} =
+ {:ok, _activity} =
TwitterAPI.create_status(user, %{
"status" => "hey @#{other_user.nickname}!"
})
- {:ok, activity} =
+ {:ok, _activity} =
TwitterAPI.create_status(user, %{
"status" => "hey again @#{other_user.nickname}!"
})
@@ -142,14 +142,14 @@ defmodule Pleroma.NotificationTest do
assert n2.id > n1.id
- {:ok, activity} =
+ {:ok, _activity} =
TwitterAPI.create_status(user, %{
"status" => "hey yet again @#{other_user.nickname}!"
})
Notification.set_read_up_to(other_user, n2.id)
- [n3, n2, n1] = notifs = Notification.for_user(other_user)
+ [n3, n2, n1] = Notification.for_user(other_user)
assert n1.seen == true
assert n2.seen == true
diff --git a/test/plugs/user_is_admin_plug_test.exs b/test/plugs/user_is_admin_plug_test.exs
index 031b2f466..cdab6b8ed 100644
--- a/test/plugs/user_is_admin_plug_test.exs
+++ b/test/plugs/user_is_admin_plug_test.exs
@@ -4,7 +4,7 @@ defmodule Pleroma.Plugs.UserIsAdminPlugTest do
alias Pleroma.Plugs.UserIsAdminPlug
import Pleroma.Factory
- test "accepts a user that is admin", %{conn: conn} do
+ test "accepts a user that is admin" do
user = insert(:user, info: %{is_admin: true})
conn =
@@ -18,7 +18,7 @@ defmodule Pleroma.Plugs.UserIsAdminPlugTest do
assert conn == ret_conn
end
- test "denies a user that isn't admin", %{conn: conn} do
+ test "denies a user that isn't admin" do
user = insert(:user)
conn =
@@ -29,7 +29,7 @@ defmodule Pleroma.Plugs.UserIsAdminPlugTest do
assert conn.status == 403
end
- test "denies when a user isn't set", %{conn: conn} do
+ test "denies when a user isn't set" do
conn =
build_conn()
|> UserIsAdminPlug.call(%{})
diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex
index 2e6707087..d25c28f49 100644
--- a/test/support/conn_case.ex
+++ b/test/support/conn_case.ex
@@ -19,6 +19,7 @@ defmodule Pleroma.Web.ConnCase do
quote do
# Import conveniences for testing with connections
use Phoenix.ConnTest
+ use Pleroma.Tests.Helpers
import Pleroma.Web.Router.Helpers
# The default endpoint for testing
diff --git a/test/support/data_case.ex b/test/support/data_case.ex
index 9dde6b5e5..53e7234d2 100644
--- a/test/support/data_case.ex
+++ b/test/support/data_case.ex
@@ -22,6 +22,7 @@ defmodule Pleroma.DataCase do
import Ecto.Changeset
import Ecto.Query
import Pleroma.DataCase
+ use Pleroma.Tests.Helpers
end
end
diff --git a/test/support/helpers.ex b/test/support/helpers.ex
new file mode 100644
index 000000000..64b6b1900
--- /dev/null
+++ b/test/support/helpers.ex
@@ -0,0 +1,25 @@
+defmodule Pleroma.Tests.Helpers do
+ @moduledoc """
+ Helpers for use in tests.
+ """
+
+ defmacro __using__(_opts) do
+ quote do
+ def refresh_record(%{id: id, __struct__: model} = _),
+ do: refresh_record(model, %{id: id})
+
+ def refresh_record(model, %{id: id} = _) do
+ Pleroma.Repo.get_by(model, id: id)
+ end
+
+ # Used for comparing json rendering during tests.
+ def render_json(view, template, assigns) do
+ assigns = Map.new(assigns)
+
+ view.render(template, assigns)
+ |> Poison.encode!()
+ |> Poison.decode!()
+ end
+ end
+ end
+end
diff --git a/test/user_test.exs b/test/user_test.exs
index 3d2f7f4e0..9baa5ef24 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1,13 +1,10 @@
defmodule Pleroma.UserTest do
alias Pleroma.Builders.UserBuilder
alias Pleroma.{User, Repo, Activity}
- alias Pleroma.Web.OStatus
- alias Pleroma.Web.Websub.WebsubClientSubscription
alias Pleroma.Web.CommonAPI
use Pleroma.DataCase
import Pleroma.Factory
- import Ecto.Query
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
@@ -163,6 +160,32 @@ defmodule Pleroma.UserTest do
end
end
+ describe "get_or_fetch/1" do
+ test "gets an existing user by nickname" do
+ user = insert(:user)
+ fetched_user = User.get_or_fetch(user.nickname)
+
+ assert user == fetched_user
+ end
+
+ test "gets an existing user by ap_id" do
+ ap_id = "http://mastodon.example.org/users/admin"
+
+ user =
+ insert(
+ :user,
+ local: false,
+ nickname: "admin@mastodon.example.org",
+ ap_id: ap_id,
+ info: %{}
+ )
+
+ fetched_user = User.get_or_fetch(ap_id)
+ freshed_user = refresh_record(user)
+ assert freshed_user == fetched_user
+ end
+ end
+
describe "fetching a user from nickname or trying to build one" do
test "gets an existing user" do
user = insert(:user)
@@ -574,7 +597,7 @@ defmodule Pleroma.UserTest do
describe "caching" do
test "invalidate_cache works" do
user = insert(:user)
- user_info = User.get_cached_user_info(user)
+ _user_info = User.get_cached_user_info(user)
User.invalidate_cache(user)
@@ -600,9 +623,9 @@ defmodule Pleroma.UserTest do
describe "User.search" do
test "finds a user, ranking by similarity" do
- user = insert(:user, %{name: "lain"})
- user_two = insert(:user, %{name: "ean"})
- user_three = insert(:user, %{name: "ebn", nickname: "lain@mastodon.social"})
+ _user = insert(:user, %{name: "lain"})
+ _user_two = insert(:user, %{name: "ean"})
+ _user_three = insert(:user, %{name: "ebn", nickname: "lain@mastodon.social"})
user_four = insert(:user, %{nickname: "lain@pleroma.soykaf.com"})
assert user_four ==
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index b4af2df5a..faeace016 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -23,10 +23,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "with the relay disabled, it returns 404", %{conn: conn} do
Pleroma.Config.put([:instance, :allow_relay], false)
- res =
- conn
- |> get(activity_pub_path(conn, :relay))
- |> json_response(404)
+ conn
+ |> get(activity_pub_path(conn, :relay))
+ |> json_response(404)
+ |> assert
Pleroma.Config.put([:instance, :allow_relay], true)
end
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 90f11ecd4..470ed08b2 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -180,7 +180,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
test "doesn't retrieve unlisted activities" do
user = insert(:user)
- {:ok, unlisted_activity} =
+ {:ok, _unlisted_activity} =
CommonAPI.post(user, %{"status" => "yeah", "visibility" => "unlisted"})
{:ok, listed_activity} = CommonAPI.post(user, %{"status" => "yeah"})
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index fa526a222..0428e052d 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -982,13 +982,12 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
end
test "users cannot be collided through fake direction spoofing attempts" do
- user =
- insert(:user, %{
- nickname: "rye@niu.moe",
- local: false,
- ap_id: "https://niu.moe/users/rye",
- follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
- })
+ insert(:user, %{
+ nickname: "rye@niu.moe",
+ local: false,
+ ap_id: "https://niu.moe/users/rye",
+ follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
+ })
{:error, _} = User.get_or_fetch_by_ap_id("https://n1u.moe/users/rye")
end
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index ba3b77fb6..4c12dd988 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -2,9 +2,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
use Pleroma.Web.ConnCase
alias Pleroma.{Repo, User}
-
import Pleroma.Factory
- import ExUnit.CaptureLog
describe "/api/pleroma/admin/user" do
test "Delete" do
diff --git a/test/web/http_sigs/http_sig_test.exs b/test/web/http_sigs/http_sig_test.exs
index 2e189d583..74d86a9e1 100644
--- a/test/web/http_sigs/http_sig_test.exs
+++ b/test/web/http_sigs/http_sig_test.exs
@@ -11,9 +11,6 @@ defmodule Pleroma.Web.HTTPSignaturesTest do
:ok
end
- @private_key hd(:public_key.pem_decode(File.read!("test/web/http_sigs/priv.key")))
- |> :public_key.pem_entry_decode()
-
@public_key hd(:public_key.pem_decode(File.read!("test/web/http_sigs/pub.key")))
|> :public_key.pem_entry_decode()
@@ -26,8 +23,6 @@ defmodule Pleroma.Web.HTTPSignaturesTest do
"content-length" => "18"
}
- @body "{\"hello\": \"world\"}"
-
@default_signature """
keyId="Test",algorithm="rsa-sha256",signature="jKyvPcxB4JbmYY4mByyBY7cZfNl4OW9HpFQlG7N4YcJPteKTu4MWCLyk+gIr0wDgqtLWf9NLpMAMimdfsH7FSWGfbMFSrsVTHNTk0rK3usrfFnti1dxsM4jl0kYJCKTGI/UWkqiaxwNiKqGcdlEDrTcUhhsFsOIo8VhddmZTZ8w="
"""
diff --git a/test/web/mastodon_api/list_view_test.exs b/test/web/mastodon_api/list_view_test.exs
index 5e36872ed..a12acc2b2 100644
--- a/test/web/mastodon_api/list_view_test.exs
+++ b/test/web/mastodon_api/list_view_test.exs
@@ -2,7 +2,6 @@ defmodule Pleroma.Web.MastodonAPI.ListViewTest do
use Pleroma.DataCase
import Pleroma.Factory
alias Pleroma.Web.MastodonAPI.ListView
- alias Pleroma.List
test "Represent a list" do
user = insert(:user)
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 092f0c9fc..e8275d4ab 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -5,7 +5,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Pleroma.{Repo, User, Object, Activity, Notification}
alias Pleroma.Web.{OStatus, CommonAPI}
alias Pleroma.Web.ActivityPub.ActivityPub
-
+ alias Pleroma.Web.MastodonAPI.FilterView
import Pleroma.Factory
import ExUnit.CaptureLog
import Tesla.Mock
@@ -351,12 +351,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, filter_one} = Pleroma.Filter.create(query_one)
{:ok, filter_two} = Pleroma.Filter.create(query_two)
- conn =
+ response =
conn
|> assign(:user, user)
|> get("/api/v1/filters")
-
- assert response = json_response(conn, 200)
+ |> json_response(200)
+
+ assert response ==
+ render_json(
+ FilterView,
+ "filters.json",
+ filters: [filter_two, filter_one]
+ )
end
test "get a filter", %{conn: conn} do
@@ -389,7 +395,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
context: ["home"]
}
- {:ok, filter} = Pleroma.Filter.create(query)
+ {:ok, _filter} = Pleroma.Filter.create(query)
new = %Pleroma.Filter{
phrase: "nii",
@@ -554,7 +560,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
other_user = insert(:user)
{:ok, activity_one} = TwitterAPI.create_status(other_user, %{"status" => "Marisa is cute."})
- {:ok, activity_two} =
+ {:ok, _activity_two} =
TwitterAPI.create_status(other_user, %{
"status" => "Marisa is cute.",
"visibility" => "private"
@@ -854,7 +860,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = insert(:user, %{info: %Pleroma.User.Info{locked: true}})
other_user = insert(:user)
- {:ok, activity} = ActivityPub.follow(other_user, user)
+ {:ok, _activity} = ActivityPub.follow(other_user, user)
user = Repo.get(User, user.id)
other_user = Repo.get(User, other_user.id)
@@ -874,7 +880,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = insert(:user, %{info: %Pleroma.User.Info{locked: true}})
other_user = insert(:user)
- {:ok, activity} = ActivityPub.follow(other_user, user)
+ {:ok, _activity} = ActivityPub.follow(other_user, user)
user = Repo.get(User, user.id)
other_user = Repo.get(User, other_user.id)
@@ -911,7 +917,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = insert(:user, %{info: %Pleroma.User.Info{locked: true}})
other_user = insert(:user)
- {:ok, activity} = ActivityPub.follow(other_user, user)
+ {:ok, _activity} = ActivityPub.follow(other_user, user)
conn =
build_conn()
@@ -1015,7 +1021,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "getting followers, hide_network", %{conn: conn} do
user = insert(:user)
other_user = insert(:user, %{info: %{hide_network: true}})
- {:ok, user} = User.follow(user, other_user)
+ {:ok, _user} = User.follow(user, other_user)
conn =
conn
@@ -1027,7 +1033,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "getting followers, hide_network, same user requesting", %{conn: conn} do
user = insert(:user)
other_user = insert(:user, %{info: %{hide_network: true}})
- {:ok, user} = User.follow(user, other_user)
+ {:ok, _user} = User.follow(user, other_user)
conn =
conn
diff --git a/test/web/mastodon_api/mastodon_socket_test.exs b/test/web/mastodon_api/mastodon_socket_test.exs
index c7d71defc..5d9b96861 100644
--- a/test/web/mastodon_api/mastodon_socket_test.exs
+++ b/test/web/mastodon_api/mastodon_socket_test.exs
@@ -1,9 +1,7 @@
defmodule Pleroma.Web.MastodonApi.MastodonSocketTest do
use Pleroma.DataCase
- alias Pleroma.Web.MastodonApi.MastodonSocket
alias Pleroma.Web.{Streamer, CommonAPI}
- alias Pleroma.User
import Pleroma.Factory
diff --git a/test/web/oauth/authorization_test.exs b/test/web/oauth/authorization_test.exs
index 98c7c4133..2b7fb2fad 100644
--- a/test/web/oauth/authorization_test.exs
+++ b/test/web/oauth/authorization_test.exs
@@ -71,7 +71,7 @@ defmodule Pleroma.Web.OAuth.AuthorizationTest do
{:ok, auth} = Authorization.create_authorization(app, user)
{:ok, auth} = Authorization.use_token(auth)
- {auths, _} = Authorization.delete_user_authorizations(user)
+ Authorization.delete_user_authorizations(user)
{_, invalid} = Authorization.use_token(auth)
diff --git a/test/web/oauth/token_test.exs b/test/web/oauth/token_test.exs
index f926ff50b..e36ca5abc 100644
--- a/test/web/oauth/token_test.exs
+++ b/test/web/oauth/token_test.exs
@@ -54,8 +54,8 @@ defmodule Pleroma.Web.OAuth.TokenTest do
{:ok, auth1} = Authorization.create_authorization(app1, user)
{:ok, auth2} = Authorization.create_authorization(app2, user)
- {:ok, token1} = Token.exchange_token(app1, auth1)
- {:ok, token2} = Token.exchange_token(app2, auth2)
+ {:ok, _token1} = Token.exchange_token(app1, auth1)
+ {:ok, _token2} = Token.exchange_token(app2, auth2)
{tokens, _} = Token.delete_user_tokens(user)
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index 411e89e94..560305c15 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -42,10 +42,10 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
"RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
})
- cng =
- Ecto.Changeset.change(salmon_user)
- |> Ecto.Changeset.put_embed(:info, info_cng)
- |> Repo.update()
+ salmon_user
+ |> Ecto.Changeset.change()
+ |> Ecto.Changeset.put_embed(:info, info_cng)
+ |> Repo.update()
conn =
build_conn()
@@ -97,82 +97,58 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
test "404s on private objects", %{conn: conn} do
note_activity = insert(:direct_note_activity)
- user = User.get_by_ap_id(note_activity.data["actor"])
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
- url = "/objects/#{uuid}"
-
- conn =
- conn
- |> get(url)
- assert response(conn, 404)
+ conn
+ |> get("/objects/#{uuid}")
+ |> response(404)
end
test "404s on nonexisting objects", %{conn: conn} do
- url = "/objects/123"
-
- conn =
- conn
- |> get(url)
-
- assert response(conn, 404)
+ conn
+ |> get("/objects/123")
+ |> response(404)
end
test "gets an activity", %{conn: conn} do
note_activity = insert(:note_activity)
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
- url = "/activities/#{uuid}"
- conn =
- conn
- |> get(url)
-
- assert response(conn, 200)
+ conn
+ |> get("/activities/#{uuid}")
+ |> response(200)
end
test "404s on private activities", %{conn: conn} do
note_activity = insert(:direct_note_activity)
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
- url = "/activities/#{uuid}"
-
- conn =
- conn
- |> get(url)
- assert response(conn, 404)
+ conn
+ |> get("/activities/#{uuid}")
+ |> response(404)
end
test "404s on nonexistent activities", %{conn: conn} do
- url = "/activities/123"
-
- conn =
- conn
- |> get(url)
-
- assert response(conn, 404)
+ conn
+ |> get("/activities/123")
+ |> response(404)
end
test "gets a notice", %{conn: conn} do
note_activity = insert(:note_activity)
- url = "/notice/#{note_activity.id}"
-
- conn =
- conn
- |> get(url)
- assert response(conn, 200)
+ conn
+ |> get("/notice/#{note_activity.id}")
+ |> response(200)
end
test "gets a notice in AS2 format", %{conn: conn} do
note_activity = insert(:note_activity)
- url = "/notice/#{note_activity.id}"
- conn =
- conn
- |> put_req_header("accept", "application/activity+json")
- |> get(url)
-
- assert json_response(conn, 200)
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/notice/#{note_activity.id}")
+ |> json_response(200)
end
test "only gets a notice in AS2 format for Create messages", %{conn: conn} do
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index f3268e83d..e577a6bee 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -511,7 +511,7 @@ defmodule Pleroma.Web.OStatusTest do
|> Map.put("type", "Article")
cs = Object.change(note_object, %{data: note_data})
- {:ok, article_object} = Repo.update(cs)
+ {:ok, _article_object} = Repo.update(cs)
# the underlying object is now an Article instead of a note, so this should fail
refute OStatus.is_representable?(note_activity)
diff --git a/test/web/retry_queue_test.exs b/test/web/retry_queue_test.exs
index ce2964993..b5a6ab030 100644
--- a/test/web/retry_queue_test.exs
+++ b/test/web/retry_queue_test.exs
@@ -4,7 +4,7 @@ defmodule MockActivityPub do
end
end
-defmodule Pleroma.ActivityTest do
+defmodule Pleroma.Web.Federator.RetryQueueTest do
use Pleroma.DataCase
alias Pleroma.Web.Federator.RetryQueue
diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs
index 23ccc038e..7e922ad83 100644
--- a/test/web/salmon/salmon_test.exs
+++ b/test/web/salmon/salmon_test.exs
@@ -3,7 +3,6 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
alias Pleroma.Web.Salmon
alias Pleroma.{Repo, Activity, User}
import Pleroma.Factory
- import Tesla.Mock
@magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
@@ -11,8 +10,8 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
@magickey_friendica "RSA.AMwa8FUs2fWEjX0xN7yRQgegQffhBpuKNC6fa5VNSVorFjGZhRrlPMn7TQOeihlc9lBz2OsHlIedbYn2uJ7yCs0.AQAB"
- setup do
- mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ setup_all do
+ Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok
end
@@ -75,7 +74,7 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
test "it pushes an activity to remote accounts it's addressed to" do
user_data = %{
info: %{
- "salmon" => "http://example.org/salmon"
+ salmon: "http://test-example.org/salmon"
},
local: false
}
@@ -97,8 +96,8 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
user = Repo.get_by(User, ap_id: activity.data["actor"])
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
- poster = fn url, _data, _headers, _options ->
- assert url == "http://example.org/salmon"
+ poster = fn url, _data, _headers ->
+ assert url == "http://test-example.org/salmon"
end
Salmon.publish(user, activity, poster)
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index 7cae4e4a1..f6c60a744 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -3,7 +3,6 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
alias Pleroma.{User, Activity, Object}
alias Pleroma.Web.TwitterAPI.Representers.{ActivityRepresenter, ObjectRepresenter}
alias Pleroma.Web.ActivityPub.ActivityPub
- alias Pleroma.Builders.UserBuilder
alias Pleroma.Web.TwitterAPI.UserView
import Pleroma.Factory
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 4119d1dd8..a30d415a7 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -12,20 +12,18 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
import Pleroma.Factory
+ @banner "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
+
describe "POST /api/account/update_profile_banner" do
test "it updates the banner", %{conn: conn} do
user = insert(:user)
- new_banner =
- "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
-
- response =
- conn
- |> assign(:user, user)
- |> post(authenticated_twitter_api__path(conn, :update_banner), %{"banner" => new_banner})
- |> json_response(200)
+ conn
+ |> assign(:user, user)
+ |> post(authenticated_twitter_api__path(conn, :update_banner), %{"banner" => @banner})
+ |> json_response(200)
- user = Repo.get(User, user.id)
+ user = refresh_record(user)
assert user.info.banner["type"] == "Image"
end
end
@@ -34,16 +32,12 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
test "it updates the background", %{conn: conn} do
user = insert(:user)
- new_bg =
- "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
-
- response =
- conn
- |> assign(:user, user)
- |> post(authenticated_twitter_api__path(conn, :update_background), %{"img" => new_bg})
- |> json_response(200)
+ conn
+ |> assign(:user, user)
+ |> post(authenticated_twitter_api__path(conn, :update_background), %{"img" => @banner})
+ |> json_response(200)
- user = Repo.get(User, user.id)
+ user = refresh_record(user)
assert user.info.background["type"] == "Image"
end
end
@@ -57,12 +51,12 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
test "with credentials", %{conn: conn, user: user} do
- conn =
+ response =
conn
|> with_credentials(user.nickname, "test")
|> post("/api/account/verify_credentials.json")
+ |> json_response(200)
- assert response = json_response(conn, 200)
assert response == UserView.render("show.json", %{user: user, token: response["token"]})
end
end
@@ -84,17 +78,28 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
"error" => "Client must provide a 'status' parameter with a value."
}
- conn = conn_with_creds |> post(request_path)
+ conn =
+ conn_with_creds
+ |> post(request_path)
+
assert json_response(conn, 400) == error_response
- conn = conn_with_creds |> post(request_path, %{status: ""})
+ conn =
+ conn_with_creds
+ |> post(request_path, %{status: ""})
+
assert json_response(conn, 400) == error_response
- conn = conn_with_creds |> post(request_path, %{status: " "})
+ conn =
+ conn_with_creds
+ |> post(request_path, %{status: " "})
+
assert json_response(conn, 400) == error_response
# we post with visibility private in order to avoid triggering relay
- conn = conn_with_creds |> post(request_path, %{status: "Nice meme.", visibility: "private"})
+ conn =
+ conn_with_creds
+ |> post(request_path, %{status: "Nice meme.", visibility: "private"})
assert json_response(conn, 200) ==
ActivityRepresenter.to_map(Repo.one(Activity), %{user: user})
@@ -117,7 +122,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert length(response) == 10
end
- test "returns 403 to unauthenticated request when the instance is not public" do
+ test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
instance =
Application.get_env(:pleroma, :instance)
|> Keyword.put(:public, false)
@@ -135,7 +140,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
Application.put_env(:pleroma, :instance, instance)
end
- test "returns 200 to unauthenticated request when the instance is public" do
+ test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
conn
|> get("/api/statuses/public_timeline.json")
|> json_response(200)
@@ -143,7 +148,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
describe "GET /statuses/public_and_external_timeline.json" do
- test "returns 403 to unauthenticated request when the instance is not public" do
+ test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
instance =
Application.get_env(:pleroma, :instance)
|> Keyword.put(:public, false)
@@ -161,7 +166,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
Application.put_env(:pleroma, :instance, instance)
end
- test "returns 200 to unauthenticated request when the instance is public" do
+ test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
conn
|> get("/api/statuses/public_and_external_timeline.json")
|> json_response(200)
@@ -654,14 +659,13 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
test "unimplemented mutes with credentials", %{conn: conn, user: current_user} do
- conn =
+ response =
conn
|> with_credentials(current_user.nickname, "test")
|> get("/api/qvitter/mutes.json")
+ |> json_response(200)
- current_user = Repo.get(User, current_user.id)
-
- assert [] = json_response(conn, 200)
+ assert [] = response
end
end
@@ -893,15 +897,16 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
follower_two = insert(:user)
not_follower = insert(:user)
- {:ok, follower_one} = User.follow(follower_one, user)
- {:ok, follower_two} = User.follow(follower_two, user)
+ {:ok, _follower_one} = User.follow(follower_one, user)
+ {:ok, _follower_two} = User.follow(follower_two, user)
- conn =
+ response =
conn
|> assign(:user, not_follower)
|> get("/api/statuses/followers", %{"user_id" => user.id})
+ |> json_response(200)
- assert [] == json_response(conn, 200)
+ assert [] == response
end
test "it returns the followers for a hidden network if requested by the user themselves", %{
@@ -910,10 +915,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
user = insert(:user, %{info: %{hide_network: true}})
follower_one = insert(:user)
follower_two = insert(:user)
- not_follower = insert(:user)
+ _not_follower = insert(:user)
- {:ok, follower_one} = User.follow(follower_one, user)
- {:ok, follower_two} = User.follow(follower_two, user)
+ {:ok, _follower_one} = User.follow(follower_one, user)
+ {:ok, _follower_two} = User.follow(follower_two, user)
conn =
conn
@@ -989,17 +994,18 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
user = insert(:user, %{info: %{hide_network: true}})
followed_one = insert(:user)
followed_two = insert(:user)
- not_followed = insert(:user)
+ _not_followed = insert(:user)
- {:ok, user} = User.follow(user, followed_one)
- {:ok, user} = User.follow(user, followed_two)
+ {:ok, _user} = User.follow(user, followed_one)
+ {:ok, _user} = User.follow(user, followed_two)
- conn =
+ response =
conn
|> assign(:user, user)
|> get("/api/statuses/friends", %{"user_id" => user.id})
+ |> json_response(200)
- refute [] == json_response(conn, 200)
+ refute [] == response
end
test "it returns a given user's friends with screen_name", %{conn: conn} do
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 522cfd11d..3d3a637b7 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -1,6 +1,5 @@
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
use Pleroma.DataCase
- alias Pleroma.Builders.UserBuilder
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView}
alias Pleroma.{Activity, User, Object, Repo, UserInviteToken}
alias Pleroma.Web.ActivityPub.ActivityPub
diff --git a/test/web/twitter_api/views/notification_view_test.exs b/test/web/twitter_api/views/notification_view_test.exs
index 79eafda7d..fcf2b3d90 100644
--- a/test/web/twitter_api/views/notification_view_test.exs
+++ b/test/web/twitter_api/views/notification_view_test.exs
@@ -8,7 +8,6 @@ defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
alias Pleroma.Web.TwitterAPI.ActivityView
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.ActivityPub.ActivityPub
- alias Pleroma.Builders.UserBuilder
import Pleroma.Factory
@@ -67,7 +66,7 @@ defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
user = User.get_cached_by_ap_id(note_activity.data["actor"])
repeater = insert(:user)
- {:ok, activity} = TwitterAPI.repeat(repeater, note_activity.id)
+ {:ok, _activity} = TwitterAPI.repeat(repeater, note_activity.id)
[notification] = Notification.for_user(user)
represented = %{
@@ -89,7 +88,7 @@ defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
user = User.get_cached_by_ap_id(note_activity.data["actor"])
liker = insert(:user)
- {:ok, activity} = TwitterAPI.fav(liker, note_activity.id)
+ {:ok, _activity} = TwitterAPI.fav(liker, note_activity.id)
[notification] = Notification.for_user(user)
represented = %{
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 9898c217d..34e6d4e27 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -4,7 +4,6 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
alias Pleroma.User
alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Web.CommonAPI.Utils
- alias Pleroma.Builders.UserBuilder
import Pleroma.Factory
@@ -27,7 +26,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
assert represented["profile_image_url"] == image
end
- test "A user with emoji in username", %{user: user} do
+ test "A user with emoji in username" do
expected =
" man"
--
cgit v1.2.3
From 4e7d98922ec621a5c9bc6638a40c09890f0f17a4 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Wed, 12 Dec 2018 16:28:00 +0300
Subject: [#114] Added tests for "POST /api/account/password_reset".
---
.../twitter_api/twitter_api_controller_test.exs | 43 +++++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index a30d415a7..c16c0cdc0 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -9,6 +9,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Comeonin.Pbkdf2
+ alias Ecto.Changeset
import Pleroma.Factory
@@ -270,7 +271,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
since_id = List.last(activities).id
current_user =
- Ecto.Changeset.change(current_user, following: [User.ap_followers(user)])
+ Changeset.change(current_user, following: [User.ap_followers(user)])
|> Repo.update!()
conn =
@@ -832,6 +833,46 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
end
+ describe "POST /api/account/password_reset, with valid parameters" do
+ setup %{conn: conn} do
+ user = insert(:user)
+ conn = post(conn, "/api/account/password_reset?email=#{user.email}")
+ %{conn: conn, user: user}
+ end
+
+ test "it returns 204", %{conn: conn} do
+ assert json_response(conn, :no_content)
+ end
+
+ test "it creates a PasswordResetToken record for user", %{user: user} do
+ token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
+ assert token_record
+ end
+
+ test "it sends an email to user", %{user: user} do
+ token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
+
+ Swoosh.TestAssertions.assert_email_sent(
+ Pleroma.UserEmail.password_reset_email(user, token_record.token)
+ )
+ end
+ end
+
+ describe "POST /api/account/password_reset, with invalid parameters" do
+ setup [:valid_user]
+
+ test "it returns 500 when user is not found", %{conn: conn, user: user} do
+ conn = post(conn, "/api/account/password_reset?email=nonexisting_#{user.email}")
+ assert json_response(conn, :internal_server_error)
+ end
+
+ test "it returns 500 when user is not local", %{conn: conn, user: user} do
+ {:ok, user} = Repo.update(Changeset.change(user, local: false))
+ conn = post(conn, "/api/account/password_reset?email=#{user.email}")
+ assert json_response(conn, :internal_server_error)
+ end
+ end
+
describe "GET /api/externalprofile/show" do
test "it returns the user", %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From 7d9ddbe6894a29dd41789ab584b2cd9f0e686c47 Mon Sep 17 00:00:00 2001
From: href
Date: Wed, 12 Dec 2018 18:17:15 +0100
Subject: Allow underscores in usernames.
Fixes #429.
---
test/formatter_test.exs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index abb9d882c..428227d78 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -109,13 +109,13 @@ defmodule Pleroma.FormatterTest do
describe "add_user_links" do
test "gives a replacement for user links" do
- text = "@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me"
+ text = "@gsimg According to @archa_eme_, that is @daggsy. Also hello @archaeme@archae.me"
gsimg = insert(:user, %{nickname: "gsimg"})
archaeme =
insert(:user, %{
- nickname: "archaeme",
- info: %Pleroma.User.Info{source_data: %{"url" => "https://archeme/@archaeme"}}
+ nickname: "archa_eme_",
+ info: %Pleroma.User.Info{source_data: %{"url" => "https://archeme/@archa_eme_"}}
})
archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
@@ -130,7 +130,7 @@ defmodule Pleroma.FormatterTest do
expected_text =
"@gsimg According to @archaeme , that is @daggsy. Also hello @archa_eme_ , that is @daggsy. Also hello @archaeme "
--
cgit v1.2.3
From 00744c6b03d043defcf87696f539d65e41ad6a62 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Thu, 13 Dec 2018 14:30:48 +0300
Subject: [#114] Initial implementation of user email invitations.
---
.../twitter_api/twitter_api_controller_test.exs | 32 ++++++++++++++++++++++
1 file changed, 32 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index c16c0cdc0..cbb5f7796 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -873,6 +873,38 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
end
+ describe "POST /api/email_invite, with valid parameters" do
+ setup [:valid_user]
+
+ setup do
+ invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
+ Pleroma.Config.put([:instance, :invites_enabled], true)
+
+ on_exit(fn ->
+ Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
+ :ok
+ end)
+
+ :ok
+ end
+
+ test "it returns 204", %{conn: conn, user: user} do
+ recipient_email = "foo@bar.com"
+ recipient_name = "J. D."
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/email_invite?email=#{recipient_email}&name=#{recipient_name}")
+
+ assert json_response(conn, :no_content)
+
+ Swoosh.TestAssertions.assert_email_sent(
+ Pleroma.UserEmail.user_invitation_email(user, recipient_email, recipient_name)
+ )
+ end
+ end
+
describe "GET /api/externalprofile/show" do
test "it returns the user", %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From 18b9467d1a63766123f625a964303f6b4d28a39f Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Thu, 13 Dec 2018 16:22:42 +0300
Subject: [#114] Removed `email_invite` implementation (to be addressed
separately).
---
.../twitter_api/twitter_api_controller_test.exs | 32 ----------------------
1 file changed, 32 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index cbb5f7796..c16c0cdc0 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -873,38 +873,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
end
- describe "POST /api/email_invite, with valid parameters" do
- setup [:valid_user]
-
- setup do
- invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
- Pleroma.Config.put([:instance, :invites_enabled], true)
-
- on_exit(fn ->
- Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
- :ok
- end)
-
- :ok
- end
-
- test "it returns 204", %{conn: conn, user: user} do
- recipient_email = "foo@bar.com"
- recipient_name = "J. D."
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/email_invite?email=#{recipient_email}&name=#{recipient_name}")
-
- assert json_response(conn, :no_content)
-
- Swoosh.TestAssertions.assert_email_sent(
- Pleroma.UserEmail.user_invitation_email(user, recipient_email, recipient_name)
- )
- end
- end
-
describe "GET /api/externalprofile/show" do
test "it returns the user", %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From 8902942128e3aee814c215d700e2eaee21b491e9 Mon Sep 17 00:00:00 2001
From: raeno
Date: Mon, 10 Dec 2018 23:08:02 +0400
Subject: WIP. Implement oembed route and handle both json/xml for "Note" type
activity
---
test/web/oembed/oembed_test.exs | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
create mode 100644 test/web/oembed/oembed_test.exs
(limited to 'test')
diff --git a/test/web/oembed/oembed_test.exs b/test/web/oembed/oembed_test.exs
new file mode 100644
index 000000000..16c2c3598
--- /dev/null
+++ b/test/web/oembed/oembed_test.exs
@@ -0,0 +1,23 @@
+defmodule Pleroma.Web.OEmbedTest do
+ use Pleroma.DataCase
+ alias Pleroma.Web.OEmbed
+ alias Pleroma.Web.XML
+ alias Pleroma.{Object, Repo, User, Activity}
+ import Pleroma.Factory
+ import ExUnit.CaptureLog
+
+ setup_all do
+ :ok
+ end
+
+ test 'recognizes notices in given url' do
+ url = "https://pleroma.site/notice/5"
+ assert { :activity, _ } = OEmbed.recognize_path(url)
+ end
+
+ test 'recognizes user card in given url' do
+ url = "https://pleroma.site/users/raeno"
+ assert { :user, _ } = OEmbed.recognize_path(url)
+ end
+
+end
--
cgit v1.2.3
From b5de7c4c4d90d1049b59381953cbd76e79b77e66 Mon Sep 17 00:00:00 2001
From: raeno
Date: Thu, 13 Dec 2018 22:16:54 +0100
Subject: Remove oembed for now, will submit it in another MR. Fix warnings
---
test/web/oembed/oembed_test.exs | 23 -----------------------
1 file changed, 23 deletions(-)
delete mode 100644 test/web/oembed/oembed_test.exs
(limited to 'test')
diff --git a/test/web/oembed/oembed_test.exs b/test/web/oembed/oembed_test.exs
deleted file mode 100644
index 16c2c3598..000000000
--- a/test/web/oembed/oembed_test.exs
+++ /dev/null
@@ -1,23 +0,0 @@
-defmodule Pleroma.Web.OEmbedTest do
- use Pleroma.DataCase
- alias Pleroma.Web.OEmbed
- alias Pleroma.Web.XML
- alias Pleroma.{Object, Repo, User, Activity}
- import Pleroma.Factory
- import ExUnit.CaptureLog
-
- setup_all do
- :ok
- end
-
- test 'recognizes notices in given url' do
- url = "https://pleroma.site/notice/5"
- assert { :activity, _ } = OEmbed.recognize_path(url)
- end
-
- test 'recognizes user card in given url' do
- url = "https://pleroma.site/users/raeno"
- assert { :user, _ } = OEmbed.recognize_path(url)
- end
-
-end
--
cgit v1.2.3
From c5c3ad90d00f1ea599e489aa03cfecada44c998c Mon Sep 17 00:00:00 2001
From: raeno
Date: Fri, 14 Dec 2018 02:59:33 +0100
Subject: Fix tests. Remove oembed template
---
test/web/ostatus/ostatus_controller_test.exs | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index 560305c15..747e30154 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -84,6 +84,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
conn =
conn
+ |> put_req_header("accept", "application/xml")
|> get(url)
expected =
@@ -110,11 +111,12 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|> response(404)
end
- test "gets an activity", %{conn: conn} do
+ test "gets an activity in xml format", %{conn: conn} do
note_activity = insert(:note_activity)
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
conn
+ |> put_req_header("accept", "application/xml")
|> get("/activities/#{uuid}")
|> response(200)
end
@@ -134,7 +136,22 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|> response(404)
end
- test "gets a notice", %{conn: conn} do
+ test "renders notice metatags in html format" do
+ note_activity = insert(:note_activity)
+
+ conn = get(conn, "/notice/#{note_activity.id}")
+
+ twitter_card_summary = " "
+
+ description_content =
+ " "
+
+ body = html_response(conn, 200)
+ assert body =~ twitter_card_summary
+ assert body =~ description_content
+ end
+
+ test "gets a notice in xml format", %{conn: conn} do
note_activity = insert(:note_activity)
conn
--
cgit v1.2.3
From 1ca080c8628d261cdb95145331aa36e631e90a3f Mon Sep 17 00:00:00 2001
From: eal
Date: Fri, 14 Dec 2018 07:56:49 +0200
Subject: Prevent accidental double RTs or favorites
---
test/web/common_api/common_api_test.exs | 39 +++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
(limited to 'test')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 8fc65f4c0..0b5a235f8 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -2,6 +2,7 @@ defmodule Pleroma.Web.CommonAPI.Test do
use Pleroma.DataCase
alias Pleroma.Web.CommonAPI
alias Pleroma.User
+ alias Pleroma.Activity
import Pleroma.Factory
@@ -53,4 +54,42 @@ defmodule Pleroma.Web.CommonAPI.Test do
assert content == "2hu
alert('xss')"
end
end
+
+ describe "reactions" do
+ test "repeating a status" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+
+ {:ok, %Activity{}, _} = CommonAPI.repeat(activity.id, user)
+ end
+
+ test "favoriting a status" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+
+ {:ok, %Activity{}, _} = CommonAPI.favorite(activity.id, user)
+ end
+
+ test "retweeting a status twice returns an error" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, %Activity{}, _object} = CommonAPI.repeat(activity.id, user)
+ {:error, _} = CommonAPI.repeat(activity.id, user)
+ end
+
+ test "favoriting a status twice returns an error" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, %Activity{}, _object} = CommonAPI.favorite(activity.id, user)
+ {:error, _} = CommonAPI.favorite(activity.id, user)
+ end
+ end
end
--
cgit v1.2.3
From 61ad2ce4221b86f77977d82c448d0eddb8add5aa Mon Sep 17 00:00:00 2001
From: eal
Date: Fri, 14 Dec 2018 08:24:18 +0200
Subject: TwitterAPI: Include favorited post in json
---
test/web/twitter_api/views/activity_view_test.exs | 3 +++
1 file changed, 3 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index bc36b0e90..77b8d99e7 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -112,6 +112,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
{:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
result = ActivityView.render("activity.json", activity: like)
+ activity = Pleroma.Activity.get_by_ap_id(activity.data["id"])
expected = %{
"activity_type" => "like",
@@ -121,6 +122,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"in_reply_to_status_id" => activity.id,
"is_local" => true,
"is_post_verb" => false,
+ "favorited_status" => ActivityView.render("activity.json", activity: activity),
"statusnet_html" => "shp favorited a status.",
"text" => "shp favorited a status.",
"uri" => "tag:#{like.data["id"]}:objectType=Favourite",
@@ -148,6 +150,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"in_reply_to_status_id" => nil,
"is_local" => true,
"is_post_verb" => false,
+ "favorited_status" => nil,
"statusnet_html" => "shp favorited a status.",
"text" => "shp favorited a status.",
"uri" => "tag:#{like.data["id"]}:objectType=Favourite",
--
cgit v1.2.3
From cc83d7ffe786f639172e28005e2912a0bad26234 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Thu, 13 Dec 2018 16:30:10 +0300
Subject: [#114] Naive implementation of email invitations.
---
.../twitter_api/twitter_api_controller_test.exs | 32 ++++++++++++++++++++++
1 file changed, 32 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index c16c0cdc0..cbb5f7796 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -873,6 +873,38 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
end
+ describe "POST /api/email_invite, with valid parameters" do
+ setup [:valid_user]
+
+ setup do
+ invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
+ Pleroma.Config.put([:instance, :invites_enabled], true)
+
+ on_exit(fn ->
+ Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
+ :ok
+ end)
+
+ :ok
+ end
+
+ test "it returns 204", %{conn: conn, user: user} do
+ recipient_email = "foo@bar.com"
+ recipient_name = "J. D."
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/email_invite?email=#{recipient_email}&name=#{recipient_name}")
+
+ assert json_response(conn, :no_content)
+
+ Swoosh.TestAssertions.assert_email_sent(
+ Pleroma.UserEmail.user_invitation_email(user, recipient_email, recipient_name)
+ )
+ end
+ end
+
describe "GET /api/externalprofile/show" do
test "it returns the user", %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From 3cbf16a5fe9f7618cae557eb260093881febd1d1 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Thu, 13 Dec 2018 17:58:40 +0300
Subject: [#114] Added UserInviteToken creation, adjusted invitation email link
to include it.
---
test/web/twitter_api/twitter_api_controller_test.exs | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index cbb5f7796..e5c6f848d 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -877,10 +877,13 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
setup [:valid_user]
setup do
+ registrations_open = Pleroma.Config.get([:instance, :registrations_open])
invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
+ Pleroma.Config.put([:instance, :registrations_open], false)
Pleroma.Config.put([:instance, :invites_enabled], true)
on_exit(fn ->
+ Pleroma.Config.put([:instance, :registrations_open], registrations_open)
Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
:ok
end)
@@ -888,7 +891,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
:ok
end
- test "it returns 204", %{conn: conn, user: user} do
+ test "sends invitation and returns 204", %{conn: conn, user: user} do
recipient_email = "foo@bar.com"
recipient_name = "J. D."
@@ -899,9 +902,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert json_response(conn, :no_content)
- Swoosh.TestAssertions.assert_email_sent(
- Pleroma.UserEmail.user_invitation_email(user, recipient_email, recipient_name)
- )
+ Swoosh.TestAssertions.assert_email_sent()
end
end
--
cgit v1.2.3
From a89e3b4b60b357992aeaedad8e3ff8d086f693a0 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Thu, 13 Dec 2018 18:23:05 +0300
Subject: [#114] Moved email_invite action to AdminAPIController, adjusted
tests.
---
test/web/admin_api/admin_api_controller_test.exs | 31 ++++++++++++++++++++
.../twitter_api/twitter_api_controller_test.exs | 33 ----------------------
2 files changed, 31 insertions(+), 33 deletions(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 4c12dd988..e7ad60aa3 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -154,6 +154,37 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
end
+ describe "POST /api/pleroma/admin/email_invite, with valid parameters" do
+ setup do
+ registrations_open = Pleroma.Config.get([:instance, :registrations_open])
+ invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
+ Pleroma.Config.put([:instance, :registrations_open], false)
+ Pleroma.Config.put([:instance, :invites_enabled], true)
+
+ on_exit(fn ->
+ Pleroma.Config.put([:instance, :registrations_open], registrations_open)
+ Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
+ :ok
+ end)
+
+ [user: insert(:user, info: %{is_admin: true})]
+ end
+
+ test "sends invitation and returns 204", %{conn: conn, user: user} do
+ recipient_email = "foo@bar.com"
+ recipient_name = "J. D."
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/pleroma/admin/email_invite?email=#{recipient_email}&name=#{recipient_name}")
+
+ assert json_response(conn, :no_content)
+
+ Swoosh.TestAssertions.assert_email_sent()
+ end
+ end
+
test "/api/pleroma/admin/invite_token" do
admin = insert(:user, info: %{is_admin: true})
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index e5c6f848d..c16c0cdc0 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -873,39 +873,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
end
- describe "POST /api/email_invite, with valid parameters" do
- setup [:valid_user]
-
- setup do
- registrations_open = Pleroma.Config.get([:instance, :registrations_open])
- invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
- Pleroma.Config.put([:instance, :registrations_open], false)
- Pleroma.Config.put([:instance, :invites_enabled], true)
-
- on_exit(fn ->
- Pleroma.Config.put([:instance, :registrations_open], registrations_open)
- Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
- :ok
- end)
-
- :ok
- end
-
- test "sends invitation and returns 204", %{conn: conn, user: user} do
- recipient_email = "foo@bar.com"
- recipient_name = "J. D."
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/email_invite?email=#{recipient_email}&name=#{recipient_name}")
-
- assert json_response(conn, :no_content)
-
- Swoosh.TestAssertions.assert_email_sent()
- end
- end
-
describe "GET /api/externalprofile/show" do
test "it returns the user", %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From 07e93f99404787b2c6b6193f90cb4102d00a72f9 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Fri, 14 Dec 2018 13:52:04 +0300
Subject: [#114] Improved tests.
---
test/web/admin_api/admin_api_controller_test.exs | 72 +++++++++++++++++++++++-
1 file changed, 70 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index e7ad60aa3..e183da3a1 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -154,7 +154,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
end
- describe "POST /api/pleroma/admin/email_invite, with valid parameters" do
+ describe "POST /api/pleroma/admin/email_invite, with valid config" do
setup do
registrations_open = Pleroma.Config.get([:instance, :registrations_open])
invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
@@ -181,7 +181,75 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert json_response(conn, :no_content)
- Swoosh.TestAssertions.assert_email_sent()
+ token_record = List.last(Pleroma.Repo.all(Pleroma.UserInviteToken))
+ assert token_record
+ refute token_record.used
+
+ Swoosh.TestAssertions.assert_email_sent(
+ Pleroma.UserEmail.user_invitation_email(
+ user,
+ token_record,
+ recipient_email,
+ recipient_name
+ )
+ )
+ end
+
+ test "it returns 403 if requested by a non-admin", %{conn: conn} do
+ non_admin_user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, non_admin_user)
+ |> post("/api/pleroma/admin/email_invite?email=foo@bar.com&name=JD")
+
+ assert json_response(conn, :forbidden)
+ end
+ end
+
+ describe "POST /api/pleroma/admin/email_invite, with invalid config" do
+ setup do
+ [user: insert(:user, info: %{is_admin: true})]
+ end
+
+ test "it returns 500 if `invites_enabled` is not enabled", %{conn: conn, user: user} do
+ registrations_open = Pleroma.Config.get([:instance, :registrations_open])
+ invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
+ Pleroma.Config.put([:instance, :registrations_open], false)
+ Pleroma.Config.put([:instance, :invites_enabled], false)
+
+ on_exit(fn ->
+ Pleroma.Config.put([:instance, :registrations_open], registrations_open)
+ Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
+ :ok
+ end)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/pleroma/admin/email_invite?email=foo@bar.com&name=JD")
+
+ assert json_response(conn, :internal_server_error)
+ end
+
+ test "it returns 500 if `registrations_open` is enabled", %{conn: conn, user: user} do
+ registrations_open = Pleroma.Config.get([:instance, :registrations_open])
+ invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
+ Pleroma.Config.put([:instance, :registrations_open], true)
+ Pleroma.Config.put([:instance, :invites_enabled], true)
+
+ on_exit(fn ->
+ Pleroma.Config.put([:instance, :registrations_open], registrations_open)
+ Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
+ :ok
+ end)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/pleroma/admin/email_invite?email=foo@bar.com&name=JD")
+
+ assert json_response(conn, :internal_server_error)
end
end
--
cgit v1.2.3
From baead4ea4b84ab1190b87a2dc73cdc4afaa6ebc6 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Fri, 14 Dec 2018 12:41:55 +0300
Subject: fix markdown formatting
---
test/formatter_test.exs | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
(limited to 'test')
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index 428227d78..bb318b7d5 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -257,4 +257,23 @@ defmodule Pleroma.FormatterTest do
text = nil
assert Formatter.get_emoji(text) == []
end
+
+ describe "/mentions_escape" do
+ test "it returns text with escaped mention names" do
+ text = """
+ @a_breakin_glass@cybre.space
+ (also, little voice inside my head thinking "maybe this will encourage people
+ pronouncing it properly instead of saying _raKEWdo_ ")
+ """
+
+ escape_text = """
+ @a\\_breakin\\_glass@cybre\\.space
+ (also, little voice inside my head thinking \"maybe this will encourage people
+ pronouncing it properly instead of saying _raKEWdo_ \")
+ """
+
+ mentions = [{"@a_breakin_glass@cybre.space", %{}}]
+ assert Formatter.mentions_escape(text, mentions) == escape_text
+ end
+ end
end
--
cgit v1.2.3
From d3ec09bb380bb990bea6edc5dae6bbda7f2322c5 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Thu, 13 Dec 2018 15:13:02 +0300
Subject: fix tags
---
test/web/mastodon_api/status_view_test.exs | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index d10d59d6c..4f9805c78 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -62,7 +62,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
visibility: "public",
media_attachments: [],
mentions: [],
- tags: note.data["object"]["tag"],
+ tags: [
+ %{
+ name: "#{note.data["object"]["tag"]}",
+ url: "/tag/#{note.data["object"]["tag"]}"
+ }
+ ],
application: %{
name: "Web",
website: nil
@@ -151,4 +156,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
assert represented[:reblog][:id] == to_string(activity.id)
assert represented[:emojis] == []
end
+
+ describe "build_tags/1" do
+ test "it returns a a dictionary tags" do
+ assert StatusView.build_tags(["fediverse", "mastodon", "nextcloud"]) == [
+ %{name: "fediverse", url: "/tag/fediverse"},
+ %{name: "mastodon", url: "/tag/mastodon"},
+ %{name: "nextcloud", url: "/tag/nextcloud"}
+ ]
+ end
+ end
end
--
cgit v1.2.3
From 9ff61ed793b7fd968b51c5f6e4b72958adeae977 Mon Sep 17 00:00:00 2001
From: raeno
Date: Fri, 14 Dec 2018 20:23:51 +0100
Subject: Fix tests
Notice test has been failing due to missing placeholder in index.html
I've tried to use fixtures to substitute that file in test environment but it became too much hassle. Fixtures are not copied to _build directory so I'd need to change file fetching logic. IMO it doesn't worth it since pleroma-fe already has this placeholder merged and all future updated of index.html will include it.
---
test/web/ostatus/ostatus_controller_test.exs | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index 747e30154..e9e9bdb16 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -136,17 +136,15 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|> response(404)
end
- test "renders notice metatags in html format" do
+ test "renders notice metatags in html format", %{conn: conn} do
note_activity = insert(:note_activity)
-
conn = get(conn, "/notice/#{note_activity.id}")
-
+ body = html_response(conn, 200)
twitter_card_summary = " "
description_content =
" "
- body = html_response(conn, 200)
assert body =~ twitter_card_summary
assert body =~ description_content
end
--
cgit v1.2.3
From ea72ac549b2ac52623462d6862154fb6f800c01c Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Fri, 14 Dec 2018 22:56:37 +0300
Subject: fix case when tags is invalid
---
test/web/mastodon_api/status_view_test.exs | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 4f9805c78..b7ac92760 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -159,7 +159,18 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
describe "build_tags/1" do
test "it returns a a dictionary tags" do
- assert StatusView.build_tags(["fediverse", "mastodon", "nextcloud"]) == [
+ object_tags = [
+ "fediverse",
+ "mastodon",
+ "nextcloud",
+ %{
+ "href" => "https://kawen.space/users/lain",
+ "name" => "@lain@kawen.space",
+ "type" => "Mention"
+ }
+ ]
+
+ assert StatusView.build_tags(object_tags) == [
%{name: "fediverse", url: "/tag/fediverse"},
%{name: "mastodon", url: "/tag/mastodon"},
%{name: "nextcloud", url: "/tag/nextcloud"}
--
cgit v1.2.3
From 5af91020f83acf3acad8511799e4b4e9ecda5b76 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Sat, 15 Dec 2018 16:17:44 +0100
Subject: Web.WebFinger.WebFingerControllerTest: test against XML and JRD
webfinger endpoints
---
test/web/web_finger/web_finger_controller_test.exs | 37 ++++++++++++++++++++++
1 file changed, 37 insertions(+)
create mode 100644 test/web/web_finger/web_finger_controller_test.exs
(limited to 'test')
diff --git a/test/web/web_finger/web_finger_controller_test.exs b/test/web/web_finger/web_finger_controller_test.exs
new file mode 100644
index 000000000..cac003e76
--- /dev/null
+++ b/test/web/web_finger/web_finger_controller_test.exs
@@ -0,0 +1,37 @@
+defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.User
+ alias Pleroma.Web.WebFinger.WebFingerController
+
+ import Pleroma.Factory
+ import ExUnit.CaptureLog
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
+ test "Webfinger JRD" do
+ user = insert(:user)
+
+ response =
+ build_conn()
+ |> put_req_header("accept", "application/jrd+json")
+ |> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
+
+ assert json_response(response, 200)["subject"] == "acct:#{user.nickname}@localhost"
+ end
+
+ test "Webfinger XML" do
+ user = insert(:user)
+
+ response =
+ build_conn()
+ |> put_req_header("accept", "application/jrd+json")
+ |> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
+
+ assert response(response, 200)
+ end
+end
--
cgit v1.2.3
From cddab5700b4903ba280fada57a79b8efe10f0bf6 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Sat, 15 Dec 2018 17:34:37 +0100
Subject: WebFinger: Sends a 400 when resource param is missing, fix XRD typo
in test
---
test/web/web_finger/web_finger_controller_test.exs | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/web_finger/web_finger_controller_test.exs b/test/web/web_finger/web_finger_controller_test.exs
index cac003e76..3bc878532 100644
--- a/test/web/web_finger/web_finger_controller_test.exs
+++ b/test/web/web_finger/web_finger_controller_test.exs
@@ -29,9 +29,18 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
response =
build_conn()
- |> put_req_header("accept", "application/jrd+json")
+ |> put_req_header("accept", "application/xrd+xml")
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
assert response(response, 200)
end
+
+ test "Sends a 400 when resource param is missing" do
+ response =
+ build_conn()
+ |> put_req_header("accept", "application/xrd+xml,application/jrd+json")
+ |> get("/.well-known/webfinger")
+
+ assert response(response, 400)
+ end
end
--
cgit v1.2.3
From e8537208bd9af701cbfc788ca307b8352306a36b Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Sat, 15 Dec 2018 22:38:39 +0300
Subject: Add a captcha mock for tests
---
test/support/captcha_mock.ex | 10 ++++++++++
1 file changed, 10 insertions(+)
create mode 100644 test/support/captcha_mock.ex
(limited to 'test')
diff --git a/test/support/captcha_mock.ex b/test/support/captcha_mock.ex
new file mode 100644
index 000000000..9d79f2e95
--- /dev/null
+++ b/test/support/captcha_mock.ex
@@ -0,0 +1,10 @@
+defmodule Pleroma.Captcha.Mock do
+ alias Pleroma.Captcha.Service
+ @behaviour Service
+
+ @impl Service
+ def new(), do: %{type: :mock}
+
+ @impl Service
+ def validate(_token, _captcha), do: true
+end
--
cgit v1.2.3
From 5f96c2d216c2728367dfdacb2dbbfc92eb30ce3c Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Sat, 15 Dec 2018 23:38:19 +0300
Subject: Add a test for kocaptcha
---
test/captcha_test.ex | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
create mode 100644 test/captcha_test.ex
(limited to 'test')
diff --git a/test/captcha_test.ex b/test/captcha_test.ex
new file mode 100644
index 000000000..3942cb051
--- /dev/null
+++ b/test/captcha_test.ex
@@ -0,0 +1,41 @@
+defmodule Pleroma.CaptchaTest do
+ use ExUnit.Case
+
+ import Tesla.Mock
+
+ @ets_options [:ordered_set, :private, :named_table, {:read_concurrency, true}]
+
+ describe "Kocaptcha" do
+
+ setup do
+ ets_name = Pleroma.Captcha.Kocaptcha.Ets
+ ^ets_name = :ets.new(ets_name, @ets_options)
+
+ mock fn
+ %{method: :get, url: "http://localhost:9093/new"} ->
+ json(
+ %{
+ md5: "63615261b77f5354fb8c4e4986477555",
+ token: "afa1815e14e29355e6c8f6b143a39fa2",
+ url: "/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
+ }
+ )
+ end
+
+ :ok
+ end
+
+ test "new and validate" do
+ assert Pleroma.Captcha.Kocaptcha.new() == %{
+ type: :kocaptcha,
+ token: "afa1815e14e29355e6c8f6b143a39fa2",
+ url: "http://localhost:9093/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
+ }
+
+ assert Pleroma.Captcha.Kocaptcha.validate(
+ "afa1815e14e29355e6c8f6b143a39fa2",
+ "7oEy8c"
+ )
+ end
+ end
+end
--
cgit v1.2.3
From c859cd1d61d81db4999c594ef61164d752d76145 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Sat, 15 Dec 2018 23:39:23 +0300
Subject: Fix style
---
test/captcha_test.ex | 31 ++++++++++++++-----------------
1 file changed, 14 insertions(+), 17 deletions(-)
(limited to 'test')
diff --git a/test/captcha_test.ex b/test/captcha_test.ex
index 3942cb051..98e8da79b 100644
--- a/test/captcha_test.ex
+++ b/test/captcha_test.ex
@@ -6,36 +6,33 @@ defmodule Pleroma.CaptchaTest do
@ets_options [:ordered_set, :private, :named_table, {:read_concurrency, true}]
describe "Kocaptcha" do
-
setup do
ets_name = Pleroma.Captcha.Kocaptcha.Ets
^ets_name = :ets.new(ets_name, @ets_options)
- mock fn
+ mock(fn
%{method: :get, url: "http://localhost:9093/new"} ->
- json(
- %{
- md5: "63615261b77f5354fb8c4e4986477555",
- token: "afa1815e14e29355e6c8f6b143a39fa2",
- url: "/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
- }
- )
- end
+ json(%{
+ md5: "63615261b77f5354fb8c4e4986477555",
+ token: "afa1815e14e29355e6c8f6b143a39fa2",
+ url: "/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
+ })
+ end)
:ok
end
test "new and validate" do
assert Pleroma.Captcha.Kocaptcha.new() == %{
- type: :kocaptcha,
- token: "afa1815e14e29355e6c8f6b143a39fa2",
- url: "http://localhost:9093/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
- }
+ type: :kocaptcha,
+ token: "afa1815e14e29355e6c8f6b143a39fa2",
+ url: "http://localhost:9093/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
+ }
assert Pleroma.Captcha.Kocaptcha.validate(
- "afa1815e14e29355e6c8f6b143a39fa2",
- "7oEy8c"
- )
+ "afa1815e14e29355e6c8f6b143a39fa2",
+ "7oEy8c"
+ )
end
end
end
--
cgit v1.2.3
From 36f1af232a3e34594617f2044652d7d02b19a234 Mon Sep 17 00:00:00 2001
From: link0ff
Date: Sun, 16 Dec 2018 02:14:23 +0200
Subject: Add tests for Mix tasks
---
test/tasks/user.exs | 225 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 225 insertions(+)
create mode 100644 test/tasks/user.exs
(limited to 'test')
diff --git a/test/tasks/user.exs b/test/tasks/user.exs
new file mode 100644
index 000000000..9f0942ba7
--- /dev/null
+++ b/test/tasks/user.exs
@@ -0,0 +1,225 @@
+defmodule Mix.Tasks.Pleroma.UserTest do
+ alias Pleroma.User
+ use Pleroma.DataCase
+
+ import Pleroma.Factory
+ import ExUnit.CaptureIO
+
+ setup_all do
+ Mix.shell(Mix.Shell.Process)
+
+ on_exit(fn ->
+ Mix.shell(Mix.Shell.IO)
+ end)
+
+ :ok
+ end
+
+ describe "running new" do
+ test "user is created" do
+ # just get random data
+ unsaved = build(:user)
+
+ # prepare to answer yes
+ send(self(), {:mix_shell_input, :yes?, true})
+
+ Mix.Tasks.Pleroma.User.run([
+ "new",
+ unsaved.nickname,
+ unsaved.email,
+ "--name",
+ unsaved.name,
+ "--bio",
+ unsaved.bio,
+ "--password",
+ "test",
+ "--moderator",
+ "--admin"
+ ])
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "user will be created"
+ assert_received {:mix_shell, :yes?, [message]}
+ assert message =~ "Continue"
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "created"
+
+ user = User.get_by_nickname(unsaved.nickname)
+ assert user.name == unsaved.name
+ assert user.email == unsaved.email
+ assert user.bio == unsaved.bio
+ assert user.info.is_moderator
+ assert user.info.is_admin
+ end
+
+ test "user is not created" do
+ unsaved = build(:user)
+
+ # prepare to answer no
+ send(self(), {:mix_shell_input, :yes?, false})
+ Mix.Tasks.Pleroma.User.run(["new", unsaved.nickname, unsaved.email])
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "user will be created"
+ assert_received {:mix_shell, :yes?, [message]}
+ assert message =~ "Continue"
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "will not be created"
+
+ refute User.get_by_nickname(unsaved.nickname)
+ end
+ end
+
+ describe "running rm" do
+ test "user is deleted" do
+ user = insert(:user)
+
+ Mix.Tasks.Pleroma.User.run(["rm", user.nickname])
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ " deleted"
+
+ user = User.get_by_nickname(user.nickname)
+ assert user.info.deactivated
+ end
+
+ test "no user to delete" do
+ Mix.Tasks.Pleroma.User.run(["rm", "nonexistant"])
+ assert_received {:mix_shell, :error, [message]}
+ assert message =~ "No local user"
+ end
+ end
+
+ describe "running toggle_activated" do
+ test "user is deactivated" do
+ user = insert(:user)
+
+ Mix.Tasks.Pleroma.User.run(["toggle_activated", user.nickname])
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ " deactivated"
+
+ user = User.get_by_nickname(user.nickname)
+ assert user.info.deactivated
+ end
+
+ test "user is activated" do
+ user = insert(:user, info: %{deactivated: true})
+
+ Mix.Tasks.Pleroma.User.run(["toggle_activated", user.nickname])
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ " activated"
+
+ user = User.get_by_nickname(user.nickname)
+ refute user.info.deactivated
+ end
+
+ test "no user to toggle" do
+ Mix.Tasks.Pleroma.User.run(["toggle_activated", "nonexistant"])
+ assert_received {:mix_shell, :error, [message]}
+ assert message =~ "No user"
+ end
+ end
+
+ describe "running unsubscribe" do
+ test "user is unsubscribed" do
+ followed = insert(:user)
+ user = insert(:user, %{following: [User.ap_followers(followed)]})
+
+ Mix.Tasks.Pleroma.User.run(["unsubscribe", user.nickname])
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "Deactivating"
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "Unsubscribing"
+ # Note that the task has delay :timer.sleep(500)
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "Successfully unsubscribed"
+
+ user = User.get_by_nickname(user.nickname)
+ assert length(user.following) == 0
+ assert user.info.deactivated
+ end
+
+ test "no user to unsubscribe" do
+ Mix.Tasks.Pleroma.User.run(["unsubscribe", "nonexistant"])
+ assert_received {:mix_shell, :error, [message]}
+ assert message =~ "No user"
+ end
+ end
+
+ describe "running set" do
+ test "All statuses set" do
+ user = insert(:user)
+
+ Mix.Tasks.Pleroma.User.run(["set", user.nickname, "--moderator", "--admin", "--locked"])
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ ~r"Moderator status .* true"
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ ~r"Locked status .* true"
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ ~r"Admin status .* true"
+
+ user = User.get_by_nickname(user.nickname)
+ assert user.info.is_moderator
+ assert user.info.locked
+ assert user.info.is_admin
+ end
+
+ test "All statuses unset" do
+ user = insert(:user, info: %{is_moderator: true, locked: true, is_admin: true})
+
+ Mix.Tasks.Pleroma.User.run([
+ "set",
+ user.nickname,
+ "--no-moderator",
+ "--no-admin",
+ "--no-locked"
+ ])
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ ~r"Moderator status .* false"
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ ~r"Locked status .* false"
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ ~r"Admin status .* false"
+
+ user = User.get_by_nickname(user.nickname)
+ refute user.info.is_moderator
+ refute user.info.locked
+ refute user.info.is_admin
+ end
+
+ test "no user to set status" do
+ Mix.Tasks.Pleroma.User.run(["set", "nonexistant", "--moderator"])
+ assert_received {:mix_shell, :error, [message]}
+ assert message =~ "No local user"
+ end
+ end
+
+ describe "running reset_password" do
+ test "password reset token is generated" do
+ user = insert(:user)
+
+ assert capture_io(fn ->
+ Mix.Tasks.Pleroma.User.run(["reset_password", user.nickname])
+ end) =~ "URL:"
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "Generated"
+ end
+
+ test "no user to reset password" do
+ Mix.Tasks.Pleroma.User.run(["reset_password", "nonexistant"])
+ assert_received {:mix_shell, :error, [message]}
+ assert message =~ "No local user"
+ end
+ end
+
+ describe "running invite" do
+ test "invite token is generated" do
+ assert capture_io(fn ->
+ Mix.Tasks.Pleroma.User.run(["invite"])
+ end) =~ "http"
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "Generated"
+ end
+ end
+end
--
cgit v1.2.3
From 2e72d49e373abf2957df82db6f8031c62936f9ba Mon Sep 17 00:00:00 2001
From: vaartis
Date: Sun, 16 Dec 2018 07:35:45 +0000
Subject: Rename captcha_test.ex to exs
---
test/captcha_test.ex | 38 --------------------------------------
test/captcha_test.exs | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 38 deletions(-)
delete mode 100644 test/captcha_test.ex
create mode 100644 test/captcha_test.exs
(limited to 'test')
diff --git a/test/captcha_test.ex b/test/captcha_test.ex
deleted file mode 100644
index 98e8da79b..000000000
--- a/test/captcha_test.ex
+++ /dev/null
@@ -1,38 +0,0 @@
-defmodule Pleroma.CaptchaTest do
- use ExUnit.Case
-
- import Tesla.Mock
-
- @ets_options [:ordered_set, :private, :named_table, {:read_concurrency, true}]
-
- describe "Kocaptcha" do
- setup do
- ets_name = Pleroma.Captcha.Kocaptcha.Ets
- ^ets_name = :ets.new(ets_name, @ets_options)
-
- mock(fn
- %{method: :get, url: "http://localhost:9093/new"} ->
- json(%{
- md5: "63615261b77f5354fb8c4e4986477555",
- token: "afa1815e14e29355e6c8f6b143a39fa2",
- url: "/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
- })
- end)
-
- :ok
- end
-
- test "new and validate" do
- assert Pleroma.Captcha.Kocaptcha.new() == %{
- type: :kocaptcha,
- token: "afa1815e14e29355e6c8f6b143a39fa2",
- url: "http://localhost:9093/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
- }
-
- assert Pleroma.Captcha.Kocaptcha.validate(
- "afa1815e14e29355e6c8f6b143a39fa2",
- "7oEy8c"
- )
- end
- end
-end
diff --git a/test/captcha_test.exs b/test/captcha_test.exs
new file mode 100644
index 000000000..98e8da79b
--- /dev/null
+++ b/test/captcha_test.exs
@@ -0,0 +1,38 @@
+defmodule Pleroma.CaptchaTest do
+ use ExUnit.Case
+
+ import Tesla.Mock
+
+ @ets_options [:ordered_set, :private, :named_table, {:read_concurrency, true}]
+
+ describe "Kocaptcha" do
+ setup do
+ ets_name = Pleroma.Captcha.Kocaptcha.Ets
+ ^ets_name = :ets.new(ets_name, @ets_options)
+
+ mock(fn
+ %{method: :get, url: "http://localhost:9093/new"} ->
+ json(%{
+ md5: "63615261b77f5354fb8c4e4986477555",
+ token: "afa1815e14e29355e6c8f6b143a39fa2",
+ url: "/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
+ })
+ end)
+
+ :ok
+ end
+
+ test "new and validate" do
+ assert Pleroma.Captcha.Kocaptcha.new() == %{
+ type: :kocaptcha,
+ token: "afa1815e14e29355e6c8f6b143a39fa2",
+ url: "http://localhost:9093/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
+ }
+
+ assert Pleroma.Captcha.Kocaptcha.validate(
+ "afa1815e14e29355e6c8f6b143a39fa2",
+ "7oEy8c"
+ )
+ end
+ end
+end
--
cgit v1.2.3
From 4c783e35c09c74097257ce56fde74025db0024c6 Mon Sep 17 00:00:00 2001
From: eal
Date: Sun, 16 Dec 2018 13:15:34 +0200
Subject: Mastodon API: Fix PUT /api/web/settings
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index e8275d4ab..aec0f851c 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1415,4 +1415,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert result["stats"]["user_count"] == 2
assert result["stats"]["status_count"] == 1
end
+
+ test "put settings", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> put("/api/web/settings", %{"data" => %{"programming" => "socks"}})
+
+ assert result = json_response(conn, 200)
+
+ user = User.get_cached_by_ap_id(user.ap_id)
+ assert user.info.settings == %{"programming" => "socks"}
+ end
end
--
cgit v1.2.3
From 7c235b8874d575cb1582b1fca2817a8db492bf4c Mon Sep 17 00:00:00 2001
From: link0ff
Date: Sun, 16 Dec 2018 18:04:31 +0200
Subject: Add more Mix task tests in relay_test.exs and uploads_test.exs.
Rename test/tasks/user.exs to test/tasks/user_test.exs.
---
test/tasks/relay_test.exs | 65 ++++++++++++
test/tasks/uploads_test.exs | 47 +++++++++
test/tasks/user.exs | 225 ----------------------------------------
test/tasks/user_test.exs | 247 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 359 insertions(+), 225 deletions(-)
create mode 100644 test/tasks/relay_test.exs
create mode 100644 test/tasks/uploads_test.exs
delete mode 100644 test/tasks/user.exs
create mode 100644 test/tasks/user_test.exs
(limited to 'test')
diff --git a/test/tasks/relay_test.exs b/test/tasks/relay_test.exs
new file mode 100644
index 000000000..737293865
--- /dev/null
+++ b/test/tasks/relay_test.exs
@@ -0,0 +1,65 @@
+defmodule Mix.Tasks.Pleroma.RelayTest do
+ alias Pleroma.Activity
+ alias Pleroma.Web.ActivityPub.{ActivityPub, Relay, Utils}
+ alias Pleroma.User
+ use Pleroma.DataCase
+
+ setup_all do
+ Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+
+ Mix.shell(Mix.Shell.Process)
+
+ on_exit(fn ->
+ Mix.shell(Mix.Shell.IO)
+ end)
+
+ :ok
+ end
+
+ describe "running follow" do
+ test "relay is followed" do
+ target_instance = "http://mastodon.example.org/users/admin"
+
+ Mix.Tasks.Pleroma.Relay.run(["follow", target_instance])
+
+ local_user = Relay.get_actor()
+ assert local_user.ap_id =~ "/relay"
+
+ target_user = User.get_by_ap_id(target_instance)
+ refute target_user.local
+
+ activity = Utils.fetch_latest_follow(local_user, target_user)
+ assert activity.data["type"] == "Follow"
+ assert activity.data["actor"] == local_user.ap_id
+ assert activity.data["object"] == target_user.ap_id
+ end
+ end
+
+ describe "running unfollow" do
+ test "relay is unfollowed" do
+ target_instance = "http://mastodon.example.org/users/admin"
+
+ Mix.Tasks.Pleroma.Relay.run(["follow", target_instance])
+
+ %User{ap_id: follower_id} = local_user = Relay.get_actor()
+ target_user = User.get_by_ap_id(target_instance)
+ follow_activity = Utils.fetch_latest_follow(local_user, target_user)
+
+ Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance])
+
+ cancelled_activity = Activity.get_by_ap_id(follow_activity.data["id"])
+ assert cancelled_activity.data["state"] == "cancelled"
+
+ [undo_activity] =
+ ActivityPub.fetch_activities([], %{
+ "type" => "Undo",
+ "actor_id" => follower_id,
+ "limit" => 1
+ })
+
+ assert undo_activity.data["type"] == "Undo"
+ assert undo_activity.data["actor"] == local_user.ap_id
+ assert undo_activity.data["object"] == cancelled_activity.data
+ end
+ end
+end
diff --git a/test/tasks/uploads_test.exs b/test/tasks/uploads_test.exs
new file mode 100644
index 000000000..a76e96df5
--- /dev/null
+++ b/test/tasks/uploads_test.exs
@@ -0,0 +1,47 @@
+defmodule Mix.Tasks.Pleroma.UploadsTest do
+ alias Pleroma.Upload
+ use Pleroma.DataCase
+
+ import Mock
+
+ setup_all do
+ Mix.shell(Mix.Shell.Process)
+
+ on_exit(fn ->
+ Mix.shell(Mix.Shell.IO)
+ end)
+
+ :ok
+ end
+
+ describe "running migrate_local" do
+ test "uploads migrated" do
+ with_mock Upload,
+ store: fn %Upload{name: _file, path: _path}, _opts -> {:ok, %{}} end do
+ Mix.Tasks.Pleroma.Uploads.run(["migrate_local", "S3"])
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "Migrating files from local"
+
+ assert_received {:mix_shell, :info, [message]}
+
+ assert %{"total_count" => total_count} =
+ Regex.named_captures(~r"^Found (?\d+) uploads$", message)
+
+ assert_received {:mix_shell, :info, [message]}
+
+ assert %{"count" => ^total_count, "total_count" => ^total_count} =
+ Regex.named_captures(
+ ~r"^Uploaded (?\d+)/(?\d+) files$",
+ message
+ )
+ end
+ end
+
+ test "nonexistent uploader" do
+ assert_raise RuntimeError, ~r/The uploader .* is not an existing/, fn ->
+ Mix.Tasks.Pleroma.Uploads.run(["migrate_local", "nonexistent"])
+ end
+ end
+ end
+end
diff --git a/test/tasks/user.exs b/test/tasks/user.exs
deleted file mode 100644
index 9f0942ba7..000000000
--- a/test/tasks/user.exs
+++ /dev/null
@@ -1,225 +0,0 @@
-defmodule Mix.Tasks.Pleroma.UserTest do
- alias Pleroma.User
- use Pleroma.DataCase
-
- import Pleroma.Factory
- import ExUnit.CaptureIO
-
- setup_all do
- Mix.shell(Mix.Shell.Process)
-
- on_exit(fn ->
- Mix.shell(Mix.Shell.IO)
- end)
-
- :ok
- end
-
- describe "running new" do
- test "user is created" do
- # just get random data
- unsaved = build(:user)
-
- # prepare to answer yes
- send(self(), {:mix_shell_input, :yes?, true})
-
- Mix.Tasks.Pleroma.User.run([
- "new",
- unsaved.nickname,
- unsaved.email,
- "--name",
- unsaved.name,
- "--bio",
- unsaved.bio,
- "--password",
- "test",
- "--moderator",
- "--admin"
- ])
-
- assert_received {:mix_shell, :info, [message]}
- assert message =~ "user will be created"
- assert_received {:mix_shell, :yes?, [message]}
- assert message =~ "Continue"
- assert_received {:mix_shell, :info, [message]}
- assert message =~ "created"
-
- user = User.get_by_nickname(unsaved.nickname)
- assert user.name == unsaved.name
- assert user.email == unsaved.email
- assert user.bio == unsaved.bio
- assert user.info.is_moderator
- assert user.info.is_admin
- end
-
- test "user is not created" do
- unsaved = build(:user)
-
- # prepare to answer no
- send(self(), {:mix_shell_input, :yes?, false})
- Mix.Tasks.Pleroma.User.run(["new", unsaved.nickname, unsaved.email])
- assert_received {:mix_shell, :info, [message]}
- assert message =~ "user will be created"
- assert_received {:mix_shell, :yes?, [message]}
- assert message =~ "Continue"
- assert_received {:mix_shell, :info, [message]}
- assert message =~ "will not be created"
-
- refute User.get_by_nickname(unsaved.nickname)
- end
- end
-
- describe "running rm" do
- test "user is deleted" do
- user = insert(:user)
-
- Mix.Tasks.Pleroma.User.run(["rm", user.nickname])
- assert_received {:mix_shell, :info, [message]}
- assert message =~ " deleted"
-
- user = User.get_by_nickname(user.nickname)
- assert user.info.deactivated
- end
-
- test "no user to delete" do
- Mix.Tasks.Pleroma.User.run(["rm", "nonexistant"])
- assert_received {:mix_shell, :error, [message]}
- assert message =~ "No local user"
- end
- end
-
- describe "running toggle_activated" do
- test "user is deactivated" do
- user = insert(:user)
-
- Mix.Tasks.Pleroma.User.run(["toggle_activated", user.nickname])
- assert_received {:mix_shell, :info, [message]}
- assert message =~ " deactivated"
-
- user = User.get_by_nickname(user.nickname)
- assert user.info.deactivated
- end
-
- test "user is activated" do
- user = insert(:user, info: %{deactivated: true})
-
- Mix.Tasks.Pleroma.User.run(["toggle_activated", user.nickname])
- assert_received {:mix_shell, :info, [message]}
- assert message =~ " activated"
-
- user = User.get_by_nickname(user.nickname)
- refute user.info.deactivated
- end
-
- test "no user to toggle" do
- Mix.Tasks.Pleroma.User.run(["toggle_activated", "nonexistant"])
- assert_received {:mix_shell, :error, [message]}
- assert message =~ "No user"
- end
- end
-
- describe "running unsubscribe" do
- test "user is unsubscribed" do
- followed = insert(:user)
- user = insert(:user, %{following: [User.ap_followers(followed)]})
-
- Mix.Tasks.Pleroma.User.run(["unsubscribe", user.nickname])
- assert_received {:mix_shell, :info, [message]}
- assert message =~ "Deactivating"
- assert_received {:mix_shell, :info, [message]}
- assert message =~ "Unsubscribing"
- # Note that the task has delay :timer.sleep(500)
- assert_received {:mix_shell, :info, [message]}
- assert message =~ "Successfully unsubscribed"
-
- user = User.get_by_nickname(user.nickname)
- assert length(user.following) == 0
- assert user.info.deactivated
- end
-
- test "no user to unsubscribe" do
- Mix.Tasks.Pleroma.User.run(["unsubscribe", "nonexistant"])
- assert_received {:mix_shell, :error, [message]}
- assert message =~ "No user"
- end
- end
-
- describe "running set" do
- test "All statuses set" do
- user = insert(:user)
-
- Mix.Tasks.Pleroma.User.run(["set", user.nickname, "--moderator", "--admin", "--locked"])
- assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r"Moderator status .* true"
- assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r"Locked status .* true"
- assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r"Admin status .* true"
-
- user = User.get_by_nickname(user.nickname)
- assert user.info.is_moderator
- assert user.info.locked
- assert user.info.is_admin
- end
-
- test "All statuses unset" do
- user = insert(:user, info: %{is_moderator: true, locked: true, is_admin: true})
-
- Mix.Tasks.Pleroma.User.run([
- "set",
- user.nickname,
- "--no-moderator",
- "--no-admin",
- "--no-locked"
- ])
-
- assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r"Moderator status .* false"
- assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r"Locked status .* false"
- assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r"Admin status .* false"
-
- user = User.get_by_nickname(user.nickname)
- refute user.info.is_moderator
- refute user.info.locked
- refute user.info.is_admin
- end
-
- test "no user to set status" do
- Mix.Tasks.Pleroma.User.run(["set", "nonexistant", "--moderator"])
- assert_received {:mix_shell, :error, [message]}
- assert message =~ "No local user"
- end
- end
-
- describe "running reset_password" do
- test "password reset token is generated" do
- user = insert(:user)
-
- assert capture_io(fn ->
- Mix.Tasks.Pleroma.User.run(["reset_password", user.nickname])
- end) =~ "URL:"
-
- assert_received {:mix_shell, :info, [message]}
- assert message =~ "Generated"
- end
-
- test "no user to reset password" do
- Mix.Tasks.Pleroma.User.run(["reset_password", "nonexistant"])
- assert_received {:mix_shell, :error, [message]}
- assert message =~ "No local user"
- end
- end
-
- describe "running invite" do
- test "invite token is generated" do
- assert capture_io(fn ->
- Mix.Tasks.Pleroma.User.run(["invite"])
- end) =~ "http"
-
- assert_received {:mix_shell, :info, [message]}
- assert message =~ "Generated"
- end
- end
-end
diff --git a/test/tasks/user_test.exs b/test/tasks/user_test.exs
new file mode 100644
index 000000000..7479bf749
--- /dev/null
+++ b/test/tasks/user_test.exs
@@ -0,0 +1,247 @@
+defmodule Mix.Tasks.Pleroma.UserTest do
+ alias Pleroma.User
+ use Pleroma.DataCase
+
+ import Pleroma.Factory
+ import ExUnit.CaptureIO
+
+ setup_all do
+ Mix.shell(Mix.Shell.Process)
+
+ on_exit(fn ->
+ Mix.shell(Mix.Shell.IO)
+ end)
+
+ :ok
+ end
+
+ describe "running new" do
+ test "user is created" do
+ # just get random data
+ unsaved = build(:user)
+
+ # prepare to answer yes
+ send(self(), {:mix_shell_input, :yes?, true})
+
+ Mix.Tasks.Pleroma.User.run([
+ "new",
+ unsaved.nickname,
+ unsaved.email,
+ "--name",
+ unsaved.name,
+ "--bio",
+ unsaved.bio,
+ "--password",
+ "test",
+ "--moderator",
+ "--admin"
+ ])
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "user will be created"
+
+ assert_received {:mix_shell, :yes?, [message]}
+ assert message =~ "Continue"
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "created"
+
+ user = User.get_by_nickname(unsaved.nickname)
+ assert user.name == unsaved.name
+ assert user.email == unsaved.email
+ assert user.bio == unsaved.bio
+ assert user.info.is_moderator
+ assert user.info.is_admin
+ end
+
+ test "user is not created" do
+ unsaved = build(:user)
+
+ # prepare to answer no
+ send(self(), {:mix_shell_input, :yes?, false})
+
+ Mix.Tasks.Pleroma.User.run(["new", unsaved.nickname, unsaved.email])
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "user will be created"
+
+ assert_received {:mix_shell, :yes?, [message]}
+ assert message =~ "Continue"
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "will not be created"
+
+ refute User.get_by_nickname(unsaved.nickname)
+ end
+ end
+
+ describe "running rm" do
+ test "user is deleted" do
+ user = insert(:user)
+
+ Mix.Tasks.Pleroma.User.run(["rm", user.nickname])
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ " deleted"
+
+ user = User.get_by_nickname(user.nickname)
+ assert user.info.deactivated
+ end
+
+ test "no user to delete" do
+ Mix.Tasks.Pleroma.User.run(["rm", "nonexistent"])
+
+ assert_received {:mix_shell, :error, [message]}
+ assert message =~ "No local user"
+ end
+ end
+
+ describe "running toggle_activated" do
+ test "user is deactivated" do
+ user = insert(:user)
+
+ Mix.Tasks.Pleroma.User.run(["toggle_activated", user.nickname])
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ " deactivated"
+
+ user = User.get_by_nickname(user.nickname)
+ assert user.info.deactivated
+ end
+
+ test "user is activated" do
+ user = insert(:user, info: %{deactivated: true})
+
+ Mix.Tasks.Pleroma.User.run(["toggle_activated", user.nickname])
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ " activated"
+
+ user = User.get_by_nickname(user.nickname)
+ refute user.info.deactivated
+ end
+
+ test "no user to toggle" do
+ Mix.Tasks.Pleroma.User.run(["toggle_activated", "nonexistent"])
+
+ assert_received {:mix_shell, :error, [message]}
+ assert message =~ "No user"
+ end
+ end
+
+ describe "running unsubscribe" do
+ test "user is unsubscribed" do
+ followed = insert(:user)
+ user = insert(:user, %{following: [User.ap_followers(followed)]})
+
+ Mix.Tasks.Pleroma.User.run(["unsubscribe", user.nickname])
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "Deactivating"
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "Unsubscribing"
+
+ # Note that the task has delay :timer.sleep(500)
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "Successfully unsubscribed"
+
+ user = User.get_by_nickname(user.nickname)
+ assert length(user.following) == 0
+ assert user.info.deactivated
+ end
+
+ test "no user to unsubscribe" do
+ Mix.Tasks.Pleroma.User.run(["unsubscribe", "nonexistent"])
+
+ assert_received {:mix_shell, :error, [message]}
+ assert message =~ "No user"
+ end
+ end
+
+ describe "running set" do
+ test "All statuses set" do
+ user = insert(:user)
+
+ Mix.Tasks.Pleroma.User.run(["set", user.nickname, "--moderator", "--admin", "--locked"])
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ ~r/Moderator status .* true/
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ ~r/Locked status .* true/
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ ~r/Admin status .* true/
+
+ user = User.get_by_nickname(user.nickname)
+ assert user.info.is_moderator
+ assert user.info.locked
+ assert user.info.is_admin
+ end
+
+ test "All statuses unset" do
+ user = insert(:user, info: %{is_moderator: true, locked: true, is_admin: true})
+
+ Mix.Tasks.Pleroma.User.run([
+ "set",
+ user.nickname,
+ "--no-moderator",
+ "--no-admin",
+ "--no-locked"
+ ])
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ ~r/Moderator status .* false/
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ ~r/Locked status .* false/
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ ~r/Admin status .* false/
+
+ user = User.get_by_nickname(user.nickname)
+ refute user.info.is_moderator
+ refute user.info.locked
+ refute user.info.is_admin
+ end
+
+ test "no user to set status" do
+ Mix.Tasks.Pleroma.User.run(["set", "nonexistent", "--moderator"])
+
+ assert_received {:mix_shell, :error, [message]}
+ assert message =~ "No local user"
+ end
+ end
+
+ describe "running reset_password" do
+ test "password reset token is generated" do
+ user = insert(:user)
+
+ assert capture_io(fn ->
+ Mix.Tasks.Pleroma.User.run(["reset_password", user.nickname])
+ end) =~ "URL:"
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "Generated"
+ end
+
+ test "no user to reset password" do
+ Mix.Tasks.Pleroma.User.run(["reset_password", "nonexistent"])
+
+ assert_received {:mix_shell, :error, [message]}
+ assert message =~ "No local user"
+ end
+ end
+
+ describe "running invite" do
+ test "invite token is generated" do
+ assert capture_io(fn ->
+ Mix.Tasks.Pleroma.User.run(["invite"])
+ end) =~ "http"
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "Generated"
+ end
+ end
+end
--
cgit v1.2.3
From f672555ad347861617c9b9b2c323b5044e840649 Mon Sep 17 00:00:00 2001
From: href
Date: Sun, 16 Dec 2018 17:15:07 +0100
Subject: Upgrade to Phoenix 1.4
---
test/web/web_finger/web_finger_controller_test.exs | 4 ----
1 file changed, 4 deletions(-)
(limited to 'test')
diff --git a/test/web/web_finger/web_finger_controller_test.exs b/test/web/web_finger/web_finger_controller_test.exs
index cac003e76..423e9d135 100644
--- a/test/web/web_finger/web_finger_controller_test.exs
+++ b/test/web/web_finger/web_finger_controller_test.exs
@@ -1,11 +1,7 @@
defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
use Pleroma.Web.ConnCase
- alias Pleroma.User
- alias Pleroma.Web.WebFinger.WebFingerController
-
import Pleroma.Factory
- import ExUnit.CaptureLog
import Tesla.Mock
setup do
--
cgit v1.2.3
From 73576ab64ef00aa012dbabae907e03faa436c212 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Sun, 16 Dec 2018 23:01:44 +0300
Subject: Fix captcha tests
---
test/captcha_test.exs | 4 ++--
test/support/captcha_mock.ex | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/captcha_test.exs b/test/captcha_test.exs
index 98e8da79b..2729e1382 100644
--- a/test/captcha_test.exs
+++ b/test/captcha_test.exs
@@ -11,7 +11,7 @@ defmodule Pleroma.CaptchaTest do
^ets_name = :ets.new(ets_name, @ets_options)
mock(fn
- %{method: :get, url: "http://localhost:9093/new"} ->
+ %{method: :get, url: "https://captcha.kotobank.ch/new"} ->
json(%{
md5: "63615261b77f5354fb8c4e4986477555",
token: "afa1815e14e29355e6c8f6b143a39fa2",
@@ -26,7 +26,7 @@ defmodule Pleroma.CaptchaTest do
assert Pleroma.Captcha.Kocaptcha.new() == %{
type: :kocaptcha,
token: "afa1815e14e29355e6c8f6b143a39fa2",
- url: "http://localhost:9093/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
+ url: "https://captcha.kotobank.ch/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
}
assert Pleroma.Captcha.Kocaptcha.validate(
diff --git a/test/support/captcha_mock.ex b/test/support/captcha_mock.ex
index 9d79f2e95..560d6c457 100644
--- a/test/support/captcha_mock.ex
+++ b/test/support/captcha_mock.ex
@@ -7,4 +7,7 @@ defmodule Pleroma.Captcha.Mock do
@impl Service
def validate(_token, _captcha), do: true
+
+ @impl Service
+ def cleanup(_token), do: true
end
--
cgit v1.2.3
From ef6829382aa32c03cf8536422537a9c219bd0035 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Sun, 16 Dec 2018 23:41:11 +0300
Subject: Clean captchas up periodically, not schedule it after theyre created
---
test/support/captcha_mock.ex | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/support/captcha_mock.ex b/test/support/captcha_mock.ex
index 560d6c457..898aa17b8 100644
--- a/test/support/captcha_mock.ex
+++ b/test/support/captcha_mock.ex
@@ -9,5 +9,5 @@ defmodule Pleroma.Captcha.Mock do
def validate(_token, _captcha), do: true
@impl Service
- def cleanup(_token), do: true
+ def cleanup(), do: :ok
end
--
cgit v1.2.3
From b12a90491156f1b31defd7aa1b322a86867dbf2b Mon Sep 17 00:00:00 2001
From: href
Date: Mon, 17 Dec 2018 17:09:06 +0100
Subject: Integration tests for mastodon websocket
---
test/integration/mastodon_websocket_test.exs | 100 +++++++++++++++++++++++++
test/support/websocket_client.ex | 58 ++++++++++++++
test/web/mastodon_api/mastodon_socket_test.exs | 31 --------
3 files changed, 158 insertions(+), 31 deletions(-)
create mode 100644 test/integration/mastodon_websocket_test.exs
create mode 100644 test/support/websocket_client.ex
delete mode 100644 test/web/mastodon_api/mastodon_socket_test.exs
(limited to 'test')
diff --git a/test/integration/mastodon_websocket_test.exs b/test/integration/mastodon_websocket_test.exs
new file mode 100644
index 000000000..b5f3d3a47
--- /dev/null
+++ b/test/integration/mastodon_websocket_test.exs
@@ -0,0 +1,100 @@
+defmodule Pleroma.Integration.MastodonWebsocketTest do
+ use Pleroma.DataCase
+
+ import Pleroma.Factory
+
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.OAuth
+ alias Pleroma.Integration.WebsocketClient
+ alias Pleroma.Web.Streamer
+
+ @path Pleroma.Web.Endpoint.url()
+ |> URI.parse()
+ |> Map.put(:scheme, "ws")
+ |> Map.put(:path, "/api/v1/streaming")
+ |> URI.to_string()
+
+ setup do
+ GenServer.start(Streamer, %{}, name: Streamer)
+
+ on_exit(fn ->
+ if pid = Process.whereis(Streamer) do
+ Process.exit(pid, :kill)
+ end
+ end)
+ end
+
+ def start_socket(qs \\ nil, headers \\ []) do
+ path =
+ case qs do
+ nil -> @path
+ qs -> @path <> qs
+ end
+
+ WebsocketClient.start_link(self(), path, headers)
+ end
+
+ test "refuses invalid requests" do
+ assert {:error, {400, _}} = start_socket()
+ assert {:error, {404, _}} = start_socket("?stream=ncjdk")
+ end
+
+ test "requires authentication and a valid token for protected streams" do
+ assert {:error, {403, _}} = start_socket("?stream=user&access_token=aaaaaaaaaaaa")
+ assert {:error, {403, _}} = start_socket("?stream=user")
+ end
+
+ test "allows public streams without authentication" do
+ assert {:ok, _} = start_socket("?stream=public")
+ assert {:ok, _} = start_socket("?stream=public:local")
+ assert {:ok, _} = start_socket("?stream=hashtag&tag=lain")
+ end
+
+ test "receives well formatted events" do
+ user = insert(:user)
+ {:ok, _} = start_socket("?stream=public")
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "nice echo chamber"})
+
+ assert_receive {:text, raw_json}, 1_000
+ assert {:ok, json} = Jason.decode(raw_json)
+
+ assert "update" == json["event"]
+ assert json["payload"]
+ assert {:ok, json} = Jason.decode(json["payload"])
+
+ # Note: we remove the "statuses_count" from this result as it changes in the meantime
+
+ view_json =
+ Pleroma.Web.MastodonAPI.StatusView.render("status.json", activity: activity, for: nil)
+ |> Jason.encode!()
+ |> Jason.decode!()
+ |> put_in(["account", "statuses_count"], 0)
+
+ assert json == view_json
+ end
+
+ describe "with a valid user token" do
+ setup do
+ {:ok, app} =
+ Pleroma.Repo.insert(
+ OAuth.App.register_changeset(%OAuth.App{}, %{
+ client_name: "client",
+ scopes: "scope",
+ redirect_uris: "url"
+ })
+ )
+
+ user = insert(:user)
+
+ {:ok, auth} = OAuth.Authorization.create_authorization(app, user)
+
+ {:ok, token} = OAuth.Token.exchange_token(app, auth)
+
+ %{user: user, token: token}
+ end
+
+ test "accepts valid tokens", state do
+ assert {:ok, _} = start_socket("?stream=user&access_token=#{state.token.token}")
+ end
+ end
+end
diff --git a/test/support/websocket_client.ex b/test/support/websocket_client.ex
new file mode 100644
index 000000000..57e9bb17f
--- /dev/null
+++ b/test/support/websocket_client.ex
@@ -0,0 +1,58 @@
+defmodule Pleroma.Integration.WebsocketClient do
+ # https://github.com/phoenixframework/phoenix/blob/master/test/support/websocket_client.exs
+
+ @doc """
+ Starts the WebSocket server for given ws URL. Received Socket.Message's
+ are forwarded to the sender pid
+ """
+ def start_link(sender, url, headers \\ []) do
+ :crypto.start()
+ :ssl.start()
+
+ :websocket_client.start_link(
+ String.to_charlist(url),
+ __MODULE__,
+ [sender],
+ extra_headers: headers
+ )
+ end
+
+ @doc """
+ Closes the socket
+ """
+ def close(socket) do
+ send(socket, :close)
+ end
+
+ @doc """
+ Sends a low-level text message to the client.
+ """
+ def send_text(server_pid, msg) do
+ send(server_pid, {:text, msg})
+ end
+
+ @doc false
+ def init([sender], _conn_state) do
+ {:ok, %{sender: sender}}
+ end
+
+ @doc false
+ def websocket_handle(frame, _conn_state, state) do
+ send(state.sender, frame)
+ {:ok, state}
+ end
+
+ @doc false
+ def websocket_info({:text, msg}, _conn_state, state) do
+ {:reply, {:text, msg}, state}
+ end
+
+ def websocket_info(:close, _conn_state, _state) do
+ {:close, <<>>, "done"}
+ end
+
+ @doc false
+ def websocket_terminate(_reason, _conn_state, _state) do
+ :ok
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_socket_test.exs b/test/web/mastodon_api/mastodon_socket_test.exs
deleted file mode 100644
index 5d9b96861..000000000
--- a/test/web/mastodon_api/mastodon_socket_test.exs
+++ /dev/null
@@ -1,31 +0,0 @@
-defmodule Pleroma.Web.MastodonApi.MastodonSocketTest do
- use Pleroma.DataCase
-
- alias Pleroma.Web.{Streamer, CommonAPI}
-
- import Pleroma.Factory
-
- test "public is working when non-authenticated" do
- user = insert(:user)
-
- task =
- Task.async(fn ->
- assert_receive {:text, _}, 4_000
- end)
-
- fake_socket = %{
- transport_pid: task.pid,
- assigns: %{}
- }
-
- topics = %{
- "public" => [fake_socket]
- }
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Test"})
-
- Streamer.push_to_socket(topics, "public", activity)
-
- Task.await(task)
- end
-end
--
cgit v1.2.3
From de981ac5a23673797951096b64a7f5ca49630467 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Mon, 17 Dec 2018 20:53:42 +0300
Subject: Alias Kocaptcha in the test
---
test/captcha_test.exs | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/captcha_test.exs b/test/captcha_test.exs
index 2729e1382..54ffbd92f 100644
--- a/test/captcha_test.exs
+++ b/test/captcha_test.exs
@@ -3,11 +3,13 @@ defmodule Pleroma.CaptchaTest do
import Tesla.Mock
+ alias Pleroma.Captcha.Kocaptcha
+
@ets_options [:ordered_set, :private, :named_table, {:read_concurrency, true}]
describe "Kocaptcha" do
setup do
- ets_name = Pleroma.Captcha.Kocaptcha.Ets
+ ets_name = Kocaptcha.Ets
^ets_name = :ets.new(ets_name, @ets_options)
mock(fn
@@ -23,13 +25,13 @@ defmodule Pleroma.CaptchaTest do
end
test "new and validate" do
- assert Pleroma.Captcha.Kocaptcha.new() == %{
+ assert Kocaptcha.new() == %{
type: :kocaptcha,
token: "afa1815e14e29355e6c8f6b143a39fa2",
url: "https://captcha.kotobank.ch/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
}
- assert Pleroma.Captcha.Kocaptcha.validate(
+ assert Kocaptcha.validate(
"afa1815e14e29355e6c8f6b143a39fa2",
"7oEy8c"
)
--
cgit v1.2.3
From e4763cd459d36b2fcd22e2e4abd3a2a326a21f5f Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 17 Dec 2018 20:12:01 +0100
Subject: Fix tagging problems for existing instances.
---
test/user_test.exs | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 9baa5ef24..1e73770df 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -11,6 +11,23 @@ defmodule Pleroma.UserTest do
:ok
end
+ describe "when tags are nil" do
+ test "tagging a user" do
+ user = insert(:user, %{tags: nil})
+ user = User.tag(user, ["cool", "dude"])
+
+ assert "cool" in user.tags
+ assert "dude" in user.tags
+ end
+
+ test "untagging a user" do
+ user = insert(:user, %{tags: nil})
+ user = User.untag(user, ["cool", "dude"])
+
+ assert user.tags == []
+ end
+ end
+
test "ap_id returns the activity pub id for the user" do
user = UserBuilder.build()
--
cgit v1.2.3
From 92a5133c42f62685007877eeaa26e4d61230d995 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Mon, 17 Dec 2018 22:41:36 +0300
Subject: fix text field
---
test/web/twitter_api/views/activity_view_test.exs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 77b8d99e7..8aa9e3130 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -14,6 +14,22 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
import Pleroma.Factory
import Mock
+ test "a create activity with a html status" do
+ text = """
+ #Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg
+ """
+
+ {:ok, activity} = CommonAPI.post(insert(:user), %{"status" => text})
+
+ result = ActivityView.render("activity.json", activity: activity)
+
+ assert result["statusnet_html"] ==
+ "#Bike log - Commute Tuesdayhttps://pla.bike/posts/20181211/ #cycling #CHScycling #commute MVIMG_20181211_054020.jpg"
+
+ assert result["text"] ==
+ "#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg"
+ end
+
test "a create activity with a note" do
user = insert(:user)
other_user = insert(:user, %{nickname: "shp"})
--
cgit v1.2.3
From 52bda3b456528e14bb9765660aa957d31f41e54c Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 17 Dec 2018 20:55:24 +0100
Subject: Fix uploads test.
---
test/tasks/uploads_test.exs | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/tasks/uploads_test.exs b/test/tasks/uploads_test.exs
index a76e96df5..93035abb6 100644
--- a/test/tasks/uploads_test.exs
+++ b/test/tasks/uploads_test.exs
@@ -30,7 +30,12 @@ defmodule Mix.Tasks.Pleroma.UploadsTest do
assert_received {:mix_shell, :info, [message]}
- assert %{"count" => ^total_count, "total_count" => ^total_count} =
+ # @logevery in Mix.Tasks.Pleroma.Uploads
+ count =
+ min(50, String.to_integer(total_count))
+ |> to_string()
+
+ assert %{"count" => ^count, "total_count" => ^total_count} =
Regex.named_captures(
~r"^Uploaded (?\d+)/(?\d+) files$",
message
--
cgit v1.2.3
From b1860fe85af1d32de937f466ba65d03614952e31 Mon Sep 17 00:00:00 2001
From: href
Date: Mon, 17 Dec 2018 22:50:59 +0100
Subject: Instance/Static runtime plug
This allows to set-up an arbitrary directory which overrides most of the
static files: index.html static/ emoji/ packs/ sounds/ images/ instance/
favicon.png.
If the files are not present in the directory, the bundled ones in
priv/static will be used.
---
test/plugs/instance_static_test.exs | 43 +++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 test/plugs/instance_static_test.exs
(limited to 'test')
diff --git a/test/plugs/instance_static_test.exs b/test/plugs/instance_static_test.exs
new file mode 100644
index 000000000..526679aae
--- /dev/null
+++ b/test/plugs/instance_static_test.exs
@@ -0,0 +1,43 @@
+defmodule Pleroma.Web.RuntimeStaticPlugTest do
+ use Pleroma.Web.ConnCase
+
+ @dir "test/tmp/instance_static"
+
+ setup do
+ static_dir = Pleroma.Config.get([:instance, :static_dir])
+ Pleroma.Config.put([:instance, :static_dir], @dir)
+ File.mkdir_p!(@dir)
+
+ on_exit(fn ->
+ Pleroma.Config.put([:instance, :static_dir], static_dir)
+ File.rm_rf(@dir)
+ end)
+ end
+
+ test "overrides index" do
+ bundled_index = get(build_conn(), "/")
+ assert html_response(bundled_index, 200) == File.read!("priv/static/index.html")
+
+ File.write!(@dir <> "/index.html", "hello world")
+
+ index = get(build_conn(), "/")
+ assert html_response(index, 200) == "hello world"
+ end
+
+ test "overrides any file in static/static" do
+ bundled_index = get(build_conn(), "/static/terms-of-service.html")
+
+ assert html_response(bundled_index, 200) ==
+ File.read!("priv/static/static/terms-of-service.html")
+
+ File.mkdir!(@dir <> "/static")
+ File.write!(@dir <> "/static/terms-of-service.html", "plz be kind")
+
+ index = get(build_conn(), "/static/terms-of-service.html")
+ assert html_response(index, 200) == "plz be kind"
+
+ File.write!(@dir <> "/static/kaniini.html", "rabbit hugs as a service ")
+ index = get(build_conn(), "/static/kaniini.html")
+ assert html_response(index, 200) == "rabbit hugs as a service "
+ end
+end
--
cgit v1.2.3
From daaa8cd66acf29eb869dd535b372f6673e9b3030 Mon Sep 17 00:00:00 2001
From: href
Date: Tue, 18 Dec 2018 13:40:25 +0100
Subject: SetUserSessionIdPlugTest: try to fix random ci failures
---
test/plugs/set_user_session_id_plug_test.exs | 2 ++
1 file changed, 2 insertions(+)
(limited to 'test')
diff --git a/test/plugs/set_user_session_id_plug_test.exs b/test/plugs/set_user_session_id_plug_test.exs
index 5edc0dab8..a5fdd4146 100644
--- a/test/plugs/set_user_session_id_plug_test.exs
+++ b/test/plugs/set_user_session_id_plug_test.exs
@@ -1,6 +1,8 @@
defmodule Pleroma.Plugs.SetUserSessionIdPlugTest do
use Pleroma.Web.ConnCase, async: true
+ Code.ensure_compiled(Pleroma.User)
+
alias Pleroma.Plugs.SetUserSessionIdPlug
alias Pleroma.User
--
cgit v1.2.3
From aed0f902871524ecc1db0d8c088ce5939e7c685a Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Tue, 18 Dec 2018 14:07:05 +0300
Subject: [#114] Added `pleroma.confirmation_pending` to user views, adjusted
view tests.
---
test/web/mastodon_api/account_view_test.exs | 10 ++++++++--
test/web/twitter_api/views/user_view_test.exs | 20 ++++++++++++++++----
2 files changed, 24 insertions(+), 6 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index 3cb9b9c5b..fec97c700 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -55,7 +55,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
privacy: "public",
sensitive: false
},
- pleroma: %{tags: []}
+ pleroma: %{
+ confirmation_pending: false,
+ tags: []
+ }
}
assert expected == AccountView.render("account.json", %{user: user})
@@ -93,7 +96,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
privacy: "public",
sensitive: false
},
- pleroma: %{tags: []}
+ pleroma: %{
+ confirmation_pending: false,
+ tags: []
+ }
}
assert expected == AccountView.render("account.json", %{user: user})
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 34e6d4e27..0adc69ff9 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -96,7 +96,10 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"default_scope" => "public",
"no_rich_text" => false,
"fields" => [],
- "pleroma" => %{"tags" => []}
+ "pleroma" => %{
+ "confirmation_pending" => false,
+ "tags" => []
+ }
}
assert represented == UserView.render("show.json", %{user: user})
@@ -138,7 +141,10 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"default_scope" => "public",
"no_rich_text" => false,
"fields" => [],
- "pleroma" => %{"tags" => []}
+ "pleroma" => %{
+ "confirmation_pending" => false,
+ "tags" => []
+ }
}
assert represented == UserView.render("show.json", %{user: user, for: follower})
@@ -181,7 +187,10 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"default_scope" => "public",
"no_rich_text" => false,
"fields" => [],
- "pleroma" => %{"tags" => []}
+ "pleroma" => %{
+ "confirmation_pending" => false,
+ "tags" => []
+ }
}
assert represented == UserView.render("show.json", %{user: follower, for: user})
@@ -231,7 +240,10 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"default_scope" => "public",
"no_rich_text" => false,
"fields" => [],
- "pleroma" => %{"tags" => []}
+ "pleroma" => %{
+ "confirmation_pending" => false,
+ "tags" => []
+ }
}
blocker = Repo.get(User, blocker.id)
--
cgit v1.2.3
From b096e30cffc79a4adf12be88da412a290cd0d190 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Tue, 18 Dec 2018 17:13:52 +0300
Subject: [#114] Added email confirmation resend action. Added tests for
registration, authentication, email confirmation, confirmation resending.
Made admin methods create confirmed users.
---
test/user_test.exs | 42 ++++++++++++++
test/web/oauth/oauth_controller_test.exs | 50 +++++++++++++++++
.../twitter_api/twitter_api_controller_test.exs | 64 ++++++++++++++++++++++
test/web/twitter_api/twitter_api_test.exs | 25 +++++++++
4 files changed, 181 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 1e73770df..b4d8174c6 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -177,6 +177,48 @@ defmodule Pleroma.UserTest do
end
end
+ describe "user registration, with :account_activation_required" do
+ @full_user_data %{
+ bio: "A guy",
+ name: "my name",
+ nickname: "nick",
+ password: "test",
+ password_confirmation: "test",
+ email: "email@example.com"
+ }
+
+ setup do
+ setting = Pleroma.Config.get([:instance, :account_activation_required])
+
+ unless setting do
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+ on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
+ end
+
+ :ok
+ end
+
+ test "it creates unconfirmed user" do
+ changeset = User.register_changeset(%User{}, @full_user_data)
+ assert changeset.valid?
+
+ {:ok, user} = Repo.insert(changeset)
+
+ assert user.info.confirmation_pending
+ assert user.info.confirmation_token
+ end
+
+ test "it creates confirmed user if :confirmed option is given" do
+ changeset = User.register_changeset(%User{}, @full_user_data, confirmed: true)
+ assert changeset.valid?
+
+ {:ok, user} = Repo.insert(changeset)
+
+ refute user.info.confirmation_pending
+ refute user.info.confirmation_token
+ end
+ end
+
describe "get_or_fetch/1" do
test "gets an existing user by nickname" do
user = insert(:user)
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index 3a902f128..55b471d8a 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -50,6 +50,26 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
assert Repo.get_by(Token, token: token)
end
+ test "issues a token for `password` grant_type with valid credentials" do
+ password = "testpassword"
+ user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
+
+ app = insert(:oauth_app)
+
+ conn =
+ build_conn()
+ |> post("/oauth/token", %{
+ "grant_type" => "password",
+ "username" => user.nickname,
+ "password" => password,
+ "client_id" => app.client_id,
+ "client_secret" => app.client_secret
+ })
+
+ assert %{"access_token" => token} = json_response(conn, 200)
+ assert Repo.get_by(Token, token: token)
+ end
+
test "issues a token for request with HTTP basic auth client credentials" do
user = insert(:user)
app = insert(:oauth_app)
@@ -93,6 +113,36 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
refute Map.has_key?(resp, "access_token")
end
+ test "rejects token exchange for valid credentials belonging to unconfirmed user" do
+ password = "testpassword"
+ user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
+ info_change = Pleroma.User.Info.confirmation_update(user.info, :unconfirmed)
+
+ {:ok, user} =
+ user
+ |> Ecto.Changeset.change()
+ |> Ecto.Changeset.put_embed(:info, info_change)
+ |> Repo.update()
+
+ refute Pleroma.User.auth_active?(user)
+
+ app = insert(:oauth_app)
+
+ conn =
+ build_conn()
+ |> post("/oauth/token", %{
+ "grant_type" => "password",
+ "username" => user.nickname,
+ "password" => password,
+ "client_id" => app.client_id,
+ "client_secret" => app.client_secret
+ })
+
+ assert resp = json_response(conn, 403)
+ assert %{"error" => _} = resp
+ refute Map.has_key?(resp, "access_token")
+ end
+
test "rejects an invalid authorization code" do
app = insert(:oauth_app)
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index c16c0cdc0..eb154608c 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -873,6 +873,70 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
end
+ describe "GET /api/account/confirm_email/:token" do
+ setup do
+ user = insert(:user)
+ info_change = User.Info.confirmation_update(user.info, :unconfirmed)
+
+ {:ok, user} =
+ user
+ |> Changeset.change()
+ |> Changeset.put_embed(:info, info_change)
+ |> Repo.update()
+
+ assert user.info.confirmation_pending
+
+ [user: user]
+ end
+
+ test "it redirects to root url", %{conn: conn, user: user} do
+ conn = get(conn, "/api/account/confirm_email/#{user.info.confirmation_token}")
+
+ assert 302 == conn.status
+ end
+
+ test "it confirms the user account", %{conn: conn, user: user} do
+ get(conn, "/api/account/confirm_email/#{user.info.confirmation_token}")
+
+ user = Repo.get(User, user.id)
+
+ refute user.info.confirmation_pending
+ refute user.info.confirmation_token
+ end
+ end
+
+ describe "POST /api/account/resend_confirmation_email" do
+ setup do
+ user = insert(:user)
+ info_change = User.Info.confirmation_update(user.info, :unconfirmed)
+
+ {:ok, user} =
+ user
+ |> Changeset.change()
+ |> Changeset.put_embed(:info, info_change)
+ |> Repo.update()
+
+ assert user.info.confirmation_pending
+
+ [user: user]
+ end
+
+ test "it returns 204 No Content", %{conn: conn, user: user} do
+ conn
+ |> assign(:user, user)
+ |> post("/api/account/resend_confirmation_email?email=#{user.email}")
+ |> json_response(:no_content)
+ end
+
+ test "it sends confirmation email", %{conn: conn, user: user} do
+ conn
+ |> assign(:user, user)
+ |> post("/api/account/resend_confirmation_email?email=#{user.email}")
+
+ Swoosh.TestAssertions.assert_email_sent(Pleroma.UserEmail.account_confirmation_email(user))
+ end
+ end
+
describe "GET /api/externalprofile/show" do
test "it returns the user", %{conn: conn} do
user = insert(:user)
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 3d3a637b7..b7c89b605 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -275,6 +275,31 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
UserView.render("show.json", %{user: fetched_user})
end
+ @moduletag skip: "needs 'account_activation_required: true' in config"
+ test "it sends confirmation email if :account_activation_required is specified in instance config" do
+ setting = Pleroma.Config.get([:instance, :account_activation_required])
+
+ unless setting do
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+ on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
+ end
+
+ data = %{
+ "nickname" => "lain",
+ "email" => "lain@wired.jp",
+ "fullname" => "lain iwakura",
+ "bio" => "",
+ "password" => "bear",
+ "confirm" => "bear"
+ }
+
+ {:ok, user} = TwitterAPI.register_user(data)
+
+ assert user.info.confirmation_pending
+
+ Swoosh.TestAssertions.assert_email_sent(Pleroma.UserEmail.account_confirmation_email(user))
+ end
+
test "it registers a new user and parses mentions in the bio" do
data1 = %{
"nickname" => "john",
--
cgit v1.2.3
From 8a67677d7791287905898bc388fbd8d9c81ec2b1 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Tue, 18 Dec 2018 22:10:56 +0300
Subject: Add test
---
test/formatter_test.exs | 12 ++++++++++++
1 file changed, 12 insertions(+)
(limited to 'test')
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index bb318b7d5..cfa735795 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -22,6 +22,18 @@ defmodule Pleroma.FormatterTest do
assert expected_text ==
Formatter.add_hashtag_links({[], text}, tags) |> Formatter.finalize()
end
+
+ test "does not turn html characters to tags" do
+ text = "Fact #3: pleroma does what mastodon't"
+
+ expected_text =
+ "Fact #3 : pleroma does what mastodon't"
+
+ tags = Formatter.parse_tags(text)
+
+ assert expected_text ==
+ Formatter.add_hashtag_links({[], text}, tags) |> Formatter.finalize()
+ end
end
describe ".add_links" do
--
cgit v1.2.3
From 196d9c0fd089942deff62aeeea60bef1972cbe38 Mon Sep 17 00:00:00 2001
From: Rin Toshaka
Date: Tue, 18 Dec 2018 20:30:04 +0100
Subject: Fix tests
---
test/formatter_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index cfa735795..6cdfa4167 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -27,7 +27,7 @@ defmodule Pleroma.FormatterTest do
text = "Fact #3: pleroma does what mastodon't"
expected_text =
- "Fact #3 : pleroma does what mastodon't"
+ "Fact #3 : pleroma does what mastodon't"
tags = Formatter.parse_tags(text)
--
cgit v1.2.3
From f3eb414e282dd0e3bd5c60838e45c69cf21541e4 Mon Sep 17 00:00:00 2001
From: lain
Date: Tue, 18 Dec 2018 21:08:52 +0100
Subject: Add a way to use the admin api without a user.
---
.../admin_secret_authentication_plug_test.exs | 38 ++++++++++++++++++++++
1 file changed, 38 insertions(+)
create mode 100644 test/plugs/admin_secret_authentication_plug_test.exs
(limited to 'test')
diff --git a/test/plugs/admin_secret_authentication_plug_test.exs b/test/plugs/admin_secret_authentication_plug_test.exs
new file mode 100644
index 000000000..c0fe2cf97
--- /dev/null
+++ b/test/plugs/admin_secret_authentication_plug_test.exs
@@ -0,0 +1,38 @@
+defmodule Pleroma.Plugs.AdminSecretAuthenticationPlugTest do
+ use Pleroma.Web.ConnCase, async: true
+ import Pleroma.Factory
+
+ alias Pleroma.Plugs.AdminSecretAuthenticationPlug
+
+ test "does nothing if a user is assigned", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+
+ ret_conn =
+ conn
+ |> AdminSecretAuthenticationPlug.call(%{})
+
+ assert conn == ret_conn
+ end
+
+ test "with secret set and given in the 'admin_token' parameter, it assigns an admin user", %{
+ conn: conn
+ } do
+ Pleroma.Config.put(:admin_token, "password123")
+
+ conn =
+ %{conn | params: %{"admin_token" => "wrong_password"}}
+ |> AdminSecretAuthenticationPlug.call(%{})
+
+ refute conn.assigns[:user]
+
+ conn =
+ %{conn | params: %{"admin_token" => "password123"}}
+ |> AdminSecretAuthenticationPlug.call(%{})
+
+ assert conn.assigns[:user].info.is_admin
+ end
+end
--
cgit v1.2.3
From 59fc5d15dfde0120fb10ec14631ad1115a6087a9 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Wed, 19 Dec 2018 16:27:16 +0300
Subject: [#114] User.Info: renamed `confirmation_update` to
`confirmation_change`.
---
test/web/oauth/oauth_controller_test.exs | 2 +-
test/web/twitter_api/twitter_api_controller_test.exs | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index 55b471d8a..26505bab7 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -116,7 +116,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
test "rejects token exchange for valid credentials belonging to unconfirmed user" do
password = "testpassword"
user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
- info_change = Pleroma.User.Info.confirmation_update(user.info, :unconfirmed)
+ info_change = Pleroma.User.Info.confirmation_change(user.info, :unconfirmed)
{:ok, user} =
user
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index eb154608c..a269c9757 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -876,7 +876,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "GET /api/account/confirm_email/:token" do
setup do
user = insert(:user)
- info_change = User.Info.confirmation_update(user.info, :unconfirmed)
+ info_change = User.Info.confirmation_change(user.info, :unconfirmed)
{:ok, user} =
user
@@ -908,7 +908,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "POST /api/account/resend_confirmation_email" do
setup do
user = insert(:user)
- info_change = User.Info.confirmation_update(user.info, :unconfirmed)
+ info_change = User.Info.confirmation_change(user.info, :unconfirmed)
{:ok, user} =
user
--
cgit v1.2.3
From 968d7490b689ba501a64f350841dc8f9b33b5244 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Wed, 19 Dec 2018 16:27:16 +0300
Subject: [#114] User.Info: renamed `confirmation_update` to
`confirmation_changeset`.
---
test/web/oauth/oauth_controller_test.exs | 2 +-
test/web/twitter_api/twitter_api_controller_test.exs | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index 26505bab7..0621a8acc 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -116,7 +116,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
test "rejects token exchange for valid credentials belonging to unconfirmed user" do
password = "testpassword"
user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
- info_change = Pleroma.User.Info.confirmation_change(user.info, :unconfirmed)
+ info_change = Pleroma.User.Info.confirmation_changeset(user.info, :unconfirmed)
{:ok, user} =
user
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index a269c9757..53b390793 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -876,7 +876,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "GET /api/account/confirm_email/:token" do
setup do
user = insert(:user)
- info_change = User.Info.confirmation_change(user.info, :unconfirmed)
+ info_change = User.Info.confirmation_changeset(user.info, :unconfirmed)
{:ok, user} =
user
@@ -908,7 +908,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "POST /api/account/resend_confirmation_email" do
setup do
user = insert(:user)
- info_change = User.Info.confirmation_change(user.info, :unconfirmed)
+ info_change = User.Info.confirmation_changeset(user.info, :unconfirmed)
{:ok, user} =
user
--
cgit v1.2.3
From adbb265fc6559c0f93c369b6adde94e9eb92f3c9 Mon Sep 17 00:00:00 2001
From: href
Date: Wed, 19 Dec 2018 20:14:33 +0100
Subject: daaa8cd6 take two
---
test/plugs/set_user_session_id_plug_test.exs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/plugs/set_user_session_id_plug_test.exs b/test/plugs/set_user_session_id_plug_test.exs
index a5fdd4146..7cf8e42cc 100644
--- a/test/plugs/set_user_session_id_plug_test.exs
+++ b/test/plugs/set_user_session_id_plug_test.exs
@@ -1,8 +1,6 @@
defmodule Pleroma.Plugs.SetUserSessionIdPlugTest do
use Pleroma.Web.ConnCase, async: true
- Code.ensure_compiled(Pleroma.User)
-
alias Pleroma.Plugs.SetUserSessionIdPlug
alias Pleroma.User
@@ -30,6 +28,8 @@ defmodule Pleroma.Plugs.SetUserSessionIdPlugTest do
end
test "sets the user_id in the session to the user id of the user assign", %{conn: conn} do
+ Code.ensure_compiled(Pleroma.User)
+
conn =
conn
|> assign(:user, %User{id: 1})
--
cgit v1.2.3
From f1b93b5be761826af9b833411689e9e0c086b815 Mon Sep 17 00:00:00 2001
From: Maksim
Date: Thu, 20 Dec 2018 09:35:01 +0000
Subject: [#413] fix parse mentions
---
test/formatter_test.exs | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index 6cdfa4167..584700b6a 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -215,8 +215,11 @@ defmodule Pleroma.FormatterTest do
end
test "it can parse mentions and return the relevant users" do
- text = "@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me"
+ text =
+ "@@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me and @o and @@@jimm"
+ o = insert(:user, %{nickname: "o"})
+ jimm = insert(:user, %{nickname: "jimm"})
gsimg = insert(:user, %{nickname: "gsimg"})
archaeme = insert(:user, %{nickname: "archaeme"})
archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
@@ -224,7 +227,9 @@ defmodule Pleroma.FormatterTest do
expected_result = [
{"@gsimg", gsimg},
{"@archaeme", archaeme},
- {"@archaeme@archae.me", archaeme_remote}
+ {"@archaeme@archae.me", archaeme_remote},
+ {"@o", o},
+ {"@jimm", jimm}
]
assert Formatter.parse_mentions(text) == expected_result
--
cgit v1.2.3
From f69cbf4755b974de0303731327180bb51ed244fc Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Thu, 20 Dec 2018 13:41:30 +0300
Subject: [#114] Added :user_id component to email confirmation path to improve
the security. Added tests for `confirm_email` action.
---
test/web/twitter_api/twitter_api_controller_test.exs | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 53b390793..16422c35a 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -873,7 +873,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
end
- describe "GET /api/account/confirm_email/:token" do
+ describe "GET /api/account/confirm_email/:id/:token" do
setup do
user = insert(:user)
info_change = User.Info.confirmation_changeset(user.info, :unconfirmed)
@@ -890,19 +890,31 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
test "it redirects to root url", %{conn: conn, user: user} do
- conn = get(conn, "/api/account/confirm_email/#{user.info.confirmation_token}")
+ conn = get(conn, "/api/account/confirm_email/#{user.id}/#{user.info.confirmation_token}")
assert 302 == conn.status
end
test "it confirms the user account", %{conn: conn, user: user} do
- get(conn, "/api/account/confirm_email/#{user.info.confirmation_token}")
+ get(conn, "/api/account/confirm_email/#{user.id}/#{user.info.confirmation_token}")
user = Repo.get(User, user.id)
refute user.info.confirmation_pending
refute user.info.confirmation_token
end
+
+ test "it returns 500 if user cannot be found by id", %{conn: conn, user: user} do
+ conn = get(conn, "/api/account/confirm_email/0/#{user.info.confirmation_token}")
+
+ assert 500 == conn.status
+ end
+
+ test "it returns 500 if token is invalid", %{conn: conn, user: user} do
+ conn = get(conn, "/api/account/confirm_email/#{user.id}/wrong_token")
+
+ assert 500 == conn.status
+ end
end
describe "POST /api/account/resend_confirmation_email" do
--
cgit v1.2.3
From 7cab7de9ff0432a582cfca0852a4b66fdd124c41 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Thu, 20 Dec 2018 14:48:48 +0300
Subject: [#114] Allowed unconfirmed users to authenticate if
:account_activation_required is disabled prior to confirmation. Ensured that
no confirmation emails are sent if :account_activation_required is not true.
Adjusted tests.
---
test/web/twitter_api/twitter_api_controller_test.exs | 7 +++++++
1 file changed, 7 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 16422c35a..1324bcc71 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -919,6 +919,13 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "POST /api/account/resend_confirmation_email" do
setup do
+ setting = Pleroma.Config.get([:instance, :account_activation_required])
+
+ unless setting do
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+ on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
+ end
+
user = insert(:user)
info_change = User.Info.confirmation_changeset(user.info, :unconfirmed)
--
cgit v1.2.3
From 851db74f1ca533f27f72f1341571948b15d2f561 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Thu, 20 Dec 2018 15:23:16 +0300
Subject: [#114] Fixed test.
---
test/web/oauth/oauth_controller_test.exs | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index 0621a8acc..52441407d 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -113,7 +113,14 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
refute Map.has_key?(resp, "access_token")
end
- test "rejects token exchange for valid credentials belonging to unconfirmed user" do
+ test "rejects token exchange for valid credentials belonging to unconfirmed user and confirmation is required" do
+ setting = Pleroma.Config.get([:instance, :account_activation_required])
+
+ unless setting do
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+ on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
+ end
+
password = "testpassword"
user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
info_change = Pleroma.User.Info.confirmation_changeset(user.info, :unconfirmed)
--
cgit v1.2.3
From 336e37d98f1b86c0332c9f260e27455a14714fa6 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Fri, 21 Dec 2018 00:32:37 +0300
Subject: Make captcha (kocaptcha) stateless
Also rename seconds_retained to seconds_valid since that's how it is
now. Put it down from 180 to 20 seconds. The answer data is now
stored in an encrypted text transfered to the client and back, so no
ETS is needed
---
test/captcha_test.exs | 18 ++++++++++--------
test/support/captcha_mock.ex | 5 +----
2 files changed, 11 insertions(+), 12 deletions(-)
(limited to 'test')
diff --git a/test/captcha_test.exs b/test/captcha_test.exs
index 54ffbd92f..93b8930da 100644
--- a/test/captcha_test.exs
+++ b/test/captcha_test.exs
@@ -25,16 +25,18 @@ defmodule Pleroma.CaptchaTest do
end
test "new and validate" do
- assert Kocaptcha.new() == %{
- type: :kocaptcha,
- token: "afa1815e14e29355e6c8f6b143a39fa2",
- url: "https://captcha.kotobank.ch/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
- }
+ new = Kocaptcha.new()
+ assert new[:type] == :kocaptcha
+ assert new[:token] == "afa1815e14e29355e6c8f6b143a39fa2"
+
+ assert new[:url] ==
+ "https://captcha.kotobank.ch/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
assert Kocaptcha.validate(
- "afa1815e14e29355e6c8f6b143a39fa2",
- "7oEy8c"
- )
+ new[:token],
+ "7oEy8c",
+ new[:answer_data]
+ ) == :ok
end
end
end
diff --git a/test/support/captcha_mock.ex b/test/support/captcha_mock.ex
index 898aa17b8..410318dc4 100644
--- a/test/support/captcha_mock.ex
+++ b/test/support/captcha_mock.ex
@@ -6,8 +6,5 @@ defmodule Pleroma.Captcha.Mock do
def new(), do: %{type: :mock}
@impl Service
- def validate(_token, _captcha), do: true
-
- @impl Service
- def cleanup(), do: :ok
+ def validate(_token, _captcha, _data), do: :ok
end
--
cgit v1.2.3
From 71f6d9f418087a16ff266ef380b3290088e0d301 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 23 Dec 2018 13:28:17 +0000
Subject: transmogrifier: significantly rework handling of peertube videos, add
test
---
test/web/activity_pub/transmogrifier_test.exs | 30 +++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 0428e052d..6778db390 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -684,6 +684,36 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
:error = Transmogrifier.handle_incoming(data)
end
+
+ test "it remaps video URLs as attachments if necessary" do
+ {:ok, object} =
+ ActivityPub.fetch_object_from_id(
+ "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
+ )
+
+ attachment = %{
+ "type" => "Link",
+ "mediaType" => "video/mp4",
+ "href" =>
+ "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
+ "mimeType" => "video/mp4",
+ "size" => 5_015_880,
+ "url" => [
+ %{
+ "href" =>
+ "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
+ "mediaType" => "video/mp4",
+ "type" => "Link"
+ }
+ ],
+ "width" => 480
+ }
+
+ assert object.data["url"] ==
+ "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
+
+ assert object.data["attachment"] == [attachment]
+ end
end
describe "prepare outgoing" do
--
cgit v1.2.3
From 9f48485f64a99dbf29f3984e614b25aee32efdc4 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 23 Dec 2018 13:42:42 +0000
Subject: tests: mastodon api: add test verifying that peertube videos are
correctly rendered
---
test/web/mastodon_api/status_view_test.exs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index b7ac92760..0af7d8621 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -5,6 +5,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
alias Pleroma.User
alias Pleroma.Web.OStatus
alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Activity
import Pleroma.Factory
import Tesla.Mock
@@ -157,6 +159,22 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
assert represented[:emojis] == []
end
+ test "a peertube video" do
+ user = insert(:user)
+
+ {:ok, object} =
+ ActivityPub.fetch_object_from_id(
+ "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
+ )
+
+ %Activity{} = activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
+
+ represented = StatusView.render("status.json", %{for: user, activity: activity})
+
+ assert represented[:id] == to_string(activity.id)
+ assert length(represented[:media_attachments]) == 1
+ end
+
describe "build_tags/1" do
test "it returns a a dictionary tags" do
object_tags = [
--
cgit v1.2.3
From 873938d223949f647a196b7f2a4140d323fbab1c Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 23 Dec 2018 13:55:08 +0000
Subject: tests: twitter api: activity view test: enable tesla mock
---
test/web/twitter_api/views/activity_view_test.exs | 7 +++++++
1 file changed, 7 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 8aa9e3130..09d7a18d4 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -12,6 +12,13 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
alias Pleroma.Web.ActivityPub.ActivityPub
import Pleroma.Factory
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
import Mock
test "a create activity with a html status" do
--
cgit v1.2.3
From a2bceaf688608f61151e298e6025ccbecc9de227 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 23 Dec 2018 13:59:06 +0000
Subject: tests: twitter api: add test proving that peertube videos are
correctly handled
---
test/web/twitter_api/views/activity_view_test.exs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 09d7a18d4..fd511b546 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -265,4 +265,18 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
assert result == expected
end
+
+ test "a peertube video" do
+ {:ok, object} =
+ ActivityPub.fetch_object_from_id(
+ "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
+ )
+
+ %Activity{} = activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
+
+ result = ActivityView.render("activity.json", activity: activity)
+
+ assert length(result["attachments"]) == 1
+ assert result["summary"] == "Friday Night"
+ end
end
--
cgit v1.2.3
From 3c08d229db423052d0dd88b8a36fb39b0ae81ead Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 23 Dec 2018 20:11:29 +0000
Subject: tests: add legal boilerplate
---
test/activity_test.exs | 4 ++++
test/captcha_test.exs | 4 ++++
test/config_test.exs | 4 ++++
test/filter_test.exs | 4 ++++
test/formatter_test.exs | 4 ++++
test/html_test.exs | 4 ++++
test/http_test.exs | 4 ++++
test/integration/mastodon_websocket_test.exs | 4 ++++
test/list_test.exs | 4 ++++
test/media_proxy_test.exs | 4 ++++
test/notification_test.exs | 4 ++++
test/object_test.exs | 4 ++++
test/plugs/admin_secret_authentication_plug_test.exs | 4 ++++
test/plugs/authentication_plug_test.exs | 4 ++++
test/plugs/basic_auth_decoder_plug_test.exs | 4 ++++
test/plugs/ensure_authenticated_plug_test.exs | 4 ++++
test/plugs/ensure_user_key_plug_test.exs | 4 ++++
test/plugs/http_security_plug_test.exs | 4 ++++
test/plugs/http_signature_plug_test.exs | 4 ++++
test/plugs/instance_static_test.exs | 4 ++++
test/plugs/legacy_authentication_plug_test.exs | 4 ++++
test/plugs/oauth_plug_test.exs | 4 ++++
test/plugs/session_authentication_plug_test.exs | 4 ++++
test/plugs/set_user_session_id_plug_test.exs | 4 ++++
test/plugs/user_enabled_plug_test.exs | 4 ++++
test/plugs/user_fetcher_plug_test.exs | 4 ++++
test/plugs/user_is_admin_plug_test.exs | 4 ++++
test/support/captcha_mock.ex | 4 ++++
test/support/channel_case.ex | 4 ++++
test/support/conn_case.ex | 4 ++++
test/support/data_case.ex | 4 ++++
test/support/factory.ex | 4 ++++
test/support/helpers.ex | 4 ++++
test/support/http_request_mock.ex | 4 ++++
test/support/ostatus_mock.ex | 4 ++++
test/support/websocket_client.ex | 4 ++++
test/support/websub_mock.ex | 4 ++++
test/tasks/relay_test.exs | 4 ++++
test/tasks/uploads_test.exs | 4 ++++
test/tasks/user_test.exs | 4 ++++
test/test_helper.exs | 4 ++++
test/upload_test.exs | 4 ++++
test/user_test.exs | 4 ++++
test/web/activity_pub/activity_pub_controller_test.exs | 4 ++++
test/web/activity_pub/activity_pub_test.exs | 4 ++++
test/web/activity_pub/relay_test.exs | 4 ++++
test/web/activity_pub/transmogrifier_test.exs | 4 ++++
test/web/admin_api/admin_api_controller_test.exs | 4 ++++
test/web/common_api/common_api_test.exs | 4 ++++
test/web/common_api/common_api_utils_test.exs | 4 ++++
test/web/federator_test.exs | 4 ++++
test/web/http_sigs/http_sig_test.exs | 4 ++++
test/web/mastodon_api/account_view_test.exs | 4 ++++
test/web/mastodon_api/list_view_test.exs | 4 ++++
test/web/mastodon_api/mastodon_api_controller_test.exs | 4 ++++
test/web/mastodon_api/status_view_test.exs | 4 ++++
test/web/node_info_test.exs | 4 ++++
test/web/oauth/authorization_test.exs | 4 ++++
test/web/oauth/oauth_controller_test.exs | 4 ++++
test/web/oauth/token_test.exs | 4 ++++
test/web/ostatus/activity_representer_test.exs | 4 ++++
test/web/ostatus/feed_representer_test.exs | 4 ++++
test/web/ostatus/ostatus_controller_test.exs | 4 ++++
test/web/ostatus/ostatus_test.exs | 4 ++++
test/web/ostatus/user_representer_test.exs | 4 ++++
test/web/plugs/federating_plug_test.exs | 4 ++++
test/web/retry_queue_test.exs | 4 ++++
test/web/salmon/salmon_test.exs | 4 ++++
test/web/streamer_test.exs | 4 ++++
test/web/twitter_api/representers/activity_representer_test.exs | 4 ++++
test/web/twitter_api/representers/object_representer_test.exs | 4 ++++
test/web/twitter_api/twitter_api_controller_test.exs | 4 ++++
test/web/twitter_api/twitter_api_test.exs | 4 ++++
test/web/twitter_api/views/activity_view_test.exs | 4 ++++
test/web/twitter_api/views/notification_view_test.exs | 4 ++++
test/web/twitter_api/views/user_view_test.exs | 4 ++++
test/web/views/error_view_test.exs | 4 ++++
test/web/web_finger/web_finger_controller_test.exs | 4 ++++
test/web/web_finger/web_finger_test.exs | 4 ++++
test/web/websub/websub_controller_test.exs | 4 ++++
test/web/websub/websub_test.exs | 4 ++++
test/xml_builder_test.exs | 4 ++++
82 files changed, 328 insertions(+)
(limited to 'test')
diff --git a/test/activity_test.exs b/test/activity_test.exs
index 55849c522..cf27fbbc5 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.ActivityTest do
use Pleroma.DataCase
import Pleroma.Factory
diff --git a/test/captcha_test.exs b/test/captcha_test.exs
index 54ffbd92f..7f559ac72 100644
--- a/test/captcha_test.exs
+++ b/test/captcha_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.CaptchaTest do
use ExUnit.Case
diff --git a/test/config_test.exs b/test/config_test.exs
index 837cbb30c..0a6f0395a 100644
--- a/test/config_test.exs
+++ b/test/config_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.ConfigTest do
use ExUnit.Case
diff --git a/test/filter_test.exs b/test/filter_test.exs
index 2b31bcc08..b31c68efd 100644
--- a/test/filter_test.exs
+++ b/test/filter_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.FilterTest do
alias Pleroma.Repo
use Pleroma.DataCase
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index 584700b6a..c76149e38 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.FormatterTest do
alias Pleroma.Formatter
alias Pleroma.User
diff --git a/test/html_test.exs b/test/html_test.exs
index f7150759b..29cab17f3 100644
--- a/test/html_test.exs
+++ b/test/html_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.HTMLTest do
alias Pleroma.HTML
use Pleroma.DataCase
diff --git a/test/http_test.exs b/test/http_test.exs
index 62f3ccb30..5f9522cf0 100644
--- a/test/http_test.exs
+++ b/test/http_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.HTTPTest do
use Pleroma.DataCase
import Tesla.Mock
diff --git a/test/integration/mastodon_websocket_test.exs b/test/integration/mastodon_websocket_test.exs
index b5f3d3a47..03aabf12c 100644
--- a/test/integration/mastodon_websocket_test.exs
+++ b/test/integration/mastodon_websocket_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Integration.MastodonWebsocketTest do
use Pleroma.DataCase
diff --git a/test/list_test.exs b/test/list_test.exs
index 2ab822815..1909c0cd9 100644
--- a/test/list_test.exs
+++ b/test/list_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.ListTest do
alias Pleroma.Repo
use Pleroma.DataCase
diff --git a/test/media_proxy_test.exs b/test/media_proxy_test.exs
index cb455ca79..05d927422 100644
--- a/test/media_proxy_test.exs
+++ b/test/media_proxy_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.MediaProxyTest do
use ExUnit.Case
import Pleroma.Web.MediaProxy
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 385210793..31c0d2c64 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.NotificationTest do
use Pleroma.DataCase
alias Pleroma.Web.TwitterAPI.TwitterAPI
diff --git a/test/object_test.exs b/test/object_test.exs
index 909605560..0effb9505 100644
--- a/test/object_test.exs
+++ b/test/object_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.ObjectTest do
use Pleroma.DataCase
import Pleroma.Factory
diff --git a/test/plugs/admin_secret_authentication_plug_test.exs b/test/plugs/admin_secret_authentication_plug_test.exs
index c0fe2cf97..e1d4b391f 100644
--- a/test/plugs/admin_secret_authentication_plug_test.exs
+++ b/test/plugs/admin_secret_authentication_plug_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Plugs.AdminSecretAuthenticationPlugTest do
use Pleroma.Web.ConnCase, async: true
import Pleroma.Factory
diff --git a/test/plugs/authentication_plug_test.exs b/test/plugs/authentication_plug_test.exs
index 061fa0cac..6158086ea 100644
--- a/test/plugs/authentication_plug_test.exs
+++ b/test/plugs/authentication_plug_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Plugs.AuthenticationPlugTest do
use Pleroma.Web.ConnCase, async: true
diff --git a/test/plugs/basic_auth_decoder_plug_test.exs b/test/plugs/basic_auth_decoder_plug_test.exs
index a4876fef7..4d7728e93 100644
--- a/test/plugs/basic_auth_decoder_plug_test.exs
+++ b/test/plugs/basic_auth_decoder_plug_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Plugs.BasicAuthDecoderPlugTest do
use Pleroma.Web.ConnCase, async: true
diff --git a/test/plugs/ensure_authenticated_plug_test.exs b/test/plugs/ensure_authenticated_plug_test.exs
index b32817fef..37ab5213a 100644
--- a/test/plugs/ensure_authenticated_plug_test.exs
+++ b/test/plugs/ensure_authenticated_plug_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Plugs.EnsureAuthenticatedPlugTest do
use Pleroma.Web.ConnCase, async: true
diff --git a/test/plugs/ensure_user_key_plug_test.exs b/test/plugs/ensure_user_key_plug_test.exs
index 9beda838e..6a9627f6a 100644
--- a/test/plugs/ensure_user_key_plug_test.exs
+++ b/test/plugs/ensure_user_key_plug_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Plugs.EnsureUserKeyPlugTest do
use Pleroma.Web.ConnCase, async: true
diff --git a/test/plugs/http_security_plug_test.exs b/test/plugs/http_security_plug_test.exs
index 169c3b3a8..0cbb7e4b1 100644
--- a/test/plugs/http_security_plug_test.exs
+++ b/test/plugs/http_security_plug_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do
use Pleroma.Web.ConnCase
alias Pleroma.Config
diff --git a/test/plugs/http_signature_plug_test.exs b/test/plugs/http_signature_plug_test.exs
index a15c5b470..6a00dd4fd 100644
--- a/test/plugs/http_signature_plug_test.exs
+++ b/test/plugs/http_signature_plug_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.Plugs.HTTPSignaturePlugTest do
use Pleroma.Web.ConnCase
alias Pleroma.Web.HTTPSignatures
diff --git a/test/plugs/instance_static_test.exs b/test/plugs/instance_static_test.exs
index 526679aae..e2dcfa3d8 100644
--- a/test/plugs/instance_static_test.exs
+++ b/test/plugs/instance_static_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.RuntimeStaticPlugTest do
use Pleroma.Web.ConnCase
diff --git a/test/plugs/legacy_authentication_plug_test.exs b/test/plugs/legacy_authentication_plug_test.exs
index 383a22ff8..302662797 100644
--- a/test/plugs/legacy_authentication_plug_test.exs
+++ b/test/plugs/legacy_authentication_plug_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Plugs.LegacyAuthenticationPlugTest do
use Pleroma.Web.ConnCase, async: true
diff --git a/test/plugs/oauth_plug_test.exs b/test/plugs/oauth_plug_test.exs
index 4dd12f207..17fdba916 100644
--- a/test/plugs/oauth_plug_test.exs
+++ b/test/plugs/oauth_plug_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Plugs.OAuthPlugTest do
use Pleroma.Web.ConnCase, async: true
diff --git a/test/plugs/session_authentication_plug_test.exs b/test/plugs/session_authentication_plug_test.exs
index bb51bc0db..0000f4258 100644
--- a/test/plugs/session_authentication_plug_test.exs
+++ b/test/plugs/session_authentication_plug_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Plugs.SessionAuthenticationPlugTest do
use Pleroma.Web.ConnCase, async: true
diff --git a/test/plugs/set_user_session_id_plug_test.exs b/test/plugs/set_user_session_id_plug_test.exs
index 7cf8e42cc..f8bfde039 100644
--- a/test/plugs/set_user_session_id_plug_test.exs
+++ b/test/plugs/set_user_session_id_plug_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Plugs.SetUserSessionIdPlugTest do
use Pleroma.Web.ConnCase, async: true
diff --git a/test/plugs/user_enabled_plug_test.exs b/test/plugs/user_enabled_plug_test.exs
index eeb167933..c0fafcab1 100644
--- a/test/plugs/user_enabled_plug_test.exs
+++ b/test/plugs/user_enabled_plug_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Plugs.UserEnabledPlugTest do
use Pleroma.Web.ConnCase, async: true
diff --git a/test/plugs/user_fetcher_plug_test.exs b/test/plugs/user_fetcher_plug_test.exs
index 5195a0c4a..262eb8d93 100644
--- a/test/plugs/user_fetcher_plug_test.exs
+++ b/test/plugs/user_fetcher_plug_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Plugs.UserFetcherPlugTest do
use Pleroma.Web.ConnCase, async: true
diff --git a/test/plugs/user_is_admin_plug_test.exs b/test/plugs/user_is_admin_plug_test.exs
index cdab6b8ed..9e05fff18 100644
--- a/test/plugs/user_is_admin_plug_test.exs
+++ b/test/plugs/user_is_admin_plug_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Plugs.UserIsAdminPlugTest do
use Pleroma.Web.ConnCase, async: true
diff --git a/test/support/captcha_mock.ex b/test/support/captcha_mock.ex
index 898aa17b8..3ab02916f 100644
--- a/test/support/captcha_mock.ex
+++ b/test/support/captcha_mock.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Captcha.Mock do
alias Pleroma.Captcha.Service
@behaviour Service
diff --git a/test/support/channel_case.ex b/test/support/channel_case.ex
index 68995a01d..466d8986f 100644
--- a/test/support/channel_case.ex
+++ b/test/support/channel_case.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.ChannelCase do
@moduledoc """
This module defines the test case to be used by
diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex
index d25c28f49..c201d9a9b 100644
--- a/test/support/conn_case.ex
+++ b/test/support/conn_case.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.ConnCase do
@moduledoc """
This module defines the test case to be used by
diff --git a/test/support/data_case.ex b/test/support/data_case.ex
index 53e7234d2..56d5896ad 100644
--- a/test/support/data_case.ex
+++ b/test/support/data_case.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.DataCase do
@moduledoc """
This module defines the setup for tests requiring
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 2889d8977..e5c0c5bcc 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Factory do
use ExMachina.Ecto, repo: Pleroma.Repo
diff --git a/test/support/helpers.ex b/test/support/helpers.ex
index 64b6b1900..6e389ce52 100644
--- a/test/support/helpers.ex
+++ b/test/support/helpers.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Tests.Helpers do
@moduledoc """
Helpers for use in tests.
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index 6f98fc5d0..e4279e14d 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule HttpRequestMock do
require Logger
diff --git a/test/support/ostatus_mock.ex b/test/support/ostatus_mock.ex
index 36865ae02..9c0f2f323 100644
--- a/test/support/ostatus_mock.ex
+++ b/test/support/ostatus_mock.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.OStatusMock do
import Pleroma.Factory
diff --git a/test/support/websocket_client.ex b/test/support/websocket_client.ex
index 57e9bb17f..121231452 100644
--- a/test/support/websocket_client.ex
+++ b/test/support/websocket_client.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Integration.WebsocketClient do
# https://github.com/phoenixframework/phoenix/blob/master/test/support/websocket_client.exs
diff --git a/test/support/websub_mock.ex b/test/support/websub_mock.ex
index 0cba0b740..e3d5a5b16 100644
--- a/test/support/websub_mock.ex
+++ b/test/support/websub_mock.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.WebsubMock do
def verify(sub) do
{:ok, sub}
diff --git a/test/tasks/relay_test.exs b/test/tasks/relay_test.exs
index 737293865..96fac4811 100644
--- a/test/tasks/relay_test.exs
+++ b/test/tasks/relay_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Mix.Tasks.Pleroma.RelayTest do
alias Pleroma.Activity
alias Pleroma.Web.ActivityPub.{ActivityPub, Relay, Utils}
diff --git a/test/tasks/uploads_test.exs b/test/tasks/uploads_test.exs
index 93035abb6..b0b8eda11 100644
--- a/test/tasks/uploads_test.exs
+++ b/test/tasks/uploads_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Mix.Tasks.Pleroma.UploadsTest do
alias Pleroma.Upload
use Pleroma.DataCase
diff --git a/test/tasks/user_test.exs b/test/tasks/user_test.exs
index 7479bf749..44271898c 100644
--- a/test/tasks/user_test.exs
+++ b/test/tasks/user_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Mix.Tasks.Pleroma.UserTest do
alias Pleroma.User
use Pleroma.DataCase
diff --git a/test/test_helper.exs b/test/test_helper.exs
index 94ba68ff8..f604ba63d 100644
--- a/test/test_helper.exs
+++ b/test/test_helper.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, :manual)
diff --git a/test/upload_test.exs b/test/upload_test.exs
index f2cad4cf0..d4ea3a573 100644
--- a/test/upload_test.exs
+++ b/test/upload_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.UploadTest do
alias Pleroma.Upload
use Pleroma.DataCase
diff --git a/test/user_test.exs b/test/user_test.exs
index b4d8174c6..aab6473cf 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.UserTest do
alias Pleroma.Builders.UserBuilder
alias Pleroma.{User, Repo, Activity}
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index faeace016..9fdf15505 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 470ed08b2..4f6b7f058 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
use Pleroma.DataCase
alias Pleroma.Web.ActivityPub.ActivityPub
diff --git a/test/web/activity_pub/relay_test.exs b/test/web/activity_pub/relay_test.exs
index 41d13e055..21a63c493 100644
--- a/test/web/activity_pub/relay_test.exs
+++ b/test/web/activity_pub/relay_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.ActivityPub.RelayTest do
use Pleroma.DataCase
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 6778db390..a5fd87ed4 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
use Pleroma.DataCase
alias Pleroma.Web.ActivityPub.Transmogrifier
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index e183da3a1..42450a7b6 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
use Pleroma.Web.ConnCase
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 0b5a235f8..c3674711a 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.CommonAPI.Test do
use Pleroma.DataCase
alias Pleroma.Web.CommonAPI
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index b01ce04f8..fc89e3116 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.CommonAPI.UtilsTest do
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.Endpoint
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 87bf73dbd..a49265c0c 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.FederatorTest do
alias Pleroma.Web.Federator
alias Pleroma.Web.CommonAPI
diff --git a/test/web/http_sigs/http_sig_test.exs b/test/web/http_sigs/http_sig_test.exs
index 74d86a9e1..c4d2eaf78 100644
--- a/test/web/http_sigs/http_sig_test.exs
+++ b/test/web/http_sigs/http_sig_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
# http signatures
# Test data from https://tools.ietf.org/html/draft-cavage-http-signatures-08#appendix-C
defmodule Pleroma.Web.HTTPSignaturesTest do
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index fec97c700..d53e11963 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
use Pleroma.DataCase
import Pleroma.Factory
diff --git a/test/web/mastodon_api/list_view_test.exs b/test/web/mastodon_api/list_view_test.exs
index a12acc2b2..73143467f 100644
--- a/test/web/mastodon_api/list_view_test.exs
+++ b/test/web/mastodon_api/list_view_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.MastodonAPI.ListViewTest do
use Pleroma.DataCase
import Pleroma.Factory
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index aec0f851c..433c135f7 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
use Pleroma.Web.ConnCase
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 0af7d8621..b953ccd76 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
use Pleroma.DataCase
diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs
index a5b0b7869..6769a4490 100644
--- a/test/web/node_info_test.exs
+++ b/test/web/node_info_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.NodeInfoTest do
use Pleroma.Web.ConnCase
diff --git a/test/web/oauth/authorization_test.exs b/test/web/oauth/authorization_test.exs
index 2b7fb2fad..3b1ddada8 100644
--- a/test/web/oauth/authorization_test.exs
+++ b/test/web/oauth/authorization_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.OAuth.AuthorizationTest do
use Pleroma.DataCase
alias Pleroma.Web.OAuth.{Authorization, App}
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index 52441407d..ccd552258 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.OAuth.OAuthControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
diff --git a/test/web/oauth/token_test.exs b/test/web/oauth/token_test.exs
index e36ca5abc..9a241d61a 100644
--- a/test/web/oauth/token_test.exs
+++ b/test/web/oauth/token_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.OAuth.TokenTest do
use Pleroma.DataCase
alias Pleroma.Web.OAuth.{App, Token, Authorization}
diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs
index a351510d8..0869f2fd5 100644
--- a/test/web/ostatus/activity_representer_test.exs
+++ b/test/web/ostatus/activity_representer_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
use Pleroma.DataCase
diff --git a/test/web/ostatus/feed_representer_test.exs b/test/web/ostatus/feed_representer_test.exs
index bf3feb14e..55717dec7 100644
--- a/test/web/ostatus/feed_representer_test.exs
+++ b/test/web/ostatus/feed_representer_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
use Pleroma.DataCase
import Pleroma.Factory
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index 560305c15..6b535a1a9 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.OStatus.OStatusControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index e577a6bee..403cc7095 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.OStatusTest do
use Pleroma.DataCase
alias Pleroma.Web.OStatus
diff --git a/test/web/ostatus/user_representer_test.exs b/test/web/ostatus/user_representer_test.exs
index 82fb8e793..e3863d2e9 100644
--- a/test/web/ostatus/user_representer_test.exs
+++ b/test/web/ostatus/user_representer_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.OStatus.UserRepresenterTest do
use Pleroma.DataCase
alias Pleroma.Web.OStatus.UserRepresenter
diff --git a/test/web/plugs/federating_plug_test.exs b/test/web/plugs/federating_plug_test.exs
index 1455a1c46..612db7e32 100644
--- a/test/web/plugs/federating_plug_test.exs
+++ b/test/web/plugs/federating_plug_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.FederatingPlugTest do
use Pleroma.Web.ConnCase
diff --git a/test/web/retry_queue_test.exs b/test/web/retry_queue_test.exs
index b5a6ab030..9351b6c24 100644
--- a/test/web/retry_queue_test.exs
+++ b/test/web/retry_queue_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule MockActivityPub do
def publish_one(ret) do
{ret, "success"}
diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs
index 7e922ad83..c539a28b2 100644
--- a/test/web/salmon/salmon_test.exs
+++ b/test/web/salmon/salmon_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.Salmon.SalmonTest do
use Pleroma.DataCase
alias Pleroma.Web.Salmon
diff --git a/test/web/streamer_test.exs b/test/web/streamer_test.exs
index df58441f0..905e29d06 100644
--- a/test/web/streamer_test.exs
+++ b/test/web/streamer_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.StreamerTest do
use Pleroma.DataCase
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index f6c60a744..2ac32aeb2 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
use Pleroma.DataCase
alias Pleroma.{User, Activity, Object}
diff --git a/test/web/twitter_api/representers/object_representer_test.exs b/test/web/twitter_api/representers/object_representer_test.exs
index 228b2ac42..c3cf330f1 100644
--- a/test/web/twitter_api/representers/object_representer_test.exs
+++ b/test/web/twitter_api/representers/object_representer_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.TwitterAPI.Representers.ObjectReprenterTest do
use Pleroma.DataCase
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 1324bcc71..0e656f9ca 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.TwitterAPI.ControllerTest do
use Pleroma.Web.ConnCase
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index b7c89b605..b9feb23d4 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
use Pleroma.DataCase
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView}
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index fd511b546..013245033 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
use Pleroma.DataCase
diff --git a/test/web/twitter_api/views/notification_view_test.exs b/test/web/twitter_api/views/notification_view_test.exs
index fcf2b3d90..8367fc6c7 100644
--- a/test/web/twitter_api/views/notification_view_test.exs
+++ b/test/web/twitter_api/views/notification_view_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
use Pleroma.DataCase
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 0adc69ff9..32e9466e1 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.TwitterAPI.UserViewTest do
use Pleroma.DataCase
diff --git a/test/web/views/error_view_test.exs b/test/web/views/error_view_test.exs
index 1d443b187..16a0c8cef 100644
--- a/test/web/views/error_view_test.exs
+++ b/test/web/views/error_view_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.ErrorViewTest do
use Pleroma.Web.ConnCase, async: true
diff --git a/test/web/web_finger/web_finger_controller_test.exs b/test/web/web_finger/web_finger_controller_test.exs
index 844ff51d2..43fccfc7a 100644
--- a/test/web/web_finger/web_finger_controller_test.exs
+++ b/test/web/web_finger/web_finger_controller_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
use Pleroma.Web.ConnCase
diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs
index 32eff9b7c..6b20d8d56 100644
--- a/test/web/web_finger/web_finger_test.exs
+++ b/test/web/web_finger/web_finger_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.WebFingerTest do
use Pleroma.DataCase
alias Pleroma.Web.WebFinger
diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs
index d861c241f..9cbcda063 100644
--- a/test/web/websub/websub_controller_test.exs
+++ b/test/web/websub/websub_controller_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.Websub.WebsubControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs
index fd559743f..9751d161d 100644
--- a/test/web/websub/websub_test.exs
+++ b/test/web/websub/websub_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.WebsubTest do
use Pleroma.DataCase
alias Pleroma.Web.Websub
diff --git a/test/xml_builder_test.exs b/test/xml_builder_test.exs
index 4be7bbd01..a7742f339 100644
--- a/test/xml_builder_test.exs
+++ b/test/xml_builder_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.XmlBuilderTest do
use Pleroma.DataCase
alias Pleroma.XmlBuilder
--
cgit v1.2.3
From 0f412cf6e68fcebda3e94b71b7f182af689748bf Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Mon, 24 Dec 2018 02:25:36 +0300
Subject: Create tombstone instead of object deletion
---
test/activity_test.exs | 25 ++++++++++++++++++++++
test/user_test.exs | 2 +-
test/web/activity_pub/activity_pub_test.exs | 2 +-
test/web/activity_pub/transmogrifier_test.exs | 2 +-
.../mastodon_api/mastodon_api_controller_test.exs | 2 +-
5 files changed, 29 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/activity_test.exs b/test/activity_test.exs
index 55849c522..87c9ddc50 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -1,5 +1,6 @@
defmodule Pleroma.ActivityTest do
use Pleroma.DataCase
+ alias Pleroma.Activity
import Pleroma.Factory
test "returns an activity by it's AP id" do
@@ -24,4 +25,28 @@ defmodule Pleroma.ActivityTest do
assert activity == found_activity
end
+
+ test "returns tombstone" do
+ activity = insert(:note_activity)
+ deleted = DateTime.utc_now()
+
+ assert Pleroma.Activity.get_tombstone(activity, deleted) == %{
+ id: activity.data["object"]["id"],
+ context: activity.data["context"],
+ type: "tombstone",
+ published: activity.data["published"],
+ deleted: deleted
+ }
+ end
+
+ test "swaps data with tombstone" do
+ activity = insert(:note_activity)
+
+ {:ok, deleted} = Pleroma.Activity.swap_data_with_tombstone(activity)
+ assert deleted.data.type == "tombstone"
+
+ found_activity = Repo.get(Activity, activity.id)
+
+ assert deleted.data.type == found_activity.data["type"]
+ end
end
diff --git a/test/user_test.exs b/test/user_test.exs
index b4d8174c6..43a3687ec 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -625,7 +625,7 @@ defmodule Pleroma.UserTest do
# TODO: Remove favorites, repeats, delete activities.
- refute Repo.get(Activity, activity.id)
+ assert Repo.get(Activity, activity.id).data["type"] == "tombstone"
end
test "get_public_key_for_ap_id fetches a user that's not in the db" do
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 470ed08b2..95731a868 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -478,7 +478,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert Repo.get(Activity, delete.id) != nil
- assert Repo.get(Object, object.id) == nil
+ assert Repo.get(Object, object.id).data["type"] == "tombstone"
end
end
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 0428e052d..18a5ad3d0 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -363,7 +363,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
- refute Repo.get(Activity, activity.id)
+ assert Repo.get(Activity, activity.id).data["type"] == "tombstone"
end
test "it fails for incoming deletes with spoofed origin" do
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index aec0f851c..6c6cc2a00 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -292,7 +292,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{} = json_response(conn, 200)
- assert Repo.get(Activity, activity.id) == nil
+ assert Repo.get(Activity, activity.id).data["type"] == "tombstone"
end
test "when you didn't create it", %{conn: conn} do
--
cgit v1.2.3
From 18a4cbb244dbc188f5a391626fb98e3a53571318 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Mon, 24 Dec 2018 20:09:18 +0300
Subject: Capitalize "tombstone"
---
test/activity_test.exs | 4 ++--
test/user_test.exs | 2 +-
test/web/activity_pub/activity_pub_test.exs | 2 +-
test/web/activity_pub/transmogrifier_test.exs | 2 +-
test/web/mastodon_api/mastodon_api_controller_test.exs | 2 +-
5 files changed, 6 insertions(+), 6 deletions(-)
(limited to 'test')
diff --git a/test/activity_test.exs b/test/activity_test.exs
index 87c9ddc50..c47fe39da 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -33,7 +33,7 @@ defmodule Pleroma.ActivityTest do
assert Pleroma.Activity.get_tombstone(activity, deleted) == %{
id: activity.data["object"]["id"],
context: activity.data["context"],
- type: "tombstone",
+ type: "Tombstone",
published: activity.data["published"],
deleted: deleted
}
@@ -43,7 +43,7 @@ defmodule Pleroma.ActivityTest do
activity = insert(:note_activity)
{:ok, deleted} = Pleroma.Activity.swap_data_with_tombstone(activity)
- assert deleted.data.type == "tombstone"
+ assert deleted.data.type == "Tombstone"
found_activity = Repo.get(Activity, activity.id)
diff --git a/test/user_test.exs b/test/user_test.exs
index 43a3687ec..f7a003c28 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -625,7 +625,7 @@ defmodule Pleroma.UserTest do
# TODO: Remove favorites, repeats, delete activities.
- assert Repo.get(Activity, activity.id).data["type"] == "tombstone"
+ assert Repo.get(Activity, activity.id).data["type"] == "Tombstone"
end
test "get_public_key_for_ap_id fetches a user that's not in the db" do
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 95731a868..4d16a87e2 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -478,7 +478,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert Repo.get(Activity, delete.id) != nil
- assert Repo.get(Object, object.id).data["type"] == "tombstone"
+ assert Repo.get(Object, object.id).data["type"] == "Tombstone"
end
end
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 18a5ad3d0..8ab240dff 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -363,7 +363,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
- assert Repo.get(Activity, activity.id).data["type"] == "tombstone"
+ assert Repo.get(Activity, activity.id).data["type"] == "Tombstone"
end
test "it fails for incoming deletes with spoofed origin" do
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 6c6cc2a00..f1baa9953 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -292,7 +292,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{} = json_response(conn, 200)
- assert Repo.get(Activity, activity.id).data["type"] == "tombstone"
+ assert Repo.get(Activity, activity.id).data["type"] == "Tombstone"
end
test "when you didn't create it", %{conn: conn} do
--
cgit v1.2.3
From 2bbec33c7112ede3f93a7d35e9d5f3ac5a31ce05 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Tue, 25 Dec 2018 00:29:13 +0300
Subject: Fix failing tests
---
test/activity_test.exs | 2 +-
test/web/ostatus/incoming_documents/delete_handling_test.exs | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/activity_test.exs b/test/activity_test.exs
index c47fe39da..dd11323b5 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -31,7 +31,7 @@ defmodule Pleroma.ActivityTest do
deleted = DateTime.utc_now()
assert Pleroma.Activity.get_tombstone(activity, deleted) == %{
- id: activity.data["object"]["id"],
+ id: activity.data["id"],
context: activity.data["context"],
type: "Tombstone",
published: activity.data["published"],
diff --git a/test/web/ostatus/incoming_documents/delete_handling_test.exs b/test/web/ostatus/incoming_documents/delete_handling_test.exs
index 1e041e5b0..4e9c0f90f 100644
--- a/test/web/ostatus/incoming_documents/delete_handling_test.exs
+++ b/test/web/ostatus/incoming_documents/delete_handling_test.exs
@@ -23,9 +23,9 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
{:ok, [delete]} = OStatus.handle_incoming(incoming)
- refute Repo.get(Activity, note.id)
- refute Repo.get(Activity, like.id)
- refute Object.get_by_ap_id(note.data["object"]["id"])
+ assert Repo.get(Activity, note.id).data["type"] == "Tombstone"
+ assert Repo.get(Activity, like.id).data["type"] == "Tombstone"
+ assert Object.get_by_ap_id(note.data["object"]["id"]).data["type"] == "Tombstone"
assert Repo.get(Activity, second_note.id)
assert Object.get_by_ap_id(second_note.data["object"]["id"])
--
cgit v1.2.3
From f75f707f6cf07c66a23ddbbe80a9b782a1ecb6f8 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Tue, 25 Dec 2018 03:00:06 +0300
Subject: Revert Activity tombstones, add ObjectTombstone struct
---
test/activity_test.exs | 24 ----------------------
test/object_test.exs | 4 ++++
test/user_test.exs | 2 +-
test/web/activity_pub/transmogrifier_test.exs | 2 +-
.../mastodon_api/mastodon_api_controller_test.exs | 21 ++++++++++++++++++-
.../incoming_documents/delete_handling_test.exs | 4 ++--
6 files changed, 28 insertions(+), 29 deletions(-)
(limited to 'test')
diff --git a/test/activity_test.exs b/test/activity_test.exs
index dd11323b5..b949d0e2e 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -25,28 +25,4 @@ defmodule Pleroma.ActivityTest do
assert activity == found_activity
end
-
- test "returns tombstone" do
- activity = insert(:note_activity)
- deleted = DateTime.utc_now()
-
- assert Pleroma.Activity.get_tombstone(activity, deleted) == %{
- id: activity.data["id"],
- context: activity.data["context"],
- type: "Tombstone",
- published: activity.data["published"],
- deleted: deleted
- }
- end
-
- test "swaps data with tombstone" do
- activity = insert(:note_activity)
-
- {:ok, deleted} = Pleroma.Activity.swap_data_with_tombstone(activity)
- assert deleted.data.type == "Tombstone"
-
- found_activity = Repo.get(Activity, activity.id)
-
- assert deleted.data.type == found_activity.data["type"]
- end
end
diff --git a/test/object_test.exs b/test/object_test.exs
index 909605560..c0a3de2d9 100644
--- a/test/object_test.exs
+++ b/test/object_test.exs
@@ -32,6 +32,8 @@ defmodule Pleroma.ObjectTest do
found_object = Object.get_by_ap_id(object.data["id"])
refute object == found_object
+
+ assert found_object.data["type"] == "Tombstone"
end
test "ensures cache is cleared for the object" do
@@ -47,6 +49,8 @@ defmodule Pleroma.ObjectTest do
cached_object = Object.get_cached_by_ap_id(object.data["id"])
refute object == cached_object
+
+ assert cached_object.data["type"] == "Tombstone"
end
end
end
diff --git a/test/user_test.exs b/test/user_test.exs
index f7a003c28..b4d8174c6 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -625,7 +625,7 @@ defmodule Pleroma.UserTest do
# TODO: Remove favorites, repeats, delete activities.
- assert Repo.get(Activity, activity.id).data["type"] == "Tombstone"
+ refute Repo.get(Activity, activity.id)
end
test "get_public_key_for_ap_id fetches a user that's not in the db" do
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 8ab240dff..0428e052d 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -363,7 +363,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
- assert Repo.get(Activity, activity.id).data["type"] == "Tombstone"
+ refute Repo.get(Activity, activity.id)
end
test "it fails for incoming deletes with spoofed origin" do
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index f1baa9953..23f63372c 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -292,7 +292,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{} = json_response(conn, 200)
- assert Repo.get(Activity, activity.id).data["type"] == "Tombstone"
+ refute Repo.get(Activity, activity.id)
end
test "when you didn't create it", %{conn: conn} do
@@ -308,6 +308,25 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert Repo.get(Activity, activity.id) == activity
end
+
+ # test "404 when making an attempt to get it" do
+ # activity = insert(:note_activity)
+ # author = User.get_by_ap_id(activity.data["actor"])
+
+ # conn =
+ # conn
+ # |> assign(:user, author)
+ # |> delete("/api/v1/statuses/#{activity.id}")
+
+ # assert %{} = json_response(conn, 200)
+
+ # conn =
+ # build_conn()
+ # |> assign(:user, author)
+ # |> get("/api/v1/statuses/#{activity.id}")
+
+ # assert %{} = json_response(conn, 200)
+ # end
end
describe "filters" do
diff --git a/test/web/ostatus/incoming_documents/delete_handling_test.exs b/test/web/ostatus/incoming_documents/delete_handling_test.exs
index 4e9c0f90f..c8fbff6cc 100644
--- a/test/web/ostatus/incoming_documents/delete_handling_test.exs
+++ b/test/web/ostatus/incoming_documents/delete_handling_test.exs
@@ -23,8 +23,8 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
{:ok, [delete]} = OStatus.handle_incoming(incoming)
- assert Repo.get(Activity, note.id).data["type"] == "Tombstone"
- assert Repo.get(Activity, like.id).data["type"] == "Tombstone"
+ refute Repo.get(Activity, note.id)
+ refute Repo.get(Activity, like.id)
assert Object.get_by_ap_id(note.data["object"]["id"]).data["type"] == "Tombstone"
assert Repo.get(Activity, second_note.id)
assert Object.get_by_ap_id(second_note.data["object"]["id"])
--
cgit v1.2.3
From aeb89bece60846d8311afd69d0ccfd1df80cbe65 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Tue, 25 Dec 2018 03:38:02 +0300
Subject: Remove unused test
---
.../web/mastodon_api/mastodon_api_controller_test.exs | 19 -------------------
1 file changed, 19 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 23f63372c..00cf52d69 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -308,25 +308,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert Repo.get(Activity, activity.id) == activity
end
-
- # test "404 when making an attempt to get it" do
- # activity = insert(:note_activity)
- # author = User.get_by_ap_id(activity.data["actor"])
-
- # conn =
- # conn
- # |> assign(:user, author)
- # |> delete("/api/v1/statuses/#{activity.id}")
-
- # assert %{} = json_response(conn, 200)
-
- # conn =
- # build_conn()
- # |> assign(:user, author)
- # |> get("/api/v1/statuses/#{activity.id}")
-
- # assert %{} = json_response(conn, 200)
- # end
end
describe "filters" do
--
cgit v1.2.3
From ab2ee436342c821b7def04a2b9f1f195c0437065 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Tue, 25 Dec 2018 03:41:14 +0300
Subject: Fix Activity test
---
test/activity_test.exs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/activity_test.exs b/test/activity_test.exs
index b949d0e2e..a4c13c5e4 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -5,14 +5,14 @@ defmodule Pleroma.ActivityTest do
test "returns an activity by it's AP id" do
activity = insert(:note_activity)
- found_activity = Pleroma.Activity.get_by_ap_id(activity.data["id"])
+ found_activity = Activity.get_by_ap_id(activity.data["id"])
assert activity == found_activity
end
test "returns activities by it's objects AP ids" do
activity = insert(:note_activity)
- [found_activity] = Pleroma.Activity.all_by_object_ap_id(activity.data["object"]["id"])
+ [found_activity] = Activity.all_by_object_ap_id(activity.data["object"]["id"])
assert activity == found_activity
end
@@ -21,7 +21,7 @@ defmodule Pleroma.ActivityTest do
activity = insert(:note_activity)
found_activity =
- Pleroma.Activity.get_create_activity_by_object_ap_id(activity.data["object"]["id"])
+ Activity.get_create_activity_by_object_ap_id(activity.data["object"]["id"])
assert activity == found_activity
end
--
cgit v1.2.3
From 340dd7a75e308cdf6936864e05d80a3bcdfdd6eb Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Tue, 25 Dec 2018 03:47:20 +0300
Subject: Format
---
test/activity_test.exs | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/activity_test.exs b/test/activity_test.exs
index a4c13c5e4..ddcf54803 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -20,8 +20,7 @@ defmodule Pleroma.ActivityTest do
test "returns the activity that created an object" do
activity = insert(:note_activity)
- found_activity =
- Activity.get_create_activity_by_object_ap_id(activity.data["object"]["id"])
+ found_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"]["id"])
assert activity == found_activity
end
--
cgit v1.2.3
From 91724d160acc39585c37742204c59b91e59df569 Mon Sep 17 00:00:00 2001
From: lain
Date: Tue, 25 Dec 2018 20:09:27 +0100
Subject: Reserve a few user names
These are all names that are used for domain.com/:route routes or projected to be.
---
test/user_test.exs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index aab6473cf..8c7e1594b 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -153,6 +153,20 @@ defmodule Pleroma.UserTest do
end)
end
+ test "it restricts certain nicknames" do
+ [restricted_name | _] = Pleroma.Config.get([Pleroma.User, :restricted_nicknames])
+
+ assert is_bitstring(restricted_name)
+
+ params =
+ @full_user_data
+ |> Map.put(:nickname, restricted_name)
+
+ changeset = User.register_changeset(%User{}, params)
+
+ refute changeset.valid?
+ end
+
test "it sets the password_hash, ap_id and following fields" do
changeset = User.register_changeset(%User{}, @full_user_data)
--
cgit v1.2.3
From 012b7ab5e64eae468c630730f392ea8289a5d874 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Tue, 25 Dec 2018 23:40:57 +0300
Subject: Add test to check /object/:id does not leak the tombstone itself
---
test/web/ostatus/ostatus_controller_test.exs | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index 560305c15..c503cadae 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -1,7 +1,7 @@
defmodule Pleroma.Web.OStatus.OStatusControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
- alias Pleroma.{User, Repo}
+ alias Pleroma.{User, Repo, Object}
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OStatus.ActivityRepresenter
@@ -110,6 +110,22 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|> response(404)
end
+ test "404s on deleted objects", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
+ object = Object.get_by_ap_id(note_activity.data["object"]["id"])
+
+ conn
+ |> get("/objects/#{uuid}")
+ |> response(200)
+
+ Object.delete(object)
+
+ conn
+ |> get("/objects/#{uuid}")
+ |> response(404)
+ end
+
test "gets an activity", %{conn: conn} do
note_activity = insert(:note_activity)
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
--
cgit v1.2.3
From 5811e65e67591b06238de66470c03744e0d83e2d Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 26 Dec 2018 12:39:35 +0100
Subject: Add some hard limits on inserted activities.
---
test/web/activity_pub/activity_pub_test.exs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 4f6b7f058..f7c7c6242 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -31,6 +31,24 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end
describe "insertion" do
+ test "drops activities beyond a certain limit" do
+ limit = Pleroma.Config.get([:instance, :remote_limit])
+
+ random_text =
+ :crypto.strong_rand_bytes(limit + 1)
+ |> Base.encode64()
+ |> binary_part(0, limit + 1)
+
+ data = %{
+ "ok" => true,
+ "object" => %{
+ "content" => random_text
+ }
+ }
+
+ assert {:error, {:remote_limit_error, _}} = ActivityPub.insert(data)
+ end
+
test "returns the activity if one with the same id is already in" do
activity = insert(:note_activity)
{:ok, new_activity} = ActivityPub.insert(activity.data)
--
cgit v1.2.3
From 551d80cc0186424d2c1653f917749adea16d9963 Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 26 Dec 2018 12:46:16 +0100
Subject: Expose restricted names in nodeinfo.
---
test/web/node_info_test.exs | 11 +++++++++++
1 file changed, 11 insertions(+)
(limited to 'test')
diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs
index 6769a4490..5981c70a7 100644
--- a/test/web/node_info_test.exs
+++ b/test/web/node_info_test.exs
@@ -19,6 +19,17 @@ defmodule Pleroma.Web.NodeInfoTest do
assert user.ap_id in result["metadata"]["staffAccounts"]
end
+ test "nodeinfo shows restricted nicknames", %{conn: conn} do
+ conn =
+ conn
+ |> get("/nodeinfo/2.0.json")
+
+ assert result = json_response(conn, 200)
+
+ assert Pleroma.Config.get([Pleroma.User, :restricted_nicknames]) ==
+ result["metadata"]["restrictedNicknames"]
+ end
+
test "returns 404 when federation is disabled", %{conn: conn} do
instance =
Application.get_env(:pleroma, :instance)
--
cgit v1.2.3
From e4562105e77dd2d580921a07f05907a63da1d826 Mon Sep 17 00:00:00 2001
From: Vyr Cossont <600-VyrCossont@users.noreply.git.pleroma.social>
Date: Wed, 26 Dec 2018 21:30:01 -0800
Subject: Implement exclude_reblogs and include_rts
---
test/web/activity_pub/activity_pub_test.exs | 10 ++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 20 ++++++++++++++++
.../twitter_api/twitter_api_controller_test.exs | 28 ++++++++++++++++++++++
3 files changed, 58 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 4f6b7f058..f7c66038d 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -180,6 +180,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert Enum.member?(activities, activity_one)
end
+ test "excludes reblogs on request" do
+ user = insert(:user)
+ {:ok, expected_activity} = ActivityBuilder.insert(%{"type" => "Create"}, %{:user => user})
+ {:ok, _} = ActivityBuilder.insert(%{"type" => "Announce"}, %{:user => user})
+
+ [activity] = ActivityPub.fetch_user_activities(user, nil, %{"exclude_reblogs" => "true"})
+
+ assert activity == expected_activity
+ end
+
describe "public fetch activities" do
test "doesn't retrieve unlisted activities" do
user = insert(:user)
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 433c135f7..1737a5ebe 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -840,6 +840,26 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [%{"id" => id}] = json_response(conn, 200)
assert id == to_string(image_post.id)
end
+
+ test "gets a user's statuses without reblogs", %{conn: conn} do
+ user = insert(:user)
+ {:ok, post} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, _, _} = CommonAPI.repeat(post.id, user)
+
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/statuses", %{"exclude_reblogs" => "true"})
+
+ assert [%{"id" => id}] = json_response(conn, 200)
+ assert id == to_string(post.id)
+
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/statuses", %{"exclude_reblogs" => "1"})
+
+ assert [%{"id" => id}] = json_response(conn, 200)
+ assert id == to_string(post.id)
+ end
end
describe "user relationships" do
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 0e656f9ca..474d72df6 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -519,6 +519,34 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert length(response) == 1
assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: user})
end
+
+ test "with credentials with user_id, excluding RTs", %{conn: conn, user: current_user} do
+ user = insert(:user)
+ {:ok, activity} = ActivityBuilder.insert(%{"id" => 1, "type" => "Create"}, %{user: user})
+ {:ok, _} = ActivityBuilder.insert(%{"id" => 2, "type" => "Announce"}, %{user: user})
+
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> get("/api/statuses/user_timeline.json", %{
+ "user_id" => user.id,
+ "include_rts" => "false"
+ })
+
+ response = json_response(conn, 200)
+
+ assert length(response) == 1
+ assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: user})
+
+ conn =
+ conn
+ |> get("/api/statuses/user_timeline.json", %{"user_id" => user.id, "include_rts" => "0"})
+
+ response = json_response(conn, 200)
+
+ assert length(response) == 1
+ assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: user})
+ end
end
describe "POST /friendships/create.json" do
--
cgit v1.2.3
From d8cc96cb1f9e2a4e736f6830529e8aa9a5d289d8 Mon Sep 17 00:00:00 2001
From: Vyr Cossont <600-VyrCossont@users.noreply.git.pleroma.social>
Date: Thu, 27 Dec 2018 22:43:40 -0800
Subject: Fix Twitter timelines for private instances
---
.../twitter_api/twitter_api_controller_test.exs | 60 ++++++++++++++++++++++
1 file changed, 60 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 474d72df6..a4526eeda 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -112,6 +112,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
describe "GET /statuses/public_timeline.json" do
+ setup [:valid_user]
+
test "returns statuses", %{conn: conn} do
user = insert(:user)
activities = ActivityBuilder.insert_list(30, %{}, %{user: user})
@@ -145,14 +147,44 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
Application.put_env(:pleroma, :instance, instance)
end
+ test "returns 200 to authenticated request when the instance is not public",
+ %{conn: conn, user: user} do
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:public, false)
+
+ Application.put_env(:pleroma, :instance, instance)
+
+ conn
+ |> with_credentials(user.nickname, "test")
+ |> get("/api/statuses/public_timeline.json")
+ |> json_response(200)
+
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:public, true)
+
+ Application.put_env(:pleroma, :instance, instance)
+ end
+
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
conn
|> get("/api/statuses/public_timeline.json")
|> json_response(200)
end
+
+ test "returns 200 to authenticated request when the instance is public",
+ %{conn: conn, user: user} do
+ conn
+ |> with_credentials(user.nickname, "test")
+ |> get("/api/statuses/public_timeline.json")
+ |> json_response(200)
+ end
end
describe "GET /statuses/public_and_external_timeline.json" do
+ setup [:valid_user]
+
test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
instance =
Application.get_env(:pleroma, :instance)
@@ -171,11 +203,39 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
Application.put_env(:pleroma, :instance, instance)
end
+ test "returns 200 to authenticated request when the instance is not public",
+ %{conn: conn, user: user} do
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:public, false)
+
+ Application.put_env(:pleroma, :instance, instance)
+
+ conn
+ |> with_credentials(user.nickname, "test")
+ |> get("/api/statuses/public_and_external_timeline.json")
+ |> json_response(200)
+
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:public, true)
+
+ Application.put_env(:pleroma, :instance, instance)
+ end
+
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
conn
|> get("/api/statuses/public_and_external_timeline.json")
|> json_response(200)
end
+
+ test "returns 200 to authenticated request when the instance is public",
+ %{conn: conn, user: user} do
+ conn
+ |> with_credentials(user.nickname, "test")
+ |> get("/api/statuses/public_and_external_timeline.json")
+ |> json_response(200)
+ end
end
describe "GET /statuses/show/:id.json" do
--
cgit v1.2.3
From b43d630f307110b5fa552c28c9fa0ebae09e85f2 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Sun, 23 Dec 2018 18:31:37 +0100
Subject: Web.TwitterAPI.UserView: Add rights.admin
---
test/web/twitter_api/views/user_view_test.exs | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 32e9466e1..5f7481eb6 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -90,7 +90,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"follows_you" => false,
"statusnet_blocking" => false,
"rights" => %{
- "delete_others_notice" => false
+ "delete_others_notice" => false,
+ "admin" => false
},
"statusnet_profile_url" => user.ap_id,
"cover_photo" => banner,
@@ -135,7 +136,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"follows_you" => false,
"statusnet_blocking" => false,
"rights" => %{
- "delete_others_notice" => false
+ "delete_others_notice" => false,
+ "admin" => false
},
"statusnet_profile_url" => user.ap_id,
"cover_photo" => banner,
@@ -181,7 +183,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"follows_you" => true,
"statusnet_blocking" => false,
"rights" => %{
- "delete_others_notice" => false
+ "delete_others_notice" => false,
+ "admin" => false
},
"statusnet_profile_url" => follower.ap_id,
"cover_photo" => banner,
@@ -207,6 +210,13 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
assert represented["rights"]["delete_others_notice"]
end
+ test "a user that is a admin" do
+ user = insert(:user, %{info: %{is_admin: true}})
+ represented = UserView.render("show.json", %{user: user, for: user})
+
+ assert represented["rights"]["admin"]
+ end
+
test "A blocked user for the blocker" do
user = insert(:user)
blocker = insert(:user)
@@ -234,7 +244,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"follows_you" => false,
"statusnet_blocking" => true,
"rights" => %{
- "delete_others_notice" => false
+ "delete_others_notice" => false,
+ "admin" => false
},
"statusnet_profile_url" => user.ap_id,
"cover_photo" => banner,
--
cgit v1.2.3
From 6e9a15b181fcca9e7485a61b1cce2e4ec6d46b78 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Fri, 28 Dec 2018 21:08:07 +0300
Subject: [#483] Blocked users export for TwitterAPI.
---
test/web/twitter_api/twitter_api_controller_test.exs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 474d72df6..e49d605bd 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1085,6 +1085,24 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
end
+ describe "GET /api/statuses/blocks" do
+ test "it returns the list of users blocked by requester", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, user} = User.block(user, other_user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/statuses/blocks")
+
+ expected = UserView.render("index.json", %{users: [other_user], for: user})
+ result = json_response(conn, 200)
+ assert Enum.sort(expected) == Enum.sort(result)
+ end
+ end
+
describe "GET /api/statuses/friends" do
test "it returns the logged in user's friends", %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From 67b4297f4d4010ee1b66452af4cea094d2cab2c4 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Sat, 29 Dec 2018 12:02:37 +0300
Subject: [#483] Refactored blocks and follows import, added tests.
---
test/user_test.exs | 30 +++++++++++++++++++++++
test/web/twitter_api/util_controller_test.exs | 35 +++++++++++++++++++++++++++
2 files changed, 65 insertions(+)
create mode 100644 test/web/twitter_api/util_controller_test.exs
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 8c7e1594b..6a081c5c5 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -485,6 +485,21 @@ defmodule Pleroma.UserTest do
end
end
+ describe "follow_import" do
+ test "it imports user followings from list" do
+ [user1, user2, user3] = insert_list(3, :user)
+
+ identifiers = [
+ user2.ap_id,
+ user3.nickname
+ ]
+
+ result = User.follow_import(user1, identifiers)
+ assert is_list(result)
+ assert result == [user2, user3]
+ end
+ end
+
describe "blocks" do
test "it blocks people" do
user = insert(:user)
@@ -584,6 +599,21 @@ defmodule Pleroma.UserTest do
end
end
+ describe "blocks_import" do
+ test "it imports user blocks from list" do
+ [user1, user2, user3] = insert_list(3, :user)
+
+ identifiers = [
+ user2.ap_id,
+ user3.nickname
+ ]
+
+ result = User.blocks_import(user1, identifiers)
+ assert is_list(result)
+ assert result == [user2, user3]
+ end
+ end
+
test "get recipients from activity" do
actor = insert(:user)
user = insert(:user, local: true)
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
new file mode 100644
index 000000000..73aa70bd5
--- /dev/null
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -0,0 +1,35 @@
+defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
+ use Pleroma.Web.ConnCase
+
+ import Pleroma.Factory
+
+ describe "POST /api/pleroma/follow_import" do
+ test "it returns HTTP 200", %{conn: conn} do
+ user1 = insert(:user)
+ user2 = insert(:user)
+
+ response =
+ conn
+ |> assign(:user, user1)
+ |> post("/api/pleroma/follow_import", %{"list" => "#{user2.ap_id}"})
+ |> json_response(:ok)
+
+ assert response == "job started"
+ end
+ end
+
+ describe "POST /api/pleroma/blocks_import" do
+ test "it returns HTTP 200", %{conn: conn} do
+ user1 = insert(:user)
+ user2 = insert(:user)
+
+ response =
+ conn
+ |> assign(:user, user1)
+ |> post("/api/pleroma/blocks_import", %{"list" => "#{user2.ap_id}"})
+ |> json_response(:ok)
+
+ assert response == "job started"
+ end
+ end
+end
--
cgit v1.2.3
From 7bd49a32222045c34098f925fbd494461ab67ccd Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Sat, 29 Dec 2018 12:26:23 +0300
Subject: [#483] User.get_by_nickname/1: ensured case-insensitive matching for
local FQN. Added tests.
---
test/user_test.exs | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 6a081c5c5..8225453ab 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -278,6 +278,25 @@ defmodule Pleroma.UserTest do
assert user == fetched_user
end
+
+ test "gets an existing user by fully qualified nickname" do
+ user = insert(:user)
+
+ fetched_user =
+ User.get_or_fetch_by_nickname(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
+
+ assert user == fetched_user
+ end
+
+ test "gets an existing user by fully qualified nickname, case insensitive" do
+ user = insert(:user, nickname: "nick")
+ casing_altered_fqn = String.upcase(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
+
+ fetched_user = User.get_or_fetch_by_nickname(casing_altered_fqn)
+
+ assert user == fetched_user
+ end
+
test "fetches an external user via ostatus if no user exists" do
fetched_user = User.get_or_fetch_by_nickname("shp@social.heldscal.la")
assert fetched_user.nickname == "shp@social.heldscal.la"
--
cgit v1.2.3
From 242cc9a6589f54c523284dc2ec18990feb2ca00a Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Sat, 29 Dec 2018 12:26:23 +0300
Subject: [#483] User.get_by_nickname/1: ensured case-insensitive matching for
local FQN. Added tests.
---
test/user_test.exs | 1 -
1 file changed, 1 deletion(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 8225453ab..4680850ea 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -278,7 +278,6 @@ defmodule Pleroma.UserTest do
assert user == fetched_user
end
-
test "gets an existing user by fully qualified nickname" do
user = insert(:user)
--
cgit v1.2.3
From aa082ca7b6a64f6cfd509118f76a5c18492e07b9 Mon Sep 17 00:00:00 2001
From: sxsdv1
Date: Sat, 29 Dec 2018 18:01:15 +0100
Subject: Wire up stub routes for client calls of activitypub inbox/outbox
Code style: remove wrapping function of outbox
---
.../fixtures/activitypub-client-post-activity.json | 9 ++++++++
.../activity_pub/activity_pub_controller_test.exs | 27 ++++++++++++++++++++++
2 files changed, 36 insertions(+)
create mode 100644 test/fixtures/activitypub-client-post-activity.json
(limited to 'test')
diff --git a/test/fixtures/activitypub-client-post-activity.json b/test/fixtures/activitypub-client-post-activity.json
new file mode 100644
index 000000000..c985e072b
--- /dev/null
+++ b/test/fixtures/activitypub-client-post-activity.json
@@ -0,0 +1,9 @@
+{
+ "@context": ["https://www.w3.org/ns/activitystreams", {"@language": "en-GB"}],
+ "type": "Create",
+ "object": {
+ "type": "Note",
+ "content": "It's a note"
+ },
+ "to": ["https://www.w3.org/ns/activitystreams#Public"]
+}
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 9fdf15505..95027f855 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -112,6 +112,19 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
:timer.sleep(500)
assert Activity.get_by_ap_id(data["id"])
end
+
+ test "it rejects reads from other users", %{conn: conn} do
+ user = insert(:user)
+ otheruser = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, otheruser)
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/users/#{user.nickname}/inbox")
+
+ assert json_response(conn, 403)
+ end
end
describe "/users/:nickname/outbox" do
@@ -138,6 +151,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert response(conn, 200) =~ announce_activity.data["object"]
end
+
+ test "it rejects posts from other users", %{conn: conn} do
+ data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!()
+ user = insert(:user)
+ otheruser = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, otheruser)
+ |> put_req_header("content-type", "application/activity+json")
+ |> post("/users/#{user.nickname}/outbox", data)
+
+ assert json_response(conn, 403)
+ end
end
describe "/users/:nickname/followers" do
--
cgit v1.2.3
From 26dc2dddab6103a3e6e44a3c7ba097283302fc2a Mon Sep 17 00:00:00 2001
From: sxsdv1
Date: Sat, 29 Dec 2018 18:15:28 +0100
Subject: Implement ActivityPub inbox view
More or less verbatim copied from the outbox template with only changes
to the activities fetched and url reported
---
test/web/activity_pub/activity_pub_controller_test.exs | 13 +++++++++++++
1 file changed, 13 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 95027f855..589645dd6 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -125,6 +125,19 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 403)
end
+
+ test "it returns a note activity in a collection", %{conn: conn} do
+ note_activity = insert(:direct_note_activity)
+ user = User.get_cached_by_ap_id(hd(note_activity.data["to"]))
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/users/#{user.nickname}/inbox")
+
+ assert response(conn, 200) =~ note_activity.data["object"]["content"]
+ end
end
describe "/users/:nickname/outbox" do
--
cgit v1.2.3
From 569bad821006add1719123f6e2830f23542921d2 Mon Sep 17 00:00:00 2001
From: sxsdv1
Date: Sat, 29 Dec 2018 18:21:45 +0100
Subject: Create activity when client posts to outbox
---
test/web/activity_pub/activity_pub_controller_test.exs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 589645dd6..cb95e0e09 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -178,6 +178,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 403)
end
+
+ test "it inserts an incoming activity into the database", %{conn: conn} do
+ data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!()
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> put_req_header("content-type", "application/activity+json")
+ |> post("/users/#{user.nickname}/outbox", data)
+
+ result = json_response(conn, 201)
+ assert Activity.get_by_ap_id(result["id"])
+ end
end
describe "/users/:nickname/followers" do
--
cgit v1.2.3
From cb286fdeba1782b75d1d7bca484d80e3cd499a98 Mon Sep 17 00:00:00 2001
From: Michael Loftis
Date: Sun, 30 Dec 2018 15:16:26 +0000
Subject: Improves RetryQueue behavior
reduces to one single timer firing once a second
switches to a parallel worker model
---
test/web/retry_queue_test.exs | 31 ++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)
(limited to 'test')
diff --git a/test/web/retry_queue_test.exs b/test/web/retry_queue_test.exs
index 9351b6c24..ecb3ce5d0 100644
--- a/test/web/retry_queue_test.exs
+++ b/test/web/retry_queue_test.exs
@@ -3,7 +3,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule MockActivityPub do
- def publish_one(ret) do
+ def publish_one({ret, waiter}) do
+ send(waiter, :complete)
{ret, "success"}
end
end
@@ -15,21 +16,33 @@ defmodule Pleroma.Web.Federator.RetryQueueTest do
@small_retry_count 0
@hopeless_retry_count 10
+ setup do
+ RetryQueue.reset_stats()
+ end
+
+ test "RetryQueue responds to stats request" do
+ assert %{delivered: 0, dropped: 0} == RetryQueue.get_stats()
+ end
+
test "failed posts are retried" do
{:retry, _timeout} = RetryQueue.get_retry_params(@small_retry_count)
- assert {:noreply, %{delivered: 1}} ==
- RetryQueue.handle_info({:send, :ok, MockActivityPub, @small_retry_count}, %{
- delivered: 0
- })
+ wait_task =
+ Task.async(fn ->
+ receive do
+ :complete -> :ok
+ end
+ end)
+
+ RetryQueue.enqueue({:ok, wait_task.pid}, MockActivityPub, @small_retry_count)
+ Task.await(wait_task)
+ assert %{delivered: 1, dropped: 0} == RetryQueue.get_stats()
end
test "posts that have been tried too many times are dropped" do
{:drop, _timeout} = RetryQueue.get_retry_params(@hopeless_retry_count)
- assert {:noreply, %{dropped: 1}} ==
- RetryQueue.handle_cast({:maybe_enqueue, %{}, nil, @hopeless_retry_count}, %{
- dropped: 0
- })
+ RetryQueue.enqueue({:ok, nil}, MockActivityPub, @hopeless_retry_count)
+ assert %{delivered: 0, dropped: 1} == RetryQueue.get_stats()
end
end
--
cgit v1.2.3
From 91d5a7e81c3161f80bb70cd9e1e7a7c8bc70c0b1 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Mon, 31 Dec 2018 00:03:03 +0300
Subject: Fix test failure
---
test/user_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 4680850ea..ef652daf7 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -709,7 +709,7 @@ defmodule Pleroma.UserTest do
test "html_filter_policy returns nil when rich-text is enabled" do
user = insert(:user)
- assert nil == User.html_filter_policy(user)
+ assert [Pleroma.HTML.Transform.MediaProxy, Pleroma.HTML.Scrubber.Default] == User.html_filter_policy(user)
end
test "html_filter_policy returns TwitterText scrubber when rich-text is disabled" do
--
cgit v1.2.3
From 05743e2000a5837365ab2393732b9a9468d738d7 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Mon, 31 Dec 2018 00:12:14 +0300
Subject: Get default scrubbers from config instead of hardcoded
---
test/user_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index ef652daf7..bd40d7f85 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -709,7 +709,7 @@ defmodule Pleroma.UserTest do
test "html_filter_policy returns nil when rich-text is enabled" do
user = insert(:user)
- assert [Pleroma.HTML.Transform.MediaProxy, Pleroma.HTML.Scrubber.Default] == User.html_filter_policy(user)
+ assert Pleroma.Config.get([:markup, :scrub_policy]) == User.html_filter_policy(user)
end
test "html_filter_policy returns TwitterText scrubber when rich-text is disabled" do
--
cgit v1.2.3
From 9f5881cbb1957a286d9b191e3d5be7f06b5a2941 Mon Sep 17 00:00:00 2001
From: Rin Toshaka
Date: Mon, 31 Dec 2018 08:34:14 +0100
Subject: Fix a typo in user_test.ex
---
test/user_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index bd40d7f85..869e9196d 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -706,7 +706,7 @@ defmodule Pleroma.UserTest do
end
describe "per-user rich-text filtering" do
- test "html_filter_policy returns nil when rich-text is enabled" do
+ test "html_filter_policy returns default policies, when rich-text is enabled" do
user = insert(:user)
assert Pleroma.Config.get([:markup, :scrub_policy]) == User.html_filter_policy(user)
--
cgit v1.2.3
From 2aab4e03c3a2867abd4555dc776eebc8b0dba176 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Tue, 1 Jan 2019 23:26:40 +0300
Subject: Add OGP parser
---
test/fixtures/rich_media/ogp.html | 9 +++++++++
test/web/rich_media/parser_test.exs | 26 ++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
create mode 100644 test/fixtures/rich_media/ogp.html
create mode 100644 test/web/rich_media/parser_test.exs
(limited to 'test')
diff --git a/test/fixtures/rich_media/ogp.html b/test/fixtures/rich_media/ogp.html
new file mode 100644
index 000000000..c886b5871
--- /dev/null
+++ b/test/fixtures/rich_media/ogp.html
@@ -0,0 +1,9 @@
+
+
+ The Rock (1996)
+
+
+
+
+
+
diff --git a/test/web/rich_media/parser_test.exs b/test/web/rich_media/parser_test.exs
new file mode 100644
index 000000000..bb0d663e9
--- /dev/null
+++ b/test/web/rich_media/parser_test.exs
@@ -0,0 +1,26 @@
+defmodule Pleroma.Web.RichMedia.ParserTest do
+ use ExUnit.Case, async: true
+
+ setup do
+ Tesla.Mock.mock(fn
+ %{
+ method: :get,
+ url: "http://example.com/ogp"
+ } ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}
+ end)
+
+ :ok
+ end
+
+ test "parses ogp" do
+ assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/ogp") ==
+ %Pleroma.Web.RichMedia.Data{
+ description: nil,
+ image: "http://ia.media-imdb.com/images/rock.jpg",
+ title: "The Rock",
+ type: "video.movie",
+ url: "http://www.imdb.com/title/tt0117500/"
+ }
+ end
+end
--
cgit v1.2.3
From 551c3d9391c0eeb282d750979b8eef5025c41482 Mon Sep 17 00:00:00 2001
From: sxsdv1
Date: Tue, 1 Jan 2019 22:16:46 +0100
Subject: Split create activity specifics from update_outbox
---
test/web/activity_pub/activity_pub_controller_test.exs | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index cb95e0e09..77dc96617 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -192,6 +192,23 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
result = json_response(conn, 201)
assert Activity.get_by_ap_id(result["id"])
end
+
+ test "it rejects an incoming activity with bogus type", %{conn: conn} do
+ data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!()
+ user = insert(:user)
+
+ data =
+ data
+ |> Map.put("type", "BadType")
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> put_req_header("content-type", "application/activity+json")
+ |> post("/users/#{user.nickname}/outbox", data)
+
+ assert json_response(conn, 400)
+ end
end
describe "/users/:nickname/followers" do
--
cgit v1.2.3
From 4e1cc2bab6ec76af1b6de986561a82887d18f366 Mon Sep 17 00:00:00 2001
From: sxsdv1
Date: Tue, 1 Jan 2019 23:19:40 +0100
Subject: Implement delete activity
---
.../activity_pub/activity_pub_controller_test.exs | 49 +++++++++++++++++++++-
1 file changed, 47 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 77dc96617..620e03674 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -6,7 +6,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
alias Pleroma.Web.ActivityPub.{UserView, ObjectView}
- alias Pleroma.{Repo, User}
+ alias Pleroma.{Object, Repo, User}
alias Pleroma.Activity
setup_all do
@@ -179,7 +179,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 403)
end
- test "it inserts an incoming activity into the database", %{conn: conn} do
+ test "it inserts an incoming create activity into the database", %{conn: conn} do
data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!()
user = insert(:user)
@@ -209,6 +209,51 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 400)
end
+
+ test "it erects a tombstone when receiving a delete activity", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+
+ data = %{
+ type: "Delete",
+ object: %{
+ id: note_activity.data["object"]["id"]
+ }
+ }
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> put_req_header("content-type", "application/activity+json")
+ |> post("/users/#{user.nickname}/outbox", data)
+
+ result = json_response(conn, 201)
+ assert Activity.get_by_ap_id(result["id"])
+
+ object = Object.get_by_ap_id(note_activity.data["object"]["id"])
+ assert object
+ assert object.data["type"] == "Tombstone"
+ end
+
+ test "it rejects delete activity of object from other actor", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ user = insert(:user)
+
+ data = %{
+ type: "Delete",
+ object: %{
+ id: note_activity.data["object"]["id"]
+ }
+ }
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> put_req_header("content-type", "application/activity+json")
+ |> post("/users/#{user.nickname}/outbox", data)
+
+ assert json_response(conn, 400)
+ end
end
describe "/users/:nickname/followers" do
--
cgit v1.2.3
From 48e81d3d40d334bccb8438c61ab6b307ddb1392f Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Wed, 2 Jan 2019 17:02:50 +0300
Subject: Add RichMediaController and tests
---
.../controllers/rich_media_controller_test.exs | 54 ++++++++++++++++++++++
test/web/rich_media/parser_test.exs | 21 ++++++---
2 files changed, 68 insertions(+), 7 deletions(-)
create mode 100644 test/web/rich_media/controllers/rich_media_controller_test.exs
(limited to 'test')
diff --git a/test/web/rich_media/controllers/rich_media_controller_test.exs b/test/web/rich_media/controllers/rich_media_controller_test.exs
new file mode 100644
index 000000000..37c82631f
--- /dev/null
+++ b/test/web/rich_media/controllers/rich_media_controller_test.exs
@@ -0,0 +1,54 @@
+defmodule Pleroma.Web.RichMedia.RichMediaControllerTest do
+ use Pleroma.Web.ConnCase
+ import Pleroma.Factory
+
+ setup do
+ Tesla.Mock.mock(fn
+ %{
+ method: :get,
+ url: "http://example.com/ogp"
+ } ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}
+
+ %{method: :get, url: "http://example.com/empty"} ->
+ %Tesla.Env{status: 200, body: "hello"}
+ end)
+
+ :ok
+ end
+
+ describe "GET /api/rich_media/parse" do
+ setup do
+ user = insert(:user)
+
+ [user: user]
+ end
+
+ test "returns 404 if not metadata found", %{user: user} do
+ build_conn()
+ |> with_credentials(user.nickname, "test")
+ |> get("/api/rich_media/parse", %{"url" => "http://example.com/empty"})
+ |> json_response(404)
+ end
+
+ test "returns OGP metadata", %{user: user} do
+ response =
+ build_conn()
+ |> with_credentials(user.nickname, "test")
+ |> get("/api/rich_media/parse", %{"url" => "http://example.com/ogp"})
+ |> json_response(200)
+
+ assert response == %{
+ "image" => "http://ia.media-imdb.com/images/rock.jpg",
+ "title" => "The Rock",
+ "type" => "video.movie",
+ "url" => "http://www.imdb.com/title/tt0117500/"
+ }
+ end
+ end
+
+ defp with_credentials(conn, username, password) do
+ header_content = "Basic " <> Base.encode64("#{username}:#{password}")
+ put_req_header(conn, "authorization", header_content)
+ end
+end
diff --git a/test/web/rich_media/parser_test.exs b/test/web/rich_media/parser_test.exs
index bb0d663e9..caf81e9fa 100644
--- a/test/web/rich_media/parser_test.exs
+++ b/test/web/rich_media/parser_test.exs
@@ -8,19 +8,26 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
url: "http://example.com/ogp"
} ->
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}
+
+ %{method: :get, url: "http://example.com/empty"} ->
+ %Tesla.Env{status: 200, body: "hello"}
end)
:ok
end
+ test "returns error when no metadata present" do
+ assert {:error, _} = Pleroma.Web.RichMedia.Parser.parse("http://example.com/empty")
+ end
+
test "parses ogp" do
assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/ogp") ==
- %Pleroma.Web.RichMedia.Data{
- description: nil,
- image: "http://ia.media-imdb.com/images/rock.jpg",
- title: "The Rock",
- type: "video.movie",
- url: "http://www.imdb.com/title/tt0117500/"
- }
+ {:ok,
+ %{
+ image: "http://ia.media-imdb.com/images/rock.jpg",
+ title: "The Rock",
+ type: "video.movie",
+ url: "http://www.imdb.com/title/tt0117500/"
+ }}
end
end
--
cgit v1.2.3
From ab6ebbae67c307e007806daa68a4217511bf4ed2 Mon Sep 17 00:00:00 2001
From: cascode
Date: Fri, 4 Jan 2019 10:14:13 -0800
Subject: added test for #499
---
test/user_test.exs | 8 ++++++++
1 file changed, 8 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 869e9196d..4f4f55f90 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -756,5 +756,13 @@ defmodule Pleroma.UserTest do
assert user_four ==
User.search("lain@ple") |> List.first() |> Map.put(:search_distance, nil)
end
+
+ test "finds a user whose name is nil" do
+ _user = insert(:user, %{name: "notamatch", nickname: "testuser@pleroma.amplifie.red"})
+ user_two = insert(:user, %{name: nil, nickname: "lain@pleroma.soykaf.com"})
+
+ assert user_two ==
+ User.search("lain@pleroma.soykaf.com") |> List.first() |> Map.put(:search_distance, nil)
+ end
end
end
--
cgit v1.2.3
From 4c5ee4c62bb68982bf286b302dec77468a6d19b5 Mon Sep 17 00:00:00 2001
From: cascode
Date: Fri, 4 Jan 2019 10:18:43 -0800
Subject: formatted
---
test/user_test.exs | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 4f4f55f90..74accb7c8 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -762,7 +762,9 @@ defmodule Pleroma.UserTest do
user_two = insert(:user, %{name: nil, nickname: "lain@pleroma.soykaf.com"})
assert user_two ==
- User.search("lain@pleroma.soykaf.com") |> List.first() |> Map.put(:search_distance, nil)
+ User.search("lain@pleroma.soykaf.com")
+ |> List.first()
+ |> Map.put(:search_distance, nil)
end
end
end
--
cgit v1.2.3
From 2d7da5f4375164aa78e221ab054529a04d09e819 Mon Sep 17 00:00:00 2001
From: sxsdv1
Date: Sat, 5 Jan 2019 10:38:38 +0100
Subject: Don't crash on AP request for tombstone
Because tombstone objects has no addressing the is_public?-predicate
would cause an error that propagated as a 500 error in the api
---
test/support/factory.ex | 13 +++++++++++++
test/web/activity_pub/activity_pub_controller_test.exs | 12 ++++++++++++
2 files changed, 25 insertions(+)
(limited to 'test')
diff --git a/test/support/factory.ex b/test/support/factory.ex
index e5c0c5bcc..57fa4a79d 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -57,6 +57,19 @@ defmodule Pleroma.Factory do
%Pleroma.Object{data: Map.merge(data, %{"to" => [user2.ap_id]})}
end
+ def tombstone_factory do
+ data = %{
+ "type" => "Tombstone",
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
+ "formerType" => "Note",
+ "deleted" => DateTime.utc_now() |> DateTime.to_iso8601()
+ }
+
+ %Pleroma.Object{
+ data: data
+ }
+ end
+
def direct_note_activity_factory do
dm = insert(:direct_note)
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 620e03674..7d1fe184e 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -75,6 +75,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 404)
end
+
+ test "it returns 404 for tombstone objects", %{conn: conn} do
+ tombstone = insert(:tombstone)
+ uuid = String.split(tombstone.data["id"], "/") |> List.last()
+
+ conn =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/objects/#{uuid}")
+
+ assert json_response(conn, 404)
+ end
end
describe "/inbox" do
--
cgit v1.2.3
From 6556be344de981272b9c14faf5fb9837c1ea0da6 Mon Sep 17 00:00:00 2001
From: scarlett
Date: Sat, 5 Jan 2019 18:20:42 +0000
Subject: Resolve some test failures.
---
test/web/twitter_api/views/activity_view_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 013245033..40c4abc39 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -73,6 +73,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"repeat_num" => 0,
"repeated" => false,
"statusnet_conversation_id" => convo_id,
+ "summary" => "",
"statusnet_html" =>
"Hey @shp !",
"tags" => [],
@@ -80,7 +81,6 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"uri" => activity.data["object"]["id"],
"user" => UserView.render("show.json", %{user: user}),
"visibility" => "direct",
- "summary" => nil
}
assert result == expected
--
cgit v1.2.3
From 096e121879f5e9aad694f1b57438f0545ecd73b3 Mon Sep 17 00:00:00 2001
From: scarlett
Date: Sat, 5 Jan 2019 18:25:36 +0000
Subject: Remove redundant comma.
---
test/web/twitter_api/views/activity_view_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 40c4abc39..32a08dbc9 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -80,7 +80,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"text" => "Hey @shp!",
"uri" => activity.data["object"]["id"],
"user" => UserView.render("show.json", %{user: user}),
- "visibility" => "direct",
+ "visibility" => "direct"
}
assert result == expected
--
cgit v1.2.3
From 57df7d6e1da1a94a3866afc9b6d353aea602d4d3 Mon Sep 17 00:00:00 2001
From: scarlett
Date: Sat, 5 Jan 2019 21:46:42 +0000
Subject: Add tests for emoji and lack of HTML in summaries.
---
test/web/twitter_api/views/activity_view_test.exs | 29 +++++++++++++++++++++++
1 file changed, 29 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 32a08dbc9..05780a54a 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -41,6 +41,35 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg"
end
+ test "a create activity with a summary containing emoji" do
+ {:ok, activity} =
+ CommonAPI.post(insert(:user), %{
+ "spoiler_text" => ":woollysocks: meow",
+ "status" => "."
+ })
+
+ result = ActivityView.render("activity.json", activity: activity)
+
+ expected =
+ " meow"
+
+ assert result["summary"] == expected
+ end
+
+ test "a create activity with a summary containing invalid HTML" do
+ {:ok, activity} =
+ CommonAPI.post(insert(:user), %{
+ "spoiler_text" => "meow ",
+ "status" => "."
+ })
+
+ result = ActivityView.render("activity.json", activity: activity)
+
+ expected = "meow"
+
+ assert result["summary"] == expected
+ end
+
test "a create activity with a note" do
user = insert(:user)
other_user = insert(:user, %{nickname: "shp"})
--
cgit v1.2.3
From 042852ecf344b4ede15a22ea0279fff8a67b75f0 Mon Sep 17 00:00:00 2001
From: Sadposter
Date: Sat, 5 Jan 2019 22:54:25 +0000
Subject: Add check to prevent multiple follow notifications from the same user
---
test/notification_test.exs | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
(limited to 'test')
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 31c0d2c64..94fb0ab15 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -46,6 +46,43 @@ defmodule Pleroma.NotificationTest do
assert nil == Notification.create_notification(activity, author)
end
+
+ test "it doesn't create a notification for follow-unfollow-follow chains" do
+ user = insert(:user)
+ followed_user = insert(:user)
+ {:ok, _, _, activity} = TwitterAPI.follow(user, %{"user_id" => followed_user.id})
+ Notification.create_notification(activity, followed_user)
+ TwitterAPI.unfollow(user, %{"user_id" => followed_user.id})
+ {:ok, _, _, activity_dupe} = TwitterAPI.follow(user, %{"user_id" => followed_user.id})
+ assert nil == Notification.create_notification(activity_dupe, followed_user)
+ end
+
+ test "it doesn't create a notification for like-unlike-like chains" do
+ user = insert(:user)
+ liked_user = insert(:user)
+ {:ok, status} = TwitterAPI.create_status(liked_user, %{"status" => "Yui is best yuru"})
+ {:ok, fav_status} = TwitterAPI.fav(user, status.id)
+ Notification.create_notification(fav_status, liked_user)
+ TwitterAPI.unfav(user, status.id)
+ {:ok, dupe} = TwitterAPI.fav(user, status.id)
+ assert nil == Notification.create_notification(dupe, liked_user)
+ end
+
+ test "it doesn't create a notification for repeat-unrepeat-repeat chains" do
+ user = insert(:user)
+ retweeted_user = insert(:user)
+
+ {:ok, status} =
+ TwitterAPI.create_status(retweeted_user, %{
+ "status" => "Send dupe notifications to the shadow realm"
+ })
+
+ {:ok, retweeted_activity} = TwitterAPI.repeat(user, status.id)
+ Notification.create_notification(retweeted_activity, retweeted_user)
+ TwitterAPI.unrepeat(user, status.id)
+ {:ok, dupe} = TwitterAPI.repeat(user, status.id)
+ assert nil == Notification.create_notification(dupe, retweeted_user)
+ end
end
describe "get notification" do
--
cgit v1.2.3
From 52493467ac314ec58ed6123d3581428a82ec170c Mon Sep 17 00:00:00 2001
From: scarlett
Date: Sun, 6 Jan 2019 10:16:40 +0000
Subject: Twitter API: Add a summary_html field.
The intention here is to allow proper subject copying when it contains
emoji, obviously this will require minor frontend changes, though.
---
test/web/twitter_api/representers/activity_representer_test.exs | 3 ++-
test/web/twitter_api/views/activity_view_test.exs | 7 ++++++-
2 files changed, 8 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index 2ac32aeb2..ab3e04985 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -163,7 +163,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
"possibly_sensitive" => true,
"uri" => activity.data["object"]["id"],
"visibility" => "direct",
- "summary" => "2hu"
+ "summary" => "2hu",
+ "summary_html" => "2hu"
}
assert ActivityRepresenter.to_map(activity, %{
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 05780a54a..a03f48b61 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -50,10 +50,13 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
result = ActivityView.render("activity.json", activity: activity)
- expected =
+ expected = ":woollysocks: meow"
+
+ expected_html =
" meow"
assert result["summary"] == expected
+ assert result["summary_html"] == expected_html
end
test "a create activity with a summary containing invalid HTML" do
@@ -68,6 +71,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
expected = "meow"
assert result["summary"] == expected
+ assert result["summary_html"] == expected
end
test "a create activity with a note" do
@@ -103,6 +107,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"repeated" => false,
"statusnet_conversation_id" => convo_id,
"summary" => "",
+ "summary_html" => "",
"statusnet_html" =>
"Hey @shp !",
"tags" => [],
--
cgit v1.2.3
From 7382adf407301945e30ee38aa4efe28a819fcf44 Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 7 Jan 2019 12:41:31 +0100
Subject: Make TwAPI UserView more resilient to issues.
Will work for missing users and badly migrated users.
---
test/web/twitter_api/views/activity_view_test.exs | 28 +++++++++++++++++++++++
1 file changed, 28 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 05780a54a..7f003c214 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -25,6 +25,34 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
import Mock
+ test "returns an error user for activities missing users" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
+
+ Repo.delete(user)
+ Cachex.clear(:user_cache)
+
+ result = ActivityView.render("activity.json", activity: activity)
+ assert result
+ end
+
+ test "tries to get a user by nickname if fetching by ap_id doesn't work" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
+
+ {:ok, user} =
+ user
+ |> Ecto.Changeset.change(%{ap_id: "#{user.ap_id}/extension/#{user.nickname}"})
+ |> Repo.update()
+
+ Cachex.clear(:user_cache)
+
+ result = ActivityView.render("activity.json", activity: activity)
+ assert result["user"]["id"] == user.id
+ end
+
test "a create activity with a html status" do
text = """
#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg
--
cgit v1.2.3
From 7dcafb4894006bd9f531403fe585ec4938d4de12 Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 7 Jan 2019 13:13:37 +0100
Subject: MastoAPI: Add test.
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 0136acf8c..ce87010c8 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1312,6 +1312,24 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end)
end
+ test "search doesn't show statuses that it shouldn't", %{conn: conn} do
+ {:ok, activity} =
+ CommonAPI.post(insert(:user), %{
+ "status" => "This is about 2hu, but private",
+ "visibility" => "private"
+ })
+
+ capture_log(fn ->
+ conn =
+ conn
+ |> get("/api/v1/search", %{"q" => activity.data["object"]["id"]})
+
+ assert results = json_response(conn, 200)
+
+ [] = results["statuses"]
+ end)
+ end
+
test "search fetches remote accounts", %{conn: conn} do
conn =
conn
--
cgit v1.2.3
From 380e9fba21123467b41629828f97d5f2c257a128 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 7 Jan 2019 20:45:33 +0700
Subject: add pinned posts
---
test/web/activity_pub/activity_pub_test.exs | 22 +++++
test/web/common_api/common_api_test.exs | 36 ++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 95 ++++++++++++++++++++++
3 files changed, 153 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 2453998ad..7d9febc47 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -601,6 +601,28 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert object
end
+ test "returned pinned posts" do
+ Pleroma.Config.put([:instance, :max_pinned_posts], 3)
+ user = insert(:user)
+
+ {:ok, activity_one} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, activity_three} = CommonAPI.post(user, %{"status" => "HI!!!"})
+
+ CommonAPI.pin(activity_one.id, user)
+
+ user = User.get_by_ap_id(user.ap_id)
+ CommonAPI.pin(activity_two.id, user)
+
+ user = User.get_by_ap_id(user.ap_id)
+ CommonAPI.pin(activity_three.id, user)
+
+ user = User.get_by_ap_id(user.ap_id)
+ activities = ActivityPub.fetch_user_activities(user, nil, %{"pinned" => "true"})
+
+ assert 3 = length(activities)
+ end
+
def data_uri do
File.read!("test/fixtures/avatar_data_uri")
end
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index c3674711a..59beb3120 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -96,4 +96,40 @@ defmodule Pleroma.Web.CommonAPI.Test do
{:error, _} = CommonAPI.favorite(activity.id, user)
end
end
+
+ describe "pinned posts" do
+ test "pin post" do
+ Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
+
+ assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
+ end
+
+ test "max pinned posts" do
+ Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ user = insert(:user)
+
+ {:ok, activity_one} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
+
+ assert {:ok, ^activity_one} = CommonAPI.pin(activity_one.id, user)
+
+ user = User.get_by_ap_id(user.ap_id)
+
+ assert {:error, "You have already pinned the maximum number of toots"} =
+ CommonAPI.pin(activity_two.id, user)
+ end
+
+ test "unpin post" do
+ Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, activity} = CommonAPI.pin(activity.id, user)
+
+ assert {:ok, ^activity} = CommonAPI.unpin(activity.id, user)
+ end
+ end
end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 0136acf8c..7f6c9fb88 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1453,4 +1453,99 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = User.get_cached_by_ap_id(user.ap_id)
assert user.info.settings == %{"programming" => "socks"}
end
+
+ describe "pinned posts" do
+ test "returns pinned posts", %{conn: conn} do
+ Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, _} = CommonAPI.pin(activity.id, user)
+
+ result =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
+ |> Map.get(:resp_body)
+ |> Jason.decode!()
+
+ id_str = Integer.to_string(activity.id)
+
+ assert [%{"id" => ^id_str}] = result
+ end
+
+ test "pin post", %{conn: conn} do
+ Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ id_str = Integer.to_string(activity.id)
+
+ assert %{"id" => ^id_str} =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity.id}/pin")
+ |> Map.get(:resp_body)
+ |> Jason.decode!()
+
+ assert [%{"id" => ^id_str}] =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
+ |> Map.get(:resp_body)
+ |> Jason.decode!()
+ end
+
+ test "unpin post", %{conn: conn} do
+ Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, _} = CommonAPI.pin(activity.id, user)
+
+ id_str = Integer.to_string(activity.id)
+ user = User.get_by_ap_id(user.ap_id)
+
+ assert %{"id" => ^id_str} =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity.id}/unpin")
+ |> Map.get(:resp_body)
+ |> Jason.decode!()
+
+ assert [] =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
+ |> Map.get(:resp_body)
+ |> Jason.decode!()
+ end
+
+ test "max pinned posts", %{conn: conn} do
+ Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+
+ user = insert(:user)
+
+ {:ok, activity_one} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
+
+ id_str_one = Integer.to_string(activity_one.id)
+
+ assert %{"id" => ^id_str_one} =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{id_str_one}/pin")
+ |> Map.get(:resp_body)
+ |> Jason.decode!()
+
+ user = User.get_by_ap_id(user.ap_id)
+
+ assert %{"error" => "You have already pinned the maximum number of toots"} =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity_two.id}/pin")
+ |> Map.get(:resp_body)
+ |> Jason.decode!()
+ end
+ end
end
--
cgit v1.2.3
From a16b17cc61a57d1adbc6f10f16fc36e8238c6c2a Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 7 Jan 2019 20:59:30 +0100
Subject: Actually put some onformation in the error user, make it actually
properly parse in conversations.
---
test/web/twitter_api/views/activity_view_test.exs | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 7f003c214..bd4878e98 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -25,7 +25,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
import Mock
- test "returns an error user for activities missing users" do
+ test "returns a temporary ap_id based user for activities missing db users" do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
@@ -33,8 +33,11 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
Repo.delete(user)
Cachex.clear(:user_cache)
- result = ActivityView.render("activity.json", activity: activity)
- assert result
+ %{"user" => tw_user} = ActivityView.render("activity.json", activity: activity)
+
+ assert tw_user["screen_name"] == "erroruser@example.com"
+ assert tw_user["name"] == user.ap_id
+ assert tw_user["statusnet_profile_url"] == user.ap_id
end
test "tries to get a user by nickname if fetching by ap_id doesn't work" do
--
cgit v1.2.3
From 63dbd875684b192e57d356a194c5d07ad98bd810 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 8 Jan 2019 15:25:50 +0700
Subject: rename `post` to `status`
---
test/web/activity_pub/activity_pub_test.exs | 4 ++--
test/web/common_api/common_api_test.exs | 14 +++++++-------
.../mastodon_api/mastodon_api_controller_test.exs | 20 ++++++++++----------
3 files changed, 19 insertions(+), 19 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 7d9febc47..325ef6636 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -601,8 +601,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert object
end
- test "returned pinned posts" do
- Pleroma.Config.put([:instance, :max_pinned_posts], 3)
+ test "returned pinned statuses" do
+ Pleroma.Config.put([:instance, :max_pinned_statuses], 3)
user = insert(:user)
{:ok, activity_one} = CommonAPI.post(user, %{"status" => "HI!!!"})
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 59beb3120..652b53099 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -97,9 +97,9 @@ defmodule Pleroma.Web.CommonAPI.Test do
end
end
- describe "pinned posts" do
- test "pin post" do
- Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ describe "pinned statuses" do
+ test "pin status" do
+ Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
@@ -107,8 +107,8 @@ defmodule Pleroma.Web.CommonAPI.Test do
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
end
- test "max pinned posts" do
- Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ test "max pinned statuses" do
+ Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
user = insert(:user)
{:ok, activity_one} = CommonAPI.post(user, %{"status" => "HI!!!"})
@@ -122,8 +122,8 @@ defmodule Pleroma.Web.CommonAPI.Test do
CommonAPI.pin(activity_two.id, user)
end
- test "unpin post" do
- Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ test "unpin status" do
+ Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 5ff7ef259..e7e42dd24 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1472,9 +1472,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert user.info.settings == %{"programming" => "socks"}
end
- describe "pinned posts" do
- test "returns pinned posts", %{conn: conn} do
- Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ describe "pinned statuses" do
+ test "returns pinned statuses", %{conn: conn} do
+ Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
@@ -1492,8 +1492,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [%{"id" => ^id_str}] = result
end
- test "pin post", %{conn: conn} do
- Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ test "pin status", %{conn: conn} do
+ Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
@@ -1514,8 +1514,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> Jason.decode!()
end
- test "unpin post", %{conn: conn} do
- Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ test "unpin status", %{conn: conn} do
+ Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
@@ -1539,8 +1539,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> Jason.decode!()
end
- test "max pinned posts", %{conn: conn} do
- Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ test "max pinned statuses", %{conn: conn} do
+ Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
user = insert(:user)
@@ -1558,7 +1558,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = User.get_by_ap_id(user.ap_id)
- assert %{"error" => "You have already pinned the maximum number of toots"} =
+ assert %{"error" => "You have already pinned the maximum number of statuses"} =
conn
|> assign(:user, user)
|> post("/api/v1/statuses/#{activity_two.id}/pin")
--
cgit v1.2.3
From e679da4c34194b366624e31356d534ab73b11d2d Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 8 Jan 2019 15:27:02 +0700
Subject: add `pinned` property to `StatusView`
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 10 +++++-----
test/web/mastodon_api/status_view_test.exs | 1 +
2 files changed, 6 insertions(+), 5 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index e7e42dd24..4a8c70b3b 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1489,7 +1489,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
id_str = Integer.to_string(activity.id)
- assert [%{"id" => ^id_str}] = result
+ assert [%{"id" => ^id_str, "pinned" => true}] = result
end
test "pin status", %{conn: conn} do
@@ -1499,14 +1499,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
id_str = Integer.to_string(activity.id)
- assert %{"id" => ^id_str} =
+ assert %{"id" => ^id_str, "pinned" => true} =
conn
|> assign(:user, user)
|> post("/api/v1/statuses/#{activity.id}/pin")
|> Map.get(:resp_body)
|> Jason.decode!()
- assert [%{"id" => ^id_str}] =
+ assert [%{"id" => ^id_str, "pinned" => true}] =
conn
|> assign(:user, user)
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
@@ -1524,7 +1524,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
id_str = Integer.to_string(activity.id)
user = User.get_by_ap_id(user.ap_id)
- assert %{"id" => ^id_str} =
+ assert %{"id" => ^id_str, "pinned" => false} =
conn
|> assign(:user, user)
|> post("/api/v1/statuses/#{activity.id}/unpin")
@@ -1549,7 +1549,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
id_str_one = Integer.to_string(activity_one.id)
- assert %{"id" => ^id_str_one} =
+ assert %{"id" => ^id_str_one, "pinned" => true} =
conn
|> assign(:user, user)
|> post("/api/v1/statuses/#{id_str_one}/pin")
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index b953ccd76..1076b5002 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -63,6 +63,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
reblogged: false,
favourited: false,
muted: false,
+ pinned: false,
sensitive: false,
spoiler_text: note.data["object"]["summary"],
visibility: "public",
--
cgit v1.2.3
From db6f4496ebb5dbcb680104b2df80410b9dcb8407 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 8 Jan 2019 15:32:06 +0700
Subject: fix test
---
test/web/common_api/common_api_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 652b53099..24e5e56f4 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -118,7 +118,7 @@ defmodule Pleroma.Web.CommonAPI.Test do
user = User.get_by_ap_id(user.ap_id)
- assert {:error, "You have already pinned the maximum number of toots"} =
+ assert {:error, "You have already pinned the maximum number of statuses"} =
CommonAPI.pin(activity_two.id, user)
end
--
cgit v1.2.3
From 0fae04c4e3961baf1f31ae664e5a7fa5de19158e Mon Sep 17 00:00:00 2001
From: lain
Date: Tue, 8 Jan 2019 09:55:33 +0100
Subject: Add a setting for users to autofollow on sign up.
---
test/user_test.exs | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 74accb7c8..f8ef2b1dc 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -142,6 +142,23 @@ defmodule Pleroma.UserTest do
email: "email@example.com"
}
+ test "it autofollows accounts that are set for it" do
+ user = insert(:user)
+ remote_user = insert(:user, %{local: false})
+
+ Pleroma.Config.put([:instance, :autofollowed_nicknames], [
+ user.nickname,
+ remote_user.nickname
+ ])
+
+ cng = User.register_changeset(%User{}, @full_user_data)
+
+ {:ok, registered_user} = User.register(cng)
+
+ assert User.following?(registered_user, user)
+ refute User.following?(registered_user, remote_user)
+ end
+
test "it requires an email, name, nickname and password, bio is optional" do
@full_user_data
|> Map.keys()
--
cgit v1.2.3
From 7b6c5f0a9d02785bee3e4c2585fea1f8983e61b0 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 8 Jan 2019 16:01:35 +0700
Subject: improve test readability
---
test/web/activity_pub/activity_pub_test.exs | 6 +++---
test/web/common_api/common_api_test.exs | 2 +-
test/web/mastodon_api/mastodon_api_controller_test.exs | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 325ef6636..e6c998876 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -610,14 +610,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
{:ok, activity_three} = CommonAPI.post(user, %{"status" => "HI!!!"})
CommonAPI.pin(activity_one.id, user)
+ user = refresh_record(user)
- user = User.get_by_ap_id(user.ap_id)
CommonAPI.pin(activity_two.id, user)
+ user = refresh_record(user)
- user = User.get_by_ap_id(user.ap_id)
CommonAPI.pin(activity_three.id, user)
+ user = refresh_record(user)
- user = User.get_by_ap_id(user.ap_id)
activities = ActivityPub.fetch_user_activities(user, nil, %{"pinned" => "true"})
assert 3 = length(activities)
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 24e5e56f4..7d5ceb398 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -116,7 +116,7 @@ defmodule Pleroma.Web.CommonAPI.Test do
assert {:ok, ^activity_one} = CommonAPI.pin(activity_one.id, user)
- user = User.get_by_ap_id(user.ap_id)
+ user = refresh_record(user)
assert {:error, "You have already pinned the maximum number of statuses"} =
CommonAPI.pin(activity_two.id, user)
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 4a8c70b3b..a3c58379e 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1522,7 +1522,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _} = CommonAPI.pin(activity.id, user)
id_str = Integer.to_string(activity.id)
- user = User.get_by_ap_id(user.ap_id)
+ user = refresh_record(user)
assert %{"id" => ^id_str, "pinned" => false} =
conn
@@ -1556,7 +1556,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> Map.get(:resp_body)
|> Jason.decode!()
- user = User.get_by_ap_id(user.ap_id)
+ user = refresh_record(user)
assert %{"error" => "You have already pinned the maximum number of statuses"} =
conn
--
cgit v1.2.3
From 4124c9aa4aae4622f7a939caa84f01ca0760057c Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Wed, 9 Jan 2019 05:02:00 +0000
Subject: tests: user: add regression test for remote_or_auth_active?/1
---
test/user_test.exs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 74accb7c8..419a576dc 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -767,4 +767,18 @@ defmodule Pleroma.UserTest do
|> Map.put(:search_distance, nil)
end
end
+
+ test "remote_or_auth_active?/1 works correctly" do
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+
+ local_user = insert(:user, local: true, info: %{confirmation_pending: true})
+ confirmed_user = insert(:user, local: true, info: %{confirmation_pending: false})
+ remote_user = insert(:user, local: false)
+
+ refute User.remote_or_auth_active?(local_user)
+ assert User.remote_or_auth_active?(confirmed_user)
+ assert User.remote_or_auth_active?(remote_user)
+
+ Pleroma.Config.put([:instance, :account_activation_required], false)
+ end
end
--
cgit v1.2.3
From 74f48beec3bf78cd94cb6db5cbdb937505891eab Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Wed, 9 Jan 2019 06:36:50 +0000
Subject: user: remove entirely redundant remote_or_auth_active?/1.
auth_active?/1 can check remote users and return true directly.
---
test/user_test.exs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 419a576dc..1c4e84914 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -768,16 +768,16 @@ defmodule Pleroma.UserTest do
end
end
- test "remote_or_auth_active?/1 works correctly" do
+ test "auth_active?/1 works correctly" do
Pleroma.Config.put([:instance, :account_activation_required], true)
local_user = insert(:user, local: true, info: %{confirmation_pending: true})
confirmed_user = insert(:user, local: true, info: %{confirmation_pending: false})
remote_user = insert(:user, local: false)
- refute User.remote_or_auth_active?(local_user)
- assert User.remote_or_auth_active?(confirmed_user)
- assert User.remote_or_auth_active?(remote_user)
+ refute User.auth_active?(local_user)
+ assert User.auth_active?(confirmed_user)
+ assert User.auth_active?(remote_user)
Pleroma.Config.put([:instance, :account_activation_required], false)
end
--
cgit v1.2.3
From f2a4f89abef810f1106afa3a9ef82fa748bc783e Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Wed, 9 Jan 2019 06:50:31 +0000
Subject: tests: user: add tests for superuser?/1
---
test/user_test.exs | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 1c4e84914..582374fb9 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -781,4 +781,32 @@ defmodule Pleroma.UserTest do
Pleroma.Config.put([:instance, :account_activation_required], false)
end
+
+ describe "superuser?/1" do
+ test "returns false for unprivileged users" do
+ user = insert(:user, local: true)
+
+ refute User.superuser?(user)
+ end
+
+ test "returns false for remote users" do
+ user = insert(:user, local: false)
+ remote_admin_user = insert(:user, local: false, info: %{is_admin: true})
+
+ refute User.superuser?(user)
+ refute User.superuser?(remote_admin_user)
+ end
+
+ test "returns true for local moderators" do
+ user = insert(:user, local: true, info: %{is_moderator: true})
+
+ assert User.superuser?(user)
+ end
+
+ test "returns true for local admins" do
+ user = insert(:user, local: true, info: %{is_admin: true})
+
+ assert User.superuser?(user)
+ end
+ end
end
--
cgit v1.2.3
From 567651fb3fcacbe5bb2f9c19deb9655edaaad076 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Wed, 9 Jan 2019 07:03:32 +0000
Subject: test: user: add tests for visible_for?/2
---
test/user_test.exs | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 582374fb9..542eaaaeb 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -809,4 +809,41 @@ defmodule Pleroma.UserTest do
assert User.superuser?(user)
end
end
+
+ describe "visible_for?/2" do
+ test "returns true when the account is itself" do
+ user = insert(:user, local: true)
+
+ assert User.visible_for?(user, user)
+ end
+
+ test "returns false when the account is unauthenticated and auth is required" do
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+
+ user = insert(:user, local: true, info: %{confirmation_pending: true})
+ other_user = insert(:user, local: true)
+
+ refute User.visible_for?(user, other_user)
+
+ Pleroma.Config.put([:instance, :account_activation_required], false)
+ end
+
+ test "returns true when the account is unauthenticated and auth is not required" do
+ user = insert(:user, local: true, info: %{confirmation_pending: true})
+ other_user = insert(:user, local: true)
+
+ assert User.visible_for?(user, other_user)
+ end
+
+ test "returns true when the account is unauthenticated and being viewed by a privileged account (auth required)" do
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+
+ user = insert(:user, local: true, info: %{confirmation_pending: true})
+ other_user = insert(:user, local: true, info: %{is_admin: true})
+
+ assert User.visible_for?(user, other_user)
+
+ Pleroma.Config.put([:instance, :account_activation_required], false)
+ end
+ end
end
--
cgit v1.2.3
From 20c0dd1e24b128e0be51197ac2d150052817c219 Mon Sep 17 00:00:00 2001
From: sxsdv1
Date: Tue, 8 Jan 2019 23:22:15 +0100
Subject: Support activity+json request for activity
---
.../activity_pub/activity_pub_controller_test.exs | 26 ++++++++++++++++++++++
1 file changed, 26 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 7d1fe184e..7aed8c71d 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -89,6 +89,32 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
end
+ describe "/activities/:uuid" do
+ test "it returns a json representation of the activity", %{conn: conn} do
+ activity = insert(:note_activity)
+ uuid = String.split(activity.data["id"], "/") |> List.last()
+
+ conn =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/activities/#{uuid}")
+
+ assert json_response(conn, 200) == ObjectView.render("object.json", %{object: activity})
+ end
+
+ test "it returns 404 for non-public activities", %{conn: conn} do
+ activity = insert(:direct_note_activity)
+ uuid = String.split(activity.data["id"], "/") |> List.last()
+
+ conn =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/activities/#{uuid}")
+
+ assert json_response(conn, 404)
+ end
+ end
+
describe "/inbox" do
test "it inserts an incoming activity into the database", %{conn: conn} do
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
--
cgit v1.2.3
From 26938d65fd5d59e6f50150f4e2bc924429d7733e Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 9 Jan 2019 11:35:23 +0100
Subject: Add User mass following function.
---
test/user_test.exs | 11 +++++++++++
1 file changed, 11 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 541252539..cfccce8d1 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -48,6 +48,17 @@ defmodule Pleroma.UserTest do
assert expected_followers_collection == User.ap_followers(user)
end
+ test "follow_all follows mutliple users" do
+ user = insert(:user)
+ followed_one = insert(:user)
+ followed_two = insert(:user)
+
+ {:ok, user} = User.follow_all(user, [followed_one, followed_two])
+
+ assert User.following?(user, followed_one)
+ assert User.following?(user, followed_two)
+ end
+
test "follow takes a user and another user" do
user = insert(:user)
followed = insert(:user)
--
cgit v1.2.3
From 1b06e6fdf3d879422d6cb0fe57cfcef223b54196 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 9 Jan 2019 17:40:15 +0700
Subject: only non-reblogs, self-authored, public statuses can be pinned
---
test/web/common_api/common_api_test.exs | 10 ++++++++++
1 file changed, 10 insertions(+)
(limited to 'test')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 7d5ceb398..84b264439 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -107,6 +107,16 @@ defmodule Pleroma.Web.CommonAPI.Test do
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
end
+ test "only self-authored can be pinned" do
+ Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
+ user_one = insert(:user)
+ user_two = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user_one, %{"status" => "HI!!!"})
+
+ assert {:error, "Could not pin"} = CommonAPI.pin(activity.id, user_two)
+ end
+
test "max pinned statuses" do
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
user = insert(:user)
--
cgit v1.2.3
From 44a1e6948488d9a96ed684f0a7855fe2fce02ed4 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 9 Jan 2019 19:54:19 +0700
Subject: Add Twitter API for the pinned statuses
```
# Only return statuses that have been pinned
GET /api/statuses/user_timeline.json?pinned=true
# Pin
POST /api/statuses/pin/:id
# Unpin
POST /api/statuses/unpin/:id
```
---
.../representers/activity_representer_test.exs | 3 +-
.../twitter_api/twitter_api_controller_test.exs | 77 +++++++++++++++++++++-
test/web/twitter_api/views/activity_view_test.exs | 3 +-
3 files changed, 80 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index 2ac32aeb2..a4f97e0f2 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
@@ -157,6 +157,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
"repeat_num" => 3,
"favorited" => false,
"repeated" => false,
+ "pinned" => false,
"external_url" => "some url",
"tags" => ["nsfw", "content", "mentioning"],
"activity_type" => "post",
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index c41f615ac..7d4c92c66 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.TwitterAPI.ControllerTest do
@@ -1694,4 +1694,79 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert object.data["name"] == description
end
end
+
+ describe "POST /api/statuses/user_timeline.json?user_id=:user_id&pinned=true" do
+ test "it returns a list of pinned statuses", %{conn: conn} do
+ Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
+
+ user = insert(:user, %{name: "egor"})
+ {:ok, %{id: activity_id}} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, _} = CommonAPI.pin(activity_id, user)
+
+ resp =
+ conn
+ |> get("/api/statuses/user_timeline.json", %{user_id: user.id, pinned: true})
+ |> json_response(200)
+
+ assert length(resp) == 1
+ assert [%{"id" => ^activity_id, "pinned" => true}] = resp
+ end
+ end
+
+ describe "POST /api/statuses/pin/:id" do
+ setup do
+ Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
+ [user: insert(:user)]
+ end
+
+ test "without valid credentials", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ conn = post(conn, "/api/statuses/pin/#{note_activity.id}.json")
+ assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
+ end
+
+ test "with credentials", %{conn: conn, user: user} do
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "test!"})
+
+ request_path = "/api/statuses/pin/#{activity.id}.json"
+
+ response =
+ conn
+ |> with_credentials(user.nickname, "test")
+ |> post(request_path)
+
+ user = refresh_record(user)
+
+ assert json_response(response, 200) == ActivityRepresenter.to_map(activity, %{user: user})
+ end
+ end
+
+ describe "POST /api/statuses/unpin/:id" do
+ setup do
+ Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
+ [user: insert(:user)]
+ end
+
+ test "without valid credentials", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ conn = post(conn, "/api/statuses/unpin/#{note_activity.id}.json")
+ assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
+ end
+
+ test "with credentials", %{conn: conn, user: user} do
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "test!"})
+ {:ok, activity} = CommonAPI.pin(activity.id, user)
+
+ request_path = "/api/statuses/unpin/#{activity.id}.json"
+
+ response =
+ conn
+ |> with_credentials(user.nickname, "test")
+ |> post(request_path)
+
+ user = refresh_record(user)
+
+ assert json_response(response, 200) == ActivityRepresenter.to_map(activity, %{user: user})
+ end
+ end
end
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index bd4878e98..374440300 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
@@ -132,6 +132,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"possibly_sensitive" => false,
"repeat_num" => 0,
"repeated" => false,
+ "pinned" => false,
"statusnet_conversation_id" => convo_id,
"summary" => "",
"statusnet_html" =>
--
cgit v1.2.3
From 6cbe63726d298ae85a75efa7591a54394469525e Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 9 Jan 2019 19:54:37 +0700
Subject: improve tests
---
test/web/common_api/common_api_test.exs | 32 +++++-------
.../mastodon_api/mastodon_api_controller_test.exs | 59 ++++++++--------------
2 files changed, 34 insertions(+), 57 deletions(-)
(limited to 'test')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 84b264439..eb69ea4b2 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.CommonAPI.Test do
@@ -98,30 +98,26 @@ defmodule Pleroma.Web.CommonAPI.Test do
end
describe "pinned statuses" do
- test "pin status" do
+ setup do
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
- user = insert(:user)
+ user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
- assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
+ [user: user, activity: activity]
end
- test "only self-authored can be pinned" do
- Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
- user_one = insert(:user)
- user_two = insert(:user)
-
- {:ok, activity} = CommonAPI.post(user_one, %{"status" => "HI!!!"})
-
- assert {:error, "Could not pin"} = CommonAPI.pin(activity.id, user_two)
+ test "pin status", %{user: user, activity: activity} do
+ assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
end
- test "max pinned statuses" do
- Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
+ test "only self-authored can be pinned", %{activity: activity} do
user = insert(:user)
- {:ok, activity_one} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ assert {:error, "Could not pin"} = CommonAPI.pin(activity.id, user)
+ end
+
+ test "max pinned statuses", %{user: user, activity: activity_one} do
{:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
assert {:ok, ^activity_one} = CommonAPI.pin(activity_one.id, user)
@@ -132,11 +128,7 @@ defmodule Pleroma.Web.CommonAPI.Test do
CommonAPI.pin(activity_two.id, user)
end
- test "unpin status" do
- Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
- user = insert(:user)
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ test "unpin status", %{user: user, activity: activity} do
{:ok, activity} = CommonAPI.pin(activity.id, user)
assert {:ok, ^activity} = CommonAPI.unpin(activity.id, user)
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index a3c58379e..b448d13f5 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
@@ -1473,88 +1473,74 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
describe "pinned statuses" do
- test "returns pinned statuses", %{conn: conn} do
+ setup do
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
- user = insert(:user)
+ user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
+
+ [user: user, activity: activity]
+ end
+
+ test "returns pinned statuses", %{conn: conn, user: user, activity: activity} do
{:ok, _} = CommonAPI.pin(activity.id, user)
result =
conn
|> assign(:user, user)
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
- |> Map.get(:resp_body)
- |> Jason.decode!()
+ |> json_response(200)
- id_str = Integer.to_string(activity.id)
+ id_str = to_string(activity.id)
assert [%{"id" => ^id_str, "pinned" => true}] = result
end
- test "pin status", %{conn: conn} do
- Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
- user = insert(:user)
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
- id_str = Integer.to_string(activity.id)
+ test "pin status", %{conn: conn, user: user, activity: activity} do
+ id_str = to_string(activity.id)
assert %{"id" => ^id_str, "pinned" => true} =
conn
|> assign(:user, user)
|> post("/api/v1/statuses/#{activity.id}/pin")
- |> Map.get(:resp_body)
- |> Jason.decode!()
+ |> json_response(200)
assert [%{"id" => ^id_str, "pinned" => true}] =
conn
|> assign(:user, user)
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
- |> Map.get(:resp_body)
- |> Jason.decode!()
+ |> json_response(200)
end
- test "unpin status", %{conn: conn} do
- Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
- user = insert(:user)
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ test "unpin status", %{conn: conn, user: user, activity: activity} do
{:ok, _} = CommonAPI.pin(activity.id, user)
- id_str = Integer.to_string(activity.id)
+ id_str = to_string(activity.id)
user = refresh_record(user)
assert %{"id" => ^id_str, "pinned" => false} =
conn
|> assign(:user, user)
|> post("/api/v1/statuses/#{activity.id}/unpin")
- |> Map.get(:resp_body)
- |> Jason.decode!()
+ |> json_response(200)
assert [] =
conn
|> assign(:user, user)
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
- |> Map.get(:resp_body)
- |> Jason.decode!()
+ |> json_response(200)
end
- test "max pinned statuses", %{conn: conn} do
- Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
-
- user = insert(:user)
-
- {:ok, activity_one} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ test "max pinned statuses", %{conn: conn, user: user, activity: activity_one} do
{:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
- id_str_one = Integer.to_string(activity_one.id)
+ id_str_one = to_string(activity_one.id)
assert %{"id" => ^id_str_one, "pinned" => true} =
conn
|> assign(:user, user)
|> post("/api/v1/statuses/#{id_str_one}/pin")
- |> Map.get(:resp_body)
- |> Jason.decode!()
+ |> json_response(200)
user = refresh_record(user)
@@ -1562,8 +1548,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
conn
|> assign(:user, user)
|> post("/api/v1/statuses/#{activity_two.id}/pin")
- |> Map.get(:resp_body)
- |> Jason.decode!()
+ |> json_response(400)
end
end
end
--
cgit v1.2.3
From 5027f82cdef52391e408428ecc8013b1c4847b6b Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 9 Jan 2019 16:45:09 +0100
Subject: Add activity visibility index.
---
test/web/activity_pub/activity_pub_test.exs | 36 +++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 2453998ad..47aa5a56f 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -18,6 +18,42 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
:ok
end
+ describe "fetching restricted by visibility" do
+ test "it restricts by the appropriate visibility" do
+ user = insert(:user)
+
+ {:ok, public_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "public"})
+
+ {:ok, direct_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+
+ {:ok, unlisted_activity} =
+ CommonAPI.post(user, %{"status" => ".", "visibility" => "unlisted"})
+
+ {:ok, private_activity} =
+ CommonAPI.post(user, %{"status" => ".", "visibility" => "private"})
+
+ activities =
+ ActivityPub.fetch_activities([], %{:visibility => "direct", "actor_id" => user.ap_id})
+
+ assert activities == [direct_activity]
+
+ activities =
+ ActivityPub.fetch_activities([], %{:visibility => "unlisted", "actor_id" => user.ap_id})
+
+ assert activities == [unlisted_activity]
+
+ activities =
+ ActivityPub.fetch_activities([], %{:visibility => "private", "actor_id" => user.ap_id})
+
+ assert activities == [private_activity]
+
+ activities =
+ ActivityPub.fetch_activities([], %{:visibility => "public", "actor_id" => user.ap_id})
+
+ assert activities == [public_activity]
+ end
+ end
+
describe "building a user from his ap id" do
test "it returns a user" do
user_id = "http://mastodon.example.org/users/admin"
--
cgit v1.2.3
From 8df348a3daaa9c5ac9693fd52b62594dfe9158be Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 9 Jan 2019 17:18:37 +0100
Subject: Add test for summary_html
---
.../twitter_api/representers/activity_representer_test.exs | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index ab3e04985..d71aaacfe 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -107,7 +107,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
"published" => date,
"type" => "Note",
"content" => content_html,
- "summary" => "2hu",
+ "summary" => "2hu :2hu:",
"inReplyToStatusId" => 213_123,
"attachment" => [
object
@@ -129,7 +129,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
}
expected_html =
- "2hu
alert('YAY')Some content mentioning 2hu
alert('YAY')Some content mentioning @shp "
@@ -138,7 +138,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
"user" => UserView.render("show.json", %{user: user, for: follower}),
"is_local" => false,
"statusnet_html" => expected_html,
- "text" => "2hu" <> content,
+ "text" => "2hu :2hu:" <> content,
"is_post_verb" => true,
"created_at" => "Tue May 24 13:26:08 +0000 2016",
"in_reply_to_status_id" => 213_123,
@@ -163,8 +163,9 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
"possibly_sensitive" => true,
"uri" => activity.data["object"]["id"],
"visibility" => "direct",
- "summary" => "2hu",
- "summary_html" => "2hu"
+ "summary" => "2hu :2hu:",
+ "summary_html" =>
+ "2hu "
}
assert ActivityRepresenter.to_map(activity, %{
--
cgit v1.2.3
From 7ac152ed38267bde3e318fab82db7d7d610cdbbb Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 9 Jan 2019 18:14:32 +0100
Subject: TwitterAPI: Add follower/following pagination.
---
.../twitter_api/twitter_api_controller_test.exs | 51 ++++++++++++++++++++++
1 file changed, 51 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index c41f615ac..3d355a087 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1082,6 +1082,31 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert Enum.sort(expected) == Enum.sort(result)
end
+ test "it returns 20 followers per page", %{conn: conn} do
+ user = insert(:user)
+ followers = insert_list(21, :user)
+
+ Enum.each(followers, fn follower ->
+ User.follow(follower, user)
+ end)
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/statuses/followers")
+
+ result = json_response(res_conn, 200)
+ assert length(result) == 20
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/statuses/followers", %{page: 2})
+
+ result = json_response(res_conn, 200)
+ assert length(result) == 1
+ end
+
test "it returns a given user's followers with user_id", %{conn: conn} do
user = insert(:user)
follower_one = insert(:user)
@@ -1183,6 +1208,32 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert Enum.sort(expected) == Enum.sort(result)
end
+ test "it returns 20 friends per page", %{conn: conn} do
+ user = insert(:user)
+ followeds = insert_list(21, :user)
+
+ {:ok, user} =
+ Enum.reduce(followeds, {:ok, user}, fn followed, {:ok, user} ->
+ User.follow(user, followed)
+ end)
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/statuses/friends")
+
+ result = json_response(res_conn, 200)
+ assert length(result) == 20
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/statuses/friends", %{page: 2})
+
+ result = json_response(res_conn, 200)
+ assert length(result) == 1
+ end
+
test "it returns a given user's friends with user_id", %{conn: conn} do
user = insert(:user)
followed_one = insert(:user)
--
cgit v1.2.3
From a99e156f2c0e3d2e5b5dec167efb29be1e429542 Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 9 Jan 2019 18:17:23 +0100
Subject: Add integer casts.
---
test/web/twitter_api/twitter_api_controller_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 3d355a087..1eddffec3 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1101,7 +1101,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
res_conn =
conn
|> assign(:user, user)
- |> get("/api/statuses/followers", %{page: 2})
+ |> get("/api/statuses/followers?page=2")
result = json_response(res_conn, 200)
assert length(result) == 1
--
cgit v1.2.3
From 490c80bc9651f93b61dfe4ae531bc0072a35d044 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Thu, 10 Jan 2019 03:46:34 +0000
Subject: test: common api: add tests for format_input/4
---
test/web/common_api/common_api_utils_test.exs | 50 +++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
(limited to 'test')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index fc89e3116..754bc7255 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -56,4 +56,54 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert expected == Utils.emoji_from_profile(user)
end
+
+ describe "format_input/4" do
+ test "works for bare text/plain" do
+ text = "hello world!"
+ expected = "hello world!"
+
+ output = Utils.format_input(text, [], [], "text/plain")
+
+ assert output == expected
+
+ text = "hello world!\n\nsecond paragraph!"
+ expected = "hello world! second paragraph!"
+
+ output = Utils.format_input(text, [], [], "text/plain")
+
+ assert output == expected
+ end
+
+ test "works for bare text/html" do
+ text = "hello world!
"
+ expected = "hello world!
"
+
+ output = Utils.format_input(text, [], [], "text/html")
+
+ assert output == expected
+
+ text = "hello world!
\n\nsecond paragraph
"
+ expected = "hello world!
\n\nsecond paragraph
"
+
+ output = Utils.format_input(text, [], [], "text/html")
+
+ assert output == expected
+ end
+
+ test "works for bare text/markdown" do
+ text = "**hello world**"
+ expected = "hello world
\n"
+
+ output = Utils.format_input(text, [], [], "text/markdown")
+
+ assert output == expected
+
+ text = "**hello world**\n\n*another paragraph*"
+ expected = "hello world
\nanother paragraph
\n"
+
+ output = Utils.format_input(text, [], [], "text/markdown")
+
+ assert output == expected
+ end
+ end
end
--
cgit v1.2.3
From 1f851a07232e510e82e7b13400dfcb31cca555bb Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Thu, 10 Jan 2019 18:09:56 +0000
Subject: Add Twitter Card parser
---
test/fixtures/rich_media/twitter_card.html | 5 +++++
test/web/rich_media/parser_test.exs | 18 ++++++++++++++++++
2 files changed, 23 insertions(+)
create mode 100644 test/fixtures/rich_media/twitter_card.html
(limited to 'test')
diff --git a/test/fixtures/rich_media/twitter_card.html b/test/fixtures/rich_media/twitter_card.html
new file mode 100644
index 000000000..34c7c6ccd
--- /dev/null
+++ b/test/fixtures/rich_media/twitter_card.html
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/test/web/rich_media/parser_test.exs b/test/web/rich_media/parser_test.exs
index caf81e9fa..ff3486a6d 100644
--- a/test/web/rich_media/parser_test.exs
+++ b/test/web/rich_media/parser_test.exs
@@ -9,6 +9,12 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
} ->
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}
+ %{
+ method: :get,
+ url: "http://example.com/twitter-card"
+ } ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/twitter_card.html")}
+
%{method: :get, url: "http://example.com/empty"} ->
%Tesla.Env{status: 200, body: "hello"}
end)
@@ -30,4 +36,16 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
url: "http://www.imdb.com/title/tt0117500/"
}}
end
+
+ test "parses twitter card" do
+ assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/twitter-card") ==
+ {:ok,
+ %{
+ card: "summary",
+ site: "@flickr",
+ image: "https://farm6.staticflickr.com/5510/14338202952_93595258ff_z.jpg",
+ title: "Small Island Developing States Photo Submission",
+ description: "View the album on Flickr."
+ }}
+ end
end
--
cgit v1.2.3
From b594a54d0caf0f91dd9188157cb34e01ee9ea794 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Fri, 11 Jan 2019 12:31:31 +0700
Subject: unpin when deleting a status
---
test/web/common_api/common_api_test.exs | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
(limited to 'test')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index eb69ea4b2..a3aff5897 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -109,6 +109,11 @@ defmodule Pleroma.Web.CommonAPI.Test do
test "pin status", %{user: user, activity: activity} do
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
+
+ id = activity.id
+ user = refresh_record(user)
+
+ assert %User{info: %{pinned_activities: [^id]}} = user
end
test "only self-authored can be pinned", %{activity: activity} do
@@ -131,7 +136,25 @@ defmodule Pleroma.Web.CommonAPI.Test do
test "unpin status", %{user: user, activity: activity} do
{:ok, activity} = CommonAPI.pin(activity.id, user)
+ user = refresh_record(user)
+
assert {:ok, ^activity} = CommonAPI.unpin(activity.id, user)
+
+ user = refresh_record(user)
+
+ assert %User{info: %{pinned_activities: []}} = user
+ end
+
+ test "should unpin status when deleting a status", %{user: user, activity: activity} do
+ {:ok, activity} = CommonAPI.pin(activity.id, user)
+
+ user = refresh_record(user)
+
+ assert {:ok, _} = CommonAPI.delete(activity.id, user)
+
+ user = refresh_record(user)
+
+ assert %User{info: %{pinned_activities: []}} = user
end
end
end
--
cgit v1.2.3
From 728587fdaabbf8db8ee0d3626ab706044f0249f7 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Fri, 11 Jan 2019 12:47:44 +0700
Subject: typo
---
test/web/common_api/common_api_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index a3aff5897..9ac805f24 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -145,7 +145,7 @@ defmodule Pleroma.Web.CommonAPI.Test do
assert %User{info: %{pinned_activities: []}} = user
end
- test "should unpin status when deleting a status", %{user: user, activity: activity} do
+ test "should unpin when deleting a status", %{user: user, activity: activity} do
{:ok, activity} = CommonAPI.pin(activity.id, user)
user = refresh_record(user)
--
cgit v1.2.3
From 1eb7318831e7239ec929457f6298fb05cb461b43 Mon Sep 17 00:00:00 2001
From: sxsdv1
Date: Sat, 12 Jan 2019 17:52:30 +0100
Subject: Prepare all types objects before serialising
Activities returned from inbox can include other types of objects like
Article
---
test/support/factory.ex | 25 +++++++++++++++++++++++++
test/web/activity_pub/transmogrifier_test.exs | 15 +++++++++++++++
2 files changed, 40 insertions(+)
(limited to 'test')
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 57fa4a79d..4ac77981a 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -57,6 +57,11 @@ defmodule Pleroma.Factory do
%Pleroma.Object{data: Map.merge(data, %{"to" => [user2.ap_id]})}
end
+ def article_factory do
+ note_factory()
+ |> Map.put("type", "Article")
+ end
+
def tombstone_factory do
data = %{
"type" => "Tombstone",
@@ -110,6 +115,26 @@ defmodule Pleroma.Factory do
}
end
+ def article_activity_factory do
+ article = insert(:article)
+
+ data = %{
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
+ "type" => "Create",
+ "actor" => article.data["actor"],
+ "to" => article.data["to"],
+ "object" => article.data,
+ "published" => DateTime.utc_now() |> DateTime.to_iso8601(),
+ "context" => article.data["context"]
+ }
+
+ %Pleroma.Activity{
+ data: data,
+ actor: data["actor"],
+ recipients: data["to"]
+ }
+ end
+
def announce_activity_factory do
note_activity = insert(:note_activity)
user = insert(:user)
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index a5fd87ed4..65c8ec36d 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -835,6 +835,21 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert is_nil(modified["object"]["announcement_count"])
assert is_nil(modified["object"]["context_id"])
end
+
+ test "it strips internal fields of article" do
+ activity = insert(:article_activity)
+
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
+
+ assert length(modified["object"]["tag"]) == 2
+
+ assert is_nil(modified["object"]["emoji"])
+ assert is_nil(modified["object"]["likes"])
+ assert is_nil(modified["object"]["like_count"])
+ assert is_nil(modified["object"]["announcements"])
+ assert is_nil(modified["object"]["announcement_count"])
+ assert is_nil(modified["object"]["context_id"])
+ end
end
describe "user upgrade" do
--
cgit v1.2.3
From 36711e1c83bb24a2b104c4a8f384c475c1583638 Mon Sep 17 00:00:00 2001
From: sxsdv1
Date: Tue, 8 Jan 2019 19:22:26 +0100
Subject: Handle client submitted activitypub like activity
---
.../activity_pub/activity_pub_controller_test.exs | 25 ++++++++++++++++++++++
1 file changed, 25 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 7aed8c71d..82ad42144 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -292,6 +292,31 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 400)
end
+
+ test "it increases like count when receiving a like action", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+
+ data = %{
+ type: "Like",
+ object: %{
+ id: note_activity.data["object"]["id"]
+ }
+ }
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> put_req_header("content-type", "application/activity+json")
+ |> post("/users/#{user.nickname}/outbox", data)
+
+ result = json_response(conn, 201)
+ assert Activity.get_by_ap_id(result["id"])
+
+ object = Object.get_by_ap_id(note_activity.data["object"]["id"])
+ assert object
+ assert object.data["like_count"] == 1
+ end
end
describe "/users/:nickname/followers" do
--
cgit v1.2.3
From 581edd5a91189e6fb2a94a277b96f9c8197617b8 Mon Sep 17 00:00:00 2001
From: sxsdv1
Date: Fri, 11 Jan 2019 23:34:32 +0100
Subject: Add route to get object like activities
---
test/web/activity_pub/activity_pub_controller_test.exs | 15 +++++++++++++++
1 file changed, 15 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 82ad42144..52e67f046 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -89,6 +89,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
end
+ describe "/object/:uuid/likes" do
+ test "it returns the like activities in a collection", %{conn: conn} do
+ like = insert(:like_activity)
+ uuid = String.split(like.data["object"], "/") |> List.last()
+
+ result =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/objects/#{uuid}/likes")
+ |> json_response(200)
+
+ assert List.first(result["first"]["orderedItems"])["id"] == like.data["id"]
+ end
+ end
+
describe "/activities/:uuid" do
test "it returns a json representation of the activity", %{conn: conn} do
activity = insert(:note_activity)
--
cgit v1.2.3
From 868034375c5122175f872967e49559dafed9403c Mon Sep 17 00:00:00 2001
From: sxsdv1
Date: Wed, 9 Jan 2019 09:22:00 +0100
Subject: Add likes to activitypub object representation
Top level of the likes OrderedCollection is inlined to get immediate
access to totalItems. Because the count can be returned without scanning
the database for like activities the extra query is saved when the
client only wants to display the total.
---
test/web/activity_pub/transmogrifier_test.exs | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 65c8ec36d..87d0ab559 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -829,7 +829,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert length(modified["object"]["tag"]) == 2
assert is_nil(modified["object"]["emoji"])
- assert is_nil(modified["object"]["likes"])
assert is_nil(modified["object"]["like_count"])
assert is_nil(modified["object"]["announcements"])
assert is_nil(modified["object"]["announcement_count"])
@@ -844,12 +843,19 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert length(modified["object"]["tag"]) == 2
assert is_nil(modified["object"]["emoji"])
- assert is_nil(modified["object"]["likes"])
assert is_nil(modified["object"]["like_count"])
assert is_nil(modified["object"]["announcements"])
assert is_nil(modified["object"]["announcement_count"])
assert is_nil(modified["object"]["context_id"])
end
+
+ test "it adds like collection to object" do
+ activity = insert(:note_activity)
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
+
+ assert modified["object"]["likes"]["type"] == "OrderedCollection"
+ assert modified["object"]["likes"]["totalItems"] == 0
+ end
end
describe "user upgrade" do
--
cgit v1.2.3
From b8a77c5d704a4a76f227854c1cab560eb98a7382 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Sun, 13 Jan 2019 02:06:50 +0200
Subject: Add OEmbed parser
---
test/fixtures/rich_media/oembed.html | 3 +++
test/fixtures/rich_media/oembed.json | 1 +
test/web/rich_media/parser_test.exs | 41 ++++++++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+)
create mode 100644 test/fixtures/rich_media/oembed.html
create mode 100644 test/fixtures/rich_media/oembed.json
(limited to 'test')
diff --git a/test/fixtures/rich_media/oembed.html b/test/fixtures/rich_media/oembed.html
new file mode 100644
index 000000000..55f17004b
--- /dev/null
+++ b/test/fixtures/rich_media/oembed.html
@@ -0,0 +1,3 @@
+
diff --git a/test/fixtures/rich_media/oembed.json b/test/fixtures/rich_media/oembed.json
new file mode 100644
index 000000000..2a5f7a771
--- /dev/null
+++ b/test/fixtures/rich_media/oembed.json
@@ -0,0 +1 @@
+{"type":"photo","flickr_type":"photo","title":"Bacon Lollys","author_name":"\u202e\u202d\u202cbees\u202c","author_url":"https:\/\/www.flickr.com\/photos\/bees\/","width":"1024","height":"768","url":"https:\/\/farm4.staticflickr.com\/3040\/2362225867_4a87ab8baf_b.jpg","web_page":"https:\/\/www.flickr.com\/photos\/bees\/2362225867\/","thumbnail_url":"https:\/\/farm4.staticflickr.com\/3040\/2362225867_4a87ab8baf_q.jpg","thumbnail_width":150,"thumbnail_height":150,"web_page_short_url":"https:\/\/flic.kr\/p\/4AK2sc","license":"All Rights Reserved","license_id":0,"html":" <\/a>",
+ "license" => "All Rights Reserved",
+ "license_id" => 0,
+ "provider_name" => "Flickr",
+ "provider_url" => "https://www.flickr.com/",
+ "thumbnail_height" => 150,
+ "thumbnail_url" =>
+ "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_q.jpg",
+ "thumbnail_width" => 150,
+ "title" => "Bacon Lollys",
+ "type" => "photo",
+ "url" => "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_b.jpg",
+ "version" => "1.0",
+ "web_page" => "https://www.flickr.com/photos/bees/2362225867/",
+ "web_page_short_url" => "https://flic.kr/p/4AK2sc",
+ "width" => "1024"
+ }}
+ end
end
--
cgit v1.2.3
From 98d9ae071877cb3e6cd65d84bfc142e9cbb998b0 Mon Sep 17 00:00:00 2001
From: Sadposter
Date: Sun, 13 Jan 2019 15:17:47 +0000
Subject: Add test for mastodon API /favourites endpoint
---
.../mastodon_api/mastodon_api_controller_test.exs | 33 ++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index b448d13f5..fe8f845c7 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1349,13 +1349,42 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _, _} = CommonAPI.favorite(activity.id, user)
- conn =
+ first_conn =
conn
|> assign(:user, user)
|> get("/api/v1/favourites")
- assert [status] = json_response(conn, 200)
+ assert [status] = json_response(first_conn, 200)
assert status["id"] == to_string(activity.id)
+
+ assert [{"link", link_header}] =
+ Enum.filter(first_conn.resp_headers, fn element -> match?({"link", _}, element) end)
+
+ # Honours query params
+ {:ok, second_activity} =
+ CommonAPI.post(other_user, %{
+ "status" =>
+ "Trees Are Never Sad Look At Them Every Once In Awhile They're Quite Beautiful."
+ })
+
+ {:ok, _, _} = CommonAPI.favorite(second_activity.id, user)
+
+ last_like = status["id"]
+
+ second_conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/favourites?since_id=#{last_like}")
+
+ assert [second_status] = json_response(second_conn, 200)
+ assert second_status["id"] == to_string(second_activity.id)
+
+ third_conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/favourites?limit=0")
+
+ assert [] = json_response(third_conn, 200)
end
describe "updating credentials" do
--
cgit v1.2.3
From dc45ec62c2f5dfcc895854dfbddf6fe9621d3072 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Mon, 14 Jan 2019 20:04:45 +0300
Subject: [#477] User search improvements: tsquery search with field weights,
friends & followers boosting.
---
test/user_test.exs | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index cfccce8d1..efa7937bc 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -781,8 +781,7 @@ defmodule Pleroma.UserTest do
_user_three = insert(:user, %{name: "ebn", nickname: "lain@mastodon.social"})
user_four = insert(:user, %{nickname: "lain@pleroma.soykaf.com"})
- assert user_four ==
- User.search("lain@ple") |> List.first() |> Map.put(:search_distance, nil)
+ assert user_four == User.search("lain@ple") |> List.first() |> Map.put(:search_rank, nil)
end
test "finds a user whose name is nil" do
@@ -792,7 +791,7 @@ defmodule Pleroma.UserTest do
assert user_two ==
User.search("lain@pleroma.soykaf.com")
|> List.first()
- |> Map.put(:search_distance, nil)
+ |> Map.put(:search_rank, nil)
end
end
--
cgit v1.2.3
From dcbe5bd58ccb1068d17ba15703169593d4bbb393 Mon Sep 17 00:00:00 2001
From: Shadowfacts
Date: Mon, 14 Jan 2019 13:29:38 -0500
Subject: Add attachment escaping test
---
test/upload_test.exs | 15 +++++++++++++++
1 file changed, 15 insertions(+)
(limited to 'test')
diff --git a/test/upload_test.exs b/test/upload_test.exs
index d4ea3a573..bda503361 100644
--- a/test/upload_test.exs
+++ b/test/upload_test.exs
@@ -137,5 +137,20 @@ defmodule Pleroma.UploadTest do
refute data["name"] == "an [image.jpg"
end
+
+ test "escapes invalid characters in url" do
+ File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
+
+ file = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image_tmp.jpg"),
+ filename: "an… image.jpg"
+ }
+
+ {:ok, data} = Upload.store(file)
+ [attachment_url | _] = data["url"]
+
+ assert Path.basename(attachment_url["href"]) == "an%E2%80%A6%20image.jpg"
+ end
end
end
--
cgit v1.2.3
From e3eb75bd234c8e21ff937d4f9b2a4a1328007e32 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Tue, 15 Jan 2019 07:40:00 +0100
Subject: Upload: Fix uploading with a ? in the filename
---
test/upload_test.exs | 15 +++++++++++++++
1 file changed, 15 insertions(+)
(limited to 'test')
diff --git a/test/upload_test.exs b/test/upload_test.exs
index bda503361..ffef74270 100644
--- a/test/upload_test.exs
+++ b/test/upload_test.exs
@@ -152,5 +152,20 @@ defmodule Pleroma.UploadTest do
assert Path.basename(attachment_url["href"]) == "an%E2%80%A6%20image.jpg"
end
+
+ test "replaces ? (question-mark) to %3f" do
+ File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
+
+ file = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image_tmp.jpg"),
+ filename: "an?image.jpg"
+ }
+
+ {:ok, data} = Upload.store(file)
+ [attachment_url | _] = data["url"]
+
+ assert Path.basename(attachment_url["href"]) == "an%3Fimage.jpg"
+ end
end
end
--
cgit v1.2.3
From 9fcdca1bdca04bdb52b7ac9a0d69e0886b12cb87 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Tue, 15 Jan 2019 07:57:48 +0100
Subject: Upload: Fix uploading with a : in the filename
---
test/upload_test.exs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/upload_test.exs b/test/upload_test.exs
index ffef74270..b2d9eca38 100644
--- a/test/upload_test.exs
+++ b/test/upload_test.exs
@@ -153,19 +153,19 @@ defmodule Pleroma.UploadTest do
assert Path.basename(attachment_url["href"]) == "an%E2%80%A6%20image.jpg"
end
- test "replaces ? (question-mark) to %3f" do
+ test "replaces : (colon) and ? (question-mark) to %3A and %3F (respectively)" do
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
file = %Plug.Upload{
content_type: "image/jpg",
path: Path.absname("test/fixtures/image_tmp.jpg"),
- filename: "an?image.jpg"
+ filename: "is:an?image.jpg"
}
{:ok, data} = Upload.store(file)
[attachment_url | _] = data["url"]
- assert Path.basename(attachment_url["href"]) == "an%3Fimage.jpg"
+ assert Path.basename(attachment_url["href"]) == "is%3Aan%3Fimage.jpg"
end
end
end
--
cgit v1.2.3
From fc965f982c62c43e11cb42c77f7c371c9835a9f2 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Tue, 15 Jan 2019 12:04:54 +0300
Subject: [#477] Added FTS index for `users`. Fixed failing test.
---
test/web/twitter_api/twitter_api_controller_test.exs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 5f13e7959..a4baf2b5f 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1655,16 +1655,16 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "GET /api/pleroma/search_user" do
test "it returns users, ordered by similarity", %{conn: conn} do
user = insert(:user, %{name: "eal"})
- user_two = insert(:user, %{name: "ean"})
- user_three = insert(:user, %{name: "ebn"})
+ user_two = insert(:user, %{name: "eal me"})
+ _user_three = insert(:user, %{name: "ebn"})
resp =
conn
- |> get(twitter_api_search__path(conn, :search_user), query: "eal")
+ |> get(twitter_api_search__path(conn, :search_user), query: "eal me")
|> json_response(200)
- assert length(resp) == 3
- assert [user.id, user_two.id, user_three.id] == Enum.map(resp, fn %{"id" => id} -> id end)
+ assert length(resp) == 2
+ assert [user_two.id, user.id] == Enum.map(resp, fn %{"id" => id} -> id end)
end
end
--
cgit v1.2.3
From 5b8f9ff8c14b5992e3db7a0c890ca5539e6a0086 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Tue, 15 Jan 2019 13:05:25 +0300
Subject: [#477] User search tests. Normalized search rank in User.search.
---
test/user_test.exs | 62 ++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 56 insertions(+), 6 deletions(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index efa7937bc..48b7b72ec 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -775,13 +775,55 @@ defmodule Pleroma.UserTest do
end
describe "User.search" do
- test "finds a user, ranking by similarity" do
- _user = insert(:user, %{name: "lain"})
- _user_two = insert(:user, %{name: "ean"})
- _user_three = insert(:user, %{name: "ebn", nickname: "lain@mastodon.social"})
- user_four = insert(:user, %{nickname: "lain@pleroma.soykaf.com"})
+ test "finds a user by full or partial nickname" do
+ user = insert(:user, %{nickname: "john"})
- assert user_four == User.search("lain@ple") |> List.first() |> Map.put(:search_rank, nil)
+ Enum.each(["john", "jo", "j"], fn query ->
+ assert user == User.search(query) |> List.first() |> Map.put(:search_rank, nil)
+ end)
+ end
+
+ test "finds a user by full or partial name" do
+ user = insert(:user, %{name: "John Doe"})
+
+ Enum.each(["John Doe", "JOHN", "doe", "j d", "j", "d"], fn query ->
+ assert user == User.search(query) |> List.first() |> Map.put(:search_rank, nil)
+ end)
+ end
+
+ test "finds users, preferring nickname matches over name matches" do
+ u1 = insert(:user, %{name: "lain", nickname: "nick1"})
+ u2 = insert(:user, %{nickname: "lain", name: "nick1"})
+
+ assert [u2.id, u1.id] == Enum.map(User.search("lain"), & &1.id)
+ end
+
+ test "finds users, considering density of matched tokens" do
+ u1 = insert(:user, %{name: "Bar Bar plus Word Word"})
+ u2 = insert(:user, %{name: "Word Word Bar Bar Bar"})
+
+ assert [u2.id, u1.id] == Enum.map(User.search("bar word"), & &1.id)
+ end
+
+ test "finds users, ranking by similarity" do
+ u1 = insert(:user, %{name: "lain"})
+ _u2 = insert(:user, %{name: "ean"})
+ u3 = insert(:user, %{name: "ebn", nickname: "lain@mastodon.social"})
+ u4 = insert(:user, %{nickname: "lain@pleroma.soykaf.com"})
+
+ assert [u4.id, u3.id, u1.id] == Enum.map(User.search("lain@ple"), & &1.id)
+ end
+
+ test "finds users, boosting ranks of friends and followers" do
+ u1 = insert(:user)
+ u2 = insert(:user, %{name: "Doe"})
+ follower = insert(:user, %{name: "Doe"})
+ friend = insert(:user, %{name: "Doe"})
+
+ {:ok, follower} = User.follow(follower, u1)
+ {:ok, u1} = User.follow(u1, friend)
+
+ assert [friend.id, follower.id, u2.id] == Enum.map(User.search("doe", false, u1), & &1.id)
end
test "finds a user whose name is nil" do
@@ -793,6 +835,14 @@ defmodule Pleroma.UserTest do
|> List.first()
|> Map.put(:search_rank, nil)
end
+
+ test "does not yield false-positive matches" do
+ insert(:user, %{name: "John Doe"})
+
+ Enum.each(["mary", "a", ""], fn query ->
+ assert [] == User.search(query)
+ end)
+ end
end
test "auth_active?/1 works correctly" do
--
cgit v1.2.3
From 85a5be6220dd87e2884b5921fc1a6c92ee7cc745 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Wed, 16 Jan 2019 04:09:01 +0000
Subject: tests: fixup
---
test/formatter_test.exs | 16 +++++++++-------
test/web/mastodon_api/mastodon_api_controller_test.exs | 18 +++++++++++-------
test/web/twitter_api/twitter_api_controller_test.exs | 6 +++---
test/web/twitter_api/twitter_api_test.exs | 4 ++--
test/web/twitter_api/views/activity_view_test.exs | 6 ++++--
5 files changed, 29 insertions(+), 21 deletions(-)
(limited to 'test')
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index c76149e38..bd8844458 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -19,7 +19,7 @@ defmodule Pleroma.FormatterTest do
text = "I love #cofe and #2hu"
expected_text =
- "I love #cofe and #2hu "
+ "I love #cofe and #2hu "
tags = Formatter.parse_tags(text)
@@ -31,7 +31,7 @@ defmodule Pleroma.FormatterTest do
text = "Fact #3: pleroma does what mastodon't"
expected_text =
- "Fact #3 : pleroma does what mastodon't"
+ "Fact #3 : pleroma does what mastodon't"
tags = Formatter.parse_tags(text)
@@ -144,11 +144,13 @@ defmodule Pleroma.FormatterTest do
Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
expected_text =
- "@gsimg According to @gsimg According to @archa_eme_ , that is @daggsy. Also hello @archa_eme_ , that is @daggsy. Also hello @archaeme "
+ }' class='u-url mention' href='#{archaeme_remote.ap_id}'>@archaeme "
assert expected_text == Formatter.finalize({subs, text})
end
@@ -166,7 +168,7 @@ defmodule Pleroma.FormatterTest do
Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
expected_text =
- "@mike test"
+ "@mike test"
assert expected_text == Formatter.finalize({subs, text})
end
@@ -183,7 +185,7 @@ defmodule Pleroma.FormatterTest do
Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
expected_text =
- "@o hi"
+ "@o hi"
assert expected_text == Formatter.finalize({subs, text})
end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index fe8f845c7..9e4ecedc5 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -386,7 +386,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> assign(:user, user)
|> get("/api/v1/filters/#{filter.filter_id}")
- assert response = json_response(conn, 200)
+ assert _response = json_response(conn, 200)
end
test "update a filter", %{conn: conn} do
@@ -600,7 +600,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> get("/api/v1/notifications")
expected_response =
- "hi @#{user.nickname} "
+ "hi @#{user.nickname} "
assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
assert response == expected_response
@@ -621,7 +623,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> get("/api/v1/notifications/#{notification.id}")
expected_response =
- "hi @#{user.nickname} "
+ "hi @#{user.nickname} "
assert %{"status" => %{"content" => response}} = json_response(conn, 200)
assert response == expected_response
@@ -1357,7 +1361,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [status] = json_response(first_conn, 200)
assert status["id"] == to_string(activity.id)
- assert [{"link", link_header}] =
+ assert [{"link", _link_header}] =
Enum.filter(first_conn.resp_headers, fn element -> match?({"link", _}, element) end)
# Honours query params
@@ -1402,9 +1406,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert user = json_response(conn, 200)
assert user["note"] ==
- "I drink #cofe with #cofe with @#{user2.nickname} "
+ }\" class=\"u-url mention\" href=\"#{user2.ap_id}\">@#{user2.nickname} "
end
test "updates the user's locking status", %{conn: conn} do
@@ -1495,7 +1499,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> assign(:user, user)
|> put("/api/web/settings", %{"data" => %{"programming" => "socks"}})
- assert result = json_response(conn, 200)
+ assert _result = json_response(conn, 200)
user = User.get_cached_by_ap_id(user.ap_id)
assert user.info.settings == %{"programming" => "socks"}
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 5f13e7959..e08edc525 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1357,9 +1357,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert user.name == "new name"
assert user.bio ==
- "hi @#{
- user2.nickname
- } "
+ "hi @#{user2.nickname} "
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index b9feb23d4..547592ff2 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -38,7 +38,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
expected_text =
- "Hello again, @shp .<script></script> This is on another :moominmamma: line. #2hu #epic #phantasmagoric image.jpg "
+ "Hello again, @shp .<script></script> This is on another :moominmamma: line. #2hu #epic #phantasmagoric image.jpg "
assert get_in(activity.data, ["object", "content"]) == expected_text
assert get_in(activity.data, ["object", "type"]) == "Note"
@@ -328,7 +328,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user2} = TwitterAPI.register_user(data2)
expected_text =
- "@john test"
+ "@john test"
assert user2.bio == expected_text
end
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 8b5a16add..3d6b264b1 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -66,7 +66,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
result = ActivityView.render("activity.json", activity: activity)
assert result["statusnet_html"] ==
- "#Bike log - Commute Tuesdayhttps://pla.bike/posts/20181211/ #cycling #CHScycling #commute MVIMG_20181211_054020.jpg"
+ "#Bike log - Commute Tuesdayhttps://pla.bike/posts/20181211/ #cycling #CHScycling #commute MVIMG_20181211_054020.jpg"
assert result["text"] ==
"#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg"
@@ -141,7 +141,9 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"summary" => "",
"summary_html" => "",
"statusnet_html" =>
- "Hey @shp !",
+ "Hey @shp !",
"tags" => [],
"text" => "Hey @shp!",
"uri" => activity.data["object"]["id"],
--
cgit v1.2.3
From 8cea00e1dc2bf3c2e807b09fac886dfd7b4ea3e9 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Wed, 16 Jan 2019 10:53:57 +0300
Subject: Remove OpenGraph test from Ostatus tests
---
test/web/ostatus/ostatus_controller_test.exs | 13 -------------
1 file changed, 13 deletions(-)
(limited to 'test')
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index 8e9d2b69a..5a94cb3b3 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -156,19 +156,6 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|> response(404)
end
- test "renders notice metatags in html format", %{conn: conn} do
- note_activity = insert(:note_activity)
- conn = get(conn, "/notice/#{note_activity.id}")
- body = html_response(conn, 200)
- twitter_card_summary = " "
-
- description_content =
- " "
-
- assert body =~ twitter_card_summary
- assert body =~ description_content
- end
-
test "gets a notice in xml format", %{conn: conn} do
note_activity = insert(:note_activity)
--
cgit v1.2.3
From 90433b988e4d9519e0d2368452aefdb0dc565b52 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Wed, 16 Jan 2019 11:07:46 +0300
Subject: [#518] Fixed /api/v1/instance ("domain_count" value) and
/api/v1/instance/peers responses.
---
.../mastodon_api/mastodon_api_controller_test.exs | 28 +++++++++++++++++-----
1 file changed, 22 insertions(+), 6 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index fe8f845c7..62677638d 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1471,20 +1471,36 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "get instance information", %{conn: conn} do
insert(:user, %{local: true})
user = insert(:user, %{local: true})
- insert(:user, %{local: false})
+ insert(:user, %{local: false, nickname: "u@peer1.com"})
+ insert(:user, %{local: false, nickname: "u@peer2.com"})
{:ok, _} = TwitterAPI.create_status(user, %{"status" => "cofe"})
Pleroma.Stats.update_stats()
- conn =
- conn
- |> get("/api/v1/instance")
+ conn = get(conn, "/api/v1/instance")
+
+ assert result = json_response(conn, 200)
+
+ stats = result["stats"]
+
+ assert stats
+ assert stats["user_count"] == 2
+ assert stats["status_count"] == 1
+ assert stats["domain_count"] == 2
+ end
+
+ test "get peers", %{conn: conn} do
+ insert(:user, %{local: false, nickname: "u@peer1.com"})
+ insert(:user, %{local: false, nickname: "u@peer2.com"})
+
+ Pleroma.Stats.update_stats()
+
+ conn = get(conn, "/api/v1/instance/peers")
assert result = json_response(conn, 200)
- assert result["stats"]["user_count"] == 2
- assert result["stats"]["status_count"] == 1
+ assert ["peer1.com", "peer2.com"] == Enum.sort(result)
end
test "put settings", %{conn: conn} do
--
cgit v1.2.3
From 943324b66158d1bd2449894ec41bc544c56058a7 Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 16 Jan 2019 15:13:09 +0100
Subject: MastoAPI: Don't break on missing users.
---
test/web/mastodon_api/status_view_test.exs | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 1076b5002..d30ae6149 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -19,6 +19,36 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
:ok
end
+ test "returns a temporary ap_id based user for activities missing db users" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
+
+ Repo.delete(user)
+ Cachex.clear(:user_cache)
+
+ %{account: ms_user} = StatusView.render("status.json", activity: activity)
+
+ assert ms_user.acct == "erroruser@example.com"
+ end
+
+ test "tries to get a user by nickname if fetching by ap_id doesn't work" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
+
+ {:ok, user} =
+ user
+ |> Ecto.Changeset.change(%{ap_id: "#{user.ap_id}/extension/#{user.nickname}"})
+ |> Repo.update()
+
+ Cachex.clear(:user_cache)
+
+ result = StatusView.render("status.json", activity: activity)
+
+ assert result[:account][:id] == to_string(user.id)
+ end
+
test "a note with null content" do
note = insert(:note_activity)
--
cgit v1.2.3
From 293f6a8b712246d0580f9eb113c798ae1ea3b634 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Wed, 16 Jan 2019 17:15:13 +0300
Subject: join us now and share the software~. Also tests
---
test/web/metadata/opengraph_test.exs | 113 +++++++++++++++++++++++++++++++++++
1 file changed, 113 insertions(+)
create mode 100644 test/web/metadata/opengraph_test.exs
(limited to 'test')
diff --git a/test/web/metadata/opengraph_test.exs b/test/web/metadata/opengraph_test.exs
new file mode 100644
index 000000000..be3f89364
--- /dev/null
+++ b/test/web/metadata/opengraph_test.exs
@@ -0,0 +1,113 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+ alias Pleroma.Web.Metadata.Providers.OpenGraph
+
+ test "it renders all supported types of attachments and skips unknown types" do
+ user = insert(:user)
+
+ note =
+ insert(:note, %{
+ data: %{
+ "actor" => user.ap_id,
+ "tag" => [],
+ "content" => "pleroma in a nutshell",
+ "attachment" => [
+ %{
+ "url" => [
+ %{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}
+ ]
+ },
+ %{
+ "url" => [
+ %{
+ "mediaType" => "application/octet-stream",
+ "href" => "https://pleroma.gov/fqa/badapple.sfc"
+ }
+ ]
+ },
+ %{
+ "url" => [
+ %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
+ ]
+ },
+ %{
+ "url" => [
+ %{
+ "mediaType" => "audio/basic",
+ "href" => "http://www.gnu.org/music/free-software-song.au"
+ }
+ ]
+ }
+ ]
+ }
+ })
+
+ note_activity =
+ insert(:note_activity, %{
+ data: %{
+ "actor" => note.data["actor"],
+ "to" => note.data["to"],
+ "object" => note.data,
+ "context" => note.data["context"]
+ },
+ actor: note.data["actor"],
+ recipients: note.data["to"]
+ })
+
+ result = OpenGraph.build_tags(%{activity: note_activity, user: user})
+
+ assert Enum.all?(
+ [
+ {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []},
+ {:meta,
+ [property: "og:audio", content: "http://www.gnu.org/music/free-software-song.au"],
+ []},
+ {:meta, [property: "og:video", content: "https://pleroma.gov/about/juche.webm"],
+ []}
+ ],
+ fn element -> element in result end
+ )
+ end
+
+ test "it does not render attachments if post is nsfw" do
+ user = insert(:user, avatar: %{"url" => [%{"href" => "https://pleroma.gov/tenshi.png"}]})
+
+ note =
+ insert(:note, %{
+ data: %{
+ "actor" => user.ap_id,
+ "content" => "#cuteposting #nsfw #hambaga",
+ "tag" => ["cuteposting", "nsfw", "hambaga"],
+ "attachment" => [
+ %{
+ "url" => [
+ %{"mediaType" => "image/png", "href" => "https://misskey.microsoft/corndog.png"}
+ ]
+ }
+ ]
+ }
+ })
+
+ note_activity =
+ insert(:note_activity, %{
+ data: %{
+ "actor" => note.data["actor"],
+ "to" => note.data["to"],
+ "object" => note.data,
+ "context" => note.data["context"]
+ },
+ actor: note.data["actor"],
+ recipients: note.data["to"]
+ })
+
+ result = OpenGraph.build_tags(%{activity: note_activity, user: user})
+
+ assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result
+
+ refute {:meta, [property: "og:image", content: "https://misskey.microsoft/corndog.png"], []} in result
+ end
+end
--
cgit v1.2.3
From 3b187896847637d93db194897565599acd73a57c Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Thu, 17 Jan 2019 11:08:50 +0300
Subject: Fix test
---
test/web/metadata/opengraph_test.exs | 1 +
1 file changed, 1 insertion(+)
(limited to 'test')
diff --git a/test/web/metadata/opengraph_test.exs b/test/web/metadata/opengraph_test.exs
index be3f89364..672942148 100644
--- a/test/web/metadata/opengraph_test.exs
+++ b/test/web/metadata/opengraph_test.exs
@@ -74,6 +74,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
end
test "it does not render attachments if post is nsfw" do
+ Pleroma.Config.put([Pleroma.Web.Metadata, :unfurl_nsfw], false)
user = insert(:user, avatar: %{"url" => [%{"href" => "https://pleroma.gov/tenshi.png"}]})
note =
--
cgit v1.2.3
From 2bfae25a1ff735499e15cb431314503f34097a6b Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Thu, 17 Jan 2019 18:03:49 +0300
Subject: [#491] Made user bio preserve full nicknames (nick@host).
---
test/formatter_test.exs | 4 ++--
test/web/twitter_api/views/user_view_test.exs | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index bd8844458..7040f1c27 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -150,7 +150,7 @@ defmodule Pleroma.FormatterTest do
archaeme.id
}' class='u-url mention' href='#{"https://archeme/@archa_eme_"}'>@archa_eme_ , that is @daggsy. Also hello @archaeme "
+ }' class='u-url mention' href='#{archaeme_remote.ap_id}'>@archaeme@archae.me "
assert expected_text == Formatter.finalize({subs, text})
end
@@ -168,7 +168,7 @@ defmodule Pleroma.FormatterTest do
Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
expected_text =
- "@mike test"
+ "@mike@osada.macgirvin.com test"
assert expected_text == Formatter.finalize({subs, text})
end
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 5f7481eb6..b8f1afa76 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -12,7 +12,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
import Pleroma.Factory
setup do
- user = insert(:user, bio: "Here's some html ")
+ user = insert(:user, bio: "Here's some html, @mention@domain.com")
[user: user]
end
--
cgit v1.2.3
From 954dc4a4ad8a387ca7b18bb7d0ed32456491daec Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Thu, 17 Jan 2019 19:16:02 +0300
Subject: [#502] Fixed `user_count` in `/api/v1/instance` to include only
active local users.
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index c83bb5bc8..dd84052a3 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1473,8 +1473,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
test "get instance information", %{conn: conn} do
- insert(:user, %{local: true})
user = insert(:user, %{local: true})
+
+ user2 = insert(:user, %{local: true})
+ {:ok, _user2} = User.deactivate(user2, !user2.info.deactivated)
+
insert(:user, %{local: false, nickname: "u@peer1.com"})
insert(:user, %{local: false, nickname: "u@peer2.com"})
@@ -1489,7 +1492,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
stats = result["stats"]
assert stats
- assert stats["user_count"] == 2
+ assert stats["user_count"] == 1
assert stats["status_count"] == 1
assert stats["domain_count"] == 2
end
--
cgit v1.2.3
From 64143d8040a5806ccf9707644a7e7eacc91d74c6 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Thu, 17 Jan 2019 22:57:24 +0300
Subject: Fix object id in OpenGraph test
---
test/web/metadata/opengraph_test.exs | 2 ++
1 file changed, 2 insertions(+)
(limited to 'test')
diff --git a/test/web/metadata/opengraph_test.exs b/test/web/metadata/opengraph_test.exs
index 672942148..1c4fadc46 100644
--- a/test/web/metadata/opengraph_test.exs
+++ b/test/web/metadata/opengraph_test.exs
@@ -14,6 +14,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
data: %{
"actor" => user.ap_id,
"tag" => [],
+ "id" => "https://pleroma.gov/objects/whatever",
"content" => "pleroma in a nutshell",
"attachment" => [
%{
@@ -81,6 +82,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
insert(:note, %{
data: %{
"actor" => user.ap_id,
+ "id" => "https://pleroma.gov/objects/whatever",
"content" => "#cuteposting #nsfw #hambaga",
"tag" => ["cuteposting", "nsfw", "hambaga"],
"attachment" => [
--
cgit v1.2.3
From 65bb9b2fba7560df7331645db9839305c47dad11 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Fri, 18 Jan 2019 09:30:16 +0300
Subject: [#491] Made full nicknames be preserved in user links text only in
Bio.
---
test/formatter_test.exs | 6 +++---
test/user_test.exs | 15 +++++++++++++++
test/web/twitter_api/views/user_view_test.exs | 2 +-
3 files changed, 19 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index 7040f1c27..2e717194b 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -124,7 +124,7 @@ defmodule Pleroma.FormatterTest do
end
describe "add_user_links" do
- test "gives a replacement for user links" do
+ test "gives a replacement for user links, using local nicknames in user links text" do
text = "@gsimg According to @archa_eme_, that is @daggsy. Also hello @archaeme@archae.me"
gsimg = insert(:user, %{nickname: "gsimg"})
@@ -150,7 +150,7 @@ defmodule Pleroma.FormatterTest do
archaeme.id
}' class='u-url mention' href='#{"https://archeme/@archa_eme_"}'>@archa_eme_ , that is @daggsy. Also hello @archaeme@archae.me "
+ }' class='u-url mention' href='#{archaeme_remote.ap_id}'>@archaeme "
assert expected_text == Formatter.finalize({subs, text})
end
@@ -168,7 +168,7 @@ defmodule Pleroma.FormatterTest do
Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
expected_text =
- "@mike@osada.macgirvin.com test"
+ "@mike test"
assert expected_text == Formatter.finalize({subs, text})
end
diff --git a/test/user_test.exs b/test/user_test.exs
index cfccce8d1..21a62483f 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -874,4 +874,19 @@ defmodule Pleroma.UserTest do
Pleroma.Config.put([:instance, :account_activation_required], false)
end
end
+
+ describe "parse_bio/2" do
+ test "preserves hosts in user links text" do
+ remote_user = insert(:user, local: false, nickname: "nick@domain.com")
+ user = insert(:user)
+ bio = "A.k.a. @nick@domain.com"
+
+ expected_text =
+ "A.k.a. " <> "@nick@domain.com "
+
+ assert expected_text == User.parse_bio(bio, user)
+ end
+ end
end
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index b8f1afa76..5f7481eb6 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -12,7 +12,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
import Pleroma.Factory
setup do
- user = insert(:user, bio: "Here's some html, @mention@domain.com")
+ user = insert(:user, bio: "Here's some html ")
[user: user]
end
--
cgit v1.2.3
From 1b1af4798a74c4ab357140ef2c5928dd9ebd3221 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Fri, 18 Jan 2019 09:32:52 +0300
Subject: Use object instead of activity for metadata
---
test/web/metadata/opengraph_test.exs | 30 ++++--------------------------
1 file changed, 4 insertions(+), 26 deletions(-)
(limited to 'test')
diff --git a/test/web/metadata/opengraph_test.exs b/test/web/metadata/opengraph_test.exs
index 1c4fadc46..c3502bad3 100644
--- a/test/web/metadata/opengraph_test.exs
+++ b/test/web/metadata/opengraph_test.exs
@@ -1,6 +1,7 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
use Pleroma.DataCase
import Pleroma.Factory
@@ -47,19 +48,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
}
})
- note_activity =
- insert(:note_activity, %{
- data: %{
- "actor" => note.data["actor"],
- "to" => note.data["to"],
- "object" => note.data,
- "context" => note.data["context"]
- },
- actor: note.data["actor"],
- recipients: note.data["to"]
- })
-
- result = OpenGraph.build_tags(%{activity: note_activity, user: user})
+ result = OpenGraph.build_tags(%{object: note, user: user})
assert Enum.all?(
[
@@ -85,6 +74,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
"id" => "https://pleroma.gov/objects/whatever",
"content" => "#cuteposting #nsfw #hambaga",
"tag" => ["cuteposting", "nsfw", "hambaga"],
+ "sensitive" => true,
"attachment" => [
%{
"url" => [
@@ -95,19 +85,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
}
})
- note_activity =
- insert(:note_activity, %{
- data: %{
- "actor" => note.data["actor"],
- "to" => note.data["to"],
- "object" => note.data,
- "context" => note.data["context"]
- },
- actor: note.data["actor"],
- recipients: note.data["to"]
- })
-
- result = OpenGraph.build_tags(%{activity: note_activity, user: user})
+ result = OpenGraph.build_tags(%{object: note, user: user})
assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result
--
cgit v1.2.3
From ed8f55ab8eb292903cec8f7699aa6775cc304458 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Fri, 18 Jan 2019 10:35:45 +0300
Subject: [#477] User: FTS and trigram search results mixing (to handle
misspelled requests).
---
test/user_test.exs | 6 ++++++
test/web/twitter_api/twitter_api_controller_test.exs | 2 +-
2 files changed, 7 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 48b7b72ec..339def217 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -814,6 +814,12 @@ defmodule Pleroma.UserTest do
assert [u4.id, u3.id, u1.id] == Enum.map(User.search("lain@ple"), & &1.id)
end
+ test "finds users, handling misspelled requests" do
+ u1 = insert(:user, %{name: "lain"})
+
+ assert [u1.id] == Enum.map(User.search("laiin"), & &1.id)
+ end
+
test "finds users, boosting ranks of friends and followers" do
u1 = insert(:user)
u2 = insert(:user, %{name: "Doe"})
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index a4baf2b5f..e013d1aca 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1656,7 +1656,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
test "it returns users, ordered by similarity", %{conn: conn} do
user = insert(:user, %{name: "eal"})
user_two = insert(:user, %{name: "eal me"})
- _user_three = insert(:user, %{name: "ebn"})
+ _user_three = insert(:user, %{name: "zzz"})
resp =
conn
--
cgit v1.2.3
From 7bc6208b2fa53b04d0d319e62c7c9b34d18e0e44 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Fri, 18 Jan 2019 10:35:52 +0300
Subject: Fix ostatus test
---
test/web/ostatus/ostatus_controller_test.exs | 2 ++
1 file changed, 2 insertions(+)
(limited to 'test')
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index 5a94cb3b3..954abf5fe 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -131,12 +131,14 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
object = Object.get_by_ap_id(note_activity.data["object"]["id"])
conn
+ |> put_req_header("accept", "application/xml")
|> get("/objects/#{uuid}")
|> response(200)
Object.delete(object)
conn
+ |> put_req_header("accept", "application/xml")
|> get("/objects/#{uuid}")
|> response(404)
end
--
cgit v1.2.3
From 5d4d51e6dcbdff442e8bbc7cd3924b621d8f1783 Mon Sep 17 00:00:00 2001
From: lain
Date: Fri, 18 Jan 2019 19:25:37 +0100
Subject: Add fixes for SPC users.
---
test/fixtures/zep.json | 1 +
test/spc_fixes_test.exs | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+)
create mode 100644 test/fixtures/zep.json
create mode 100644 test/spc_fixes_test.exs
(limited to 'test')
diff --git a/test/fixtures/zep.json b/test/fixtures/zep.json
new file mode 100644
index 000000000..1aab043be
--- /dev/null
+++ b/test/fixtures/zep.json
@@ -0,0 +1 @@
+{"url":"https://shitposter.club/users/zep","type":"Person","tag":[],"summary":"The Zeptar Show on anonradio.net","publicKey":{"publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsdkm3pQxYTW7rVVUQBJ0\nc+J7pUI623gohi2fwM05ZenYVysRIw0Mm6GYvDsCO6DHywi97pG4EBABEQNyagLS\njIDTrLR1GU0K4dnPgaZ7fIkXvMN+d2NNe0LoIw0wX23sw+L+D+U5l0AJ+3LqDC9s\nwucLz4uYokcrl8yxGFYHWjpRYqy/WVuk8986Hm1Mov4j8AWWV5VLl1yYcbQthSuw\nDXL5yMqwiLPn+Vhc4Pb216IhwIl+k9/tfdsnyAlCiasvUQ8Cigde0AJC0sqnUQhy\nJ4gSftvyW5ejYYebNWg09Afjq3I8k0gj1fGks0pY9IJr2a2H+eqCA//YI8z1XHvE\nlwIDAQAB\n-----END PUBLIC KEY-----\n\n","owner":"https://shitposter.club/users/zep","id":"https://shitposter.club/users/zep#main-key"},"preferredUsername":"zep","outbox":"https://shitposter.club/users/zep/outbox","name":"DJ Zep","manuallyApprovesFollowers":false,"inbox":"https://shitposter.club/users/zep/inbox","image":{"url":"https://shitposter.club/media/13946026-15ba-40e1-9cad-ba3a7aeb47e1/13946026-15ba-40e1-9cad-ba3a7aeb47e1.jpeg","type":"Image"},"id":"https://shitposter.club/users/zep","icon":{"url":"https://shitposter.club/media/83650c2f-7f31-98f5-acee-69a486c94173/83650c2f-7f31-98f5-acee-69a486c94173.jpeg","type":"Image"},"following":"https://shitposter.club/users/zep/following","followers":"https://shitposter.club/users/zep/followers","endpoints":{"sharedInbox":"https://shitposter.club/inbox"},"@context":["https://www.w3.org/ns/activitystreams","https://shitposter.club/schemas/litepub-0.1.jsonld"]}
\ No newline at end of file
diff --git a/test/spc_fixes_test.exs b/test/spc_fixes_test.exs
new file mode 100644
index 000000000..01629e374
--- /dev/null
+++ b/test/spc_fixes_test.exs
@@ -0,0 +1,52 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.SpcFixesTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.SpcFixes
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.User
+
+ import Pleroma.Factory
+
+ test "resets the ap_id and follower_address of old spc users" do
+ Tesla.Mock.mock(fn
+ %{url: "https://shitposter.club/users/zep"} ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/zep.json")}
+
+ %{url: nil} ->
+ nil
+ end)
+
+ user =
+ insert(:user, %{
+ local: false,
+ ap_id: "https://shitposter.club/user/4962",
+ follower_address: User.ap_followers(%User{nickname: "zep@shitposter.club"}),
+ info: %{topic: "ignore"},
+ nickname: "zep@shitposter.club"
+ })
+
+ other_user = insert(:user)
+ {:ok, other_user} = User.follow(other_user, user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "blabla"})
+
+ assert User.following?(other_user, user)
+ assert [activity] == ActivityPub.fetch_activities(other_user.following)
+
+ SpcFixes.upgrade_users()
+
+ user = Pleroma.Repo.get(User, user.id)
+ other_user = Pleroma.Repo.get(User, other_user.id)
+
+ assert user.ap_id == "https://shitposter.club/users/zep"
+ assert user.follower_address == "https://shitposter.club/users/zep/followers"
+
+ # Activites and following are correctly stitched.
+ assert User.following?(other_user, user)
+ assert [activity] == ActivityPub.fetch_activities(other_user.following) |> IO.inspect()
+ end
+end
--
cgit v1.2.3
From e116e55cabb34d468866231d1690421792c27a0c Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Fri, 18 Jan 2019 22:40:52 +0300
Subject: Add actor to recipients
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 10 ++++++++++
1 file changed, 10 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index fe8f845c7..ce3aa5a02 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -181,6 +181,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"visibility" => "direct"} = status
assert status["url"] != direct.data["id"]
+ # User should be able to see his own direct message
+ res_conn =
+ build_conn()
+ |> assign(:user, user_one)
+ |> get("api/v1/timelines/direct")
+
+ [status] = json_response(res_conn, 200)
+
+ assert %{"visibility" => "direct"} = status
+
# Both should be visible here
res_conn =
conn
--
cgit v1.2.3
From 31517bec129df1958de871bded16e2d637d8d6e0 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Fri, 18 Jan 2019 22:32:01 +0000
Subject: test: add regression test for to/cc clobbering
---
test/web/activity_pub/transmogrifier_test.exs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 87d0ab559..6107ac4f7 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -288,6 +288,22 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert Activity.get_create_activity_by_object_ap_id(data["object"]).id == activity.id
end
+ test "it does not clobber the addressing on announce activities" do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
+
+ data =
+ File.read!("test/fixtures/mastodon-announce.json")
+ |> Poison.decode!()
+ |> Map.put("object", activity.data["object"]["id"])
+ |> Map.put("to", ["http://mastodon.example.org/users/admin/followers"])
+ |> Map.put("cc", [])
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+
+ assert data["to"] == ["http://mastodon.example.org/users/admin/followers"]
+ end
+
test "it works for incoming update activities" do
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
--
cgit v1.2.3
From 651a1d64b53db061cc6a24099e706a64cc6d6dd8 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Sat, 19 Jan 2019 04:25:15 +0300
Subject: Add current user to mentioned
---
test/user_test.exs | 5 +++--
test/web/activity_pub/activity_pub_test.exs | 2 +-
test/web/mastodon_api/mastodon_api_controller_test.exs | 2 +-
test/web/mastodon_api/status_view_test.exs | 4 +++-
test/web/twitter_api/views/activity_view_test.exs | 4 +---
5 files changed, 9 insertions(+), 8 deletions(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index cfccce8d1..935c9c5b1 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -672,12 +672,13 @@ defmodule Pleroma.UserTest do
"status" => "hey @#{addressed.nickname} @#{addressed_remote.nickname}"
})
- assert [addressed] == User.get_recipients_from_activity(activity)
+ assert Enum.map([actor, addressed], & &1.ap_id) --
+ Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
{:ok, user} = User.follow(user, actor)
{:ok, _user_two} = User.follow(user_two, actor)
recipients = User.get_recipients_from_activity(activity)
- assert length(recipients) == 2
+ assert length(recipients) == 3
assert user in recipients
assert addressed in recipients
end
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index eafb96f3a..6b1debc61 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -160,7 +160,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert activity.data["to"] == ["user1", "user2"]
assert activity.actor == user.ap_id
- assert activity.recipients == ["user1", "user2"]
+ assert activity.recipients == ["user1", "user2", user.ap_id]
end
end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index ce3aa5a02..fdd3f1213 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -147,7 +147,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"id" => id, "visibility" => "direct"} = json_response(conn, 200)
assert activity = Repo.get(Activity, id)
- assert activity.recipients == [user2.ap_id]
+ assert activity.recipients == [user2.ap_id, user1.ap_id]
assert activity.data["to"] == [user2.ap_id]
assert activity.data["cc"] == []
end
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 1076b5002..5779a030e 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -119,7 +119,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
status = StatusView.render("status.json", %{activity: activity})
- assert status.mentions == [AccountView.render("mention.json", %{user: user})]
+ actor = Repo.get_by(User, ap_id: activity.actor)
+
+ assert status.mentions == Enum.map([user, actor], fn u -> AccountView.render("mention.json", %{user: u}) end)
end
test "attachments" do
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 8b5a16add..4aa8c16bc 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -118,9 +118,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
expected = %{
"activity_type" => "post",
"attachments" => [],
- "attentions" => [
- UserView.render("show.json", %{user: other_user})
- ],
+ "attentions" => Enum.map([other_user, user], fn u -> UserView.render("show.json", %{user: u}) end),
"created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(),
"external_url" => activity.data["object"]["id"],
"fave_num" => 0,
--
cgit v1.2.3
From 0a97baddddbb8bf89c806f7e5b7cd754c88f4fe5 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Sat, 19 Jan 2019 04:26:52 +0300
Subject: Format
---
test/web/mastodon_api/status_view_test.exs | 5 +++--
test/web/twitter_api/views/activity_view_test.exs | 3 ++-
2 files changed, 5 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 5779a030e..82bf71c70 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -120,8 +120,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
status = StatusView.render("status.json", %{activity: activity})
actor = Repo.get_by(User, ap_id: activity.actor)
-
- assert status.mentions == Enum.map([user, actor], fn u -> AccountView.render("mention.json", %{user: u}) end)
+
+ assert status.mentions ==
+ Enum.map([user, actor], fn u -> AccountView.render("mention.json", %{user: u}) end)
end
test "attachments" do
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 4aa8c16bc..0f514dab1 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -118,7 +118,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
expected = %{
"activity_type" => "post",
"attachments" => [],
- "attentions" => Enum.map([other_user, user], fn u -> UserView.render("show.json", %{user: u}) end),
+ "attentions" =>
+ Enum.map([other_user, user], fn u -> UserView.render("show.json", %{user: u}) end),
"created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(),
"external_url" => activity.data["object"]["id"],
"fave_num" => 0,
--
cgit v1.2.3
From 8d06be35e0f1cb5caa2b638330c8bb03ad08a127 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sat, 17 Nov 2018 15:51:02 +0000
Subject: activitypub: utils: add determine_explicit_mentions() and tests
---
test/web/activity_pub/utils_test.exs | 57 ++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
create mode 100644 test/web/activity_pub/utils_test.exs
(limited to 'test')
diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs
new file mode 100644
index 000000000..aeed0564c
--- /dev/null
+++ b/test/web/activity_pub/utils_test.exs
@@ -0,0 +1,57 @@
+defmodule Pleroma.Web.ActivityPub.UtilsTest do
+ use Pleroma.DataCase
+ alias Pleroma.Web.ActivityPub.Utils
+
+ describe "determine_explicit_mentions()" do
+ test "works with an object that has mentions" do
+ object = %{
+ "tag" => [
+ %{
+ "type" => "Mention",
+ "href" => "https://example.com/~alyssa",
+ "name" => "Alyssa P. Hacker"
+ }
+ ]
+ }
+
+ assert Utils.determine_explicit_mentions(object) == ["https://example.com/~alyssa"]
+ end
+
+ test "works with an object that does not have mentions" do
+ object = %{
+ "tag" => [
+ %{"type" => "Hashtag", "href" => "https://example.com/tag/2hu", "name" => "2hu"}
+ ]
+ }
+
+ assert Utils.determine_explicit_mentions(object) == []
+ end
+
+ test "works with an object that has mentions and other tags" do
+ object = %{
+ "tag" => [
+ %{
+ "type" => "Mention",
+ "href" => "https://example.com/~alyssa",
+ "name" => "Alyssa P. Hacker"
+ },
+ %{"type" => "Hashtag", "href" => "https://example.com/tag/2hu", "name" => "2hu"}
+ ]
+ }
+
+ assert Utils.determine_explicit_mentions(object) == ["https://example.com/~alyssa"]
+ end
+
+ test "works with an object that has no tags" do
+ object = %{}
+
+ assert Utils.determine_explicit_mentions(object) == []
+ end
+
+ test "works with an object that has only IR tags" do
+ object = %{"tag" => ["2hu"]}
+
+ assert Utils.determine_explicit_mentions(object) == []
+ end
+ end
+end
--
cgit v1.2.3
From 21ac35fcc0a531914cc3f84ace89f6cf029cfa6c Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sat, 17 Nov 2018 16:18:40 +0000
Subject: tests: add tests for DM sanitizer
---
test/web/activity_pub/transmogrifier_test.exs | 30 +++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 6107ac4f7..5aa136e65 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -162,6 +162,36 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["object"]["url"] == "https://prismo.news/posts/83"
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")
+ |> Poison.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}} = Transmogrifier.handle_incoming(data)
+
+ assert data["to"] == []
+ assert data["cc"] == to
+
+ object = data["object"]
+
+ assert object["to"] == []
+ assert object["cc"] == to
+ end
+
test "it works for incoming follow requests" do
user = insert(:user)
--
cgit v1.2.3
From cf3099231db2f51a4e804a4e5630cd6774e60c77 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 23 Dec 2018 15:55:07 +0000
Subject: test: transmogrifier: verify directMessage flag is sent outbound
based on declared visibility
---
test/web/activity_pub/transmogrifier_test.exs | 28 +++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 5aa136e65..c1d542245 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -902,6 +902,34 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert modified["object"]["likes"]["type"] == "OrderedCollection"
assert modified["object"]["likes"]["totalItems"] == 0
end
+
+ test "the directMessage flag is present" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu :moominmamma:"})
+
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
+
+ assert modified["directMessage"] == false
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "@{other_user.nickname} :moominmamma:"})
+
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
+
+ assert modified["directMessage"] == false
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "@{other_user.nickname} :moominmamma:",
+ "visibility" => "direct"
+ })
+
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
+
+ assert modified["directMessage"] == true
+ end
end
describe "user upgrade" do
--
cgit v1.2.3
From be0fb5dec47e5dc69aaef5f9c4f6910eba92b48a Mon Sep 17 00:00:00 2001
From: lain
Date: Sun, 20 Jan 2019 11:48:53 +0100
Subject: Add a test to ensure #39 is fixed.
---
test/web/common_api/common_api_test.exs | 7 +++++++
1 file changed, 7 insertions(+)
(limited to 'test')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 9ac805f24..a7d9e6161 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -17,6 +17,13 @@ defmodule Pleroma.Web.CommonAPI.Test do
assert activity.data["object"]["tag"] == ["2hu"]
end
+ test "it adds emoji in the object" do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => ":moominmamma:"})
+
+ assert activity.data["object"]["emoji"]["moominmamma"]
+ end
+
test "it adds emoji when updating profiles" do
user = insert(:user, %{name: ":karjalanpiirakka:"})
--
cgit v1.2.3
From cf1f35a93a096311dee62ee5ac142a1bb3cfb844 Mon Sep 17 00:00:00 2001
From: lain
Date: Sun, 20 Jan 2019 13:00:46 +0100
Subject: Send delete event over Mastodon streaming api
Closes #116
---
test/web/streamer_test.exs | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/streamer_test.exs b/test/web/streamer_test.exs
index 905e29d06..16d7b9c24 100644
--- a/test/web/streamer_test.exs
+++ b/test/web/streamer_test.exs
@@ -6,7 +6,8 @@ defmodule Pleroma.Web.StreamerTest do
use Pleroma.DataCase
alias Pleroma.Web.Streamer
- alias Pleroma.{List, User}
+ alias Pleroma.List
+ alias Pleroma.User
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
@@ -35,6 +36,28 @@ defmodule Pleroma.Web.StreamerTest do
Streamer.push_to_socket(topics, "public", activity)
Task.await(task)
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _}, 4_000
+ end)
+
+ fake_socket = %{
+ transport_pid: task.pid,
+ assigns: %{
+ user: user
+ }
+ }
+
+ {:ok, activity} = CommonAPI.delete(activity.id, other_user)
+
+ topics = %{
+ "public" => [fake_socket]
+ }
+
+ Streamer.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
end
test "it doesn't send to blocked users" do
--
cgit v1.2.3
From b82c6dc53685ebd26c276eccc5ed915ddf81afa6 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Mon, 21 Jan 2019 06:29:05 +0100
Subject: =?UTF-8?q?Activity:=20all=5Fby=5Fobject=5Fap=5Fid/1=20=E2=86=92?=
=?UTF-8?q?=20get=5Fall=5Fby=5Fobject=5Fap=5Fid/1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/activity_test.exs | 2 +-
test/web/activity_pub/activity_pub_test.exs | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/activity_test.exs b/test/activity_test.exs
index 36c718869..8f3f613ec 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -16,7 +16,7 @@ defmodule Pleroma.ActivityTest do
test "returns activities by it's objects AP ids" do
activity = insert(:note_activity)
- [found_activity] = Activity.all_by_object_ap_id(activity.data["object"]["id"])
+ [found_activity] = Activity.get_all_by_object_ap_id(activity.data["object"]["id"])
assert activity == found_activity
end
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index eafb96f3a..6538fb7af 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -330,7 +330,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert like_activity == same_like_activity
assert object.data["likes"] == [user.ap_id]
- [note_activity] = Activity.all_by_object_ap_id(object.data["id"])
+ [note_activity] = Activity.get_all_by_object_ap_id(object.data["id"])
assert note_activity.data["object"]["like_count"] == 1
{:ok, _like_activity, object} = ActivityPub.like(user_two, object)
--
cgit v1.2.3
From f8ab1b7427e91ec1b7883e021836099226b56566 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Mon, 21 Jan 2019 06:46:47 +0100
Subject: =?UTF-8?q?Activity:=20get=5Fall=5Fby=5Fobject=5Fap=5Fid/1=20?=
=?UTF-8?q?=E2=86=92=20get=5Fall=5Fcreate=5Fby=5Fobject=5Fap=5Fid/1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/activity_test.exs | 2 +-
test/web/activity_pub/activity_pub_test.exs | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/activity_test.exs b/test/activity_test.exs
index 8f3f613ec..dcac8649a 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -16,7 +16,7 @@ defmodule Pleroma.ActivityTest do
test "returns activities by it's objects AP ids" do
activity = insert(:note_activity)
- [found_activity] = Activity.get_all_by_object_ap_id(activity.data["object"]["id"])
+ [found_activity] = Activity.get_all_create_by_object_ap_id(activity.data["object"]["id"])
assert activity == found_activity
end
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 6538fb7af..ea9ac5ba8 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -330,7 +330,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert like_activity == same_like_activity
assert object.data["likes"] == [user.ap_id]
- [note_activity] = Activity.get_all_by_object_ap_id(object.data["id"])
+ [note_activity] = Activity.get_all_create_by_object_ap_id(object.data["id"])
assert note_activity.data["object"]["like_count"] == 1
{:ok, _like_activity, object} = ActivityPub.like(user_two, object)
--
cgit v1.2.3
From 98c8184c1fc013fbd48bd78a2603c8e560038081 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Mon, 21 Jan 2019 07:14:20 +0100
Subject: =?UTF-8?q?Activity:=20get=5Fcreate=5Factivity=5Fby=5Fobject=5Fap?=
=?UTF-8?q?=5Fid/1=20=E2=86=92=20get=5Fcreate=5Fby=5Fobject=5Fap=5Fid/1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/activity_test.exs | 2 +-
test/web/activity_pub/activity_pub_test.exs | 6 +++---
test/web/activity_pub/transmogrifier_test.exs | 6 +++---
test/web/mastodon_api/status_view_test.exs | 2 +-
test/web/twitter_api/twitter_api_test.exs | 2 +-
test/web/twitter_api/views/activity_view_test.exs | 2 +-
6 files changed, 10 insertions(+), 10 deletions(-)
(limited to 'test')
diff --git a/test/activity_test.exs b/test/activity_test.exs
index dcac8649a..ad889f544 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -24,7 +24,7 @@ defmodule Pleroma.ActivityTest do
test "returns the activity that created an object" do
activity = insert(:note_activity)
- found_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"]["id"])
+ found_activity = Activity.get_create_by_object_ap_id(activity.data["object"]["id"])
assert activity == found_activity
end
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index ea9ac5ba8..18f094379 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -216,7 +216,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
{:ok, user} = User.block(user, %{ap_id: activity_three.data["actor"]})
{:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.repeat(activity_three.id, booster)
- %Activity{} = boost_activity = Activity.get_create_activity_by_object_ap_id(id)
+ %Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id)
activity_three = Repo.get(Activity, activity_three.id)
activities = ActivityPub.fetch_activities([], %{"blocking_user" => user})
@@ -445,7 +445,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
{:ok, object} =
ActivityPub.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
- assert activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
+ assert activity = Activity.get_create_by_object_ap_id(object.data["id"])
assert activity.data["id"]
{:ok, object_again} =
@@ -459,7 +459,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
test "it works with objects only available via Ostatus" do
{:ok, object} = ActivityPub.fetch_object_from_id("https://shitposter.club/notice/2827873")
- assert activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
+ assert activity = Activity.get_create_by_object_ap_id(object.data["id"])
assert activity.data["id"]
{:ok, object_again} =
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 6107ac4f7..89e3dafd6 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -51,7 +51,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
assert activity =
- Activity.get_create_activity_by_object_ap_id(
+ Activity.get_create_by_object_ap_id(
"tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
)
@@ -263,7 +263,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["object"] ==
"http://mastodon.example.org/users/admin/statuses/99541947525187367"
- assert Activity.get_create_activity_by_object_ap_id(data["object"])
+ assert Activity.get_create_by_object_ap_id(data["object"])
end
test "it works for incoming announces with an existing activity" do
@@ -285,7 +285,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["object"] == activity.data["object"]["id"]
- assert Activity.get_create_activity_by_object_ap_id(data["object"]).id == activity.id
+ assert Activity.get_create_by_object_ap_id(data["object"]).id == activity.id
end
test "it does not clobber the addressing on announce activities" do
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index d30ae6149..e33479368 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -202,7 +202,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
"https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
)
- %Activity{} = activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
+ %Activity{} = activity = Activity.get_create_by_object_ap_id(object.data["id"])
represented = StatusView.render("status.json", %{for: user, activity: activity})
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 547592ff2..f94e2b873 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -451,7 +451,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert represented["id"] == UserView.render("show.json", %{user: remote, for: user})["id"]
# Also fetches the feed.
- # assert Activity.get_create_activity_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status")
+ # assert Activity.get_create_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status")
end
end
end
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 3d6b264b1..ba053d20d 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -344,7 +344,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
)
- %Activity{} = activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
+ %Activity{} = activity = Activity.get_create_by_object_ap_id(object.data["id"])
result = ActivityView.render("activity.json", activity: activity)
--
cgit v1.2.3
From 789a9843da0eef1e5426ab6558f1adf24231ce02 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Mon, 21 Jan 2019 14:30:01 +0300
Subject: [#530] Fixed test.
---
test/integration/mastodon_websocket_test.exs | 3 ---
1 file changed, 3 deletions(-)
(limited to 'test')
diff --git a/test/integration/mastodon_websocket_test.exs b/test/integration/mastodon_websocket_test.exs
index 03aabf12c..2e385f5ad 100644
--- a/test/integration/mastodon_websocket_test.exs
+++ b/test/integration/mastodon_websocket_test.exs
@@ -66,13 +66,10 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
assert json["payload"]
assert {:ok, json} = Jason.decode(json["payload"])
- # Note: we remove the "statuses_count" from this result as it changes in the meantime
-
view_json =
Pleroma.Web.MastodonAPI.StatusView.render("status.json", activity: activity, for: nil)
|> Jason.encode!()
|> Jason.decode!()
- |> put_in(["account", "statuses_count"], 0)
assert json == view_json
end
--
cgit v1.2.3
From 762fafe7387648520c8f7e4b5b248bc90e8c0f66 Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 21 Jan 2019 17:54:11 +0100
Subject: Fix buggy test.
---
test/web/activity_pub/transmogrifier_test.exs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index c1d542245..7db28854a 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -914,7 +914,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert modified["directMessage"] == false
{:ok, activity} =
- CommonAPI.post(user, %{"status" => "@{other_user.nickname} :moominmamma:"})
+ CommonAPI.post(user, %{"status" => "@#{other_user.nickname} :moominmamma:"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
@@ -922,7 +922,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "@{other_user.nickname} :moominmamma:",
+ "status" => "@#{other_user.nickname} :moominmamma:",
"visibility" => "direct"
})
--
cgit v1.2.3
From 34d59e40086ad8adc020bac6d23ab2aa835f267b Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Tue, 22 Jan 2019 17:12:53 +0300
Subject: [#502] Fixed User.active_local_user_query to return users with nil or
missing `info.deactivated`. Adjusted test.
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 11 +++++++++++
1 file changed, 11 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index dd84052a3..8443dc856 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -10,6 +10,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Pleroma.Web.{OStatus, CommonAPI}
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.MastodonAPI.FilterView
+ alias Ecto.Changeset
import Pleroma.Factory
import ExUnit.CaptureLog
import Tesla.Mock
@@ -1483,6 +1484,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _} = TwitterAPI.create_status(user, %{"status" => "cofe"})
+ # Stats should count users with missing or nil `info.deactivated` value
+ user = Repo.get(User, user.id)
+ info_change = Changeset.change(user.info, %{deactivated: nil})
+
+ {:ok, _user} =
+ user
+ |> Changeset.change()
+ |> Changeset.put_embed(:info, info_change)
+ |> User.update_and_set_cache()
+
Pleroma.Stats.update_stats()
conn = get(conn, "/api/v1/instance")
--
cgit v1.2.3
From 28d77e373cbaf0908f86973a873c9bfd6c3221cb Mon Sep 17 00:00:00 2001
From: href
Date: Wed, 9 Jan 2019 16:08:24 +0100
Subject: Flake Ids for Users and Activities
---
test/web/twitter_api/twitter_api_controller_test.exs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index f22cdd870..863abd10f 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -797,7 +797,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> with_credentials(current_user.nickname, "test")
|> post("/api/favorites/create/1.json")
- assert json_response(conn, 500)
+ assert json_response(conn, 400)
end
end
@@ -1621,7 +1621,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
conn =
build_conn()
|> assign(:user, user)
- |> post("/api/pleroma/friendships/approve", %{"user_id" => to_string(other_user.id)})
+ |> post("/api/pleroma/friendships/approve", %{"user_id" => other_user.id})
assert relationship = json_response(conn, 200)
assert other_user.id == relationship["id"]
@@ -1644,7 +1644,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
conn =
build_conn()
|> assign(:user, user)
- |> post("/api/pleroma/friendships/deny", %{"user_id" => to_string(other_user.id)})
+ |> post("/api/pleroma/friendships/deny", %{"user_id" => other_user.id})
assert relationship = json_response(conn, 200)
assert other_user.id == relationship["id"]
--
cgit v1.2.3
From 9d63b27dcd61dff61b77b6df0ef8a4cf8d7c87e3 Mon Sep 17 00:00:00 2001
From: href
Date: Tue, 15 Jan 2019 16:18:18 +0100
Subject: Test FlakeID old id compat & Ecto type
---
test/flake_id_test.exs | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
create mode 100644 test/flake_id_test.exs
(limited to 'test')
diff --git a/test/flake_id_test.exs b/test/flake_id_test.exs
new file mode 100644
index 000000000..e480fbdf3
--- /dev/null
+++ b/test/flake_id_test.exs
@@ -0,0 +1,41 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.FlakeIdTest do
+ use Pleroma.DataCase
+ import Kernel, except: [to_string: 1]
+ import Pleroma.FlakeId
+
+ describe "fake flakes (compatibility with older serial integers)" do
+ test "from_string/1" do
+ fake_flake = <<0::integer-size(64), 42::integer-size(64)>>
+ assert from_string("42") == fake_flake
+ end
+
+ test "zero or -1 is a null flake" do
+ fake_flake = <<0::integer-size(128)>>
+ assert from_string("0") == fake_flake
+ assert from_string("-1") == fake_flake
+ end
+
+ test "to_string/1" do
+ fake_flake = <<0::integer-size(64), 42::integer-size(64)>>
+ assert to_string(fake_flake) == "42"
+ end
+ end
+
+ test "ecto type behaviour" do
+ flake = <<0, 0, 1, 104, 80, 229, 2, 235, 140, 22, 69, 201, 53, 210, 0, 0>>
+ flake_s = "9eoozpwTul5mjSEDRI"
+
+ assert cast(flake) == {:ok, flake_s}
+ assert cast(flake_s) == {:ok, flake_s}
+
+ assert load(flake) == {:ok, flake_s}
+ assert load(flake_s) == {:ok, flake_s}
+
+ assert dump(flake_s) == {:ok, flake}
+ assert dump(flake) == {:ok, flake}
+ end
+end
--
cgit v1.2.3
From 422e60ad7693ecc06f5fe6dfd65a61caf338e6b6 Mon Sep 17 00:00:00 2001
From: href
Date: Tue, 15 Jan 2019 16:42:33 +0100
Subject: 2019
---
test/flake_id_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/flake_id_test.exs b/test/flake_id_test.exs
index e480fbdf3..8e969fd1c 100644
--- a/test/flake_id_test.exs
+++ b/test/flake_id_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.FlakeIdTest do
--
cgit v1.2.3
From e221c681dcd387aa445c35957a32fdc0189a0955 Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 23 Jan 2019 12:40:57 +0100
Subject: New frontend configuration mechanism.
---
test/web/twitter_api/util_controller_test.exs | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index 73aa70bd5..c099db003 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -32,4 +32,27 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
assert response == "job started"
end
end
+
+ describe "GET /api/pleroma/frontent_configurations" do
+ test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} do
+ config = [
+ frontend_a: %{
+ x: 1,
+ y: 2
+ },
+ frontend_b: %{
+ z: 3
+ }
+ ]
+
+ Pleroma.Config.put(:frontend_configurations, config)
+
+ response =
+ conn
+ |> get("/api/pleroma/frontend_configurations")
+ |> json_response(:ok)
+
+ assert response == Jason.encode!(config |> Enum.into(%{})) |> Jason.decode!()
+ end
+ end
end
--
cgit v1.2.3
From 4333fea1dc2942526c78d97f3e8694fdc79b0575 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Wed, 23 Jan 2019 19:47:51 +0300
Subject: Send "hide_network" in user_view
---
test/web/twitter_api/views/user_view_test.exs | 4 ++++
1 file changed, 4 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 5f7481eb6..daf18c1c5 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -100,6 +100,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
+ "hide_network" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
@@ -146,6 +147,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
+ "hide_network" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
@@ -193,6 +195,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
+ "hide_network" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
@@ -254,6 +257,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
+ "hide_network" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
--
cgit v1.2.3
From 13d72826dfe3eab3b08f58800c63effb1e3cdfd6 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Thu, 24 Jan 2019 09:50:40 +0000
Subject: test: add anti-followbot policy tests
---
.../mrf/anti_followbot_policy_test.exs | 57 ++++++++++++++++++++++
1 file changed, 57 insertions(+)
create mode 100644 test/web/activity_pub/mrf/anti_followbot_policy_test.exs
(limited to 'test')
diff --git a/test/web/activity_pub/mrf/anti_followbot_policy_test.exs b/test/web/activity_pub/mrf/anti_followbot_policy_test.exs
new file mode 100644
index 000000000..2ea4f9d3f
--- /dev/null
+++ b/test/web/activity_pub/mrf/anti_followbot_policy_test.exs
@@ -0,0 +1,57 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicyTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+
+ alias Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy
+
+ describe "blocking based on attributes" do
+ test "matches followbots by nickname" do
+ actor = insert(:user, %{nickname: "followbot@example.com"})
+ target = insert(:user)
+
+ message = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "type" => "Follow",
+ "actor" => actor.ap_id,
+ "object" => target.ap_id,
+ "id" => "https://example.com/activities/1234"
+ }
+
+ {:reject, nil} = AntiFollowbotPolicy.filter(message)
+ end
+
+ test "matches followbots by display name" do
+ actor = insert(:user, %{name: "Federation Bot"})
+ target = insert(:user)
+
+ message = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "type" => "Follow",
+ "actor" => actor.ap_id,
+ "object" => target.ap_id,
+ "id" => "https://example.com/activities/1234"
+ }
+
+ {:reject, nil} = AntiFollowbotPolicy.filter(message)
+ end
+ end
+
+ test "it allows non-followbots" do
+ actor = insert(:user)
+ target = insert(:user)
+
+ message = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "type" => "Follow",
+ "actor" => actor.ap_id,
+ "object" => target.ap_id,
+ "id" => "https://example.com/activities/1234"
+ }
+
+ {:ok, _} = AntiFollowbotPolicy.filter(message)
+ end
+end
--
cgit v1.2.3
From 9274cabe01977a3c2d35059d7889c63e2bd54de1 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Thu, 24 Jan 2019 23:30:43 +0300
Subject: Use correct logic to determine "attentions" list
---
test/web/twitter_api/views/activity_view_test.exs | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 0f514dab1..8b5a16add 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -118,8 +118,9 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
expected = %{
"activity_type" => "post",
"attachments" => [],
- "attentions" =>
- Enum.map([other_user, user], fn u -> UserView.render("show.json", %{user: u}) end),
+ "attentions" => [
+ UserView.render("show.json", %{user: other_user})
+ ],
"created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(),
"external_url" => activity.data["object"]["id"],
"fave_num" => 0,
--
cgit v1.2.3
From a45a90348046902df831d3a69f98677d8a0329db Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Fri, 25 Jan 2019 10:51:06 +0300
Subject: Fix OGP provider tests
---
test/web/metadata/opengraph_test.exs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/metadata/opengraph_test.exs b/test/web/metadata/opengraph_test.exs
index c3502bad3..4283f72cd 100644
--- a/test/web/metadata/opengraph_test.exs
+++ b/test/web/metadata/opengraph_test.exs
@@ -48,7 +48,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
}
})
- result = OpenGraph.build_tags(%{object: note, user: user})
+ result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
assert Enum.all?(
[
@@ -85,7 +85,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
}
})
- result = OpenGraph.build_tags(%{object: note, user: user})
+ result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user})
assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result
--
cgit v1.2.3
From aa8ddfdbe2303375e3f019faca30a620bfc58fc7 Mon Sep 17 00:00:00 2001
From: lain
Date: Fri, 25 Jan 2019 17:55:24 +0100
Subject: SPC fixes: Fix activities.
---
test/spc_fixes_test.exs | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/spc_fixes_test.exs b/test/spc_fixes_test.exs
index 01629e374..76c081248 100644
--- a/test/spc_fixes_test.exs
+++ b/test/spc_fixes_test.exs
@@ -9,6 +9,8 @@ defmodule Pleroma.SpcFixesTest do
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.User
+ alias Pleroma.Activity
+ alias Pleroma.Repo
import Pleroma.Factory
@@ -33,6 +35,7 @@ defmodule Pleroma.SpcFixesTest do
other_user = insert(:user)
{:ok, other_user} = User.follow(other_user, user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "blabla"})
+ {:ok, _other_activity} = CommonAPI.post(other_user, %{"status" => "blabla"})
assert User.following?(other_user, user)
assert [activity] == ActivityPub.fetch_activities(other_user.following)
@@ -45,8 +48,19 @@ defmodule Pleroma.SpcFixesTest do
assert user.ap_id == "https://shitposter.club/users/zep"
assert user.follower_address == "https://shitposter.club/users/zep/followers"
+ aid = activity.id
# Activites and following are correctly stitched.
assert User.following?(other_user, user)
- assert [activity] == ActivityPub.fetch_activities(other_user.following) |> IO.inspect()
+ assert [%{id: ^aid}] = ActivityPub.fetch_activities(other_user.following)
+
+ third_user = insert(:user)
+ {:ok, third_user} = User.follow(third_user, user)
+ assert [%{id: ^aid}] = ActivityPub.fetch_activities(third_user.following)
+
+ activity = Repo.get(Activity, aid)
+
+ assert activity.data["actor"] == user.ap_id
+ assert user.follower_address in activity.recipients
+ assert user.follower_address in activity.data["to"]
end
end
--
cgit v1.2.3
From d99650270b980c006690a7051a2d5cffe07779f1 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Fri, 25 Jan 2019 20:38:54 +0300
Subject: [#534] Federation reachability filtering tests.
---
test/support/factory.ex | 2 +-
.../activity_pub/activity_pub_controller_test.exs | 44 ++++++++-
test/web/federator_test.exs | 101 ++++++++++++++++++-
test/web/ostatus/ostatus_controller_test.exs | 108 ++++++++++++---------
test/web/websub/websub_controller_test.exs | 84 ++++++++++------
5 files changed, 259 insertions(+), 80 deletions(-)
(limited to 'test')
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 4ac77981a..964b2b61c 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -193,7 +193,7 @@ defmodule Pleroma.Factory do
def websub_subscription_factory do
%Pleroma.Web.Websub.WebsubServerSubscription{
topic: "http://example.org",
- callback: "http://example/org/callback",
+ callback: "http://example.org/callback",
secret: "here's a secret",
valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), 100),
state: "requested"
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 52e67f046..1b704330f 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -6,8 +6,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
alias Pleroma.Web.ActivityPub.{UserView, ObjectView}
- alias Pleroma.{Object, Repo, User}
- alias Pleroma.Activity
+ alias Pleroma.{Object, Repo, Activity, User, Instances}
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
@@ -144,6 +143,24 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
:timer.sleep(500)
assert Activity.get_by_ap_id(data["id"])
end
+
+ test "it clears `unreachable` federation status of the sender", %{conn: conn} do
+ sender_url = "https://pleroma.soykaf.com"
+ Instances.set_unreachable(sender_url, Instances.reachability_datetime_threshold())
+ refute Instances.reachable?(sender_url)
+
+ data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
+
+ conn =
+ conn
+ |> assign(:valid_signature, true)
+ |> put_req_header("content-type", "application/activity+json")
+ |> put_req_header("referer", sender_url)
+ |> post("/inbox", data)
+
+ assert "ok" == json_response(conn, 200)
+ assert Instances.reachable?(sender_url)
+ end
end
describe "/users/:nickname/inbox" do
@@ -191,6 +208,29 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert response(conn, 200) =~ note_activity.data["object"]["content"]
end
+
+ test "it clears `unreachable` federation status of the sender", %{conn: conn} do
+ sender_host = "pleroma.soykaf.com"
+ Instances.set_unreachable(sender_host, Instances.reachability_datetime_threshold())
+ refute Instances.reachable?(sender_host)
+
+ user = insert(:user)
+
+ data =
+ File.read!("test/fixtures/mastodon-post-activity.json")
+ |> Poison.decode!()
+ |> Map.put("bcc", [user.ap_id])
+
+ conn =
+ conn
+ |> assign(:valid_signature, true)
+ |> put_req_header("content-type", "application/activity+json")
+ |> put_req_header("referer", "https://#{sender_host}")
+ |> post("/users/#{user.nickname}/inbox", data)
+
+ assert "ok" == json_response(conn, 200)
+ assert Instances.reachable?(sender_host)
+ end
end
describe "/users/:nickname/outbox" do
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index a49265c0c..f4234aea8 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -3,8 +3,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.FederatorTest do
- alias Pleroma.Web.Federator
- alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.{CommonAPI, Federator}
+ alias Pleroma.Instances
use Pleroma.DataCase
import Pleroma.Factory
import Mock
@@ -71,6 +71,103 @@ defmodule Pleroma.Web.FederatorTest do
end
end
+ describe "Targets reachability filtering in `publish`" do
+ test_with_mock "it federates only to reachable instances via AP",
+ Federator,
+ [:passthrough],
+ [] do
+ user = insert(:user)
+
+ {inbox1, inbox2} =
+ {"https://domain.com/users/nick1/inbox", "https://domain2.com/users/nick2/inbox"}
+
+ insert(:user, %{
+ local: false,
+ nickname: "nick1@domain.com",
+ ap_id: "https://domain.com/users/nick1",
+ info: %{ap_enabled: true, source_data: %{"inbox" => inbox1}}
+ })
+
+ insert(:user, %{
+ local: false,
+ nickname: "nick2@domain2.com",
+ ap_id: "https://domain2.com/users/nick2",
+ info: %{ap_enabled: true, source_data: %{"inbox" => inbox2}}
+ })
+
+ Instances.set_unreachable(
+ URI.parse(inbox2).host,
+ Instances.reachability_datetime_threshold()
+ )
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
+
+ assert called(Federator.enqueue(:publish_single_ap, %{inbox: inbox1}))
+ refute called(Federator.enqueue(:publish_single_ap, %{inbox: inbox2}))
+ end
+
+ test_with_mock "it federates only to reachable instances via Websub",
+ Federator,
+ [:passthrough],
+ [] do
+ user = insert(:user)
+ websub_topic = Pleroma.Web.OStatus.feed_path(user)
+
+ sub1 =
+ insert(:websub_subscription, %{
+ topic: websub_topic,
+ state: "active",
+ callback: "http://pleroma.soykaf.com/cb"
+ })
+
+ sub2 =
+ insert(:websub_subscription, %{
+ topic: websub_topic,
+ state: "active",
+ callback: "https://pleroma2.soykaf.com/cb"
+ })
+
+ Instances.set_unreachable(sub1.callback, Instances.reachability_datetime_threshold())
+
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => "HI"})
+
+ assert called(Federator.enqueue(:publish_single_websub, %{callback: sub2.callback}))
+ refute called(Federator.enqueue(:publish_single_websub, %{callback: sub1.callback}))
+ end
+
+ test_with_mock "it federates only to reachable instances via Salmon",
+ Federator,
+ [:passthrough],
+ [] do
+ user = insert(:user)
+
+ remote_user1 =
+ insert(:user, %{
+ local: false,
+ nickname: "nick1@domain.com",
+ ap_id: "https://domain.com/users/nick1",
+ info: %{salmon: "https://domain.com/salmon"}
+ })
+
+ remote_user2 =
+ insert(:user, %{
+ local: false,
+ nickname: "nick2@domain2.com",
+ ap_id: "https://domain2.com/users/nick2",
+ info: %{salmon: "https://domain2.com/salmon"}
+ })
+
+ Instances.set_unreachable("domain.com", Instances.reachability_datetime_threshold())
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
+
+ assert called(Federator.enqueue(:publish_single_salmon, {remote_user2, :_, :_}))
+ refute called(Federator.enqueue(:publish_single_websub, {remote_user1, :_, :_}))
+ end
+ end
+
describe "Receive an activity" do
test "successfully processes incoming AP docs with correct origin" do
params = %{
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index 995cc00d6..ca447aa5d 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -5,7 +5,7 @@
defmodule Pleroma.Web.OStatus.OStatusControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
- alias Pleroma.{User, Repo, Object}
+ alias Pleroma.{User, Repo, Object, Instances}
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OStatus.ActivityRepresenter
@@ -14,49 +14,69 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
:ok
end
- test "decodes a salmon", %{conn: conn} do
- user = insert(:user)
- salmon = File.read!("test/fixtures/salmon.xml")
-
- conn =
- conn
- |> put_req_header("content-type", "application/atom+xml")
- |> post("/users/#{user.nickname}/salmon", salmon)
-
- assert response(conn, 200)
- end
-
- test "decodes a salmon with a changed magic key", %{conn: conn} do
- user = insert(:user)
- salmon = File.read!("test/fixtures/salmon.xml")
-
- conn =
- conn
- |> put_req_header("content-type", "application/atom+xml")
- |> post("/users/#{user.nickname}/salmon", salmon)
-
- assert response(conn, 200)
-
- # Set a wrong magic-key for a user so it has to refetch
- salmon_user = User.get_by_ap_id("http://gs.example.org:4040/index.php/user/1")
- # Wrong key
- info_cng =
- User.Info.remote_user_creation(salmon_user.info, %{
- magic_key:
- "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
- })
-
- salmon_user
- |> Ecto.Changeset.change()
- |> Ecto.Changeset.put_embed(:info, info_cng)
- |> Repo.update()
-
- conn =
- build_conn()
- |> put_req_header("content-type", "application/atom+xml")
- |> post("/users/#{user.nickname}/salmon", salmon)
-
- assert response(conn, 200)
+ describe "salmon_incoming" do
+ test "decodes a salmon", %{conn: conn} do
+ user = insert(:user)
+ salmon = File.read!("test/fixtures/salmon.xml")
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/atom+xml")
+ |> post("/users/#{user.nickname}/salmon", salmon)
+
+ assert response(conn, 200)
+ end
+
+ test "decodes a salmon with a changed magic key", %{conn: conn} do
+ user = insert(:user)
+ salmon = File.read!("test/fixtures/salmon.xml")
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/atom+xml")
+ |> post("/users/#{user.nickname}/salmon", salmon)
+
+ assert response(conn, 200)
+
+ # Set a wrong magic-key for a user so it has to refetch
+ salmon_user = User.get_by_ap_id("http://gs.example.org:4040/index.php/user/1")
+ # Wrong key
+ info_cng =
+ User.Info.remote_user_creation(salmon_user.info, %{
+ magic_key:
+ "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
+ })
+
+ salmon_user
+ |> Ecto.Changeset.change()
+ |> Ecto.Changeset.put_embed(:info, info_cng)
+ |> Repo.update()
+
+ conn =
+ build_conn()
+ |> put_req_header("content-type", "application/atom+xml")
+ |> post("/users/#{user.nickname}/salmon", salmon)
+
+ assert response(conn, 200)
+ end
+
+ test "it clears `unreachable` federation status of the sender", %{conn: conn} do
+ sender_url = "https://pleroma.soykaf.com"
+ Instances.set_unreachable(sender_url, Instances.reachability_datetime_threshold())
+ refute Instances.reachable?(sender_url)
+
+ user = insert(:user)
+ salmon = File.read!("test/fixtures/salmon.xml")
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/atom+xml")
+ |> put_req_header("referer", sender_url)
+ |> post("/users/#{user.nickname}/salmon", salmon)
+
+ assert response(conn, 200)
+ assert Instances.reachable?(sender_url)
+ end
end
test "gets a feed", %{conn: conn} do
diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs
index 9cbcda063..c445ed676 100644
--- a/test/web/websub/websub_controller_test.exs
+++ b/test/web/websub/websub_controller_test.exs
@@ -6,7 +6,7 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
alias Pleroma.Web.Websub.WebsubClientSubscription
- alias Pleroma.{Repo, Activity}
+ alias Pleroma.{Repo, Activity, Instances}
alias Pleroma.Web.Websub
test "websub subscription request", %{conn: conn} do
@@ -50,35 +50,57 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
assert_in_delta NaiveDateTime.diff(websub.valid_until, NaiveDateTime.utc_now()), 100, 5
end
- test "handles incoming feed updates", %{conn: conn} do
- websub = insert(:websub_client_subscription)
- doc = "some stuff"
- signature = Websub.sign(websub.secret, doc)
-
- conn =
- conn
- |> put_req_header("x-hub-signature", "sha1=" <> signature)
- |> put_req_header("content-type", "application/atom+xml")
- |> post("/push/subscriptions/#{websub.id}", doc)
-
- assert response(conn, 200) == "OK"
-
- assert length(Repo.all(Activity)) == 1
- end
-
- test "rejects incoming feed updates with the wrong signature", %{conn: conn} do
- websub = insert(:websub_client_subscription)
- doc = "some stuff"
- signature = Websub.sign("wrong secret", doc)
-
- conn =
- conn
- |> put_req_header("x-hub-signature", "sha1=" <> signature)
- |> put_req_header("content-type", "application/atom+xml")
- |> post("/push/subscriptions/#{websub.id}", doc)
-
- assert response(conn, 500) == "Error"
-
- assert length(Repo.all(Activity)) == 0
+ describe "websub_incoming" do
+ test "handles incoming feed updates", %{conn: conn} do
+ websub = insert(:websub_client_subscription)
+ doc = "some stuff"
+ signature = Websub.sign(websub.secret, doc)
+
+ conn =
+ conn
+ |> put_req_header("x-hub-signature", "sha1=" <> signature)
+ |> put_req_header("content-type", "application/atom+xml")
+ |> post("/push/subscriptions/#{websub.id}", doc)
+
+ assert response(conn, 200) == "OK"
+
+ assert length(Repo.all(Activity)) == 1
+ end
+
+ test "rejects incoming feed updates with the wrong signature", %{conn: conn} do
+ websub = insert(:websub_client_subscription)
+ doc = "some stuff"
+ signature = Websub.sign("wrong secret", doc)
+
+ conn =
+ conn
+ |> put_req_header("x-hub-signature", "sha1=" <> signature)
+ |> put_req_header("content-type", "application/atom+xml")
+ |> post("/push/subscriptions/#{websub.id}", doc)
+
+ assert response(conn, 500) == "Error"
+
+ assert length(Repo.all(Activity)) == 0
+ end
+
+ test "it clears `unreachable` federation status of the sender", %{conn: conn} do
+ sender_url = "https://pleroma.soykaf.com"
+ Instances.set_unreachable(sender_url, Instances.reachability_datetime_threshold())
+ refute Instances.reachable?(sender_url)
+
+ websub = insert(:websub_client_subscription)
+ doc = "some stuff"
+ signature = Websub.sign(websub.secret, doc)
+
+ conn =
+ conn
+ |> put_req_header("x-hub-signature", "sha1=" <> signature)
+ |> put_req_header("content-type", "application/atom+xml")
+ |> put_req_header("referer", sender_url)
+ |> post("/push/subscriptions/#{websub.id}", doc)
+
+ assert response(conn, 200) == "OK"
+ assert Instances.reachable?(sender_url)
+ end
end
end
--
cgit v1.2.3
From 499a4591a4689094bff597e30ce599a6fc189ea3 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Sat, 26 Jan 2019 04:23:52 +0100
Subject: Web.ActivityPub.ActivityPubTest: test against inserting activities
with content: null
---
test/web/activity_pub/activity_pub_test.exs | 11 +++++++++++
1 file changed, 11 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index d2e54d804..91548ab5f 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -85,6 +85,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert {:error, {:remote_limit_error, _}} = ActivityPub.insert(data)
end
+ test "doesn't drop activities with content being null" do
+ data = %{
+ "ok" => true,
+ "object" => %{
+ "content" => nil
+ }
+ }
+
+ assert {:ok, _} = ActivityPub.insert(data)
+ end
+
test "returns the activity if one with the same id is already in" do
activity = insert(:note_activity)
{:ok, new_activity} = ActivityPub.insert(activity.data)
--
cgit v1.2.3
From d8f446f438716cc1a474c9352e8cca8778a48d85 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Fri, 21 Dec 2018 19:34:08 +0100
Subject: Web.MastodonAPI.MastodonAPIControllerTest: Add test against
multi-hashtag timeline
---
.../mastodon_api/mastodon_api_controller_test.exs | 24 ++++++++++++++++++++++
1 file changed, 24 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 6004285d6..be868c081 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1044,6 +1044,30 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end)
end
+ test "multi-hashtag timeline", %{conn: conn} do
+ user = insert(:user)
+
+ {:ok, activity_test} = CommonAPI.post(user, %{"status" => "#test"})
+ {:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test1"})
+ {:ok, activity_none} = CommonAPI.post(user, %{"status" => "#test #none"})
+
+ all_test =
+ conn
+ |> get("/api/v1/timelines/tag/test", %{"all" => ["test1"]})
+
+ assert [status_none, status_test1, status_test] = json_response(all_test, 200)
+
+ assert to_string(activity_test.id) == status_test["id"]
+ assert to_string(activity_test1.id) == status_test1["id"]
+ assert to_string(activity_none.id) == status_none["id"]
+
+ restricted_test =
+ conn
+ |> get("/api/v1/timelines/tag/test", %{"all" => ["test1"], "none" => ["none"]})
+
+ assert [status_test1, status_test] == json_response(restricted_test, 200)
+ end
+
test "getting followers", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
--
cgit v1.2.3
From 4ad0ad14ed2d8a10bbf642fd989b3f7f55f9017d Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Thu, 10 Jan 2019 16:07:32 +0100
Subject: Web.ActivityPub.ActivityPub: Simplify multi-hashtag, add tests
---
test/web/activity_pub/activity_pub_test.exs | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index d2e54d804..acece36f0 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -64,6 +64,27 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert user.info.ap_enabled
assert user.follower_address == "http://mastodon.example.org/users/admin/followers"
end
+
+ test "it fetches the appropriate tag-restricted posts" do
+ user = insert(:user)
+
+ {:ok, status_one} = CommonAPI.post(user, %{"status" => ". #test"})
+ {:ok, status_two} = CommonAPI.post(user, %{"status" => ". #essais"})
+ {:ok, status_three} = CommonAPI.post(user, %{"status" => ". #test #reject"})
+
+ fetch_one = ActivityPub.fetch_activities([], %{"tag" => "test"})
+ fetch_two = ActivityPub.fetch_activities([], %{"tag" => ["test", "essais"]})
+
+ fetch_three =
+ ActivityPub.fetch_activities([], %{
+ "tag" => ["test", "essais"],
+ "tag_reject" => ["reject"]
+ })
+
+ assert fetch_one == [status_one, status_three]
+ assert fetch_two == [status_one, status_two, status_three]
+ assert fetch_three == [status_one, status_two]
+ end
end
describe "insertion" do
--
cgit v1.2.3
From 5a84def6a6cd6ac782e16b2aace220a99c31ace7 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Thu, 10 Jan 2019 16:44:28 +0100
Subject: Fix the logic in multi-hashtag TLs
---
test/web/activity_pub/activity_pub_test.exs | 7 +++++++
test/web/mastodon_api/mastodon_api_controller_test.exs | 10 +++++++---
2 files changed, 14 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index acece36f0..48eed3f13 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -81,9 +81,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
"tag_reject" => ["reject"]
})
+ fetch_four =
+ ActivityPub.fetch_activities([], %{
+ "tag" => ["test"],
+ "tag_all" => ["test", "reject"]
+ })
+
assert fetch_one == [status_one, status_three]
assert fetch_two == [status_one, status_two, status_three]
assert fetch_three == [status_one, status_two]
+ assert fetch_four == [status_three]
end
end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index be868c081..b4870e0b2 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1051,11 +1051,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test1"})
{:ok, activity_none} = CommonAPI.post(user, %{"status" => "#test #none"})
- all_test =
+ any_test =
conn
- |> get("/api/v1/timelines/tag/test", %{"all" => ["test1"]})
+ |> get("/api/v1/timelines/tag/test", %{"any" => ["none"]})
- assert [status_none, status_test1, status_test] = json_response(all_test, 200)
+ [status_none, status_test1, status_test] = json_response(any_test, 200)
assert to_string(activity_test.id) == status_test["id"]
assert to_string(activity_test1.id) == status_test1["id"]
@@ -1066,6 +1066,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> get("/api/v1/timelines/tag/test", %{"all" => ["test1"], "none" => ["none"]})
assert [status_test1, status_test] == json_response(restricted_test, 200)
+
+ all_test = conn |> get("/api/v1/timelines/tag/test", %{"all" => ["none"]})
+
+ assert [status_none] == json_response(all_test, 200)
end
test "getting followers", %{conn: conn} do
--
cgit v1.2.3
From 22f2687f176a90d0d7d54d002e972d5f036c4579 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Tue, 22 Jan 2019 15:42:46 +0100
Subject: Web.MastodonAPI.MastodonAPIControllerTest: Update for difference
between all and any parameters
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index b4870e0b2..3ca8d4651 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1048,12 +1048,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = insert(:user)
{:ok, activity_test} = CommonAPI.post(user, %{"status" => "#test"})
- {:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test1"})
+ {:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test #test1"})
{:ok, activity_none} = CommonAPI.post(user, %{"status" => "#test #none"})
any_test =
conn
- |> get("/api/v1/timelines/tag/test", %{"any" => ["none"]})
+ |> get("/api/v1/timelines/tag/test", %{"any" => ["test1"]})
[status_none, status_test1, status_test] = json_response(any_test, 200)
@@ -1065,7 +1065,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
conn
|> get("/api/v1/timelines/tag/test", %{"all" => ["test1"], "none" => ["none"]})
- assert [status_test1, status_test] == json_response(restricted_test, 200)
+ assert [status_test1] == json_response(restricted_test, 200)
all_test = conn |> get("/api/v1/timelines/tag/test", %{"all" => ["none"]})
--
cgit v1.2.3
From d9f3af477d687fb8cb469ec652586911ad51d0b0 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Mon, 14 Jan 2019 00:05:45 +0100
Subject: Move definitions of RichMedia fixtures to
test/support/http_request_mock.ex
---
test/support/http_request_mock.ex | 8 ++++++++
.../controllers/rich_media_controller_test.exs | 17 ++++++-----------
2 files changed, 14 insertions(+), 11 deletions(-)
(limited to 'test')
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index e4279e14d..3043d2be6 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -653,6 +653,14 @@ defmodule HttpRequestMock do
{:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
end
+ def get("http://example.com/ogp", _, _, _) do
+ {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
+ end
+
+ def get("http://example.com/empty", _, _, _) do
+ {:ok, %Tesla.Env{status: 200, body: "hello"}}
+ end
+
def get(url, query, body, headers) do
{:error,
"Not implemented the mock response for get #{inspect(url)}, #{query}, #{inspect(body)}, #{
diff --git a/test/web/rich_media/controllers/rich_media_controller_test.exs b/test/web/rich_media/controllers/rich_media_controller_test.exs
index 37c82631f..fef126513 100644
--- a/test/web/rich_media/controllers/rich_media_controller_test.exs
+++ b/test/web/rich_media/controllers/rich_media_controller_test.exs
@@ -1,19 +1,14 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.RichMedia.RichMediaControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
+ import Tesla.Mock
setup do
- Tesla.Mock.mock(fn
- %{
- method: :get,
- url: "http://example.com/ogp"
- } ->
- %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}
-
- %{method: :get, url: "http://example.com/empty"} ->
- %Tesla.Env{status: 200, body: "hello"}
- end)
-
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok
end
--
cgit v1.2.3
From 3f64379b1382f2e26cacd28da230c67bf68656a0 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Mon, 14 Jan 2019 00:06:55 +0100
Subject: Web.MastodonAPI.MastodonAPIController: Add Rich-Media support
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 6004285d6..bc87383f7 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1623,5 +1623,21 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> post("/api/v1/statuses/#{activity_two.id}/pin")
|> json_response(400)
end
+
+ test "Status rich-media Card", %{conn: conn, user: user} do
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "http://example.com/ogp"})
+
+ response =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}/card")
+ |> json_response(200)
+
+ assert response == %{
+ "image" => "http://ia.media-imdb.com/images/rock.jpg",
+ "title" => "The Rock",
+ "type" => "link",
+ "url" => "http://www.imdb.com/title/tt0117500/"
+ }
+ end
end
end
--
cgit v1.2.3
From 1f7843b9b8afcb559c8ba59388724dbf4ef3e3c9 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sat, 26 Jan 2019 15:20:27 +0000
Subject: mastodon api: use OGP uri instead of page_url for deducing domain
name, fix test
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 1 +
1 file changed, 1 insertion(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index bc87383f7..55e778e4f 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1634,6 +1634,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert response == %{
"image" => "http://ia.media-imdb.com/images/rock.jpg",
+ "provider_name" => "www.imdb.com",
"title" => "The Rock",
"type" => "link",
"url" => "http://www.imdb.com/title/tt0117500/"
--
cgit v1.2.3
From d6015338c8fea62602e969a498b80c2a5b754909 Mon Sep 17 00:00:00 2001
From: href
Date: Sat, 26 Jan 2019 16:58:23 +0100
Subject: Flake: support integers in from_string/1
Some previously issued stateless tokens have integer ids in them.
---
test/flake_id_test.exs | 1 +
1 file changed, 1 insertion(+)
(limited to 'test')
diff --git a/test/flake_id_test.exs b/test/flake_id_test.exs
index 8e969fd1c..ca2338041 100644
--- a/test/flake_id_test.exs
+++ b/test/flake_id_test.exs
@@ -11,6 +11,7 @@ defmodule Pleroma.FlakeIdTest do
test "from_string/1" do
fake_flake = <<0::integer-size(64), 42::integer-size(64)>>
assert from_string("42") == fake_flake
+ assert from_string(42) == fake_flake
end
test "zero or -1 is a null flake" do
--
cgit v1.2.3
From a65c18859307f4aacf42eb5dd14e63ad76747a6d Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Sun, 27 Jan 2019 10:21:13 +0100
Subject: Web.MastodonAPI.AccountView: Add is_moderator and is_admin
Closes: https://git.pleroma.social/pleroma/pleroma/issues/557
---
test/web/mastodon_api/account_view_test.exs | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index d53e11963..f8cd68173 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -61,7 +61,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
},
pleroma: %{
confirmation_pending: false,
- tags: []
+ tags: [],
+ is_admin: false,
+ is_moderator: false
}
}
@@ -102,7 +104,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
},
pleroma: %{
confirmation_pending: false,
- tags: []
+ tags: [],
+ is_admin: false,
+ is_moderator: false
}
}
--
cgit v1.2.3
From 2e277dd4ad96ef6f7ce3267eb05d0b84668df772 Mon Sep 17 00:00:00 2001
From: lain
Date: Sun, 27 Jan 2019 21:03:15 +0100
Subject: Fix objects.
---
test/spc_fixes_test.exs | 6 ++++++
1 file changed, 6 insertions(+)
(limited to 'test')
diff --git a/test/spc_fixes_test.exs b/test/spc_fixes_test.exs
index 76c081248..67ab54ccf 100644
--- a/test/spc_fixes_test.exs
+++ b/test/spc_fixes_test.exs
@@ -11,6 +11,7 @@ defmodule Pleroma.SpcFixesTest do
alias Pleroma.User
alias Pleroma.Activity
alias Pleroma.Repo
+ alias Pleroma.Object
import Pleroma.Factory
@@ -62,5 +63,10 @@ defmodule Pleroma.SpcFixesTest do
assert activity.data["actor"] == user.ap_id
assert user.follower_address in activity.recipients
assert user.follower_address in activity.data["to"]
+
+ object = Object.get_by_ap_id(activity.data["object"]["id"])
+
+ assert object.data["actor"] == user.ap_id
+ assert user.follower_address in object.data["to"]
end
end
--
cgit v1.2.3
From cda1470e02100bfcdcbd128fd08d0af64dca7271 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Wed, 19 Sep 2018 02:04:56 +0200
Subject: [MastoAPI][GlitchAPI] Add bookmarks
---
test/user_test.exs | 27 ++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 51 ++++++++++++++++++++++
test/web/mastodon_api/status_view_test.exs | 1 +
3 files changed, 79 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index a0657c7b6..b33398ff6 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -945,4 +945,31 @@ defmodule Pleroma.UserTest do
assert expected_text == User.parse_bio(bio, user)
end
end
+
+ test "bookmarks" do
+ user = insert(:user)
+
+ {:ok, activity1} =
+ CommonAPI.post(user, %{
+ "status" => "heweoo!"
+ })
+
+ id1 = activity1.data["object"]["id"]
+
+ {:ok, activity2} =
+ CommonAPI.post(user, %{
+ "status" => "heweoo!"
+ })
+
+ id2 = activity2.data["object"]["id"]
+
+ assert {:ok, user_state1} = User.bookmark(user, id1)
+ assert user_state1.bookmarks == [id1]
+
+ assert {:ok, user_state2} = User.unbookmark(user, id1)
+ assert user_state2.bookmarks == []
+
+ assert {:ok, user_state3} = User.bookmark(user, id2)
+ assert user_state3.bookmarks == [id2]
+ end
end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index b8f901e6c..edc74d802 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1669,4 +1669,55 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
}
end
end
+
+ test "bookmarks" do
+ user = insert(:user)
+ for_user = insert(:user)
+
+ {:ok, activity1} =
+ CommonAPI.post(user, %{
+ "status" => "heweoo?"
+ })
+
+ {:ok, activity2} =
+ CommonAPI.post(user, %{
+ "status" => "heweoo!"
+ })
+
+ response1 =
+ build_conn()
+ |> assign(:user, for_user)
+ |> post("/api/v1/statuses/#{activity1.id}/bookmark")
+
+ assert json_response(response1, 200)["bookmarked"] == true
+
+ response2 =
+ build_conn()
+ |> assign(:user, for_user)
+ |> post("/api/v1/statuses/#{activity2.id}/bookmark")
+
+ assert json_response(response2, 200)["bookmarked"] == true
+
+ bookmarks =
+ build_conn()
+ |> assign(:user, for_user)
+ |> get("/api/v1/bookmarks")
+
+ assert [json_response(response2, 200), json_response(response1, 200)] ==
+ json_response(bookmarks, 200)
+
+ response1 =
+ build_conn()
+ |> assign(:user, for_user)
+ |> post("/api/v1/statuses/#{activity1.id}/unbookmark")
+
+ assert json_response(response1, 200)["bookmarked"] == false
+
+ bookmarks =
+ build_conn()
+ |> assign(:user, for_user)
+ |> get("/api/v1/bookmarks")
+
+ assert [json_response(response2, 200)] == json_response(bookmarks, 200)
+ end
end
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index ebf6273e8..f054ded1c 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -91,6 +91,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
replies_count: 0,
favourites_count: 0,
reblogged: false,
+ bookmarked: false,
favourited: false,
muted: false,
pinned: false,
--
cgit v1.2.3
From 132d815f1f749cec4b54083fc46046c45e7d0d04 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 27 Jan 2019 09:37:11 +0000
Subject: mastodon api: factor out status card fetching, move status card
rendering to statusview, add opengraph extended data
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index b8f901e6c..02a0eb228 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1663,9 +1663,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert response == %{
"image" => "http://ia.media-imdb.com/images/rock.jpg",
"provider_name" => "www.imdb.com",
+ "provider_url" => "http://www.imdb.com",
"title" => "The Rock",
"type" => "link",
- "url" => "http://www.imdb.com/title/tt0117500/"
+ "url" => "http://www.imdb.com/title/tt0117500/",
+ "description" => nil,
+ "pleroma" => %{
+ "opengraph" => %{
+ "image" => "http://ia.media-imdb.com/images/rock.jpg",
+ "title" => "The Rock",
+ "type" => "video.movie",
+ "url" => "http://www.imdb.com/title/tt0117500/"
+ }
+ }
}
end
end
--
cgit v1.2.3
From 364cf5369b711e15b9ec60c768dadc280969a962 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 27 Jan 2019 12:21:51 +0000
Subject: test: update mastodon status view tests
---
test/web/mastodon_api/status_view_test.exs | 1 +
1 file changed, 1 insertion(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index ebf6273e8..f957fedac 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -84,6 +84,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
account: AccountView.render("account.json", %{user: user}),
in_reply_to_id: nil,
in_reply_to_account_id: nil,
+ card: nil,
reblog: nil,
content: HtmlSanitizeEx.basic_html(note.data["object"]["content"]),
created_at: created_at,
--
cgit v1.2.3
From 020b3b29d998a6d2b960549c1ab9fb89d60cdd0f Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 27 Jan 2019 12:27:46 +0000
Subject: test: update twitterapi tests
---
test/web/twitter_api/representers/activity_representer_test.exs | 1 +
test/web/twitter_api/views/activity_view_test.exs | 3 ++-
2 files changed, 3 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index ef0294140..ea5813733 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -164,6 +164,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
"possibly_sensitive" => true,
"uri" => activity.data["object"]["id"],
"visibility" => "direct",
+ "card" => nil,
"summary" => "2hu :2hu:",
"summary_html" =>
"2hu "
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index ba053d20d..4f854ecaa 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -148,7 +148,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"text" => "Hey @shp!",
"uri" => activity.data["object"]["id"],
"user" => UserView.render("show.json", %{user: user}),
- "visibility" => "direct"
+ "visibility" => "direct",
+ "card" => nil
}
assert result == expected
--
cgit v1.2.3
From 6096846f5f33e1e81ef72c0f97b30c2745426c5d Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 27 Jan 2019 12:34:49 +0000
Subject: API: kill /api/rich_media/parse endpoint
---
.../controllers/rich_media_controller_test.exs | 49 ----------------------
1 file changed, 49 deletions(-)
delete mode 100644 test/web/rich_media/controllers/rich_media_controller_test.exs
(limited to 'test')
diff --git a/test/web/rich_media/controllers/rich_media_controller_test.exs b/test/web/rich_media/controllers/rich_media_controller_test.exs
deleted file mode 100644
index fef126513..000000000
--- a/test/web/rich_media/controllers/rich_media_controller_test.exs
+++ /dev/null
@@ -1,49 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.RichMedia.RichMediaControllerTest do
- use Pleroma.Web.ConnCase
- import Pleroma.Factory
- import Tesla.Mock
-
- setup do
- mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
- :ok
- end
-
- describe "GET /api/rich_media/parse" do
- setup do
- user = insert(:user)
-
- [user: user]
- end
-
- test "returns 404 if not metadata found", %{user: user} do
- build_conn()
- |> with_credentials(user.nickname, "test")
- |> get("/api/rich_media/parse", %{"url" => "http://example.com/empty"})
- |> json_response(404)
- end
-
- test "returns OGP metadata", %{user: user} do
- response =
- build_conn()
- |> with_credentials(user.nickname, "test")
- |> get("/api/rich_media/parse", %{"url" => "http://example.com/ogp"})
- |> json_response(200)
-
- assert response == %{
- "image" => "http://ia.media-imdb.com/images/rock.jpg",
- "title" => "The Rock",
- "type" => "video.movie",
- "url" => "http://www.imdb.com/title/tt0117500/"
- }
- end
- end
-
- defp with_credentials(conn, username, password) do
- header_content = "Basic " <> Base.encode64("#{username}:#{password}")
- put_req_header(conn, "authorization", header_content)
- end
-end
--
cgit v1.2.3
From 339c26e12ba7312d283191196888ca7a5ce81dfe Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Mon, 28 Jan 2019 06:19:00 +0000
Subject: test: add status posting with OGP link preview test
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 02a0eb228..1a5eb090c 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -136,6 +136,20 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert Repo.get(Activity, id)
end
+ test "posting a status with OGP link preview", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{
+ "status" => "http://example.com/ogp"
+ })
+
+ assert %{"id" => id, "card" => %{"title" => "The Rock"}} = json_response(conn, 200)
+ assert Repo.get(Activity, id)
+ end
+
test "posting a direct status", %{conn: conn} do
user1 = insert(:user)
user2 = insert(:user)
--
cgit v1.2.3
From 1825118fd46883cb2a9132b039925c160ad7e57b Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 28 Jan 2019 11:41:47 +0100
Subject: Correctly handle invalid credentials on auth login.
Closes #407
---
test/web/oauth/oauth_controller_test.exs | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
(limited to 'test')
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index ccd552258..e0d3cb55f 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -34,6 +34,31 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
assert Repo.get_by(Authorization, token: code)
end
+ test "correctly handles wrong credentials", %{conn: conn} do
+ user = insert(:user)
+ app = insert(:oauth_app)
+
+ result =
+ conn
+ |> post("/oauth/authorize", %{
+ "authorization" => %{
+ "name" => user.nickname,
+ "password" => "wrong",
+ "client_id" => app.client_id,
+ "redirect_uri" => app.redirect_uris,
+ "state" => "statepassed"
+ }
+ })
+ |> html_response(:unauthorized)
+
+ # Keep the details
+ assert result =~ app.client_id
+ assert result =~ app.redirect_uris
+
+ # Error message
+ assert result =~ "Invalid"
+ end
+
test "issues a token for an all-body request" do
user = insert(:user)
app = insert(:oauth_app)
--
cgit v1.2.3
From 8e8a1e1ba8a08bc297884fe085b4542a052d6d01 Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 28 Jan 2019 13:07:12 +0100
Subject: Return new-style config if old-style config is set to false.
This is in preparation for 1.0. We'll be able to switch the config to the new
mechanism on PleromaFE then as well.
---
test/web/twitter_api/util_controller_test.exs | 46 ++++++++++++++++++++++++++-
1 file changed, 45 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index c099db003..dc9bad369 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -33,7 +33,51 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
end
end
- describe "GET /api/pleroma/frontent_configurations" do
+ describe "GET /api/statusnet/config.json" do
+ test "it returns the managed config", %{conn: conn} do
+ Pleroma.Config.put([:instance, :managed_config], false)
+
+ response =
+ conn
+ |> get("/api/statusnet/config.json")
+ |> json_response(:ok)
+
+ refute response["site"]["pleromafe"]
+
+ Pleroma.Config.put([:instance, :managed_config], true)
+
+ response =
+ conn
+ |> get("/api/statusnet/config.json")
+ |> json_response(:ok)
+
+ assert response["site"]["pleromafe"]
+ end
+
+ test "if :pleroma, :fe is false, it returns the new style config settings", %{conn: conn} do
+ Pleroma.Config.put([:instance, :managed_config], true)
+ Pleroma.Config.put([:fe, :theme], "rei-ayanami-towel")
+ Pleroma.Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
+
+ response =
+ conn
+ |> get("/api/statusnet/config.json")
+ |> json_response(:ok)
+
+ assert response["site"]["pleromafe"]["theme"] == "rei-ayanami-towel"
+
+ Pleroma.Config.put([:fe], false)
+
+ response =
+ conn
+ |> get("/api/statusnet/config.json")
+ |> json_response(:ok)
+
+ assert response["site"]["pleromafe"]["theme"] == "asuka-hospital"
+ end
+ end
+
+ describe "GET /api/pleroma/frontend_configurations" do
test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} do
config = [
frontend_a: %{
--
cgit v1.2.3
From 1d2f41642cfec5710055bcf8409778bb362beecb Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Mon, 28 Jan 2019 15:25:06 +0300
Subject: [#534] Various tweaks. Tests for Instances and Instance.
---
test/support/factory.ex | 7 ++
test/support/http_request_mock.ex | 28 ++++++
.../activity_pub/activity_pub_controller_test.exs | 4 +-
test/web/activity_pub/activity_pub_test.exs | 43 ++++++++-
test/web/federator_test.exs | 4 +-
test/web/instances/instance_test.exs | 107 +++++++++++++++++++++
test/web/instances/instances_test.exs | 94 ++++++++++++++++++
test/web/ostatus/ostatus_controller_test.exs | 2 +-
test/web/websub/websub_controller_test.exs | 2 +-
9 files changed, 284 insertions(+), 7 deletions(-)
create mode 100644 test/web/instances/instance_test.exs
create mode 100644 test/web/instances/instances_test.exs
(limited to 'test')
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 964b2b61c..0c21093ce 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -220,4 +220,11 @@ defmodule Pleroma.Factory do
client_secret: "aaa;/&bbb"
}
end
+
+ def instance_factory do
+ %Pleroma.Instances.Instance{
+ host: "domain.com",
+ unreachable_since: nil
+ }
+ end
end
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index e4279e14d..3d6efd52c 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -653,6 +653,14 @@ defmodule HttpRequestMock do
{:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
end
+ def get("http://404.site" <> _, _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 404,
+ body: ""
+ }}
+ end
+
def get(url, query, body, headers) do
{:error,
"Not implemented the mock response for get #{inspect(url)}, #{query}, #{inspect(body)}, #{
@@ -673,6 +681,26 @@ defmodule HttpRequestMock do
}}
end
+ def post("http://200.site" <> _, _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: ""
+ }}
+ end
+
+ def post("http://connrefused.site" <> _, _, _, _) do
+ {:error, :connrefused}
+ end
+
+ def post("http://404.site" <> _, _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 404,
+ body: ""
+ }}
+ end
+
def post(url, _query, _body, _headers) do
{:error, "Not implemented the mock response for post #{inspect(url)}"}
end
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 1b704330f..eca5c134d 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -146,7 +146,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it clears `unreachable` federation status of the sender", %{conn: conn} do
sender_url = "https://pleroma.soykaf.com"
- Instances.set_unreachable(sender_url, Instances.reachability_datetime_threshold())
+ Instances.set_consistently_unreachable(sender_url)
refute Instances.reachable?(sender_url)
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
@@ -211,7 +211,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it clears `unreachable` federation status of the sender", %{conn: conn} do
sender_host = "pleroma.soykaf.com"
- Instances.set_unreachable(sender_host, Instances.reachability_datetime_threshold())
+ Instances.set_consistently_unreachable(sender_host)
refute Instances.reachable?(sender_host)
user = insert(:user)
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 18f094379..d517c7aa7 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -7,11 +7,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI
- alias Pleroma.{Activity, Object, User}
+ alias Pleroma.{Activity, Object, User, Instances}
alias Pleroma.Builders.ActivityBuilder
import Pleroma.Factory
import Tesla.Mock
+ import Mock
setup do
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
@@ -659,6 +660,46 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert 3 = length(activities)
end
+ describe "publish_one/1" do
+ test_with_mock "it calls `Instances.set_unreachable` on target inbox on non-2xx HTTP response code",
+ Instances,
+ [:passthrough],
+ [] do
+ actor = insert(:user)
+ inbox = "http://404.site/users/nick1/inbox"
+
+ assert {:error, _} =
+ ActivityPub.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1})
+
+ assert called(Instances.set_unreachable(inbox))
+ end
+
+ test_with_mock "it calls `Instances.set_unreachable` on target inbox on request error of any kind",
+ Instances,
+ [:passthrough],
+ [] do
+ actor = insert(:user)
+ inbox = "http://connrefused.site/users/nick1/inbox"
+
+ assert {:error, _} =
+ ActivityPub.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1})
+
+ assert called(Instances.set_unreachable(inbox))
+ end
+
+ test_with_mock "it does NOT call `Instances.set_unreachable` if target is reachable",
+ Instances,
+ [:passthrough],
+ [] do
+ actor = insert(:user)
+ inbox = "http://200.site/users/nick1/inbox"
+
+ assert {:ok, _} = ActivityPub.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1})
+
+ refute called(Instances.set_unreachable(inbox))
+ end
+ end
+
def data_uri do
File.read!("test/fixtures/avatar_data_uri")
end
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index f4234aea8..c6d10ef78 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -128,7 +128,7 @@ defmodule Pleroma.Web.FederatorTest do
callback: "https://pleroma2.soykaf.com/cb"
})
- Instances.set_unreachable(sub1.callback, Instances.reachability_datetime_threshold())
+ Instances.set_consistently_unreachable(sub1.callback)
{:ok, _activity} = CommonAPI.post(user, %{"status" => "HI"})
@@ -158,7 +158,7 @@ defmodule Pleroma.Web.FederatorTest do
info: %{salmon: "https://domain2.com/salmon"}
})
- Instances.set_unreachable("domain.com", Instances.reachability_datetime_threshold())
+ Instances.set_consistently_unreachable("domain.com")
{:ok, _activity} =
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
diff --git a/test/web/instances/instance_test.exs b/test/web/instances/instance_test.exs
new file mode 100644
index 000000000..a158c0a42
--- /dev/null
+++ b/test/web/instances/instance_test.exs
@@ -0,0 +1,107 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Instances.InstanceTest do
+ alias Pleroma.Repo
+ alias Pleroma.Instances.Instance
+
+ use Pleroma.DataCase
+
+ import Pleroma.Factory
+
+ setup_all do
+ config_path = [:instance, :federation_reachability_timeout_days]
+ initial_setting = Pleroma.Config.get(config_path)
+
+ Pleroma.Config.put(config_path, 1)
+ on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
+
+ :ok
+ end
+
+ describe "set_reachable/1" do
+ test "clears `unreachable_since` of existing matching Instance record having non-nil `unreachable_since`" do
+ instance = insert(:instance, unreachable_since: NaiveDateTime.utc_now())
+
+ assert {:ok, instance} = Instance.set_reachable(instance.host)
+ refute instance.unreachable_since
+ end
+
+ test "keeps nil `unreachable_since` of existing matching Instance record having nil `unreachable_since`" do
+ instance = insert(:instance, unreachable_since: nil)
+
+ assert {:ok, instance} = Instance.set_reachable(instance.host)
+ refute instance.unreachable_since
+ end
+
+ test "does NOT create an Instance record in case of no existing matching record" do
+ host = "domain.org"
+ assert nil == Instance.set_reachable(host)
+
+ assert [] = Repo.all(Ecto.Query.from(i in Instance))
+ assert Instance.reachable?(host)
+ end
+ end
+
+ describe "set_unreachable/1" do
+ test "creates new record having `unreachable_since` to current time if record does not exist" do
+ assert {:ok, instance} = Instance.set_unreachable("https://domain.com/path")
+
+ instance = Repo.get(Instance, instance.id)
+ assert instance.unreachable_since
+ assert "domain.com" == instance.host
+ end
+
+ test "sets `unreachable_since` of existing record having nil `unreachable_since`" do
+ instance = insert(:instance, unreachable_since: nil)
+ refute instance.unreachable_since
+
+ assert {:ok, _} = Instance.set_unreachable(instance.host)
+
+ instance = Repo.get(Instance, instance.id)
+ assert instance.unreachable_since
+ end
+
+ test "does NOT modify `unreachable_since` value of existing record in case it's present" do
+ instance =
+ insert(:instance, unreachable_since: NaiveDateTime.add(NaiveDateTime.utc_now(), -10))
+
+ assert instance.unreachable_since
+ initial_value = instance.unreachable_since
+
+ assert {:ok, _} = Instance.set_unreachable(instance.host)
+
+ instance = Repo.get(Instance, instance.id)
+ assert initial_value == instance.unreachable_since
+ end
+ end
+
+ describe "set_unreachable/2" do
+ test "sets `unreachable_since` value of existing record in case it's newer than supplied value" do
+ instance =
+ insert(:instance, unreachable_since: NaiveDateTime.add(NaiveDateTime.utc_now(), -10))
+
+ assert instance.unreachable_since
+
+ past_value = NaiveDateTime.add(NaiveDateTime.utc_now(), -100)
+ assert {:ok, _} = Instance.set_unreachable(instance.host, past_value)
+
+ instance = Repo.get(Instance, instance.id)
+ assert past_value == instance.unreachable_since
+ end
+
+ test "does NOT modify `unreachable_since` value of existing record in case it's equal to or older than supplied value" do
+ instance =
+ insert(:instance, unreachable_since: NaiveDateTime.add(NaiveDateTime.utc_now(), -10))
+
+ assert instance.unreachable_since
+ initial_value = instance.unreachable_since
+
+ assert {:ok, _} = Instance.set_unreachable(instance.host, NaiveDateTime.utc_now())
+
+ instance = Repo.get(Instance, instance.id)
+ assert initial_value == instance.unreachable_since
+ end
+ end
+end
diff --git a/test/web/instances/instances_test.exs b/test/web/instances/instances_test.exs
new file mode 100644
index 000000000..a2fdf1019
--- /dev/null
+++ b/test/web/instances/instances_test.exs
@@ -0,0 +1,94 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.InstancesTest do
+ alias Pleroma.Instances
+
+ use Pleroma.DataCase
+
+ setup_all do
+ config_path = [:instance, :federation_reachability_timeout_days]
+ initial_setting = Pleroma.Config.get(config_path)
+
+ Pleroma.Config.put(config_path, 1)
+ on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
+
+ :ok
+ end
+
+ describe "reachable?/1" do
+ test "returns `true` for host / url with unknown reachability status" do
+ assert Instances.reachable?("unknown.site")
+ assert Instances.reachable?("http://unknown.site")
+ end
+
+ test "returns `false` for host / url marked unreachable for at least `reachability_datetime_threshold()`" do
+ host = "consistently-unreachable.name"
+ Instances.set_consistently_unreachable(host)
+
+ refute Instances.reachable?(host)
+ refute Instances.reachable?("http://#{host}/path")
+ end
+
+ test "returns `true` for host / url marked unreachable for less than `reachability_datetime_threshold()`" do
+ url = "http://eventually-unreachable.name/path"
+
+ Instances.set_unreachable(url)
+
+ assert Instances.reachable?(url)
+ assert Instances.reachable?(URI.parse(url).host)
+ end
+ end
+
+ describe "filter_reachable/1" do
+ test "keeps only reachable elements of supplied list" do
+ host = "consistently-unreachable.name"
+ url1 = "http://eventually-unreachable.com/path"
+ url2 = "http://domain.com/path"
+
+ Instances.set_consistently_unreachable(host)
+ Instances.set_unreachable(url1)
+
+ assert [url1, url2] == Instances.filter_reachable([host, url1, url2])
+ end
+ end
+
+ describe "set_reachable/1" do
+ test "sets unreachable url or host reachable" do
+ host = "domain.com"
+ Instances.set_consistently_unreachable(host)
+ refute Instances.reachable?(host)
+
+ Instances.set_reachable(host)
+ assert Instances.reachable?(host)
+ end
+
+ test "keeps reachable url or host reachable" do
+ url = "https://site.name?q="
+ assert Instances.reachable?(url)
+
+ Instances.set_reachable(url)
+ assert Instances.reachable?(url)
+ end
+ end
+
+ describe "set_consistently_unreachable/1" do
+ test "sets reachable url or host unreachable" do
+ url = "http://domain.com?q="
+ assert Instances.reachable?(url)
+
+ Instances.set_consistently_unreachable(url)
+ refute Instances.reachable?(url)
+ end
+
+ test "keeps unreachable url or host unreachable" do
+ host = "site.name"
+ Instances.set_consistently_unreachable(host)
+ refute Instances.reachable?(host)
+
+ Instances.set_consistently_unreachable(host)
+ refute Instances.reachable?(host)
+ end
+ end
+end
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index ca447aa5d..ad9bc418a 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -62,7 +62,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
test "it clears `unreachable` federation status of the sender", %{conn: conn} do
sender_url = "https://pleroma.soykaf.com"
- Instances.set_unreachable(sender_url, Instances.reachability_datetime_threshold())
+ Instances.set_consistently_unreachable(sender_url)
refute Instances.reachable?(sender_url)
user = insert(:user)
diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs
index c445ed676..cb19d6fe6 100644
--- a/test/web/websub/websub_controller_test.exs
+++ b/test/web/websub/websub_controller_test.exs
@@ -85,7 +85,7 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
test "it clears `unreachable` federation status of the sender", %{conn: conn} do
sender_url = "https://pleroma.soykaf.com"
- Instances.set_unreachable(sender_url, Instances.reachability_datetime_threshold())
+ Instances.set_consistently_unreachable(sender_url)
refute Instances.reachable?(sender_url)
websub = insert(:websub_client_subscription)
--
cgit v1.2.3
From 55affbca7fcb214c71b3f8378b0de869c4d4d072 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 28 Jan 2019 22:17:17 +0700
Subject: add a job queue
---
test/jobs_test.exs | 83 ++++++++++++++++++++++++++++++++++++++++
test/support/jobs_worker_mock.ex | 19 +++++++++
test/web/federator_test.exs | 24 ++----------
3 files changed, 106 insertions(+), 20 deletions(-)
create mode 100644 test/jobs_test.exs
create mode 100644 test/support/jobs_worker_mock.ex
(limited to 'test')
diff --git a/test/jobs_test.exs b/test/jobs_test.exs
new file mode 100644
index 000000000..ccb518dec
--- /dev/null
+++ b/test/jobs_test.exs
@@ -0,0 +1,83 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.JobsTest do
+ use ExUnit.Case, async: true
+
+ alias Pleroma.Jobs
+ alias Jobs.WorkerMock
+
+ setup do
+ state = %{
+ queues: Enum.into([Jobs.create_queue(:testing)], %{}),
+ refs: %{}
+ }
+
+ [state: state]
+ end
+
+ test "creates queue" do
+ queue = Jobs.create_queue(:foobar)
+
+ assert {:foobar, set} = queue
+ assert :set == elem(set, 0) |> elem(0)
+ end
+
+ test "enqueues an element according to priority" do
+ queue = [%{item: 1, priority: 2}]
+
+ new_queue = Jobs.enqueue_sorted(queue, 2, 1)
+ assert new_queue == [%{item: 2, priority: 1}, %{item: 1, priority: 2}]
+
+ new_queue = Jobs.enqueue_sorted(queue, 2, 3)
+ assert new_queue == [%{item: 1, priority: 2}, %{item: 2, priority: 3}]
+ end
+
+ test "pop first item" do
+ queue = [%{item: 2, priority: 1}, %{item: 1, priority: 2}]
+
+ assert {2, [%{item: 1, priority: 2}]} = Jobs.queue_pop(queue)
+ end
+
+ test "enqueue a job", %{state: state} do
+ assert {:noreply, new_state} =
+ Jobs.handle_cast({:enqueue, :testing, WorkerMock, [:test_job, :foo, :bar], 3}, state)
+
+ assert %{queues: %{testing: {running_jobs, []}}, refs: _} = new_state
+ assert :sets.size(running_jobs) == 1
+ assert [ref] = :sets.to_list(running_jobs)
+ assert %{refs: %{^ref => :testing}} = new_state
+ end
+
+ test "max jobs setting", %{state: state} do
+ max_jobs = Pleroma.Config.get([Jobs, :testing, :max_jobs])
+
+ {:noreply, state} =
+ Enum.reduce(1..(max_jobs + 1), {:noreply, state}, fn _, {:noreply, state} ->
+ Jobs.handle_cast({:enqueue, :testing, WorkerMock, [:test_job, :foo, :bar], 3}, state)
+ end)
+
+ assert %{
+ queues: %{
+ testing:
+ {running_jobs, [%{item: {WorkerMock, [:test_job, :foo, :bar]}, priority: 3}]}
+ }
+ } = state
+
+ assert :sets.size(running_jobs) == max_jobs
+ end
+
+ test "remove job after it finished", %{state: state} do
+ {:noreply, new_state} =
+ Jobs.handle_cast({:enqueue, :testing, WorkerMock, [:test_job, :foo, :bar], 3}, state)
+
+ %{queues: %{testing: {running_jobs, []}}} = new_state
+ [ref] = :sets.to_list(running_jobs)
+
+ assert {:noreply, %{queues: %{testing: {running_jobs, []}}, refs: %{}}} =
+ Jobs.handle_info({:DOWN, ref, :process, nil, nil}, new_state)
+
+ assert :sets.size(running_jobs) == 0
+ end
+end
diff --git a/test/support/jobs_worker_mock.ex b/test/support/jobs_worker_mock.ex
new file mode 100644
index 000000000..0fb976d05
--- /dev/null
+++ b/test/support/jobs_worker_mock.ex
@@ -0,0 +1,19 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Jobs.WorkerMock do
+ require Logger
+
+ def perform(:test_job, arg, arg2) do
+ Logger.debug({:perform, :test_job, arg, arg2})
+ end
+
+ def perform(:test_job, payload) do
+ Logger.debug({:perform, :test_job, payload})
+ end
+
+ def test_job(payload) do
+ Pleroma.Jobs.enqueue(:testing, __MODULE__, [:test_job, payload])
+ end
+end
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index a49265c0c..d58621cc3 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -14,22 +14,6 @@ defmodule Pleroma.Web.FederatorTest do
:ok
end
- test "enqueues an element according to priority" do
- queue = [%{item: 1, priority: 2}]
-
- new_queue = Federator.enqueue_sorted(queue, 2, 1)
- assert new_queue == [%{item: 2, priority: 1}, %{item: 1, priority: 2}]
-
- new_queue = Federator.enqueue_sorted(queue, 2, 3)
- assert new_queue == [%{item: 1, priority: 2}, %{item: 2, priority: 3}]
- end
-
- test "pop first item" do
- queue = [%{item: 2, priority: 1}, %{item: 1, priority: 2}]
-
- assert {2, [%{item: 1, priority: 2}]} = Federator.queue_pop(queue)
- end
-
describe "Publish an activity" do
setup do
user = insert(:user)
@@ -49,7 +33,7 @@ defmodule Pleroma.Web.FederatorTest do
relay_mock: relay_mock
} do
with_mocks([relay_mock]) do
- Federator.handle(:publish, activity)
+ Federator.publish(activity)
end
assert_received :relay_publish
@@ -62,7 +46,7 @@ defmodule Pleroma.Web.FederatorTest do
Pleroma.Config.put([:instance, :allow_relay], false)
with_mocks([relay_mock]) do
- Federator.handle(:publish, activity)
+ Federator.publish(activity)
end
refute_received :relay_publish
@@ -87,7 +71,7 @@ defmodule Pleroma.Web.FederatorTest do
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
}
- {:ok, _activity} = Federator.handle(:incoming_ap_doc, params)
+ {:ok, _activity} = Federator.incoming_ap_doc(params)
end
test "rejects incoming AP docs with incorrect origin" do
@@ -105,7 +89,7 @@ defmodule Pleroma.Web.FederatorTest do
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
}
- :error = Federator.handle(:incoming_ap_doc, params)
+ :error = Federator.incoming_ap_doc(params)
end
end
end
--
cgit v1.2.3
From 50d6183893166b51a400659a38dd657ac84603d6 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Mon, 28 Jan 2019 21:31:08 +0300
Subject: Split hide_network into hide_followers & hide_followings
---
.../activity_pub/activity_pub_controller_test.exs | 8 ++--
.../mastodon_api/mastodon_api_controller_test.exs | 16 +++----
.../twitter_api/twitter_api_controller_test.exs | 50 ++++++++++++++++------
test/web/twitter_api/views/user_view_test.exs | 12 ++++--
4 files changed, 57 insertions(+), 29 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 52e67f046..374d3e2d1 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -348,9 +348,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert result["first"]["orderedItems"] == [user.ap_id]
end
- test "it returns returns empty if the user has 'hide_network' set", %{conn: conn} do
+ test "it returns returns empty if the user has 'hide_followers' set", %{conn: conn} do
user = insert(:user)
- user_two = insert(:user, %{info: %{hide_network: true}})
+ user_two = insert(:user, %{info: %{hide_followers: true}})
User.follow(user, user_two)
result =
@@ -403,8 +403,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert result["first"]["orderedItems"] == [user_two.ap_id]
end
- test "it returns returns empty if the user has 'hide_network' set", %{conn: conn} do
- user = insert(:user, %{info: %{hide_network: true}})
+ test "it returns returns empty if the user has 'hide_followings' set", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_followings: true}})
user_two = insert(:user)
User.follow(user, user_two)
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index b8f901e6c..9aa47977e 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1085,9 +1085,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert id == to_string(user.id)
end
- test "getting followers, hide_network", %{conn: conn} do
+ test "getting followers, hide_followers", %{conn: conn} do
user = insert(:user)
- other_user = insert(:user, %{info: %{hide_network: true}})
+ other_user = insert(:user, %{info: %{hide_followers: true}})
{:ok, _user} = User.follow(user, other_user)
conn =
@@ -1097,9 +1097,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [] == json_response(conn, 200)
end
- test "getting followers, hide_network, same user requesting", %{conn: conn} do
+ test "getting followers, hide_followers, same user requesting", %{conn: conn} do
user = insert(:user)
- other_user = insert(:user, %{info: %{hide_network: true}})
+ other_user = insert(:user, %{info: %{hide_followers: true}})
{:ok, _user} = User.follow(user, other_user)
conn =
@@ -1123,8 +1123,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert id == to_string(other_user.id)
end
- test "getting following, hide_network", %{conn: conn} do
- user = insert(:user, %{info: %{hide_network: true}})
+ test "getting following, hide_followings", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_followings: true}})
other_user = insert(:user)
{:ok, user} = User.follow(user, other_user)
@@ -1135,8 +1135,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [] == json_response(conn, 200)
end
- test "getting following, hide_network, same user requesting", %{conn: conn} do
- user = insert(:user, %{info: %{hide_network: true}})
+ test "getting following, hide_followings, same user requesting", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_followings: true}})
other_user = insert(:user)
{:ok, user} = User.follow(user, other_user)
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 863abd10f..7a685d9b0 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1132,8 +1132,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
)
end
- test "it returns empty for a hidden network", %{conn: conn} do
- user = insert(:user, %{info: %{hide_network: true}})
+ test "it returns empty when hide_followers is set to true", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_followers: true}})
follower_one = insert(:user)
follower_two = insert(:user)
not_follower = insert(:user)
@@ -1150,10 +1150,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert [] == response
end
- test "it returns the followers for a hidden network if requested by the user themselves", %{
+ test "it returns the followers when hide_followers is set to true if requested by the user themselves", %{
conn: conn
} do
- user = insert(:user, %{info: %{hide_network: true}})
+ user = insert(:user, %{info: %{hide_followers: true}})
follower_one = insert(:user)
follower_two = insert(:user)
_not_follower = insert(:user)
@@ -1256,8 +1256,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
)
end
- test "it returns empty for a hidden network", %{conn: conn} do
- user = insert(:user, %{info: %{hide_network: true}})
+ test "it returns empty when hide_followings is set to true", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_followings: true}})
followed_one = insert(:user)
followed_two = insert(:user)
not_followed = insert(:user)
@@ -1273,10 +1273,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert [] == json_response(conn, 200)
end
- test "it returns friends for a hidden network if the user themselves request it", %{
+ test "it returns friends when hide_followings is set to true if the user themselves request it", %{
conn: conn
} do
- user = insert(:user, %{info: %{hide_network: true}})
+ user = insert(:user, %{info: %{hide_followings: true}})
followed_one = insert(:user)
followed_two = insert(:user)
_not_followed = insert(:user)
@@ -1364,27 +1364,51 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
- test "it sets and un-sets hide_network", %{conn: conn} do
+ test "it sets and un-sets hide_followings", %{conn: conn} do
user = insert(:user)
conn
|> assign(:user, user)
|> post("/api/account/update_profile.json", %{
- "hide_network" => "true"
+ "hide_followings" => "true"
})
user = Repo.get!(User, user.id)
- assert user.info.hide_network == true
+ assert user.info.hide_followings == true
conn =
conn
|> assign(:user, user)
|> post("/api/account/update_profile.json", %{
- "hide_network" => "false"
+ "hide_followings" => "false"
})
user = Repo.get!(User, user.id)
- assert user.info.hide_network == false
+ assert user.info.hide_followings == false
+ assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
+ end
+
+ test "it sets and un-sets hide_followers", %{conn: conn} do
+ user = insert(:user)
+
+ conn
+ |> assign(:user, user)
+ |> post("/api/account/update_profile.json", %{
+ "hide_followers" => "true"
+ })
+
+ user = Repo.get!(User, user.id)
+ assert user.info.hide_followers == true
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/account/update_profile.json", %{
+ "hide_followers" => "false"
+ })
+
+ user = Repo.get!(User, user.id)
+ assert user.info.hide_followers == false
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index daf18c1c5..0885afaec 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -100,7 +100,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "hide_network" => false,
+ "hide_followings" => false,
+ "hide_followers" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
@@ -147,7 +148,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "hide_network" => false,
+ "hide_followings" => false,
+ "hide_followers" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
@@ -195,7 +197,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "hide_network" => false,
+ "hide_followings" => false,
+ "hide_followers" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
@@ -257,7 +260,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "hide_network" => false,
+ "hide_followings" => false,
+ "hide_followers" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
--
cgit v1.2.3
From 3e968f9ef22f48819f5f08a493ccf13d6b52cca8 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Mon, 28 Jan 2019 21:35:02 +0300
Subject: Format
---
test/web/twitter_api/twitter_api_controller_test.exs | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 7a685d9b0..6777354c3 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1150,9 +1150,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert [] == response
end
- test "it returns the followers when hide_followers is set to true if requested by the user themselves", %{
- conn: conn
- } do
+ test "it returns the followers when hide_followers is set to true if requested by the user themselves",
+ %{
+ conn: conn
+ } do
user = insert(:user, %{info: %{hide_followers: true}})
follower_one = insert(:user)
follower_two = insert(:user)
@@ -1273,9 +1274,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert [] == json_response(conn, 200)
end
- test "it returns friends when hide_followings is set to true if the user themselves request it", %{
- conn: conn
- } do
+ test "it returns friends when hide_followings is set to true if the user themselves request it",
+ %{
+ conn: conn
+ } do
user = insert(:user, %{info: %{hide_followings: true}})
followed_one = insert(:user)
followed_two = insert(:user)
--
cgit v1.2.3
From 61d6715714fe9c2ce6bf4fe6afc353f7fe5502a6 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Mon, 28 Jan 2019 21:07:36 +0000
Subject: rich media: oembed: return data in the same format as the other
parsers
---
test/web/rich_media/parser_test.exs | 41 ++++++++++++++++++-------------------
1 file changed, 20 insertions(+), 21 deletions(-)
(limited to 'test')
diff --git a/test/web/rich_media/parser_test.exs b/test/web/rich_media/parser_test.exs
index e14b5061a..93a58c528 100644
--- a/test/web/rich_media/parser_test.exs
+++ b/test/web/rich_media/parser_test.exs
@@ -65,28 +65,27 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/oembed") ==
{:ok,
%{
- "author_name" => "bees",
- "author_url" => "https://www.flickr.com/photos/bees/",
- "cache_age" => 3600,
- "flickr_type" => "photo",
- "height" => "768",
- "html" =>
+ author_name: "bees",
+ author_url: "https://www.flickr.com/photos/bees/",
+ cache_age: 3600,
+ flickr_type: "photo",
+ height: "768",
+ html:
" ",
- "license" => "All Rights Reserved",
- "license_id" => 0,
- "provider_name" => "Flickr",
- "provider_url" => "https://www.flickr.com/",
- "thumbnail_height" => 150,
- "thumbnail_url" =>
- "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_q.jpg",
- "thumbnail_width" => 150,
- "title" => "Bacon Lollys",
- "type" => "photo",
- "url" => "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_b.jpg",
- "version" => "1.0",
- "web_page" => "https://www.flickr.com/photos/bees/2362225867/",
- "web_page_short_url" => "https://flic.kr/p/4AK2sc",
- "width" => "1024"
+ license: "All Rights Reserved",
+ license_id: 0,
+ provider_name: "Flickr",
+ provider_url: "https://www.flickr.com/",
+ thumbnail_height: 150,
+ thumbnail_url: "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_q.jpg",
+ thumbnail_width: 150,
+ title: "Bacon Lollys",
+ type: "photo",
+ url: "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_b.jpg",
+ version: "1.0",
+ web_page: "https://www.flickr.com/photos/bees/2362225867/",
+ web_page_short_url: "https://flic.kr/p/4AK2sc",
+ width: "1024"
}}
end
end
--
cgit v1.2.3
From 92753b0cd9cfcdc5edb64a5e55ad27f73079f9e0 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Tue, 29 Jan 2019 13:12:28 +0300
Subject: [#534] Made federation push sender be determined basing on content
instead of `referer` header. Updated tests.
---
.../activity_pub/activity_pub_controller_test.exs | 16 +++++++---------
test/web/instances/instances_test.exs | 18 ++++++++++++++++++
.../incoming_documents/delete_handling_test.exs | 7 +++++++
test/web/ostatus/ostatus_controller_test.exs | 20 +-------------------
test/web/ostatus/ostatus_test.exs | 18 +++++++++++++++++-
test/web/websub/websub_controller_test.exs | 22 +---------------------
6 files changed, 51 insertions(+), 50 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index eca5c134d..d3dd160dd 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -145,17 +145,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
test "it clears `unreachable` federation status of the sender", %{conn: conn} do
- sender_url = "https://pleroma.soykaf.com"
+ data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
+
+ sender_url = data["actor"]
Instances.set_consistently_unreachable(sender_url)
refute Instances.reachable?(sender_url)
- data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
-
conn =
conn
|> assign(:valid_signature, true)
|> put_req_header("content-type", "application/activity+json")
- |> put_req_header("referer", sender_url)
|> post("/inbox", data)
assert "ok" == json_response(conn, 200)
@@ -210,10 +209,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
test "it clears `unreachable` federation status of the sender", %{conn: conn} do
- sender_host = "pleroma.soykaf.com"
- Instances.set_consistently_unreachable(sender_host)
- refute Instances.reachable?(sender_host)
-
user = insert(:user)
data =
@@ -221,11 +216,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> Poison.decode!()
|> Map.put("bcc", [user.ap_id])
+ sender_host = URI.parse(data["actor"]).host
+ Instances.set_consistently_unreachable(sender_host)
+ refute Instances.reachable?(sender_host)
+
conn =
conn
|> assign(:valid_signature, true)
|> put_req_header("content-type", "application/activity+json")
- |> put_req_header("referer", "https://#{sender_host}")
|> post("/users/#{user.nickname}/inbox", data)
assert "ok" == json_response(conn, 200)
diff --git a/test/web/instances/instances_test.exs b/test/web/instances/instances_test.exs
index a2fdf1019..adb8560a7 100644
--- a/test/web/instances/instances_test.exs
+++ b/test/web/instances/instances_test.exs
@@ -39,6 +39,11 @@ defmodule Pleroma.InstancesTest do
assert Instances.reachable?(url)
assert Instances.reachable?(URI.parse(url).host)
end
+
+ test "returns true on non-binary input" do
+ assert Instances.reachable?(nil)
+ assert Instances.reachable?(1)
+ end
end
describe "filter_reachable/1" do
@@ -71,6 +76,19 @@ defmodule Pleroma.InstancesTest do
Instances.set_reachable(url)
assert Instances.reachable?(url)
end
+
+ test "returns error status on non-binary input" do
+ assert {:error, _} = Instances.set_reachable(nil)
+ assert {:error, _} = Instances.set_reachable(1)
+ end
+ end
+
+ # Note: implementation-specific (e.g. Instance) details of set_unreachable/1 should be tested in implementation-specific tests
+ describe "set_unreachable/1" do
+ test "returns error status on non-binary input" do
+ assert {:error, _} = Instances.set_unreachable(nil)
+ assert {:error, _} = Instances.set_unreachable(1)
+ end
end
describe "set_consistently_unreachable/1" do
diff --git a/test/web/ostatus/incoming_documents/delete_handling_test.exs b/test/web/ostatus/incoming_documents/delete_handling_test.exs
index c8fbff6cc..d97cd79f4 100644
--- a/test/web/ostatus/incoming_documents/delete_handling_test.exs
+++ b/test/web/ostatus/incoming_documents/delete_handling_test.exs
@@ -2,9 +2,16 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
use Pleroma.DataCase
import Pleroma.Factory
+ import Tesla.Mock
+
alias Pleroma.{Repo, Activity, Object}
alias Pleroma.Web.OStatus
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
describe "deletions" do
test "it removes the mentioned activity" do
note = insert(:note_activity)
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index cba12b3f7..3145ca9a1 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -5,7 +5,7 @@
defmodule Pleroma.Web.OStatus.OStatusControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
- alias Pleroma.{User, Repo, Object, Instances}
+ alias Pleroma.{User, Repo, Object}
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OStatus.ActivityRepresenter
@@ -59,24 +59,6 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
assert response(conn, 200)
end
-
- test "it clears `unreachable` federation status of the sender", %{conn: conn} do
- sender_url = "https://pleroma.soykaf.com"
- Instances.set_consistently_unreachable(sender_url)
- refute Instances.reachable?(sender_url)
-
- user = insert(:user)
- salmon = File.read!("test/fixtures/salmon.xml")
-
- conn =
- conn
- |> put_req_header("content-type", "application/atom+xml")
- |> put_req_header("referer", sender_url)
- |> post("/users/#{user.nickname}/salmon", salmon)
-
- assert response(conn, 200)
- assert Instances.reachable?(sender_url)
- end
end
test "gets a feed", %{conn: conn} do
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index 403cc7095..0c63dd84d 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -6,7 +6,7 @@ defmodule Pleroma.Web.OStatusTest do
use Pleroma.DataCase
alias Pleroma.Web.OStatus
alias Pleroma.Web.XML
- alias Pleroma.{Object, Repo, User, Activity}
+ alias Pleroma.{Object, Repo, User, Activity, Instances}
import Pleroma.Factory
import ExUnit.CaptureLog
@@ -311,6 +311,22 @@ defmodule Pleroma.Web.OStatusTest do
refute User.following?(follower, followed)
end
+ test "it clears `unreachable` federation status of the sender" do
+ incoming_reaction_xml = File.read!("test/fixtures/share-gs.xml")
+ doc = XML.parse_document(incoming_reaction_xml)
+ actor_uri = XML.string_from_xpath("//author/uri[1]", doc)
+ reacted_to_author_uri = XML.string_from_xpath("//author/uri[2]", doc)
+
+ Instances.set_consistently_unreachable(actor_uri)
+ Instances.set_consistently_unreachable(reacted_to_author_uri)
+ refute Instances.reachable?(actor_uri)
+ refute Instances.reachable?(reacted_to_author_uri)
+
+ {:ok, _} = OStatus.handle_incoming(incoming_reaction_xml)
+ assert Instances.reachable?(actor_uri)
+ refute Instances.reachable?(reacted_to_author_uri)
+ end
+
describe "new remote user creation" do
test "returns local users" do
local_user = insert(:user)
diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs
index cb19d6fe6..6492df2a0 100644
--- a/test/web/websub/websub_controller_test.exs
+++ b/test/web/websub/websub_controller_test.exs
@@ -6,7 +6,7 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
alias Pleroma.Web.Websub.WebsubClientSubscription
- alias Pleroma.{Repo, Activity, Instances}
+ alias Pleroma.{Repo, Activity}
alias Pleroma.Web.Websub
test "websub subscription request", %{conn: conn} do
@@ -82,25 +82,5 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
assert length(Repo.all(Activity)) == 0
end
-
- test "it clears `unreachable` federation status of the sender", %{conn: conn} do
- sender_url = "https://pleroma.soykaf.com"
- Instances.set_consistently_unreachable(sender_url)
- refute Instances.reachable?(sender_url)
-
- websub = insert(:websub_client_subscription)
- doc = "some stuff"
- signature = Websub.sign(websub.secret, doc)
-
- conn =
- conn
- |> put_req_header("x-hub-signature", "sha1=" <> signature)
- |> put_req_header("content-type", "application/atom+xml")
- |> put_req_header("referer", sender_url)
- |> post("/push/subscriptions/#{websub.id}", doc)
-
- assert response(conn, 200) == "OK"
- assert Instances.reachable?(sender_url)
- end
end
end
--
cgit v1.2.3
From 47ec690c54d8af9e317217990fb0756c7d37e2a5 Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 30 Jan 2019 19:33:25 +0100
Subject: Use race-condition free mass follow.
---
test/user_test.exs | 6 ++++++
1 file changed, 6 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index a0657c7b6..cd202e360 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -50,13 +50,19 @@ defmodule Pleroma.UserTest do
test "follow_all follows mutliple users" do
user = insert(:user)
+ followed_zero = insert(:user)
followed_one = insert(:user)
followed_two = insert(:user)
+ not_followed = insert(:user)
+
+ {:ok, user} = User.follow(user, followed_zero)
{:ok, user} = User.follow_all(user, [followed_one, followed_two])
assert User.following?(user, followed_one)
assert User.following?(user, followed_two)
+ assert User.following?(user, followed_zero)
+ refute User.following?(user, not_followed)
end
test "follow takes a user and another user" do
--
cgit v1.2.3
From c53b96a024d4802a153ae3f561b2f6accb334ace Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 30 Jan 2019 19:45:31 +0100
Subject: Fix specs.
---
test/web/activity_pub/activity_pub_test.exs | 2 --
1 file changed, 2 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 7895cf21d..b826f5a1b 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -623,8 +623,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
"in_reply_to_status_id" => private_activity_2.id
})
- assert user1.following == [user3.ap_id <> "/followers", user1.ap_id]
-
activities = ActivityPub.fetch_activities([user1.ap_id | user1.following])
assert [public_activity, private_activity_1, private_activity_3] == activities
--
cgit v1.2.3
From a43a1c6d4e6ff26c751cce1284deb2ef40b00ab7 Mon Sep 17 00:00:00 2001
From: lambda
Date: Thu, 31 Jan 2019 12:16:23 +0000
Subject: Revert "Merge branch 'spc-fix-3' into 'develop'"
This reverts merge request !682
---
test/fixtures/zep.json | 1 -
test/spc_fixes_test.exs | 72 -------------------------------------------------
2 files changed, 73 deletions(-)
delete mode 100644 test/fixtures/zep.json
delete mode 100644 test/spc_fixes_test.exs
(limited to 'test')
diff --git a/test/fixtures/zep.json b/test/fixtures/zep.json
deleted file mode 100644
index 1aab043be..000000000
--- a/test/fixtures/zep.json
+++ /dev/null
@@ -1 +0,0 @@
-{"url":"https://shitposter.club/users/zep","type":"Person","tag":[],"summary":"The Zeptar Show on anonradio.net","publicKey":{"publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsdkm3pQxYTW7rVVUQBJ0\nc+J7pUI623gohi2fwM05ZenYVysRIw0Mm6GYvDsCO6DHywi97pG4EBABEQNyagLS\njIDTrLR1GU0K4dnPgaZ7fIkXvMN+d2NNe0LoIw0wX23sw+L+D+U5l0AJ+3LqDC9s\nwucLz4uYokcrl8yxGFYHWjpRYqy/WVuk8986Hm1Mov4j8AWWV5VLl1yYcbQthSuw\nDXL5yMqwiLPn+Vhc4Pb216IhwIl+k9/tfdsnyAlCiasvUQ8Cigde0AJC0sqnUQhy\nJ4gSftvyW5ejYYebNWg09Afjq3I8k0gj1fGks0pY9IJr2a2H+eqCA//YI8z1XHvE\nlwIDAQAB\n-----END PUBLIC KEY-----\n\n","owner":"https://shitposter.club/users/zep","id":"https://shitposter.club/users/zep#main-key"},"preferredUsername":"zep","outbox":"https://shitposter.club/users/zep/outbox","name":"DJ Zep","manuallyApprovesFollowers":false,"inbox":"https://shitposter.club/users/zep/inbox","image":{"url":"https://shitposter.club/media/13946026-15ba-40e1-9cad-ba3a7aeb47e1/13946026-15ba-40e1-9cad-ba3a7aeb47e1.jpeg","type":"Image"},"id":"https://shitposter.club/users/zep","icon":{"url":"https://shitposter.club/media/83650c2f-7f31-98f5-acee-69a486c94173/83650c2f-7f31-98f5-acee-69a486c94173.jpeg","type":"Image"},"following":"https://shitposter.club/users/zep/following","followers":"https://shitposter.club/users/zep/followers","endpoints":{"sharedInbox":"https://shitposter.club/inbox"},"@context":["https://www.w3.org/ns/activitystreams","https://shitposter.club/schemas/litepub-0.1.jsonld"]}
\ No newline at end of file
diff --git a/test/spc_fixes_test.exs b/test/spc_fixes_test.exs
deleted file mode 100644
index 67ab54ccf..000000000
--- a/test/spc_fixes_test.exs
+++ /dev/null
@@ -1,72 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.SpcFixesTest do
- use Pleroma.Web.ConnCase
-
- alias Pleroma.SpcFixes
- alias Pleroma.Web.CommonAPI
- alias Pleroma.Web.ActivityPub.ActivityPub
- alias Pleroma.User
- alias Pleroma.Activity
- alias Pleroma.Repo
- alias Pleroma.Object
-
- import Pleroma.Factory
-
- test "resets the ap_id and follower_address of old spc users" do
- Tesla.Mock.mock(fn
- %{url: "https://shitposter.club/users/zep"} ->
- %Tesla.Env{status: 200, body: File.read!("test/fixtures/zep.json")}
-
- %{url: nil} ->
- nil
- end)
-
- user =
- insert(:user, %{
- local: false,
- ap_id: "https://shitposter.club/user/4962",
- follower_address: User.ap_followers(%User{nickname: "zep@shitposter.club"}),
- info: %{topic: "ignore"},
- nickname: "zep@shitposter.club"
- })
-
- other_user = insert(:user)
- {:ok, other_user} = User.follow(other_user, user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "blabla"})
- {:ok, _other_activity} = CommonAPI.post(other_user, %{"status" => "blabla"})
-
- assert User.following?(other_user, user)
- assert [activity] == ActivityPub.fetch_activities(other_user.following)
-
- SpcFixes.upgrade_users()
-
- user = Pleroma.Repo.get(User, user.id)
- other_user = Pleroma.Repo.get(User, other_user.id)
-
- assert user.ap_id == "https://shitposter.club/users/zep"
- assert user.follower_address == "https://shitposter.club/users/zep/followers"
-
- aid = activity.id
- # Activites and following are correctly stitched.
- assert User.following?(other_user, user)
- assert [%{id: ^aid}] = ActivityPub.fetch_activities(other_user.following)
-
- third_user = insert(:user)
- {:ok, third_user} = User.follow(third_user, user)
- assert [%{id: ^aid}] = ActivityPub.fetch_activities(third_user.following)
-
- activity = Repo.get(Activity, aid)
-
- assert activity.data["actor"] == user.ap_id
- assert user.follower_address in activity.recipients
- assert user.follower_address in activity.data["to"]
-
- object = Object.get_by_ap_id(activity.data["object"]["id"])
-
- assert object.data["actor"] == user.ap_id
- assert user.follower_address in object.data["to"]
- end
-end
--
cgit v1.2.3
From 4e76f9fde1f13c001f11d8184a9d75894461f881 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Thu, 31 Jan 2019 16:12:35 +0000
Subject: test: add malformed OGP data fixture
---
test/fixtures/rich_media/malformed-data.html | 4874 ++++++++++++++++++++++++++
test/support/http_request_mock.ex | 4 +
2 files changed, 4878 insertions(+)
create mode 100644 test/fixtures/rich_media/malformed-data.html
(limited to 'test')
diff --git a/test/fixtures/rich_media/malformed-data.html b/test/fixtures/rich_media/malformed-data.html
new file mode 100644
index 000000000..dec628c16
--- /dev/null
+++ b/test/fixtures/rich_media/malformed-data.html
@@ -0,0 +1,4874 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Pomys na biznes: chusta, ktra chroni przed smogiem
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1 ZDJĘCIE
+
+
+
+
+
+
+
+
+
+
Prace nad projektem chusty antysmogowej rozpoczy si w lutym 2018 roku, a w styczniu 2019 pojawia si na rynku (MATERIAY PRASOWE)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Filtr ma tak dokadny, e zatrzymuje nawet wirusy i bakterie. Trjka wrocawian stworzya chust, ktra chroni przed smogiem.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Choć Wrocław to piękne miasto, często pojawia się w polskiej czołówce tych najbardziej ogarniętych smogiem. Zdarza się, że i w światowym rankingu zajmuje wysokie lokaty. Wszystko zależy od tego, jaka akurat jest pogoda.
+ Trójka zaniepokojonych wrocławian od dawna obserwuje wskazania dwóch oficjalnych stacji pomiarowych. I często aż strach jest wyjść z domu. Zresztą w nim też nie jest dużo lepiej.
+ – Szkodliwe cząsteczki unoszące się w smogu są bardzo małe. Gdy ich stężenie jest wysokie, dostają się również do wewnątrz mieszkań. A to oznacza, że przed smogiem nie da się całkowicie ochronić, zamykając drzwi i okna – opowiada Adam Muszyński oraz Diana i Przemek Jaworscy, założyciele firmy produkującej innowacyjny element ubioru chroniący przed smogiem.
+ Oni, jak i wielu ich znajomych, chcieli zadbać o zdrowie. Jednym ze sposobów na to jest noszenie specjalnej maseczki z filtrem. Do obrazka, na którym ludzie mają pozasłaniane białymi maseczkami twarze, przywykliśmy oglądając relacje z największych miast Azji, gdzie problem smogu jest szczególnie widoczny.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Wyprbuj cyfrow Wyborcz
+Nieograniczony dostp do serwisw informacyjnych, biznesowych, lokalnych i wszystkich magazynw Wyborczej
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Inne
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Konsument i zakupy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Konsument i zakupy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Konsument i zakupy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Konsument i zakupy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Konsument i zakupy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Konsument i zakupy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Zobacz take
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Wiadomoci - najwaniejsze informacje
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index 3043d2be6..e9f5bbb88 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -657,6 +657,10 @@ defmodule HttpRequestMock do
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
end
+ def get("http://example.com/malformed", _, _, _) do
+ {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
+ end
+
def get("http://example.com/empty", _, _, _) do
{:ok, %Tesla.Env{status: 200, body: "hello"}}
end
--
cgit v1.2.3
From 3f5b78459661d8b2d9d6c3edf5a4010fc4a53909 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Thu, 31 Jan 2019 16:19:53 +0000
Subject: test: rich media: parser: add malformed data regression test
---
test/web/rich_media/parser_test.exs | 4 ++++
1 file changed, 4 insertions(+)
(limited to 'test')
diff --git a/test/web/rich_media/parser_test.exs b/test/web/rich_media/parser_test.exs
index 93a58c528..47b127cf9 100644
--- a/test/web/rich_media/parser_test.exs
+++ b/test/web/rich_media/parser_test.exs
@@ -88,4 +88,8 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
width: "1024"
}}
end
+
+ test "rejects invalid OGP data" do
+ assert {:error, _} = Pleroma.Web.RichMedia.Parser.parse("http://example.com/malformed")
+ end
end
--
cgit v1.2.3
From 106475f265f1d36c28c22361616d7e95ae96d674 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Thu, 31 Jan 2019 16:30:56 +0000
Subject: test: http mocks: formatting
---
test/support/http_request_mock.ex | 53 +++++++++++++++++++++++++++++++--------
1 file changed, 42 insertions(+), 11 deletions(-)
(limited to 'test')
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index e9f5bbb88..c60f61873 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -143,7 +143,10 @@ defmodule HttpRequestMock do
}}
end
- def get("https://squeet.me/xrd/?uri=lain@squeet.me", _, _,
+ def get(
+ "https://squeet.me/xrd/?uri=lain@squeet.me",
+ _,
+ _,
Accept: "application/xrd+xml,application/jrd+json"
) do
{:ok,
@@ -153,7 +156,10 @@ defmodule HttpRequestMock do
}}
end
- def get("https://mst3k.interlinked.me/users/luciferMysticus", _, _,
+ def get(
+ "https://mst3k.interlinked.me/users/luciferMysticus",
+ _,
+ _,
Accept: "application/activity+json"
) do
{:ok,
@@ -171,7 +177,10 @@ defmodule HttpRequestMock do
}}
end
- def get("https://hubzilla.example.org/channel/kaniini", _, _,
+ def get(
+ "https://hubzilla.example.org/channel/kaniini",
+ _,
+ _,
Accept: "application/activity+json"
) do
{:ok,
@@ -248,7 +257,10 @@ defmodule HttpRequestMock do
}}
end
- def get("http://mastodon.example.org/@admin/99541947525187367", _, _,
+ def get(
+ "http://mastodon.example.org/@admin/99541947525187367",
+ _,
+ _,
Accept: "application/activity+json"
) do
{:ok,
@@ -274,7 +286,10 @@ defmodule HttpRequestMock do
}}
end
- def get("https://mstdn.io/users/mayuutann/statuses/99568293732299394", _, _,
+ def get(
+ "https://mstdn.io/users/mayuutann/statuses/99568293732299394",
+ _,
+ _,
Accept: "application/activity+json"
) do
{:ok,
@@ -429,7 +444,10 @@ defmodule HttpRequestMock do
}}
end
- def get("https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056", _, _,
+ def get(
+ "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056",
+ _,
+ _,
Accept: "application/atom+xml"
) do
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/httpoison_mock/sakamoto.atom")}}
@@ -510,7 +528,10 @@ defmodule HttpRequestMock do
%Tesla.Env{status: 200, body: File.read!("test/fixtures/httpoison_mock/squeet.me_host_meta")}}
end
- def get("https://squeet.me/xrd?uri=lain@squeet.me", _, _,
+ def get(
+ "https://squeet.me/xrd?uri=lain@squeet.me",
+ _,
+ _,
Accept: "application/xrd+xml,application/jrd+json"
) do
{:ok,
@@ -541,7 +562,10 @@ defmodule HttpRequestMock do
}}
end
- def get("http://framatube.org/main/xrd?uri=framasoft@framatube.org", _, _,
+ def get(
+ "http://framatube.org/main/xrd?uri=framasoft@framatube.org",
+ _,
+ _,
Accept: "application/xrd+xml,application/jrd+json"
) do
{:ok,
@@ -560,7 +584,10 @@ defmodule HttpRequestMock do
}}
end
- def get("http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de", _, _,
+ def get(
+ "http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de",
+ _,
+ _,
Accept: "application/xrd+xml,application/jrd+json"
) do
{:ok,
@@ -594,7 +621,10 @@ defmodule HttpRequestMock do
}}
end
- def get("https://gerzilla.de/xrd/?uri=kaniini@gerzilla.de", _, _,
+ def get(
+ "https://gerzilla.de/xrd/?uri=kaniini@gerzilla.de",
+ _,
+ _,
Accept: "application/xrd+xml,application/jrd+json"
) do
{:ok,
@@ -658,7 +688,8 @@ defmodule HttpRequestMock do
end
def get("http://example.com/malformed", _, _, _) do
- {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
+ {:ok,
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
end
def get("http://example.com/empty", _, _, _) do
--
cgit v1.2.3
From 308b35ebe2f2062b87a5d7703df8ab5b1210d9c8 Mon Sep 17 00:00:00 2001
From: href
Date: Thu, 31 Jan 2019 18:07:46 +0100
Subject: User.follow_all: ensure its stays unique
---
test/user_test.exs | 13 +++++++++++++
1 file changed, 13 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 9815c4d5a..98d3bc464 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -65,6 +65,19 @@ defmodule Pleroma.UserTest do
refute User.following?(user, not_followed)
end
+ test "follow_all follows mutliple users without duplicating" do
+ user = insert(:user)
+ followed_zero = insert(:user)
+ followed_one = insert(:user)
+ followed_two = insert(:user)
+
+ {:ok, user} = User.follow_all(user, [followed_zero, followed_one])
+ assert length(user.following) == 3
+
+ {:ok, user} = User.follow_all(user, [followed_one, followed_two])
+ assert length(user.following) == 4
+ end
+
test "follow takes a user and another user" do
user = insert(:user)
followed = insert(:user)
--
cgit v1.2.3
From c05928dbdabfafc536512341e8d64b240b097f62 Mon Sep 17 00:00:00 2001
From: Luna
Date: Fri, 1 Feb 2019 03:55:10 -0300
Subject: use nodeinfo 2.1, add repository field
that is the only change from nodeinfo 2.0 to 2.1
also this makes the nodeinfo tests use 2.1.json instead of 2.0.json
---
test/web/node_info_test.exs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs
index 5981c70a7..360ee0baf 100644
--- a/test/web/node_info_test.exs
+++ b/test/web/node_info_test.exs
@@ -12,7 +12,7 @@ defmodule Pleroma.Web.NodeInfoTest do
conn =
conn
- |> get("/nodeinfo/2.0.json")
+ |> get("/nodeinfo/2.1.json")
assert result = json_response(conn, 200)
@@ -22,7 +22,7 @@ defmodule Pleroma.Web.NodeInfoTest do
test "nodeinfo shows restricted nicknames", %{conn: conn} do
conn =
conn
- |> get("/nodeinfo/2.0.json")
+ |> get("/nodeinfo/2.1.json")
assert result = json_response(conn, 200)
@@ -42,7 +42,7 @@ defmodule Pleroma.Web.NodeInfoTest do
|> json_response(404)
conn
- |> get("/nodeinfo/2.0.json")
+ |> get("/nodeinfo/2.1.json")
|> json_response(404)
instance =
@@ -58,7 +58,7 @@ defmodule Pleroma.Web.NodeInfoTest do
|> json_response(200)
conn
- |> get("/nodeinfo/2.0.json")
+ |> get("/nodeinfo/2.1.json")
|> json_response(200)
end
end
--
cgit v1.2.3
From e8c7be38fcf416eb8676c5e586c56c15b4f88986 Mon Sep 17 00:00:00 2001
From: Luna
Date: Fri, 1 Feb 2019 14:33:14 -0300
Subject: add tests for nodeinfo 2.0 compat and 2.1's new field
---
test/web/node_info_test.exs | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
(limited to 'test')
diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs
index 360ee0baf..763549bd1 100644
--- a/test/web/node_info_test.exs
+++ b/test/web/node_info_test.exs
@@ -61,4 +61,49 @@ defmodule Pleroma.Web.NodeInfoTest do
|> get("/nodeinfo/2.1.json")
|> json_response(200)
end
+
+ test "returns 404 when federation is disabled (nodeinfo 2.0)", %{conn: conn} do
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:federating, false)
+
+ Application.put_env(:pleroma, :instance, instance)
+
+ conn
+ |> get("/.well-known/nodeinfo")
+ |> json_response(404)
+
+ conn
+ |> get("/nodeinfo/2.0.json")
+ |> json_response(404)
+
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:federating, true)
+
+ Application.put_env(:pleroma, :instance, instance)
+ end
+
+ test "returns 200 when federation is enabled (nodeinfo 2.0)", %{conn: conn} do
+ conn
+ |> get("/.well-known/nodeinfo")
+ |> json_response(200)
+
+ conn
+ |> get("/nodeinfo/2.0.json")
+ |> json_response(200)
+ end
+
+ test "returns software.repository field in nodeinfo 2.1", %{conn: conn} do
+ conn
+ |> get("/.well-known/nodeinfo")
+ |> json_response(200)
+
+ conn =
+ conn
+ |> get("/nodeinfo/2.1.json")
+
+ assert result = json_response(conn, 200)
+ assert Pleroma.Application.repository() == result["software"]["repository"]
+ end
end
--
cgit v1.2.3
From 486749064f72ac5078a42ed339519afbbf48027a Mon Sep 17 00:00:00 2001
From: kaniini
Date: Fri, 1 Feb 2019 20:22:58 +0000
Subject: Revert "Merge branch 'feature/split-hide-network' into 'develop'"
This reverts merge request !733
---
.../activity_pub/activity_pub_controller_test.exs | 8 +--
.../mastodon_api/mastodon_api_controller_test.exs | 16 +++---
.../twitter_api/twitter_api_controller_test.exs | 60 ++++++----------------
test/web/twitter_api/views/user_view_test.exs | 12 ++---
4 files changed, 33 insertions(+), 63 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 0a0103793..d3dd160dd 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -386,9 +386,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert result["first"]["orderedItems"] == [user.ap_id]
end
- test "it returns returns empty if the user has 'hide_followers' set", %{conn: conn} do
+ test "it returns returns empty if the user has 'hide_network' set", %{conn: conn} do
user = insert(:user)
- user_two = insert(:user, %{info: %{hide_followers: true}})
+ user_two = insert(:user, %{info: %{hide_network: true}})
User.follow(user, user_two)
result =
@@ -441,8 +441,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert result["first"]["orderedItems"] == [user_two.ap_id]
end
- test "it returns returns empty if the user has 'hide_followings' set", %{conn: conn} do
- user = insert(:user, %{info: %{hide_followings: true}})
+ test "it returns returns empty if the user has 'hide_network' set", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_network: true}})
user_two = insert(:user)
User.follow(user, user_two)
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index dc6c7e0e8..141d300c7 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1099,9 +1099,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert id == to_string(user.id)
end
- test "getting followers, hide_followers", %{conn: conn} do
+ test "getting followers, hide_network", %{conn: conn} do
user = insert(:user)
- other_user = insert(:user, %{info: %{hide_followers: true}})
+ other_user = insert(:user, %{info: %{hide_network: true}})
{:ok, _user} = User.follow(user, other_user)
conn =
@@ -1111,9 +1111,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [] == json_response(conn, 200)
end
- test "getting followers, hide_followers, same user requesting", %{conn: conn} do
+ test "getting followers, hide_network, same user requesting", %{conn: conn} do
user = insert(:user)
- other_user = insert(:user, %{info: %{hide_followers: true}})
+ other_user = insert(:user, %{info: %{hide_network: true}})
{:ok, _user} = User.follow(user, other_user)
conn =
@@ -1137,8 +1137,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert id == to_string(other_user.id)
end
- test "getting following, hide_followings", %{conn: conn} do
- user = insert(:user, %{info: %{hide_followings: true}})
+ test "getting following, hide_network", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_network: true}})
other_user = insert(:user)
{:ok, user} = User.follow(user, other_user)
@@ -1149,8 +1149,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [] == json_response(conn, 200)
end
- test "getting following, hide_followings, same user requesting", %{conn: conn} do
- user = insert(:user, %{info: %{hide_followings: true}})
+ test "getting following, hide_network, same user requesting", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_network: true}})
other_user = insert(:user)
{:ok, user} = User.follow(user, other_user)
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 6777354c3..863abd10f 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1132,8 +1132,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
)
end
- test "it returns empty when hide_followers is set to true", %{conn: conn} do
- user = insert(:user, %{info: %{hide_followers: true}})
+ test "it returns empty for a hidden network", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_network: true}})
follower_one = insert(:user)
follower_two = insert(:user)
not_follower = insert(:user)
@@ -1150,11 +1150,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert [] == response
end
- test "it returns the followers when hide_followers is set to true if requested by the user themselves",
- %{
- conn: conn
- } do
- user = insert(:user, %{info: %{hide_followers: true}})
+ test "it returns the followers for a hidden network if requested by the user themselves", %{
+ conn: conn
+ } do
+ user = insert(:user, %{info: %{hide_network: true}})
follower_one = insert(:user)
follower_two = insert(:user)
_not_follower = insert(:user)
@@ -1257,8 +1256,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
)
end
- test "it returns empty when hide_followings is set to true", %{conn: conn} do
- user = insert(:user, %{info: %{hide_followings: true}})
+ test "it returns empty for a hidden network", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_network: true}})
followed_one = insert(:user)
followed_two = insert(:user)
not_followed = insert(:user)
@@ -1274,11 +1273,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert [] == json_response(conn, 200)
end
- test "it returns friends when hide_followings is set to true if the user themselves request it",
- %{
- conn: conn
- } do
- user = insert(:user, %{info: %{hide_followings: true}})
+ test "it returns friends for a hidden network if the user themselves request it", %{
+ conn: conn
+ } do
+ user = insert(:user, %{info: %{hide_network: true}})
followed_one = insert(:user)
followed_two = insert(:user)
_not_followed = insert(:user)
@@ -1366,51 +1364,27 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
- test "it sets and un-sets hide_followings", %{conn: conn} do
- user = insert(:user)
-
- conn
- |> assign(:user, user)
- |> post("/api/account/update_profile.json", %{
- "hide_followings" => "true"
- })
-
- user = Repo.get!(User, user.id)
- assert user.info.hide_followings == true
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/account/update_profile.json", %{
- "hide_followings" => "false"
- })
-
- user = Repo.get!(User, user.id)
- assert user.info.hide_followings == false
- assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
- end
-
- test "it sets and un-sets hide_followers", %{conn: conn} do
+ test "it sets and un-sets hide_network", %{conn: conn} do
user = insert(:user)
conn
|> assign(:user, user)
|> post("/api/account/update_profile.json", %{
- "hide_followers" => "true"
+ "hide_network" => "true"
})
user = Repo.get!(User, user.id)
- assert user.info.hide_followers == true
+ assert user.info.hide_network == true
conn =
conn
|> assign(:user, user)
|> post("/api/account/update_profile.json", %{
- "hide_followers" => "false"
+ "hide_network" => "false"
})
user = Repo.get!(User, user.id)
- assert user.info.hide_followers == false
+ assert user.info.hide_network == false
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 0885afaec..daf18c1c5 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -100,8 +100,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "hide_followings" => false,
- "hide_followers" => false,
+ "hide_network" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
@@ -148,8 +147,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "hide_followings" => false,
- "hide_followers" => false,
+ "hide_network" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
@@ -197,8 +195,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "hide_followings" => false,
- "hide_followers" => false,
+ "hide_network" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
@@ -260,8 +257,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "hide_followings" => false,
- "hide_followers" => false,
+ "hide_network" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
--
cgit v1.2.3
From b40b4bc4e5b49ac2b35746cee7b1db92428d3ee1 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Sun, 3 Feb 2019 12:41:27 +0300
Subject: [#582] Optimized federation retirement by reducing the number of SQL
calls (calling `Instances.set_reachable/1` only if instance had
`unreachable_since`, calling `Instances.set_unreachable/1` only if instance
had nil `unreachable_since`).
---
test/web/federator_test.exs | 4 ++--
test/web/instances/instances_test.exs | 23 +++++++++++++++++++++--
2 files changed, 23 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index c6d10ef78..7bb249d74 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -163,8 +163,8 @@ defmodule Pleroma.Web.FederatorTest do
{:ok, _activity} =
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
- assert called(Federator.enqueue(:publish_single_salmon, {remote_user2, :_, :_}))
- refute called(Federator.enqueue(:publish_single_websub, {remote_user1, :_, :_}))
+ assert called(Federator.enqueue(:publish_single_salmon, %{recipient: remote_user2}))
+ refute called(Federator.enqueue(:publish_single_websub, %{recipient: remote_user1}))
end
end
diff --git a/test/web/instances/instances_test.exs b/test/web/instances/instances_test.exs
index adb8560a7..2530c09fe 100644
--- a/test/web/instances/instances_test.exs
+++ b/test/web/instances/instances_test.exs
@@ -47,7 +47,7 @@ defmodule Pleroma.InstancesTest do
end
describe "filter_reachable/1" do
- test "keeps only reachable elements of supplied list" do
+ setup do
host = "consistently-unreachable.name"
url1 = "http://eventually-unreachable.com/path"
url2 = "http://domain.com/path"
@@ -55,7 +55,26 @@ defmodule Pleroma.InstancesTest do
Instances.set_consistently_unreachable(host)
Instances.set_unreachable(url1)
- assert [url1, url2] == Instances.filter_reachable([host, url1, url2])
+ result = Instances.filter_reachable([host, url1, url2, nil])
+ %{result: result, url1: url1, url2: url2}
+ end
+
+ test "returns a map with keys containing 'not marked consistently unreachable' elements of supplied list",
+ %{result: result, url1: url1, url2: url2} do
+ assert is_map(result)
+ assert Enum.sort([url1, url2]) == result |> Map.keys() |> Enum.sort()
+ end
+
+ test "returns a map with `unreachable_since` values for keys",
+ %{result: result, url1: url1, url2: url2} do
+ assert is_map(result)
+ assert %NaiveDateTime{} = result[url1]
+ assert is_nil(result[url2])
+ end
+
+ test "returns an empty map for empty list or list containing no hosts / url" do
+ assert %{} == Instances.filter_reachable([])
+ assert %{} == Instances.filter_reachable([nil])
end
end
--
cgit v1.2.3
From 3913b0196e47c829df90aa835ade2efdb7c43850 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Sun, 3 Feb 2019 13:28:13 +0300
Subject: [#582] Made single-pub task call Instance.set_reachable/1 if
`set_reachable` is not specified. Added tests.
---
test/web/activity_pub/activity_pub_test.exs | 73 ++++++++++++++++++++++++++++-
test/web/federator_test.exs | 35 +++++++++++---
2 files changed, 99 insertions(+), 9 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 2ada4f2e5..a55961ac4 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -698,7 +698,57 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end
describe "publish_one/1" do
- test_with_mock "it calls `Instances.set_unreachable` on target inbox on non-2xx HTTP response code",
+ test_with_mock "calls `Instances.set_reachable` on successful federation if `unreachable_since` is not specified",
+ Instances,
+ [:passthrough],
+ [] do
+ actor = insert(:user)
+ inbox = "http://200.site/users/nick1/inbox"
+
+ assert {:ok, _} = ActivityPub.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1})
+
+ assert called(Instances.set_reachable(inbox))
+ end
+
+ test_with_mock "calls `Instances.set_reachable` on successful federation if `unreachable_since` is set",
+ Instances,
+ [:passthrough],
+ [] do
+ actor = insert(:user)
+ inbox = "http://200.site/users/nick1/inbox"
+
+ assert {:ok, _} =
+ ActivityPub.publish_one(%{
+ inbox: inbox,
+ json: "{}",
+ actor: actor,
+ id: 1,
+ unreachable_since: NaiveDateTime.utc_now()
+ })
+
+ assert called(Instances.set_reachable(inbox))
+ end
+
+ test_with_mock "does NOT call `Instances.set_reachable` on successful federation if `unreachable_since` is nil",
+ Instances,
+ [:passthrough],
+ [] do
+ actor = insert(:user)
+ inbox = "http://200.site/users/nick1/inbox"
+
+ assert {:ok, _} =
+ ActivityPub.publish_one(%{
+ inbox: inbox,
+ json: "{}",
+ actor: actor,
+ id: 1,
+ unreachable_since: nil
+ })
+
+ refute called(Instances.set_reachable(inbox))
+ end
+
+ test_with_mock "calls `Instances.set_unreachable` on target inbox on non-2xx HTTP response code",
Instances,
[:passthrough],
[] do
@@ -724,7 +774,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert called(Instances.set_unreachable(inbox))
end
- test_with_mock "it does NOT call `Instances.set_unreachable` if target is reachable",
+ test_with_mock "does NOT call `Instances.set_unreachable` if target is reachable",
Instances,
[:passthrough],
[] do
@@ -735,6 +785,25 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
refute called(Instances.set_unreachable(inbox))
end
+
+ test_with_mock "does NOT call `Instances.set_unreachable` if target instance has non-nil `unreachable_since`",
+ Instances,
+ [:passthrough],
+ [] do
+ actor = insert(:user)
+ inbox = "http://connrefused.site/users/nick1/inbox"
+
+ assert {:error, _} =
+ ActivityPub.publish_one(%{
+ inbox: inbox,
+ json: "{}",
+ actor: actor,
+ id: 1,
+ unreachable_since: NaiveDateTime.utc_now()
+ })
+
+ refute called(Instances.set_unreachable(inbox))
+ end
end
def data_uri do
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 7bb249d74..05f813291 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -95,15 +95,18 @@ defmodule Pleroma.Web.FederatorTest do
info: %{ap_enabled: true, source_data: %{"inbox" => inbox2}}
})
- Instances.set_unreachable(
- URI.parse(inbox2).host,
- Instances.reachability_datetime_threshold()
- )
+ dt = NaiveDateTime.utc_now()
+ Instances.set_unreachable(inbox1, dt)
+
+ Instances.set_consistently_unreachable(URI.parse(inbox2).host)
{:ok, _activity} =
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
- assert called(Federator.enqueue(:publish_single_ap, %{inbox: inbox1}))
+ assert called(
+ Federator.enqueue(:publish_single_ap, %{inbox: inbox1, unreachable_since: dt})
+ )
+
refute called(Federator.enqueue(:publish_single_ap, %{inbox: inbox2}))
end
@@ -128,11 +131,20 @@ defmodule Pleroma.Web.FederatorTest do
callback: "https://pleroma2.soykaf.com/cb"
})
+ dt = NaiveDateTime.utc_now()
+ Instances.set_unreachable(sub2.callback, dt)
+
Instances.set_consistently_unreachable(sub1.callback)
{:ok, _activity} = CommonAPI.post(user, %{"status" => "HI"})
- assert called(Federator.enqueue(:publish_single_websub, %{callback: sub2.callback}))
+ assert called(
+ Federator.enqueue(:publish_single_websub, %{
+ callback: sub2.callback,
+ unreachable_since: dt
+ })
+ )
+
refute called(Federator.enqueue(:publish_single_websub, %{callback: sub1.callback}))
end
@@ -158,12 +170,21 @@ defmodule Pleroma.Web.FederatorTest do
info: %{salmon: "https://domain2.com/salmon"}
})
+ dt = NaiveDateTime.utc_now()
+ Instances.set_unreachable(remote_user2.ap_id, dt)
+
Instances.set_consistently_unreachable("domain.com")
{:ok, _activity} =
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
- assert called(Federator.enqueue(:publish_single_salmon, %{recipient: remote_user2}))
+ assert called(
+ Federator.enqueue(:publish_single_salmon, %{
+ recipient: remote_user2,
+ unreachable_since: dt
+ })
+ )
+
refute called(Federator.enqueue(:publish_single_websub, %{recipient: remote_user1}))
end
end
--
cgit v1.2.3
From 505a084058eeeed7d945b43630c97c38cafec656 Mon Sep 17 00:00:00 2001
From: lain
Date: Sun, 3 Feb 2019 18:28:14 +0100
Subject: Still do caching in tests.
---
test/web/twitter_api/twitter_api_test.exs | 15 +++++++++++++++
1 file changed, 15 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index f94e2b873..48ddbcf50 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -200,12 +200,27 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
test "it favorites a status, returns the updated activity" do
user = insert(:user)
+ other_user = insert(:user)
note_activity = insert(:note_activity)
{:ok, status} = TwitterAPI.fav(user, note_activity.id)
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
+ assert ActivityView.render("activity.json", %{activity: updated_activity})["fave_num"] == 1
+
+ object = Object.normalize(note_activity.data["object"])
+
+ assert object.data["like_count"] == 1
assert status == updated_activity
+
+ {:ok, _status} = TwitterAPI.fav(other_user, note_activity.id)
+
+ object = Object.normalize(note_activity.data["object"])
+
+ assert object.data["like_count"] == 2
+
+ updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
+ assert ActivityView.render("activity.json", %{activity: updated_activity})["fave_num"] == 2
end
test "it unfavorites a status, returns the updated activity" do
--
cgit v1.2.3
From e61f0be9518aff867f4c56f5102723eddbcf40f1 Mon Sep 17 00:00:00 2001
From: lain
Date: Sun, 3 Feb 2019 18:54:39 +0100
Subject: Unbreak all the tests.
---
test/support/conn_case.ex | 1 +
test/support/data_case.ex | 1 +
test/web/mastodon_api/mastodon_api_controller_test.exs | 5 +++++
test/web/ostatus/ostatus_test.exs | 2 ++
4 files changed, 9 insertions(+)
(limited to 'test')
diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex
index c201d9a9b..ec5892ff5 100644
--- a/test/support/conn_case.ex
+++ b/test/support/conn_case.ex
@@ -33,6 +33,7 @@ defmodule Pleroma.Web.ConnCase do
setup tags do
Cachex.clear(:user_cache)
+ Cachex.clear(:object_cache)
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
unless tags[:async] do
diff --git a/test/support/data_case.ex b/test/support/data_case.ex
index 56d5896ad..df260bd3f 100644
--- a/test/support/data_case.ex
+++ b/test/support/data_case.ex
@@ -32,6 +32,7 @@ defmodule Pleroma.DataCase do
setup tags do
Cachex.clear(:user_cache)
+ Cachex.clear(:object_cache)
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
unless tags[:async] do
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 141d300c7..8528d4f64 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -137,6 +137,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
test "posting a status with OGP link preview", %{conn: conn} do
+ Pleroma.Config.put([:rich_media, :enabled], true)
user = insert(:user)
conn =
@@ -148,6 +149,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"id" => id, "card" => %{"title" => "The Rock"}} = json_response(conn, 200)
assert Repo.get(Activity, id)
+ Pleroma.Config.put([:rich_media, :enabled], false)
end
test "posting a direct status", %{conn: conn} do
@@ -1667,6 +1669,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
test "Status rich-media Card", %{conn: conn, user: user} do
+ Pleroma.Config.put([:rich_media, :enabled], true)
{:ok, activity} = CommonAPI.post(user, %{"status" => "http://example.com/ogp"})
response =
@@ -1691,6 +1694,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
}
}
}
+
+ Pleroma.Config.put([:rich_media, :enabled], false)
end
end
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index 0c63dd84d..dbe5de2e2 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -530,6 +530,8 @@ defmodule Pleroma.Web.OStatusTest do
note_object.data
|> Map.put("type", "Article")
+ Cachex.clear(:object_cache)
+
cs = Object.change(note_object, %{data: note_data})
{:ok, _article_object} = Repo.update(cs)
--
cgit v1.2.3
From 16ce129e382cc5fa0cf5d86fc0785457a0dedd76 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Sun, 3 Feb 2019 21:24:09 +0300
Subject: Split hide_network into hide_followers & hide_followings (fixed)
---
.../activity_pub/activity_pub_controller_test.exs | 8 +--
.../mastodon_api/mastodon_api_controller_test.exs | 16 +++---
.../twitter_api/twitter_api_controller_test.exs | 60 ++++++++++++++++------
test/web/twitter_api/views/user_view_test.exs | 12 +++--
4 files changed, 63 insertions(+), 33 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index d3dd160dd..0a0103793 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -386,9 +386,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert result["first"]["orderedItems"] == [user.ap_id]
end
- test "it returns returns empty if the user has 'hide_network' set", %{conn: conn} do
+ test "it returns returns empty if the user has 'hide_followers' set", %{conn: conn} do
user = insert(:user)
- user_two = insert(:user, %{info: %{hide_network: true}})
+ user_two = insert(:user, %{info: %{hide_followers: true}})
User.follow(user, user_two)
result =
@@ -441,8 +441,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert result["first"]["orderedItems"] == [user_two.ap_id]
end
- test "it returns returns empty if the user has 'hide_network' set", %{conn: conn} do
- user = insert(:user, %{info: %{hide_network: true}})
+ test "it returns returns empty if the user has 'hide_followings' set", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_followings: true}})
user_two = insert(:user)
User.follow(user, user_two)
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 8528d4f64..d4e2acae3 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1101,9 +1101,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert id == to_string(user.id)
end
- test "getting followers, hide_network", %{conn: conn} do
+ test "getting followers, hide_followers", %{conn: conn} do
user = insert(:user)
- other_user = insert(:user, %{info: %{hide_network: true}})
+ other_user = insert(:user, %{info: %{hide_followers: true}})
{:ok, _user} = User.follow(user, other_user)
conn =
@@ -1113,9 +1113,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [] == json_response(conn, 200)
end
- test "getting followers, hide_network, same user requesting", %{conn: conn} do
+ test "getting followers, hide_followers, same user requesting", %{conn: conn} do
user = insert(:user)
- other_user = insert(:user, %{info: %{hide_network: true}})
+ other_user = insert(:user, %{info: %{hide_followers: true}})
{:ok, _user} = User.follow(user, other_user)
conn =
@@ -1139,8 +1139,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert id == to_string(other_user.id)
end
- test "getting following, hide_network", %{conn: conn} do
- user = insert(:user, %{info: %{hide_network: true}})
+ test "getting following, hide_followings", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_followings: true}})
other_user = insert(:user)
{:ok, user} = User.follow(user, other_user)
@@ -1151,8 +1151,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [] == json_response(conn, 200)
end
- test "getting following, hide_network, same user requesting", %{conn: conn} do
- user = insert(:user, %{info: %{hide_network: true}})
+ test "getting following, hide_followings, same user requesting", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_followings: true}})
other_user = insert(:user)
{:ok, user} = User.follow(user, other_user)
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 863abd10f..6777354c3 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1132,8 +1132,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
)
end
- test "it returns empty for a hidden network", %{conn: conn} do
- user = insert(:user, %{info: %{hide_network: true}})
+ test "it returns empty when hide_followers is set to true", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_followers: true}})
follower_one = insert(:user)
follower_two = insert(:user)
not_follower = insert(:user)
@@ -1150,10 +1150,11 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert [] == response
end
- test "it returns the followers for a hidden network if requested by the user themselves", %{
- conn: conn
- } do
- user = insert(:user, %{info: %{hide_network: true}})
+ test "it returns the followers when hide_followers is set to true if requested by the user themselves",
+ %{
+ conn: conn
+ } do
+ user = insert(:user, %{info: %{hide_followers: true}})
follower_one = insert(:user)
follower_two = insert(:user)
_not_follower = insert(:user)
@@ -1256,8 +1257,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
)
end
- test "it returns empty for a hidden network", %{conn: conn} do
- user = insert(:user, %{info: %{hide_network: true}})
+ test "it returns empty when hide_followings is set to true", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_followings: true}})
followed_one = insert(:user)
followed_two = insert(:user)
not_followed = insert(:user)
@@ -1273,10 +1274,11 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert [] == json_response(conn, 200)
end
- test "it returns friends for a hidden network if the user themselves request it", %{
- conn: conn
- } do
- user = insert(:user, %{info: %{hide_network: true}})
+ test "it returns friends when hide_followings is set to true if the user themselves request it",
+ %{
+ conn: conn
+ } do
+ user = insert(:user, %{info: %{hide_followings: true}})
followed_one = insert(:user)
followed_two = insert(:user)
_not_followed = insert(:user)
@@ -1364,27 +1366,51 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
- test "it sets and un-sets hide_network", %{conn: conn} do
+ test "it sets and un-sets hide_followings", %{conn: conn} do
+ user = insert(:user)
+
+ conn
+ |> assign(:user, user)
+ |> post("/api/account/update_profile.json", %{
+ "hide_followings" => "true"
+ })
+
+ user = Repo.get!(User, user.id)
+ assert user.info.hide_followings == true
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/account/update_profile.json", %{
+ "hide_followings" => "false"
+ })
+
+ user = Repo.get!(User, user.id)
+ assert user.info.hide_followings == false
+ assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
+ end
+
+ test "it sets and un-sets hide_followers", %{conn: conn} do
user = insert(:user)
conn
|> assign(:user, user)
|> post("/api/account/update_profile.json", %{
- "hide_network" => "true"
+ "hide_followers" => "true"
})
user = Repo.get!(User, user.id)
- assert user.info.hide_network == true
+ assert user.info.hide_followers == true
conn =
conn
|> assign(:user, user)
|> post("/api/account/update_profile.json", %{
- "hide_network" => "false"
+ "hide_followers" => "false"
})
user = Repo.get!(User, user.id)
- assert user.info.hide_network == false
+ assert user.info.hide_followers == false
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index daf18c1c5..0885afaec 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -100,7 +100,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "hide_network" => false,
+ "hide_followings" => false,
+ "hide_followers" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
@@ -147,7 +148,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "hide_network" => false,
+ "hide_followings" => false,
+ "hide_followers" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
@@ -195,7 +197,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "hide_network" => false,
+ "hide_followings" => false,
+ "hide_followers" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
@@ -257,7 +260,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "hide_network" => false,
+ "hide_followings" => false,
+ "hide_followers" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
--
cgit v1.2.3
From c4d317ccb679f7fef11983b9629249e047bec4db Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Tue, 5 Feb 2019 18:49:02 +0000
Subject: test: twitterapi: fix the test breakage for real
---
test/web/twitter_api/util_controller_test.exs | 1 +
1 file changed, 1 insertion(+)
(limited to 'test')
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index dc9bad369..8e152ecd4 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -36,6 +36,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
describe "GET /api/statusnet/config.json" do
test "it returns the managed config", %{conn: conn} do
Pleroma.Config.put([:instance, :managed_config], false)
+ Pleroma.Config.put([:fe, :theme], "rei-ayanami-towel")
response =
conn
--
cgit v1.2.3
From 73e6a1f1dd9bfe9ebf95308292ecb9a2dd67abe4 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Tue, 5 Feb 2019 20:04:39 +0000
Subject: test: twitterapi: fix another possible test failure case
---
test/web/twitter_api/util_controller_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index 8e152ecd4..007d7d8e6 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -36,7 +36,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
describe "GET /api/statusnet/config.json" do
test "it returns the managed config", %{conn: conn} do
Pleroma.Config.put([:instance, :managed_config], false)
- Pleroma.Config.put([:fe, :theme], "rei-ayanami-towel")
+ Pleroma.Config.put([:fe], theme: "rei-ayanami-towel")
response =
conn
--
cgit v1.2.3
From 398c81f9c8e55b280e64948b4ac63ae51fabd32f Mon Sep 17 00:00:00 2001
From: eugenijm
Date: Mon, 4 Feb 2019 05:03:57 +0300
Subject: Add is_admin and is_moderator boolean fields to the user view
---
test/web/twitter_api/views/user_view_test.exs | 8 ++++++++
1 file changed, 8 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 0885afaec..637b84d72 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -97,6 +97,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
+ "is_admin" => false,
+ "is_moderator" => false,
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
@@ -145,6 +147,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
+ "is_admin" => false,
+ "is_moderator" => false,
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
@@ -194,6 +198,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
+ "is_admin" => false,
+ "is_moderator" => false,
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
@@ -257,6 +263,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
+ "is_admin" => false,
+ "is_moderator" => false,
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
--
cgit v1.2.3
From 035eaeb9b8702ed233e8bb589a78838efd1f131e Mon Sep 17 00:00:00 2001
From: eugenijm
Date: Mon, 4 Feb 2019 15:28:35 +0300
Subject: Allow to configure visibility for admin and moderator badges
---
.../twitter_api/twitter_api_controller_test.exs | 40 +++++++++++++++++++---
test/web/twitter_api/views/user_view_test.exs | 24 ++++++++-----
2 files changed, 51 insertions(+), 13 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 6777354c3..cb98f1809 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -62,7 +62,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> post("/api/account/verify_credentials.json")
|> json_response(200)
- assert response == UserView.render("show.json", %{user: user, token: response["token"]})
+ assert response ==
+ UserView.render("show.json", %{user: user, token: response["token"], for: user})
end
end
@@ -107,7 +108,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> post(request_path, %{status: "Nice meme.", visibility: "private"})
assert json_response(conn, 200) ==
- ActivityRepresenter.to_map(Repo.one(Activity), %{user: user})
+ ActivityRepresenter.to_map(Repo.one(Activity), %{user: user, for: user})
end
end
@@ -418,6 +419,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert Enum.at(response, 0) ==
ActivityRepresenter.to_map(activity, %{
user: current_user,
+ for: current_user,
mentioned: [current_user]
})
end
@@ -547,7 +549,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
response = json_response(conn, 200)
assert length(response) == 1
- assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: current_user})
+
+ assert Enum.at(response, 0) ==
+ ActivityRepresenter.to_map(activity, %{user: current_user, for: current_user})
end
test "with credentials with user_id", %{conn: conn, user: current_user} do
@@ -1414,6 +1418,30 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
+ test "it sets and un-sets show_role", %{conn: conn} do
+ user = insert(:user)
+
+ conn
+ |> assign(:user, user)
+ |> post("/api/account/update_profile.json", %{
+ "show_role" => "true"
+ })
+
+ user = Repo.get!(User, user.id)
+ assert user.info.show_role == true
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/account/update_profile.json", %{
+ "show_role" => "false"
+ })
+
+ user = Repo.get!(User, user.id)
+ assert user.info.show_role == false
+ assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
+ end
+
test "it locks an account", %{conn: conn} do
user = insert(:user)
@@ -1814,7 +1842,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
user = refresh_record(user)
- assert json_response(response, 200) == ActivityRepresenter.to_map(activity, %{user: user})
+ assert json_response(response, 200) ==
+ ActivityRepresenter.to_map(activity, %{user: user, for: user})
end
end
@@ -1843,7 +1872,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
user = refresh_record(user)
- assert json_response(response, 200) == ActivityRepresenter.to_map(activity, %{user: user})
+ assert json_response(response, 200) ==
+ ActivityRepresenter.to_map(activity, %{user: user, for: user})
end
end
end
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 637b84d72..b89da50a4 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -97,8 +97,6 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
- "is_admin" => false,
- "is_moderator" => false,
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
@@ -147,8 +145,6 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
- "is_admin" => false,
- "is_moderator" => false,
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
@@ -198,8 +194,6 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
- "is_admin" => false,
- "is_moderator" => false,
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
@@ -220,6 +214,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
represented = UserView.render("show.json", %{user: user, for: user})
assert represented["rights"]["delete_others_notice"]
+ assert represented["role"] == "moderator"
end
test "a user that is a admin" do
@@ -227,6 +222,21 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
represented = UserView.render("show.json", %{user: user, for: user})
assert represented["rights"]["admin"]
+ assert represented["role"] == "admin"
+ end
+
+ test "A moderator with hidden role for another user", %{user: user} do
+ admin = insert(:user, %{info: %{is_moderator: true, show_role: false}})
+ represented = UserView.render("show.json", %{user: admin, for: user})
+
+ assert represented["role"] == nil
+ end
+
+ test "An admin with hidden role for another user", %{user: user} do
+ admin = insert(:user, %{info: %{is_admin: true, show_role: false}})
+ represented = UserView.render("show.json", %{user: admin, for: user})
+
+ assert represented["role"] == nil
end
test "A blocked user for the blocker" do
@@ -263,8 +273,6 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
- "is_admin" => false,
- "is_moderator" => false,
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
--
cgit v1.2.3
From 5b1d7c3c5672af065af503891d156b6e0cf5a8c1 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 6 Feb 2019 12:17:41 +0700
Subject: fix tests
---
test/web/federator_test.exs | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
(limited to 'test')
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 147086918..b56694a8b 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -87,11 +87,9 @@ defmodule Pleroma.Web.FederatorTest do
{:ok, _activity} =
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
- assert called(
- Federator.enqueue(:publish_single_ap, %{inbox: inbox1, unreachable_since: dt})
- )
+ assert called(Federator.publish_single_ap(%{inbox: inbox1, unreachable_since: dt}))
- refute called(Federator.enqueue(:publish_single_ap, %{inbox: inbox2}))
+ refute called(Federator.publish_single_ap(%{inbox: inbox2}))
end
test_with_mock "it federates only to reachable instances via Websub",
@@ -123,13 +121,13 @@ defmodule Pleroma.Web.FederatorTest do
{:ok, _activity} = CommonAPI.post(user, %{"status" => "HI"})
assert called(
- Federator.enqueue(:publish_single_websub, %{
+ Federator.publish_single_websub(%{
callback: sub2.callback,
unreachable_since: dt
})
)
- refute called(Federator.enqueue(:publish_single_websub, %{callback: sub1.callback}))
+ refute called(Federator.publish_single_websub(%{callback: sub1.callback}))
end
test_with_mock "it federates only to reachable instances via Salmon",
@@ -163,13 +161,13 @@ defmodule Pleroma.Web.FederatorTest do
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
assert called(
- Federator.enqueue(:publish_single_salmon, %{
+ Federator.publish_single_salmon(%{
recipient: remote_user2,
unreachable_since: dt
})
)
- refute called(Federator.enqueue(:publish_single_websub, %{recipient: remote_user1}))
+ refute called(Federator.publish_single_websub(%{recipient: remote_user1}))
end
end
--
cgit v1.2.3
From 6eb8c1eb92e1992bb24f64e76f16f133aa978eee Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Wed, 6 Feb 2019 18:12:26 +0000
Subject: test: add some regression tests for the rich media card rendering
---
test/web/mastodon_api/status_view_test.exs | 40 ++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index c6a5783c6..f0c4468cf 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -235,4 +235,44 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
]
end
end
+
+ describe "rich media cards" do
+ test "a rich media card without a site name renders correctly" do
+ page_url = "http://example.com"
+
+ card = %{
+ url: page_url,
+ image: page_url <> "/example.jpg",
+ title: "Example website"
+ }
+
+ %{provider_name: "example.com"} =
+ StatusView.render("card.json", %{page_url: page_url, rich_media: card})
+ end
+
+ test "a rich media card without a site name or image renders correctly" do
+ page_url = "http://example.com"
+
+ card = %{
+ url: page_url,
+ title: "Example website"
+ }
+
+ %{provider_name: "example.com"} =
+ StatusView.render("card.json", %{page_url: page_url, rich_media: card})
+ end
+
+ test "a rich media card without an image renders correctly" do
+ page_url = "http://example.com"
+
+ card = %{
+ url: page_url,
+ site_name: "Example site name",
+ title: "Example website"
+ }
+
+ %{provider_name: "Example site name"} =
+ StatusView.render("card.json", %{page_url: page_url, rich_media: card})
+ end
+ end
end
--
cgit v1.2.3
From 26670b09a7a1fb144a8a2b0141d64c0d85cd6ad6 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Wed, 6 Feb 2019 18:27:55 +0000
Subject: tests: add a rich media card that contains all relevant fields
---
test/web/mastodon_api/status_view_test.exs | 15 +++++++++++++++
1 file changed, 15 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index f0c4468cf..2106253f2 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -274,5 +274,20 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
%{provider_name: "Example site name"} =
StatusView.render("card.json", %{page_url: page_url, rich_media: card})
end
+
+ test "a rich media card with all relevant data renders correctly" do
+ page_url = "http://example.com"
+
+ card = %{
+ url: page_url,
+ site_name: "Example site name",
+ title: "Example website",
+ image: page_url <> "/example.jpg",
+ description: "Example description"
+ }
+
+ %{provider_name: "Example site name"} =
+ StatusView.render("card.json", %{page_url: page_url, rich_media: card})
+ end
end
end
--
cgit v1.2.3
From 74518d0b607695a80e25f17de8369f47c7652b17 Mon Sep 17 00:00:00 2001
From: Mark Felder
Date: Wed, 6 Feb 2019 22:34:44 +0000
Subject: hide_followings was renamed to hide_followers in the FE, but never
synced up in the BE
This was a dirty regex replace which worked on my server
---
test/web/activity_pub/activity_pub_controller_test.exs | 4 ++--
test/web/mastodon_api/mastodon_api_controller_test.exs | 8 ++++----
test/web/twitter_api/twitter_api_controller_test.exs | 18 +++++++++---------
test/web/twitter_api/views/user_view_test.exs | 8 ++++----
4 files changed, 19 insertions(+), 19 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 0a0103793..570bee6b3 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -441,8 +441,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert result["first"]["orderedItems"] == [user_two.ap_id]
end
- test "it returns returns empty if the user has 'hide_followings' set", %{conn: conn} do
- user = insert(:user, %{info: %{hide_followings: true}})
+ test "it returns returns empty if the user has 'hide_follows' set", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_follows: true}})
user_two = insert(:user)
User.follow(user, user_two)
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index d4e2acae3..f8da86004 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1139,8 +1139,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert id == to_string(other_user.id)
end
- test "getting following, hide_followings", %{conn: conn} do
- user = insert(:user, %{info: %{hide_followings: true}})
+ test "getting following, hide_follows", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_follows: true}})
other_user = insert(:user)
{:ok, user} = User.follow(user, other_user)
@@ -1151,8 +1151,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [] == json_response(conn, 200)
end
- test "getting following, hide_followings, same user requesting", %{conn: conn} do
- user = insert(:user, %{info: %{hide_followings: true}})
+ test "getting following, hide_follows, same user requesting", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_follows: true}})
other_user = insert(:user)
{:ok, user} = User.follow(user, other_user)
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index cb98f1809..855ae1526 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1261,8 +1261,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
)
end
- test "it returns empty when hide_followings is set to true", %{conn: conn} do
- user = insert(:user, %{info: %{hide_followings: true}})
+ test "it returns empty when hide_follows is set to true", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_follows: true}})
followed_one = insert(:user)
followed_two = insert(:user)
not_followed = insert(:user)
@@ -1278,11 +1278,11 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert [] == json_response(conn, 200)
end
- test "it returns friends when hide_followings is set to true if the user themselves request it",
+ test "it returns friends when hide_follows is set to true if the user themselves request it",
%{
conn: conn
} do
- user = insert(:user, %{info: %{hide_followings: true}})
+ user = insert(:user, %{info: %{hide_follows: true}})
followed_one = insert(:user)
followed_two = insert(:user)
_not_followed = insert(:user)
@@ -1370,27 +1370,27 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
- test "it sets and un-sets hide_followings", %{conn: conn} do
+ test "it sets and un-sets hide_follows", %{conn: conn} do
user = insert(:user)
conn
|> assign(:user, user)
|> post("/api/account/update_profile.json", %{
- "hide_followings" => "true"
+ "hide_follows" => "true"
})
user = Repo.get!(User, user.id)
- assert user.info.hide_followings == true
+ assert user.info.hide_follows == true
conn =
conn
|> assign(:user, user)
|> post("/api/account/update_profile.json", %{
- "hide_followings" => "false"
+ "hide_follows" => "false"
})
user = Repo.get!(User, user.id)
- assert user.info.hide_followings == false
+ assert user.info.hide_follows == false
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index b89da50a4..95e52ca46 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -100,7 +100,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "hide_followings" => false,
+ "hide_follows" => false,
"hide_followers" => false,
"fields" => [],
"pleroma" => %{
@@ -148,7 +148,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "hide_followings" => false,
+ "hide_follows" => false,
"hide_followers" => false,
"fields" => [],
"pleroma" => %{
@@ -197,7 +197,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "hide_followings" => false,
+ "hide_follows" => false,
"hide_followers" => false,
"fields" => [],
"pleroma" => %{
@@ -276,7 +276,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "hide_followings" => false,
+ "hide_follows" => false,
"hide_followers" => false,
"fields" => [],
"pleroma" => %{
--
cgit v1.2.3
From 9a23f8f3ea9e788978055f0ad3a10db105f68cc6 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Fri, 8 Feb 2019 20:23:26 +0300
Subject: Add tests and fix a typo in docs
---
test/web/activity_pub/mrf/keyword_policy_test.exs | 113 ++++++++++++++++++++++
1 file changed, 113 insertions(+)
create mode 100644 test/web/activity_pub/mrf/keyword_policy_test.exs
(limited to 'test')
diff --git a/test/web/activity_pub/mrf/keyword_policy_test.exs b/test/web/activity_pub/mrf/keyword_policy_test.exs
new file mode 100644
index 000000000..77e2a08c9
--- /dev/null
+++ b/test/web/activity_pub/mrf/keyword_policy_test.exs
@@ -0,0 +1,113 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.ActivityPub.MRF.KeywordPolicy
+
+ setup do
+ Pleroma.Config.put([:mrf_keyword], %{reject: [], federated_timeline_removal: [], replace: []})
+ end
+
+ describe "rejecting based on keywords" do
+ test "rejects if string matches" do
+ Pleroma.Config.put([:mrf_keyword, :reject], ["pun"])
+
+ message = %{
+ "type" => "Create",
+ "object" => %{"content" => "just a daily reminder that compLAINer is a good pun"}
+ }
+
+ assert {:reject, nil} == KeywordPolicy.filter(message)
+ end
+
+ test "rejects if regex matches" do
+ Pleroma.Config.put([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/])
+
+ assert true ==
+ Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "content" => "just a daily reminder that #{content} is a good pun"
+ }
+ }
+
+ {:reject, nil} == KeywordPolicy.filter(message)
+ end)
+ end
+ end
+
+ describe "delisting from ftl based on keywords" do
+ test "delists if string matches" do
+ Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], ["pun"])
+
+ message = %{
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "type" => "Create",
+ "object" => %{"content" => "just a daily reminder that compLAINer is a good pun"}
+ }
+
+ {:ok, result} = KeywordPolicy.filter(message)
+ assert ["https://www.w3.org/ns/activitystreams#Public"] == result["cc"]
+ refute ["https://www.w3.org/ns/activitystreams#Public"] == result["to"]
+ end
+
+ test "delists if regex matches" do
+ Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/])
+
+ assert true ==
+ Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
+ message = %{
+ "type" => "Create",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "object" => %{
+ "content" => "just a daily reminder that #{content} is a good pun"
+ }
+ }
+
+ {:ok, result} = KeywordPolicy.filter(message)
+
+ ["https://www.w3.org/ns/activitystreams#Public"] == result["cc"] and
+ not (["https://www.w3.org/ns/activitystreams#Public"] == result["to"])
+ end)
+ end
+ end
+
+ describe "replacing keywords" do
+ test "replaces keyword if string matches" do
+ Pleroma.Config.put([:mrf_keyword, :replace], [{"opensource", "free software"}])
+
+ message = %{
+ "type" => "Create",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "object" => %{"content" => "ZFS is opensource"}
+ }
+
+ {:ok, %{"object" => %{"content" => result}}} = KeywordPolicy.filter(message)
+ assert result == "ZFS is free software"
+ end
+
+ test "replaces keyword if regex matches" do
+ Pleroma.Config.put([:mrf_keyword, :replace], [
+ {~r/open(-|\s)?source\s?(software)?/, "free software"}
+ ])
+
+ assert true ==
+ Enum.all?(["opensource", "open-source", "open source"], fn content ->
+ message = %{
+ "type" => "Create",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "object" => %{"content" => "ZFS is #{content}"}
+ }
+
+ {:ok, %{"object" => %{"content" => result}}} = KeywordPolicy.filter(message)
+ IO.inspect(content)
+ IO.inspect(result)
+ result == "ZFS is free software"
+ end)
+ end
+ end
+end
--
cgit v1.2.3
From b05a3411871fbfb8d1a5525d6875a635917abffa Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sat, 9 Feb 2019 08:12:30 +0300
Subject: oof
---
test/web/activity_pub/mrf/keyword_policy_test.exs | 2 --
1 file changed, 2 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/mrf/keyword_policy_test.exs b/test/web/activity_pub/mrf/keyword_policy_test.exs
index 77e2a08c9..67a5858d7 100644
--- a/test/web/activity_pub/mrf/keyword_policy_test.exs
+++ b/test/web/activity_pub/mrf/keyword_policy_test.exs
@@ -104,8 +104,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
}
{:ok, %{"object" => %{"content" => result}}} = KeywordPolicy.filter(message)
- IO.inspect(content)
- IO.inspect(result)
result == "ZFS is free software"
end)
end
--
cgit v1.2.3
From bbd0049faef310d1ef9f1f04ecceee3fc924249d Mon Sep 17 00:00:00 2001
From: lain
Date: Sat, 9 Feb 2019 13:24:23 +0100
Subject: Respect blocks in mass follow.
---
test/user_test.exs | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 98d3bc464..523ab1ea4 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -53,16 +53,20 @@ defmodule Pleroma.UserTest do
followed_zero = insert(:user)
followed_one = insert(:user)
followed_two = insert(:user)
+ blocked = insert(:user)
not_followed = insert(:user)
+ {:ok, user} = User.block(user, blocked)
+
{:ok, user} = User.follow(user, followed_zero)
- {:ok, user} = User.follow_all(user, [followed_one, followed_two])
+ {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked])
assert User.following?(user, followed_one)
assert User.following?(user, followed_two)
assert User.following?(user, followed_zero)
refute User.following?(user, not_followed)
+ refute User.following?(user, blocked)
end
test "follow_all follows mutliple users without duplicating" do
--
cgit v1.2.3
From 09189c3a7c61d15dc8c73c2474df19320f5032d0 Mon Sep 17 00:00:00 2001
From: Karen Konou
Date: Sat, 9 Feb 2019 14:23:51 +0100
Subject: Made a test!
---
test/web/thread_mute_test.exs | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
create mode 100644 test/web/thread_mute_test.exs
(limited to 'test')
diff --git a/test/web/thread_mute_test.exs b/test/web/thread_mute_test.exs
new file mode 100644
index 000000000..4dea44d2f
--- /dev/null
+++ b/test/web/thread_mute_test.exs
@@ -0,0 +1,25 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ThreadMuteTest do
+ use Pleroma.DataCase
+ import Pleroma.Web.ThreadMute
+
+ import Pleroma.Factory
+
+ test "add a mute" do
+ user = insert(:user, %{id: "1"})
+
+ activity =
+ insert(:note_activity, %{
+ data: %{"context" => "http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592"}
+ })
+
+ id = activity.id
+ {:ok, mute} = add_mute(user, id)
+
+ assert mute.user_id == "1"
+ assert mute.context == "http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592"
+ end
+end
--
cgit v1.2.3
From 4430a0ad127411b818d875dbbaf14369c109f331 Mon Sep 17 00:00:00 2001
From: Karen Konou
Date: Sat, 9 Feb 2019 14:34:42 +0100
Subject: added another test
---
test/web/thread_mute_test.exs | 35 +++++++++++++++++++++++++----------
1 file changed, 25 insertions(+), 10 deletions(-)
(limited to 'test')
diff --git a/test/web/thread_mute_test.exs b/test/web/thread_mute_test.exs
index 4dea44d2f..75277ef62 100644
--- a/test/web/thread_mute_test.exs
+++ b/test/web/thread_mute_test.exs
@@ -8,18 +8,33 @@ defmodule Pleroma.Web.ThreadMuteTest do
import Pleroma.Factory
- test "add a mute" do
- user = insert(:user, %{id: "1"})
+ describe "mute tests" do
+ setup do
+ user = insert(:user, %{id: "1"})
- activity =
- insert(:note_activity, %{
- data: %{"context" => "http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592"}
- })
+ activity =
+ insert(:note_activity, %{
+ data: %{
+ "context" => "http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592"
+ }
+ })
- id = activity.id
- {:ok, mute} = add_mute(user, id)
+ [user: user, activity: activity]
+ end
- assert mute.user_id == "1"
- assert mute.context == "http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592"
+ test "add mute", %{user: user, activity: activity} do
+ id = activity.id
+ {:ok, mute} = add_mute(user, id)
+
+ assert mute.user_id == "1"
+ assert mute.context == "http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592"
+ end
+
+ test "remove mute", %{user: user, activity: activity} do
+ id = activity.id
+
+ add_mute(user, id)
+ {1, nil} = remove_mute(user, id)
+ end
end
end
--
cgit v1.2.3
From a0d732ec55fcbce8cf345344d1456dc77bb0f3bf Mon Sep 17 00:00:00 2001
From: Karen Konou
Date: Sat, 9 Feb 2019 17:47:57 +0100
Subject: it works!!
---
test/web/thread_mute_test.exs | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
(limited to 'test')
diff --git a/test/web/thread_mute_test.exs b/test/web/thread_mute_test.exs
index 75277ef62..212cae860 100644
--- a/test/web/thread_mute_test.exs
+++ b/test/web/thread_mute_test.exs
@@ -10,31 +10,32 @@ defmodule Pleroma.Web.ThreadMuteTest do
describe "mute tests" do
setup do
- user = insert(:user, %{id: "1"})
+ user = insert(:user)
- activity =
- insert(:note_activity, %{
- data: %{
- "context" => "http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592"
- }
- })
+ activity = insert(:note_activity)
[user: user, activity: activity]
end
test "add mute", %{user: user, activity: activity} do
id = activity.id
- {:ok, mute} = add_mute(user, id)
-
- assert mute.user_id == "1"
- assert mute.context == "http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592"
+ {:ok, _activity} = add_mute(user, id)
end
test "remove mute", %{user: user, activity: activity} do
id = activity.id
add_mute(user, id)
- {1, nil} = remove_mute(user, id)
+ {:ok, _activity} = remove_mute(user, id)
+ end
+
+ test "check mute", %{user: user, activity: activity} do
+ id = activity.id
+
+ add_mute(user, id)
+ assert muted?(user, activity)
+ remove_mute(user, id)
+ refute muted?(user, activity)
end
end
end
--
cgit v1.2.3
From 478a05b4c99d696846b71d0eb4d6982ba422bfb8 Mon Sep 17 00:00:00 2001
From: Karen Konou
Date: Sat, 9 Feb 2019 18:34:00 +0100
Subject: Merged "check mute" test into the other two
---
test/web/thread_mute_test.exs | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
(limited to 'test')
diff --git a/test/web/thread_mute_test.exs b/test/web/thread_mute_test.exs
index 212cae860..119a06f52 100644
--- a/test/web/thread_mute_test.exs
+++ b/test/web/thread_mute_test.exs
@@ -20,6 +20,7 @@ defmodule Pleroma.Web.ThreadMuteTest do
test "add mute", %{user: user, activity: activity} do
id = activity.id
{:ok, _activity} = add_mute(user, id)
+ assert muted?(user, activity)
end
test "remove mute", %{user: user, activity: activity} do
@@ -27,14 +28,6 @@ defmodule Pleroma.Web.ThreadMuteTest do
add_mute(user, id)
{:ok, _activity} = remove_mute(user, id)
- end
-
- test "check mute", %{user: user, activity: activity} do
- id = activity.id
-
- add_mute(user, id)
- assert muted?(user, activity)
- remove_mute(user, id)
refute muted?(user, activity)
end
end
--
cgit v1.2.3
From 6a150de3bd416cfe0b4870deee2e6557791345f8 Mon Sep 17 00:00:00 2001
From: Karen Konou
Date: Sat, 9 Feb 2019 20:52:11 +0100
Subject: Add unique index and unique constraint check, uniqueness test fails
---
test/web/thread_mute_test.exs | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
(limited to 'test')
diff --git a/test/web/thread_mute_test.exs b/test/web/thread_mute_test.exs
index 119a06f52..f3a24613c 100644
--- a/test/web/thread_mute_test.exs
+++ b/test/web/thread_mute_test.exs
@@ -18,17 +18,20 @@ defmodule Pleroma.Web.ThreadMuteTest do
end
test "add mute", %{user: user, activity: activity} do
- id = activity.id
- {:ok, _activity} = add_mute(user, id)
+ {:ok, _activity} = add_mute(user, activity.id)
assert muted?(user, activity)
end
test "remove mute", %{user: user, activity: activity} do
- id = activity.id
-
- add_mute(user, id)
- {:ok, _activity} = remove_mute(user, id)
+ add_mute(user, activity.id)
+ {:ok, _activity} = remove_mute(user, activity.id)
refute muted?(user, activity)
end
+
+ test "check that mutes can't be duplicate", %{user: user, activity: activity} do
+ add_mute(user, activity.id)
+ assert muted?(user, activity)
+ {:error, _} = add_mute(user, activity.id)
+ end
end
end
--
cgit v1.2.3
From f8388be9c69981958e9a96dce68fc39bdedb5cd3 Mon Sep 17 00:00:00 2001
From: lain
Date: Sat, 9 Feb 2019 22:01:08 +0100
Subject: Do object insertion through Cachex
So we don't flood our postgres logs with errors. Should also make things
slightly faster.
---
test/object_test.exs | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
(limited to 'test')
diff --git a/test/object_test.exs b/test/object_test.exs
index 72194975d..ab6431012 100644
--- a/test/object_test.exs
+++ b/test/object_test.exs
@@ -57,4 +57,32 @@ defmodule Pleroma.ObjectTest do
assert cached_object.data["type"] == "Tombstone"
end
end
+
+ describe "insert_or_get" do
+ test "inserting the same object twice (by id) just returns the original object" do
+ data = %{data: %{"id" => Ecto.UUID.generate()}}
+ cng = Object.change(%Object{}, data)
+ {:ok, object} = Object.insert_or_get(cng)
+ {:ok, second_object} = Object.insert_or_get(cng)
+
+ Cachex.clear(:object_cache)
+ {:ok, third_object} = Object.insert_or_get(cng)
+
+ assert object == second_object
+ assert object == third_object
+ end
+ end
+
+ describe "create" do
+ test "inserts an object for a given data set" do
+ data = %{"id" => Ecto.UUID.generate()}
+
+ {:ok, object} = Object.create(data)
+ assert object.data["id"] == data["id"]
+
+ # Works when doing it twice.
+ {:ok, object} = Object.create(data)
+ assert object.data["id"] == data["id"]
+ end
+ end
end
--
cgit v1.2.3
From 8bb7e19b3814e261e66c2d3592d146f72d4ce623 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Sun, 10 Feb 2019 22:57:38 +0100
Subject: test: de-group alias/es
---
test/notification_test.exs | 3 ++-
test/object_test.exs | 3 ++-
test/support/builders/user_builder.ex | 3 ++-
test/tasks/relay_test.exs | 4 +++-
test/user_test.exs | 4 +++-
test/web/activity_pub/activity_pub_controller_test.exs | 9 +++++++--
test/web/activity_pub/activity_pub_test.exs | 5 ++++-
test/web/admin_api/admin_api_controller_test.exs | 3 ++-
test/web/common_api/common_api_utils_test.exs | 2 +-
test/web/federator_test.exs | 3 ++-
test/web/mastodon_api/mastodon_api_controller_test.exs | 9 +++++++--
test/web/mastodon_api/status_view_test.exs | 3 ++-
test/web/oauth/authorization_test.exs | 3 ++-
test/web/oauth/oauth_controller_test.exs | 3 ++-
test/web/oauth/token_test.exs | 4 +++-
test/web/ostatus/activity_representer_test.exs | 4 +++-
test/web/ostatus/feed_representer_test.exs | 4 +++-
test/web/ostatus/incoming_documents/delete_handling_test.exs | 4 +++-
test/web/ostatus/ostatus_controller_test.exs | 4 +++-
test/web/ostatus/ostatus_test.exs | 6 +++++-
test/web/salmon/salmon_test.exs | 4 +++-
test/web/twitter_api/representers/activity_representer_test.exs | 7 +++++--
test/web/twitter_api/twitter_api_controller_test.exs | 9 +++++++--
test/web/twitter_api/twitter_api_test.exs | 9 +++++++--
test/web/twitter_api/views/notification_view_test.exs | 3 ++-
test/web/websub/websub_controller_test.exs | 3 ++-
test/web/websub/websub_test.exs | 3 ++-
27 files changed, 89 insertions(+), 32 deletions(-)
(limited to 'test')
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 94fb0ab15..d36a92a7c 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -6,7 +6,8 @@ defmodule Pleroma.NotificationTest do
use Pleroma.DataCase
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.CommonAPI
- alias Pleroma.{User, Notification}
+ alias Pleroma.User
+ alias Pleroma.Notification
alias Pleroma.Web.ActivityPub.Transmogrifier
import Pleroma.Factory
diff --git a/test/object_test.exs b/test/object_test.exs
index ab6431012..9f5283d2d 100644
--- a/test/object_test.exs
+++ b/test/object_test.exs
@@ -5,7 +5,8 @@
defmodule Pleroma.ObjectTest do
use Pleroma.DataCase
import Pleroma.Factory
- alias Pleroma.{Repo, Object}
+ alias Pleroma.Repo
+ alias Pleroma.Object
test "returns an object by it's AP id" do
object = insert(:note)
diff --git a/test/support/builders/user_builder.ex b/test/support/builders/user_builder.ex
index 7a1ca79b5..611a5be18 100644
--- a/test/support/builders/user_builder.ex
+++ b/test/support/builders/user_builder.ex
@@ -1,5 +1,6 @@
defmodule Pleroma.Builders.UserBuilder do
- alias Pleroma.{User, Repo}
+ alias Pleroma.User
+ alias Pleroma.Repo
def build(data \\ %{}) do
user = %User{
diff --git a/test/tasks/relay_test.exs b/test/tasks/relay_test.exs
index 96fac4811..64ff07753 100644
--- a/test/tasks/relay_test.exs
+++ b/test/tasks/relay_test.exs
@@ -4,7 +4,9 @@
defmodule Mix.Tasks.Pleroma.RelayTest do
alias Pleroma.Activity
- alias Pleroma.Web.ActivityPub.{ActivityPub, Relay, Utils}
+ alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.ActivityPub.Utils
+ alias Pleroma.Web.ActivityPub.Relay
alias Pleroma.User
use Pleroma.DataCase
diff --git a/test/user_test.exs b/test/user_test.exs
index 523ab1ea4..1fd54b944 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -4,7 +4,9 @@
defmodule Pleroma.UserTest do
alias Pleroma.Builders.UserBuilder
- alias Pleroma.{User, Repo, Activity}
+ alias Pleroma.Activity
+ alias Pleroma.Repo
+ alias Pleroma.User
alias Pleroma.Web.CommonAPI
use Pleroma.DataCase
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 570bee6b3..acd295988 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -5,8 +5,13 @@
defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
- alias Pleroma.Web.ActivityPub.{UserView, ObjectView}
- alias Pleroma.{Object, Repo, Activity, User, Instances}
+ alias Pleroma.Web.ActivityPub.UserView
+ alias Pleroma.Web.ActivityPub.ObjectView
+ alias Pleroma.Object
+ alias Pleroma.Repo
+ alias Pleroma.Activity
+ alias Pleroma.User
+ alias Pleroma.Instances
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index a55961ac4..a6f8b822a 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -7,7 +7,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI
- alias Pleroma.{Activity, Object, User, Instances}
+ alias Pleroma.Activity
+ alias Pleroma.Object
+ alias Pleroma.User
+ alias Pleroma.Instances
alias Pleroma.Builders.ActivityBuilder
import Pleroma.Factory
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 42450a7b6..a27c26f95 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -5,7 +5,8 @@
defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
use Pleroma.Web.ConnCase
- alias Pleroma.{Repo, User}
+ alias Pleroma.Repo
+ alias Pleroma.User
import Pleroma.Factory
describe "/api/pleroma/admin/user" do
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 754bc7255..faed6b685 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -5,7 +5,7 @@
defmodule Pleroma.Web.CommonAPI.UtilsTest do
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.Endpoint
- alias Pleroma.Builders.{UserBuilder}
+ alias Pleroma.Builders.UserBuilder
use Pleroma.DataCase
test "it adds attachment links to a given text and attachment set" do
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 05f813291..9f8d71454 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -3,7 +3,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.FederatorTest do
- alias Pleroma.Web.{CommonAPI, Federator}
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.Federator
alias Pleroma.Instances
use Pleroma.DataCase
import Pleroma.Factory
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index f8da86004..9fd505f84 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -6,8 +6,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
use Pleroma.Web.ConnCase
alias Pleroma.Web.TwitterAPI.TwitterAPI
- alias Pleroma.{Repo, User, Object, Activity, Notification}
- alias Pleroma.Web.{OStatus, CommonAPI}
+ alias Pleroma.Repo
+ alias Pleroma.User
+ alias Pleroma.Object
+ alias Pleroma.Activity
+ alias Pleroma.Notification
+ alias Pleroma.Web.OStatus
+ alias Pleroma.Web.CommonAPI
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.MastodonAPI.FilterView
alias Ecto.Changeset
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 2106253f2..0dc9c538c 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -5,7 +5,8 @@
defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
use Pleroma.DataCase
- alias Pleroma.Web.MastodonAPI.{StatusView, AccountView}
+ alias Pleroma.Web.MastodonAPI.AccountView
+ alias Pleroma.Web.MastodonAPI.StatusView
alias Pleroma.User
alias Pleroma.Web.OStatus
alias Pleroma.Web.CommonAPI
diff --git a/test/web/oauth/authorization_test.exs b/test/web/oauth/authorization_test.exs
index 3b1ddada8..81618e935 100644
--- a/test/web/oauth/authorization_test.exs
+++ b/test/web/oauth/authorization_test.exs
@@ -4,7 +4,8 @@
defmodule Pleroma.Web.OAuth.AuthorizationTest do
use Pleroma.DataCase
- alias Pleroma.Web.OAuth.{Authorization, App}
+ alias Pleroma.Web.OAuth.Authorization
+ alias Pleroma.Web.OAuth.App
import Pleroma.Factory
test "create an authorization token for a valid app" do
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index e0d3cb55f..2315f9a34 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -7,7 +7,8 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
import Pleroma.Factory
alias Pleroma.Repo
- alias Pleroma.Web.OAuth.{Authorization, Token}
+ alias Pleroma.Web.OAuth.Authorization
+ alias Pleroma.Web.OAuth.Token
test "redirects with oauth authorization" do
user = insert(:user)
diff --git a/test/web/oauth/token_test.exs b/test/web/oauth/token_test.exs
index 9a241d61a..4dab4a308 100644
--- a/test/web/oauth/token_test.exs
+++ b/test/web/oauth/token_test.exs
@@ -4,7 +4,9 @@
defmodule Pleroma.Web.OAuth.TokenTest do
use Pleroma.DataCase
- alias Pleroma.Web.OAuth.{App, Token, Authorization}
+ alias Pleroma.Web.OAuth.App
+ alias Pleroma.Web.OAuth.Authorization
+ alias Pleroma.Web.OAuth.Token
alias Pleroma.Repo
import Pleroma.Factory
diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs
index 0869f2fd5..eebc5c040 100644
--- a/test/web/ostatus/activity_representer_test.exs
+++ b/test/web/ostatus/activity_representer_test.exs
@@ -6,7 +6,9 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
use Pleroma.DataCase
alias Pleroma.Web.OStatus.ActivityRepresenter
- alias Pleroma.{User, Activity, Object}
+ alias Pleroma.Activity
+ alias Pleroma.User
+ alias Pleroma.Object
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.OStatus
diff --git a/test/web/ostatus/feed_representer_test.exs b/test/web/ostatus/feed_representer_test.exs
index 55717dec7..efd4e7217 100644
--- a/test/web/ostatus/feed_representer_test.exs
+++ b/test/web/ostatus/feed_representer_test.exs
@@ -6,7 +6,9 @@ defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
use Pleroma.DataCase
import Pleroma.Factory
alias Pleroma.User
- alias Pleroma.Web.OStatus.{FeedRepresenter, UserRepresenter, ActivityRepresenter}
+ alias Pleroma.Web.OStatus.ActivityRepresenter
+ alias Pleroma.Web.OStatus.FeedRepresenter
+ alias Pleroma.Web.OStatus.UserRepresenter
alias Pleroma.Web.OStatus
test "returns a feed of the last 20 items of the user" do
diff --git a/test/web/ostatus/incoming_documents/delete_handling_test.exs b/test/web/ostatus/incoming_documents/delete_handling_test.exs
index d97cd79f4..d295cc539 100644
--- a/test/web/ostatus/incoming_documents/delete_handling_test.exs
+++ b/test/web/ostatus/incoming_documents/delete_handling_test.exs
@@ -4,7 +4,9 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
import Pleroma.Factory
import Tesla.Mock
- alias Pleroma.{Repo, Activity, Object}
+ alias Pleroma.Repo
+ alias Pleroma.Activity
+ alias Pleroma.Object
alias Pleroma.Web.OStatus
setup do
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index 3145ca9a1..da9c72be8 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -5,7 +5,9 @@
defmodule Pleroma.Web.OStatus.OStatusControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
- alias Pleroma.{User, Repo, Object}
+ alias Pleroma.User
+ alias Pleroma.Repo
+ alias Pleroma.Object
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OStatus.ActivityRepresenter
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index dbe5de2e2..b4b19ab05 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -6,7 +6,11 @@ defmodule Pleroma.Web.OStatusTest do
use Pleroma.DataCase
alias Pleroma.Web.OStatus
alias Pleroma.Web.XML
- alias Pleroma.{Object, Repo, User, Activity, Instances}
+ alias Pleroma.Object
+ alias Pleroma.Repo
+ alias Pleroma.User
+ alias Pleroma.Activity
+ alias Pleroma.Instances
import Pleroma.Factory
import ExUnit.CaptureLog
diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs
index c539a28b2..9e583ba40 100644
--- a/test/web/salmon/salmon_test.exs
+++ b/test/web/salmon/salmon_test.exs
@@ -5,7 +5,9 @@
defmodule Pleroma.Web.Salmon.SalmonTest do
use Pleroma.DataCase
alias Pleroma.Web.Salmon
- alias Pleroma.{Repo, Activity, User}
+ alias Pleroma.Activity
+ alias Pleroma.Repo
+ alias Pleroma.User
import Pleroma.Factory
@magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index ea5813733..365c7f659 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -4,8 +4,11 @@
defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
use Pleroma.DataCase
- alias Pleroma.{User, Activity, Object}
- alias Pleroma.Web.TwitterAPI.Representers.{ActivityRepresenter, ObjectRepresenter}
+ alias Pleroma.User
+ alias Pleroma.Activity
+ alias Pleroma.Object
+ alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
+ alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.UserView
import Pleroma.Factory
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 855ae1526..acb03b146 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -5,8 +5,13 @@
defmodule Pleroma.Web.TwitterAPI.ControllerTest do
use Pleroma.Web.ConnCase
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
- alias Pleroma.Builders.{ActivityBuilder, UserBuilder}
- alias Pleroma.{Repo, Activity, User, Object, Notification}
+ alias Pleroma.Builders.ActivityBuilder
+ alias Pleroma.Builders.UserBuilder
+ alias Pleroma.Repo
+ alias Pleroma.Activity
+ alias Pleroma.User
+ alias Pleroma.Object
+ alias Pleroma.Notification
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Web.TwitterAPI.NotificationView
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 48ddbcf50..aa2a4d650 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -4,8 +4,13 @@
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
use Pleroma.DataCase
- alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView}
- alias Pleroma.{Activity, User, Object, Repo, UserInviteToken}
+ alias Pleroma.Web.TwitterAPI.TwitterAPI
+ alias Pleroma.Web.TwitterAPI.UserView
+ alias Pleroma.Activity
+ alias Pleroma.User
+ alias Pleroma.Object
+ alias Pleroma.Repo
+ alias Pleroma.UserInviteToken
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.ActivityView
diff --git a/test/web/twitter_api/views/notification_view_test.exs b/test/web/twitter_api/views/notification_view_test.exs
index 8367fc6c7..3a67f7292 100644
--- a/test/web/twitter_api/views/notification_view_test.exs
+++ b/test/web/twitter_api/views/notification_view_test.exs
@@ -5,7 +5,8 @@
defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
use Pleroma.DataCase
- alias Pleroma.{User, Notification}
+ alias Pleroma.User
+ alias Pleroma.Notification
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.TwitterAPI.NotificationView
alias Pleroma.Web.TwitterAPI.UserView
diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs
index 6492df2a0..04fb4a5a3 100644
--- a/test/web/websub/websub_controller_test.exs
+++ b/test/web/websub/websub_controller_test.exs
@@ -6,7 +6,8 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
alias Pleroma.Web.Websub.WebsubClientSubscription
- alias Pleroma.{Repo, Activity}
+ alias Pleroma.Activity
+ alias Pleroma.Repo
alias Pleroma.Web.Websub
test "websub subscription request", %{conn: conn} do
diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs
index 9751d161d..9a9b9df02 100644
--- a/test/web/websub/websub_test.exs
+++ b/test/web/websub/websub_test.exs
@@ -5,7 +5,8 @@
defmodule Pleroma.Web.WebsubTest do
use Pleroma.DataCase
alias Pleroma.Web.Websub
- alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription}
+ alias Pleroma.Web.Websub.WebsubServerSubscription
+ alias Pleroma.Web.Websub.WebsubClientSubscription
import Pleroma.Factory
alias Pleroma.Web.Router.Helpers
import Tesla.Mock
--
cgit v1.2.3
From 74579115a73d697aed67abe2dc8ea1a664c89c5b Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Mon, 11 Feb 2019 00:08:48 +0100
Subject: =?UTF-8?q?test:=20Change=20`lenght(=E2=80=A6)=20=3D=3D=200`=20to?=
=?UTF-8?q?=20`Enum.empty=3F(=E2=80=A6)`?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/formatter_test.exs | 2 +-
test/notification_test.exs | 30 +++++++++++-----------
test/tasks/user_test.exs | 2 +-
.../mastodon_api/mastodon_api_controller_test.exs | 2 +-
test/web/websub/websub_controller_test.exs | 2 +-
5 files changed, 19 insertions(+), 19 deletions(-)
(limited to 'test')
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index 2e717194b..f14077d25 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -197,7 +197,7 @@ defmodule Pleroma.FormatterTest do
{subs, text} = Formatter.add_user_links({[], text}, mentions)
- assert length(subs) == 0
+ assert Enum.empty?(subs)
Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
expected_text = "@a hi"
diff --git a/test/notification_test.exs b/test/notification_test.exs
index d36a92a7c..755874a3d 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -300,7 +300,7 @@ defmodule Pleroma.NotificationTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
{:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
@@ -308,7 +308,7 @@ defmodule Pleroma.NotificationTest do
{:ok, _} = CommonAPI.delete(activity.id, user)
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
end
test "liking an activity results in 1 notification, then 0 if the activity is unliked" do
@@ -317,7 +317,7 @@ defmodule Pleroma.NotificationTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
{:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
@@ -325,7 +325,7 @@ defmodule Pleroma.NotificationTest do
{:ok, _, _, _} = CommonAPI.unfavorite(activity.id, other_user)
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
end
test "repeating an activity results in 1 notification, then 0 if the activity is deleted" do
@@ -334,7 +334,7 @@ defmodule Pleroma.NotificationTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
{:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
@@ -342,7 +342,7 @@ defmodule Pleroma.NotificationTest do
{:ok, _} = CommonAPI.delete(activity.id, user)
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
end
test "repeating an activity results in 1 notification, then 0 if the activity is unrepeated" do
@@ -351,7 +351,7 @@ defmodule Pleroma.NotificationTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
{:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
@@ -359,7 +359,7 @@ defmodule Pleroma.NotificationTest do
{:ok, _, _} = CommonAPI.unrepeat(activity.id, other_user)
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
end
test "liking an activity which is already deleted does not generate a notification" do
@@ -368,15 +368,15 @@ defmodule Pleroma.NotificationTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
{:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
{:error, _} = CommonAPI.favorite(activity.id, other_user)
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
end
test "repeating an activity which is already deleted does not generate a notification" do
@@ -385,15 +385,15 @@ defmodule Pleroma.NotificationTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
{:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
{:error, _} = CommonAPI.repeat(activity.id, other_user)
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
end
test "replying to a deleted post without tagging does not generate a notification" do
@@ -409,7 +409,7 @@ defmodule Pleroma.NotificationTest do
"in_reply_to_status_id" => activity.id
})
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
end
end
end
diff --git a/test/tasks/user_test.exs b/test/tasks/user_test.exs
index 44271898c..7b814d171 100644
--- a/test/tasks/user_test.exs
+++ b/test/tasks/user_test.exs
@@ -151,7 +151,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert message =~ "Successfully unsubscribed"
user = User.get_by_nickname(user.nickname)
- assert length(user.following) == 0
+ assert Enum.empty?(user.following)
assert user.info.deactivated
end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 9fd505f84..19393f355 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -36,7 +36,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> assign(:user, user)
|> get("/api/v1/timelines/home")
- assert length(json_response(conn, 200)) == 0
+ assert Enum.empty?(json_response(conn, 200))
{:ok, user} = User.follow(user, following)
diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs
index 04fb4a5a3..87b01d89b 100644
--- a/test/web/websub/websub_controller_test.exs
+++ b/test/web/websub/websub_controller_test.exs
@@ -81,7 +81,7 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
assert response(conn, 500) == "Error"
- assert length(Repo.all(Activity)) == 0
+ assert Enum.empty?(Repo.all(Activity))
end
end
end
--
cgit v1.2.3
From d53e36bf1e004177277cb5917bb290d512278aa9 Mon Sep 17 00:00:00 2001
From: lambda
Date: Mon, 11 Feb 2019 08:07:39 +0000
Subject: Revert "Merge branch 'object-creation' into 'develop'"
This reverts merge request !802
---
test/object_test.exs | 28 ----------------------------
1 file changed, 28 deletions(-)
(limited to 'test')
diff --git a/test/object_test.exs b/test/object_test.exs
index ab6431012..72194975d 100644
--- a/test/object_test.exs
+++ b/test/object_test.exs
@@ -57,32 +57,4 @@ defmodule Pleroma.ObjectTest do
assert cached_object.data["type"] == "Tombstone"
end
end
-
- describe "insert_or_get" do
- test "inserting the same object twice (by id) just returns the original object" do
- data = %{data: %{"id" => Ecto.UUID.generate()}}
- cng = Object.change(%Object{}, data)
- {:ok, object} = Object.insert_or_get(cng)
- {:ok, second_object} = Object.insert_or_get(cng)
-
- Cachex.clear(:object_cache)
- {:ok, third_object} = Object.insert_or_get(cng)
-
- assert object == second_object
- assert object == third_object
- end
- end
-
- describe "create" do
- test "inserts an object for a given data set" do
- data = %{"id" => Ecto.UUID.generate()}
-
- {:ok, object} = Object.create(data)
- assert object.data["id"] == data["id"]
-
- # Works when doing it twice.
- {:ok, object} = Object.create(data)
- assert object.data["id"] == data["id"]
- end
- end
end
--
cgit v1.2.3
From c01ef574c192488c2643a20b4064439757613449 Mon Sep 17 00:00:00 2001
From: Karen Konou
Date: Mon, 11 Feb 2019 11:59:51 +0100
Subject: Refactor as per Rin's suggestions, add endpoint tests
---
test/web/common_api/common_api_test.exs | 26 +++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 33 +++++++++++++++++++
test/web/thread_mute_test.exs | 37 ----------------------
3 files changed, 59 insertions(+), 37 deletions(-)
delete mode 100644 test/web/thread_mute_test.exs
(limited to 'test')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index a7d9e6161..d26b6e49c 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -164,4 +164,30 @@ defmodule Pleroma.Web.CommonAPI.Test do
assert %User{info: %{pinned_activities: []}} = user
end
end
+
+ describe "mute tests" do
+ setup do
+ user = insert(:user)
+
+ activity = insert(:note_activity)
+
+ [user: user, activity: activity]
+ end
+
+ test "add mute", %{user: user, activity: activity} do
+ {:ok, _} = CommonAPI.add_mute(user, activity)
+ assert CommonAPI.thread_muted?(user, activity)
+ end
+
+ test "remove mute", %{user: user, activity: activity} do
+ CommonAPI.add_mute(user, activity)
+ {:ok, _} = CommonAPI.remove_mute(user, activity)
+ refute CommonAPI.thread_muted?(user, activity)
+ end
+
+ test "check that mutes can't be duplicate", %{user: user, activity: activity} do
+ CommonAPI.add_mute(user, activity)
+ {:error, _} = CommonAPI.add_mute(user, activity)
+ end
+ end
end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index f8da86004..f7c059663 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1749,4 +1749,37 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [json_response(response2, 200)] == json_response(bookmarks, 200)
end
+
+ describe "conversation muting" do
+ setup do
+
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "HIE"})
+
+ [user: user, activity: activity]
+ end
+
+ test "mute conversation", %{conn: conn, user: user, activity: activity} do
+ id_str = to_string(activity.id)
+
+ assert %{"id" => ^id_str, "muted" => true} =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity.id}/mute")
+ |> json_response(200)
+ end
+
+ test "unmute conversation", %{conn: conn, user: user, activity: activity} do
+ {:ok, _} = CommonAPI.add_mute(user, activity)
+
+ id_str = to_string(activity.id)
+ user = refresh_record(user)
+
+ assert %{"id" => ^id_str, "muted" => false} =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity.id}/unmute")
+ |> json_response(200)
+ end
+ end
end
diff --git a/test/web/thread_mute_test.exs b/test/web/thread_mute_test.exs
deleted file mode 100644
index f3a24613c..000000000
--- a/test/web/thread_mute_test.exs
+++ /dev/null
@@ -1,37 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.ThreadMuteTest do
- use Pleroma.DataCase
- import Pleroma.Web.ThreadMute
-
- import Pleroma.Factory
-
- describe "mute tests" do
- setup do
- user = insert(:user)
-
- activity = insert(:note_activity)
-
- [user: user, activity: activity]
- end
-
- test "add mute", %{user: user, activity: activity} do
- {:ok, _activity} = add_mute(user, activity.id)
- assert muted?(user, activity)
- end
-
- test "remove mute", %{user: user, activity: activity} do
- add_mute(user, activity.id)
- {:ok, _activity} = remove_mute(user, activity.id)
- refute muted?(user, activity)
- end
-
- test "check that mutes can't be duplicate", %{user: user, activity: activity} do
- add_mute(user, activity.id)
- assert muted?(user, activity)
- {:error, _} = add_mute(user, activity.id)
- end
- end
-end
--
cgit v1.2.3
From 379d04692cdbf558c611c588c0e6a4262c02a58c Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Mon, 11 Feb 2019 21:35:40 +0300
Subject: Filter summary in keywordpolicy
---
test/web/activity_pub/mrf/keyword_policy_test.exs | 132 ++++++++++++++++++++--
1 file changed, 120 insertions(+), 12 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/mrf/keyword_policy_test.exs b/test/web/activity_pub/mrf/keyword_policy_test.exs
index 67a5858d7..602892a37 100644
--- a/test/web/activity_pub/mrf/keyword_policy_test.exs
+++ b/test/web/activity_pub/mrf/keyword_policy_test.exs
@@ -12,18 +12,35 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
end
describe "rejecting based on keywords" do
- test "rejects if string matches" do
+ test "rejects if string matches in content" do
Pleroma.Config.put([:mrf_keyword, :reject], ["pun"])
message = %{
"type" => "Create",
- "object" => %{"content" => "just a daily reminder that compLAINer is a good pun"}
+ "object" => %{
+ "content" => "just a daily reminder that compLAINer is a good pun",
+ "summary" => ""
+ }
}
assert {:reject, nil} == KeywordPolicy.filter(message)
end
- test "rejects if regex matches" do
+ test "rejects if string matches in summary" do
+ Pleroma.Config.put([:mrf_keyword, :reject], ["pun"])
+
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "summary" => "just a daily reminder that compLAINer is a good pun",
+ "content" => ""
+ }
+ }
+
+ assert {:reject, nil} == KeywordPolicy.filter(message)
+ end
+
+ test "rejects if regex matches in content" do
Pleroma.Config.put([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/])
assert true ==
@@ -31,7 +48,25 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
message = %{
"type" => "Create",
"object" => %{
- "content" => "just a daily reminder that #{content} is a good pun"
+ "content" => "just a daily reminder that #{content} is a good pun",
+ "summary" => ""
+ }
+ }
+
+ {:reject, nil} == KeywordPolicy.filter(message)
+ end)
+ end
+
+ test "rejects if regex matches in summary" do
+ Pleroma.Config.put([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/])
+
+ assert true ==
+ Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "summary" => "just a daily reminder that #{content} is a good pun",
+ "content" => ""
}
}
@@ -41,13 +76,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
end
describe "delisting from ftl based on keywords" do
- test "delists if string matches" do
+ test "delists if string matches in content" do
Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], ["pun"])
message = %{
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
"type" => "Create",
- "object" => %{"content" => "just a daily reminder that compLAINer is a good pun"}
+ "object" => %{
+ "content" => "just a daily reminder that compLAINer is a good pun",
+ "summary" => ""
+ }
}
{:ok, result} = KeywordPolicy.filter(message)
@@ -55,7 +93,45 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
refute ["https://www.w3.org/ns/activitystreams#Public"] == result["to"]
end
- test "delists if regex matches" do
+ test "delists if string matches in summary" do
+ Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], ["pun"])
+
+ message = %{
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "type" => "Create",
+ "object" => %{
+ "summary" => "just a daily reminder that compLAINer is a good pun",
+ "content" => ""
+ }
+ }
+
+ {:ok, result} = KeywordPolicy.filter(message)
+ assert ["https://www.w3.org/ns/activitystreams#Public"] == result["cc"]
+ refute ["https://www.w3.org/ns/activitystreams#Public"] == result["to"]
+ end
+
+ test "delists if regex matches in content" do
+ Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/])
+
+ assert true ==
+ Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
+ message = %{
+ "type" => "Create",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "object" => %{
+ "content" => "just a daily reminder that #{content} is a good pun",
+ "summary" => ""
+ }
+ }
+
+ {:ok, result} = KeywordPolicy.filter(message)
+
+ ["https://www.w3.org/ns/activitystreams#Public"] == result["cc"] and
+ not (["https://www.w3.org/ns/activitystreams#Public"] == result["to"])
+ end)
+ end
+
+ test "delists if regex matches in summary" do
Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/])
assert true ==
@@ -64,7 +140,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
"type" => "Create",
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
"object" => %{
- "content" => "just a daily reminder that #{content} is a good pun"
+ "summary" => "just a daily reminder that #{content} is a good pun",
+ "content" => ""
}
}
@@ -77,20 +154,33 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
end
describe "replacing keywords" do
- test "replaces keyword if string matches" do
+ test "replaces keyword if string matches in content" do
Pleroma.Config.put([:mrf_keyword, :replace], [{"opensource", "free software"}])
message = %{
"type" => "Create",
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
- "object" => %{"content" => "ZFS is opensource"}
+ "object" => %{"content" => "ZFS is opensource", "summary" => ""}
}
{:ok, %{"object" => %{"content" => result}}} = KeywordPolicy.filter(message)
assert result == "ZFS is free software"
end
- test "replaces keyword if regex matches" do
+ test "replaces keyword if string matches in summary" do
+ Pleroma.Config.put([:mrf_keyword, :replace], [{"opensource", "free software"}])
+
+ message = %{
+ "type" => "Create",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "object" => %{"summary" => "ZFS is opensource", "content" => ""}
+ }
+
+ {:ok, %{"object" => %{"summary" => result}}} = KeywordPolicy.filter(message)
+ assert result == "ZFS is free software"
+ end
+
+ test "replaces keyword if regex matches in content" do
Pleroma.Config.put([:mrf_keyword, :replace], [
{~r/open(-|\s)?source\s?(software)?/, "free software"}
])
@@ -100,12 +190,30 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
message = %{
"type" => "Create",
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
- "object" => %{"content" => "ZFS is #{content}"}
+ "object" => %{"content" => "ZFS is #{content}", "summary" => ""}
}
{:ok, %{"object" => %{"content" => result}}} = KeywordPolicy.filter(message)
result == "ZFS is free software"
end)
end
+
+ test "replaces keyword if regex matches in summary" do
+ Pleroma.Config.put([:mrf_keyword, :replace], [
+ {~r/open(-|\s)?source\s?(software)?/, "free software"}
+ ])
+
+ assert true ==
+ Enum.all?(["opensource", "open-source", "open source"], fn content ->
+ message = %{
+ "type" => "Create",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "object" => %{"summary" => "ZFS is #{content}", "content" => ""}
+ }
+
+ {:ok, %{"object" => %{"summary" => result}}} = KeywordPolicy.filter(message)
+ result == "ZFS is free software"
+ end)
+ end
end
end
--
cgit v1.2.3
From 61a4bc50952b11a59dce7f655c883de59306adcd Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Sun, 10 Feb 2019 22:41:06 +0300
Subject: Add OAuth tokens endpoint
---
test/support/factory.ex | 13 +++++++++++++
test/web/twitter_api/twitter_api_controller_test.exs | 18 ++++++++++++++++++
2 files changed, 31 insertions(+)
(limited to 'test')
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 0c21093ce..7a91549f5 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -227,4 +227,17 @@ defmodule Pleroma.Factory do
unreachable_since: nil
}
end
+
+ def oauth_token_factory do
+ user = insert(:user)
+ oauth_app = insert(:oauth_app)
+
+ %Pleroma.Web.OAuth.Token{
+ token: :crypto.strong_rand_bytes(32) |> Base.url_encode64(),
+ refresh_token: :crypto.strong_rand_bytes(32) |> Base.url_encode64(),
+ user_id: user.id,
+ app_id: oauth_app.id,
+ valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), 60 * 10)
+ }
+ end
end
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 855ae1526..c50d82def 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1876,4 +1876,22 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
ActivityRepresenter.to_map(activity, %{user: user, for: user})
end
end
+
+ describe "GET /api/oauth_tokens" do
+ test "renders list" do
+ token = insert(:oauth_token)
+
+ response =
+ build_conn()
+ |> assign(:user, Repo.get(User, token.user_id))
+ |> get("/api/oauth_tokens")
+
+ keys =
+ json_response(response, 200)
+ |> hd()
+ |> Map.keys()
+
+ assert keys -- ["id", "refresh_token", "token", "valid_until"] == []
+ end
+ end
end
--
cgit v1.2.3
From 62a45bdc11bc98ca4c24b0b8aa54c9d2958f81a1 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Mon, 11 Feb 2019 00:49:56 +0300
Subject: Add revoke token
---
.../twitter_api/twitter_api_controller_test.exs | 23 +++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index c50d82def..527a920fb 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -8,6 +8,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
alias Pleroma.Builders.{ActivityBuilder, UserBuilder}
alias Pleroma.{Repo, Activity, User, Object, Notification}
alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.OAuth.Token
alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Web.TwitterAPI.NotificationView
alias Pleroma.Web.CommonAPI
@@ -1878,12 +1879,16 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
describe "GET /api/oauth_tokens" do
- test "renders list" do
- token = insert(:oauth_token)
+ setup do
+ token = insert(:oauth_token) |> Repo.preload(:user)
+
+ %{token: token}
+ end
+ test "renders list", %{token: token} do
response =
build_conn()
- |> assign(:user, Repo.get(User, token.user_id))
+ |> assign(:user, token.user)
|> get("/api/oauth_tokens")
keys =
@@ -1893,5 +1898,17 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert keys -- ["id", "refresh_token", "token", "valid_until"] == []
end
+
+ test "revoke token", %{token: token} do
+ response =
+ build_conn()
+ |> assign(:user, token.user)
+ |> delete("/api/oauth_tokens/#{token.id}")
+
+ tokens = Token.get_user_tokens(token.user)
+
+ assert tokens == []
+ assert response.status == 201
+ end
end
end
--
cgit v1.2.3
From 88a4de24f9bc6fc73696cb5c986440c2c659b636 Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 13 Feb 2019 13:52:27 +0100
Subject: User.follow_all: Respect blocks in both directions.
---
test/user_test.exs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 523ab1ea4..a282274ce 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -55,18 +55,21 @@ defmodule Pleroma.UserTest do
followed_two = insert(:user)
blocked = insert(:user)
not_followed = insert(:user)
+ reverse_blocked = insert(:user)
{:ok, user} = User.block(user, blocked)
+ {:ok, reverse_blocked} = User.block(reverse_blocked, user)
{:ok, user} = User.follow(user, followed_zero)
- {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked])
+ {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked, reverse_blocked])
assert User.following?(user, followed_one)
assert User.following?(user, followed_two)
assert User.following?(user, followed_zero)
refute User.following?(user, not_followed)
refute User.following?(user, blocked)
+ refute User.following?(user, reverse_blocked)
end
test "follow_all follows mutliple users without duplicating" do
--
cgit v1.2.3
From d54c483964692e1ca6b813d6b35a0635d3c0abf9 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Wed, 13 Feb 2019 19:48:24 +0000
Subject: tests: add tests for endpoints
---
test/web/activity_pub/views/user_view_test.exs | 28 ++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs
index 7fc870e96..95d736c50 100644
--- a/test/web/activity_pub/views/user_view_test.exs
+++ b/test/web/activity_pub/views/user_view_test.exs
@@ -15,4 +15,32 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
end
+
+ describe "endpoints" do
+ test "local users have a usable endpoints structure" do
+ user = insert(:user)
+ {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
+
+ result = UserView.render("user.json", %{user: user})
+
+ assert result["id"] == user.ap_id
+
+ %{
+ "sharedInbox" => _,
+ "oauthAuthorizationEndpoint" => _,
+ "oauthRegistrationEndpoint" => _,
+ "oauthTokenEndpoint" => _
+ } = result["endpoints"]
+ end
+
+ test "remote users have an empty endpoints structure" do
+ user = insert(:user, local: false)
+ {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
+
+ result = UserView.render("user.json", %{user: user})
+
+ assert result["id"] == user.ap_id
+ assert result["endpoints"] == %{}
+ end
+ end
end
--
cgit v1.2.3
From 063baca5e4f3a100c0d45dffb14e4968599ef43b Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Thu, 14 Feb 2019 00:29:29 +0300
Subject: [#468] User UI for OAuth permissions restriction. Standardized
storage format for `scopes` fields, updated usages.
---
test/integration/mastodon_websocket_test.exs | 2 +-
test/support/factory.ex | 2 +-
test/web/oauth/authorization_test.exs | 6 +++---
test/web/oauth/oauth_controller_test.exs | 1 +
test/web/oauth/token_test.exs | 6 +++---
5 files changed, 9 insertions(+), 8 deletions(-)
(limited to 'test')
diff --git a/test/integration/mastodon_websocket_test.exs b/test/integration/mastodon_websocket_test.exs
index 2e385f5ad..0c513b6e7 100644
--- a/test/integration/mastodon_websocket_test.exs
+++ b/test/integration/mastodon_websocket_test.exs
@@ -80,7 +80,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
Pleroma.Repo.insert(
OAuth.App.register_changeset(%OAuth.App{}, %{
client_name: "client",
- scopes: "scope",
+ scopes: ["scope"],
redirect_uris: "url"
})
)
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 0c21093ce..eaa6f0ce2 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -214,7 +214,7 @@ defmodule Pleroma.Factory do
%Pleroma.Web.OAuth.App{
client_name: "Some client",
redirect_uris: "https://example.com/callback",
- scopes: "read",
+ scopes: ["read"],
website: "https://example.com",
client_id: "aaabbb==",
client_secret: "aaa;/&bbb"
diff --git a/test/web/oauth/authorization_test.exs b/test/web/oauth/authorization_test.exs
index 3b1ddada8..68db1ceb0 100644
--- a/test/web/oauth/authorization_test.exs
+++ b/test/web/oauth/authorization_test.exs
@@ -12,7 +12,7 @@ defmodule Pleroma.Web.OAuth.AuthorizationTest do
Repo.insert(
App.register_changeset(%App{}, %{
client_name: "client",
- scopes: "scope",
+ scopes: ["scope"],
redirect_uris: "url"
})
)
@@ -32,7 +32,7 @@ defmodule Pleroma.Web.OAuth.AuthorizationTest do
Repo.insert(
App.register_changeset(%App{}, %{
client_name: "client",
- scopes: "scope",
+ scopes: ["scope"],
redirect_uris: "url"
})
)
@@ -65,7 +65,7 @@ defmodule Pleroma.Web.OAuth.AuthorizationTest do
Repo.insert(
App.register_changeset(%App{}, %{
client_name: "client",
- scopes: "scope",
+ scopes: ["scope"],
redirect_uris: "url"
})
)
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index e0d3cb55f..74d512c7f 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -21,6 +21,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"password" => "test",
"client_id" => app.client_id,
"redirect_uri" => app.redirect_uris,
+ "scope" => Enum.join(app.scopes, " "),
"state" => "statepassed"
}
})
diff --git a/test/web/oauth/token_test.exs b/test/web/oauth/token_test.exs
index 9a241d61a..63a7eb3ae 100644
--- a/test/web/oauth/token_test.exs
+++ b/test/web/oauth/token_test.exs
@@ -14,7 +14,7 @@ defmodule Pleroma.Web.OAuth.TokenTest do
Repo.insert(
App.register_changeset(%App{}, %{
client_name: "client",
- scopes: "scope",
+ scopes: ["scope"],
redirect_uris: "url"
})
)
@@ -39,7 +39,7 @@ defmodule Pleroma.Web.OAuth.TokenTest do
Repo.insert(
App.register_changeset(%App{}, %{
client_name: "client1",
- scopes: "scope",
+ scopes: ["scope"],
redirect_uris: "url"
})
)
@@ -48,7 +48,7 @@ defmodule Pleroma.Web.OAuth.TokenTest do
Repo.insert(
App.register_changeset(%App{}, %{
client_name: "client2",
- scopes: "scope",
+ scopes: ["scope"],
redirect_uris: "url"
})
)
--
cgit v1.2.3
From 889ad95a2a766b82d17aa148d92754ecda244bf7 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Thu, 14 Feb 2019 00:59:18 +0000
Subject: tests: add some reserialization tests based on IR differences
---
test/web/activity_pub/transmogrifier_test.exs | 54 +++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index e5e3c8d33..86c66deff 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -1128,4 +1128,58 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
)
end
end
+
+ describe "reserialization" do
+ test "successfully reserializes a message with inReplyTo == nil" do
+ user = insert(:user)
+
+ message = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "cc" => [],
+ "type" => "Create",
+ "object" => %{
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "cc" => [],
+ "type" => "Note",
+ "content" => "Hi",
+ "inReplyTo" => nil,
+ "attributedTo" => user.ap_id
+ },
+ "actor" => user.ap_id
+ }
+
+ {:ok, activity} = Transmogrifier.handle_incoming(message)
+
+ {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
+ end
+
+ test "successfully reserializes a message with AS2 objects in IR" do
+ user = insert(:user)
+
+ message = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "cc" => [],
+ "type" => "Create",
+ "object" => %{
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "cc" => [],
+ "type" => "Note",
+ "content" => "Hi",
+ "inReplyTo" => nil,
+ "attributedTo" => user.ap_id,
+ "tag" => [
+ %{"name" => "#2hu", "href" => "http://example.com/2hu", "type" => "Hashtag"},
+ %{"name" => "Bob", "href" => "http://example.com/bob", "type" => "Mention"}
+ ]
+ },
+ "actor" => user.ap_id
+ }
+
+ {:ok, activity} = Transmogrifier.handle_incoming(message)
+
+ {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
+ end
+ end
end
--
cgit v1.2.3
From 64620d8980e3e93791d3f880296be2060ffc4d39 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Thu, 14 Feb 2019 02:41:21 +0000
Subject: activitypub: user view: do not expose oAuth endpoints for instance
users
---
test/web/activity_pub/views/user_view_test.exs | 11 +++++++++++
1 file changed, 11 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs
index 95d736c50..0bc1d4728 100644
--- a/test/web/activity_pub/views/user_view_test.exs
+++ b/test/web/activity_pub/views/user_view_test.exs
@@ -42,5 +42,16 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
assert result["id"] == user.ap_id
assert result["endpoints"] == %{}
end
+
+ test "instance users do not expose oAuth endpoints" do
+ user = insert(:user, nickname: nil, local: true)
+ {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
+
+ result = UserView.render("user.json", %{user: user})
+
+ refute result["endpoints"]["oauthAuthorizationEndpoint"]
+ refute result["endpoints"]["oauthRegistrationEndpoint"]
+ refute result["endpoints"]["oauthTokenEndpoint"]
+ end
end
end
--
cgit v1.2.3
From e031cc6473e12cae7249324fe6fdea5287b6304a Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Thu, 14 Feb 2019 03:22:54 +0000
Subject: tests: update tests for totalItems leak fix
---
test/web/activity_pub/activity_pub_controller_test.exs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 570bee6b3..9f6d87caa 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -397,7 +397,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> json_response(200)
assert result["first"]["orderedItems"] == []
- assert result["totalItems"] == 1
+ assert result["totalItems"] == 0
end
test "it works for more than 10 users", %{conn: conn} do
@@ -452,7 +452,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> json_response(200)
assert result["first"]["orderedItems"] == []
- assert result["totalItems"] == 1
+ assert result["totalItems"] == 0
end
test "it works for more than 10 users", %{conn: conn} do
--
cgit v1.2.3
From 907306174b082cccd823894c855194a4fc1e8305 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Thu, 14 Feb 2019 15:55:21 +0700
Subject: fix S3 links encoding in Mediaproxy
---
test/media_proxy_test.exs | 9 +++++++++
1 file changed, 9 insertions(+)
(limited to 'test')
diff --git a/test/media_proxy_test.exs b/test/media_proxy_test.exs
index 05d927422..ddbadfbf5 100644
--- a/test/media_proxy_test.exs
+++ b/test/media_proxy_test.exs
@@ -140,6 +140,15 @@ defmodule Pleroma.MediaProxyTest do
assert String.starts_with?(encoded, Pleroma.Config.get([:media_proxy, :base_url]))
end
+
+ # https://git.pleroma.social/pleroma/pleroma/issues/580
+ test "encoding S3 links (must preserve `%2F`)" do
+ url =
+ "https://s3.amazonaws.com/example/test.png?X-Amz-Credential=your-access-key-id%2F20130721%2Fus-east-1%2Fs3%2Faws4_request"
+
+ encoded = url(url)
+ assert decode_result(encoded) == url
+ end
end
describe "when disabled" do
--
cgit v1.2.3
From 32b164943433ddebfdb04494bbd4d4e8a90578d4 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Thu, 14 Feb 2019 19:59:12 +0000
Subject: test: user: add a test for whether user search returns a user or not
---
test/user_test.exs | 10 ++++++++++
1 file changed, 10 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 58587bd82..a99b79a0d 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -878,6 +878,16 @@ defmodule Pleroma.UserTest do
assert [] == User.search(query)
end)
end
+
+ test "works with URIs" do
+ results = User.search("http://mastodon.example.org/users/admin", true)
+ result = results |> List.first()
+
+ user = User.get_by_ap_id("http://mastodon.example.org/users/admin")
+
+ assert length(results) == 1
+ assert user == result |> Map.put(:search_rank, nil)
+ end
end
test "auth_active?/1 works correctly" do
--
cgit v1.2.3
From ecdf0657ba4a90d821d3874c827593963e0ff041 Mon Sep 17 00:00:00 2001
From: eugenijm
Date: Sun, 10 Feb 2019 02:26:29 +0300
Subject: Add logic for keeping follow_request_count up-to-date on the
`follow`,
`approve_friend_request`, and `deny_friend_request` actions.
Add follow_request_count to the user view.
---
.../mastodon_api/mastodon_api_controller_test.exs | 8 ++++++-
.../twitter_api/twitter_api_controller_test.exs | 26 ++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 26c9c25a6..7749c5ded 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -937,7 +937,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
test "/api/v1/follow_requests/:id/authorize works" do
- user = insert(:user, %{info: %Pleroma.User.Info{locked: true}})
+ user = insert(:user, %{info: %User.Info{locked: true}})
other_user = insert(:user)
{:ok, _activity} = ActivityPub.follow(other_user, user)
@@ -946,6 +946,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == false
+ assert user.info.follow_request_count == 1
conn =
build_conn()
@@ -959,6 +960,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == true
+ assert user.info.follow_request_count == 0
end
test "verify_credentials", %{conn: conn} do
@@ -979,6 +981,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _activity} = ActivityPub.follow(other_user, user)
+ user = Repo.get(User, user.id)
+ assert user.info.follow_request_count == 1
+
conn =
build_conn()
|> assign(:user, user)
@@ -991,6 +996,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == false
+ assert user.info.follow_request_count == 0
end
end
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index acb03b146..50b19fd86 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -640,6 +640,24 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert json_response(conn, 200) ==
UserView.render("show.json", %{user: followed, for: current_user})
end
+
+ test "for restricted account", %{conn: conn, user: current_user} do
+ followed = insert(:user, info: %User.Info{locked: true})
+
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/friendships/create.json", %{user_id: followed.id})
+
+ current_user = Repo.get(User, current_user.id)
+ followed = Repo.get(User, followed.id)
+
+ refute User.ap_followers(followed) in current_user.following
+ assert followed.info.follow_request_count == 1
+
+ assert json_response(conn, 200) ==
+ UserView.render("show.json", %{user: followed, for: current_user})
+ end
end
describe "POST /friendships/destroy.json" do
@@ -1676,15 +1694,19 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == false
+ assert user.info.follow_request_count == 1
conn =
build_conn()
|> assign(:user, user)
|> post("/api/pleroma/friendships/approve", %{"user_id" => other_user.id})
+ user = Repo.get(User, user.id)
+
assert relationship = json_response(conn, 200)
assert other_user.id == relationship["id"]
assert relationship["follows_you"] == true
+ assert user.info.follow_request_count == 0
end
end
@@ -1699,15 +1721,19 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == false
+ assert user.info.follow_request_count == 1
conn =
build_conn()
|> assign(:user, user)
|> post("/api/pleroma/friendships/deny", %{"user_id" => other_user.id})
+ user = Repo.get(User, user.id)
+
assert relationship = json_response(conn, 200)
assert other_user.id == relationship["id"]
assert relationship["follows_you"] == false
+ assert user.info.follow_request_count == 0
end
end
--
cgit v1.2.3
From d943c90249e0a598e57a0dbdf41d387b53916092 Mon Sep 17 00:00:00 2001
From: Karen Konou
Date: Fri, 15 Feb 2019 12:47:50 +0100
Subject: Add tests, change default config values, fix a bug
---
.../activity_pub/mrf/hellthread_policy_test.exs | 50 ++++++++++++++++++++++
1 file changed, 50 insertions(+)
create mode 100644 test/web/activity_pub/mrf/hellthread_policy_test.exs
(limited to 'test')
diff --git a/test/web/activity_pub/mrf/hellthread_policy_test.exs b/test/web/activity_pub/mrf/hellthread_policy_test.exs
new file mode 100644
index 000000000..b5bdd35cc
--- /dev/null
+++ b/test/web/activity_pub/mrf/hellthread_policy_test.exs
@@ -0,0 +1,50 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+
+ import Pleroma.Web.ActivityPub.MRF.HellthreadPolicy
+
+ describe "hellthread filter tests" do
+ setup do
+ user = insert(:user)
+
+ message = %{
+ "actor" => user.ap_id,
+ "cc" => [user.follower_address],
+ "type" => "Create",
+ "to" => [
+ "https://www.w3.org/ns/activitystreams#Public",
+ "https://instace.tld/users/user1",
+ "https://instace.tld/users/user2",
+ "https://instace.tld/users/user3"
+ ]
+ }
+
+ [user: user, message: message]
+ end
+
+ test "reject test", %{message: message} do
+ Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
+
+ {:reject, nil} = filter(message)
+ end
+
+ test "delist test", %{user: user, message: message} do
+ Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
+
+ {:ok, message} = filter(message)
+ assert user.follower_address in message["to"]
+ assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"]
+ end
+
+ test "threshold test", %{message: message} do
+ Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
+
+ {:ok, _} = filter(message)
+ end
+ end
+end
--
cgit v1.2.3
From dca6bee2f7eba1dc366cc65d3087f20678549739 Mon Sep 17 00:00:00 2001
From: Karen Konou
Date: Fri, 15 Feb 2019 13:43:14 +0100
Subject: Rename test, add check for follower collection when delisting
---
test/web/activity_pub/mrf/hellthread_policy_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/activity_pub/mrf/hellthread_policy_test.exs b/test/web/activity_pub/mrf/hellthread_policy_test.exs
index b5bdd35cc..ebf9997cd 100644
--- a/test/web/activity_pub/mrf/hellthread_policy_test.exs
+++ b/test/web/activity_pub/mrf/hellthread_policy_test.exs
@@ -41,7 +41,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"]
end
- test "threshold test", %{message: message} do
+ test "excludes follower collection and public URI from threshold count", %{message: message} do
Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
{:ok, _} = filter(message)
--
cgit v1.2.3
From d812a347ca936dba764eb223fde029d83ca3fba0 Mon Sep 17 00:00:00 2001
From: lain
Date: Sat, 16 Feb 2019 16:42:34 +0100
Subject: Add optional welcome message.
---
test/user_test.exs | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index a99b79a0d..d89fe379f 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -196,6 +196,25 @@ defmodule Pleroma.UserTest do
assert User.following?(registered_user, user)
refute User.following?(registered_user, remote_user)
+
+ Pleroma.Config.put([:instance, :autofollowed_nicknames], [])
+ end
+
+ test "it sends a welcome message if it is set" do
+ welcome_user = insert(:user)
+
+ Pleroma.Config.put([:instance, :welcome_user_nickname], welcome_user.nickname)
+ Pleroma.Config.put([:instance, :welcome_message], "Hello, this is a cool site")
+
+ cng = User.register_changeset(%User{}, @full_user_data)
+ {:ok, registered_user} = User.register(cng)
+
+ activity = Repo.one(Pleroma.Activity)
+ assert registered_user.ap_id in activity.recipients
+ assert activity.data["object"]["content"] =~ "cool site"
+
+ Pleroma.Config.put([:instance, :welcome_user_nickname], nil)
+ Pleroma.Config.put([:instance, :welcome_message], nil)
end
test "it requires an email, name, nickname and password, bio is optional" do
--
cgit v1.2.3
From 38e15930cb7e8aec4742eb85da26955b4c08e8ce Mon Sep 17 00:00:00 2001
From: lain
Date: Sat, 16 Feb 2019 17:01:15 +0100
Subject: Add option to return all friends in twitter api.
Mainly useful for user export.
---
test/web/twitter_api/twitter_api_controller_test.exs | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index acb03b146..f7e40e0d3 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1218,7 +1218,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert Enum.sort(expected) == Enum.sort(result)
end
- test "it returns 20 friends per page", %{conn: conn} do
+ test "it returns 20 friends per page, except if 'export' is set to true", %{conn: conn} do
user = insert(:user)
followeds = insert_list(21, :user)
@@ -1242,6 +1242,14 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
result = json_response(res_conn, 200)
assert length(result) == 1
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/statuses/friends", %{all: true})
+
+ result = json_response(res_conn, 200)
+ assert length(result) == 21
end
test "it returns a given user's friends with user_id", %{conn: conn} do
--
cgit v1.2.3
From f469a8610f47d6d36b2bcaa1974a1744990db7b4 Mon Sep 17 00:00:00 2001
From: lain
Date: Sat, 16 Feb 2019 17:24:31 +0100
Subject: Check that the welcome message is sent from the correct user.
---
test/user_test.exs | 1 +
1 file changed, 1 insertion(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index d89fe379f..92991d063 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -212,6 +212,7 @@ defmodule Pleroma.UserTest do
activity = Repo.one(Pleroma.Activity)
assert registered_user.ap_id in activity.recipients
assert activity.data["object"]["content"] =~ "cool site"
+ assert activity.actor == welcome_user.ap_id
Pleroma.Config.put([:instance, :welcome_user_nickname], nil)
Pleroma.Config.put([:instance, :welcome_message], nil)
--
cgit v1.2.3
From 72a4272d84a68ceb4d9a39ddaa4d3f45779bfebf Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Sun, 10 Feb 2019 23:11:12 +0100
Subject: Web.MastodonAPI.MastodonAPIControllerTest: Add testing of the flavour
switching
---
.../mastodon_api/mastodon_api_controller_test.exs | 25 ++++++++++++++++++++++
1 file changed, 25 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 26c9c25a6..450bf10a3 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1786,4 +1786,29 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> json_response(200)
end
end
+
+ test "flavours switching (Pleroma Extension)", %{conn: conn} do
+ user = insert(:user)
+
+ get_old_flavour =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/pleroma/flavour")
+
+ assert "glitch" == json_response(get_old_flavour, 200)
+
+ set_flavour =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/pleroma/flavour/vanilla")
+
+ assert "vanilla" == json_response(set_flavour, 200)
+
+ get_new_flavour =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/pleroma/flavour/vanilla")
+
+ assert json_response(set_flavour, 200) == json_response(get_new_flavour, 200)
+ end
end
--
cgit v1.2.3
From dcf24a3233bb50689d26f9d7833f98158730ce35 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Sun, 17 Feb 2019 13:49:14 +0300
Subject: [#468] Refactored OAuth scopes' defaults & missing selection
handling.
---
test/support/factory.ex | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/support/factory.ex b/test/support/factory.ex
index eaa6f0ce2..fa5d60bfc 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -214,7 +214,7 @@ defmodule Pleroma.Factory do
%Pleroma.Web.OAuth.App{
client_name: "Some client",
redirect_uris: "https://example.com/callback",
- scopes: ["read"],
+ scopes: ["read", "write", "follow"],
website: "https://example.com",
client_id: "aaabbb==",
client_secret: "aaa;/&bbb"
--
cgit v1.2.3
From d0a94f98e030dd700c56e8cc4576fb45cf449f53 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sun, 17 Feb 2019 14:33:44 +0300
Subject: more tests for HellthreadPolicy
---
.../activity_pub/mrf/hellthread_policy_test.exs | 69 ++++++++++++++--------
1 file changed, 46 insertions(+), 23 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/mrf/hellthread_policy_test.exs b/test/web/activity_pub/mrf/hellthread_policy_test.exs
index ebf9997cd..eb6ee4d04 100644
--- a/test/web/activity_pub/mrf/hellthread_policy_test.exs
+++ b/test/web/activity_pub/mrf/hellthread_policy_test.exs
@@ -8,32 +8,47 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
import Pleroma.Web.ActivityPub.MRF.HellthreadPolicy
- describe "hellthread filter tests" do
- setup do
- user = insert(:user)
-
- message = %{
- "actor" => user.ap_id,
- "cc" => [user.follower_address],
- "type" => "Create",
- "to" => [
- "https://www.w3.org/ns/activitystreams#Public",
- "https://instace.tld/users/user1",
- "https://instace.tld/users/user2",
- "https://instace.tld/users/user3"
- ]
- }
-
- [user: user, message: message]
- end
+ setup do
+ user = insert(:user)
+
+ message = %{
+ "actor" => user.ap_id,
+ "cc" => [user.follower_address],
+ "type" => "Create",
+ "to" => [
+ "https://www.w3.org/ns/activitystreams#Public",
+ "https://instance.tld/users/user1",
+ "https://instance.tld/users/user2",
+ "https://instance.tld/users/user3"
+ ]
+ }
+
+ [user: user, message: message]
+ end
- test "reject test", %{message: message} do
+ describe "reject" do
+ test "rejects the message if the recipient count is above reject_threshold", %{
+ message: message
+ } do
Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
{:reject, nil} = filter(message)
end
- test "delist test", %{user: user, message: message} do
+ test "does not reject the message if the recipient count is below reject_threshold", %{
+ message: message
+ } do
+ Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
+
+ assert {:ok, ^message} = filter(message)
+ end
+ end
+
+ describe "delist" do
+ test "delists the message if the recipient count is above delist_threshold", %{
+ user: user,
+ message: message
+ } do
Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
{:ok, message} = filter(message)
@@ -41,10 +56,18 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"]
end
- test "excludes follower collection and public URI from threshold count", %{message: message} do
- Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
+ test "does not delist the message if the recipient count is below delist_threshold", %{
+ message: message
+ } do
+ Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 4, reject_threshold: 0})
- {:ok, _} = filter(message)
+ assert {:ok, ^message} = filter(message)
end
end
+
+ test "excludes follower collection and public URI from threshold count", %{message: message} do
+ Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
+
+ assert {:ok, ^message} = filter(message)
+ end
end
--
cgit v1.2.3
From 71c8c60ded8dce402dbe69545afebd55c63927e5 Mon Sep 17 00:00:00 2001
From: lain
Date: Sun, 17 Feb 2019 17:47:24 +0100
Subject: More speedup, test fixes.
---
test/web/common_api/common_api_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index d26b6e49c..870648fb5 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -2,7 +2,7 @@
# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Web.CommonAPI.Test do
+defmodule Pleroma.Web.CommonAPITest do
use Pleroma.DataCase
alias Pleroma.Web.CommonAPI
alias Pleroma.User
--
cgit v1.2.3
From fd17a0cc9b78d1338e1fee51aa452858172639fe Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Mon, 18 Feb 2019 00:10:48 +0300
Subject: Fix test
---
test/web/twitter_api/twitter_api_controller_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 527a920fb..3922b3c5e 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1896,7 +1896,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> hd()
|> Map.keys()
- assert keys -- ["id", "refresh_token", "token", "valid_until"] == []
+ assert keys -- ["id", "app_name", "valid_until"] == []
end
test "revoke token", %{token: token} do
--
cgit v1.2.3
From 25b9e7a8c39602e6463a867089948a7957cfab9f Mon Sep 17 00:00:00 2001
From: eugenijm
Date: Tue, 19 Feb 2019 18:40:57 +0300
Subject: Added admin API for changing user activation status
---
test/web/admin_api/admin_api_controller_test.exs | 48 ++++++++++++++++++++++++
1 file changed, 48 insertions(+)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index a27c26f95..9fbaaba39 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -159,6 +159,54 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
end
+ describe "PUT /api/pleroma/admin/activation_status" do
+ setup %{conn: conn} do
+ admin = insert(:user, info: %{is_admin: true})
+
+ conn =
+ conn
+ |> assign(:user, admin)
+ |> put_req_header("accept", "application/json")
+
+ %{conn: conn}
+ end
+
+ test "deactivates the user", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> put("/api/pleroma/admin/activation_status/#{user.nickname}", %{status: false})
+
+ user = Repo.get(User, user.id)
+ assert user.info.deactivated == true
+ assert json_response(conn, :no_content)
+ end
+
+ test "activates the user", %{conn: conn} do
+ user = insert(:user, info: %{deactivated: true})
+
+ conn =
+ conn
+ |> put("/api/pleroma/admin/activation_status/#{user.nickname}", %{status: true})
+
+ user = Repo.get(User, user.id)
+ assert user.info.deactivated == false
+ assert json_response(conn, :no_content)
+ end
+
+ test "returns 403 when requested by a non-admin", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> put("/api/pleroma/admin/activation_status/#{user.nickname}", %{status: false})
+
+ assert json_response(conn, :forbidden)
+ end
+ end
+
describe "POST /api/pleroma/admin/email_invite, with valid config" do
setup do
registrations_open = Pleroma.Config.get([:instance, :registrations_open])
--
cgit v1.2.3
From ad2cf4fd86b811a9d2a4c152bcaaa0f0b8e25341 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Sun, 2 Sep 2018 00:34:15 +0300
Subject: Add test for mastodon muting endpoints
---
.../mastodon_api/mastodon_api_controller_test.exs | 56 +++++++++++++++-------
1 file changed, 38 insertions(+), 18 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index e43bc4508..e804ae203 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1206,6 +1206,42 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert id == to_string(other_user.id)
end
+ test "muting / unmuting a user", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/mute")
+
+ assert %{"id" => _id, "muting" => true} = json_response(conn, 200)
+
+ user = Repo.get(User, user.id)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/unmute")
+
+ assert %{"id" => _id, "muting" => false} = json_response(conn, 200)
+ end
+
+ test "getting a list of mutes", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, user} = User.mute(user, other_user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/mutes")
+
+ other_user_id = to_string(other_user.id)
+ assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
+ end
+
test "blocking / unblocking a user", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
@@ -1282,26 +1318,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert "even.worse.site" in domain_blocks
end
- test "unimplemented mute endpoints" do
- user = insert(:user)
- other_user = insert(:user)
-
- ["mute", "unmute"]
- |> Enum.each(fn endpoint ->
- conn =
- build_conn()
- |> assign(:user, user)
- |> post("/api/v1/accounts/#{other_user.id}/#{endpoint}")
-
- assert %{"id" => id} = json_response(conn, 200)
- assert id == to_string(other_user.id)
- end)
- end
-
- test "unimplemented mutes, follow_requests, blocks, domain blocks" do
+ test "unimplemented follow_requests, blocks, domain blocks" do
user = insert(:user)
- ["blocks", "domain_blocks", "mutes", "follow_requests"]
+ ["blocks", "domain_blocks", "follow_requests"]
|> Enum.each(fn endpoint ->
conn =
build_conn()
--
cgit v1.2.3
From 04ee877a20a849db53a307a1736e635229129b7a Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Tue, 19 Feb 2019 22:28:21 +0300
Subject: [#468] Added OAuth scopes-specific tests.
---
.../mastodon_api/mastodon_api_controller_test.exs | 18 ++++
test/web/oauth/authorization_test.exs | 46 +++++------
test/web/oauth/oauth_controller_test.exs | 96 ++++++++++++++++++----
test/web/oauth/token_test.exs | 8 +-
.../twitter_api/twitter_api_controller_test.exs | 18 ++++
test/web/twitter_api/util_controller_test.exs | 19 +++++
6 files changed, 160 insertions(+), 45 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index e43bc4508..8dcbde48b 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1536,6 +1536,24 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert user_response = json_response(conn, 200)
assert user_response["header"] != User.banner_url(user)
end
+
+ test "requires 'write' permission", %{conn: conn} do
+ token1 = insert(:oauth_token, scopes: ["read"])
+ token2 = insert(:oauth_token, scopes: ["write", "follow"])
+
+ for token <- [token1, token2] do
+ conn =
+ conn
+ |> put_req_header("authorization", "Bearer #{token.token}")
+ |> patch("/api/v1/accounts/update_credentials", %{})
+
+ if token == token1 do
+ assert %{"error" => "Insufficient permissions: write."} == json_response(conn, 403)
+ else
+ assert json_response(conn, 200)
+ end
+ end
+ end
end
test "get instance information", %{conn: conn} do
diff --git a/test/web/oauth/authorization_test.exs b/test/web/oauth/authorization_test.exs
index b1a51e30e..306db2e62 100644
--- a/test/web/oauth/authorization_test.exs
+++ b/test/web/oauth/authorization_test.exs
@@ -8,36 +8,37 @@ defmodule Pleroma.Web.OAuth.AuthorizationTest do
alias Pleroma.Web.OAuth.App
import Pleroma.Factory
- test "create an authorization token for a valid app" do
+ setup do
{:ok, app} =
Repo.insert(
App.register_changeset(%App{}, %{
client_name: "client",
- scopes: ["scope"],
+ scopes: ["read", "write"],
redirect_uris: "url"
})
)
+ %{app: app}
+ end
+
+ test "create an authorization token for a valid app", %{app: app} do
user = insert(:user)
- {:ok, auth} = Authorization.create_authorization(app, user)
+ {:ok, auth1} = Authorization.create_authorization(app, user)
+ assert auth1.scopes == app.scopes
- assert auth.user_id == user.id
- assert auth.app_id == app.id
- assert String.length(auth.token) > 10
- assert auth.used == false
- end
+ {:ok, auth2} = Authorization.create_authorization(app, user, ["read"])
+ assert auth2.scopes == ["read"]
- test "use up a token" do
- {:ok, app} =
- Repo.insert(
- App.register_changeset(%App{}, %{
- client_name: "client",
- scopes: ["scope"],
- redirect_uris: "url"
- })
- )
+ for auth <- [auth1, auth2] do
+ assert auth.user_id == user.id
+ assert auth.app_id == app.id
+ assert String.length(auth.token) > 10
+ assert auth.used == false
+ end
+ end
+ test "use up a token", %{app: app} do
user = insert(:user)
{:ok, auth} = Authorization.create_authorization(app, user)
@@ -61,16 +62,7 @@ defmodule Pleroma.Web.OAuth.AuthorizationTest do
assert {:error, "token expired"} == Authorization.use_token(expired_auth)
end
- test "delete authorizations" do
- {:ok, app} =
- Repo.insert(
- App.register_changeset(%App{}, %{
- client_name: "client",
- scopes: ["scope"],
- redirect_uris: "url"
- })
- )
-
+ test "delete authorizations", %{app: app} do
user = insert(:user)
{:ok, auth} = Authorization.create_authorization(app, user)
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index ca1c04319..53d83e6e8 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -12,7 +12,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
test "redirects with oauth authorization" do
user = insert(:user)
- app = insert(:oauth_app)
+ app = insert(:oauth_app, scopes: ["read", "write", "follow"])
conn =
build_conn()
@@ -22,7 +22,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"password" => "test",
"client_id" => app.client_id,
"redirect_uri" => app.redirect_uris,
- "scope" => Enum.join(app.scopes, " "),
+ "scope" => "read write",
"state" => "statepassed"
}
})
@@ -33,10 +33,12 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
query = URI.parse(target).query |> URI.query_decoder() |> Map.new()
assert %{"state" => "statepassed", "code" => code} = query
- assert Repo.get_by(Authorization, token: code)
+ auth = Repo.get_by(Authorization, token: code)
+ assert auth
+ assert auth.scopes == ["read", "write"]
end
- test "correctly handles wrong credentials", %{conn: conn} do
+ test "returns 401 for wrong credentials", %{conn: conn} do
user = insert(:user)
app = insert(:oauth_app)
@@ -48,7 +50,8 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"password" => "wrong",
"client_id" => app.client_id,
"redirect_uri" => app.redirect_uris,
- "state" => "statepassed"
+ "state" => "statepassed",
+ "scope" => Enum.join(app.scopes, " ")
}
})
|> html_response(:unauthorized)
@@ -58,14 +61,66 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
assert result =~ app.redirect_uris
# Error message
- assert result =~ "Invalid"
+ assert result =~ "Invalid Username/Password"
end
- test "issues a token for an all-body request" do
+ test "returns 401 for missing scopes", %{conn: conn} do
user = insert(:user)
app = insert(:oauth_app)
- {:ok, auth} = Authorization.create_authorization(app, user)
+ result =
+ conn
+ |> post("/oauth/authorize", %{
+ "authorization" => %{
+ "name" => user.nickname,
+ "password" => "test",
+ "client_id" => app.client_id,
+ "redirect_uri" => app.redirect_uris,
+ "state" => "statepassed",
+ "scope" => ""
+ }
+ })
+ |> html_response(:unauthorized)
+
+ # Keep the details
+ assert result =~ app.client_id
+ assert result =~ app.redirect_uris
+
+ # Error message
+ assert result =~ "Permissions not specified"
+ end
+
+ test "returns 401 for scopes beyond app scopes", %{conn: conn} do
+ user = insert(:user)
+ app = insert(:oauth_app, scopes: ["read", "write"])
+
+ result =
+ conn
+ |> post("/oauth/authorize", %{
+ "authorization" => %{
+ "name" => user.nickname,
+ "password" => "test",
+ "client_id" => app.client_id,
+ "redirect_uri" => app.redirect_uris,
+ "state" => "statepassed",
+ "scope" => "read write follow"
+ }
+ })
+ |> html_response(:unauthorized)
+
+ # Keep the details
+ assert result =~ app.client_id
+ assert result =~ app.redirect_uris
+
+ # Error message
+ assert result =~ "Permissions not specified"
+ end
+
+ test "issues a token for an all-body request" do
+ user = insert(:user)
+ app = insert(:oauth_app, scopes: ["read", "write"])
+
+ {:ok, auth} = Authorization.create_authorization(app, user, ["write"])
conn =
build_conn()
@@ -78,15 +133,19 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
})
assert %{"access_token" => token} = json_response(conn, 200)
- assert Repo.get_by(Token, token: token)
+
+ token = Repo.get_by(Token, token: token)
+ assert token
+ assert token.scopes == auth.scopes
end
- test "issues a token for `password` grant_type with valid credentials" do
+ test "issues a token for `password` grant_type with valid credentials, with full permissions by default" do
password = "testpassword"
user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
- app = insert(:oauth_app)
+ app = insert(:oauth_app, scopes: ["read", "write"])
+ # Note: "scope" param is intentionally omitted
conn =
build_conn()
|> post("/oauth/token", %{
@@ -98,14 +157,18 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
})
assert %{"access_token" => token} = json_response(conn, 200)
- assert Repo.get_by(Token, token: token)
+
+ token = Repo.get_by(Token, token: token)
+ assert token
+ assert token.scopes == app.scopes
end
test "issues a token for request with HTTP basic auth client credentials" do
user = insert(:user)
- app = insert(:oauth_app)
+ app = insert(:oauth_app, scopes: ["scope1", "scope2"])
- {:ok, auth} = Authorization.create_authorization(app, user)
+ {:ok, auth} = Authorization.create_authorization(app, user, ["scope2"])
+ assert auth.scopes == ["scope2"]
app_encoded =
(URI.encode_www_form(app.client_id) <> ":" <> URI.encode_www_form(app.client_secret))
@@ -121,7 +184,10 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
})
assert %{"access_token" => token} = json_response(conn, 200)
- assert Repo.get_by(Token, token: token)
+
+ token = Repo.get_by(Token, token: token)
+ assert token
+ assert token.scopes == ["scope2"]
end
test "rejects token exchange with invalid client credentials" do
diff --git a/test/web/oauth/token_test.exs b/test/web/oauth/token_test.exs
index a708e4991..62444a0fa 100644
--- a/test/web/oauth/token_test.exs
+++ b/test/web/oauth/token_test.exs
@@ -11,24 +11,26 @@ defmodule Pleroma.Web.OAuth.TokenTest do
import Pleroma.Factory
- test "exchanges a auth token for an access token" do
+ test "exchanges a auth token for an access token, preserving `scopes`" do
{:ok, app} =
Repo.insert(
App.register_changeset(%App{}, %{
client_name: "client",
- scopes: ["scope"],
+ scopes: ["read", "write"],
redirect_uris: "url"
})
)
user = insert(:user)
- {:ok, auth} = Authorization.create_authorization(app, user)
+ {:ok, auth} = Authorization.create_authorization(app, user, ["read"])
+ assert auth.scopes == ["read"]
{:ok, token} = Token.exchange_token(app, auth)
assert token.app_id == app.id
assert token.user_id == user.id
+ assert token.scopes == auth.scopes
assert String.length(token.token) > 10
assert String.length(token.refresh_token) > 10
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 1571ab68e..27b1e878c 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1690,6 +1690,24 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert [relationship] = json_response(conn, 200)
assert other_user.id == relationship["id"]
end
+
+ test "requires 'read' permission", %{conn: conn} do
+ token1 = insert(:oauth_token, scopes: ["write"])
+ token2 = insert(:oauth_token, scopes: ["read"])
+
+ for token <- [token1, token2] do
+ conn =
+ conn
+ |> put_req_header("authorization", "Bearer #{token.token}")
+ |> get("/api/pleroma/friend_requests")
+
+ if token == token1 do
+ assert %{"error" => "Insufficient permissions: read."} == json_response(conn, 403)
+ else
+ assert json_response(conn, 200)
+ end
+ end
+ end
end
describe "POST /api/pleroma/friendships/approve" do
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index 007d7d8e6..fc762ab18 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -16,6 +16,25 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
assert response == "job started"
end
+
+ test "requires 'follow' permission", %{conn: conn} do
+ token1 = insert(:oauth_token, scopes: ["read", "write"])
+ token2 = insert(:oauth_token, scopes: ["follow"])
+ another_user = insert(:user)
+
+ for token <- [token1, token2] do
+ conn =
+ conn
+ |> put_req_header("authorization", "Bearer #{token.token}")
+ |> post("/api/pleroma/follow_import", %{"list" => "#{another_user.ap_id}"})
+
+ if token == token1 do
+ assert %{"error" => "Insufficient permissions: follow."} == json_response(conn, 403)
+ else
+ assert json_response(conn, 200)
+ end
+ end
+ end
end
describe "POST /api/pleroma/blocks_import" do
--
cgit v1.2.3
From 337367d764dda8947eb0369f31da641c045dd3b0 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Wed, 20 Feb 2019 12:27:28 +0300
Subject: [#468] More OAuth scopes-specific tests.
---
test/plugs/oauth_scopes_plug_test.exs | 122 +++++++++++++++++++++
.../twitter_api/twitter_api_controller_test.exs | 16 +++
2 files changed, 138 insertions(+)
create mode 100644 test/plugs/oauth_scopes_plug_test.exs
(limited to 'test')
diff --git a/test/plugs/oauth_scopes_plug_test.exs b/test/plugs/oauth_scopes_plug_test.exs
new file mode 100644
index 000000000..f328026df
--- /dev/null
+++ b/test/plugs/oauth_scopes_plug_test.exs
@@ -0,0 +1,122 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Plugs.OAuthScopesPlugTest do
+ use Pleroma.Web.ConnCase, async: true
+
+ alias Pleroma.Plugs.OAuthScopesPlug
+ alias Pleroma.Repo
+
+ import Pleroma.Factory
+
+ test "proceeds with no op if `assigns[:token]` is nil", %{conn: conn} do
+ conn =
+ conn
+ |> assign(:user, insert(:user))
+ |> OAuthScopesPlug.call(%{scopes: ["read"]})
+
+ refute conn.halted
+ assert conn.assigns[:user]
+ end
+
+ test "proceeds with no op if `token.scopes` fulfill specified 'any of' conditions", %{
+ conn: conn
+ } do
+ token = insert(:oauth_token, scopes: ["read", "write"]) |> Repo.preload(:user)
+
+ conn =
+ conn
+ |> assign(:user, token.user)
+ |> assign(:token, token)
+ |> OAuthScopesPlug.call(%{scopes: ["read"]})
+
+ refute conn.halted
+ assert conn.assigns[:user]
+ end
+
+ test "proceeds with no op if `token.scopes` fulfill specified 'all of' conditions", %{
+ conn: conn
+ } do
+ token = insert(:oauth_token, scopes: ["scope1", "scope2", "scope3"]) |> Repo.preload(:user)
+
+ conn =
+ conn
+ |> assign(:user, token.user)
+ |> assign(:token, token)
+ |> OAuthScopesPlug.call(%{scopes: ["scope2", "scope3"], op: :&})
+
+ refute conn.halted
+ assert conn.assigns[:user]
+ end
+
+ test "proceeds with cleared `assigns[:user]` if `token.scopes` doesn't fulfill specified 'any of' conditions " <>
+ "and `fallback: :proceed_unauthenticated` option is specified",
+ %{conn: conn} do
+ token = insert(:oauth_token, scopes: ["read", "write"]) |> Repo.preload(:user)
+
+ conn =
+ conn
+ |> assign(:user, token.user)
+ |> assign(:token, token)
+ |> OAuthScopesPlug.call(%{scopes: ["follow"], fallback: :proceed_unauthenticated})
+
+ refute conn.halted
+ refute conn.assigns[:user]
+ end
+
+ test "proceeds with cleared `assigns[:user]` if `token.scopes` doesn't fulfill specified 'all of' conditions " <>
+ "and `fallback: :proceed_unauthenticated` option is specified",
+ %{conn: conn} do
+ token = insert(:oauth_token, scopes: ["read", "write"]) |> Repo.preload(:user)
+
+ conn =
+ conn
+ |> assign(:user, token.user)
+ |> assign(:token, token)
+ |> OAuthScopesPlug.call(%{
+ scopes: ["read", "follow"],
+ op: :&,
+ fallback: :proceed_unauthenticated
+ })
+
+ refute conn.halted
+ refute conn.assigns[:user]
+ end
+
+ test "returns 403 and halts in case of no :fallback option and `token.scopes` not fulfilling specified 'any of' conditions",
+ %{conn: conn} do
+ token = insert(:oauth_token, scopes: ["read", "write"])
+ any_of_scopes = ["follow"]
+
+ conn =
+ conn
+ |> assign(:token, token)
+ |> OAuthScopesPlug.call(%{scopes: any_of_scopes})
+
+ assert conn.halted
+ assert 403 == conn.status
+
+ expected_error = "Insufficient permissions: #{Enum.join(any_of_scopes, ", ")}."
+ assert Jason.encode!(%{error: expected_error}) == conn.resp_body
+ end
+
+ test "returns 403 and halts in case of no :fallback option and `token.scopes` not fulfilling specified 'all of' conditions",
+ %{conn: conn} do
+ token = insert(:oauth_token, scopes: ["read", "write"])
+ all_of_scopes = ["write", "follow"]
+
+ conn =
+ conn
+ |> assign(:token, token)
+ |> OAuthScopesPlug.call(%{scopes: all_of_scopes, op: :&})
+
+ assert conn.halted
+ assert 403 == conn.status
+
+ expected_error =
+ "Insufficient permissions: #{Enum.join(all_of_scopes -- token.scopes, ", ")}."
+
+ assert Jason.encode!(%{error: expected_error}) == conn.resp_body
+ end
+end
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 27b1e878c..05a832967 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -14,6 +14,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
alias Pleroma.Notification
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.OAuth.Token
+ alias Pleroma.Web.TwitterAPI.Controller
alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Web.TwitterAPI.NotificationView
alias Pleroma.Web.CommonAPI
@@ -22,6 +23,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
alias Ecto.Changeset
import Pleroma.Factory
+ import Mock
@banner "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
@@ -187,6 +189,20 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> get("/api/statuses/public_timeline.json")
|> json_response(200)
end
+
+ test_with_mock "treats user as unauthenticated if `assigns[:token]` is present but lacks `read` permission",
+ Controller,
+ [:passthrough],
+ [] do
+ token = insert(:oauth_token, scopes: ["write"])
+
+ build_conn()
+ |> put_req_header("authorization", "Bearer #{token.token}")
+ |> get("/api/statuses/public_timeline.json")
+ |> json_response(200)
+
+ assert called(Controller.public_timeline(%{assigns: %{user: nil}}, :_))
+ end
end
describe "GET /statuses/public_and_external_timeline.json" do
--
cgit v1.2.3
From 9ae79bb71a2f0e9f88275f350126f1b1ba02c734 Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 20 Feb 2019 13:47:44 +0100
Subject: Add test for muting functionality.
---
test/web/activity_pub/activity_pub_test.exs | 42 +++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index a6f8b822a..33ed17434 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -277,6 +277,48 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert Enum.member?(activities, activity_one)
end
+ test "doesn't return muted activities" do
+ activity_one = insert(:note_activity)
+ activity_two = insert(:note_activity)
+ activity_three = insert(:note_activity)
+ user = insert(:user)
+ booster = insert(:user)
+ {:ok, user} = User.mute(user, %User{ap_id: activity_one.data["actor"]})
+
+ activities = ActivityPub.fetch_activities([], %{"muting_user" => user})
+
+ assert Enum.member?(activities, activity_two)
+ assert Enum.member?(activities, activity_three)
+ refute Enum.member?(activities, activity_one)
+
+ {:ok, user} = User.unmute(user, %User{ap_id: activity_one.data["actor"]})
+
+ activities = ActivityPub.fetch_activities([], %{"muting_user" => user})
+
+ assert Enum.member?(activities, activity_two)
+ assert Enum.member?(activities, activity_three)
+ assert Enum.member?(activities, activity_one)
+
+ {:ok, user} = User.mute(user, %User{ap_id: activity_three.data["actor"]})
+ {:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.repeat(activity_three.id, booster)
+ %Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id)
+ activity_three = Repo.get(Activity, activity_three.id)
+
+ activities = ActivityPub.fetch_activities([], %{"muting_user" => user})
+
+ assert Enum.member?(activities, activity_two)
+ refute Enum.member?(activities, activity_three)
+ refute Enum.member?(activities, boost_activity)
+ assert Enum.member?(activities, activity_one)
+
+ activities = ActivityPub.fetch_activities([], %{"muting_user" => nil})
+
+ assert Enum.member?(activities, activity_two)
+ assert Enum.member?(activities, activity_three)
+ assert Enum.member?(activities, boost_activity)
+ assert Enum.member?(activities, activity_one)
+ end
+
test "excludes reblogs on request" do
user = insert(:user)
{:ok, expected_activity} = ActivityBuilder.insert(%{"type" => "Create"}, %{:user => user})
--
cgit v1.2.3
From 4196d9af111893e186bfedd8a03994cd02cf87a2 Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 20 Feb 2019 14:14:52 +0100
Subject: Add test for User.mutes and so on.
---
test/user_test.exs | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 92991d063..0b1c39ecf 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -594,6 +594,29 @@ defmodule Pleroma.UserTest do
end
end
+ describe "mutes" do
+ test "it mutes people" do
+ user = insert(:user)
+ muted_user = insert(:user)
+
+ refute User.mutes?(user, muted_user)
+
+ {:ok, user} = User.mute(user, muted_user)
+
+ assert User.mutes?(user, muted_user)
+ end
+
+ test "it unmutes users" do
+ user = insert(:user)
+ muted_user = insert(:user)
+
+ {:ok, user} = User.mute(user, muted_user)
+ {:ok, user} = User.unmute(user, muted_user)
+
+ refute User.mutes?(user, muted_user)
+ end
+ end
+
describe "blocks" do
test "it blocks people" do
user = insert(:user)
--
cgit v1.2.3
From b574d97c2ee5ea926342b6ef00d9c22c1cc7ebdd Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Wed, 20 Feb 2019 17:27:41 +0300
Subject: [#468] Added support for `push` OAuth scope (Mastodon 2.4+).
---
test/support/factory.ex | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 0c59b3ce8..d1956d1cd 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -214,7 +214,7 @@ defmodule Pleroma.Factory do
%Pleroma.Web.OAuth.App{
client_name: "Some client",
redirect_uris: "https://example.com/callback",
- scopes: ["read", "write", "follow"],
+ scopes: ["read", "write", "follow", "push"],
website: "https://example.com",
client_id: "aaabbb==",
client_secret: "aaa;/&bbb"
--
cgit v1.2.3
From 59c27f29c8315b3de97c35d260a038a3f09c1885 Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 20 Feb 2019 17:36:16 +0100
Subject: Add some nicer urls in status view.
---
test/web/mastodon_api/status_view_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 0dc9c538c..3412a6be2 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -81,7 +81,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
expected = %{
id: to_string(note.id),
uri: note.data["object"]["id"],
- url: note.data["object"]["id"],
+ url: Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, note),
account: AccountView.render("account.json", %{user: user}),
in_reply_to_id: nil,
in_reply_to_account_id: nil,
--
cgit v1.2.3
From bff9eb5ef7ad446376f68807d4e51db5f2de9515 Mon Sep 17 00:00:00 2001
From: Egor
Date: Wed, 20 Feb 2019 16:51:25 +0000
Subject: Reports
---
test/web/activity_pub/activity_pub_test.exs | 33 ++++++++++-
test/web/common_api/common_api_test.exs | 31 +++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 65 ++++++++++++++++++++++
3 files changed, 128 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 33ed17434..11262c523 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
@@ -742,6 +742,37 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert 3 = length(activities)
end
+ test "it can create a Flag activity" do
+ reporter = insert(:user)
+ target_account = insert(:user)
+ {:ok, activity} = CommonAPI.post(target_account, %{"status" => "foobar"})
+ context = Utils.generate_context_id()
+ content = "foobar"
+
+ reporter_ap_id = reporter.ap_id
+ target_ap_id = target_account.ap_id
+ activity_ap_id = activity.data["id"]
+
+ assert {:ok, activity} =
+ ActivityPub.flag(%{
+ actor: reporter,
+ context: context,
+ account: target_account,
+ statuses: [activity],
+ content: content
+ })
+
+ assert %Activity{
+ actor: ^reporter_ap_id,
+ data: %{
+ "type" => "Flag",
+ "content" => ^content,
+ "context" => ^context,
+ "object" => [^target_ap_id, ^activity_ap_id]
+ }
+ } = activity
+ end
+
describe "publish_one/1" do
test_with_mock "calls `Instances.set_reachable` on successful federation if `unreachable_since` is not specified",
Instances,
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 870648fb5..9ba320f59 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -190,4 +190,35 @@ defmodule Pleroma.Web.CommonAPITest do
{:error, _} = CommonAPI.add_mute(user, activity)
end
end
+
+ describe "reports" do
+ test "creates a report" do
+ reporter = insert(:user)
+ target_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(target_user, %{"status" => "foobar"})
+
+ reporter_ap_id = reporter.ap_id
+ target_ap_id = target_user.ap_id
+ activity_ap_id = activity.data["id"]
+ comment = "foobar"
+
+ report_data = %{
+ "account_id" => target_user.id,
+ "comment" => comment,
+ "status_ids" => [activity.id]
+ }
+
+ assert {:ok, flag_activity} = CommonAPI.report(reporter, report_data)
+
+ assert %Activity{
+ actor: ^reporter_ap_id,
+ data: %{
+ "type" => "Flag",
+ "content" => ^comment,
+ "object" => [^target_ap_id, ^activity_ap_id]
+ }
+ } = flag_activity
+ end
+ end
end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 691264135..3dfbc8669 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1855,4 +1855,69 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert json_response(set_flavour, 200) == json_response(get_new_flavour, 200)
end
+
+ describe "reports" do
+ setup do
+ reporter = insert(:user)
+ target_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(target_user, %{"status" => "foobar"})
+
+ [reporter: reporter, target_user: target_user, activity: activity]
+ end
+
+ test "submit a basic report", %{conn: conn, reporter: reporter, target_user: target_user} do
+ assert %{"action_taken" => false, "id" => _} =
+ conn
+ |> assign(:user, reporter)
+ |> post("/api/v1/reports", %{"account_id" => target_user.id})
+ |> json_response(200)
+ end
+
+ test "submit a report with statuses and comment", %{
+ conn: conn,
+ reporter: reporter,
+ target_user: target_user,
+ activity: activity
+ } do
+ assert %{"action_taken" => false, "id" => _} =
+ conn
+ |> assign(:user, reporter)
+ |> post("/api/v1/reports", %{
+ "account_id" => target_user.id,
+ "status_ids" => [activity.id],
+ "comment" => "bad status!"
+ })
+ |> json_response(200)
+ end
+
+ test "accound_id is required", %{
+ conn: conn,
+ reporter: reporter,
+ activity: activity
+ } do
+ assert %{"error" => "Valid `account_id` required"} =
+ conn
+ |> assign(:user, reporter)
+ |> post("/api/v1/reports", %{"status_ids" => [activity.id]})
+ |> json_response(400)
+ end
+
+ test "comment must be up to the size specified in the config", %{
+ conn: conn,
+ reporter: reporter,
+ target_user: target_user
+ } do
+ max_size = Pleroma.Config.get([:instance, :max_report_comment_size], 1000)
+ comment = String.pad_trailing("a", max_size + 1, "a")
+
+ error = %{"error" => "Comment must be up to #{max_size} characters"}
+
+ assert ^error =
+ conn
+ |> assign(:user, reporter)
+ |> post("/api/v1/reports", %{"account_id" => target_user.id, "comment" => comment})
+ |> json_response(400)
+ end
+ end
end
--
cgit v1.2.3
From 3ee77e95b2496b253ebd37a24dce7fdfa7a9c550 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Wed, 20 Feb 2019 17:23:05 +0000
Subject: tests: fix tests
---
test/web/views/error_view_test.exs | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/views/error_view_test.exs b/test/web/views/error_view_test.exs
index 16a0c8cef..d529fd2c3 100644
--- a/test/web/views/error_view_test.exs
+++ b/test/web/views/error_view_test.exs
@@ -14,11 +14,16 @@ defmodule Pleroma.Web.ErrorViewTest do
test "render 500.json" do
assert render(Pleroma.Web.ErrorView, "500.json", []) ==
- %{errors: %{detail: "Internal server error"}}
+ %{errors: %{detail: "Internal server error", reason: "nil"}}
end
test "render any other" do
assert render(Pleroma.Web.ErrorView, "505.json", []) ==
- %{errors: %{detail: "Internal server error"}}
+ %{errors: %{detail: "Internal server error", reason: "nil"}}
+ end
+
+ test "render 500.json with reason" do
+ assert render(Pleroma.Web.ErrorView, "500.json", reason: "test reason") ==
+ %{errors: %{detail: "Internal server error", reason: "\"test reason\""}}
end
end
--
cgit v1.2.3
From aa45674be68d65c500e776f15a4a28097b415829 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Wed, 20 Feb 2019 20:45:09 +0000
Subject: tests: add test for fetching AP objects with application/json.
---
.../activity_pub/activity_pub_controller_test.exs | 54 +++++++++++++++++++++-
1 file changed, 52 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 398bedf77..aa2ca4eb8 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -41,7 +41,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
describe "/users/:nickname" do
- test "it returns a json representation of the user", %{conn: conn} do
+ test "it returns a json representation of the user with accept application/json", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> put_req_header("accept", "application/json")
+ |> get("/users/#{user.nickname}")
+
+ user = Repo.get(User, user.id)
+
+ assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
+ end
+
+ test "it returns a json representation of the user with accept application/activity+json", %{conn: conn} do
user = insert(:user)
conn =
@@ -53,10 +66,35 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
end
+
+ test "it returns a json representation of the user with accept application/ld+json", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> put_req_header("accept", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
+ |> get("/users/#{user.nickname}")
+
+ user = Repo.get(User, user.id)
+
+ assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
+ end
end
describe "/object/:uuid" do
- test "it returns a json representation of the object", %{conn: conn} do
+ test "it returns a json representation of the object with accept application/json", %{conn: conn} do
+ note = insert(:note)
+ uuid = String.split(note.data["id"], "/") |> List.last()
+
+ conn =
+ conn
+ |> put_req_header("accept", "application/json")
+ |> get("/objects/#{uuid}")
+
+ assert json_response(conn, 200) == ObjectView.render("object.json", %{object: note})
+ end
+
+ test "it returns a json representation of the object with accept application/activity+json", %{conn: conn} do
note = insert(:note)
uuid = String.split(note.data["id"], "/") |> List.last()
@@ -68,6 +106,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 200) == ObjectView.render("object.json", %{object: note})
end
+ test "it returns a json representation of the object with accept application/ld+json", %{conn: conn} do
+ note = insert(:note)
+ uuid = String.split(note.data["id"], "/") |> List.last()
+
+ conn =
+ conn
+ |> put_req_header("accept", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
+ |> get("/objects/#{uuid}")
+
+ assert json_response(conn, 200) == ObjectView.render("object.json", %{object: note})
+ end
+
test "it returns 404 for non-public messages", %{conn: conn} do
note = insert(:direct_note)
uuid = String.split(note.data["id"], "/") |> List.last()
--
cgit v1.2.3
From e95dbecf3e3c831a3bff201b06a5e901c401ae89 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Wed, 20 Feb 2019 20:49:10 +0000
Subject: tests: fix formatting
---
.../activity_pub/activity_pub_controller_test.exs | 33 ++++++++++++++++------
1 file changed, 25 insertions(+), 8 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index aa2ca4eb8..a809c15b1 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -41,7 +41,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
describe "/users/:nickname" do
- test "it returns a json representation of the user with accept application/json", %{conn: conn} do
+ test "it returns a json representation of the user with accept application/json", %{
+ conn: conn
+ } do
user = insert(:user)
conn =
@@ -54,7 +56,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
end
- test "it returns a json representation of the user with accept application/activity+json", %{conn: conn} do
+ test "it returns a json representation of the user with accept application/activity+json", %{
+ conn: conn
+ } do
user = insert(:user)
conn =
@@ -67,12 +71,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
end
- test "it returns a json representation of the user with accept application/ld+json", %{conn: conn} do
+ test "it returns a json representation of the user with accept application/ld+json", %{
+ conn: conn
+ } do
user = insert(:user)
conn =
conn
- |> put_req_header("accept", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
+ |> put_req_header(
+ "accept",
+ "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
+ )
|> get("/users/#{user.nickname}")
user = Repo.get(User, user.id)
@@ -82,7 +91,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
describe "/object/:uuid" do
- test "it returns a json representation of the object with accept application/json", %{conn: conn} do
+ test "it returns a json representation of the object with accept application/json", %{
+ conn: conn
+ } do
note = insert(:note)
uuid = String.split(note.data["id"], "/") |> List.last()
@@ -94,7 +105,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 200) == ObjectView.render("object.json", %{object: note})
end
- test "it returns a json representation of the object with accept application/activity+json", %{conn: conn} do
+ test "it returns a json representation of the object with accept application/activity+json",
+ %{conn: conn} do
note = insert(:note)
uuid = String.split(note.data["id"], "/") |> List.last()
@@ -106,13 +118,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 200) == ObjectView.render("object.json", %{object: note})
end
- test "it returns a json representation of the object with accept application/ld+json", %{conn: conn} do
+ test "it returns a json representation of the object with accept application/ld+json", %{
+ conn: conn
+ } do
note = insert(:note)
uuid = String.split(note.data["id"], "/") |> List.last()
conn =
conn
- |> put_req_header("accept", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
+ |> put_req_header(
+ "accept",
+ "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
+ )
|> get("/objects/#{uuid}")
assert json_response(conn, 200) == ObjectView.render("object.json", %{object: note})
--
cgit v1.2.3
From 7c722c08f5fa44fc5d1baf0eb0fabb32942988a2 Mon Sep 17 00:00:00 2001
From: KZ
Date: Fri, 22 Feb 2019 04:37:48 +0000
Subject: Fix: Fixing an outbox related bug when local user activity is empty
---
test/web/activity_pub/activity_pub_controller_test.exs | 12 ++++++++++++
1 file changed, 12 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index a809c15b1..6bd4493f5 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -304,6 +304,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
describe "/users/:nickname/outbox" do
+ test "it will not bomb when there is no activity", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/users/#{user.nickname}/outbox")
+
+ result = json_response(conn, 200)
+ assert user.ap_id <> "/outbox" == result["id"]
+ end
+
test "it returns a note activity in a collection", %{conn: conn} do
note_activity = insert(:note_activity)
user = User.get_cached_by_ap_id(note_activity.data["actor"])
--
cgit v1.2.3
From 62296f5a251e376bed5b234a66b20226dbd58419 Mon Sep 17 00:00:00 2001
From: lain
Date: Fri, 22 Feb 2019 12:02:51 +0100
Subject: Fix private post card handling.
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 12 ++++++++++++
1 file changed, 12 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 3dfbc8669..b52c2b805 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1744,6 +1744,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
}
}
+ # works with private posts
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "http://example.com/ogp", "visibility" => "direct"})
+
+ response_two =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/statuses/#{activity.id}/card")
+ |> json_response(200)
+
+ assert response_two == response
+
Pleroma.Config.put([:rich_media, :enabled], false)
end
end
--
cgit v1.2.3
From 9e0686efa61940fe78736c3e2669acb7233d8ada Mon Sep 17 00:00:00 2001
From: lain
Date: Fri, 22 Feb 2019 13:29:52 +0100
Subject: Move visibility into own module.
---
test/web/activity_pub/visibilty_test.exs | 98 ++++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+)
create mode 100644 test/web/activity_pub/visibilty_test.exs
(limited to 'test')
diff --git a/test/web/activity_pub/visibilty_test.exs b/test/web/activity_pub/visibilty_test.exs
new file mode 100644
index 000000000..1172b7455
--- /dev/null
+++ b/test/web/activity_pub/visibilty_test.exs
@@ -0,0 +1,98 @@
+defmodule Pleroma.Web.ActivityPub.VisibilityTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.ActivityPub.Visibility
+ import Pleroma.Factory
+
+ setup do
+ user = insert(:user)
+ mentioned = insert(:user)
+ following = insert(:user)
+ unrelated = insert(:user)
+ {:ok, following} = Pleroma.User.follow(following, user)
+
+ {:ok, public} =
+ CommonAPI.post(user, %{"status" => "@#{mentioned.nickname}", "visibility" => "public"})
+
+ {:ok, private} =
+ CommonAPI.post(user, %{"status" => "@#{mentioned.nickname}", "visibility" => "private"})
+
+ {:ok, direct} =
+ CommonAPI.post(user, %{"status" => "@#{mentioned.nickname}", "visibility" => "direct"})
+
+ {:ok, unlisted} =
+ CommonAPI.post(user, %{"status" => "@#{mentioned.nickname}", "visibility" => "unlisted"})
+
+ %{
+ public: public,
+ private: private,
+ direct: direct,
+ unlisted: unlisted,
+ user: user,
+ mentioned: mentioned,
+ following: following,
+ unrelated: unrelated
+ }
+ end
+
+ test "is_direct?", %{public: public, private: private, direct: direct, unlisted: unlisted} do
+ assert Visibility.is_direct?(direct)
+ refute Visibility.is_direct?(public)
+ refute Visibility.is_direct?(private)
+ refute Visibility.is_direct?(unlisted)
+ end
+
+ test "is_public?", %{public: public, private: private, direct: direct, unlisted: unlisted} do
+ refute Visibility.is_public?(direct)
+ assert Visibility.is_public?(public)
+ refute Visibility.is_public?(private)
+ assert Visibility.is_public?(unlisted)
+ end
+
+ test "is_private?", %{public: public, private: private, direct: direct, unlisted: unlisted} do
+ refute Visibility.is_private?(direct)
+ refute Visibility.is_private?(public)
+ assert Visibility.is_private?(private)
+ refute Visibility.is_private?(unlisted)
+ end
+
+ test "visible_for_user?", %{
+ public: public,
+ private: private,
+ direct: direct,
+ unlisted: unlisted,
+ user: user,
+ mentioned: mentioned,
+ following: following,
+ unrelated: unrelated
+ } do
+ # All visible to author
+
+ assert Visibility.visible_for_user?(public, user)
+ assert Visibility.visible_for_user?(private, user)
+ assert Visibility.visible_for_user?(unlisted, user)
+ assert Visibility.visible_for_user?(direct, user)
+
+ # All visible to a mentioned user
+
+ assert Visibility.visible_for_user?(public, mentioned)
+ assert Visibility.visible_for_user?(private, mentioned)
+ assert Visibility.visible_for_user?(unlisted, mentioned)
+ assert Visibility.visible_for_user?(direct, mentioned)
+
+ # DM not visible for just follower
+
+ assert Visibility.visible_for_user?(public, following)
+ assert Visibility.visible_for_user?(private, following)
+ assert Visibility.visible_for_user?(unlisted, following)
+ refute Visibility.visible_for_user?(direct, following)
+
+ # Public and unlisted visible for unrelated user
+
+ assert Visibility.visible_for_user?(public, unrelated)
+ assert Visibility.visible_for_user?(unlisted, unrelated)
+ refute Visibility.visible_for_user?(private, unrelated)
+ refute Visibility.visible_for_user?(direct, unrelated)
+ end
+end
--
cgit v1.2.3
From c3ac9424d2affe87df82c14dc243f507fa639343 Mon Sep 17 00:00:00 2001
From: Egor
Date: Tue, 26 Feb 2019 23:32:26 +0000
Subject: AutoLinker
---
test/formatter_test.exs | 114 +++++++++-----------------
test/web/common_api/common_api_utils_test.exs | 32 ++++++--
2 files changed, 65 insertions(+), 81 deletions(-)
(limited to 'test')
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index f14077d25..7d8864bf4 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -21,22 +21,16 @@ defmodule Pleroma.FormatterTest do
expected_text =
"I love #cofe and #2hu "
- tags = Formatter.parse_tags(text)
-
- assert expected_text ==
- Formatter.add_hashtag_links({[], text}, tags) |> Formatter.finalize()
+ assert {^expected_text, [], _tags} = Formatter.linkify(text)
end
test "does not turn html characters to tags" do
- text = "Fact #3: pleroma does what mastodon't"
+ text = "#fact_3: pleroma does what mastodon't"
expected_text =
- "Fact #3 : pleroma does what mastodon't"
-
- tags = Formatter.parse_tags(text)
+ "#fact_3 : pleroma does what mastodon't"
- assert expected_text ==
- Formatter.add_hashtag_links({[], text}, tags) |> Formatter.finalize()
+ assert {^expected_text, [], _tags} = Formatter.linkify(text)
end
end
@@ -47,79 +41,79 @@ defmodule Pleroma.FormatterTest do
expected =
"Hey, check out https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla ."
- assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
+ assert {^expected, [], []} = Formatter.linkify(text)
text = "https://mastodon.social/@lambadalambda"
expected =
"https://mastodon.social/@lambadalambda "
- assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
+ assert {^expected, [], []} = Formatter.linkify(text)
text = "https://mastodon.social:4000/@lambadalambda"
expected =
"https://mastodon.social:4000/@lambadalambda "
- assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
+ assert {^expected, [], []} = Formatter.linkify(text)
text = "@lambadalambda"
expected = "@lambadalambda"
- assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
+ assert {^expected, [], []} = Formatter.linkify(text)
text = "http://www.cs.vu.nl/~ast/intel/"
expected = "http://www.cs.vu.nl/~ast/intel/ "
- assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
+ assert {^expected, [], []} = Formatter.linkify(text)
text = "https://forum.zdoom.org/viewtopic.php?f=44&t=57087"
expected =
"https://forum.zdoom.org/viewtopic.php?f=44&t=57087 "
- assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
+ assert {^expected, [], []} = Formatter.linkify(text)
text = "https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul"
expected =
"https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul "
- assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
+ assert {^expected, [], []} = Formatter.linkify(text)
text = "https://www.google.co.jp/search?q=Nasim+Aghdam"
expected =
"https://www.google.co.jp/search?q=Nasim+Aghdam "
- assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
+ assert {^expected, [], []} = Formatter.linkify(text)
text = "https://en.wikipedia.org/wiki/Duff's_device"
expected =
"https://en.wikipedia.org/wiki/Duff's_device "
- assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
+ assert {^expected, [], []} = Formatter.linkify(text)
text = "https://pleroma.com https://pleroma.com/sucks"
expected =
"https://pleroma.com https://pleroma.com/sucks "
- assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
+ assert {^expected, [], []} = Formatter.linkify(text)
text = "xmpp:contact@hacktivis.me"
expected = "xmpp:contact@hacktivis.me "
- assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
+ assert {^expected, [], []} = Formatter.linkify(text)
text =
"magnet:?xt=urn:btih:7ec9d298e91d6e4394d1379caf073c77ff3e3136&tr=udp%3A%2F%2Fopentor.org%3A2710&tr=udp%3A%2F%2Ftracker.blackunicorn.xyz%3A6969&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com"
expected = "#{text} "
- assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
+ assert {^expected, [], []} = Formatter.linkify(text)
end
end
@@ -136,12 +130,9 @@ defmodule Pleroma.FormatterTest do
archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
- mentions = Pleroma.Formatter.parse_mentions(text)
-
- {subs, text} = Formatter.add_user_links({[], text}, mentions)
+ {text, mentions, []} = Formatter.linkify(text)
- assert length(subs) == 3
- Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
+ assert length(mentions) == 3
expected_text =
"@archaeme "
- assert expected_text == Formatter.finalize({subs, text})
+ assert expected_text == text
end
test "gives a replacement for user links when the user is using Osada" do
@@ -160,48 +151,35 @@ defmodule Pleroma.FormatterTest do
text = "@mike@osada.macgirvin.com test"
- mentions = Formatter.parse_mentions(text)
+ {text, mentions, []} = Formatter.linkify(text)
- {subs, text} = Formatter.add_user_links({[], text}, mentions)
-
- assert length(subs) == 1
- Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
+ assert length(mentions) == 1
expected_text =
"@mike test"
- assert expected_text == Formatter.finalize({subs, text})
+ assert expected_text == text
end
test "gives a replacement for single-character local nicknames" do
text = "@o hi"
o = insert(:user, %{nickname: "o"})
- mentions = Formatter.parse_mentions(text)
-
- {subs, text} = Formatter.add_user_links({[], text}, mentions)
+ {text, mentions, []} = Formatter.linkify(text)
- assert length(subs) == 1
- Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
+ assert length(mentions) == 1
expected_text =
"@o hi"
- assert expected_text == Formatter.finalize({subs, text})
+ assert expected_text == text
end
test "does not give a replacement for single-character local nicknames who don't exist" do
text = "@a hi"
- mentions = Formatter.parse_mentions(text)
-
- {subs, text} = Formatter.add_user_links({[], text}, mentions)
-
- assert Enum.empty?(subs)
- Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
-
expected_text = "@a hi"
- assert expected_text == Formatter.finalize({subs, text})
+ assert {^expected_text, [] = _mentions, [] = _tags} = Formatter.linkify(text)
end
end
@@ -209,14 +187,14 @@ defmodule Pleroma.FormatterTest do
test "parses tags in the text" do
text = "Here's a #Test. Maybe these are #working or not. What about #漢字? And #は。"
- expected = [
+ expected_tags = [
{"#Test", "test"},
{"#working", "working"},
- {"#漢字", "漢字"},
- {"#は", "は"}
+ {"#は", "は"},
+ {"#漢字", "漢字"}
]
- assert Formatter.parse_tags(text) == expected
+ assert {_text, [], ^expected_tags} = Formatter.linkify(text)
end
end
@@ -230,15 +208,15 @@ defmodule Pleroma.FormatterTest do
archaeme = insert(:user, %{nickname: "archaeme"})
archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
- expected_result = [
- {"@gsimg", gsimg},
+ expected_mentions = [
{"@archaeme", archaeme},
{"@archaeme@archae.me", archaeme_remote},
- {"@o", o},
- {"@jimm", jimm}
+ {"@gsimg", gsimg},
+ {"@jimm", jimm},
+ {"@o", o}
]
- assert Formatter.parse_mentions(text) == expected_result
+ assert {_text, ^expected_mentions, []} = Formatter.linkify(text)
end
test "it adds cool emoji" do
@@ -281,22 +259,10 @@ defmodule Pleroma.FormatterTest do
assert Formatter.get_emoji(text) == []
end
- describe "/mentions_escape" do
- test "it returns text with escaped mention names" do
- text = """
- @a_breakin_glass@cybre.space
- (also, little voice inside my head thinking "maybe this will encourage people
- pronouncing it properly instead of saying _raKEWdo_ ")
- """
-
- escape_text = """
- @a\\_breakin\\_glass@cybre\\.space
- (also, little voice inside my head thinking \"maybe this will encourage people
- pronouncing it properly instead of saying _raKEWdo_ \")
- """
-
- mentions = [{"@a_breakin_glass@cybre.space", %{}}]
- assert Formatter.mentions_escape(text, mentions) == escape_text
- end
+ test "it escapes HTML in plain text" do
+ text = "hello & world google.com/?a=b&c=d \n http://test.com/?a=b&c=d 1"
+ expected = "hello & world google.com/?a=b&c=d \n http://test.com/?a=b&c=d 1"
+
+ assert Formatter.html_escape(text, "text/plain") == expected
end
end
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index faed6b685..dc7b4c229 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -57,19 +57,19 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert expected == Utils.emoji_from_profile(user)
end
- describe "format_input/4" do
+ describe "format_input/3" do
test "works for bare text/plain" do
text = "hello world!"
expected = "hello world!"
- output = Utils.format_input(text, [], [], "text/plain")
+ {output, [], []} = Utils.format_input(text, "text/plain")
assert output == expected
text = "hello world!\n\nsecond paragraph!"
expected = "hello world! second paragraph!"
- output = Utils.format_input(text, [], [], "text/plain")
+ {output, [], []} = Utils.format_input(text, "text/plain")
assert output == expected
end
@@ -78,14 +78,14 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
text = "hello world!
"
expected = "hello world!
"
- output = Utils.format_input(text, [], [], "text/html")
+ {output, [], []} = Utils.format_input(text, "text/html")
assert output == expected
text = "hello world!
\n\nsecond paragraph
"
expected = "hello world!
\n\nsecond paragraph
"
- output = Utils.format_input(text, [], [], "text/html")
+ {output, [], []} = Utils.format_input(text, "text/html")
assert output == expected
end
@@ -94,14 +94,32 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
text = "**hello world**"
expected = "hello world
\n"
- output = Utils.format_input(text, [], [], "text/markdown")
+ {output, [], []} = Utils.format_input(text, "text/markdown")
assert output == expected
text = "**hello world**\n\n*another paragraph*"
expected = "hello world
\nanother paragraph
\n"
- output = Utils.format_input(text, [], [], "text/markdown")
+ {output, [], []} = Utils.format_input(text, "text/markdown")
+
+ assert output == expected
+ end
+
+ test "works for text/markdown with mentions" do
+ {:ok, user} =
+ UserBuilder.insert(%{nickname: "user__test", ap_id: "http://foo.com/user__test"})
+
+ text = "**hello world**\n\n*another @user__test and @user__test google.com paragraph*"
+
+ expected =
+ "hello world
\nanother @user__test and @user__test google.com paragraph
\n"
+
+ {output, _, _} = Utils.format_input(text, "text/markdown")
assert output == expected
end
--
cgit v1.2.3
From ed7fd6b47e93e0874e3d79f124b71693e43dbb2c Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Wed, 27 Feb 2019 03:08:03 +0300
Subject: Add missing docs and tests
---
test/web/admin_api/admin_api_controller_test.exs | 35 ++++++++++++++++++++++++
1 file changed, 35 insertions(+)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 9fbaaba39..f6ae16844 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -330,4 +330,39 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert conn.status == 200
end
+
+ test "GET /api/pleroma/admin/users" do
+ admin = insert(:user, info: %{is_admin: true})
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> get("/api/pleroma/admin/users")
+
+ assert json_response(conn, 200) == [
+ %{
+ "deactivated" => user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname
+ }
+ ]
+ end
+
+ test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do
+ admin = insert(:user, info: %{is_admin: true})
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> patch("/api/pleroma/admin/users/#{user.nickname}/toggle_activation")
+
+ assert json_response(conn, 200) ==
+ %{
+ "deactivated" => !user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname
+ }
+ end
end
--
cgit v1.2.3
From 5d961d536cd190c8201d53624680a6f3384ffd9b Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 27 Feb 2019 15:40:30 +0700
Subject: fix formatter
---
test/web/common_api/common_api_utils_test.exs | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index dc7b4c229..684f2a23f 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -104,6 +104,18 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{output, [], []} = Utils.format_input(text, "text/markdown")
assert output == expected
+
+ text = """
+ > cool quote
+
+ by someone
+ """
+
+ expected = "cool quote
\n \nby someone
\n"
+
+ {output, [], []} = Utils.format_input(text, "text/markdown")
+
+ assert output == expected
end
test "works for text/markdown with mentions" do
@@ -113,11 +125,11 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
text = "**hello world**\n\n*another @user__test and @user__test google.com paragraph*"
expected =
- "hello world
\nanother @user__test and @user__test google.com paragraph
\n"
+ }\" class=\"u-url mention\" href=\"http://foo.com/user__test\">@user__test google.com paragraph\n"
{output, _, _} = Utils.format_input(text, "text/markdown")
--
cgit v1.2.3
From 153664096255208055ae2e0b31ea20238ad540b2 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Wed, 27 Feb 2019 13:01:10 +0000
Subject: mastodon api: embed relationship card under account card for Pleroma
FE convenience
---
test/web/mastodon_api/account_view_test.exs | 66 ++++++++++++++++++++++++++++-
1 file changed, 64 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index f8cd68173..6be66ef63 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -63,7 +63,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
confirmation_pending: false,
tags: [],
is_admin: false,
- is_moderator: false
+ is_moderator: false,
+ relationship: %{}
}
}
@@ -106,7 +107,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
confirmation_pending: false,
tags: [],
is_admin: false,
- is_moderator: false
+ is_moderator: false,
+ relationship: %{}
}
}
@@ -148,4 +150,64 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
assert expected == AccountView.render("relationship.json", %{user: user, target: other_user})
end
+
+ test "represent an embedded relationship" do
+ user =
+ insert(:user, %{
+ info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
+ nickname: "shp@shitposter.club",
+ inserted_at: ~N[2017-08-15 15:47:06.597036]
+ })
+
+ other_user = insert(:user)
+
+ {:ok, other_user} = User.follow(other_user, user)
+ {:ok, other_user} = User.block(other_user, user)
+
+ expected = %{
+ id: to_string(user.id),
+ username: "shp",
+ acct: user.nickname,
+ display_name: user.name,
+ locked: false,
+ created_at: "2017-08-15T15:47:06.000Z",
+ followers_count: 3,
+ following_count: 0,
+ statuses_count: 5,
+ note: user.bio,
+ url: user.ap_id,
+ avatar: "http://localhost:4001/images/avi.png",
+ avatar_static: "http://localhost:4001/images/avi.png",
+ header: "http://localhost:4001/images/banner.png",
+ header_static: "http://localhost:4001/images/banner.png",
+ emojis: [],
+ fields: [],
+ bot: true,
+ source: %{
+ note: "",
+ privacy: "public",
+ sensitive: false
+ },
+ pleroma: %{
+ confirmation_pending: false,
+ tags: [],
+ is_admin: false,
+ is_moderator: false,
+ relationship: %{
+ id: to_string(user.id),
+ following: false,
+ followed_by: false,
+ blocking: true,
+ muting: false,
+ muting_notifications: false,
+ requested: false,
+ domain_blocking: false,
+ showing_reblogs: false,
+ endorsed: false
+ }
+ }
+ }
+
+ assert expected == AccountView.render("account.json", %{user: user, for: other_user})
+ end
end
--
cgit v1.2.3
From 8d8cb08f94490299bfc7fe97381a34e4a7a095a9 Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 27 Feb 2019 14:51:07 +0100
Subject: Add follow request test.
---
test/user_test.exs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 0b1c39ecf..cbe4693fc 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -50,6 +50,20 @@ defmodule Pleroma.UserTest do
assert expected_followers_collection == User.ap_followers(user)
end
+ test "returns all pending follow requests" do
+ unlocked = insert(:user)
+ locked = insert(:user, %{info: %{locked: true}})
+ follower = insert(:user)
+
+ Pleroma.Web.TwitterAPI.TwitterAPI.follow(follower, %{"user_id" => unlocked.id})
+ Pleroma.Web.TwitterAPI.TwitterAPI.follow(follower, %{"user_id" => locked.id})
+
+ assert {:ok, []} = User.get_follow_requests(unlocked)
+ assert {:ok, [activity]} = User.get_follow_requests(locked)
+
+ assert activity
+ end
+
test "follow_all follows mutliple users" do
user = insert(:user)
followed_zero = insert(:user)
--
cgit v1.2.3
From c4235f96bde49def1fb6927ba79a49a0f75cd60a Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 27 Feb 2019 16:37:42 +0100
Subject: Add `with_muted` param.
---
test/web/activity_pub/activity_pub_test.exs | 7 +++++++
1 file changed, 7 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 11262c523..ac3a565de 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -291,6 +291,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert Enum.member?(activities, activity_three)
refute Enum.member?(activities, activity_one)
+ # Calling with 'with_muted' will deliver muted activities, too.
+ activities = ActivityPub.fetch_activities([], %{"muting_user" => user, "with_muted" => true})
+
+ assert Enum.member?(activities, activity_two)
+ assert Enum.member?(activities, activity_three)
+ assert Enum.member?(activities, activity_one)
+
{:ok, user} = User.unmute(user, %User{ap_id: activity_one.data["actor"]})
activities = ActivityPub.fetch_activities([], %{"muting_user" => user})
--
cgit v1.2.3
From c1ae495878cc95d09a051cc56e2bf7dc7ed0a032 Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 27 Feb 2019 16:46:47 +0100
Subject: Add user muted status info to MastodonAPI.
---
test/web/mastodon_api/status_view_test.exs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 3412a6be2..351dbf673 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -126,6 +126,22 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
assert status == expected
end
+ test "tells if the message is muted for some reason" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, user} = User.mute(user, other_user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
+ status = StatusView.render("status.json", %{activity: activity})
+
+ assert status.muted == false
+
+ status = StatusView.render("status.json", %{activity: activity, for: user})
+
+ assert status.muted == true
+ end
+
test "a reply" do
note = insert(:note_activity)
user = insert(:user)
--
cgit v1.2.3
From 9ade1242c20acae5d27785deb833b453628b12ee Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 27 Feb 2019 16:52:03 +0100
Subject: Add user muted status info to twitterapi.
---
test/web/twitter_api/views/activity_view_test.exs | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 4f854ecaa..0a5384f34 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -56,6 +56,22 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
assert result["user"]["id"] == user.id
end
+ test "tells if the message is muted for some reason" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, user} = User.mute(user, other_user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
+ status = ActivityView.render("activity.json", %{activity: activity})
+
+ assert status["muted"] == false
+
+ status = ActivityView.render("activity.json", %{activity: activity, for: user})
+
+ assert status["muted"] == true
+ end
+
test "a create activity with a html status" do
text = """
#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg
@@ -149,7 +165,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"uri" => activity.data["object"]["id"],
"user" => UserView.render("show.json", %{user: user}),
"visibility" => "direct",
- "card" => nil
+ "card" => nil,
+ "muted" => false
}
assert result == expected
--
cgit v1.2.3
From bbbdbec4fd8f14aa039d7f4a42215544cd6e4932 Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 27 Feb 2019 17:24:51 +0100
Subject: Remove parts of the old activity view.
Not used anymore.
---
.../representers/activity_representer_test.exs | 43 +---------------------
1 file changed, 1 insertion(+), 42 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index 365c7f659..0e554623c 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -13,36 +13,6 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
alias Pleroma.Web.TwitterAPI.UserView
import Pleroma.Factory
- test "an announce activity" do
- user = insert(:user)
- note_activity = insert(:note_activity)
- activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"])
- object = Object.get_by_ap_id(note_activity.data["object"]["id"])
-
- {:ok, announce_activity, _object} = ActivityPub.announce(user, object)
- note_activity = Activity.get_by_ap_id(note_activity.data["id"])
-
- status =
- ActivityRepresenter.to_map(announce_activity, %{
- users: [user, activity_actor],
- announced_activity: note_activity,
- for: user
- })
-
- assert status["id"] == announce_activity.id
- assert status["user"] == UserView.render("show.json", %{user: user, for: user})
-
- retweeted_status =
- ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
-
- assert retweeted_status["repeated"] == true
- assert retweeted_status["id"] == note_activity.id
- assert status["statusnet_conversation_id"] == retweeted_status["statusnet_conversation_id"]
-
- assert status["retweeted_status"] == retweeted_status
- assert status["activity_type"] == "repeat"
- end
-
test "a like activity" do
user = insert(:user)
note_activity = insert(:note_activity)
@@ -168,6 +138,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
"uri" => activity.data["object"]["id"],
"visibility" => "direct",
"card" => nil,
+ "muted" => false,
"summary" => "2hu :2hu:",
"summary_html" =>
"2hu "
@@ -180,18 +151,6 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
}) == expected_status
end
- test "an undo for a follow" do
- follower = insert(:user)
- followed = insert(:user)
-
- {:ok, _follow} = ActivityPub.follow(follower, followed)
- {:ok, unfollow} = ActivityPub.unfollow(follower, followed)
-
- map = ActivityRepresenter.to_map(unfollow, %{user: follower})
- assert map["is_post_verb"] == false
- assert map["activity_type"] == "undo"
- end
-
test "a delete activity" do
object = insert(:note)
user = User.get_by_ap_id(object.data["actor"])
--
cgit v1.2.3
From 2883f75a3a25599c6217460133578cddcd34ebb4 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Thu, 28 Feb 2019 01:11:56 +0300
Subject: Add pagination to users admin API
---
test/web/admin_api/admin_api_controller_test.exs | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index f6ae16844..1b0a2f5be 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -338,15 +338,19 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn =
build_conn()
|> assign(:user, admin)
- |> get("/api/pleroma/admin/users")
-
- assert json_response(conn, 200) == [
- %{
- "deactivated" => user.info.deactivated,
- "id" => user.id,
- "nickname" => user.nickname
- }
- ]
+ |> get("/api/pleroma/admin/users?page=1")
+
+ assert json_response(conn, 200) == %{
+ "count" => 1,
+ "page_size" => 50,
+ "users" => [
+ %{
+ "deactivated" => user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname
+ }
+ ]
+ }
end
test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do
--
cgit v1.2.3
From 6b11011039dca5090c3a7b7b2a01f32b666be380 Mon Sep 17 00:00:00 2001
From: eugenijm
Date: Thu, 28 Feb 2019 08:31:33 +0300
Subject: Added deactivated to the user view
---
test/web/twitter_api/views/user_view_test.exs | 7 +++++++
1 file changed, 7 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 95e52ca46..114f24a1c 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -239,6 +239,13 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
assert represented["role"] == nil
end
+ test "A regular user for the admin", %{user: user} do
+ admin = insert(:user, %{info: %{is_admin: true}})
+ represented = UserView.render("show.json", %{user: user, for: admin})
+
+ assert represented["pleroma"]["deactivated"] == false
+ end
+
test "A blocked user for the blocker" do
user = insert(:user)
blocker = insert(:user)
--
cgit v1.2.3
From 70e82a3465ee10004d0ae347934524e779bd778a Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Thu, 28 Feb 2019 17:54:02 +0300
Subject: Add test for the second page
---
test/web/admin_api/admin_api_controller_test.exs | 56 ++++++++++++++++--------
1 file changed, 37 insertions(+), 19 deletions(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 1b0a2f5be..893387ef5 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -331,26 +331,44 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert conn.status == 200
end
- test "GET /api/pleroma/admin/users" do
- admin = insert(:user, info: %{is_admin: true})
- user = insert(:user)
+ describe "GET /api/pleroma/admin/users" do
+ test "renders users array for the first page" do
+ admin = insert(:user, info: %{is_admin: true})
+ user = insert(:user)
- conn =
- build_conn()
- |> assign(:user, admin)
- |> get("/api/pleroma/admin/users?page=1")
-
- assert json_response(conn, 200) == %{
- "count" => 1,
- "page_size" => 50,
- "users" => [
- %{
- "deactivated" => user.info.deactivated,
- "id" => user.id,
- "nickname" => user.nickname
- }
- ]
- }
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> get("/api/pleroma/admin/users?page=1")
+
+ assert json_response(conn, 200) == %{
+ "count" => 1,
+ "page_size" => 50,
+ "users" => [
+ %{
+ "deactivated" => user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname
+ }
+ ]
+ }
+ end
+
+ test "renders empty array for the second page" do
+ admin = insert(:user, info: %{is_admin: true})
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> get("/api/pleroma/admin/users?page=2")
+
+ assert json_response(conn, 200) == %{
+ "count" => 1,
+ "page_size" => 50,
+ "users" => []
+ }
+ end
end
test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do
--
cgit v1.2.3
From 46f29b9da1cfdcc2ab14616f999f061fa0c87ddc Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Thu, 28 Feb 2019 19:04:47 +0300
Subject: Add search users endpoint
---
test/web/admin_api/admin_api_controller_test.exs | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 893387ef5..14625af32 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -356,7 +356,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
test "renders empty array for the second page" do
admin = insert(:user, info: %{is_admin: true})
- user = insert(:user)
+ insert(:user)
conn =
build_conn()
@@ -387,4 +387,26 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"nickname" => user.nickname
}
end
+
+ test "GET /api/pleroma/admin/users/search" do
+ admin = insert(:user, info: %{is_admin: true})
+ user = insert(:user, nickname: "bob")
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> get("/api/pleroma/admin/users/search?query=bo")
+
+ assert json_response(conn, 200) == %{
+ "count" => 1,
+ "page_size" => 50,
+ "users" => [
+ %{
+ "deactivated" => user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname
+ }
+ ]
+ }
+ end
end
--
cgit v1.2.3
From 1341ee650ecde656f385454264f43b21051e86f2 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Fri, 1 Mar 2019 09:37:29 +0300
Subject: [#675] Do not show DMs in mentions timeline
---
test/web/activity_pub/activity_pub_test.exs | 8 ++++++++
test/web/twitter_api/twitter_api_controller_test.exs | 19 ++++++++++++++++++-
2 files changed, 26 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 11262c523..17f48797b 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -55,6 +55,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
ActivityPub.fetch_activities([], %{:visibility => "public", "actor_id" => user.ap_id})
assert activities == [public_activity]
+
+ activities =
+ ActivityPub.fetch_activities([], %{
+ :visibility => ~w[private public],
+ "actor_id" => user.ap_id
+ })
+
+ assert activities == [public_activity, private_activity]
end
end
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 05a832967..ed5683779 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -427,7 +427,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
test "with credentials", %{conn: conn, user: current_user} do
{:ok, activity} =
- ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: current_user})
+ ActivityBuilder.insert(
+ %{"to" => [current_user.ap_id, "https://www.w3.org/ns/activitystreams#Public"]},
+ %{user: current_user}
+ )
conn =
conn
@@ -445,6 +448,20 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
mentioned: [current_user]
})
end
+
+ test "does not show DMs in mentions timeline", %{conn: conn, user: current_user} do
+ {:ok, _activity} =
+ ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: current_user})
+
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> get("/api/statuses/mentions.json")
+
+ response = json_response(conn, 200)
+
+ assert length(response) == 0
+ end
end
describe "GET /api/qvitter/statuses/notifications.json" do
--
cgit v1.2.3
From 9c6abec4d8b2487edeb124aa197a5dd6d771e345 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Fri, 1 Mar 2019 15:48:04 +0300
Subject: use commonapi.post instead of activitybulder
---
test/web/twitter_api/twitter_api_controller_test.exs | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index ed5683779..7125d85ab 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -427,10 +427,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
test "with credentials", %{conn: conn, user: current_user} do
{:ok, activity} =
- ActivityBuilder.insert(
- %{"to" => [current_user.ap_id, "https://www.w3.org/ns/activitystreams#Public"]},
- %{user: current_user}
- )
+ CommonAPI.post(current_user, %{
+ "status" => "why is tenshi eating a corndog so cute?",
+ "visibility" => "public"
+ })
conn =
conn
@@ -451,7 +451,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
test "does not show DMs in mentions timeline", %{conn: conn, user: current_user} do
{:ok, _activity} =
- ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: current_user})
+ CommonAPI.post(current_user, %{
+ "status" => "Have you guys ever seen how cute tenshi eating a corndog is?",
+ "visibility" => "direct"
+ })
conn =
conn
--
cgit v1.2.3
From 5b08b470f69738f4528455a58fefe3a8d4acae02 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Fri, 1 Mar 2019 20:13:02 +0300
Subject: Add "local" params to users search
---
test/web/admin_api/admin_api_controller_test.exs | 64 +++++++++++++++++-------
1 file changed, 45 insertions(+), 19 deletions(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 14625af32..460f2a6bd 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -388,25 +388,51 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
}
end
- test "GET /api/pleroma/admin/users/search" do
- admin = insert(:user, info: %{is_admin: true})
- user = insert(:user, nickname: "bob")
+ describe "GET /api/pleroma/admin/users/search" do
+ test "regular search" do
+ admin = insert(:user, info: %{is_admin: true})
+ user = insert(:user, nickname: "bob")
- conn =
- build_conn()
- |> assign(:user, admin)
- |> get("/api/pleroma/admin/users/search?query=bo")
-
- assert json_response(conn, 200) == %{
- "count" => 1,
- "page_size" => 50,
- "users" => [
- %{
- "deactivated" => user.info.deactivated,
- "id" => user.id,
- "nickname" => user.nickname
- }
- ]
- }
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> get("/api/pleroma/admin/users/search?query=bo")
+
+ assert json_response(conn, 200) == %{
+ "count" => 1,
+ "page_size" => 50,
+ "users" => [
+ %{
+ "deactivated" => user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname
+ }
+ ]
+ }
+ end
+
+ test "only local users" do
+ admin = insert(:user, info: %{is_admin: true})
+ user = insert(:user, nickname: "bob")
+
+ insert(:user, nickname: "bobb", local: false)
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> get("/api/pleroma/admin/users/search?query=bo&local=true")
+
+ assert json_response(conn, 200) == %{
+ "count" => 1,
+ "page_size" => 50,
+ "users" => [
+ %{
+ "deactivated" => user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname
+ }
+ ]
+ }
+ end
end
end
--
cgit v1.2.3
From f1a4c3163b18692a7a8bd9874a45e75a6535dd5a Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Fri, 1 Mar 2019 20:23:03 +0300
Subject: Show current user in users list as well
---
test/web/admin_api/admin_api_controller_test.exs | 45 +++++++++++++-----------
1 file changed, 25 insertions(+), 20 deletions(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 460f2a6bd..0679f5dfe 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -345,6 +345,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"count" => 1,
"page_size" => 50,
"users" => [
+ %{
+ "deactivated" => admin.info.deactivated,
+ "id" => admin.id,
+ "nickname" => admin.nickname
+ },
%{
"deactivated" => user.info.deactivated,
"id" => user.id,
@@ -399,16 +404,16 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|> get("/api/pleroma/admin/users/search?query=bo")
assert json_response(conn, 200) == %{
- "count" => 1,
- "page_size" => 50,
- "users" => [
- %{
- "deactivated" => user.info.deactivated,
- "id" => user.id,
- "nickname" => user.nickname
- }
- ]
- }
+ "count" => 1,
+ "page_size" => 50,
+ "users" => [
+ %{
+ "deactivated" => user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname
+ }
+ ]
+ }
end
test "only local users" do
@@ -423,16 +428,16 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|> get("/api/pleroma/admin/users/search?query=bo&local=true")
assert json_response(conn, 200) == %{
- "count" => 1,
- "page_size" => 50,
- "users" => [
- %{
- "deactivated" => user.info.deactivated,
- "id" => user.id,
- "nickname" => user.nickname
- }
- ]
- }
+ "count" => 1,
+ "page_size" => 50,
+ "users" => [
+ %{
+ "deactivated" => user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname
+ }
+ ]
+ }
end
end
end
--
cgit v1.2.3
From f384a9a2563d2fb6161ebb824534fda08cf67c64 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Fri, 1 Mar 2019 20:23:19 +0300
Subject: Format
---
test/web/admin_api/admin_api_controller_test.exs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 0679f5dfe..a3042fa05 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -345,11 +345,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"count" => 1,
"page_size" => 50,
"users" => [
- %{
- "deactivated" => admin.info.deactivated,
- "id" => admin.id,
- "nickname" => admin.nickname
- },
+ %{
+ "deactivated" => admin.info.deactivated,
+ "id" => admin.id,
+ "nickname" => admin.nickname
+ },
%{
"deactivated" => user.info.deactivated,
"id" => user.id,
--
cgit v1.2.3
From aaa9fed1ca196b55d8c05af838d6947959548bf0 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Fri, 1 Mar 2019 20:58:47 +0300
Subject: Fix user_test
---
test/user_test.exs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 0b1c39ecf..27137fc35 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -901,7 +901,7 @@ defmodule Pleroma.UserTest do
{:ok, follower} = User.follow(follower, u1)
{:ok, u1} = User.follow(u1, friend)
- assert [friend.id, follower.id, u2.id] == Enum.map(User.search("doe", false, u1), & &1.id)
+ assert [friend.id, follower.id, u2.id] == Enum.map(User.search("doe", resolve: false, for_user: u1), & &1.id)
end
test "finds a user whose name is nil" do
@@ -923,7 +923,7 @@ defmodule Pleroma.UserTest do
end
test "works with URIs" do
- results = User.search("http://mastodon.example.org/users/admin", true)
+ results = User.search("http://mastodon.example.org/users/admin", resolve: true)
result = results |> List.first()
user = User.get_by_ap_id("http://mastodon.example.org/users/admin")
--
cgit v1.2.3
From a25c1313aee2f5f3d2b858b9802698f29acf4043 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Fri, 1 Mar 2019 21:07:05 +0300
Subject: Format
---
test/user_test.exs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 27137fc35..4f9de4e31 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -901,7 +901,8 @@ defmodule Pleroma.UserTest do
{:ok, follower} = User.follow(follower, u1)
{:ok, u1} = User.follow(u1, friend)
- assert [friend.id, follower.id, u2.id] == Enum.map(User.search("doe", resolve: false, for_user: u1), & &1.id)
+ assert [friend.id, follower.id, u2.id] ==
+ Enum.map(User.search("doe", resolve: false, for_user: u1), & &1.id)
end
test "finds a user whose name is nil" do
--
cgit v1.2.3
From bb9e40968a90b882ba85e71a2622756e40563207 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Sat, 2 Mar 2019 04:10:43 +0100
Subject: Web.OAuth.OAuthControllerTest: Add test against token formatting
---
test/web/oauth/oauth_controller_test.exs | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
(limited to 'test')
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index 53d83e6e8..ed94416ff 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -165,10 +165,10 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
test "issues a token for request with HTTP basic auth client credentials" do
user = insert(:user)
- app = insert(:oauth_app, scopes: ["scope1", "scope2"])
+ app = insert(:oauth_app, scopes: ["scope1", "scope2", "scope3"])
- {:ok, auth} = Authorization.create_authorization(app, user, ["scope2"])
- assert auth.scopes == ["scope2"]
+ {:ok, auth} = Authorization.create_authorization(app, user, ["scope1", "scope2"])
+ assert auth.scopes == ["scope1", "scope2"]
app_encoded =
(URI.encode_www_form(app.client_id) <> ":" <> URI.encode_www_form(app.client_secret))
@@ -183,11 +183,13 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"redirect_uri" => app.redirect_uris
})
- assert %{"access_token" => token} = json_response(conn, 200)
+ assert %{"access_token" => token, "scope" => scope} = json_response(conn, 200)
+
+ assert scope == "scope1 scope2"
token = Repo.get_by(Token, token: token)
assert token
- assert token.scopes == ["scope2"]
+ assert token.scopes == ["scope1", "scope2"]
end
test "rejects token exchange with invalid client credentials" do
--
cgit v1.2.3
From 25e588496adab62be79da65e8dc23426b8813159 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Sat, 2 Mar 2019 06:13:04 +0100
Subject: Pleroma.Web.RelMeTest: Add test against Pleroma.Web.RelMe
---
test/fixtures/rel_me_anchor.html | 14 +++++++++++
test/fixtures/rel_me_link.html | 14 +++++++++++
test/fixtures/rel_me_null.html | 13 ++++++++++
test/web/rel_me_test.exs | 54 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 95 insertions(+)
create mode 100644 test/fixtures/rel_me_anchor.html
create mode 100644 test/fixtures/rel_me_link.html
create mode 100644 test/fixtures/rel_me_null.html
create mode 100644 test/web/rel_me_test.exs
(limited to 'test')
diff --git a/test/fixtures/rel_me_anchor.html b/test/fixtures/rel_me_anchor.html
new file mode 100644
index 000000000..5abcce129
--- /dev/null
+++ b/test/fixtures/rel_me_anchor.html
@@ -0,0 +1,14 @@
+
+
+
+
+ Blog
+
+
+
+ Lorem ipsum
+ Lorem ipsum dolor sit ameph, …
+ lain’s account
+
+
+
diff --git a/test/fixtures/rel_me_link.html b/test/fixtures/rel_me_link.html
new file mode 100644
index 000000000..b9ff18f6e
--- /dev/null
+++ b/test/fixtures/rel_me_link.html
@@ -0,0 +1,14 @@
+
+
+
+
+ Blog
+
+
+
+
+ Lorem ipsum
+ Lorem ipsum dolor sit ameph, …
+
+
+
diff --git a/test/fixtures/rel_me_null.html b/test/fixtures/rel_me_null.html
new file mode 100644
index 000000000..57d424b80
--- /dev/null
+++ b/test/fixtures/rel_me_null.html
@@ -0,0 +1,13 @@
+
+
+
+
+ Blog
+
+
+
+ Lorem ipsum
+ Lorem ipsum dolor sit ameph, …
+
+
+
diff --git a/test/web/rel_me_test.exs b/test/web/rel_me_test.exs
new file mode 100644
index 000000000..94cc01728
--- /dev/null
+++ b/test/web/rel_me_test.exs
@@ -0,0 +1,54 @@
+defmodule Pleroma.Web.RelMeTest do
+ use ExUnit.Case, async: true
+
+ setup do
+ Tesla.Mock.mock(fn
+ %{
+ method: :get,
+ url: "http://example.com/rel_me/anchor"
+ } ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}
+
+ %{
+ method: :get,
+ url: "http://example.com/rel_me/link"
+ } ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}
+
+ %{
+ method: :get,
+ url: "http://example.com/rel_me/null"
+ } ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}
+ end)
+
+ :ok
+ end
+
+ test "parse/1" do
+ hrefs = ["https://social.example.org/users/lain"]
+
+ assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/null") == {:ok, []}
+ assert {:error, _} = Pleroma.Web.RelMe.parse("http://example.com/rel_me/error")
+
+ assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/link") == {:ok, hrefs}
+ assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor") == {:ok, hrefs}
+ end
+
+ test "maybe_put_rel_me/2" do
+ profile_urls = ["https://social.example.org/users/lain"]
+ attr = "rel=\"me\" "
+
+ assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/null", profile_urls) ==
+ ""
+
+ assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/error", profile_urls) ==
+ ""
+
+ assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/anchor", profile_urls) ==
+ attr
+
+ assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/link", profile_urls) ==
+ attr
+ end
+end
--
cgit v1.2.3
From 8e6f7fdb86bc7f90618c59ee4b13b30b94fda475 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Sat, 2 Mar 2019 06:58:42 +0100
Subject: RelMe.maybe_put_rel_me/2: When true put "me" otherwise nil
---
test/web/rel_me_test.exs | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/web/rel_me_test.exs b/test/web/rel_me_test.exs
index 94cc01728..ba8038e69 100644
--- a/test/web/rel_me_test.exs
+++ b/test/web/rel_me_test.exs
@@ -37,13 +37,14 @@ defmodule Pleroma.Web.RelMeTest do
test "maybe_put_rel_me/2" do
profile_urls = ["https://social.example.org/users/lain"]
- attr = "rel=\"me\" "
+ attr = "me"
+ fallback = nil
assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/null", profile_urls) ==
- ""
+ fallback
assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/error", profile_urls) ==
- ""
+ fallback
assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/anchor", profile_urls) ==
attr
--
cgit v1.2.3
From 7b9868f34344144bfb965cdd099f71b2617976c6 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Sat, 2 Mar 2019 06:59:09 +0100
Subject: Pleroma.UserTest: Add tests for rel=me
---
test/user_test.exs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index cbe4693fc..e182a809f 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1039,6 +1039,22 @@ defmodule Pleroma.UserTest do
assert expected_text == User.parse_bio(bio, user)
end
+
+ test "Adds rel=me on linkbacked urls" do
+ user = insert(:user, ap_id: "http://social.example.org/users/lain")
+
+ bio = "http://example.org/rel_me/null"
+ expected_text = "#{bio} "
+ assert expected_text == User.parse_bio(bio, user)
+
+ bio = "http://example.org/rel_me/link"
+ expected_text = "#{bio} "
+ assert expected_text == User.parse_bio(bio, user)
+
+ bio = "http://example.org/rel_me/anchor"
+ expected_text = "#{bio} "
+ assert expected_text == User.parse_bio(bio, user)
+ end
end
test "bookmarks" do
--
cgit v1.2.3
From 2ec8cf566569912b767e15ab467cadd04fd1fd1c Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Sat, 2 Mar 2019 17:21:18 +0300
Subject: Add pagination to search
---
test/web/admin_api/admin_api_controller_test.exs | 46 ++++++++++++++++++++++--
1 file changed, 43 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index a3042fa05..42e0daf8e 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -342,7 +342,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|> get("/api/pleroma/admin/users?page=1")
assert json_response(conn, 200) == %{
- "count" => 1,
+ "count" => 2,
"page_size" => 50,
"users" => [
%{
@@ -369,7 +369,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|> get("/api/pleroma/admin/users?page=2")
assert json_response(conn, 200) == %{
- "count" => 1,
+ "count" => 2,
"page_size" => 50,
"users" => []
}
@@ -416,9 +416,49 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
}
end
- test "only local users" do
+ test "regular search with page size" do
admin = insert(:user, info: %{is_admin: true})
user = insert(:user, nickname: "bob")
+ user2 = insert(:user, nickname: "bo")
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> get("/api/pleroma/admin/users/search?query=bo&page_size=1&page=1")
+
+ assert json_response(conn, 200) == %{
+ "count" => 2,
+ "page_size" => 1,
+ "users" => [
+ %{
+ "deactivated" => user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname
+ }
+ ]
+ }
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> get("/api/pleroma/admin/users/search?query=bo&page_size=1&page=2")
+
+ assert json_response(conn, 200) == %{
+ "count" => 2,
+ "page_size" => 1,
+ "users" => [
+ %{
+ "deactivated" => user2.info.deactivated,
+ "id" => user2.id,
+ "nickname" => user2.nickname
+ }
+ ]
+ }
+ end
+
+ test "only local users" do
+ admin = insert(:user, info: %{is_admin: true}, nickname: "john")
+ user = insert(:user, nickname: "bob")
insert(:user, nickname: "bobb", local: false)
--
cgit v1.2.3
From bf30df99cb9a08870f7c6a25e0f9f3d2e03d5de7 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Sat, 2 Mar 2019 17:32:40 +0300
Subject: We do not guarantee the order of elements when we search
---
test/user_test.exs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 4f9de4e31..188ab1a5c 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -901,8 +901,8 @@ defmodule Pleroma.UserTest do
{:ok, follower} = User.follow(follower, u1)
{:ok, u1} = User.follow(u1, friend)
- assert [friend.id, follower.id, u2.id] ==
- Enum.map(User.search("doe", resolve: false, for_user: u1), & &1.id)
+ assert [friend.id, follower.id, u2.id] --
+ Enum.map(User.search("doe", resolve: false, for_user: u1), & &1.id) == []
end
test "finds a user whose name is nil" do
--
cgit v1.2.3
From 1a1f4520cd711d46a53ffa0ec657f8a7e46896e7 Mon Sep 17 00:00:00 2001
From: eugenijm
Date: Sat, 2 Mar 2019 22:18:51 +0300
Subject: Use sql query in User.get_follow_requests/1 for filtering logic
---
test/user_test.exs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index cbe4693fc..b8d41ecfd 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -64,6 +64,20 @@ defmodule Pleroma.UserTest do
assert activity
end
+ test "doesn't return already accepted or duplicate follow requests" do
+ locked = insert(:user, %{info: %{locked: true}})
+ pending_follower = insert(:user)
+ accepted_follower = insert(:user)
+
+ Pleroma.Web.TwitterAPI.TwitterAPI.follow(pending_follower, %{"user_id" => locked.id})
+ Pleroma.Web.TwitterAPI.TwitterAPI.follow(pending_follower, %{"user_id" => locked.id})
+ Pleroma.Web.TwitterAPI.TwitterAPI.follow(accepted_follower, %{"user_id" => locked.id})
+ User.maybe_follow(accepted_follower, locked)
+
+ assert {:ok, [activity]} = User.get_follow_requests(locked)
+ assert activity
+ end
+
test "follow_all follows mutliple users" do
user = insert(:user)
followed_zero = insert(:user)
--
cgit v1.2.3
From c46950d3b16e6fe1ebb86a202ca47a810bfb76dc Mon Sep 17 00:00:00 2001
From: eugenijm
Date: Sun, 3 Mar 2019 13:21:03 +0300
Subject: Increment user note count only on public activities
---
test/web/activity_pub/activity_pub_test.exs | 43 +++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index ac3a565de..70a98824d 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -205,6 +205,25 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert activity.actor == user.ap_id
assert activity.recipients == ["user1", "user2", user.ap_id]
end
+
+ test "increases user note count only for public activities" do
+ user = insert(:user)
+
+ {:ok, _} =
+ CommonAPI.post(Repo.get(User, user.id), %{"status" => "1", "visibility" => "public"})
+
+ {:ok, _} =
+ CommonAPI.post(Repo.get(User, user.id), %{"status" => "2", "visibility" => "unlisted"})
+
+ {:ok, _} =
+ CommonAPI.post(Repo.get(User, user.id), %{"status" => "2", "visibility" => "private"})
+
+ {:ok, _} =
+ CommonAPI.post(Repo.get(User, user.id), %{"status" => "3", "visibility" => "direct"})
+
+ user = Repo.get(User, user.id)
+ assert user.info.note_count == 2
+ end
end
describe "fetch activities for recipients" do
@@ -640,6 +659,30 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert Repo.get(Object, object.id).data["type"] == "Tombstone"
end
+
+ test "decrements user note count only for public activities" do
+ user = insert(:user, info: %{note_count: 10})
+
+ {:ok, a1} =
+ CommonAPI.post(Repo.get(User, user.id), %{"status" => "yeah", "visibility" => "public"})
+
+ {:ok, a2} =
+ CommonAPI.post(Repo.get(User, user.id), %{"status" => "yeah", "visibility" => "unlisted"})
+
+ {:ok, a3} =
+ CommonAPI.post(Repo.get(User, user.id), %{"status" => "yeah", "visibility" => "private"})
+
+ {:ok, a4} =
+ CommonAPI.post(Repo.get(User, user.id), %{"status" => "yeah", "visibility" => "direct"})
+
+ {:ok, _} = a1.data["object"]["id"] |> Object.get_by_ap_id() |> ActivityPub.delete()
+ {:ok, _} = a2.data["object"]["id"] |> Object.get_by_ap_id() |> ActivityPub.delete()
+ {:ok, _} = a3.data["object"]["id"] |> Object.get_by_ap_id() |> ActivityPub.delete()
+ {:ok, _} = a4.data["object"]["id"] |> Object.get_by_ap_id() |> ActivityPub.delete()
+
+ user = Repo.get(User, user.id)
+ assert user.info.note_count == 10
+ end
end
describe "timeline post-processing" do
--
cgit v1.2.3
From d5418e9ff78785c48bc94fbc8cb146ffe90c1fc5 Mon Sep 17 00:00:00 2001
From: eugenijm
Date: Sun, 3 Mar 2019 18:39:37 +0300
Subject: Remove follow_request_count as it's not needed for FE anymore.
MastoFE uses `GET /api/v1/follow_requests` and PleromaFE uses
`GET /api/pleroma/friend_requests` which they query on the initial page
load.
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 4 ----
test/web/twitter_api/twitter_api_controller_test.exs | 5 -----
2 files changed, 9 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index b52c2b805..f7f10662a 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -946,7 +946,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == false
- assert user.info.follow_request_count == 1
conn =
build_conn()
@@ -960,7 +959,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == true
- assert user.info.follow_request_count == 0
end
test "verify_credentials", %{conn: conn} do
@@ -982,7 +980,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _activity} = ActivityPub.follow(other_user, user)
user = Repo.get(User, user.id)
- assert user.info.follow_request_count == 1
conn =
build_conn()
@@ -996,7 +993,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == false
- assert user.info.follow_request_count == 0
end
end
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 7125d85ab..d18b65876 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -690,7 +690,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
followed = Repo.get(User, followed.id)
refute User.ap_followers(followed) in current_user.following
- assert followed.info.follow_request_count == 1
assert json_response(conn, 200) ==
UserView.render("show.json", %{user: followed, for: current_user})
@@ -1757,7 +1756,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == false
- assert user.info.follow_request_count == 1
conn =
build_conn()
@@ -1769,7 +1767,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert relationship = json_response(conn, 200)
assert other_user.id == relationship["id"]
assert relationship["follows_you"] == true
- assert user.info.follow_request_count == 0
end
end
@@ -1784,7 +1781,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == false
- assert user.info.follow_request_count == 1
conn =
build_conn()
@@ -1796,7 +1792,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert relationship = json_response(conn, 200)
assert other_user.id == relationship["id"]
assert relationship["follows_you"] == false
- assert user.info.follow_request_count == 0
end
end
--
cgit v1.2.3
From 86e4b48a5e053f7fc949c682c1d5c0c820b0dd58 Mon Sep 17 00:00:00 2001
From: eugenijm
Date: Mon, 4 Mar 2019 02:59:54 +0300
Subject: Fix DM visibility for blocking users
---
.../mastodon_api/mastodon_api_controller_test.exs | 27 +++++++++++++++++++
.../twitter_api/twitter_api_controller_test.exs | 31 +++++++++++++++++++---
2 files changed, 54 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index f7f10662a..ec6869db9 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -248,6 +248,33 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert status["url"] != direct.data["id"]
end
+ test "doesn't include DMs from blocked users", %{conn: conn} do
+ blocker = insert(:user)
+ blocked = insert(:user)
+ user = insert(:user)
+ {:ok, blocker} = User.block(blocker, blocked)
+
+ {:ok, _blocked_direct} =
+ CommonAPI.post(blocked, %{
+ "status" => "Hi @#{blocker.nickname}!",
+ "visibility" => "direct"
+ })
+
+ {:ok, direct} =
+ CommonAPI.post(user, %{
+ "status" => "Hi @#{blocker.nickname}!",
+ "visibility" => "direct"
+ })
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> get("api/v1/timelines/direct")
+
+ [status] = json_response(res_conn, 200)
+ assert status["id"] == direct.id
+ end
+
test "replying to a status", %{conn: conn} do
user = insert(:user)
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index d18b65876..ce0812308 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -415,6 +415,33 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert status["id"] == direct_two.id
assert status_two["id"] == direct.id
end
+
+ test "doesn't include DMs from blocked users", %{conn: conn} do
+ blocker = insert(:user)
+ blocked = insert(:user)
+ user = insert(:user)
+ {:ok, blocker} = User.block(blocker, blocked)
+
+ {:ok, _blocked_direct} =
+ CommonAPI.post(blocked, %{
+ "status" => "Hi @#{blocker.nickname}!",
+ "visibility" => "direct"
+ })
+
+ {:ok, direct} =
+ CommonAPI.post(user, %{
+ "status" => "Hi @#{blocker.nickname}!",
+ "visibility" => "direct"
+ })
+
+ res_conn =
+ conn
+ |> assign(:user, blocker)
+ |> get("/api/statuses/dm_timeline.json")
+
+ [status] = json_response(res_conn, 200)
+ assert status["id"] == direct.id
+ end
end
describe "GET /statuses/mentions.json" do
@@ -1762,8 +1789,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> assign(:user, user)
|> post("/api/pleroma/friendships/approve", %{"user_id" => other_user.id})
- user = Repo.get(User, user.id)
-
assert relationship = json_response(conn, 200)
assert other_user.id == relationship["id"]
assert relationship["follows_you"] == true
@@ -1787,8 +1812,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> assign(:user, user)
|> post("/api/pleroma/friendships/deny", %{"user_id" => other_user.id})
- user = Repo.get(User, user.id)
-
assert relationship = json_response(conn, 200)
assert other_user.id == relationship["id"]
assert relationship["follows_you"] == false
--
cgit v1.2.3
From aab86698a5356e26fe68c650f277913497aac3e9 Mon Sep 17 00:00:00 2001
From: Karen Konou
Date: Mon, 4 Mar 2019 10:47:04 +0100
Subject: Expand "to" of delete activities
---
test/web/activity_pub/activity_pub_test.exs | 10 ++++++++++
1 file changed, 10 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index f4029896c..e607c7f4d 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -691,6 +691,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
user = Repo.get(User, user.id)
assert user.info.note_count == 10
end
+
+ test "it creates a delete activity and checks that it is also sent to users mentioned by the deleted object" do
+ user = insert(:user)
+ note = insert(:note_activity)
+ object = Object.get_by_ap_id(note.data["object"]["id"])
+ object = Kernel.put_in(object.data["to"], [user.ap_id])
+ {:ok, delete} = ActivityPub.delete(object)
+
+ assert user.ap_id in delete.data["to"]
+ end
end
describe "timeline post-processing" do
--
cgit v1.2.3
From 33c614bce002ff27cedbe3969f587c800744b997 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Mon, 4 Mar 2019 18:09:58 +0300
Subject: Stop adresssing like activities to actor's follower collection on
non-public posts
---
test/web/activity_pub/utils_test.exs | 50 ++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs
index aeed0564c..2e5e95795 100644
--- a/test/web/activity_pub/utils_test.exs
+++ b/test/web/activity_pub/utils_test.exs
@@ -1,7 +1,10 @@
defmodule Pleroma.Web.ActivityPub.UtilsTest do
use Pleroma.DataCase
+ alias Pleroma.Web.CommonAPI
alias Pleroma.Web.ActivityPub.Utils
+ import Pleroma.Factory
+
describe "determine_explicit_mentions()" do
test "works with an object that has mentions" do
object = %{
@@ -54,4 +57,51 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
assert Utils.determine_explicit_mentions(object) == []
end
end
+
+ describe "make_like_data" do
+ setup do
+ user = insert(:user)
+ other_user = insert(:user)
+ third_user = insert(:user)
+ [user: user, other_user: other_user, third_user: third_user]
+ end
+
+ test "addresses actor's follower address if the activity is public", %{
+ user: user,
+ other_user: other_user,
+ third_user: third_user
+ } do
+ expected_to = Enum.sort([user.ap_id, other_user.follower_address])
+ expected_cc = Enum.sort(["https://www.w3.org/ns/activitystreams#Public", third_user.ap_id])
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "hey @#{other_user.nickname}, @#{third_user.nickname} how about beering together this weekend?"
+ })
+
+ %{"to" => to, "cc" => cc} = Utils.make_like_data(other_user, activity, nil)
+ assert Enum.sort(to) == expected_to
+ assert Enum.sort(cc) == expected_cc
+ end
+
+ test "does not adress actor's follower address if the activity is not public", %{
+ user: user,
+ other_user: other_user,
+ third_user: third_user
+ } do
+ expected_to = Enum.sort([user.ap_id])
+ expected_cc = [third_user.ap_id]
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "@#{other_user.nickname} @#{third_user.nickname} bought a new swimsuit!",
+ "visibility" => "private"
+ })
+
+ %{"to" => to, "cc" => cc} = Utils.make_like_data(other_user, activity, nil)
+ assert Enum.sort(to) == expected_to
+ assert Enum.sort(cc) == expected_cc
+ end
+ end
end
--
cgit v1.2.3
From cc7b35e0976a44d21c9f43999f42387ad0a87845 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Mon, 4 Mar 2019 20:47:34 +0300
Subject: Add status text to notifications (mentions and reposts)
---
test/support/factory.ex | 14 +++---
test/web/push/push_test.exs | 53 ++++++++++++++++++++++
.../twitter_api/twitter_api_controller_test.exs | 4 --
3 files changed, 60 insertions(+), 11 deletions(-)
create mode 100644 test/web/push/push_test.exs
(limited to 'test')
diff --git a/test/support/factory.ex b/test/support/factory.ex
index d1956d1cd..c025aaf21 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -23,7 +23,7 @@ defmodule Pleroma.Factory do
}
end
- def note_factory do
+ def note_factory(attrs \\ %{}) do
text = sequence(:text, &"This is :moominmamma: note #{&1}")
user = insert(:user)
@@ -46,7 +46,7 @@ defmodule Pleroma.Factory do
}
%Pleroma.Object{
- data: data
+ data: merge_attributes(data, Map.get(attrs, :data, %{}))
}
end
@@ -95,8 +95,8 @@ defmodule Pleroma.Factory do
}
end
- def note_activity_factory do
- note = insert(:note)
+ def note_activity_factory(attrs \\ %{}) do
+ note = attrs[:note] || insert(:note)
data = %{
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
@@ -135,9 +135,9 @@ defmodule Pleroma.Factory do
}
end
- def announce_activity_factory do
- note_activity = insert(:note_activity)
- user = insert(:user)
+ def announce_activity_factory(attrs \\ %{}) do
+ note_activity = attrs[:note_activity] || insert(:note_activity)
+ user = attrs[:user] || insert(:user)
data = %{
"type" => "Announce",
diff --git a/test/web/push/push_test.exs b/test/web/push/push_test.exs
new file mode 100644
index 000000000..5fa97531d
--- /dev/null
+++ b/test/web/push/push_test.exs
@@ -0,0 +1,53 @@
+defmodule Pleroma.Web.PushTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.Push
+
+ import Pleroma.Factory
+
+ test "renders body for create activity" do
+ assert Push.format_body(
+ %{
+ activity: %{
+ data: %{
+ "type" => "Create",
+ "object" => %{
+ "content" =>
+ "Lorem ipsum dolor sit amet , consectetur :bear: adipiscing elit. Fusce sagittis finibus turpis."
+ }
+ }
+ }
+ },
+ %{nickname: "Bob"}
+ ) ==
+ "@Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
+ end
+
+ test "renders body for follow activity" do
+ assert Push.format_body(%{activity: %{data: %{"type" => "Follow"}}}, %{nickname: "Bob"}) ==
+ "@Bob has followed you"
+ end
+
+ test "renders body for announce activity" do
+ user = insert(:user)
+
+ note =
+ insert(:note, %{
+ data: %{
+ "content" =>
+ "Lorem ipsum dolor sit amet , consectetur :bear: adipiscing elit. Fusce sagittis finibus turpis."
+ }
+ })
+
+ note_activity = insert(:note_activity, %{note: note})
+ announce_activity = insert(:announce_activity, %{user: user, note_activity: note_activity})
+
+ assert Push.format_body(%{activity: announce_activity}, user) ==
+ "@#{user.nickname} repeated: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
+ end
+
+ test "renders body for like activity" do
+ assert Push.format_body(%{activity: %{data: %{"type" => "Like"}}}, %{nickname: "Bob"}) ==
+ "@Bob has favorited your post"
+ end
+end
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index d18b65876..fd76121e3 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -1762,8 +1762,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> assign(:user, user)
|> post("/api/pleroma/friendships/approve", %{"user_id" => other_user.id})
- user = Repo.get(User, user.id)
-
assert relationship = json_response(conn, 200)
assert other_user.id == relationship["id"]
assert relationship["follows_you"] == true
@@ -1787,8 +1785,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> assign(:user, user)
|> post("/api/pleroma/friendships/deny", %{"user_id" => other_user.id})
- user = Repo.get(User, user.id)
-
assert relationship = json_response(conn, 200)
assert other_user.id == relationship["id"]
assert relationship["follows_you"] == false
--
cgit v1.2.3
From f62019983605dd9af9017351a59b52807bb74ba1 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Mon, 4 Mar 2019 21:26:32 +0300
Subject: Merge search endpoint into /users
---
test/web/admin_api/admin_api_controller_test.exs | 73 ++++++++++++++++--------
1 file changed, 50 insertions(+), 23 deletions(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 42e0daf8e..dd40b4a06 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -374,26 +374,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"users" => []
}
end
- end
-
- test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do
- admin = insert(:user, info: %{is_admin: true})
- user = insert(:user)
- conn =
- build_conn()
- |> assign(:user, admin)
- |> patch("/api/pleroma/admin/users/#{user.nickname}/toggle_activation")
-
- assert json_response(conn, 200) ==
- %{
- "deactivated" => !user.info.deactivated,
- "id" => user.id,
- "nickname" => user.nickname
- }
- end
-
- describe "GET /api/pleroma/admin/users/search" do
test "regular search" do
admin = insert(:user, info: %{is_admin: true})
user = insert(:user, nickname: "bob")
@@ -401,7 +382,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn =
build_conn()
|> assign(:user, admin)
- |> get("/api/pleroma/admin/users/search?query=bo")
+ |> get("/api/pleroma/admin/users?query=bo")
assert json_response(conn, 200) == %{
"count" => 1,
@@ -424,7 +405,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn =
build_conn()
|> assign(:user, admin)
- |> get("/api/pleroma/admin/users/search?query=bo&page_size=1&page=1")
+ |> get("/api/pleroma/admin/users?query=bo&page_size=1&page=1")
assert json_response(conn, 200) == %{
"count" => 2,
@@ -441,7 +422,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn =
build_conn()
|> assign(:user, admin)
- |> get("/api/pleroma/admin/users/search?query=bo&page_size=1&page=2")
+ |> get("/api/pleroma/admin/users?query=bo&page_size=1&page=2")
assert json_response(conn, 200) == %{
"count" => 2,
@@ -465,7 +446,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn =
build_conn()
|> assign(:user, admin)
- |> get("/api/pleroma/admin/users/search?query=bo&local=true")
+ |> get("/api/pleroma/admin/users?query=bo&local_only=true")
assert json_response(conn, 200) == %{
"count" => 1,
@@ -479,5 +460,51 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
]
}
end
+
+ test "only local users with no query" do
+ admin = insert(:user, info: %{is_admin: true}, nickname: "john")
+ user = insert(:user, nickname: "bob")
+
+ insert(:user, nickname: "bobb", local: false)
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> get("/api/pleroma/admin/users?local_only=true")
+
+ assert json_response(conn, 200) == %{
+ "count" => 2,
+ "page_size" => 50,
+ "users" => [
+ %{
+ "deactivated" => admin.info.deactivated,
+ "id" => admin.id,
+ "nickname" => admin.nickname
+ },
+ %{
+ "deactivated" => user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname
+ }
+ ]
+ }
+ end
+ end
+
+ test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do
+ admin = insert(:user, info: %{is_admin: true})
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> patch("/api/pleroma/admin/users/#{user.nickname}/toggle_activation")
+
+ assert json_response(conn, 200) ==
+ %{
+ "deactivated" => !user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname
+ }
end
end
--
cgit v1.2.3
From d7a278a733616d01ee41c3923a3d87730c685879 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 24 Feb 2019 19:39:27 +0000
Subject: tests: add tests for rich media helper functions
---
test/web/rich_media/helpers_test.exs | 42 ++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
create mode 100644 test/web/rich_media/helpers_test.exs
(limited to 'test')
diff --git a/test/web/rich_media/helpers_test.exs b/test/web/rich_media/helpers_test.exs
new file mode 100644
index 000000000..9285f078d
--- /dev/null
+++ b/test/web/rich_media/helpers_test.exs
@@ -0,0 +1,42 @@
+defmodule Pleroma.Web.RichMedia.HelpersTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
+ test "refuses to crawl incomplete URLs" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "[test](example.com/ogp)",
+ "content_type" => "text/markdown"
+ })
+
+ assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+ end
+
+ test "crawls valid, complete URLs" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "[test](http://example.com/ogp)",
+ "content_type" => "text/markdown"
+ })
+
+ Pleroma.Config.put([:rich_media, :enabled], true)
+
+ assert %{page_url: "http://example.com/ogp", rich_media: _} =
+ Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+
+ Pleroma.Config.put([:rich_media, :enabled], false)
+ end
+end
--
cgit v1.2.3
From 9f3cb38012281c596d1aa8c479f07362fa58dacb Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sat, 2 Mar 2019 12:22:02 +0000
Subject: helpers: use AutoLinker to validate URIs as well as the other tests
---
test/web/rich_media/helpers_test.exs | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
(limited to 'test')
diff --git a/test/web/rich_media/helpers_test.exs b/test/web/rich_media/helpers_test.exs
index 9285f078d..60d93768f 100644
--- a/test/web/rich_media/helpers_test.exs
+++ b/test/web/rich_media/helpers_test.exs
@@ -20,7 +20,27 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
"content_type" => "text/markdown"
})
+ Pleroma.Config.put([:rich_media, :enabled], true)
+
+ assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+
+ Pleroma.Config.put([:rich_media, :enabled], false)
+ end
+
+ test "refuses to crawl malformed URLs" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "[test](example.com[]/ogp)",
+ "content_type" => "text/markdown"
+ })
+
+ Pleroma.Config.put([:rich_media, :enabled], true)
+
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+
+ Pleroma.Config.put([:rich_media, :enabled], false)
end
test "crawls valid, complete URLs" do
--
cgit v1.2.3
From e34710b9888d5a3602971111c3a376bf8442fb84 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Mon, 4 Mar 2019 21:33:53 +0300
Subject: Format & update docs
---
test/web/admin_api/admin_api_controller_test.exs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index dd40b4a06..1b8b4d4b7 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -476,11 +476,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"count" => 2,
"page_size" => 50,
"users" => [
- %{
- "deactivated" => admin.info.deactivated,
- "id" => admin.id,
- "nickname" => admin.nickname
- },
+ %{
+ "deactivated" => admin.info.deactivated,
+ "id" => admin.id,
+ "nickname" => admin.nickname
+ },
%{
"deactivated" => user.info.deactivated,
"id" => user.id,
--
cgit v1.2.3
From d1de0a30ccbc33a45b5b164e1cb910f4717296e9 Mon Sep 17 00:00:00 2001
From: eugenijm
Date: Mon, 4 Mar 2019 22:14:04 +0300
Subject: Include admins in nodeinfo
---
test/web/node_info_test.exs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs
index 763549bd1..038feecc1 100644
--- a/test/web/node_info_test.exs
+++ b/test/web/node_info_test.exs
@@ -8,7 +8,8 @@ defmodule Pleroma.Web.NodeInfoTest do
import Pleroma.Factory
test "nodeinfo shows staff accounts", %{conn: conn} do
- user = insert(:user, %{local: true, info: %{is_moderator: true}})
+ moderator = insert(:user, %{local: true, info: %{is_moderator: true}})
+ admin = insert(:user, %{local: true, info: %{is_admin: true}})
conn =
conn
@@ -16,7 +17,8 @@ defmodule Pleroma.Web.NodeInfoTest do
assert result = json_response(conn, 200)
- assert user.ap_id in result["metadata"]["staffAccounts"]
+ assert moderator.ap_id in result["metadata"]["staffAccounts"]
+ assert admin.ap_id in result["metadata"]["staffAccounts"]
end
test "nodeinfo shows restricted nicknames", %{conn: conn} do
--
cgit v1.2.3
From 788a354ce0cbe91d0430ce48db62cb537e845a6d Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Tue, 5 Mar 2019 02:03:44 +0100
Subject: Web.RelMe: Fix having other values in rel attr
One example of this is Github which puts a rel="nofollow me" on the
profile link.
---
test/fixtures/rel_me_anchor_nofollow.html | 14 ++++++++++++++
test/fixtures/rel_me_null.html | 1 +
test/web/rel_me_test.exs | 12 ++++++++++++
3 files changed, 27 insertions(+)
create mode 100644 test/fixtures/rel_me_anchor_nofollow.html
(limited to 'test')
diff --git a/test/fixtures/rel_me_anchor_nofollow.html b/test/fixtures/rel_me_anchor_nofollow.html
new file mode 100644
index 000000000..c856f0091
--- /dev/null
+++ b/test/fixtures/rel_me_anchor_nofollow.html
@@ -0,0 +1,14 @@
+
+
+
+
+ Blog
+
+
+
+ Lorem ipsum
+ Lorem ipsum dolor sit ameph, …
+ lain’s account
+
+
+
diff --git a/test/fixtures/rel_me_null.html b/test/fixtures/rel_me_null.html
index 57d424b80..5ab5f10c1 100644
--- a/test/fixtures/rel_me_null.html
+++ b/test/fixtures/rel_me_null.html
@@ -8,6 +8,7 @@
Lorem ipsum
Lorem ipsum dolor sit ameph, …
+ lain’s account
Czsto o tym myl. Dziki za te celne uwagi.
oczyci nieznacznie z substancji lotnych, ale nie z pyw
Filtr wglowy nie suy do zatrzymywania pyw. Jeeli sam chcesz zrobi filtr smogu, czyli czstek okoo 1 mikrona potrzebujesz wkniny min klasy F9 a lepiej E10-11. Wtedy niestety wzrastaj opory przepywu i bdziesz potrzebowa wentylatora nieco wyszych cinie, np limakowego. Wszystko to oczywicie trzeba uszczelini. Taniej moe by jednak kupi gotowy.