Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_empty_filled_queue(self):
client = Client("server", "username", "password")
queue = Queue()
queue.put(b"Hello")
queue.put(b"\n")
queue.put(b"World")
expected = b"Hello\nWorld"
actual = client._empty_queue(queue)
assert actual == expected
def _get_paexec_files_and_services(self, client):
server = os.environ['PYPSEXEC_SERVER']
username = os.environ['PYPSEXEC_USERNAME']
password = os.environ['PYPSEXEC_PASSWORD']
paexec_services = []
# need to close and reopen the connection to ensure deletes are
# processed
client.disconnect()
client = Client(server, username=username, password=password)
client.connect()
scmr = client._service._scmr
scmr_handle = client._service._scmr_handle
services = scmr.enum_services_status_w(scmr_handle,
ServiceType.
SERVICE_WIN32_OWN_PROCESS,
EnumServiceState.
SERVICE_STATE_ALL)
for service in services:
if service['service_name'].lower().startswith("paexec"):
paexec_services.append(service['service_name'])
smb_tree = TreeConnect(client.session,
r"\\%s\ADMIN$" % client.connection.server_name)
smb_tree.connect()
def _get_new_generic_client(self, client):
username = os.environ['PYPSEXEC_USERNAME']
password = os.environ['PYPSEXEC_PASSWORD']
new_client = Client(client.server, username, password)
new_client.pid = 1234
new_client.current_host = "other-host"
new_client.service_name = "PAExec-%d-%s"\
% (new_client.pid, new_client.current_host)
new_client._exe_file = "%s.exe" % new_client.service_name
new_client._service = Service(new_client.service_name,
new_client.session)
return new_client
def test_proc_both_elevated_and_limited_error(self):
client = Client("username", "password", "server")
with pytest.raises(PypsexecException) as exc:
client.run_executable("whoami",
run_elevated=True,
run_limited=True)
assert str(exc.value) == "Both run_elevated and run_limited are " \
"set, only 1 of these can be true"
def client(self):
server = os.environ.get('PYPSEXEC_SERVER', None)
username = os.environ.get('PYPSEXEC_USERNAME', None)
password = os.environ.get('PYPSEXEC_PASSWORD', None)
if server and username and password:
client = Client(server, username=username, password=password)
client.connect()
try:
client.create_service()
yield client
finally:
client.disconnect()
else:
pytest.skip("PYPSEXEC_SERVER, PYPSEXEC_USERNAME, PYPSEXEC_PASSWORD"
" environment variables were not set. Integration "
def test_proc_stdin_and_async(self):
client = Client("username", "password", "server")
with pytest.raises(PypsexecException) as exc:
client.run_executable("whoami",
asynchronous=True,
stdin=b"")
assert str(exc.value) == "Cannot send stdin data on an interactive " \
"or asynchronous process"
"high": ProcessPriority.HIGH_PRIORITY_CLASS,
"idle": ProcessPriority.IDLE_PRIORITY_CLASS,
"normal": ProcessPriority.NORMAL_PRIORITY_CLASS,
"realtime": ProcessPriority.REALTIME_PRIORITY_CLASS
}[module.params['priority']]
show_ui_on_logon_screen = module.params['show_ui_on_logon_screen']
process_timeout = module.params['process_timeout']
stdin = module.params['stdin']
if connection_username is None or connection_password is None and \
not HAS_KERBEROS:
module.fail_json(msg=missing_required_lib("gssapi"),
execption=KERBEROS_IMP_ERR)
win_client = client.Client(server=hostname, username=connection_username,
password=connection_password, port=port,
encrypt=encrypt)
try:
win_client.connect(timeout=connection_timeout)
except SMBAuthenticationError as exc:
module.fail_json(msg='Failed to authenticate over SMB: %s'
% to_text(exc))
except SMBResponseException as exc:
module.fail_json(msg='Received unexpected SMB response when opening '
'the connection: %s' % to_text(exc))
except PDUException as exc:
module.fail_json(msg='Received an exception with RPC PDU message: %s'
% to_text(exc))
except SCMRException as exc:
module.fail_json(msg='Received an exception when dealing with SCMR on '