package_spec.rb 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Package, type: :model do
  4. let(:package_zpm_files_json) do
  5. <<-JSON
  6. [
  7. {
  8. "permission": "644",
  9. "location": "example.rb",
  10. "content": "YWJjw6TDtsO8w58="
  11. },
  12. {
  13. "permission": "644",
  14. "location": "app/controllers/test_controller.rb",
  15. "content": "YWJjw6TDtsO8w58="
  16. }
  17. ]
  18. JSON
  19. end
  20. let(:package_zpm_json) do
  21. <<-JSON
  22. {
  23. "name": "UnitTestSample",
  24. "version": "1.0.1",
  25. "vendor": "Zammad Foundation",
  26. "license": "ABC",
  27. "url": "https://zammad.org/",
  28. "description": [
  29. {
  30. "language": "en",
  31. "text": "some description"
  32. }
  33. ],
  34. "files": #{package_zpm_files_json}
  35. }
  36. JSON
  37. end
  38. context 'with different file locations' do
  39. context 'with correct file locations' do
  40. it 'installation should work' do
  41. expect(described_class.install(string: package_zpm_json)).to be_truthy
  42. end
  43. end
  44. shared_examples 'check not allowed file location' do |file_location|
  45. let(:package_zpm_files_json) do
  46. <<-JSON
  47. [
  48. {
  49. "permission": "644",
  50. "location": "example.rb",
  51. "content": "YWJjw6TDtsO8w58="
  52. },
  53. {
  54. "permission": "644",
  55. "location": "#{file_location}",
  56. "content": "YWJjw6TDtsO8w58="
  57. }
  58. ]
  59. JSON
  60. end
  61. it 'installation should raise a error and package/store should not be present, because of not allowed file location' do
  62. expect { described_class.install(string: package_zpm_json) }
  63. .to raise_error(RuntimeError)
  64. .and change(described_class, :count).by(0)
  65. .and change(Store, :count).by(0)
  66. end
  67. end
  68. context "with not allowed file location part: '..'" do
  69. include_examples 'check not allowed file location', '../../../../../tmp/test_controller.rb'
  70. end
  71. context "with not allowed file location part: '%2e%2e'" do
  72. include_examples 'check not allowed file location', '%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/tmp/test_controller.rb'
  73. end
  74. end
  75. end