folder_spec.rb 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'viewpoint' # Only load this gem when it is really used.
  4. #
  5. # DEPRECATION WARNING
  6. #
  7. # Microsoft announced in July 2018 that Exchange Web Services (EWS) API will not receive any feature updates. This
  8. # effectively freezes the structure of expected responses that are mocked in this test via VCR cassettes.
  9. #
  10. # https://techcommunity.microsoft.com/t5/exchange-team-blog/upcoming-changes-to-exchange-web-services-ews-api-for-office-365/ba-p/608055
  11. #
  12. # Furthermore, in September 2022, Microsoft also announced that they will start to turn off basic auth for EWS
  13. # protocol in Exchange Online. As of this writing, it's not possible to recreate the test responses to EWS API used
  14. # below without an on-premise system to serve them.
  15. #
  16. # https://techcommunity.microsoft.com/t5/exchange-team-blog/basic-authentication-deprecation-in-exchange-online-september/ba-p/3609437
  17. RSpec.describe Import::Exchange::Folder, :integration do
  18. # see https://github.com/zammad/zammad/issues/2152
  19. describe '#display_path (#2152)', :use_vcr do
  20. subject(:folder) { described_class.new(ews_connection) }
  21. let(:ews_connection) { Viewpoint::EWSClient.new(endpoint, user, pass) }
  22. let(:endpoint) { 'https://exchange.example.com/EWS/Exchange.asmx' }
  23. let(:user) { 'user@example.com' }
  24. let(:pass) { 'password' }
  25. let(:grandchild_of_root) { ews_connection.get_folder_by_name('Inbox') }
  26. let(:child_of_root) { ews_connection.get_folder(grandchild_of_root.parent_folder_id) }
  27. before do
  28. if VCR.configuration.allow_http_connections_when_no_cassette?
  29. skip 'This test example requires a VCR cassette to work, and they are disabled in the current environment.'
  30. end
  31. end
  32. context 'when server returns valid UTF-8' do
  33. context 'and target folder is in root directory' do
  34. it 'returns the display name of the folder' do
  35. expect(folder.display_path(child_of_root))
  36. .to eq('Top of Information Store')
  37. end
  38. end
  39. context 'and target folder is in subfolder of root' do
  40. it 'returns the full path from root to target' do
  41. expect(folder.display_path(grandchild_of_root))
  42. .to eq('Top of Information Store -> Inbox')
  43. end
  44. end
  45. context 'and walking up directory tree raises EwsError' do
  46. it 'returns the partial path from error to target folder' do
  47. allow(folder)
  48. .to receive(:id_folder_map).with(any_args).and_raise(Viewpoint::EWS::EwsError)
  49. expect(folder.display_path(grandchild_of_root))
  50. .to eq('Inbox')
  51. end
  52. end
  53. end
  54. context 'when server returns invalid UTF-8' do
  55. context 'and target folder is in root directory' do
  56. it 'returns the display name of the folder in valid UTF-8' do
  57. allow(child_of_root)
  58. .to receive(:display_name).and_return('你好'.b)
  59. expect { folder.display_path(child_of_root).to_json }.not_to raise_error
  60. end
  61. end
  62. context 'and target folder is in subfolder of root' do
  63. it 'returns the full path from root to target in valid UTF-8' do
  64. allow(grandchild_of_root)
  65. .to receive(:display_name).and_return('你好'.b)
  66. expect { folder.display_path(grandchild_of_root).to_json }.not_to raise_error
  67. end
  68. end
  69. context 'and walking up directory tree raises EwsError' do
  70. it 'returns the partial path from error to target folder in valid UTF-8' do
  71. allow(grandchild_of_root)
  72. .to receive(:display_name).and_return('你好'.b)
  73. allow(folder)
  74. .to receive(:id_folder_map).with(any_args).and_raise(Viewpoint::EWS::EwsError)
  75. expect { folder.display_path(grandchild_of_root).to_json }.not_to raise_error
  76. end
  77. end
  78. end
  79. end
  80. end