U4-7042 - bugfix the physical filesystem

This commit is contained in:
Stephan
2015-09-03 15:11:49 +02:00
parent 37e6e61eff
commit b03d7884bb
5 changed files with 84 additions and 25 deletions

View File

@@ -27,6 +27,8 @@ namespace Umbraco.Tests.IO
public void TearDown()
{
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileSysTests");
if (Directory.Exists(path) == false) return;
var files = Directory.GetFiles(path);
foreach (var f in files)
{
@@ -39,5 +41,31 @@ namespace Umbraco.Tests.IO
{
return "/Media/" + path;
}
[Test]
public void GetFullPathTest()
{
// outside of tests, one initializes the PhysicalFileSystem with eg ~/Dir
// and then, rootPath = /path/to/Dir and rootUrl = /Dir/
// here we initialize the PhysicalFileSystem with
// rootPath = /path/to/FileSysTests
// rootUrl = /Media/
var basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileSysTests");
// ensure that GetFullPath
// - does return the proper full path
// - does properly normalize separators
// - does throw on invalid paths
var path = _fileSystem.GetFullPath("foo.tmp");
Assert.AreEqual(Path.Combine(basePath, @"foo.tmp"), path);
path = _fileSystem.GetFullPath("foo/bar.tmp");
Assert.AreEqual(Path.Combine(basePath, @"foo\bar.tmp"), path);
// that path is invalid as it would be outside the root directory
Assert.Throws<FileSecurityException>(() => _fileSystem.GetFullPath("../../foo.tmp"));
}
}
}