annotate tests/test-trusted.py @ 9622:9d1a480ca6ea

gendoc: fix synopsis The synopsis is used as an inline literal when generating the manpage. There should not be any whitespace on the inside of the quotation marks in inline literals. Commands with an empty synopsis (such as tags) produces ``tags `` as synopsis, which triggers a warning.
author Martin Geisler <mg@lazybytes.net>
date Tue, 20 Oct 2009 22:42:49 +0200
parents 3fa92c618624
children 543597fae51d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3551
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
1 # Since it's not easy to write a test that portably deals
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
2 # with files from different users/groups, we cheat a bit by
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
3 # monkey-patching some functions in the util module
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
4
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
5 import os
8144
fca54469480e ui: introduce new config parser
Matt Mackall <mpm@selenic.com>
parents: 8142
diff changeset
6 from mercurial import ui, util, error
3551
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
7
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
8 hgrc = os.environ['HGRCPATH']
5523
5db730475d6d tests/*: avoid losing the original settings from $HGRCPATH
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4516
diff changeset
9 f = open(hgrc)
5db730475d6d tests/*: avoid losing the original settings from $HGRCPATH
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4516
diff changeset
10 basehgrc = f.read()
5db730475d6d tests/*: avoid losing the original settings from $HGRCPATH
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4516
diff changeset
11 f.close()
3551
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
12
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
13 def testui(user='foo', group='bar', tusers=(), tgroups=(),
3552
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
14 cuser='foo', cgroup='bar', debug=False, silent=False):
3551
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
15 # user, group => owners of the file
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
16 # tusers, tgroups => trusted users/groups
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
17 # cuser, cgroup => user/group of the current process
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
18
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
19 # write a global hgrc with the list of trusted users/groups and
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
20 # some setting so that we can be sure it was read
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
21 f = open(hgrc, 'w')
5523
5db730475d6d tests/*: avoid losing the original settings from $HGRCPATH
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4516
diff changeset
22 f.write(basehgrc)
5db730475d6d tests/*: avoid losing the original settings from $HGRCPATH
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4516
diff changeset
23 f.write('\n[paths]\n')
3551
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
24 f.write('global = /some/path\n\n')
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
25
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
26 if tusers or tgroups:
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
27 f.write('[trusted]\n')
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
28 if tusers:
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
29 f.write('users = %s\n' % ', '.join(tusers))
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
30 if tgroups:
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
31 f.write('groups = %s\n' % ', '.join(tgroups))
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
32 f.close()
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
33
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
34 # override the functions that give names to uids and gids
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
35 def username(uid=None):
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
36 if uid is None:
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
37 return cuser
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
38 return user
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
39 util.username = username
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
40
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
41 def groupname(gid=None):
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
42 if gid is None:
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
43 return 'bar'
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
44 return group
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
45 util.groupname = groupname
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
46
8657
3fa92c618624 posix: do not use fstat in isowner
Martin Geisler <mg@lazybytes.net>
parents: 8190
diff changeset
47 def isowner(st):
3677
1a0fa3914c46 Avoid looking up usernames if the current user owns the .hgrc file
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3552
diff changeset
48 return user == cuser
1a0fa3914c46 Avoid looking up usernames if the current user owns the .hgrc file
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3552
diff changeset
49 util.isowner = isowner
1a0fa3914c46 Avoid looking up usernames if the current user owns the .hgrc file
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3552
diff changeset
50
3551
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
51 # try to read everything
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
52 #print '# File belongs to user %s, group %s' % (user, group)
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
53 #print '# trusted users = %s; trusted groups = %s' % (tusers, tgroups)
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
54 kind = ('different', 'same')
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
55 who = ('', 'user', 'group', 'user and the group')
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
56 trusted = who[(user in tusers) + 2*(group in tgroups)]
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
57 if trusted:
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
58 trusted = ', but we trust the ' + trusted
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
59 print '# %s user, %s group%s' % (kind[user == cuser], kind[group == cgroup],
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
60 trusted)
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
61
8190
9b8ac5fb7760 ui: kill most users of parentui name and arg, replace with .copy()
Matt Mackall <mpm@selenic.com>
parents: 8144
diff changeset
62 u = ui.ui()
9b8ac5fb7760 ui: kill most users of parentui name and arg, replace with .copy()
Matt Mackall <mpm@selenic.com>
parents: 8144
diff changeset
63 u.setconfig('ui', 'debug', str(bool(debug)))
3551
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
64 u.readconfig('.hg/hgrc')
3552
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
65 if silent:
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
66 return u
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
67 print 'trusted'
3551
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
68 for name, path in u.configitems('paths'):
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
69 print ' ', name, '=', path
3552
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
70 print 'untrusted'
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
71 for name, path in u.configitems('paths', untrusted=True):
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
72 print '.',
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
73 u.config('paths', name) # warning with debug=True
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
74 print '.',
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
75 u.config('paths', name, untrusted=True) # no warnings
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
76 print name, '=', path
3551
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
77 print
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
78
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
79 return u
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
80
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
81 os.mkdir('repo')
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
82 os.chdir('repo')
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
83 os.mkdir('.hg')
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
84 f = open('.hg/hgrc', 'w')
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
85 f.write('[paths]\n')
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
86 f.write('local = /another/path\n\n')
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
87 f.close()
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
88
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
89 #print '# Everything is run by user foo, group bar\n'
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
90
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
91 # same user, same group
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
92 testui()
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
93 # same user, different group
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
94 testui(group='def')
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
95 # different user, same group
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
96 testui(user='abc')
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
97 # ... but we trust the group
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
98 testui(user='abc', tgroups=['bar'])
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
99 # different user, different group
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
100 testui(user='abc', group='def')
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
101 # ... but we trust the user
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
102 testui(user='abc', group='def', tusers=['abc'])
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
103 # ... but we trust the group
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
104 testui(user='abc', group='def', tgroups=['def'])
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
105 # ... but we trust the user and the group
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
106 testui(user='abc', group='def', tusers=['abc'], tgroups=['def'])
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
107 # ... but we trust all users
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
108 print '# we trust all users'
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
109 testui(user='abc', group='def', tusers=['*'])
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
110 # ... but we trust all groups
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
111 print '# we trust all groups'
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
112 testui(user='abc', group='def', tgroups=['*'])
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
113 # ... but we trust the whole universe
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
114 print '# we trust all users and groups'
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
115 testui(user='abc', group='def', tusers=['*'], tgroups=['*'])
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
116 # ... check that users and groups are in different namespaces
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
117 print "# we don't get confused by users and groups with the same name"
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
118 testui(user='abc', group='def', tusers=['def'], tgroups=['abc'])
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
119 # ... lists of user names work
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
120 print "# list of user names"
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
121 testui(user='abc', group='def', tusers=['foo', 'xyz', 'abc', 'bleh'],
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
122 tgroups=['bar', 'baz', 'qux'])
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
123 # ... lists of group names work
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
124 print "# list of group names"
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
125 testui(user='abc', group='def', tusers=['foo', 'xyz', 'bleh'],
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
126 tgroups=['bar', 'def', 'baz', 'qux'])
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
127
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
128 print "# Can't figure out the name of the user running this process"
3b07e223534b Only read .hg/hgrc files from trusted users/groups
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
129 testui(user='abc', group='def', cuser=None)
3552
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
130
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
131 print "# prints debug warnings"
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
132 u = testui(user='abc', group='def', cuser='foo', debug=True)
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
133
8142
912bfef12ba6 ui: fold readsections into readconfig
Matt Mackall <mpm@selenic.com>
parents: 8136
diff changeset
134 print "# ui.readconfig sections"
3552
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
135 filename = 'foobar'
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
136 f = open(filename, 'w')
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
137 f.write('[foobar]\n')
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
138 f.write('baz = quux\n')
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
139 f.close()
8142
912bfef12ba6 ui: fold readsections into readconfig
Matt Mackall <mpm@selenic.com>
parents: 8136
diff changeset
140 u.readconfig(filename, sections = ['foobar'])
3552
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
141 print u.config('foobar', 'baz')
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
142
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
143 print
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
144 print "# read trusted, untrusted, new ui, trusted"
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
145 u = ui.ui()
8136
6b5522cb2ad2 ui: refactor option setting
Matt Mackall <mpm@selenic.com>
parents: 5523
diff changeset
146 u.setconfig('ui', 'debug', 'on')
3552
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
147 u.readconfig(filename)
8190
9b8ac5fb7760 ui: kill most users of parentui name and arg, replace with .copy()
Matt Mackall <mpm@selenic.com>
parents: 8144
diff changeset
148 u2 = u.copy()
3552
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
149 def username(uid=None):
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
150 return 'foo'
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
151 util.username = username
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
152 u2.readconfig('.hg/hgrc')
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
153 print 'trusted:'
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
154 print u2.config('foobar', 'baz')
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
155 print 'untrusted:'
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
156 print u2.config('foobar', 'baz', untrusted=True)
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
157
4516
96d8a56d4ef9 Removed trailing whitespace and tabs from python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4122
diff changeset
158 print
3552
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
159 print "# error handling"
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
160
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
161 def assertraises(f, exc=util.Abort):
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
162 try:
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
163 f()
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
164 except exc, inst:
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
165 print 'raised', inst.__class__.__name__
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
166 else:
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
167 print 'no exception?!'
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
168
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
169 print "# file doesn't exist"
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
170 os.unlink('.hg/hgrc')
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
171 assert not os.path.exists('.hg/hgrc')
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
172 testui(debug=True, silent=True)
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
173 testui(user='abc', group='def', debug=True, silent=True)
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
174
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
175 print
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
176 print "# parse error"
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
177 f = open('.hg/hgrc', 'w')
8144
fca54469480e ui: introduce new config parser
Matt Mackall <mpm@selenic.com>
parents: 8142
diff changeset
178 f.write('foo')
3552
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
179 f.close()
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
180
8144
fca54469480e ui: introduce new config parser
Matt Mackall <mpm@selenic.com>
parents: 8142
diff changeset
181 try:
fca54469480e ui: introduce new config parser
Matt Mackall <mpm@selenic.com>
parents: 8142
diff changeset
182 testui(user='abc', group='def', silent=True)
fca54469480e ui: introduce new config parser
Matt Mackall <mpm@selenic.com>
parents: 8142
diff changeset
183 except error.ConfigError, inst:
fca54469480e ui: introduce new config parser
Matt Mackall <mpm@selenic.com>
parents: 8142
diff changeset
184 print inst
3552
9b52239dc740 save settings from untrusted config files in a separate configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3551
diff changeset
185
8144
fca54469480e ui: introduce new config parser
Matt Mackall <mpm@selenic.com>
parents: 8142
diff changeset
186 try:
fca54469480e ui: introduce new config parser
Matt Mackall <mpm@selenic.com>
parents: 8142
diff changeset
187 testui(debug=True, silent=True)
fca54469480e ui: introduce new config parser
Matt Mackall <mpm@selenic.com>
parents: 8142
diff changeset
188 except error.ConfigError, inst:
fca54469480e ui: introduce new config parser
Matt Mackall <mpm@selenic.com>
parents: 8142
diff changeset
189 print inst