Class: RuboCop::Cop::Chef::ChefCorrectness::InsecureCookbookURL

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/chef/correctness/insecure_cookbook_url.rb

Overview

Use secure Github and Gitlab URLs for source_url and issues_url

Examples:


# bad
source_url 'http://github.com/something/something'
source_url 'http://www.github.com/something/something'
source_url 'http://www.gitlab.com/something/something'
source_url 'http://gitlab.com/something/something'

# good
source_url 'http://github.com/something/something'
source_url 'http://gitlab.com/something/something'

Constant Summary collapse

MSG =
'Insecure http Github or Gitlab URLs for metadata source_url/issues_url fields'.freeze

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



53
54
55
56
57
# File 'lib/rubocop/cop/chef/correctness/insecure_cookbook_url.rb', line 53

def autocorrect(node)
  lambda do |corrector|
    corrector.replace(node.loc.expression, node.source.gsub(%r{http://(www.)*}, 'https://'))
  end
end

#insecure_url?(url) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/rubocop/cop/chef/correctness/insecure_cookbook_url.rb', line 42

def insecure_url?(url)
  # https://rubular.com/r/dS6L6bQZvwWxWq
  url.match?(%r{http://(www.)*git(hub|lab)})
end

#on_send(node) ⇒ Object



47
48
49
50
51
# File 'lib/rubocop/cop/chef/correctness/insecure_cookbook_url.rb', line 47

def on_send(node)
  insecure_cb_url?(node) do
    add_offense(node, location: :expression, message: MSG, severity: :refactor)
  end
end