diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-06-23 08:48:22 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-06-23 08:48:22 +0000 |
commit | f189c36d8d352deccbd37b8ae92ca0c539e330c3 (patch) | |
tree | 7fd67948d200908821302ab9fb3454af65a46655 /spec | |
parent | 4aa1fdd347d1df4001d9e1298e6dc09c0c478c2e (diff) | |
parent | dcfce8b1988af62806a8bcdfd38bc2dcc0b7cf4e (diff) | |
download | gitlab-ce-f189c36d8d352deccbd37b8ae92ca0c539e330c3.tar.gz |
Merge branch 'rs-dev-issue-2414' into 'master'
Allow Admin to filter users by 2FA status
> ![Screen_Shot_2015-06-19_at_4.38.12_PM](https://gitlab.com/gitlab-org/gitlab-ce/uploads/deba7f2a6b8d1548c1d1ac401e0e35a1/Screen_Shot_2015-06-19_at_4.38.12_PM.png)
Closes internal https://dev.gitlab.org/gitlab/gitlabhq/issues/2414
See merge request !852
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/admin/admin_users_spec.rb | 40 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 74 |
2 files changed, 78 insertions, 36 deletions
diff --git a/spec/features/admin/admin_users_spec.rb b/spec/features/admin/admin_users_spec.rb index 7f5cb30cb94..86717761582 100644 --- a/spec/features/admin/admin_users_spec.rb +++ b/spec/features/admin/admin_users_spec.rb @@ -16,6 +16,46 @@ describe "Admin::Users", feature: true do expect(page).to have_content(@user.email) expect(page).to have_content(@user.name) end + + describe 'Two-factor Authentication filters' do + it 'counts users who have enabled 2FA' do + create(:user, two_factor_enabled: true) + + 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_enabled: true) + + 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, two_factor_enabled: false) + + 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, two_factor_enabled: false) + + visit admin_users_path + click_link '2FA Disabled' + + expect(page).to have_content(user.email) + end + end end describe "GET /admin/users/new" do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 9f7c83f3476..b80273c053d 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -50,12 +50,12 @@ # bitbucket_access_token :string(255) # bitbucket_access_token_secret :string(255) # location :string(255) -# public_email :string(255) default(""), not null # encrypted_otp_secret :string(255) # encrypted_otp_secret_iv :string(255) # encrypted_otp_secret_salt :string(255) -# otp_required_for_login :boolean +# otp_required_for_login :boolean default(FALSE), not null # otp_backup_codes :text +# public_email :string(255) default(""), not null # dashboard :integer default(0) # @@ -210,30 +210,6 @@ describe User do end end - describe '#two_factor_enabled' do - it 'returns two-factor authentication status' do - enabled = build_stubbed(:user, two_factor_enabled: true) - disabled = build_stubbed(:user) - - expect(enabled).to be_two_factor_enabled - expect(disabled).not_to be_two_factor_enabled - end - end - - describe '#two_factor_enabled=' do - it 'enables two-factor authentication' do - user = build_stubbed(:user, two_factor_enabled: false) - expect { user.two_factor_enabled = true }. - to change { user.two_factor_enabled? }.to(true) - end - - it 'disables two-factor authentication' do - user = build_stubbed(:user, two_factor_enabled: true) - expect { user.two_factor_enabled = false }. - to change { user.two_factor_enabled? }.to(false) - end - end - describe 'authentication token' do it "should have authentication token" do user = create(:user) @@ -308,18 +284,44 @@ describe User do end end - describe 'filter' do - before do - User.delete_all - @user = create :user - @admin = create :user, admin: true - @blocked = create :user, state: :blocked + describe '.filter' do + let(:user) { double } + + it 'filters by active users by default' do + expect(User).to receive(:active).and_return([user]) + + expect(User.filter(nil)).to include user + end + + it 'filters by admins' do + expect(User).to receive(:admins).and_return([user]) + + expect(User.filter('admins')).to include user end - it { expect(User.filter("admins")).to eq([@admin]) } - it { expect(User.filter("blocked")).to eq([@blocked]) } - it { expect(User.filter("wop")).to include(@user, @admin, @blocked) } - it { expect(User.filter(nil)).to include(@user, @admin) } + it 'filters by blocked' do + expect(User).to receive(:blocked).and_return([user]) + + expect(User.filter('blocked')).to include user + end + + it 'filters by two_factor_disabled' do + expect(User).to receive(:without_two_factor).and_return([user]) + + expect(User.filter('two_factor_disabled')).to include user + end + + it 'filters by two_factor_enabled' do + expect(User).to receive(:with_two_factor).and_return([user]) + + expect(User.filter('two_factor_enabled')).to include user + end + + it 'filters by wop' do + expect(User).to receive(:without_projects).and_return([user]) + + expect(User.filter('wop')).to include user + end end describe :not_in_project do |