2020-08-24 08:35:00 +02:00
|
|
|
|
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
|
2020-08-24 08:35:00 +02:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void OpenFileSystemWithNoPermissions_ReturnsPermissionDenied()
|
2020-08-24 08:35:00 +02:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Horizon hos = HorizonFactory.CreateBasicHorizon();
|
2020-08-24 08:35:00 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
HorizonClient regClient = hos.CreatePrivilegedHorizonClient();
|
|
|
|
|
HorizonClient client = hos.CreateHorizonClient();
|
2020-08-24 08:35:00 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
var dataHeader = new AccessControlDataHeader();
|
|
|
|
|
var descriptor = new AccessControlDescriptor();
|
2020-08-24 08:35:00 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
descriptor.Version = 123;
|
|
|
|
|
dataHeader.Version = 123;
|
2020-08-24 08:35:00 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
descriptor.AccessFlags = (ulong)AccessControlBits.Bits.None;
|
|
|
|
|
dataHeader.AccessFlags = (ulong)AccessControlBits.Bits.None;
|
2020-08-24 08:35:00 +02:00
|
|
|
|
|
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)));
|
2020-08-24 08:35:00 +02:00
|
|
|
|
|
2022-12-01 07:28:02 +01:00
|
|
|
|
Result res = client.Fs.MountContent("test"u8, "@System:/fake.nca"u8, ContentType.Meta);
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Assert.Result(ResultFs.PermissionDenied, res);
|
2021-11-14 20:08:57 +01:00
|
|
|
|
}
|
2020-08-24 08:35:00 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void OpenFileSystemWithPermissions_ReturnsInvalidNcaMountPoint()
|
|
|
|
|
{
|
|
|
|
|
Horizon hos = HorizonFactory.CreateBasicHorizon();
|
2020-08-24 08:35:00 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
HorizonClient regClient = hos.CreatePrivilegedHorizonClient();
|
|
|
|
|
HorizonClient client = hos.CreateHorizonClient();
|
2020-08-24 08:35:00 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
var dataHeader = new AccessControlDataHeader();
|
|
|
|
|
var descriptor = new AccessControlDescriptor();
|
2020-08-24 08:35:00 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
descriptor.Version = 123;
|
|
|
|
|
dataHeader.Version = 123;
|
2020-08-24 08:35:00 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
descriptor.AccessFlags = (ulong)AccessControlBits.Bits.ApplicationInfo;
|
|
|
|
|
dataHeader.AccessFlags = (ulong)AccessControlBits.Bits.ApplicationInfo;
|
2020-08-24 08:35:00 +02:00
|
|
|
|
|
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)));
|
2020-08-24 08:35:00 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
// We should get UnexpectedInNcaFileSystemServiceImplA because mounting NCAs from @System isn't allowed
|
2022-12-01 07:28:02 +01:00
|
|
|
|
Result res = client.Fs.MountContent("test"u8, "@System:/fake.nca"u8, ContentType.Meta);
|
2022-11-10 05:33:27 +01:00
|
|
|
|
Assert.Result(ResultFs.UnexpectedInNcaFileSystemServiceImplA, res);
|
2020-08-24 08:35:00 +02:00
|
|
|
|
}
|
2022-01-17 02:43:12 +01:00
|
|
|
|
}
|