diff --git a/.circleci/pgcat_trust.toml b/.circleci/pgcat_trust.toml deleted file mode 100644 index 7e33ac8..0000000 --- a/.circleci/pgcat_trust.toml +++ /dev/null @@ -1,21 +0,0 @@ - -[general] -host = "0.0.0.0" -port = 6432 -admin_username = "admin_user" -admin_password = "" -admin_auth_type = "trust" - -[pools.sharded_db.users.0] -username = "sharding_user" -password = "sharding_user" -auth_type = "trust" -pool_size = 10 -min_pool_size = 1 -pool_mode = "transaction" - -[pools.sharded_db.shards.0] -servers = [ - [ "127.0.0.1", 5432, "primary" ], -] -database = "shard0" diff --git a/tests/python/test_auth.py b/tests/python/test_auth.py new file mode 100644 index 0000000..bd94342 --- /dev/null +++ b/tests/python/test_auth.py @@ -0,0 +1,71 @@ +import utils +import signal + +class TestTrustAuth: + @classmethod + def setup_method(cls): + config= """ + [general] + host = "0.0.0.0" + port = 6432 + admin_username = "admin_user" + admin_password = "" + admin_auth_type = "trust" + + [pools.sharded_db.users.0] + username = "sharding_user" + password = "sharding_user" + auth_type = "trust" + pool_size = 10 + min_pool_size = 1 + pool_mode = "transaction" + + [pools.sharded_db.shards.0] + servers = [ + [ "127.0.0.1", 5432, "primary" ], + ] + database = "shard0" + """ + utils.pgcat_generic_start(config) + + @classmethod + def teardown_method(self): + utils.pg_cat_send_signal(signal.SIGTERM) + + def test_admin_trust_auth(self): + conn, cur = utils.connect_db_trust(admin=True) + cur.execute("SHOW POOLS") + res = cur.fetchall() + print(res) + utils.cleanup_conn(conn, cur) + + def test_normal_trust_auth(self): + conn, cur = utils.connect_db_trust(autocommit=False) + cur.execute("SELECT 1") + res = cur.fetchall() + print(res) + utils.cleanup_conn(conn, cur) + +class TestMD5Auth: + @classmethod + def setup_method(cls): + utils.pgcat_start() + + @classmethod + def teardown_method(self): + utils.pg_cat_send_signal(signal.SIGTERM) + + def test_normal_db_access(self): + conn, cur = utils.connect_db(autocommit=False) + cur.execute("SELECT 1") + res = cur.fetchall() + print(res) + utils.cleanup_conn(conn, cur) + + def test_admin_db_access(self): + conn, cur = utils.connect_db(admin=True) + + cur.execute("SHOW POOLS") + res = cur.fetchall() + print(res) + utils.cleanup_conn(conn, cur) diff --git a/tests/python/test_pgcat.py b/tests/python/test_pgcat.py index fbced71..773715d 100644 --- a/tests/python/test_pgcat.py +++ b/tests/python/test_pgcat.py @@ -7,46 +7,6 @@ import utils SHUTDOWN_TIMEOUT = 5 -def _test_admin_trust_auth(): - conn, cur = utils.connect_db_trust(admin=True) - cur.execute("SHOW POOLS") - res = cur.fetchall() - print(res) - utils.cleanup_conn(conn, cur) - - -def _test_normal_trust_auth(): - conn, cur = utils.connect_db_trust(autocommit=False) - cur.execute("SELECT 1") - res = cur.fetchall() - print(res) - utils.cleanup_conn(conn, cur) - - -def test_trust(): - utils.pgcat_trust_start() - _test_admin_trust_auth() - _test_normal_trust_auth() - utils.pg_cat_send_signal(signal.SIGTERM) - - -def test_normal_db_access(): - utils.pgcat_start() - conn, cur = utils.connect_db(autocommit=False) - cur.execute("SELECT 1") - res = cur.fetchall() - print(res) - utils.cleanup_conn(conn, cur) - - -def test_admin_db_access(): - conn, cur = utils.connect_db(admin=True) - - cur.execute("SHOW POOLS") - res = cur.fetchall() - print(res) - utils.cleanup_conn(conn, cur) - def test_shutdown_logic(): diff --git a/tests/python/utils.py b/tests/python/utils.py index d7d11f7..9a1c6de 100644 --- a/tests/python/utils.py +++ b/tests/python/utils.py @@ -2,6 +2,7 @@ import os import signal import time from typing import Tuple +import tempfile import psutil import psycopg2 @@ -20,8 +21,11 @@ def pgcat_start(): _pgcat_start(config_path='.circleci/pgcat.toml') -def pgcat_trust_start(): - _pgcat_start(config_path='.circleci/pgcat_trust.toml') +def pgcat_generic_start(config: str): + tmp = tempfile.NamedTemporaryFile() + with open(tmp.name, 'w') as f: + f.write(config) + _pgcat_start(config_path=tmp.name) def glauth_send_signal(signal: signal.Signals): @@ -43,7 +47,7 @@ def glauth_send_signal(signal: signal.Signals): def pg_cat_send_signal(signal: signal.Signals): try: for proc in psutil.process_iter(["pid", "name"]): - if proc.name() == "pgcat": + if "pgcat" == proc.name(): os.kill(proc.pid, signal) except Exception as e: # The process can be gone when we send this signal