cookstyle 7.12.2 → 7.12.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68835852d8021cee74896aa171d78ca5b540fca9fdee42632719d867910c107e
4
- data.tar.gz: f71d3a8f4bc874dd86f81b0b01d4caa929ba62c2bf2222ca66a3e726eb398611
3
+ metadata.gz: d6b4ac76f05be60a51f678d80bb34d68d4396560b2887214a0a3dd7ac6cd038f
4
+ data.tar.gz: 74a95cd52549baf8086aa14e3579370d917b8db198deafdc6ced6c28071b3956
5
5
  SHA512:
6
- metadata.gz: a8ce79400b3866f0ac4b5b94ed0eb39da7a7b19dcd6dcf5fb0e6347affc31a70c0d56d8e2d671b776cea74465b6c715a20d9d88b3941291655ed01833c38796b
7
- data.tar.gz: 1d324b44b1ce454718685eb5339e14d4063072b2d66dec6707091a871aa1fbef6f8eb4a13aeee683552b4b6d54f0821b5fa82493b4bde31d62aac48e9577a396
6
+ metadata.gz: 105f70150e5c66d01b6e157b7f07660a3bf4c755dbb7eed18709fca10b911b54c14fbfff2a2cd41d04ce11b649525b742a469f5f3631ee6c13eaa9f7fa1dc90b
7
+ data.tar.gz: fb7ffae6e230fa1f26f68626cd9adf4f8d265aee2feeec5fed68c963fde79bbce1022fa973e6bc2cccfbb07e396e4784d81ba0747778915eb3c288ea7e20f19b
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Cookstyle
3
- VERSION = "7.12.2" # rubocop: disable Style/StringLiterals
3
+ VERSION = "7.12.3" # rubocop: disable Style/StringLiterals
4
4
  RUBOCOP_VERSION = '1.14.0'
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
- # Copyright:: 2020, Chef Software, Inc.
3
+ # Copyright:: 2020-2021, Chef Software, Inc.
4
4
  # Author:: Tim Smith (<tsmith@chef.io>)
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -47,24 +47,43 @@ module RuboCop
47
47
 
48
48
  MSG = 'Chef Infra Client 15.0 and later includes a windows_uac resource that should be used to set Windows UAC values instead of setting registry keys directly.'
49
49
  RESTRICT_ON_SEND = [:registry_key].freeze
50
+ VALID_VALUES = %w(EnableLUA ValidateAdminCodeSignatures PromptOnSecureDesktop ConsentPromptBehaviorAdmin ConsentPromptBehaviorUser EnableInstallerDetection).freeze
50
51
 
51
- # non block execute resources
52
- def on_send(node)
53
- return unless node&.arguments.first&.source.match?(/(HKLM|HKEY_LOCAL_MACHINE)\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System/i) &&
54
- node.parent&.method_name != :describe
55
-
56
- # use source instead of .value in case there's string interpolation which adds a complex dstr type
57
- # with a nested string and a begin. Source allows us to avoid a lot of defensive programming here
52
+ # block registry_key resources
53
+ def on_block(node)
54
+ return unless node.method_name == :registry_key
55
+ return unless correct_key?(node)
56
+ return unless uac_supported_values?(node)
58
57
  add_offense(node, message: MSG, severity: :refactor)
59
58
  end
60
59
 
61
- # block execute resources
62
- def on_block(node)
60
+ # make sure the values passed are all the ones in the uac resource
61
+ # this key has other values we don't support in the windows_uac resource
62
+ def uac_supported_values?(node)
63
+ match_property_in_resource?(:registry_key, 'values', node) do |val_prop|
64
+ return false unless val_prop&.arguments[0].array_type? # make sure values isn't being passed a variable or method
65
+ val_prop.arguments[0].each_value do |array|
66
+ array.each_pair do |key, value|
67
+ if key == s(:sym, :name)
68
+ return false unless value.str_type? # make sure it isn't being a variable or method that we can't parse
69
+ return false unless VALID_VALUES.include?(value.value)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ true
75
+ end
76
+
77
+ # make sure the registry_key resource is running against the correct key
78
+ # check the block name and the key property (registry_key's name property)
79
+ def correct_key?(node)
80
+ return true if node.send_node.arguments.first.source.match?(/(HKLM|HKEY_LOCAL_MACHINE)\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System/i)
81
+
63
82
  match_property_in_resource?(:registry_key, 'key', node) do |key_prop|
64
83
  property_data = method_arg_ast_to_string(key_prop)
65
- return unless property_data && property_data.match?(/(HKLM|HKEY_LOCAL_MACHINE)\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System/i)
66
- add_offense(node, message: MSG, severity: :refactor)
84
+ return true if property_data && property_data.match?(/(HKLM|HKEY_LOCAL_MACHINE)\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System/i)
67
85
  end
86
+ false
68
87
  end
69
88
  end
70
89
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cookstyle
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.12.2
4
+ version: 7.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thom May
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-05-10 00:00:00.000000000 Z
12
+ date: 2021-05-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubocop