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
111 /files/etc/pam.d/login/4
112 /files/etc/pam.d/newrole/4
115 test descendant /files/etc/aliases/4/descendant::4
117 test descendant-or-self-2 /files/etc/aliases/4/descendant-or-self::4
120 # No matches because the predicate asks if there is a toplevel node
121 # 'ipaddr' with the given value
122 test abs-locpath /files/etc/hosts/*[/ipaddr = '127.0.0.1']/canonical
124 test rel-pred /files/etc/hosts/*/canonical[../ipaddr = '127.0.0.1']
125 /files/etc/hosts/1/canonical = localhost.localdomain
127 # Not the best way to write this, but entirely acceptable
128 test path-with-parent /files/etc/hosts/*/canonical[../ipaddr = '127.0.0.1']/../alias
129 /files/etc/hosts/1/alias[1] = localhost
130 /files/etc/hosts/1/alias[2] = galia.watzmann.net
131 /files/etc/hosts/1/alias[3] = galia
133 test node-exists-pred /files/etc/hosts/*/canonical[../alias]
134 /files/etc/hosts/1/canonical = localhost.localdomain
135 /files/etc/hosts/2/canonical = orange.watzmann.net
137 test ipaddr-child //*[ipaddr]
141 test ipaddr-sibling //*[../ipaddr]
142 /files/etc/hosts/1/ipaddr = 127.0.0.1
143 /files/etc/hosts/1/canonical = localhost.localdomain
144 /files/etc/hosts/1/alias[1] = localhost
145 /files/etc/hosts/1/alias[2] = galia.watzmann.net
146 /files/etc/hosts/1/alias[3] = galia
147 /files/etc/hosts/2/ipaddr = 172.31.122.14
148 /files/etc/hosts/2/canonical = orange.watzmann.net
149 /files/etc/hosts/2/alias = orange
151 test lircd-ancestor //*[ancestor::kudzu][label() != '#comment']
152 /augeas/files/etc/sysconfig/kudzu/path = /files/etc/sysconfig/kudzu
153 /augeas/files/etc/sysconfig/kudzu/mtime = ...
154 /augeas/files/etc/sysconfig/kudzu/lens = @Shellvars
155 /augeas/files/etc/sysconfig/kudzu/lens/info = ...
156 /files/etc/sysconfig/kudzu/SAFE = no
158 test wildcard-last /files/etc/hosts/*[position() = last()]
161 test wildcard-not-last /files/etc/hosts/*[position() != last()][ipaddr]
164 test nodeset-nodeset-eq /files/etc/sysconfig/network-scripts/*[BRIDGE = /files/etc/sysconfig/network-scripts/ifcfg-br0/DEVICE]
165 /files/etc/sysconfig/network-scripts/ifcfg-eth0
167 test last-ssh-service /files/etc/services/service-name[port = '22'][last()]
168 /files/etc/services/service-name[24] = ssh
170 test count-one-alias /files/etc/hosts/*[count(alias) = 1]
173 test number-gt /files/etc/hosts/*[count(alias) > 1]
176 test pred-or /files/etc/hosts/*[canonical = 'localhost' or alias = 'localhost']
179 test pred-and-or /files/etc/hosts/*[(canonical = 'localhost' or alias = 'localhost') and ipaddr = '127.0.0.1']
182 # We used to parse this as '/files/etc/.' followed by garbage, that
183 # was silently ignored. This path must not match anything, instead of
184 # every child of /files/etc
185 test path-with-dot /files/etc/.notthere
187 test str-neq /files/etc/*['foo' != 'foo']
189 # label() returns the label of the context node as a string
190 test label-neq /files/etc/hosts/*[label() != '#comment']
194 # 'and' and 'or' need to coerce types to boolean
195 test coerce-or /files[/files/etc/hosts/*[ipaddr = '127.0.0.1'] or /files/etc/aliases/*[name = 'root'] ]
198 test coerce-and-true /files['foo' and count(/files/etc/hosts/*) ]
201 test coerce-and-false /files['' and count(/none) and /none]
203 test preceding-sibling /files/etc/hosts/*/preceding-sibling::*[alias = 'localhost']
206 test preceding-sibling-pred /files/etc/grub.conf/*[preceding-sibling::*[1] = ../default]
207 /files/etc/grub.conf/timeout = 5
209 test preceding-sibling-pred2 /files/etc/grub.conf/*[preceding-sibling::*[1][self::default]]
210 /files/etc/grub.conf/timeout = 5
212 test following-sibling /files/etc/hosts/1/*/following-sibling::alias
213 /files/etc/hosts/1/alias[1] = localhost
214 /files/etc/hosts/1/alias[2] = galia.watzmann.net
215 /files/etc/hosts/1/alias[3] = galia
217 test following-sibling-pred /files/etc/hosts/1/*[following-sibling::alias]
218 /files/etc/hosts/1/ipaddr = 127.0.0.1
219 /files/etc/hosts/1/canonical = localhost.localdomain
220 /files/etc/hosts/1/alias[1] = localhost
221 /files/etc/hosts/1/alias[2] = galia.watzmann.net
223 test regexp1 /files/etc/sysconfig/network-scripts/*[label() =~ regexp('.*-eth0')]
224 /files/etc/sysconfig/network-scripts/ifcfg-eth0
226 test regexp2 /files/etc/hosts/*[* =~ regexp('127\..*')]
229 test regexp3 /files/etc/hosts/*[ipaddr =~ regexp(/files/etc/hosts/*/ipaddr)]
233 # Check that we don't crash when the nodeset contains all NULL's
234 test regexp4 /files/etc/hosts/*[ipaddr =~ regexp(/files/etc/hosts/*[ipaddr])]
236 # Check case-insensitive matches
237 test regexp5 /files/etc/sysconfig/network-scripts/*[label() =~ regexp('.*-ETH0', 'i')]
238 /files/etc/sysconfig/network-scripts/ifcfg-eth0
240 test regexp6 /files/etc/hosts/*[ipaddr =~ regexp(/files/etc/hosts/*/ipaddr, 'i')]
244 test glob1 /files[ 'axxa' =~ glob('a*a') ]
247 test glob2 /files[ 'axxa' =~ glob('a?[a-z]a') ]
250 test glob3 /files[ '^a' =~ glob('^a') ]
253 test glob4 /augeas/load/*[ '/etc/hosts' =~ glob(incl) ]
256 test glob5 /files[ '/files/etc/hosts/1' =~ glob('/files/*/1') ]
258 test glob6 /files[ '/files/etc/hosts/1' =~ glob('/files/*/*/1') ]
261 test glob_nomatch /files/etc/hosts/*[ipaddr][ ipaddr !~ glob(/files/etc/hosts/*/ipaddr[1]) ]
264 test glob_for_lens /augeas/load/*[ '/etc/hosts/1/ipaddr' =~ glob(incl) + regexp('/.*') ]/lens
265 /augeas/load/Hosts/lens = @Hosts
268 test union (/files/etc/yum.conf | /files/etc/yum.repos.d/*)/*/gpgcheck
269 /files/etc/yum.conf/main/gpgcheck = 1
270 /files/etc/yum.repos.d/fedora-updates.repo/updates/gpgcheck = 1
271 /files/etc/yum.repos.d/fedora-updates.repo/updates-debuginfo/gpgcheck = 1
272 /files/etc/yum.repos.d/fedora-updates.repo/updates-source/gpgcheck = 1
273 /files/etc/yum.repos.d/fedora.repo/fedora/gpgcheck = 1
274 /files/etc/yum.repos.d/fedora.repo/fedora-debuginfo/gpgcheck = 1
275 /files/etc/yum.repos.d/fedora.repo/fedora-source/gpgcheck = 1
276 /files/etc/yum.repos.d/remi.repo/remi/gpgcheck = 1
277 /files/etc/yum.repos.d/remi.repo/remi-test/gpgcheck = 1
279 # Paths with whitespace in them
280 test php1 $php/mail function
281 /files/etc/php.ini/mail\ function
283 test php2 $php[mail function]
286 test php3 $php[count(mail function) = 1]
289 test php4 $php/mail function/SMTP
290 /files/etc/php.ini/mail\ function/SMTP = localhost
292 test php5 $php/mail\ function
293 /files/etc/php.ini/mail\ function
295 test expr-or /files/etc/group/root/*[self::gid or self::user]
296 /files/etc/group/root/gid = 0
297 /files/etc/group/root/user = root
299 test int-ns-eq /files/etc/group/*[int(gid) = 30]
300 /files/etc/group/gopher
302 test int-ns-lt /files/etc/group/*[int(gid) < 3]
303 /files/etc/group/root
305 /files/etc/group/daemon
307 test int-bool-f /files[int(1 = 0) > 0]
309 test int-bool-t /files[int(1 = 1) > 0]
312 # Relative paths, relying on default /files context
313 test ctx_file etc/network/interfaces
314 /files/etc/network/interfaces
316 test ctx_file_pred etc/network/interfaces/iface[. = "lo"]
317 /files/etc/network/interfaces/iface[1] = lo
319 # Test matching with characters that need escaping in the filename
320 test escape1 /files/etc/sysconfig/network-scripts/*
321 /files/etc/sysconfig/network-scripts/ifcfg-eth0
322 /files/etc/sysconfig/network-scripts/ifcfg-wlan0
323 /files/etc/sysconfig/network-scripts/ifcfg-weird\ \[\!\]\ \(used\ to\ fail\)
324 /files/etc/sysconfig/network-scripts/ifcfg-lo
325 /files/etc/sysconfig/network-scripts/ifcfg-br0
327 test escape2 /files/etc/sysconfig/network-scripts/ifcfg-weird\ \[\!\]\ \(used\ to\ fail\)/DEVICE
328 /files/etc/sysconfig/network-scripts/ifcfg-weird\ \[\!\]\ \(used\ to\ fail\)/DEVICE = weird
330 test escape3 /files/etc/sysconfig/network-scripts/*[DEVICE = 'weird']
331 /files/etc/sysconfig/network-scripts/ifcfg-weird\ \[\!\]\ \(used\ to\ fail\)
333 # Test matching in the presence of hidden nodes
334 test hidden1 /files/etc/security/limits.conf/*[label() != '#comment'][1]
335 /files/etc/security/limits.conf/domain[1] = @jackuser