File: all.sh

package info (click to toggle)
openscap 1.4.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 125,116 kB
  • sloc: xml: 527,136; ansic: 91,867; sh: 19,831; python: 2,531; perl: 444; makefile: 49
file content (685 lines) | stat: -rwxr-xr-x 40,113 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
#!/usr/bin/env bash
#
# Copyright 2013 Red Hat Inc., Durham, North Carolina.
# All Rights Reserved.
#
# This script is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

set -e -o pipefail

. $builddir/tests/test_common.sh

#
# Export two values from XCCDF to a single OVAL variable as a part
# of single rule. Result is a single varible set with multiple values.
#
function xccdf_export_1_multival() {
	local name=$FUNCNAME
	local variables0="requires_both-oval.xml-0.variables-0.xml"
	local variables1="requires_both-oval.xml-0.variables-1.xml"
	local result="$variables0"
	local stderr=$(mktemp -t ${FUNCNAME}.err.XXXXXX)
	echo "Stderr file = $stderr"

	[ ! -f $variables0 ] || rm $variables0
	[ ! -f $variables1 ] || rm $variables1
	$OSCAP xccdf export-oval-variables --profile xccdf_moc.elpmaxe.www_profile_1 \
		$srcdir/test_xccdf_variable_instance.xccdf.xml 2>&1 > $stderr
	[ -f $stderr ]; [ ! -s $stderr ]
	[ -f $variables0 ]
	[ ! -f $variables1 ]
	$OSCAP oval validate $variables0
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 1 '/oval_variables/variables/variable'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 2 '/oval_variables/variables/variable/value'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="300"]'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="600"]'
	rm $variables0
	rm $stderr
}

#
# Export two values from XCCDF to a single OVAL variable that it should
# result in multiple (two) variable sets each with a single value.
#
function xccdf_export_2_multiset(){
	local variables0="requires_both-oval.xml-0.variables-0.xml"
	local variables1="requires_both-oval.xml-0.variables-1.xml"
	local variables2="requires_both-oval.xml-0.variables-2.xml"
	local stderr=$(mktemp -t ${FUNCNAME}.err.XXXXXX)
	echo "Stderr file = $stderr"

	[ ! -f $variables0 ] || rm $variables0
	[ ! -f $variables1 ] || rm $variables1
	[ ! -f $variables2 ] || rm $variables2
	$OSCAP xccdf export-oval-variables --profile xccdf_moc.elpmaxe.www_profile_2 \
		$srcdir/test_xccdf_variable_instance.xccdf.xml 2>&1 > $stderr
	[ -f $stderr ]; [ ! -s $stderr ]
	[ -f $variables0 ]
	[ -f $variables1 ]
	[ ! -f $variables2 ]
	$OSCAP oval validate $variables0
	$OSCAP oval validate $variables1
	local result="$variables0"
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 1 '/oval_variables/variables/variable'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 1 '/oval_variables/variables/variable/value'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="300"]'
	result="$variables1"
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 1 '/oval_variables/variables/variable'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 1 '/oval_variables/variables/variable/value'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="600"]'
	rm $stderr
	rm $variables0
	rm $variables1
}

#
# Export a single value from XCCDF to a single OVAL variable twice.
#
function xccdf_export_3_twice_same(){
	local variables0="requires_both-oval.xml-0.variables-0.xml"
	local variables1="requires_both-oval.xml-0.variables-1.xml"
	local stderr=$(mktemp -t ${FUNCNAME}.err.XXXXXX)
	echo "Stderr file = $stderr"

	[ ! -f $variables0 ] || rm $variables0
	[ ! -f $variables1 ] || rm $variables1
	$OSCAP xccdf export-oval-variables --profile xccdf_moc.elpmaxe.www_profile_3 \
		$srcdir/test_xccdf_variable_instance.xccdf.xml 2>&1 > $stderr
	[ -f $stderr ]; [ ! -s $stderr ]
	[ -f $variables0 ]
	[ ! -f $variables1 ]
	$OSCAP oval validate $variables0
	local result="$variables0"
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 1 '/oval_variables/variables/variable'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 1 '/oval_variables/variables/variable/value'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="300"]'
	rm $stderr
	rm $variables0
}

#
# Export the very same value twice in the same batch. The behaviour seems
# undefined, although OpenSCAP chooses to export a single value to OVAL
#
function xccdf_export_4_two_same(){
	local variables0="requires_both-oval.xml-0.variables-0.xml"
	local variables1="requires_both-oval.xml-0.variables-1.xml"
	local stderr=$(mktemp -t ${FUNCNAME}.err.XXXXXX)
	echo "Stderr file = $stderr"

	[ ! -f $variables0 ] || rm $variables0
	[ ! -f $variables1 ] || rm $variables1
	$OSCAP xccdf export-oval-variables --profile xccdf_moc.elpmaxe.www_profile_4 \
		$srcdir/test_xccdf_variable_instance.xccdf.xml 2>&1 > $stderr
	[ -f $stderr ]; [ ! -s $stderr ]
	[ -f $variables0 ]
	[ ! -f $variables1 ]
	$OSCAP oval validate $variables0
	local result="$variables0"
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 1 '/oval_variables/variables/variable'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 1 '/oval_variables/variables/variable/value'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="300"]'
	rm $stderr
	rm $variables0
}

#
# Export two variable sets (the very same) from XCCDF to OVAL.
#
function xccdf_export_5_multival_twice(){
	local variables0="requires_both-oval.xml-0.variables-0.xml"
	local variables1="requires_both-oval.xml-0.variables-1.xml"
	local stderr=$(mktemp -t ${FUNCNAME}.err.XXXXXX)
	echo "Stderr file = $stderr"

	[ ! -f $variables0 ] || rm $variables0
	[ ! -f $variables1 ] || rm $variables1
	$OSCAP xccdf export-oval-variables --profile xccdf_moc.elpmaxe.www_profile_5 \
		$srcdir/test_xccdf_variable_instance.xccdf.xml 2>&1 > $stderr
	[ -f $stderr ]; [ ! -s $stderr ]
	[ -f $variables0 ]
	[ ! -f $variables1 ]
	$OSCAP oval validate $variables0
	local result="$variables0"
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 1 '/oval_variables/variables/variable'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 2 '/oval_variables/variables/variable/value'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="300"]'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="600"]'
	rm $stderr
	rm $variables0
}

#
# Export two distinct variable sets from XCCDF to OVAL.
#
function xccdf_export_6_multiset_multival(){
	local variables0="requires_both-oval.xml-0.variables-0.xml"
	local variables1="requires_both-oval.xml-0.variables-1.xml"
	local variables2="requires_both-oval.xml-0.variables-2.xml"
	local stderr=$(mktemp -t ${FUNCNAME}.err.XXXXXX)
	echo "Stderr file = $stderr"

	[ ! -f $variables0 ] || rm $variables0
	[ ! -f $variables1 ] || rm $variables1
	[ ! -f $variables2 ] || rm $variables2
	$OSCAP xccdf export-oval-variables --profile xccdf_moc.elpmaxe.www_profile_6 \
		$srcdir/test_xccdf_variable_instance.xccdf.xml 2>&1 > $stderr
	[ -f $stderr ]; [ ! -s $stderr ]
	[ -f $variables0 ]
	[ -f $variables1 ]
	[ ! -f $variables2 ]
	$OSCAP oval validate $variables0
	$OSCAP oval validate $variables1
	local result="$variables0"
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 1 '/oval_variables/variables/variable'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 2 '/oval_variables/variables/variable/value'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="300"]'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="600"]'
	result="$variables1"
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 1 '/oval_variables/variables/variable'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 2 '/oval_variables/variables/variable/value'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="200"]'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="400"]'
	rm $stderr
	rm $variables0
	rm $variables1
}

#
# Export the very same variable sets twice (the second value-set is shuffled
# but the tool should correctly recognize it is the same
#
function xccdf_export_7_shuffled_multival(){
	local variables0="requires_both-oval.xml-0.variables-0.xml"
	local variables1="requires_both-oval.xml-0.variables-1.xml"
	local stderr=$(mktemp -t ${FUNCNAME}.err.XXXXXX)
	echo "Stderr file = $stderr"

	[ ! -f $variables0 ] || rm $variables0
	[ ! -f $variables1 ] || rm $variables1
	$OSCAP xccdf export-oval-variables --profile xccdf_moc.elpmaxe.www_profile_7 \
		$srcdir/test_xccdf_variable_instance.xccdf.xml 2>&1 > $stderr
	[ -f $stderr ]; [ ! -s $stderr ]
	[ -f $variables0 ]
	[ ! -f $variables1 ]
	$OSCAP oval validate $variables0
	local result="$variables0"
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 1 '/oval_variables/variables/variable'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 4 '/oval_variables/variables/variable/value'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="300"]'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="600"]'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="200"]'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="400"]'
	rm $stderr
	rm $variables0
}

#
# Export the very same variable sets twice (the second value-set is shuffled
# and a different set of values is duplicated in each bunch.
#
function xccdf_export_8_shuffled_multival(){
	local variables0="requires_both-oval.xml-0.variables-0.xml"
	local variables1="requires_both-oval.xml-0.variables-1.xml"
	local stderr=$(mktemp -t ${FUNCNAME}.err.XXXXXX)
	echo "Stderr file = $stderr"

	[ ! -f $variables0 ] || rm $variables0
	[ ! -f $variables1 ] || rm $variables1
	$OSCAP xccdf export-oval-variables --profile xccdf_moc.elpmaxe.www_profile_8 \
		$srcdir/test_xccdf_variable_instance.xccdf.xml 2>&1 > $stderr
	[ -f $stderr ]; [ ! -s $stderr ]
	[ -f $variables0 ]
	[ ! -f $variables1 ]
	$OSCAP oval validate $variables0
	local result="$variables0"
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 1 '/oval_variables/variables/variable'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 3 '/oval_variables/variables/variable/value'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="300"]'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="600"]'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="200"]'
	rm $stderr
	rm $variables0
}

#
# Export two multivals, the first is subset of the second or third.
#
function xccdf_export_9_first_subset(){
	local variables0="requires_both-oval.xml-0.variables-0.xml"
	local variables1="requires_both-oval.xml-0.variables-1.xml"
	local variables2="requires_both-oval.xml-0.variables-2.xml"
	local stderr=$(mktemp -t ${FUNCNAME}.err.XXXXXX)
	echo "Stderr file = $stderr"

	[ ! -f $variables0 ] || rm $variables0
	[ ! -f $variables1 ] || rm $variables1
	[ ! -f $variables2 ] || rm $variables2
	$OSCAP xccdf export-oval-variables --profile xccdf_moc.elpmaxe.www_profile_9 \
		$srcdir/test_xccdf_variable_instance.xccdf.xml 2>&1 > $stderr
	[ -f $stderr ]; [ ! -s $stderr ]
	[ -f $variables0 ]
	[ -f $variables1 ]
	[ ! -f $variables2 ]
	$OSCAP oval validate $variables0
	$OSCAP oval validate $variables1
	local result="$variables0"
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 1 '/oval_variables/variables/variable'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 2 '/oval_variables/variables/variable/value'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="300"]'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="600"]'
	result="$variables1"
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 1 '/oval_variables/variables/variable'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 3 '/oval_variables/variables/variable/value'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="200"]'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="300"]'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="600"]'
	rm $stderr
	rm $variables0
	rm $variables1
}

#
# Export two multivals, the last is subset of the first two.
#
function xccdf_export_A_second_subset(){
	local variables0="requires_both-oval.xml-0.variables-0.xml"
	local variables1="requires_both-oval.xml-0.variables-1.xml"
	local variables2="requires_both-oval.xml-0.variables-2.xml"
	local stderr=$(mktemp -t ${FUNCNAME}.err.XXXXXX)
	echo "Stderr file = $stderr"

	[ ! -f $variables0 ] || rm $variables0
	[ ! -f $variables1 ] || rm $variables1
	[ ! -f $variables2 ] || rm $variables2
	$OSCAP xccdf export-oval-variables --profile xccdf_moc.elpmaxe.www_profile_10 \
		$srcdir/test_xccdf_variable_instance.xccdf.xml 2>&1 > $stderr
	[ -f $stderr ]; [ ! -s $stderr ]
	[ -f $variables0 ]
	[ -f $variables1 ]
	[ ! -f $variables2 ]
	$OSCAP oval validate $variables0
	$OSCAP oval validate $variables1
	local result="$variables0"
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 1 '/oval_variables/variables/variable'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 3 '/oval_variables/variables/variable/value'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="200"]'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="300"]'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="600"]'
	result="$variables1"
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 1 '/oval_variables/variables/variable'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 2 '/oval_variables/variables/variable/value'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="300"]'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="600"]'
	rm $stderr
	rm $variables0
	rm $variables1
}

#
# Evaluate XCCDF while exporting two values from XCCDF document to a single OVAL
# variable that it should result in multiple (two) variable sets each with a single
# value. This tests asserts for correctly collected system characteristics.
#
function xccdf_eval_2_multiset(){
	local variables0="requires_both-oval.xml-0.variables-0.xml"
	local variables1="requires_both-oval.xml-0.variables-1.xml"
	local variables2="requires_both-oval.xml-0.variables-2.xml"
	local oval_result="requires_both-oval.xml.result.xml"
	local xccdf_result=$(mktemp -t ${FUNCNAME}.xml.XXXXXX)
	local stderr=$(mktemp -t ${FUNCNAME}.err.XXXXXX)
	local profile="xccdf_moc.elpmaxe.www_profile_2"
	local tested_file="testing_file.xml"
	echo "Stderr file = $stderr"
	cp $srcdir/testing_file_300.xml $tested_file

	for f in $variables0 $variables1 $variables2 $oval_result $xccdf_result; do
		[ ! -f $f ] || rm $f
	done
	local res=0
	$OSCAP xccdf eval --profile $profile \
		--export-variables --oval-results --results $xccdf_result \
		$srcdir/test_xccdf_variable_instance.xccdf.xml 2> $stderr || res=$?
	[ $res -eq 2 ]
	[ -f $stderr ]; [ ! -s $stderr ]
	[ -f $variables0 ]
	[ -f $variables1 ]
	[ ! -f $variables2 ]
	$OSCAP oval validate $variables0
	$OSCAP oval validate $variables1
	$OSCAP oval validate $oval_result
	local result="$xccdf_result"
	assert_exists 1 '/Benchmark/TestResult'
	assert_exists 1 '/Benchmark/TestResult/profile'
	assert_exists 1 '/Benchmark/TestResult/profile/@*'
	assert_exists 1 '/Benchmark/TestResult/profile[@idref="'$profile'"]'
	assert_exists 2 '/Benchmark/TestResult/rule-result/result[text()!="notselected"]'
	assert_exists 1 '/Benchmark/TestResult/rule-result/result[text()="pass"]'
	assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_moc.elpmaxe.www_rule_2"]'
	assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_moc.elpmaxe.www_rule_2"]/result[text()="pass"]'
	assert_exists 0 '/Benchmark/TestResult/rule-result[@idref="xccdf_moc.elpmaxe.www_rule_2"]/message'
	assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_moc.elpmaxe.www_rule_2"]/check'
	assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_moc.elpmaxe.www_rule_2"]/check/check-export'
	assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_moc.elpmaxe.www_rule_2"]/check/check-export[@export-name="oval:com.example.www:var:1"]'
	assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_moc.elpmaxe.www_rule_2"]/check/check-export[@value-id="xccdf_moc.elpmaxe.www_value_1"]'
	assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_moc.elpmaxe.www_rule_2"]/check/check-content-ref'
	assert_exists 1 '/Benchmark/TestResult/rule-result/result[text()="fail"]'
	assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_moc.elpmaxe.www_rule_3"]'
	assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_moc.elpmaxe.www_rule_3"]/result[text()="fail"]'
	assert_exists 0 '/Benchmark/TestResult/rule-result[@idref="xccdf_moc.elpmaxe.www_rule_3"]/message'
	assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_moc.elpmaxe.www_rule_3"]/check'
	assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_moc.elpmaxe.www_rule_3"]/check/check-export'
	assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_moc.elpmaxe.www_rule_3"]/check/check-export[@export-name="oval:com.example.www:var:1"]'
	assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_moc.elpmaxe.www_rule_3"]/check/check-export[@value-id="xccdf_moc.elpmaxe.www_value_2"]'
	assert_exists 1 '/Benchmark/TestResult/rule-result[@idref="xccdf_moc.elpmaxe.www_rule_3"]/check/check-content-ref'
	result="$variables0"
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 1 '/oval_variables/variables/variable'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 1 '/oval_variables/variables/variable/value'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="300"]'
	result="$variables1"
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 1 '/oval_variables/variables/variable'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 1 '/oval_variables/variables/variable/value'
	assert_exists 1 '/oval_variables/variables/variable/value[text()="600"]'
	result="$oval_result"
	assert_exists 1 '/oval_results'
	assert_exists 1 '/oval_results/results'
	assert_exists 1 '/oval_results/results/system'
	assert_exists 1 '/oval_results/results/system/oval_system_characteristics'
	assert_exists 1 '/oval_results/results/system/oval_system_characteristics/generator'
	assert_exists 1 '/oval_results/results/system/oval_system_characteristics/system_info'
	assert_exists 1 '/oval_results/results/system/oval_system_characteristics/system_data'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item[count(*) = 5]'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:filepath'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:path'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:filename'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:xpath'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:value_of'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:value_of[text()="300"]'
	assert_exists 1 '/oval_results/results/system/oval_system_characteristics/collected_objects'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/collected_objects/object'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[count(@*) = 4]'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[@id="oval:com.example.www:obj:1"]'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[@version="1"]'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[@flag="complete"]'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[reference]'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[count(reference/@*) = 1]'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[reference/@item_ref]'
	assert_exists 1 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[@variable_instance="1"]'
	assert_exists 1 '/oval_results/results/system/oval_system_characteristics/collected_objects/object[@variable_instance="2"]'
	assert_exists 4 '/oval_results/results/system/oval_system_characteristics/*'
	assert_exists 1 '/oval_results/results/system/tests'
	assert_exists 3 '/oval_results/results/system/tests/test'
	assert_exists 3 '/oval_results/results/system/tests/test[@version="1"]'
	assert_exists 3 '/oval_results/results/system/tests/test[@check="at least one"]'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2"]'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2" and @result="not evaluated"]'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2" and count(*) = 0]'
	assert_exists 2 '/oval_results/results/system/tests/test[count(*) = 2]'
	assert_exists 2 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:1"]'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:1" and @result="true"]'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:1" and not(@variable_instance)]'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:1" and not(@variable_instance) and @result="true"]'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:1" and @result="false"]'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:1" and @variable_instance="2"]'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:1" and @variable_instance="2" and @result="false"]'
	assert_exists 2 '/oval_results/results/system/tests/test/tested_item'
	assert_exists 4 '/oval_results/results/system/tests/test/tested_item/@*'
	assert_exists 2 '/oval_results/results/system/tests/test/tested_item/@item_id'
	assert_exists 1 '/oval_results/results/system/tests/test/tested_item[@result="true"]'
	assert_exists 1 '/oval_results/results/system/tests/test/tested_item[@result="false"]'
	assert_exists 2 '/oval_results/results/system/tests/test/tested_variable'
	assert_exists 2 '/oval_results/results/system/tests/test/tested_variable[@variable_id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_results/results/system/tests/test/tested_variable[text()="300"]'
	assert_exists 1 '/oval_results/results/system/tests/test/tested_variable[text()="600"]'
	assert_exists 1 '/oval_results/results/system/definitions'
	assert_exists 3 '/oval_results/results/system/definitions/*'
	assert_exists 3 '/oval_results/results/system/definitions/definition'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:com.example.www:def:2"]'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:com.example.www:def:2" and not(@variable_instance)]'
	assert_exists 2 '/oval_results/results/system/definitions/definition[@definition_id="oval:com.example.www:def:1"]'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@variable_instance="2"]'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@variable_instance="2"]/criteria'
	assert_exists 2 '/oval_results/results/system/definitions/definition[@variable_instance="2"]/criteria/@*'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@variable_instance="2"]/criteria[@operator="AND"]'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@variable_instance="2"]/criteria[@result="false"]'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@variable_instance="2"]/criteria/criterion'
	assert_exists 3 '/oval_results/results/system/definitions/definition[@variable_instance="2"]/criteria/criterion/@*'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@variable_instance="2"]/criteria/criterion[@test_ref="oval:com.example.www:tst:1"]'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@variable_instance="2"]/criteria/criterion[@version="1"]'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@variable_instance="2"]/criteria/criterion[@result="false"]'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@variable_instance="1"]'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@variable_instance="1"]/criteria'
	assert_exists 2 '/oval_results/results/system/definitions/definition[@variable_instance="1"]/criteria/@*'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@variable_instance="1"]/criteria[@operator="AND"]'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@variable_instance="1"]/criteria[@result="true"]'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@variable_instance="1"]/criteria/criterion'
	assert_exists 3 '/oval_results/results/system/definitions/definition[@variable_instance="1"]/criteria/criterion/@*'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@variable_instance="1"]/criteria/criterion[@test_ref="oval:com.example.www:tst:1"]'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@variable_instance="1"]/criteria/criterion[@version="1"]'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@variable_instance="1"]/criteria/criterion[@result="true"]'
	assert_exists 3 '/oval_results/results/system/*'
	rm $stderr
	rm $xccdf_result
	rm $oval_result
	rm $variables0
	rm $variables1
	chmod u+w $tested_file ; rm $tested_file
}

#
# Evaluate XCCDF while exporting two values from XCCDF document to a single OVAL
# variable that it should result in multiple (two) variable sets each with a single
# value. This tests asserts for correctly collected system characteristics.
#
function xccdf_eval_1_multiset_syschar(){
	local variables0="requires_both-oval.xml-0.variables-0.xml"
	local variables1="requires_both-oval.xml-0.variables-1.xml"
	local variables2="requires_both-oval.xml-0.variables-2.xml"
	local oval_result="requires_both-oval.xml.result.xml"
	local xccdf_result=$(mktemp -t ${FUNCNAME}.xml.XXXXXX)
	local stderr=$(mktemp -t ${FUNCNAME}.err.XXXXXX)
	local profile="xccdf_moc.elpmaxe.www_profile_11"
	local file300="testing_file_300x.xml"
	local file600="testing_file_600x.xml"
	echo "Stderr file = $stderr"

	cp $srcdir/testing_file_300.xml $file300
	cp $srcdir/testing_file_600.xml $file600
	for f in $variables0 $variables1 $variables2 $oval_result $xccdf_result; do
		[ ! -f $f ] || rm $f
	done

	# Creating files in ./ directory for distcheck
	$OSCAP xccdf eval --profile $profile \
		--export-variables --oval-results --results $xccdf_result \
		$srcdir/test_xccdf_variable_instance.xccdf.xml 2> $stderr
	[ -f $stderr ]; [ ! -s $stderr ]
	[ -f $variables0 ]
	[ -f $variables1 ]
	[ ! -f $variables2 ]
	$OSCAP oval validate $variables0
	$OSCAP oval validate $variables1
	$OSCAP oval validate $oval_result
	result="$variables0"
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 2 '/oval_variables/variables/variable'
	assert_exists 2 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]/value'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]/value[text()="300"]'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:2"]'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:2"]/value'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:2"]/value[text()="./'$file300'"]'
	result="$variables1"
	assert_exists 1 '/oval_variables'
	assert_exists 1 '/oval_variables/variables'
	assert_exists 2 '/oval_variables/variables/variable'
	assert_exists 2 '/oval_variables/variables/variable[@datatype="string"]'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]/value'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:1"]/value[text()="600"]'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:2"]'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:2"]/value'
	assert_exists 1 '/oval_variables/variables/variable[@id="oval:com.example.www:var:2"]/value[text()="./'$file600'"]'
	result="$oval_result"
	assert_exists 1 '/oval_results'
	assert_exists 1 '/oval_results/results'
	assert_exists 1 '/oval_results/results/system'
	assert_exists 1 '/oval_results/results/system/oval_system_characteristics'
	assert_exists 1 '/oval_results/results/system/oval_system_characteristics/generator'
	assert_exists 1 '/oval_results/results/system/oval_system_characteristics/system_info'
	assert_exists 1 '/oval_results/results/system/oval_system_characteristics/system_data'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/*'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item[count(*) = 5]'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item[count(@*) = 2]'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item[@status="exists"]'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:filepath'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:path'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:filename'
	assert_exists 1 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:filename[text()="'$file600'"]'
	assert_exists 1 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:filename[text()="'$file300'"]'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:xpath'
	assert_exists 2 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:value_of'
	assert_exists 1 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:value_of[text()="300"]'
	assert_exists 1 '/oval_results/results/system/oval_system_characteristics/system_data/ind-sys:xmlfilecontent_item/ind-sys:value_of[text()="600"]'
	assert_exists 1 '/oval_results/results/system/tests'
	assert_exists 3 '/oval_results/results/system/tests/test'
	assert_exists 3 '/oval_results/results/system/tests/test[@version="1"]'
	assert_exists 3 '/oval_results/results/system/tests/test[@check="at least one"]'
	assert_exists 2 '/oval_results/results/system/tests/test[count(*) = 3]'

	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:1"]'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:1" and @result="not evaluated"]'
	assert_exists 0 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:1"]/*'
	assert_exists 2 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2"]'
	assert_exists 2 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2"][tested_item]'
	assert_exists 2 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2"][tested_item/@result = "true"]'
	assert_exists 2 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2" and @result="true"]'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2" and not(@variable_instance)]'
	assert_exists 2 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2" and not(@variable_instance)]/tested_variable'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2" and not(@variable_instance)]/tested_variable[@variable_id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2" and not(@variable_instance)]/tested_variable[@variable_id="oval:com.example.www:var:1" and text() = "300"]'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2" and not(@variable_instance)]/tested_variable[@variable_id="oval:com.example.www:var:2"]'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2" and not(@variable_instance)]/tested_variable[@variable_id="oval:com.example.www:var:2" and text() = "./'$file300'"]'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2" and @variable_instance="2"]'
	assert_exists 2 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2" and @variable_instance="2"]/tested_variable'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2" and @variable_instance="2"]/tested_variable[@variable_id="oval:com.example.www:var:1"]'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2" and @variable_instance="2"]/tested_variable[@variable_id="oval:com.example.www:var:1" and text() = "600"]'
	assert_exists 1 '/oval_results/results/system/tests/test[@test_id="oval:com.example.www:tst:2" and @variable_instance="2"]/tested_variable[@variable_id="oval:com.example.www:var:2" and text() = "./'$file600'"]'
	assert_exists 1 '/oval_results/results/system/definitions'
	assert_exists 3 '/oval_results/results/system/definitions/*'
	assert_exists 3 '/oval_results/results/system/definitions/definition'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:com.example.www:def:1"]'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:com.example.www:def:1" and not(@variable_instance)]'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:com.example.www:def:1" and @result="not evaluated"]'
	assert_exists 2 '/oval_results/results/system/definitions/definition[@definition_id="oval:com.example.www:def:2"]'
	assert_exists 2 '/oval_results/results/system/definitions/definition[@definition_id="oval:com.example.www:def:2" and @result="true"]'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:com.example.www:def:2" and @variable_instance="1"]'
	assert_exists 1 '/oval_results/results/system/definitions/definition[@definition_id="oval:com.example.www:def:2" and @variable_instance="2"]'
	assert_exists 3 '/oval_results/results/system/*'
	rm $stderr
	rm $xccdf_result
	rm $oval_result
	rm $variables0
	rm $variables1
	for f in $file300 $file600; do
		chmod u+w $f ; rm $f
	done
}

test_init test_api_xccdf_variable_instance.log

test_run "Export from XCCDF to variables: 1x2 values (multival)" xccdf_export_1_multival
test_run "Export from XCCDF to variables: 2x1 values (multiset)" xccdf_export_2_multiset
test_run "Export from XCCDF to variables: 1x2 same vales (none)" xccdf_export_4_two_same
test_run "Export from XCCDF to variables: 2x1 same value (none)" xccdf_export_3_twice_same
test_run "Export from XCCDF to variables: 2x2 values (multiset,multival)" xccdf_export_6_multiset_multival
test_run "Export from XCCDF to variables: 2x2 same values (multival)" xccdf_export_5_multival_twice
test_run "Export from XCCDF to variables: 2x4 same shuffled values (multival)" xccdf_export_7_shuffled_multival
test_run "Export from XCCDF to variables: 2x4 same shuffled repeating values (multival)" xccdf_export_8_shuffled_multival
test_run "Export from XCCDF to variables: 3x3 the first is subset (multiset,multival)" xccdf_export_9_first_subset
test_run "Export from XCCDF to variables: 3x3 the last is subset (multiset,multival)" xccdf_export_A_second_subset

test_run "Evaluate XCCDF: 2x1 values (multiset)" xccdf_eval_2_multiset
test_run "Evaluate XCCDF: 2x1 values (multiset) in syschar" xccdf_eval_1_multiset_syschar

test_exit