From f9d13558c8198bf2a25035dfb3c112aaa2be4cbf Mon Sep 17 00:00:00 2001 From: eal Date: Sun, 12 Aug 2018 22:24:10 +0300 Subject: CommonAPI: add emoji to user source data on update --- test/web/common_api/common_api_test.exs | 11 +++++++++++ test/web/common_api/common_api_utils_test.exs | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'test/web/common_api') diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index a5da271b3..2a2c40833 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -1,6 +1,7 @@ defmodule Pleroma.Web.CommonAPI.Test do use Pleroma.DataCase alias Pleroma.Web.CommonAPI + alias Pleroma.User import Pleroma.Factory @@ -10,4 +11,14 @@ defmodule Pleroma.Web.CommonAPI.Test do assert activity.data["object"]["tag"] == ["2hu"] end + + test "it adds emoji when updating profiles" do + user = insert(:user, %{name: ":karjalanpiirakka:"}) + + CommonAPI.update(user) + user = User.get_cached_by_ap_id(user.ap_id) + [karjalanpiirakka] = user.info["source_data"]["tag"] + + assert karjalanpiirakka["name"] == ":karjalanpiirakka:" + end end diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs index f39472ee3..cf97b2bfd 100644 --- a/test/web/common_api/common_api_utils_test.exs +++ b/test/web/common_api/common_api_utils_test.exs @@ -1,5 +1,6 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do alias Pleroma.Web.CommonAPI.Utils + alias Pleroma.Web.Endpoint alias Pleroma.Builders.{UserBuilder} use Pleroma.DataCase @@ -29,4 +30,23 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do assert Utils.confirm_current_password(user, "test") == {:ok, user} end end + + test "parses emoji from name and bio" do + {:ok, user} = UserBuilder.insert(%{name: ":karjalanpiirakka:", bio: ":perkele:"}) + + expected = [ + %{ + "type" => "Emoji", + "icon" => %{"url" => "#{Endpoint.url()}/finmoji/128px/perkele-128.png"}, + "name" => ":perkele:" + }, + %{ + "type" => "Emoji", + "icon" => %{"url" => "#{Endpoint.url()}/finmoji/128px/karjalanpiirakka-128.png"}, + "name" => ":karjalanpiirakka:" + } + ] + + assert expected == Utils.emoji_from_profile(user) + end end -- cgit v1.2.3 From 92caa2632ba559961ebceccc9c0b44fbb8af05ed Mon Sep 17 00:00:00 2001 From: eal Date: Mon, 13 Aug 2018 16:21:18 +0300 Subject: Use Image type for emoji icons. --- test/web/common_api/common_api_utils_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/web/common_api') diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs index cf97b2bfd..f7d614582 100644 --- a/test/web/common_api/common_api_utils_test.exs +++ b/test/web/common_api/common_api_utils_test.exs @@ -37,12 +37,12 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do expected = [ %{ "type" => "Emoji", - "icon" => %{"url" => "#{Endpoint.url()}/finmoji/128px/perkele-128.png"}, + "icon" => %{"type" => "Image", "url" => "#{Endpoint.url()}/finmoji/128px/perkele-128.png"}, "name" => ":perkele:" }, %{ "type" => "Emoji", - "icon" => %{"url" => "#{Endpoint.url()}/finmoji/128px/karjalanpiirakka-128.png"}, + "icon" => %{"type" => "Image", "url" => "#{Endpoint.url()}/finmoji/128px/karjalanpiirakka-128.png"}, "name" => ":karjalanpiirakka:" } ] -- cgit v1.2.3 From 86dca3964084c3c1b1a9c0d051ac5e214ff03c94 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 26 Aug 2018 23:19:45 +0000 Subject: tests: fix formatting --- test/web/common_api/common_api_utils_test.exs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/web/common_api') diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs index f7d614582..b01ce04f8 100644 --- a/test/web/common_api/common_api_utils_test.exs +++ b/test/web/common_api/common_api_utils_test.exs @@ -42,7 +42,10 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do }, %{ "type" => "Emoji", - "icon" => %{"type" => "Image", "url" => "#{Endpoint.url()}/finmoji/128px/karjalanpiirakka-128.png"}, + "icon" => %{ + "type" => "Image", + "url" => "#{Endpoint.url()}/finmoji/128px/karjalanpiirakka-128.png" + }, "name" => ":karjalanpiirakka:" } ] -- cgit v1.2.3 From e7871ed05e9ebc8e2fe2f1afe966285e767c682f Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 31 Aug 2018 03:34:56 +0000 Subject: tests: add tests for evil HTML filtering --- test/web/common_api/common_api_test.exs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'test/web/common_api') diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index 2a2c40833..cd5aca961 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -21,4 +21,36 @@ defmodule Pleroma.Web.CommonAPI.Test do assert karjalanpiirakka["name"] == ":karjalanpiirakka:" end + + describe "posting" do + test "it filters out obviously bad tags when accepting a post as HTML" do + user = insert(:user) + + post = "

2hu

" + + {:ok, activity} = + CommonAPI.post(user, %{ + "status" => post, + "content_type" => "text/html" + }) + + content = activity.data["object"]["content"] + assert content == "

2hu

alert('xss')" + end + + test "it filters out obviously bad tags when accepting a post as Markdown" do + user = insert(:user) + + post = "

2hu

" + + {:ok, activity} = + CommonAPI.post(user, %{ + "status" => post, + "content_type" => "text/markdown" + }) + + content = activity.data["object"]["content"] + assert content == "

2hu

alert('xss')" + end + end end -- cgit v1.2.3 From 58539e13573681238fdd4d4e7334666389084be3 Mon Sep 17 00:00:00 2001 From: lambda Date: Fri, 31 Aug 2018 09:51:20 +0000 Subject: Revert "Merge branch 'feature/rich-text' into 'develop'" This reverts merge request !309 --- test/web/common_api/common_api_test.exs | 32 -------------------------------- 1 file changed, 32 deletions(-) (limited to 'test/web/common_api') diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index cd5aca961..2a2c40833 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -21,36 +21,4 @@ defmodule Pleroma.Web.CommonAPI.Test do assert karjalanpiirakka["name"] == ":karjalanpiirakka:" end - - describe "posting" do - test "it filters out obviously bad tags when accepting a post as HTML" do - user = insert(:user) - - post = "

2hu

" - - {:ok, activity} = - CommonAPI.post(user, %{ - "status" => post, - "content_type" => "text/html" - }) - - content = activity.data["object"]["content"] - assert content == "

2hu

alert('xss')" - end - - test "it filters out obviously bad tags when accepting a post as Markdown" do - user = insert(:user) - - post = "

2hu

" - - {:ok, activity} = - CommonAPI.post(user, %{ - "status" => post, - "content_type" => "text/markdown" - }) - - content = activity.data["object"]["content"] - assert content == "

2hu

alert('xss')" - end - end end -- cgit v1.2.3 From b1be9415effadf81e557eddee3f60bdf0fa359af Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 2 Sep 2018 00:14:25 +0000 Subject: Revert "Merge branch 'revert-a26d5e6b' into 'develop'" This reverts commit d31bbb1cfe04ca6073a322bcf77239e7d4b79839, reversing changes made to 340ab3cb9068d444b77213e07beb8c2c3ca128b9. --- test/web/common_api/common_api_test.exs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'test/web/common_api') diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index 2a2c40833..cd5aca961 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -21,4 +21,36 @@ defmodule Pleroma.Web.CommonAPI.Test do assert karjalanpiirakka["name"] == ":karjalanpiirakka:" end + + describe "posting" do + test "it filters out obviously bad tags when accepting a post as HTML" do + user = insert(:user) + + post = "

2hu

" + + {:ok, activity} = + CommonAPI.post(user, %{ + "status" => post, + "content_type" => "text/html" + }) + + content = activity.data["object"]["content"] + assert content == "

2hu

alert('xss')" + end + + test "it filters out obviously bad tags when accepting a post as Markdown" do + user = insert(:user) + + post = "

2hu

" + + {:ok, activity} = + CommonAPI.post(user, %{ + "status" => post, + "content_type" => "text/markdown" + }) + + content = activity.data["object"]["content"] + assert content == "

2hu

alert('xss')" + end + end end -- cgit v1.2.3 From 497814cbbb4baea91b2882fbddd5cd8d5ad6e170 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 5 Oct 2018 21:11:22 +0000 Subject: test: update test for new html scrub policy --- test/web/common_api/common_api_test.exs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/web/common_api') diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index cd5aca961..cd36e409c 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -26,7 +26,7 @@ defmodule Pleroma.Web.CommonAPI.Test do test "it filters out obviously bad tags when accepting a post as HTML" do user = insert(:user) - post = "

2hu

" + post = "

2hu

" {:ok, activity} = CommonAPI.post(user, %{ @@ -35,13 +35,13 @@ defmodule Pleroma.Web.CommonAPI.Test do }) content = activity.data["object"]["content"] - assert content == "

2hu

alert('xss')" + assert content == "

2hu

alert('xss')" end test "it filters out obviously bad tags when accepting a post as Markdown" do user = insert(:user) - post = "

2hu

" + post = "

2hu

" {:ok, activity} = CommonAPI.post(user, %{ @@ -50,7 +50,7 @@ defmodule Pleroma.Web.CommonAPI.Test do }) content = activity.data["object"]["content"] - assert content == "

2hu

alert('xss')" + assert content == "

2hu

alert('xss')" end end end -- cgit v1.2.3