From 884b5c6455e7422fd987f1253ec7444ba5a1ca4e Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Tue, 10 Aug 2021 14:42:56 +0200 Subject: [PATCH] Fixes #3669 - Do not send domain and migrate domain out of Google and Microsoft 365 channels. --- .../20210810091200_issue_3669_fix_domain.rb | 12 +++++ lib/external_credential/google.rb | 1 - lib/external_credential/microsoft365.rb | 1 - spec/db/migrate/issue_3669_fix_domain_spec.rb | 49 +++++++++++++++++++ spec/factories/channel.rb | 2 - spec/lib/external_credential/google_spec.rb | 1 - .../external_credential/microsoft365_spec.rb | 1 - 7 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20210810091200_issue_3669_fix_domain.rb create mode 100644 spec/db/migrate/issue_3669_fix_domain_spec.rb diff --git a/db/migrate/20210810091200_issue_3669_fix_domain.rb b/db/migrate/20210810091200_issue_3669_fix_domain.rb new file mode 100644 index 000000000..cb6ebab64 --- /dev/null +++ b/db/migrate/20210810091200_issue_3669_fix_domain.rb @@ -0,0 +1,12 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + +class Issue3669FixDomain < ActiveRecord::Migration[6.0] + def change + return if !Setting.exists?(name: 'system_init_done') + + Channel.where(area: ['Google::Account', 'Microsoft365::Account']).each do |channel| + channel.options[:outbound][:options].delete(:domain) + channel.save! + end + end +end diff --git a/lib/external_credential/google.rb b/lib/external_credential/google.rb index 5ea45c651..10de9ec88 100644 --- a/lib/external_credential/google.rb +++ b/lib/external_credential/google.rb @@ -57,7 +57,6 @@ class ExternalCredential::Google adapter: 'smtp', options: { host: 'smtp.gmail.com', - domain: 'gmail.com', port: 465, ssl: true, user: user_data[:email], diff --git a/lib/external_credential/microsoft365.rb b/lib/external_credential/microsoft365.rb index e74ec6145..ccf006341 100644 --- a/lib/external_credential/microsoft365.rb +++ b/lib/external_credential/microsoft365.rb @@ -61,7 +61,6 @@ class ExternalCredential::Microsoft365 adapter: 'smtp', options: { host: 'smtp.office365.com', - domain: 'office365.com', port: 587, user: user_data[:preferred_username], authentication: 'xoauth2', diff --git a/spec/db/migrate/issue_3669_fix_domain_spec.rb b/spec/db/migrate/issue_3669_fix_domain_spec.rb new file mode 100644 index 000000000..cc759a8cb --- /dev/null +++ b/spec/db/migrate/issue_3669_fix_domain_spec.rb @@ -0,0 +1,49 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + +require 'rails_helper' + +RSpec.describe Issue3669FixDomain, type: :db_migration do + let!(:channel) do + channel_options = { + inbound: { + adapter: 'imap', + options: { + auth_type: 'XOAUTH2', + host: 'imap.gmail.com', + ssl: true, + user: 'example@gmail.com', + }, + }, + outbound: { + adapter: 'smtp', + options: { + host: 'smtp.gmail.com', + domain: 'gmail.com', + port: 465, + ssl: true, + user: 'example@gmail.com', + authentication: 'xoauth2', + }, + }, + auth: { + provider: 'google', + type: 'XOAUTH2', + client_id: 'abc', + client_secret: 'efg', + }, + } + + Channel.create!( + area: 'Google::Account', + group_id: Group.first.id, + options: channel_options, + active: false, + created_by_id: 1, + updated_by_id: 1, + ) + end + + it 'removes domain from the configuration' do + expect { migrate }.to change { channel.reload.options[:outbound][:options][:domain] }.to(nil) + end +end diff --git a/spec/factories/channel.rb b/spec/factories/channel.rb index 821af32e5..2291f0aac 100644 --- a/spec/factories/channel.rb +++ b/spec/factories/channel.rb @@ -143,7 +143,6 @@ FactoryBot.define do 'adapter' => 'smtp', 'options' => { 'host' => 'smtp.gmail.com', - 'domain' => 'gmail.com', 'port' => 465, 'ssl' => true, 'user' => ENV['GMAIL_USER'], @@ -186,7 +185,6 @@ FactoryBot.define do 'adapter' => 'smtp', 'options' => { 'host' => 'smtp.office365.com', - 'domain' => 'office365.com', 'port' => 587, 'user' => ENV['MICROSOFT365_USER'], 'authentication' => 'xoauth2', diff --git a/spec/lib/external_credential/google_spec.rb b/spec/lib/external_credential/google_spec.rb index 135dc52af..17c222b02 100644 --- a/spec/lib/external_credential/google_spec.rb +++ b/spec/lib/external_credential/google_spec.rb @@ -129,7 +129,6 @@ RSpec.describe ExternalCredential::Google do 'options' => a_hash_including( 'authentication' => 'xoauth2', 'host' => 'smtp.gmail.com', - 'domain' => 'gmail.com', 'port' => 465, 'ssl' => true, 'user' => primary_email, diff --git a/spec/lib/external_credential/microsoft365_spec.rb b/spec/lib/external_credential/microsoft365_spec.rb index d2c1df753..679962aa3 100644 --- a/spec/lib/external_credential/microsoft365_spec.rb +++ b/spec/lib/external_credential/microsoft365_spec.rb @@ -95,7 +95,6 @@ RSpec.describe ExternalCredential::Microsoft365 do 'options' => a_hash_including( 'authentication' => 'xoauth2', 'host' => 'smtp.office365.com', - 'domain' => 'office365.com', 'port' => 587, 'user' => email_address, )