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_create_destroy(self):
event_loop_group = EventLoopGroup()
host_resolver = DefaultHostResolver(event_loop_group)
bootstrap = ClientBootstrap(event_loop_group, host_resolver)
# ensure shutdown_event fires
bootstrap_shutdown_event = bootstrap.shutdown_event
del bootstrap
self.assertTrue(bootstrap_shutdown_event.wait(TIMEOUT))
def _new_client_connection(self, secure, proxy_options=None):
if secure:
tls_ctx_opt = TlsContextOptions()
tls_ctx_opt.override_default_trust_store_from_path(None, 'test/resources/unittests.crt')
tls_ctx = ClientTlsContext(tls_ctx_opt)
tls_conn_opt = tls_ctx.new_connection_options()
tls_conn_opt.set_server_name(self.hostname)
else:
tls_conn_opt = None
event_loop_group = EventLoopGroup()
host_resolver = DefaultHostResolver(event_loop_group)
bootstrap = ClientBootstrap(event_loop_group, host_resolver)
connection_future = HttpClientConnection.new(host_name=self.hostname,
port=self.port,
bootstrap=bootstrap,
tls_connection_options=tls_conn_opt,
proxy_options=proxy_options)
return connection_future.result(self.timeout)
def test_websockets_proxy(self):
config = Config.get()
elg = EventLoopGroup()
resolver = DefaultHostResolver(elg)
bootstrap = ClientBootstrap(elg, resolver)
cred_provider = AwsCredentialsProvider.new_default_chain(bootstrap)
connection = awsiot_mqtt_connection_builder.websockets_with_default_aws_signing(
credentials_provider=cred_provider,
websocket_proxy_options=HttpProxyOptions(PROXY_HOST, PROXY_PORT),
endpoint=config.endpoint,
region=config.region,
client_id=create_client_id(),
client_bootstrap=bootstrap)
self._test_connection(connection)
def test_init_defaults(self):
event_loop_group = EventLoopGroup()
def test_1_thread(self):
event_loop_group = EventLoopGroup(1)
def _new_client_connection(self, secure, proxy_options=None):
if secure:
tls_ctx_opt = TlsContextOptions()
tls_ctx_opt.override_default_trust_store_from_path(None, 'test/resources/unittests.crt')
tls_ctx = ClientTlsContext(tls_ctx_opt)
tls_conn_opt = tls_ctx.new_connection_options()
tls_conn_opt.set_server_name(self.hostname)
else:
tls_conn_opt = None
event_loop_group = EventLoopGroup()
host_resolver = DefaultHostResolver(event_loop_group)
bootstrap = ClientBootstrap(event_loop_group, host_resolver)
connection_future = HttpClientConnection.new(host_name=self.hostname,
port=self.port,
bootstrap=bootstrap,
tls_connection_options=tls_conn_opt,
proxy_options=proxy_options)
return connection_future.result(self.timeout)
def test_default_provider(self):
# Use environment variable to force specific credentials file
scoped_env = ScopedEnvironmentVariable('AWS_SHARED_CREDENTIALS_FILE', 'test/resources/credentials_test')
event_loop_group = awscrt.io.EventLoopGroup()
host_resolver = awscrt.io.DefaultHostResolver(event_loop_group)
bootstrap = awscrt.io.ClientBootstrap(event_loop_group, host_resolver)
provider = awscrt.auth.AwsCredentialsProvider.new_default_chain(bootstrap)
future = provider.get_credentials()
credentials = future.result(TIMEOUT)
self.assertEqual('credentials_test_access_key_id', credentials.access_key_id)
self.assertEqual('credentials_test_secret_access_key', credentials.secret_access_key)
self.assertIsNone(credentials.session_token)
del scoped_env
def test_websockets_proxy(self):
config = Config.get()
elg = EventLoopGroup()
resolver = DefaultHostResolver(elg)
bootstrap = ClientBootstrap(elg, resolver)
cred_provider = AwsCredentialsProvider.new_default_chain(bootstrap)
connection = awsiot_mqtt_connection_builder.websockets_with_default_aws_signing(
credentials_provider=cred_provider,
websocket_proxy_options=HttpProxyOptions(PROXY_HOST, PROXY_PORT),
endpoint=config.endpoint,
region=config.region,
client_id=create_client_id(),
client_bootstrap=bootstrap)
self._test_connection(connection)
def _test_connection(self):
config = Config.get()
elg = EventLoopGroup()
resolver = DefaultHostResolver(elg)
bootstrap = ClientBootstrap(elg, resolver)
tls_opts = TlsContextOptions.create_client_with_mtls(config.cert, config.key)
tls = ClientTlsContext(tls_opts)
client = Client(bootstrap, tls)
connection = Connection(
client=client,
client_id=create_client_id(),
host_name=config.endpoint,
port=8883)
connection.connect().result(TIMEOUT)
return connection
def _new_client_connection(self, secure, proxy_options=None):
if secure:
tls_ctx_opt = TlsContextOptions()
tls_ctx_opt.override_default_trust_store_from_path(None, 'test/resources/unittests.crt')
tls_ctx = ClientTlsContext(tls_ctx_opt)
tls_conn_opt = tls_ctx.new_connection_options()
tls_conn_opt.set_server_name(self.hostname)
else:
tls_conn_opt = None
event_loop_group = EventLoopGroup()
host_resolver = DefaultHostResolver(event_loop_group)
bootstrap = ClientBootstrap(event_loop_group, host_resolver)
connection_future = HttpClientConnection.new(host_name=self.hostname,
port=self.port,
bootstrap=bootstrap,
tls_connection_options=tls_conn_opt,
proxy_options=proxy_options)
return connection_future.result(self.timeout)