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 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 = + "\"woollysocks\" 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 = "\"woollysocks\" 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 \"2hu\" content mentioning 2hu \"2hu\"

alert('YAY')Some \"2hu\" 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 \"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\n

second paragraph

" + expected = "

hello world!

\n\n

second 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

\n

another 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