1
0

AssetServerPostHandlerTests.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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.IO;
  29. using System.Net;
  30. using System.Text;
  31. using System.Xml;
  32. using System.Xml.Serialization;
  33. using Nini.Config;
  34. using NUnit.Framework;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Server.Handlers.Asset;
  38. using OpenSim.Services.AssetService;
  39. using OpenSim.Services.Interfaces;
  40. using OpenSim.Tests.Common;
  41. namespace OpenSim.Server.Handlers.Asset.Test
  42. {
  43. [TestFixture]
  44. public class AssetServerPostHandlerTests : OpenSimTestCase
  45. {
  46. [Test]
  47. public void TestGoodAssetStoreRequest()
  48. {
  49. TestHelpers.InMethod();
  50. UUID assetId = TestHelpers.ParseTail(0x1);
  51. IConfigSource config = new IniConfigSource();
  52. config.AddConfig("AssetService");
  53. config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
  54. AssetService assetService = new AssetService(config);
  55. AssetServerPostHandler asph = new AssetServerPostHandler(assetService);
  56. AssetBase asset = AssetHelpers.CreateNotecardAsset(assetId, "Hello World");
  57. MemoryStream buffer = new MemoryStream();
  58. XmlWriterSettings settings = new XmlWriterSettings();
  59. settings.Encoding = Encoding.UTF8;
  60. using (XmlWriter writer = XmlWriter.Create(buffer, settings))
  61. {
  62. XmlSerializer serializer = new XmlSerializer(typeof(AssetBase));
  63. serializer.Serialize(writer, asset);
  64. writer.Flush();
  65. }
  66. buffer.Position = 0;
  67. asph.Handle(null, buffer, null, null);
  68. AssetBase retrievedAsset = assetService.Get(assetId.ToString());
  69. Assert.That(retrievedAsset, Is.Not.Null);
  70. }
  71. [Test]
  72. public void TestBadXmlAssetStoreRequest()
  73. {
  74. TestHelpers.InMethod();
  75. IConfigSource config = new IniConfigSource();
  76. config.AddConfig("AssetService");
  77. config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
  78. AssetService assetService = new AssetService(config);
  79. AssetServerPostHandler asph = new AssetServerPostHandler(assetService);
  80. MemoryStream buffer = new MemoryStream();
  81. byte[] badData = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f };
  82. buffer.Write(badData, 0, badData.Length);
  83. buffer.Position = 0;
  84. TestOSHttpResponse response = new TestOSHttpResponse();
  85. asph.Handle(null, buffer, null, response);
  86. Assert.That(response.StatusCode, Is.EqualTo((int)HttpStatusCode.BadRequest));
  87. }
  88. }
  89. }