-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more substantial tests for compute migrations
The previous tests really didn't do much. This set should be quite a bit more encompassing. Signed-off-by: Tristan Partin <[email protected]>
- Loading branch information
1 parent
04517c6
commit 183df72
Showing
26 changed files
with
315 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
compute_tools/src/migrations/tests/0001-neon_superuser_bypass_rls.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
DO $$ | ||
DECLARE | ||
bypassrls boolean; | ||
BEGIN | ||
SELECT rolbypassrls INTO bypassrls FROM pg_roles WHERE rolname = 'neon_superuser'; | ||
IF NOT bypassrls THEN | ||
RAISE EXCEPTION 'neon_superuser cannot bypass RLS'; | ||
END IF; | ||
END $$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
DO $$ | ||
DECLARE | ||
role record; | ||
BEGIN | ||
FOR role IN | ||
SELECT rolname AS name, rolinherit AS inherit | ||
FROM pg_roles | ||
WHERE pg_has_role(rolname, 'neon_superuser', 'member') | ||
LOOP | ||
IF NOT role.inherit THEN | ||
RAISE EXCEPTION '% cannot inherit', quote_ident(role.name); | ||
END IF; | ||
END LOOP; | ||
|
||
FOR role IN | ||
SELECT rolname AS name, rolbypassrls AS bypassrls | ||
FROM pg_roles | ||
WHERE NOT pg_has_role(rolname, 'neon_superuser', 'member') | ||
AND NOT starts_with(rolname, 'pg_') | ||
LOOP | ||
IF role.bypassrls THEN | ||
RAISE EXCEPTION '% can bypass RLS', quote_ident(role.name); | ||
END IF; | ||
END LOOP; | ||
END $$; |
10 changes: 10 additions & 0 deletions
10
compute_tools/src/migrations/tests/0003-grant_pg_create_subscription_to_neon_superuser.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
DO $$ | ||
BEGIN | ||
IF (SELECT current_setting('server_version_num')::numeric < 160000) THEN | ||
RETURN; | ||
END IF; | ||
|
||
IF NOT (SELECT pg_has_role('neon_superuser', 'pg_create_subscription', 'member')) THEN | ||
RAISE EXCEPTION 'neon_superuser cannot execute pg_create_subscription'; | ||
END IF; | ||
END $$; |
19 changes: 19 additions & 0 deletions
19
compute_tools/src/migrations/tests/0004-grant_pg_monitor_to_neon_superuser.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
DO $$ | ||
DECLARE | ||
monitor record; | ||
BEGIN | ||
SELECT pg_has_role('neon_superuser', 'pg_monitor', 'member') AS member, | ||
admin_option AS admin | ||
INTO monitor | ||
FROM pg_auth_members | ||
WHERE roleid = 'pg_monitor'::regrole | ||
AND member = 'pg_monitor'::regrole; | ||
|
||
IF NOT monitor.member THEN | ||
RAISE EXCEPTION 'neon_superuser is not a member of pg_monitor'; | ||
END IF; | ||
|
||
IF NOT monitor.admin THEN | ||
RAISE EXCEPTION 'neon_superuser cannot grant pg_monitor'; | ||
END IF; | ||
END $$; |
2 changes: 2 additions & 0 deletions
2
compute_tools/src/migrations/tests/0005-grant_all_on_tables_to_neon_superuser.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- This test was never written becuase at the time migration tests were added | ||
-- the accompanying migration was already skipped. |
2 changes: 2 additions & 0 deletions
2
compute_tools/src/migrations/tests/0006-grant_all_on_sequences_to_neon_superuser.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- This test was never written becuase at the time migration tests were added | ||
-- the accompanying migration was already skipped. |
2 changes: 2 additions & 0 deletions
2
...ols/src/migrations/tests/0007-grant_all_on_tables_to_neon_superuser_with_grant_option.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- This test was never written becuase at the time migration tests were added | ||
-- the accompanying migration was already skipped. |
2 changes: 2 additions & 0 deletions
2
.../src/migrations/tests/0008-grant_all_on_sequences_to_neon_superuser_with_grant_option.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- This test was never written becuase at the time migration tests were added | ||
-- the accompanying migration was already skipped. |
2 changes: 2 additions & 0 deletions
2
compute_tools/src/migrations/tests/0009-revoke_replication_for_previously_allowed_roles.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- This test was never written becuase at the time migration tests were added | ||
-- the accompanying migration was already skipped. |
13 changes: 13 additions & 0 deletions
13
...ools/src/migrations/tests/0010-grant_snapshot_synchronization_funcs_to_neon_superuser.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
DO $$ | ||
DECLARE | ||
can_execute boolean; | ||
BEGIN | ||
SELECT bool_and(has_function_privilege('neon_superuser', oid, 'execute')) | ||
INTO can_execute | ||
FROM pg_proc | ||
WHERE proname IN ('pg_export_snapshot', 'pg_log_standby_snapshot') | ||
AND pronamespace = 'pg_catalog'::regnamespace; | ||
IF NOT can_execute THEN | ||
RAISE EXCEPTION 'neon_superuser cannot execute both pg_export_snapshot and pg_log_standby_snapshot'; | ||
END IF; | ||
END $$; |
13 changes: 13 additions & 0 deletions
13
...s/src/migrations/tests/0011-grant_pg_show_replication_origin_status_to_neon_superuser.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
DO $$ | ||
DECLARE | ||
can_execute boolean; | ||
BEGIN | ||
SELECT has_function_privilege('neon_superuser', oid, 'execute') | ||
INTO can_execute | ||
FROM pg_proc | ||
WHERE proname = 'pg_show_replication_origin_status' | ||
AND pronamespace = 'pg_catalog'::regnamespace; | ||
IF NOT can_execute THEN | ||
RAISE EXCEPTION 'neon_superuser cannot execute pg_show_replication_origin_status'; | ||
END IF; | ||
END $$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
from fixtures.paths import BASE_DIR | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import Iterator | ||
from pathlib import Path | ||
|
||
COMPUTE_MIGRATIONS_DIR = BASE_DIR / "compute_tools" / "src" / "migrations" | ||
COMPUTE_MIGRATIONS_TEST_DIR = COMPUTE_MIGRATIONS_DIR / "tests" | ||
|
||
COMPUTE_MIGRATIONS = sorted(next(os.walk(COMPUTE_MIGRATIONS_DIR))[2]) | ||
NUM_COMPUTE_MIGRATIONS = len(COMPUTE_MIGRATIONS) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def compute_migrations_dir() -> Iterator[Path]: | ||
""" | ||
Retrieve the path to the compute migrations directory. | ||
""" | ||
yield COMPUTE_MIGRATIONS_DIR | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def compute_migrations_test_dir() -> Iterator[Path]: | ||
""" | ||
Retrieve the path to the compute migrations test directory. | ||
""" | ||
yield COMPUTE_MIGRATIONS_TEST_DIR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.