2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-17 22:29:11 +11:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-04 13:49:53 +10:00
|
|
|
RSpec.describe Auth::RegistrationsController do
|
2016-11-17 22:29:11 +11:00
|
|
|
render_views
|
|
|
|
|
2017-06-26 05:42:55 +10:00
|
|
|
shared_examples 'checks for enabled registrations' do |path|
|
|
|
|
it 'redirects if it is in single user mode while it is open for registration' do
|
|
|
|
Fabricate(:account)
|
2019-03-14 15:28:30 +11:00
|
|
|
Setting.registrations_mode = 'open'
|
2023-07-12 18:20:10 +10:00
|
|
|
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(true)
|
2017-06-26 05:42:55 +10:00
|
|
|
|
|
|
|
get path
|
|
|
|
|
|
|
|
expect(response).to redirect_to '/'
|
2023-07-12 18:20:10 +10:00
|
|
|
expect(Rails.configuration.x).to have_received(:single_user_mode)
|
2017-06-26 05:42:55 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects if it is not open for registration while it is not in single user mode' do
|
2019-03-14 15:28:30 +11:00
|
|
|
Setting.registrations_mode = 'none'
|
2023-07-12 18:20:10 +10:00
|
|
|
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(false)
|
2017-06-26 05:42:55 +10:00
|
|
|
|
|
|
|
get path
|
|
|
|
|
|
|
|
expect(response).to redirect_to '/'
|
2023-07-12 18:20:10 +10:00
|
|
|
expect(Rails.configuration.x).to have_received(:single_user_mode)
|
2016-11-17 22:29:11 +11:00
|
|
|
end
|
2017-06-26 05:42:55 +10:00
|
|
|
end
|
2016-11-17 22:29:11 +11:00
|
|
|
|
2017-06-26 05:42:55 +10:00
|
|
|
describe 'GET #edit' do
|
2023-04-20 00:07:29 +10:00
|
|
|
before do
|
2023-02-19 09:38:14 +11:00
|
|
|
request.env['devise.mapping'] = Devise.mappings[:user]
|
2017-06-26 05:42:55 +10:00
|
|
|
sign_in(Fabricate(:user))
|
|
|
|
get :edit
|
2023-04-20 00:07:29 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2018-04-22 05:35:07 +10:00
|
|
|
expect(response).to have_http_status(200)
|
2016-11-17 22:29:11 +11:00
|
|
|
end
|
2023-04-20 00:07:29 +10:00
|
|
|
|
|
|
|
it 'returns private cache control header' do
|
|
|
|
expect(response.headers['Cache-Control']).to include('private, no-store')
|
|
|
|
end
|
2016-11-17 22:29:11 +11:00
|
|
|
end
|
|
|
|
|
2024-02-27 03:09:56 +11:00
|
|
|
describe 'PUT #update' do
|
|
|
|
let(:current_password) { 'current password' }
|
|
|
|
let(:user) { Fabricate(:user, password: current_password) }
|
2023-04-20 00:07:29 +10:00
|
|
|
|
|
|
|
before do
|
2023-02-19 09:38:14 +11:00
|
|
|
request.env['devise.mapping'] = Devise.mappings[:user]
|
2023-04-20 00:07:29 +10:00
|
|
|
sign_in(user, scope: :user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2024-02-27 03:09:56 +11:00
|
|
|
put :update
|
2018-04-22 05:35:07 +10:00
|
|
|
expect(response).to have_http_status(200)
|
2017-06-26 05:42:55 +10: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 18:48:50 +10:00
|
|
|
|
2023-04-20 00:07:29 +10:00
|
|
|
it 'returns private cache control headers' do
|
2024-02-27 03:09:56 +11:00
|
|
|
put :update
|
2023-04-20 00:07:29 +10:00
|
|
|
expect(response.headers['Cache-Control']).to include('private, no-store')
|
|
|
|
end
|
|
|
|
|
2024-02-27 03:09:56 +11:00
|
|
|
it 'can update the user email' do
|
|
|
|
expect do
|
|
|
|
put :update, params: {
|
|
|
|
user: {
|
|
|
|
email: 'newemail@example.com',
|
|
|
|
current_password: current_password,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
expect(response).to redirect_to(edit_user_registration_path)
|
|
|
|
end.to change { user.reload.unconfirmed_email }.to('newemail@example.com')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'requires the current password to update the email' do
|
|
|
|
expect do
|
|
|
|
put :update, params: {
|
|
|
|
user: {
|
|
|
|
email: 'newemail@example.com',
|
|
|
|
current_password: 'something',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end.to_not(change { user.reload.unconfirmed_email })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can update the user password' do
|
|
|
|
expect do
|
|
|
|
put :update, params: {
|
|
|
|
user: {
|
|
|
|
password: 'new password',
|
|
|
|
password_confirmation: 'new password',
|
|
|
|
current_password: current_password,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
expect(response).to redirect_to(edit_user_registration_path)
|
|
|
|
end.to(change { user.reload.encrypted_password })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'requires the password confirmation' do
|
|
|
|
expect do
|
|
|
|
put :update, params: {
|
|
|
|
user: {
|
|
|
|
password: 'new password',
|
|
|
|
password_confirmation: 'something else',
|
|
|
|
current_password: current_password,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end.to_not(change { user.reload.encrypted_password })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'requires the current password to update the password' do
|
|
|
|
expect do
|
|
|
|
put :update, params: {
|
|
|
|
user: {
|
|
|
|
password: 'new password',
|
|
|
|
password_confirmation: 'new password',
|
|
|
|
current_password: 'something',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end.to_not(change { user.reload.encrypted_password })
|
|
|
|
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 18:48:50 +10:00
|
|
|
context 'when suspended' do
|
2023-04-20 00:07:29 +10:00
|
|
|
let(:user) { Fabricate(:user, account_attributes: { username: 'test', suspended_at: Time.now.utc }) }
|
|
|
|
|
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 18:48:50 +10:00
|
|
|
it 'returns http forbidden' do
|
2024-02-27 03:09:56 +11:00
|
|
|
put :update
|
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 18:48:50 +10:00
|
|
|
expect(response).to have_http_status(403)
|
|
|
|
end
|
|
|
|
end
|
2017-06-26 05:42:55 +10:00
|
|
|
end
|
2017-04-17 18:29:08 +10:00
|
|
|
|
2017-06-26 05:42:55 +10:00
|
|
|
describe 'GET #new' do
|
2016-11-17 22:29:11 +11:00
|
|
|
before do
|
2023-02-19 09:38:14 +11:00
|
|
|
request.env['devise.mapping'] = Devise.mappings[:user]
|
2016-11-17 22:29:11 +11:00
|
|
|
end
|
|
|
|
|
2023-06-06 23:51:42 +10:00
|
|
|
context 'with open registrations' do
|
2017-06-26 05:42:55 +10:00
|
|
|
it 'returns http success' do
|
2019-03-14 15:28:30 +11:00
|
|
|
Setting.registrations_mode = 'open'
|
2017-06-26 05:42:55 +10:00
|
|
|
get :new
|
2018-04-22 05:35:07 +10:00
|
|
|
expect(response).to have_http_status(200)
|
2017-06-26 05:42:55 +10:00
|
|
|
end
|
2016-11-17 22:29:11 +11:00
|
|
|
end
|
|
|
|
|
2017-06-26 05:42:55 +10:00
|
|
|
include_examples 'checks for enabled registrations', :new
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #create' do
|
2023-05-16 04:20:13 +10:00
|
|
|
let(:accept_language) { 'de' }
|
2017-06-26 05:42:55 +10:00
|
|
|
|
2020-12-10 16:27:26 +11:00
|
|
|
before do
|
|
|
|
session[:registration_form_time] = 5.seconds.ago
|
2023-05-11 18:32:09 +10:00
|
|
|
|
|
|
|
request.env['devise.mapping'] = Devise.mappings[:user]
|
2020-12-10 16:27:26 +11:00
|
|
|
end
|
|
|
|
|
2018-04-22 07:37:07 +10:00
|
|
|
around do |example|
|
2023-04-30 22:07:03 +10:00
|
|
|
I18n.with_locale(I18n.locale) do
|
|
|
|
example.run
|
|
|
|
end
|
2018-04-22 07:37:07 +10:00
|
|
|
end
|
|
|
|
|
2023-06-06 23:51:42 +10:00
|
|
|
context 'when an accept language is present in headers' do
|
2017-06-26 05:42:55 +10:00
|
|
|
subject do
|
2019-03-14 15:28:30 +11:00
|
|
|
Setting.registrations_mode = 'open'
|
2023-02-19 09:38:14 +11:00
|
|
|
request.headers['Accept-Language'] = accept_language
|
2020-02-16 22:56:53 +11:00
|
|
|
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } }
|
2017-06-26 05:42:55 +10: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 18:48:50 +10:00
|
|
|
it 'redirects to setup' do
|
2017-06-26 05:42:55 +10: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 18:48:50 +10:00
|
|
|
expect(response).to redirect_to auth_setup_path
|
2017-06-26 05:42:55 +10: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 22:56:53 +11:00
|
|
|
context 'when user has not agreed to terms of service' do
|
|
|
|
subject do
|
|
|
|
Setting.registrations_mode = 'open'
|
2023-02-19 09:38:14 +11:00
|
|
|
request.headers['Accept-Language'] = accept_language
|
2020-02-16 22:56:53 +11:00
|
|
|
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
|
|
|
|
|
2024-01-04 20:07:05 +11:00
|
|
|
context 'when user has an email address requiring approval' do
|
|
|
|
subject do
|
2024-01-16 04:10:57 +11:00
|
|
|
request.headers['Accept-Language'] = accept_language
|
|
|
|
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } }
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2024-01-04 20:07:05 +11:00
|
|
|
Setting.registrations_mode = 'open'
|
|
|
|
Fabricate(:email_domain_block, allow_with_approval: true, domain: 'example.com')
|
2024-01-16 04:10:57 +11:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates unapproved user and redirects to setup' do
|
|
|
|
subject
|
|
|
|
expect(response).to redirect_to auth_setup_path
|
|
|
|
|
|
|
|
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 be(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has an email address requiring approval through a MX record' do
|
|
|
|
subject do
|
2024-01-04 20:07:05 +11:00
|
|
|
request.headers['Accept-Language'] = accept_language
|
|
|
|
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } }
|
|
|
|
end
|
|
|
|
|
2024-01-16 04:10:57 +11:00
|
|
|
before do
|
|
|
|
Setting.registrations_mode = 'open'
|
|
|
|
Fabricate(:email_domain_block, allow_with_approval: true, domain: 'mail.example.com')
|
|
|
|
allow(User).to receive(:skip_mx_check?).and_return(false)
|
|
|
|
|
|
|
|
resolver = instance_double(Resolv::DNS, :timeouts= => nil)
|
|
|
|
|
|
|
|
allow(resolver).to receive(:getresources)
|
|
|
|
.with('example.com', Resolv::DNS::Resource::IN::MX)
|
|
|
|
.and_return([instance_double(Resolv::DNS::Resource::MX, exchange: 'mail.example.com')])
|
|
|
|
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::A).and_return([])
|
|
|
|
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::AAAA).and_return([])
|
|
|
|
allow(resolver).to receive(:getresources).with('mail.example.com', Resolv::DNS::Resource::IN::A).and_return([instance_double(Resolv::DNS::Resource::IN::A, address: '2.3.4.5')])
|
|
|
|
allow(resolver).to receive(:getresources).with('mail.example.com', Resolv::DNS::Resource::IN::AAAA).and_return([instance_double(Resolv::DNS::Resource::IN::AAAA, address: 'fd00::2')])
|
|
|
|
allow(Resolv::DNS).to receive(:open).and_yield(resolver)
|
|
|
|
end
|
|
|
|
|
2024-01-04 20:07:05 +11:00
|
|
|
it 'creates unapproved user and redirects to setup' do
|
|
|
|
subject
|
|
|
|
expect(response).to redirect_to auth_setup_path
|
|
|
|
|
|
|
|
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 be(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 13:49:08 +10:00
|
|
|
context 'with Approval-based registrations without invite' do
|
2019-05-02 12:30:12 +10:00
|
|
|
subject do
|
|
|
|
Setting.registrations_mode = 'approved'
|
2023-02-19 09:38:14 +11:00
|
|
|
request.headers['Accept-Language'] = accept_language
|
2020-02-16 22:56:53 +11:00
|
|
|
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } }
|
2019-05-02 12:30:12 +10: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 18:48:50 +10:00
|
|
|
it 'redirects to setup' do
|
2019-05-02 12:30:12 +10: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 18:48:50 +10:00
|
|
|
expect(response).to redirect_to auth_setup_path
|
2019-05-02 12:30:12 +10: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)
|
2023-02-20 16:14:50 +11:00
|
|
|
expect(user.approved).to be(false)
|
2019-05-02 12:30:12 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 13:49:08 +10:00
|
|
|
context 'with Approval-based registrations with expired invite' do
|
2019-05-02 12:30:12 +10:00
|
|
|
subject do
|
|
|
|
Setting.registrations_mode = 'approved'
|
2023-02-19 09:38:14 +11:00
|
|
|
request.headers['Accept-Language'] = accept_language
|
2019-05-02 12:30:12 +10:00
|
|
|
invite = Fabricate(:invite, max_uses: nil, expires_at: 1.hour.ago)
|
2023-02-18 13:23:49 +11: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 12:30:12 +10: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 18:48:50 +10:00
|
|
|
it 'redirects to setup' do
|
2019-05-02 12:30:12 +10: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 18:48:50 +10:00
|
|
|
expect(response).to redirect_to auth_setup_path
|
2019-05-02 12:30:12 +10: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)
|
2023-02-20 16:14:50 +11:00
|
|
|
expect(user.approved).to be(false)
|
2019-05-02 12:30:12 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 13:49:08 +10:00
|
|
|
context 'with Approval-based registrations with valid invite and required invite text' do
|
2019-05-02 12:30:12 +10:00
|
|
|
subject do
|
2020-09-15 22:37:58 +10:00
|
|
|
inviter = Fabricate(:user, confirmed_at: 2.days.ago)
|
2019-05-02 12:30:12 +10:00
|
|
|
Setting.registrations_mode = 'approved'
|
2020-12-23 03:14:32 +11:00
|
|
|
Setting.require_invite_text = true
|
2023-02-19 09:38:14 +11:00
|
|
|
request.headers['Accept-Language'] = accept_language
|
2020-09-15 22:37:58 +10:00
|
|
|
invite = Fabricate(:invite, user: inviter, max_uses: nil, expires_at: 1.hour.from_now)
|
2023-02-18 13:23:49 +11: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 12:30:12 +10: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 18:48:50 +10:00
|
|
|
it 'redirects to setup' do
|
2019-05-02 12:30:12 +10: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 18:48:50 +10:00
|
|
|
expect(response).to redirect_to auth_setup_path
|
2019-05-02 12:30:12 +10: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)
|
2023-02-20 16:14:50 +11:00
|
|
|
expect(user.approved).to be(true)
|
2019-05-02 12:30:12 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-26 17:41:12 +10:00
|
|
|
context 'with an already taken username' do
|
|
|
|
subject do
|
|
|
|
Setting.registrations_mode = 'open'
|
|
|
|
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } }
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
Fabricate(:account, username: 'test')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds with an error message about the username' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
expect(username_error_text).to eq(I18n.t('errors.messages.taken'))
|
|
|
|
end
|
|
|
|
|
|
|
|
def username_error_text
|
2024-09-05 03:29:05 +10:00
|
|
|
response.parsed_body.css('.user_account_username .error').text
|
2023-05-26 17:41:12 +10:00
|
|
|
end
|
2016-11-17 22:29:11 +11:00
|
|
|
end
|
2017-06-26 05:42:55 +10:00
|
|
|
|
|
|
|
include_examples 'checks for enabled registrations', :create
|
2016-11-17 22:29:11 +11:00
|
|
|
end
|
2017-05-24 05:32:42 +10: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
|
2023-02-20 13:16:40 +11:00
|
|
|
expect(response).to have_http_status(404)
|
2017-05-24 05:32:42 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not delete user' do
|
|
|
|
expect(User.find(user.id)).to_not be_nil
|
|
|
|
end
|
|
|
|
end
|
2016-11-17 22:29:11 +11:00
|
|
|
end
|