public void GroupPermissions() { // Always throw when used var mockNativeLibraryInterface = new Mock <INativeLibraryInterface>(MockBehavior.Strict); var posixPermissionInfo = new PosixPermissionInfo(mockNativeLibraryInterface.Object, 1, 1000); Assert.Equal(1000, posixPermissionInfo.GroupId); Assert.True(posixPermissionInfo.TryGetGroupPermissions(1000, out _)); posixPermissionInfo.GroupPermissions = FilePermissions.Read; Assert.Equal(FilePermissions.Read, posixPermissionInfo.GroupPermissions); Assert.True(posixPermissionInfo.TryGetGroupPermissions(1000, out FilePermissions ownerPermissions)); Assert.Equal(FilePermissions.Read, ownerPermissions); posixPermissionInfo.SetGroupPermissions(1000, FilePermissions.Write); Assert.True(posixPermissionInfo.TryGetGroupPermissions(1000, out ownerPermissions)); Assert.Equal(FilePermissions.Write, ownerPermissions); posixPermissionInfo.SetGroupPermissions(2000, FilePermissions.Read); Assert.True(posixPermissionInfo.TryGetGroupPermissions(2000, out FilePermissions userPermissions)); Assert.Equal(FilePermissions.Read, userPermissions); Assert.Throws <ArgumentException>(() => posixPermissionInfo.RemoveGroupPermissions(1000)); Assert.False(posixPermissionInfo.TryGetGroupPermissions(3000, out _)); posixPermissionInfo.RemoveGroupPermissions(3000); // Should not throw posixPermissionInfo.RemoveGroupPermissions(2000); Assert.False(posixPermissionInfo.TryGetGroupPermissions(2000, out _)); Assert.Throws <ArgumentNullException>(() => posixPermissionInfo.SetGroupPermissions(null)); posixPermissionInfo.SetGroupPermissions(new[] { new KeyValuePair <int, FilePermissions>(4000, FilePermissions.Execute) }); posixPermissionInfo.GroupId = 4000; Assert.Equal(FilePermissions.Execute, posixPermissionInfo.GroupPermissions); Assert.False(posixPermissionInfo.TryGetGroupPermissions(1000, out _)); }
public void FromNative() { var mockNativeLibraryInterface = new Mock <INativeLibraryInterface>(MockBehavior.Strict); FilePermissions r = FilePermissions.Read; FilePermissions rw = FilePermissions.Read | FilePermissions.Write; FilePermissions rwx = FilePermissions.Read | FilePermissions.Write | FilePermissions.Execute; AccessControlListEntry[] acl = { new AccessControlListEntry { TagType = AccessControlListEntryTagTypes.UserObj, TagQualifier = 1000, Permissions = rwx }, new AccessControlListEntry { TagType = AccessControlListEntryTagTypes.GroupObj, TagQualifier = 1000, Permissions = rw }, new AccessControlListEntry { TagType = AccessControlListEntryTagTypes.Other, TagQualifier = -1, Permissions = r }, new AccessControlListEntry { TagType = AccessControlListEntryTagTypes.User, TagQualifier = 2000, Permissions = rw }, new AccessControlListEntry { TagType = AccessControlListEntryTagTypes.User, TagQualifier = 3000, Permissions = r }, new AccessControlListEntry { TagType = AccessControlListEntryTagTypes.Group, TagQualifier = 2000, Permissions = rw }, new AccessControlListEntry { TagType = AccessControlListEntryTagTypes.Group, TagQualifier = 3000, Permissions = r }, new AccessControlListEntry { TagType = AccessControlListEntryTagTypes.Mask, TagQualifier = -1, Permissions = rw } }; NativePermissionDataContainer dataContainer = new NativePermissionDataContainer { AclSize = acl.Length, OwnerId = 1000, GroupId = 1000, OwnerPermissions = rwx, GroupPermissions = rw, OtherPermissions = r }; mockNativeLibraryInterface.Setup(obj => obj.GetPermissionData("file", 0, out dataContainer)).Returns(acl); var posixPermissionInfo = new PosixPermissionInfo(mockNativeLibraryInterface.Object, "file", 0); Assert.Equal(1000, posixPermissionInfo.OwnerId); Assert.Equal(rwx, posixPermissionInfo.OwnerPermissions); Assert.True(posixPermissionInfo.TryGetUserPermissions(2000, out var permissionsUser2000)); Assert.Equal(rw, permissionsUser2000); Assert.True(posixPermissionInfo.TryGetUserPermissions(3000, out var permissionsUser3000)); Assert.Equal(r, permissionsUser3000); Assert.Equal(1000, posixPermissionInfo.GroupId); Assert.Equal(rw, posixPermissionInfo.GroupPermissions); Assert.True(posixPermissionInfo.TryGetGroupPermissions(2000, out var permissionsGroup2000)); Assert.Equal(rw, permissionsGroup2000); Assert.True(posixPermissionInfo.TryGetGroupPermissions(3000, out var permissionsGroup3000)); Assert.Equal(r, permissionsGroup3000); Assert.Equal(r, posixPermissionInfo.OtherPermissions); }