From 992d702bfafdb4258e65cbfa7353a631460a8389 Mon Sep 17 00:00:00 2001
From: Stephen Frost <sfrost@snowman.net>
Date: Mon, 28 Sep 2015 15:48:36 -0400
Subject: [PATCH] Ensure a few policies remain for pg_upgrade

To make sure that pg_dump/pg_restore function properly with RLS
policies, arrange to have a few of them left around at the end of the
regression tests.

Back-patch to 9.5 where RLS was added.
---
 src/test/regress/expected/rowsecurity.out |  9 +++++++++
 src/test/regress/output/misc.source       |  3 ++-
 src/test/regress/sql/rowsecurity.sql      | 10 ++++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out
index 9d3540fb1ea..54091e5dede 100644
--- a/src/test/regress/expected/rowsecurity.out
+++ b/src/test/regress/expected/rowsecurity.out
@@ -3026,3 +3026,12 @@ DROP USER rls_regress_user2;
 DROP USER rls_regress_exempt_user;
 DROP ROLE rls_regress_group1;
 DROP ROLE rls_regress_group2;
+-- Arrange to have a few policies left over, for testing
+-- pg_dump/pg_restore
+CREATE SCHEMA rls_regress_schema;
+CREATE TABLE rls_tbl (c1 int);
+ALTER TABLE rls_tbl ENABLE ROW LEVEL SECURITY;
+CREATE POLICY p1 ON rls_tbl USING (c1 > 5);
+CREATE POLICY p2 ON rls_tbl FOR SELECT USING (c1 <= 3);
+CREATE POLICY p3 ON rls_tbl FOR UPDATE USING (c1 <= 3) WITH CHECK (c1 > 5);
+CREATE POLICY p4 ON rls_tbl FOR DELETE USING (c1 <= 3);
diff --git a/src/test/regress/output/misc.source b/src/test/regress/output/misc.source
index 9eedb363d06..44147638188 100644
--- a/src/test/regress/output/misc.source
+++ b/src/test/regress/output/misc.source
@@ -671,6 +671,7 @@ SELECT user_relns() AS user_relns
  random_tbl
  real_city
  reltime_tbl
+ rls_tbl
  road
  shighway
  slow_emp4000
@@ -708,7 +709,7 @@ SELECT user_relns() AS user_relns
  tvvmv
  varchar_tbl
  xacttest
-(130 rows)
+(131 rows)
 
 SELECT name(equipment(hobby_construct(text 'skywalking', text 'mer')));
  name 
diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql
index 933c83e5579..6ed0daf345f 100644
--- a/src/test/regress/sql/rowsecurity.sql
+++ b/src/test/regress/sql/rowsecurity.sql
@@ -1307,3 +1307,13 @@ DROP USER rls_regress_user2;
 DROP USER rls_regress_exempt_user;
 DROP ROLE rls_regress_group1;
 DROP ROLE rls_regress_group2;
+
+-- Arrange to have a few policies left over, for testing
+-- pg_dump/pg_restore
+CREATE SCHEMA rls_regress_schema;
+CREATE TABLE rls_tbl (c1 int);
+ALTER TABLE rls_tbl ENABLE ROW LEVEL SECURITY;
+CREATE POLICY p1 ON rls_tbl USING (c1 > 5);
+CREATE POLICY p2 ON rls_tbl FOR SELECT USING (c1 <= 3);
+CREATE POLICY p3 ON rls_tbl FOR UPDATE USING (c1 <= 3) WITH CHECK (c1 > 5);
+CREATE POLICY p4 ON rls_tbl FOR DELETE USING (c1 <= 3);
-- 
GitLab