summaryrefslogtreecommitdiff
path: root/src/test/regress/sql
diff options
context:
space:
mode:
authorJoe Conway <mail@joeconway.com>2015-07-28 16:24:01 -0700
committerJoe Conway <mail@joeconway.com>2015-07-28 16:24:01 -0700
commitd824e2800f66f6180189d973c720611855c6f619 (patch)
tree2a2700c0a3180d82a5afb6a2d3e034ced3542867 /src/test/regress/sql
parentf781a0f1d88411978c9df5f05cbb4f46aabe3d24 (diff)
downloadpostgresql-d824e2800f66f6180189d973c720611855c6f619.tar.gz
Disallow converting a table to a view if row security is present.
When DefineQueryRewrite() is about to convert a table to a view, it checks the table for features unavailable to views. For example, it rejects tables having triggers. It omits to reject tables having relrowsecurity or a pg_policy record. Fix that. To faciliate the repair, invent relation_has_policies() which indicates the presence of policies on a relation even when row security is disabled for that relation. Reported by Noah Misch. Patch by me, review by Stephen Frost. Back-patch to 9.5 where RLS was introduced.
Diffstat (limited to 'src/test/regress/sql')
-rw-r--r--src/test/regress/sql/rowsecurity.sql25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql
index 529edd01c7..03f82987c4 100644
--- a/src/test/regress/sql/rowsecurity.sql
+++ b/src/test/regress/sql/rowsecurity.sql
@@ -1261,6 +1261,31 @@ ROLLBACK TO q;
ROLLBACK; -- cleanup
--
+-- Converting table to view
+--
+BEGIN;
+SET ROW_SECURITY = FORCE;
+CREATE TABLE t (c int);
+CREATE POLICY p ON t USING (c % 2 = 1);
+ALTER TABLE t ENABLE ROW LEVEL SECURITY;
+
+SAVEPOINT q;
+CREATE RULE "_RETURN" AS ON SELECT TO t DO INSTEAD
+ SELECT * FROM generate_series(1,5) t0(c); -- fails due to row level security enabled
+ROLLBACK TO q;
+
+ALTER TABLE t DISABLE ROW LEVEL SECURITY;
+SAVEPOINT q;
+CREATE RULE "_RETURN" AS ON SELECT TO t DO INSTEAD
+ SELECT * FROM generate_series(1,5) t0(c); -- fails due to policy p on t
+ROLLBACK TO q;
+
+DROP POLICY p ON t;
+CREATE RULE "_RETURN" AS ON SELECT TO t DO INSTEAD
+ SELECT * FROM generate_series(1,5) t0(c); -- succeeds
+ROLLBACK;
+
+--
-- Clean up objects
--
RESET SESSION AUTHORIZATION;