|
| 1 | +-- |
| 2 | +-- Tests for things affected by allow_system_table_mods |
| 3 | +-- |
| 4 | +-- We run the same set of commands once with allow_system_table_mods |
| 5 | +-- off and then again with on. |
| 6 | +-- |
| 7 | +-- The "on" tests should where possible be wrapped in BEGIN/ROLLBACK |
| 8 | +-- blocks so as to not leave a mess around. |
| 9 | +CREATE USER regress_user_ast; |
| 10 | +SET allow_system_table_mods = off; |
| 11 | +-- create new table in pg_catalog |
| 12 | +CREATE TABLE pg_catalog.test (a int); |
| 13 | +ERROR: permission denied to create "pg_catalog.test" |
| 14 | +DETAIL: System catalog modifications are currently disallowed. |
| 15 | +-- anyarray column |
| 16 | +CREATE TABLE t1x (a int, b anyarray); |
| 17 | +ERROR: column "b" has pseudo-type anyarray |
| 18 | +-- index on system catalog |
| 19 | +ALTER TABLE pg_namespace ADD UNIQUE USING INDEX pg_namespace_oid_index; |
| 20 | +ERROR: permission denied: "pg_namespace" is a system catalog |
| 21 | +-- write to system catalog table as superuser |
| 22 | +-- (allowed even without allow_system_table_mods) |
| 23 | +INSERT INTO pg_description (objoid, classoid, objsubid, description) VALUES (0, 0, 0, 'foo'); |
| 24 | +-- write to system catalog table as normal user |
| 25 | +GRANT INSERT ON pg_description TO regress_user_ast; |
| 26 | +SET ROLE regress_user_ast; |
| 27 | +INSERT INTO pg_description (objoid, classoid, objsubid, description) VALUES (0, 0, 1, 'foo'); |
| 28 | +ERROR: permission denied for table pg_description |
| 29 | +RESET ROLE; |
| 30 | +-- policy on system catalog |
| 31 | +CREATE POLICY foo ON pg_description FOR SELECT USING (description NOT LIKE 'secret%'); |
| 32 | +ERROR: permission denied: "pg_description" is a system catalog |
| 33 | +-- reserved schema name |
| 34 | +CREATE SCHEMA pg_foo; |
| 35 | +ERROR: unacceptable schema name "pg_foo" |
| 36 | +DETAIL: The prefix "pg_" is reserved for system schemas. |
| 37 | +-- drop system table |
| 38 | +DROP TABLE pg_description; |
| 39 | +ERROR: permission denied: "pg_description" is a system catalog |
| 40 | +-- truncate of system table |
| 41 | +TRUNCATE pg_description; |
| 42 | +ERROR: permission denied: "pg_description" is a system catalog |
| 43 | +-- rename column of system table |
| 44 | +ALTER TABLE pg_description RENAME COLUMN description TO comment; |
| 45 | +ERROR: permission denied: "pg_description" is a system catalog |
| 46 | +-- ATSimplePermissions() |
| 47 | +ALTER TABLE pg_description ALTER COLUMN description SET NOT NULL; |
| 48 | +ERROR: permission denied: "pg_description" is a system catalog |
| 49 | +-- SET STATISTICS |
| 50 | +ALTER TABLE pg_description ALTER COLUMN description SET STATISTICS -1; |
| 51 | +ERROR: permission denied: "pg_description" is a system catalog |
| 52 | +-- foreign key referencing catalog |
| 53 | +CREATE TABLE foo (a oid, b oid, c int, FOREIGN KEY (a, b, c) REFERENCES pg_description); |
| 54 | +ERROR: permission denied: "pg_description" is a system catalog |
| 55 | +-- RangeVarCallbackOwnsRelation() |
| 56 | +CREATE INDEX pg_descripton_test_index ON pg_description (description); |
| 57 | +ERROR: permission denied: "pg_description" is a system catalog |
| 58 | +-- RangeVarCallbackForAlterRelation() |
| 59 | +ALTER TABLE pg_description RENAME TO pg_comment; |
| 60 | +ERROR: permission denied: "pg_description" is a system catalog |
| 61 | +ALTER TABLE pg_description SET SCHEMA public; |
| 62 | +ERROR: permission denied: "pg_description" is a system catalog |
| 63 | +-- reserved tablespace name |
| 64 | +CREATE TABLESPACE pg_foo LOCATION '/no/such/location'; |
| 65 | +ERROR: unacceptable tablespace name "pg_foo" |
| 66 | +DETAIL: The prefix "pg_" is reserved for system tablespaces. |
| 67 | +-- triggers |
| 68 | +CREATE FUNCTION tf1() RETURNS trigger |
| 69 | +LANGUAGE plpgsql |
| 70 | +AS $$ |
| 71 | +BEGIN |
| 72 | + RETURN NULL; |
| 73 | +END $$; |
| 74 | +CREATE TRIGGER t1 BEFORE INSERT ON pg_description EXECUTE FUNCTION tf1(); |
| 75 | +ERROR: permission denied: "pg_description" is a system catalog |
| 76 | +ALTER TRIGGER t1 ON pg_description RENAME TO t2; |
| 77 | +ERROR: permission denied: "pg_description" is a system catalog |
| 78 | +--DROP TRIGGER t2 ON pg_description; |
| 79 | +-- rules |
| 80 | +CREATE RULE r1 AS ON INSERT TO pg_description DO INSTEAD NOTHING; |
| 81 | +ERROR: permission denied: "pg_description" is a system catalog |
| 82 | +ALTER RULE r1 ON pg_description RENAME TO r2; |
| 83 | +ERROR: permission denied: "pg_description" is a system catalog |
| 84 | +--DROP RULE r2 ON pg_description; |
| 85 | +SET allow_system_table_mods = on; |
| 86 | +-- create new table in pg_catalog |
| 87 | +BEGIN; |
| 88 | +CREATE TABLE pg_catalog.test (a int); |
| 89 | +ROLLBACK; |
| 90 | +-- anyarray column |
| 91 | +BEGIN; |
| 92 | +CREATE TABLE t1 (a int, b anyarray); |
| 93 | +ROLLBACK; |
| 94 | +-- index on system catalog |
| 95 | +BEGIN; |
| 96 | +ALTER TABLE pg_namespace ADD UNIQUE USING INDEX pg_namespace_oid_index; |
| 97 | +ROLLBACK; |
| 98 | +-- write to system catalog table as superuser |
| 99 | +BEGIN; |
| 100 | +INSERT INTO pg_description (objoid, classoid, objsubid, description) VALUES (0, 0, 2, 'foo'); |
| 101 | +ROLLBACK; |
| 102 | +-- write to system catalog table as normal user |
| 103 | +-- (not allowed) |
| 104 | +SET ROLE regress_user_ast; |
| 105 | +INSERT INTO pg_description (objoid, classoid, objsubid, description) VALUES (0, 0, 3, 'foo'); |
| 106 | +ERROR: permission denied for table pg_description |
| 107 | +RESET ROLE; |
| 108 | +-- policy on system catalog |
| 109 | +BEGIN; |
| 110 | +CREATE POLICY foo ON pg_description FOR SELECT USING (description NOT LIKE 'secret%'); |
| 111 | +ROLLBACK; |
| 112 | +-- reserved schema name |
| 113 | +BEGIN; |
| 114 | +CREATE SCHEMA pg_foo; |
| 115 | +ROLLBACK; |
| 116 | +-- drop system table |
| 117 | +-- (This will fail anyway because it's pinned.) |
| 118 | +BEGIN; |
| 119 | +DROP TABLE pg_description; |
| 120 | +ERROR: cannot drop table pg_description because it is required by the database system |
| 121 | +ROLLBACK; |
| 122 | +-- truncate of system table |
| 123 | +BEGIN; |
| 124 | +TRUNCATE pg_description; |
| 125 | +ROLLBACK; |
| 126 | +-- rename column of system table |
| 127 | +BEGIN; |
| 128 | +ALTER TABLE pg_description RENAME COLUMN description TO comment; |
| 129 | +ROLLBACK; |
| 130 | +-- ATSimplePermissions() |
| 131 | +BEGIN; |
| 132 | +ALTER TABLE pg_description ALTER COLUMN description SET NOT NULL; |
| 133 | +ROLLBACK; |
| 134 | +-- SET STATISTICS |
| 135 | +BEGIN; |
| 136 | +ALTER TABLE pg_description ALTER COLUMN description SET STATISTICS -1; |
| 137 | +ROLLBACK; |
| 138 | +-- foreign key referencing catalog |
| 139 | +BEGIN; |
| 140 | +ALTER TABLE pg_description ADD PRIMARY KEY USING INDEX pg_description_o_c_o_index; |
| 141 | +CREATE TABLE foo (a oid, b oid, c int, FOREIGN KEY (a, b, c) REFERENCES pg_description); |
| 142 | +ROLLBACK; |
| 143 | +-- RangeVarCallbackOwnsRelation() |
| 144 | +BEGIN; |
| 145 | +CREATE INDEX pg_descripton_test_index ON pg_description (description); |
| 146 | +ROLLBACK; |
| 147 | +-- RangeVarCallbackForAlterRelation() |
| 148 | +BEGIN; |
| 149 | +ALTER TABLE pg_description RENAME TO pg_comment; |
| 150 | +ROLLBACK; |
| 151 | +BEGIN; |
| 152 | +ALTER TABLE pg_description SET SCHEMA public; |
| 153 | +ROLLBACK; |
| 154 | +-- reserved tablespace name |
| 155 | +CREATE TABLESPACE pg_foo LOCATION '/no/such/location'; |
| 156 | +ERROR: directory "/no/such/location" does not exist |
| 157 | +-- triggers |
| 158 | +CREATE TRIGGER t1 BEFORE INSERT ON pg_description EXECUTE FUNCTION tf1(); |
| 159 | +ALTER TRIGGER t1 ON pg_description RENAME TO t2; |
| 160 | +DROP TRIGGER t2 ON pg_description; |
| 161 | +-- rules |
| 162 | +CREATE RULE r1 AS ON INSERT TO pg_description DO INSTEAD NOTHING; |
| 163 | +ALTER RULE r1 ON pg_description RENAME TO r2; |
| 164 | +DROP RULE r2 ON pg_description; |
| 165 | +-- cleanup |
| 166 | +REVOKE ALL ON pg_description FROM regress_user_ast; |
| 167 | +DROP USER regress_user_ast; |
| 168 | +DROP FUNCTION tf1; |
0 commit comments