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/lib/rex/proto/pjl/client_spec.rb
Views: 11789
require 'spec_helper'1require 'msfenv'23RSpec.describe Rex::Proto::PJL::Client do4context "methods" do5let(:default_response) do6'OK'7end89let(:sock) do10s = double("sock")11allow(s).to receive(:put).with(an_instance_of(String))12allow(s).to receive(:get).and_return(default_response)13s14end1516let(:cli) do17Rex::Proto::PJL::Client.new(sock)18end1920context "#initialize" do21it "should initialize a 'sock' ivar" do22expect(cli.instance_variable_get(:@sock).class).to eq(RSpec::Mocks::Double)23end24end2526context "#begin_job" do27it "should send a PJL start request without an error" do28expect { cli.begin_job }.to_not raise_error29end30end3132context "#end_job" do33it "should send a PJL end request without an error" do34expect { cli.end_job }.to_not raise_error35end36end3738context "#info" do39it "should raise an exception for not having a category" do40expect { cli.info(nil) }.to raise_error(ArgumentError)41end4243it "should receive a response for an INFO request" do44expect(cli.info(:id)).to eq(default_response)45end46end4748context "#info_id" do49it "should return the version information" do50fake_version = '"1337"'51allow(cli).to receive(:info).with(an_instance_of(Symbol)).and_return(fake_version)52expect(cli.info_id).to eq('1337')53end54end5556context "#info_variables" do57it "should return the environment variables" do58fake_env_vars = "#{Rex::Proto::PJL::Info::VARIABLES}\r\nPASSWORD=DISABLED\f"59allow(cli).to receive(:info).with(an_instance_of(Symbol)).and_return(fake_env_vars)60expect(cli.info_variables).to eq('PASSWORD=DISABLED')61end62end6364context "#info_filesys" do65it "should return the volumes" do66fake_volumes = "[1 TABLE]\r\nDIR\f"67allow(cli).to receive(:info).with(an_instance_of(Symbol)).and_return(fake_volumes)68expect(cli.info_filesys).to eq('DIR')69end70end7172context "#get_rdymsg" do73it "should return a READY message" do74fake_ready_message = 'DISPLAY="RES"'75allow(cli).to receive(:info).with(an_instance_of(Symbol)).and_return(fake_ready_message)76expect(cli.get_rdymsg).to eq('RES')77end78end7980context "#set_rdymsg" do81it "should send a READY message without an error" do82expect { cli.set_rdymsg("") }.to_not raise_error83end84end8586context "#fsinit" do87it "should raise an exception due to an invalid volume" do88expect { cli.fsinit("BAD") }.to raise_error(ArgumentError)89end9091it "should send a FS INIT message without an error" do92expect { cli.fsinit("1:") }.to_not raise_error93end94end9596context "#fsquery" do97it "should raise an exception due to an invalid path" do98expect { cli.fsquery("BAD") }.to raise_error(ArgumentError)99end100101it "should query a file" do102response = "TYPE=FILE SIZE=1337\r\n\f"103tmp_sock = double("sock")104allow(tmp_sock).to receive(:put).with(an_instance_of(String))105allow(tmp_sock).to receive(:get).with(Rex::Proto::PJL::DEFAULT_TIMEOUT).and_return(response)106tmp_cli = Rex::Proto::PJL::Client.new(tmp_sock)107expect(tmp_cli.fsquery("1:")).to eq(true)108end109end110111context "#fsdirlist" do112it "should raise an exception due to an invalid path" do113expect { cli.fsdirlist("BAD") }.to raise_error(ArgumentError)114end115116it "should return a LIST directory response" do117response = "ENTRY=1\r\nDIR\f"118tmp_sock = double("sock")119allow(tmp_sock).to receive(:put).with(an_instance_of(String))120allow(tmp_sock).to receive(:get).with(Rex::Proto::PJL::DEFAULT_TIMEOUT).and_return(response)121tmp_cli = Rex::Proto::PJL::Client.new(tmp_sock)122expect(tmp_cli.fsdirlist("1:")).to eq('DIR')123end124end125126context "#fsupload" do127it "should raise an exception due to an invalid path" do128expect { cli.fsupload("BAD") }.to raise_error(ArgumentError)129end130131it "should return a file" do132response = "SIZE=1337\r\nFILE\f"133tmp_sock = double("sock")134allow(tmp_sock).to receive(:put).with(an_instance_of(String))135allow(tmp_sock).to receive(:get).with(Rex::Proto::PJL::DEFAULT_TIMEOUT).and_return(response)136tmp_cli = Rex::Proto::PJL::Client.new(tmp_sock)137expect(tmp_cli.fsupload("1:")).to eq('FILE')138end139end140141context "#fsdownload" do142it "should raise an exception due to an invalid path" do143expect { cli.fsdownload("/dev/null", "BAD") }.to raise_error(ArgumentError)144end145146it "should upload a file" do147response = "TYPE=FILE SIZE=1337\r\n\f"148tmp_sock = double("sock")149allow(tmp_sock).to receive(:put).with(an_instance_of(String))150allow(tmp_sock).to receive(:get).with(Rex::Proto::PJL::DEFAULT_TIMEOUT).and_return(response)151tmp_cli = Rex::Proto::PJL::Client.new(tmp_sock)152expect(tmp_cli.fsdownload("/dev/null", "1:")).to eq(true)153end154155it "should upload data from a string" do156response = "TYPE=FILE SIZE=1337\r\n\f"157tmp_sock = double("sock")158allow(tmp_sock).to receive(:put).with(an_instance_of(String))159allow(tmp_sock).to receive(:get).with(Rex::Proto::PJL::DEFAULT_TIMEOUT).and_return(response)160tmp_cli = Rex::Proto::PJL::Client.new(tmp_sock)161expect(tmp_cli.fsdownload("Miscellaneous Data", "1:root/.workspace/.garbage.", is_file: false)).to eq(true)162end163end164165context "#fsdelete" do166it "should raise an exception due to an invalid path" do167expect { cli.fsdelete("BAD") }.to raise_error(ArgumentError)168end169170it "should delete a file" do171response = "FILEERROR=3\r\n\f"172tmp_sock = double("sock")173allow(tmp_sock).to receive(:put).with(an_instance_of(String))174allow(tmp_sock).to receive(:get).with(Rex::Proto::PJL::DEFAULT_TIMEOUT).and_return(response)175tmp_cli = Rex::Proto::PJL::Client.new(tmp_sock)176expect(tmp_cli.fsdelete("1:")).to eq(true)177end178end179end180end181182183