Skip to content

Commit

Permalink
Refactor checking directory permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-lf committed Jan 30, 2024
1 parent 6524998 commit 59945da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void TestThatThrowsErrorWhenLogPathIsNotSetAndHomeDirectoryThrowsAnExcept
}

[Test]
public void TestThatDoesNotFailWhenDirectoryPermissionIsNot600Or700()
public void TestThatDoesNotFailWhenExistingDirectoryContainsUnexpectedPermissions()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Expand All @@ -137,8 +137,8 @@ public void TestThatDoesNotFailWhenDirectoryPermissionIsNot600Or700()
.Setup(provider => provider.ProvideConfig(ConfigPath))
.Returns(s_configWithInfoLevel);
t_directoryOperations
.Setup(dir => dir.Exists(ConfigPath))
.Returns(false);
.Setup(dir => dir.Exists(s_expectedLogPath))
.Returns(true);
t_unixOperations
.Setup(unix => unix.GetDirPermissions(s_expectedLogPath))
.Returns(FileAccessPermissions.AllPermissions);
Expand All @@ -148,7 +148,7 @@ public void TestThatDoesNotFailWhenDirectoryPermissionIsNot600Or700()

// assert
t_unixOperations.Verify(u => u.CreateDirectoryWithPermissions(s_expectedLogPath,
FilePermissions.S_IRUSR | FilePermissions.S_IWUSR | FilePermissions.S_IXUSR), Times.Once);
FilePermissions.S_IRUSR | FilePermissions.S_IWUSR | FilePermissions.S_IXUSR), Times.Never);
}

[Test]
Expand Down
5 changes: 4 additions & 1 deletion Snowflake.Data/Core/Session/EasyLoggingStarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,12 @@ private string GetLogPath(string logPath)
}
_unixOperations.CreateDirectoryWithPermissions(pathWithDotnetSubdirectory,
FilePermissions.S_IRUSR | FilePermissions.S_IWUSR | FilePermissions.S_IXUSR);
CheckDirPermissionsOnlyAllowUser(pathWithDotnetSubdirectory);
}
}
else
{
CheckDirPermissionsOnlyAllowUser(pathWithDotnetSubdirectory);
}

return pathWithDotnetSubdirectory;
}
Expand Down

0 comments on commit 59945da

Please sign in to comment.