summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-09-28 15:43:02 +0200
committerDouwe Maan <douwe@gitlab.com>2015-09-28 15:43:02 +0200
commit1c1c7e1abd2ac4f4e88de06f7336bbf8ca5ad3da (patch)
tree07ad5566f3c768bccdf4b547640d70da99d89e5b /spec
parentac34ce8648f48979c257b626a31e65c0ba5b38dc (diff)
parent0c877875ea3e7ccbdf48b7736f8c35e2a179ab45 (diff)
downloadgitlab-ce-1c1c7e1abd2ac4f4e88de06f7336bbf8ca5ad3da.tar.gz
Merge branch 'fxposter/gitlab-ce-login-from-admin'
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin/users_controller_spec.rb15
-rw-r--r--spec/features/admin/admin_users_spec.rb21
2 files changed, 36 insertions, 0 deletions
diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb
index c40b2c2a583..7168db117d6 100644
--- a/spec/controllers/admin/users_controller_spec.rb
+++ b/spec/controllers/admin/users_controller_spec.rb
@@ -7,6 +7,21 @@ describe Admin::UsersController do
sign_in(admin)
end
+ describe 'POST login_as' do
+ let(:user) { create(:user) }
+
+ it 'logs admin as another user' do
+ expect(warden.authenticate(scope: :user)).not_to eq(user)
+ post :login_as, id: user.username
+ expect(warden.authenticate(scope: :user)).to eq(user)
+ end
+
+ it 'redirects user to homepage' do
+ post :login_as, id: user.username
+ expect(response).to redirect_to(root_path)
+ end
+ end
+
describe 'DELETE #user with projects' do
let(:user) { create(:user) }
let(:project) { create(:project, namespace: user.namespace) }
diff --git a/spec/features/admin/admin_users_spec.rb b/spec/features/admin/admin_users_spec.rb
index 86717761582..c2c7364f6c5 100644
--- a/spec/features/admin/admin_users_spec.rb
+++ b/spec/features/admin/admin_users_spec.rb
@@ -111,6 +111,27 @@ describe "Admin::Users", feature: true do
expect(page).to have_content(@user.name)
end
+ describe 'Login as another user' do
+ it 'should show login button for other users and check that it works' do
+ another_user = create(:user)
+
+ visit admin_user_path(another_user)
+
+ click_link 'Log in as this user'
+
+ expect(page).to have_content("Logged in as #{another_user.username}")
+
+ page.within '.sidebar-user .username' do
+ expect(page).to have_content(another_user.username)
+ end
+ end
+
+ it 'should not show login button for admin itself' do
+ visit admin_user_path(@user)
+ expect(page).not_to have_content('Log in as this user')
+ end
+ end
+
describe 'Two-factor Authentication status' do
it 'shows when enabled' do
@user.update_attribute(:two_factor_enabled, true)