aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Servers/Tests')
-rw-r--r--OpenSim/Framework/Servers/Tests/OSHttpTests.cs393
1 files changed, 0 insertions, 393 deletions
diff --git a/OpenSim/Framework/Servers/Tests/OSHttpTests.cs b/OpenSim/Framework/Servers/Tests/OSHttpTests.cs
deleted file mode 100644
index f3872a6..0000000
--- a/OpenSim/Framework/Servers/Tests/OSHttpTests.cs
+++ /dev/null
@@ -1,393 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Specialized;
30using System.IO;
31using System.Net;
32using System.Net.Sockets;
33using System.Text;
34using HttpServer;
35using HttpServer.FormDecoders;
36using NUnit.Framework;
37using NUnit.Framework.SyntaxHelpers;
38
39namespace OpenSim.Framework.Servers.Tests
40{
41 [TestFixture]
42 public class OSHttpTests
43 {
44 // we need an IHttpClientContext for our tests
45 public class TestHttpClientContext: IHttpClientContext
46 {
47 private bool _secured;
48 public bool Secured
49 {
50 get { return _secured; }
51 }
52
53 public TestHttpClientContext(bool secured)
54 {
55 _secured = secured;
56 }
57
58 public void Disconnect(SocketError error) {}
59 public void Respond(string httpVersion, HttpStatusCode statusCode, string reason, string body) {}
60 public void Respond(string httpVersion, HttpStatusCode statusCode, string reason) {}
61 public void Respond(string body) {}
62 public void Send(byte[] buffer) {}
63 public void Send(byte[] buffer, int offset, int size) {}
64 }
65
66 public class TestHttpRequest: IHttpRequest
67 {
68 public bool BodyIsComplete
69 {
70 get { return true; }
71 }
72 public string[] AcceptTypes
73 {
74 get {return _acceptTypes; }
75 }
76 private string[] _acceptTypes;
77 public Stream Body
78 {
79 get { return _body; }
80 set { _body = value;}
81 }
82 private Stream _body;
83 public ConnectionType Connection
84 {
85 get { return _connection; }
86 set { _connection = value; }
87 }
88 private ConnectionType _connection;
89 public int ContentLength
90 {
91 get { return _contentLength; }
92 set { _contentLength = value; }
93 }
94 private int _contentLength;
95 public NameValueCollection Headers
96 {
97 get { return _headers; }
98 }
99 private NameValueCollection _headers = new NameValueCollection();
100 public string HttpVersion
101 {
102 get { return _httpVersion; }
103 set { _httpVersion = value; }
104 }
105 private string _httpVersion = null;
106 public string Method
107 {
108 get { return _method; }
109 set { _method = value; }
110 }
111 private string _method = null;
112 public HttpInput QueryString
113 {
114 get { return _queryString; }
115 }
116 private HttpInput _queryString = null;
117 public Uri Uri
118 {
119 get { return _uri; }
120 set { _uri = value; }
121 }
122 private Uri _uri = null;
123 public string[] UriParts
124 {
125 get { return _uri.Segments; }
126 }
127 public HttpParam Param
128 {
129 get { return null; }
130 }
131 public HttpForm Form
132 {
133 get { return null; }
134 }
135 public bool IsAjax
136 {
137 get { return false; }
138 }
139 public RequestCookies Cookies
140 {
141 get { return null; }
142 }
143
144 public TestHttpRequest() {}
145
146 public TestHttpRequest(string contentEncoding, string contentType, string userAgent,
147 string remoteAddr, string remotePort, string[] acceptTypes,
148 ConnectionType connectionType, int contentLength, Uri uri)
149 {
150 _headers["content-encoding"] = contentEncoding;
151 _headers["content-type"] = contentType;
152 _headers["user-agent"] = userAgent;
153 _headers["remote_addr"] = remoteAddr;
154 _headers["remote_port"] = remotePort;
155
156 _acceptTypes = acceptTypes;
157 _connection = connectionType;
158 _contentLength = contentLength;
159 _uri = uri;
160 }
161
162 public void DecodeBody(FormDecoderProvider providers) {}
163 public void SetCookies(RequestCookies cookies) {}
164 public void AddHeader(string name, string value)
165 {
166 _headers.Add(name, value);
167 }
168 public int AddToBody(byte[] bytes, int offset, int length)
169 {
170 return 0;
171 }
172 public void Clear() {}
173
174 public object Clone()
175 {
176 TestHttpRequest clone = new TestHttpRequest();
177 clone._acceptTypes = _acceptTypes;
178 clone._connection = _connection;
179 clone._contentLength = _contentLength;
180 clone._uri = _uri;
181 clone._headers = new NameValueCollection(_headers);
182
183 return clone;
184 }
185 }
186
187 public class TestHttpResponse: IHttpResponse
188 {
189 public Stream Body
190 {
191 get { return _body; }
192
193 set { _body = value; }
194 }
195 private Stream _body;
196
197 public string ProtocolVersion
198 {
199 get { return _protocolVersion; }
200 set { _protocolVersion = value; }
201 }
202 private string _protocolVersion;
203
204 public bool Chunked
205 {
206 get { return _chunked; }
207
208 set { _chunked = value; }
209 }
210 private bool _chunked;
211
212 public ConnectionType Connection
213 {
214 get { return _connection; }
215
216 set { _connection = value; }
217 }
218 private ConnectionType _connection;
219
220 public Encoding Encoding
221 {
222 get { return _encoding; }
223
224 set { _encoding = value; }
225 }
226 private Encoding _encoding;
227
228 public int KeepAlive
229 {
230 get { return _keepAlive; }
231
232 set { _keepAlive = value; }
233 }
234 private int _keepAlive;
235
236 public HttpStatusCode Status
237 {
238 get { return _status; }
239
240 set { _status = value; }
241 }
242 private HttpStatusCode _status;
243
244 public string Reason
245 {
246 get { return _reason; }
247
248 set { _reason = value; }
249 }
250 private string _reason;
251
252 public long ContentLength
253 {
254 get { return _contentLength; }
255
256 set { _contentLength = value; }
257 }
258 private long _contentLength;
259
260 public string ContentType
261 {
262 get { return _contentType; }
263
264 set { _contentType = value; }
265 }
266 private string _contentType;
267
268 public bool HeadersSent
269 {
270 get { return _headersSent; }
271 }
272 private bool _headersSent;
273
274 public bool Sent
275 {
276 get { return _sent; }
277 }
278 private bool _sent;
279
280 public ResponseCookies Cookies
281 {
282 get { return _cookies; }
283 }
284 private ResponseCookies _cookies = null;
285
286 public TestHttpResponse()
287 {
288 _headersSent = false;
289 _sent = false;
290 }
291
292 public void AddHeader(string name, string value) {}
293 public void Send()
294 {
295 if (!_headersSent) SendHeaders();
296 if (_sent) throw new InvalidOperationException("stuff already sent");
297 _sent = true;
298 }
299
300 public void SendBody(byte[] buffer, int offset, int count)
301 {
302 if (!_headersSent) SendHeaders();
303 _sent = true;
304 }
305 public void SendBody(byte[] buffer)
306 {
307 if (!_headersSent) SendHeaders();
308 _sent = true;
309 }
310
311 public void SendHeaders()
312 {
313 if (_headersSent) throw new InvalidOperationException("headers already sent");
314 _headersSent = true;
315 }
316
317 public void Redirect(Uri uri) {}
318 public void Redirect(string url) {}
319 }
320
321
322 public OSHttpRequest req0;
323 public OSHttpRequest req1;
324
325 public OSHttpResponse rsp0;
326
327 public IPEndPoint ipEP0;
328
329 [TestFixtureSetUp]
330 public void Init()
331 {
332 TestHttpRequest threq0 = new TestHttpRequest("utf-8", "text/xml", "OpenSim Test Agent", "192.168.0.1", "4711",
333 new string[] {"text/xml"},
334 ConnectionType.KeepAlive, 4711,
335 new Uri("http://127.0.0.1/admin/inventory/Dr+Who/Tardis"));
336 threq0.Method = "GET";
337 threq0.HttpVersion = HttpHelper.HTTP10;
338
339 TestHttpRequest threq1 = new TestHttpRequest("utf-8", "text/xml", "OpenSim Test Agent", "192.168.0.1", "4711",
340 new string[] {"text/xml"},
341 ConnectionType.KeepAlive, 4711,
342 new Uri("http://127.0.0.1/admin/inventory/Dr+Who/Tardis?a=0&b=1&c=2"));
343 threq1.Method = "POST";
344 threq1.HttpVersion = HttpHelper.HTTP11;
345 threq1.Headers["x-wuff"] = "wuffwuff";
346 threq1.Headers["www-authenticate"] = "go away";
347
348 req0 = new OSHttpRequest(new TestHttpClientContext(false), threq0);
349 req1 = new OSHttpRequest(new TestHttpClientContext(false), threq1);
350
351 rsp0 = new OSHttpResponse(new TestHttpResponse());
352
353 ipEP0 = new IPEndPoint(IPAddress.Parse("192.168.0.1"), 4711);
354
355 }
356
357 [Test]
358 public void T000_OSHttpRequest()
359 {
360 Assert.That(req0.HttpMethod, Is.EqualTo("GET"));
361 Assert.That(req0.ContentType, Is.EqualTo("text/xml"));
362 Assert.That(req0.ContentLength, Is.EqualTo(4711));
363
364 Assert.That(req1.HttpMethod, Is.EqualTo("POST"));
365 }
366
367 [Test]
368 public void T001_OSHttpRequestHeaderAccess()
369 {
370 Assert.That(req1.Headers["x-wuff"], Is.EqualTo("wuffwuff"));
371 Assert.That(req1.Headers.Get("x-wuff"), Is.EqualTo("wuffwuff"));
372
373 Assert.That(req1.Headers["www-authenticate"], Is.EqualTo("go away"));
374 Assert.That(req1.Headers.Get("www-authenticate"), Is.EqualTo("go away"));
375
376 Assert.That(req0.RemoteIPEndPoint, Is.EqualTo(ipEP0));
377 }
378
379 [Test]
380 public void T002_OSHttpRequestUriParsing()
381 {
382 Assert.That(req0.RawUrl, Is.EqualTo("/admin/inventory/Dr+Who/Tardis"));
383 Assert.That(req1.Url.ToString(), Is.EqualTo("http://127.0.0.1/admin/inventory/Dr+Who/Tardis?a=0&b=1&c=2"));
384 }
385
386 [Test]
387 public void T100_OSHttpResponse()
388 {
389 rsp0.ContentType = "text/xml";
390 Assert.That(rsp0.ContentType, Is.EqualTo("text/xml"));
391 }
392 }
393}