mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-05 16:19:21 +02:00
Improve regression test coverage of table lock modes vs permissions.
Test the interactions with permissions and LOCK TABLE. Specifically ROW EXCLUSIVE, ACCESS SHARE, and ACCESS EXCLUSIVE modes against SELECT, INSERT, UPDATE, DELETE, and TRUNCATE permissions. Discussed by Stephen Frost and Michael Paquier, patch by the latter. Backpatch to 9.5 where matching behavior was first committed.
This commit is contained in:
parent
de184e57e8
commit
d5f551abcf
@ -1569,3 +1569,86 @@ DROP USER regressuser4;
|
||||
DROP USER regressuser5;
|
||||
DROP USER regressuser6;
|
||||
ERROR: role "regressuser6" does not exist
|
||||
-- permissions with LOCK TABLE
|
||||
CREATE USER locktable_user;
|
||||
CREATE TABLE lock_table (a int);
|
||||
-- LOCK TABLE and SELECT permission
|
||||
GRANT SELECT ON lock_table TO locktable_user;
|
||||
SET SESSION AUTHORIZATION locktable_user;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ROW EXCLUSIVE MODE; -- should fail
|
||||
ERROR: permission denied for relation lock_table
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS SHARE MODE; -- should pass
|
||||
COMMIT;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS EXCLUSIVE MODE; -- should fail
|
||||
ERROR: permission denied for relation lock_table
|
||||
ROLLBACK;
|
||||
\c
|
||||
REVOKE SELECT ON lock_table FROM locktable_user;
|
||||
-- LOCK TABLE and INSERT permission
|
||||
GRANT INSERT ON lock_table TO locktable_user;
|
||||
SET SESSION AUTHORIZATION locktable_user;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ROW EXCLUSIVE MODE; -- should pass
|
||||
COMMIT;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS SHARE MODE; -- should fail
|
||||
ERROR: permission denied for relation lock_table
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS EXCLUSIVE MODE; -- should fail
|
||||
ERROR: permission denied for relation lock_table
|
||||
ROLLBACK;
|
||||
\c
|
||||
REVOKE INSERT ON lock_table FROM locktable_user;
|
||||
-- LOCK TABLE and UPDATE permission
|
||||
GRANT UPDATE ON lock_table TO locktable_user;
|
||||
SET SESSION AUTHORIZATION locktable_user;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ROW EXCLUSIVE MODE; -- should pass
|
||||
COMMIT;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS SHARE MODE; -- should fail
|
||||
ERROR: permission denied for relation lock_table
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS EXCLUSIVE MODE; -- should pass
|
||||
COMMIT;
|
||||
\c
|
||||
REVOKE UPDATE ON lock_table FROM locktable_user;
|
||||
-- LOCK TABLE and DELETE permission
|
||||
GRANT DELETE ON lock_table TO locktable_user;
|
||||
SET SESSION AUTHORIZATION locktable_user;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ROW EXCLUSIVE MODE; -- should pass
|
||||
COMMIT;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS SHARE MODE; -- should fail
|
||||
ERROR: permission denied for relation lock_table
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS EXCLUSIVE MODE; -- should pass
|
||||
COMMIT;
|
||||
\c
|
||||
REVOKE DELETE ON lock_table FROM locktable_user;
|
||||
-- LOCK TABLE and TRUNCATE permission
|
||||
GRANT TRUNCATE ON lock_table TO locktable_user;
|
||||
SET SESSION AUTHORIZATION locktable_user;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ROW EXCLUSIVE MODE; -- should pass
|
||||
COMMIT;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS SHARE MODE; -- should fail
|
||||
ERROR: permission denied for relation lock_table
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS EXCLUSIVE MODE; -- should pass
|
||||
COMMIT;
|
||||
\c
|
||||
REVOKE TRUNCATE ON lock_table FROM locktable_user;
|
||||
-- clean up
|
||||
DROP TABLE lock_table;
|
||||
DROP USER locktable_user;
|
||||
|
@ -975,3 +975,87 @@ DROP USER regressuser3;
|
||||
DROP USER regressuser4;
|
||||
DROP USER regressuser5;
|
||||
DROP USER regressuser6;
|
||||
|
||||
|
||||
-- permissions with LOCK TABLE
|
||||
CREATE USER locktable_user;
|
||||
CREATE TABLE lock_table (a int);
|
||||
|
||||
-- LOCK TABLE and SELECT permission
|
||||
GRANT SELECT ON lock_table TO locktable_user;
|
||||
SET SESSION AUTHORIZATION locktable_user;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ROW EXCLUSIVE MODE; -- should fail
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS SHARE MODE; -- should pass
|
||||
COMMIT;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS EXCLUSIVE MODE; -- should fail
|
||||
ROLLBACK;
|
||||
\c
|
||||
REVOKE SELECT ON lock_table FROM locktable_user;
|
||||
|
||||
-- LOCK TABLE and INSERT permission
|
||||
GRANT INSERT ON lock_table TO locktable_user;
|
||||
SET SESSION AUTHORIZATION locktable_user;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ROW EXCLUSIVE MODE; -- should pass
|
||||
COMMIT;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS SHARE MODE; -- should fail
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS EXCLUSIVE MODE; -- should fail
|
||||
ROLLBACK;
|
||||
\c
|
||||
REVOKE INSERT ON lock_table FROM locktable_user;
|
||||
|
||||
-- LOCK TABLE and UPDATE permission
|
||||
GRANT UPDATE ON lock_table TO locktable_user;
|
||||
SET SESSION AUTHORIZATION locktable_user;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ROW EXCLUSIVE MODE; -- should pass
|
||||
COMMIT;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS SHARE MODE; -- should fail
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS EXCLUSIVE MODE; -- should pass
|
||||
COMMIT;
|
||||
\c
|
||||
REVOKE UPDATE ON lock_table FROM locktable_user;
|
||||
|
||||
-- LOCK TABLE and DELETE permission
|
||||
GRANT DELETE ON lock_table TO locktable_user;
|
||||
SET SESSION AUTHORIZATION locktable_user;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ROW EXCLUSIVE MODE; -- should pass
|
||||
COMMIT;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS SHARE MODE; -- should fail
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS EXCLUSIVE MODE; -- should pass
|
||||
COMMIT;
|
||||
\c
|
||||
REVOKE DELETE ON lock_table FROM locktable_user;
|
||||
|
||||
-- LOCK TABLE and TRUNCATE permission
|
||||
GRANT TRUNCATE ON lock_table TO locktable_user;
|
||||
SET SESSION AUTHORIZATION locktable_user;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ROW EXCLUSIVE MODE; -- should pass
|
||||
COMMIT;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS SHARE MODE; -- should fail
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
LOCK TABLE lock_table IN ACCESS EXCLUSIVE MODE; -- should pass
|
||||
COMMIT;
|
||||
\c
|
||||
REVOKE TRUNCATE ON lock_table FROM locktable_user;
|
||||
|
||||
-- clean up
|
||||
DROP TABLE lock_table;
|
||||
DROP USER locktable_user;
|
||||
|
Loading…
Reference in New Issue
Block a user