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(
72
72
+ ";args="
73
73
)
74
74
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 1
1
import logging
2
2
from typing import Optional
3
3
4
+ from .address_helper import validate_address
4
5
from .consumer import Consumer
6
+ from .exceptions import ArgumentOutOfRangeException
5
7
from .management import Management
6
8
from .publisher import Publisher
7
9
from .qpid .proton ._handlers import MessagingHandler
@@ -35,11 +37,19 @@ def close(self) -> None:
35
37
self ._conn .close ()
36
38
37
39
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
+ )
38
44
publisher = Publisher (self ._conn , destination )
39
45
return publisher
40
46
41
47
def consumer (
42
48
self , destination : str , handler : Optional [MessagingHandler ] = None
43
49
) -> Consumer :
50
+ if validate_address (destination ) is False :
51
+ raise ArgumentOutOfRangeException (
52
+ "destination address must start with /queue or /exchanges"
53
+ )
44
54
consumer = Consumer (self ._conn , destination , handler )
45
55
return consumer
Original file line number Diff line number Diff line change 1
1
def validate_annotations (annotations : []) -> bool : # type: ignore
2
2
validated = True
3
3
for annotation in annotations :
4
- if len ( annotation ) > 0 and annotation [: 2 ] == "x-" :
4
+ if annotation . startswith ( "x-" ) :
5
5
pass
6
6
else :
7
7
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:
53
53
assert consumed > 0
54
54
55
55
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
+
56
74
def test_consumer_async_queue_accept (connection : Connection ) -> None :
57
75
58
76
messages_to_send = 1000
Original file line number Diff line number Diff line change 1
1
from rabbitmq_amqp_python_client import (
2
2
AddressHelper ,
3
+ ArgumentOutOfRangeException ,
3
4
BindingSpecification ,
4
5
Connection ,
5
6
ExchangeSpecification ,
@@ -31,6 +32,27 @@ def test_publish_queue(connection: Connection) -> None:
31
32
assert raised is False
32
33
33
34
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
+
34
56
def test_publish_exchange (connection : Connection ) -> None :
35
57
36
58
exchange_name = "test-exchange"
You can’t perform that action at this time.
0 commit comments