metasploit-framework/spec/lib/rex/proto/quake/message_spec.rb

105 lines
3.0 KiB
Ruby
Raw Normal View History

2014-11-12 21:32:56 +00:00
# -*- coding: binary -*-
require 'spec_helper'
require 'rex/proto/quake/message'
describe Rex::Proto::Quake do
subject do
mod = Module.new
mod.extend described_class
mod
end
describe '#encode_message' do
it 'should properly encode messages' do
message = subject.encode_message('getinfo')
expect(message).to eq("\xFF\xFF\xFF\xFFgetinfo")
end
end
describe '#decode_message' do
it 'should not decode overly short messages' do
expect(subject.decode_message('foo')).to eq(nil)
end
it 'should not decode unknown messages' do
expect(subject.decode_message("\xFF\xFF\xFF\x01blahblahblah")).to eq(nil)
end
it 'should properly decode valid messages' do
expect(subject.decode_message(subject.getstatus)).to eq('getstatus')
end
end
describe '#decode_infostring' do
it 'should not decode things that are not infostrings' do
expect(subject.decode_infostring('this is not an infostring')).to eq(nil)
end
it 'should properly decode infostrings' do
2014-11-13 00:44:43 +00:00
expect(subject.decode_infostring('a\1\b\2\c\blah')).to eq(
'a' => '1', 'b' => '2', 'c' => 'blah'
)
2014-11-12 21:32:56 +00:00
end
end
describe '#decode_response' do
it 'should raise when server-side errors are encountered' do
2014-11-13 00:44:43 +00:00
expect do
2014-11-12 21:32:56 +00:00
subject.decode_response(subject.encode_message("print\nsomeerror\n"))
2014-11-13 00:44:43 +00:00
end.to raise_error(::ArgumentError)
2014-11-12 21:32:56 +00:00
end
end
describe '#decode_info' do
it 'should decode info responses properly' do
expected_info = {
"clients" => "0",
"g_humanplayers" => "0",
"g_needpass" => "0",
"gamename" => "Quake3Arena",
"gametype" => "0",
"hostname" => "noname",
"mapname" => "q3dm2",
"protocol" => "68",
"pure" => "1",
"sv_maxclients" => "8",
"voip" => "1"
}
actual_info = subject.decode_info(IO.read(File.join(File.dirname(__FILE__), 'info_response.bin')))
expect(actual_info).to eq(expected_info)
end
end
describe '#decode_status' do
it 'should decode status responses properly' do
expected_status = {
2014-11-13 00:44:43 +00:00
"bot_minplayers" => "0",
"capturelimit" => "8",
"com_gamename" => "Quake3Arena",
"com_protocol" => "71",
"dmflags" => "0",
"fraglimit" => "30",
"g_gametype" => "0",
"g_maxGameClients" => "0",
"g_needpass" => "0",
"gamename" => "baseq3",
"mapname" => "q3dm2",
"sv_allowDownload" => "0",
"sv_dlRate" => "100",
"sv_floodProtect" => "1",
"sv_hostname" => "noname",
"sv_maxPing" => "0",
"sv_maxRate" => "10000",
"sv_maxclients" => "8",
"sv_minPing" => "0",
"sv_minRate" => "0",
"sv_privateClients" => "0",
"timelimit" => "25",
"version" => "ioq3 1.36+svn2202-1/Ubuntu linux-x86_64 Dec 12 2011"
2014-11-12 21:32:56 +00:00
}
actual_status = subject.decode_status(IO.read(File.join(File.dirname(__FILE__), 'status_response.bin')))
expect(actual_status).to eq(expected_status)
end
end
end