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/steam/message_spec.rb
Views: 11789
1
# -*- coding: binary -*-
2
require 'spec_helper'
3
4
RSpec.describe Rex::Proto::Steam do
5
subject(:steam) do
6
mod = Module.new
7
mod.extend described_class
8
mod
9
end
10
11
describe '#encode_message' do
12
it 'properly encodes messages' do
13
message = steam.encode_message('T', 'Test')
14
expect(message).to eq("\xFF\xFF\xFF\xFF\x54Test")
15
end
16
end
17
18
describe '#decode_message' do
19
it 'does not decode overly short messages' do
20
expect(steam.decode_message('foo')).to eq(nil)
21
end
22
23
it 'does not decode unknown messages' do
24
expect(steam.decode_message("\xFF\xFF\xFF\x01blahblahblah")).to eq(nil)
25
end
26
27
it 'properly decodes valid messages' do
28
type, message = steam.decode_message("\xFF\xFF\xFF\xFF\x54Test")
29
expect(type).to eq(0x54)
30
expect(message).to eq('Test')
31
end
32
end
33
34
describe '#a2s_info_decode' do
35
it 'extracts a2s_info fields properly' do
36
expected_info = {
37
version: 17, name: "-=THE BATTLEGROUNDS *HARDCORE*=-", map: "aoc_battleground",
38
folder: "ageofchivalry", game_name: "Age of Chivalry", game_id: 17510,
39
players: "22/32", bots: 0, game_version: "1.0.0.6", type: "Dedicated",
40
environment: "Linux", visibility: "public", VAC: "secured"
41
}
42
actual_info = steam.a2s_info_decode(File.binread(File.join(File.dirname(__FILE__), 'steam_info.bin')))
43
expect(actual_info).to eq(expected_info)
44
end
45
end
46
end
47
48