From e639240ecb476c7d4f674677401c7edb0cf5b5d6 Mon Sep 17 00:00:00 2001 From: James Truher Date: Tue, 23 Aug 2016 17:08:15 -0700 Subject: [PATCH] Add set-Date test this one is a bit tricky, unless you're elevated you can't set the date however, if you are not elevated you should get an error. This file does one or the other based on whether you're elevated --- .../Set-Date.Tests.ps1 | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 new file mode 100644 index 000000000..ec58428bf --- /dev/null +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 @@ -0,0 +1,26 @@ +# first check to see which platform we're on. If we're on windows we should be able +# to be sure whether we're running elevated. If we're on Linux, we can use whoami to +# determine whether we're elevated +Describe "Set-Date" { + BeforeAll { + if ( $IsWindows ) { + $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent() + $windowsPrincipal = new-object 'Security.Principal.WindowsPrincipal' $identity + if ($windowsPrincipal.IsInRole("Administrators") -eq 1) { $IsElevated = $true } else { $IsElevated = $false } + } + else { + if ( (whoami) -match "root" ) { + $IsElevated = $true + } + else { + $IsElevated = $false + } + } + } + It "Set-Date should be able to set the date in an elevated context" -Skip:(! $IsElevated) { + { get-date | set-date } | Should not throw + } + It "Set-Date should produce an error in a non-elevated context" -Skip:($IsElevated) { + { get-date |set-date} | should throw + } +}