Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusStorhaug committed Mar 30, 2024
1 parent 5c14b83 commit 703c062
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 38 deletions.
3 changes: 0 additions & 3 deletions src/header.ps1

This file was deleted.

38 changes: 13 additions & 25 deletions src/public/Test-Admin.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,23 @@
.SYNOPSIS
Test if the current context is running as a specified role.
.DESCRIPTION
Test if the current context is running as a specified role.
.EXAMPLE
Test-Role -Role Administrator
Test-Role
Test if the current context is running as an Administrator.
.EXAMPLE
Test-Role -Role User
Test if the current context is running as a User.
.NOTES
Supported OS: Windows
#>
[OutputType([Boolean])]
[OutputType([System.Boolean])]
[CmdletBinding()]
[alias('Test-Role', 'Test-Administrator', 'IsAdmin', 'IsAdministrator')]
param(
# Role to test
[Parameter()]
[Security.Principal.WindowsBuiltInRole] $Role = 'Administrator'
)
[Alias('Test-Administrator', 'IsAdmin', 'IsAdministrator')]
param()

Write-Verbose "Test Role - [$Role]"
$user = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($user)
$isAdmin = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::$Role)
Write-Verbose "Test Role - [$Role] - [$isAdmin]"
$isAdmin
$IsUnix = $PSVersionTable.Platform -eq 'Unix'
if ($IsUnix) {
whoami -eq 'root'
} else {
$user = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($user)
$isAdmin = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
$isAdmin
}
}
14 changes: 4 additions & 10 deletions tests/Admin.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@ Describe 'Admin' {
}
}

Context 'Functions' {
It 'Test-Admin' {
Context 'Function: Test-Admin' {
It 'should not throw' {
{ Test-Admin } | Should -Not -Throw
}

It 'EUID is not null' {
Write-Verbose "EUID: $EUID" -Verbose
$EUID | Should -Not -BeNullOrEmpty
}

It "whoami == 'root'" {
Write-Verbose "whoami: $(whoami)" -Verbose
whoami | Should -Be 'root'
It 'should return true' {
{ Test-Admin } | Should -Be $true
}
}
}

0 comments on commit 703c062

Please sign in to comment.