storage_provider_spec.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Setting::Validation::StorageProvider do
  4. let(:setting_name) { 'storage_provider' }
  5. context 'with blank settings' do
  6. it 'does not raise an error' do
  7. expect { Setting.set(setting_name, {}) }.not_to raise_error
  8. end
  9. end
  10. context 'with using DB as storage provider' do
  11. it 'does not raise an error' do
  12. expect { Setting.set(setting_name, 'DB') }.not_to raise_error
  13. end
  14. end
  15. context 'with using S3 as storage provider' do
  16. before do
  17. ENV.delete('S3_URL') if ENV['CI']
  18. Store::Provider::S3.reset
  19. end
  20. context 'when no config is present' do
  21. it 'does raise an error' do
  22. expect { Setting.set(setting_name, 'S3') }.to raise_error(ActiveRecord::RecordInvalid, 'Validation failed: Simple Storage Service not reachable.')
  23. end
  24. end
  25. context 'when endpoint is not reachable' do
  26. before do
  27. ENV['S3_URL'] = 'https://s3.eu-central-1.zammad.org/zammad-storage-bucket?region=eu-central-1&force_path_style=true'
  28. end
  29. it 'does raise an error' do
  30. expect { Setting.set(setting_name, 'S3') }.to raise_error(ActiveRecord::RecordInvalid, 'Validation failed: Simple Storage Service not reachable.')
  31. end
  32. end
  33. context 'with invalid S3_URL environment variable' do
  34. before do
  35. ENV['S3_URL'] = 'https://key:secret@s3.eu-central-1.amazonaws.com/zammad-storage-bucket'
  36. end
  37. it 'does raise an error' do
  38. expect { Setting.set(setting_name, 'S3') }.to raise_error(ActiveRecord::RecordInvalid, 'Validation failed: Simple Storage Service not reachable.')
  39. end
  40. end
  41. end
  42. end