Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/support/shared/contexts/untested_payloads.rb
Views: 11784
# Use along with `it_should_behave_like 'payload can be instantiated'` to detect if a payload under `:modules_pathname`1# was not tested. If any payloads are untested, an error will be written to stderr and the names of untested payloads2# will be logged to `log/untested-payloads.log`. This log is reset for run of context, so if there were previously3# untested payloads and there aren't anymore, then `log/untested-payloads.log` will be deleted. Can be used with4# {Metasploit::Framework::Spec::UntestedPayloads.define_task} so that the `spec` task fails if there are untested5# payloads.6#7# @example Using 'untested payloads' with `Metasploit::Framework::Spec::UntestedPayloads.define_task` and 'payloads can be instantiated' shared examples8# # Rakefile9# require 'metasploit/framework/spec/untested_payloads'10#11# # defined spec task with rspec-rails12# My::Application.load_tasks13# # extends spec task to fail when there are untested payloads14# Metasploit::Framework::Spec::UntestedPayloads.define_task15#16# # spec/modules/payloads_spec.rb17# require 'spec_helper'18#19# describe 'modules/payloads' do20# modules_pathname = Pathname.new(__FILE__).parent.parent.parent.join('modules')21#22# include_context 'untested payloads', modules_pathname: modules_pathname23#24# context 'my/staged/payload/handler' do25# it_should_behave_like 'payload can be instantiated',26# ancestor_reference_names: [27# 'stages/my/payload',28# 'stagers/my/payload/handler',29# modules_pathname: modules_pathname,30# reference_name: 'my/staged/payload/handler'31# ]32# end33# end34#35# @param options [Hash{Symbol => Pathname}]36# @option options [Pathname] :modules_pathname Pathname of `modules` directory underwhich payloads are defined on the37# file system.38RSpec.shared_context 'untested payloads' do |options={}|39options.assert_valid_keys(:modules_pathname)4041modules_pathname = options.fetch(:modules_pathname)4243before(:context) do44@expected_ancestor_reference_name_set = Set.new45@actual_ancestor_reference_name_set = Set.new4647payloads_pathname = modules_pathname.join('payloads')4849Dir.glob(payloads_pathname.join('**', '*.rb')) do |expected_ancestor_path|50expected_ancestor_pathname = Pathname.new(expected_ancestor_path)51expected_ancestor_reference_pathname = expected_ancestor_pathname.relative_path_from(payloads_pathname)52expected_ancestor_reference_name = expected_ancestor_reference_pathname.to_path.gsub(/.rb$/, '')5354@expected_ancestor_reference_name_set.add(expected_ancestor_reference_name)55end56end5758after(:context) do59missing_ancestor_reference_name_set = @expected_ancestor_reference_name_set - @actual_ancestor_reference_name_set6061expect(missing_ancestor_reference_name_set).to be_empty, "Some payloads are untested: #{missing_ancestor_reference_name_set.join(', ')}. Please update `modules/payloads_spec.rb` with the payload definitions"62end63end646566