Merge branch 'develop' into fix/CW-7007

This commit is contained in:
Sivin Varghese
2026-05-08 19:54:38 +05:30
committed by GitHub
16 changed files with 39953 additions and 2575 deletions
@@ -568,8 +568,10 @@ RSpec.describe 'Inboxes API', type: :request do
email_channel = create(:channel_email, account: account)
email_inbox = create(:inbox, channel: email_channel, account: account)
imap_connection = double
allow(Mail).to receive(:connection).and_return(imap_connection)
imap_connection = instance_double(Net::IMAP, disconnected?: false)
allow(Net::IMAP).to receive(:new).and_return(imap_connection)
allow(imap_connection).to receive(:login)
allow(imap_connection).to receive(:disconnect)
patch "/api/v1/accounts/#{account.id}/inboxes/#{email_inbox.id}",
headers: admin.create_new_auth_token,
@@ -578,7 +580,8 @@ RSpec.describe 'Inboxes API', type: :request do
imap_enabled: true,
imap_address: 'imap.gmail.com',
imap_port: 993,
imap_login: 'imaptest@gmail.com'
imap_login: 'imaptest@gmail.com',
imap_authentication: 'login'
}
},
as: :json
@@ -587,6 +590,7 @@ RSpec.describe 'Inboxes API', type: :request do
expect(email_channel.reload.imap_enabled).to be true
expect(email_channel.reload.imap_address).to eq('imap.gmail.com')
expect(email_channel.reload.imap_port).to eq(993)
expect(email_channel.reload.imap_authentication).to eq('login')
end
it 'updates avatar when administrator' do
+2
View File
@@ -16,6 +16,7 @@ FactoryBot.define do
imap_login { 'email@example.com' }
imap_password { '' }
imap_enable_ssl { true }
provider_config do
{
expires_on: Time.zone.now + 3600,
@@ -33,6 +34,7 @@ FactoryBot.define do
imap_login { 'email@example.com' }
imap_password { 'random-password' }
imap_enable_ssl { true }
imap_authentication { 'plain' }
end
end
end
+56 -2
View File
@@ -13,14 +13,68 @@ RSpec.describe Imap::FetchEmailService do
before do
allow(Rails).to receive(:logger).and_return(logger)
allow(Net::IMAP).to receive(:new).with(
imap_email_channel.imap_address, port: imap_email_channel.imap_port, ssl: true
imap_email_channel.imap_address, port: imap_email_channel.imap_port, ssl: imap_email_channel.imap_enable_ssl
).and_return(imap)
allow(imap).to receive(:authenticate).with(
'PLAIN', imap_email_channel.imap_login, imap_email_channel.imap_password
'plain', imap_email_channel.imap_login, imap_email_channel.imap_password
)
allow(imap).to receive(:select).with('INBOX')
end
context 'when using CRAM-MD5 authentication' do
let(:cram_md5_channel) { create(:channel_email, :imap_email, account: account, imap_authentication: 'cram-md5') }
before do
allow(Net::IMAP).to receive(:new).with(
cram_md5_channel.imap_address, port: cram_md5_channel.imap_port, ssl: cram_md5_channel.imap_enable_ssl
).and_return(imap)
allow(imap).to receive(:authenticate).with(
'CRAM-MD5', cram_md5_channel.imap_login, cram_md5_channel.imap_password
)
allow(imap).to receive(:select).with('INBOX')
end
it 'uses CRAM-MD5 authentication' do
travel_to '26.10.2020 10:00'.to_datetime do
allow(imap).to receive(:search).with(%w[SINCE 25-Oct-2020]).and_return([])
allow(imap).to receive(:logout)
described_class.new(channel: cram_md5_channel).perform
expect(imap).to have_received(:authenticate).with(
'CRAM-MD5', cram_md5_channel.imap_login, cram_md5_channel.imap_password
)
end
end
end
context 'when using LOGIN authentication' do
let(:login_channel) { create(:channel_email, :imap_email, account: account, imap_authentication: 'login') }
before do
allow(Net::IMAP).to receive(:new).with(
login_channel.imap_address, port: login_channel.imap_port, ssl: login_channel.imap_enable_ssl
).and_return(imap)
allow(imap).to receive(:login).with(
login_channel.imap_login, login_channel.imap_password
)
allow(imap).to receive(:select).with('INBOX')
end
it 'uses LOGIN authentication' do
travel_to '26.10.2020 10:00'.to_datetime do
allow(imap).to receive(:search).with(%w[SINCE 25-Oct-2020]).and_return([])
allow(imap).to receive(:logout)
described_class.new(channel: login_channel).perform
expect(imap).to have_received(:login).with(
login_channel.imap_login, login_channel.imap_password
)
end
end
end
context 'when new emails are available in the mailbox' do
it 'fetches the emails and returns the emails that are not present in the db' do
travel_to '26.10.2020 10:00'.to_datetime do