diff --git a/test/expected/attribute.out b/test/expected/attribute.out index c9fe346..6a85915 100644 --- a/test/expected/attribute.out +++ b/test/expected/attribute.out @@ -1,8 +1,9 @@ \set ECHO none -1..5 +1..6 ok 1 - Verify public has no perms ok 2 - Non-existent relation throws error ok 3 - Non-existent column throws error ok 4 - Verify details of pg_class.relname ok 5 - Verify details of pg_tables.tablename +ok 6 - cat_tools schema(s) must not be part of the resolved search_path -- got {tap,public} # TRANSACTION INTENTIONALLY LEFT OPEN! diff --git a/test/expected/enum.out b/test/expected/enum.out index c010e3a..490b589 100644 --- a/test/expected/enum.out +++ b/test/expected/enum.out @@ -1,7 +1,8 @@ \set ECHO none -1..4 +1..5 ok 1 - Create test enum ok 2 - Permission denied trying to run functions ok 3 - Permission denied trying to run functions ok 4 +ok 5 - cat_tools schema(s) must not be part of the resolved search_path -- got {tap,public} # TRANSACTION INTENTIONALLY LEFT OPEN! diff --git a/test/expected/extension.out b/test/expected/extension.out index 05eda82..5e91526 100644 --- a/test/expected/extension.out +++ b/test/expected/extension.out @@ -1,5 +1,5 @@ \set ECHO none -1..7 +1..8 ok 1 - cat_tools.pg_extension view row count ok 2 - Sanity-check that we get a row for our extension ok 3 - pg_extension__get() returns correct data @@ -7,4 +7,5 @@ ok 4 - pg_extension__get() for non-existent extension throws an error ok 5 - Verify extension__schemas_unique(text) returns correct data ok 6 - Verify extension__schemas(text) returns correct data ok 7 - extension__schemas_unique with bogus extension fails +ok 8 - cat_tools schema(s) must not be part of the resolved search_path -- got {tap,public} # TRANSACTION INTENTIONALLY LEFT OPEN! diff --git a/test/expected/function.out b/test/expected/function.out index 8be118c..6160517 100644 --- a/test/expected/function.out +++ b/test/expected/function.out @@ -1,5 +1,5 @@ \set ECHO none -1..7 +1..8 ok 1 - Function _cat_tools.function__arg_to_regprocedure(text, text, text) should not be security definer ok 2 - Function _cat_tools.function__drop_temp(regprocedure, text) should not be security definer ok 3 - Verify regprocedure() @@ -11,4 +11,5 @@ WARNING: function__arg_types_text() is deprecated, use routine__parse_arg_types ok 6 - Verify deprecated function__arg_types_text() with INOUT and OUT WARNING: function__arg_types_text() is deprecated, use routine__parse_arg_types_text instead ok 7 - Verify deprecated function__arg_types_text() with simple args +ok 8 - cat_tools schema(s) must not be part of the resolved search_path -- got {tap,public} # TRANSACTION INTENTIONALLY LEFT OPEN! diff --git a/test/expected/general.out b/test/expected/general.out index 84e08e2..afa2175 100644 --- a/test/expected/general.out +++ b/test/expected/general.out @@ -1,4 +1,5 @@ \set ECHO none -1..1 +1..2 ok 1 - Schema __cat_tools should not exist +ok 2 - cat_tools schema(s) must not be part of the resolved search_path -- got {tap,public} # TRANSACTION INTENTIONALLY LEFT OPEN! diff --git a/test/expected/name__check.out b/test/expected/name__check.out index c966947..9e75dfb 100644 --- a/test/expected/name__check.out +++ b/test/expected/name__check.out @@ -1,8 +1,9 @@ \set ECHO none -1..5 +1..6 ok 1 - Verify public has no perms ok 2 - Simple name ok 3 - Name with spaces ok 4 - NULL ok 5 - Error on overflow +ok 6 - cat_tools schema(s) must not be part of the resolved search_path -- got {tap,public} # TRANSACTION INTENTIONALLY LEFT OPEN! diff --git a/test/expected/object_type.out b/test/expected/object_type.out index 1c9029b..7e57300 100644 --- a/test/expected/object_type.out +++ b/test/expected/object_type.out @@ -1,5 +1,5 @@ \set ECHO none -1..230 +1..231 ok 1 - sanity check size of pg_temp.extra_types() ok 2 - sanity check size of pg_temp.obj_type ok 3 - Permission denied trying to use types @@ -230,4 +230,5 @@ ok 227 - Simple 'regclass'::regtype should not return pg_catalog.regtype ok 228 - cat_tools.object__catalog('table') returns pg_catalog.pg_class ok 229 - cat_tools.object__catalog('table') returns pg_catalog.pg_class ok 230 - Verify objects__shared_src() returns correct values +ok 231 - cat_tools schema(s) must not be part of the resolved search_path -- got {public,tap,pg_catalog} # TRANSACTION INTENTIONALLY LEFT OPEN! diff --git a/test/expected/permissions.out b/test/expected/permissions.out index 4984217..4fcff24 100644 --- a/test/expected/permissions.out +++ b/test/expected/permissions.out @@ -1,5 +1,5 @@ \set ECHO none -1..160 +1..161 ok 1 - Permission denied trying to execute cat_tools.currval(table_name text, column_name text) ok 2 - Permission denied trying to execute cat_tools.enum_range(enum regtype) ok 3 - Permission denied trying to execute cat_tools.enum_range_srf(enum regtype) @@ -160,4 +160,5 @@ ok 157 - Permission granted to use type cat_tools.routine_type ok 158 - Permission granted to use type cat_tools.routine_volatility ok 159 - no_use_role has no USAGE on _cat_tools schema ok 160 - use_role has USAGE on _cat_tools schema +ok 161 - cat_tools schema(s) must not be part of the resolved search_path -- got {tap,public} # TRANSACTION INTENTIONALLY LEFT OPEN! diff --git a/test/expected/pg_depends.out b/test/expected/pg_depends.out index 9a89a9c..244f27e 100644 --- a/test/expected/pg_depends.out +++ b/test/expected/pg_depends.out @@ -1,6 +1,7 @@ \set ECHO none -1..2 +1..3 ok 1 - Verify base data on ok 2 - Verify public has no perms +ok 3 - cat_tools schema(s) must not be part of the resolved search_path -- got {tap,public} # TRANSACTION INTENTIONALLY LEFT OPEN! diff --git a/test/expected/relation__.out b/test/expected/relation__.out index ff14a93..ed633d4 100644 --- a/test/expected/relation__.out +++ b/test/expected/relation__.out @@ -1,5 +1,5 @@ \set ECHO none -1..38 +1..39 ok 1 - Verify count from kinds ok 2 - Simple sanity check of relation__kind() ok 3 - Simple sanity check of relation__relkind() @@ -38,4 +38,5 @@ ok 35 - Temp table returns expected column names ok 36 - Drop middle column from temp table ok 37 - Temp table with dropped column returns expected column names ok 38 - NULL input returns NULL (STRICT function) +ok 39 - cat_tools schema(s) must not be part of the resolved search_path -- got {tap,public} # TRANSACTION INTENTIONALLY LEFT OPEN! diff --git a/test/expected/routine__.out b/test/expected/routine__.out index e9736f0..cffeaaa 100644 --- a/test/expected/routine__.out +++ b/test/expected/routine__.out @@ -1,5 +1,5 @@ \set ECHO none -1..89 +1..90 ok 1 - Verify type and prokind enums have same size ok 2 - Simple sanity check of routine__type() ok 3 - Simple sanity check of routine__type() with enum @@ -89,4 +89,5 @@ ok 86 - Verify routine__arg_names_text() formatting ok 87 - Verify routine__arg_names_text() with unnamed arguments ok 88 - Verify routine__arg_names_text() with built-in function ok 89 - Verify routine__arg_names_text() with no arguments +ok 90 - cat_tools schema(s) must not be part of the resolved search_path -- got {tap,public} # TRANSACTION INTENTIONALLY LEFT OPEN! diff --git a/test/expected/sequence.out b/test/expected/sequence.out index d36acbe..8328f2b 100644 --- a/test/expected/sequence.out +++ b/test/expected/sequence.out @@ -1,5 +1,5 @@ \set ECHO none -1..50 +1..51 ok 1 - Permission denied trying to use cat_tools.currval() ok 2 - Permission denied trying to use cat_tools.setval() ok 3 - Permission denied trying to use cat_tools.nextval() @@ -50,4 +50,5 @@ ok 47 - sequence__next returns correct value ok 48 - INSERT INTO seqtest VALUES(default) ok 49 - currval ok 50 - currval +ok 51 - cat_tools schema(s) must not be part of the resolved search_path -- got {tap,public} # TRANSACTION INTENTIONALLY LEFT OPEN! diff --git a/test/expected/trigger.out b/test/expected/trigger.out index d4577ea..5ee9594 100644 --- a/test/expected/trigger.out +++ b/test/expected/trigger.out @@ -1,5 +1,5 @@ \set ECHO none -1..10 +1..11 ok 1 - Verify public has no perms ok 2 - Verify public has no perms ok 3 - Verify public has no perms @@ -10,4 +10,5 @@ ok 7 - SELECT cat_tools.trigger__parse( 1259 ) throws correct error for missing ok 8 - verify results of trigger__parse(oid) ok 9 - verify results of trigger__parse(regclass,text) ok 10 - verify trigger__args_as_text() +ok 11 - cat_tools schema(s) must not be part of the resolved search_path -- got {tap,public} # TRANSACTION INTENTIONALLY LEFT OPEN! diff --git a/test/finish.sql b/test/finish.sql new file mode 100644 index 0000000..8b85457 --- /dev/null +++ b/test/finish.sql @@ -0,0 +1,22 @@ +/* + * Asserts cat_tools' own schema(s) are absent from the resolved search_path -- + * checked here (file end, before finish()) rather than only at setup, so a + * test that mutates search_path mid-file and never restores it is caught. Not + * foolproof: mutate-then-restore before this line still slips through. \i'd by + * every SQL file under test/sql. + */ +SELECT ok( + NOT ( 'cat_tools' = ANY (current_schemas(false)) OR '_cat_tools' = ANY (current_schemas(false)) ) + , format( + 'cat_tools schema(s) must not be part of the resolved search_path -- got %s' + , current_schemas(false) + ) +); + +/* + * Chain through to pgxntool's own finish, same wrapping pattern as + * test/setup.sql does for test/pgxntool/setup.sql. + */ +\i test/pgxntool/finish.sql + +-- vi: expandtab ts=2 sw=2 diff --git a/test/setup.sql b/test/setup.sql index 9097b62..fe66b06 100644 --- a/test/setup.sql +++ b/test/setup.sql @@ -1,6 +1,16 @@ -- Pulls in deps.sql \i test/pgxntool/setup.sql +/* + * pgxntool's own tap_setup.sql (just \i'd above) sets search_path = tap, public + * for every test file -- cat_tools' own schemas are never on it. That's what + * makes every pgTAP pass in this suite mean cat_tools' internal views/functions + * fully schema-qualify their own cross-references, rather than happening to + * resolve by search_path accident. See test/finish.sql, \i'd by every SQL + * file under test/sql, for the actual assertion of this fact -- checked + * there, at the END of each file, rather than here at the start. + */ + GRANT USAGE ON SCHEMA tap TO :"use_role", :"no_use_role"; CREATE FUNCTION pg_temp.exec( diff --git a/test/sql/attribute.sql b/test/sql/attribute.sql index 6fadecc..06b2239 100644 --- a/test/sql/attribute.sql +++ b/test/sql/attribute.sql @@ -16,6 +16,7 @@ SELECT plan( + (SELECT count(*)::int FROM func_calls) + 4 -- pg_attribute__get() + + 1 -- search_path still clean (test/finish.sql) ); SET LOCAL ROLE :"no_use_role"; @@ -110,6 +111,6 @@ SELECT results_eq( ); -\i test/pgxntool/finish.sql +\i test/finish.sql -- vi: expandtab ts=2 sw=2 diff --git a/test/sql/enum.sql b/test/sql/enum.sql index 8cc9c0c..a78a63e 100644 --- a/test/sql/enum.sql +++ b/test/sql/enum.sql @@ -10,6 +10,7 @@ SELECT plan( + 1 + 2 -- no_use tests + 1 + + 1 -- search_path still clean (test/finish.sql) ); SELECT lives_ok( @@ -35,6 +36,6 @@ SELECT results_eq( , $$VALUES ( 'ZZZ Label 1' ), ( 'Label 2' )$$ ); -\i test/pgxntool/finish.sql +\i test/finish.sql -- vi: expandtab ts=2 sw=2 diff --git a/test/sql/extension.sql b/test/sql/extension.sql index 904132e..1dd1446 100644 --- a/test/sql/extension.sql +++ b/test/sql/extension.sql @@ -17,6 +17,8 @@ SELECT plan( + 1 -- extension__schemas_unique + 1 -- extension__schemas + 1 -- extension__schemas_unique with bad schema + + + 1 -- search_path still clean (test/finish.sql) ); SELECT is( @@ -73,6 +75,6 @@ SELECT throws_ok( , 'extension__schemas_unique with bogus extension fails' ); -\i test/pgxntool/finish.sql +\i test/finish.sql -- vi: expandtab ts=2 sw=2 diff --git a/test/sql/function.sql b/test/sql/function.sql index e0b0f59..e814737 100644 --- a/test/sql/function.sql +++ b/test/sql/function.sql @@ -9,6 +9,7 @@ SELECT plan( 2 -- security definer checks for _cat_tools helpers + 1 -- regprocedure() + 4 -- deprecated function__arg_types() wrappers + + 1 -- search_path still clean (test/finish.sql) ); /* @@ -66,6 +67,6 @@ SELECT is( , 'Verify deprecated function__arg_types_text() with simple args' ); -\i test/pgxntool/finish.sql +\i test/finish.sql -- vi: expandtab ts=2 sw=2 diff --git a/test/sql/general.sql b/test/sql/general.sql index 08d6f2d..d81060f 100644 --- a/test/sql/general.sql +++ b/test/sql/general.sql @@ -5,12 +5,13 @@ SELECT plan( 0 +1 + +1 -- search_path still clean (test/finish.sql) ); SELECT hasnt_schema( '__cat_tools' ); -\i test/pgxntool/finish.sql +\i test/finish.sql -- vi: expandtab ts=2 sw=2 diff --git a/test/sql/name__check.sql b/test/sql/name__check.sql index e65db56..f062442 100644 --- a/test/sql/name__check.sql +++ b/test/sql/name__check.sql @@ -5,7 +5,10 @@ \set s cat_tools \set f name__check -SELECT plan(5); +SELECT plan( + 5 + + 1 -- search_path still clean (test/finish.sql) +); SET LOCAL ROLE :"no_use_role"; @@ -56,6 +59,6 @@ SELECT throws_like( , 'Error on overflow' ); -\i test/pgxntool/finish.sql +\i test/finish.sql -- vi: expandtab ts=2 sw=2 diff --git a/test/sql/object_type.sql b/test/sql/object_type.sql index 822a89a..ab1aa5d 100644 --- a/test/sql/object_type.sql +++ b/test/sql/object_type.sql @@ -60,6 +60,8 @@ SELECT plan( + 3 * 2 + 1 -- objects__shared + + + 1 -- search_path still clean (test/finish.sql) ); SELECT is( @@ -261,7 +263,7 @@ SELECT bag_eq( , 'Verify objects__shared_src() returns correct values' ); -\i test/pgxntool/finish.sql +\i test/finish.sql --select name,setting from pg_settings where name ~ '^lc_'; diff --git a/test/sql/permissions.sql b/test/sql/permissions.sql index d26f592..aa75a23 100644 --- a/test/sql/permissions.sql +++ b/test/sql/permissions.sql @@ -30,6 +30,7 @@ SELECT plan( (SELECT count(*)::int FROM cat_types) * 2 -- no_use denied + use allowed + (SELECT count(*)::int FROM cat_functions) * 2 -- no_use denied + use allowed + 2 -- _cat_tools schema access (no_use denied + use allowed) + + 1 -- search_path still clean (test/finish.sql) ); /* @@ -97,6 +98,6 @@ SELECT is( , 'use_role has USAGE on _cat_tools schema' ); -\i test/pgxntool/finish.sql +\i test/finish.sql -- vi: expandtab ts=2 sw=2 diff --git a/test/sql/pg_depends.sql b/test/sql/pg_depends.sql index d279917..8d9ca70 100644 --- a/test/sql/pg_depends.sql +++ b/test/sql/pg_depends.sql @@ -34,6 +34,7 @@ SELECT plan( --+ (SELECT count(*)::int FROM func_calls) + 1 -- _cat_tools.pg_depend_v + + 1 -- search_path still clean (test/finish.sql) ); /* @@ -89,6 +90,6 @@ SELECT CASE SET LOCAL ROLE :"use_role"; -\i test/pgxntool/finish.sql +\i test/finish.sql -- vi: expandtab ts=2 sw=2 diff --git a/test/sql/relation__.sql b/test/sql/relation__.sql index 3c3e558..d811762 100644 --- a/test/sql/relation__.sql +++ b/test/sql/relation__.sql @@ -43,6 +43,7 @@ SELECT plan( + 4 -- relation__is_catalog + 5 -- relation__column_names + 1 -- relkind drift check vs pg_class.h + + 1 -- search_path still clean (test/finish.sql) ); -- relation_type enum mapping @@ -214,6 +215,6 @@ SELECT is( , 'NULL input returns NULL (STRICT function)' ); -\i test/pgxntool/finish.sql +\i test/finish.sql -- vi: expandtab ts=2 sw=2 diff --git a/test/sql/routine__.sql b/test/sql/routine__.sql index 5b67b93..4933c51 100644 --- a/test/sql/routine__.sql +++ b/test/sql/routine__.sql @@ -25,6 +25,7 @@ SELECT plan( + 1 -- isnt_definer: routine__parse_arg_names_text + 3 -- routine__arg_names() tests + 4 -- routine__arg_names_text() tests + + 1 -- search_path still clean (test/finish.sql) ); \set kind type @@ -287,6 +288,6 @@ SELECT is( , 'Verify routine__arg_names_text() with no arguments' ); -\i test/pgxntool/finish.sql +\i test/finish.sql -- vi: expandtab ts=2 sw=2 diff --git a/test/sql/sequence.sql b/test/sql/sequence.sql index a408b32..aac96c2 100644 --- a/test/sql/sequence.sql +++ b/test/sql/sequence.sql @@ -26,6 +26,7 @@ SELECT plan(( +2 -- next +8 -- set +3 -- currval + +1 -- search_path still clean (test/finish.sql) )::int); GRANT SELECT ON functions TO public; @@ -135,6 +136,6 @@ SELECT is( , 'currval' ); -\i test/pgxntool/finish.sql +\i test/finish.sql -- vi: expandtab ts=2 sw=2 diff --git a/test/sql/trigger.sql b/test/sql/trigger.sql index 76a3f49..6b361c5 100644 --- a/test/sql/trigger.sql +++ b/test/sql/trigger.sql @@ -17,6 +17,8 @@ SELECT plan( + 2 -- verify trigger__parse output + 1 -- verify trigger__args_as_array() + + + 1 -- search_path still clean (test/finish.sql) ); SET LOCAL ROLE :"no_use_role"; @@ -149,6 +151,6 @@ SELECT is( , 'verify trigger__args_as_text()' ); -\i test/pgxntool/finish.sql +\i test/finish.sql -- vi: expandtab ts=2 sw=2