tests: add tests for contain_origin_from_id()
authorWilliam Pitcock <nenolod@dereferenced.org>
Sat, 17 Nov 2018 20:07:49 +0000 (20:07 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Sat, 17 Nov 2018 20:16:03 +0000 (20:16 +0000)
test/web/activity_pub/transmogrifier_test.exs

index 6320b5b6e9c8dae48458b311a9b8251dcc3520d7..b8adf3b8acefea48bfa248884efaa3b92e53a92e 100644 (file)
@@ -918,4 +918,42 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
       :error = Transmogrifier.handle_incoming(data)
     end
   end
+
+  describe "general origin containment" do
+    test "contain_origin_from_id() catches obvious spoofing attempts" do
+      data = %{
+        "id" => "http://example.com/~alyssa/activities/1234.json"
+      }
+
+      :error =
+        Transmogrifier.contain_origin_from_id(
+          "http://example.org/~alyssa/activities/1234.json",
+          data
+        )
+    end
+
+    test "contain_origin_from_id() allows alternate IDs within the same origin domain" do
+      data = %{
+        "id" => "http://example.com/~alyssa/activities/1234.json"
+      }
+
+      :ok =
+        Transmogrifier.contain_origin_from_id(
+          "http://example.com/~alyssa/activities/1234",
+          data
+        )
+    end
+
+    test "contain_origin_from_id() allows matching IDs" do
+      data = %{
+        "id" => "http://example.com/~alyssa/activities/1234.json"
+      }
+
+      :ok =
+        Transmogrifier.contain_origin_from_id(
+          "http://example.com/~alyssa/activities/1234.json",
+          data
+        )
+    end
+  end
 end