Skip to content

Commit 170343b

Browse files
author
CommanderKeynes
committed
Add integration test for trust authentication
1 parent 896e5a5 commit 170343b

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

.circleci/pgcat.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ tls_private_key = ".circleci/server.key"
4949
# Connecting to that database allows running commands like `SHOW POOLS`, `SHOW DATABASES`, etc..
5050
admin_username = "admin_user"
5151
admin_password = "admin_pass"
52+
admin_auth_type = "md5"
5253

5354
# pool
5455
# configs are structured as pool.<pool_name>

.circleci/pgcat_trust.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
[general]
3+
4+
host = "0.0.0.0"
5+
port = 6432
6+
admin_username = "admin_user"
7+
admin_password = ""
8+
admin_auth_type = "trust"
9+
10+
[pools.sharded_db.users.0]
11+
username = "sharding_user"
12+
password = "sharding_user"
13+
auth_type = "trust"
14+
pool_size = 10
15+
min_pool_size = 1
16+
pool_mode = "transaction"
17+
18+
[pools.sharded_db.shards.0]
19+
servers = [
20+
[ "127.0.0.1", 5432, "primary" ],
21+
]
22+
database = "shard0"

tests/python/tests.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ def pgcat_start():
1616
os.system("./target/debug/pgcat .circleci/pgcat.toml &")
1717
time.sleep(2)
1818

19+
def pgcat_trust_start():
20+
pg_cat_send_signal(signal.SIGTERM)
21+
os.system("./target/debug/pgcat .circleci/pgcat_trust.toml &")
22+
time.sleep(2)
23+
1924

2025
def pg_cat_send_signal(signal: signal.Signals):
2126
try:
@@ -33,6 +38,28 @@ def pg_cat_send_signal(signal: signal.Signals):
3338
raise Exception("pgcat not closed after SIGTERM")
3439

3540

41+
def connect_db_trust(
42+
autocommit: bool = True,
43+
admin: bool = False,
44+
) -> Tuple[psycopg2.extensions.connection, psycopg2.extensions.cursor]:
45+
46+
if admin:
47+
user = "admin_user"
48+
db = "pgcat"
49+
else:
50+
user = "sharding_user"
51+
db = "sharded_db"
52+
53+
conn = psycopg2.connect(
54+
f"postgres://{user}:@{PGCAT_HOST}:{PGCAT_PORT}/{db}?application_name=testing_pgcat",
55+
connect_timeout=2,
56+
)
57+
conn.autocommit = autocommit
58+
cur = conn.cursor()
59+
60+
return (conn, cur)
61+
62+
3663
def connect_db(
3764
autocommit: bool = True,
3865
admin: bool = False,
@@ -62,6 +89,29 @@ def cleanup_conn(conn: psycopg2.extensions.connection, cur: psycopg2.extensions.
6289
conn.close()
6390

6491

92+
def test_admin_trust_auth():
93+
conn, cur = connect_db_trust(admin=True)
94+
cur.execute("SHOW POOLS")
95+
res = cur.fetchall()
96+
print(res)
97+
cleanup_conn(conn, cur)
98+
99+
100+
def test_normal_trust_auth():
101+
conn, cur = connect_db_trust(autocommit=False)
102+
cur.execute("SELECT 1")
103+
res = cur.fetchall()
104+
print(res)
105+
cleanup_conn(conn, cur)
106+
107+
108+
def test_trust():
109+
pgcat_trust_start()
110+
test_admin_trust_auth()
111+
test_normal_trust_auth()
112+
pg_cat_send_signal(signal.SIGTERM)
113+
114+
65115
def test_normal_db_access():
66116
pgcat_start()
67117
conn, cur = connect_db(autocommit=False)
@@ -71,6 +121,7 @@ def test_normal_db_access():
71121
cleanup_conn(conn, cur)
72122

73123

124+
74125
def test_admin_db_access():
75126
conn, cur = connect_db(admin=True)
76127

@@ -317,3 +368,5 @@ def test_shutdown_logic():
317368
test_normal_db_access()
318369
test_admin_db_access()
319370
test_shutdown_logic()
371+
372+
test_trust()

0 commit comments

Comments
 (0)