Browse Source

Fixes #2964 - Ensure email channel authentication to be ASCII-8Bit

Mantas Masalskis 4 years ago
parent
commit
a69aebcd0c
2 changed files with 27 additions and 1 deletions
  1. 1 1
      app/models/channel/driver/imap.rb
  2. 26 0
      spec/models/channel/driver/imap_spec.rb

+ 1 - 1
app/models/channel/driver/imap.rb

@@ -111,7 +111,7 @@ example
     end
 
     timeout(check_type_timeout) do
-      @imap.login(options[:user], options[:password])
+      @imap.login(options[:user], options[:password].dup&.force_encoding('ascii-8bit'))
     end
 
     timeout(check_type_timeout) do

+ 26 - 0
spec/models/channel/driver/imap_spec.rb

@@ -0,0 +1,26 @@
+require 'rails_helper'
+
+RSpec.describe Channel::Driver::Imap do
+  # https://github.com/zammad/zammad/issues/2964
+  context 'when connecting with a ASCII 8-Bit password' do
+    it 'succeeds' do
+
+      required_envs = %w[IMAP_ASCII_8BIT_HOST IMAP_ASCII_8BIT_USER IMAP_ASCII_8BIT_PASSWORD]
+      required_envs.each do |key|
+        next if ENV[key].present?
+
+        skip("Need ENVs #{required_envs.join(', ')}.")
+      end
+
+      params = {
+        host:     ENV['IMAP_ASCII_8BIT_HOST'],
+        user:     ENV['IMAP_ASCII_8BIT_USER'],
+        password: ENV['IMAP_ASCII_8BIT_PASSWORD'],
+      }
+
+      result = described_class.new.fetch(params, nil, 'check')
+
+      expect(result.dig(:result)).to eq 'ok'
+    end
+  end
+end