public void CustomAce_GetBinaryForm_Invalid() { GenericAce ace = new CustomAce((AceType)19, (AceFlags)0, new byte[4]); Assert.Throws<ArgumentNullException>("binaryForm", () => ace.GetBinaryForm(null, 1)); Assert.Throws<ArgumentOutOfRangeException>("offset", () => ace.GetBinaryForm(new byte[1], -1)); Assert.Throws<ArgumentOutOfRangeException>("binaryForm", () => ace.GetBinaryForm(new byte[ace.BinaryLength + 1], 2)); Assert.Throws<ArgumentOutOfRangeException>("binaryForm", () => ace.GetBinaryForm(new byte[ace.BinaryLength], 1)); }
public void CustomAce_GetBinaryForm_Invalid() { GenericAce ace = new CustomAce((AceType)19, (AceFlags)0, new byte[4]); Assert.Throws <ArgumentNullException>("binaryForm", () => ace.GetBinaryForm(null, 1)); Assert.Throws <ArgumentOutOfRangeException>("offset", () => ace.GetBinaryForm(new byte[1], -1)); Assert.Throws <ArgumentOutOfRangeException>("binaryForm", () => ace.GetBinaryForm(new byte[ace.BinaryLength + 1], 2)); Assert.Throws <ArgumentOutOfRangeException>("binaryForm", () => ace.GetBinaryForm(new byte[ace.BinaryLength], 1)); }
public static void AdditionalTestCases() { RawAcl rawAcl = null; byte[] binaryForm = null; int offset = 0; //case 1, binaryForm is null Assert.Throws <ArgumentNullException>(() => { binaryForm = null; offset = 0; rawAcl = new RawAcl(binaryForm, offset); }); //case 2, binaryForm is empty Assert.Throws <ArgumentOutOfRangeException>(() => { binaryForm = new byte[0]; offset = 0; rawAcl = new RawAcl(binaryForm, offset); }); //case 3, negative offset Assert.Throws <ArgumentOutOfRangeException>(() => { binaryForm = new byte[100]; offset = -1; rawAcl = new RawAcl(binaryForm, offset); }); //case 4, binaryForm length less than GenericAcl.HeaderLength Assert.Throws <ArgumentOutOfRangeException>(() => { binaryForm = new byte[4]; offset = 0; rawAcl = new RawAcl(binaryForm, offset); }); //case 5, a RawAcl of length 64K. RawAcl length = HeaderLength + all ACE's length // = HeaderLength + (HeaderLength + OpaqueLength) * num_of_custom_ace // = 8 + ( 4 + OpaqueLength) * num_of_custom_ace GenericAce gAce = null; byte revision = 0; int capacity = 0; string sid = "BG"; //CustomAce constructor parameters AceType aceType = 0; AceFlags aceFlag = 0; byte[] opaque = null; revision = 127; capacity = 1; rawAcl = new RawAcl(revision, capacity); aceType = AceType.MaxDefinedAceType + 1; aceFlag = (AceFlags)223; //all flags ored together opaque = new byte[GenericAcl.MaxBinaryLength - 3 - 8 - 4]; //GenericAcl.MaxBinaryLength = 65535, is not multiple of 4 gAce = new CustomAce(aceType, aceFlag, opaque); rawAcl.InsertAce(0, gAce); binaryForm = new byte[rawAcl.BinaryLength]; rawAcl.GetBinaryForm(binaryForm, 0); Assert.True(TestCreateFromBinaryForm(binaryForm, offset, revision, 1, rawAcl.BinaryLength)); //case 6, a RawAcl of length 64K + 1. RawAcl length = HeaderLength + all ACE's length // = HeaderLength + (HeaderLength + OpaqueLength) * num_of_custom_ace // = 8 + ( 4 + OpaqueLength) * num_of_custom_ace gAce = null; sid = "BA"; //CustomAce constructor parameters aceType = 0; aceFlag = 0; binaryForm = new byte[65536]; AssertExtensions.Throws <ArgumentException>("binaryForm", () => { revision = 127; capacity = 1; rawAcl = new RawAcl(revision, capacity); rawAcl.GetBinaryForm(binaryForm, 0); //change the length bytes to 65535 binaryForm[2] = 0xf; binaryForm[3] = 0xf; //change the aceCount to 1 binaryForm[4] = 1; aceType = AceType.MaxDefinedAceType + 1; aceFlag = (AceFlags)223; //all flags ored together opaque = new byte[GenericAcl.MaxBinaryLength + 1 - 8 - 4]; //GenericAcl.MaxBinaryLength = 65535, is not multiple of 4 gAce = new CustomAce(aceType, aceFlag, opaque); gAce.GetBinaryForm(binaryForm, 8); TestCreateFromBinaryForm(binaryForm, 0, revision, 1, binaryForm.Length); }); //case 7, a valid binary representation with revision 255, 256 Access //CommonAce to test the correctness of the process of the AceCount in the header revision = 255; capacity = 1; rawAcl = new RawAcl(revision, capacity); for (int i = 0; i < 256; i++) { gAce = new CommonAce(AceFlags.None, AceQualifier.AccessAllowed, i + 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid(sid)), false, null); rawAcl.InsertAce(0, gAce); } binaryForm = new byte[rawAcl.BinaryLength + 1000]; rawAcl.GetBinaryForm(binaryForm, 1000); Assert.True(TestCreateFromBinaryForm(binaryForm, 1000, revision, 256, rawAcl.BinaryLength)); //case 8, array containing garbage Assert.Throws <ArgumentOutOfRangeException>(() => { binaryForm = new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; TestCreateFromBinaryForm(binaryForm, offset, revision, 1, 12); }); //case 9, array containing garbage Assert.Throws <ArgumentOutOfRangeException>(() => { //binary form shows the length will be 1, actual length is 12 binaryForm = new byte[] { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; TestCreateFromBinaryForm(binaryForm, offset, revision, 1, 12); }); //case 10, array containing garbage Assert.Throws <ArgumentOutOfRangeException>(() => { binaryForm = new byte[] { 1, 1, 12, 0, 1, 1, 1, 1, 1, 1, 1, 1 }; TestCreateFromBinaryForm(binaryForm, offset, revision, 1, 12); }); }
public static void AdditionalTestCases() { RawAcl rawAcl = null; byte[] binaryForm = null; int offset = 0; //case 1, binaryForm is null Assert.Throws<ArgumentNullException>(() => { binaryForm = null; offset = 0; rawAcl = new RawAcl(binaryForm, offset); }); //case 2, binaryForm is empty Assert.Throws<ArgumentOutOfRangeException>(() => { binaryForm = new byte[0]; offset = 0; rawAcl = new RawAcl(binaryForm, offset); }); //case 3, negative offset Assert.Throws<ArgumentOutOfRangeException>(() => { binaryForm = new byte[100]; offset = -1; rawAcl = new RawAcl(binaryForm, offset); }); //case 4, binaryForm length less than GenericAcl.HeaderLength Assert.Throws<ArgumentOutOfRangeException>(() => { binaryForm = new byte[4]; offset = 0; rawAcl = new RawAcl(binaryForm, offset); }); //case 5, a RawAcl of length 64K. RawAcl length = HeaderLength + all ACE's length // = HeaderLength + (HeaderLength + OpaqueLength) * num_of_custom_ace // = 8 + ( 4 + OpaqueLength) * num_of_custom_ace GenericAce gAce = null; byte revision = 0; int capacity = 0; string sid = "BG"; //CustomAce constructor parameters AceType aceType = 0; AceFlags aceFlag = 0; byte[] opaque = null; revision = 127; capacity = 1; rawAcl = new RawAcl(revision, capacity); aceType = AceType.MaxDefinedAceType + 1; aceFlag = (AceFlags)223; //all flags ored together opaque = new byte[GenericAcl.MaxBinaryLength - 3 - 8 - 4];//GenericAcl.MaxBinaryLength = 65535, is not multiple of 4 gAce = new CustomAce(aceType, aceFlag, opaque); rawAcl.InsertAce(0, gAce); binaryForm = new byte[rawAcl.BinaryLength]; rawAcl.GetBinaryForm(binaryForm, 0); Assert.True(TestCreateFromBinaryForm(binaryForm, offset, revision, 1, rawAcl.BinaryLength)); //case 6, a RawAcl of length 64K + 1. RawAcl length = HeaderLength + all ACE's length // = HeaderLength + (HeaderLength + OpaqueLength) * num_of_custom_ace // = 8 + ( 4 + OpaqueLength) * num_of_custom_ace gAce = null; sid = "BA"; //CustomAce constructor parameters aceType = 0; aceFlag = 0; binaryForm = new byte[65536]; Assert.Throws<ArgumentException>(() => { revision = 127; capacity = 1; rawAcl = new RawAcl(revision, capacity); rawAcl.GetBinaryForm(binaryForm, 0); //change the length bytes to 65535 binaryForm[2] = 0xf; binaryForm[3] = 0xf; //change the aceCount to 1 binaryForm[4] = 1; aceType = AceType.MaxDefinedAceType + 1; aceFlag = (AceFlags)223; //all flags ored together opaque = new byte[GenericAcl.MaxBinaryLength + 1 - 8 - 4];//GenericAcl.MaxBinaryLength = 65535, is not multiple of 4 gAce = new CustomAce(aceType, aceFlag, opaque); gAce.GetBinaryForm(binaryForm, 8); TestCreateFromBinaryForm(binaryForm, 0, revision, 1, binaryForm.Length); }); //case 7, a valid binary representation with revision 255, 256 Access //CommonAce to test the correctness of the process of the AceCount in the header revision = 255; capacity = 1; rawAcl = new RawAcl(revision, capacity); for (int i = 0; i < 256; i++) { gAce = new CommonAce(AceFlags.None, AceQualifier.AccessAllowed, i + 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid(sid)), false, null); rawAcl.InsertAce(0, gAce); } binaryForm = new byte[rawAcl.BinaryLength + 1000]; rawAcl.GetBinaryForm(binaryForm, 1000); Assert.True(TestCreateFromBinaryForm(binaryForm, 1000, revision, 256, rawAcl.BinaryLength)); //case 8, array containing garbage Assert.Throws<ArgumentOutOfRangeException>(() => { binaryForm = new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; TestCreateFromBinaryForm(binaryForm, offset, revision, 1, 12); }); //case 9, array containing garbage Assert.Throws<ArgumentOutOfRangeException>(() => { //binary form shows the length will be 1, actual length is 12 binaryForm = new byte[] { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; TestCreateFromBinaryForm(binaryForm, offset, revision, 1, 12); }); //case 10, array containing garbage Assert.Throws<ArgumentOutOfRangeException>(() => { binaryForm = new byte[] { 1, 1, 12, 0, 1, 1, 1, 1, 1, 1, 1, 1 }; TestCreateFromBinaryForm(binaryForm, offset, revision, 1, 12); }); }