Merge branch 'develop' into feature/activitypub
This commit is contained in:
commit
30e9b22f96
2938 changed files with 211846 additions and 378 deletions
1
test/fixtures/ostatus_incoming_post_tag.xml
vendored
1
test/fixtures/ostatus_incoming_post_tag.xml
vendored
|
|
@ -43,6 +43,7 @@
|
|||
<title>New note by lambadalambda</title>
|
||||
<content type="html">Will it blend?</content>
|
||||
<category term="Nsfw"/>
|
||||
<category term=""/>
|
||||
<link rel="alternate" type="text/html" href="https://social.heldscal.la/notice/1967725"/>
|
||||
<status_net notice_id="1967725"></status_net>
|
||||
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
|
||||
|
|
|
|||
|
|
@ -7,10 +7,34 @@ defmodule Pleroma.FormatterTest do
|
|||
describe ".linkify" do
|
||||
test "turning urls into links" do
|
||||
text = "Hey, check out https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla."
|
||||
|
||||
expected = "Hey, check out <a href='https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla'>https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla</a>."
|
||||
|
||||
assert Formatter.linkify(text) == expected
|
||||
|
||||
text = "https://mastodon.social/@lambadalambda"
|
||||
expected = "<a href='https://mastodon.social/@lambadalambda'>https://mastodon.social/@lambadalambda</a>"
|
||||
|
||||
assert Formatter.linkify(text) == expected
|
||||
|
||||
text = "@lambadalambda"
|
||||
expected = "@lambadalambda"
|
||||
|
||||
assert Formatter.linkify(text) == expected
|
||||
|
||||
text = "http://www.cs.vu.nl/~ast/intel/"
|
||||
expected = "<a href='http://www.cs.vu.nl/~ast/intel/'>http://www.cs.vu.nl/~ast/intel/</a>"
|
||||
|
||||
assert Formatter.linkify(text) == expected
|
||||
|
||||
text = "https://forum.zdoom.org/viewtopic.php?f=44&t=57087"
|
||||
expected = "<a href='https://forum.zdoom.org/viewtopic.php?f=44&t=57087'>https://forum.zdoom.org/viewtopic.php?f=44&t=57087</a>"
|
||||
|
||||
assert Formatter.linkify(text) == expected
|
||||
|
||||
text = "https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul"
|
||||
expected = "<a href='https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul'>https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul</a>"
|
||||
|
||||
assert Formatter.linkify(text) == expected
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -20,4 +20,76 @@ defmodule Pleroma.NotificationTest do
|
|||
assert other_notification.activity_id == activity.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "create_notification" do
|
||||
test "it doesn't create a notification for user if the user blocks the activity author" do
|
||||
activity = insert(:note_activity)
|
||||
author = User.get_by_ap_id(activity.data["actor"])
|
||||
user = insert(:user)
|
||||
{:ok, user} = User.block(user, author)
|
||||
|
||||
assert nil == Notification.create_notification(activity, user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "get notification" do
|
||||
test "it gets a notification that belongs to the user" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
{:ok, notification} = Notification.get(other_user, notification.id)
|
||||
|
||||
assert notification.user_id == other_user.id
|
||||
end
|
||||
|
||||
test "it returns error if the notification doesn't belong to the user" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
{:error, notification} = Notification.get(user, notification.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "dismiss notification" do
|
||||
test "it dismisses a notification that belongs to the user" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
{:ok, notification} = Notification.dismiss(other_user, notification.id)
|
||||
|
||||
assert notification.user_id == other_user.id
|
||||
end
|
||||
|
||||
test "it returns error if the notification doesn't belong to the user" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
{:error, notification} = Notification.dismiss(user, notification.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "clear notification" do
|
||||
test "it clears all notifications belonging to the user" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
third_user = insert(:user)
|
||||
|
||||
{:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname} and @#{third_user.nickname} !"})
|
||||
{:ok, _notifs} = Notification.create_notifications(activity)
|
||||
{:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey again @#{other_user.nickname} and @#{third_user.nickname} !"})
|
||||
{:ok, _notifs} = Notification.create_notifications(activity)
|
||||
Notification.clear(other_user)
|
||||
|
||||
assert Notification.for_user(other_user) == []
|
||||
assert Notification.for_user(third_user) != []
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,6 +14,13 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do
|
|||
password_hash: Comeonin.Pbkdf2.hashpwsalt("guy")
|
||||
}
|
||||
|
||||
@deactivated %User{
|
||||
id: 1,
|
||||
name: "dude",
|
||||
password_hash: Comeonin.Pbkdf2.hashpwsalt("guy"),
|
||||
info: %{"deactivated" => true}
|
||||
}
|
||||
|
||||
@session_opts [
|
||||
store: :cookie,
|
||||
key: "_test",
|
||||
|
|
@ -131,6 +138,26 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "with a correct authorization header for an deactiviated user" do
|
||||
test "it halts the appication", %{conn: conn} do
|
||||
opts = %{
|
||||
optional: false,
|
||||
fetcher: fn _ -> @deactivated end
|
||||
}
|
||||
|
||||
header = basic_auth_enc("dude", "guy")
|
||||
|
||||
conn = conn
|
||||
|> Plug.Session.call(Plug.Session.init(@session_opts))
|
||||
|> fetch_session
|
||||
|> put_req_header("authorization", header)
|
||||
|> AuthenticationPlug.call(opts)
|
||||
|
||||
assert conn.status == 403
|
||||
assert conn.halted == true
|
||||
end
|
||||
end
|
||||
|
||||
describe "with a user_id in the session for an existing user" do
|
||||
test "it assigns the user", %{conn: conn} do
|
||||
opts = %{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ defmodule Pleroma.Factory do
|
|||
password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
|
||||
bio: sequence(:bio, &"Tester Number #{&1}")
|
||||
}
|
||||
%{ user | ap_id: Pleroma.User.ap_id(user), follower_address: Pleroma.User.ap_followers(user) }
|
||||
%{ user | ap_id: Pleroma.User.ap_id(user), follower_address: Pleroma.User.ap_followers(user), following: [Pleroma.User.ap_id(user)] }
|
||||
end
|
||||
|
||||
def note_factory do
|
||||
|
|
@ -26,7 +26,11 @@ defmodule Pleroma.Factory do
|
|||
"likes" => [],
|
||||
"like_count" => 0,
|
||||
"context" => "2hu",
|
||||
"tag" => ["2hu"]
|
||||
"summary" => "2hu",
|
||||
"tag" => ["2hu"],
|
||||
"emoji" => %{
|
||||
"2hu" => "corndog.png"
|
||||
}
|
||||
}
|
||||
|
||||
%Pleroma.Object{
|
||||
|
|
@ -47,7 +51,8 @@ defmodule Pleroma.Factory do
|
|||
}
|
||||
|
||||
%Pleroma.Activity{
|
||||
data: data
|
||||
data: data,
|
||||
actor: data["actor"]
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -9,5 +9,17 @@ defmodule Pleroma.UploadTest do
|
|||
assert data["name"] == "an [image.jpg"
|
||||
assert List.first(data["url"])["href"] == "http://localhost:4001/media/#{data["uuid"]}/an%20%5Bimage.jpg"
|
||||
end
|
||||
|
||||
test "fixes an incorrect content type" do
|
||||
file = %Plug.Upload{content_type: "application/octet-stream", path: Path.absname("test/fixtures/image.jpg"), filename: "an [image.jpg"}
|
||||
data = Upload.store(file)
|
||||
assert hd(data["url"])["mediaType"] == "image/jpeg"
|
||||
end
|
||||
|
||||
test "does not modify a valid content type" do
|
||||
file = %Plug.Upload{content_type: "image/png", path: Path.absname("test/fixtures/image.jpg"), filename: "an [image.jpg"}
|
||||
data = Upload.store(file)
|
||||
assert hd(data["url"])["mediaType"] == "image/png"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,19 +1,15 @@
|
|||
defmodule Pleroma.UserTest do
|
||||
alias Pleroma.Builders.UserBuilder
|
||||
alias Pleroma.{User, Repo}
|
||||
alias Pleroma.{User, Repo, Activity}
|
||||
alias Pleroma.Web.OStatus
|
||||
alias Pleroma.Web.Websub.WebsubClientSubscription
|
||||
alias Pleroma.Web.CommonAPI
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
import Ecto.Query
|
||||
|
||||
test "ap_id returns the activity pub id for the user" do
|
||||
host =
|
||||
Application.get_env(:pleroma, Pleroma.Web.Endpoint)
|
||||
|> Keyword.fetch!(:url)
|
||||
|> Keyword.fetch!(:host)
|
||||
|
||||
user = UserBuilder.build
|
||||
|
||||
expected_ap_id = "#{Pleroma.Web.base_url}/users/#{user.nickname}"
|
||||
|
|
@ -40,7 +36,14 @@ defmodule Pleroma.UserTest do
|
|||
followed = User.get_by_ap_id(followed.ap_id)
|
||||
assert followed.info["follower_count"] == 1
|
||||
|
||||
assert user.following == [User.ap_followers(followed)]
|
||||
assert User.ap_followers(followed) in user.following
|
||||
end
|
||||
|
||||
test "can't follow a deactivated users" do
|
||||
user = insert(:user)
|
||||
followed = insert(:user, info: %{"deactivated" => true})
|
||||
|
||||
{:error, _} = User.follow(user, followed)
|
||||
end
|
||||
|
||||
test "following a remote user will ensure a websub subscription is present" do
|
||||
|
|
@ -50,7 +53,7 @@ defmodule Pleroma.UserTest do
|
|||
assert followed.local == false
|
||||
|
||||
{:ok, user} = User.follow(user, followed)
|
||||
assert user.following == [User.ap_followers(followed)]
|
||||
assert User.ap_followers(followed) in user.following
|
||||
|
||||
query = from w in WebsubClientSubscription,
|
||||
where: w.topic == ^followed.info["topic"]
|
||||
|
|
@ -70,6 +73,16 @@ defmodule Pleroma.UserTest do
|
|||
assert user.following == []
|
||||
end
|
||||
|
||||
test "unfollow doesn't unfollow yourself" do
|
||||
user = insert(:user)
|
||||
|
||||
{:error, _} = User.unfollow(user, user)
|
||||
|
||||
user = Repo.get(User, user.id)
|
||||
assert user.following == [user.ap_id]
|
||||
end
|
||||
|
||||
|
||||
test "test if a user is following another user" do
|
||||
followed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(followed)]})
|
||||
|
|
@ -213,7 +226,9 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
{:ok, res} = User.get_followers(user)
|
||||
|
||||
assert res == [follower_one, follower_two]
|
||||
assert Enum.member?(res, follower_one)
|
||||
assert Enum.member?(res, follower_two)
|
||||
refute Enum.member?(res, not_follower)
|
||||
end
|
||||
|
||||
test "gets all friends (followed users) for a given user" do
|
||||
|
|
@ -229,7 +244,9 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
followed_one = User.get_by_ap_id(followed_one.ap_id)
|
||||
followed_two = User.get_by_ap_id(followed_two.ap_id)
|
||||
assert res == [followed_one, followed_two]
|
||||
assert Enum.member?(res, followed_one)
|
||||
assert Enum.member?(res, followed_two)
|
||||
refute Enum.member?(res, not_followed)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -246,6 +263,21 @@ defmodule Pleroma.UserTest do
|
|||
assert user.info["note_count"] == 1
|
||||
end
|
||||
|
||||
test "it increases the info->note_count property" do
|
||||
note = insert(:note)
|
||||
user = User.get_by_ap_id(note.data["actor"])
|
||||
|
||||
assert user.info["note_count"] == nil
|
||||
|
||||
{:ok, user} = User.increase_note_count(user)
|
||||
|
||||
assert user.info["note_count"] == 1
|
||||
|
||||
{:ok, user} = User.increase_note_count(user)
|
||||
|
||||
assert user.info["note_count"] == 2
|
||||
end
|
||||
|
||||
test "it sets the info->follower_count property" do
|
||||
user = insert(:user)
|
||||
follower = insert(:user)
|
||||
|
|
@ -259,5 +291,83 @@ defmodule Pleroma.UserTest do
|
|||
assert user.info["follower_count"] == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "blocks" do
|
||||
test "it blocks people" do
|
||||
user = insert(:user)
|
||||
blocked_user = insert(:user)
|
||||
|
||||
refute User.blocks?(user, blocked_user)
|
||||
|
||||
{:ok, user} = User.block(user, blocked_user)
|
||||
|
||||
assert User.blocks?(user, blocked_user)
|
||||
end
|
||||
|
||||
test "it unblocks users" do
|
||||
user = insert(:user)
|
||||
blocked_user = insert(:user)
|
||||
|
||||
{:ok, user} = User.block(user, blocked_user)
|
||||
{:ok, user} = User.unblock(user, blocked_user)
|
||||
|
||||
refute User.blocks?(user, blocked_user)
|
||||
end
|
||||
end
|
||||
|
||||
test "get recipients from activity" do
|
||||
actor = insert(:user)
|
||||
user = insert(:user, local: true)
|
||||
user_two = insert(:user, local: false)
|
||||
addressed = insert(:user, local: true)
|
||||
addressed_remote = insert(:user, local: false)
|
||||
{:ok, activity} = CommonAPI.post(actor, %{"status" => "hey @#{addressed.nickname} @#{addressed_remote.nickname}"})
|
||||
|
||||
assert [addressed] == User.get_recipients_from_activity(activity)
|
||||
|
||||
{:ok, user} = User.follow(user, actor)
|
||||
{:ok, user_two} = User.follow(user_two, actor)
|
||||
recipients = User.get_recipients_from_activity(activity)
|
||||
assert length(recipients) == 2
|
||||
assert user in recipients
|
||||
assert addressed in recipients
|
||||
end
|
||||
|
||||
test ".deactivate deactivates a user" do
|
||||
user = insert(:user)
|
||||
assert false == !!user.info["deactivated"]
|
||||
{:ok, user} = User.deactivate(user)
|
||||
assert true == user.info["deactivated"]
|
||||
end
|
||||
|
||||
test ".delete deactivates a user, all follow relationships and all create activities" do
|
||||
user = insert(:user)
|
||||
followed = insert(:user)
|
||||
follower = insert(:user)
|
||||
|
||||
{:ok, user} = User.follow(user, followed)
|
||||
{:ok, follower} = User.follow(follower, user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
|
||||
{:ok, activity_two} = CommonAPI.post(follower, %{"status" => "3hu"})
|
||||
|
||||
{:ok, _, _} = CommonAPI.favorite(activity_two.id, user)
|
||||
{:ok, _, _} = CommonAPI.favorite(activity.id, follower)
|
||||
{:ok, _, _} = CommonAPI.repeat(activity.id, follower)
|
||||
|
||||
:ok = User.delete(user)
|
||||
|
||||
followed = Repo.get(User, followed.id)
|
||||
follower = Repo.get(User, follower.id)
|
||||
user = Repo.get(User, user.id)
|
||||
|
||||
assert user.info["deactivated"]
|
||||
|
||||
refute User.following?(user, followed)
|
||||
refute User.following?(followed, follower)
|
||||
|
||||
# TODO: Remove favorites, repeats, delete activities.
|
||||
|
||||
refute Repo.get(Activity, activity.id)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
test "removes doubled 'to' recipients" do
|
||||
{:ok, activity} = ActivityPub.create(["user1", "user1", "user2"], %User{ap_id: "1"}, "", %{})
|
||||
assert activity.data["to"] == ["user1", "user2"]
|
||||
assert activity.actor == "1"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -73,15 +74,44 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
{:ok, activity_two} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"})
|
||||
{:ok, _activity_three} = ActivityBuilder.insert(%{"type" => "Create", "context" => "3hu"})
|
||||
{:ok, _activity_four} = ActivityBuilder.insert(%{"type" => "Announce", "context" => "2hu"})
|
||||
activity_five = insert(:note_activity)
|
||||
user = insert(:user)
|
||||
|
||||
activities = ActivityPub.fetch_activities_for_context("2hu")
|
||||
{:ok, user} = User.block(user, %{ap_id: activity_five.data["actor"]})
|
||||
|
||||
activities = ActivityPub.fetch_activities_for_context("2hu", %{"blocking_user" => user})
|
||||
assert activities == [activity_two, activity]
|
||||
end
|
||||
end
|
||||
|
||||
test "doesn't return blocked activities" do
|
||||
activity_one = insert(:note_activity)
|
||||
activity_two = insert(:note_activity)
|
||||
user = insert(:user)
|
||||
{:ok, user} = User.block(user, %{ap_id: activity_one.data["actor"]})
|
||||
|
||||
activities = ActivityPub.fetch_activities([], %{"blocking_user" => user})
|
||||
|
||||
assert Enum.member?(activities, activity_two)
|
||||
refute Enum.member?(activities, activity_one)
|
||||
|
||||
{:ok, user} = User.unblock(user, %{ap_id: activity_one.data["actor"]})
|
||||
|
||||
activities = ActivityPub.fetch_activities([], %{"blocking_user" => user})
|
||||
|
||||
assert Enum.member?(activities, activity_two)
|
||||
assert Enum.member?(activities, activity_one)
|
||||
|
||||
activities = ActivityPub.fetch_activities([], %{"blocking_user" => nil})
|
||||
|
||||
assert Enum.member?(activities, activity_two)
|
||||
assert Enum.member?(activities, activity_one)
|
||||
end
|
||||
|
||||
describe "public fetch activities" do
|
||||
test "retrieves public activities" do
|
||||
activities = ActivityPub.fetch_public_activities
|
||||
|
||||
%{public: public} = ActivityBuilder.public_and_non_public
|
||||
|
||||
activities = ActivityPub.fetch_public_activities
|
||||
|
|
|
|||
|
|
@ -11,6 +11,6 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
|
||||
res = Utils.add_attachments("", [attachment])
|
||||
|
||||
assert res == "<br>\n<a href=\"#{name}\" class='attachment'>Sakura Mana – Turned on by a Se…</a>"
|
||||
assert res == "<br><a href=\"#{name}\" class='attachment'>Sakura Mana – Turned on by a Se…</a>"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
20
test/web/federator_test.exs
Normal file
20
test/web/federator_test.exs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
defmodule Pleroma.Web.FederatorTest do
|
||||
alias Pleroma.Web.Federator
|
||||
use Pleroma.DataCase
|
||||
|
||||
test "enqueues an element according to priority" do
|
||||
queue = [%{item: 1, priority: 2}]
|
||||
|
||||
new_queue = Federator.enqueue_sorted(queue, 2, 1)
|
||||
assert new_queue == [%{item: 2, priority: 1}, %{item: 1, priority: 2}]
|
||||
|
||||
new_queue = Federator.enqueue_sorted(queue, 2, 3)
|
||||
assert new_queue == [%{item: 1, priority: 2}, %{item: 2, priority: 3}]
|
||||
end
|
||||
|
||||
test "pop first item" do
|
||||
queue = [%{item: 2, priority: 1}, %{item: 1, priority: 2}]
|
||||
|
||||
assert {2, [%{item: 1, priority: 2}]} = Federator.queue_pop(queue)
|
||||
end
|
||||
end
|
||||
|
|
@ -8,7 +8,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
user = insert(:user, %{info: %{"note_count" => 5, "follower_count" => 3}, nickname: "shp@shitposter.club", inserted_at: ~N[2017-08-15 15:47:06.597036]})
|
||||
|
||||
expected = %{
|
||||
id: user.id,
|
||||
id: to_string(user.id),
|
||||
username: "shp",
|
||||
acct: user.nickname,
|
||||
display_name: user.name,
|
||||
|
|
@ -37,7 +37,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
user = insert(:user)
|
||||
|
||||
expected = %{
|
||||
id: user.id,
|
||||
id: to_string(user.id),
|
||||
acct: user.nickname,
|
||||
username: user.nickname,
|
||||
url: user.ap_id
|
||||
|
|
@ -51,12 +51,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
other_user = insert(:user)
|
||||
|
||||
{:ok, user} = User.follow(user, other_user)
|
||||
{:ok, user} = User.block(user, other_user)
|
||||
|
||||
expected = %{
|
||||
id: other_user.id,
|
||||
id: to_string(other_user.id),
|
||||
following: true,
|
||||
followed_by: false,
|
||||
blocking: false,
|
||||
blocking: true,
|
||||
muting: false,
|
||||
requested: false,
|
||||
domain_blocking: false
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||
alias Pleroma.{Repo, User, Activity}
|
||||
alias Pleroma.{Repo, User, Activity, Notification}
|
||||
alias Pleroma.Web.{OStatus, CommonAPI}
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
@ -50,9 +50,20 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses", %{"status" => "cofe"})
|
||||
|> post("/api/v1/statuses", %{"status" => "cofe", "spoiler_text" => "2hu"})
|
||||
|
||||
assert %{"content" => "cofe", "id" => id} = json_response(conn, 200)
|
||||
assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu"} = json_response(conn, 200)
|
||||
assert Repo.get(Activity, id)
|
||||
end
|
||||
|
||||
test "posting a sensitive status", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses", %{"status" => "cofe", "sensitive" => true})
|
||||
|
||||
assert %{"content" => "cofe", "id" => id, "sensitive" => true} = json_response(conn, 200)
|
||||
assert Repo.get(Activity, id)
|
||||
end
|
||||
|
||||
|
|
@ -81,7 +92,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> get("/api/v1/accounts/verify_credentials")
|
||||
|
||||
assert %{"id" => id} = json_response(conn, 200)
|
||||
assert id == user.id
|
||||
assert id == to_string(user.id)
|
||||
end
|
||||
|
||||
test "get a status", %{conn: conn} do
|
||||
|
|
@ -91,7 +102,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> get("/api/v1/statuses/#{activity.id}")
|
||||
|
||||
assert %{"id" => id} = json_response(conn, 200)
|
||||
assert id == activity.id
|
||||
assert id == to_string(activity.id)
|
||||
end
|
||||
|
||||
describe "deleting a status" do
|
||||
|
|
@ -122,6 +133,75 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "notifications" do
|
||||
test "list of notifications", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications")
|
||||
|
||||
expected_response = "hi <a href=\"#{user.ap_id}\">@#{user.nickname}</a>"
|
||||
assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
|
||||
assert response == expected_response
|
||||
end
|
||||
|
||||
test "getting a single notification", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications/#{notification.id}")
|
||||
|
||||
expected_response = "hi <a href=\"#{user.ap_id}\">@#{user.nickname}</a>"
|
||||
assert %{"status" => %{"content" => response}} = json_response(conn, 200)
|
||||
assert response == expected_response
|
||||
end
|
||||
|
||||
test "dismissing a single notification", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/notifications/dismiss", %{"id" => notification.id})
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "clearing all notifications", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/notifications/clear")
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
|
||||
conn = build_conn()
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications")
|
||||
|
||||
assert all = json_response(conn, 200)
|
||||
assert all == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "reblogging" do
|
||||
test "reblogs and returns the reblogged status", %{conn: conn} do
|
||||
activity = insert(:note_activity)
|
||||
|
|
@ -131,8 +211,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses/#{activity.id}/reblog")
|
||||
|
||||
assert %{"id" => id, "reblogged" => true, "reblogs_count" => 1} = json_response(conn, 200)
|
||||
assert activity.id == id
|
||||
assert %{"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1}} = json_response(conn, 200)
|
||||
assert to_string(activity.id) == id
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -146,7 +226,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> post("/api/v1/statuses/#{activity.id}/favourite")
|
||||
|
||||
assert %{"id" => id, "favourites_count" => 1, "favourited" => true} = json_response(conn, 200)
|
||||
assert activity.id == id
|
||||
assert to_string(activity.id) == id
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -162,7 +242,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> post("/api/v1/statuses/#{activity.id}/unfavourite")
|
||||
|
||||
assert %{"id" => id, "favourites_count" => 0, "favourited" => false} = json_response(conn, 200)
|
||||
assert activity.id == id
|
||||
assert to_string(activity.id) == id
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -178,7 +258,30 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
assert [%{"id" => id}] = json_response(conn, 200)
|
||||
|
||||
assert id == note_two.id
|
||||
assert id == to_string(note_two.id)
|
||||
end
|
||||
|
||||
test "gets an users media", %{conn: conn} do
|
||||
note = insert(:note_activity)
|
||||
user = User.get_by_ap_id(note.data["actor"])
|
||||
|
||||
file = %Plug.Upload{content_type: "image/jpg", path: Path.absname("test/fixtures/image.jpg"), filename: "an_image.jpg"}
|
||||
media = TwitterAPI.upload(file, "json")
|
||||
|> Poison.decode!
|
||||
|
||||
{:ok, image_post} = TwitterAPI.create_status(user, %{"status" => "cofe", "media_ids" => [media["media_id"]]})
|
||||
|
||||
conn = conn
|
||||
|> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => "true"})
|
||||
|
||||
assert [%{"id" => id}] = json_response(conn, 200)
|
||||
assert id == to_string(image_post.id)
|
||||
|
||||
conn = build_conn()
|
||||
|> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => "1"})
|
||||
|
||||
assert [%{"id" => id}] = json_response(conn, 200)
|
||||
assert id == to_string(image_post.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -194,7 +297,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
assert [relationship] = json_response(conn, 200)
|
||||
|
||||
assert other_user.id == relationship["id"]
|
||||
assert to_string(other_user.id) == relationship["id"]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -205,7 +308,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> get("/api/v1/accounts/#{user.id}")
|
||||
|
||||
assert %{"id" => id} = json_response(conn, 200)
|
||||
assert id == user.id
|
||||
assert id == to_string(user.id)
|
||||
|
||||
conn = build_conn()
|
||||
|> get("/api/v1/accounts/-1")
|
||||
|
|
@ -238,7 +341,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
assert [%{"id" => id}] = json_response(conn, 200)
|
||||
|
||||
assert id == activity.id
|
||||
assert id == to_string(activity.id)
|
||||
end
|
||||
|
||||
test "getting followers", %{conn: conn} do
|
||||
|
|
@ -250,7 +353,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> get("/api/v1/accounts/#{other_user.id}/followers")
|
||||
|
||||
assert [%{"id" => id}] = json_response(conn, 200)
|
||||
assert id = user.id
|
||||
assert id == to_string(user.id)
|
||||
end
|
||||
|
||||
test "getting following", %{conn: conn} do
|
||||
|
|
@ -262,7 +365,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> get("/api/v1/accounts/#{user.id}/following")
|
||||
|
||||
assert [%{"id" => id}] = json_response(conn, 200)
|
||||
assert id = other_user.id
|
||||
assert id == to_string(other_user.id)
|
||||
end
|
||||
|
||||
test "following / unfollowing a user", %{conn: conn} do
|
||||
|
|
@ -281,20 +384,60 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> post("/api/v1/accounts/#{other_user.id}/unfollow")
|
||||
|
||||
assert %{"id" => id, "following" => false} = json_response(conn, 200)
|
||||
|
||||
user = Repo.get(User, user.id)
|
||||
conn = build_conn()
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/follows", %{"uri" => other_user.nickname})
|
||||
|
||||
assert %{"id" => id} = json_response(conn, 200)
|
||||
assert id == to_string(other_user.id)
|
||||
end
|
||||
|
||||
test "unimplemented block/mute endpoints" do
|
||||
test "blocking / unblocking a user", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
["block", "unblock", "mute", "unmute"]
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/accounts/#{other_user.id}/block")
|
||||
|
||||
assert %{"id" => id, "blocking" => true} = json_response(conn, 200)
|
||||
|
||||
user = Repo.get(User, user.id)
|
||||
conn = build_conn()
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/accounts/#{other_user.id}/unblock")
|
||||
|
||||
assert %{"id" => id, "blocking" => false} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "getting a list of blocks", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, user} = User.block(user, other_user)
|
||||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/blocks")
|
||||
|
||||
other_user_id = to_string(other_user.id)
|
||||
assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "unimplemented mute endpoints" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
["mute", "unmute"]
|
||||
|> Enum.each(fn(endpoint) ->
|
||||
conn = build_conn()
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/accounts/#{other_user.id}/#{endpoint}")
|
||||
|
||||
assert %{"id" => id} = json_response(conn, 200)
|
||||
assert id == other_user.id
|
||||
assert id == to_string(other_user.id)
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
@ -311,6 +454,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
end)
|
||||
end
|
||||
|
||||
test "account search", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user_two = insert(:user, %{nickname: "shp@shitposter.club"})
|
||||
user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
|
||||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/accounts/search", %{"q" => "2hu"})
|
||||
|
||||
assert [account] = json_response(conn, 200)
|
||||
assert account["id"] == to_string(user_three.id)
|
||||
end
|
||||
|
||||
test "search", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user_two = insert(:user, %{nickname: "shp@shitposter.club"})
|
||||
|
|
@ -325,12 +481,21 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
assert results = json_response(conn, 200)
|
||||
|
||||
[account] = results["accounts"]
|
||||
assert account["id"] == user_three.id
|
||||
assert account["id"] == to_string(user_three.id)
|
||||
|
||||
assert results["hashtags"] == []
|
||||
|
||||
[status] = results["statuses"]
|
||||
assert status["id"] == activity.id
|
||||
assert status["id"] == to_string(activity.id)
|
||||
end
|
||||
|
||||
test "search fetches remote statuses", %{conn: conn} do
|
||||
conn = conn
|
||||
|> get("/api/v1/search", %{"q" => "https://shitposter.club/notice/2827873"})
|
||||
assert results = json_response(conn, 200)
|
||||
|
||||
[status] = results["statuses"]
|
||||
assert status["uri"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
|
||||
end
|
||||
|
||||
test "search fetches remote accounts", %{conn: conn} do
|
||||
|
|
@ -356,6 +521,71 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> get("/api/v1/favourites")
|
||||
|
||||
assert [status] = json_response(conn, 200)
|
||||
assert status["id"] == activity.id
|
||||
assert status["id"] == to_string(activity.id)
|
||||
end
|
||||
|
||||
describe "updating credentials" do
|
||||
test "updates the user's bio" do
|
||||
user = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"note" => "I drink #cofe"})
|
||||
|
||||
assert user = json_response(conn, 200)
|
||||
assert user["note"] == "I drink #cofe"
|
||||
end
|
||||
|
||||
test "updates the user's name" do
|
||||
user = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"display_name" => "markorepairs"})
|
||||
|
||||
assert user = json_response(conn, 200)
|
||||
assert user["display_name"] == "markorepairs"
|
||||
end
|
||||
|
||||
test "updates the user's avatar" do
|
||||
user = insert(:user)
|
||||
|
||||
new_avatar = %Plug.Upload{content_type: "image/jpg", path: Path.absname("test/fixtures/image.jpg"), filename: "an_image.jpg"}
|
||||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"avatar" => new_avatar})
|
||||
|
||||
assert user = json_response(conn, 200)
|
||||
assert user["avatar"] != "https://placehold.it/48x48"
|
||||
end
|
||||
|
||||
test "updates the user's banner" do
|
||||
user = insert(:user)
|
||||
|
||||
new_header = %Plug.Upload{content_type: "image/jpg", path: Path.absname("test/fixtures/image.jpg"), filename: "an_image.jpg"}
|
||||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"header" => new_header})
|
||||
|
||||
assert user = json_response(conn, 200)
|
||||
assert user["header"] != "https://placehold.it/700x335"
|
||||
end
|
||||
end
|
||||
|
||||
test "get instance information" do
|
||||
insert(:user, %{local: true})
|
||||
user = insert(:user, %{local: true})
|
||||
insert(:user, %{local: false})
|
||||
|
||||
{:ok, _} = TwitterAPI.create_status(user, %{"status" => "cofe"})
|
||||
|
||||
conn = conn
|
||||
|> get("/api/v1/instance")
|
||||
|
||||
assert result = json_response(conn, 200)
|
||||
|
||||
assert result["stats"]["user_count"] == 2
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|> String.replace(~r/\.\d+Z/, ".000Z")
|
||||
|
||||
expected = %{
|
||||
id: note.id,
|
||||
id: to_string(note.id),
|
||||
uri: note.data["object"]["id"],
|
||||
url: note.data["object"]["external_id"],
|
||||
url: note.data["object"]["id"],
|
||||
account: AccountView.render("account.json", %{user: user}),
|
||||
in_reply_to_id: nil,
|
||||
in_reply_to_account_id: nil,
|
||||
|
|
@ -32,7 +32,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
favourited: false,
|
||||
muted: false,
|
||||
sensitive: false,
|
||||
spoiler_text: "",
|
||||
spoiler_text: note.data["object"]["summary"],
|
||||
visibility: "public",
|
||||
media_attachments: [],
|
||||
mentions: [],
|
||||
|
|
@ -41,7 +41,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
name: "Web",
|
||||
website: nil
|
||||
},
|
||||
language: nil
|
||||
language: nil,
|
||||
emojis: [
|
||||
%{
|
||||
shortcode: "2hu",
|
||||
url: "corndog.png",
|
||||
static_url: "corndog.png"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
assert status == expected
|
||||
|
|
@ -71,7 +78,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
}
|
||||
|
||||
expected = %{
|
||||
id: 1638338801,
|
||||
id: "1638338801",
|
||||
type: "image",
|
||||
url: "someurl",
|
||||
remote_url: "someurl",
|
||||
|
|
@ -83,7 +90,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
# If theres a "id", use that instead of the generated one
|
||||
object = Map.put(object, "id", 2)
|
||||
assert %{id: 2} = StatusView.render("attachment.json", %{attachment: object})
|
||||
assert %{id: "2"} = StatusView.render("attachment.json", %{attachment: object})
|
||||
end
|
||||
|
||||
test "a reblog" do
|
||||
|
|
@ -94,7 +101,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
represented = StatusView.render("status.json", %{for: user, activity: reblog})
|
||||
|
||||
assert represented[:id] == reblog.id
|
||||
assert represented[:reblog][:id] == activity.id
|
||||
assert represented[:id] == to_string(reblog.id)
|
||||
assert represented[:reblog][:id] == to_string(activity.id)
|
||||
assert represented[:emojis] == []
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -36,11 +36,12 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
|
|||
<updated>#{note_activity.data["object"]["published"]}</updated>
|
||||
<ostatus:conversation ref="#{note_activity.data["context"]}">#{note_activity.data["context"]}</ostatus:conversation>
|
||||
<link ref="#{note_activity.data["context"]}" rel="ostatus:conversation" />
|
||||
<summary>#{note_activity.data["object"]["summary"]}</summary>
|
||||
<link type="application/atom+xml" href="#{note_activity.data["object"]["id"]}" rel="self" />
|
||||
<link type="text/html" href="#{note_activity.data["object"]["id"]}" rel="alternate" />
|
||||
<category term="2hu"/>
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
|
||||
<link name="moominmamma" rel="emoji" href="#{Pleroma.Web.Endpoint.static_url}/finmoji/128px/moominmamma-128.png" />
|
||||
<link name="2hu" rel="emoji" href="corndog.png" />
|
||||
"""
|
||||
|
||||
tuple = ActivityRepresenter.to_simple_form(note_activity, user)
|
||||
|
|
@ -74,12 +75,13 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
|
|||
<updated>#{answer.data["object"]["published"]}</updated>
|
||||
<ostatus:conversation ref="#{answer.data["context"]}">#{answer.data["context"]}</ostatus:conversation>
|
||||
<link ref="#{answer.data["context"]}" rel="ostatus:conversation" />
|
||||
<summary>2hu</summary>
|
||||
<link type="application/atom+xml" href="#{answer.data["object"]["id"]}" rel="self" />
|
||||
<link type="text/html" href="#{answer.data["object"]["id"]}" rel="alternate" />
|
||||
<category term="2hu"/>
|
||||
<thr:in-reply-to ref="#{note.data["object"]["id"]}" href="someurl" />
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
|
||||
<link name="moominmamma" rel="emoji" href="#{Pleroma.Web.Endpoint.static_url}/finmoji/128px/moominmamma-128.png" />
|
||||
<link name="2hu" rel="emoji" href="corndog.png" />
|
||||
"""
|
||||
|
||||
tuple = ActivityRepresenter.to_simple_form(answer, user)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,41 @@
|
|||
defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.User
|
||||
alias Pleroma.{User, Repo}
|
||||
alias Pleroma.Web.OStatus.ActivityRepresenter
|
||||
|
||||
test "decodes a salmon", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
salmon = File.read!("test/fixtures/salmon.xml")
|
||||
conn = conn
|
||||
|> put_req_header("content-type", "application/atom+xml")
|
||||
|> post("/users/#{user.nickname}/salmon", salmon)
|
||||
|
||||
assert response(conn, 200)
|
||||
end
|
||||
|
||||
test "decodes a salmon with a changed magic key", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
salmon = File.read!("test/fixtures/salmon.xml")
|
||||
conn = conn
|
||||
|> put_req_header("content-type", "application/atom+xml")
|
||||
|> post("/users/#{user.nickname}/salmon", salmon)
|
||||
|
||||
assert response(conn, 200)
|
||||
|
||||
# Set a wrong magic-key for a user so it has to refetch
|
||||
salmon_user = User.get_by_ap_id("http://gs.example.org:4040/index.php/user/1")
|
||||
info = salmon_user.info
|
||||
|> Map.put("magic_key", "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB") # Wrong key
|
||||
Repo.update(User.info_changeset(salmon_user, %{info: info}))
|
||||
|
||||
conn = build_conn()
|
||||
|> put_req_header("content-type", "application/atom+xml")
|
||||
|> post("/users/#{user.nickname}/salmon", salmon)
|
||||
|
||||
assert response(conn, 200)
|
||||
end
|
||||
|
||||
test "gets a feed", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
|
@ -41,4 +73,21 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|
||||
assert response(conn, 200)
|
||||
end
|
||||
|
||||
test "gets a notice", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
url = "/notice/#{note_activity.id}"
|
||||
|
||||
conn = conn
|
||||
|> get(url)
|
||||
|
||||
assert response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Pleroma.Web.OStatusMock do
|
||||
import Pleroma.Factory
|
||||
def handle_incoming(_doc) do
|
||||
insert(:note_activity)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ defmodule Pleroma.Web.OStatusTest do
|
|||
assert activity.data["type"] == "Create"
|
||||
assert activity.data["object"]["type"] == "Note"
|
||||
assert activity.data["object"]["actor"] == "https://mastodon.social/users/lambadalambda"
|
||||
assert String.contains?(activity.data["object"]["content"], "technologic")
|
||||
assert activity.data["object"]["summary"] == "technologic"
|
||||
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
||||
end
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ defmodule Pleroma.Web.OStatusTest do
|
|||
incoming = File.read!("test/fixtures/cw_retweet.xml")
|
||||
{:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
|
||||
|
||||
assert String.contains?(retweeted_activity.data["object"]["content"], "Hey.")
|
||||
assert retweeted_activity.data["object"]["summary"] == "Hey."
|
||||
end
|
||||
|
||||
test "handle incoming notes - GS, subscription, reply" do
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ defmodule Pleroma.Web.OStatus.UserRepresenterTest do
|
|||
<poco:preferredUsername>#{user.nickname}</poco:preferredUsername>
|
||||
<poco:displayName>#{user.name}</poco:displayName>
|
||||
<poco:note>#{user.bio}</poco:note>
|
||||
<summary>#{user.bio}</summary>
|
||||
<name>#{user.nickname}</name>
|
||||
<link rel="avatar" href="#{User.avatar_url(user)}" />
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
"published" => date,
|
||||
"type" => "Note",
|
||||
"content" => content_html,
|
||||
"summary" => "2hu",
|
||||
"inReplyToStatusId" => 213123,
|
||||
"attachment" => [
|
||||
object
|
||||
|
|
@ -110,14 +111,14 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
local: false
|
||||
}
|
||||
|
||||
expected_html = "alert('YAY')Some <img height='32px' width='32px' alt='2hu' title='2hu' src='corndog.png' /> content mentioning <a href=\"#{mentioned_user.ap_id}\">@shp</a>"
|
||||
expected_html = "<span>2hu</span><br />alert('YAY')Some <img height='32px' width='32px' alt='2hu' title='2hu' src='corndog.png' /> content mentioning <a href=\"#{mentioned_user.ap_id}\">@shp</a>"
|
||||
|
||||
expected_status = %{
|
||||
"id" => activity.id,
|
||||
"user" => UserView.render("show.json", %{user: user, for: follower}),
|
||||
"is_local" => false,
|
||||
"statusnet_html" => expected_html,
|
||||
"text" => content,
|
||||
"text" => "2hu" <> content,
|
||||
"is_post_verb" => true,
|
||||
"created_at" => "Tue May 24 13:26:08 +0000 2016",
|
||||
"in_reply_to_status_id" => 213123,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.TwitterAPI.UserView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
@ -21,7 +22,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|> with_credentials(user.nickname, "test")
|
||||
|> post("/api/account/verify_credentials.json")
|
||||
|
||||
assert json_response(conn, 200) == UserView.render("show.json", %{user: user})
|
||||
assert response = json_response(conn, 200)
|
||||
assert response == UserView.render("show.json", %{user: user, token: response["token"]})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -101,6 +103,45 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "GET /users/show.json" do
|
||||
test "gets user with screen_name", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> get("/api/users/show.json", %{"screen_name" => user.nickname})
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
||||
assert response["id"] == user.id
|
||||
end
|
||||
|
||||
test "gets user with user_id", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> get("/api/users/show.json", %{"user_id" => user.id})
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
||||
assert response["id"] == user.id
|
||||
end
|
||||
|
||||
test "gets a user for a logged in user", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
logged_in = insert(:user)
|
||||
|
||||
{:ok, logged_in, user, _activity} = TwitterAPI.follow(logged_in, %{"user_id" => user.id})
|
||||
|
||||
conn = conn
|
||||
|> with_credentials(logged_in.nickname, "test")
|
||||
|> get("/api/users/show.json", %{"user_id" => user.id})
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
||||
assert response["following"] == true
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /statusnet/conversation/:id.json" do
|
||||
test "returns the statuses in the conversation", %{conn: conn} do
|
||||
{:ok, _user} = UserBuilder.insert
|
||||
|
|
@ -248,7 +289,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|> post("/api/friendships/create.json", %{user_id: followed.id})
|
||||
|
||||
current_user = Repo.get(User, current_user.id)
|
||||
assert current_user.following == [User.ap_followers(followed)]
|
||||
assert User.ap_followers(followed) in current_user.following
|
||||
assert json_response(conn, 200) == UserView.render("show.json", %{user: followed, for: current_user})
|
||||
end
|
||||
end
|
||||
|
|
@ -264,7 +305,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
followed = insert(:user)
|
||||
|
||||
{:ok, current_user} = User.follow(current_user, followed)
|
||||
assert current_user.following == [User.ap_followers(followed)]
|
||||
assert User.ap_followers(followed) in current_user.following
|
||||
ActivityPub.follow(current_user, followed)
|
||||
|
||||
conn = conn
|
||||
|
|
@ -272,11 +313,54 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|> post("/api/friendships/destroy.json", %{user_id: followed.id})
|
||||
|
||||
current_user = Repo.get(User, current_user.id)
|
||||
assert current_user.following == []
|
||||
assert current_user.following == [current_user.ap_id]
|
||||
assert json_response(conn, 200) == UserView.render("show.json", %{user: followed, for: current_user})
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /blocks/create.json" do
|
||||
setup [:valid_user]
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
conn = post conn, "/api/blocks/create.json"
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
blocked = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/blocks/create.json", %{user_id: blocked.id})
|
||||
|
||||
current_user = Repo.get(User, current_user.id)
|
||||
assert User.blocks?(current_user, blocked)
|
||||
assert json_response(conn, 200) == UserView.render("show.json", %{user: blocked, for: current_user})
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /blocks/destroy.json" do
|
||||
setup [:valid_user]
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
conn = post conn, "/api/blocks/destroy.json"
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
blocked = insert(:user)
|
||||
|
||||
{:ok, current_user} = User.block(current_user, blocked)
|
||||
assert User.blocks?(current_user, blocked)
|
||||
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/blocks/destroy.json", %{user_id: blocked.id})
|
||||
|
||||
current_user = Repo.get(User, current_user.id)
|
||||
assert current_user.info["blocks"] == []
|
||||
assert json_response(conn, 200) == UserView.render("show.json", %{user: blocked, for: current_user})
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /help/test.json" do
|
||||
test "returns \"ok\"", %{conn: conn} do
|
||||
conn = get conn, "/api/help/test.json"
|
||||
|
|
@ -405,11 +489,13 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
describe "GET /api/externalprofile/show" do
|
||||
test "it returns the user", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> get("/api/externalprofile/show", %{profileurl: user.ap_id})
|
||||
|> assign(:user, user)
|
||||
|> get("/api/externalprofile/show", %{profileurl: other_user.ap_id})
|
||||
|
||||
assert json_response(conn, 200) == UserView.render("show.json", %{user: user})
|
||||
assert json_response(conn, 200) == UserView.render("show.json", %{user: other_user})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -445,7 +531,26 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|> assign(:user, user)
|
||||
|> get("/api/statuses/friends")
|
||||
|
||||
assert json_response(conn, 200) == UserView.render("index.json", %{users: [followed_one, followed_two], for: user})
|
||||
assert MapSet.equal?(MapSet.new(json_response(conn, 200)), MapSet.new(UserView.render("index.json", %{users: [followed_one, followed_two], for: user})))
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /friends/ids" do
|
||||
test "it returns a user's friends", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
followed_one = insert(:user)
|
||||
followed_two = insert(:user)
|
||||
not_followed = insert(:user)
|
||||
|
||||
{:ok, user} = User.follow(user, followed_one)
|
||||
{:ok, user} = User.follow(user, followed_two)
|
||||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/friends/ids")
|
||||
|
||||
expected = [followed_one.id, followed_two.id]
|
||||
assert MapSet.equal?(MapSet.new(Poison.decode!(json_response(conn, 200))), MapSet.new(expected))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -28,13 +28,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
object = Repo.insert!(%Object{data: object_data})
|
||||
|
||||
input = %{
|
||||
"status" => "Hello again, @shp.<script></script>\nThis is on another line. #2hu #epic #phantasmagoric",
|
||||
"status" => "Hello again, @shp.<script></script>\nThis is on another :moominmamma: line. #2hu #epic #phantasmagoric",
|
||||
"media_ids" => [object.id]
|
||||
}
|
||||
|
||||
{ :ok, activity = %Activity{} } = TwitterAPI.create_status(user, input)
|
||||
|
||||
assert get_in(activity.data, ["object", "content"]) == "Hello again, <a href='shp'>@shp</a>.<br>\nThis is on another line. #2hu #epic #phantasmagoric<br>\n<a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>"
|
||||
assert get_in(activity.data, ["object", "content"]) == "Hello again, <a href='shp'>@shp</a>.<script></script><br>This is on another :moominmamma: line. #2hu #epic #phantasmagoric<br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>"
|
||||
assert get_in(activity.data, ["object", "type"]) == "Note"
|
||||
assert get_in(activity.data, ["object", "actor"]) == user.ap_id
|
||||
assert get_in(activity.data, ["actor"]) == user.ap_id
|
||||
|
|
@ -43,6 +43,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
assert Enum.member?(get_in(activity.data, ["to"]), "shp")
|
||||
assert activity.local == true
|
||||
|
||||
assert %{"moominmamma" => "http://localhost:4001/finmoji/128px/moominmamma-128.png"} = activity.data["object"]["emoji"]
|
||||
|
||||
# hashtags
|
||||
assert activity.data["object"]["tag"] == ["2hu", "epic", "phantasmagoric"]
|
||||
|
||||
|
|
@ -179,7 +181,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
followed = insert(:user)
|
||||
|
||||
{:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"user_id" => followed.id})
|
||||
assert user.following == [User.ap_followers(followed)]
|
||||
assert User.ap_followers(followed) in user.following
|
||||
|
||||
{ :error, msg } = TwitterAPI.follow(user, %{"user_id" => followed.id})
|
||||
assert msg == "Could not follow user: #{followed.nickname} is already on your list."
|
||||
|
|
@ -190,7 +192,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
followed = insert(:user)
|
||||
|
||||
{:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
|
||||
assert user.following == [User.ap_followers(followed)]
|
||||
assert User.ap_followers(followed) in user.following
|
||||
|
||||
followed = User.get_by_ap_id(followed.ap_id)
|
||||
assert followed.info["follower_count"] == 1
|
||||
|
|
@ -224,6 +226,40 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
assert msg == "Not subscribed!"
|
||||
end
|
||||
|
||||
test "Block another user using user_id" do
|
||||
user = insert(:user)
|
||||
blocked = insert(:user)
|
||||
|
||||
{:ok, user, blocked} = TwitterAPI.block(user, %{"user_id" => blocked.id})
|
||||
assert User.blocks?(user, blocked)
|
||||
end
|
||||
|
||||
test "Block another user using screen_name" do
|
||||
user = insert(:user)
|
||||
blocked = insert(:user)
|
||||
|
||||
{:ok, user, blocked} = TwitterAPI.block(user, %{"screen_name" => blocked.nickname})
|
||||
assert User.blocks?(user, blocked)
|
||||
end
|
||||
|
||||
test "Unblock another user using user_id" do
|
||||
unblocked = insert(:user)
|
||||
user = insert(:user)
|
||||
User.block(user, unblocked)
|
||||
|
||||
{:ok, user, unblocked} = TwitterAPI.unblock(user, %{"user_id" => unblocked.id})
|
||||
assert user.info["blocks"] == []
|
||||
end
|
||||
|
||||
test "Unblock another user using screen_name" do
|
||||
unblocked = insert(:user)
|
||||
user = insert(:user)
|
||||
User.block(user, unblocked)
|
||||
|
||||
{:ok, user, unblocked} = TwitterAPI.unblock(user, %{"screen_name" => unblocked.nickname})
|
||||
assert user.info["blocks"] == []
|
||||
end
|
||||
|
||||
test "fetch statuses in a context using the conversation id" do
|
||||
{:ok, user} = UserBuilder.insert()
|
||||
{:ok, activity} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"})
|
||||
|
|
@ -365,7 +401,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
{:ok, represented} = TwitterAPI.get_external_profile(user, id)
|
||||
remote = User.get_by_ap_id(id)
|
||||
|
||||
assert represented == UserView.render("show.json", %{user: remote, for: user})
|
||||
assert represented["id"] == UserView.render("show.json", %{user: remote, for: user})["id"]
|
||||
|
||||
# Also fetches the feed.
|
||||
assert Activity.get_create_activity_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status")
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
|
|||
"profile_image_url_profile_size" => image,
|
||||
"profile_image_url_original" => image,
|
||||
"following" => false,
|
||||
"follows_you" => false,
|
||||
"statusnet_blocking" => false,
|
||||
"rights" => %{},
|
||||
"statusnet_profile_url" => user.ap_id,
|
||||
"cover_photo" => nil,
|
||||
|
|
@ -78,6 +80,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
|
|||
"profile_image_url_profile_size" => image,
|
||||
"profile_image_url_original" => image,
|
||||
"following" => true,
|
||||
"follows_you" => false,
|
||||
"statusnet_blocking" => false,
|
||||
"rights" => %{},
|
||||
"statusnet_profile_url" => user.ap_id,
|
||||
"cover_photo" => nil,
|
||||
|
|
@ -86,4 +90,67 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
|
|||
|
||||
assert represented == UserView.render("show.json", %{user: user, for: follower})
|
||||
end
|
||||
|
||||
test "A user that follows you", %{user: user} do
|
||||
follower = insert(:user)
|
||||
{:ok, follower} = User.follow(follower, user)
|
||||
{:ok, user} = User.update_follower_count(user)
|
||||
image = "https://placehold.it/48x48"
|
||||
represented = %{
|
||||
"id" => follower.id,
|
||||
"name" => follower.name,
|
||||
"screen_name" => follower.nickname,
|
||||
"description" => HtmlSanitizeEx.strip_tags(follower.bio),
|
||||
"created_at" => follower.inserted_at |> Utils.format_naive_asctime,
|
||||
"favourites_count" => 0,
|
||||
"statuses_count" => 0,
|
||||
"friends_count" => 1,
|
||||
"followers_count" => 0,
|
||||
"profile_image_url" => image,
|
||||
"profile_image_url_https" => image,
|
||||
"profile_image_url_profile_size" => image,
|
||||
"profile_image_url_original" => image,
|
||||
"following" => false,
|
||||
"follows_you" => true,
|
||||
"statusnet_blocking" => false,
|
||||
"rights" => %{},
|
||||
"statusnet_profile_url" => follower.ap_id,
|
||||
"cover_photo" => nil,
|
||||
"background_image" => nil
|
||||
}
|
||||
|
||||
assert represented == UserView.render("show.json", %{user: follower, for: user})
|
||||
end
|
||||
|
||||
test "A blocked user for the blocker", %{user: user} do
|
||||
user = insert(:user)
|
||||
blocker = insert(:user)
|
||||
User.block(blocker, user)
|
||||
image = "https://placehold.it/48x48"
|
||||
represented = %{
|
||||
"id" => user.id,
|
||||
"name" => user.name,
|
||||
"screen_name" => user.nickname,
|
||||
"description" => HtmlSanitizeEx.strip_tags(user.bio),
|
||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime,
|
||||
"favourites_count" => 0,
|
||||
"statuses_count" => 0,
|
||||
"friends_count" => 0,
|
||||
"followers_count" => 0,
|
||||
"profile_image_url" => image,
|
||||
"profile_image_url_https" => image,
|
||||
"profile_image_url_profile_size" => image,
|
||||
"profile_image_url_original" => image,
|
||||
"following" => false,
|
||||
"follows_you" => false,
|
||||
"statusnet_blocking" => true,
|
||||
"rights" => %{},
|
||||
"statusnet_profile_url" => user.ap_id,
|
||||
"cover_photo" => nil,
|
||||
"background_image" => nil
|
||||
}
|
||||
|
||||
blocker = Repo.get(User, blocker.id)
|
||||
assert represented == UserView.render("show.json", %{user: user, for: blocker})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -46,7 +46,8 @@ defmodule Pleroma.Web.WebsubTest do
|
|||
end
|
||||
|
||||
{:error, sub} = Websub.verify(sub, getter)
|
||||
assert sub.state == "rejected"
|
||||
# Keep the current state.
|
||||
assert sub.state == "requested"
|
||||
end
|
||||
|
||||
test "an incoming subscription request" do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue