diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /spec/mailers/emails/profile_spec.rb | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) | |
download | gitlab-ce-9dc93a4519d9d5d7be48ff274127136236a3adb3.tar.gz |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'spec/mailers/emails/profile_spec.rb')
-rw-r--r-- | spec/mailers/emails/profile_spec.rb | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/spec/mailers/emails/profile_spec.rb b/spec/mailers/emails/profile_spec.rb index a32e566fc90..8ac1f15d67e 100644 --- a/spec/mailers/emails/profile_spec.rb +++ b/spec/mailers/emails/profile_spec.rb @@ -212,6 +212,106 @@ RSpec.describe Emails::Profile do end end + describe 'SSH key notification' do + let_it_be_with_reload(:user) { create(:user) } + let_it_be(:fingerprints) { ["aa:bb:cc:dd:ee:zz"] } + + shared_examples 'is sent to the user' do + it { is_expected.to deliver_to user.email } + end + + shared_examples 'has the correct subject' do |subject_text| + it { is_expected.to have_subject subject_text } + end + + shared_examples 'has the correct body text' do |body_text| + it { is_expected.to have_body_text body_text } + end + + shared_examples 'includes a link to ssh key page' do + it { is_expected.to have_body_text /#{profile_keys_url}/ } + end + + shared_examples 'includes the email reason' do + it { is_expected.to have_body_text /You're receiving this email because of your account on localhost/ } + end + + shared_examples 'valid use case' do + it_behaves_like 'an email sent from GitLab' + it_behaves_like 'it should not have Gmail Actions links' + it_behaves_like 'a user cannot unsubscribe through footer link' + it_behaves_like 'is sent to the user' + it_behaves_like 'includes a link to ssh key page' + it_behaves_like 'includes the email reason' + end + + shared_examples 'does not send email' do + it do + expect { subject }.not_to change { ActionMailer::Base.deliveries.count } + end + end + + shared_context 'block user' do + before do + user.block! + end + end + + context 'notification email for expired ssh key' do + context 'when valid' do + subject { Notify.ssh_key_expired_email(user, fingerprints) } + + include_examples 'valid use case' + + it_behaves_like 'has the correct subject', /Your SSH key has expired/ + it_behaves_like 'has the correct body text', /Your SSH keys with the following fingerprints has expired/ + end + + context 'when invalid' do + context 'when user does not exist' do + subject { Notify.ssh_key_expired_email(nil, fingerprints) } + + it_behaves_like 'does not send email' + end + + context 'when user is not active' do + subject { Notify.ssh_key_expired_email(user, fingerprints) } + + include_context 'block user' + + it_behaves_like 'does not send email' + end + end + end + + context 'notification email for expiring ssh key' do + context 'when valid' do + subject { Notify.ssh_key_expiring_soon_email(user, fingerprints) } + + include_examples 'valid use case' + + it_behaves_like 'has the correct subject', /Your SSH key is expiring soon/ + it_behaves_like 'has the correct body text', /Your SSH keys with the following fingerprints are scheduled to expire soon/ + end + + context 'when invalid' do + context 'when user does not exist' do + subject { Notify.ssh_key_expiring_soon_email(nil, fingerprints) } + + it_behaves_like 'does not send email' + end + + context 'when user is not active' do + subject { Notify.ssh_key_expiring_soon_email(user, fingerprints) } + + include_context 'block user' + + it_behaves_like 'does not send email' + end + end + end + end + describe 'user unknown sign in email' do let_it_be(:user) { create(:user) } let_it_be(:ip) { '169.0.0.1' } |