ObjectAceTest.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // ObjectAceTest.cs - NUnit Test Cases for ObjectAce
  2. //
  3. // Authors:
  4. // James Bellinger <[email protected]>
  5. //
  6. // Copyright (C) 2012 James Bellinger
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Security.AccessControl;
  10. using System.Security.Principal;
  11. using NUnit.Framework;
  12. namespace MonoTests.System.Security.AccessControl
  13. {
  14. [TestFixture]
  15. public class ObjectAceTest
  16. {
  17. static RawAcl CreateRoundtripRawAcl ()
  18. {
  19. SecurityIdentifier sid = new SecurityIdentifier (WellKnownSidType.BuiltinUsersSid, null);
  20. Assert.AreEqual (16, sid.BinaryLength);
  21. GenericAce[] aces = new GenericAce[] {
  22. new ObjectAce (AceFlags.None, AceQualifier.AccessAllowed, 1, sid,
  23. ObjectAceFlags.ObjectAceTypePresent,
  24. Guid.Empty, Guid.Empty, false, new byte[8]),
  25. new ObjectAce (AceFlags.None, AceQualifier.AccessAllowed, 2, sid,
  26. ObjectAceFlags.InheritedObjectAceTypePresent,
  27. Guid.Empty, Guid.Empty, true, new byte[16]),
  28. new ObjectAce (AceFlags.None, AceQualifier.AccessAllowed, 4, sid,
  29. ObjectAceFlags.InheritedObjectAceTypePresent,
  30. Guid.Empty, new Guid ("{8865FB90-A9EB-422F-A8BA-07ECA611D699}"), true, new byte[4]),
  31. new ObjectAce (AceFlags.None, AceQualifier.AccessAllowed, 4, sid,
  32. ObjectAceFlags.ObjectAceTypePresent|ObjectAceFlags.InheritedObjectAceTypePresent,
  33. Guid.Empty, new Guid ("{B893007C-38D5-4827-A698-BA25F1E30BAC}"), true, new byte[4]),
  34. new ObjectAce (AceFlags.None, AceQualifier.AccessAllowed, 4, sid,
  35. ObjectAceFlags.None,
  36. Guid.Empty, new Guid ("{C0F9DF22-C320-4400-B41F-754F69668640}"), true, new byte[4])
  37. };
  38. // Make sure this created right, first of all.
  39. Assert.AreEqual (AceType.AccessAllowedObject, aces [0].AceType);
  40. Assert.AreEqual (AceType.AccessAllowedCallbackObject, aces [1].AceType);
  41. Assert.AreEqual (AceType.AccessAllowedCallbackObject, aces [2].AceType);
  42. Assert.AreEqual (AceType.AccessAllowedCallbackObject, aces [3].AceType);
  43. Assert.AreEqual (AceType.AccessAllowedCallbackObject, aces [4].AceType);
  44. Assert.AreEqual (52, aces [0].BinaryLength);
  45. Assert.AreEqual (60, aces [1].BinaryLength);
  46. Assert.AreEqual (48, aces [2].BinaryLength);
  47. Assert.AreEqual (64, aces [3].BinaryLength);
  48. Assert.AreEqual (32, aces [4].BinaryLength);
  49. RawAcl acl = new RawAcl (RawAcl.AclRevision, 0);
  50. for (int i = 0; i < aces.Length; i ++)
  51. acl.InsertAce (i, aces[i]);
  52. return acl;
  53. }
  54. void CompareBinaryForms (byte[] binaryFormExpected, byte[] binaryFormActual)
  55. {
  56. Assert.AreEqual (binaryFormExpected.Length, binaryFormActual.Length);
  57. for (int i = 0; i < binaryFormExpected.Length; i ++)
  58. Assert.AreEqual (binaryFormExpected [i], binaryFormActual [i], "Mismatch at position " + i.ToString ());
  59. }
  60. [Test]
  61. public void BinaryRoundtrip ()
  62. {
  63. RawAcl acl = CreateRoundtripRawAcl ();
  64. byte[] binaryForm1 = new byte[acl.BinaryLength];
  65. acl.GetBinaryForm (binaryForm1, 0);
  66. RawAcl acl2 = new RawAcl (binaryForm1, 0);
  67. byte[] binaryForm2 = new byte[acl2.BinaryLength];
  68. acl2.GetBinaryForm (binaryForm2, 0);
  69. CompareBinaryForms (binaryForm1, binaryForm2);
  70. }
  71. [Test] // This blob produced by binaryForm1 from the BinaryRoundtrip test...
  72. public void BlobMatchesMSNet ()
  73. {
  74. RawAcl acl = CreateRoundtripRawAcl ();
  75. byte[] binaryForm1 = new byte[acl.BinaryLength];
  76. acl.GetBinaryForm (binaryForm1, 0);
  77. byte[] binaryForm2 = new byte[] { // 11 per line
  78. (byte)0x02, (byte)0x00, (byte)0x08, (byte)0x01, (byte)0x05, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x05, (byte)0x00, (byte)0x34,
  79. (byte)0x00, (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
  80. (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
  81. (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x05,
  82. (byte)0x20, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x21, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
  83. (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0B, (byte)0x00, (byte)0x3C, (byte)0x00, (byte)0x02, (byte)0x00,
  84. (byte)0x00, (byte)0x00, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
  85. (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
  86. (byte)0x01, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x05, (byte)0x20, (byte)0x00, (byte)0x00,
  87. (byte)0x00, (byte)0x21, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
  88. (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0B,
  89. (byte)0x00, (byte)0x30, (byte)0x00, (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00,
  90. (byte)0x90, (byte)0xFB, (byte)0x65, (byte)0x88, (byte)0xEB, (byte)0xA9, (byte)0x2F, (byte)0x42, (byte)0xA8, (byte)0xBA, (byte)0x07,
  91. (byte)0xEC, (byte)0xA6, (byte)0x11, (byte)0xD6, (byte)0x99, (byte)0x01, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
  92. (byte)0x00, (byte)0x05, (byte)0x20, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x21, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00,
  93. (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0B, (byte)0x00, (byte)0x40, (byte)0x00, (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x00,
  94. (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
  95. (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x7C, (byte)0x00,
  96. (byte)0x93, (byte)0xB8, (byte)0xD5, (byte)0x38, (byte)0x27, (byte)0x48, (byte)0xA6, (byte)0x98, (byte)0xBA, (byte)0x25, (byte)0xF1,
  97. (byte)0xE3, (byte)0x0B, (byte)0xAC, (byte)0x01, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x05,
  98. (byte)0x20, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x21, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
  99. (byte)0x00, (byte)0x0B, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
  100. (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x05, (byte)0x20,
  101. (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x21, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00
  102. };
  103. CompareBinaryForms (binaryForm2, binaryForm1);
  104. }
  105. }
  106. }