2016-11-17 13:29:11 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Auth::RegistrationsController, type: :controller do
|
|
|
|
render_views
|
|
|
|
|
2017-06-25 22:42:55 +03:00
|
|
|
shared_examples 'checks for enabled registrations' do |path|
|
|
|
|
around do |example|
|
2019-03-14 06:28:30 +02:00
|
|
|
registrations_mode = Setting.registrations_mode
|
2017-06-25 22:42:55 +03:00
|
|
|
example.run
|
2019-03-14 06:28:30 +02:00
|
|
|
Setting.registrations_mode = registrations_mode
|
2017-06-25 22:42:55 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects if it is in single user mode while it is open for registration' do
|
|
|
|
Fabricate(:account)
|
2019-03-14 06:28:30 +02:00
|
|
|
Setting.registrations_mode = 'open'
|
2017-06-25 22:42:55 +03:00
|
|
|
expect(Rails.configuration.x).to receive(:single_user_mode).and_return(true)
|
|
|
|
|
|
|
|
get path
|
|
|
|
|
|
|
|
expect(response).to redirect_to '/'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects if it is not open for registration while it is not in single user mode' do
|
2019-03-14 06:28:30 +02:00
|
|
|
Setting.registrations_mode = 'none'
|
2017-06-25 22:42:55 +03:00
|
|
|
expect(Rails.configuration.x).to receive(:single_user_mode).and_return(false)
|
|
|
|
|
|
|
|
get path
|
|
|
|
|
|
|
|
expect(response).to redirect_to '/'
|
2016-11-17 13:29:11 +02:00
|
|
|
end
|
2017-06-25 22:42:55 +03:00
|
|
|
end
|
2016-11-17 13:29:11 +02:00
|
|
|
|
2017-06-25 22:42:55 +03:00
|
|
|
describe 'GET #edit' do
|
2016-11-17 13:29:11 +02:00
|
|
|
it 'returns http success' do
|
2017-06-25 22:42:55 +03:00
|
|
|
request.env["devise.mapping"] = Devise.mappings[:user]
|
|
|
|
sign_in(Fabricate(:user))
|
|
|
|
get :edit
|
2018-04-21 22:35:07 +03:00
|
|
|
expect(response).to have_http_status(200)
|
2016-11-17 13:29:11 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-25 22:42:55 +03:00
|
|
|
describe 'GET #update' do
|
|
|
|
it 'returns http success' do
|
|
|
|
request.env["devise.mapping"] = Devise.mappings[:user]
|
|
|
|
sign_in(Fabricate(:user), scope: :user)
|
|
|
|
post :update
|
2018-04-21 22:35:07 +03:00
|
|
|
expect(response).to have_http_status(200)
|
2017-06-25 22:42:55 +03:00
|
|
|
end
|
Change unconfirmed user login behaviour (#11375)
Allow access to account settings, 2FA, authorized applications, and
account deletions to unconfirmed and pending users, as well as
users who had their accounts disabled. Suspended users cannot update
their e-mail or password or delete their account.
Display account status on account settings page, for example, when
an account is frozen, limited, unconfirmed or pending review.
After sign up, login users straight away and show a simple page that
tells them the status of their account with links to account settings
and logout, to reduce onboarding friction and allow users to correct
wrongly typed e-mail addresses.
Move the final sign-up step of SSO integrations to be the same
as above to reduce code duplication.
2019-07-22 11:48:50 +03:00
|
|
|
|
|
|
|
context 'when suspended' do
|
|
|
|
it 'returns http forbidden' do
|
|
|
|
request.env["devise.mapping"] = Devise.mappings[:user]
|
|
|
|
sign_in(Fabricate(:user, account_attributes: { username: 'test', suspended_at: Time.now.utc }), scope: :user)
|
|
|
|
post :update
|
|
|
|
expect(response).to have_http_status(403)
|
|
|
|
end
|
|
|
|
end
|
2017-06-25 22:42:55 +03:00
|
|
|
end
|
2017-04-17 11:29:08 +03:00
|
|
|
|
2017-06-25 22:42:55 +03:00
|
|
|
describe 'GET #new' do
|
2016-11-17 13:29:11 +02:00
|
|
|
before do
|
|
|
|
request.env["devise.mapping"] = Devise.mappings[:user]
|
|
|
|
end
|
|
|
|
|
2017-06-25 22:42:55 +03:00
|
|
|
context do
|
|
|
|
around do |example|
|
2019-03-14 06:28:30 +02:00
|
|
|
registrations_mode = Setting.registrations_mode
|
2017-06-25 22:42:55 +03:00
|
|
|
example.run
|
2019-03-14 06:28:30 +02:00
|
|
|
Setting.registrations_mode = registrations_mode
|
2017-06-25 22:42:55 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2019-03-14 06:28:30 +02:00
|
|
|
Setting.registrations_mode = 'open'
|
2017-06-25 22:42:55 +03:00
|
|
|
get :new
|
2018-04-21 22:35:07 +03:00
|
|
|
expect(response).to have_http_status(200)
|
2017-06-25 22:42:55 +03:00
|
|
|
end
|
2016-11-17 13:29:11 +02:00
|
|
|
end
|
|
|
|
|
2017-06-25 22:42:55 +03:00
|
|
|
include_examples 'checks for enabled registrations', :new
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #create' do
|
|
|
|
let(:accept_language) { Rails.application.config.i18n.available_locales.sample.to_s }
|
|
|
|
|
2018-04-22 00:37:07 +03:00
|
|
|
around do |example|
|
|
|
|
current_locale = I18n.locale
|
|
|
|
example.run
|
|
|
|
I18n.locale = current_locale
|
|
|
|
end
|
|
|
|
|
2017-06-25 22:42:55 +03:00
|
|
|
before { request.env["devise.mapping"] = Devise.mappings[:user] }
|
|
|
|
|
|
|
|
context do
|
|
|
|
around do |example|
|
2019-03-14 06:28:30 +02:00
|
|
|
registrations_mode = Setting.registrations_mode
|
2017-06-25 22:42:55 +03:00
|
|
|
example.run
|
2019-03-14 06:28:30 +02:00
|
|
|
Setting.registrations_mode = registrations_mode
|
2017-06-25 22:42:55 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
subject do
|
2019-03-14 06:28:30 +02:00
|
|
|
Setting.registrations_mode = 'open'
|
2017-06-25 22:42:55 +03:00
|
|
|
request.headers["Accept-Language"] = accept_language
|
2020-02-16 13:56:53 +02:00
|
|
|
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } }
|
2017-06-25 22:42:55 +03:00
|
|
|
end
|
|
|
|
|
Change unconfirmed user login behaviour (#11375)
Allow access to account settings, 2FA, authorized applications, and
account deletions to unconfirmed and pending users, as well as
users who had their accounts disabled. Suspended users cannot update
their e-mail or password or delete their account.
Display account status on account settings page, for example, when
an account is frozen, limited, unconfirmed or pending review.
After sign up, login users straight away and show a simple page that
tells them the status of their account with links to account settings
and logout, to reduce onboarding friction and allow users to correct
wrongly typed e-mail addresses.
Move the final sign-up step of SSO integrations to be the same
as above to reduce code duplication.
2019-07-22 11:48:50 +03:00
|
|
|
it 'redirects to setup' do
|
2017-06-25 22:42:55 +03:00
|
|
|
subject
|
Change unconfirmed user login behaviour (#11375)
Allow access to account settings, 2FA, authorized applications, and
account deletions to unconfirmed and pending users, as well as
users who had their accounts disabled. Suspended users cannot update
their e-mail or password or delete their account.
Display account status on account settings page, for example, when
an account is frozen, limited, unconfirmed or pending review.
After sign up, login users straight away and show a simple page that
tells them the status of their account with links to account settings
and logout, to reduce onboarding friction and allow users to correct
wrongly typed e-mail addresses.
Move the final sign-up step of SSO integrations to be the same
as above to reduce code duplication.
2019-07-22 11:48:50 +03:00
|
|
|
expect(response).to redirect_to auth_setup_path
|
2017-06-25 22:42:55 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates user' do
|
|
|
|
subject
|
|
|
|
user = User.find_by(email: 'test@example.com')
|
|
|
|
expect(user).to_not be_nil
|
|
|
|
expect(user.locale).to eq(accept_language)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-16 13:56:53 +02:00
|
|
|
context 'when user has not agreed to terms of service' do
|
|
|
|
around do |example|
|
|
|
|
registrations_mode = Setting.registrations_mode
|
|
|
|
example.run
|
|
|
|
Setting.registrations_mode = registrations_mode
|
|
|
|
end
|
|
|
|
|
|
|
|
subject do
|
|
|
|
Setting.registrations_mode = 'open'
|
|
|
|
request.headers["Accept-Language"] = accept_language
|
|
|
|
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'false' } }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create user' do
|
|
|
|
subject
|
|
|
|
user = User.find_by(email: 'test@example.com')
|
|
|
|
expect(user).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-02 05:30:12 +03:00
|
|
|
context 'approval-based registrations without invite' do
|
|
|
|
around do |example|
|
|
|
|
registrations_mode = Setting.registrations_mode
|
|
|
|
example.run
|
|
|
|
Setting.registrations_mode = registrations_mode
|
|
|
|
end
|
|
|
|
|
|
|
|
subject do
|
|
|
|
Setting.registrations_mode = 'approved'
|
|
|
|
request.headers["Accept-Language"] = accept_language
|
2020-02-16 13:56:53 +02:00
|
|
|
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } }
|
2019-05-02 05:30:12 +03:00
|
|
|
end
|
|
|
|
|
Change unconfirmed user login behaviour (#11375)
Allow access to account settings, 2FA, authorized applications, and
account deletions to unconfirmed and pending users, as well as
users who had their accounts disabled. Suspended users cannot update
their e-mail or password or delete their account.
Display account status on account settings page, for example, when
an account is frozen, limited, unconfirmed or pending review.
After sign up, login users straight away and show a simple page that
tells them the status of their account with links to account settings
and logout, to reduce onboarding friction and allow users to correct
wrongly typed e-mail addresses.
Move the final sign-up step of SSO integrations to be the same
as above to reduce code duplication.
2019-07-22 11:48:50 +03:00
|
|
|
it 'redirects to setup' do
|
2019-05-02 05:30:12 +03:00
|
|
|
subject
|
Change unconfirmed user login behaviour (#11375)
Allow access to account settings, 2FA, authorized applications, and
account deletions to unconfirmed and pending users, as well as
users who had their accounts disabled. Suspended users cannot update
their e-mail or password or delete their account.
Display account status on account settings page, for example, when
an account is frozen, limited, unconfirmed or pending review.
After sign up, login users straight away and show a simple page that
tells them the status of their account with links to account settings
and logout, to reduce onboarding friction and allow users to correct
wrongly typed e-mail addresses.
Move the final sign-up step of SSO integrations to be the same
as above to reduce code duplication.
2019-07-22 11:48:50 +03:00
|
|
|
expect(response).to redirect_to auth_setup_path
|
2019-05-02 05:30:12 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates user' do
|
|
|
|
subject
|
|
|
|
user = User.find_by(email: 'test@example.com')
|
|
|
|
expect(user).to_not be_nil
|
|
|
|
expect(user.locale).to eq(accept_language)
|
|
|
|
expect(user.approved).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'approval-based registrations with expired invite' do
|
|
|
|
around do |example|
|
|
|
|
registrations_mode = Setting.registrations_mode
|
|
|
|
example.run
|
|
|
|
Setting.registrations_mode = registrations_mode
|
|
|
|
end
|
|
|
|
|
|
|
|
subject do
|
|
|
|
Setting.registrations_mode = 'approved'
|
|
|
|
request.headers["Accept-Language"] = accept_language
|
|
|
|
invite = Fabricate(:invite, max_uses: nil, expires_at: 1.hour.ago)
|
2020-02-16 13:56:53 +02:00
|
|
|
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', 'invite_code': invite.code, agreement: 'true' } }
|
2019-05-02 05:30:12 +03:00
|
|
|
end
|
|
|
|
|
Change unconfirmed user login behaviour (#11375)
Allow access to account settings, 2FA, authorized applications, and
account deletions to unconfirmed and pending users, as well as
users who had their accounts disabled. Suspended users cannot update
their e-mail or password or delete their account.
Display account status on account settings page, for example, when
an account is frozen, limited, unconfirmed or pending review.
After sign up, login users straight away and show a simple page that
tells them the status of their account with links to account settings
and logout, to reduce onboarding friction and allow users to correct
wrongly typed e-mail addresses.
Move the final sign-up step of SSO integrations to be the same
as above to reduce code duplication.
2019-07-22 11:48:50 +03:00
|
|
|
it 'redirects to setup' do
|
2019-05-02 05:30:12 +03:00
|
|
|
subject
|
Change unconfirmed user login behaviour (#11375)
Allow access to account settings, 2FA, authorized applications, and
account deletions to unconfirmed and pending users, as well as
users who had their accounts disabled. Suspended users cannot update
their e-mail or password or delete their account.
Display account status on account settings page, for example, when
an account is frozen, limited, unconfirmed or pending review.
After sign up, login users straight away and show a simple page that
tells them the status of their account with links to account settings
and logout, to reduce onboarding friction and allow users to correct
wrongly typed e-mail addresses.
Move the final sign-up step of SSO integrations to be the same
as above to reduce code duplication.
2019-07-22 11:48:50 +03:00
|
|
|
expect(response).to redirect_to auth_setup_path
|
2019-05-02 05:30:12 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates user' do
|
|
|
|
subject
|
|
|
|
user = User.find_by(email: 'test@example.com')
|
|
|
|
expect(user).to_not be_nil
|
|
|
|
expect(user.locale).to eq(accept_language)
|
|
|
|
expect(user.approved).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'approval-based registrations with valid invite' do
|
|
|
|
around do |example|
|
|
|
|
registrations_mode = Setting.registrations_mode
|
|
|
|
example.run
|
|
|
|
Setting.registrations_mode = registrations_mode
|
|
|
|
end
|
|
|
|
|
|
|
|
subject do
|
2020-09-15 15:37:58 +03:00
|
|
|
inviter = Fabricate(:user, confirmed_at: 2.days.ago)
|
2019-05-02 05:30:12 +03:00
|
|
|
Setting.registrations_mode = 'approved'
|
|
|
|
request.headers["Accept-Language"] = accept_language
|
2020-09-15 15:37:58 +03:00
|
|
|
invite = Fabricate(:invite, user: inviter, max_uses: nil, expires_at: 1.hour.from_now)
|
2020-02-16 13:56:53 +02:00
|
|
|
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', 'invite_code': invite.code, agreement: 'true' } }
|
2019-05-02 05:30:12 +03:00
|
|
|
end
|
|
|
|
|
Change unconfirmed user login behaviour (#11375)
Allow access to account settings, 2FA, authorized applications, and
account deletions to unconfirmed and pending users, as well as
users who had their accounts disabled. Suspended users cannot update
their e-mail or password or delete their account.
Display account status on account settings page, for example, when
an account is frozen, limited, unconfirmed or pending review.
After sign up, login users straight away and show a simple page that
tells them the status of their account with links to account settings
and logout, to reduce onboarding friction and allow users to correct
wrongly typed e-mail addresses.
Move the final sign-up step of SSO integrations to be the same
as above to reduce code duplication.
2019-07-22 11:48:50 +03:00
|
|
|
it 'redirects to setup' do
|
2019-05-02 05:30:12 +03:00
|
|
|
subject
|
Change unconfirmed user login behaviour (#11375)
Allow access to account settings, 2FA, authorized applications, and
account deletions to unconfirmed and pending users, as well as
users who had their accounts disabled. Suspended users cannot update
their e-mail or password or delete their account.
Display account status on account settings page, for example, when
an account is frozen, limited, unconfirmed or pending review.
After sign up, login users straight away and show a simple page that
tells them the status of their account with links to account settings
and logout, to reduce onboarding friction and allow users to correct
wrongly typed e-mail addresses.
Move the final sign-up step of SSO integrations to be the same
as above to reduce code duplication.
2019-07-22 11:48:50 +03:00
|
|
|
expect(response).to redirect_to auth_setup_path
|
2019-05-02 05:30:12 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates user' do
|
|
|
|
subject
|
|
|
|
user = User.find_by(email: 'test@example.com')
|
|
|
|
expect(user).to_not be_nil
|
|
|
|
expect(user.locale).to eq(accept_language)
|
|
|
|
expect(user.approved).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-25 22:42:55 +03:00
|
|
|
it 'does nothing if user already exists' do
|
|
|
|
Fabricate(:user, account: Fabricate(:account, username: 'test'))
|
|
|
|
subject
|
2016-11-17 13:29:11 +02:00
|
|
|
end
|
2017-06-25 22:42:55 +03:00
|
|
|
|
|
|
|
include_examples 'checks for enabled registrations', :create
|
2016-11-17 13:29:11 +02:00
|
|
|
end
|
2017-05-23 22:32:42 +03:00
|
|
|
|
|
|
|
describe 'DELETE #destroy' do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
request.env['devise.mapping'] = Devise.mappings[:user]
|
|
|
|
sign_in(user, scope: :user)
|
|
|
|
delete :destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http not found' do
|
|
|
|
expect(response).to have_http_status(:not_found)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not delete user' do
|
|
|
|
expect(User.find(user.id)).to_not be_nil
|
|
|
|
end
|
|
|
|
end
|
2016-11-17 13:29:11 +02:00
|
|
|
end
|