AuthorizationRuleTest.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // AuthorizationRuleTest.cs - NUnit Test Cases for AuthorizationRule
  2. //
  3. // Authors:
  4. // James Bellinger ([email protected])
  5. #if NET_4_0
  6. using System;
  7. using System.Security.AccessControl;
  8. using System.Security.Principal;
  9. using NUnit.Framework;
  10. namespace MonoTests.System.Security.AccessControl
  11. {
  12. [TestFixture]
  13. public class AuthorizationRuleTest
  14. {
  15. class TestRule : AuthorizationRule
  16. {
  17. public TestRule (IdentityReference identity,
  18. int accessMask, bool isInherited,
  19. InheritanceFlags inheritanceFlags,
  20. PropagationFlags propagationFlags)
  21. : base (identity, accessMask, isInherited, inheritanceFlags, propagationFlags)
  22. {
  23. }
  24. }
  25. [Test, ExpectedException (typeof (ArgumentException))]
  26. public void ThrowOnZeroAccessMask ()
  27. {
  28. new TestRule (new SecurityIdentifier (WellKnownSidType.WorldSid, null),
  29. 0, false, InheritanceFlags.None, PropagationFlags.None);
  30. }
  31. [Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
  32. public void ThrowOnBadInheritanceFlags ()
  33. {
  34. new TestRule (new SecurityIdentifier (WellKnownSidType.WorldSid, null),
  35. 1, false, (InheritanceFlags)(-1), PropagationFlags.None);
  36. }
  37. // While InheritanceFlags.None makes PropagationFlags not *significant*,
  38. // my tests with MS.NET show that it is still *validated*. So, we'll use
  39. // that case with this test to make sure.
  40. [Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
  41. public void ThrowOnBadPropagationFlags ()
  42. {
  43. new TestRule (new SecurityIdentifier (WellKnownSidType.WorldSid, null),
  44. 1, false, InheritanceFlags.None, (PropagationFlags)(-1));
  45. }
  46. [Test]
  47. public void AcceptNTAccount ()
  48. {
  49. new TestRule (new NTAccount ("Test"), 1, false, InheritanceFlags.None, PropagationFlags.None);
  50. }
  51. [Test]
  52. public void AcceptSecurityIdentifier ()
  53. {
  54. new TestRule (new SecurityIdentifier (WellKnownSidType.WorldSid, null),
  55. 1, false, InheritanceFlags.None, PropagationFlags.None);
  56. }
  57. [Test]
  58. public void AcceptValidFlags ()
  59. {
  60. SecurityIdentifier id = new SecurityIdentifier (WellKnownSidType.WorldSid, null);
  61. new TestRule (id, 1, false, InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit);
  62. new TestRule (id, 1, false, InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly);
  63. }
  64. }
  65. }
  66. #endif