Skip to content

Commit 50b10df

Browse files
committed
Fix build
1 parent 159d175 commit 50b10df

5 files changed

Lines changed: 36 additions & 12 deletions

File tree

‎.github/workflows/dotnet-secure-file-tests.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ jobs:
3030
- name: Test secure file operations
3131
run: >-
3232
dotnet test dotnet/src/Plugins/Plugins.UnitTests/Plugins.UnitTests.csproj
33-
--filter "FullyQualifiedName~SecureFileSystemTests|FullyQualifiedName~FileIOPluginTests|FullyQualifiedName~SessionsPythonPluginTests|FullyQualifiedName~WebFileDownloadPluginTests|FullyQualifiedName~CloudDrivePluginTests|FullyQualifiedName~DocumentPluginTests|FullyQualifiedName~LocalFileSystemConnectorTests|FullyQualifiedName~OneDriveConnectorTests"
33+
--filter "FullyQualifiedName~SecureFileSystemTests|FullyQualifiedName~FileIOPluginTests|FullyQualifiedName~SessionsPythonPluginTests|FullyQualifiedName~WebFileDownloadPluginTests|FullyQualifiedName~CloudDrivePluginTests|FullyQualifiedName~DocumentPluginTests|FullyQualifiedName~LocalFileSystemConnectorTests|FullyQualifiedName~OneDriveConnectorTests|FullyQualifiedName~PathUtilitiesTests"

‎dotnet/src/InternalUtilities/src/System/SecureFileSystem.cs‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ internal static SafeFileHandle Open(
232232
{
233233
created = false;
234234
var directoryFlags = GetDirectoryFlags();
235-
var currentHandle = OpenPath("/", directoryFlags, 0);
235+
var currentHandle = OpenPath("/", directoryFlags);
236236

237237
try
238238
{
@@ -347,9 +347,9 @@ private static string[] GetSegmentsAfterRoot(string path)
347347
StringSplitOptions.RemoveEmptyEntries);
348348
}
349349

350-
private static SafeFileHandle OpenPath(string path, int flags, uint mode)
350+
private static SafeFileHandle OpenPath(string path, int flags)
351351
{
352-
var descriptor = OpenNative(path, flags, mode);
352+
var descriptor = OpenNative(path, flags);
353353
return CreateHandle(descriptor, path);
354354
}
355355

@@ -359,6 +359,21 @@ private static SafeFileHandle OpenAt(SafeFileHandle directory, string path, int
359359
return CreateHandle(descriptor, path);
360360
}
361361

362+
private static int OpenAtNative(SafeFileHandle directory, string path, int flags, uint mode)
363+
{
364+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) &&
365+
RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
366+
{
367+
// Apple's ARM64 openat reads its optional permissions argument from the stack,
368+
// not a register. Fill the five remaining argument registers so this fixed
369+
// P/Invoke signature puts mode on the stack, where the native function expects it.
370+
return OpenAtMacArm64(directory, path, flags,
371+
IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, mode);
372+
}
373+
374+
return OpenAtDefault(directory, path, flags, mode);
375+
}
376+
362377
private static void CheckFile(SafeFileHandle handle, bool rejectReadOnly)
363378
{
364379
ushort mode;
@@ -429,10 +444,15 @@ private static SafeFileHandle CreateHandle(int descriptor, string path)
429444
}
430445

431446
[DllImport("libc", EntryPoint = "open", SetLastError = true)]
432-
private static extern int OpenNative(string path, int flags, uint mode);
447+
private static extern int OpenNative(string path, int flags);
448+
449+
[DllImport("libc", EntryPoint = "openat", SetLastError = true)]
450+
private static extern int OpenAtDefault(SafeFileHandle directoryDescriptor, string path, int flags, uint mode);
433451

434452
[DllImport("libc", EntryPoint = "openat", SetLastError = true)]
435-
private static extern int OpenAtNative(SafeFileHandle directoryDescriptor, string path, int flags, uint mode);
453+
private static extern int OpenAtMacArm64(
454+
SafeFileHandle directoryDescriptor, string path, int flags,
455+
IntPtr unused3, IntPtr unused4, IntPtr unused5, IntPtr unused6, IntPtr unused7, uint mode);
436456

437457
[DllImport("libc", EntryPoint = "flock", SetLastError = true)]
438458
private static extern int Flock(SafeFileHandle descriptor, int operation);

‎dotnet/src/Plugins/Plugins.UnitTests/Core/PathUtilitiesTests.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public sealed class PathUtilitiesTests : IDisposable
1313

1414
public PathUtilitiesTests()
1515
{
16-
this._tempDir = Path.Combine(Path.GetTempPath(), $"PathUtilitiesTests_{Guid.NewGuid():N}");
16+
this._tempDir = Path.Combine(PathUtilities.GetSafeFullPath(Path.GetTempPath()), $"PathUtilitiesTests_{Guid.NewGuid():N}");
1717
Directory.CreateDirectory(this._tempDir);
1818
}
1919

‎dotnet/src/Plugins/Plugins.UnitTests/Document/DocumentPluginTests.cs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.SemanticKernel;
89
using Microsoft.SemanticKernel.Plugins.Document;
910
using Microsoft.SemanticKernel.Plugins.Document.FileSystem;
1011
using Moq;
@@ -21,10 +22,11 @@ public async Task ReadTextAsyncSucceedsAsync()
2122
var expectedText = Guid.NewGuid().ToString();
2223
var folderPath = Path.GetTempPath();
2324
var anyFilePath = Path.Combine(folderPath, Guid.NewGuid().ToString());
25+
var expectedFilePath = PathUtilities.GetSafeFullPath(anyFilePath);
2426

2527
var fileSystemConnectorMock = new Mock<IFileSystemConnector>();
2628
fileSystemConnectorMock
27-
.Setup(mock => mock.GetFileContentStreamAsync(It.Is<string>(filePath => filePath.Equals(anyFilePath, StringComparison.Ordinal)),
29+
.Setup(mock => mock.GetFileContentStreamAsync(It.Is<string>(filePath => filePath.Equals(expectedFilePath, StringComparison.Ordinal)),
2830
It.IsAny<IEnumerable<string>>(),
2931
It.IsAny<CancellationToken>()))
3032
.ReturnsAsync(Stream.Null);
@@ -55,10 +57,11 @@ public async Task AppendTextAsyncFileExistsSucceedsAsync()
5557
var anyText = Guid.NewGuid().ToString();
5658
var folderPath = Path.GetTempPath();
5759
var anyFilePath = Path.Combine(folderPath, Guid.NewGuid().ToString());
60+
var expectedFilePath = PathUtilities.GetSafeFullPath(anyFilePath);
5861

5962
var fileSystemConnectorMock = new Mock<IFileSystemConnector>();
6063
fileSystemConnectorMock
61-
.Setup(mock => mock.OpenUpdateAsync(It.Is<string>(filePath => filePath.Equals(anyFilePath, StringComparison.Ordinal)),
64+
.Setup(mock => mock.OpenUpdateAsync(It.Is<string>(filePath => filePath.Equals(expectedFilePath, StringComparison.Ordinal)),
6265
It.IsAny<IEnumerable<string>>(),
6366
It.IsAny<CancellationToken>()))
6467
.ReturnsAsync((Stream.Null, false));
@@ -87,10 +90,11 @@ public async Task AppendTextAsyncFileDoesNotExistSucceedsAsync()
8790
var anyText = Guid.NewGuid().ToString();
8891
var folderPath = Path.GetTempPath();
8992
var anyFilePath = Path.Combine(folderPath, Guid.NewGuid().ToString());
93+
var expectedFilePath = PathUtilities.GetSafeFullPath(anyFilePath);
9094

9195
var fileSystemConnectorMock = new Mock<IFileSystemConnector>();
9296
fileSystemConnectorMock
93-
.Setup(mock => mock.OpenUpdateAsync(It.Is<string>(filePath => filePath.Equals(anyFilePath, StringComparison.Ordinal)),
97+
.Setup(mock => mock.OpenUpdateAsync(It.Is<string>(filePath => filePath.Equals(expectedFilePath, StringComparison.Ordinal)),
9498
It.IsAny<IEnumerable<string>>(),
9599
It.IsAny<CancellationToken>()))
96100
.ReturnsAsync((Stream.Null, true));

‎dotnet/src/Plugins/Plugins.UnitTests/Web/WebFileDownloadPluginTests.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public async Task DownloadToFileSucceedsAsync()
3737
var filePath = Path.Combine(folderPath, "sk_logo.png");
3838
Directory.CreateDirectory(folderPath);
3939

40-
var webFileDownload = new WebFileDownloadPlugin()
40+
var webFileDownload = new WebFileDownloadPlugin(this._httpClient)
4141
{
4242
AllowedDomains = ["raw.githubusercontent.com"],
4343
AllowedFolders = [folderPath]
@@ -180,7 +180,7 @@ public async Task DownloadToFileFailsForInvalidParametersAsync()
180180
var invalidFilePath = Path.Combine(Path.GetTempPath(), "sk_logo.png");
181181
Directory.CreateDirectory(folderPath);
182182

183-
var webFileDownload = new WebFileDownloadPlugin()
183+
var webFileDownload = new WebFileDownloadPlugin(this._httpClient)
184184
{
185185
AllowedDomains = ["raw.githubusercontent.com"],
186186
AllowedFolders = [folderPath],

0 commit comments

Comments
 (0)