CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/metasploit/framework/spec/untested_payloads.rb
Views: 1904
1
# @note needs to use explicit nesting. so this file can be loaded directly without loading 'metasploit/framework' which
2
# allows for faster loading of rake tasks.
3
module Metasploit
4
module Framework
5
module Spec
6
module UntestedPayloads
7
# @note `Metasploit::Framework::Spec::UntestedPayloads.define_task` should be run after the normal spec task is
8
# defined.
9
#
10
# Adds action to `spec` tasks so that `rake spec` fails if `log/untested-payloads.log` exists and prints out untested
11
# payloads from that log to stderr.
12
#
13
# # @example Using `Metasploit::Framework::Spec::UntestedPayloads.define_task` with 'payload can be instantiated' shared examples and 'untested payloads' shared context
14
# # Rakefile
15
# require 'metasploit/framework/spec/untested_payloads'
16
#
17
# # defined spec task with rspec-rails
18
# My::Application.load_tasks
19
# # extends spec task to fail when there are untested payloads
20
# Metasploit::Framework::Spec::UntestedPayloads.define_task
21
#
22
# # spec/modules/payloads_spec.rb
23
# require 'spec_helper'
24
#
25
# describe 'modules/payloads' do
26
# modules_pathname = Pathname.new(__FILE__).parent.parent.parent.join('modules')
27
#
28
# include_context 'untested payloads', modules_pathname: modules_pathname
29
#
30
# context 'my/staged/payload/handler' do
31
# it_should_behave_like 'payload can be instantiated',
32
# ancestor_reference_names: [
33
# 'stages/my/payload',
34
# 'stagers/my/payload/handler'
35
# ],
36
# modules_pathname: modules_pathname,
37
# reference_name: 'my/staged/payload/handler'
38
# end
39
# end
40
#
41
# @return [void]
42
def self.define_task
43
Rake::Task.define_task :spec do
44
untested_payloads_pathname = Pathname.new 'log/untested-payloads.log'
45
46
if untested_payloads_pathname.exist?
47
tool_path = 'tools/modules/missing_payload_tests.rb'
48
49
$stderr.puts "Untested payload detected. Running `#{tool_path}` to see contexts to add to " \
50
"`spec/modules/payloads_spec.rb` to test those payload ancestor reference names."
51
52
system(tool_path)
53
54
exit 1
55
end
56
end
57
end
58
end
59
end
60
end
61
end
62
63