Merge pull request #47601 from dwoz/runas_detect

Skip tests when we can not use runas
This commit is contained in:
Daniel Wozniak 2018-05-14 08:26:35 -07:00 committed by GitHub
commit 6dd3ab9f06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

4
test Normal file
View file

@ -0,0 +1,4 @@
a
b
c

View file

@ -37,6 +37,7 @@ from tests.support.case import ModuleCase
import salt.utils
import salt.utils.win_dacl
import salt.utils.win_functions
import salt.utils.win_runas
from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
from salt.exceptions import CommandExecutionError
@ -44,6 +45,26 @@ from salt.exceptions import CommandExecutionError
import salt.ext.six as six
def can_runas():
'''
Detect if we are running in a limited shell (winrm) and are un-able to use
the runas utility method.
'''
if salt.utils.is_windows():
try:
salt.utils.win_runas.run_as(
'cmd.exe /c echo 1', 'noexistuser', 'n0existp4ss',
)
except WindowsError as exc: # pylint: disable=undefined-variable
if exc.winerror == 5:
# Access Denied
return False
return True
CAN_RUNAS = can_runas()
class VirtualEnv(object):
def __init__(self, test, venv_dir):
self.venv_dir = venv_dir
@ -270,6 +291,7 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
@destructiveTest
@skip_if_not_root
@skipIf(not CAN_RUNAS, 'Runas support required')
@with_system_user('issue-6912', on_existing='delete', delete=True,
password='PassWord1!')
@with_tempdir()
@ -313,6 +335,7 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
@destructiveTest
@skip_if_not_root
@skipIf(not CAN_RUNAS, 'Runas support required')
@with_system_user('issue-6912', on_existing='delete', delete=True,
password='PassWord1!')
@with_tempdir()