-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
RawAcl_CopyTo.cs
111 lines (98 loc) · 5.1 KB
/
RawAcl_CopyTo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.Security.Principal;
using Xunit;
namespace System.Security.AccessControl.Tests
{
public class RawAcl_CopyTo
{
[Fact]
public static void BasicValidationTestCases()
{
GenericAce gAce = null;
RawAcl rAcl = null;
GenericAce[] gAces = null;
// Case 1, when collection is actually empty
rAcl = new RawAcl(1, 1);
gAces = new GenericAce[rAcl.Count];
rAcl.CopyTo(gAces, 0);
// Case 2, collection has one ACE
rAcl = new RawAcl(0, 1);
gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
rAcl.InsertAce(0, gAce);
gAces = new GenericAce[rAcl.Count];
rAcl.CopyTo(gAces, 0);
//Case 3, index = 3
rAcl = new RawAcl(0, 1);
gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BG")), false, null);
rAcl.InsertAce(0, gAce);
gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
rAcl.InsertAce(0, gAce);
gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BO")), false, null);
rAcl.InsertAce(0, gAce);
gAces = new GenericAce[rAcl.Count + 5];
//initialize to null
for (int i = 0; i < gAces.Length; i++)
gAces[i] = null;
rAcl.CopyTo(gAces, 3);
}
[Fact]
public static void AdditionalTestCases()
{
GenericAce gAce = null;
RawAcl rAcl = null;
GenericAce[] gAces = null;
// case 1, null array
Assert.Throws<ArgumentNullException>(() =>
{
rAcl = new RawAcl(0, 1);
gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
rAcl.InsertAce(0, gAce);
rAcl.CopyTo(gAces, 0);
});
// case 2, negative index
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
rAcl = new RawAcl(0, 1);
gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
rAcl.InsertAce(0, gAce);
gAces = new GenericAce[rAcl.Count];
rAcl.CopyTo(gAces, -1);
});
// case 3, insufficient size array
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
rAcl = new RawAcl(0, 1);
gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
rAcl.InsertAce(0, gAce);
gAces = new GenericAce[0];
rAcl.CopyTo(gAces, 0);
});
// Case 4, insufficient size array
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
rAcl = new RawAcl(0, 1);
gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BG")), false, null);
rAcl.InsertAce(0, gAce);
gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
rAcl.InsertAce(0, gAce);
gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BO")), false, null);
rAcl.InsertAce(0, gAce);
gAces = new GenericAce[rAcl.Count - 1];
rAcl.CopyTo(gAces, 0);
});
//case 5, RawAcl with huge number of Aces
rAcl = new RawAcl(0, GenericAcl.MaxBinaryLength);
for (int i = 0; i < 1820; i++)
{
//this ace binary length is 36, 1820 * 36 = 65520
gAce = new CommonAce(AceFlags.SuccessfulAccess, AceQualifier.SystemAudit, i + 1, new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid("BA")), false, null);
rAcl.InsertAce(0, gAce);
}
gAces = new GenericAce[rAcl.Count];
rAcl.CopyTo(gAces, 0);
}
}
}