(self)
| 1362 | os.unlink(connection_service_file.name) |
| 1363 | |
| 1364 | def test_connect_pgpass_regular(self): |
| 1365 | passfile = tempfile.NamedTemporaryFile('w+t', delete=False) |
| 1366 | passfile.write(textwrap.dedent(R''' |
| 1367 | abc:*:*:user:password from pgpass for user@abc |
| 1368 | localhost:*:*:*:password from pgpass for localhost |
| 1369 | cde:5433:*:*:password from pgpass for cde:5433 |
| 1370 | |
| 1371 | *:*:*:testuser:password from pgpass for testuser |
| 1372 | *:*:testdb:*:password from pgpass for testdb |
| 1373 | # comment |
| 1374 | *:*:test\:db:test\\:password from pgpass with escapes |
| 1375 | ''')) |
| 1376 | passfile.close() |
| 1377 | os.chmod(passfile.name, stat.S_IWUSR | stat.S_IRUSR) |
| 1378 | |
| 1379 | try: |
| 1380 | # passfile path in env |
| 1381 | self.run_testcase({ |
| 1382 | 'env': { |
| 1383 | 'PGPASSFILE': passfile.name |
| 1384 | }, |
| 1385 | 'host': 'abc', |
| 1386 | 'user': 'user', |
| 1387 | 'database': 'db', |
| 1388 | 'result': ( |
| 1389 | [('abc', 5432)], |
| 1390 | { |
| 1391 | 'password': 'password from pgpass for user@abc', |
| 1392 | 'user': 'user', |
| 1393 | 'database': 'db', |
| 1394 | 'target_session_attrs': 'any', |
| 1395 | } |
| 1396 | ) |
| 1397 | }) |
| 1398 | |
| 1399 | # passfile path as explicit arg |
| 1400 | self.run_testcase({ |
| 1401 | 'host': 'abc', |
| 1402 | 'user': 'user', |
| 1403 | 'database': 'db', |
| 1404 | 'passfile': passfile.name, |
| 1405 | 'result': ( |
| 1406 | [('abc', 5432)], |
| 1407 | { |
| 1408 | 'password': 'password from pgpass for user@abc', |
| 1409 | 'user': 'user', |
| 1410 | 'database': 'db', |
| 1411 | 'target_session_attrs': 'any', |
| 1412 | } |
| 1413 | ) |
| 1414 | }) |
| 1415 | |
| 1416 | # passfile path in dsn |
| 1417 | self.run_testcase({ |
| 1418 | 'dsn': 'postgres://user@abc/db?passfile={}'.format( |
| 1419 | passfile.name), |
| 1420 | 'result': ( |
| 1421 | [('abc', 5432)], |
nothing calls this directly
no test coverage detected