Skip to content

Commit b16732c

Browse files
committed
Updates enforce notes rubocop rule to add notes to modules that are missing notes
1 parent ade9b54 commit b16732c

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/msf/core/constants.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ module Msf
5555
# Stability traits
5656
#
5757

58+
# Module stability is unknown.
59+
UNKNOWN_STABILITY = 'unknown-stability'
5860
# Module should not crash the service.
5961
CRASH_SAFE = 'crash-safe'
6062
# Module may crash the service, but the service restarts.
@@ -74,6 +76,8 @@ module Msf
7476
# Side-effect traits
7577
#
7678

79+
# Module side effects are unknown.
80+
UNKNOWN_SIDE_EFFECTS = 'unknown-side-effects'
7781
# Modules leaves a payload or a dropper on the target machine.
7882
ARTIFACTS_ON_DISK = 'artifacts-on-disk'
7983
# Module modifies some configuration setting on the target machine.
@@ -95,6 +99,8 @@ module Msf
9599
# Reliability
96100
#
97101

102+
# Module reliability is unknown.
103+
UNKNOWN_RELIABILITY = 'unknown-reliability'
98104
# The module tends to fail to get a session on the first attempt.
99105
FIRST_ATTEMPT_FAIL = 'first-attempt-fail'
100106
# The module is expected to get a shell every time it runs.

lib/rubocop/cop/lint/module_enforce_notes.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module RuboCop
44
module Cop
55
module Lint
66
class ModuleEnforceNotes < Base
7+
extend AutoCorrector
78

89
NO_NOTES_MSG = 'Module is missing the Notes section which must include Stability, Reliability and SideEffects] - https://docs.metasploit.com/docs/development/developing-modules/module-metadata/definition-of-module-reliability-side-effects-and-stability.html'
910
MISSING_KEY_MSG = 'Module is missing %s from the Notes section - https://docs.metasploit.com/docs/development/developing-modules/module-metadata/definition-of-module-reliability-side-effects-and-stability.html'
@@ -36,12 +37,32 @@ def on_def(node)
3637
if notes_present
3738
check_for_required_keys(notes)
3839
else
39-
add_offense(last_key || hash, message: NO_NOTES_MSG)
40+
add_offense(last_key || hash, message: NO_NOTES_MSG) do |corrector|
41+
insert_notes_autocorrect(corrector, hash)
42+
end
4043
end
4144
end
4245

4346
private
4447

48+
def insert_notes_autocorrect(corrector, hash)
49+
last_pair = hash.pairs.last
50+
indent_width = last_pair.loc.expression.column
51+
indent = ' ' * indent_width
52+
corrector.insert_after(last_pair.loc.expression, notes_formatted(indent))
53+
end
54+
55+
def notes_formatted(indent)
56+
<<~EOF.strip
57+
,
58+
#{indent}'Notes' => {
59+
#{indent} 'Reliability' => UNKNOWN_RELIABILITY,
60+
#{indent} 'Stability' => UNKNOWN_STABILITY,
61+
#{indent} 'SideEffects' => UNKNOWN_SIDE_EFFECTS
62+
#{indent}}
63+
EOF
64+
end
65+
4566
def check_for_required_keys(notes)
4667
last_key = nil
4768
keys_present = []

0 commit comments

Comments
 (0)