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/parser/winscp_spec.rb
Views: 11655
1INI_SECURITY = "[Configuration\\Security]\nUseMasterPassword=1\nMasterPasswordVerifier=\n"23USERNAME = 'username'4HOST = 'server.feralhosting.com'5PASSWORD='A35C7659654B2AB83C292F392E323D31392F392E2A392E723A392E3D3034332F2835323B723F33312F383A2F383A3B2F3B3B3B'6SAMPLE_INI = <<-END7[Sessions\\[email protected]]8HostName=#{HOST}9Timeout=600010SshProt=311UserName=#{USERNAME}12UpdateDirectories=013Utf=114Password=#{PASSWORD}15Shell=/bin/bash}16END1718RSpec.describe Rex::Parser::WinSCP do19let(:target) do20d = Class.new { include Rex::Parser::WinSCP }21d.new22end2324context "#parse_protocol" do25it "returns 'Unknown' for unknown protocols" do26expect(target.parse_protocol(nil)).to eq('Unknown')27expect(target.parse_protocol(99)).to eq('Unknown')28expect(target.parse_protocol('stuff')).to eq('Unknown')29end3031it "returns 'SSH' for protocol 0" do32expect(target.parse_protocol(0)).to eq('SSH')33end3435it "returns 'FTP' for protocol 5" do36expect(target.parse_protocol(5)).to eq('FTP')37end38end3940context "#decrypt_next_char" do41it "returns 0 and the pwd if pwd length <= 0" do42r, pwd = target.decrypt_next_char('')43expect(r).to eq(0)44expect(pwd).to eq('')45end4647it "strips the first two characters from the return value" do48_, pwd = target.decrypt_next_char('A3')49expect(pwd).to eq('')50end5152it "returns 255 for 'A3'" do53r, _ = target.decrypt_next_char('A3')54expect(r).to eq(Rex::Parser::WinSCP::PWDALG_SIMPLE_FLAG)55end56end5758context "#decrypt_password" do59it "returns 'sdfsdfgsggg' for the example password" do60expect(target.decrypt_password(PASSWORD, "#{USERNAME}#{HOST}")).to eq('sdfsdfgsggg')61end62end6364context "#parse_ini" do65it "raises a RuntimeError if ini is nil or empty" do66expect { target.parse_ini('') }.to raise_error(RuntimeError, /No data/i)67expect { target.parse_ini(nil) }.to raise_error(RuntimeError, /No data/i)68end6970it "raises a RuntimeError if UseMasterPassword is 1" do71expect { target.parse_ini(INI_SECURITY) }.to raise_error(RuntimeError, /Master/i)72end7374it "parses the example ini" do75r = target.parse_ini(SAMPLE_INI).first76expect(r[:hostname]).to eq(HOST)77expect(r[:password]).to eq('sdfsdfgsggg')78expect(r[:username]).to eq(USERNAME)79expect(r[:protocol]).to eq('SSH')80expect(r[:portnumber]).to eq(22)81end82end8384context "#read_and_parse_ini" do85it "returns nil if file is empty or doesn't exist" do86expect(File).to receive(:read).and_return(nil)87expect(target.read_and_parse_ini('blah')).to be nil88end8990it "parses the example ini and return a single result" do91expect(File).to receive(:read).and_return(SAMPLE_INI)92expect(target.read_and_parse_ini(SAMPLE_INI).count).to eq 193end94end95end96979899