From 8902942128e3aee814c215d700e2eaee21b491e9 Mon Sep 17 00:00:00 2001 From: raeno Date: Mon, 10 Dec 2018 23:08:02 +0400 Subject: WIP. Implement oembed route and handle both json/xml for "Note" type activity --- test/web/oembed/oembed_test.exs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/web/oembed/oembed_test.exs (limited to 'test') diff --git a/test/web/oembed/oembed_test.exs b/test/web/oembed/oembed_test.exs new file mode 100644 index 000000000..16c2c3598 --- /dev/null +++ b/test/web/oembed/oembed_test.exs @@ -0,0 +1,23 @@ +defmodule Pleroma.Web.OEmbedTest do + use Pleroma.DataCase + alias Pleroma.Web.OEmbed + alias Pleroma.Web.XML + alias Pleroma.{Object, Repo, User, Activity} + import Pleroma.Factory + import ExUnit.CaptureLog + + setup_all do + :ok + end + + test 'recognizes notices in given url' do + url = "https://pleroma.site/notice/5" + assert { :activity, _ } = OEmbed.recognize_path(url) + end + + test 'recognizes user card in given url' do + url = "https://pleroma.site/users/raeno" + assert { :user, _ } = OEmbed.recognize_path(url) + end + +end -- cgit v1.2.3 From b5de7c4c4d90d1049b59381953cbd76e79b77e66 Mon Sep 17 00:00:00 2001 From: raeno Date: Thu, 13 Dec 2018 22:16:54 +0100 Subject: Remove oembed for now, will submit it in another MR. Fix warnings --- test/web/oembed/oembed_test.exs | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 test/web/oembed/oembed_test.exs (limited to 'test') diff --git a/test/web/oembed/oembed_test.exs b/test/web/oembed/oembed_test.exs deleted file mode 100644 index 16c2c3598..000000000 --- a/test/web/oembed/oembed_test.exs +++ /dev/null @@ -1,23 +0,0 @@ -defmodule Pleroma.Web.OEmbedTest do - use Pleroma.DataCase - alias Pleroma.Web.OEmbed - alias Pleroma.Web.XML - alias Pleroma.{Object, Repo, User, Activity} - import Pleroma.Factory - import ExUnit.CaptureLog - - setup_all do - :ok - end - - test 'recognizes notices in given url' do - url = "https://pleroma.site/notice/5" - assert { :activity, _ } = OEmbed.recognize_path(url) - end - - test 'recognizes user card in given url' do - url = "https://pleroma.site/users/raeno" - assert { :user, _ } = OEmbed.recognize_path(url) - end - -end -- cgit v1.2.3 From c5c3ad90d00f1ea599e489aa03cfecada44c998c Mon Sep 17 00:00:00 2001 From: raeno Date: Fri, 14 Dec 2018 02:59:33 +0100 Subject: Fix tests. Remove oembed template --- test/web/ostatus/ostatus_controller_test.exs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index 560305c15..747e30154 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -84,6 +84,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do conn = conn + |> put_req_header("accept", "application/xml") |> get(url) expected = @@ -110,11 +111,12 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do |> response(404) end - test "gets an activity", %{conn: conn} do + test "gets an activity in xml format", %{conn: conn} do note_activity = insert(:note_activity) [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"])) conn + |> put_req_header("accept", "application/xml") |> get("/activities/#{uuid}") |> response(200) end @@ -134,7 +136,22 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do |> response(404) end - test "gets a notice", %{conn: conn} do + test "renders notice metatags in html format" do + note_activity = insert(:note_activity) + + conn = get(conn, "/notice/#{note_activity.id}") + + twitter_card_summary = "" + + description_content = + "" + + body = html_response(conn, 200) + assert body =~ twitter_card_summary + assert body =~ description_content + end + + test "gets a notice in xml format", %{conn: conn} do note_activity = insert(:note_activity) conn -- cgit v1.2.3 From 9ff61ed793b7fd968b51c5f6e4b72958adeae977 Mon Sep 17 00:00:00 2001 From: raeno Date: Fri, 14 Dec 2018 20:23:51 +0100 Subject: Fix tests Notice test has been failing due to missing placeholder in index.html I've tried to use fixtures to substitute that file in test environment but it became too much hassle. Fixtures are not copied to _build directory so I'd need to change file fetching logic. IMO it doesn't worth it since pleroma-fe already has this placeholder merged and all future updated of index.html will include it. --- test/web/ostatus/ostatus_controller_test.exs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index 747e30154..e9e9bdb16 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -136,17 +136,15 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do |> response(404) end - test "renders notice metatags in html format" do + test "renders notice metatags in html format", %{conn: conn} do note_activity = insert(:note_activity) - conn = get(conn, "/notice/#{note_activity.id}") - + body = html_response(conn, 200) twitter_card_summary = "" description_content = "" - body = html_response(conn, 200) assert body =~ twitter_card_summary assert body =~ description_content end -- cgit v1.2.3 From 8cea00e1dc2bf3c2e807b09fac886dfd7b4ea3e9 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 10:53:57 +0300 Subject: Remove OpenGraph test from Ostatus tests --- test/web/ostatus/ostatus_controller_test.exs | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'test') diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index 8e9d2b69a..5a94cb3b3 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -156,19 +156,6 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do |> response(404) end - test "renders notice metatags in html format", %{conn: conn} do - note_activity = insert(:note_activity) - conn = get(conn, "/notice/#{note_activity.id}") - body = html_response(conn, 200) - twitter_card_summary = "" - - description_content = - "" - - assert body =~ twitter_card_summary - assert body =~ description_content - end - test "gets a notice in xml format", %{conn: conn} do note_activity = insert(:note_activity) -- cgit v1.2.3 From 293f6a8b712246d0580f9eb113c798ae1ea3b634 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 17:15:13 +0300 Subject: join us now and share the software~. Also tests --- test/web/metadata/opengraph_test.exs | 113 +++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 test/web/metadata/opengraph_test.exs (limited to 'test') diff --git a/test/web/metadata/opengraph_test.exs b/test/web/metadata/opengraph_test.exs new file mode 100644 index 000000000..be3f89364 --- /dev/null +++ b/test/web/metadata/opengraph_test.exs @@ -0,0 +1,113 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only +defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do + use Pleroma.DataCase + import Pleroma.Factory + alias Pleroma.Web.Metadata.Providers.OpenGraph + + test "it renders all supported types of attachments and skips unknown types" do + user = insert(:user) + + note = + insert(:note, %{ + data: %{ + "actor" => user.ap_id, + "tag" => [], + "content" => "pleroma in a nutshell", + "attachment" => [ + %{ + "url" => [ + %{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"} + ] + }, + %{ + "url" => [ + %{ + "mediaType" => "application/octet-stream", + "href" => "https://pleroma.gov/fqa/badapple.sfc" + } + ] + }, + %{ + "url" => [ + %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"} + ] + }, + %{ + "url" => [ + %{ + "mediaType" => "audio/basic", + "href" => "http://www.gnu.org/music/free-software-song.au" + } + ] + } + ] + } + }) + + note_activity = + insert(:note_activity, %{ + data: %{ + "actor" => note.data["actor"], + "to" => note.data["to"], + "object" => note.data, + "context" => note.data["context"] + }, + actor: note.data["actor"], + recipients: note.data["to"] + }) + + result = OpenGraph.build_tags(%{activity: note_activity, user: user}) + + assert Enum.all?( + [ + {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []}, + {:meta, + [property: "og:audio", content: "http://www.gnu.org/music/free-software-song.au"], + []}, + {:meta, [property: "og:video", content: "https://pleroma.gov/about/juche.webm"], + []} + ], + fn element -> element in result end + ) + end + + test "it does not render attachments if post is nsfw" do + user = insert(:user, avatar: %{"url" => [%{"href" => "https://pleroma.gov/tenshi.png"}]}) + + note = + insert(:note, %{ + data: %{ + "actor" => user.ap_id, + "content" => "#cuteposting #nsfw #hambaga", + "tag" => ["cuteposting", "nsfw", "hambaga"], + "attachment" => [ + %{ + "url" => [ + %{"mediaType" => "image/png", "href" => "https://misskey.microsoft/corndog.png"} + ] + } + ] + } + }) + + note_activity = + insert(:note_activity, %{ + data: %{ + "actor" => note.data["actor"], + "to" => note.data["to"], + "object" => note.data, + "context" => note.data["context"] + }, + actor: note.data["actor"], + recipients: note.data["to"] + }) + + result = OpenGraph.build_tags(%{activity: note_activity, user: user}) + + assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result + + refute {:meta, [property: "og:image", content: "https://misskey.microsoft/corndog.png"], []} in result + end +end -- cgit v1.2.3 From 3b187896847637d93db194897565599acd73a57c Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 17 Jan 2019 11:08:50 +0300 Subject: Fix test --- test/web/metadata/opengraph_test.exs | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/web/metadata/opengraph_test.exs b/test/web/metadata/opengraph_test.exs index be3f89364..672942148 100644 --- a/test/web/metadata/opengraph_test.exs +++ b/test/web/metadata/opengraph_test.exs @@ -74,6 +74,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do end test "it does not render attachments if post is nsfw" do + Pleroma.Config.put([Pleroma.Web.Metadata, :unfurl_nsfw], false) user = insert(:user, avatar: %{"url" => [%{"href" => "https://pleroma.gov/tenshi.png"}]}) note = -- cgit v1.2.3 From 64143d8040a5806ccf9707644a7e7eacc91d74c6 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 17 Jan 2019 22:57:24 +0300 Subject: Fix object id in OpenGraph test --- test/web/metadata/opengraph_test.exs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test') diff --git a/test/web/metadata/opengraph_test.exs b/test/web/metadata/opengraph_test.exs index 672942148..1c4fadc46 100644 --- a/test/web/metadata/opengraph_test.exs +++ b/test/web/metadata/opengraph_test.exs @@ -14,6 +14,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do data: %{ "actor" => user.ap_id, "tag" => [], + "id" => "https://pleroma.gov/objects/whatever", "content" => "pleroma in a nutshell", "attachment" => [ %{ @@ -81,6 +82,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do insert(:note, %{ data: %{ "actor" => user.ap_id, + "id" => "https://pleroma.gov/objects/whatever", "content" => "#cuteposting #nsfw #hambaga", "tag" => ["cuteposting", "nsfw", "hambaga"], "attachment" => [ -- cgit v1.2.3 From 1b1af4798a74c4ab357140ef2c5928dd9ebd3221 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 18 Jan 2019 09:32:52 +0300 Subject: Use object instead of activity for metadata --- test/web/metadata/opengraph_test.exs | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) (limited to 'test') diff --git a/test/web/metadata/opengraph_test.exs b/test/web/metadata/opengraph_test.exs index 1c4fadc46..c3502bad3 100644 --- a/test/web/metadata/opengraph_test.exs +++ b/test/web/metadata/opengraph_test.exs @@ -1,6 +1,7 @@ # Pleroma: A lightweight social networking server # Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do use Pleroma.DataCase import Pleroma.Factory @@ -47,19 +48,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do } }) - note_activity = - insert(:note_activity, %{ - data: %{ - "actor" => note.data["actor"], - "to" => note.data["to"], - "object" => note.data, - "context" => note.data["context"] - }, - actor: note.data["actor"], - recipients: note.data["to"] - }) - - result = OpenGraph.build_tags(%{activity: note_activity, user: user}) + result = OpenGraph.build_tags(%{object: note, user: user}) assert Enum.all?( [ @@ -85,6 +74,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do "id" => "https://pleroma.gov/objects/whatever", "content" => "#cuteposting #nsfw #hambaga", "tag" => ["cuteposting", "nsfw", "hambaga"], + "sensitive" => true, "attachment" => [ %{ "url" => [ @@ -95,19 +85,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do } }) - note_activity = - insert(:note_activity, %{ - data: %{ - "actor" => note.data["actor"], - "to" => note.data["to"], - "object" => note.data, - "context" => note.data["context"] - }, - actor: note.data["actor"], - recipients: note.data["to"] - }) - - result = OpenGraph.build_tags(%{activity: note_activity, user: user}) + result = OpenGraph.build_tags(%{object: note, user: user}) assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result -- cgit v1.2.3 From 7bc6208b2fa53b04d0d319e62c7c9b34d18e0e44 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 18 Jan 2019 10:35:52 +0300 Subject: Fix ostatus test --- test/web/ostatus/ostatus_controller_test.exs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test') diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index 5a94cb3b3..954abf5fe 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -131,12 +131,14 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do object = Object.get_by_ap_id(note_activity.data["object"]["id"]) conn + |> put_req_header("accept", "application/xml") |> get("/objects/#{uuid}") |> response(200) Object.delete(object) conn + |> put_req_header("accept", "application/xml") |> get("/objects/#{uuid}") |> response(404) end -- cgit v1.2.3 From a45a90348046902df831d3a69f98677d8a0329db Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 25 Jan 2019 10:51:06 +0300 Subject: Fix OGP provider tests --- test/web/metadata/opengraph_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/web/metadata/opengraph_test.exs b/test/web/metadata/opengraph_test.exs index c3502bad3..4283f72cd 100644 --- a/test/web/metadata/opengraph_test.exs +++ b/test/web/metadata/opengraph_test.exs @@ -48,7 +48,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do } }) - result = OpenGraph.build_tags(%{object: note, user: user}) + result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user}) assert Enum.all?( [ @@ -85,7 +85,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do } }) - result = OpenGraph.build_tags(%{object: note, user: user}) + result = OpenGraph.build_tags(%{object: note, url: note.data["id"], user: user}) assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result -- cgit v1.2.3