(self)
| 2655 | await con.close() |
| 2656 | |
| 2657 | async def test_tls_version(self): |
| 2658 | if self.cluster.get_pg_version() < (12, 0): |
| 2659 | self.skipTest("PostgreSQL < 12 cannot set ssl protocol version") |
| 2660 | |
| 2661 | # XXX: uvloop artifact |
| 2662 | old_handler = self.loop.get_exception_handler() |
| 2663 | |
| 2664 | with warnings.catch_warnings(): |
| 2665 | warnings.filterwarnings( |
| 2666 | "ignore", |
| 2667 | message="ssl.TLSVersion.TLSv1_1 is deprecated", |
| 2668 | category=DeprecationWarning |
| 2669 | ) |
| 2670 | try: |
| 2671 | self.loop.set_exception_handler(lambda *args: None) |
| 2672 | with self.assertRaisesRegex( |
| 2673 | ssl.SSLError, |
| 2674 | '(protocol version)|(handshake failure)', |
| 2675 | ): |
| 2676 | await self.connect( |
| 2677 | dsn='postgresql://ssl_user@localhost/postgres' |
| 2678 | '?sslmode=require&ssl_min_protocol_version=TLSv1.3' |
| 2679 | ) |
| 2680 | with self.assertRaises((ssl.SSLError, ConnectionResetError)): |
| 2681 | await self.connect( |
| 2682 | dsn='postgresql://ssl_user@localhost/postgres' |
| 2683 | '?sslmode=require' |
| 2684 | '&ssl_min_protocol_version=TLSv1.1' |
| 2685 | '&ssl_max_protocol_version=TLSv1.1' |
| 2686 | ) |
| 2687 | if not ssl.OPENSSL_VERSION.startswith('LibreSSL'): |
| 2688 | with self.assertRaisesRegex(ssl.SSLError, 'no protocols'): |
| 2689 | await self.connect( |
| 2690 | dsn='postgresql://ssl_user@localhost/postgres' |
| 2691 | '?sslmode=require' |
| 2692 | '&ssl_min_protocol_version=TLSv1.2' |
| 2693 | '&ssl_max_protocol_version=TLSv1.1' |
| 2694 | ) |
| 2695 | await self._test_works( |
| 2696 | dsn='postgresql://ssl_user@localhost/postgres' |
| 2697 | '?sslmode=require' |
| 2698 | '&ssl_min_protocol_version=TLSv1.2' |
| 2699 | '&ssl_max_protocol_version=TLSv1.2' |
| 2700 | ) |
| 2701 | finally: |
| 2702 | self.loop.set_exception_handler(old_handler) |
| 2703 | |
| 2704 | |
| 2705 | @unittest.skipIf(os.environ.get('PGHOST'), 'unmanaged cluster') |
nothing calls this directly
no test coverage detected