[#1985] Prevented force login on registration if account approval and/or email confirmation needed.
Refactored login code in OAuthController, reused in AccountController. Added tests.
This commit is contained in:
parent
a1a43f39dc
commit
27b0a8b155
4 changed files with 103 additions and 62 deletions
|
|
@ -5,7 +5,6 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
|
|
@ -16,8 +15,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
import Pleroma.Factory
|
||||
|
||||
describe "account fetching" do
|
||||
setup do: clear_config([:instance, :limit_to_local_content])
|
||||
|
||||
test "works by id" do
|
||||
%User{id: user_id} = insert(:user)
|
||||
|
||||
|
|
@ -42,7 +39,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
test "works by nickname for remote users" do
|
||||
Config.put([:instance, :limit_to_local_content], false)
|
||||
clear_config([:instance, :limit_to_local_content], false)
|
||||
|
||||
user = insert(:user, nickname: "user@example.com", local: false)
|
||||
|
||||
|
|
@ -53,7 +50,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
test "respects limit_to_local_content == :all for remote user nicknames" do
|
||||
Config.put([:instance, :limit_to_local_content], :all)
|
||||
clear_config([:instance, :limit_to_local_content], :all)
|
||||
|
||||
user = insert(:user, nickname: "user@example.com", local: false)
|
||||
|
||||
|
|
@ -63,7 +60,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
test "respects limit_to_local_content == :unauthenticated for remote user nicknames" do
|
||||
Config.put([:instance, :limit_to_local_content], :unauthenticated)
|
||||
clear_config([:instance, :limit_to_local_content], :unauthenticated)
|
||||
|
||||
user = insert(:user, nickname: "user@example.com", local: false)
|
||||
reading_user = insert(:user)
|
||||
|
|
@ -903,8 +900,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
[valid_params: valid_params]
|
||||
end
|
||||
|
||||
test "Account registration via Application, no confirmation required", %{conn: conn} do
|
||||
test "registers and logs in without :account_activation_required / :account_approval_required",
|
||||
%{conn: conn} do
|
||||
clear_config([:instance, :account_activation_required], false)
|
||||
clear_config([:instance, :account_approval_required], false)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -962,15 +961,16 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
token_from_db = Repo.get_by(Token, token: token)
|
||||
assert token_from_db
|
||||
token_from_db = Repo.preload(token_from_db, :user)
|
||||
assert token_from_db.user
|
||||
refute token_from_db.user.confirmation_pending
|
||||
user = Repo.preload(token_from_db, :user).user
|
||||
|
||||
assert user
|
||||
refute user.confirmation_pending
|
||||
refute user.approval_pending
|
||||
end
|
||||
|
||||
setup do: clear_config([:instance, :account_approval_required])
|
||||
|
||||
test "Account registration via Application", %{conn: conn} do
|
||||
test "registers but does not log in with :account_activation_required", %{conn: conn} do
|
||||
clear_config([:instance, :account_activation_required], true)
|
||||
clear_config([:instance, :account_approval_required], false)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -1019,23 +1019,18 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
agreement: true
|
||||
})
|
||||
|
||||
%{
|
||||
"access_token" => token,
|
||||
"created_at" => _created_at,
|
||||
"scope" => ^scope,
|
||||
"token_type" => "Bearer"
|
||||
} = json_response_and_validate_schema(conn, 200)
|
||||
response = json_response_and_validate_schema(conn, 200)
|
||||
assert %{"identifier" => "missing_confirmed_email"} = response
|
||||
refute response["access_token"]
|
||||
refute response["token_type"]
|
||||
|
||||
token_from_db = Repo.get_by(Token, token: token)
|
||||
assert token_from_db
|
||||
token_from_db = Repo.preload(token_from_db, :user)
|
||||
assert token_from_db.user
|
||||
|
||||
assert token_from_db.user.confirmation_pending
|
||||
user = Repo.get_by(User, email: "lain@example.org")
|
||||
assert user.confirmation_pending
|
||||
end
|
||||
|
||||
test "Account registration via app with account_approval_required", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :account_approval_required], true)
|
||||
test "registers but does not log in with :account_approval_required", %{conn: conn} do
|
||||
clear_config([:instance, :account_approval_required], true)
|
||||
clear_config([:instance, :account_activation_required], false)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -1085,21 +1080,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
reason: "I'm a cool dude, bro"
|
||||
})
|
||||
|
||||
%{
|
||||
"access_token" => token,
|
||||
"created_at" => _created_at,
|
||||
"scope" => ^scope,
|
||||
"token_type" => "Bearer"
|
||||
} = json_response_and_validate_schema(conn, 200)
|
||||
response = json_response_and_validate_schema(conn, 200)
|
||||
assert %{"identifier" => "awaiting_approval"} = response
|
||||
refute response["access_token"]
|
||||
refute response["token_type"]
|
||||
|
||||
token_from_db = Repo.get_by(Token, token: token)
|
||||
assert token_from_db
|
||||
token_from_db = Repo.preload(token_from_db, :user)
|
||||
assert token_from_db.user
|
||||
user = Repo.get_by(User, email: "lain@example.org")
|
||||
|
||||
assert token_from_db.user.approval_pending
|
||||
|
||||
assert token_from_db.user.registration_reason == "I'm a cool dude, bro"
|
||||
assert user.approval_pending
|
||||
assert user.registration_reason == "I'm a cool dude, bro"
|
||||
end
|
||||
|
||||
test "returns error when user already registred", %{conn: conn, valid_params: valid_params} do
|
||||
|
|
@ -1153,11 +1142,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end)
|
||||
end
|
||||
|
||||
setup do: 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)
|
||||
clear_config([:instance, :account_activation_required], true)
|
||||
|
||||
app_token = insert(:oauth_token, user: nil)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue