debian-mirror-gitlab/spec/features/admin/admin_users_spec.rb

229 lines
6.2 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
describe "Admin::Users", feature: true do
before { login_as :admin }
describe "GET /admin/users" do
before do
visit admin_users_path
end
2016-09-13 17:45:13 +05:30
it "is ok" do
2015-04-26 12:48:37 +05:30
expect(current_path).to eq(admin_users_path)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "has users list" do
2015-04-26 12:48:37 +05:30
expect(page).to have_content(@user.email)
expect(page).to have_content(@user.name)
2014-09-02 18:07:02 +05:30
end
2015-09-11 14:41:01 +05:30
describe 'Two-factor Authentication filters' do
it 'counts users who have enabled 2FA' do
create(:user, :two_factor)
2015-09-11 14:41:01 +05:30
visit admin_users_path
page.within('.filter-two-factor-enabled small') do
expect(page).to have_content('1')
end
end
it 'filters by users who have enabled 2FA' do
user = create(:user, :two_factor)
2015-09-11 14:41:01 +05:30
visit admin_users_path
click_link '2FA Enabled'
expect(page).to have_content(user.email)
end
it 'counts users who have not enabled 2FA' do
create(:user)
2015-09-11 14:41:01 +05:30
visit admin_users_path
page.within('.filter-two-factor-disabled small') do
expect(page).to have_content('2') # Including admin
end
end
it 'filters by users who have not enabled 2FA' do
user = create(:user)
2015-09-11 14:41:01 +05:30
visit admin_users_path
click_link '2FA Disabled'
expect(page).to have_content(user.email)
end
end
2014-09-02 18:07:02 +05:30
end
describe "GET /admin/users/new" do
before do
visit new_admin_user_path
fill_in "user_name", with: "Big Bang"
fill_in "user_username", with: "bang"
fill_in "user_email", with: "bigbang@mail.com"
end
2016-09-13 17:45:13 +05:30
it "creates new user" do
2014-09-02 18:07:02 +05:30
expect { click_button "Create user" }.to change {User.count}.by(1)
end
2016-09-13 17:45:13 +05:30
it "applies defaults to user" do
2014-09-02 18:07:02 +05:30
click_button "Create user"
2015-04-26 12:48:37 +05:30
user = User.find_by(username: 'bang')
expect(user.projects_limit).
to eq(Gitlab.config.gitlab.default_projects_limit)
expect(user.can_create_group).
to eq(Gitlab.config.gitlab.default_can_create_group)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "creates user with valid data" do
2014-09-02 18:07:02 +05:30
click_button "Create user"
2015-04-26 12:48:37 +05:30
user = User.find_by(username: 'bang')
expect(user.name).to eq('Big Bang')
expect(user.email).to eq('bigbang@mail.com')
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "calls send mail" do
2015-12-23 02:04:40 +05:30
expect_any_instance_of(NotificationService).to receive(:new_user)
2014-09-02 18:07:02 +05:30
click_button "Create user"
end
2016-09-13 17:45:13 +05:30
it "sends valid email to user with email & password" do
2015-12-23 02:04:40 +05:30
perform_enqueued_jobs do
click_button "Create user"
end
2015-04-26 12:48:37 +05:30
user = User.find_by(username: 'bang')
2014-09-02 18:07:02 +05:30
email = ActionMailer::Base.deliveries.last
2015-04-26 12:48:37 +05:30
expect(email.subject).to have_content('Account was created')
expect(email.text_part.body).to have_content(user.email)
expect(email.text_part.body).to have_content('password')
2014-09-02 18:07:02 +05:30
end
end
describe "GET /admin/users/:id" do
2016-09-13 17:45:13 +05:30
it "has user info" do
2014-09-02 18:07:02 +05:30
visit admin_users_path
2015-09-11 14:41:01 +05:30
click_link @user.name
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
expect(page).to have_content(@user.email)
expect(page).to have_content(@user.name)
2014-09-02 18:07:02 +05:30
end
2015-09-11 14:41:01 +05:30
2015-11-26 14:37:03 +05:30
describe 'Impersonation' do
let(:another_user) { create(:user) }
before { visit admin_user_path(another_user) }
2015-10-24 18:46:33 +05:30
2015-11-26 14:37:03 +05:30
context 'before impersonating' do
it 'shows impersonate button for other users' do
expect(page).to have_content('Impersonate')
end
2015-10-24 18:46:33 +05:30
2016-09-13 17:45:13 +05:30
it 'does not show impersonate button for admin itself' do
2015-11-26 14:37:03 +05:30
visit admin_user_path(@user)
2015-10-24 18:46:33 +05:30
2015-11-26 14:37:03 +05:30
expect(page).not_to have_content('Impersonate')
2015-10-24 18:46:33 +05:30
end
2015-12-23 02:04:40 +05:30
2016-09-13 17:45:13 +05:30
it 'does not show impersonate button for blocked user' do
2015-12-23 02:04:40 +05:30
another_user.block
visit admin_user_path(another_user)
expect(page).not_to have_content('Impersonate')
another_user.activate
end
2015-10-24 18:46:33 +05:30
end
2015-11-26 14:37:03 +05:30
context 'when impersonating' do
before { click_link 'Impersonate' }
it 'logs in as the user when impersonate is clicked' do
2016-08-24 12:49:21 +05:30
expect(page.find(:css, '.header-user .profile-link')['data-user']).to eql(another_user.username)
2015-11-26 14:37:03 +05:30
end
it 'sees impersonation log out icon' do
icon = first('.fa.fa-user-secret')
expect(icon).not_to eql nil
2015-11-26 14:37:03 +05:30
end
2016-09-13 17:45:13 +05:30
it 'logs out of impersonated user back to original user' do
2015-11-26 14:37:03 +05:30
find(:css, 'li.impersonation a').click
2016-08-24 12:49:21 +05:30
expect(page.find(:css, '.header-user .profile-link')['data-user']).to eql(@user.username)
2015-11-26 14:37:03 +05:30
end
it 'is redirected back to the impersonated users page in the admin after stopping' do
find(:css, 'li.impersonation a').click
expect(current_path).to eql "/admin/users/#{another_user.username}"
end
2015-10-24 18:46:33 +05:30
end
end
2015-09-11 14:41:01 +05:30
describe 'Two-factor Authentication status' do
it 'shows when enabled' do
@user.update_attribute(:otp_required_for_login, true)
2015-09-11 14:41:01 +05:30
visit admin_user_path(@user)
expect_two_factor_status('Enabled')
end
it 'shows when disabled' do
visit admin_user_path(@user)
expect_two_factor_status('Disabled')
end
def expect_two_factor_status(status)
page.within('.two-factor-status') do
expect(page).to have_content(status)
end
end
end
2014-09-02 18:07:02 +05:30
end
describe "GET /admin/users/:id/edit" do
before do
@simple_user = create(:user)
visit admin_users_path
click_link "edit_user_#{@simple_user.id}"
end
2016-09-13 17:45:13 +05:30
it "has user edit page" do
2015-04-26 12:48:37 +05:30
expect(page).to have_content('Name')
expect(page).to have_content('Password')
2014-09-02 18:07:02 +05:30
end
describe "Update user" do
before do
fill_in "user_name", with: "Big Bang"
fill_in "user_email", with: "bigbang@mail.com"
2016-06-02 11:05:42 +05:30
fill_in "user_password", with: "AValidPassword1"
fill_in "user_password_confirmation", with: "AValidPassword1"
2014-09-02 18:07:02 +05:30
check "user_admin"
click_button "Save changes"
end
2016-09-13 17:45:13 +05:30
it "shows page with new data" do
2015-04-26 12:48:37 +05:30
expect(page).to have_content('bigbang@mail.com')
expect(page).to have_content('Big Bang')
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "changes user entry" do
2014-09-02 18:07:02 +05:30
@simple_user.reload
2015-04-26 12:48:37 +05:30
expect(@simple_user.name).to eq('Big Bang')
expect(@simple_user.is_admin?).to be_truthy
2016-06-02 11:05:42 +05:30
expect(@simple_user.password_expires_at).to be <= Time.now
2014-09-02 18:07:02 +05:30
end
end
end
end