2020-10-12 11:00:50 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-25 23:11:42 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-10-12 11:00:50 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-01-20 05:23:21 -07:00
|
|
|
defmodule Mix.Tasks.Pleroma.EmailTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
|
|
|
|
import Swoosh.TestAssertions
|
|
|
|
|
|
|
|
alias Pleroma.Config
|
|
|
|
alias Pleroma.Tests.ObanHelpers
|
|
|
|
|
2020-09-24 17:24:44 -06:00
|
|
|
import Pleroma.Factory
|
|
|
|
|
2020-01-20 05:23:21 -07:00
|
|
|
setup_all do
|
|
|
|
Mix.shell(Mix.Shell.Process)
|
|
|
|
|
|
|
|
on_exit(fn ->
|
|
|
|
Mix.shell(Mix.Shell.IO)
|
|
|
|
end)
|
|
|
|
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2020-08-19 03:57:29 -06:00
|
|
|
setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true)
|
2020-09-24 17:24:44 -06:00
|
|
|
setup do: clear_config([:instance, :account_activation_required], true)
|
2020-08-19 03:57:29 -06:00
|
|
|
|
2020-01-20 05:23:21 -07:00
|
|
|
describe "pleroma.email test" do
|
|
|
|
test "Sends test email with no given address" do
|
|
|
|
mail_to = Config.get([:instance, :email])
|
|
|
|
|
|
|
|
:ok = Mix.Tasks.Pleroma.Email.run(["test"])
|
|
|
|
|
|
|
|
ObanHelpers.perform_all()
|
|
|
|
|
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
|
|
|
assert message =~ "Test email has been sent"
|
|
|
|
|
|
|
|
assert_email_sent(
|
|
|
|
to: mail_to,
|
|
|
|
html_body: ~r/a test email was requested./i
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "Sends test email with given address" do
|
|
|
|
mail_to = "hewwo@example.com"
|
|
|
|
|
|
|
|
:ok = Mix.Tasks.Pleroma.Email.run(["test", "--to", mail_to])
|
|
|
|
|
|
|
|
ObanHelpers.perform_all()
|
|
|
|
|
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
|
|
|
assert message =~ "Test email has been sent"
|
|
|
|
|
|
|
|
assert_email_sent(
|
|
|
|
to: mail_to,
|
|
|
|
html_body: ~r/a test email was requested./i
|
|
|
|
)
|
|
|
|
end
|
2020-09-24 17:24:44 -06:00
|
|
|
|
|
|
|
test "Sends confirmation emails" do
|
|
|
|
local_user1 =
|
|
|
|
insert(:user, %{
|
2020-10-13 13:29:34 -06:00
|
|
|
is_confirmed: false,
|
2020-09-24 17:24:44 -06:00
|
|
|
confirmation_token: "mytoken",
|
2020-10-12 16:42:27 -06:00
|
|
|
is_active: true,
|
2020-09-24 17:24:44 -06:00
|
|
|
email: "local1@pleroma.com",
|
|
|
|
local: true
|
|
|
|
})
|
|
|
|
|
|
|
|
local_user2 =
|
|
|
|
insert(:user, %{
|
2020-10-13 13:29:34 -06:00
|
|
|
is_confirmed: false,
|
2020-09-24 17:24:44 -06:00
|
|
|
confirmation_token: "mytoken",
|
2020-10-12 16:42:27 -06:00
|
|
|
is_active: true,
|
2020-09-24 17:24:44 -06:00
|
|
|
email: "local2@pleroma.com",
|
|
|
|
local: true
|
|
|
|
})
|
|
|
|
|
|
|
|
:ok = Mix.Tasks.Pleroma.Email.run(["resend_confirmation_emails"])
|
|
|
|
|
|
|
|
ObanHelpers.perform_all()
|
|
|
|
|
|
|
|
assert_email_sent(to: {local_user1.name, local_user1.email})
|
|
|
|
assert_email_sent(to: {local_user2.name, local_user2.email})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "Does not send confirmation email to inappropriate users" do
|
|
|
|
# confirmed user
|
|
|
|
insert(:user, %{
|
2020-10-13 13:29:34 -06:00
|
|
|
is_confirmed: true,
|
2020-09-24 17:24:44 -06:00
|
|
|
confirmation_token: "mytoken",
|
2020-10-12 16:42:27 -06:00
|
|
|
is_active: true,
|
2020-09-24 17:24:44 -06:00
|
|
|
email: "confirmed@pleroma.com",
|
|
|
|
local: true
|
|
|
|
})
|
|
|
|
|
|
|
|
# remote user
|
|
|
|
insert(:user, %{
|
2020-10-12 16:42:27 -06:00
|
|
|
is_active: true,
|
2020-09-24 17:24:44 -06:00
|
|
|
email: "remote@not-pleroma.com",
|
|
|
|
local: false
|
|
|
|
})
|
|
|
|
|
|
|
|
# deactivated user =
|
|
|
|
insert(:user, %{
|
2020-10-12 16:42:27 -06:00
|
|
|
is_active: false,
|
2020-09-24 17:24:44 -06:00
|
|
|
email: "deactivated@pleroma.com",
|
|
|
|
local: false
|
|
|
|
})
|
|
|
|
|
|
|
|
# invisible user
|
|
|
|
insert(:user, %{
|
2020-10-12 16:42:27 -06:00
|
|
|
is_active: true,
|
2020-09-24 17:24:44 -06:00
|
|
|
email: "invisible@pleroma.com",
|
|
|
|
local: true,
|
|
|
|
invisible: true
|
|
|
|
})
|
|
|
|
|
|
|
|
:ok = Mix.Tasks.Pleroma.Email.run(["resend_confirmation_emails"])
|
|
|
|
|
|
|
|
ObanHelpers.perform_all()
|
|
|
|
|
|
|
|
refute_email_sent()
|
|
|
|
end
|
2020-01-20 05:23:21 -07:00
|
|
|
end
|
|
|
|
end
|