|
| 1 | +# Role and permissions checks |
| 2 | +# We are using three backends: read-write, read, snapshot. |
| 3 | + |
| 4 | +setup { |
| 5 | + create role test_owner; |
| 6 | + create role test_role1; |
| 7 | + create role test_role2; |
| 8 | + create role test_role3; |
| 9 | + create table t1 as |
| 10 | + select generate_series as id, trim( to_char( generate_series, '00' ) ) as "name" |
| 11 | + from generate_series( 1, 10 ); |
| 12 | + alter table t1 owner to test_owner; |
| 13 | +} |
| 14 | + |
| 15 | +teardown { |
| 16 | + select pg_switch_to_snapshot( 0 ); |
| 17 | + select pg_remove_snapshot( ( select recent_snapshot from pg_control_snapshot() ) ); |
| 18 | + DROP TABLE t1 CASCADE; |
| 19 | + drop role test_role3; |
| 20 | + drop role test_role2; |
| 21 | + drop role test_role1; |
| 22 | + drop role test_owner; |
| 23 | +} |
| 24 | + |
| 25 | +session "s_1" |
| 26 | +step "s1_g_1" { |
| 27 | + grant select, insert, update, delete on t1 to test_role1; |
| 28 | +} |
| 29 | +step "s1_g_2" { |
| 30 | + alter table t1 owner to test_role2; |
| 31 | + revoke all on t1 from test_role2; |
| 32 | + grant select, update, insert, delete on t1 to test_role2; |
| 33 | +} |
| 34 | +step "s1_g_3" { |
| 35 | + grant select on t1 to test_role3; |
| 36 | +} |
| 37 | +step "s1_r_1" { |
| 38 | + revoke delete, insert on table t1 from test_role1; |
| 39 | +} |
| 40 | +step "s1_r_2" { |
| 41 | + revoke delete, insert, update on table t1 from test_role2; |
| 42 | +} |
| 43 | +step "s1_check" { |
| 44 | + SELECT grantee, grantor, privilege_type, ( select tableowner from pg_tables where ( table_schema || '.' || table_name ) = ( schemaname || '.' || tablename ) ) FROM information_schema.role_table_grants WHERE table_name = 't1' order by grantor, grantee, privilege_type; |
| 45 | + select count(*) as cnt from t1; |
| 46 | +} |
| 47 | +step "s1_sb_0" { |
| 48 | + select pg_set_backend_snapshot( 0 ); |
| 49 | +} |
| 50 | +step "s1_sb_1" { |
| 51 | + select pg_set_backend_snapshot( ( select recent_snapshot - 2 from pg_control_snapshot() ) ); |
| 52 | +} |
| 53 | +step "s1_sb_2" { |
| 54 | + select pg_set_backend_snapshot( ( select recent_snapshot - 1 from pg_control_snapshot() ) ); |
| 55 | +} |
| 56 | +step "s1_sb_3" { |
| 57 | + select pg_set_backend_snapshot( ( select recent_snapshot from pg_control_snapshot() ) ); |
| 58 | +} |
| 59 | + |
| 60 | +session "s2" |
| 61 | +step "s2_check" { |
| 62 | + SELECT grantee, grantor, privilege_type, ( select tableowner from pg_tables where ( table_schema || '.' || table_name ) = ( schemaname || '.' || tablename ) ) FROM information_schema.role_table_grants WHERE table_name = 't1' order by grantor, grantee, privilege_type; |
| 63 | +} |
| 64 | +step "s2_sb_0" { |
| 65 | + select pg_set_backend_snapshot( 0 ); |
| 66 | +} |
| 67 | +step "s2_sb_1" { |
| 68 | + select pg_set_backend_snapshot( ( select recent_snapshot - 2 from pg_control_snapshot() ) ); |
| 69 | +} |
| 70 | +step "s2_sb_2" { |
| 71 | + select pg_set_backend_snapshot( ( select recent_snapshot - 1 from pg_control_snapshot() ) ); |
| 72 | +} |
| 73 | +step "s2_sb_3" { |
| 74 | + select pg_set_backend_snapshot( ( select recent_snapshot from pg_control_snapshot() ) ); |
| 75 | +} |
| 76 | + |
| 77 | +session "s3" |
| 78 | +step "s3_mk_sn" { |
| 79 | + select 1 from pg_make_snapshot(); |
| 80 | +} |
| 81 | +step "s3_sw_0" { |
| 82 | + select pg_switch_to_snapshot( 0 ); |
| 83 | +} |
| 84 | +step "s3_sw_1" { |
| 85 | + select pg_control_snapshot(); |
| 86 | + select pg_switch_to_snapshot( ( select recent_snapshot - 2 from pg_control_snapshot() ) ); |
| 87 | + select pg_control_snapshot(); |
| 88 | +} |
| 89 | +step "s3_sw_2" { |
| 90 | + select pg_switch_to_snapshot( ( select recent_snapshot - 1 from pg_control_snapshot() ) ); |
| 91 | +} |
| 92 | +step "s3_sw_3" { |
| 93 | + select pg_switch_to_snapshot( ( select recent_snapshot from pg_control_snapshot() ) ); |
| 94 | + select 'СМОТРЕТЬ НИЖЕ'; |
| 95 | +} |
| 96 | +step "s3_rc_sn" { |
| 97 | + select pg_recover_to_snapshot( ( select recent_snapshot from pg_control_snapshot() ) ); |
| 98 | +} |
| 99 | +step "s3_rc_sn_1" { |
| 100 | + select pg_recover_to_snapshot( ( select recent_snapshot - 2 from pg_control_snapshot() ) ); |
| 101 | +} |
| 102 | +step "s3_rc_sn_2" { |
| 103 | + select pg_recover_to_snapshot( ( select recent_snapshot - 1 from pg_control_snapshot() ) ); |
| 104 | +} |
| 105 | +step "s3_control_sn" { |
| 106 | + select * from pg_control_snapshot(); |
| 107 | +} |
| 108 | + |
| 109 | +#permutation "s3_mk_sn" "s1_g_1" "s3_mk_sn" "s1_g_2" "s1_g_3" "s1_r_1" "s3_mk_sn" "s1_r_2" "s3_sw_1" "s1_check" "s2_check" "s3_sw_2" "s1_check" "s2_check" "s3_sw_3" "s1_check" "s2_check" "s3_sw_0" "s1_check" "s2_check" |
| 110 | +#permutation "s3_mk_sn" "s1_g_1" "s3_mk_sn" "s1_g_2" "s1_g_3" "s1_r_1" "s3_mk_sn" "s1_r_2" "s1_sb_1" "s1_check" "s2_check" "s1_sb_2" "s1_check" "s2_check" "s1_sb_3" "s1_check" "s2_check" "s1_sb_0" "s1_check" "s2_check" |
| 111 | +#permutation "s3_mk_sn" "s1_g_1" "s3_mk_sn" "s1_g_2" "s1_g_3" "s1_r_1" "s3_mk_sn" "s1_r_2" "s2_sb_1" "s1_check" "s2_check" "s2_sb_2" "s1_check" "s2_check" "s2_sb_3" "s1_check" "s2_check" "s2_sb_0" "s1_check" "s2_check" |
| 112 | +#permutation "s3_mk_sn" "s1_g_1" "s3_mk_sn" "s1_g_2" "s1_g_3" "s1_r_1" "s3_mk_sn" "s1_r_2" "s3_rc_sn_2" "s1_check" "s2_check" |
| 113 | +#permutation "s3_mk_sn" "s1_g_1" "s3_mk_sn" "s1_g_2" "s1_g_3" "s1_r_1" "s3_mk_sn" "s1_r_2" "s3_control_sn" "s3_rc_sn_2" "s1_check" "s2_check" "s3_control_sn" |
| 114 | +#permutation "s3_mk_sn" "s1_g_1" "s3_mk_sn" "s1_g_2" "s1_g_3" "s1_r_1" "s3_mk_sn" "s1_r_2" "s3_rc_sn" "s1_check" "s2_check" "s3_rc_sn" "s1_check" "s2_check" "s3_rc_sn" "s1_check" "s2_check" "s3_mk_sn" |
| 115 | + |
| 116 | +#permutation "s3_mk_sn" "s1_g_1" "s3_mk_sn" "s1_g_2" "s1_g_3" "s1_r_1" "s3_mk_sn" "s1_r_2" "s3_sw_1" "s1_check" |
| 117 | +#permutation "s3_mk_sn" "s1_g_1" "s3_mk_sn" "s1_g_2" "s1_g_3" "s1_r_1" "s3_mk_sn" "s1_r_2" "s3_control_sn" "s3_rc_sn_2" "s1_check" "s3_control_sn" |
| 118 | + |
| 119 | +permutation "s3_mk_sn" "s1_check" "s1_g_1" "s1_check" "s3_sw_3" "s1_check" |
| 120 | +permutation "s3_mk_sn" "s1_g_1" "s3_mk_sn" "s1_g_2" "s3_mk_sn" "s3_control_sn" "s3_rc_sn_2" "s1_check" "s3_control_sn" |
| 121 | +permutation "s3_mk_sn" "s1_check" "s1_g_1" "s1_check" "s3_sw_3" "s1_check" |
| 122 | +permutation "s3_mk_sn" "s1_g_1" "s3_mk_sn" "s1_g_2" "s3_mk_sn" "s3_control_sn" "s3_rc_sn" "s1_check" "s3_control_sn" |
| 123 | +permutation "s3_mk_sn" "s1_check" "s1_g_1" "s1_check" "s3_sw_3" "s1_check" |
0 commit comments