4
4
import asyncio
5
5
import time
6
6
from redis import asyncio as aioredis
7
- from redis .exceptions import ConnectionError as redis_conn_error
7
+ from redis .exceptions import ConnectionError as redis_conn_error , ResponseError
8
8
import async_timeout
9
9
from dataclasses import dataclass
10
10
11
11
from . import dfly_args
12
- from .instance import DflyInstance
12
+ from .instance import DflyInstance , DflyInstanceFactory
13
13
14
14
BASE_PORT = 1111
15
15
@@ -564,7 +564,7 @@ async def test_large_cmd(async_client: aioredis.Redis):
564
564
565
565
@pytest .mark .asyncio
566
566
async def test_reject_non_tls_connections_on_tls (with_tls_server_args , df_local_factory ):
567
- server = df_local_factory .create (
567
+ server : DflyInstance = df_local_factory .create (
568
568
no_tls_on_admin_port = "true" ,
569
569
admin_port = 1111 ,
570
570
port = 1211 ,
@@ -573,13 +573,12 @@ async def test_reject_non_tls_connections_on_tls(with_tls_server_args, df_local_
573
573
)
574
574
server .start ()
575
575
576
- client = aioredis .Redis (port = server .port , password = "XXX" )
577
- try :
578
- await client .execute_command ("DBSIZE" )
579
- except redis_conn_error :
580
- pass
576
+ client = server .client (password = "XXX" )
577
+ with pytest .raises ((ResponseError )):
578
+ await client .dbsize ()
579
+ await client .close ()
581
580
582
- client = aioredis . Redis ( port = server .admin_port , password = "XXX" )
581
+ client = server .admin_client ( password = "XXX" )
583
582
assert await client .dbsize () == 0
584
583
await client .close ()
585
584
@@ -605,27 +604,19 @@ async def test_tls_full_auth(with_ca_tls_server_args, with_ca_tls_client_args, d
605
604
606
605
607
606
@pytest .mark .asyncio
608
- async def test_tls_reject (with_ca_tls_server_args , with_tls_client_args , df_local_factory ):
609
- server = df_local_factory .create (port = BASE_PORT , ** with_ca_tls_server_args )
607
+ async def test_tls_reject (
608
+ with_ca_tls_server_args , with_tls_client_args , df_local_factory : DflyInstanceFactory
609
+ ):
610
+ server : DflyInstance = df_local_factory .create (port = BASE_PORT , ** with_ca_tls_server_args )
610
611
server .start ()
611
612
612
- client = aioredis .Redis (port = server .port , ** with_tls_client_args , ssl_cert_reqs = None )
613
- try :
613
+ client = server .client (** with_tls_client_args , ssl_cert_reqs = None )
614
+ await client .ping ()
615
+ await client .close ()
616
+
617
+ client = server .client (** with_tls_client_args )
618
+ with pytest .raises (redis_conn_error ):
614
619
await client .ping ()
615
- except redis_conn_error :
616
- pass
617
-
618
- client = aioredis .Redis (port = server .port , ** with_tls_client_args )
619
- try :
620
- assert await client .dbsize () != 0
621
- except redis_conn_error :
622
- pass
623
-
624
- client = aioredis .Redis (port = server .port , ssl_cert_reqs = None )
625
- try :
626
- assert await client .dbsize () != 0
627
- except redis_conn_error :
628
- pass
629
620
await client .close ()
630
621
631
622
0 commit comments