diff --git a/test_runner/batch_others/test_createuser.py b/test_runner/batch_others/test_createuser.py new file mode 100644 index 0000000000..15ff2ff63d --- /dev/null +++ b/test_runner/batch_others/test_createuser.py @@ -0,0 +1,36 @@ +import psycopg2 + +pytest_plugins = ("fixtures.zenith_fixtures") + + +# +# Test CREATE USER to check shared catalog restore +# +def test_createuser(zenith_cli, pageserver, postgres, pg_bin): + zenith_cli.run(["branch", "test_createuser", "empty"]) + + pg = postgres.create_start('test_createuser') + print("postgres is running on 'test_createuser' branch") + + with psycopg2.connect(pg.connstr()) as conn: + conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) + + with conn.cursor() as cur: + # Cause a 'relmapper' change in the original branch + cur.execute('CREATE USER testuser with password %s', ('testpwd',)) + + cur.execute('CHECKPOINT') + + cur.execute('SELECT pg_current_wal_insert_lsn()') + lsn = cur.fetchone()[0] + + # Create a branch + zenith_cli.run(["branch", "test_createuser2", "test_createuser@" + lsn]) + + pg2 = postgres.create_start('test_createuser2') + + # Test that you can connect to new branch as a new user + conn2 = psycopg2.connect(pg2.connstr(username='testuser')) + with conn2.cursor() as cur: + cur.execute('select current_user;') + assert cur.fetchone() == ('testuser', ) diff --git a/test_runner/fixtures/zenith_fixtures.py b/test_runner/fixtures/zenith_fixtures.py index f958798495..628447e2ae 100644 --- a/test_runner/fixtures/zenith_fixtures.py +++ b/test_runner/fixtures/zenith_fixtures.py @@ -247,13 +247,13 @@ class Postgres: return self - def connstr(self, dbname='postgres'): + def connstr(self, dbname='postgres', username=None): """ Build a libpq connection string for the Postgres instance. """ conn_str = 'host={} port={} dbname={} user={}'.format(self.host, self.port, dbname, - self.username) + username or self.username) return conn_str