diff --git a/aws-c-auth b/aws-c-auth index a42e16d8e..0ecb31397 160000 --- a/aws-c-auth +++ b/aws-c-auth @@ -1 +1 @@ -Subproject commit a42e16d8e8a32e761f3791648bbad0d1414a3e16 +Subproject commit 0ecb3139761c6ad75cc91d81fc952a4ef11a5848 diff --git a/aws-c-mqtt b/aws-c-mqtt index 632f99668..8c78e0890 160000 --- a/aws-c-mqtt +++ b/aws-c-mqtt @@ -1 +1 @@ -Subproject commit 632f996688945c8845628405288e22f10ac822d0 +Subproject commit 8c78e08908d31b418c86302278fc6a107754eaea diff --git a/awscrt/auth.py b/awscrt/auth.py index acd4f5078..fb3de475e 100644 --- a/awscrt/auth.py +++ b/awscrt/auth.py @@ -171,6 +171,21 @@ class AwsSigningAlgorithm(IntEnum): SigV4QueryParam = 1 +class AwsBodySigningConfigType(IntEnum): + """Body Signing config + + BodySigningOff: No attempts will be made to sign the payload, and no + x-amz-content-sha256 header will be added to the request. + BodySigningOn: The body will be signed and x-amz-content-sha256 will contain + the value of the signature + UnsignedPayload: The body will not be signed, but x-amz-content-sha256 will contain + the value UNSIGNED-PAYLOAD. This value is currently only used for Amazon S3. + """ + BodySigningOff = 0 + BodySigningOn = 1 + UnsignedPayload = 2 + + class AwsSigningConfig(NativeResource): """ Configuration for use in AWS-related signing. @@ -179,10 +194,10 @@ class AwsSigningConfig(NativeResource): It is good practice to use a new config for each signature, or the date might get too old. Naive dates (lacking timezone info) are assumed to be in local time. """ - __slots__ = () + __slots__ = ('_priv_should_sign_cb') _attributes = ('algorithm', 'credentials_provider', 'region', 'service', 'date', 'should_sign_param', - 'use_double_uri_encode', 'should_normalize_uri_path', 'sign_body') + 'use_double_uri_encode', 'should_normalize_uri_path', 'body_signing_type') def __init__(self, algorithm, # type: AwsSigningAlgorithm @@ -193,7 +208,7 @@ def __init__(self, should_sign_param=None, # type: Optional[Callable[[str], bool]] use_double_uri_encode=False, # type: bool should_normalize_uri_path=True, # type: bool - sign_body=True # type: bool + body_signing_type=AwsBodySigningConfigType.BodySigningOn # type: AwsBodySigningConfigType ): # type: (...) -> None @@ -203,6 +218,7 @@ def __init__(self, assert isinstance_str(service) assert isinstance(date, datetime.datetime) or date is None assert callable(should_sign_param) or should_sign_param is None + assert isinstance(body_signing_type, AwsBodySigningConfigType) super(AwsSigningConfig, self).__init__() @@ -220,6 +236,14 @@ def __init__(self, epoch = datetime.datetime(1970, 1, 1, tzinfo=_utc) timestamp = (date - epoch).total_seconds() + self._priv_should_sign_cb = should_sign_param + + if should_sign_param is not None: + def should_sign_param_wrapper(name): + return should_sign_param(name=name) + else: + should_sign_param_wrapper = None + self._binding = _awscrt.signing_config_new( algorithm, credentials_provider, @@ -227,10 +251,10 @@ def __init__(self, service, date, timestamp, - should_sign_param, + should_sign_param_wrapper, use_double_uri_encode, should_normalize_uri_path, - sign_body) + body_signing_type) def replace(self, **kwargs): """ @@ -279,7 +303,7 @@ def should_sign_param(self): supplements it. In particular, a header will get signed if and only if it returns true to both the internal check (skips x-amzn-trace-id, user-agent) and this function (if defined). """ - return _awscrt.signing_config_get_should_sign_param(self._binding) + return self._priv_should_sign_cb @property def use_double_uri_encode(self): @@ -296,12 +320,18 @@ def should_normalize_uri_path(self): return _awscrt.signing_config_get_should_normalize_uri_path(self._binding) @property - def sign_body(self): + def body_signing_type(self): """ - If true adds the x-amz-content-sha256 header (with appropriate value) to the canonical request, - otherwise does nothing + BodySigningOff: No attempts will be made to sign the payload, and no + x-amz-content-sha256 header will be added to the request. + + BodySigningOn: The body will be signed and x-amz-content-sha256 will contain + the value of the signature + + UnsignedPayload: The body will not be signed, but x-amz-content-sha256 will contain + the value UNSIGNED-PAYLOAD. This value is currently only used for Amazon S3. """ - return _awscrt.signing_config_get_sign_body(self._binding) + return AwsBodySigningConfigType(_awscrt.signing_config_get_body_signing_type(self._binding)) def aws_sign_request(http_request, signing_config): diff --git a/awscrt/awsiot_mqtt_connection_builder.py b/awscrt/awsiot_mqtt_connection_builder.py index ed586051e..e30c46ec4 100644 --- a/awscrt/awsiot_mqtt_connection_builder.py +++ b/awscrt/awsiot_mqtt_connection_builder.py @@ -237,8 +237,9 @@ def websockets_with_default_aws_signing(region, credentials_provider, websocket_ """ _check_required_kwargs(**kwargs) - def _should_sign_param(name): + def _should_sign_param(**kwargs): blacklist = ['x-amz-date', 'x-amz-security-token'] + name = kwargs['name'] return not (name.lower() in blacklist) def _sign_websocket_handshake_request(handshake_args): @@ -250,7 +251,7 @@ def _sign_websocket_handshake_request(handshake_args): region=region, service='iotdevicegateway', should_sign_param=_should_sign_param, - sign_body=False) + body_signing_type=awscrt.auth.AwsBodySigningConfigType.BodySigningOff) signing_future = awscrt.auth.aws_sign_request(handshake_args.http_request, signing_config) signing_future.add_done_callback(lambda x: handshake_args.set_done(x.exception())) diff --git a/awscrt/http.py b/awscrt/http.py index 2aa71975a..5ee1d7780 100644 --- a/awscrt/http.py +++ b/awscrt/http.py @@ -157,7 +157,7 @@ def completion_future(self): def _on_body(self, chunk): if self._on_body_cb: - self._on_body_cb(self, chunk) + self._on_body_cb(http_stream=self, chunk=chunk) class HttpClientStream(HttpStreamBase): @@ -184,7 +184,7 @@ def _on_response(self, status_code, name_value_pairs): self._response_status_code = status_code if self._on_response_cb: - self._on_response_cb(self, status_code, name_value_pairs) + self._on_response_cb(http_stream=self, status_code=status_code, headers=name_value_pairs) def _on_complete(self, error_code): if error_code == 0: diff --git a/awscrt/mqtt.py b/awscrt/mqtt.py index a77d968f1..7a303d9a3 100644 --- a/awscrt/mqtt.py +++ b/awscrt/mqtt.py @@ -107,14 +107,21 @@ def __init__(self, If an existing session is resumed, the server remembers previous subscriptions and sends mesages (with QoS1 or higher) that were published while the client was offline. - on_connection_interrupted (function): Optional callback with signature: - (Connection, awscrt.exceptions.AwsCrtError) -> None - Invoked when the MQTT connection is lost. + on_connection_interrupted (function): Optional callback invoked whenever the MQTT connection is lost. The MQTT client will automatically attempt to reconnect. - - on_connection_resumed (function): Optional callback with signature: - (Connection, ConnectReturnCode, session_present: bool) -> None - Invoked when the MQTT connection is automatically resumed. + The function should take **kwargs and return nothing. + The kwargs contain: + 'connection': This MQTT Connection + 'error': awscrt.exceptions.AwsCrtError + + on_connection_resumed (function): Optional callback invoked whenever the MQTT connection + is automatically resumed. Function should take **kwargs and return nothing. + The kwargs contain: + 'connection': This MQTT Connection + 'return_code': ConnectReturnCode received from the server. + 'session_present': True if resuming existing session. False if new session. + Note that the server has forgotten all previous subscriptions if this is False. + Subscriptions can be re-established via resubscribe_existing_topics(). reconnect_min_timeout_secs (int): Minimum time to wait between reconnect attempts. Wait starts at min and doubles with each attempt until max is reached. @@ -195,11 +202,14 @@ def __init__(self, def _on_connection_interrupted(self, error_code): if self._on_connection_interrupted_cb: - self._on_connection_interrupted_cb(self, awscrt.exceptions.from_code(error_code)) + self._on_connection_interrupted_cb(connection=self, error=awscrt.exceptions.from_code(error_code)) def _on_connection_resumed(self, return_code, session_present): if self._on_connection_resumed_cb: - self._on_connection_resumed_cb(self, ConnectReturnCode(return_code), session_present) + self._on_connection_resumed_cb( + connection=self, + error=connectionConnectReturnCode(return_code), + session_present=session_present) def _ws_handshake_transform(self, http_request_binding, http_headers_binding, native_userdata): if self._ws_handshake_transform_cb is None: @@ -214,7 +224,7 @@ def _on_complete(f): http_request = HttpRequest._from_bindings(http_request_binding, http_headers_binding) transform_args = WebsocketHandshakeTransformArgs(self, http_request, future) try: - self._ws_handshake_transform_cb(transform_args) + self._ws_handshake_transform_cb(transform_args=transform_args) except Exception as e: # Call set_done() if user failed to do so before uncaught exception was raised, # there's a chance the callback wasn't callable and user has no idea we tried to hand them the baton. @@ -289,12 +299,22 @@ def on_disconnect(): def subscribe(self, topic, qos, callback=None): """ - callback: optional callback with signature (topic, message) + callback: Optional callback invoked when message received. + Function should take **kwargs and return nothing. + The kwargs contain: + 'topic' (str): Topic receiving message. + 'payload' (bytes): Payload of message. """ future = Future() packet_id = 0 + if callback: + def callback_wrapper(topic, payload): + callback(topic=topic, payload=payload) + else: + callback_wrapper = None + def suback(packet_id, topic, qos, error_code): if error_code: future.set_exception(awscrt.exceptions.from_code(error_code)) @@ -312,7 +332,8 @@ def suback(packet_id, topic, qos, error_code): try: assert callable(callback) or callback is None assert isinstance(qos, QoS) - packet_id = _awscrt.mqtt_client_connection_subscribe(self._binding, topic, qos.value, callback, suback) + packet_id = _awscrt.mqtt_client_connection_subscribe( + self._binding, topic, qos.value, callback_wrapper, suback) except Exception as e: future.set_exception(e) @@ -320,10 +341,21 @@ def suback(packet_id, topic, qos, error_code): def on_message(self, callback): """ - callback: callback with signature (topic, message), or None to disable. + callback: Callback invoked when message received, or None to disable. + Function should take **kwargs and return nothing. + The kwargs contain: + 'topic' (str): Topic receiving message. + 'payload' (bytes): Payload of message. """ assert callable(callback) or callback is None - _awscrt.mqtt_client_connection_on_message(self._binding, callback) + + if callback: + def callback_wrapper(topic, payload): + callback(topic=topic, payload=payload) + else: + callback_wrapper = None + + _awscrt.mqtt_client_connection_on_message(self._binding, callback_wrapper) def unsubscribe(self, topic): future = Future() diff --git a/elasticurl.py b/elasticurl.py index ae2f7ae79..fc0d579b9 100644 --- a/elasticurl.py +++ b/elasticurl.py @@ -28,25 +28,63 @@ def print_header_list(headers): parser = argparse.ArgumentParser() -parser.add_argument('url', help='URL to make request to. HTTPS is assumed unless port 80 is specified or HTTP is specified in the scheme.') +parser.add_argument( + 'url', + help='URL to make request to. HTTPS is assumed unless port 80 is specified or HTTP is specified in the scheme.') parser.add_argument('--cacert', required=False, help='FILE: path to a CA certificate file.') parser.add_argument('--capath', required=False, help='PATH: path to a directory containing CA files.') parser.add_argument('--cert', required=False, help='FILE: path to a PEM encoded certificate to use with mTLS') parser.add_argument('--key', required=False, help='FILE: Path to a PEM encoded private key that matches cert.') -parser.add_argument('--connect_timeout', required=False, type=int, help='INT: time in milliseconds to wait for a connection.', default=3000) -parser.add_argument('-H', '--header', required=False, help='STRING: line to send as a header in format "name:value". May be specified multiple times.', action='append') +parser.add_argument( + '--connect_timeout', + required=False, + type=int, + help='INT: time in milliseconds to wait for a connection.', + default=3000) +parser.add_argument( + '-H', + '--header', + required=False, + help='STRING: line to send as a header in format "name:value". May be specified multiple times.', + action='append') parser.add_argument('-d', '--data', required=False, help='STRING: Data to POST or PUT.') parser.add_argument('--data_file', required=False, help='FILE: File to read from file and POST or PUT') -parser.add_argument('-M', '--method', required=False, help='STRING: Http Method verb to use for the request', default='GET') +parser.add_argument( + '-M', + '--method', + required=False, + help='STRING: Http Method verb to use for the request', + default='GET') parser.add_argument('-G', '--get', required=False, help='uses GET for the verb', action='store_true') parser.add_argument('-P', '--post', required=False, help='uses POST for the verb', action='store_true') parser.add_argument('-I', '--head', required=False, help='uses HEAD for the verb', action='store_true') -parser.add_argument('-i', '--include', required=False, help='Includes headers in output', action='store_true', default=False) -parser.add_argument('-k', '--insecure', required=False, help='Turns off x.509 validation', action='store_true', default=False) +parser.add_argument( + '-i', + '--include', + required=False, + help='Includes headers in output', + action='store_true', + default=False) +parser.add_argument( + '-k', + '--insecure', + required=False, + help='Turns off x.509 validation', + action='store_true', + default=False) parser.add_argument('-o', '--output', required=False, help='FILE: dumps content-body to FILE instead of stdout.') parser.add_argument('-t', '--trace', required=False, help='FILE: dumps logs to FILE instead of stderr.') -parser.add_argument('-p', '--alpn', required=False, help='STRING: protocol for ALPN. May be specified multiple times.', action='append') -parser.add_argument('-v', '--verbose', required=False, help='ERROR|INFO|DEBUG|TRACE: log level to configure. Default is none.') +parser.add_argument( + '-p', + '--alpn', + required=False, + help='STRING: protocol for ALPN. May be specified multiple times.', + action='append') +parser.add_argument( + '-v', + '--verbose', + required=False, + help='ERROR|INFO|DEBUG|TRACE: log level to configure. Default is none.') args = parser.parse_args() @@ -85,7 +123,7 @@ def print_header_list(headers): host_resolver = io.DefaultHostResolver(event_loop_group) - # client bootstrap knows how to connect all the pieces. In this case it also has the default dns resolver +# client bootstrap knows how to connect all the pieces. In this case it also has the default dns resolver # baked in. client_bootstrap = io.ClientBootstrap(event_loop_group, host_resolver) @@ -126,13 +164,15 @@ def print_header_list(headers): tls_connection_options.set_alpn_list(args.alpn) # invoked up on the connection closing + + def on_connection_shutdown(shutdown_future): print('connection close with error: {}'.format(shutdown_future.exception())) # invoked by the http request call as the response body is received in chunks -def on_incoming_body(http_stream, body_data): - output.write(body_data) +def on_incoming_body(http_stream, chunk): + output.write(chunk) data_len = 0 @@ -190,6 +230,8 @@ def on_incoming_body(http_stream, body_data): request.headers.add(name.strip(), value.strip()) # invoked as soon as the response headers are received + + def response_received_cb(http_stream, status_code, headers): if args.include: print('Response Code: {}'.format(status_code)) diff --git a/mqtt_test.py b/mqtt_test.py index a563976cd..5a13810d6 100644 --- a/mqtt_test.py +++ b/mqtt_test.py @@ -59,8 +59,8 @@ def on_resubscribe_complete(resubscribe_future): receive_results = {} receive_event = threading.Event() -def on_receive_message(topic, message): - receive_results.update(locals()) +def on_receive_message(**kwargs): + receive_results.update(kwargs) receive_event.set() # Run @@ -133,7 +133,7 @@ def on_receive_message(topic, message): print("Waiting to receive messsage") assert(receive_event.wait(TIMEOUT)) assert(receive_results['topic'] == TOPIC) -assert(receive_results['message'].decode() == MESSAGE) +assert(receive_results['payload'].decode() == MESSAGE) # Unsubscribe print("Unsubscribing from topic") diff --git a/setup.py b/setup.py index dedf78e6d..f8f1e73bd 100644 --- a/setup.py +++ b/setup.py @@ -228,7 +228,7 @@ def awscrt_ext(): setuptools.setup( name="awscrt", - version="0.4.1", + version="0.5.1", author="Amazon Web Services, Inc", author_email="aws-sdk-common-runtime@amazon.com", description="A common runtime for AWS Python projects", diff --git a/source/auth.h b/source/auth.h index 7045b58d9..4e3c0b2c4 100644 --- a/source/auth.h +++ b/source/auth.h @@ -33,10 +33,9 @@ PyObject *aws_py_signing_config_get_credentials_provider(PyObject *self, PyObjec PyObject *aws_py_signing_config_get_region(PyObject *self, PyObject *args); PyObject *aws_py_signing_config_get_service(PyObject *self, PyObject *args); PyObject *aws_py_signing_config_get_date(PyObject *self, PyObject *args); -PyObject *aws_py_signing_config_get_should_sign_param(PyObject *self, PyObject *args); PyObject *aws_py_signing_config_get_use_double_uri_encode(PyObject *self, PyObject *args); PyObject *aws_py_signing_config_get_should_normalize_uri_path(PyObject *self, PyObject *args); -PyObject *aws_py_signing_config_get_sign_body(PyObject *self, PyObject *args); +PyObject *aws_py_signing_config_get_body_signing_type(PyObject *self, PyObject *args); PyObject *aws_py_sign_request_aws(PyObject *self, PyObject *args); diff --git a/source/auth_signing_config.c b/source/auth_signing_config.c index 61d790db0..819ae306b 100644 --- a/source/auth_signing_config.c +++ b/source/auth_signing_config.c @@ -84,10 +84,10 @@ PyObject *aws_py_signing_config_new(PyObject *self, PyObject *args) { PyObject *py_should_sign_param_fn; PyObject *py_use_double_uri_encode; PyObject *py_should_normalize_uri_path; - PyObject *py_sign_body; + int py_body_signing_config; if (!PyArg_ParseTuple( args, - "iOs#s#OdOOOO", + "iOs#s#OdOOOi", &algorithm, &py_credentials_provider, ®ion.ptr, @@ -99,7 +99,7 @@ PyObject *aws_py_signing_config_new(PyObject *self, PyObject *args) { &py_should_sign_param_fn, &py_use_double_uri_encode, &py_should_normalize_uri_path, - &py_sign_body)) { + &py_body_signing_config)) { return NULL; } @@ -123,7 +123,7 @@ PyObject *aws_py_signing_config_new(PyObject *self, PyObject *args) { binding->native.algorithm = algorithm; binding->native.use_double_uri_encode = PyObject_IsTrue(py_use_double_uri_encode); binding->native.should_normalize_uri_path = PyObject_IsTrue(py_should_normalize_uri_path); - binding->native.sign_body = PyObject_IsTrue(py_sign_body); + binding->native.body_signing_type = py_body_signing_config; /* credentials_provider */ binding->native.credentials_provider = aws_py_get_credentials_provider(py_credentials_provider); @@ -243,16 +243,6 @@ PyObject *aws_py_signing_config_get_date(PyObject *self, PyObject *args) { return binding->py_date; } -PyObject *aws_py_signing_config_get_should_sign_param(PyObject *self, PyObject *args) { - struct config_binding *binding = s_common_get(self, args); - if (!binding) { - return NULL; - } - - Py_INCREF(binding->py_should_sign_param_fn); - return binding->py_should_sign_param_fn; -} - PyObject *aws_py_signing_config_get_use_double_uri_encode(PyObject *self, PyObject *args) { struct config_binding *binding = s_common_get(self, args); if (!binding) { @@ -271,11 +261,11 @@ PyObject *aws_py_signing_config_get_should_normalize_uri_path(PyObject *self, Py return PyBool_FromLong(binding->native.should_normalize_uri_path); } -PyObject *aws_py_signing_config_get_sign_body(PyObject *self, PyObject *args) { +PyObject *aws_py_signing_config_get_body_signing_type(PyObject *self, PyObject *args) { struct config_binding *binding = s_common_get(self, args); if (!binding) { return NULL; } - return PyBool_FromLong(binding->native.sign_body); + return PyLong_FromLong(binding->native.body_signing_type); } diff --git a/source/module.c b/source/module.c index 4f63894d2..19ef9256f 100644 --- a/source/module.c +++ b/source/module.c @@ -459,10 +459,9 @@ static PyMethodDef s_module_methods[] = { AWS_PY_METHOD_DEF(signing_config_get_region, METH_VARARGS), AWS_PY_METHOD_DEF(signing_config_get_service, METH_VARARGS), AWS_PY_METHOD_DEF(signing_config_get_date, METH_VARARGS), - AWS_PY_METHOD_DEF(signing_config_get_should_sign_param, METH_VARARGS), AWS_PY_METHOD_DEF(signing_config_get_use_double_uri_encode, METH_VARARGS), AWS_PY_METHOD_DEF(signing_config_get_should_normalize_uri_path, METH_VARARGS), - AWS_PY_METHOD_DEF(signing_config_get_sign_body, METH_VARARGS), + AWS_PY_METHOD_DEF(signing_config_get_body_signing_type, METH_VARARGS), AWS_PY_METHOD_DEF(sign_request_aws, METH_VARARGS), {NULL, NULL, 0, NULL}, diff --git a/source/mqtt_client_connection.c b/source/mqtt_client_connection.c index 1f6f4e059..73e017689 100644 --- a/source/mqtt_client_connection.c +++ b/source/mqtt_client_connection.c @@ -914,14 +914,12 @@ PyObject *aws_py_mqtt_client_connection_on_message(PyObject *self, PyObject *arg Py_RETURN_NONE; } - callback = PyWeakref_NewProxy(callback, NULL); - AWS_FATAL_ASSERT(callback); - if (aws_mqtt_client_connection_set_on_any_publish_handler(py_connection->native, s_subscribe_callback, callback)) { Py_DECREF(callback); return PyErr_AwsLastError(); } + Py_INCREF(callback); py_connection->on_any_publish = callback; Py_RETURN_NONE; diff --git a/test/test_auth.py b/test/test_auth.py index a9a9bf9f1..c787fc93b 100644 --- a/test/test_auth.py +++ b/test/test_auth.py @@ -119,7 +119,7 @@ def should_sign_param(name): use_double_uri_encode = True should_normalize_uri_path = False - sign_body = False + body_signing_type = awscrt.auth.AwsBodySigningConfigType.BodySigningOff cfg = awscrt.auth.AwsSigningConfig(algorithm=algorithm, credentials_provider=credentials_provider, @@ -129,7 +129,7 @@ def should_sign_param(name): should_sign_param=should_sign_param, use_double_uri_encode=use_double_uri_encode, should_normalize_uri_path=should_normalize_uri_path, - sign_body=sign_body) + body_signing_type=body_signing_type) self.assertIs(algorithm, cfg.algorithm) # assert IS enum, not just EQUAL self.assertIs(credentials_provider, cfg.credentials_provider) @@ -139,7 +139,7 @@ def should_sign_param(name): self.assertIs(should_sign_param, cfg.should_sign_param) self.assertEqual(use_double_uri_encode, cfg.use_double_uri_encode) self.assertEqual(should_normalize_uri_path, cfg.should_normalize_uri_path) - self.assertEqual(sign_body, cfg.sign_body) + self.assertEqual(body_signing_type, cfg.body_signing_type) def test_replace(self): credentials_provider = awscrt.auth.AwsCredentialsProvider.new_static( @@ -154,7 +154,7 @@ def test_replace(self): should_sign_param=lambda x: False, use_double_uri_encode=True, should_normalize_uri_path=False, - sign_body=False) + body_signing_type=awscrt.auth.AwsBodySigningConfigType.BodySigningOff) # Call replace on single attribute, then assert that ONLY the one attribute differs def _replace_attr(name, value): @@ -181,12 +181,13 @@ def _replace_attr(name, value): _replace_attr('should_sign_param', lambda x: True) _replace_attr('use_double_uri_encode', False) _replace_attr('should_normalize_uri_path', True) - _replace_attr('sign_body', True) + _replace_attr('body_signing_type', awscrt.auth.AwsBodySigningConfigType.BodySigningOn) # check that we can replace multiple values at once new_cfg = orig_cfg.replace(region='us-west-3', service='aws-slow-blinking') self.assertEqual('us-west-3', new_cfg.region) self.assertEqual('aws-slow-blinking', new_cfg.service) + self.assertEqual(orig_cfg.should_sign_param, new_cfg.should_sign_param) @@ -224,7 +225,7 @@ def test_signing_sigv4_headers(self): region=SIGV4TEST_REGION, service=SIGV4TEST_SERVICE, date=SIGV4TEST_DATE, - sign_body=False) + body_signing_type=awscrt.auth.AwsBodySigningConfigType.BodySigningOff) http_request = awscrt.http.HttpRequest( method=SIGV4TEST_METHOD, diff --git a/test/test_http_client.py b/test/test_http_client.py index 27a594615..0dcf4d2cb 100644 --- a/test/test_http_client.py +++ b/test/test_http_client.py @@ -46,12 +46,12 @@ def __init__(self): self.headers = None self.body = bytearray() - def on_response(self, stream, status_code, headers): - self.status_code = status_code - self.headers = HttpHeaders(headers) + def on_response(self, **kwargs): + self.status_code = kwargs['status_code'] + self.headers = HttpHeaders(kwargs['headers']) - def on_body(self, stream, chunk): - self.body.extend(chunk) + def on_body(self, **kwargs): + self.body.extend(kwargs['chunk']) class TestRequestHandler(SimpleHTTPRequestHandler): diff --git a/test/test_mqtt.py b/test/test_mqtt.py index 75d6b1070..9ebc7986f 100644 --- a/test/test_mqtt.py +++ b/test/test_mqtt.py @@ -113,8 +113,8 @@ def test_pub_sub(self): connection = self._test_connection() received = Future() - def on_message(topic, payload): - received.set_result((topic, payload)) + def on_message(**kwargs): + received.set_result(kwargs) # subscribe subscribed, packet_id = connection.subscribe(self.TEST_TOPIC, QoS.AT_LEAST_ONCE, on_message) @@ -129,9 +129,9 @@ def on_message(topic, payload): self.assertEqual(packet_id, puback['packet_id']) # receive message - rcv_topic, rcv_payload = received.result(TIMEOUT) - self.assertEqual(self.TEST_TOPIC, rcv_topic) - self.assertEqual(self.TEST_MSG, rcv_payload) + rcv = received.result(TIMEOUT) + self.assertEqual(self.TEST_TOPIC, rcv['topic']) + self.assertEqual(self.TEST_MSG, rcv['payload']) # unsubscribe unsubscribed, packet_id = connection.unsubscribe(self.TEST_TOPIC) @@ -145,8 +145,8 @@ def test_on_message(self): connection = self._test_connection() received = Future() - def on_message(topic, payload): - received.set_result((topic, payload)) + def on_message(**kwargs): + received.set_result(kwargs) connection.on_message(on_message) @@ -159,9 +159,9 @@ def on_message(topic, payload): puback = published.result(TIMEOUT) # receive message - rcv_topic, rcv_payload = received.result(TIMEOUT) - self.assertEqual(self.TEST_TOPIC, rcv_topic) - self.assertEqual(self.TEST_MSG, rcv_payload) + rcv = received.result(TIMEOUT) + self.assertEqual(self.TEST_TOPIC, rcv['topic']) + self.assertEqual(self.TEST_MSG, rcv['payload']) # disconnect connection.disconnect().result(TIMEOUT)