Skip to content

Commit 4164811

Browse files
author
DanielePalaia
committed
testing mutual authentication
1 parent 2a5bf3d commit 4164811

File tree

7 files changed

+49
-18
lines changed

7 files changed

+49
-18
lines changed

.ci/conf/rabbitmq.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ ssl_options.certfile = /etc/rabbitmq/certs/server_certificate.pem
55
ssl_options.keyfile = /etc/rabbitmq/certs/server_key.pem
66
listeners.ssl.default = 5671
77
stream.listeners.ssl.default = 5551
8+
ssl_options.verify = verify_peer
9+
ssl_options.fail_if_no_peer_cert = false

examples/getting_started/main.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
ExchangeSpecification,
1111
Message,
1212
QuorumQueueSpecification,
13-
SSlConfigurationContext,
13+
# SslConfigurationContext,
1414
)
1515

1616

@@ -60,15 +60,15 @@ def on_link_closed(self, event: Event) -> None:
6060

6161

6262
def create_connection() -> Connection:
63-
# connection = Connection("amqps://guest:guest@localhost:5672/")
63+
connection = Connection("amqps://guest:guest@localhost:5672/")
6464
# in case of SSL
65-
ca_cert_file = (
66-
"/Users/dpalaia/projects/rabbitmq-stream-go-client/.ci/certs/ca_certificate.pem"
67-
)
68-
connection = Connection(
69-
"amqps://guest:guest@localhost:5671/",
70-
ssl_context=SSlConfigurationContext(ca_cert=ca_cert_file),
71-
)
65+
# ca_cert_file = (
66+
# "/Users/dpalaia/projects/rabbitmq-stream-go-client/.ci/certs/ca_certificate.pem"
67+
# )
68+
# connection = Connection(
69+
# "amqps://guest:guest@localhost:5671/",
70+
# ssl_context=SSlConfigurationContext(ca_cert=ca_cert_file),
71+
# )
7272
connection.dial()
7373

7474
return connection

rabbitmq_amqp_python_client/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
QuorumQueueSpecification,
2323
StreamSpecification,
2424
)
25-
from .ssl_configuration import SSlConfigurationContext
25+
from .ssl_configuration import (
26+
ClientCert,
27+
SslConfigurationContext,
28+
)
2629

2730
try:
2831
__version__ = metadata.version(__package__)
@@ -53,5 +56,6 @@
5356
"AddressHelper",
5457
"AMQPMessagingHandler",
5558
"ArgumentOutOfRangeException",
56-
"SSlConfigurationContext",
59+
"SslConfigurationContext",
60+
"ClientCert",
5761
]

rabbitmq_amqp_python_client/connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
from .qpid.proton._handlers import MessagingHandler
1010
from .qpid.proton._transport import SSLDomain
1111
from .qpid.proton.utils import BlockingConnection
12-
from .ssl_configuration import SSlConfigurationContext
12+
from .ssl_configuration import SslConfigurationContext
1313

1414
logger = logging.getLogger(__name__)
1515

1616

1717
class Connection:
1818
def __init__(
19-
self, addr: str, ssl_context: Optional[SSlConfigurationContext] = None
19+
self, addr: str, ssl_context: Optional[SslConfigurationContext] = None
2020
):
2121
self._addr: str = addr
2222
self._conn: BlockingConnection
2323
self._management: Management
24-
self._conf_ssl_context: Optional[SSlConfigurationContext] = ssl_context
24+
self._conf_ssl_context: Optional[SslConfigurationContext] = ssl_context
2525
self._ssl_domain = None
2626

2727
def dial(self) -> None:

rabbitmq_amqp_python_client/ssl_configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ class ClientCert:
1010

1111

1212
@dataclass
13-
class SSlConfigurationContext:
13+
class SslConfigurationContext:
1414
ca_cert: str
1515
client_cert: Optional[ClientCert] = None

tests/conftest.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from rabbitmq_amqp_python_client import (
44
AddressHelper,
55
AMQPMessagingHandler,
6+
ClientCert,
67
Connection,
78
Event,
8-
SSlConfigurationContext,
9+
SslConfigurationContext,
910
symbol,
1011
)
1112

@@ -23,9 +24,15 @@ def connection(pytestconfig):
2324

2425
@pytest.fixture()
2526
def connection_ssl(pytestconfig):
27+
ca_cert_file = ".ci/certs/ca_certificate.pem"
28+
client_cert = ".ci/certs/client_certificate.pem"
29+
client_key = ".ci/certs/client_key.pem"
2630
connection = Connection(
2731
"amqps://guest:guest@localhost:5671/",
28-
ssl_context=SSlConfigurationContext(ca_cert=".ci/certs/ca_certificate.pem"),
32+
ssl_context=SslConfigurationContext(
33+
ca_cert=ca_cert_file,
34+
client_cert=ClientCert(client_cert=client_cert, client_key=client_key),
35+
),
2936
)
3037
connection.dial()
3138
try:

tests/test_connection.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1-
from rabbitmq_amqp_python_client import Connection
1+
from rabbitmq_amqp_python_client import (
2+
ClientCert,
3+
Connection,
4+
SslConfigurationContext,
5+
)
26

37

48
def test_connection() -> None:
59
connection = Connection("amqp://guest:guest@localhost:5672/")
610
connection.dial()
711
connection.close()
12+
13+
14+
def test_connection_ssl() -> None:
15+
ca_cert_file = ".ci/certs/ca_certificate.pem"
16+
client_cert = ".ci/certs/client_certificate.pem"
17+
client_key = ".ci/certs/client_key.pem"
18+
connection = Connection(
19+
"amqps://guest:guest@localhost:5671/",
20+
ssl_context=SslConfigurationContext(
21+
ca_cert=ca_cert_file,
22+
client_cert=ClientCert(client_cert=client_cert, client_key=client_key),
23+
),
24+
)
25+
connection.dial()

0 commit comments

Comments
 (0)