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