comparison tap_tests.sql @ 104:bc1c7fa3a939

Add tests for authorisation of templates.
author Tom Gottfried <tom@intevation.de>
date Fri, 15 Jun 2018 18:15:04 +0200
parents 7f934f77831a
children ae5bb7a979ff
comparison
equal deleted inserted replaced
103:b29538ac409d 104:bc1c7fa3a939
3 -- 3 --
4 BEGIN; 4 BEGIN;
5 5
6 CREATE EXTENSION pgtap; 6 CREATE EXTENSION pgtap;
7 7
8 SELECT plan(5); -- Give number of tests that have to be run 8 SELECT plan(7); -- Give number of tests that have to be run
9 9
10 SET search_path TO public, wamos, wamos_waterway, wamos_fairway; 10 SET search_path TO public, wamos, wamos_waterway, wamos_fairway;
11 11
12 -- 12 --
13 -- Add test data 13 -- Add test data
51 ('AT', 'XXX', '00001', '00000', 2)::isrs), 51 ('AT', 'XXX', '00001', '00000', 2)::isrs),
52 ST_geomfromtext('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))', 4326), 52 ST_geomfromtext('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))', 4326),
53 'AT', 'AT', 'AT', 53 'AT', 'AT', 'AT',
54 1, 'depth', 'testorganization', true); 54 1, 'depth', 'testorganization', true);
55 55
56 INSERT INTO templates (dummy_attrib)
57 VALUES ('usertemplate'), ('othertemplate');
58 INSERT INTO user_templates
59 SELECT 'waterway_user', id FROM templates
60 WHERE dummy_attrib = 'usertemplate';
61
56 -- 62 --
57 -- Run tests as unprivileged user 63 -- Run tests as unprivileged user
64 --
58 SET SESSION AUTHORIZATION waterway_user; 65 SET SESSION AUTHORIZATION waterway_user;
59 66
60 SELECT throws_ok('CREATE TABLE test()', 42501, NULL, 67 SELECT throws_ok('CREATE TABLE test()', 42501, NULL,
61 'No objects can be created'); 68 'No objects can be created');
62 69
70 SELECT isnt_empty('SELECT * FROM bottlenecks',
71 'Staged data should be visible');
63 SELECT is_empty('SELECT * FROM bottlenecks WHERE NOT staging_done', 72 SELECT is_empty('SELECT * FROM bottlenecks WHERE NOT staging_done',
64 'Only staged data should be visible'); 73 'Only staged data should be visible');
65 SELECT isnt_empty('SELECT * FROM bottlenecks',
66 'Only staged data should be visible');
67 74
68 SELECT set_eq('SELECT count(*) FROM wamos.user_profiles', ARRAY[1], 75 SELECT set_eq('SELECT count(*) FROM wamos.user_profiles', ARRAY[1],
69 'User should only see his own profile'); 76 'User should only see his own profile');
70 SELECT results_eq('SELECT username FROM user_profiles', 77 SELECT results_eq('SELECT username FROM user_profiles',
71 'SELECT CAST(current_user AS varchar)', 78 'SELECT CAST(current_user AS varchar)',
72 'User should only see his own profile'); 79 'User should only see his own profile');
73 80
81 SELECT isnt_empty('SELECT * FROM templates',
82 'User should see templates associated to him');
83 SELECT is_empty('SELECT * FROM templates t
84 JOIN user_templates ut ON t.id = template_id
85 WHERE username <> current_user',
86 'User should only see templates associated to him');
87
74 -- 88 --
75 -- finish tests 89 -- finish tests
76 -- 90 --
77 SELECT * FROM finish(); 91 SELECT * FROM finish();
78 92