mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 19:48:08 +00:00
Add openssl verify mode and email encryption for smtp configuration (#3885)
* Add openssl verify mode and email encryption for smtp configuration * Add spec for code coverage
This commit is contained in:
@@ -437,32 +437,6 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
expect(email_channel.reload.imap_port).to eq(993)
|
||||
end
|
||||
|
||||
it 'updates email inbox with smtp when administrator' do
|
||||
email_channel = create(:channel_email, account: account)
|
||||
email_inbox = create(:inbox, channel: email_channel, account: account)
|
||||
|
||||
smtp_connection = double
|
||||
allow(smtp_connection).to receive(:finish).and_return(true)
|
||||
allow(Net::SMTP).to receive(:start).and_return(smtp_connection)
|
||||
|
||||
patch "/api/v1/accounts/#{account.id}/inboxes/#{email_inbox.id}",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: {
|
||||
channel: {
|
||||
smtp_enabled: true,
|
||||
smtp_address: 'smtp.gmail.com',
|
||||
smtp_port: 587,
|
||||
smtp_email: 'smtptest@gmail.com'
|
||||
}
|
||||
},
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(email_channel.reload.smtp_enabled).to be true
|
||||
expect(email_channel.reload.smtp_address).to eq('smtp.gmail.com')
|
||||
expect(email_channel.reload.smtp_port).to eq(587)
|
||||
end
|
||||
|
||||
it 'updates avatar when administrator' do
|
||||
# no avatar before upload
|
||||
expect(inbox.avatar.attached?).to eq(false)
|
||||
@@ -501,6 +475,72 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
expect(inbox.reload.allow_messages_after_resolved).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
context 'when an authenticated user updates email inbox' do
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let(:email_channel) { create(:channel_email, account: account) }
|
||||
let(:email_inbox) { create(:inbox, channel: email_channel, account: account) }
|
||||
|
||||
it 'updates smtp configuration with starttls encryption' do
|
||||
smtp_connection = double
|
||||
allow(smtp_connection).to receive(:start).and_return(true)
|
||||
allow(smtp_connection).to receive(:finish).and_return(true)
|
||||
allow(smtp_connection).to receive(:respond_to?).and_return(true)
|
||||
allow(smtp_connection).to receive(:enable_starttls_auto).and_return(true)
|
||||
allow(Net::SMTP).to receive(:new).and_return(smtp_connection)
|
||||
|
||||
patch "/api/v1/accounts/#{account.id}/inboxes/#{email_inbox.id}",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: {
|
||||
channel: {
|
||||
smtp_enabled: true,
|
||||
smtp_address: 'smtp.gmail.com',
|
||||
smtp_port: 587,
|
||||
smtp_email: 'smtptest@gmail.com',
|
||||
smtp_enable_starttls_auto: true,
|
||||
smtp_openssl_verify_mode: 'peer'
|
||||
}
|
||||
},
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(email_channel.reload.smtp_enabled).to be true
|
||||
expect(email_channel.reload.smtp_address).to eq('smtp.gmail.com')
|
||||
expect(email_channel.reload.smtp_port).to eq(587)
|
||||
expect(email_channel.reload.smtp_enable_starttls_auto).to be true
|
||||
expect(email_channel.reload.smtp_openssl_verify_mode).to eq('peer')
|
||||
end
|
||||
|
||||
it 'updates smtp configuration with ssl/tls encryption' do
|
||||
smtp_connection = double
|
||||
allow(smtp_connection).to receive(:start).and_return(true)
|
||||
allow(smtp_connection).to receive(:finish).and_return(true)
|
||||
allow(smtp_connection).to receive(:respond_to?).and_return(true)
|
||||
allow(smtp_connection).to receive(:enable_tls).and_return(true)
|
||||
allow(Net::SMTP).to receive(:new).and_return(smtp_connection)
|
||||
|
||||
patch "/api/v1/accounts/#{account.id}/inboxes/#{email_inbox.id}",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: {
|
||||
channel: {
|
||||
smtp_enabled: true,
|
||||
smtp_address: 'smtp.gmail.com',
|
||||
smtp_email: 'smtptest@gmail.com',
|
||||
smtp_port: 587,
|
||||
smtp_enable_ssl_tls: true,
|
||||
smtp_openssl_verify_mode: 'none'
|
||||
}
|
||||
},
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(email_channel.reload.smtp_enabled).to be true
|
||||
expect(email_channel.reload.smtp_address).to eq('smtp.gmail.com')
|
||||
expect(email_channel.reload.smtp_port).to eq(587)
|
||||
expect(email_channel.reload.smtp_enable_ssl_tls).to be true
|
||||
expect(email_channel.reload.smtp_openssl_verify_mode).to eq('none')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /api/v1/accounts/{account.id}/inboxes/{inbox.id}/agent_bot' do
|
||||
|
||||
Reference in New Issue
Block a user