def test_enumerate_services(self, session): scmr = SCMRApi(session) scmr.open() try: scmr_handle = scmr.open_sc_manager_w( session.connection.server_name, None, DesiredAccess.SC_MANAGER_CONNECT | DesiredAccess.SC_MANAGER_CREATE_SERVICE | DesiredAccess.SC_MANAGER_ENUMERATE_SERVICE) types = ServiceType.SERVICE_INTERACTIVE_PROCESS | \ ServiceType.SERVICE_KERNEL_DRIVER | \ ServiceType.SERVICE_WIN32_SHARE_PROCESS | \ ServiceType.SERVICE_WIN32_OWN_PROCESS | \ ServiceType.SERVICE_FILE_SYSTEM_DRIVER actual = scmr.enum_services_status_w( scmr_handle, types, EnumServiceState.SERVICE_STATE_ALL) assert len(actual) > 0 assert isinstance(actual[0]['display_name'], string_types) assert isinstance(actual[0]['service_name'], string_types) assert isinstance(actual[0]['service_status'], ServiceStatus) finally: if scmr_handle: scmr.close_service_handle_w(scmr_handle) scmr.close()
def test_parse_error_unknown(self): connection = Connection(uuid.uuid4(), "server", 445) session = Session(connection, "user", "password") api = SCMRApi(session) with pytest.raises(SCMRException) as exc: api._parse_error(999, "function_name") assert str(exc.value) == "Exception calling function_name. Code: 999" \ ", Msg: ERROR_UNKNOWN"
def test_marshal_string_none(self): connection = Connection(uuid.uuid4(), "server", 445) session = Session(connection, "user", "password") api = SCMRApi(session) expected = b"\x00\x00\x00\x00" actual = api._marshal_string(None) assert actual == expected
def test_parse_pdu_failure(self): connection = Connection(uuid.uuid4(), "server", 445) session = Session(connection, "user", "password") api = SCMRApi(session) fault_pdu = FaultPDU() fault_pdu['packed_drep'] = DataRepresentationFormat() with pytest.raises(PDUException) as exc: api._parse_pdu(fault_pdu.pack(), 10) assert "Expecting ResponsePDU for opnum 10 response but got: " \ "FaultPDU" in str(exc.value)
def test_parse_pdu_fine(self): connection = Connection(uuid.uuid4(), "server", 445) session = Session(connection, "user", "password") api = SCMRApi(session) response_pdu = ResponsePDU() response_pdu['packed_drep'] = DataRepresentationFormat() response_pdu['stub_data'] = b"\x01\x02\x03\x04" expected = b"\x01\x02\x03\x04" actual = api._parse_pdu(response_pdu.pack(), 10) assert actual == expected
def test_marshal_string_as_referent(self): connection = Connection(uuid.uuid4(), "server", 445) session = Session(connection, "user", "password") api = SCMRApi(session) expected = b"\x00\x00\x00\x01" \ b"\x03\x00\x00\x00" \ b"\x00\x00\x00\x00" \ b"\x03\x00\x00\x00" \ b"\x68\x00\x69\x00\x00\x00" \ b"\x00\x00" actual = api._marshal_string("hi", unique=True) assert actual == expected