OSHttpTests.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 OpenSimulator 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. using System;
  28. using System.Collections.Specialized;
  29. using System.IO;
  30. using System.Net;
  31. using System.Net.Sockets;
  32. using System.Text;
  33. using HttpServer;
  34. using HttpServer.FormDecoders;
  35. using NUnit.Framework;
  36. using OpenSim.Framework.Servers.HttpServer;
  37. using OpenSim.Tests.Common;
  38. namespace OpenSim.Framework.Servers.Tests
  39. {
  40. [TestFixture]
  41. public class OSHttpTests : OpenSimTestCase
  42. {
  43. public OSHttpRequest req0;
  44. public OSHttpRequest req1;
  45. public OSHttpResponse rsp0;
  46. public IPEndPoint ipEP0;
  47. [TestFixtureSetUp]
  48. public void Init()
  49. {
  50. TestHttpRequest threq0 = new TestHttpRequest("utf-8", "text/xml", "OpenSim Test Agent", "192.168.0.1", "4711",
  51. new string[] {"text/xml"},
  52. ConnectionType.KeepAlive, 4711,
  53. new Uri("http://127.0.0.1/admin/inventory/Dr+Who/Tardis"));
  54. threq0.Method = "GET";
  55. threq0.HttpVersion = HttpHelper.HTTP10;
  56. TestHttpRequest threq1 = new TestHttpRequest("utf-8", "text/xml", "OpenSim Test Agent", "192.168.0.1", "4711",
  57. new string[] {"text/xml"},
  58. ConnectionType.KeepAlive, 4711,
  59. new Uri("http://127.0.0.1/admin/inventory/Dr+Who/Tardis?a=0&b=1&c=2"));
  60. threq1.Method = "POST";
  61. threq1.HttpVersion = HttpHelper.HTTP11;
  62. threq1.Headers["x-wuff"] = "wuffwuff";
  63. threq1.Headers["www-authenticate"] = "go away";
  64. req0 = new OSHttpRequest(new TestHttpClientContext(false), threq0);
  65. req1 = new OSHttpRequest(new TestHttpClientContext(false), threq1);
  66. rsp0 = new OSHttpResponse(new TestHttpResponse());
  67. ipEP0 = new IPEndPoint(IPAddress.Parse("192.168.0.1"), 4711);
  68. }
  69. [Test]
  70. public void T000_OSHttpRequest()
  71. {
  72. Assert.That(req0.HttpMethod, Is.EqualTo("GET"));
  73. Assert.That(req0.ContentType, Is.EqualTo("text/xml"));
  74. Assert.That(req0.ContentLength, Is.EqualTo(4711));
  75. Assert.That(req1.HttpMethod, Is.EqualTo("POST"));
  76. }
  77. [Test]
  78. public void T001_OSHttpRequestHeaderAccess()
  79. {
  80. Assert.That(req1.Headers["x-wuff"], Is.EqualTo("wuffwuff"));
  81. Assert.That(req1.Headers.Get("x-wuff"), Is.EqualTo("wuffwuff"));
  82. Assert.That(req1.Headers["www-authenticate"], Is.EqualTo("go away"));
  83. Assert.That(req1.Headers.Get("www-authenticate"), Is.EqualTo("go away"));
  84. Assert.That(req0.RemoteIPEndPoint, Is.EqualTo(ipEP0));
  85. }
  86. [Test]
  87. public void T002_OSHttpRequestUriParsing()
  88. {
  89. Assert.That(req0.RawUrl, Is.EqualTo("/admin/inventory/Dr+Who/Tardis"));
  90. Assert.That(req1.Url.ToString(), Is.EqualTo("http://127.0.0.1/admin/inventory/Dr+Who/Tardis?a=0&b=1&c=2"));
  91. }
  92. [Test]
  93. public void T100_OSHttpResponse()
  94. {
  95. rsp0.ContentType = "text/xml";
  96. Assert.That(rsp0.ContentType, Is.EqualTo("text/xml"));
  97. }
  98. }
  99. }