Skip to content

Commit 391ff5b

Browse files
David MaloneyDavid Maloney
authored andcommitted
basic TLV method tests
1 parent b18f5b1 commit 391ff5b

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

spec/lib/rex/post/meterpreter/packet_spec.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,55 @@
3939
subject.should respond_to :from_r
4040
end
4141

42+
context "A String TLV" do
43+
it "should return the correct TLV type" do
44+
subject.type.should == Rex::Post::Meterpreter::TLV_TYPE_STRING
45+
end
46+
47+
it "should return the correct value" do
48+
subject.value.should == "test"
49+
end
50+
51+
context "the type? method" do
52+
it "should return true for STRING" do
53+
subject.type?(Rex::Post::Meterpreter::TLV_TYPE_STRING).should == true
54+
end
55+
56+
it "should return false for UINT" do
57+
subject.type?(Rex::Post::Meterpreter::TLV_TYPE_UINT).should == false
58+
end
59+
end
60+
61+
context "the value? method" do
62+
it "should return true for the correct value" do
63+
subject.value?("test").should == true
64+
end
65+
66+
it "should return false for an incorrect value" do
67+
subject.value?("fake").should == false
68+
end
69+
end
70+
71+
context "the inspect method" do
72+
it "should return a string representation of the TLV" do
73+
tlv_to_s = "#<Rex::Post::Meterpreter::Tlv type=STRING meta=STRING value=\"test\">"
74+
subject.inspect.should == tlv_to_s
75+
end
76+
end
77+
78+
context "the to_r method" do
79+
it "should return the raw bytes of the TLV to send over the wire" do
80+
tlv_bytes = "\x00\x00\x00\r\x00\x01\x00\ntest\x00"
81+
subject.to_r.should == tlv_bytes
82+
end
83+
end
84+
85+
context "the from_r method" do
86+
it "should adjust the tlv attributes from the given raw bytes" do
87+
subject.from_r("\x00\x00\x00\r\x00\x01\x00\ntes2\x00")
88+
subject.value.should == "tes2"
89+
end
90+
end
91+
end
92+
4293
end

0 commit comments

Comments
 (0)