activitypub: user view: do not expose oAuth endpoints for instance users
authorWilliam Pitcock <nenolod@dereferenced.org>
Thu, 14 Feb 2019 02:41:21 +0000 (02:41 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Thu, 14 Feb 2019 02:41:21 +0000 (02:41 +0000)
lib/pleroma/web/activity_pub/views/user_view.ex
test/web/activity_pub/views/user_view_test.exs

index 035463de2c861f6e15866ac0736365177c4d110a..b363a3dc46e880ef676f9e8523f268edbdb90042 100644 (file)
@@ -17,7 +17,11 @@ defmodule Pleroma.Web.ActivityPub.UserView do
 
   import Ecto.Query
 
-  def render("endpoints.json", %{user: %User{nickname: _nickname, local: true} = _user}) do
+  def render("endpoints.json", %{user: %User{nickname: nil, local: true} = _user}) do
+    %{"sharedInbox" => Helpers.activity_pub_url(Endpoint, :inbox)}
+  end
+
+  def render("endpoints.json", %{user: %User{local: true} = _user}) do
     %{
       "oauthAuthorizationEndpoint" => Helpers.o_auth_url(Endpoint, :authorize),
       "oauthRegistrationEndpoint" => Helpers.mastodon_api_url(Endpoint, :create_app),
index 95d736c505eb8aefb1196d4a3316a29f92c9555e..0bc1d4728f2296f29b5c52cae442beef1b139fa0 100644 (file)
@@ -42,5 +42,16 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
       assert result["id"] == user.ap_id
       assert result["endpoints"] == %{}
     end
+
+    test "instance users do not expose oAuth endpoints" do
+      user = insert(:user, nickname: nil, local: true)
+      {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
+
+      result = UserView.render("user.json", %{user: user})
+
+      refute result["endpoints"]["oauthAuthorizationEndpoint"]
+      refute result["endpoints"]["oauthRegistrationEndpoint"]
+      refute result["endpoints"]["oauthTokenEndpoint"]
+    end
   end
 end