Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
runs-on: windows-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
uses: actions/checkout@v6

- name: Build module - Debug
shell: pwsh
Expand All @@ -38,7 +38,7 @@ jobs:
if: ${{ env.BUILD_CONFIGURATION == 'Release' }}

- name: Capture PowerShell Module
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: PSModule
path: output/*.nupkg
Expand All @@ -60,10 +60,10 @@ jobs:
os: windows-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Restore Built PowerShell Module
uses: actions/download-artifact@v4
uses: actions/download-artifact@v8
with:
name: PSModule
path: output
Expand Down Expand Up @@ -100,21 +100,21 @@ jobs:

- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: Unit Test Results (${{ matrix.info.name }})
path: ./output/TestResults/Pester.xml

- name: Upload Coverage Results
if: always() && !startsWith(github.ref, 'refs/tags/v')
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: Coverage Results (${{ matrix.info.name }})
path: ./output/TestResults/Coverage.xml

- name: Upload Coverage to codecov
if: always() && !startsWith(github.ref, 'refs/tags/v')
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v6
with:
files: ./output/TestResults/Coverage.xml
flags: ${{ matrix.info.name }}
Expand All @@ -128,7 +128,7 @@ jobs:
runs-on: windows-latest
steps:
- name: Restore Built PowerShell Module
uses: actions/download-artifact@v4
uses: actions/download-artifact@v8
with:
name: PSModule
path: ./
Expand Down
2 changes: 1 addition & 1 deletion src/PSADTree/Internal/_FormattingInternals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace PSADTree.Internal;
[EditorBrowsable(EditorBrowsableState.Never)]
public static class _FormattingInternals
{
private static Regex s_getDomain = new(
private static readonly Regex s_getDomain = new(
@"^DC=|(?<!\\),.+",
RegexOptions.Compiled | RegexOptions.IgnoreCase);

Expand Down
48 changes: 27 additions & 21 deletions src/PSADTree/Internal/_SecurityDescriptorInternals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,42 @@ namespace PSADTree.Internal;
[EditorBrowsable(EditorBrowsableState.Never)]
public static class _SecurityDescriptorInternals
{
private readonly static Type _target = typeof(NTAccount);
private static readonly MethodInfo _getOwner;
private static readonly MethodInfo _getGroup;
private static readonly MethodInfo _getSddlForm;
private static readonly MethodInfo _getAccessRules;
private static readonly MethodInfo _getAccessToString;
private readonly static Type s_target = typeof(NTAccount);
private static readonly MethodInfo s_getOwner;
private static readonly MethodInfo s_getGroup;
private static readonly MethodInfo s_getSddlForm;
private static readonly MethodInfo s_getAccessRules;
private static readonly MethodInfo s_getAccessToString;

static _SecurityDescriptorInternals()
{
Type type = typeof(_SecurityDescriptorInternals);
_getOwner = type.GetMethod(nameof(GetOwner))!;
_getGroup = type.GetMethod(nameof(GetGroup))!;
_getSddlForm = type.GetMethod(nameof(GetSddlForm))!;
_getAccessRules = type.GetMethod(nameof(GetAccessRules))!;
_getAccessToString = type.GetMethod(nameof(GetAccessToString))!;
s_getOwner = GetMethod(type, nameof(GetOwner));
s_getGroup = GetMethod(type, nameof(GetGroup));
s_getSddlForm = GetMethod(type, nameof(GetSddlForm));
s_getAccessRules = GetMethod(type, nameof(GetAccessRules));
s_getAccessToString = GetMethod(type, nameof(GetAccessToString));
}

private static MethodInfo GetMethod(Type type, string name) =>
type.GetMethod(name)
?? throw new InvalidOperationException(
$"Method '{name}' not found on type '{type.FullName}'.");

private static ActiveDirectorySecurity GetBaseObject(PSObject target)
=> (ActiveDirectorySecurity)target.BaseObject;

public static IdentityReference? GetOwner(PSObject target)
=> GetBaseObject(target).GetOwner(_target);
=> GetBaseObject(target).GetOwner(s_target);

public static IdentityReference? GetGroup(PSObject target)
=> GetBaseObject(target).GetGroup(_target);
=> GetBaseObject(target).GetGroup(s_target);

public static string GetSddlForm(PSObject target)
=> GetBaseObject(target).GetSecurityDescriptorSddlForm(AccessControlSections.All);

public static AuthorizationRuleCollection GetAccessRules(PSObject target)
=> GetBaseObject(target).GetAccessRules(true, true, _target);
=> GetBaseObject(target).GetAccessRules(true, true, s_target);

public static string GetAccessToString(PSObject target)
{
Expand All @@ -56,13 +61,14 @@ public static string GetAccessToString(PSObject target)
}

internal static PSObject GetSecurityDescriptorAsPSObject(this DirectoryEntry entry)
=> PSObject.AsPSObject(entry.ObjectSecurity)
.AddProperty("Path", entry.Path)
.AddCodeProperty("Owner", _getOwner)
.AddCodeProperty("Group", _getGroup)
.AddCodeProperty("Sddl", _getSddlForm)
.AddCodeProperty("Access", _getAccessRules)
.AddCodeProperty("AccessToString", _getAccessToString);
=> PSObject
.AsPSObject(entry.ObjectSecurity)
.AddProperty("Path", entry.Path)
.AddCodeProperty("Owner", s_getOwner)
.AddCodeProperty("Group", s_getGroup)
.AddCodeProperty("Sddl", s_getSddlForm)
.AddCodeProperty("Access", s_getAccessRules)
.AddCodeProperty("AccessToString", s_getAccessToString);

private static PSObject AddProperty(
this PSObject psObject,
Expand Down
5 changes: 4 additions & 1 deletion tools/InvokeBuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ task PesterTests {

if (-not (dotnet tool list --global | Select-String coverlet.console -SimpleMatch)) {
Write-Host 'Installing dotnet tool coverlet.console' -ForegroundColor Yellow
dotnet tool install --global coverlet.console
dotnet @(
'tool', 'install'
'--global', 'coverlet.console'
if (-not $IsCoreCLR) { '--version', '6.0.4' })
}

coverlet $ProjectInfo.Pester.GetTestArgs($PSVersionTable.PSVersion)
Expand Down