1
+ require 'spec_helper'
2
+
3
+ require 'msf/core'
4
+ require 'msf/core/exploit/http/client'
5
+
6
+ describe Msf ::Exploit ::Remote ::HttpClient do
7
+ subject do
8
+ mod = Module . new
9
+ mod . extend described_class
10
+
11
+ mod
12
+ end
13
+
14
+ context 'normalize_uri' do
15
+ let ( :expected_normalized_uri ) do
16
+ '/a/b/c'
17
+ end
18
+
19
+ let ( :normalized_uri ) do
20
+ subject . normalize_uri ( unnormalized_uri )
21
+ end
22
+
23
+ context "with starting '/'" do
24
+ let ( :unnormalized_uri ) do
25
+ expected_normalized_uri
26
+ end
27
+
28
+ it "should start with '/'" do
29
+ unnormalized_uri [ 0 , 1 ] . should == '/'
30
+ end
31
+
32
+ it "should not add another starting '/'" do
33
+ normalized_uri . should == expected_normalized_uri
34
+ end
35
+
36
+ context "with multiple starting '/'" do
37
+ let ( :unnormalized_uri ) do
38
+ "/#{ expected_normalized_uri } "
39
+ end
40
+
41
+ it "should have at least 2 starting '/'" do
42
+ unnormalized_uri [ 0 , 2 ] . should == '//'
43
+ end
44
+
45
+ it "should return with one starting '/'" do
46
+ normalized_uri . should == expected_normalized_uri
47
+ end
48
+ end
49
+
50
+ context "with trailing '/'" do
51
+ let ( :unnormalized_uri ) do
52
+ "#{ expected_normalized_uri } /"
53
+ end
54
+
55
+ it "should end with '/'" do
56
+ unnormalized_uri [ -1 , 1 ] . should == '/'
57
+ end
58
+
59
+ it "should remove the trailing '/'" do
60
+ normalized_uri . should == expected_normalized_uri
61
+ end
62
+
63
+ context "with just '/'" do
64
+ let ( :unnormalized_uri ) do
65
+ '/'
66
+ end
67
+
68
+ it "should be '/'" do
69
+ unnormalized_uri . should == '/'
70
+ end
71
+
72
+ it "should return '/'" do
73
+ normalized_uri . should == '/'
74
+ end
75
+ end
76
+
77
+ context "with multiple multiple trailing '/'" do
78
+ let ( :unnormalized_uri ) do
79
+ "#{ expected_normalized_uri } //"
80
+ end
81
+
82
+ it "should have multiple trailing '/'" do
83
+ unnormalized_uri [ -2 .. -1 ] . should == '//'
84
+ end
85
+
86
+ it "should return only one trailing '/'" do
87
+ normalized_uri . should == expected_normalized_uri
88
+ end
89
+ end
90
+ end
91
+
92
+ context "without trailing '/'" do
93
+ let ( :unnormalized_uri ) do
94
+ expected_normalized_uri
95
+ end
96
+
97
+ it "should not have a trailing '/'" do
98
+ unnormalized_uri [ -1 , 1 ] . should_not == '/'
99
+ end
100
+
101
+ it "should return original string" do
102
+ normalized_uri . should == expected_normalized_uri
103
+ end
104
+ end
105
+ end
106
+
107
+ context "without starting '/'" do
108
+ let ( :unnormalized_uri ) do
109
+ 'a/b/c'
110
+ end
111
+
112
+ context "with trailing '/'" do
113
+ let ( :unnormalized_uri ) do
114
+ 'a/b/c/'
115
+ end
116
+
117
+ it "'should have trailing '/'" do
118
+ unnormalized_uri [ -1 , 1 ] . should == '/'
119
+ end
120
+
121
+ it "should add starting '/'" do
122
+ normalized_uri [ 0 , 1 ] . should == '/'
123
+ end
124
+
125
+ it "'should remove trailing '/'" do
126
+ normalized_uri [ -1 , 1 ] . should_not == '/'
127
+ end
128
+
129
+ it 'should normalize the uri' do
130
+ normalized_uri . should == expected_normalized_uri
131
+ end
132
+ end
133
+
134
+ context "without trailing '/'" do
135
+ it "'should not have trailing '/'" do
136
+ unnormalized_uri [ -1 , 1 ] . should_not == '/'
137
+ end
138
+
139
+ it "should add starting '/'" do
140
+ normalized_uri [ 0 , 1 ] . should == '/'
141
+ end
142
+
143
+ it "should add trailing '/'" do
144
+ normalized_uri [ -1 , 1 ] . should_not == '/'
145
+ end
146
+
147
+ context 'with empty string' do
148
+ let ( :unnormalized_uri ) do
149
+ ''
150
+ end
151
+
152
+ it "should be empty" do
153
+ unnormalized_uri . should be_empty
154
+ end
155
+
156
+ it "should return '/'" do
157
+ normalized_uri . should == '/'
158
+ end
159
+ end
160
+
161
+ context 'with nil' do
162
+ let ( :unnormalized_uri ) do
163
+ nil
164
+ end
165
+
166
+ it 'should be nil' do
167
+ unnormalized_uri . should be_nil
168
+ end
169
+
170
+ it "should return '/" do
171
+ normalized_uri . should == '/'
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end
177
+ end
0 commit comments