add inbound language test
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending

This commit is contained in:
FloatingGhost 2023-01-11 15:42:13 +00:00
parent 78c44f31ca
commit ff5793198f
4 changed files with 59 additions and 1 deletions

View file

@ -30,7 +30,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator do
field(:replies, {:array, ObjectValidators.ObjectID}, default: []) field(:replies, {:array, ObjectValidators.ObjectID}, default: [])
field(:source, :map) field(:source, :map)
field(:content_map, :map) field(:contentMap, :map)
end end
def cast_and_apply(data) do def cast_and_apply(data) do
@ -155,6 +155,7 @@ defp fix_content_map_languages(%{"contentMap" => content_map} = object)
|> Enum.reject(fn {lang, _content} -> |> Enum.reject(fn {lang, _content} ->
!Pleroma.ISO639.valid_alpha2?(lang) !Pleroma.ISO639.valid_alpha2?(lang)
end) end)
|> Enum.into(%{})
Map.put(object, "contentMap", content_map) Map.put(object, "contentMap", content_map)
end end

View file

@ -0,0 +1,38 @@
{
"@context": [
"https://www.w3.org/ns/activitystreams",
{
"ostatus": "http://ostatus.org#",
"atomUri": "ostatus:atomUri",
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
"conversation": "ostatus:conversation",
"sensitive": "as:sensitive",
"toot": "http://joinmastodon.org/ns#",
"votersCount": "toot:votersCount"
}
],
"id": "https://mastodon.social/users/akkoma_ap_integration_tester/statuses/109671288784583764",
"type": "Note",
"summary": null,
"inReplyTo": null,
"published": "2023-01-11T15:31:01Z",
"url": "https://mastodon.social/@akkoma_ap_integration_tester/109671288784583764",
"attributedTo": "https://mastodon.social/users/akkoma_ap_integration_tester",
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"cc": [
"https://mastodon.social/users/akkoma_ap_integration_tester/followers"
],
"sensitive": false,
"atomUri": "https://mastodon.social/users/akkoma_ap_integration_tester/statuses/109671288784583764",
"inReplyToAtomUri": null,
"conversation": "tag:mastodon.social,2023-01-11:objectId=376794415:objectType=Conversation",
"content": "<p>tag</p>",
"contentMap": {
"ja": "<p>tag</p>"
},
"attachment": [],
"tag": [],
"replies": []
}

View file

@ -0,0 +1,11 @@
defmodule Pleroma.ISO639Test do
use Pleroma.DataCase
describe "ISO639 validation" do
test "should validate a language" do
assert Pleroma.ISO639.valid_alpha2?("en")
assert Pleroma.ISO639.valid_alpha2?("ja")
refute Pleroma.ISO639.valid_alpha2?("xx")
end
end
end

View file

@ -39,6 +39,14 @@ test "a basic note validates", %{note: note} do
%{valid?: true} = ArticleNotePageValidator.cast_and_validate(note) %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
end end
test "a note with a language validates" do
user = insert(:user, %{ap_id: "https://mastodon.social/users/akkoma_ap_integration_tester"})
note = File.read!("test/fixtures/mastodon/note_with_language.json") |> Jason.decode!()
%{valid?: true, changes: %{ contentMap: %{
"ja" => "<p>tag</p>",
}}} = ArticleNotePageValidator.cast_and_validate(note)
end
test "a note from factory validates" do test "a note from factory validates" do
note = insert(:note) note = insert(:note)
%{valid?: true} = ArticleNotePageValidator.cast_and_validate(note.data) %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note.data)