Skip to content

Commit

Permalink
Project validations (#3780)
Browse files Browse the repository at this point in the history
* dont need to mkpath here

* ensure template is a real directory and is readable
  • Loading branch information
johrstrom authored Sep 11, 2024
1 parent f97dafd commit 11d1179
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 1 addition & 3 deletions apps/dashboard/app/models/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class ClusterNotFound < StandardError; end

class << self
def scripts_dir(project_dir)
Pathname.new("#{project_dir}/.ondemand/scripts").tap do |path|
path.mkpath unless path.exist?
end
Pathname.new("#{project_dir}/.ondemand/scripts")
end

def find(id, project_dir)
Expand Down
8 changes: 5 additions & 3 deletions apps/dashboard/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,10 @@ def project_directory_invalid

def project_template_invalid
# This validation is to prevent the template directory being manipulated in the form.
if !template.blank? && Project.templates.map { |template| template.directory.to_s }.exclude?(template.to_s)
errors.add(:template, :invalid)
end
return if template.blank?

template_path = Pathname.new(template)
errors.add(:template, :invalid) if Project.templates.map { |t| t.directory.to_s }.exclude?(template.to_s)
errors.add(:template, :invalid) unless template_path.exist? && template_path.readable?
end
end
4 changes: 3 additions & 1 deletion apps/dashboard/test/models/projects_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ class ProjectsTest < ActiveSupport::TestCase
template: '/invalid/template' })

assert_not project.save
assert_equal 2, project.errors.size
assert_equal 3, project.errors.size
assert_not_equal invalid_icon, project.icon
assert_not project.errors[:directory].empty?
assert_not project.errors[:template].empty?
assert_equal(1, project.errors[:directory].size)
assert_equal(2, project.errors[:template].size)
end
end

Expand Down

0 comments on commit 11d1179

Please sign in to comment.