diff --git a/src/test/regress/expected/sequence.out b/src/test/regress/expected/sequence.out index a27b5fda04500773e89cd4d8f087e0f94c0ae3d3..8783ca62a6f268412d823c50c2d08ca444d9efbb 100644 --- a/src/test/regress/expected/sequence.out +++ b/src/test/regress/expected/sequence.out @@ -367,6 +367,41 @@ DROP SEQUENCE seq2; SELECT lastval(); ERROR: lastval is not yet defined in this session CREATE USER seq_user; +-- privileges tests +-- nextval +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +REVOKE ALL ON seq3 FROM seq_user; +GRANT SELECT ON seq3 TO seq_user; +SELECT nextval('seq3'); +ERROR: permission denied for sequence seq3 +ROLLBACK; +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +REVOKE ALL ON seq3 FROM seq_user; +GRANT UPDATE ON seq3 TO seq_user; +SELECT nextval('seq3'); + nextval +--------- + 1 +(1 row) + +ROLLBACK; +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +REVOKE ALL ON seq3 FROM seq_user; +GRANT USAGE ON seq3 TO seq_user; +SELECT nextval('seq3'); + nextval +--------- + 1 +(1 row) + +ROLLBACK; +-- currval BEGIN; SET LOCAL SESSION AUTHORIZATION seq_user; CREATE SEQUENCE seq3; @@ -377,8 +412,96 @@ SELECT nextval('seq3'); (1 row) REVOKE ALL ON seq3 FROM seq_user; +GRANT SELECT ON seq3 TO seq_user; +SELECT currval('seq3'); + currval +--------- + 1 +(1 row) + +ROLLBACK; +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +SELECT nextval('seq3'); + nextval +--------- + 1 +(1 row) + +REVOKE ALL ON seq3 FROM seq_user; +GRANT UPDATE ON seq3 TO seq_user; +SELECT currval('seq3'); +ERROR: permission denied for sequence seq3 +ROLLBACK; +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +SELECT nextval('seq3'); + nextval +--------- + 1 +(1 row) + +REVOKE ALL ON seq3 FROM seq_user; +GRANT USAGE ON seq3 TO seq_user; +SELECT currval('seq3'); + currval +--------- + 1 +(1 row) + +ROLLBACK; +-- lastval +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +SELECT nextval('seq3'); + nextval +--------- + 1 +(1 row) + +REVOKE ALL ON seq3 FROM seq_user; +GRANT SELECT ON seq3 TO seq_user; +SELECT lastval(); + lastval +--------- + 1 +(1 row) + +ROLLBACK; +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +SELECT nextval('seq3'); + nextval +--------- + 1 +(1 row) + +REVOKE ALL ON seq3 FROM seq_user; +GRANT UPDATE ON seq3 TO seq_user; SELECT lastval(); ERROR: permission denied for sequence seq3 +ROLLBACK; +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +SELECT nextval('seq3'); + nextval +--------- + 1 +(1 row) + +REVOKE ALL ON seq3 FROM seq_user; +GRANT USAGE ON seq3 TO seq_user; +SELECT lastval(); + lastval +--------- + 1 +(1 row) + ROLLBACK; -- Sequences should get wiped out as well: DROP TABLE serialTest, serialTest2; diff --git a/src/test/regress/expected/sequence_1.out b/src/test/regress/expected/sequence_1.out index e426f64278104306291445dedb56937d6ed6de4e..951fc9e791d56bbf9e981f845a6c2cb2efe04989 100644 --- a/src/test/regress/expected/sequence_1.out +++ b/src/test/regress/expected/sequence_1.out @@ -367,6 +367,41 @@ DROP SEQUENCE seq2; SELECT lastval(); ERROR: lastval is not yet defined in this session CREATE USER seq_user; +-- privileges tests +-- nextval +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +REVOKE ALL ON seq3 FROM seq_user; +GRANT SELECT ON seq3 TO seq_user; +SELECT nextval('seq3'); +ERROR: permission denied for sequence seq3 +ROLLBACK; +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +REVOKE ALL ON seq3 FROM seq_user; +GRANT UPDATE ON seq3 TO seq_user; +SELECT nextval('seq3'); + nextval +--------- + 1 +(1 row) + +ROLLBACK; +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +REVOKE ALL ON seq3 FROM seq_user; +GRANT USAGE ON seq3 TO seq_user; +SELECT nextval('seq3'); + nextval +--------- + 1 +(1 row) + +ROLLBACK; +-- currval BEGIN; SET LOCAL SESSION AUTHORIZATION seq_user; CREATE SEQUENCE seq3; @@ -377,8 +412,96 @@ SELECT nextval('seq3'); (1 row) REVOKE ALL ON seq3 FROM seq_user; +GRANT SELECT ON seq3 TO seq_user; +SELECT currval('seq3'); + currval +--------- + 1 +(1 row) + +ROLLBACK; +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +SELECT nextval('seq3'); + nextval +--------- + 1 +(1 row) + +REVOKE ALL ON seq3 FROM seq_user; +GRANT UPDATE ON seq3 TO seq_user; +SELECT currval('seq3'); +ERROR: permission denied for sequence seq3 +ROLLBACK; +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +SELECT nextval('seq3'); + nextval +--------- + 1 +(1 row) + +REVOKE ALL ON seq3 FROM seq_user; +GRANT USAGE ON seq3 TO seq_user; +SELECT currval('seq3'); + currval +--------- + 1 +(1 row) + +ROLLBACK; +-- lastval +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +SELECT nextval('seq3'); + nextval +--------- + 1 +(1 row) + +REVOKE ALL ON seq3 FROM seq_user; +GRANT SELECT ON seq3 TO seq_user; +SELECT lastval(); + lastval +--------- + 1 +(1 row) + +ROLLBACK; +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +SELECT nextval('seq3'); + nextval +--------- + 1 +(1 row) + +REVOKE ALL ON seq3 FROM seq_user; +GRANT UPDATE ON seq3 TO seq_user; SELECT lastval(); ERROR: permission denied for sequence seq3 +ROLLBACK; +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +SELECT nextval('seq3'); + nextval +--------- + 1 +(1 row) + +REVOKE ALL ON seq3 FROM seq_user; +GRANT USAGE ON seq3 TO seq_user; +SELECT lastval(); + lastval +--------- + 1 +(1 row) + ROLLBACK; -- Sequences should get wiped out as well: DROP TABLE serialTest, serialTest2; diff --git a/src/test/regress/sql/sequence.sql b/src/test/regress/sql/sequence.sql index 8d3b700f7da73caa030652703552d2adad7170d2..0dd653dc223a6315bb58556de0485089388fa15c 100644 --- a/src/test/regress/sql/sequence.sql +++ b/src/test/regress/sql/sequence.sql @@ -168,11 +168,86 @@ SELECT lastval(); CREATE USER seq_user; +-- privileges tests + +-- nextval +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +REVOKE ALL ON seq3 FROM seq_user; +GRANT SELECT ON seq3 TO seq_user; +SELECT nextval('seq3'); +ROLLBACK; + +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +REVOKE ALL ON seq3 FROM seq_user; +GRANT UPDATE ON seq3 TO seq_user; +SELECT nextval('seq3'); +ROLLBACK; + +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +REVOKE ALL ON seq3 FROM seq_user; +GRANT USAGE ON seq3 TO seq_user; +SELECT nextval('seq3'); +ROLLBACK; + +-- currval +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +SELECT nextval('seq3'); +REVOKE ALL ON seq3 FROM seq_user; +GRANT SELECT ON seq3 TO seq_user; +SELECT currval('seq3'); +ROLLBACK; + +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +SELECT nextval('seq3'); +REVOKE ALL ON seq3 FROM seq_user; +GRANT UPDATE ON seq3 TO seq_user; +SELECT currval('seq3'); +ROLLBACK; + +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +SELECT nextval('seq3'); +REVOKE ALL ON seq3 FROM seq_user; +GRANT USAGE ON seq3 TO seq_user; +SELECT currval('seq3'); +ROLLBACK; + +-- lastval +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +SELECT nextval('seq3'); +REVOKE ALL ON seq3 FROM seq_user; +GRANT SELECT ON seq3 TO seq_user; +SELECT lastval(); +ROLLBACK; + +BEGIN; +SET LOCAL SESSION AUTHORIZATION seq_user; +CREATE SEQUENCE seq3; +SELECT nextval('seq3'); +REVOKE ALL ON seq3 FROM seq_user; +GRANT UPDATE ON seq3 TO seq_user; +SELECT lastval(); +ROLLBACK; + BEGIN; SET LOCAL SESSION AUTHORIZATION seq_user; CREATE SEQUENCE seq3; SELECT nextval('seq3'); REVOKE ALL ON seq3 FROM seq_user; +GRANT USAGE ON seq3 TO seq_user; SELECT lastval(); ROLLBACK;