def test_invalid_ssl_version_config(self): msg = "invalid_ssl is not a valid SSL protocol, please use one of TLSv1, TLSv1_1, or TLSv1_2" with assert_raises(SystemExit) as error: ssl_settings( self.host, os.path.join('test', 'config', 'sslhandling_invalid.config')) assert msg in error.exception.message
def _test_ssl_version_from_env(self, version): """ Getting SSL version string from env variable SSL_VERSION. """ os.environ['SSL_VERSION'] = version ssl_ret_val = ssl_settings(self.host, self.config_file) assert ssl_ret_val is not None assert ssl_ret_val.get('ssl_version') == getattr(ssl, 'PROTOCOL_%s' % version)
def __init__(self, hostname, port, color=False, username=None, password=None, encoding=None, stdin=None, tty=True, completekey=cqlsh.DEFAULT_COMPLETEKEY, browser=None, use_conn=None, cqlver=None, keyspace=None, tracing_enabled=False, expand_enabled=False, no_compact=False, display_nanotime_format=cqlsh.DEFAULT_NANOTIME_FORMAT, display_timestamp_format=cqlsh.DEFAULT_TIMESTAMP_FORMAT, display_date_format=cqlsh.DEFAULT_DATE_FORMAT, display_float_precision=cqlsh.DEFAULT_FLOAT_PRECISION, display_double_precision=cqlsh.DEFAULT_DOUBLE_PRECISION, display_timezone=None, max_trace_wait=cqlsh.DEFAULT_MAX_TRACE_WAIT, ssl=False, single_statement=None, request_timeout=cqlsh.DEFAULT_REQUEST_TIMEOUT_SECONDS, protocol_version=None, connect_timeout=cqlsh.DEFAULT_CONNECT_TIMEOUT_SECONDS, no_file_io=cqlsh.DEFAULT_NO_FILE_IO, is_subshell=False): from dselib.authfactory import get_auth_provider if username: if not password: password = getpass.getpass() auth_provider = get_auth_provider(cqlsh.CONFIG_FILE, os.environ, username, password, cqlsh.options) self.execute_as = None self.consistency_level = dse.ConsistencyLevel.ONE self.serial_consistency_level = dse.ConsistencyLevel.SERIAL conn = None execution_profile = ExecutionProfile( load_balancing_policy=WhiteListRoundRobinPolicy([hostname]), row_factory=ordered_dict_factory, request_timeout=request_timeout, consistency_level=self.consistency_level, serial_consistency_level=self.serial_consistency_level) self.execution_profiles = {EXEC_PROFILE_DEFAULT: execution_profile} if use_conn: conn = use_conn else: kwargs = {} if protocol_version is not None: kwargs['protocol_version'] = protocol_version conn = cqlsh.Cluster( contact_points=(hostname, ), port=port, cql_version=cqlver, auth_provider=auth_provider, ssl_options=sslhandling.ssl_settings( hostname, cqlsh.CONFIG_FILE) if ssl else None, control_connection_timeout=connect_timeout, connect_timeout=connect_timeout, execution_profiles=self.execution_profiles, **kwargs) OriginalShell.__init__( self, hostname, port, color=color, auth_provider=auth_provider, username=username, password=password, encoding=encoding, stdin=stdin, tty=tty, completekey=completekey, browser=browser, use_conn=conn, cqlver=cqlver, keyspace=keyspace, tracing_enabled=tracing_enabled, expand_enabled=expand_enabled, no_compact=no_compact, display_nanotime_format=display_nanotime_format, display_timestamp_format=display_timestamp_format, display_date_format=display_date_format, display_float_precision=display_float_precision, display_double_precision=display_double_precision, display_timezone=display_timezone, max_trace_wait=max_trace_wait, ssl=ssl, single_statement=single_statement, request_timeout=request_timeout, protocol_version=protocol_version, connect_timeout=connect_timeout, no_file_io=no_file_io, is_subshell=is_subshell) self.owns_connection = not use_conn self.execution_profile = self.session.get_execution_profile( EXEC_PROFILE_DEFAULT)
def test_ssl_version_config(self): ssl_ret_val = ssl_settings( self.host, os.path.join('test', 'config', 'sslhandling.config')) assert ssl_ret_val is not None assert ssl_ret_val.get('ssl_version') == getattr(ssl, 'PROTOCOL_TLSv1')
def test_default_ssl_version(self): ssl_ret_val = ssl_settings(self.host, self.config_file) assert ssl_ret_val is not None assert ssl_ret_val.get('ssl_version') == getattr(ssl, 'PROTOCOL_TLS')
def __init__(self, hostname, port, color=False, username=None, password=None, encoding=None, stdin=None, tty=True, completekey=cqlsh.DEFAULT_COMPLETEKEY, browser=None, use_conn=None, cqlver=None, keyspace=None, secure_connect_bundle=None, consistency_level=None, serial_consistency_level=None, tracing_enabled=False, timing_enabled=False, expand_enabled=False, display_nanotime_format=cqlsh.DEFAULT_NANOTIME_FORMAT, display_timestamp_format=cqlsh.DEFAULT_TIMESTAMP_FORMAT, display_date_format=cqlsh.DEFAULT_DATE_FORMAT, display_float_precision=cqlsh.DEFAULT_FLOAT_PRECISION, display_double_precision=cqlsh.DEFAULT_DOUBLE_PRECISION, display_timezone=None, max_trace_wait=cqlsh.DEFAULT_MAX_TRACE_WAIT, ssl=False, single_statement=None, request_timeout=cqlsh.DEFAULT_REQUEST_TIMEOUT_SECONDS, protocol_version=None, connect_timeout=cqlsh.DEFAULT_CONNECT_TIMEOUT_SECONDS, no_file_io=cqlsh.DEFAULT_NO_FILE_IO, is_subshell=False): from dselib.authfactory import get_auth_provider if username: if not password: password = getpass.getpass() auth_provider = get_auth_provider(cqlsh.CONFIG_FILE, os.environ, username, password, cqlsh.options) \ if not is_unix_socket(hostname) else None self.execute_as = None if not consistency_level: raise Exception('Argument consistency_level must not be None') if not serial_consistency_level: raise Exception( 'Argument serial_consistency_level must not be None') self.consistency_level = consistency_level self.serial_consistency_level = serial_consistency_level execution_profile = ExecutionProfile( row_factory=ordered_dict_factory, request_timeout=request_timeout, consistency_level=self.consistency_level, serial_consistency_level=self.serial_consistency_level) self.execution_profiles = {EXEC_PROFILE_DEFAULT: execution_profile} if use_conn: conn = use_conn else: conn = cluster_factory( hostname, port=port, protocol_version=protocol_version if protocol_version is not None else _NOT_SET, cql_version=cqlver, auth_provider=auth_provider, ssl_options=sslhandling.ssl_settings( hostname, cqlsh.CONFIG_FILE) if ssl else None, control_connection_timeout=connect_timeout, connect_timeout=connect_timeout, execution_profiles=self.execution_profiles, secure_connect_bundle=secure_connect_bundle) OriginalShell.__init__( self, hostname, port, color=color, auth_provider=auth_provider, username=username, password=password, encoding=encoding, stdin=stdin, tty=tty, completekey=completekey, browser=browser, use_conn=conn, cqlver=cqlver, keyspace=keyspace, secure_connect_bundle=secure_connect_bundle, consistency_level=consistency_level, serial_consistency_level=serial_consistency_level, tracing_enabled=tracing_enabled, timing_enabled=timing_enabled, expand_enabled=expand_enabled, display_nanotime_format=display_nanotime_format, display_timestamp_format=display_timestamp_format, display_date_format=display_date_format, display_float_precision=display_float_precision, display_double_precision=display_double_precision, display_timezone=display_timezone, max_trace_wait=max_trace_wait, ssl=ssl, single_statement=single_statement, request_timeout=request_timeout, protocol_version=protocol_version, connect_timeout=connect_timeout, no_file_io=no_file_io, is_subshell=is_subshell) self.owns_connection = not use_conn self.execution_profile = self.session.get_execution_profile( EXEC_PROFILE_DEFAULT)