Repository navigation
Set-Date don't work and admin-elevated test is silently skipped #3099
Description
Activity
- changed the title
[-]Set-Date don't work and admin-elevated test silently skipped[/-][+]Set-Date don't work and admin-elevated test is silently skipped[/+]on Feb 4, 2017 Good catch
- addedWG-Quality-Testissues in a test or in test infrastructureissues in a test or in test infrastructureWG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issues
on Feb 4, 2017 Tests isn't fixed.
I am trying to fix
Set-Date.Tests.ps1. I have 2 problems.-
RequireAdminOnWindowstag only affects on Windows.
There is no tags likeRequireAdminOnLinux,RequireAdminOnMac. -
RequireAdminOnWindowstag is used only to skip elevated context tests.
The third test("Set-Date should produce an error in a non-elevated context") requires explicitly non-elevated context.
I think we have to keep using
Test-IsElevatedfunction and$IsElevatedvariable.
The first error in this Issue
set-date : The parameter is incorrect
was caused by program bug, and I fixed it by #6006 .
NowSet-Date.Tests.ps1works fine without changes.-
We always run test on CI Travis under sudo.
We shouldn't use
Test-IsElevated- as I said above tests is silently skipped.I wrote a prototype.
# RequireAdminOnWindows tag can use for the first two tests. Describe "Set-Date for admin" -Tag @('CI', 'RequireAdminOnWindows') { It "Set-Date should be able to set the date in an elevated context" { { Get-Date | Set-Date } | Should Not Throw } It "Set-Date should be able to set the date with -Date parameter" { $target = Get-Date $expected = $target Set-Date -Date $target | Should Be $expected } } # This test is executed in both non-elevated and elevated contexts, # and fails in elevated context without $IsElevated . Describe "Set-Date for non-admin" -Tag "CI" { BeforeAll { $IsElevated = Test-IsElevated } It "Set-Date should produce an error in a non-elevated context" -Skip:($IsElevated) { { Get-Date | Set-Date } | ShouldBeErrorId "System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.SetDateCommand" } }
Do you have a good way for the last test("Set-Date should produce an error in a non-elevated context") without
Test-IsElevatedand$IsElevated?Takuya Shibata (@stknohg) Our script automatically process
RequireAdminOnWindowsand run tests on Windows withRequireAdminOnWindowsonly in elevated phase. On Unix all tests run under sudo.I guess we only need skip last test on Unix - see pattern https://github.com/PowerShell/PowerShell/blob/master/docs/testing-guidelines/WritingPesterTests.md
Ilya (@iSazonov) Thank you. I understood about the two CI passes.
But I am a little confused.
My understanding is-
The pass with exclusion of tests with 'RequireAdminOnWindows' tag
- Pattern 1 : CI run tests on Windows (non-elevated phase)
- Pattern 2 : CI run tests on Linux/Mac (elevated(root) phase)
-
The pass where we run only 'RequireAdminOnWindows' tests
- Pattern 3 : CI run tests on Windows (elevated phase)
Is this correct?
-
Takuya Shibata (@stknohg) Correct.
Test-IsElevatedisn't correct. And our tests works incorrect - you can look logs and see that 1 and 2 test skipped and 3 passed on both CIs, the tests never run elevated on Windows.Ilya (@iSazonov) Thank you.
Reading the CI logs,I understood what you are pointing out.
I will make Pull Request so please review.I pushed Pull Request #6034, but CI tests on Linux/macOS failed.
It seems to be that CI tests on Linux/macOS are run as normal user.
Set-Datetests is silently skipped during elevated test phase in Start-PSPester because the tests useTest-IsElevatedfunction instead ofRequireAdminOnWindowstag.The command is manually executed failed too (I tested on Windows 10 with PS Core beta 15):
RequireAdminOnWindowstag in order to run in admin-elevated phase.And we could remove
Test-IsElevatedfrom the tests and fromTest.Helpers.psm1./cc James Truher (@JamesWTruher) sergei (@vors)
Set-Daterequires a fix (for Windows only?)./cc Andy Jordan (@andschwa)