Question: Add tests on HTML tags in options
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Thu, 2 Jul 2020 03:47:18 +0000 (05:47 +0200)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Wed, 15 Jul 2020 10:32:43 +0000 (12:32 +0200)
Closes: https://git.pleroma.social/pleroma/pleroma/-/issues/1362
test/web/activity_pub/transmogrifier/question_handling_test.exs
test/web/mastodon_api/views/poll_view_test.exs

index b7b9a1a7bb5c0f9786a7a7f54eaba8323c5d5bd9..fba8106b502b95d59dd348cd6a74bd3789b83b3b 100644 (file)
@@ -55,6 +55,41 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.QuestionHandlingTest do
              ])
   end
 
+  test "Mastodon Question activity with HTML tags in plaintext" do
+    options = [
+      %{
+        "type" => "Note",
+        "name" => "<input type=\"date\">",
+        "replies" => %{"totalItems" => 0, "type" => "Collection"}
+      },
+      %{
+        "type" => "Note",
+        "name" => "<input type=\"date\"/>",
+        "replies" => %{"totalItems" => 0, "type" => "Collection"}
+      },
+      %{
+        "type" => "Note",
+        "name" => "<input type=\"date\" />",
+        "replies" => %{"totalItems" => 1, "type" => "Collection"}
+      },
+      %{
+        "type" => "Note",
+        "name" => "<input type=\"date\"></input>",
+        "replies" => %{"totalItems" => 1, "type" => "Collection"}
+      }
+    ]
+
+    data =
+      File.read!("test/fixtures/mastodon-question-activity.json")
+      |> Poison.decode!()
+      |> Kernel.put_in(["object", "oneOf"], options)
+
+    {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
+    object = Object.normalize(activity, false)
+
+    assert Enum.sort(object.data["oneOf"]) == Enum.sort(options)
+  end
+
   test "returns an error if received a second time" do
     data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
 
index 76672f36c79bdf1f928b791d0b70ecfc049a9cbc..b7e2f17eff9faf85af39ba109f1ff0bc964d493e 100644 (file)
@@ -135,4 +135,33 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do
     assert result[:expires_at] == nil
     assert result[:expired] == false
   end
+
+  test "doesn't strips HTML tags" do
+    user = insert(:user)
+
+    {:ok, activity} =
+      CommonAPI.post(user, %{
+        status: "What's with the smug face?",
+        poll: %{
+          options: [
+            "<input type=\"date\">",
+            "<input type=\"date\" >",
+            "<input type=\"date\"/>",
+            "<input type=\"date\"></input>"
+          ],
+          expires_in: 20
+        }
+      })
+
+    object = Object.normalize(activity)
+
+    assert %{
+             options: [
+               %{title: "<input type=\"date\">", votes_count: 0},
+               %{title: "<input type=\"date\" >", votes_count: 0},
+               %{title: "<input type=\"date\"/>", votes_count: 0},
+               %{title: "<input type=\"date\"></input>", votes_count: 0}
+             ]
+           } = PollView.render("show.json", %{object: object})
+  end
 end