Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into feature/digest-email
This commit is contained in:
commit
87013f8438
33 changed files with 428 additions and 91 deletions
|
|
@ -28,4 +28,18 @@ defmodule Pleroma.ActivityTest do
|
|||
|
||||
assert activity == found_activity
|
||||
end
|
||||
|
||||
test "reply count" do
|
||||
%{id: id, data: %{"object" => %{"id" => object_ap_id}}} = activity = insert(:note_activity)
|
||||
|
||||
replies_count = activity.data["object"]["repliesCount"] || 0
|
||||
expected_increase = replies_count + 1
|
||||
Activity.increase_replies_count(object_ap_id)
|
||||
%{data: %{"object" => %{"repliesCount" => actual_increase}}} = Activity.get_by_id(id)
|
||||
assert expected_increase == actual_increase
|
||||
expected_decrease = expected_increase - 1
|
||||
Activity.decrease_replies_count(object_ap_id)
|
||||
%{data: %{"object" => %{"repliesCount" => actual_decrease}}} = Activity.get_by_id(id)
|
||||
assert expected_decrease == actual_decrease
|
||||
end
|
||||
end
|
||||
|
|
|
|||
62
test/tasks/instance.exs
Normal file
62
test/tasks/instance.exs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
defmodule Pleroma.InstanceTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
setup do
|
||||
File.mkdir_p!(tmp_path())
|
||||
on_exit(fn -> File.rm_rf(tmp_path()) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
defp tmp_path do
|
||||
"/tmp/generated_files/"
|
||||
end
|
||||
|
||||
test "running gen" do
|
||||
mix_task = fn ->
|
||||
Mix.Tasks.Pleroma.Instance.run([
|
||||
"gen",
|
||||
"--output",
|
||||
tmp_path() <> "generated_config.exs",
|
||||
"--output-psql",
|
||||
tmp_path() <> "setup.psql",
|
||||
"--domain",
|
||||
"test.pleroma.social",
|
||||
"--instance-name",
|
||||
"Pleroma",
|
||||
"--admin-email",
|
||||
"admin@example.com",
|
||||
"--notify-email",
|
||||
"notify@example.com",
|
||||
"--dbhost",
|
||||
"dbhost",
|
||||
"--dbname",
|
||||
"dbname",
|
||||
"--dbuser",
|
||||
"dbuser",
|
||||
"--dbpass",
|
||||
"dbpass",
|
||||
"--indexable",
|
||||
"y"
|
||||
])
|
||||
end
|
||||
|
||||
ExUnit.CaptureIO.capture_io(fn ->
|
||||
mix_task.()
|
||||
end)
|
||||
|
||||
generated_config = File.read!(tmp_path() <> "generated_config.exs")
|
||||
assert generated_config =~ "host: \"test.pleroma.social\""
|
||||
assert generated_config =~ "name: \"Pleroma\""
|
||||
assert generated_config =~ "email: \"admin@example.com\""
|
||||
assert generated_config =~ "notify_email: \"notify@example.com\""
|
||||
assert generated_config =~ "hostname: \"dbhost\""
|
||||
assert generated_config =~ "database: \"dbname\""
|
||||
assert generated_config =~ "username: \"dbuser\""
|
||||
assert generated_config =~ "password: \"dbpass\""
|
||||
assert File.read!(tmp_path() <> "setup.psql") == generated_setup_psql()
|
||||
end
|
||||
|
||||
defp generated_setup_psql do
|
||||
~s(CREATE USER dbuser WITH ENCRYPTED PASSWORD 'dbpass';\nCREATE DATABASE dbname OWNER dbuser;\n\\c dbname;\n--Extensions made by ecto.migrate that need superuser access\nCREATE EXTENSION IF NOT EXISTS citext;\nCREATE EXTENSION IF NOT EXISTS pg_trgm;\nCREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";\n)
|
||||
end
|
||||
end
|
||||
|
|
@ -253,6 +253,36 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
assert Activity.get_by_ap_id(data["id"])
|
||||
end
|
||||
|
||||
test "it accepts messages from actors that are followed by the user", %{conn: conn} do
|
||||
recipient = insert(:user)
|
||||
actor = insert(:user, %{ap_id: "http://mastodon.example.org/users/actor"})
|
||||
|
||||
{:ok, recipient} = User.follow(recipient, actor)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|
||||
object =
|
||||
data["object"]
|
||||
|> Map.put("attributedTo", actor.ap_id)
|
||||
|
||||
data =
|
||||
data
|
||||
|> Map.put("actor", actor.ap_id)
|
||||
|> Map.put("object", object)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:valid_signature, true)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{recipient.nickname}/inbox", data)
|
||||
|
||||
assert "ok" == json_response(conn, 200)
|
||||
:timer.sleep(500)
|
||||
assert Activity.get_by_ap_id(data["id"])
|
||||
end
|
||||
|
||||
test "it rejects reads from other users", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
otheruser = insert(:user)
|
||||
|
|
|
|||
|
|
@ -58,8 +58,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
assert returned_activity.data["object"]["inReplyToAtomUri"] ==
|
||||
"https://shitposter.club/notice/2827873"
|
||||
|
||||
assert returned_activity.data["object"]["inReplyToStatusId"] == activity.id
|
||||
end
|
||||
|
||||
test "it works for incoming notices" do
|
||||
|
|
|
|||
|
|
@ -317,13 +317,21 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
assert token_record
|
||||
refute token_record.used
|
||||
|
||||
Swoosh.TestAssertions.assert_email_sent(
|
||||
notify_email = Pleroma.Config.get([:instance, :notify_email])
|
||||
instance_name = Pleroma.Config.get([:instance, :name])
|
||||
|
||||
email =
|
||||
Pleroma.Emails.UserEmail.user_invitation_email(
|
||||
user,
|
||||
token_record,
|
||||
recipient_email,
|
||||
recipient_name
|
||||
)
|
||||
|
||||
Swoosh.TestAssertions.assert_email_sent(
|
||||
from: {instance_name, notify_email},
|
||||
to: {recipient_name, recipient_email},
|
||||
html_body: email.html_body
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -342,7 +342,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
activity = Activity.get_by_id(id)
|
||||
|
||||
assert activity.data["context"] == replied_to.data["context"]
|
||||
assert activity.data["object"]["inReplyToStatusId"] == replied_to.id
|
||||
assert Activity.get_in_reply_to_activity(activity).id == replied_to.id
|
||||
end
|
||||
|
||||
test "posting a status with an invalid in_reply_to_id", %{conn: conn} do
|
||||
|
|
@ -1008,8 +1008,41 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses/#{activity.id}/reblog")
|
||||
|
||||
assert %{"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1}} =
|
||||
json_response(conn, 200)
|
||||
assert %{
|
||||
"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1},
|
||||
"reblogged" => true
|
||||
} = json_response(conn, 200)
|
||||
|
||||
assert to_string(activity.id) == id
|
||||
end
|
||||
|
||||
test "reblogged status for another user", %{conn: conn} do
|
||||
activity = insert(:note_activity)
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
user3 = insert(:user)
|
||||
{:ok, reblog_activity1, _object} = CommonAPI.repeat(activity.id, user1)
|
||||
{:ok, _, _object} = CommonAPI.repeat(activity.id, user2)
|
||||
|
||||
conn_res =
|
||||
conn
|
||||
|> assign(:user, user3)
|
||||
|> get("/api/v1/statuses/#{reblog_activity1.id}")
|
||||
|
||||
assert %{
|
||||
"reblog" => %{"id" => id, "reblogged" => false, "reblogs_count" => 2},
|
||||
"reblogged" => false
|
||||
} = json_response(conn_res, 200)
|
||||
|
||||
conn_res =
|
||||
conn
|
||||
|> assign(:user, user2)
|
||||
|> get("/api/v1/statuses/#{reblog_activity1.id}")
|
||||
|
||||
assert %{
|
||||
"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 2},
|
||||
"reblogged" => true
|
||||
} = json_response(conn_res, 200)
|
||||
|
||||
assert to_string(activity.id) == id
|
||||
end
|
||||
|
|
@ -1587,6 +1620,40 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
assert id == to_string(other_user.id)
|
||||
end
|
||||
|
||||
test "following / unfollowing errors" do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|
||||
# self follow
|
||||
conn_res = post(conn, "/api/v1/accounts/#{user.id}/follow")
|
||||
assert %{"error" => "Record not found"} = json_response(conn_res, 404)
|
||||
|
||||
# self unfollow
|
||||
user = User.get_cached_by_id(user.id)
|
||||
conn_res = post(conn, "/api/v1/accounts/#{user.id}/unfollow")
|
||||
assert %{"error" => "Record not found"} = json_response(conn_res, 404)
|
||||
|
||||
# self follow via uri
|
||||
user = User.get_cached_by_id(user.id)
|
||||
conn_res = post(conn, "/api/v1/follows", %{"uri" => user.nickname})
|
||||
assert %{"error" => "Record not found"} = json_response(conn_res, 404)
|
||||
|
||||
# follow non existing user
|
||||
conn_res = post(conn, "/api/v1/accounts/doesntexist/follow")
|
||||
assert %{"error" => "Record not found"} = json_response(conn_res, 404)
|
||||
|
||||
# follow non existing user via uri
|
||||
conn_res = post(conn, "/api/v1/follows", %{"uri" => "doesntexist"})
|
||||
assert %{"error" => "Record not found"} = json_response(conn_res, 404)
|
||||
|
||||
# unfollow non existing user
|
||||
conn_res = post(conn, "/api/v1/accounts/doesntexist/unfollow")
|
||||
assert %{"error" => "Record not found"} = json_response(conn_res, 404)
|
||||
end
|
||||
|
||||
test "muting / unmuting a user", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
|
@ -1981,13 +2048,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
conn = get(conn, "/api/v1/instance")
|
||||
assert result = json_response(conn, 200)
|
||||
|
||||
email = Pleroma.Config.get([:instance, :email])
|
||||
# Note: not checking for "max_toot_chars" since it's optional
|
||||
assert %{
|
||||
"uri" => _,
|
||||
"title" => _,
|
||||
"description" => _,
|
||||
"version" => _,
|
||||
"email" => _,
|
||||
"email" => from_config_email,
|
||||
"urls" => %{
|
||||
"streaming_api" => _
|
||||
},
|
||||
|
|
@ -1996,6 +2064,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
"languages" => _,
|
||||
"registrations" => _
|
||||
} = result
|
||||
|
||||
assert email == from_config_email
|
||||
end
|
||||
|
||||
test "get instance stats", %{conn: conn} do
|
||||
|
|
@ -2724,7 +2794,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
activity = Activity.get_by_id(id)
|
||||
|
||||
assert activity.data["object"]["inReplyTo"] == replied_to.data["object"]["id"]
|
||||
assert activity.data["object"]["inReplyToStatusId"] == replied_to.id
|
||||
assert Activity.get_in_reply_to_activity(activity).id == replied_to.id
|
||||
|
||||
# Reblog from the third user
|
||||
conn2 =
|
||||
|
|
|
|||
|
|
@ -22,8 +22,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||
alias Pleroma.Web.TwitterAPI.UserView
|
||||
|
||||
import Pleroma.Factory
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
@banner "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
|
||||
|
||||
|
|
@ -1063,8 +1064,14 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
test "it sends an email to user", %{user: user} do
|
||||
token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
|
||||
|
||||
Swoosh.TestAssertions.assert_email_sent(
|
||||
Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
|
||||
email = Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
|
||||
notify_email = Pleroma.Config.get([:instance, :notify_email])
|
||||
instance_name = Pleroma.Config.get([:instance, :name])
|
||||
|
||||
assert_email_sent(
|
||||
from: {instance_name, notify_email},
|
||||
to: {user.name, user.email},
|
||||
html_body: email.html_body
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
@ -1163,8 +1170,14 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|> assign(:user, user)
|
||||
|> post("/api/account/resend_confirmation_email?email=#{user.email}")
|
||||
|
||||
Swoosh.TestAssertions.assert_email_sent(
|
||||
Pleroma.Emails.UserEmail.account_confirmation_email(user)
|
||||
email = Pleroma.Emails.UserEmail.account_confirmation_email(user)
|
||||
notify_email = Pleroma.Config.get([:instance, :notify_email])
|
||||
instance_name = Pleroma.Config.get([:instance, :name])
|
||||
|
||||
assert_email_sent(
|
||||
from: {instance_name, notify_email},
|
||||
to: {user.name, user.email},
|
||||
html_body: email.html_body
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
get_in(activity.data, ["object", "context"])
|
||||
|
||||
assert get_in(reply.data, ["object", "inReplyTo"]) == get_in(activity.data, ["object", "id"])
|
||||
assert get_in(reply.data, ["object", "inReplyToStatusId"]) == activity.id
|
||||
assert Activity.get_in_reply_to_activity(reply).id == activity.id
|
||||
end
|
||||
|
||||
test "Follow another user using user_id" do
|
||||
|
|
@ -325,8 +325,15 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
assert user.info.confirmation_pending
|
||||
|
||||
email = Pleroma.Emails.UserEmail.account_confirmation_email(user)
|
||||
|
||||
notify_email = Pleroma.Config.get([:instance, :notify_email])
|
||||
instance_name = Pleroma.Config.get([:instance, :name])
|
||||
|
||||
Swoosh.TestAssertions.assert_email_sent(
|
||||
Pleroma.Emails.UserEmail.account_confirmation_email(user)
|
||||
from: {instance_name, notify_email},
|
||||
to: {user.name, user.email},
|
||||
html_body: email.html_body
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,21 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
assert response == "job started"
|
||||
end
|
||||
|
||||
test "it imports new-style mastodon follow lists", %{conn: conn} do
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user1)
|
||||
|> post("/api/pleroma/follow_import", %{
|
||||
"list" => "Account address,Show boosts\n#{user2.ap_id},true"
|
||||
})
|
||||
|> json_response(:ok)
|
||||
|
||||
assert response == "job started"
|
||||
end
|
||||
|
||||
test "requires 'follow' permission", %{conn: conn} do
|
||||
token1 = insert(:oauth_token, scopes: ["read", "write"])
|
||||
token2 = insert(:oauth_token, scopes: ["follow"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue