Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test/expected/attribute.out
Original file line number Diff line number Diff line change
@@ -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!
3 changes: 2 additions & 1 deletion test/expected/enum.out
Original file line number Diff line number Diff line change
@@ -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!
3 changes: 2 additions & 1 deletion test/expected/extension.out
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
\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
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!
3 changes: 2 additions & 1 deletion test/expected/function.out
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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!
3 changes: 2 additions & 1 deletion test/expected/general.out
Original file line number Diff line number Diff line change
@@ -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!
3 changes: 2 additions & 1 deletion test/expected/name__check.out
Original file line number Diff line number Diff line change
@@ -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!
3 changes: 2 additions & 1 deletion test/expected/object_type.out
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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!
3 changes: 2 additions & 1 deletion test/expected/permissions.out
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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!
3 changes: 2 additions & 1 deletion test/expected/pg_depends.out
Original file line number Diff line number Diff line change
@@ -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!
3 changes: 2 additions & 1 deletion test/expected/relation__.out
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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!
3 changes: 2 additions & 1 deletion test/expected/routine__.out
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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!
3 changes: 2 additions & 1 deletion test/expected/sequence.out
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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!
3 changes: 2 additions & 1 deletion test/expected/trigger.out
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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!
21 changes: 21 additions & 0 deletions test/finish.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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; bump that file's plan() by one to account
* for it.
*/
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
10 changes: 10 additions & 0 deletions test/setup.sql
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
3 changes: 2 additions & 1 deletion test/sql/attribute.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -110,6 +111,6 @@ SELECT results_eq(
);


\i test/pgxntool/finish.sql
\i test/finish.sql

-- vi: expandtab ts=2 sw=2
3 changes: 2 additions & 1 deletion test/sql/enum.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SELECT plan(
+ 1
+ 2 -- no_use tests
+ 1
+ 1 -- search_path still clean (test/finish.sql)
);

SELECT lives_ok(
Expand All @@ -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
4 changes: 3 additions & 1 deletion test/sql/extension.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion test/sql/function.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);

/*
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion test/sql/general.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 5 additions & 2 deletions test/sql/name__check.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion test/sql/object_type.sql
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ SELECT plan(
+ 3 * 2

+ 1 -- objects__shared

+ 1 -- search_path still clean (test/finish.sql)
);

SELECT is(
Expand Down Expand Up @@ -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_';

Expand Down
3 changes: 2 additions & 1 deletion test/sql/permissions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);

/*
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion test/sql/pg_depends.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);

/*
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion test/sql/relation__.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion test/sql/routine__.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion test/sql/sequence.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -135,6 +136,6 @@ SELECT is(
, 'currval'
);

\i test/pgxntool/finish.sql
\i test/finish.sql

-- vi: expandtab ts=2 sw=2
Loading
Loading