Files
RobustToolbox/Robust.UnitTesting/Shared/Resources/WritableDirProviderTest.cs
T
PJB3005 5a24576d78 Squashed commit of the following:
commit d4f265c314
Author: PJB3005 <pieterjan.briers+git@gmail.com>
Date:   Sun Sep 14 14:32:44 2025 +0200

    Fix incorrect path combine in DirLoader and WritableDirProvider

    This (and the other couple past commits) reported by Elelzedel.

commit 7654d38612
Author: PJB3005 <pieterjan.briers+git@gmail.com>
Date:   Sat Sep 13 22:50:51 2025 +0200

    Move CEF cache out of data directory

    Don't want content messing with this...

commit cdcc255123
Author: PJB3005 <pieterjan.briers+git@gmail.com>
Date:   Sat Sep 13 19:11:16 2025 +0200

    Make Robust.Client.WebView.Cef.Program internal.

commit 2f56a6a110
Author: PJB3005 <pieterjan.briers+git@gmail.com>
Date:   Sat Sep 13 19:10:46 2025 +0200

    Update SpaceWizards.NFluidSynth to 0.2.2

commit 16fc48cef2
Author: PJB3005 <pieterjan.briers+git@gmail.com>
Date:   Sat Sep 13 19:09:43 2025 +0200

    Hide IWritableDirProvider.RootDir on client

    This shouldn't be exposed.

(cherry picked from commit 2f07159336bc640e41fbbccfdec4133a68c13bdb)
(cherry picked from commit d6c3212c74373ed2420cc4be2cf10fcd899c2106)
(cherry picked from commit bfa70d7e2ca6758901b680547fcfa9b24e0610b7)
(cherry picked from commit 06e52f5d58efc1491915822c2650f922673c82c6)
2025-09-14 14:55:48 +02:00

66 lines
2.0 KiB
C#

using System;
using System.IO;
using NUnit.Framework;
using Robust.Shared.ContentPack;
using Robust.Shared.Utility;
namespace Robust.UnitTesting.Shared.Resources
{
[TestFixture]
[TestOf(typeof(WritableDirProvider))]
public sealed class WritableDirProviderTest
{
private string _testDirPath = default!;
private DirectoryInfo _testDir = default!;
private WritableDirProvider _dirProvider = default!;
[OneTimeSetUp]
public void Setup()
{
var tmpPath = Path.GetTempPath();
var guid = Guid.NewGuid();
_testDirPath = Path.Combine(tmpPath, guid.ToString());
_testDir = Directory.CreateDirectory(_testDirPath);
var subDir = Path.Combine(_testDirPath, "writable");
_dirProvider = new WritableDirProvider(Directory.CreateDirectory(subDir), hideRootDir: false);
}
[OneTimeTearDown]
public void TearDown()
{
_testDir.Delete(true);
}
[Test]
public void TestNoParentAccess()
{
File.WriteAllText(Path.Combine(_testDirPath, "dummy"), "foobar");
// No, ../ does not work to read stuff in the parent dir.
Assert.That(() => _dirProvider.ReadAllText(new ResPath("/../dummy")),
Throws.InstanceOf<FileNotFoundException>());
}
[Test]
public void TestNotRooted()
{
// Path must be rooted.
Assert.That(() => _dirProvider.OpenRead(new ResPath("foo.bar")),
Throws.InstanceOf<ArgumentException>());
}
[Test]
public void TestParentAccessClamped()
{
File.WriteAllText(Path.Combine(_testDirPath, "dummy"), "foobar");
_dirProvider.WriteAllText(new ResPath("/dummy"), "pranked");
// ../ should get clamped to /.
Assert.That(_dirProvider.ReadAllText(new ResPath("/../dummy")), Is.EqualTo("pranked"));
}
}
}