aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/Servers/GetAssetStreamHandler.cs7
-rw-r--r--OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs7
-rw-r--r--OpenSim/Framework/Servers/HttpServer/Tests/BaseRequestHandlerTests.cs43
-rw-r--r--OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs39
-rw-r--r--OpenSim/Tests/Common/BaseRequestHandlerTestHelper.cs44
5 files changed, 104 insertions, 36 deletions
diff --git a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs b/OpenSim/Framework/Servers/GetAssetStreamHandler.cs
index 1b87496..ba0355c 100644
--- a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs
+++ b/OpenSim/Framework/Servers/GetAssetStreamHandler.cs
@@ -126,13 +126,6 @@ namespace OpenSim.Framework.Servers
126 return result; 126 return result;
127 } 127 }
128 128
129 public string[] SplitParams(string path)
130 {
131 string param = GetParam(path);
132
133 return param.Split(new char[] { '/', '?', '&' }, StringSplitOptions.RemoveEmptyEntries);
134 }
135
136 // private byte[] ProcessOutgoingAssetData(byte[] assetData) 129 // private byte[] ProcessOutgoingAssetData(byte[] assetData)
137 // { 130 // {
138 // string data = Encoding.ASCII.GetString(assetData); 131 // string data = Encoding.ASCII.GetString(assetData);
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs b/OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs
index da4f9a8..c47a44a 100644
--- a/OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs
+++ b/OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs
@@ -75,5 +75,12 @@ namespace OpenSim.Framework.Servers.HttpServer
75 75
76 return path.StartsWith(Path); 76 return path.StartsWith(Path);
77 } 77 }
78
79 public string[] SplitParams(string path)
80 {
81 string param = GetParam(path);
82
83 return param.Split(new char[] { '/', '?', '&' }, StringSplitOptions.RemoveEmptyEntries);
84 }
78 } 85 }
79} 86}
diff --git a/OpenSim/Framework/Servers/HttpServer/Tests/BaseRequestHandlerTests.cs b/OpenSim/Framework/Servers/HttpServer/Tests/BaseRequestHandlerTests.cs
new file mode 100644
index 0000000..14998c5
--- /dev/null
+++ b/OpenSim/Framework/Servers/HttpServer/Tests/BaseRequestHandlerTests.cs
@@ -0,0 +1,43 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using NUnit.Framework;
5using OpenSim.Tests.Common;
6
7namespace OpenSim.Framework.Servers.HttpServer.Tests
8{
9 [TestFixture]
10 public class BaseRequestHandlerTests
11 {
12 private const string BASE_PATH = "/testpath";
13
14 private class BaseRequestHandlerImpl : BaseRequestHandler
15 {
16 public BaseRequestHandlerImpl(string httpMethod, string path) : base(httpMethod, path)
17 {
18 }
19 }
20
21 [Test]
22 public void TestConstructor()
23 {
24 BaseRequestHandlerImpl handler = new BaseRequestHandlerImpl( null, null );
25 }
26
27 [Test]
28 public void TestGetParams()
29 {
30 BaseRequestHandlerImpl handler = new BaseRequestHandlerImpl(null, BASE_PATH);
31
32 BaseRequestHandlerTestHelper.BaseTestGetParams(handler, BASE_PATH);
33 }
34
35 [Test]
36 public void TestSplitParams()
37 {
38 BaseRequestHandlerImpl handler = new BaseRequestHandlerImpl(null, BASE_PATH);
39
40 BaseRequestHandlerTestHelper.BaseTestSplitParams(handler, BASE_PATH);
41 }
42 }
43}
diff --git a/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs b/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs
index d3a0368..157a883 100644
--- a/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs
+++ b/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs
@@ -3,13 +3,17 @@ using System.Collections.Generic;
3using System.Text; 3using System.Text;
4using NUnit.Framework; 4using NUnit.Framework;
5using OpenSim.Data; 5using OpenSim.Data;
6using OpenSim.Framework.Servers.HttpServer;
6using OpenSim.Tests.Common; 7using OpenSim.Tests.Common;
7 8
8namespace OpenSim.Framework.Servers.Tests 9namespace OpenSim.Framework.Servers.Tests
9{ 10{
10 [TestFixture] 11 [TestFixture]
11 public class GetAssetStreamHandlerTests 12 public class GetAssetStreamHandlerTests
12 { 13 {
14 private static byte[] EmptyByteArray = new byte[] {};
15 private const string ASSETS_PATH = "/assets";
16
13 [Test] 17 [Test]
14 public void TestConstructor() 18 public void TestConstructor()
15 { 19 {
@@ -24,18 +28,7 @@ namespace OpenSim.Framework.Servers.Tests
24 TestHelper.InMethod(); 28 TestHelper.InMethod();
25 29
26 GetAssetStreamHandler handler = new GetAssetStreamHandler(null); 30 GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
27 31 BaseRequestHandlerTestHelper.BaseTestGetParams(handler, ASSETS_PATH);
28 Assert.AreEqual("", handler.GetParam(null), "Failed on null path.");
29 Assert.AreEqual("", handler.GetParam(""), "Failed on empty path.");
30 Assert.AreEqual("", handler.GetParam("s"), "Failed on short url.");
31 Assert.AreEqual("", handler.GetParam("corruptUrl"), "Failed on corruptUrl.");
32
33 Assert.AreEqual("", handler.GetParam("/assets"));
34 Assert.AreEqual("/", handler.GetParam("/assets/"));
35 Assert.AreEqual("/a", handler.GetParam("/assets/a"));
36 Assert.AreEqual("/b/", handler.GetParam("/assets/b/"));
37 Assert.AreEqual("/c/d", handler.GetParam("/assets/c/d"));
38 Assert.AreEqual("/e/f/", handler.GetParam("/assets/e/f/"));
39 } 32 }
40 33
41 [Test] 34 [Test]
@@ -44,17 +37,7 @@ namespace OpenSim.Framework.Servers.Tests
44 TestHelper.InMethod(); 37 TestHelper.InMethod();
45 38
46 GetAssetStreamHandler handler = new GetAssetStreamHandler(null); 39 GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
47 40 BaseRequestHandlerTestHelper.BaseTestSplitParams(handler, ASSETS_PATH);
48 Assert.AreEqual(new string[] { }, handler.SplitParams(null), "Failed on null.");
49 Assert.AreEqual(new string[] { }, handler.SplitParams(""), "Failed on empty path.");
50 Assert.AreEqual(new string[] { }, handler.SplitParams("corruptUrl"), "Failed on corrupt url.");
51
52 Assert.AreEqual(new string[] { }, handler.SplitParams("/assets"), "Failed on empty params.");
53 Assert.AreEqual(new string[] { }, handler.SplitParams("/assets/"), "Failed on single slash.");
54 Assert.AreEqual(new string[] { "a" }, handler.SplitParams("/assets/a"), "Failed on first segment.");
55 Assert.AreEqual(new string[] { "b" }, handler.SplitParams("/assets/b/"), "Failed on second slash.");
56 Assert.AreEqual(new string[] { "c", "d" }, handler.SplitParams("/assets/c/d"), "Failed on second segment.");
57 Assert.AreEqual(new string[] { "e", "f" }, handler.SplitParams("/assets/e/f/"), "Failed on trailing slash.");
58 } 41 }
59 42
60 [Test] 43 [Test]
@@ -62,11 +45,10 @@ namespace OpenSim.Framework.Servers.Tests
62 { 45 {
63 TestHelper.InMethod(); 46 TestHelper.InMethod();
64 47
65 byte[] emptyResult = new byte[] {};
66 GetAssetStreamHandler handler = new GetAssetStreamHandler(null); 48 GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
67 49
68 Assert.AreEqual(new string[] { }, handler.Handle("/assets", null, null, null), "Failed on empty params."); 50 Assert.AreEqual(EmptyByteArray, handler.Handle(ASSETS_PATH, null, null, null), "Failed on empty params.");
69 Assert.AreEqual(new string[] { }, handler.Handle("/assets/", null, null, null ), "Failed on single slash."); 51 Assert.AreEqual(EmptyByteArray, handler.Handle(ASSETS_PATH + "/", null, null, null), "Failed on single slash.");
70 } 52 }
71 53
72 [Test] 54 [Test]
@@ -74,10 +56,9 @@ namespace OpenSim.Framework.Servers.Tests
74 { 56 {
75 TestHelper.InMethod(); 57 TestHelper.InMethod();
76 58
77 byte[] emptyResult = new byte[] {};
78 GetAssetStreamHandler handler = new GetAssetStreamHandler(null); 59 GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
79 60
80 Assert.AreEqual(new string[] {}, handler.Handle("/assets/badGuid", null, null, null), "Failed on bad guid."); 61 Assert.AreEqual(EmptyByteArray, handler.Handle(ASSETS_PATH + "/badGuid", null, null, null), "Failed on bad guid.");
81 } 62 }
82 63
83 //[Test] 64 //[Test]
diff --git a/OpenSim/Tests/Common/BaseRequestHandlerTestHelper.cs b/OpenSim/Tests/Common/BaseRequestHandlerTestHelper.cs
new file mode 100644
index 0000000..4052920
--- /dev/null
+++ b/OpenSim/Tests/Common/BaseRequestHandlerTestHelper.cs
@@ -0,0 +1,44 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using NUnit.Framework;
5using OpenSim.Framework.Servers;
6using OpenSim.Framework.Servers.HttpServer;
7
8namespace OpenSim.Tests.Common
9{
10 public class BaseRequestHandlerTestHelper
11 {
12 private static string[] m_emptyStringArray = new string[] { };
13
14 public static void BaseTestGetParams(BaseRequestHandler handler, string assetsPath)
15 {
16 Assert.AreEqual(String.Empty, handler.GetParam(null), "Failed on null path.");
17 Assert.AreEqual(String.Empty, handler.GetParam(""), "Failed on empty path.");
18 Assert.AreEqual(String.Empty, handler.GetParam("s"), "Failed on short url.");
19 Assert.AreEqual(String.Empty, handler.GetParam("corruptUrl"), "Failed on corruptUrl.");
20
21 Assert.AreEqual(String.Empty, handler.GetParam(assetsPath));
22 Assert.AreEqual("/", handler.GetParam(assetsPath + "/"));
23 Assert.AreEqual("/a", handler.GetParam(assetsPath + "/a"));
24 Assert.AreEqual("/b/", handler.GetParam(assetsPath + "/b/"));
25 Assert.AreEqual("/c/d", handler.GetParam(assetsPath + "/c/d"));
26 Assert.AreEqual("/e/f/", handler.GetParam(assetsPath + "/e/f/"));
27 }
28
29 public static void BaseTestSplitParams(BaseRequestHandler handler, string assetsPath)
30 {
31 Assert.AreEqual(m_emptyStringArray, handler.SplitParams(null), "Failed on null.");
32 Assert.AreEqual(m_emptyStringArray, handler.SplitParams(""), "Failed on empty path.");
33 Assert.AreEqual(m_emptyStringArray, handler.SplitParams("corruptUrl"), "Failed on corrupt url.");
34
35 Assert.AreEqual(m_emptyStringArray, handler.SplitParams(assetsPath), "Failed on empty params.");
36 Assert.AreEqual(m_emptyStringArray, handler.SplitParams(assetsPath + "/"), "Failed on single slash.");
37
38 Assert.AreEqual(new string[] { "a" }, handler.SplitParams(assetsPath + "/a"), "Failed on first segment.");
39 Assert.AreEqual(new string[] { "b" }, handler.SplitParams(assetsPath + "/b/"), "Failed on second slash.");
40 Assert.AreEqual(new string[] { "c", "d" }, handler.SplitParams(assetsPath + "/c/d"), "Failed on second segment.");
41 Assert.AreEqual(new string[] { "e", "f" }, handler.SplitParams(assetsPath + "/e/f/"), "Failed on trailing slash.");
42 }
43 }
44}