Mercurial > gemma
comparison schema/auth_tests.sql @ 1904:931b15be6d7f
Complement authorisation tests for import management
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 18 Jan 2019 17:01:19 +0100 |
parents | 9f8f7d3fd655 |
children | f9f1babe52ae |
comparison
equal
deleted
inserted
replaced
1902:c4af342be999 | 1904:931b15be6d7f |
---|---|
134 INSERT INTO waterway.track_imports | 134 INSERT INTO waterway.track_imports |
135 SELECT id, 'waterway.bottlenecks', 0 FROM job | 135 SELECT id, 'waterway.bottlenecks', 0 FROM job |
136 $$, | 136 $$, |
137 'Waterway admin can add import job and related data'); | 137 'Waterway admin can add import job and related data'); |
138 | 138 |
139 SET SESSION AUTHORIZATION test_admin_at2; | |
140 SELECT bag_has($$ | |
141 SELECT username FROM users.list_users | |
142 $$, | |
143 $$ | |
144 WITH job AS ( | |
145 UPDATE waterway.imports SET state = 'accepted' | |
146 RETURNING id, username), | |
147 log AS ( | |
148 INSERT INTO waterway.import_logs (import_id, msg) | |
149 SELECT id, 'test continued' FROM job) | |
150 SELECT username FROM job | |
151 $$, | |
152 'Waterway admin can edit import jobs from his country only'); | |
153 | |
139 SELECT lives_ok($$ | 154 SELECT lives_ok($$ |
140 WITH | 155 WITH |
141 config AS ( | 156 config AS ( |
142 INSERT INTO waterway.import_configuration (kind, username) VALUES ( | 157 INSERT INTO waterway.import_configuration (kind, username) VALUES ( |
143 'test', current_user) RETURNING id) | 158 'test', current_user) RETURNING id) |
144 INSERT INTO waterway.import_configuration_attributes | 159 INSERT INTO waterway.import_configuration_attributes |
145 SELECT id, 'test key', 'test value' FROM config | 160 SELECT id, 'test key', 'test value' FROM config |
146 $$, | 161 $$, |
147 'Waterway admin can add import config and related data'); | 162 'Waterway admin can add import config and related data'); |
148 | 163 |
164 SET SESSION AUTHORIZATION test_admin_at; | |
165 SELECT bag_has($$ | |
166 SELECT username FROM users.list_users | |
167 $$, | |
168 $$ | |
169 WITH config AS ( | |
170 UPDATE waterway.import_configuration SET send_email = true | |
171 RETURNING id, username), | |
172 attrib AS ( | |
173 INSERT INTO waterway.import_configuration_attributes | |
174 SELECT id, 'test continued', 'test value' FROM config), | |
175 attrib_upd AS ( | |
176 UPDATE waterway.import_configuration_attributes SET v = 'test v' | |
177 WHERE import_configuration_id = (SELECT id FROM config)) | |
178 SELECT username FROM config | |
179 $$, | |
180 'Waterway admin can edit import config from his country only'); | |
181 | |
149 SET SESSION AUTHORIZATION test_admin_ro; | 182 SET SESSION AUTHORIZATION test_admin_ro; |
150 | |
151 SELECT throws_ok($$ | 183 SELECT throws_ok($$ |
152 INSERT INTO waterway.import_logs (import_id, msg) | 184 INSERT INTO waterway.import_logs (import_id, msg) |
153 VALUES (1, 'test') | 185 VALUES (currval(pg_get_serial_sequence('waterway.imports', 'id')), |
186 'test') | |
154 $$, | 187 $$, |
155 42501, NULL, | 188 42501, NULL, |
156 'Waterway admin cannot add log messages to other countries imports'); | 189 'Waterway admin cannot add log messages to other countries imports'); |
190 | |
191 SELECT throws_ok($$ | |
192 DELETE FROM waterway.track_imports | |
193 WHERE import_id = currval( | |
194 pg_get_serial_sequence('waterway.imports', 'id')) | |
195 $$, | |
196 42501, NULL, | |
197 'Waterway admin cannot delete tracking data of other countries imports'); | |
198 | |
199 SELECT throws_ok($$ | |
200 INSERT INTO waterway.import_configuration_attributes | |
201 VALUES (currval(pg_get_serial_sequence( | |
202 'waterway.import_configuration', 'id')), | |
203 'test', 'test value') | |
204 $$, | |
205 42501, NULL, | |
206 'Waterway admin cannot add attributes to other countries import config'); | |
207 | |
208 SELECT throws_ok($$ | |
209 UPDATE waterway.import_configuration_attributes SET v = 'evil' | |
210 WHERE import_configuration_id = currval( | |
211 pg_get_serial_sequence('waterway.import_configuration', 'id')) | |
212 $$, | |
213 42501, NULL, | |
214 'Waterway admin cannot overwrite attributes of other countries config'); |