1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.RichMedia.ParserTest do
6 use ExUnit.Case, async: true
12 url: "http://example.com/ogp"
14 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}
18 url: "http://example.com/non-ogp"
20 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/non_ogp_embed.html")}
24 url: "http://example.com/ogp-missing-title"
28 body: File.read!("test/fixtures/rich_media/ogp-missing-title.html")
33 url: "http://example.com/twitter-card"
35 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/twitter_card.html")}
39 url: "http://example.com/oembed"
41 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/oembed.html")}
45 url: "http://example.com/oembed.json"
47 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/oembed.json")}
49 %{method: :get, url: "http://example.com/empty"} ->
50 %Tesla.Env{status: 200, body: "hello"}
56 test "returns error when no metadata present" do
57 assert {:error, _} = Pleroma.Web.RichMedia.Parser.parse("http://example.com/empty")
60 test "doesn't just add a title" do
61 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/non-ogp") ==
62 {:error, "Found metadata was invalid or incomplete: %{}"}
66 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/ogp") ==
69 image: "http://ia.media-imdb.com/images/rock.jpg",
72 "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
74 url: "http://www.imdb.com/title/tt0117500/"
78 test "falls back to <title> when ogp:title is missing" do
79 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/ogp-missing-title") ==
82 image: "http://ia.media-imdb.com/images/rock.jpg",
83 title: "The Rock (1996)",
85 "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
87 url: "http://www.imdb.com/title/tt0117500/"
91 test "parses twitter card" do
92 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/twitter-card") ==
97 image: "https://farm6.staticflickr.com/5510/14338202952_93595258ff_z.jpg",
98 title: "Small Island Developing States Photo Submission",
99 description: "View the album on Flickr."
103 test "parses OEmbed" do
104 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/oembed") ==
107 author_name: "bees",
108 author_url: "https://www.flickr.com/photos/bees/",
110 flickr_type: "photo",
113 "<a data-flickr-embed=\"true\" href=\"https://www.flickr.com/photos/bees/2362225867/\" title=\"Bacon Lollys by bees, on Flickr\"><img src=\"https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_b.jpg\" width=\"1024\" height=\"768\" alt=\"Bacon Lollys\"></a><script async src=\"https://embedr.flickr.com/assets/client-code.js\" charset=\"utf-8\"></script>",
114 license: "All Rights Reserved",
116 provider_name: "Flickr",
117 provider_url: "https://www.flickr.com/",
118 thumbnail_height: 150,
119 thumbnail_url: "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_q.jpg",
120 thumbnail_width: 150,
121 title: "Bacon Lollys",
123 url: "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_b.jpg",
125 web_page: "https://www.flickr.com/photos/bees/2362225867/",
126 web_page_short_url: "https://flic.kr/p/4AK2sc",
131 test "rejects invalid OGP data" do
132 assert {:error, _} = Pleroma.Web.RichMedia.Parser.parse("http://example.com/malformed")