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/acceptance/session.rb
Views: 11780
module Acceptance::Session1# @return [Symbol] The current platform2def self.current_platform3host_os = RbConfig::CONFIG['host_os']4case host_os5when /darwin/6:osx7when /mingw/8:windows9when /linux/10:linux11else12raise "unknown host_os #{host_os.inspect}"13end14end1516# Allows restricting the tests of a specific Meterpreter's test suite with the METERPRETER environment variable17# @return [TrueClass, FalseClass] True if the given Meterpreter should be run, false otherwise.18def self.run_meterpreter?(meterpreter_config)19return true if ENV['SESSION'].blank?2021name = meterpreter_config[:name].to_s22ENV['SESSION'].include?(name)23end2425# Allows restricting the tests of a specific Meterpreter's test suite with the METERPRETER environment variable26# @return [TrueClass, FalseClass] True if the given Meterpreter should be run, false otherwise.27def self.run_meterpreter_module_test?(module_test)28return true if ENV['SESSION_MODULE_TEST'].blank?2930ENV['SESSION_MODULE_TEST'].include?(module_test)31end3233# Allows restricting the tests of a specific session's test suite with the SESSION environment variable34# @return [TrueClass, FalseClass] True if the given session should be run, false otherwise.35def self.run_session?(session_config)36return true if ENV['SESSION'].blank?3738name = session_config[:name].to_s39ENV['SESSION'].include?("command_shell/#{name}")40end4142# Allows restricting the tests of a specific session's test suite with the SESSION environment variable43# @return [TrueClass, FalseClass] True if the given session should be run, false otherwise.44def self.run_session_module_test?(module_test)45return true if ENV['SESSION_MODULE_TEST'].blank?4647ENV['SESSION_MODULE_TEST'].include?(module_test)48end4950# @param [String] string A console string with ANSI escape codes present51# @return [String] A string with the ANSI escape codes removed52def self.uncolorize(string)53string.gsub(/\e\[\d+m/, '')54end5556# @param [Hash] payload_config57# @return [Boolean]58def self.supported_platform?(payload_config)59payload_config[:platforms].include?(current_platform)60end6162# @param [Hash] module_test63# @return [Boolean]64def self.skipped_module_test?(module_test, test_environment)65current_platform_requirements = Array(module_test[:platforms].find { |platform| Array(platform)[0] == current_platform })[1] || {}66module_test.fetch(:skip, false) ||67self.eval_predicate(current_platform_requirements.fetch(:skip, false), test_environment)68end6970# @param [Hash] payload_config71# @return [String] The human readable name for the given payload configuration72def self.human_name_for_payload(payload_config)73is_stageless = payload_config[:name].include?('_reverse_tcp')74is_staged = payload_config[:name].include?('/reverse_tcp')7576details = []77details << 'stageless' if is_stageless78details << 'staged' if is_staged79details << payload_config[:name]8081details.join(' ')82end8384# @param [Object] hash A hash of key => hash85# @return [Object] Returns a new hash with the 'key' merged into hash value and all payloads86def self.with_session_name_merged(hash)87hash.each_with_object({}) do |(name, config), acc|88acc[name] = config.merge({ name: name })89end90end9192# Evaluates a simple predicate; Similar to Msf::OptCondition.eval_condition93# @param [TrueClass,FalseClass,Array] value94# @param [Hash] environment95# @return [TrueClass, FalseClass] True or false96def self.eval_predicate(value, environment)97case value98when Array99left_operand, operator, right_operand = value100# Map values such as `:session_name` to the runtime value101left_operand = environment[left_operand] if environment.key?(left_operand)102right_operand = environment[right_operand] if environment.key?(right_operand)103104case operator.to_sym105when :==106evaluate_predicate(left_operand, environment) == evaluate_predicate(right_operand, environment)107when :!=108evaluate_predicate(left_operand, environment) != evaluate_predicate(right_operand, environment)109when :or110evaluate_predicate(left_operand, environment) || evaluate_predicate(right_operand, environment)111else112raise "unexpected operator #{operator.inspect}"113end114else115value116end117end118end119120121