PageRenderTime 30ms CodeModel.GetById 15ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/spec/lib/rex/proto/ntp/modes_spec.rb

https://github.com/debbiemezyene/metasploit-framework
Ruby | 83 lines | 71 code | 10 blank | 2 comment | 6 complexity | 64587983dd82349ba1a0e12ab2db165f MD5 | raw file
 1# -*- coding: binary -*-
 2#
 3require 'rex/proto/ntp/modes'
 4
 5describe "Rex::Proto::NTP mode message handling" do
 6  before do
 7    @payload = 'R7' * 7
 8  end
 9
10  describe Rex::Proto::NTP::NTPControl do
11    before do
12      @control_raw = "\x1e\x05\x12\x34\x12\x34\x12\x34\x00\x00\x00\x0e" + @payload
13      @control = Rex::Proto::NTP::NTPControl.new
14      @control.version = 3
15      @control.response = 0
16      @control.more = 0
17      @control.operation = 5
18      @control.sequence = 0x1234
19      @control.association_id = 0x1234
20      @control.status = 0x1234
21      @control.payload_offset = 0
22      @control.payload_size = 14
23      @control.payload = @payload
24    end
25
26    it 'Generates control NTP messages correctly' do
27      @control_raw.should == @control.to_s
28    end
29
30    it 'Parses control NTP messages correctly' do
31      parsed_raw = Rex::Proto::NTP::NTPControl.new(@control_raw)
32      @control.should == parsed_raw
33    end
34  end
35
36  describe Rex::Proto::NTP::NTPGeneric do
37    before do
38      @generic_raw = "\xcc\x12\x34\x56" + @payload
39      @generic = Rex::Proto::NTP::NTPGeneric.new
40      @generic.li = 3
41      @generic.version = 1
42      @generic.mode = 4
43      @generic.stratum = 0x12
44      @generic.poll = 0x34
45      @generic.precision = 0x56
46      @generic.payload = @payload
47    end
48
49    it 'Generates generic NTP messages correctly' do
50      @generic_raw.should == @generic.to_s
51    end
52
53    it 'Parses generic NTP messages correctly' do
54      parsed_raw = Rex::Proto::NTP::NTPGeneric.new(@generic_raw)
55      @generic.should == parsed_raw
56    end
57  end
58
59  describe Rex::Proto::NTP::NTPPrivate do
60    before do
61      @private_raw = "\x1f\x5a\x01\x99\x00\x00\x00\x00" + @payload
62      @private = Rex::Proto::NTP::NTPPrivate.new
63      @private.response = 0
64      @private.more = 0
65      @private.version = 3
66      @private.mode = 7
67      @private.auth = 0
68      @private.sequence = 90
69      @private.implementation = 1
70      @private.request_code = 153
71      @private.payload = @payload
72    end
73
74    it 'Generates private NTP messages correctly' do
75      @private_raw.should == @private.to_s
76    end
77
78    it 'Parses private NTP messages correctly' do
79      parsed_raw = Rex::Proto::NTP::NTPPrivate.new(@private_raw)
80      @private.should == parsed_raw
81    end
82  end
83end