From 0b01f3524e5939ff324c6a4684ea2be4ebf9dd06 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Sun, 14 Jun 2020 18:10:34 -0400 Subject: [PATCH] Add tests for Omnibot.Contrib.Linkbot Signed-off-by: Alek Ratzloff --- test/contrib/linkbot_test.exs | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 test/contrib/linkbot_test.exs diff --git a/test/contrib/linkbot_test.exs b/test/contrib/linkbot_test.exs new file mode 100644 index 0000000..9fcad67 --- /dev/null +++ b/test/contrib/linkbot_test.exs @@ -0,0 +1,48 @@ +defmodule LinkbotTest do + use ExUnit.Case + + alias Omnibot.Contrib.Linkbot + + test "blacklist blocks local addresses" do + blocked_hosts = [ + "localhost", + "remote", + "remote.local", + "remote.corp.local", + "127.0.0.1", + "192.168.0.1", + "192.168.1.1", + "192.168.1.255", + "10.1.1.24", + "10.1.1.255", + "172.1.1.22", + "172.1.1.255", + ] + allowed_hosts = [ + "local.tld", + "localhost.com", + "local.remote.com", + "remote.local.com", + ] + + Enum.each(blocked_hosts, fn host -> + assert Linkbot.blacklisted?("http://#{host}") + assert Linkbot.blacklisted?("http://#{host}/") + assert Linkbot.blacklisted?("http://foo:bar@#{host}/") + + assert Linkbot.blacklisted?("https://#{host}") + assert Linkbot.blacklisted?("https://#{host}/") + assert Linkbot.blacklisted?("https://foo:bar@#{host}/") + end) + + Enum.each(allowed_hosts, fn host -> + assert !Linkbot.blacklisted?("http://#{host}") + assert !Linkbot.blacklisted?("http://#{host}/") + assert !Linkbot.blacklisted?("http://foo:bar@#{host}/") + + assert !Linkbot.blacklisted?("https://#{host}") + assert !Linkbot.blacklisted?("https://#{host}/") + assert !Linkbot.blacklisted?("https://foo:bar@#{host}/") + end) + end +end