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/tools/jsobfu_spec.rb
Views: 11768
require 'spec_helper'12load Metasploit::Framework.root.join('tools/exploit/jsobfu.rb').to_path34require 'stringio'56RSpec.describe Jsobfu do78let(:fname) {9'test.js'10}1112let(:js) {13%Q|alert("test");|14}1516describe Jsobfu::Driver do1718subject do19Jsobfu::Driver.new20end2122describe '#run' do23let(:default_opts) {24{ :input => fname, :iteration => 1 }25}2627before(:example) do28allow(Jsobfu::OptsConsole).to receive(:parse).with(any_args).and_return(default_opts)29allow(File).to receive(:open).with(fname, 'rb').and_yield(StringIO.new(js))30@out = $stdout31$stdout = StringIO.new32$stdout.string = ''33end3435after(:example) do36$stdout = @out37end3839context 'when a javascript file is given' do40it 'returns an String' do41subject.run42expect($stdout.string).to be_a(String)43end4445it 'returns a non empty String' do46subject.run47expect($stdout.string).not_to be_empty48end4950it 'returns an String different than the original' do51subject.run52expect($stdout.string).not_to eq(js)53end54end55end56end575859describe Jsobfu::OptsConsole do60subject do61Jsobfu::OptsConsole62end6364context 'when no options are given' do65it 'raises OptionParser::MissingArgument' do66expect{subject.parse([])}.to raise_error(OptionParser::MissingArgument)67end68end6970context 'when -t isn\'t a number' do71it 'raises OptionParser::MissingArgument' do72args = "-i #{fname} -t NaN".split73expect{subject.parse(args)}.to raise_error(OptionParser::InvalidOption)74end75end76end7778end798081