From 8902942128e3aee814c215d700e2eaee21b491e9 Mon Sep 17 00:00:00 2001 From: raeno Date: Mon, 10 Dec 2018 23:08:02 +0400 Subject: WIP. Implement oembed route and handle both json/xml for "Note" type activity --- test/web/oembed/oembed_test.exs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/web/oembed/oembed_test.exs (limited to 'test/web') diff --git a/test/web/oembed/oembed_test.exs b/test/web/oembed/oembed_test.exs new file mode 100644 index 000000000..16c2c3598 --- /dev/null +++ b/test/web/oembed/oembed_test.exs @@ -0,0 +1,23 @@ +defmodule Pleroma.Web.OEmbedTest do + use Pleroma.DataCase + alias Pleroma.Web.OEmbed + alias Pleroma.Web.XML + alias Pleroma.{Object, Repo, User, Activity} + import Pleroma.Factory + import ExUnit.CaptureLog + + setup_all do + :ok + end + + test 'recognizes notices in given url' do + url = "https://pleroma.site/notice/5" + assert { :activity, _ } = OEmbed.recognize_path(url) + end + + test 'recognizes user card in given url' do + url = "https://pleroma.site/users/raeno" + assert { :user, _ } = OEmbed.recognize_path(url) + end + +end -- cgit v1.2.3 From b5de7c4c4d90d1049b59381953cbd76e79b77e66 Mon Sep 17 00:00:00 2001 From: raeno Date: Thu, 13 Dec 2018 22:16:54 +0100 Subject: Remove oembed for now, will submit it in another MR. Fix warnings --- test/web/oembed/oembed_test.exs | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 test/web/oembed/oembed_test.exs (limited to 'test/web') diff --git a/test/web/oembed/oembed_test.exs b/test/web/oembed/oembed_test.exs deleted file mode 100644 index 16c2c3598..000000000 --- a/test/web/oembed/oembed_test.exs +++ /dev/null @@ -1,23 +0,0 @@ -defmodule Pleroma.Web.OEmbedTest do - use Pleroma.DataCase - alias Pleroma.Web.OEmbed - alias Pleroma.Web.XML - alias Pleroma.{Object, Repo, User, Activity} - import Pleroma.Factory - import ExUnit.CaptureLog - - setup_all do - :ok - end - - test 'recognizes notices in given url' do - url = "https://pleroma.site/notice/5" - assert { :activity, _ } = OEmbed.recognize_path(url) - end - - test 'recognizes user card in given url' do - url = "https://pleroma.site/users/raeno" - assert { :user, _ } = OEmbed.recognize_path(url) - end - -end -- cgit v1.2.3 From c5c3ad90d00f1ea599e489aa03cfecada44c998c Mon Sep 17 00:00:00 2001 From: raeno Date: Fri, 14 Dec 2018 02:59:33 +0100 Subject: Fix tests. Remove oembed template --- test/web/ostatus/ostatus_controller_test.exs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'test/web') diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index 560305c15..747e30154 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -84,6 +84,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do conn = conn + |> put_req_header("accept", "application/xml") |> get(url) expected = @@ -110,11 +111,12 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do |> response(404) end - test "gets an activity", %{conn: conn} do + test "gets an activity in xml format", %{conn: conn} do note_activity = insert(:note_activity) [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"])) conn + |> put_req_header("accept", "application/xml") |> get("/activities/#{uuid}") |> response(200) end @@ -134,7 +136,22 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do |> response(404) end - test "gets a notice", %{conn: conn} do + test "renders notice metatags in html format" do + note_activity = insert(:note_activity) + + conn = get(conn, "/notice/#{note_activity.id}") + + twitter_card_summary = "" + + description_content = + "" + + body = html_response(conn, 200) + assert body =~ twitter_card_summary + assert body =~ description_content + end + + test "gets a notice in xml format", %{conn: conn} do note_activity = insert(:note_activity) conn -- cgit v1.2.3 From 9ff61ed793b7fd968b51c5f6e4b72958adeae977 Mon Sep 17 00:00:00 2001 From: raeno Date: Fri, 14 Dec 2018 20:23:51 +0100 Subject: Fix tests Notice test has been failing due to missing placeholder in index.html I've tried to use fixtures to substitute that file in test environment but it became too much hassle. Fixtures are not copied to _build directory so I'd need to change file fetching logic. IMO it doesn't worth it since pleroma-fe already has this placeholder merged and all future updated of index.html will include it. --- test/web/ostatus/ostatus_controller_test.exs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'test/web') diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index 747e30154..e9e9bdb16 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -136,17 +136,15 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do |> response(404) end - test "renders notice metatags in html format" do + test "renders notice metatags in html format", %{conn: conn} do note_activity = insert(:note_activity) - conn = get(conn, "/notice/#{note_activity.id}") - + body = html_response(conn, 200) twitter_card_summary = "" description_content = "" - body = html_response(conn, 200) assert body =~ twitter_card_summary assert body =~ description_content end -- cgit v1.2.3 From 8cea00e1dc2bf3c2e807b09fac886dfd7b4ea3e9 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 10:53:57 +0300 Subject: Remove OpenGraph test from Ostatus tests --- test/web/ostatus/ostatus_controller_test.exs | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'test/web') diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index 8e9d2b69a..5a94cb3b3 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -156,19 +156,6 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do |> response(404) end - test "renders notice metatags in html format", %{conn: conn} do - note_activity = insert(:note_activity) - conn = get(conn, "/notice/#{note_activity.id}") - body = html_response(conn, 200) - twitter_card_summary = "" - - description_content = - "" - - assert body =~ twitter_card_summary - assert body =~ description_content - end - test "gets a notice in xml format", %{conn: conn} do note_activity = insert(:note_activity) -- cgit v1.2.3 From 293f6a8b712246d0580f9eb113c798ae1ea3b634 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 17:15:13 +0300 Subject: join us now and share the software~. Also tests --- test/web/metadata/opengraph_test.exs | 113 +++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 test/web/metadata/opengraph_test.exs (limited to 'test/web') diff --git a/test/web/metadata/opengraph_test.exs b/test/web/metadata/opengraph_test.exs new file mode 100644 index 000000000..be3f89364 --- /dev/null +++ b/test/web/metadata/opengraph_test.exs @@ -0,0 +1,113 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only +defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do + use Pleroma.DataCase + import Pleroma.Factory + alias Pleroma.Web.Metadata.Providers.OpenGraph + + test "it renders all supported types of attachments and skips unknown types" do + user = insert(:user) + + note = + insert(:note, %{ + data: %{ + "actor" => user.ap_id, + "tag" => [], + "content" => "pleroma in a nutshell", + "attachment" => [ + %{ + "url" => [ + %{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"} + ] + }, + %{ + "url" => [ + %{ + "mediaType" => "application/octet-stream", + "href" => "https://pleroma.gov/fqa/badapple.sfc" + } + ] + }, + %{ + "url" => [ + %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"} + ] + }, + %{ + "url" => [ + %{ + "mediaType" => "audio/basic", + "href" => "http://www.gnu.org/music/free-software-song.au" + } + ] + } + ] + } + }) + + note_activity = + insert(:note_activity, %{ + data: %{ + "actor" => note.data["actor"], + "to" => note.data["to"], + "object" => note.data, + "context" => note.data["context"] + }, + actor: note.data["actor"], + recipients: note.data["to"] + }) + + result = OpenGraph.build_tags(%{activity: note_activity, user: user}) + + assert Enum.all?( + [ + {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []}, + {:meta, + [property: "og:audio", content: "http://www.gnu.org/music/free-software-song.au"], + []}, + {:meta, [property: "og:video", content: "https://pleroma.gov/about/juche.webm"], + []} + ], + fn element -> element in result end + ) + end + + test "it does not render attachments if post is nsfw" do + user = insert(:user, avatar: %{"url" => [%{"href" => "https://pleroma.gov/tenshi.png"}]}) + + note = + insert(:note, %{ + data: %{ + "actor" => user.ap_id, + "content" => "#cuteposting #nsfw #hambaga", + "tag" => ["cuteposting", "nsfw", "hambaga"], + "attachment" => [ + %{ + "url" => [ + %{"mediaType" => "image/png", "href" => "https://misskey.microsoft/corndog.png"} + ] + } + ] + } + }) + + note_activity = + insert(:note_activity, %{ + data: %{ + "actor" => note.data["actor"], + "to" => note.data["to"], + "object" => note.data, + "context" => note.data["context"] + }, + actor: note.data["actor"], + recipients: note.data["to"] + }) + + result = OpenGraph.build_tags(%{activity: note_activity, user: user}) + + assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result + + refute {:meta, [property: "og:image", content: "https://misskey.microsoft/corndog.png"], []} in result + end +end -- cgit v1.2.3 From 3b187896847637d93db194897565599acd73a57c Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 17 Jan 2019 11:08:50 +0300 Subject: Fix test --- test/web/metadata/opengraph_test.exs | 1 + 1 file changed, 1 insertion(+) (limited to 'test/web') diff --git a/test/web/metadata/opengraph_test.exs b/test/web/metadata/opengraph_test.exs index be3f89364..672942148 100644 --- a/test/web/metadata/opengraph_test.exs +++ b/test/web/metadata/opengraph_test.exs @@ -74,6 +74,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do end test "it does not render attachments if post is nsfw" do + Pleroma.Config.put([Pleroma.Web.Metadata, :unfurl_nsfw], false) user = insert(:user, avatar: %{"url" => [%{"href" => "https://pleroma.gov/tenshi.png"}]}) note = -- cgit v1.2.3 From 64143d8040a5806ccf9707644a7e7eacc91d74c6 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 17 Jan 2019 22:57:24 +0300 Subject: Fix object id in OpenGraph test --- test/web/metadata/opengraph_test.exs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/web') diff --git a/test/web/metadata/opengraph_test.exs b/test/web/metadata/opengraph_test.exs index 672942148..1c4fadc46 100644 --- a/test/web/metadata/opengraph_test.exs +++ b/test/web/metadata/opengraph_test.exs @@ -14,6 +14,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do data: %{ "actor" => user.ap_id, "tag" => [], + "id" => "https://pleroma.gov/objects/whatever", "content" => "pleroma in a nutshell", "attachment" => [ %{ @@ -81,6 +82,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do insert(:note, %{ data: %{ "actor" => user.ap_id, + "id" => "https://pleroma.gov/objects/whatever", "content" => "#cuteposting #nsfw #hambaga", "tag" => ["cuteposting", "nsfw", "hambaga"], "attachment" => [ -- cgit v1.2.3 From 1b1af4798a74c4ab357140ef2c5928dd9ebd3221 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 18 Jan 2019 09:32:52 +0300 Subject: Use object instead of activity for metadata --- test/web/metadata/opengraph_test.exs | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) (limited to 'test/web') diff --git a/test/web/metadata/opengraph_test.exs b/test/web/metadata/opengraph_test.exs index 1c4fadc46..c3502bad3 100644 --- a/test/web/metadata/opengraph_test.exs +++ b/test/web/metadata/opengraph_test.exs @@ -1,6 +1,7 @@ # Pleroma: A lightweight social networking server # Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do use Pleroma.DataCase import Pleroma.Factory @@ -47,19 +48,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do } }) - note_activity = - insert(:note_activity, %{ - data: %{ - "actor" => note.data["actor"], - "to" => note.data["to"], - "object" => note.data, - "context" => note.data["context"] - }, - actor: note.data["actor"], - recipients: note.data["to"] - }) - - result = OpenGraph.build_tags(%{activity: note_activity, user: user}) + result = OpenGraph.build_tags(%{object: note, user: user}) assert Enum.all?( [ @@ -85,6 +74,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do "id" => "https://pleroma.gov/objects/whatever", "content" => "#cuteposting #nsfw #hambaga", "tag" => ["cuteposting", "nsfw", "hambaga"], + "sensitive" => true, "attachment" => [ %{ "url" => [ @@ -95,19 +85,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do } }) - note_activity = - insert(:note_activity, %{ - data: %{ - "actor" => note.data["actor"], - "to" => note.data["to"], - "object" => note.data, - "context" => note.data["context"] - }, - actor: note.data["actor"], - recipients: note.data["to"] - }) - - result = OpenGraph.build_tags(%{activity: note_activity, user: user}) + result = OpenGraph.build_tags(%{object: note, user: user}) assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result -- cgit v1.2.3 From 7bc6208b2fa53b04d0d319e62c7c9b34d18e0e44 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 18 Jan 2019 10:35:52 +0300 Subject: Fix ostatus test --- test/web/ostatus/ostatus_controller_test.exs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/web') diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index 5a94cb3b3..954abf5fe 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -131,12 +131,14 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do object = Object.get_by_ap_id(note_activity.data["object"]["id"]) conn + |> put_req_header("accept", "application/xml") |> get("/objects/#{uuid}") |> response(200) Object.delete(object) conn + |> put_req_header("accept", "application/xml") |> get("/objects/#{uuid}") |> response(404) end -- cgit v1.2.3 From e116e55cabb34d468866231d1690421792c27a0c Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Fri, 18 Jan 2019 22:40:52 +0300 Subject: Add actor to recipients --- test/web/mastodon_api/mastodon_api_controller_test.exs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index fe8f845c7..ce3aa5a02 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -181,6 +181,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert %{"visibility" => "direct"} = status assert status["url"] != direct.data["id"] + # User should be able to see his own direct message + res_conn = + build_conn() + |> assign(:user, user_one) + |> get("api/v1/timelines/direct") + + [status] = json_response(res_conn, 200) + + assert %{"visibility" => "direct"} = status + # Both should be visible here res_conn = conn -- cgit v1.2.3 From 651a1d64b53db061cc6a24099e706a64cc6d6dd8 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Sat, 19 Jan 2019 04:25:15 +0300 Subject: Add current user to mentioned --- test/web/activity_pub/activity_pub_test.exs | 2 +- test/web/mastodon_api/mastodon_api_controller_test.exs | 2 +- test/web/mastodon_api/status_view_test.exs | 4 +++- test/web/twitter_api/views/activity_view_test.exs | 4 +--- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'test/web') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index eafb96f3a..6b1debc61 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -160,7 +160,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert activity.data["to"] == ["user1", "user2"] assert activity.actor == user.ap_id - assert activity.recipients == ["user1", "user2"] + assert activity.recipients == ["user1", "user2", user.ap_id] end end diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index ce3aa5a02..fdd3f1213 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -147,7 +147,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert %{"id" => id, "visibility" => "direct"} = json_response(conn, 200) assert activity = Repo.get(Activity, id) - assert activity.recipients == [user2.ap_id] + assert activity.recipients == [user2.ap_id, user1.ap_id] assert activity.data["to"] == [user2.ap_id] assert activity.data["cc"] == [] end diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index 1076b5002..5779a030e 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -119,7 +119,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do status = StatusView.render("status.json", %{activity: activity}) - assert status.mentions == [AccountView.render("mention.json", %{user: user})] + actor = Repo.get_by(User, ap_id: activity.actor) + + assert status.mentions == Enum.map([user, actor], fn u -> AccountView.render("mention.json", %{user: u}) end) end test "attachments" do diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 8b5a16add..4aa8c16bc 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -118,9 +118,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do expected = %{ "activity_type" => "post", "attachments" => [], - "attentions" => [ - UserView.render("show.json", %{user: other_user}) - ], + "attentions" => Enum.map([other_user, user], fn u -> UserView.render("show.json", %{user: u}) end), "created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(), "external_url" => activity.data["object"]["id"], "fave_num" => 0, -- cgit v1.2.3 From 0a97baddddbb8bf89c806f7e5b7cd754c88f4fe5 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Sat, 19 Jan 2019 04:26:52 +0300 Subject: Format --- test/web/mastodon_api/status_view_test.exs | 5 +++-- test/web/twitter_api/views/activity_view_test.exs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index 5779a030e..82bf71c70 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -120,8 +120,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do status = StatusView.render("status.json", %{activity: activity}) actor = Repo.get_by(User, ap_id: activity.actor) - - assert status.mentions == Enum.map([user, actor], fn u -> AccountView.render("mention.json", %{user: u}) end) + + assert status.mentions == + Enum.map([user, actor], fn u -> AccountView.render("mention.json", %{user: u}) end) end test "attachments" do diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 4aa8c16bc..0f514dab1 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -118,7 +118,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do expected = %{ "activity_type" => "post", "attachments" => [], - "attentions" => Enum.map([other_user, user], fn u -> UserView.render("show.json", %{user: u}) end), + "attentions" => + Enum.map([other_user, user], fn u -> UserView.render("show.json", %{user: u}) end), "created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(), "external_url" => activity.data["object"]["id"], "fave_num" => 0, -- cgit v1.2.3 From 28d77e373cbaf0908f86973a873c9bfd6c3221cb Mon Sep 17 00:00:00 2001 From: href Date: Wed, 9 Jan 2019 16:08:24 +0100 Subject: Flake Ids for Users and Activities --- test/web/twitter_api/twitter_api_controller_test.exs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/web') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index f22cdd870..863abd10f 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -797,7 +797,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do |> with_credentials(current_user.nickname, "test") |> post("/api/favorites/create/1.json") - assert json_response(conn, 500) + assert json_response(conn, 400) end end @@ -1621,7 +1621,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do conn = build_conn() |> assign(:user, user) - |> post("/api/pleroma/friendships/approve", %{"user_id" => to_string(other_user.id)}) + |> post("/api/pleroma/friendships/approve", %{"user_id" => other_user.id}) assert relationship = json_response(conn, 200) assert other_user.id == relationship["id"] @@ -1644,7 +1644,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do conn = build_conn() |> assign(:user, user) - |> post("/api/pleroma/friendships/deny", %{"user_id" => to_string(other_user.id)}) + |> post("/api/pleroma/friendships/deny", %{"user_id" => other_user.id}) assert relationship = json_response(conn, 200) assert other_user.id == relationship["id"] -- cgit v1.2.3 From 4333fea1dc2942526c78d97f3e8694fdc79b0575 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Wed, 23 Jan 2019 19:47:51 +0300 Subject: Send "hide_network" in user_view --- test/web/twitter_api/views/user_view_test.exs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test/web') diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 5f7481eb6..daf18c1c5 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -100,6 +100,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "locked" => false, "default_scope" => "public", "no_rich_text" => false, + "hide_network" => false, "fields" => [], "pleroma" => %{ "confirmation_pending" => false, @@ -146,6 +147,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "locked" => false, "default_scope" => "public", "no_rich_text" => false, + "hide_network" => false, "fields" => [], "pleroma" => %{ "confirmation_pending" => false, @@ -193,6 +195,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "locked" => false, "default_scope" => "public", "no_rich_text" => false, + "hide_network" => false, "fields" => [], "pleroma" => %{ "confirmation_pending" => false, @@ -254,6 +257,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "locked" => false, "default_scope" => "public", "no_rich_text" => false, + "hide_network" => false, "fields" => [], "pleroma" => %{ "confirmation_pending" => false, -- cgit v1.2.3 From 13d72826dfe3eab3b08f58800c63effb1e3cdfd6 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 24 Jan 2019 09:50:40 +0000 Subject: test: add anti-followbot policy tests --- .../mrf/anti_followbot_policy_test.exs | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test/web/activity_pub/mrf/anti_followbot_policy_test.exs (limited to 'test/web') diff --git a/test/web/activity_pub/mrf/anti_followbot_policy_test.exs b/test/web/activity_pub/mrf/anti_followbot_policy_test.exs new file mode 100644 index 000000000..2ea4f9d3f --- /dev/null +++ b/test/web/activity_pub/mrf/anti_followbot_policy_test.exs @@ -0,0 +1,57 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicyTest do + use Pleroma.DataCase + import Pleroma.Factory + + alias Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy + + describe "blocking based on attributes" do + test "matches followbots by nickname" do + actor = insert(:user, %{nickname: "followbot@example.com"}) + target = insert(:user) + + message = %{ + "@context" => "https://www.w3.org/ns/activitystreams", + "type" => "Follow", + "actor" => actor.ap_id, + "object" => target.ap_id, + "id" => "https://example.com/activities/1234" + } + + {:reject, nil} = AntiFollowbotPolicy.filter(message) + end + + test "matches followbots by display name" do + actor = insert(:user, %{name: "Federation Bot"}) + target = insert(:user) + + message = %{ + "@context" => "https://www.w3.org/ns/activitystreams", + "type" => "Follow", + "actor" => actor.ap_id, + "object" => target.ap_id, + "id" => "https://example.com/activities/1234" + } + + {:reject, nil} = AntiFollowbotPolicy.filter(message) + end + end + + test "it allows non-followbots" do + actor = insert(:user) + target = insert(:user) + + message = %{ + "@context" => "https://www.w3.org/ns/activitystreams", + "type" => "Follow", + "actor" => actor.ap_id, + "object" => target.ap_id, + "id" => "https://example.com/activities/1234" + } + + {:ok, _} = AntiFollowbotPolicy.filter(message) + end +end -- cgit v1.2.3 From 9274cabe01977a3c2d35059d7889c63e2bd54de1 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Thu, 24 Jan 2019 23:30:43 +0300 Subject: Use correct logic to determine "attentions" list --- test/web/twitter_api/views/activity_view_test.exs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test/web') diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 0f514dab1..8b5a16add 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -118,8 +118,9 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do expected = %{ "activity_type" => "post", "attachments" => [], - "attentions" => - Enum.map([other_user, user], fn u -> UserView.render("show.json", %{user: u}) end), + "attentions" => [ + UserView.render("show.json", %{user: other_user}) + ], "created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(), "external_url" => activity.data["object"]["id"], "fave_num" => 0, -- cgit v1.2.3 From a45a90348046902df831d3a69f98677d8a0329db Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 25 Jan 2019 10:51:06 +0300 Subject: Fix OGP provider tests --- test/web/metadata/opengraph_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/web') diff --git a/test/web/metadata/opengraph_test.exs b/test/web/metadata/opengraph_test.exs index c3502bad3..4283f72cd 100644 --- a/test/web/metadata/opengraph_test.exs +++ b/test/web/metadata/opengraph_test.exs @@ -48,7 +48,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do } }) - result = OpenGraph.build_tags(%{object: note, user: user}) + result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user}) assert Enum.all?( [ @@ -85,7 +85,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do } }) - result = OpenGraph.build_tags(%{object: note, user: user}) + result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user}) assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result -- cgit v1.2.3 From 499a4591a4689094bff597e30ce599a6fc189ea3 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 26 Jan 2019 04:23:52 +0100 Subject: Web.ActivityPub.ActivityPubTest: test against inserting activities with content: null --- test/web/activity_pub/activity_pub_test.exs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test/web') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index d2e54d804..91548ab5f 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -85,6 +85,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert {:error, {:remote_limit_error, _}} = ActivityPub.insert(data) end + test "doesn't drop activities with content being null" do + data = %{ + "ok" => true, + "object" => %{ + "content" => nil + } + } + + assert {:ok, _} = ActivityPub.insert(data) + end + test "returns the activity if one with the same id is already in" do activity = insert(:note_activity) {:ok, new_activity} = ActivityPub.insert(activity.data) -- cgit v1.2.3 From d8f446f438716cc1a474c9352e8cca8778a48d85 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 21 Dec 2018 19:34:08 +0100 Subject: Web.MastodonAPI.MastodonAPIControllerTest: Add test against multi-hashtag timeline --- .../mastodon_api/mastodon_api_controller_test.exs | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 6004285d6..be868c081 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -1044,6 +1044,30 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do end) end + test "multi-hashtag timeline", %{conn: conn} do + user = insert(:user) + + {:ok, activity_test} = CommonAPI.post(user, %{"status" => "#test"}) + {:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test1"}) + {:ok, activity_none} = CommonAPI.post(user, %{"status" => "#test #none"}) + + all_test = + conn + |> get("/api/v1/timelines/tag/test", %{"all" => ["test1"]}) + + assert [status_none, status_test1, status_test] = json_response(all_test, 200) + + assert to_string(activity_test.id) == status_test["id"] + assert to_string(activity_test1.id) == status_test1["id"] + assert to_string(activity_none.id) == status_none["id"] + + restricted_test = + conn + |> get("/api/v1/timelines/tag/test", %{"all" => ["test1"], "none" => ["none"]}) + + assert [status_test1, status_test] == json_response(restricted_test, 200) + end + test "getting followers", %{conn: conn} do user = insert(:user) other_user = insert(:user) -- cgit v1.2.3 From 4ad0ad14ed2d8a10bbf642fd989b3f7f55f9017d Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 10 Jan 2019 16:07:32 +0100 Subject: Web.ActivityPub.ActivityPub: Simplify multi-hashtag, add tests --- test/web/activity_pub/activity_pub_test.exs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/web') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index d2e54d804..acece36f0 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -64,6 +64,27 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert user.info.ap_enabled assert user.follower_address == "http://mastodon.example.org/users/admin/followers" end + + test "it fetches the appropriate tag-restricted posts" do + user = insert(:user) + + {:ok, status_one} = CommonAPI.post(user, %{"status" => ". #test"}) + {:ok, status_two} = CommonAPI.post(user, %{"status" => ". #essais"}) + {:ok, status_three} = CommonAPI.post(user, %{"status" => ". #test #reject"}) + + fetch_one = ActivityPub.fetch_activities([], %{"tag" => "test"}) + fetch_two = ActivityPub.fetch_activities([], %{"tag" => ["test", "essais"]}) + + fetch_three = + ActivityPub.fetch_activities([], %{ + "tag" => ["test", "essais"], + "tag_reject" => ["reject"] + }) + + assert fetch_one == [status_one, status_three] + assert fetch_two == [status_one, status_two, status_three] + assert fetch_three == [status_one, status_two] + end end describe "insertion" do -- cgit v1.2.3 From 5a84def6a6cd6ac782e16b2aace220a99c31ace7 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 10 Jan 2019 16:44:28 +0100 Subject: Fix the logic in multi-hashtag TLs --- test/web/activity_pub/activity_pub_test.exs | 7 +++++++ test/web/mastodon_api/mastodon_api_controller_test.exs | 10 +++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'test/web') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index acece36f0..48eed3f13 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -81,9 +81,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do "tag_reject" => ["reject"] }) + fetch_four = + ActivityPub.fetch_activities([], %{ + "tag" => ["test"], + "tag_all" => ["test", "reject"] + }) + assert fetch_one == [status_one, status_three] assert fetch_two == [status_one, status_two, status_three] assert fetch_three == [status_one, status_two] + assert fetch_four == [status_three] end end diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index be868c081..b4870e0b2 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -1051,11 +1051,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do {:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test1"}) {:ok, activity_none} = CommonAPI.post(user, %{"status" => "#test #none"}) - all_test = + any_test = conn - |> get("/api/v1/timelines/tag/test", %{"all" => ["test1"]}) + |> get("/api/v1/timelines/tag/test", %{"any" => ["none"]}) - assert [status_none, status_test1, status_test] = json_response(all_test, 200) + [status_none, status_test1, status_test] = json_response(any_test, 200) assert to_string(activity_test.id) == status_test["id"] assert to_string(activity_test1.id) == status_test1["id"] @@ -1066,6 +1066,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> get("/api/v1/timelines/tag/test", %{"all" => ["test1"], "none" => ["none"]}) assert [status_test1, status_test] == json_response(restricted_test, 200) + + all_test = conn |> get("/api/v1/timelines/tag/test", %{"all" => ["none"]}) + + assert [status_none] == json_response(all_test, 200) end test "getting followers", %{conn: conn} do -- cgit v1.2.3 From 22f2687f176a90d0d7d54d002e972d5f036c4579 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 22 Jan 2019 15:42:46 +0100 Subject: Web.MastodonAPI.MastodonAPIControllerTest: Update for difference between all and any parameters --- test/web/mastodon_api/mastodon_api_controller_test.exs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index b4870e0b2..3ca8d4651 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -1048,12 +1048,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do user = insert(:user) {:ok, activity_test} = CommonAPI.post(user, %{"status" => "#test"}) - {:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test1"}) + {:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test #test1"}) {:ok, activity_none} = CommonAPI.post(user, %{"status" => "#test #none"}) any_test = conn - |> get("/api/v1/timelines/tag/test", %{"any" => ["none"]}) + |> get("/api/v1/timelines/tag/test", %{"any" => ["test1"]}) [status_none, status_test1, status_test] = json_response(any_test, 200) @@ -1065,7 +1065,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do conn |> get("/api/v1/timelines/tag/test", %{"all" => ["test1"], "none" => ["none"]}) - assert [status_test1, status_test] == json_response(restricted_test, 200) + assert [status_test1] == json_response(restricted_test, 200) all_test = conn |> get("/api/v1/timelines/tag/test", %{"all" => ["none"]}) -- cgit v1.2.3 From d9f3af477d687fb8cb469ec652586911ad51d0b0 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 14 Jan 2019 00:05:45 +0100 Subject: Move definitions of RichMedia fixtures to test/support/http_request_mock.ex --- .../controllers/rich_media_controller_test.exs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'test/web') diff --git a/test/web/rich_media/controllers/rich_media_controller_test.exs b/test/web/rich_media/controllers/rich_media_controller_test.exs index 37c82631f..fef126513 100644 --- a/test/web/rich_media/controllers/rich_media_controller_test.exs +++ b/test/web/rich_media/controllers/rich_media_controller_test.exs @@ -1,19 +1,14 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.RichMedia.RichMediaControllerTest do use Pleroma.Web.ConnCase import Pleroma.Factory + import Tesla.Mock setup do - Tesla.Mock.mock(fn - %{ - method: :get, - url: "http://example.com/ogp" - } -> - %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")} - - %{method: :get, url: "http://example.com/empty"} -> - %Tesla.Env{status: 200, body: "hello"} - end) - + mock(fn env -> apply(HttpRequestMock, :request, [env]) end) :ok end -- cgit v1.2.3 From 3f64379b1382f2e26cacd28da230c67bf68656a0 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 14 Jan 2019 00:06:55 +0100 Subject: Web.MastodonAPI.MastodonAPIController: Add Rich-Media support --- test/web/mastodon_api/mastodon_api_controller_test.exs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 6004285d6..bc87383f7 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -1623,5 +1623,21 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> post("/api/v1/statuses/#{activity_two.id}/pin") |> json_response(400) end + + test "Status rich-media Card", %{conn: conn, user: user} do + {:ok, activity} = CommonAPI.post(user, %{"status" => "http://example.com/ogp"}) + + response = + conn + |> get("/api/v1/statuses/#{activity.id}/card") + |> json_response(200) + + assert response == %{ + "image" => "http://ia.media-imdb.com/images/rock.jpg", + "title" => "The Rock", + "type" => "link", + "url" => "http://www.imdb.com/title/tt0117500/" + } + end end end -- cgit v1.2.3 From 1f7843b9b8afcb559c8ba59388724dbf4ef3e3c9 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 26 Jan 2019 15:20:27 +0000 Subject: mastodon api: use OGP uri instead of page_url for deducing domain name, fix test --- test/web/mastodon_api/mastodon_api_controller_test.exs | 1 + 1 file changed, 1 insertion(+) (limited to 'test/web') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index bc87383f7..55e778e4f 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -1634,6 +1634,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert response == %{ "image" => "http://ia.media-imdb.com/images/rock.jpg", + "provider_name" => "www.imdb.com", "title" => "The Rock", "type" => "link", "url" => "http://www.imdb.com/title/tt0117500/" -- cgit v1.2.3 From a65c18859307f4aacf42eb5dd14e63ad76747a6d Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sun, 27 Jan 2019 10:21:13 +0100 Subject: Web.MastodonAPI.AccountView: Add is_moderator and is_admin Closes: https://git.pleroma.social/pleroma/pleroma/issues/557 --- test/web/mastodon_api/account_view_test.exs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'test/web') diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs index d53e11963..f8cd68173 100644 --- a/test/web/mastodon_api/account_view_test.exs +++ b/test/web/mastodon_api/account_view_test.exs @@ -61,7 +61,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do }, pleroma: %{ confirmation_pending: false, - tags: [] + tags: [], + is_admin: false, + is_moderator: false } } @@ -102,7 +104,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do }, pleroma: %{ confirmation_pending: false, - tags: [] + tags: [], + is_admin: false, + is_moderator: false } } -- cgit v1.2.3 From 1825118fd46883cb2a9132b039925c160ad7e57b Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 28 Jan 2019 11:41:47 +0100 Subject: Correctly handle invalid credentials on auth login. Closes #407 --- test/web/oauth/oauth_controller_test.exs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/web') diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs index ccd552258..e0d3cb55f 100644 --- a/test/web/oauth/oauth_controller_test.exs +++ b/test/web/oauth/oauth_controller_test.exs @@ -34,6 +34,31 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do assert Repo.get_by(Authorization, token: code) end + test "correctly handles wrong credentials", %{conn: conn} do + user = insert(:user) + app = insert(:oauth_app) + + result = + conn + |> post("/oauth/authorize", %{ + "authorization" => %{ + "name" => user.nickname, + "password" => "wrong", + "client_id" => app.client_id, + "redirect_uri" => app.redirect_uris, + "state" => "statepassed" + } + }) + |> html_response(:unauthorized) + + # Keep the details + assert result =~ app.client_id + assert result =~ app.redirect_uris + + # Error message + assert result =~ "Invalid" + end + test "issues a token for an all-body request" do user = insert(:user) app = insert(:oauth_app) -- cgit v1.2.3