Class: RuboCop::Cop::Chef::Sharing::InsecureCookbookURL

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/chef/sharing/insecure_cookbook_url.rb

Overview

Use secure Github and Gitlab URLs for source_url and issues_url

Examples:


### incorrect
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'

### correct
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'
RESTRICT_ON_SEND =
[:source_url, :issues_url].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#insecure_url?(url) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/rubocop/cop/chef/sharing/insecure_cookbook_url.rb', line 46

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

#on_send(node) ⇒ Object



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

def on_send(node)
  insecure_cb_url?(node) do
    add_offense(node, severity: :refactor) do |corrector|
      corrector.replace(node, node.source.gsub(%r{http://(www.)*}, 'https://'))
    end
  end
end