Skip to content

Commit

Permalink
Add error handling when one of the workers cannot be loaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Jun 8, 2024
1 parent 1269e33 commit a539758
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/ronin/recon/cli/commands/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ def load_workers
if (level = options[:intensity])
@workers = @workers.intensity(level)
end
rescue Ronin::Recon::ClassNotFound => error
print_error(error.message)
exit(1)
end

#
Expand Down
26 changes: 26 additions & 0 deletions spec/cli/commands/run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,32 @@
expect(subject.workers.map(&:intensity)).to all(eq(intensity))
end
end

context "when one of the enabled workers cannot be found" do
let(:worker) { 'does/not/exist' }
before { subject.enable_workers << worker }

it "must print an error and exit with 1" do
expect(subject).to receive(:print_error).with("could not find file for #{worker.inspect}")
expect(subject).to receive(:exit).with(1)

subject.load_config
subject.load_workers
end
end

context "when one of the enabled worker files does not exist" do
let(:worker_file) { 'does/not/exist' }
before { subject.worker_files << worker_file }

it "must print an error and exit with 1" do
expect(subject).to receive(:print_error).with("no such file or directory: #{File.expand_path(worker_file).inspect}")
expect(subject).to receive(:exit).with(1)

subject.load_config
subject.load_workers
end
end
end

describe "#parse_value" do
Expand Down

0 comments on commit a539758

Please sign in to comment.