Skip tests when we can not use runas

This commit is contained in:
Daniel A. Wozniak 2018-05-10 12:03:31 -07:00
parent 82fb6ba366
commit a48ac26573
No known key found for this signature in database
GPG key ID: 166B9D2C06C82D61

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
'''
if salt.utils.is_windows():
try:
salt.utils.win_runas.run_as(
'cmd.exe /c echo 1', 'noexistuser', 'n0existp4ss',
)
except WindowsError as exc:
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()