AuthorizationRuleTest.cs 2.2 KB

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