CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/lib/rex/proto/quake/message_spec.rb
Views: 11789
1
# -*- coding: binary -*-
2
require 'spec_helper'
3
4
RSpec.describe Rex::Proto::Quake do
5
subject do
6
mod = Module.new
7
mod.extend described_class
8
mod
9
end
10
11
describe '#encode_message' do
12
it 'should properly encode messages' do
13
message = subject.encode_message('getinfo')
14
expect(message).to eq("\xFF\xFF\xFF\xFFgetinfo")
15
end
16
end
17
18
describe '#decode_message' do
19
it 'should not decode overly short messages' do
20
expect(subject.decode_message('foo')).to eq(nil)
21
end
22
23
it 'should not decode unknown messages' do
24
expect(subject.decode_message("\xFF\xFF\xFF\x01blahblahblah")).to eq(nil)
25
end
26
27
it 'should properly decode valid messages' do
28
expect(subject.decode_message(subject.getstatus)).to eq('getstatus')
29
end
30
end
31
32
describe '#decode_infostring' do
33
it 'should not decode things that are not infostrings' do
34
expect(subject.decode_infostring('this is not an infostring')).to eq(nil)
35
end
36
37
it 'should properly decode infostrings' do
38
expect(subject.decode_infostring('a\1\b\2\c\blah')).to eq(
39
'a' => '1', 'b' => '2', 'c' => 'blah'
40
)
41
end
42
end
43
44
describe '#decode_response' do
45
it 'should raise when server-side errors are encountered' do
46
expect do
47
subject.decode_response(subject.encode_message("print\nsomeerror\n"))
48
end.to raise_error(::ArgumentError)
49
end
50
end
51
52
describe '#decode_info' do
53
it 'should decode info responses properly' do
54
expected_info = {
55
"clients" => "0",
56
"g_humanplayers" => "0",
57
"g_needpass" => "0",
58
"gamename" => "Quake3Arena",
59
"gametype" => "0",
60
"hostname" => "noname",
61
"mapname" => "q3dm2",
62
"protocol" => "68",
63
"pure" => "1",
64
"sv_maxclients" => "8",
65
"voip" => "1"
66
}
67
actual_info = subject.decode_info(File.binread(File.join(File.dirname(__FILE__), 'info_response.bin')))
68
expect(actual_info).to eq(expected_info)
69
end
70
end
71
72
describe '#decode_status' do
73
it 'should decode status responses properly' do
74
expected_status = {
75
"bot_minplayers" => "0",
76
"capturelimit" => "8",
77
"com_gamename" => "Quake3Arena",
78
"com_protocol" => "71",
79
"dmflags" => "0",
80
"fraglimit" => "30",
81
"g_gametype" => "0",
82
"g_maxGameClients" => "0",
83
"g_needpass" => "0",
84
"gamename" => "baseq3",
85
"mapname" => "q3dm2",
86
"sv_allowDownload" => "0",
87
"sv_dlRate" => "100",
88
"sv_floodProtect" => "1",
89
"sv_hostname" => "noname",
90
"sv_maxPing" => "0",
91
"sv_maxRate" => "10000",
92
"sv_maxclients" => "8",
93
"sv_minPing" => "0",
94
"sv_minRate" => "0",
95
"sv_privateClients" => "0",
96
"timelimit" => "25",
97
"version" => "ioq3 1.36+svn2202-1/Ubuntu linux-x86_64 Dec 12 2011"
98
}
99
actual_status = subject.decode_status(File.binread(File.join(File.dirname(__FILE__), 'status_response.bin')))
100
expect(actual_status).to eq(expected_status)
101
end
102
end
103
end
104
105