summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Playfair Cal <daniel.playfair.cal@gmail.com>2019-01-04 23:27:44 +0000
committerDaniel Playfair Cal <daniel.playfair.cal@gmail.com>2019-01-04 23:27:44 +0000
commit433f49bc11c2208450843165a9d50ba571d62500 (patch)
tree12a6447ac5778b26526f91c229bd8be511b62b6c
parent8d03db335063cc47ef97ad8e0c1a549fa31adfb7 (diff)
parent6ef3d0209dd6e78c1247c1dded0948e0cadf2ffb (diff)
downloaddconf-433f49bc11c2208450843165a9d50ba571d62500.tar.gz
Merge branch 'integration-test-3' into 'master'
tests: Key paths can be locked in system databases See merge request GNOME/dconf!35
-rwxr-xr-xtests/test-dconf.py89
1 files changed, 88 insertions, 1 deletions
diff --git a/tests/test-dconf.py b/tests/test-dconf.py
index 40a8737..88f6769 100755
--- a/tests/test-dconf.py
+++ b/tests/test-dconf.py
@@ -73,6 +73,10 @@ def dconf_write(key, value):
def dconf_list(key):
return dconf('list', key).stdout.splitlines()
+def dconf_locks(key, **kwargs):
+ lines = dconf('list-locks', key, **kwargs).stdout.splitlines()
+ lines.sort()
+ return lines
def dconf_complete(suffix, prefix):
lines = dconf('_complete', suffix, prefix).stdout.splitlines()
@@ -661,13 +665,96 @@ class DBusTest(unittest.TestCase):
self.assertFalse(os.path.exists(path))
self.assertRegex(cm.exception.stderr, name)
+ def test_locks(self):
+ """Key paths can be locked in system databases.
+
+ - Update configures locks based on files found in "locks" subdirectory.
+ - Locks can be listed with list-locks command.
+ - Locks are enforced during write.
+ """
+
+ db = os.path.join(self.temporary_dir.name, 'db')
+ profile = os.path.join(self.temporary_dir.name, 'profile')
+ site = os.path.join(db, 'site')
+ site_d = os.path.join(db, 'site.d')
+ site_locks = os.path.join(db, site_d, 'locks')
+
+ os.makedirs(site_locks)
+
+ # For meaningful test of locks we need two sources, first of which
+ # should be writable. We will use user-db and file-db.
+ with open(profile, 'w') as file:
+ file.write(dedent('''\
+ user-db:user
+ file-db:{}
+ '''.format(site)))
+
+ # Environment to use for all dconf client invocations.
+ env = dict(os.environ)
+ env['DCONF_PROFILE'] = profile
+
+ # Default settings
+ with open(os.path.join(site_d, '10-site-defaults'), 'w') as file:
+ file.write(dedent('''\
+ # Some useful default settings for our site
+ [system/proxy/http]
+ host='172.16.0.1'
+ enabled=true
+
+ [org/gnome/desktop/background]
+ picture-uri='file:///usr/local/rupert-corp/company-wallpaper.jpeg'
+ '''))
+
+ # Lock proxy settings.
+ with open(os.path.join(site_locks, '10-proxy-lock'), 'w') as file:
+ file.write(dedent('''\
+ # Prevent changes to proxy
+ /system/proxy/http/host
+ /system/proxy/http/enabled
+ /system/proxy/ftp/host
+ /system/proxy/ftp/enabled
+ '''))
+
+ # Compile site configuration.
+ dconf('update', db)
+
+ # Test list-locks:
+ self.assertEqual(['/system/proxy/ftp/enabled',
+ '/system/proxy/ftp/host',
+ '/system/proxy/http/enabled',
+ '/system/proxy/http/host'],
+ dconf_locks('/', env=env))
+
+ self.assertEqual(['/system/proxy/http/enabled',
+ '/system/proxy/http/host'],
+ dconf_locks('/system/proxy/http/', env=env))
+
+ self.assertEqual([],
+ dconf_locks('/org/gnome/', env=env))
+
+ # Changing unlocked defaults is fine.
+ dconf('write', '/org/gnome/desktop/background/picture-uri',
+ '"file:///usr/share/backgrounds/gnome/ColdWarm.jpg"',
+ env=env)
+
+ # It is an error to change locked keys.
+ with self.assertRaises(subprocess.CalledProcessError) as cm:
+ dconf('write', '/system/proxy/http/enabled', 'false',
+ env=env, stderr=subprocess.PIPE)
+ self.assertRegex(cm.exception.stderr, 'non-writable keys')
+
+
if __name__ == '__main__':
# Make sure we don't pick up mandatory profile.
mandatory_profile = '/run/dconf/user/{}'.format(os.getuid())
assert not os.path.isfile(mandatory_profile)
- # Avoid profile sourced from environment
+ # Avoid profile sourced from environment or system data dirs.
os.environ.pop('DCONF_PROFILE', None)
+ os.environ.pop('XDG_DATA_DIRS', None)
+ # Avoid interfering with external message buses.
+ os.environ.pop('DBUS_SYSTEM_BUS_ADDRESS', None)
+ os.environ.pop('DBUS_SESSION_BUS_ADDRESS', None)
if len(sys.argv) < 3:
message = 'Usage: {} path-to-dconf path-to-dconf-service'.format(