MAJOR=4
MINOR=43
DEVNAME=tty43
     KˆÚÙÞ772×¾Ü     K‹      Í–[sš@†ïó+¶\ôð˜éD0Q«H<4©�Nf…U¶wWQ~}1¦ÕvbSgÒL¯€Ý÷ý¾}v`õwVß}vš 5êu�3ntÛ&�dïŠ&„ÖÈÚM”
Š
aÓ–€ä‘\@˜¦i!-(›ÃÑ ú"
K�F\Qð„'gúvÌ8º�‘—_�.ˆ±ÑŽ=¼t ]
N<œWN–Ó�¸?~Nh0CQ„<(¢ºÈõ1DœcÁ!OuƒíÝ*_ZA�ª©Ã]ý¼#|j©O©·Ù®Dý‡]óâ�áÐô±ùö–ºðÁ
…d×%AÉÐI4œ¹u	—ÆNC…9™I …¢.}i›ý¯¹
ë6t|†guéƒY·/ûuK2la¢ç5½\s%]Äˆ¨Gf{GÅÃ�xH²ã­�ÆÂÜe$„Æ{)Ì#FuiÈ”g-ç	|v¨ÚI¼—h ÷ÎÕ i�¬ö`‡ÄÛ–Ø¯îUß¡d8ˆáX ‹0ì
Ê6O9wMßÇSž\þxO)™ûB2 �Á³Ê¢/ã ¦i|˜>'ûlnÕl­Kå¨�Y©ÕëÑéÂé^“e¿œñdE±Œopu¥ò¤›NÜÂchÉ8Ùrþ·´š¢Ud¥&ke ie€cÂjém±ôb1™Læ¥›æzÚ:·ÃPiò![$¢±
;‰S»ÎÌFðñ·÷XN´¼„EUd¥²ÅR¬Åò¹7ÅrçŸ†ãLUfÕNÙAºþFok¬q?ùÄØuû^ÉÖÐ~èí±œhy‹*«E /4õønQŠo‹%ò_<ljíÛ”¨\Î‚¬h+�}QÛ»µZiœjãMõŽð=–-�E«¥rQ.ý?»…uJ–o«·8Í–fš°ŽJÝµg.mö�ÚUÿ*Hƒ±£Ú»åDËk`Qkµ·Å²Þç5vG6‹þ�XµÌ™cZƒqÿ~Ô+Wœ�|žT;³ÎÂÏ{,'Z^ã“«žkÀò—¿jøtˆÑáãÁI‡»#Üw2R%
    D   Mˆl–Ü4ý('ÜZÔâ€vàZ¸ÓJbÑ¿�þcp8Ù‘÷ƒ ¿Ÿàƒáß_�uÐb&=LyZËcõÀÞ `    M# Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'

RSpec.describe Gql::Mutations::Channel::Email::ValidateConfigurationOutbound, type: :graphql do

  let(:query) do
    <<~QUERY
      mutation channelEmailValidateConfigurationOutbound($outboundConfiguration: ChannelEmailOutboundConfigurationInput!, $emailAddress: String!) {
        channelEmailValidateConfigurationOutbound(outboundConfiguration: $outboundConfiguration, emailAddress: $emailAddress) {
          success
          errors {
            message
            field
          }
        }
      }
    QUERY
  end

  let(:outbound_configuration) do
    {
      adapter:   'smtp',
      host:      'nonexisting.host.local',
      port:      25,
      user:      'some@example.com',
      password:  'password',
      sslVerify: false,
    }
  end

  let(:variables)           { { 'outboundConfiguration' => outbound_configuration, emailAddress: 'some.sender@example.com' } }
  let(:probe_full_response) { nil }
  let(:docker_env)          { false }

  before do
    if docker_env
      allow(ENV).to receive(:[]).and_call_original
      allow(ENV).to receive(:[]).with('ZAMMAD_DOCKER').and_return('true')
    end

    allow(EmailHelper::Probe).to receive(:outbound).and_return(probe_full_response) if probe_full_response
    allow_any_instance_of(Channel::Driver::Smtp).to receive(:deliver).and_raise(Errno::EHOSTUNREACH)
    gql.execute(query, variables: variables)
  end

  context 'when authenticated as admin', authenticated_as: :admin do
    let(:admin) { create(:admin) }

    context 'with successful probe' do
      let(:probe_full_response) { { result: 'ok' } }

      it 'validates configuration data' do
        expect(gql.result.data).to eq({ 'success' => true, 'errors' => nil })
      end

      context 'when outbound adapter is sendmail' do
        let(:outbound_configuration) { { adapter: 'sendmail' } }

        it 'validates configuration data' do
          expect(gql.result.data).to eq({ 'success' => true, 'errors' => nil })
        end

        context 'when running in docker environment' do
          let(:docker_env) { true }

          it 'fails with validation error' do
            expect(gql.result.error_message).to include('Unsupported outbound adapter: "sendmail"')
          end
        end
      end
    end

    context 'with failed probe' do
      it 'returns error messages' do
        expect(gql.result.data).to eq({ 'success' => false, 'errors' => [{ 'field' => 'outbound.host', 'message' => 'There is no route to this host.' }] })
      end
    end
  end

  context 'when authenticated as non-admin', authenticated_as: :agent do
    let(:agent) { create(:agent) }

    it 'fails with authentication error' do
      expect(gql.result.error_type).to eq(Exceptions::Forbidden)
    end
  end

  it_behaves_like 'graphql responds with error if unauthenticated'
end
     OˆÜÛàƒDÏÙÀÞ c    O‹      ÕZß�Ú8~ï_áËÃ½�“ðc9õ`¥[ÝvwµåTU§2‰IÜMìÈ6Pö¯?;Ø¥KÚ4
O��™ÏßÌÄžÄùmr?ž~y¸M?Þ‚‡þ¼½£áçÎÂÉt’tÛ¦áõ�ŒPÊdáz½n¯;mÆ8}„¡Œ£.’O¶}éî;GëÜwÀ	1òUId„Ýêão€- dK)ˆ�í�°kM>£8F>	ö Ø‰cf?WÂíŠÎœùýGÖ�/ª~›š†æéÚZä®#C°B	èÈ�,1\