summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/plugs/http_signature_plug_test.exs44
-rw-r--r--test/web/twitter_api/twitter_api_controller_test.exs14
2 files changed, 50 insertions, 8 deletions
diff --git a/test/plugs/http_signature_plug_test.exs b/test/plugs/http_signature_plug_test.exs
new file mode 100644
index 000000000..a15c5b470
--- /dev/null
+++ b/test/plugs/http_signature_plug_test.exs
@@ -0,0 +1,44 @@
+defmodule Pleroma.Web.Plugs.HTTPSignaturePlugTest do
+ use Pleroma.Web.ConnCase
+ alias Pleroma.Web.HTTPSignatures
+ alias Pleroma.Web.Plugs.HTTPSignaturePlug
+
+ import Plug.Conn
+ import Mock
+
+ test "it call HTTPSignatures to check validity if the actor sighed it" do
+ params = %{"actor" => "http://mastodon.example.org/users/admin"}
+ conn = build_conn(:get, "/doesntmattter", params)
+
+ with_mock HTTPSignatures, validate_conn: fn _ -> true end do
+ conn =
+ conn
+ |> put_req_header(
+ "signature",
+ "keyId=\"http://mastodon.example.org/users/admin#main-key"
+ )
+ |> HTTPSignaturePlug.call(%{})
+
+ assert conn.assigns.valid_signature == true
+ assert called(HTTPSignatures.validate_conn(:_))
+ end
+ end
+
+ test "bails out early if the signature isn't by the activity actor" do
+ params = %{"actor" => "https://mst3k.interlinked.me/users/luciferMysticus"}
+ conn = build_conn(:get, "/doesntmattter", params)
+
+ with_mock HTTPSignatures, validate_conn: fn _ -> false end do
+ conn =
+ conn
+ |> put_req_header(
+ "signature",
+ "keyId=\"http://mastodon.example.org/users/admin#main-key"
+ )
+ |> HTTPSignaturePlug.call(%{})
+
+ assert conn.assigns.valid_signature == false
+ refute called(HTTPSignatures.validate_conn(:_))
+ end
+ end
+end
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 5abdc2e0e..2cbcfd086 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -600,8 +600,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> assign(:user, user)
|> get("/api/statuses/followers")
- assert json_response(conn, 200) ==
- UserView.render("index.json", %{users: [follower_one, follower_two], for: user})
+ expected = UserView.render("index.json", %{users: [follower_one, follower_two], for: user})
+ result = json_response(conn, 200)
+ assert Enum.sort(expected) == Enum.sort(result)
end
end
@@ -620,12 +621,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> assign(:user, user)
|> get("/api/statuses/friends")
- assert MapSet.equal?(
- MapSet.new(json_response(conn, 200)),
- MapSet.new(
- UserView.render("index.json", %{users: [followed_one, followed_two], for: user})
- )
- )
+ expected = UserView.render("index.json", %{users: [followed_one, followed_two], for: user})
+ result = json_response(conn, 200)
+ assert Enum.sort(expected) == Enum.sort(result)
end
test "it returns a given user's friends with user_id", %{conn: conn} do