* Added some more GetAssetStreamHandlerTests

* In the process, caught a potential bug where the handler would allow paths not starting with the registered prefix
0.6.5-rc1
lbsa71 2009-05-07 06:31:16 +00:00
parent 1352a19838
commit f3db3d6a00
2 changed files with 52 additions and 4 deletions

View File

@ -58,14 +58,22 @@ namespace OpenSim.Framework.Servers.HttpServer
public string GetParam(string path) public string GetParam(string path)
{ {
try if (CheckParam(path))
{ {
return path.Substring(m_path.Length); return path.Substring(m_path.Length);
} }
catch (Exception)
return String.Empty;
}
protected bool CheckParam(string path)
{
if(String.IsNullOrEmpty(path))
{ {
return String.Empty; return false;
} }
return path.StartsWith(Path);
} }
} }
} }

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using NUnit.Framework; using NUnit.Framework;
using OpenSim.Data;
namespace OpenSim.Framework.Servers.Tests namespace OpenSim.Framework.Servers.Tests
{ {
@ -19,6 +20,11 @@ namespace OpenSim.Framework.Servers.Tests
{ {
GetAssetStreamHandler handler = new GetAssetStreamHandler(null); GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
Assert.AreEqual("", handler.GetParam(null), "Failed on null path.");
Assert.AreEqual("", handler.GetParam(""), "Failed on empty path.");
Assert.AreEqual("", handler.GetParam("s"), "Failed on short url.");
Assert.AreEqual("", handler.GetParam("corruptUrl"), "Failed on corruptUrl.");
Assert.AreEqual("", handler.GetParam("/assets")); Assert.AreEqual("", handler.GetParam("/assets"));
Assert.AreEqual("/", handler.GetParam("/assets/")); Assert.AreEqual("/", handler.GetParam("/assets/"));
Assert.AreEqual("/a", handler.GetParam("/assets/a")); Assert.AreEqual("/a", handler.GetParam("/assets/a"));
@ -32,11 +38,45 @@ namespace OpenSim.Framework.Servers.Tests
{ {
GetAssetStreamHandler handler = new GetAssetStreamHandler(null); GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
Assert.AreEqual(new string[] { }, handler.SplitParams(null), "Failed on null.");
Assert.AreEqual(new string[] { }, handler.SplitParams(""), "Failed on empty path.");
Assert.AreEqual(new string[] { }, handler.SplitParams("corruptUrl"), "Failed on corrupt url.");
Assert.AreEqual(new string[] { }, handler.SplitParams("/assets"), "Failed on empty params."); Assert.AreEqual(new string[] { }, handler.SplitParams("/assets"), "Failed on empty params.");
Assert.AreEqual(new string[] { }, handler.SplitParams("/assets/"), "Failed on single slash."); Assert.AreEqual(new string[] { }, handler.SplitParams("/assets/"), "Failed on single slash.");
Assert.AreEqual(new string[] { "a" }, handler.SplitParams("/assets/a"), "Failed on first segment."); Assert.AreEqual(new string[] { "a" }, handler.SplitParams("/assets/a"), "Failed on first segment.");
Assert.AreEqual(new string[] { "b" }, handler.SplitParams("/assets/b/"), "Failed on second slash."); Assert.AreEqual(new string[] { "b" }, handler.SplitParams("/assets/b/"), "Failed on second slash.");
Assert.AreEqual(new string[] { "c", "d" }, handler.SplitParams("/assets/c/d"), "Failed on second segment.");
Assert.AreEqual(new string[] { "e", "f" }, handler.SplitParams("/assets/e/f/"), "Failed on trailing slash.");
} }
[Test]
public void TestHandleNoParams()
{
byte[] emptyResult = new byte[] {};
GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
Assert.AreEqual(new string[] { }, handler.Handle("/assets", null, null, null), "Failed on empty params.");
Assert.AreEqual(new string[] { }, handler.Handle("/assets/", null, null, null ), "Failed on single slash.");
}
[Test]
public void TestHandleMalformedGuid()
{
byte[] emptyResult = new byte[] {};
GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
Assert.AreEqual(new string[] {}, handler.Handle("/assets/badGuid", null, null, null), "Failed on bad guid.");
}
//[Test]
//public void TestHandleFetchMissingAsset()
//{
// byte[] emptyResult = new byte[] { };
// GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
// Assert.AreEqual(new string[] { }, handler.Handle("/assets/badGuid", null, null, null), "Failed on bad guid.");
//}
} }
} }