(self)
| 2161 | auth_method='trust') |
| 2162 | |
| 2163 | async def test_nossl_connection_sslmode(self): |
| 2164 | async def verify_works(sslmode, *, host='localhost'): |
| 2165 | con = None |
| 2166 | try: |
| 2167 | con = await self.connect( |
| 2168 | dsn='postgresql://foo/postgres?sslmode=' + sslmode, |
| 2169 | host=host, |
| 2170 | user='ssl_user') |
| 2171 | self.assertEqual(await con.fetchval('SELECT 42'), 42) |
| 2172 | self.assertFalse(con._protocol.is_ssl) |
| 2173 | finally: |
| 2174 | if con: |
| 2175 | await con.close() |
| 2176 | |
| 2177 | async def verify_fails(sslmode, *, host='localhost'): |
| 2178 | # XXX: uvloop artifact |
| 2179 | old_handler = self.loop.get_exception_handler() |
| 2180 | con = None |
| 2181 | try: |
| 2182 | self.loop.set_exception_handler(lambda *args: None) |
| 2183 | with self.assertRaises( |
| 2184 | asyncpg.InvalidAuthorizationSpecificationError |
| 2185 | ): |
| 2186 | con = await self.connect( |
| 2187 | dsn='postgresql://foo/?sslmode=' + sslmode, |
| 2188 | host=host, |
| 2189 | user='ssl_user') |
| 2190 | await con.fetchval('SELECT 42') |
| 2191 | finally: |
| 2192 | if con: |
| 2193 | await con.close() |
| 2194 | self.loop.set_exception_handler(old_handler) |
| 2195 | |
| 2196 | await verify_works('disable') |
| 2197 | await verify_works('allow') |
| 2198 | await verify_works('prefer') |
| 2199 | await verify_fails('require') |
| 2200 | with mock_dot_postgresql(): |
| 2201 | await verify_fails('require') |
| 2202 | await verify_fails('verify-ca') |
| 2203 | await verify_fails('verify-full') |
| 2204 | |
| 2205 | async def test_nossl_connection_prefer_cancel(self): |
| 2206 | con = await self.connect( |
nothing calls this directly
no test coverage detected