Question: Add tests on HTML tags in options

Closes: https://git.pleroma.social/pleroma/pleroma/-/issues/1362
This commit is contained in:
Haelwenn (lanodan) Monnier 2020-07-02 05:47:18 +02:00
parent bfe2dafd39
commit 922ca23298
No known key found for this signature in database
GPG Key ID: D5B7A8E43C997DEE
2 changed files with 64 additions and 0 deletions

View File

@ -55,6 +55,41 @@ test "Mastodon Question activity" 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!()

View File

@ -135,4 +135,33 @@ test "does not crash on polls with no end date" 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