1#! /usr/bin/env atf-sh 2 3. $(atf_get_srcdir)/test_environment.sh 4 5tests_init \ 6 create_from_plist \ 7 create_from_plist_set_owner \ 8 create_from_plist_set_group_space \ 9 create_from_plist_gather_mode \ 10 create_from_plist_set_mode \ 11 create_from_plist_mini \ 12 create_from_plist_fflags create_from_plist_bad_fflags \ 13 create_from_plist_with_keyword_arguments \ 14 create_from_manifest_and_plist \ 15 create_from_manifest \ 16 create_from_manifest_dir \ 17 create_from_plist_pkg_descr \ 18 create_from_plist_hash \ 19 create_from_plist_with_keyword_and_message \ 20 create_from_plist_include \ 21 create_with_hardlink \ 22 create_no_clobber \ 23 time \ 24 create_from_plist_keyword_validation \ 25 create_from_plist_keyword_real_args \ 26 create_from_plist_keyword_lua_actions \ 27 create_from_plist_keyword_deprecated 28 29genmanifest() { 30 cat << EOF >> +MANIFEST 31name: test 32origin: test 33version: 1 34maintainer: test 35categories: [test] 36comment: a test 37www: http://test 38prefix: / 39abi = "*"; 40desc: <<EOD 41Yet another test 42EOD 43EOF 44} 45 46genplist() { 47 cat << EOF >> test.plist 48$@ 49EOF 50} 51 52preparetestcredentials() { 53 touch file1 54 55 genmanifest 56 genplist "@$1 file1" 57} 58 59basic_validation() { 60 test -f test-1.pkg || atf_fail "Package not created" 61} 62 63create_with_hardlink_body() { 64 atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1.0" 65 echo "blah" >> foo 66 ln foo bar 67 echo "@(root,wheel,0555,) /foo" >> test.plist 68 echo "@config(root,wheel,0644,) /bar" >> test.plist 69 70 atf_check \ 71 -o ignore \ 72 -e ignore \ 73 pkg create -M test.ucl -p test.plist -r . 74} 75 76create_from_plist_body() { 77 touch file1 78 genmanifest 79 genplist "file1" 80 81 atf_check \ 82 -o empty \ 83 -e empty \ 84 -s exit:0 \ 85 pkg create -o ${TMPDIR} -m . -p test.plist -r . 86 87 basic_validation 88 atf_check \ 89 -o match:"-rw-r--r-- .*root[ /]+wheel.* /file1$" \ 90 -e ignore \ 91 -s exit:0 \ 92 bsdtar tvf test-1.pkg 93} 94 95create_from_plist_set_owner_body() { 96 97 preparetestcredentials "(plop,,)" 98 99 atf_check \ 100 -o empty \ 101 -e empty \ 102 -s exit:0 \ 103 pkg create -o ${TMPDIR} -m . -p test.plist -r . 104 105 basic_validation 106 atf_check \ 107 -o match:"-rw-r--r-- .*plop[ /]+wheel.* /file1$" \ 108 -e ignore \ 109 -s exit:0 \ 110 bsdtar tvf test-1.pkg 111} 112 113create_from_plist_set_group_body() { 114 115 preparetestcredentials "(,bla,)" 116 117 atf_check \ 118 -o empty \ 119 -e empty \ 120 -s exit:0 \ 121 pkg create -o ${TMPDIR} -m . -p test.plist -r . 122 123 basic_validation 124 atf_check \ 125 -o match:"-rw-r--r-- .*root[ /]+bla.* /file1$" \ 126 -e ignore \ 127 -s exit:0 \ 128 bsdtar tvf test-1.pkg 129} 130 131 132create_from_plist_set_group_space_body() { 133 134 preparetestcredentials "(, bla,)" 135 136 atf_check \ 137 -o empty \ 138 -e empty \ 139 -s exit:0 \ 140 pkg create -o ${TMPDIR} -m . -p test.plist -r . 141 142 basic_validation 143 atf_check \ 144 -o match:"-rw-r--r-- .*root[ /]+bla.* /file1$" \ 145 -e ignore \ 146 -s exit:0 \ 147 bsdtar tvf test-1.pkg 148} 149 150create_from_plist_gather_mode_body() { 151 152 preparetestcredentials "(plop,bla,)" 153 154 chmod 777 file1 || atf_fail "Impossible to change mode" 155 156 atf_check \ 157 -o empty \ 158 -e empty \ 159 -s exit:0 \ 160 pkg create -o ${TMPDIR} -m . -p test.plist -r . 161 162 basic_validation 163 atf_check \ 164 -o match:"-rwxrwxrwx .*plop[ /]+bla.* /file1$" \ 165 -e ignore \ 166 -s exit:0 \ 167 bsdtar tvf test-1.pkg 168} 169 170create_from_plist_set_mode_body() { 171 172 preparetestcredentials "(,,2755)" 173 174 atf_check \ 175 -o empty \ 176 -e empty \ 177 -s exit:0 \ 178 pkg create -o ${TMPDIR} -m . -p test.plist -r . 179 180 basic_validation 181 atf_check \ 182 -o match:"-rwxr-sr-x .*root[ /]+wheel.* /file1$" \ 183 -e ignore \ 184 -s exit:0 \ 185 bsdtar tvf test-1.pkg 186} 187 188create_from_plist_mini_body() { 189 190 preparetestcredentials "(plop,)" 191 192 atf_check \ 193 -o empty \ 194 -e empty \ 195 -s exit:0 \ 196 pkg create -o ${TMPDIR} -m . -p test.plist -r . 197 198 basic_validation 199 atf_check \ 200 -o match:"-rw-r--r-- .*plop[ /]+wheel.* /file1$" \ 201 -e ignore \ 202 -s exit:0 \ 203 bsdtar tvf test-1.pkg 204} 205 206create_from_plist_fflags_body() { 207 atf_skip_on Linux does not support fflags 208 preparetestcredentials "(,,,schg)" 209 210 atf_check \ 211 -o empty \ 212 -e empty \ 213 -s exit:0 \ 214 pkg create -o ${TMPDIR} -m . -p test.plist -r . 215} 216 217create_from_plist_bad_fflags_body() { 218 atf_skip_on Linux does not support fflags 219 preparetestcredentials "(,,,schg,bad)" 220 221 atf_check \ 222 -o empty \ 223 -e inline:"${PROGNAME}: Malformed keyword '', wrong fflags\n${PROGNAME}: Malformed keyword @(,,,schg,bad) file1, expecting @keyword or @keyword(owner,group,mode)\n" \ 224 -s exit:1 \ 225 pkg create -o ${TMPDIR} -m . -p test.plist -r . 226} 227 228create_from_plist_keyword_real_args_body() { 229 preparetestcredentials "test" 230 231cat << EOF > test.ucl 232actions: [] 233arguments: true 234post-install-lua: <<EOS 235if arg ~= nil then 236 print("yes") 237end 238for i = 1, #arg do 239 print(arg[i]) 240end 241EOS 242EOF 243 244 genplist "@test A B C D" 245 246mkdir target 247 248 atf_check \ 249 pkg -o PLIST_KEYWORDS_DIR=. create -o ${TMPDIR} -m . -p test.plist -r . 250 251 atf_check \ 252 -o inline:"yes\nfile1\nyes\nA\nB\nC\nD\n" \ 253 pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy ${TMPDIR}/test-1.pkg 254} 255 256create_from_plist_keyword_validation_body() { 257 preparetestcredentials "test" 258 259cat << EOF > test.ucl 260actions: [] 261prepackaging: <<EOS 262io.stderr:write("meh\n") 263return 1 264EOS 265EOF 266 atf_check \ 267 -o empty \ 268 -e inline:"meh\n${PROGNAME}: Fail to apply keyword 'test'\n" \ 269 -s exit:1 \ 270 pkg -o PLIST_KEYWORDS_DIR=. create -o ${TMPDIR} -m . -p test.plist -r . 271 272cat << EOF > test.ucl 273actions: [] 274prepackaging: <<EOS 275print(line) 276io.stderr:write("meh\n") 277return 1 278EOS 279EOF 280 atf_check \ 281 -o inline:"file1\n" \ 282 -e inline:"meh\n${PROGNAME}: Fail to apply keyword 'test'\n" \ 283 -s exit:1 \ 284 pkg -o PLIST_KEYWORDS_DIR=. create -o ${TMPDIR} -m . -p test.plist -r . 285 286cat << EOF > test.ucl 287actions: [] 288prepackaging: <<EOS 289print(#arg) 290io.stderr:write("meh\n") 291return 1 292EOS 293EOF 294 atf_check \ 295 -o inline:"0\n" \ 296 -e inline:"meh\n${PROGNAME}: Fail to apply keyword 'test'\n" \ 297 -s exit:1 \ 298 pkg -o PLIST_KEYWORDS_DIR=. create -o ${TMPDIR} -m . -p test.plist -r . 299 300cat << EOF > test.ucl 301actions: [] 302arguments: true 303prepackaging: <<EOS 304print(#arg) 305io.stderr:write("meh\n") 306return 1 307EOS 308EOF 309 atf_check \ 310 -o inline:"1\n" \ 311 -e inline:"meh\n${PROGNAME}: Fail to apply keyword 'test'\n" \ 312 -s exit:1 \ 313 pkg -o PLIST_KEYWORDS_DIR=. create -o ${TMPDIR} -m . -p test.plist -r . 314 315 genplist "@test A B" 316 genplist "@test A A" 317 genplist "@test A B C" 318cat << EOF > test.ucl 319actions: [] 320arguments: true 321prepackaging: <<EOS 322if #arg == 1 then 323 return 0 324end 325if #arg == 2 then 326 if arg[1] == arg[2] then 327 io.stderr:write("The first and the second argument are identical\n") 328 return 1 329 end 330 return 1 331end 332io.stderr:write("Invalid number of arguments '".. #arg .. "' expecting 1 or 2\n") 333return 1 334EOS 335EOF 336output="${PROGNAME}: Fail to apply keyword 'test' 337The first and the second argument are identical 338${PROGNAME}: Fail to apply keyword 'test' 339Invalid number of arguments '3' expecting 1 or 2 340${PROGNAME}: Fail to apply keyword 'test' 341" 342 atf_check \ 343 -e inline:"${output}" \ 344 -s exit:1 \ 345 pkg -o PLIST_KEYWORDS_DIR=. create -o ${TMPDIR} -m . -p test.plist -r . 346} 347 348create_from_plist_with_keyword_arguments_body() { 349 preparetestcredentials "testkeyword" 350 351 atf_check \ 352 -o empty \ 353 -e inline:"${PROGNAME}: cannot load keyword from ./testkeyword.ucl: No such file or directory\n${PROGNAME}: unknown keyword testkeyword: @testkeyword\n" \ 354 -s exit:1 \ 355 pkg -o PLIST_KEYWORDS_DIR=. create -o ${TMPDIR} -m . -p test.plist -r . 356 357cat << EOF >> testkeyword.ucl 358actions: [] 359arguments: true 360post-install: 361 echo %1 %2 362EOF 363 364 atf_check \ 365 -o empty \ 366 -e inline:"${PROGNAME}: Requesting argument %2 while only 1 arguments are available\n${PROGNAME}: Fail to apply keyword 'testkeyword'\n" \ 367 -s exit:1 \ 368 pkg -o PLIST_KEYWORDS_DIR=. create -o ${TMPDIR} -m . -p test.plist -r . 369 370cat << EOF > testkeyword.ucl 371actions: [file(%1)] 372arguments: true 373post-install: 374 echo %1 %2 375EOF 376 377 echo "@testkeyword A B" > test.plist 378 379 atf_check \ 380 -o empty \ 381 -e inline:"${PROGNAME}: Invalid argument: expecting a number got (%1)\n${PROGNAME}: Fail to apply keyword 'testkeyword'\n" \ 382 -s exit:1 \ 383 pkg -o PLIST_KEYWORDS_DIR=. create -o ${TMPDIR} -m . -p test.plist -r . 384 385cat << EOF > testkeyword.ucl 386actions: [file(1), dir(2)] 387arguments: true 388post-install: 389 echo %1 %2 390EOF 391 touch A 392 mkdir B 393 394 atf_check \ 395 -o empty \ 396 -e empty \ 397 -s exit:0 \ 398 pkg -o PLIST_KEYWORDS_DIR=. create -o ${TMPDIR} -m . -p test.plist -r . 399 400 atf_check \ 401 -o empty \ 402 -e empty \ 403 -s exit:0 \ 404 pkg -o PLIST_KEYWORDS_DIR=. create -o ${TMPDIR} -m . -p test.plist -r . 405 406cat << EOF >> output.ucl 407name = "test"; 408origin = "test"; 409version = "1"; 410comment = "a test"; 411maintainer = "test"; 412www = "http://test"; 413abi = "*"; 414arch = "*"; 415prefix = "/"; 416flatsize = 0; 417desc = "Yet another test"; 418categories [ 419 "test", 420] 421files { 422 /A = "1\$e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; 423} 424directories { 425 /B = "y"; 426} 427scripts { 428 post-install = "# args: A B\necho A B"; 429} 430 431EOF 432 433 atf_check \ 434 -o file:output.ucl \ 435 -e empty \ 436 -s exit:0 \ 437 pkg info -R --raw-format=ucl -F test-1.pkg 438} 439 440create_from_manifest_and_plist_body() { 441 genmanifest 442 touch testfile 443 genplist "testfile" 444 atf_check \ 445 -o empty \ 446 -e empty \ 447 -s exit:0 \ 448 pkg create -M ./+MANIFEST -p test.plist -r ${TMPDIR} 449 450 cat << EOF > output.ucl 451name = "test"; 452origin = "test"; 453version = "1"; 454comment = "a test"; 455maintainer = "test"; 456www = "http://test"; 457abi = "*"; 458arch = "*"; 459prefix = "/"; 460flatsize = 0; 461desc = "Yet another test"; 462categories [ 463 "test", 464] 465files { 466 /testfile = "1\$e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; 467} 468 469EOF 470 471 atf_check \ 472 -o file:output.ucl \ 473 -e empty \ 474 -s exit:0 \ 475 pkg info -R --raw-format=ucl -F test-1.pkg 476} 477 478create_from_manifest_body() { 479 genmanifest 480 cat <<EOF >> +MANIFEST 481files: { 482 /testfile: {perm: 0644} 483} 484EOF 485 touch testfile 486 atf_check \ 487 -o empty \ 488 -e empty \ 489 -s exit:0 \ 490 pkg create -M ./+MANIFEST -r ${TMPDIR} 491 492 cat << EOF > output.ucl 493name = "test"; 494origin = "test"; 495version = "1"; 496comment = "a test"; 497maintainer = "test"; 498www = "http://test"; 499abi = "*"; 500arch = "*"; 501prefix = "/"; 502flatsize = 0; 503desc = "Yet another test"; 504categories [ 505 "test", 506] 507files { 508 /testfile = "1\$e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; 509} 510 511EOF 512 513 atf_check \ 514 -o file:output.ucl \ 515 -e empty \ 516 -s exit:0 \ 517 pkg info -R --raw-format=ucl -F test-1.pkg 518} 519 520create_from_manifest_dir_body() { 521 genmanifest 522 cat <<EOF >> +MANIFEST 523files: { 524 /testfile: {perm: 0644} 525 /testdir: {perm: 0644} 526} 527EOF 528 touch testfile 529 mkdir testdir 530 atf_check \ 531 -o empty \ 532 -e not-empty \ 533 -s not-exit:0 \ 534 pkg create -M ./+MANIFEST -r ${TMPDIR} 535 536} 537 538create_from_plist_pkg_descr_body() { 539 genmanifest 540cat << EOF > ./+DISPLAY 541Message 542EOF 543 544OUTPUT="test-1: 545Always: 546Message 547 548" 549 atf_check pkg create -m . -r ${TMPDIR} 550 atf_check -o inline:"${OUTPUT}" pkg info -D -F ./test-1.pkg 551 552cat << EOF > ./+DISPLAY 553[ 554 { message: "message" }, 555 { message: "message upgrade", type = "upgrade" }, 556] 557EOF 558 559OUTPUT='test-1: 560Always: 561message 562 563On upgrade: 564message upgrade 565 566' 567 568 atf_check pkg create -m . -r ${TMPDIR} 569 atf_check -o inline:"${OUTPUT}" pkg info -D -F ./test-1.pkg 570 571} 572 573create_from_plist_hash_body() { 574 touch file1 575 genmanifest 576 genplist "file1" 577 578 atf_check \ 579 -o empty \ 580 -e empty \ 581 -s exit:0 \ 582 pkg create -h -o ${TMPDIR} -m . -p test.plist -r . 583 584 atf_check \ 585 -o ignore \ 586 -e empty \ 587 -s exit:0 \ 588 ls test-1-*.pkg 589} 590 591create_from_plist_with_keyword_and_message_body() { 592 genmanifest 593 genplist "@showmsg plop" 594cat << EOF > showmsg.ucl 595actions: [] 596messages: [ 597 { message: "always" }, 598 { message: "on upgrade";type = "upgrade" }, 599 { message: "on install"; type = "install" }, 600] 601EOF 602cat << EOF > +DISPLAY 603old message 604EOF 605 606OUTPUT='test-1: 607Always: 608old message 609 610Always: 611always 612 613On upgrade: 614on upgrade 615 616On install: 617on install 618 619' 620 atf_check pkg -o PLIST_KEYWORDS_DIR=. create -m . -r ${TMPDIR} -p test.plist 621 atf_check -o inline:"${OUTPUT}" pkg info -D -F ./test-1.pkg 622 623} 624 625time_body() { 626 atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1" 627 cat << EOF >> test.ucl 628files: { 629 "${TMPDIR}/a" = ""; 630} 631EOF 632 touch a 633 pattern=$(ls -l ${TMPDIR}/a | awk '{print $6" +"$7" +"$8".*/a"}') 634 atf_check pkg create -M test.ucl 635 atf_check env SOURCE_DATE_EPOCH=86400 pkg create -M test.ucl 636 atf_check \ 637 -o match:"0 Jan +2 +1970.*/a" \ 638 bsdtar tvf test-1.pkg 639 atf_check -e match:"Invalid" -s exit:1 pkg create -t meh -M test.ucl 640 atf_check pkg create -t 172800 -M test.ucl 641 atf_check \ 642 -o match:"0 Jan +3 +1970.*/a" \ 643 bsdtar tvf test-1.pkg 644 atf_check env SOURCE_DATE_EPOCH=86400 pkg create -t 172800 -M test.ucl 645 atf_check \ 646 -o match:"0 Jan +3 +1970.*/a" \ 647 bsdtar tvf test-1.pkg 648 atf_check pkg create -M test.ucl 649 atf_check \ 650 -o match:"${pattern}" \ 651 bsdtar tvf test-1.pkg 652 653 mkdir target 654 atf_check -o empty \ 655 pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy ${TMPDIR}/test-1.pkg 656 atf_check \ 657 -o match:"${pattern}" \ 658 ls -l ${TMPDIR}/target/${TMPDIR}/a 659} 660 661create_no_clobber_body() 662{ 663 atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1" 664 665 touch test-1.pkg 666 before=$(ls -l test-1.pkg) 667 atf_check pkg create -nM test.ucl 668 after=$(ls -l test-1.pkg) 669 [ "$before" = "$after" ] || atf_fail "Package was recreated \"$before\" vs \"$after\"" 670} 671 672create_from_plist_include_body() 673{ 674 genmanifest 675 cat << EOF >> test.plist 676file1 677@include other-plist 678file2 679EOF 680 cat <<EOF >> other-plist 681file3 682EOF 683 684 touch file1 685 touch file2 686 touch file3 687 688 atf_check \ 689 -s exit:0 \ 690 pkg create -o ${TMPDIR} -m . -p test.plist -r . 691 692 atf_check -o inline:"/file1\n/file3\n/file2\n" pkg info -ql -F test*.pkg 693 cat << EOF >> other-plist 694@include test.plist 695EOF 696 atf_check \ 697 -e inline:"pkg: Inside in @include it is not allowed to reuse @include\n" \ 698 -s exit:1 \ 699 pkg create -o ${TMPDIR} -m . -p test.plist -r . 700} 701 702create_from_plist_keyword_lua_actions_body() 703{ 704 genmanifest 705 genplist "@test(plop,,) A B C D" 706 707cat << EOF > test.ucl 708arguments: true 709prepackaging: <<EOS 710ok = true 711for i = 1, #arg do 712 if not pkg.file(arg[i]) then 713 ok = false 714 end 715end 716if not ok then 717 return 1 718end 719EOS 720arguments: true 721EOF 722 723touch C 724touch D 725 726output="${PROGNAME}: Unable to access file ./A:No such file or directory 727${PROGNAME}: Unable to access file ./B:No such file or directory 728${PROGNAME}: Fail to apply keyword 'test' 729" 730 731 atf_check \ 732 -e inline:"${output}" \ 733 -s exit:1 \ 734 pkg -o PLIST_KEYWORDS_DIR=. create -o ${TMPDIR} -m . -p test.plist -r . 735 736touch A B 737 atf_check \ 738 -s exit:0 \ 739 pkg -o PLIST_KEYWORDS_DIR=. create -o ${TMPDIR} -m . -p test.plist -r . 740 atf_check \ 741 -o match:"-rw-r--r-- .*plop[ /]+wheel.* /A$" \ 742 bsdtar tvf test-1.pkg 743} 744 745create_from_plist_keyword_deprecated_body() 746{ 747 genmanifest 748 genplist "@test A B C D" 749 750cat << EOF > test.ucl 751arguments: true 752deprecated: true 753EOF 754 755 atf_check \ 756 -e inline:"${PROGNAME}: Use of '@test' is deprecated\n" \ 757 -s exit:0 \ 758 pkg -o PLIST_KEYWORDS_DIR=. create -o ${TMPDIR} -m . -p test.plist -r . 759 760cat << EOF > test.ucl 761arguments: true 762deprecated: true 763deprecation_message: <<EOM 764we don't like it anymore 765EOM 766EOF 767 768 atf_check \ 769 -e inline:"${PROGNAME}: Use of '@test' is deprecated: we don't like it anymore\n" \ 770 -s exit:0 \ 771 pkg -o PLIST_KEYWORDS_DIR=. create -o ${TMPDIR} -m . -p test.plist -r . 772 773} 774