2019-01-21 17:17:18 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2019-09-02 13:28:39 +00:00
|
|
|
require 'system/examples/text_modules_examples'
|
2019-07-03 16:14:28 +00:00
|
|
|
|
2019-01-21 17:17:18 +00:00
|
|
|
RSpec.describe 'Ticket Create', type: :system do
|
|
|
|
context 'when applying ticket templates' do
|
2020-06-19 09:17:18 +00:00
|
|
|
let(:agent) { create(:agent, groups: [permitted_group]) }
|
2020-04-30 15:38:57 +00:00
|
|
|
let(:permitted_group) { create(:group) }
|
|
|
|
let(:unpermitted_group) { create(:group) }
|
|
|
|
let!(:template) { create(:template, :dummy_data, group: unpermitted_group, owner: agent) }
|
2019-01-21 17:17:18 +00:00
|
|
|
|
2020-04-30 15:38:57 +00:00
|
|
|
# Regression test for issue #2424 - Unavailable ticket template attributes get applied
|
2020-06-18 11:51:25 +00:00
|
|
|
it 'unavailable attributes do not get applied', authenticated_as: :agent do
|
2019-01-21 17:17:18 +00:00
|
|
|
visit 'ticket/create'
|
2019-02-04 06:56:18 +00:00
|
|
|
|
2020-04-30 15:38:57 +00:00
|
|
|
use_template(template)
|
2019-01-21 17:17:18 +00:00
|
|
|
expect(page).not_to have_selector 'select[name="group_id"]'
|
|
|
|
end
|
|
|
|
end
|
2019-07-03 16:14:28 +00:00
|
|
|
|
|
|
|
context 'when using text modules' do
|
2019-09-02 13:28:39 +00:00
|
|
|
include_examples 'text modules', path: 'ticket/create'
|
2019-07-03 16:14:28 +00:00
|
|
|
end
|
2020-06-02 11:01:16 +00:00
|
|
|
|
2020-06-15 22:11:29 +00:00
|
|
|
context 'S/MIME', authenticated_as: :authenticate do
|
|
|
|
def authenticate
|
2020-06-02 11:01:16 +00:00
|
|
|
Setting.set('smime_integration', true)
|
2020-06-15 22:11:29 +00:00
|
|
|
current_user
|
2020-06-02 11:01:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'no certificate present' do
|
2020-06-15 22:11:29 +00:00
|
|
|
let!(:template) { create(:template, :dummy_data) }
|
|
|
|
let(:current_user) { true }
|
2020-06-02 11:01:16 +00:00
|
|
|
|
|
|
|
it 'has no security selections' do
|
|
|
|
visit 'ticket/create'
|
|
|
|
|
|
|
|
within(:active_content) do
|
|
|
|
use_template(template)
|
|
|
|
|
|
|
|
expect(page).not_to have_css('div.js-securityEncrypt.btn--active', wait: 5)
|
|
|
|
expect(page).not_to have_css('div.js-securitySign.btn--active', wait: 5)
|
|
|
|
click '.js-submit'
|
|
|
|
|
|
|
|
expect(page).to have_css('.ticket-article-item', count: 1)
|
|
|
|
|
|
|
|
open_article_meta
|
|
|
|
|
|
|
|
expect(page).not_to have_css('span', text: 'Signed')
|
|
|
|
expect(page).not_to have_css('span', text: 'Encrypted')
|
|
|
|
|
|
|
|
security_result = Ticket::Article.last.preferences['security']
|
|
|
|
expect(security_result['encryption']['success']).to be nil
|
|
|
|
expect(security_result['sign']['success']).to be nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-15 22:11:29 +00:00
|
|
|
context 'private key configured' do
|
|
|
|
let(:current_user) { agent }
|
2020-06-02 11:01:16 +00:00
|
|
|
let!(:template) { create(:template, :dummy_data, group: group, owner: agent, customer: customer) }
|
|
|
|
|
|
|
|
let(:system_email_address) { 'smime1@example.com' }
|
|
|
|
let(:email_address) { create(:email_address, email: system_email_address) }
|
|
|
|
let(:group) { create(:group, email_address: email_address) }
|
|
|
|
let(:agent_groups) { [group] }
|
2020-06-19 09:17:18 +00:00
|
|
|
let(:agent) { create(:agent, groups: agent_groups) }
|
2020-06-02 11:01:16 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
create(:smime_certificate, :with_private, fixture: system_email_address)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'recipient certificate present' do
|
|
|
|
|
|
|
|
let(:recipient_email_address) { 'smime2@example.com' }
|
2020-06-19 09:17:18 +00:00
|
|
|
let(:customer) { create(:customer, email: recipient_email_address) }
|
2020-06-02 11:01:16 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
create(:smime_certificate, fixture: recipient_email_address)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'plain' do
|
|
|
|
visit 'ticket/create'
|
|
|
|
|
|
|
|
within(:active_content) do
|
|
|
|
use_template(template)
|
|
|
|
|
|
|
|
# wait till S/MIME check AJAX call is ready
|
|
|
|
expect(page).to have_css('div.js-securityEncrypt.btn--active', wait: 5)
|
|
|
|
expect(page).to have_css('div.js-securitySign.btn--active', wait: 5)
|
|
|
|
|
|
|
|
# deactivate encryption and signing
|
|
|
|
click '.js-securityEncrypt'
|
|
|
|
click '.js-securitySign'
|
|
|
|
|
|
|
|
click '.js-submit'
|
|
|
|
|
|
|
|
expect(page).to have_css('.ticket-article-item', count: 1)
|
|
|
|
|
|
|
|
open_article_meta
|
|
|
|
|
|
|
|
expect(page).not_to have_css('span', text: 'Signed')
|
|
|
|
expect(page).not_to have_css('span', text: 'Encrypted')
|
|
|
|
|
|
|
|
security_result = Ticket::Article.last.preferences['security']
|
|
|
|
expect(security_result['encryption']['success']).to be nil
|
|
|
|
expect(security_result['sign']['success']).to be nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'signed' do
|
|
|
|
visit 'ticket/create'
|
|
|
|
|
|
|
|
within(:active_content) do
|
|
|
|
use_template(template)
|
|
|
|
|
|
|
|
# wait till S/MIME check AJAX call is ready
|
|
|
|
expect(page).to have_css('div.js-securityEncrypt.btn--active', wait: 5)
|
|
|
|
expect(page).to have_css('div.js-securitySign.btn--active', wait: 5)
|
|
|
|
|
|
|
|
# deactivate encryption
|
|
|
|
click '.js-securityEncrypt'
|
|
|
|
|
|
|
|
click '.js-submit'
|
|
|
|
|
|
|
|
expect(page).to have_css('.ticket-article-item', count: 1)
|
|
|
|
|
|
|
|
open_article_meta
|
|
|
|
|
|
|
|
expect(page).to have_css('span', text: 'Signed')
|
|
|
|
expect(page).not_to have_css('span', text: 'Encrypted')
|
|
|
|
|
|
|
|
security_result = Ticket::Article.last.preferences['security']
|
|
|
|
expect(security_result['encryption']['success']).to be nil
|
|
|
|
expect(security_result['sign']['success']).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'encrypted' do
|
|
|
|
visit 'ticket/create'
|
|
|
|
|
|
|
|
within(:active_content) do
|
|
|
|
use_template(template)
|
|
|
|
|
|
|
|
# wait till S/MIME check AJAX call is ready
|
|
|
|
expect(page).to have_css('div.js-securityEncrypt.btn--active', wait: 5)
|
|
|
|
expect(page).to have_css('div.js-securitySign.btn--active', wait: 5)
|
|
|
|
|
|
|
|
# deactivate signing
|
|
|
|
click '.js-securitySign'
|
|
|
|
|
|
|
|
click '.js-submit'
|
|
|
|
|
|
|
|
expect(page).to have_css('.ticket-article-item', count: 1)
|
|
|
|
|
|
|
|
open_article_meta
|
|
|
|
|
|
|
|
expect(page).not_to have_css('span', text: 'Signed')
|
|
|
|
expect(page).to have_css('span', text: 'Encrypted')
|
|
|
|
|
|
|
|
security_result = Ticket::Article.last.preferences['security']
|
|
|
|
expect(security_result['encryption']['success']).to be true
|
|
|
|
expect(security_result['sign']['success']).to be nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'signed and encrypted' do
|
|
|
|
visit 'ticket/create'
|
|
|
|
|
|
|
|
within(:active_content) do
|
|
|
|
use_template(template)
|
|
|
|
|
|
|
|
# wait till S/MIME check AJAX call is ready
|
|
|
|
expect(page).to have_css('div.js-securityEncrypt.btn--active', wait: 5)
|
|
|
|
expect(page).to have_css('div.js-securitySign.btn--active', wait: 5)
|
|
|
|
|
|
|
|
click '.js-submit'
|
|
|
|
|
|
|
|
expect(page).to have_css('.ticket-article-item', count: 1)
|
|
|
|
|
|
|
|
open_article_meta
|
|
|
|
|
|
|
|
expect(page).to have_css('span', text: 'Signed')
|
|
|
|
expect(page).to have_css('span', text: 'Encrypted')
|
|
|
|
|
|
|
|
security_result = Ticket::Article.last.preferences['security']
|
|
|
|
expect(security_result['encryption']['success']).to be true
|
|
|
|
expect(security_result['sign']['success']).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'Group default behavior' do
|
|
|
|
|
|
|
|
let(:smime_config) { {} }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Setting.set('smime_config', smime_config)
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'security defaults example' do |sign:, encrypt:|
|
|
|
|
|
|
|
|
it "security defaults sign: #{sign}, encrypt: #{encrypt}" do
|
|
|
|
within(:active_content) do
|
|
|
|
encrypt_button = find('.js-securityEncrypt', wait: 5)
|
|
|
|
sign_button = find('.js-securitySign', wait: 5)
|
|
|
|
|
|
|
|
await_empty_ajax_queue
|
|
|
|
|
|
|
|
active_button_class = '.btn--active'
|
|
|
|
expect(encrypt_button.matches_css?(active_button_class, wait: 2)).to be(encrypt)
|
|
|
|
expect(sign_button.matches_css?(active_button_class, wait: 2)).to be(sign)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'security defaults' do |sign:, encrypt:|
|
|
|
|
|
|
|
|
before do
|
|
|
|
visit 'ticket/create'
|
|
|
|
|
|
|
|
within(:active_content) do
|
|
|
|
use_template(template)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'security defaults example', sign: sign, encrypt: encrypt
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'security defaults group change' do |sign:, encrypt:|
|
|
|
|
|
|
|
|
before do
|
|
|
|
visit 'ticket/create'
|
|
|
|
|
|
|
|
within(:active_content) do
|
|
|
|
use_template(template)
|
|
|
|
|
|
|
|
await_empty_ajax_queue
|
|
|
|
|
|
|
|
select new_group.name, from: 'group_id'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'security defaults example', sign: sign, encrypt: encrypt
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'not configured' do
|
|
|
|
it_behaves_like 'security defaults', sign: true, encrypt: true
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'configuration present' do
|
|
|
|
|
|
|
|
let(:smime_config) do
|
|
|
|
{
|
|
|
|
'group_id' => group_defaults
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:group_defaults) do
|
|
|
|
{
|
|
|
|
'default_encryption' => {
|
|
|
|
group.id.to_s => default_encryption,
|
|
|
|
},
|
|
|
|
'default_sign' => {
|
|
|
|
group.id.to_s => default_sign,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:default_sign) { true }
|
|
|
|
let(:default_encryption) { true }
|
|
|
|
|
|
|
|
shared_examples 'sign and encrypt variations' do |check_examples_name|
|
|
|
|
|
|
|
|
it_behaves_like check_examples_name, sign: true, encrypt: true
|
|
|
|
|
|
|
|
context 'no value' do
|
|
|
|
let(:group_defaults) { {} }
|
|
|
|
|
|
|
|
it_behaves_like check_examples_name, sign: true, encrypt: true
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'signing disabled' do
|
|
|
|
let(:default_sign) { false }
|
|
|
|
|
|
|
|
it_behaves_like check_examples_name, sign: false, encrypt: true
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'encryption disabled' do
|
|
|
|
let(:default_encryption) { false }
|
|
|
|
|
|
|
|
it_behaves_like check_examples_name, sign: true, encrypt: false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'same Group' do
|
|
|
|
it_behaves_like 'sign and encrypt variations', 'security defaults'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'Group change' do
|
|
|
|
let(:new_group) { create(:group, email_address: email_address) }
|
|
|
|
|
|
|
|
let(:agent_groups) { [group, new_group] }
|
|
|
|
|
|
|
|
let(:group_defaults) do
|
|
|
|
{
|
|
|
|
'default_encryption' => {
|
|
|
|
new_group.id.to_s => default_encryption,
|
|
|
|
},
|
|
|
|
'default_sign' => {
|
|
|
|
new_group.id.to_s => default_sign,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'sign and encrypt variations', 'security defaults group change'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-01-21 17:17:18 +00:00
|
|
|
end
|