2017-12-11 17:19:46 +00:00
|
|
|
defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
alias Pleroma.Web.ActivityPub.UserView
|
|
|
|
|
|
|
|
test "Renders a user, including the public key" do
|
|
|
|
user = insert(:user)
|
|
|
|
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
|
|
|
|
|
|
|
|
result = UserView.render("user.json", %{user: user})
|
|
|
|
|
|
|
|
assert result["id"] == user.ap_id
|
|
|
|
assert result["preferredUsername"] == user.nickname
|
|
|
|
|
2018-07-12 02:45:48 +00:00
|
|
|
assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
|
2017-12-11 17:19:46 +00:00
|
|
|
end
|
2019-02-13 19:48:24 +00:00
|
|
|
|
|
|
|
describe "endpoints" do
|
|
|
|
test "local users have a usable endpoints structure" do
|
|
|
|
user = insert(:user)
|
|
|
|
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
|
|
|
|
|
|
|
|
result = UserView.render("user.json", %{user: user})
|
|
|
|
|
|
|
|
assert result["id"] == user.ap_id
|
|
|
|
|
|
|
|
%{
|
|
|
|
"sharedInbox" => _,
|
|
|
|
"oauthAuthorizationEndpoint" => _,
|
|
|
|
"oauthRegistrationEndpoint" => _,
|
|
|
|
"oauthTokenEndpoint" => _
|
|
|
|
} = result["endpoints"]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "remote users have an empty endpoints structure" do
|
|
|
|
user = insert(:user, local: false)
|
|
|
|
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
|
|
|
|
|
|
|
|
result = UserView.render("user.json", %{user: user})
|
|
|
|
|
|
|
|
assert result["id"] == user.ap_id
|
|
|
|
assert result["endpoints"] == %{}
|
|
|
|
end
|
2019-02-14 02:41:21 +00:00
|
|
|
|
|
|
|
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
|
2019-02-13 19:48:24 +00:00
|
|
|
end
|
2017-12-11 17:19:46 +00:00
|
|
|
end
|