Skip to content

Commit 4e57aff

Browse files
authored
msg update and adding separator for directory access (#607)
* msg update and adding separator for directory access * test msg update
1 parent c5ee132 commit 4e57aff

7 files changed

Lines changed: 26 additions & 5 deletions

File tree

src/Microsoft.PowerApps.TestEngine.Tests/Config/YamlTestConfigParserTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ public void YamlTestConfigParserThrowsOnInvalidFilePath()
381381
var ex = Assert.Throws<UserInputException>(() => parser.ParseTestConfig<TestSettings>("some invalid file path", MockLogger.Object));
382382
Assert.Equal(ex.Message, UserInputException.ErrorMapping.UserInputExceptionInvalidFilePath.ToString());
383383
// Verify the message is logged in this case
384-
LoggingTestHelper.VerifyLogging(MockLogger, "Invalid file path: TestSettings in test config file.", LogLevel.Error, Times.Once());
384+
LoggingTestHelper.VerifyLogging(MockLogger, "Test config file path is invalid or access is not permitted. For more details, check the logs and refer https://aka.ms/pactests/fileaccessrestrictions.", LogLevel.Error, Times.Once());
385385
}
386386

387387
[Fact]

src/Microsoft.PowerApps.TestEngine.Tests/System/FileSystemTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void Dispose()
6262
[InlineData(@"C:\folder\PRN.yaml", false)]
6363
[InlineData(@"C:\WINDOWS\system32", false)]
6464
[InlineData(@"C:\folder\file.com", false)]
65+
[InlineData(@"C:\Users\Public\Videos\test.yaml", false)]
6566
public void CanAccessFilePathTest_Windows(string? filePath, bool expectedResult)
6667
{
6768
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))

src/Microsoft.PowerApps.TestEngine/Config/YamlTestConfigParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public T ParseTestConfig<T>(string testConfigFilePath, ILogger logger)
3131

3232
if (!_fileSystem.FileExists(testConfigFilePath))
3333
{
34-
logger.LogError($"Invalid file path: {typeof(T).Name} in test config file.");
34+
logger.LogError($"Test config file path is invalid or access is not permitted. For more details, check the logs and refer https://aka.ms/pactests/fileaccessrestrictions.");
3535
throw new UserInputException(UserInputException.ErrorMapping.UserInputExceptionInvalidFilePath.ToString());
3636
}
3737

src/Microsoft.PowerApps.TestEngine/PowerFx/Functions/ScreenshotFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public BlankValue Execute(StringValue file)
3838
var testResultDirectory = _singleTestInstanceState.GetTestResultsDirectory();
3939
if (!_fileSystem.Exists(testResultDirectory))
4040
{
41-
_logger.LogError("Test result directory needs to be set.");
41+
_logger.LogError("Test result directory needs to be set and accessible.");
4242
throw new InvalidOperationException();
4343
}
4444

src/Microsoft.PowerApps.TestEngine/System/FileSystem.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ public bool WindowsReservedLocationExistsInPath(string fullPath)
233233
{
234234
return true;
235235
}
236+
// Ensure the path ends with a directory separator
237+
if (!fullPath.EndsWith(Path.DirectorySeparatorChar.ToString()) && !fullPath.EndsWith(Path.AltDirectorySeparatorChar.ToString()))
238+
{
239+
fullPathUri = new Uri(fullPathUri.ToString().TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) + Path.DirectorySeparatorChar, UriKind.Absolute);
240+
}
236241

237242
//check if any of reserved base locations referred then fail
238243
IEnumerable<Uri> windowsRestrictedPaths = new List<Uri>
@@ -304,6 +309,11 @@ public bool LinuxReservedLocationExistsInPath(string fullPath)
304309
{
305310
return true;
306311
}
312+
// Ensure the path ends with a directory separator
313+
if (!fullPath.EndsWith(Path.DirectorySeparatorChar.ToString()) && !fullPath.EndsWith(Path.AltDirectorySeparatorChar.ToString()))
314+
{
315+
fullPathUri = new Uri(fullPathUri.ToString().TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) + Path.DirectorySeparatorChar, UriKind.Absolute);
316+
}
307317

308318
IEnumerable<Uri> LinuxRestrictedPaths = new List<Uri>
309319
{
@@ -354,12 +364,22 @@ public bool LinuxReservedLocationExistsInPath(string fullPath)
354364
public bool OsxReservedLocationExistsInPath(string fullPath)
355365
{
356366
fullPath = Path.GetFullPath(fullPath);
367+
368+
if (fullPath.Equals("/"))
369+
{
370+
return true;
371+
}
357372
//check if its a network path if so fail
358373
var fullPathUri = new Uri(fullPath.StartsWith(@"\\?\") ? fullPath.Replace(@"\\?\", "") : fullPath, UriKind.Absolute);
359374
if (fullPathUri.IsUnc)
360375
{
361376
return true;
362377
}
378+
// Ensure the path ends with a directory separator
379+
if (!fullPath.EndsWith(Path.DirectorySeparatorChar.ToString()) && !fullPath.EndsWith(Path.AltDirectorySeparatorChar.ToString()))
380+
{
381+
fullPathUri = new Uri(fullPathUri.ToString().TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) + Path.DirectorySeparatorChar, UriKind.Absolute);
382+
}
363383

364384
IEnumerable<Uri> OsxRestrictedPaths = new List<Uri>
365385
{

src/Microsoft.PowerApps.TestEngine/TestEngineEventHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class TestEngineEventHandler : ITestEngineEvents
1818
// NOTE: Any changes to these messages need to be handled in the consuming tool's console event handler, like in pac cli tool.
1919
// These console messages need to be considered for localization.
2020
public static string UserAppExceptionMessage = " [Critical Error] Could not access Provider. For more details, check the logs.";
21-
public static string UserInputExceptionInvalidFilePathMessage = " Invalid file path. For more details, check the logs.";
21+
public static string UserInputExceptionInvalidFilePathMessage = " File path is invalid or access is not permitted. For more details, check the logs and refer https://aka.ms/pactests/fileaccessrestrictions.";
2222
public static string UserInputExceptionInvalidOutputPathMessage = " [Critical Error]: The output directory provided is invalid.";
2323
public static string UserInputExceptionInvalidTestSettingsMessage = " Invalid test settings specified in testconfig. For more details, check the logs.";
2424
public static string UserInputExceptionLoginCredentialMessage = " Invalid login credential(s). For more details, check the logs.";

src/testengine.module.playwrightaction/PlaywrightActionValueFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public BooleanValue Execute(StringValue locator, StringValue action, StringValue
7474
var testResultDirectory = _singleTestInstanceState.GetTestResultsDirectory();
7575
if (!_fileSystem.Exists(testResultDirectory))
7676
{
77-
_logger.LogError("Test result directory needs to be set.");
77+
_logger.LogError("Test result directory needs to be set and accessible.");
7878
throw new InvalidOperationException();
7979
}
8080

0 commit comments

Comments
 (0)