Skip to content

Commit

Permalink
test creating a directory with permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-knozderko committed Jan 2, 2025
1 parent 99907c3 commit 867e953
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,31 @@ public void TestChangeCacheDirPermissionsWhenInsecure()
}
}

[Test]
public void TestCreateDirectoryWithSecurePermissions()
{
// arrange
var tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
t_environmentOperations
.Setup(e => e.GetEnvironmentVariable(SFCredentialManagerFileStorage.CredentialCacheDirectoryEnvironmentName))
.Returns(tempDirectory);
_credentialManager = CreateFileCredentialManagerWithMockedEnvironmentalVariables();
try
{
// act
_credentialManager.SaveCredentials("key", "token");
var result = _credentialManager.GetCredentials("key");

// assert
Assert.AreEqual("token", result);
Assert.AreEqual(FileAccessPermissions.UserReadWriteExecute, UnixOperations.Instance.GetDirectoryInfo(tempDirectory).Permissions);
}
finally
{
DirectoryOperations.Instance.Delete(tempDirectory, true);
}
}

private SFCredentialManagerFileImpl CreateFileCredentialManagerWithMockedEnvironmentalVariables() =>
new (FileOperations.Instance, DirectoryOperations.Instance, UnixOperations.Instance, t_environmentOperations.Object);
}
Expand Down

0 comments on commit 867e953

Please sign in to comment.