[SRE] Improved token fixups processing.
[mono.git] / mcs / class / corlib / Test / System.Security.AccessControl / ObjectSecurity_TTest.cs
1 // ObjectSecurity_TTest.cs - NUnit Test Cases for ObjectSecurity<T>
2 //
3 // Authors:
4 //      James Bellinger (jfb@zer7.com)
5
6 #if NET_4_0
7
8 using System;
9 using System.Security.AccessControl;
10 using System.Security.Principal;
11 using NUnit.Framework;
12
13 namespace MonoTests.System.Security.AccessControl
14 {
15         [TestFixture]
16         public class ObjectSecurity_TTest
17         {
18                 enum WillWorkRights
19                 {
20                         Value = 1
21                 }
22
23                 class WillWorkSecurity : ObjectSecurity<WillWorkRights>
24                 {
25                         public WillWorkSecurity ()
26                                 : base (false, ResourceType.Unknown)
27                         {
28
29                         }
30                 }
31
32                 struct WillFailRights
33                 {
34
35                 }
36
37                 class WillFailSecurity : ObjectSecurity<WillFailRights>
38                 {
39                         public WillFailSecurity ()
40                                 : base (false, ResourceType.Unknown)
41                         {
42
43                         }
44                 }
45
46                 [Test]
47                 public void TypesAreCorrect ()
48                 {
49                         WillWorkSecurity security = new WillWorkSecurity ();
50                         Assert.AreEqual (security.AccessRightType, typeof (WillWorkRights));
51                         Assert.AreEqual (security.AccessRuleType, typeof (AccessRule<WillWorkRights>));
52                         Assert.AreEqual (security.AuditRuleType, typeof (AuditRule<WillWorkRights>));
53                 }
54
55                 [Test]
56                 public void WillWorkOKUsingAccessFactory ()
57                 {
58                         WillWorkSecurity security = new WillWorkSecurity ();
59                         SecurityIdentifier id = new SecurityIdentifier (WellKnownSidType.WorldSid, null);
60                         AccessRule<WillWorkRights> rule = (AccessRule<WillWorkRights>)
61                                 security.AccessRuleFactory (id, 1, false,
62                                         InheritanceFlags.None, PropagationFlags.None,
63                                         AccessControlType.Allow);
64                         Assert.AreEqual (rule.AccessControlType, AccessControlType.Allow);
65                         Assert.AreEqual (rule.IdentityReference, id);
66                         Assert.AreEqual (rule.InheritanceFlags, InheritanceFlags.None);
67                         Assert.AreEqual (rule.PropagationFlags, PropagationFlags.None);
68                         Assert.AreEqual (rule.Rights, WillWorkRights.Value);
69                 }
70
71                 [Test]
72                 public void WillWorkOKUsingConstructor()
73                 {
74                         SecurityIdentifier id = new SecurityIdentifier (WellKnownSidType.WorldSid, null);
75                         AccessRule<WillWorkRights> rule = new AccessRule<WillWorkRights> (id, WillWorkRights.Value,
76                                                                                           AccessControlType.Allow);
77                         Assert.AreEqual (rule.AccessControlType, AccessControlType.Allow);
78                         Assert.AreEqual (rule.IdentityReference, id);
79                         Assert.AreEqual (rule.Rights, WillWorkRights.Value);
80                 }
81
82                 [Test, ExpectedException (typeof (InvalidCastException))]
83                 public void WillFailFailsUsingFactoryOnGetter()
84                 {
85                         WillFailSecurity security = new WillFailSecurity ();
86                         SecurityIdentifier id = new SecurityIdentifier (WellKnownSidType.WorldSid, null);
87                         AccessRule<WillFailRights> rule = (AccessRule<WillFailRights>)
88                                 security.AccessRuleFactory (id, 1, false,
89                                         InheritanceFlags.None, PropagationFlags.None,
90                                         AccessControlType.Allow);
91                         WillFailRights rights = rule.Rights;
92                 }
93
94                 [Test, ExpectedException (typeof (InvalidCastException))]
95                 public void WillFailFailsUsingConstructor()
96                 {
97                         SecurityIdentifier id = new SecurityIdentifier (WellKnownSidType.WorldSid, null);
98                         AccessRule<WillFailRights> rule = new AccessRule<WillFailRights> (id, new WillFailRights(),
99                                                                                           AccessControlType.Allow);
100                 }
101         }
102 }
103
104 #endif
105