diff options
author | Justin Clark-Casey (justincc) | 2012-11-22 03:01:57 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-11-22 03:03:37 +0000 |
commit | 448811ccddfa6fb3dbbd7279e240ff9ef805d218 (patch) | |
tree | a1aa55d5bf0ad871dc75fc01e40320bdeebc7ce5 | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC-448811ccddfa6fb3dbbd7279e240ff9ef805d218.zip opensim-SC-448811ccddfa6fb3dbbd7279e240ff9ef805d218.tar.gz opensim-SC-448811ccddfa6fb3dbbd7279e240ff9ef805d218.tar.bz2 opensim-SC-448811ccddfa6fb3dbbd7279e240ff9ef805d218.tar.xz |
If an asset POST does not contain well-formed XML, return a 400 (Bad Request) HTTP status rather than simply dropping the request.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs | 15 | ||||
-rw-r--r-- | OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs | 26 |
2 files changed, 38 insertions, 3 deletions
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs index 87b3d2d..a006fa8 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs | |||
@@ -57,14 +57,23 @@ namespace OpenSim.Server.Handlers.Asset | |||
57 | public override byte[] Handle(string path, Stream request, | 57 | public override byte[] Handle(string path, Stream request, |
58 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | 58 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) |
59 | { | 59 | { |
60 | AssetBase asset; | ||
60 | XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); | 61 | XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); |
61 | AssetBase asset = (AssetBase) xs.Deserialize(request); | 62 | |
63 | try | ||
64 | { | ||
65 | asset = (AssetBase)xs.Deserialize(request); | ||
66 | } | ||
67 | catch (XmlException) | ||
68 | { | ||
69 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | ||
70 | return null; | ||
71 | } | ||
62 | 72 | ||
63 | string[] p = SplitParams(path); | 73 | string[] p = SplitParams(path); |
64 | if (p.Length > 1) | 74 | if (p.Length > 1) |
65 | { | 75 | { |
66 | bool result = | 76 | bool result = m_AssetService.UpdateContent(p[1], asset.Data); |
67 | m_AssetService.UpdateContent(p[1], asset.Data); | ||
68 | 77 | ||
69 | xs = new XmlSerializer(typeof(bool)); | 78 | xs = new XmlSerializer(typeof(bool)); |
70 | return ServerUtils.SerializeResult(xs, result); | 79 | return ServerUtils.SerializeResult(xs, result); |
diff --git a/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs index 9e82576..427fa16 100644 --- a/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs +++ b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.IO; | 29 | using System.IO; |
30 | using System.Net; | ||
30 | using System.Text; | 31 | using System.Text; |
31 | using System.Xml; | 32 | using System.Xml; |
32 | using System.Xml.Serialization; | 33 | using System.Xml.Serialization; |
@@ -38,6 +39,7 @@ using OpenSim.Server.Handlers.Asset; | |||
38 | using OpenSim.Services.AssetService; | 39 | using OpenSim.Services.AssetService; |
39 | using OpenSim.Services.Interfaces; | 40 | using OpenSim.Services.Interfaces; |
40 | using OpenSim.Tests.Common; | 41 | using OpenSim.Tests.Common; |
42 | using OpenSim.Tests.Common.Mock; | ||
41 | 43 | ||
42 | namespace OpenSim.Server.Handlers.Asset.Test | 44 | namespace OpenSim.Server.Handlers.Asset.Test |
43 | { | 45 | { |
@@ -80,5 +82,29 @@ namespace OpenSim.Server.Handlers.Asset.Test | |||
80 | 82 | ||
81 | Assert.That(retrievedAsset, Is.Not.Null); | 83 | Assert.That(retrievedAsset, Is.Not.Null); |
82 | } | 84 | } |
85 | |||
86 | [Test] | ||
87 | public void TestBadXmlAssetStoreRequest() | ||
88 | { | ||
89 | TestHelpers.InMethod(); | ||
90 | |||
91 | IConfigSource config = new IniConfigSource(); | ||
92 | config.AddConfig("AssetService"); | ||
93 | config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); | ||
94 | |||
95 | AssetService assetService = new AssetService(config); | ||
96 | |||
97 | AssetServerPostHandler asph = new AssetServerPostHandler(assetService); | ||
98 | |||
99 | MemoryStream buffer = new MemoryStream(); | ||
100 | byte[] badData = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f }; | ||
101 | buffer.Write(badData, 0, badData.Length); | ||
102 | buffer.Position = 0; | ||
103 | |||
104 | TestOSHttpResponse response = new TestOSHttpResponse(); | ||
105 | asph.Handle(null, buffer, null, response); | ||
106 | |||
107 | Assert.That(response.StatusCode, Is.EqualTo((int)HttpStatusCode.BadRequest)); | ||
108 | } | ||
83 | } | 109 | } |
84 | } \ No newline at end of file | 110 | } \ No newline at end of file |