Skip to content

Commit

Permalink
Add autodiscovery exception handling to ExchangeController
Browse files Browse the repository at this point in the history
  • Loading branch information
rlue committed Jul 12, 2018
1 parent d02edbf commit 2e4b712
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 5 additions & 3 deletions app/controllers/integration/exchange_controller.rb
Expand Up @@ -16,9 +16,11 @@ def autodiscover
client.http.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE client.http.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
end end


{ begin
endpoint: client.try(:autodiscover).try(:ews_url), { endpoint: client.autodiscover&.ews_url }
} rescue Errno::EADDRNOTAVAIL
{}
end
end end
end end


Expand Down
20 changes: 19 additions & 1 deletion spec/requests/integration/exchange_spec.rb
Expand Up @@ -12,7 +12,8 @@
end end


describe 'EWS folder retrieval' do describe 'EWS folder retrieval' do
context 'when no folders found' do # see https://github.com/zammad/zammad/issues/1802
context 'when no folders found (#1802)' do
let(:empty_folder_list) { { folders: {} } } let(:empty_folder_list) { { folders: {} } }


it 'responds with an error message' do it 'responds with an error message' do
Expand All @@ -25,4 +26,21 @@
end end
end end
end end

describe 'autodiscovery' do
# see https://github.com/zammad/zammad/issues/2065
context 'when Autodiscover gem raises Errno::EADDRNOTAVAIL (#2065)' do
let(:client) { instance_double('Autodiscover::Client') }

it 'rescues and responds with an empty hash (to proceed to manual configuration)' do
allow(Autodiscover::Client).to receive(:new).with(any_args).and_return(client)
allow(client).to receive(:autodiscover).and_raise(Errno::EADDRNOTAVAIL)

post api_v1_integration_exchange_autodiscover_path,
params: {}, as: :json

expect(json_response).to eq('result' => 'ok')
end
end
end
end end

0 comments on commit 2e4b712

Please sign in to comment.