2019-07-09 23:13:23 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2017-12-11 10:19:46 -07:00
|
|
|
defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
2019-05-21 21:58:15 -06:00
|
|
|
alias Pleroma.User
|
2017-12-11 10:19:46 -07:00
|
|
|
alias Pleroma.Web.ActivityPub.UserView
|
|
|
|
|
|
|
|
test "Renders a user, including the public key" do
|
|
|
|
user = insert(:user)
|
2019-05-21 21:58:15 -06:00
|
|
|
{:ok, user} = User.ensure_keys_present(user)
|
2017-12-11 10:19:46 -07:00
|
|
|
|
|
|
|
result = UserView.render("user.json", %{user: user})
|
|
|
|
|
|
|
|
assert result["id"] == user.ap_id
|
|
|
|
assert result["preferredUsername"] == user.nickname
|
|
|
|
|
2018-07-11 20:45:48 -06:00
|
|
|
assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
|
2017-12-11 10:19:46 -07:00
|
|
|
end
|
2019-02-13 12:48:24 -07:00
|
|
|
|
2019-03-26 09:40:09 -06:00
|
|
|
test "Does not add an avatar image if the user hasn't set one" do
|
|
|
|
user = insert(:user)
|
2019-05-21 21:58:15 -06:00
|
|
|
{:ok, user} = User.ensure_keys_present(user)
|
2019-03-26 09:40:09 -06:00
|
|
|
|
|
|
|
result = UserView.render("user.json", %{user: user})
|
|
|
|
refute result["icon"]
|
|
|
|
refute result["image"]
|
|
|
|
|
|
|
|
user =
|
|
|
|
insert(:user,
|
|
|
|
avatar: %{"url" => [%{"href" => "https://someurl"}]},
|
|
|
|
info: %{
|
|
|
|
banner: %{"url" => [%{"href" => "https://somebanner"}]}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2019-05-21 21:58:15 -06:00
|
|
|
{:ok, user} = User.ensure_keys_present(user)
|
2019-03-26 09:40:09 -06:00
|
|
|
|
|
|
|
result = UserView.render("user.json", %{user: user})
|
|
|
|
assert result["icon"]["url"] == "https://someurl"
|
|
|
|
assert result["image"]["url"] == "https://somebanner"
|
|
|
|
end
|
|
|
|
|
2019-02-13 12:48:24 -07:00
|
|
|
describe "endpoints" do
|
|
|
|
test "local users have a usable endpoints structure" do
|
|
|
|
user = insert(:user)
|
2019-05-21 21:58:15 -06:00
|
|
|
{:ok, user} = User.ensure_keys_present(user)
|
2019-02-13 12:48:24 -07:00
|
|
|
|
|
|
|
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)
|
2019-05-21 21:58:15 -06:00
|
|
|
{:ok, user} = User.ensure_keys_present(user)
|
2019-02-13 12:48:24 -07:00
|
|
|
|
|
|
|
result = UserView.render("user.json", %{user: user})
|
|
|
|
|
|
|
|
assert result["id"] == user.ap_id
|
|
|
|
assert result["endpoints"] == %{}
|
|
|
|
end
|
2019-02-13 19:41:21 -07:00
|
|
|
|
|
|
|
test "instance users do not expose oAuth endpoints" do
|
|
|
|
user = insert(:user, nickname: nil, local: true)
|
2019-05-21 21:58:15 -06:00
|
|
|
{:ok, user} = User.ensure_keys_present(user)
|
2019-02-13 19:41:21 -07:00
|
|
|
|
|
|
|
result = UserView.render("user.json", %{user: user})
|
|
|
|
|
|
|
|
refute result["endpoints"]["oauthAuthorizationEndpoint"]
|
|
|
|
refute result["endpoints"]["oauthRegistrationEndpoint"]
|
|
|
|
refute result["endpoints"]["oauthTokenEndpoint"]
|
|
|
|
end
|
2019-02-13 12:48:24 -07:00
|
|
|
end
|
2017-12-11 10:19:46 -07:00
|
|
|
end
|