Skip to content

Commit c9bf3a2

Browse files
authored
Fix bug where mkdir_p failed due to incorrect permissions. (#1688)
1 parent 691cb30 commit c9bf3a2

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

Gemfile.lock

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,6 @@ DEPENDENCIES
303303
jbuilder (~> 2)
304304
m (~> 1)
305305
minitest (= 5.6.0)
306-
net-imap
307-
net-pop
308-
net-smtp
309306
pry (~> 0.13)
310307
puma (~> 5)
311308
rails (~> 7.0.0)

app/controllers/view_components_system_test_controller.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# frozen_string_literal: true
22

33
class ViewComponentsSystemTestController < ActionController::Base # :nodoc:
4-
TEMP_DIR = FileUtils.mkdir_p("./tmp/view_components/").first
5-
64
before_action :validate_test_env
75
before_action :validate_file_path
86

7+
def self.temp_dir
8+
@_tmpdir ||= FileUtils.mkdir_p("./tmp/view_components/").first
9+
end
10+
911
def system_test_entrypoint
1012
render file: @path
1113
end
@@ -19,7 +21,7 @@ def validate_test_env
1921
# Ensure that the file path is valid and doesn't target files outside
2022
# the expected directory (e.g. via a path traversal or symlink attack)
2123
def validate_file_path
22-
base_path = ::File.realpath(TEMP_DIR)
24+
base_path = ::File.realpath(self.class.temp_dir)
2325
@path = ::File.realpath(params.permit(:file)[:file], base_path)
2426
unless @path.start_with?(base_path)
2527
raise ArgumentError, "Invalid file path"

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ nav_order: 5
1010

1111
## main
1212

13+
* Fix bug where `mkdir_p` failed due to incorrect permissions.
14+
15+
*Joel Hawksley*
16+
1317
* Check for inline `erb_template` calls when deciding whether or not to compile a component's superclass.
1418

1519
*Justin Kenyon*

lib/view_component/system_test_helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module SystemTestHelpers
1212
def with_rendered_component_path(fragment, layout: false, &block)
1313
file = Tempfile.new(
1414
["rendered_#{fragment.class.name}", ".html"],
15-
ViewComponentsSystemTestController::TEMP_DIR
15+
ViewComponentsSystemTestController.temp_dir
1616
)
1717
begin
1818
file.write(vc_test_controller.render_to_string(html: fragment.to_html.html_safe, layout: layout))

0 commit comments

Comments
 (0)