1import pytest
2
3import pg8000.dbapi
4
5
6# This requires a line in pg_hba.conf that requires md5 for the database
7# pg8000_md5
8
9
10def testMd5(db_kwargs):
11    db_kwargs["database"] = "pg8000_md5"
12
13    # Should only raise an exception saying db doesn't exist
14    with pytest.raises(pg8000.dbapi.DatabaseError, match="3D000"):
15        pg8000.dbapi.connect(**db_kwargs)
16
17
18# This requires a line in pg_hba.conf that requires gss for the database
19# pg8000_gss
20
21
22def testGss(db_kwargs):
23    db_kwargs["database"] = "pg8000_gss"
24
25    # Should raise an exception saying gss isn't supported
26    with pytest.raises(
27        pg8000.dbapi.InterfaceError,
28        match="Authentication method 7 not supported by pg8000.",
29    ):
30        pg8000.dbapi.connect(**db_kwargs)
31
32
33# This requires a line in pg_hba.conf that requires 'password' for the
34# database pg8000_password
35
36
37def testPassword(db_kwargs):
38    db_kwargs["database"] = "pg8000_password"
39
40    # Should only raise an exception saying db doesn't exist
41    with pytest.raises(pg8000.dbapi.DatabaseError, match="3D000"):
42        pg8000.dbapi.connect(**db_kwargs)
43
44
45# This requires a line in pg_hba.conf that requires scram-sha-256 for the
46# database scram-sha-256
47
48
49def test_scram_sha_256(db_kwargs):
50    db_kwargs["database"] = "pg8000_scram_sha_256"
51
52    # Should only raise an exception saying db doesn't exist
53    with pytest.raises(pg8000.dbapi.DatabaseError, match="3D000"):
54        pg8000.dbapi.connect(**db_kwargs)
55