LibHac/tests/LibHac.Tests/FsSrv/AccessControlTests.cs

63 lines
2.4 KiB
C#
Raw Permalink Normal View History

using LibHac.Common;
using LibHac.Fs;
using LibHac.Fs.Shim;
using LibHac.FsSrv.Impl;
using LibHac.Ncm;
using Xunit;
using ContentType = LibHac.Fs.ContentType;
2021-11-14 20:08:57 +01:00
namespace LibHac.Tests.FsSrv;
public class AccessControlTests
{
2021-11-14 20:08:57 +01:00
[Fact]
public void OpenFileSystemWithNoPermissions_ReturnsPermissionDenied()
{
2021-11-14 20:08:57 +01:00
Horizon hos = HorizonFactory.CreateBasicHorizon();
2021-11-14 20:08:57 +01:00
HorizonClient regClient = hos.CreatePrivilegedHorizonClient();
HorizonClient client = hos.CreateHorizonClient();
2021-11-14 20:08:57 +01:00
var dataHeader = new AccessControlDataHeader();
var descriptor = new AccessControlDescriptor();
2021-11-14 20:08:57 +01:00
descriptor.Version = 123;
dataHeader.Version = 123;
2021-11-14 20:08:57 +01:00
descriptor.AccessFlags = (ulong)AccessControlBits.Bits.None;
dataHeader.AccessFlags = (ulong)AccessControlBits.Bits.None;
2021-11-14 20:08:57 +01:00
Assert.Success(regClient.Fs.RegisterProgram(client.ProcessId.Value, new ProgramId(123),
StorageId.BuiltInUser, SpanHelpers.AsReadOnlyByteSpan(in dataHeader),
SpanHelpers.AsReadOnlyByteSpan(in descriptor)));
2024-04-01 08:27:06 +02:00
Result res = client.Fs.MountContent("test"u8, "@System:/fake.nca"u8, ContentAttributes.None, ContentType.Meta);
Assert.Result(ResultFs.PermissionDenied, res);
2021-11-14 20:08:57 +01:00
}
2021-11-14 20:08:57 +01:00
[Fact]
public void OpenFileSystemWithPermissions_ReturnsInvalidNcaMountPoint()
{
Horizon hos = HorizonFactory.CreateBasicHorizon();
2021-11-14 20:08:57 +01:00
HorizonClient regClient = hos.CreatePrivilegedHorizonClient();
HorizonClient client = hos.CreateHorizonClient();
2021-11-14 20:08:57 +01:00
var dataHeader = new AccessControlDataHeader();
var descriptor = new AccessControlDescriptor();
2021-11-14 20:08:57 +01:00
descriptor.Version = 123;
dataHeader.Version = 123;
2021-11-14 20:08:57 +01:00
descriptor.AccessFlags = (ulong)AccessControlBits.Bits.ApplicationInfo;
dataHeader.AccessFlags = (ulong)AccessControlBits.Bits.ApplicationInfo;
2021-11-14 20:08:57 +01:00
Assert.Success(regClient.Fs.RegisterProgram(client.ProcessId.Value, new ProgramId(123),
StorageId.BuiltInUser, SpanHelpers.AsReadOnlyByteSpan(in dataHeader),
SpanHelpers.AsReadOnlyByteSpan(in descriptor)));
2021-11-14 20:08:57 +01:00
// We should get UnexpectedInNcaFileSystemServiceImplA because mounting NCAs from @System isn't allowed
2024-04-01 08:27:06 +02:00
Result res = client.Fs.MountContent("test"u8, "@System:/fake.nca"u8, ContentAttributes.None, ContentType.Meta);
Assert.Result(ResultFs.UnexpectedInNcaFileSystemServiceImplA, res);
}
}