@@ -109,17 +109,32 @@ def on_lifecycle_disconnection(self, lifecycle_disconnect_data: mqtt5.LifecycleD
109109
110110class Mqtt5ClientTest (NativeResourceTest ):
111111
112+ def _create_tls_context (self ):
113+ cert = _get_env_variable ("AWS_TEST_MQTT5_IOT_CORE_RSA_CERT" )
114+ key = _get_env_variable ("AWS_TEST_MQTT5_IOT_CORE_RSA_KEY" )
115+ return io .ClientTlsContext (
116+ io .TlsContextOptions .create_client_with_mtls_from_path (cert , key ))
117+
112118 def _create_client (
113119 self ,
114120 client_options : mqtt5 .ClientOptions = None ,
115121 callbacks : Mqtt5TestCallbacks = None ):
116122
117123 default_host = _get_env_variable ("AWS_TEST_MQTT5_IOT_CORE_HOST" )
124+
118125 if client_options is None :
119126 client_options = mqtt5 .ClientOptions (
120127 host_name = default_host ,
121- port = 8883
122- )
128+ port = 8883 ,
129+ tls_ctx = self ._create_tls_context ())
130+
131+ if (client_options .host_name == _get_env_variable ("AWS_TEST_MQTT5_IOT_CORE_HOST" ) and
132+ client_options .tls_ctx is None ):
133+ client_options .tls_ctx = self ._create_tls_context ()
134+
135+ if client_options .port is None :
136+ client_options .port = 8883
137+
123138 if client_options .connect_options is None :
124139 client_options .connect_options = mqtt5 .ConnectPacket ()
125140 client_options .connect_options .client_id = create_client_id ()
@@ -198,12 +213,10 @@ def test_client_creation_maximum(self):
198213 # ==============================================================
199214
200215 def _test_direct_connect_minimum (self ):
201- input_host_name = _get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_HOST" )
202- input_port = int (_get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_PORT" ))
216+ input_host_name = _get_env_variable ("AWS_TEST_MQTT5_IOT_CORE_HOST" )
203217
204218 client_options = mqtt5 .ClientOptions (
205- host_name = input_host_name ,
206- port = input_port
219+ host_name = input_host_name
207220 )
208221 callbacks = Mqtt5TestCallbacks ()
209222 client = self ._create_client (client_options = client_options , callbacks = callbacks )
@@ -321,8 +334,7 @@ def test_direct_connect_http_proxy_tls(self):
321334 test_retry_wrapper (self ._test_direct_connect_http_proxy_tls )
322335
323336 def _test_direct_connect_maximum (self ):
324- input_host_name = _get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_HOST" )
325- input_port = int (_get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_PORT" ))
337+ input_host_name = _get_env_variable ("AWS_TEST_MQTT5_IOT_CORE_HOST" )
326338
327339 user_properties = []
328340 user_properties .append (mqtt5 .UserProperty (name = "name1" , value = "value1" ))
@@ -355,7 +367,7 @@ def _test_direct_connect_maximum(self):
355367 )
356368 client_options = mqtt5 .ClientOptions (
357369 host_name = input_host_name ,
358- port = input_port ,
370+ port = 8883 ,
359371 connect_options = connect_options ,
360372 session_behavior = mqtt5 .ClientSessionBehaviorType .CLEAN ,
361373 extended_validation_and_flow_control_options = mqtt5 .ExtendedValidationAndFlowControlOptions .AWS_IOT_CORE_DEFAULTS ,
@@ -564,7 +576,7 @@ def test_connect_with_invalid_host_name(self):
564576 callbacks .future_stopped .result (TIMEOUT )
565577
566578 def test_connect_with_invalid_port (self ):
567- input_host_name = _get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_HOST " )
579+ input_host_name = _get_env_variable ("AWS_TEST_MQTT5_IOT_CORE_HOST " )
568580 client_options = mqtt5 .ClientOptions (
569581 host_name = input_host_name ,
570582 port = 444
@@ -577,7 +589,7 @@ def test_connect_with_invalid_port(self):
577589 callbacks .future_stopped .result (TIMEOUT )
578590
579591 def test_connect_with_invalid_port_for_websocket_connection (self ):
580- input_host_name = _get_env_variable ("AWS_TEST_MQTT5_WS_MQTT_HOST " )
592+ input_host_name = _get_env_variable ("AWS_TEST_MQTT5_IOT_CORE_HOST " )
581593 client_options = mqtt5 .ClientOptions (
582594 host_name = input_host_name ,
583595 port = 1883
@@ -628,14 +640,12 @@ def test_connect_with_incorrect_basic_authentication_credentials(self):
628640 # test_websocket_handshake_failure : tested in the SDK
629641
630642 def test_double_client_id_failure (self ):
631- input_host_name = _get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_HOST" )
632- input_port = int (_get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_PORT" ))
643+ input_host_name = _get_env_variable ("AWS_TEST_MQTT5_IOT_CORE_HOST" )
633644 shared_client_id = create_client_id ()
634645
635646 connect_options = mqtt5 .ConnectPacket (client_id = shared_client_id )
636647 client_options = mqtt5 .ClientOptions (
637648 host_name = input_host_name ,
638- port = input_port ,
639649 connect_options = connect_options
640650 )
641651 callbacks = Mqtt5TestCallbacks ()
@@ -893,15 +903,13 @@ def test_negative_subscribe_packet_properties(self):
893903 # ==============================================================
894904
895905 def _test_negotiated_settings_minimal_settings (self ):
896- input_host_name = _get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_HOST" )
897- input_port = int (_get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_PORT" ))
906+ input_host_name = _get_env_variable ("AWS_TEST_MQTT5_IOT_CORE_HOST" )
898907
899908 connect_options = mqtt5 .ConnectPacket (
900909 session_expiry_interval_sec = 600000
901910 )
902911 client_options = mqtt5 .ClientOptions (
903912 host_name = input_host_name ,
904- port = input_port ,
905913 connect_options = connect_options
906914 )
907915 callbacks = Mqtt5TestCallbacks ()
@@ -910,7 +918,7 @@ def _test_negotiated_settings_minimal_settings(self):
910918 callbacks .future_connection_success .result (TIMEOUT )
911919
912920 self .assertIsNotNone (callbacks .negotiated_settings )
913- self .assertEqual (callbacks .negotiated_settings .session_expiry_interval_sec , 600000 )
921+ self .assertEqual (callbacks .negotiated_settings .session_expiry_interval_sec , 3600 )
914922
915923 client .stop ()
916924 callbacks .future_stopped .result (TIMEOUT )
@@ -919,8 +927,7 @@ def test_negotiated_settings_minimal_settings(self):
919927 test_retry_wrapper (self ._test_negotiated_settings_minimal_settings )
920928
921929 def _test_negotiated_settings_maximum_settings (self ):
922- input_host_name = _get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_HOST" )
923- input_port = int (_get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_PORT" ))
930+ input_host_name = _get_env_variable ("AWS_TEST_MQTT5_IOT_CORE_HOST" )
924931
925932 client_id = create_client_id ()
926933 connect_options = mqtt5 .ConnectPacket (
@@ -931,7 +938,6 @@ def _test_negotiated_settings_maximum_settings(self):
931938
932939 client_options = mqtt5 .ClientOptions (
933940 host_name = input_host_name ,
934- port = input_port ,
935941 connect_options = connect_options
936942 )
937943 callbacks = Mqtt5TestCallbacks ()
@@ -945,13 +951,13 @@ def _test_negotiated_settings_maximum_settings(self):
945951 self .assertEqual (callbacks .negotiated_settings .session_expiry_interval_sec , 600 )
946952 self .assertEqual (callbacks .negotiated_settings .server_keep_alive_sec , 1000 )
947953 self .assertEqual (callbacks .negotiated_settings .maximum_qos , mqtt5 .QoS .AT_LEAST_ONCE )
948- self .assertEqual (callbacks .negotiated_settings .receive_maximum_from_server , 10 )
949- self .assertEqual (callbacks .negotiated_settings .maximum_packet_size_to_server , 268435460 )
950- self .assertEqual (callbacks .negotiated_settings .topic_alias_maximum_to_server , 10 )
954+ self .assertEqual (callbacks .negotiated_settings .receive_maximum_from_server , 100 )
955+ self .assertEqual (callbacks .negotiated_settings .maximum_packet_size_to_server , 149504 )
956+ self .assertEqual (callbacks .negotiated_settings .topic_alias_maximum_to_server , 8 )
951957 self .assertEqual (callbacks .negotiated_settings .topic_alias_maximum_to_client , 0 )
952958 self .assertTrue (callbacks .negotiated_settings .retain_available )
953959 self .assertTrue (callbacks .negotiated_settings .wildcard_subscriptions_available )
954- self .assertTrue (callbacks .negotiated_settings .subscription_identifiers_available )
960+ self .assertFalse (callbacks .negotiated_settings .subscription_identifiers_available )
955961 self .assertTrue (callbacks .negotiated_settings .shared_subscriptions_available )
956962 self .assertFalse (callbacks .negotiated_settings .rejoined_session )
957963 self .assertEqual (callbacks .negotiated_settings .client_id , client_id )
@@ -963,8 +969,7 @@ def test_negotiated_settings_maximum_settings(self):
963969 test_retry_wrapper (self ._test_negotiated_settings_maximum_settings )
964970
965971 def _test_negotiated_settings_server_limit (self ):
966- input_host_name = _get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_HOST" )
967- input_port = int (_get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_PORT" ))
972+ input_host_name = _get_env_variable ("AWS_TEST_MQTT5_IOT_CORE_HOST" )
968973
969974 uint32_max = 4294967295
970975 uint16_max = 65535
@@ -978,7 +983,6 @@ def _test_negotiated_settings_server_limit(self):
978983
979984 client_options = mqtt5 .ClientOptions (
980985 host_name = input_host_name ,
981- port = input_port ,
982986 connect_options = connect_options
983987 )
984988 callbacks = Mqtt5TestCallbacks ()
@@ -989,8 +993,8 @@ def _test_negotiated_settings_server_limit(self):
989993 self .assertIsNotNone (callbacks .negotiated_settings )
990994 self .assertNotEqual (callbacks .negotiated_settings .receive_maximum_from_server , uint16_max )
991995 self .assertNotEqual (callbacks .negotiated_settings .maximum_packet_size_to_server , uint32_max )
992- self .assertEqual (callbacks .negotiated_settings .server_keep_alive_sec , uint16_max )
993- self .assertEqual (callbacks .negotiated_settings .session_expiry_interval_sec , uint32_max )
996+ self .assertEqual (callbacks .negotiated_settings .server_keep_alive_sec , 1200 )
997+ self .assertEqual (callbacks .negotiated_settings .session_expiry_interval_sec , 3600 )
994998
995999 client .stop ()
9961000 callbacks .future_stopped .result (TIMEOUT )
@@ -1400,12 +1404,10 @@ def test_operation_publish_correlation_data_bytes_binary_precedence(self):
14001404 # ==============================================================
14011405
14021406 def _test_operation_error_null_publish (self ):
1403- input_host_name = _get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_HOST" )
1404- input_port = int (_get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_PORT" ))
1407+ input_host_name = _get_env_variable ("AWS_TEST_MQTT5_IOT_CORE_HOST" )
14051408
14061409 client_options = mqtt5 .ClientOptions (
1407- host_name = input_host_name ,
1408- port = input_port
1410+ host_name = input_host_name
14091411 )
14101412 callbacks = Mqtt5TestCallbacks ()
14111413 client = self ._create_client (client_options = client_options , callbacks = callbacks )
@@ -1422,12 +1424,10 @@ def test_operation_error_null_publish(self):
14221424 test_retry_wrapper (self ._test_operation_error_null_publish )
14231425
14241426 def _test_operation_error_null_subscribe (self ):
1425- input_host_name = _get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_HOST" )
1426- input_port = int (_get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_PORT" ))
1427+ input_host_name = _get_env_variable ("AWS_TEST_MQTT5_IOT_CORE_HOST" )
14271428
14281429 client_options = mqtt5 .ClientOptions (
1429- host_name = input_host_name ,
1430- port = input_port
1430+ host_name = input_host_name
14311431 )
14321432 callbacks = Mqtt5TestCallbacks ()
14331433 client = self ._create_client (client_options = client_options , callbacks = callbacks )
@@ -1444,12 +1444,10 @@ def test_operation_error_null_subscribe(self):
14441444 test_retry_wrapper (self ._test_operation_error_null_subscribe )
14451445
14461446 def _test_operation_error_null_unsubscribe (self ):
1447- input_host_name = _get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_HOST" )
1448- input_port = int (_get_env_variable ("AWS_TEST_MQTT5_DIRECT_MQTT_PORT" ))
1447+ input_host_name = _get_env_variable ("AWS_TEST_MQTT5_IOT_CORE_HOST" )
14491448
14501449 client_options = mqtt5 .ClientOptions (
1451- host_name = input_host_name ,
1452- port = input_port
1450+ host_name = input_host_name
14531451 )
14541452 callbacks = Mqtt5TestCallbacks ()
14551453 client = self ._create_client (client_options = client_options , callbacks = callbacks )
0 commit comments