join us now and share the software~. Also tests
authorrinpatch <rinpatch@sdf.org>
Wed, 16 Jan 2019 14:15:13 +0000 (17:15 +0300)
committerrinpatch <rinpatch@sdf.org>
Wed, 16 Jan 2019 14:15:13 +0000 (17:15 +0300)
lib/pleroma/web/metadata.ex
lib/pleroma/web/metadata/opengraph.ex
lib/pleroma/web/metadata/provider.ex
lib/pleroma/web/metadata/twitter_card.ex
test/web/metadata/opengraph_test.exs [new file with mode: 0644]

index d859dfd8b938705e63a4aaaf9a9ee0a4e8eea278..8793fc265ec76dcfe1a78eed1752c5602c1870a4 100644 (file)
@@ -1,3 +1,6 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
 defmodule Pleroma.Web.Metadata do
   alias Phoenix.HTML
 
index f6a1f302316acd2a3cf0cf145d44f35def7c22a5..b7c5dc64e8e483fb83c55f661409a06976b317f6 100644 (file)
@@ -1,3 +1,6 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
 defmodule Pleroma.Web.Metadata.Providers.OpenGraph do
   alias Pleroma.Web.Metadata.Providers.Provider
   alias Pleroma.{HTML, Formatter, User}
index f64810fad41023a22566927bf343016204a083f8..a39008bccf8f6cdc4892dbb05ed096cf7d9214c3 100644 (file)
@@ -1,3 +1,6 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
 defmodule Pleroma.Web.Metadata.Providers.Provider do
   @callback build_tags(map()) :: list()
 end
index 3094e61fdf3a4af1681876f643e0dcd29b823f14..8537766112d804e68a6829783052dbc98b7af411 100644 (file)
@@ -1,3 +1,6 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
 defmodule Pleroma.Web.Metadata.Providers.TwitterCard do
   alias Pleroma.Web.Metadata.Providers.Provider
 
diff --git a/test/web/metadata/opengraph_test.exs b/test/web/metadata/opengraph_test.exs
new file mode 100644 (file)
index 0000000..be3f893
--- /dev/null
@@ -0,0 +1,113 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# 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