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/quake/message_spec.rb
Views: 11789
# -*- coding: binary -*-1require 'spec_helper'23RSpec.describe Rex::Proto::Quake do4subject do5mod = Module.new6mod.extend described_class7mod8end910describe '#encode_message' do11it 'should properly encode messages' do12message = subject.encode_message('getinfo')13expect(message).to eq("\xFF\xFF\xFF\xFFgetinfo")14end15end1617describe '#decode_message' do18it 'should not decode overly short messages' do19expect(subject.decode_message('foo')).to eq(nil)20end2122it 'should not decode unknown messages' do23expect(subject.decode_message("\xFF\xFF\xFF\x01blahblahblah")).to eq(nil)24end2526it 'should properly decode valid messages' do27expect(subject.decode_message(subject.getstatus)).to eq('getstatus')28end29end3031describe '#decode_infostring' do32it 'should not decode things that are not infostrings' do33expect(subject.decode_infostring('this is not an infostring')).to eq(nil)34end3536it 'should properly decode infostrings' do37expect(subject.decode_infostring('a\1\b\2\c\blah')).to eq(38'a' => '1', 'b' => '2', 'c' => 'blah'39)40end41end4243describe '#decode_response' do44it 'should raise when server-side errors are encountered' do45expect do46subject.decode_response(subject.encode_message("print\nsomeerror\n"))47end.to raise_error(::ArgumentError)48end49end5051describe '#decode_info' do52it 'should decode info responses properly' do53expected_info = {54"clients" => "0",55"g_humanplayers" => "0",56"g_needpass" => "0",57"gamename" => "Quake3Arena",58"gametype" => "0",59"hostname" => "noname",60"mapname" => "q3dm2",61"protocol" => "68",62"pure" => "1",63"sv_maxclients" => "8",64"voip" => "1"65}66actual_info = subject.decode_info(File.binread(File.join(File.dirname(__FILE__), 'info_response.bin')))67expect(actual_info).to eq(expected_info)68end69end7071describe '#decode_status' do72it 'should decode status responses properly' do73expected_status = {74"bot_minplayers" => "0",75"capturelimit" => "8",76"com_gamename" => "Quake3Arena",77"com_protocol" => "71",78"dmflags" => "0",79"fraglimit" => "30",80"g_gametype" => "0",81"g_maxGameClients" => "0",82"g_needpass" => "0",83"gamename" => "baseq3",84"mapname" => "q3dm2",85"sv_allowDownload" => "0",86"sv_dlRate" => "100",87"sv_floodProtect" => "1",88"sv_hostname" => "noname",89"sv_maxPing" => "0",90"sv_maxRate" => "10000",91"sv_maxclients" => "8",92"sv_minPing" => "0",93"sv_minRate" => "0",94"sv_privateClients" => "0",95"timelimit" => "25",96"version" => "ioq3 1.36+svn2202-1/Ubuntu linux-x86_64 Dec 12 2011"97}98actual_status = subject.decode_status(File.binread(File.join(File.dirname(__FILE__), 'status_response.bin')))99expect(actual_status).to eq(expected_status)100end101end102end103104105