policy1="mydb\tfiltered_table1\tdefault\tdefault ON mydb.filtered_table1\t9e8a8f62-4965-2b5e-8599-57c7b99b3549\tusers.xml\t0\ta = 1\t\t\t\t\n"
policy2="mydb\tfiltered_table2\tdefault\tdefault ON mydb.filtered_table2\tcffae79d-b9bf-a2ef-b798-019c18470b25\tusers.xml\t0\ta + b < 1 or c - d > 5\t\t\t\t\n"
policy3="mydb\tfiltered_table3\tdefault\tdefault ON mydb.filtered_table3\t12fc5cef-e3da-3940-ec79-d8be3911f42b\tusers.xml\t0\tc = 1\t\t\t\t\n"
assertinstance.query("SELECT * from system.row_policies WHERE has(currentRowPolicyIDs('mydb', 'filtered_table1'), id) ORDER BY table, name")==policy1
assertinstance.query("SELECT * from system.row_policies WHERE has(currentRowPolicyIDs('mydb', 'filtered_table2'), id) ORDER BY table, name")==policy2
assertinstance.query("SELECT * from system.row_policies WHERE has(currentRowPolicyIDs('mydb', 'filtered_table3'), id) ORDER BY table, name")==policy3
assertinstance.query("SELECT * from system.row_policies ORDER BY table, name")==policy1+policy2+policy3
assertinstance.query("SELECT * from system.row_policies WHERE has(currentRowPolicyIDs(), id) ORDER BY table, name")==policy1+policy2+policy3
assertinstance.query("SHOW POLICIES ON mydb.filtered_table1")=="default\n"
assertinstance.query("SHOW POLICIES CURRENT ON mydb.filtered_table2")=="default\n"
assertinstance.query("SHOW POLICIES")=="default ON mydb.filtered_table1\ndefault ON mydb.filtered_table2\ndefault ON mydb.filtered_table3\n"
assertinstance.query("SHOW POLICIES CURRENT")=="default ON mydb.filtered_table1\ndefault ON mydb.filtered_table2\ndefault ON mydb.filtered_table3\n"
assertinstance.query("SHOW CREATE POLICY default ON mydb.filtered_table1")=="CREATE POLICY default ON mydb.filtered_table1 FOR SELECT USING a = 1 TO default\n"
assertinstance.query("SHOW CREATE POLICY default ON mydb.filtered_table2")=="CREATE POLICY default ON mydb.filtered_table2 FOR SELECT USING ((a + b) < 1) OR ((c - d) > 5) TO default\n"
assertinstance.query("SHOW CREATE POLICY default ON mydb.filtered_table3")=="CREATE POLICY default ON mydb.filtered_table3 FOR SELECT USING c = 1 TO default\n"
copy_policy_xml('all_rows.xml')
assertinstance.query("SHOW CREATE POLICY default ON mydb.filtered_table1")=="CREATE POLICY default ON mydb.filtered_table1 FOR SELECT USING 1 TO default\n"
assertinstance.query("SHOW CREATE POLICY default ON mydb.filtered_table2")=="CREATE POLICY default ON mydb.filtered_table2 FOR SELECT USING 1 TO default\n"
assertinstance.query("SHOW CREATE POLICY default ON mydb.filtered_table3")=="CREATE POLICY default ON mydb.filtered_table3 FOR SELECT USING 1 TO default\n"
copy_policy_xml('no_rows.xml')
assertinstance.query("SHOW CREATE POLICY default ON mydb.filtered_table1")=="CREATE POLICY default ON mydb.filtered_table1 FOR SELECT USING NULL TO default\n"
assertinstance.query("SHOW CREATE POLICY default ON mydb.filtered_table2")=="CREATE POLICY default ON mydb.filtered_table2 FOR SELECT USING NULL TO default\n"
assertinstance.query("SHOW CREATE POLICY default ON mydb.filtered_table3")=="CREATE POLICY default ON mydb.filtered_table3 FOR SELECT USING NULL TO default\n"
copy_policy_xml('no_filters.xml')
assertinstance.query("SHOW POLICIES")==""
deftest_dcl_management():
copy_policy_xml('no_filters.xml')
assertinstance.query("SHOW POLICIES")==""
instance.query("CREATE POLICY pA ON mydb.filtered_table1 FOR SELECT USING a<b")
assertinstance.query("SELECT * FROM mydb.filtered_table1")=="0\t0\n0\t1\n1\t0\n1\t1\n"
assertinstance.query("SHOW POLICIES CURRENT ON mydb.filtered_table1")==""
assertinstance.query("SHOW POLICIES ON mydb.filtered_table1")=="pA\n"
instance.query("ALTER POLICY pA ON mydb.filtered_table1 TO default")
assertinstance.query("SELECT * FROM mydb.filtered_table1")=="0\t1\n"
assertinstance.query("SHOW POLICIES CURRENT ON mydb.filtered_table1")=="pA\n"
instance.query("ALTER POLICY pA ON mydb.filtered_table1 FOR SELECT USING a>b")
assertinstance.query("SELECT * FROM mydb.filtered_table1")=="1\t0\n"
instance.query("ALTER POLICY pA ON mydb.filtered_table1 RENAME TO pB")
assertinstance.query("SELECT * FROM mydb.filtered_table1")=="1\t0\n"
assertinstance.query("SHOW POLICIES CURRENT ON mydb.filtered_table1")=="pB\n"
assertinstance.query("SHOW CREATE POLICY pB ON mydb.filtered_table1")=="CREATE POLICY pB ON mydb.filtered_table1 FOR SELECT USING a > b TO default\n"
instance.query("DROP POLICY pB ON mydb.filtered_table1")
assertinstance.query("SELECT * FROM mydb.filtered_table1")=="0\t0\n0\t1\n1\t0\n1\t1\n"
assertinstance.query("SHOW POLICIES")==""
deftest_users_xml_is_readonly():
assertre.search("storage is readonly",instance.query_and_get_error("DROP POLICY default ON mydb.filtered_table1"))