1 # Tests of the XPath matching
3 # Blank lines and lines starting with '#' are ignored
5 # Each test consists of one line declaring the test followed by a complete
6 # list of the expected result of the match.
8 # The test is declared with a line 'test NAME MATCH'. A result is either
9 # just a path (meaning that the value associated with that node must be
10 # NULL) or of the form PATH = VALUE, meaning that the value for the node at
11 # PATH must be VALUE. If VALUE is '...', the test does not check the value
12 # associated with PATH in the tree.
14 # The MATCH XPath expression is matched against a fixed tree (the one from the
15 # root/ subdirectory) and the result of the aug_match is compared with the
16 # results listed in the test
18 # The test framework sets up variables:
19 # hosts /files/etc/hosts/*
20 # localhost '127.0.0.1'
21 # php /files/etc/php.ini
23 # Very simple to warm up
24 test wildcard /files/etc/hosts/*/ipaddr
25 /files/etc/hosts/1/ipaddr = 127.0.0.1
26 /files/etc/hosts/2/ipaddr = 172.31.122.14
28 test wildcard-var $hosts/ipaddr
29 /files/etc/hosts/1/ipaddr = 127.0.0.1
30 /files/etc/hosts/2/ipaddr = 172.31.122.14
32 # Compare the value of the current node with a constant
33 test self-value /files/etc/hosts/*/ipaddr[ . = '127.0.0.1' ]
34 /files/etc/hosts/1/ipaddr = 127.0.0.1
36 test self-value-var $hosts/ipaddr[ . = $localhost ]
37 /files/etc/hosts/1/ipaddr = 127.0.0.1
39 # Find nodes that have a child named 'ipaddr' with a fixed value
40 test child-value /files/etc/hosts/*[ipaddr = '127.0.0.1']
43 test child-value-var $hosts[ipaddr = $localhost]
46 # Find nodes that have a child 'ipaddr' that has no value
47 test child-nil-value /files/etc/hosts/*[ipaddr = '']
49 test child-nil-value-var $hosts[ipaddr = '']
51 # Find nodes that have no value
52 test self-nil-value /files/etc/hosts/*[. = '']
56 test self-nil-value-var $hosts[. = '']
60 # Match over two levels of the tree
61 test two-wildcards /files/etc/*/*[ipaddr='127.0.0.1']
64 test pam-system-auth /files/etc/pam.d/*/*[module = 'system-auth']
65 /files/etc/pam.d/login/2
66 /files/etc/pam.d/login/4
67 /files/etc/pam.d/login/5
68 /files/etc/pam.d/login/8
69 /files/etc/pam.d/postgresql/1
70 /files/etc/pam.d/postgresql/2
71 /files/etc/pam.d/newrole/1
72 /files/etc/pam.d/newrole/2
73 /files/etc/pam.d/newrole/3
75 # Multiple predicates are treated with 'and'
76 test pam-two-preds /files/etc/pam.d/*/*[module = 'system-auth'][type = 'account']
77 /files/etc/pam.d/login/4
78 /files/etc/pam.d/postgresql/2
79 /files/etc/pam.d/newrole/2
81 # Find nodes that have siblings with a given value
82 test pam-two-preds-control /files/etc/pam.d/*/*[module = 'system-auth'][type = 'account']/control
83 /files/etc/pam.d/login/4/control = include
84 /files/etc/pam.d/postgresql/2/control = include
85 /files/etc/pam.d/newrole/2/control = include
87 # last() gives the last node with a certain name
88 test last /files/etc/hosts/*[ipaddr = "127.0.0.1"]/alias[last()]
89 /files/etc/hosts/1/alias[3] = galia
91 test last-var $hosts[ipaddr = $localhost]/alias[last()]
92 /files/etc/hosts/1/alias[3] = galia
94 # We can get nodes counting from the right with 'last()-N'
95 test last-minus-one /files/etc/hosts/*[ipaddr = "127.0.0.1"]/alias[ last() - 1 ]
96 /files/etc/hosts/1/alias[2] = galia.watzmann.net
98 # Make sure we look at all nodes with a given label (ticket #23)
99 test transparent-multi-node /files/etc/ssh/sshd_config/AcceptEnv/10
100 /files/etc/ssh/sshd_config/AcceptEnv[2]/10 = LC_ADDRESS
102 test abbrev-descendants /files/etc/pam.d//1
103 /files/etc/pam.d/login/1
104 /files/etc/pam.d/postgresql/1
105 /files/etc/pam.d/newrole/1
107 test descendant-or-self /files/descendant-or-self :: 4
108 /files/etc/ssh/sshd_config/AcceptEnv[1]/4 = LC_TIME
109 /files/etc/ssh/ssh_config/Host/SendEnv[1]/4 = LC_TIME
110 /files/etc/ssh/ssh_config/Host/SendEnv[2]/4 = LC_TELEPHONE
112 /files/etc/selinux/semanage.conf/ignoredirs/4 = /dev
114 /files/etc/pam.d/login/4
115 /files/etc/pam.d/newrole/4
118 test descendant /files/etc/aliases/4/descendant::4
120 test descendant-or-self-2 /files/etc/aliases/4/descendant-or-self::4
123 # No matches because the predicate asks if there is a toplevel node
124 # 'ipaddr' with the given value
125 test abs-locpath /files/etc/hosts/*[/ipaddr = '127.0.0.1']/canonical
127 test rel-pred /files/etc/hosts/*/canonical[../ipaddr = '127.0.0.1']
128 /files/etc/hosts/1/canonical = localhost.localdomain
130 # Not the best way to write this, but entirely acceptable
131 test path-with-parent /files/etc/hosts/*/canonical[../ipaddr = '127.0.0.1']/../alias
132 /files/etc/hosts/1/alias[1] = localhost
133 /files/etc/hosts/1/alias[2] = galia.watzmann.net
134 /files/etc/hosts/1/alias[3] = galia
136 test node-exists-pred /files/etc/hosts/*/canonical[../alias]
137 /files/etc/hosts/1/canonical = localhost.localdomain
138 /files/etc/hosts/2/canonical = orange.watzmann.net
140 test ipaddr-child //*[ipaddr]
144 test ipaddr-sibling //*[../ipaddr]
145 /files/etc/hosts/1/ipaddr = 127.0.0.1
146 /files/etc/hosts/1/canonical = localhost.localdomain
147 /files/etc/hosts/1/alias[1] = localhost
148 /files/etc/hosts/1/alias[2] = galia.watzmann.net
149 /files/etc/hosts/1/alias[3] = galia
150 /files/etc/hosts/2/ipaddr = 172.31.122.14
151 /files/etc/hosts/2/canonical = orange.watzmann.net
152 /files/etc/hosts/2/alias = orange
154 test lircd-ancestor //*[ancestor::kudzu][label() != '#comment']
155 /augeas/files/etc/sysconfig/kudzu/path = /files/etc/sysconfig/kudzu
156 /augeas/files/etc/sysconfig/kudzu/mtime = ...
157 /augeas/files/etc/sysconfig/kudzu/lens = @Shellvars
158 /augeas/files/etc/sysconfig/kudzu/lens/info = ...
159 /files/etc/sysconfig/kudzu/SAFE = no
161 test wildcard-last /files/etc/hosts/*[position() = last()]
164 test wildcard-not-last /files/etc/hosts/*[position() != last()][ipaddr]
167 test nodeset-nodeset-eq /files/etc/sysconfig/network-scripts/*[BRIDGE = /files/etc/sysconfig/network-scripts/ifcfg-br0/DEVICE]
168 /files/etc/sysconfig/network-scripts/ifcfg-eth0
170 test last-ssh-service /files/etc/services/service-name[port = '22'][last()]
171 /files/etc/services/service-name[24] = ssh
173 test count-one-alias /files/etc/hosts/*[count(alias) = 1]
176 test number-gt /files/etc/hosts/*[count(alias) > 1]
179 test pred-or /files/etc/hosts/*[canonical = 'localhost' or alias = 'localhost']
182 test pred-and-or /files/etc/hosts/*[(canonical = 'localhost' or alias = 'localhost') and ipaddr = '127.0.0.1']
185 # We used to parse this as '/files/etc/.' followed by garbage, that
186 # was silently ignored. This path must not match anything, instead of
187 # every child of /files/etc
188 test path-with-dot /files/etc/.notthere
190 test str-neq /files/etc/*['foo' != 'foo']
192 # label() returns the label of the context node as a string
193 test label-neq /files/etc/hosts/*[label() != '#comment']
197 # 'and' and 'or' need to coerce types to boolean
198 test coerce-or /files[/files/etc/hosts/*[ipaddr = '127.0.0.1'] or /files/etc/aliases/*[name = 'root'] ]
201 test coerce-and-true /files['foo' and count(/files/etc/hosts/*) ]
204 test coerce-and-false /files['' and count(/none) and /none]
206 test preceding-sibling /files/etc/hosts/*/preceding-sibling::*[alias = 'localhost']
209 test preceding-sibling-pred /files/etc/grub.conf/*[preceding-sibling::*[1] = ../default]
210 /files/etc/grub.conf/timeout = 5
212 test preceding-sibling-pred2 /files/etc/grub.conf/*[preceding-sibling::*[1][self::default]]
213 /files/etc/grub.conf/timeout = 5
215 test following-sibling /files/etc/hosts/1/*/following-sibling::alias
216 /files/etc/hosts/1/alias[1] = localhost
217 /files/etc/hosts/1/alias[2] = galia.watzmann.net
218 /files/etc/hosts/1/alias[3] = galia
220 test following-sibling-pred /files/etc/hosts/1/*[following-sibling::alias]
221 /files/etc/hosts/1/ipaddr = 127.0.0.1
222 /files/etc/hosts/1/canonical = localhost.localdomain
223 /files/etc/hosts/1/alias[1] = localhost
224 /files/etc/hosts/1/alias[2] = galia.watzmann.net
226 test regexp1 /files/etc/sysconfig/network-scripts/*[label() =~ regexp('.*-eth0')]
227 /files/etc/sysconfig/network-scripts/ifcfg-eth0
229 test regexp2 /files/etc/hosts/*[* =~ regexp('127\..*')]
232 test regexp3 /files/etc/hosts/*[ipaddr =~ regexp(/files/etc/hosts/*/ipaddr)]
236 # Check that we don't crash when the nodeset contains all NULL's
237 test regexp4 /files/etc/hosts/*[ipaddr =~ regexp(/files/etc/hosts/*[ipaddr])]
239 # Check case-insensitive matches
240 test regexp5 /files/etc/sysconfig/network-scripts/*[label() =~ regexp('.*-ETH0', 'i')]
241 /files/etc/sysconfig/network-scripts/ifcfg-eth0
243 test regexp6 /files/etc/hosts/*[ipaddr =~ regexp(/files/etc/hosts/*/ipaddr, 'i')]
247 test glob1 /files[ 'axxa' =~ glob('a*a') ]
250 test glob2 /files[ 'axxa' =~ glob('a?[a-z]a') ]
253 test glob3 /files[ '^a' =~ glob('^a') ]
256 test glob4 /augeas/load/*[ '/etc/hosts' =~ glob(incl) ]
259 test glob5 /files[ '/files/etc/hosts/1' =~ glob('/files/*/1') ]
261 test glob6 /files[ '/files/etc/hosts/1' =~ glob('/files/*/*/1') ]
264 test glob_nomatch /files/etc/hosts/*[ipaddr][ ipaddr !~ glob(/files/etc/hosts/*/ipaddr[1]) ]
267 test glob_for_lens /augeas/load/*[ '/etc/hosts/1/ipaddr' =~ glob(incl) + regexp('/.*') ]/lens
268 /augeas/load/Hosts/lens = @Hosts
271 test union (/files/etc/yum.conf | /files/etc/yum.repos.d/*)/*/gpgcheck
272 /files/etc/yum.conf/main/gpgcheck = 1
273 /files/etc/yum.repos.d/fedora-updates.repo/updates/gpgcheck = 1
274 /files/etc/yum.repos.d/fedora-updates.repo/updates-debuginfo/gpgcheck = 1
275 /files/etc/yum.repos.d/fedora-updates.repo/updates-source/gpgcheck = 1
276 /files/etc/yum.repos.d/fedora.repo/fedora/gpgcheck = 1
277 /files/etc/yum.repos.d/fedora.repo/fedora-debuginfo/gpgcheck = 1
278 /files/etc/yum.repos.d/fedora.repo/fedora-source/gpgcheck = 1
279 /files/etc/yum.repos.d/remi.repo/remi/gpgcheck = 1
280 /files/etc/yum.repos.d/remi.repo/remi-test/gpgcheck = 1
282 test else_nodeset_lhs (/files/etc/yum.conf else /files/etc/yum.repos.d/*)/*/gpgcheck
283 /files/etc/yum.conf/main/gpgcheck = 1
285 test else_nodeset_rhs (/files/etc/yum.conf.missing else /files/etc/yum.repos.d/fedora.repo)/*/gpgcheck
286 /files/etc/yum.repos.d/fedora.repo/fedora/gpgcheck = 1
287 /files/etc/yum.repos.d/fedora.repo/fedora-debuginfo/gpgcheck = 1
288 /files/etc/yum.repos.d/fedora.repo/fedora-source/gpgcheck = 1
290 test else_nodeset_nomatch (/files/left else /files/right)
292 # Paths with whitespace in them
293 test php1 $php/mail function
294 /files/etc/php.ini/mail\ function
296 test php2 $php[mail function]
299 test php3 $php[count(mail function) = 1]
302 test php4 $php/mail function/SMTP
303 /files/etc/php.ini/mail\ function/SMTP = localhost
305 test php5 $php/mail\ function
306 /files/etc/php.ini/mail\ function
308 test expr-or /files/etc/group/root/*[self::gid or self::user]
309 /files/etc/group/root/gid = 0
310 /files/etc/group/root/user = root
312 test int-ns-eq /files/etc/group/*[int(gid) = 30]
313 /files/etc/group/gopher
315 test int-ns-lt /files/etc/group/*[int(gid) < 3]
316 /files/etc/group/root
318 /files/etc/group/daemon
320 test int-bool-f /files[int(1 = 0) > 0]
322 test int-bool-t /files[int(1 = 1) > 0]
325 # Relative paths, relying on default /files context
326 test ctx_file etc/network/interfaces
327 /files/etc/network/interfaces
329 test ctx_file_pred etc/network/interfaces/iface[. = "lo"]
330 /files/etc/network/interfaces/iface[1] = lo
332 # Test matching with characters that need escaping in the filename
333 test escape1 /files/etc/sysconfig/network-scripts/*
334 /files/etc/sysconfig/network-scripts/ifcfg-eth0
335 /files/etc/sysconfig/network-scripts/ifcfg-wlan0
336 /files/etc/sysconfig/network-scripts/ifcfg-weird\ \[\!\]\ \(used\ to\ fail\)
337 /files/etc/sysconfig/network-scripts/ifcfg-lo
338 /files/etc/sysconfig/network-scripts/ifcfg-br0
340 test escape2 /files/etc/sysconfig/network-scripts/ifcfg-weird\ \[\!\]\ \(used\ to\ fail\)/DEVICE
341 /files/etc/sysconfig/network-scripts/ifcfg-weird\ \[\!\]\ \(used\ to\ fail\)/DEVICE = weird
343 test escape3 /files/etc/sysconfig/network-scripts/*[DEVICE = 'weird']
344 /files/etc/sysconfig/network-scripts/ifcfg-weird\ \[\!\]\ \(used\ to\ fail\)
346 # Test matching in the presence of hidden nodes
347 test hidden1 /files/etc/security/limits.conf/*[label() != '#comment'][1]
348 /files/etc/security/limits.conf/domain[1] = @jackuser
350 test seqaxismatchall /files/etc/hosts/seq::*
354 test seqaxismatchpos /files/etc/hosts/seq::*[2]
357 test seqaxismatchlabel /files/etc/hosts/seq::2
360 test seqaxismatchregexp /files/etc/hosts/seq::*[canonical =~ regexp('.*orange.*')]
363 test else_simple_lhs /files/etc/fstab/*[passno='1' else passno='2']/file
364 /files/etc/fstab/1/file = /
366 test else_simple_rhs /files/etc/fstab/*[passno='9' else passno='2']/file
367 /files/etc/fstab/2/file = /boot
368 /files/etc/fstab/5/file = /home
369 /files/etc/fstab/8/file = /local
370 /files/etc/fstab/9/file = /var/lib/xen/images
372 test else_haschild_lhs /files/etc/hosts/*[alias else alias='orange']/canonical
373 /files/etc/hosts/1/canonical = localhost.localdomain
374 /files/etc/hosts/2/canonical = orange.watzmann.net
376 test else_chain1 /files/etc/fstab/*[passno='9' else passno='1' else passno='2']/file
377 /files/etc/fstab/1/file = /
379 test else_chain2 /files/etc/fstab/*[passno='9' else passno='8' else passno='2']/file
380 /files/etc/fstab/2/file = /boot
381 /files/etc/fstab/5/file = /home
382 /files/etc/fstab/8/file = /local
383 /files/etc/fstab/9/file = /var/lib/xen/images
385 # Although there are nodes matching passno=2 and nodes matching dump=0
386 # there is no node with both
387 test_and_else_lhs /files/etc/fstab/*[passno='2' and ( dump='0' else dump='1')]/file
389 test_and_else_rhs /files/etc/fstab/*[passno='2' and ( dump='nemo' else dump='1')]/file
390 /files/etc/fstab/2/file = /boot
391 /files/etc/fstab/5/file = /home
392 /files/etc/fstab/8/file = /local
393 /files/etc/fstab/9/file = /var/lib/xen/images