-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
FileSystemAccessRuleTests.cs
84 lines (74 loc) · 4.19 KB
/
FileSystemAccessRuleTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Security.AccessControl;
using System.Security.Principal;
using Xunit;
namespace System.IO
{
public class FileSystemAccessRuleTests
{
[Fact]
public void FileSystemAccessRule_Returns_Valid_Object()
{
var accessRule = new FileSystemAccessRule(Helpers.s_WorldSidNTAccount, FileSystemRights.AppendData, AccessControlType.Allow);
var expectedFileSystemRights = FileSystemRights.AppendData | FileSystemRights.Synchronize;
Assert.Equal(Helpers.s_WorldSidNTAccount, accessRule.IdentityReference);
Assert.Equal(expectedFileSystemRights, accessRule.FileSystemRights);
Assert.Equal(AccessControlType.Allow, accessRule.AccessControlType);
Assert.Equal(PropagationFlags.None, accessRule.PropagationFlags);
Assert.Equal(InheritanceFlags.None, accessRule.InheritanceFlags);
}
[Fact]
public void FileSystemAccessRule_InvalidFileSystemRights()
{
AssertExtensions.Throws<ArgumentOutOfRangeException>("fileSystemRights", () =>
new FileSystemAccessRule(Helpers.s_WorldSidNTAccount, (FileSystemRights)(-1), AccessControlType.Allow));
}
[Fact]
public void FileSystemAccessRule_AccessControlTypeDeny_Returns_Valid_Object()
{
var accessRule = new FileSystemAccessRule(Helpers.s_WorldSidNTAccount, FileSystemRights.AppendData, AccessControlType.Deny);
var expectedFileSystemRights = FileSystemRights.AppendData & ~FileSystemRights.Synchronize;
Assert.Equal(expectedFileSystemRights, accessRule.FileSystemRights);
Assert.Equal(AccessControlType.Deny, accessRule.AccessControlType);
}
[Fact]
public void FileSystemAccessRule_FileSystemRightsFullControl_Returns_Valid_Object()
{
var accessRule = new FileSystemAccessRule(Helpers.s_WorldSidNTAccount, FileSystemRights.FullControl, AccessControlType.Deny);
Assert.Equal(FileSystemRights.FullControl, accessRule.FileSystemRights);
Assert.Equal(AccessControlType.Deny, accessRule.AccessControlType);
}
[Fact]
public void FileSystemAccessRule_IdentityAsString_Returns_Valid_Object()
{
var accessRule = new FileSystemAccessRule(@"MYDOMAIN\MyAccount", FileSystemRights.AppendData,
AccessControlType.Allow);
var expectedFileSystemRights = FileSystemRights.AppendData | FileSystemRights.Synchronize;
Assert.Equal(new NTAccount(@"MYDOMAIN\MyAccount"), accessRule.IdentityReference);
Assert.Equal(expectedFileSystemRights, accessRule.FileSystemRights);
Assert.Equal(AccessControlType.Allow, accessRule.AccessControlType);
Assert.Equal(PropagationFlags.None, accessRule.PropagationFlags);
Assert.Equal(InheritanceFlags.None, accessRule.InheritanceFlags);
}
[Fact]
public void FileSystemAccessRule_InhertianceFlag_PropagationFlag_Returns_Valid_Object()
{
var accessRule = new FileSystemAccessRule(Helpers.s_WorldSidNTAccount, FileSystemRights.AppendData,
InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit,
AccessControlType.Allow);
Assert.Equal(PropagationFlags.NoPropagateInherit, accessRule.PropagationFlags);
Assert.Equal(InheritanceFlags.ContainerInherit, accessRule.InheritanceFlags);
}
[Fact]
public void FileSystemAccessRule_InhertianceFlag_PropagationFlag_IdentityAsString_Returns_Valid_Object()
{
var accessRule = new FileSystemAccessRule(@"MYDOMAIN\MyAccount", FileSystemRights.AppendData,
InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly,
AccessControlType.Allow);
Assert.Equal(new NTAccount(@"MYDOMAIN\MyAccount"), accessRule.IdentityReference);
Assert.Equal(PropagationFlags.InheritOnly, accessRule.PropagationFlags);
Assert.Equal(InheritanceFlags.ObjectInherit, accessRule.InheritanceFlags);
}
}
}