summaryrefslogtreecommitdiff
path: root/spec/models/user_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-09-01 16:52:41 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-01 16:52:41 +0000
commita986819a7bce2002018dfafed3900dc3f2e8fb81 (patch)
tree15c063738d999a0aff035c4842885276a9ab6ac4 /spec/models/user_spec.rb
parent92d5172ad42ebc62eb78cac21b1e236ad6ace580 (diff)
downloadgitlab-ce-a986819a7bce2002018dfafed3900dc3f2e8fb81.tar.gz
Add latest changes from gitlab-org/security/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/models/user_spec.rb')
-rw-r--r--spec/models/user_spec.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index f9b819e22cd..e9077ed4143 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -894,6 +894,20 @@ RSpec.describe User do
expect(described_class.without_ghosts).to match_array([user1, user2])
end
end
+
+ describe '.by_id_and_login' do
+ let_it_be(:user) { create(:user) }
+
+ it 'finds a user regardless of case' do
+ expect(described_class.by_id_and_login(user.id, user.username.upcase))
+ .to contain_exactly(user)
+ end
+
+ it 'finds a user when login is an email address regardless of case' do
+ expect(described_class.by_id_and_login(user.id, user.email.upcase))
+ .to contain_exactly(user)
+ end
+ end
end
describe "Respond to" do
@@ -3579,6 +3593,42 @@ RSpec.describe User do
end
end
+ describe '#source_groups_of_two_factor_authentication_requirement' do
+ let_it_be(:group_not_requiring_2FA) { create :group }
+ let(:user) { create :user }
+
+ before do
+ group.add_user(user, GroupMember::OWNER)
+ group_not_requiring_2FA.add_user(user, GroupMember::OWNER)
+ end
+
+ context 'when user is direct member of group requiring 2FA' do
+ let_it_be(:group) { create :group, require_two_factor_authentication: true }
+
+ it 'returns group requiring 2FA' do
+ expect(user.source_groups_of_two_factor_authentication_requirement).to contain_exactly(group)
+ end
+ end
+
+ context 'when user is member of group which parent requires 2FA' do
+ let_it_be(:parent_group) { create :group, require_two_factor_authentication: true }
+ let_it_be(:group) { create :group, parent: parent_group }
+
+ it 'returns group requiring 2FA' do
+ expect(user.source_groups_of_two_factor_authentication_requirement).to contain_exactly(group)
+ end
+ end
+
+ context 'when user is member of group which child requires 2FA' do
+ let_it_be(:group) { create :group }
+ let_it_be(:child_group) { create :group, require_two_factor_authentication: true, parent: group }
+
+ it 'returns group requiring 2FA' do
+ expect(user.source_groups_of_two_factor_authentication_requirement).to contain_exactly(group)
+ end
+ end
+ end
+
describe '.active' do
before do
described_class.ghost