Mercurial > gemma
changeset 100:7f934f77831a
Add first tests of RLS policies.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Wed, 13 Jun 2018 22:46:40 +0200 |
parents | 3ad1c35b258f |
children | aa32ffd5060b |
files | Dockerfile tap_tests.sql |
diffstat | 2 files changed, 80 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/Dockerfile Wed Jun 13 22:40:51 2018 +0200 +++ b/Dockerfile Wed Jun 13 22:46:40 2018 +0200 @@ -11,7 +11,7 @@ # Install PostgreSQL 10 and PostGIS RUN yum -q -y install postgresql10-server RUN yum -q -y install epel-release -RUN yum -q -y install postgis24_10 +RUN yum -q -y install postgis24_10 pgtap10 USER postgres ENV PGBIN /usr/pgsql-10/bin/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tap_tests.sql Wed Jun 13 22:46:40 2018 +0200 @@ -0,0 +1,79 @@ +-- +-- pgTAP test script +-- +BEGIN; + +CREATE EXTENSION pgtap; + +SELECT plan(5); -- Give number of tests that have to be run + +SET search_path TO public, wamos, wamos_waterway, wamos_fairway; + +-- +-- Add test data +-- +INSERT INTO countries VALUES ('AT'); + +INSERT INTO user_profiles (username, country, email_adress) + VALUES + ('waterway_user', 'AT', 'xxx'), + ('waterway_admin', 'AT', 'yyy'), + ('sys_admin', 'AT', 'zzz'); + +INSERT INTO limiting_factors VALUES ('depth'), ('width'); +INSERT INTO gauges ( + location, function_code, objname, geom, zero_point, source_organization) + VALUES + (('AT', 'XXX', '00001', '00000', 1)::isrs, + 'xxx', + 'testgauge', + ST_geomfromtext('POINT(0 0)', 4326), + 0, + 'testorganization'); +INSERT INTO bottlenecks ( + bottleneck_id, fk_g_fid, stretch, area, rb, lb, responsible_country, + revisiting_time, limiting, source_organization) + VALUES + ('testbottleneck1', + ('AT', 'XXX', '00001', '00000', 1)::isrs, + isrsrange(('AT', 'XXX', '00001', '00000', 0)::isrs, + ('AT', 'XXX', '00001', '00000', 2)::isrs), + ST_geomfromtext('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))', 4326), + 'AT', 'AT', 'AT', + 1, 'depth', 'testorganization'); +INSERT INTO bottlenecks ( + bottleneck_id, fk_g_fid, stretch, area, rb, lb, responsible_country, + revisiting_time, limiting, source_organization, staging_done) + VALUES + ('testbottleneck2', + ('AT', 'XXX', '00001', '00000', 1)::isrs, + isrsrange(('AT', 'XXX', '00001', '00000', 0)::isrs, + ('AT', 'XXX', '00001', '00000', 2)::isrs), + ST_geomfromtext('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))', 4326), + 'AT', 'AT', 'AT', + 1, 'depth', 'testorganization', true); + +-- +-- Run tests as unprivileged user +SET SESSION AUTHORIZATION waterway_user; + +SELECT throws_ok('CREATE TABLE test()', 42501, NULL, + 'No objects can be created'); + +SELECT is_empty('SELECT * FROM bottlenecks WHERE NOT staging_done', + 'Only staged data should be visible'); +SELECT isnt_empty('SELECT * FROM bottlenecks', + 'Only staged data should be visible'); + +SELECT set_eq('SELECT count(*) FROM wamos.user_profiles', ARRAY[1], + 'User should only see his own profile'); +SELECT results_eq('SELECT username FROM user_profiles', + 'SELECT CAST(current_user AS varchar)', + 'User should only see his own profile'); + +-- +-- finish tests +-- +SELECT * FROM finish(); + +ROLLBACK;