Merge branch 'email-fix-develop' into 'develop'

Allow emails to be sent again (develop)

Closes #2172

See merge request pleroma/pleroma!3025
This commit is contained in:
lain 2020-09-23 09:05:52 +00:00
commit 34235bc02a
6 changed files with 29 additions and 14 deletions

View File

@ -28,6 +28,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Removed `:managed_config` option. In practice, it was accidentally removed with 2.0.0 release when frontends were - Removed `:managed_config` option. In practice, it was accidentally removed with 2.0.0 release when frontends were
switched to a new configuration mechanism, however it was not officially removed until now. switched to a new configuration mechanism, however it was not officially removed until now.
### Fixed
- Allow sending out emails again.
## [2.1.2] - 2020-09-17 ## [2.1.2] - 2020-09-17

View File

@ -35,6 +35,11 @@ def perform(:deliver_async, email, config), do: deliver(email, config)
def deliver(email, config \\ []) def deliver(email, config \\ [])
def deliver(email, config) do def deliver(email, config) do
# temporary hackney fix until hackney max_connections bug is fixed
# https://git.pleroma.social/pleroma/pleroma/-/issues/2101
email =
Swoosh.Email.put_private(email, :hackney_options, ssl_options: [versions: [:"tlsv1.2"]])
case enabled?() do case enabled?() do
true -> Swoosh.Mailer.deliver(email, parse_config(config)) true -> Swoosh.Mailer.deliver(email, parse_config(config))
false -> {:error, :deliveries_disabled} false -> {:error, :deliveries_disabled}

View File

@ -5,6 +5,8 @@
defmodule Pleroma.Web.MastodonAPI.AuthController do defmodule Pleroma.Web.MastodonAPI.AuthController do
use Pleroma.Web, :controller use Pleroma.Web, :controller
import Pleroma.Web.ControllerHelper, only: [json_response: 3]
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.OAuth.App alias Pleroma.Web.OAuth.App
alias Pleroma.Web.OAuth.Authorization alias Pleroma.Web.OAuth.Authorization
@ -61,9 +63,7 @@ def password_reset(conn, params) do
TwitterAPI.password_reset(nickname_or_email) TwitterAPI.password_reset(nickname_or_email)
conn json_response(conn, :no_content, "")
|> put_status(:no_content)
|> json("")
end end
defp local_mastodon_root_path(conn) do defp local_mastodon_root_path(conn) do

View File

@ -509,7 +509,12 @@ test "it sends a confirm email" do
cng = User.register_changeset(%User{}, @full_user_data) cng = User.register_changeset(%User{}, @full_user_data)
{:ok, registered_user} = User.register(cng) {:ok, registered_user} = User.register(cng)
ObanHelpers.perform_all() ObanHelpers.perform_all()
assert_email_sent(Pleroma.Emails.UserEmail.account_confirmation_email(registered_user))
Pleroma.Emails.UserEmail.account_confirmation_email(registered_user)
# temporary hackney fix until hackney max_connections bug is fixed
# https://git.pleroma.social/pleroma/pleroma/-/issues/2101
|> Swoosh.Email.put_private(:hackney_options, ssl_options: [versions: [:"tlsv1.2"]])
|> assert_email_sent()
end end
test "it requires an email, name, nickname and password, bio is optional when account_activation_required is enabled" do test "it requires an email, name, nickname and password, bio is optional when account_activation_required is enabled" do

View File

@ -1977,7 +1977,12 @@ test "it resend emails for two users", %{conn: conn, admin: admin} do
}" }"
ObanHelpers.perform_all() ObanHelpers.perform_all()
assert_email_sent(Pleroma.Emails.UserEmail.account_confirmation_email(first_user))
Pleroma.Emails.UserEmail.account_confirmation_email(first_user)
# temporary hackney fix until hackney max_connections bug is fixed
# https://git.pleroma.social/pleroma/pleroma/-/issues/2101
|> Swoosh.Email.put_private(:hackney_options, ssl_options: [versions: [:"tlsv1.2"]])
|> assert_email_sent()
end end
end end

View File

@ -61,7 +61,7 @@ test "redirects to the getting-started page when referer is not present", %{conn
end end
test "it returns 204", %{conn: conn} do test "it returns 204", %{conn: conn} do
assert json_response(conn, :no_content) assert empty_json_response(conn)
end end
test "it creates a PasswordResetToken record for user", %{user: user} do test "it creates a PasswordResetToken record for user", %{user: user} do
@ -91,7 +91,7 @@ test "it returns 204", %{conn: conn} do
assert conn assert conn
|> post("/auth/password?nickname=#{user.nickname}") |> post("/auth/password?nickname=#{user.nickname}")
|> json_response(:no_content) |> empty_json_response()
ObanHelpers.perform_all() ObanHelpers.perform_all()
token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id) token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
@ -112,7 +112,7 @@ test "it doesn't fail when a user has no email", %{conn: conn} do
assert conn assert conn
|> post("/auth/password?nickname=#{user.nickname}") |> post("/auth/password?nickname=#{user.nickname}")
|> json_response(:no_content) |> empty_json_response()
end end
end end
@ -125,24 +125,21 @@ test "it doesn't fail when a user has no email", %{conn: conn} do
test "it returns 204 when user is not found", %{conn: conn, user: user} do test "it returns 204 when user is not found", %{conn: conn, user: user} do
conn = post(conn, "/auth/password?email=nonexisting_#{user.email}") conn = post(conn, "/auth/password?email=nonexisting_#{user.email}")
assert conn assert empty_json_response(conn)
|> json_response(:no_content)
end end
test "it returns 204 when user is not local", %{conn: conn, user: user} do test "it returns 204 when user is not local", %{conn: conn, user: user} do
{:ok, user} = Repo.update(Ecto.Changeset.change(user, local: false)) {:ok, user} = Repo.update(Ecto.Changeset.change(user, local: false))
conn = post(conn, "/auth/password?email=#{user.email}") conn = post(conn, "/auth/password?email=#{user.email}")
assert conn assert empty_json_response(conn)
|> json_response(:no_content)
end end
test "it returns 204 when user is deactivated", %{conn: conn, user: user} do test "it returns 204 when user is deactivated", %{conn: conn, user: user} do
{:ok, user} = Repo.update(Ecto.Changeset.change(user, deactivated: true, local: true)) {:ok, user} = Repo.update(Ecto.Changeset.change(user, deactivated: true, local: true))
conn = post(conn, "/auth/password?email=#{user.email}") conn = post(conn, "/auth/password?email=#{user.email}")
assert conn assert empty_json_response(conn)
|> json_response(:no_content)
end end
end end