comparison tap_tests.sql @ 100:7f934f77831a

Add first tests of RLS policies.
author Tom Gottfried <tom@intevation.de>
date Wed, 13 Jun 2018 22:46:40 +0200
parents
children bc1c7fa3a939
comparison
equal deleted inserted replaced
99:3ad1c35b258f 100:7f934f77831a
1 --
2 -- pgTAP test script
3 --
4 BEGIN;
5
6 CREATE EXTENSION pgtap;
7
8 SELECT plan(5); -- Give number of tests that have to be run
9
10 SET search_path TO public, wamos, wamos_waterway, wamos_fairway;
11
12 --
13 -- Add test data
14 --
15 INSERT INTO countries VALUES ('AT');
16
17 INSERT INTO user_profiles (username, country, email_adress)
18 VALUES
19 ('waterway_user', 'AT', 'xxx'),
20 ('waterway_admin', 'AT', 'yyy'),
21 ('sys_admin', 'AT', 'zzz');
22
23 INSERT INTO limiting_factors VALUES ('depth'), ('width');
24 INSERT INTO gauges (
25 location, function_code, objname, geom, zero_point, source_organization)
26 VALUES
27 (('AT', 'XXX', '00001', '00000', 1)::isrs,
28 'xxx',
29 'testgauge',
30 ST_geomfromtext('POINT(0 0)', 4326),
31 0,
32 'testorganization');
33 INSERT INTO bottlenecks (
34 bottleneck_id, fk_g_fid, stretch, area, rb, lb, responsible_country,
35 revisiting_time, limiting, source_organization)
36 VALUES
37 ('testbottleneck1',
38 ('AT', 'XXX', '00001', '00000', 1)::isrs,
39 isrsrange(('AT', 'XXX', '00001', '00000', 0)::isrs,
40 ('AT', 'XXX', '00001', '00000', 2)::isrs),
41 ST_geomfromtext('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))', 4326),
42 'AT', 'AT', 'AT',
43 1, 'depth', 'testorganization');
44 INSERT INTO bottlenecks (
45 bottleneck_id, fk_g_fid, stretch, area, rb, lb, responsible_country,
46 revisiting_time, limiting, source_organization, staging_done)
47 VALUES
48 ('testbottleneck2',
49 ('AT', 'XXX', '00001', '00000', 1)::isrs,
50 isrsrange(('AT', 'XXX', '00001', '00000', 0)::isrs,
51 ('AT', 'XXX', '00001', '00000', 2)::isrs),
52 ST_geomfromtext('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))', 4326),
53 'AT', 'AT', 'AT',
54 1, 'depth', 'testorganization', true);
55
56 --
57 -- Run tests as unprivileged user
58 SET SESSION AUTHORIZATION waterway_user;
59
60 SELECT throws_ok('CREATE TABLE test()', 42501, NULL,
61 'No objects can be created');
62
63 SELECT is_empty('SELECT * FROM bottlenecks WHERE NOT staging_done',
64 'Only staged data should be visible');
65 SELECT isnt_empty('SELECT * FROM bottlenecks',
66 'Only staged data should be visible');
67
68 SELECT set_eq('SELECT count(*) FROM wamos.user_profiles', ARRAY[1],
69 'User should only see his own profile');
70 SELECT results_eq('SELECT username FROM user_profiles',
71 'SELECT CAST(current_user AS varchar)',
72 'User should only see his own profile');
73
74 --
75 -- finish tests
76 --
77 SELECT * FROM finish();
78
79 ROLLBACK;