summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-26 15:41:13 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-26 15:41:13 +0000
commit1e61fc763e645038f2da69fc9af6fe166a6b101a (patch)
tree76053795a637d056347c1891d98935c0361a331d /spec/models
parent57b9b49b27a730294ae37d2ac25cab943f4b801d (diff)
downloadgitlab-ce-1e61fc763e645038f2da69fc9af6fe166a6b101a.tar.gz
Add latest changes from gitlab-org/security/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/group_spec.rb5
-rw-r--r--spec/models/notification_setting_spec.rb27
-rw-r--r--spec/models/user_spec.rb64
3 files changed, 91 insertions, 5 deletions
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb
index a4e49f88115..d6e76258491 100644
--- a/spec/models/group_spec.rb
+++ b/spec/models/group_spec.rb
@@ -110,6 +110,11 @@ describe Group do
let(:group_notification_email) { 'user+group@example.com' }
let(:subgroup_notification_email) { 'user+subgroup@example.com' }
+ before do
+ create(:email, :confirmed, user: user, email: group_notification_email)
+ create(:email, :confirmed, user: user, email: subgroup_notification_email)
+ end
+
subject { subgroup.notification_email_for(user) }
context 'when both group notification emails are set' do
diff --git a/spec/models/notification_setting_spec.rb b/spec/models/notification_setting_spec.rb
index 9ab9ae494ec..67738eaec20 100644
--- a/spec/models/notification_setting_spec.rb
+++ b/spec/models/notification_setting_spec.rb
@@ -48,6 +48,33 @@ RSpec.describe NotificationSetting do
expect(notification_setting.reopen_merge_request).to eq(false)
end
end
+
+ context 'notification_email' do
+ let_it_be(:user) { create(:user) }
+ subject { described_class.new(source_id: 1, source_type: 'Project', user_id: user.id) }
+
+ it 'allows to change email to verified one' do
+ email = create(:email, :confirmed, user: user)
+
+ subject.update(notification_email: email.email)
+
+ expect(subject).to be_valid
+ end
+
+ it 'does not allow to change email to not verified one' do
+ email = create(:email, user: user)
+
+ subject.update(notification_email: email.email)
+
+ expect(subject).to be_invalid
+ end
+
+ it 'allows to change email to empty one' do
+ subject.update(notification_email: '')
+
+ expect(subject).to be_valid
+ end
+ end
end
describe '#for_projects' do
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index abc52263298..60def077239 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -310,7 +310,7 @@ describe User do
end
it_behaves_like 'an object with RFC3696 compliant email-formated attributes', :public_email, :notification_email do
- subject { build(:user).tap { |user| user.emails << build(:email, email: email_value) } }
+ subject { create(:user).tap { |user| user.emails << build(:email, email: email_value, confirmed_at: Time.current) } }
end
describe '#commit_email' do
@@ -567,6 +567,32 @@ describe User do
user = build(:user, email: "temp-email-for-oauth@example.com")
expect(user).to be_valid
end
+
+ it 'does not accept not verified emails' do
+ email = create(:email)
+ user = email.user
+ user.update(notification_email: email.email)
+
+ expect(user).to be_invalid
+ end
+ end
+
+ context 'owns_public_email' do
+ it 'accepts verified emails' do
+ email = create(:email, :confirmed, email: 'test@test.com')
+ user = email.user
+ user.update(public_email: email.email)
+
+ expect(user).to be_valid
+ end
+
+ it 'does not accept not verified emails' do
+ email = create(:email)
+ user = email.user
+ user.update(public_email: email.email)
+
+ expect(user).to be_invalid
+ end
end
context 'set_commit_email' do
@@ -2171,6 +2197,31 @@ describe User do
end
end
+ describe '#public_verified_emails' do
+ let(:user) { create(:user) }
+
+ it 'returns only confirmed public emails' do
+ email_confirmed = create :email, user: user, confirmed_at: Time.current
+ create :email, user: user
+
+ expect(user.public_verified_emails).to contain_exactly(
+ user.email,
+ email_confirmed.email
+ )
+ end
+
+ it 'returns confirmed public emails plus main user email when user is not confirmed' do
+ user = create(:user, confirmed_at: nil)
+ email_confirmed = create :email, user: user, confirmed_at: Time.current
+ create :email, user: user
+
+ expect(user.public_verified_emails).to contain_exactly(
+ user.email,
+ email_confirmed.email
+ )
+ end
+ end
+
describe '#verified_email?' do
let(:user) { create(:user) }
@@ -4333,9 +4384,10 @@ describe User do
context 'when an ancestor has a level other than Global' do
let(:ancestor) { create(:group) }
let(:group) { create(:group, parent: ancestor) }
+ let(:email) { create(:email, :confirmed, email: 'ancestor@example.com', user: user) }
before do
- create(:notification_setting, user: user, source: ancestor, level: 'participating', notification_email: 'ancestor@example.com')
+ create(:notification_setting, user: user, source: ancestor, level: 'participating', notification_email: email.email)
end
it 'has the same level set' do
@@ -4360,10 +4412,12 @@ describe User do
let(:grand_ancestor) { create(:group) }
let(:ancestor) { create(:group, parent: grand_ancestor) }
let(:group) { create(:group, parent: ancestor) }
+ let(:ancestor_email) { create(:email, :confirmed, email: 'ancestor@example.com', user: user) }
+ let(:grand_email) { create(:email, :confirmed, email: 'grand@example.com', user: user) }
before do
- create(:notification_setting, user: user, source: grand_ancestor, level: 'participating', notification_email: 'grand@example.com')
- create(:notification_setting, user: user, source: ancestor, level: 'global', notification_email: 'ancestor@example.com')
+ create(:notification_setting, user: user, source: grand_ancestor, level: 'participating', notification_email: grand_email.email)
+ create(:notification_setting, user: user, source: ancestor, level: 'global', notification_email: ancestor_email.email)
end
it 'has the same email set' do
@@ -4401,7 +4455,7 @@ describe User do
context 'when group has notification email set' do
it 'returns group notification email' do
group_notification_email = 'user+group@example.com'
-
+ create(:email, :confirmed, user: user, email: group_notification_email)
create(:notification_setting, user: user, source: group, notification_email: group_notification_email)
is_expected.to eq(group_notification_email)