File tree Expand file tree Collapse file tree 5 files changed +57
-1
lines changed
rabbitmq_amqp_python_client Expand file tree Collapse file tree 5 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -72,3 +72,9 @@ def binding_path_with_exchange_queue(
7272 + ";args="
7373 )
7474 return binding_path_wth_exchange_queue_key
75+
76+
77+ def validate_address (address : str ) -> bool :
78+ if address .startswith ("/queues" ) or address .startswith ("/exchanges" ):
79+ return True
80+ return False
Original file line number Diff line number Diff line change 11import logging
22from typing import Optional
33
4+ from .address_helper import validate_address
45from .consumer import Consumer
6+ from .exceptions import ArgumentOutOfRangeException
57from .management import Management
68from .publisher import Publisher
79from .qpid .proton ._handlers import MessagingHandler
@@ -35,11 +37,19 @@ def close(self) -> None:
3537 self ._conn .close ()
3638
3739 def publisher (self , destination : str ) -> Publisher :
40+ if validate_address (destination ) is False :
41+ raise ArgumentOutOfRangeException (
42+ "destination address must start with /queue or /exchanges"
43+ )
3844 publisher = Publisher (self ._conn , destination )
3945 return publisher
4046
4147 def consumer (
4248 self , destination : str , handler : Optional [MessagingHandler ] = None
4349 ) -> Consumer :
50+ if validate_address (destination ) is False :
51+ raise ArgumentOutOfRangeException (
52+ "destination address must start with /queue or /exchanges"
53+ )
4454 consumer = Consumer (self ._conn , destination , handler )
4555 return consumer
Original file line number Diff line number Diff line change 11def validate_annotations (annotations : []) -> bool : # type: ignore
22 validated = True
33 for annotation in annotations :
4- if len ( annotation ) > 0 and annotation [: 2 ] == "x-" :
4+ if annotation . startswith ( "x-" ) :
55 pass
66 else :
77 validated = False
Original file line number Diff line number Diff line change @@ -53,6 +53,24 @@ def test_consumer_sync_queue_accept(connection: Connection) -> None:
5353 assert consumed > 0
5454
5555
56+ def test_consumer_invalid_destination (connection : Connection ) -> None :
57+
58+ queue_name = "test-queue-sync-invalid-accept"
59+ raised = False
60+ consumer = None
61+ try :
62+ consumer = connection .consumer ("/invalid-destination/" + queue_name )
63+ except ArgumentOutOfRangeException :
64+ raised = True
65+ except Exception :
66+ raised = False
67+
68+ if consumer is not None :
69+ consumer .close ()
70+
71+ assert raised is True
72+
73+
5674def test_consumer_async_queue_accept (connection : Connection ) -> None :
5775
5876 messages_to_send = 1000
Original file line number Diff line number Diff line change 11from rabbitmq_amqp_python_client import (
22 AddressHelper ,
3+ ArgumentOutOfRangeException ,
34 BindingSpecification ,
45 Connection ,
56 ExchangeSpecification ,
@@ -31,6 +32,27 @@ def test_publish_queue(connection: Connection) -> None:
3132 assert raised is False
3233
3334
35+ def test_publish_to_invalid_destination (connection : Connection ) -> None :
36+
37+ queue_name = "test-queue"
38+
39+ raised = False
40+
41+ publisher = None
42+ try :
43+ publisher = connection .publisher ("/invalid-destination/" + queue_name )
44+ publisher .publish (Message (body = "test" ))
45+ except ArgumentOutOfRangeException :
46+ raised = True
47+ except Exception :
48+ raised = False
49+
50+ if publisher is not None :
51+ publisher .close ()
52+
53+ assert raised is True
54+
55+
3456def test_publish_exchange (connection : Connection ) -> None :
3557
3658 exchange_name = "test-exchange"
You can’t perform that action at this time.
0 commit comments