changeset 31481:75e4bae56068

config: honour the trusted flag in ui.configbytes
author Martijn Pieters <mjpieters@fb.com>
date Sun, 12 Mar 2017 11:43:31 -0700
parents 95be8b7181d3
children 1b9b00aca8a3
files mercurial/ui.py tests/test-trusted.py tests/test-trusted.py.out
diffstat 3 files changed, 55 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/ui.py	Wed Mar 15 20:43:12 2017 -0700
+++ b/mercurial/ui.py	Sun Mar 12 11:43:31 2017 -0700
@@ -542,7 +542,7 @@
         ConfigError: foo.invalid is not a byte quantity ('somevalue')
         """
 
-        value = self.config(section, name)
+        value = self.config(section, name, None, untrusted)
         if value is None:
             if not isinstance(default, str):
                 return default
--- a/tests/test-trusted.py	Wed Mar 15 20:43:12 2017 -0700
+++ b/tests/test-trusted.py	Sun Mar 12 11:43:31 2017 -0700
@@ -201,3 +201,41 @@
     testui(debug=True, silent=True)
 except error.ParseError as inst:
     print(inst)
+
+print()
+print('# access typed information')
+with open('.hg/hgrc', 'w') as f:
+    f.write('''\
+[foo]
+sub=main
+sub:one=one
+sub:two=two
+path=monty/python
+bool=true
+int=42
+bytes=81mb
+list=spam,ham,eggs
+''')
+u = testui(user='abc', group='def', cuser='foo', silent=True)
+print('# suboptions, trusted and untrusted')
+trusted = u.configsuboptions('foo', 'sub')
+untrusted = u.configsuboptions('foo', 'sub', untrusted=True)
+print(
+    (trusted[0], sorted(trusted[1].items())),
+    (untrusted[0], sorted(untrusted[1].items())))
+print('# path, trusted and untrusted')
+print(u.configpath('foo', 'path'), u.configpath('foo', 'path', untrusted=True))
+print('# bool, trusted and untrusted')
+print(u.configbool('foo', 'bool'), u.configbool('foo', 'bool', untrusted=True))
+print('# int, trusted and untrusted')
+print(
+    u.configint('foo', 'int', 0),
+    u.configint('foo', 'int', 0, untrusted=True))
+print('# bytes, trusted and untrusted')
+print(
+    u.configbytes('foo', 'bytes', 0),
+    u.configbytes('foo', 'bytes', 0, untrusted=True))
+print('# list, trusted and untrusted')
+print(
+    u.configlist('foo', 'list', []),
+    u.configlist('foo', 'list', [], untrusted=True))
--- a/tests/test-trusted.py.out	Wed Mar 15 20:43:12 2017 -0700
+++ b/tests/test-trusted.py.out	Sun Mar 12 11:43:31 2017 -0700
@@ -177,3 +177,19 @@
 ('foo', '.hg/hgrc:1')
 # same user, same group
 ('foo', '.hg/hgrc:1')
+
+# access typed information
+# different user, different group
+not trusting file .hg/hgrc from untrusted user abc, group def
+# suboptions, trusted and untrusted
+(None, []) ('main', [('one', 'one'), ('two', 'two')])
+# path, trusted and untrusted
+None .hg/monty/python
+# bool, trusted and untrusted
+False True
+# int, trusted and untrusted
+0 42
+# bytes, trusted and untrusted
+0 84934656
+# list, trusted and untrusted
+[] ['spam', 'ham', 'eggs']