Skip to content

Commit

Permalink
Merge pull request #1301 from OSC/fix-rubocop
Browse files Browse the repository at this point in the history
move rubocop file to the dashboard and fix 1 file's warnings
  • Loading branch information
Oglopf authored Jul 23, 2021
2 parents 4d890ca + 075b6be commit 1930523
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
File renamed without changes.
17 changes: 9 additions & 8 deletions apps/dashboard/app/models/allowlist_policy.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'pathname'

# AllowlistPolicy allows or denies access to directories based off of a configuration.
class AllowlistPolicy
attr_reader :allowlist

Expand All @@ -16,7 +17,7 @@ def initialize(allowlist)
# @raises ArgumentError if any allowlist path or permitted? argument
# has the form ~user/some/path where user doesn't exist
def permitted?(path)
allowlist.blank? || allowlist.any?{ |parent| child?(Pathname.new(parent), real_expanded_path(path)) }
allowlist.blank? || allowlist.any? { |parent| child?(Pathname.new(parent), real_expanded_path(path)) }
end

# @raises AllowlistPolicy::Forbidden if path is not permitted by allowlist
Expand All @@ -30,12 +31,12 @@ def validate!(path)

# call realpath to ensure symlinks are handled
def real_expanded_path(path)
# call realpath to ensure symlinks are resolved
Pathname.new(path).expand_path.realpath
rescue SystemCallError
# path doesn't exist, so we just get absolute version then
Pathname.new(path).expand_path
end
# call realpath to ensure symlinks are resolved
Pathname.new(path).expand_path.realpath
rescue SystemCallError
# path doesn't exist, so we just get absolute version then
Pathname.new(path).expand_path
end

# Determine if child is a subpath of parent
#
Expand All @@ -46,7 +47,7 @@ def real_expanded_path(path)
# @param child [Pathname]
# @return Boolean
def child?(parent, child)
! child.expand_path.relative_path_from(
!child.expand_path.relative_path_from(
parent.expand_path
).each_filename.to_a.include?(
'..'
Expand Down

0 comments on commit 1930523

Please sign in to comment.