Mercurial > gemma
changeset 106:ae5bb7a979ff
Test RLS policy for responsibility area.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 15 Jun 2018 19:38:18 +0200 |
parents | b5e403843639 |
children | dd3dd2d94703 |
files | tap_tests.sql |
diffstat | 1 files changed, 28 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/tap_tests.sql Fri Jun 15 18:41:42 2018 +0200 +++ b/tap_tests.sql Fri Jun 15 19:38:18 2018 +0200 @@ -5,7 +5,7 @@ CREATE EXTENSION pgtap; -SELECT plan(7); -- Give number of tests that have to be run +SELECT plan(9); -- Give number of tests that have to be run SET search_path TO public, wamos, wamos_waterway, wamos_fairway; @@ -13,6 +13,8 @@ -- Add test data -- INSERT INTO countries VALUES ('AT'); +INSERT INTO responsibility_areas VALUES + ('AT', ST_geomfromtext('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))', 4326)); INSERT INTO user_profiles (username, country, email_adress) VALUES @@ -86,6 +88,31 @@ 'User should only see templates associated to him'); -- +-- Run tests as waterway administrator +-- +SET SESSION AUTHORIZATION waterway_admin; + +PREPARE bn_insert (varchar, geometry(POLYGON, 4326)) AS + INSERT INTO bottlenecks ( + bottleneck_id, fk_g_fid, stretch, area, rb, lb, responsible_country, + revisiting_time, limiting, source_organization) + VALUES + ($1, + ('AT', 'XXX', '00001', '00000', 1)::isrs, + isrsrange(('AT', 'XXX', '00001', '00000', 0)::isrs, + ('AT', 'XXX', '00001', '00000', 2)::isrs), + $2, 'AT', 'AT', 'AT', + 1, 'depth', 'testorganization'); +SELECT lives_ok('EXECUTE bn_insert(''test1'', + ST_geomfromtext(''POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))'', + 4326))', + 'Waterway admin can insert data within his region'); +SELECT throws_ok('EXECUTE bn_insert(''test2'', + ST_geomfromtext(''POLYGON((1 0, 1 1, 2 1, 2 0, 1 0))'', + 4326))', 42501, NULL, + 'Waterway admin cannot insert data outside his region'); + +-- -- finish tests -- SELECT * FROM finish();