2016-04-02 18:10:28 +05:30
|
|
|
shared_context 'gitlab email notification' do
|
2019-02-15 15:39:39 +05:30
|
|
|
set(:project) { create(:project, :repository, name: 'a-known-name') }
|
2017-09-10 17:25:29 +05:30
|
|
|
set(:recipient) { create(:user, email: 'recipient@example.com') }
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
let(:gitlab_sender_display_name) { Gitlab.config.gitlab.email_display_name }
|
|
|
|
let(:gitlab_sender) { Gitlab.config.gitlab.email_from }
|
|
|
|
let(:gitlab_sender_reply_to) { Gitlab.config.gitlab.email_reply_to }
|
|
|
|
let(:new_user_address) { 'newguy@example.com' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
email = recipient.emails.create(email: "notifications@example.com")
|
|
|
|
recipient.update_attribute(:notification_email, email.email)
|
2016-06-02 11:05:42 +05:30
|
|
|
stub_incoming_email_setting(enabled: true, address: "reply+%{key}@#{Gitlab.config.gitlab.host}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_context 'reply-by-email is enabled with incoming address without %{key}' do
|
|
|
|
before do
|
|
|
|
stub_incoming_email_setting(enabled: true, address: "reply@#{Gitlab.config.gitlab.host}")
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'a multiple recipients email' do
|
|
|
|
it 'is sent to the given recipient' do
|
|
|
|
is_expected.to deliver_to recipient.notification_email
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'an email sent from GitLab' do
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'has the characteristics of an email sent from GitLab' do
|
2016-04-02 18:10:28 +05:30
|
|
|
sender = subject.header[:from].addrs[0]
|
|
|
|
reply_to = subject.header[:reply_to].addresses
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
aggregate_failures do
|
|
|
|
expect(sender.display_name).to eq(gitlab_sender_display_name)
|
|
|
|
expect(sender.address).to eq(gitlab_sender)
|
|
|
|
expect(reply_to).to eq([gitlab_sender_reply_to])
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'an email that contains a header with author username' do
|
|
|
|
it 'has X-GitLab-Author header containing author\'s username' do
|
|
|
|
is_expected.to have_header 'X-GitLab-Author', user.username
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
shared_examples 'an email with X-GitLab headers containing IDs' do
|
|
|
|
it 'has X-GitLab-*-ID header' do
|
|
|
|
is_expected.to have_header "X-GitLab-#{model.class.name}-ID", "#{model.id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has X-GitLab-*-IID header if model has iid defined' do
|
|
|
|
if model.respond_to?(:iid)
|
|
|
|
is_expected.to have_header "X-GitLab-#{model.class.name}-IID", "#{model.iid}"
|
|
|
|
else
|
|
|
|
expect(subject.header["X-GitLab-#{model.class.name}-IID"]).to eq nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
shared_examples 'an email with X-GitLab headers containing project details' do
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'has X-GitLab-Project headers' do
|
|
|
|
aggregate_failures do
|
2019-02-15 15:39:39 +05:30
|
|
|
full_path_as_domain = "#{project.name}.#{project.namespace.path}"
|
2017-08-17 22:00:37 +05:30
|
|
|
is_expected.to have_header('X-GitLab-Project', /#{project.name}/)
|
|
|
|
is_expected.to have_header('X-GitLab-Project-Id', /#{project.id}/)
|
2017-09-10 17:25:29 +05:30
|
|
|
is_expected.to have_header('X-GitLab-Project-Path', /#{project.full_path}/)
|
2019-02-15 15:39:39 +05:30
|
|
|
is_expected.to have_header('List-Id', "#{project.full_path} <#{project.id}.#{full_path_as_domain}.#{Gitlab.config.gitlab.host}>")
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
shared_examples 'a new thread email with reply-by-email enabled' do
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'has the characteristics of a threaded email' do
|
|
|
|
host = Gitlab.config.gitlab.host
|
|
|
|
route_key = "#{model.class.model_name.singular_route_key}_#{model.id}"
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
aggregate_failures do
|
|
|
|
is_expected.to have_header('Message-ID', "<#{route_key}@#{host}>")
|
|
|
|
is_expected.to have_header('References', /\A<reply\-.*@#{host}>\Z/ )
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
shared_examples 'a thread answer email with reply-by-email enabled' do
|
2016-04-02 18:10:28 +05:30
|
|
|
include_examples 'an email with X-GitLab headers containing project details'
|
2018-12-13 13:39:08 +05:30
|
|
|
include_examples 'an email with X-GitLab headers containing IDs'
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'has the characteristics of a threaded reply' do
|
|
|
|
host = Gitlab.config.gitlab.host
|
|
|
|
route_key = "#{model.class.model_name.singular_route_key}_#{model.id}"
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
aggregate_failures do
|
|
|
|
is_expected.to have_header('Message-ID', /\A<.*@#{host}>\Z/)
|
|
|
|
is_expected.to have_header('In-Reply-To', "<#{route_key}@#{host}>")
|
2018-11-18 11:00:15 +05:30
|
|
|
is_expected.to have_header('References', /\A<reply\-.*@#{host}> <#{route_key}@#{host}>\Z/ )
|
2017-08-17 22:00:37 +05:30
|
|
|
is_expected.to have_subject(/^Re: /)
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
shared_examples 'an email starting a new thread with reply-by-email enabled' do
|
|
|
|
include_examples 'an email with X-GitLab headers containing project details'
|
2018-12-13 13:39:08 +05:30
|
|
|
include_examples 'an email with X-GitLab headers containing IDs'
|
2016-06-02 11:05:42 +05:30
|
|
|
include_examples 'a new thread email with reply-by-email enabled'
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
it 'includes "Reply to this email directly or <View it on GitLab>"' do
|
|
|
|
expect(subject.default_part.body).to include(%(Reply to this email directly or <a href="#{Gitlab::UrlBuilder.build(model)}">view it on GitLab</a>.))
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
context 'when reply-by-email is enabled with incoming address with %{key}' do
|
|
|
|
it 'has a Reply-To header' do
|
|
|
|
is_expected.to have_header 'Reply-To', /<reply+(.*)@#{Gitlab.config.gitlab.host}>\Z/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when reply-by-email is enabled with incoming address without %{key}' do
|
|
|
|
include_context 'reply-by-email is enabled with incoming address without %{key}'
|
|
|
|
include_examples 'a new thread email with reply-by-email enabled'
|
|
|
|
|
|
|
|
it 'has a Reply-To header' do
|
|
|
|
is_expected.to have_header 'Reply-To', /<reply@#{Gitlab.config.gitlab.host}>\Z/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'an answer to an existing thread with reply-by-email enabled' do
|
|
|
|
include_examples 'an email with X-GitLab headers containing project details'
|
2018-12-13 13:39:08 +05:30
|
|
|
include_examples 'an email with X-GitLab headers containing IDs'
|
2016-06-02 11:05:42 +05:30
|
|
|
include_examples 'a thread answer email with reply-by-email enabled'
|
|
|
|
|
|
|
|
context 'when reply-by-email is enabled with incoming address with %{key}' do
|
|
|
|
it 'has a Reply-To header' do
|
|
|
|
is_expected.to have_header 'Reply-To', /<reply+(.*)@#{Gitlab.config.gitlab.host}>\Z/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when reply-by-email is enabled with incoming address without %{key}' do
|
|
|
|
include_context 'reply-by-email is enabled with incoming address without %{key}'
|
|
|
|
include_examples 'a thread answer email with reply-by-email enabled'
|
|
|
|
|
|
|
|
it 'has a Reply-To header' do
|
|
|
|
is_expected.to have_header 'Reply-To', /<reply@#{Gitlab.config.gitlab.host}>\Z/
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'it should have Gmail Actions links' do
|
2017-08-17 22:00:37 +05:30
|
|
|
it do
|
|
|
|
aggregate_failures do
|
|
|
|
is_expected.to have_body_text('<script type="application/ld+json">')
|
|
|
|
is_expected.to have_body_text('ViewAction')
|
|
|
|
end
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'it should not have Gmail Actions links' do
|
2017-08-17 22:00:37 +05:30
|
|
|
it do
|
|
|
|
aggregate_failures do
|
|
|
|
is_expected.not_to have_body_text('<script type="application/ld+json">')
|
|
|
|
is_expected.not_to have_body_text('ViewAction')
|
|
|
|
end
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'it should show Gmail Actions View Issue link' do
|
|
|
|
it_behaves_like 'it should have Gmail Actions links'
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to have_body_text('View Issue') }
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'it should show Gmail Actions View Merge request link' do
|
|
|
|
it_behaves_like 'it should have Gmail Actions links'
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to have_body_text('View Merge request') }
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'it should show Gmail Actions View Commit link' do
|
|
|
|
it_behaves_like 'it should have Gmail Actions links'
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to have_body_text('View Commit') }
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'an unsubscribeable thread' do
|
2017-08-17 22:00:37 +05:30
|
|
|
it_behaves_like 'an unsubscribeable thread with incoming address without %{key}'
|
|
|
|
|
|
|
|
it 'has a List-Unsubscribe header in the correct format, and a body link' do
|
|
|
|
aggregate_failures do
|
|
|
|
is_expected.to have_header('List-Unsubscribe', /unsubscribe/)
|
|
|
|
is_expected.to have_header('List-Unsubscribe', /mailto/)
|
|
|
|
is_expected.to have_header('List-Unsubscribe', /^<.+,.+>$/)
|
|
|
|
is_expected.to have_body_text('unsubscribe')
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'an unsubscribeable thread with incoming address without %{key}' do
|
|
|
|
include_context 'reply-by-email is enabled with incoming address without %{key}'
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'has a List-Unsubscribe header in the correct format, and a body link' do
|
|
|
|
aggregate_failures do
|
|
|
|
is_expected.to have_header('List-Unsubscribe', /unsubscribe/)
|
|
|
|
is_expected.not_to have_header('List-Unsubscribe', /mailto/)
|
|
|
|
is_expected.to have_header('List-Unsubscribe', /^<[^,]+>$/)
|
|
|
|
is_expected.to have_body_text('unsubscribe')
|
|
|
|
end
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
shared_examples 'a user cannot unsubscribe through footer link' do
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'does not have a List-Unsubscribe header or a body link' do
|
|
|
|
aggregate_failures do
|
|
|
|
is_expected.not_to have_header('List-Unsubscribe', /unsubscribe/)
|
|
|
|
is_expected.not_to have_body_text('unsubscribe')
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
shared_examples 'an email with a labels subscriptions link in its footer' do
|
2017-08-17 22:00:37 +05:30
|
|
|
it { is_expected.to have_body_text('label subscriptions') }
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
shared_examples 'a note email' do
|
|
|
|
it_behaves_like 'it should have Gmail Actions links'
|
|
|
|
|
|
|
|
it 'is sent to the given recipient as the author' do
|
|
|
|
sender = subject.header[:from].addrs[0]
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(sender.display_name).to eq(note_author.name)
|
|
|
|
expect(sender.address).to eq(gitlab_sender)
|
|
|
|
expect(subject).to deliver_to(recipient.notification_email)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains the message from the note' do
|
2018-11-08 19:23:39 +05:30
|
|
|
is_expected.to have_body_text note.note
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not contain note author' do
|
|
|
|
is_expected.not_to have_body_text note.author_name
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when enabled email_author_in_body' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(email_author_in_body: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains a link to note author' do
|
2018-11-08 19:23:39 +05:30
|
|
|
is_expected.to have_body_text note.author_name
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|