diff options
author | lbsa71 | 2009-05-07 06:31:16 +0000 |
---|---|---|
committer | lbsa71 | 2009-05-07 06:31:16 +0000 |
commit | f3db3d6a001abdca53d88def7a22a40d6aa30271 (patch) | |
tree | 666a0a4132d3fc67fcb60e8b5a098c0066dbc685 /OpenSim/Framework/Servers | |
parent | refactoring Scene.NewUserConnection() to be simpler and clearer. (diff) | |
download | opensim-SC-f3db3d6a001abdca53d88def7a22a40d6aa30271.zip opensim-SC-f3db3d6a001abdca53d88def7a22a40d6aa30271.tar.gz opensim-SC-f3db3d6a001abdca53d88def7a22a40d6aa30271.tar.bz2 opensim-SC-f3db3d6a001abdca53d88def7a22a40d6aa30271.tar.xz |
* Added some more GetAssetStreamHandlerTests
* In the process, caught a potential bug where the handler would allow paths not starting with the registered prefix
Diffstat (limited to 'OpenSim/Framework/Servers')
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs | 14 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs | 42 |
2 files changed, 52 insertions, 4 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs b/OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs index 5ad4520..da4f9a8 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs | |||
@@ -58,14 +58,22 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
58 | 58 | ||
59 | public string GetParam(string path) | 59 | public string GetParam(string path) |
60 | { | 60 | { |
61 | try | 61 | if (CheckParam(path)) |
62 | { | 62 | { |
63 | return path.Substring(m_path.Length); | 63 | return path.Substring(m_path.Length); |
64 | } | 64 | } |
65 | catch (Exception) | 65 | |
66 | return String.Empty; | ||
67 | } | ||
68 | |||
69 | protected bool CheckParam(string path) | ||
70 | { | ||
71 | if(String.IsNullOrEmpty(path)) | ||
66 | { | 72 | { |
67 | return String.Empty; | 73 | return false; |
68 | } | 74 | } |
75 | |||
76 | return path.StartsWith(Path); | ||
69 | } | 77 | } |
70 | } | 78 | } |
71 | } | 79 | } |
diff --git a/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs b/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs index d399274..0b70cb1 100644 --- a/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs +++ b/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs | |||
@@ -2,12 +2,13 @@ | |||
2 | using System.Collections.Generic; | 2 | using System.Collections.Generic; |
3 | using System.Text; | 3 | using System.Text; |
4 | using NUnit.Framework; | 4 | using NUnit.Framework; |
5 | using OpenSim.Data; | ||
5 | 6 | ||
6 | namespace OpenSim.Framework.Servers.Tests | 7 | namespace OpenSim.Framework.Servers.Tests |
7 | { | 8 | { |
8 | [TestFixture] | 9 | [TestFixture] |
9 | public class GetAssetStreamHandlerTests | 10 | public class GetAssetStreamHandlerTests |
10 | { | 11 | { |
11 | [Test] | 12 | [Test] |
12 | public void TestConstructor() | 13 | public void TestConstructor() |
13 | { | 14 | { |
@@ -19,6 +20,11 @@ namespace OpenSim.Framework.Servers.Tests | |||
19 | { | 20 | { |
20 | GetAssetStreamHandler handler = new GetAssetStreamHandler(null); | 21 | GetAssetStreamHandler handler = new GetAssetStreamHandler(null); |
21 | 22 | ||
23 | Assert.AreEqual("", handler.GetParam(null), "Failed on null path."); | ||
24 | Assert.AreEqual("", handler.GetParam(""), "Failed on empty path."); | ||
25 | Assert.AreEqual("", handler.GetParam("s"), "Failed on short url."); | ||
26 | Assert.AreEqual("", handler.GetParam("corruptUrl"), "Failed on corruptUrl."); | ||
27 | |||
22 | Assert.AreEqual("", handler.GetParam("/assets")); | 28 | Assert.AreEqual("", handler.GetParam("/assets")); |
23 | Assert.AreEqual("/", handler.GetParam("/assets/")); | 29 | Assert.AreEqual("/", handler.GetParam("/assets/")); |
24 | Assert.AreEqual("/a", handler.GetParam("/assets/a")); | 30 | Assert.AreEqual("/a", handler.GetParam("/assets/a")); |
@@ -32,11 +38,45 @@ namespace OpenSim.Framework.Servers.Tests | |||
32 | { | 38 | { |
33 | GetAssetStreamHandler handler = new GetAssetStreamHandler(null); | 39 | GetAssetStreamHandler handler = new GetAssetStreamHandler(null); |
34 | 40 | ||
41 | Assert.AreEqual(new string[] { }, handler.SplitParams(null), "Failed on null."); | ||
42 | Assert.AreEqual(new string[] { }, handler.SplitParams(""), "Failed on empty path."); | ||
43 | Assert.AreEqual(new string[] { }, handler.SplitParams("corruptUrl"), "Failed on corrupt url."); | ||
44 | |||
35 | Assert.AreEqual(new string[] { }, handler.SplitParams("/assets"), "Failed on empty params."); | 45 | Assert.AreEqual(new string[] { }, handler.SplitParams("/assets"), "Failed on empty params."); |
36 | Assert.AreEqual(new string[] { }, handler.SplitParams("/assets/"), "Failed on single slash."); | 46 | Assert.AreEqual(new string[] { }, handler.SplitParams("/assets/"), "Failed on single slash."); |
37 | Assert.AreEqual(new string[] { "a" }, handler.SplitParams("/assets/a"), "Failed on first segment."); | 47 | Assert.AreEqual(new string[] { "a" }, handler.SplitParams("/assets/a"), "Failed on first segment."); |
38 | Assert.AreEqual(new string[] { "b" }, handler.SplitParams("/assets/b/"), "Failed on second slash."); | 48 | Assert.AreEqual(new string[] { "b" }, handler.SplitParams("/assets/b/"), "Failed on second slash."); |
49 | Assert.AreEqual(new string[] { "c", "d" }, handler.SplitParams("/assets/c/d"), "Failed on second segment."); | ||
50 | Assert.AreEqual(new string[] { "e", "f" }, handler.SplitParams("/assets/e/f/"), "Failed on trailing slash."); | ||
51 | } | ||
52 | |||
53 | [Test] | ||
54 | public void TestHandleNoParams() | ||
55 | { | ||
56 | byte[] emptyResult = new byte[] {}; | ||
57 | GetAssetStreamHandler handler = new GetAssetStreamHandler(null); | ||
58 | |||
59 | Assert.AreEqual(new string[] { }, handler.Handle("/assets", null, null, null), "Failed on empty params."); | ||
60 | Assert.AreEqual(new string[] { }, handler.Handle("/assets/", null, null, null ), "Failed on single slash."); | ||
39 | } | 61 | } |
40 | 62 | ||
63 | [Test] | ||
64 | public void TestHandleMalformedGuid() | ||
65 | { | ||
66 | byte[] emptyResult = new byte[] {}; | ||
67 | GetAssetStreamHandler handler = new GetAssetStreamHandler(null); | ||
68 | |||
69 | Assert.AreEqual(new string[] {}, handler.Handle("/assets/badGuid", null, null, null), "Failed on bad guid."); | ||
70 | } | ||
71 | |||
72 | //[Test] | ||
73 | //public void TestHandleFetchMissingAsset() | ||
74 | //{ | ||
75 | |||
76 | // byte[] emptyResult = new byte[] { }; | ||
77 | // GetAssetStreamHandler handler = new GetAssetStreamHandler(null); | ||
78 | |||
79 | // Assert.AreEqual(new string[] { }, handler.Handle("/assets/badGuid", null, null, null), "Failed on bad guid."); | ||
80 | //} | ||
41 | } | 81 | } |
42 | } | 82 | } |