Debian Codegraph @

tests/src/testModels.js

raw
1 /* testModels.js
2 *
3 * Copyright 2020 Martin Abente Lahaye
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 const {Gio, GLib} = imports.gi;
20
21 const {
22 setup,
23 update,
24 has,
25 hasOnly,
26 hasInTotal,
27 startService,
28 waitForService,
29 stopService,
30 partialService,
31 getValueFromService,
32 } = imports.utils;
33
34 setup();
35
36 const _totalPermissions = 41;
37
38 const _basicAppId = 'com.test.Basic';
39 const _basicNegatedAppId = 'com.test.BasicNegated';
40 const _oldAppId = 'com.test.Old';
41 const _reduceAppId = 'com.test.Reduce';
42 const _increaseAppId = 'com.test.Increase';
43 const _baseAppId = 'com.test.BaseApp';
44 const _negationAppId = 'com.test.Negation';
45 const _unsupportedAppId = 'com.test.Unsupported';
46 const _overridenAppId = 'com.test.Overriden';
47 const _extraAppId = 'com.test.Extra';
48 const _environmentAppId = 'com.test.Environment';
49 const _busAppId = 'com.test.Bus';
50 const _variablesAppId = 'com.test.Variables';
51 const _trailingSemicolonId = 'com.test.TrailingSemicolon';
52 const _filesystemWithMode = 'com.test.FilesystemWithMode';
53 const _resetModeId = 'com.test.ResetMode';
54 const _globalAppId = 'com.test.Global';
55 const _globalRestoredAppId = 'com.test.GlobalRestored';
56 const _statusesAppId = 'com.test.Statuses';
57 const _malformedAppId = 'com.test.Malformed';
58
59 const _flatpakInfo = GLib.build_filenamev(['..', 'tests', 'content', '.flatpak-info']);
60 const _flatpakInfoOld = GLib.build_filenamev(['..', 'tests', 'content', '.flatpak-info.old']);
61 const _flatpakInfoNew = GLib.build_filenamev(['..', 'tests', 'content', '.flatpak-info.new']);
62
63 const _system = GLib.build_filenamev(['..', 'tests', 'content', 'system', 'flatpak']);
64 const _user = GLib.build_filenamev(['..', 'tests', 'content', 'user', 'flatpak']);
65 const _global = GLib.build_filenamev(['..', 'tests', 'content', 'global', 'flatpak']);
66 const _globalNegated = GLib.build_filenamev(['..', 'tests', 'content', 'globalNegated', 'flatpak']);
67 const _globalResetMode = GLib.build_filenamev(['..', 'tests', 'content', 'globalResetMode', 'flatpak']);
68 const _statuses = GLib.build_filenamev(['..', 'tests', 'content', 'statuses', 'flatpak']);
69 const _tmp = GLib.build_filenamev([GLib.DIR_SEPARATOR_S, 'tmp']);
70 const _none = GLib.build_filenamev([GLib.DIR_SEPARATOR_S, 'dev', 'null']);
71 const _overrides = GLib.build_filenamev([_tmp, 'overrides']);
72 const _globalOverride = GLib.build_filenamev([_overrides, 'global']);
73 const _globalNegatedOverride = GLib.build_filenamev([_globalNegated, 'overrides', 'global']);
74 const _globalResetModeOverride = GLib.build_filenamev([_globalResetMode, 'overrides', 'global']);
75 const _basicOverride = GLib.build_filenamev([_overrides, _basicAppId]);
76 const _reduceOverride = GLib.build_filenamev([_overrides, _reduceAppId]);
77 const _increaseOverride = GLib.build_filenamev([_overrides, _increaseAppId]);
78 const _negationOverride = GLib.build_filenamev([_overrides, _negationAppId]);
79 const _unsupportedOverride = GLib.build_filenamev([_overrides, _unsupportedAppId]);
80 const _overridenOverride = GLib.build_filenamev([_overrides, _overridenAppId]);
81 const _environmentOverride = GLib.build_filenamev([_overrides, _environmentAppId]);
82 const _busOverride = GLib.build_filenamev([_overrides, _busAppId]);
83 const _filesystemWithModeOverride = GLib.build_filenamev([_overrides, _filesystemWithMode]);
84 const _resetModeOverride = GLib.build_filenamev([_overrides, _resetModeId]);
85 const _globalWithGlobalOverride = GLib.build_filenamev([_global, 'overrides', _globalAppId]);
86
87 const _sessionGroup = 'Session Bus Policy';
88 const _key = 'filesystems';
89
90 const _flatpakConfig = GLib.build_filenamev(['..', 'tests', 'content']);
91
92
93 describe('Model', function() {
94 var delay, permissionsDefault, applicationsDefault, infoDefault, portalsDefault, portalState;
95
96 beforeAll(function() {
97 startService();
98 waitForService();
99
100 const {applications, info, permissions, portals} = imports.models;
101
102 infoDefault = info.getDefault();
103 portalsDefault = portals.getDefault();
104 applicationsDefault = applications.getDefault();
105 permissionsDefault = permissions.getDefault();
106
107 delay = permissions.DELAY;
108 portalState = portals.FlatpakPortalState;
109
110 GLib.unlink(_overridenOverride);
111 GLib.mkdir_with_parents(_overrides, 0o755);
112 });
113
114 afterAll(function() {
115 stopService();
116 });
117
118 beforeEach(function() {
119 GLib.setenv('FLATPAK_SYSTEM_DIR', _system, true);
120 GLib.setenv('FLATPAK_USER_DIR', _none, true);
121 GLib.setenv('FLATPAK_INFO_PATH', _flatpakInfo, true);
122
123 infoDefault.reload();
124 portalsDefault.reload();
125 applicationsDefault.reload();
126 permissionsDefault.reload();
127
128 GLib.unlink(_basicOverride);
129 GLib.unlink(_reduceOverride);
130 GLib.unlink(_increaseOverride);
131 GLib.unlink(_negationOverride);
132 GLib.unlink(_unsupportedOverride);
133 GLib.unlink(_environmentOverride);
134 GLib.unlink(_busOverride);
135 GLib.unlink(_filesystemWithModeOverride);
136 GLib.unlink(_resetModeOverride);
137 GLib.unlink(_globalWithGlobalOverride);
138 GLib.unlink(_globalOverride);
139 });
140
141 it('loads applications', function() {
142 const appIds = applicationsDefault.getAll().map(a => a.appId);
143
144 expect(appIds).toContain(_basicAppId);
145 expect(appIds).toContain(_basicNegatedAppId);
146 expect(appIds).toContain(_oldAppId);
147 expect(appIds).toContain(_reduceAppId);
148 expect(appIds).toContain(_increaseAppId);
149 expect(appIds).toContain(_negationAppId);
150 expect(appIds).toContain(_unsupportedAppId);
151 expect(appIds).toContain(_trailingSemicolonId);
152 expect(appIds).toContain(_filesystemWithMode);
153 expect(appIds).toContain(_resetModeId);
154 });
155
156 it('ignores BaseApp bundles', function() {
157 const path = GLib.build_filenamev([
158 _system, 'app', _baseAppId, 'current', 'active', 'metadata',
159 ]);
160
161 expect(GLib.access(path, 0)).toEqual(0);
162
163 const appIds = applicationsDefault.getAll().map(a => a.appId);
164 expect(appIds).not.toContain(_baseAppId);
165 });
166
167 it('loads permissions', function() {
168 permissionsDefault.appId = _basicAppId;
169
170 expect(permissionsDefault.shared_network).toBe(true);
171 expect(permissionsDefault.shared_ipc).toBe(true);
172 expect(permissionsDefault.sockets_x11).toBe(true);
173 expect(permissionsDefault.sockets_fallback_x11).toBe(true);
174 expect(permissionsDefault.sockets_wayland).toBe(true);
175 expect(permissionsDefault.sockets_pulseaudio).toBe(true);
176 expect(permissionsDefault.sockets_system_bus).toBe(true);
177 expect(permissionsDefault.sockets_session_bus).toBe(true);
178 expect(permissionsDefault.sockets_ssh_auth).toBe(true);
179 expect(permissionsDefault.sockets_pcsc).toBe(true);
180 expect(permissionsDefault.sockets_cups).toBe(true);
181 expect(permissionsDefault.sockets_gpg_agent).toBe(true);
182 expect(permissionsDefault.sockets_inherit_wayland_socket).toBe(true);
183 expect(permissionsDefault.devices_dri).toBe(true);
184 expect(permissionsDefault.devices_input).toBe(true);
185 expect(permissionsDefault.devices_kvm).toBe(true);
186 expect(permissionsDefault.devices_shm).toBe(true);
187 expect(permissionsDefault.devices_usb).toBe(true);
188 expect(permissionsDefault.devices_all).toBe(true);
189 expect(permissionsDefault.features_bluetooth).toBe(true);
190 expect(permissionsDefault.features_devel).toBe(true);
191 expect(permissionsDefault.features_multiarch).toBe(true);
192 expect(permissionsDefault.features_canbus).toBe(true);
193 expect(permissionsDefault.features_per_app_dev_shm).toBe(true);
194 expect(permissionsDefault.filesystems_host).toBe(true);
195 expect(permissionsDefault.filesystems_host_os).toBe(true);
196 expect(permissionsDefault.filesystems_host_etc).toBe(true);
197 expect(permissionsDefault.filesystems_home).toBe(true);
198 expect(permissionsDefault.filesystems_other).toEqual('~/test');
199 expect(permissionsDefault.session_talk).toEqual('org.test.Service-1');
200 expect(permissionsDefault.session_own).toEqual('org.test.Service-2');
201 expect(permissionsDefault.system_talk).toEqual('org.test.Service-3');
202 expect(permissionsDefault.system_own).toEqual('org.test.Service-4');
203 expect(permissionsDefault.persistent).toEqual('.test');
204 expect(permissionsDefault.variables).toEqual('TEST=yes');
205 });
206
207 it('loads overrides', function() {
208 GLib.setenv('FLATPAK_USER_DIR', _user, true);
209 permissionsDefault.appId = _basicAppId;
210
211 expect(permissionsDefault.shared_network).toBe(false);
212 expect(permissionsDefault.shared_ipc).toBe(false);
213 expect(permissionsDefault.sockets_x11).toBe(false);
214 expect(permissionsDefault.sockets_fallback_x11).toBe(false);
215 expect(permissionsDefault.sockets_wayland).toBe(false);
216 expect(permissionsDefault.sockets_pulseaudio).toBe(false);
217 expect(permissionsDefault.sockets_system_bus).toBe(false);
218 expect(permissionsDefault.sockets_session_bus).toBe(false);
219 expect(permissionsDefault.sockets_ssh_auth).toBe(false);
220 expect(permissionsDefault.sockets_pcsc).toBe(false);
221 expect(permissionsDefault.sockets_cups).toBe(false);
222 expect(permissionsDefault.sockets_gpg_agent).toBe(false);
223 expect(permissionsDefault.sockets_inherit_wayland_socket).toBe(false);
224 expect(permissionsDefault.devices_dri).toBe(false);
225 expect(permissionsDefault.devices_input).toBe(false);
226 expect(permissionsDefault.devices_kvm).toBe(false);
227 expect(permissionsDefault.devices_shm).toBe(false);
228 expect(permissionsDefault.devices_usb).toBe(false);
229 expect(permissionsDefault.devices_all).toBe(false);
230 expect(permissionsDefault.features_bluetooth).toBe(false);
231 expect(permissionsDefault.features_devel).toBe(false);
232 expect(permissionsDefault.features_multiarch).toBe(false);
233 expect(permissionsDefault.features_canbus).toBe(false);
234 expect(permissionsDefault.features_per_app_dev_shm).toBe(false);
235 expect(permissionsDefault.filesystems_host).toBe(false);
236 expect(permissionsDefault.filesystems_host_os).toBe(false);
237 expect(permissionsDefault.filesystems_host_etc).toBe(false);
238 expect(permissionsDefault.filesystems_home).toBe(false);
239 expect(permissionsDefault.session_talk).toEqual('');
240 expect(permissionsDefault.session_own).toEqual('');
241 expect(permissionsDefault.system_talk).toEqual('');
242 expect(permissionsDefault.system_own).toEqual('');
243 expect(permissionsDefault.persistent).toEqual('.test;tset.');
244 expect(permissionsDefault.variables).toEqual('TEST=no');
245 });
246
247 it('loads negated permissions', function() {
248 permissionsDefault.appId = _basicNegatedAppId;
249
250 expect(permissionsDefault.shared_network).toBe(false);
251 expect(permissionsDefault.shared_ipc).toBe(false);
252 expect(permissionsDefault.sockets_x11).toBe(false);
253 expect(permissionsDefault.sockets_fallback_x11).toBe(false);
254 expect(permissionsDefault.sockets_wayland).toBe(false);
255 expect(permissionsDefault.sockets_pulseaudio).toBe(false);
256 expect(permissionsDefault.sockets_system_bus).toBe(false);
257 expect(permissionsDefault.sockets_session_bus).toBe(false);
258 expect(permissionsDefault.sockets_ssh_auth).toBe(false);
259 expect(permissionsDefault.sockets_pcsc).toBe(false);
260 expect(permissionsDefault.sockets_cups).toBe(false);
261 expect(permissionsDefault.sockets_gpg_agent).toBe(false);
262 expect(permissionsDefault.sockets_inherit_wayland_socket).toBe(false);
263 expect(permissionsDefault.devices_dri).toBe(false);
264 expect(permissionsDefault.devices_input).toBe(false);
265 expect(permissionsDefault.devices_kvm).toBe(false);
266 expect(permissionsDefault.devices_shm).toBe(false);
267 expect(permissionsDefault.devices_usb).toBe(false);
268 expect(permissionsDefault.devices_all).toBe(false);
269 expect(permissionsDefault.features_bluetooth).toBe(false);
270 expect(permissionsDefault.features_devel).toBe(false);
271 expect(permissionsDefault.features_multiarch).toBe(false);
272 expect(permissionsDefault.features_canbus).toBe(false);
273 expect(permissionsDefault.features_per_app_dev_shm).toBe(false);
274 expect(permissionsDefault.filesystems_host).toBe(false);
275 expect(permissionsDefault.filesystems_host_os).toBe(false);
276 expect(permissionsDefault.filesystems_host_etc).toBe(false);
277 expect(permissionsDefault.filesystems_home).toBe(false);
278 expect(permissionsDefault.filesystems_other).toEqual('!~/test');
279 expect(permissionsDefault.session_talk).toEqual('');
280 expect(permissionsDefault.session_own).toEqual('');
281 expect(permissionsDefault.system_talk).toEqual('');
282 expect(permissionsDefault.system_own).toEqual('');
283 expect(permissionsDefault.persistent).toEqual('tset.');
284 expect(permissionsDefault.variables).toEqual('TEST=no');
285 });
286
287 it('loads negated overrides', function() {
288 GLib.setenv('FLATPAK_USER_DIR', _user, true);
289 permissionsDefault.appId = _basicNegatedAppId;
290
291 expect(permissionsDefault.shared_network).toBe(true);
292 expect(permissionsDefault.shared_ipc).toBe(true);
293 expect(permissionsDefault.sockets_x11).toBe(true);
294 expect(permissionsDefault.sockets_fallback_x11).toBe(true);
295 expect(permissionsDefault.sockets_wayland).toBe(true);
296 expect(permissionsDefault.sockets_pulseaudio).toBe(true);
297 expect(permissionsDefault.sockets_system_bus).toBe(true);
298 expect(permissionsDefault.sockets_session_bus).toBe(true);
299 expect(permissionsDefault.sockets_ssh_auth).toBe(true);
300 expect(permissionsDefault.sockets_pcsc).toBe(true);
301 expect(permissionsDefault.sockets_cups).toBe(true);
302 expect(permissionsDefault.sockets_gpg_agent).toBe(true);
303 expect(permissionsDefault.sockets_inherit_wayland_socket).toBe(true);
304 expect(permissionsDefault.devices_dri).toBe(true);
305 expect(permissionsDefault.devices_input).toBe(true);
306 expect(permissionsDefault.devices_kvm).toBe(true);
307 expect(permissionsDefault.devices_shm).toBe(true);
308 expect(permissionsDefault.devices_usb).toBe(true);
309 expect(permissionsDefault.devices_all).toBe(true);
310 expect(permissionsDefault.features_bluetooth).toBe(true);
311 expect(permissionsDefault.features_devel).toBe(true);
312 expect(permissionsDefault.features_multiarch).toBe(true);
313 expect(permissionsDefault.features_canbus).toBe(true);
314 expect(permissionsDefault.features_per_app_dev_shm).toBe(true);
315 expect(permissionsDefault.filesystems_host).toBe(true);
316 expect(permissionsDefault.filesystems_host_os).toBe(true);
317 expect(permissionsDefault.filesystems_host_etc).toBe(true);
318 expect(permissionsDefault.filesystems_home).toBe(true);
319 expect(permissionsDefault.filesystems_other).toEqual('');
320 expect(permissionsDefault.session_talk).toEqual('org.test.Service-1');
321 expect(permissionsDefault.session_own).toEqual('org.test.Service-2');
322 expect(permissionsDefault.system_talk).toEqual('org.test.Service-3');
323 expect(permissionsDefault.system_own).toEqual('org.test.Service-4');
324 expect(permissionsDefault.persistent).toEqual('tset.;.test');
325 expect(permissionsDefault.variables).toEqual('TEST=yes');
326 });
327
328 it('creates overrides when properties changed', function(done) {
329 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
330 permissionsDefault.appId = _overridenAppId;
331
332 permissionsDefault.set_property('shared-network', false);
333 permissionsDefault.set_property('sockets_x11', false);
334 permissionsDefault.set_property('devices_dri', false);
335 permissionsDefault.set_property('shared-network', false);
336 permissionsDefault.set_property('features-bluetooth', false);
337 permissionsDefault.set_property('filesystems-host', false);
338 permissionsDefault.set_property('filesystems-other', '~/tset');
339 permissionsDefault.set_property('session_talk', 'org.test.Service-3');
340 permissionsDefault.set_property('session_own', 'org.test.Service-4');
341 permissionsDefault.set_property('system_talk', 'org.test.Service-5');
342 permissionsDefault.set_property('system_own', 'org.test.Service-6');
343 permissionsDefault.set_property('persistent', 'tset.');
344 permissionsDefault.set_property('variables', 'TEST=maybe');
345
346
347 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
348 expect(GLib.access(_overridenOverride, 0)).toEqual(0);
349 done();
350 return GLib.SOURCE_REMOVE;
351 });
352
353 update();
354 });
355
356 it('reloads previous overrides later on', function() {
357 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
358 permissionsDefault.appId = _overridenAppId;
359
360 expect(permissionsDefault.shared_network).toBe(false);
361 expect(permissionsDefault.shared_ipc).toBe(true);
362 expect(permissionsDefault.sockets_x11).toBe(false);
363 expect(permissionsDefault.sockets_fallback_x11).toBe(true);
364 expect(permissionsDefault.sockets_wayland).toBe(true);
365 expect(permissionsDefault.sockets_pulseaudio).toBe(true);
366 expect(permissionsDefault.sockets_system_bus).toBe(true);
367 expect(permissionsDefault.sockets_session_bus).toBe(true);
368 expect(permissionsDefault.sockets_ssh_auth).toBe(true);
369 expect(permissionsDefault.sockets_cups).toBe(true);
370 expect(permissionsDefault.sockets_gpg_agent).toBe(true);
371 expect(permissionsDefault.sockets_inherit_wayland_socket).toBe(true);
372 expect(permissionsDefault.devices_dri).toBe(false);
373 expect(permissionsDefault.devices_all).toBe(true);
374 expect(permissionsDefault.features_bluetooth).toBe(false);
375 expect(permissionsDefault.features_devel).toBe(true);
376 expect(permissionsDefault.features_multiarch).toBe(true);
377 expect(permissionsDefault.filesystems_host).toBe(false);
378 expect(permissionsDefault.filesystems_host_os).toBe(false);
379 expect(permissionsDefault.filesystems_host_etc).toBe(false);
380 expect(permissionsDefault.filesystems_home).toBe(true);
381 expect(permissionsDefault.filesystems_other).toEqual('~/tset');
382 expect(permissionsDefault.session_talk).toEqual('org.test.Service-3');
383 expect(permissionsDefault.session_own).toEqual('org.test.Service-4');
384 expect(permissionsDefault.system_talk).toEqual('org.test.Service-5');
385 expect(permissionsDefault.system_own).toEqual('org.test.Service-6');
386 expect(permissionsDefault.persistent).toEqual('tset.');
387 expect(permissionsDefault.variables).toEqual('TEST=maybe');
388 });
389
390 it('resets overrides', function() {
391 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
392 permissionsDefault.appId = _overridenAppId;
393
394 permissionsDefault.reset();
395
396 expect(GLib.access(_overridenOverride, 0)).toEqual(-1);
397 });
398
399 it('creates overrides when properties values changed', function(done) {
400 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
401 permissionsDefault.appId = _overridenAppId;
402
403 permissionsDefault.set_property('shared-network', false);
404
405 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
406 expect(GLib.access(_overridenOverride, 0)).toEqual(0);
407 done();
408 return GLib.SOURCE_REMOVE;
409 });
410
411 update();
412 });
413
414 it('removes overrides when properties values restore', function(done) {
415 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
416 permissionsDefault.appId = _overridenAppId;
417
418 permissionsDefault.set_property('shared-network', true);
419
420 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
421 expect(GLib.access(_overridenOverride, 0)).toEqual(-1);
422 done();
423 return GLib.SOURCE_REMOVE;
424 });
425
426 update();
427 });
428
429 it('loads old filesystems overrides', function() {
430 GLib.setenv('FLATPAK_USER_DIR', _user, true);
431 permissionsDefault.appId = _oldAppId;
432
433 expect(permissionsDefault.filesystems_other).toEqual('xdg-pictures:ro');
434 });
435
436 it('reduces filesystems permission', function(done) {
437 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
438 permissionsDefault.appId = _reduceAppId;
439
440 expect(permissionsDefault.filesystems_other).toEqual('xdg-downloads');
441
442 permissionsDefault.set_property('filesystems-other', 'xdg-downloads:ro');
443
444 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
445 const group = permissionsDefault.constructor.getGroupForProperty('filesystems-other');
446 expect(hasOnly(_reduceOverride, group, _key, 'xdg-downloads:ro')).toBe(true);
447 done();
448 return GLib.SOURCE_REMOVE;
449 });
450
451 update();
452 });
453
454 it('increases filesystems permission', function(done) {
455 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
456 permissionsDefault.appId = _increaseAppId;
457
458 expect(permissionsDefault.filesystems_other).toEqual('xdg-pictures:ro');
459
460 permissionsDefault.set_property('filesystems-other', 'xdg-pictures:rw');
461
462 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
463 const group = permissionsDefault.constructor.getGroupForProperty('filesystems-other');
464 expect(hasOnly(_increaseOverride, group, _key, 'xdg-pictures:rw')).toBe(true);
465 done();
466 return GLib.SOURCE_REMOVE;
467 });
468
469 update();
470 });
471
472 it('increases filesystems permission (default)', function(done) {
473 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
474 permissionsDefault.appId = _increaseAppId;
475
476 expect(permissionsDefault.filesystems_other).toEqual('xdg-pictures:ro');
477
478 permissionsDefault.set_property('filesystems-other', 'xdg-pictures');
479
480 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
481 const group = permissionsDefault.constructor.getGroupForProperty('filesystems-other');
482 expect(hasOnly(_increaseOverride, group, _key, 'xdg-pictures')).toBe(true);
483 done();
484 return GLib.SOURCE_REMOVE;
485 });
486
487 update();
488 });
489
490 it('handles negated filesystems permission', function(done) {
491 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
492 permissionsDefault.appId = _negationAppId;
493
494 expect(permissionsDefault.filesystems_other).toEqual('!~/negative;~/positive');
495
496 permissionsDefault.set_property('filesystems-other', '!~/negative');
497
498 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
499 const group = permissionsDefault.constructor.getGroupForProperty('filesystems-other');
500 expect(hasOnly(_negationOverride, group, _key, '!~/positive')).toBe(true);
501 done();
502 return GLib.SOURCE_REMOVE;
503 });
504
505 update();
506 });
507
508 it('handles removing negated filesystems permission', function(done) {
509 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
510 permissionsDefault.appId = _negationAppId;
511
512 expect(permissionsDefault.filesystems_other).toEqual('!~/negative;~/positive');
513
514 permissionsDefault.set_property('filesystems-other', '~/positive');
515
516 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
517 const group = permissionsDefault.constructor.getGroupForProperty('filesystems-other');
518 expect(hasOnly(_negationOverride, group, _key, '~/negative')).toBe(true);
519 done();
520 return GLib.SOURCE_REMOVE;
521 });
522
523 update();
524 });
525
526 it('handles adding negated filesystems override (manually)', function(done) {
527 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
528 permissionsDefault.appId = _negationAppId;
529
530 expect(permissionsDefault.filesystems_other).toEqual('!~/negative;~/positive');
531
532 permissionsDefault.set_property('filesystems-other', '!~/negative;!~/positive');
533
534 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
535 const group = permissionsDefault.constructor.getGroupForProperty('filesystems-other');
536 expect(hasOnly(_negationOverride, group, _key, '!~/positive')).toBe(true);
537 done();
538 return GLib.SOURCE_REMOVE;
539 });
540
541 update();
542 });
543
544 it('handles removing negated filesystems override (manually)', function(done) {
545 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
546 permissionsDefault.appId = _negationAppId;
547
548 expect(permissionsDefault.filesystems_other).toEqual('!~/negative;~/positive');
549
550 permissionsDefault.set_property('filesystems-other', '~/negative;~/positive');
551
552 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
553 const group = permissionsDefault.constructor.getGroupForProperty('filesystems-other');
554 expect(hasOnly(_negationOverride, group, _key, '~/negative')).toBe(true);
555 done();
556 return GLib.SOURCE_REMOVE;
557 });
558
559 update();
560 });
561
562 it('ignores unsupported permissions', function(done) {
563 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
564 permissionsDefault.appId = _unsupportedAppId;
565
566 expect(permissionsDefault.filesystems_other).toEqual('~/unsupported');
567
568 permissionsDefault.set_property('filesystems-other', '');
569
570 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
571 const group = permissionsDefault.constructor.getGroupForProperty('filesystems-other');
572 expect(hasOnly(_unsupportedOverride, group, _key, '!~/unsupported')).toBe(true);
573 done();
574 return GLib.SOURCE_REMOVE;
575 });
576
577 update();
578 });
579
580 it('preserves unsupported permissions', function(done) {
581 GLib.setenv('FLATPAK_USER_DIR', _user, true);
582 permissionsDefault.appId = _unsupportedAppId;
583
584 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
585 permissionsDefault.set_property('filesystems-other', '');
586
587 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
588 expect(has(_unsupportedOverride, 'Context', 'unsupported', 'always')).toBe(true);
589 expect(has(_unsupportedOverride, 'Context', 'unsupported', 'undefined')).toBe(false);
590 expect(has(_unsupportedOverride, 'Context', 'unsupported', 'null')).toBe(false);
591
592 expect(has(_unsupportedOverride, 'Context', 'shared', 'unsupported')).toBe(true);
593 expect(has(_unsupportedOverride, 'Context', 'shared', 'undefined')).toBe(false);
594 expect(has(_unsupportedOverride, 'Context', 'shared', 'null')).toBe(false);
595
596 done();
597 return GLib.SOURCE_REMOVE;
598 });
599
600 update();
601 });
602
603 it('signals changes with overrides', function(done) {
604 spyOn(permissionsDefault, 'emit');
605
606 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
607 permissionsDefault.appId = _basicAppId;
608
609 permissionsDefault.set_property('shared-network', false);
610
611 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
612 expect(permissionsDefault.emit.calls.mostRecent().args).toEqual(['changed', true, false]);
613 done();
614 return GLib.SOURCE_REMOVE;
615 });
616
617 update();
618 });
619
620 it('signals changes with no overrides', function() {
621 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
622 permissionsDefault.appId = _basicAppId;
623
624 spyOn(permissionsDefault, 'emit');
625
626 permissionsDefault.reset();
627
628 expect(permissionsDefault.emit.calls.first().args).toEqual(['changed', false, false]);
629 expect(permissionsDefault.emit.calls.count()).toEqual(2); // including reset signal
630 });
631
632 it('signals changes with unsupported overrides', function() {
633 spyOn(permissionsDefault, 'emit');
634
635 GLib.setenv('FLATPAK_USER_DIR', _user, true);
636 permissionsDefault.appId = _unsupportedAppId;
637
638 expect(permissionsDefault.emit.calls.mostRecent().args).toEqual(['changed', true, true]);
639 });
640
641 it('signals changes without unsupported overrides', function() {
642 spyOn(permissionsDefault, 'emit');
643
644 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
645 permissionsDefault.appId = _unsupportedAppId;
646
647 expect(permissionsDefault.emit.calls.mostRecent().args).toEqual(['changed', false, false]);
648 });
649
650 it('saves pending updates before selecting other application', function(done) {
651 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
652 permissionsDefault.appId = _basicAppId;
653
654 expect(permissionsDefault.shared_network).toEqual(true);
655
656 permissionsDefault.set_property('shared-network', false);
657
658 permissionsDefault.appId = _unsupportedAppId;
659
660 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
661 expect(GLib.access(_basicOverride, 0)).toEqual(0);
662 expect(GLib.access(_unsupportedOverride, 0)).toEqual(-1);
663 done();
664 return GLib.SOURCE_REMOVE;
665 });
666
667 update();
668 });
669
670 it('saves pending updates before shutting down', function(done) {
671 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
672 permissionsDefault.appId = _basicAppId;
673
674 expect(permissionsDefault.shared_network).toEqual(true);
675
676 permissionsDefault.set_property('shared-network', false);
677
678 permissionsDefault.shutdown();
679
680 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
681 expect(GLib.access(_basicOverride, 0)).toEqual(0);
682 done();
683 return GLib.SOURCE_REMOVE;
684 });
685
686 update();
687 });
688
689 it('disables all permissions with old flatpak version', function() {
690 GLib.setenv('FLATPAK_INFO_PATH', _flatpakInfoOld, true);
691 infoDefault.reload();
692 portalsDefault.reload();
693 permissionsDefault.appId = _basicAppId;
694
695 const total = permissionsDefault.getAll().filter(p => p.supported).length;
696
697 expect(total).toEqual(0);
698 });
699
700 it('enables all permissions with new flatpak version', function() {
701 GLib.setenv('FLATPAK_INFO_PATH', _flatpakInfoNew, true);
702 infoDefault.reload();
703 portalsDefault.reload();
704 permissionsDefault.appId = _basicAppId;
705
706 const total = permissionsDefault.getAll().filter(p => p.supported).length;
707
708 expect(total).toEqual(_totalPermissions);
709 });
710
711 it('disables permissions with stable flatpak version', function() {
712 infoDefault.reload();
713 portalsDefault.reload();
714 permissionsDefault.appId = _basicAppId;
715
716 const total = permissionsDefault.getAll().filter(p => p.supported).length;
717
718 expect(total).toEqual(_totalPermissions - 11);
719 });
720
721 it('handles missing .flatpak-info', function() {
722 GLib.setenv('FLATPAK_INFO_PATH', _none, true);
723 infoDefault.reload();
724 portalsDefault.reload();
725 permissionsDefault.appId = _basicAppId;
726
727 const total = permissionsDefault.getAll().filter(p => p.supported).length;
728
729 expect(total).toEqual(_totalPermissions);
730 });
731
732 it('loads extra applications', function() {
733 GLib.setenv('FLATPAK_CONFIG_DIR', _flatpakConfig, true);
734 applicationsDefault.reload();
735
736 const appIds = applicationsDefault.getAll().map(a => a.appId);
737 expect(appIds).toContain(_extraAppId);
738 });
739
740 it('preserves installation priorities', function() {
741 GLib.setenv('FLATPAK_USER_DIR', _user, true);
742 GLib.setenv('FLATPAK_CONFIG_DIR', _flatpakConfig, true);
743 applicationsDefault.reload();
744
745 permissionsDefault.appId = _extraAppId;
746
747 expect(permissionsDefault.shared_network).toBe(false);
748 expect(permissionsDefault.shared_ipc).toBe(true);
749 });
750
751 it('add new environment variable', function(done) {
752 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
753 permissionsDefault.appId = _environmentAppId;
754
755 expect(permissionsDefault.variables).toEqual('TEST=yes');
756
757 permissionsDefault.set_property('variables', 'TEST=yes;TEST2=no');
758
759 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
760 expect(hasOnly(_environmentOverride, 'Environment', 'TEST2', 'no')).toBe(true);
761 done();
762 return GLib.SOURCE_REMOVE;
763 });
764
765 update();
766 });
767
768 it('override original environment variable', function(done) {
769 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
770 permissionsDefault.appId = _environmentAppId;
771
772 expect(permissionsDefault.variables).toEqual('TEST=yes');
773
774 permissionsDefault.set_property('variables', 'TEST=no');
775
776 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
777 expect(hasOnly(_environmentOverride, 'Environment', 'TEST', 'no')).toBe(true);
778 done();
779 return GLib.SOURCE_REMOVE;
780 });
781
782 update();
783 });
784
785 it('remove original environment variable', function(done) {
786 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
787 permissionsDefault.appId = _environmentAppId;
788
789 expect(permissionsDefault.variables).toEqual('TEST=yes');
790
791 permissionsDefault.set_property('variables', '');
792
793 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
794 expect(hasOnly(_environmentOverride, 'Environment', 'TEST', '')).toBe(true);
795 done();
796 return GLib.SOURCE_REMOVE;
797 });
798
799 update();
800 });
801
802 it('handles re-loading removed variables', function() {
803 GLib.setenv('FLATPAK_USER_DIR', _user, true);
804 permissionsDefault.appId = _variablesAppId;
805
806 expect(permissionsDefault.variables).toEqual('');
807 });
808
809 it('handles non-valid environment variable', function(done) {
810 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
811 permissionsDefault.appId = _environmentAppId;
812
813 expect(permissionsDefault.variables).toEqual('TEST=yes');
814
815 permissionsDefault.set_property('variables', 'TEST=yes;TE ST=no');
816
817 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
818 expect(GLib.access(_environmentOverride, 0)).toEqual(-1);
819 done();
820 return GLib.SOURCE_REMOVE;
821 });
822
823 update();
824 });
825
826 it('handles RUST debug export environment variables', function(done) {
827 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
828 permissionsDefault.appId = _environmentAppId;
829
830 expect(permissionsDefault.variables).toEqual('TEST=yes');
831
832 permissionsDefault.set_property('variables', 'TEST=yes=no');
833
834 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
835 expect(hasOnly(_environmentOverride, 'Environment', 'TEST', 'yes=no')).toBe(true);
836
837 permissionsDefault.appId = _environmentAppId;
838 expect(permissionsDefault.variables).toEqual('TEST=yes=no');
839
840 done();
841 return GLib.SOURCE_REMOVE;
842 });
843
844 update();
845 });
846
847
848 it('handles environment variables with semicolons', function(done) {
849 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
850 permissionsDefault.appId = _environmentAppId;
851
852 expect(permissionsDefault.variables).toEqual('TEST=yes');
853
854 permissionsDefault.set_property('variables', 'TEST=yes;no');
855
856 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
857 permissionsDefault.appId = _environmentAppId;
858 expect(permissionsDefault.variables).toEqual('TEST=yes;no');
859
860 done();
861 return GLib.SOURCE_REMOVE;
862 });
863
864 update();
865 });
866
867 it('Add new well-known names', function(done) {
868 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
869 permissionsDefault.appId = _busAppId;
870
871 expect(permissionsDefault.session_talk).toEqual('org.test.Service-1');
872 expect(permissionsDefault.session_own).toEqual('org.test.Service-2');
873
874 permissionsDefault.set_property('session-talk', 'org.test.Service-1;org.test.Service-3');
875 permissionsDefault.set_property('session-own', 'org.test.Service-2;org.test.Service-4');
876
877 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
878 expect(has(_busOverride, _sessionGroup, 'org.test.Service-1', 'talk')).toBe(false);
879 expect(has(_busOverride, _sessionGroup, 'org.test.Service-2', 'own')).toBe(false);
880 expect(has(_busOverride, _sessionGroup, 'org.test.Service-3', 'talk')).toBe(true);
881 expect(has(_busOverride, _sessionGroup, 'org.test.Service-4', 'own')).toBe(true);
882 done();
883 return GLib.SOURCE_REMOVE;
884 });
885
886 update();
887 });
888
889 it('Remove well-known names', function(done) {
890 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
891 permissionsDefault.appId = _busAppId;
892
893 expect(permissionsDefault.session_talk).toEqual('org.test.Service-1');
894 expect(permissionsDefault.session_own).toEqual('org.test.Service-2');
895
896 permissionsDefault.set_property('session-talk', '');
897 permissionsDefault.set_property('session-own', '');
898
899 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
900 expect(has(_busOverride, _sessionGroup, 'org.test.Service-1', 'none')).toBe(true);
901 expect(has(_busOverride, _sessionGroup, 'org.test.Service-2', 'none')).toBe(true);
902 done();
903 return GLib.SOURCE_REMOVE;
904 });
905
906 update();
907 });
908
909 it('Modify well-known names', function(done) {
910 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
911 permissionsDefault.appId = _busAppId;
912
913 expect(permissionsDefault.session_talk).toEqual('org.test.Service-1');
914 expect(permissionsDefault.session_own).toEqual('org.test.Service-2');
915
916 permissionsDefault.set_property('session-talk', 'org.test.Service-2');
917 permissionsDefault.set_property('session-own', 'org.test.Service-1');
918
919 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
920 expect(has(_busOverride, _sessionGroup, 'org.test.Service-1', 'own')).toBe(true);
921 expect(has(_busOverride, _sessionGroup, 'org.test.Service-2', 'talk')).toBe(true);
922 done();
923 return GLib.SOURCE_REMOVE;
924 });
925
926 update();
927 });
928
929 it('signals reset when done explicitly', function() {
930 spyOn(permissionsDefault, 'emit');
931
932 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
933 permissionsDefault.appId = _basicAppId;
934
935 permissionsDefault.reset();
936
937 expect(permissionsDefault.emit.calls.mostRecent().args).toEqual(['reset']);
938 });
939
940 it('restores overrides when undo', function(done) {
941 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
942 permissionsDefault.appId = _basicAppId;
943
944 expect(permissionsDefault.shared_network).toEqual(true);
945 permissionsDefault.set_property('shared_network', false);
946
947 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
948 expect(permissionsDefault.shared_network).toBe(false);
949
950 permissionsDefault.reset();
951 expect(permissionsDefault.shared_network).toBe(true);
952
953 permissionsDefault.undo();
954 expect(permissionsDefault.shared_network).toBe(false);
955
956 done();
957 return GLib.SOURCE_REMOVE;
958 });
959
960 update();
961 });
962
963 it('handles portals permissions', function(done) {
964 permissionsDefault.appId = _basicAppId;
965
966 expect(permissionsDefault.portals_background).toBe(portalState.UNSET);
967 permissionsDefault.set_property('portals_background', portalState.ALLOWED);
968
969 expect(permissionsDefault.portals_notification).toBe(portalState.UNSET);
970 permissionsDefault.set_property('portals_notification', portalState.ALLOWED);
971
972 expect(permissionsDefault.portals_microphone).toBe(portalState.UNSET);
973 permissionsDefault.set_property('portals_microphone', portalState.ALLOWED);
974
975 expect(permissionsDefault.portals_speakers).toBe(portalState.UNSET);
976 permissionsDefault.set_property('portals_speakers', portalState.ALLOWED);
977
978 expect(permissionsDefault.portals_camera).toBe(portalState.UNSET);
979 permissionsDefault.set_property('portals_camera', portalState.ALLOWED);
980
981 expect(permissionsDefault.portals_location).toBe(portalState.UNSET);
982 permissionsDefault.set_property('portals_location', portalState.ALLOWED);
983
984 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
985 expect(getValueFromService('background', 'background', 'yes', _basicAppId)).toBe(true);
986 expect(getValueFromService('notifications', 'notification', 'yes', _basicAppId)).toBe(true);
987 expect(getValueFromService('devices', 'microphone', 'yes', _basicAppId)).toBe(true);
988 expect(getValueFromService('devices', 'speakers', 'yes', _basicAppId)).toBe(true);
989 expect(getValueFromService('devices', 'camera', 'yes', _basicAppId)).toBe(true);
990 expect(getValueFromService('location', 'location', 'EXACT', _basicAppId)).toBe(true);
991
992 done();
993 return GLib.SOURCE_REMOVE;
994 });
995
996 update();
997 });
998
999 it('resets portals permissions', function() {
1000 permissionsDefault.appId = _basicAppId;
1001
1002 permissionsDefault.reset();
1003
1004 expect(getValueFromService('background', 'background', null, _basicAppId)).toBe(true);
1005 expect(getValueFromService('notifications', 'notification', null, _basicAppId)).toBe(true);
1006 expect(getValueFromService('devices', 'microphone', null, _basicAppId)).toBe(true);
1007 expect(getValueFromService('devices', 'speakers', null, _basicAppId)).toBe(true);
1008 expect(getValueFromService('devices', 'camera', null, _basicAppId)).toBe(true);
1009 expect(getValueFromService('location', 'location', null, _basicAppId)).toBe(true);
1010 });
1011
1012
1013 it('restores portals permissions when undo', function(done) {
1014 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
1015 permissionsDefault.appId = _overridenAppId;
1016
1017 expect(permissionsDefault.portals_background).toBe(portalState.UNSET);
1018 expect(permissionsDefault.portals_notification).toBe(portalState.UNSET);
1019 expect(permissionsDefault.portals_microphone).toBe(portalState.UNSET);
1020 expect(permissionsDefault.portals_speakers).toBe(portalState.UNSET);
1021 expect(permissionsDefault.portals_camera).toBe(portalState.UNSET);
1022 expect(permissionsDefault.portals_location).toBe(portalState.UNSET);
1023
1024 permissionsDefault.set_property('portals_notification', portalState.ALLOWED);
1025 permissionsDefault.set_property('portals_background', portalState.ALLOWED);
1026 permissionsDefault.set_property('portals_microphone', portalState.ALLOWED);
1027 permissionsDefault.set_property('portals_speakers', portalState.ALLOWED);
1028 permissionsDefault.set_property('portals_camera', portalState.ALLOWED);
1029 permissionsDefault.set_property('portals_location', portalState.ALLOWED);
1030
1031 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
1032 expect(getValueFromService('background', 'background', 'yes', _overridenAppId)).toBe(true);
1033 expect(getValueFromService('notifications', 'notification', 'yes', _overridenAppId)).toBe(true);
1034 expect(getValueFromService('devices', 'microphone', 'yes', _overridenAppId)).toBe(true);
1035 expect(getValueFromService('devices', 'speakers', 'yes', _overridenAppId)).toBe(true);
1036 expect(getValueFromService('devices', 'camera', 'yes', _overridenAppId)).toBe(true);
1037 expect(getValueFromService('location', 'location', 'EXACT', _overridenAppId)).toBe(true);
1038
1039 permissionsDefault.reset();
1040
1041 expect(getValueFromService('background', 'background', null, _overridenAppId)).toBe(true);
1042 expect(getValueFromService('notifications', 'notification', null, _overridenAppId)).toBe(true);
1043 expect(getValueFromService('devices', 'microphone', null, _overridenAppId)).toBe(true);
1044 expect(getValueFromService('devices', 'speakers', null, _overridenAppId)).toBe(true);
1045 expect(getValueFromService('devices', 'camera', null, _overridenAppId)).toBe(true);
1046 expect(getValueFromService('location', 'location', null, _overridenAppId)).toBe(true);
1047
1048 permissionsDefault.undo();
1049
1050 expect(getValueFromService('background', 'background', 'yes', _overridenAppId)).toBe(true);
1051 expect(getValueFromService('notifications', 'notification', 'yes', _overridenAppId)).toBe(true);
1052 expect(getValueFromService('devices', 'microphone', 'yes', _overridenAppId)).toBe(true);
1053 expect(getValueFromService('devices', 'speakers', 'yes', _overridenAppId)).toBe(true);
1054 expect(getValueFromService('devices', 'camera', 'yes', _overridenAppId)).toBe(true);
1055 expect(getValueFromService('location', 'location', 'EXACT', _overridenAppId)).toBe(true);
1056
1057 done();
1058 return GLib.SOURCE_REMOVE;
1059 });
1060
1061 update();
1062 });
1063
1064 it('does not write to the store unnecessarily', function() {
1065 permissionsDefault.appId = _reduceAppId;
1066
1067 expect(permissionsDefault.portals_background).toBe(portalState.UNSET);
1068 expect(getValueFromService('background', 'background', null, _reduceAppId)).toBe(true);
1069 });
1070
1071 it('handles portals with partial tables on permission store', function() {
1072 partialService();
1073
1074 GLib.setenv('FLATPAK_INFO_PATH', _flatpakInfoNew, true);
1075 infoDefault.reload();
1076 portalsDefault.reload();
1077 permissionsDefault.appId = _basicAppId;
1078
1079 const total = permissionsDefault.getAll().filter(p => p.supported).length;
1080
1081 expect(total).toEqual(_totalPermissions - 1);
1082
1083 expect(permissionsDefault.portals_background).toBe(portalState.UNSET);
1084 expect(permissionsDefault.portals_notification).toBe(portalState.UNSET);
1085 expect(permissionsDefault.portals_microphone).toBe(portalState.UNSUPPORTED);
1086 expect(permissionsDefault.portals_speakers).toBe(portalState.UNSET);
1087 expect(permissionsDefault.portals_camera).toBe(portalState.UNSET);
1088 expect(permissionsDefault.portals_location).toBe(portalState.UNSET);
1089 });
1090
1091 it('handles writing to missing pair on permission store', function(done) {
1092 permissionsDefault.appId = _basicAppId;
1093
1094 expect(permissionsDefault.portals_microphone).toBe(portalState.UNSUPPORTED);
1095 permissionsDefault.set_property('portals_microphone', portalState.ALLOWED);
1096
1097 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
1098 expect(getValueFromService('devices', 'microphone', null, _basicAppId)).toBe(true);
1099
1100 done();
1101 return GLib.SOURCE_REMOVE;
1102 });
1103
1104 update();
1105 });
1106
1107 it('handles portals without permission store', function() {
1108 stopService();
1109
1110 GLib.setenv('FLATPAK_INFO_PATH', _flatpakInfoNew, true);
1111 infoDefault.reload();
1112 portalsDefault.reload();
1113 permissionsDefault.appId = _basicAppId;
1114
1115 const total = permissionsDefault.getAll().filter(p => p.supported).length;
1116
1117 expect(total).toEqual(_totalPermissions - 6);
1118
1119 expect(permissionsDefault.portals_background).toBe(portalState.UNSUPPORTED);
1120 expect(permissionsDefault.portals_notification).toBe(portalState.UNSUPPORTED);
1121 expect(permissionsDefault.portals_microphone).toBe(portalState.UNSUPPORTED);
1122 expect(permissionsDefault.portals_speakers).toBe(portalState.UNSUPPORTED);
1123 expect(permissionsDefault.portals_camera).toBe(portalState.UNSUPPORTED);
1124 expect(permissionsDefault.portals_location).toBe(portalState.UNSUPPORTED);
1125 });
1126
1127 it('handles trailing semicolons', function(done) {
1128 GLib.setenv('FLATPAK_USER_DIR', _user, true);
1129 permissionsDefault.appId = _trailingSemicolonId;
1130
1131 expect(permissionsDefault.shared_network).toBe(true);
1132 expect(permissionsDefault.shared_network).toBe(true);
1133 expect(permissionsDefault.variables).toEqual('TEST=;');
1134
1135 /* force change to verify that there ins't unsupported permissions */
1136 spyOn(permissionsDefault, 'emit');
1137 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
1138 permissionsDefault.set_property('shared-network', false);
1139
1140 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
1141 expect(permissionsDefault.emit.calls.mostRecent().args).toEqual(['changed', true, false]);
1142 done();
1143 return GLib.SOURCE_REMOVE;
1144 });
1145
1146 update();
1147 });
1148
1149 it('handles loading filesystems with mode', function() {
1150 GLib.setenv('FLATPAK_USER_DIR', _user, true);
1151 permissionsDefault.appId = _filesystemWithMode;
1152
1153 expect(permissionsDefault.filesystems_other).toEqual('home:ro');
1154 });
1155
1156 it('handles overriding filesystems with mode', function(done) {
1157 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
1158 permissionsDefault.appId = _filesystemWithMode;
1159
1160 expect(permissionsDefault.filesystems_other).toEqual('host:ro;xdg-documents:ro;home:ro');
1161 permissionsDefault.set_property('filesystems-other', 'home:ro');
1162
1163 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
1164 const group = permissionsDefault.constructor.getGroupForProperty('filesystems-other');
1165 expect(has(_filesystemWithModeOverride, group, _key, '!host')).toBe(true);
1166 expect(has(_filesystemWithModeOverride, group, _key, '!xdg-documents')).toBe(true);
1167 done();
1168 return GLib.SOURCE_REMOVE;
1169 });
1170
1171 update();
1172 });
1173
1174 it('loads global overrides', function() {
1175 GLib.setenv('FLATPAK_USER_DIR', _global, true);
1176 permissionsDefault.appId = _globalAppId;
1177
1178 expect(permissionsDefault.sockets_x11).toBe(false);
1179 expect(permissionsDefault.sockets_wayland).toBe(true);
1180 expect(permissionsDefault.sockets_cups).toBe(true);
1181 expect(permissionsDefault.variables).toEqual('TEST1=global;TEST2=original;TEST3=global');
1182 expect(permissionsDefault.persistent).toEqual('.test1;.test2');
1183 expect(permissionsDefault.filesystems_other).toEqual('~/test2;~/test3');
1184 expect(permissionsDefault.session_talk).toEqual('org.test.Service-3');
1185 expect(permissionsDefault.session_own).toEqual('org.test.Service-2');
1186 });
1187
1188 it('handles overriding apps already globally overridden', function(done) {
1189 GLib.setenv('FLATPAK_USER_DIR', _global, true);
1190 permissionsDefault.appId = _globalAppId;
1191
1192 expect(permissionsDefault.sockets_x11).toBe(false);
1193 permissionsDefault.set_property('sockets-x11', true);
1194
1195 expect(permissionsDefault.sockets_wayland).toBe(true);
1196 permissionsDefault.set_property('sockets-wayland', false);
1197
1198 expect(permissionsDefault.sockets_cups).toBe(true);
1199
1200 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
1201 const group = permissionsDefault.constructor.getGroupForProperty('sockets-x11');
1202 expect(has(_globalWithGlobalOverride, group, 'sockets', 'x11')).toBe(true);
1203 expect(has(_globalWithGlobalOverride, group, 'sockets', '!wayland')).toBe(true);
1204 expect(hasInTotal(_globalWithGlobalOverride)).toEqual(2);
1205 done();
1206 return GLib.SOURCE_REMOVE;
1207 });
1208
1209 update();
1210 });
1211
1212 it('handles variables already globally overridden', function(done) {
1213 GLib.setenv('FLATPAK_USER_DIR', _global, true);
1214 permissionsDefault.appId = _globalAppId;
1215
1216 expect(permissionsDefault.variables).toEqual('TEST1=global;TEST2=original;TEST3=global');
1217 permissionsDefault.set_property('variables', 'TEST2=override;TEST3=global;TEST4=override');
1218
1219 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
1220 expect(has(_globalWithGlobalOverride, 'Environment', 'TEST1', '')).toBe(true);
1221 expect(has(_globalWithGlobalOverride, 'Environment', 'TEST2', 'override')).toBe(true);
1222 expect(has(_globalWithGlobalOverride, 'Environment', 'TEST4', 'override')).toBe(true);
1223 expect(hasInTotal(_globalWithGlobalOverride)).toEqual(3);
1224 done();
1225 return GLib.SOURCE_REMOVE;
1226 });
1227
1228 update();
1229 });
1230
1231 it('handles persistent path already globally overridden', function(done) {
1232 GLib.setenv('FLATPAK_USER_DIR', _global, true);
1233 permissionsDefault.appId = _globalAppId;
1234
1235 expect(permissionsDefault.persistent).toEqual('.test1;.test2');
1236 permissionsDefault.set_property('persistent', '.test1;.test2;.test3');
1237
1238 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
1239 expect(has(_globalWithGlobalOverride, 'Context', 'persistent', '.test3')).toBe(true);
1240 expect(hasInTotal(_globalWithGlobalOverride)).toEqual(1);
1241 done();
1242 return GLib.SOURCE_REMOVE;
1243 });
1244
1245 update();
1246 });
1247
1248 it('handles filesystem path already globally overridden', function(done) {
1249 GLib.setenv('FLATPAK_USER_DIR', _global, true);
1250 permissionsDefault.appId = _globalAppId;
1251
1252 expect(permissionsDefault.filesystems_other).toEqual('~/test2;~/test3');
1253 permissionsDefault.set_property('filesystems_other', '~/test4');
1254
1255 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
1256 expect(has(_globalWithGlobalOverride, 'Context', 'filesystems', '!~/test2')).toBe(true);
1257 expect(has(_globalWithGlobalOverride, 'Context', 'filesystems', '!~/test3')).toBe(true);
1258 expect(has(_globalWithGlobalOverride, 'Context', 'filesystems', '~/test4')).toBe(true);
1259 expect(hasInTotal(_globalWithGlobalOverride)).toEqual(3);
1260 done();
1261 return GLib.SOURCE_REMOVE;
1262 });
1263
1264 update();
1265 });
1266
1267 it('handles well-known names already globally overridden', function(done) {
1268 GLib.setenv('FLATPAK_USER_DIR', _global, true);
1269 permissionsDefault.appId = _globalAppId;
1270
1271 expect(permissionsDefault.session_talk).toEqual('org.test.Service-3');
1272 permissionsDefault.set_property('session_talk', 'org.test.Service-4');
1273
1274 expect(permissionsDefault.session_own).toEqual('org.test.Service-2');
1275 permissionsDefault.set_property('session_own', 'org.test.Service-5');
1276
1277
1278 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
1279 const group = 'Session Bus Policy';
1280 expect(has(_globalWithGlobalOverride, group, 'org.test.Service-3', 'none')).toBe(true);
1281 expect(has(_globalWithGlobalOverride, group, 'org.test.Service-4', 'talk')).toBe(true);
1282 expect(has(_globalWithGlobalOverride, group, 'org.test.Service-2', 'none')).toBe(true);
1283 expect(has(_globalWithGlobalOverride, group, 'org.test.Service-5', 'own')).toBe(true);
1284 expect(hasInTotal(_globalWithGlobalOverride)).toEqual(4);
1285 done();
1286 return GLib.SOURCE_REMOVE;
1287 });
1288
1289 update();
1290 });
1291
1292 it('restores all overriden global overrides', function() {
1293 GLib.setenv('FLATPAK_USER_DIR', _global, true);
1294 permissionsDefault.appId = _globalRestoredAppId;
1295
1296 expect(permissionsDefault.sockets_x11).toBe(true);
1297 expect(permissionsDefault.sockets_wayland).toBe(false);
1298 expect(permissionsDefault.sockets_cups).toBe(true);
1299 expect(permissionsDefault.variables).toEqual('TEST2=override;TEST3=global;TEST4=override');
1300 expect(permissionsDefault.persistent).toEqual('.test1;.test2;.test3');
1301 expect(permissionsDefault.filesystems_other).toEqual('~/test4');
1302 expect(permissionsDefault.session_talk).toEqual('org.test.Service-4');
1303 expect(permissionsDefault.session_own).toEqual('org.test.Service-5');
1304 });
1305
1306 it('sets proper override statuses', function() {
1307 GLib.setenv('FLATPAK_USER_DIR', _statuses, true);
1308 permissionsDefault.appId = _statusesAppId;
1309
1310 expect(permissionsDefault.sockets_cups_status).toEqual('original');
1311 expect(permissionsDefault.sockets_wayland_status).toEqual('global');
1312 expect(permissionsDefault.sockets_x11_status).toEqual('user');
1313 expect(permissionsDefault.variables_status).toEqual('original;global;user');
1314 expect(permissionsDefault.persistent_status).toEqual('original;global;user');
1315 expect(permissionsDefault.filesystems_other_status).toEqual('original;global;user');
1316 expect(permissionsDefault.session_talk_status).toEqual('original;global;user');
1317 expect(permissionsDefault.session_own_status).toEqual('original;global;user');
1318 });
1319
1320 it('handles writting global overridden', function(done) {
1321 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
1322 permissionsDefault.appId = 'global';
1323
1324 expect(permissionsDefault.sockets_x11).toBe(false);
1325 permissionsDefault.set_property('sockets-x11', true);
1326
1327 expect(permissionsDefault.variables).toEqual('');
1328 permissionsDefault.set_property('variables', 'TEST=override');
1329
1330 expect(permissionsDefault.persistent).toEqual('');
1331 permissionsDefault.set_property('persistent', '.test');
1332
1333 expect(permissionsDefault.filesystems_other).toEqual('');
1334 permissionsDefault.set_property('filesystems_other', '~/test');
1335
1336 expect(permissionsDefault.session_talk).toEqual('');
1337 permissionsDefault.set_property('session_talk', 'org.test.Talk');
1338
1339 expect(permissionsDefault.session_own).toEqual('');
1340 permissionsDefault.set_property('session_own', 'org.test.Own');
1341
1342 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
1343 expect(has(_globalOverride, 'Context', 'sockets', 'x11')).toBe(true);
1344 expect(has(_globalOverride, 'Environment', 'TEST', 'override')).toBe(true);
1345 expect(has(_globalOverride, 'Context', 'persistent', '.test')).toBe(true);
1346 expect(has(_globalOverride, 'Context', 'filesystems', '~/test')).toBe(true);
1347 expect(has(_globalOverride, 'Session Bus Policy', 'org.test.Talk', 'talk')).toBe(true);
1348 expect(has(_globalOverride, 'Session Bus Policy', 'org.test.Own', 'own')).toBe(true);
1349 expect(hasInTotal(_globalOverride)).toEqual(6);
1350 done();
1351 return GLib.SOURCE_REMOVE;
1352 });
1353
1354 update();
1355 });
1356
1357 it('preserves negated global overridden', function(done) {
1358 const source = Gio.File.new_for_path(_globalNegatedOverride);
1359 const destination = Gio.File.new_for_path(_globalOverride);
1360 source.copy(destination, Gio.FileCopyFlags.NONE, null, null);
1361
1362 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
1363 permissionsDefault.appId = 'global';
1364
1365 expect(permissionsDefault.sockets_x11).toBe(false);
1366 expect(permissionsDefault.filesystems_other).toEqual('!~/test');
1367 expect(permissionsDefault.variables).toEqual('');
1368 expect(permissionsDefault.session_talk).toEqual('');
1369 expect(permissionsDefault.session_own).toEqual('');
1370
1371 permissionsDefault.set_property('shared-network', true);
1372
1373 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
1374 expect(has(_globalOverride, 'Context', 'shared', 'unsupported')).toBe(true);
1375 expect(has(_globalOverride, 'Context', 'shared', 'network')).toBe(true);
1376 expect(has(_globalOverride, 'Context', 'sockets', '!x11')).toBe(true);
1377 expect(has(_globalOverride, 'Context', 'filesystems', '!~/test')).toBe(true);
1378 expect(has(_globalOverride, 'Environment', 'TEST', '')).toBe(true);
1379 expect(has(_globalOverride, 'Session Bus Policy', 'org.test.Test', 'none')).toBe(true);
1380 expect(hasInTotal(_globalOverride)).toEqual(6);
1381 done();
1382 return GLib.SOURCE_REMOVE;
1383 });
1384
1385 update();
1386 });
1387
1388 it('handles weird interactions with reset mode', function(done) {
1389 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
1390 permissionsDefault.appId = _resetModeId;
1391
1392 expect(permissionsDefault.filesystems_host).toBe(true);
1393 expect(permissionsDefault.filesystems_other).toEqual('');
1394 permissionsDefault.set_property('filesystems_other', '!host:reset');
1395
1396 expect(permissionsDefault.sockets_x11).toBe(false);
1397 permissionsDefault.set_property('sockets_x11', true);
1398
1399 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
1400 expect(has(_resetModeOverride, 'Context', 'sockets', 'x11')).toBe(true);
1401 expect(has(_resetModeOverride, 'Context', 'filesystems', '!host:reset')).toBe(true);
1402 expect(hasInTotal(_resetModeOverride)).toEqual(2);
1403 done();
1404 return GLib.SOURCE_REMOVE;
1405 });
1406
1407 update();
1408 });
1409
1410 it('handles weird interactions with global reset mode', function(done) {
1411 const source = Gio.File.new_for_path(_globalResetModeOverride);
1412 const destination = Gio.File.new_for_path(_globalOverride);
1413 source.copy(destination, Gio.FileCopyFlags.NONE, null, null);
1414
1415 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
1416 permissionsDefault.appId = _resetModeId;
1417
1418 expect(permissionsDefault.filesystems_host).toBe(true);
1419 expect(permissionsDefault.filesystems_other).toEqual('!host:reset');
1420
1421 expect(permissionsDefault.sockets_x11).toBe(false);
1422 permissionsDefault.set_property('sockets_x11', true);
1423
1424 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
1425 expect(has(_resetModeOverride, 'Context', 'sockets', 'x11')).toBe(true);
1426 expect(hasInTotal(_resetModeOverride)).toEqual(1);
1427 done();
1428 return GLib.SOURCE_REMOVE;
1429 });
1430
1431 update();
1432 });
1433
1434 it('handles global overrides that negate filesystems with mode', function(done) {
1435 GLib.setenv('FLATPAK_USER_DIR', _tmp, true);
1436
1437 permissionsDefault.appId = _filesystemWithMode;
1438 expect(permissionsDefault.filesystems_other).toEqual('host:ro;xdg-documents:ro;home:ro');
1439
1440 permissionsDefault.appId = 'global';
1441 expect(permissionsDefault.filesystems_other).toEqual('');
1442 permissionsDefault.set_property('filesystems_other', '!host');
1443
1444 GLib.timeout_add(GLib.PRIORITY_HIGH, delay + 1, () => {
1445 permissionsDefault.appId = _filesystemWithMode;
1446 expect(permissionsDefault.filesystems_other).toEqual('xdg-documents:ro;home:ro');
1447
1448 done();
1449 return GLib.SOURCE_REMOVE;
1450 });
1451
1452 update();
1453 });
1454
1455 it('handles malformed overrides', function() {
1456 spyOn(permissionsDefault, 'emit');
1457
1458 GLib.setenv('FLATPAK_USER_DIR', _user, true);
1459 permissionsDefault.appId = _malformedAppId;
1460
1461 expect(permissionsDefault.emit.calls.first().args).toEqual(['failed']);
1462 });
1463 });