Merge branch 'fix/signup-without-email' into 'develop'
Allow account registration without an email See merge request pleroma/pleroma!2246
This commit is contained in:
parent
e3ccaeaa53
commit
e7837bc14e
5 changed files with 90 additions and 5 deletions
|
|
@ -412,7 +412,11 @@ defmodule Pleroma.UserTest do
|
|||
assert activity.actor == welcome_user.ap_id
|
||||
end
|
||||
|
||||
test "it requires an email, name, nickname and password, bio is optional" do
|
||||
clear_config([:instance, :account_activation_required])
|
||||
|
||||
test "it requires an email, name, nickname and password, bio is optional when account_activation_required is enabled" do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
|
||||
@full_user_data
|
||||
|> Map.keys()
|
||||
|> Enum.each(fn key ->
|
||||
|
|
@ -423,6 +427,19 @@ defmodule Pleroma.UserTest do
|
|||
end)
|
||||
end
|
||||
|
||||
test "it requires an name, nickname and password, bio and email are optional when account_activation_required is disabled" do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], false)
|
||||
|
||||
@full_user_data
|
||||
|> Map.keys()
|
||||
|> Enum.each(fn key ->
|
||||
params = Map.delete(@full_user_data, key)
|
||||
changeset = User.register_changeset(%User{}, params)
|
||||
|
||||
assert if key in [:bio, :email], do: changeset.valid?, else: not changeset.valid?
|
||||
end)
|
||||
end
|
||||
|
||||
test "it restricts certain nicknames" do
|
||||
[restricted_name | _] = Pleroma.Config.get([User, :restricted_nicknames])
|
||||
|
||||
|
|
|
|||
|
|
@ -601,6 +601,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
[valid_params: valid_params]
|
||||
end
|
||||
|
||||
clear_config([:instance, :account_activation_required])
|
||||
|
||||
test "Account registration via Application", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, "/api/v1/apps", %{
|
||||
|
|
@ -685,7 +687,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert json_response(res, 200)
|
||||
|
||||
[{127, 0, 0, 1}, {127, 0, 0, 2}, {127, 0, 0, 3}, {127, 0, 0, 4}]
|
||||
|> Stream.zip(valid_params)
|
||||
|> Stream.zip(Map.delete(valid_params, :email))
|
||||
|> Enum.each(fn {ip, {attr, _}} ->
|
||||
res =
|
||||
conn
|
||||
|
|
@ -697,6 +699,54 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end)
|
||||
end
|
||||
|
||||
clear_config([:instance, :account_activation_required])
|
||||
|
||||
test "returns bad_request if missing email params when :account_activation_required is enabled",
|
||||
%{conn: conn, valid_params: valid_params} do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
|
||||
app_token = insert(:oauth_token, user: nil)
|
||||
conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> Map.put(:remote_ip, {127, 0, 0, 5})
|
||||
|> post("/api/v1/accounts", Map.delete(valid_params, :email))
|
||||
|
||||
assert json_response(res, 400) == %{"error" => "Missing parameters"}
|
||||
|
||||
res =
|
||||
conn
|
||||
|> Map.put(:remote_ip, {127, 0, 0, 6})
|
||||
|> post("/api/v1/accounts", Map.put(valid_params, :email, ""))
|
||||
|
||||
assert json_response(res, 400) == %{"error" => "{\"email\":[\"can't be blank\"]}"}
|
||||
end
|
||||
|
||||
test "allow registration without an email", %{conn: conn, valid_params: valid_params} do
|
||||
app_token = insert(:oauth_token, user: nil)
|
||||
conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> Map.put(:remote_ip, {127, 0, 0, 7})
|
||||
|> post("/api/v1/accounts", Map.delete(valid_params, :email))
|
||||
|
||||
assert json_response(res, 200)
|
||||
end
|
||||
|
||||
test "allow registration with an empty email", %{conn: conn, valid_params: valid_params} do
|
||||
app_token = insert(:oauth_token, user: nil)
|
||||
conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> Map.put(:remote_ip, {127, 0, 0, 8})
|
||||
|> post("/api/v1/accounts", Map.put(valid_params, :email, ""))
|
||||
|
||||
assert json_response(res, 200)
|
||||
end
|
||||
|
||||
test "returns forbidden if token is invalid", %{conn: conn, valid_params: valid_params} do
|
||||
conn = put_req_header(conn, "authorization", "Bearer " <> "invalid-token")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue