diff options
author | Alex Gleason <alex@alexgleason.me> | 2020-10-08 15:44:48 -0500 |
---|---|---|
committer | Alex Gleason <alex@alexgleason.me> | 2020-10-08 15:44:48 -0500 |
commit | 77b1ea68a7700ac4a78c7f2e0ea9f118441d23da (patch) | |
tree | 06243af101a609256b517f48175380a7c4f5bfbb /test/web/instances/instance_test.exs | |
parent | 4af1b803811cbb59d41f0149706d6dda340b4755 (diff) | |
parent | 74be4de3f6c2c34447029649526637411acfa9f3 (diff) | |
download | pleroma-77b1ea68a7700ac4a78c7f2e0ea9f118441d23da.tar.gz pleroma-77b1ea68a7700ac4a78c7f2e0ea9f118441d23da.zip |
Merge remote-tracking branch 'upstream/develop' into aliases
Diffstat (limited to 'test/web/instances/instance_test.exs')
-rw-r--r-- | test/web/instances/instance_test.exs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/web/instances/instance_test.exs b/test/web/instances/instance_test.exs index e463200ca..4f0805100 100644 --- a/test/web/instances/instance_test.exs +++ b/test/web/instances/instance_test.exs @@ -8,6 +8,7 @@ defmodule Pleroma.Instances.InstanceTest do use Pleroma.DataCase + import ExUnit.CaptureLog import Pleroma.Factory setup_all do: clear_config([:instance, :federation_reachability_timeout_days], 1) @@ -97,4 +98,55 @@ defmodule Pleroma.Instances.InstanceTest do assert initial_value == instance.unreachable_since end end + + describe "get_or_update_favicon/1" do + test "Scrapes favicon URLs" do + Tesla.Mock.mock(fn %{url: "https://favicon.example.org/"} -> + %Tesla.Env{ + status: 200, + body: ~s[<html><head><link rel="icon" href="/favicon.png"></head></html>] + } + end) + + assert "https://favicon.example.org/favicon.png" == + Instance.get_or_update_favicon(URI.parse("https://favicon.example.org/")) + end + + test "Returns nil on too long favicon URLs" do + long_favicon_url = + "https://Lorem.ipsum.dolor.sit.amet/consecteturadipiscingelit/Praesentpharetrapurusutaliquamtempus/Mauriseulaoreetarcu/atfacilisisorci/Nullamporttitor/nequesedfeugiatmollis/dolormagnaefficiturlorem/nonpretiumsapienorcieurisus/Nullamveleratsem/Maecenassedaccumsanexnam/favicon.png" + + Tesla.Mock.mock(fn %{url: "https://long-favicon.example.org/"} -> + %Tesla.Env{ + status: 200, + body: + ~s[<html><head><link rel="icon" href="] <> long_favicon_url <> ~s["></head></html>] + } + end) + + assert capture_log(fn -> + assert nil == + Instance.get_or_update_favicon( + URI.parse("https://long-favicon.example.org/") + ) + end) =~ + "Instance.get_or_update_favicon(\"long-favicon.example.org\") error: %Postgrex.Error{" + end + + test "Handles not getting a favicon URL properly" do + Tesla.Mock.mock(fn %{url: "https://no-favicon.example.org/"} -> + %Tesla.Env{ + status: 200, + body: ~s[<html><head><h1>I wil look down and whisper "GNO.."</h1></head></html>] + } + end) + + refute capture_log(fn -> + assert nil == + Instance.get_or_update_favicon( + URI.parse("https://no-favicon.example.org/") + ) + end) =~ "Instance.scrape_favicon(\"https://no-favicon.example.org/\") error: " + end + end end |