2 # This script is uses ShUnit to test packaging/common/*. Currently
3 # it only tests the functions as they perform for rpm and deb building.
4 # As support is added for other styles of package, these tests should be
7 #######################
8 # If EXECUTING WITH ROOT ACCESS SCRIPT DELETES AND CREATES USERS.
9 # EXECUTE WITH CAUTION.
10 #######################
14 # Note on conflicting variable names:
15 # SHUNIT_* and SHU_* are shunit2 variables
16 # test_* should only be used by test functions.
17 # All other variables will probably be used by pre/post/common functions.
28 # shunit2 assumes shunit_inc, but we might run from a separate
29 # builddir. So try to use srcdir, as defined by automake, or
31 SHUNIT_INC="${srcdir=`pwd`}/packaging/common"; export SHUNIT_INC
32 TMPDIR=`pwd`/shunit-test; export TMPDIR
33 amanda_user=test_amandabackup; export amanda_user
34 amanda_group=test_disk; export amanda_group
35 sup_group="test_tape"; export sup_group
36 AMANDAHOMEDIR=$TMPDIR/amanda; export AMANDAHOMEDIR
37 AMANDATES=$AMANDAHOMEDIR/amandates; export AMANDATES
39 wanted_shell='/bin/false'; export wanted_shell
40 dist=Fedora; export dist
41 SYSCONFDIR=$TMPDIR/etc; export SYSCONFDIR
42 SBINDIR=$TMPDIR/sbin; export SBINDIR
43 encoder=`{ command -v base64 2>/dev/null; } || { command -v uuencode 2>/dev/null; }`
44 # Don't potentially conflict with a real value...
45 deb_uid=63000; export deb_uid
48 # Append stuff to this when you make temp files if they are outside TMPDIR
49 test_cleanup_files="$TMPDIR"; export test_cleanup_files
51 # This can't be part of one-time setup, because TMPDIR must exist before
53 mkdir -p ${TMPDIR} || exit 1
55 LOGFILE="$TMPDIR/test_sh_libs.log"
56 (umask 077 && touch $LOGFILE)
58 echo "Unable to create log file!"
64 msg_prefix="oneTimeSetUp: "
65 if [ "$IAmRoot" ]; then
66 # Delete an existing user.
67 echo "$msg_prefix attempting to delete an existing user."
68 userdel -f -r ${amanda_user}
69 # If the user exists, our tests will act wrong, so exit
70 grep "${amanda_user}" ${SYSCONFDIR}/passwd &> /dev/null || { \
71 echo "$msg_prefix ${amanda_user} still exists, or no ${SYSCONFDIR}/passwd.";
73 groupdel ${amanda_group} || exit 1
74 groupdel ${sup_group} || exit 1
76 echo "Not root, cleanup skipped"
78 # Make all directories which might be needed.
79 mkdir -p ${AMANDAHOMEDIR}/example
80 if [ ! "$IAmRoot" ]; then
81 mkdir -p ${SYSCONFDIR}/xinetd.d
82 mkdir -p ${SYSCONFDIR}/init.d
87 if [ ${__shunit_assertsFailed} -eq 0 ] && [ ! "${DEBUG}" ]; then
88 rm -rf $test_cleanup_files
90 echo "Check ${test_cleanup_files} for logs and error info."
94 test_cleanup_files="$LOGFILE ${test_cleanup_files}"
96 # shows syntax errors before the tests are run.
97 . ${SHUNIT_INC}/common_functions.sh
98 . ${SHUNIT_INC}/pre_inst_functions.sh
99 . ${SHUNIT_INC}/post_inst_functions.sh
100 . ${SHUNIT_INC}/post_rm_functions.sh
102 # Use this to skip root requiring tests.
103 # id -u is not portable to solaris.
104 tester_id=`id | sed 's/gid=\([0-9]*\).*/\1/'`
105 if [ "$tester_id" = "0" ]; then
106 # Same as SHUNIT_TRUE, but we can't use that yet...
112 # CAUTION: using real values if we are root.
113 if [ "$IAmRoot" ]; then
114 amanda_group=disk; export amanda_group
115 SYSCONFDIR=/etc; export SYSCONFDIR
116 SBINDDIR=/sbin; export SBINDDIR
119 # Source our mock utils.
120 . ${SHUNIT_INC}/mock_utils.sh
122 log_tail_no_stamp() {
123 # This strips the date off of a log line so only the message is
125 LOG_TAIL=`tail -1 ${LOGFILE}|cut -d " " -f 5-`
128 ######################################
131 # shUnit reorders tests alphabetically. We need the logger and cleanup tests
134 # Write a line to the log, test that it got there.
135 TEST_MSG="test___logger message"
136 LOG_LINE="`date +'%b %d %Y %T'`: ${TEST_MSG}"
137 # It's important for the log messages to be quoted, or funny stuff happens.
139 assertEquals "logger() return code" 0 $?
141 assertEquals "logger() did not write <${LOG_LINE}> " \
142 "${TEST_MSG}" "${LOG_TAIL}"
143 # Leave this outside the unit test framework. if the logger is
144 # broken we must exit.
145 if [ ! `grep -c "${LOG_LINE}" ${LOGFILE}` = "1" ]; then
146 echo "error: logger(): Incorrect content in ${LOGFILE}: " `cat ${LOGFILE}`
151 test__log_output_of() {
152 # Use log_output_of to append to the log
153 TEST_MSG="test__log_output_of message"
154 log_output_of echo "${TEST_MSG}"
155 assertEquals "log_output_of()" 0 $?
156 LOG_LINE="echo: ${TEST_MSG}"
158 assertEquals "log_output_of() message should be: " \
159 "${LOG_LINE}" "${LOG_TAIL}"
160 COUNT=`grep -c "${TEST_MSG}" ${LOGFILE}`
161 assertEquals "log_output_of(): incorrect content in log" \
163 # Leave this outside the unit test framework. if the logger is
164 # broken we must exit.
165 if [ ! ${COUNT} = '1' ]; then
166 echo "error: log_output_of(): Incorrect content in ${LOGFILE}: " `cat ${LOGFILE}`
172 # NOTE: check_xinetd and check_inetd tests end up simply duplicating the
173 # code of the function itself
176 logger "test_check_smf"
177 [ "$os" = "SunOS" ] || { startSkipping; echo "test_check_smf: skipped"; }
178 # Test existing service
179 touch ${MOCKDIR}/prexisting_service
181 assertEquals "check_smf preexisting services" 0 $?
182 rm ${MOCKDIR}/prexisting_service
184 assertEquals "check_smf no amanda service" 1 $?
187 test_check_superserver_running() {
188 logger "test_check_superserver_running"
189 [ "$IAmRoot" ] && { startSkipping; echo "test_check_superserver_running: skipped"; }
190 # Test the positive cases
191 # running changes the output of mocked ps
192 touch ${MOCKDIR}/running
193 check_superserver_running inetd
194 assertEquals "check_superserver_running inetd" 0 $?
195 assertSame "ps args: -e" "`cat $mock_ps_flags`"
196 if [ `uname` = 'Darwin' ]; then
197 [ "$IAmRoot" ] && startSkipping
198 check_superserver_running launchd
199 assertEquals "check_superserver_running launchd" 0 $?
200 assertSame "ps args: aux" "`cat $mock_ps_flags`"
204 check_superserver_running launchd
207 # Test the negative case, skip if root
208 [ "$IAmRoot" ] && startSkipping
209 rm ${MOCKDIR}/running
210 check_superserver_running inetd
211 assertEquals "check_superserver_running inetd returned 0 when inetd was not running" 1 $?
212 assertSame "ps args: -e" "`cat $mock_ps_flags`"
213 check_superserver_running xinetd
214 assertNotEquals "check_superserver_running xinetd incorrectly returned 0" \
216 assertSame "ps args: -e" "`cat $mock_ps_flags`"
219 test_backup_xinetd() {
220 logger "test_backup_xinetd"
221 touch ${SYSCONFDIR}/xinetd.d/amandaserver
222 backup_xinetd "amandaserver"
223 assertEquals "backup_xinetd returns 0" 0 $?
224 assertTrue "[ -f ${AMANDAHOMEDIR}/example/*.amandaserver.orig ]"
227 test_backup_inetd() {
228 logger "test_backup_inetd"
230 SunOS) inetd_dir=${SYSCONFDIR}/inet ;;
231 *) inetd_dir=${SYSCONFDIR} ;;
233 [ -d "${inetd_dir}" ] || mkdir -p ${inetd_dir}
234 touch ${inetd_dir}/inetd.conf
235 echo "amanda foo/bar/baz amandad" >> ${inetd_dir}/inetd.conf
237 assertEquals "backup_inetd returns 0" 0 $?
238 assertTrue "[ -f ${AMANDAHOMEDIR}/example/inetd.orig ]"
242 logger "test_backup_smf"
244 # TODO: how to mock this?
247 test_install_xinetd() {
248 logger "test_install_xinetd"
249 if [ "$os" = "SunOS" ] ; then
250 # Solaris has install_xinetd_sol
252 echo "test_install_xinetd: skipped"
256 touch ${MOCKDIR}/success
257 touch ${AMANDAHOMEDIR}/example/xinetd.amandaserver
258 install_xinetd "amandaserver"
259 assertEquals "install_xinetd returns 0" 0 $?
260 # Test "install" failure
261 rm ${MOCKDIR}/success
262 install_xinetd "amandaserver"
263 assertEquals "install_xinetd returns 1" 1 $?
266 test_install_inetd() {
267 logger "test_install_inetd"
269 SunOS) inetd_dir=${BASEDIR}/${SYSCONFDIR}/inet ;;
270 *) inetd_dir=${SYSCONFDIR} ;;
272 [ -f ${inetd_dir}/inetd.conf ] || touch ${inetd_dir}/inetd.conf
273 test_inetd_entry='amanda foo/bar/baz amandad'
274 if [ ! -f ${AMANDAHOMEDIR}/example/inetd.conf ]; then
275 echo "${test_inetd_entry}" > ${AMANDAHOMEDIR}/example/inetd.conf.amandaserver
277 install_inetd amandaserver
278 assertEquals "install_inetd returns 0" 0 $?
279 assertSame "${test_inetd_entry}" "`tail -1 ${inetd_dir}/inetd.conf`"
282 # TODO: test_install_smf() {
283 # Needs mocks for: inetconv, inetadm, svcadm.
285 test_reload_xinetd() {
286 logger "test_reload_xinetd"
287 # Might need init script.
288 if [ "$IAmRoot" ]; then
290 echo "test_reload_xinetd: skipped"
292 elif [ ! -f "${SYSCONFDIR}/init.d/xinetd" ]; then
293 mv ${MOCKDIR}/xinetd ${SYSCONFDIR}/init.d
297 assertEquals "reload_xinetd should reject argument 'foo'" 1 $?
299 touch ${MOCKDIR}/success
300 reload_xinetd "reload"
301 assertEquals "reload_xinetd" 0 $?
304 assertEquals "reload_xinetd should attempt to reload" 0 $?
305 flags=`cat ${mock_xinetd_flags}`
306 assertEquals "xinetd_flags should contain: " \
307 "xinetd args: reload" "${flags}"
309 rm ${MOCKDIR}/success
310 reload_xinetd "reload"
311 assertEquals "reload_xinetd" 1 $?
312 tail -4 ${LOGFILE}|grep "\<xinetd.*Attempting restart" >/dev/null
313 assertEquals "reload_xinetd should try to restart." 0 $?
314 reload_xinetd "restart"
315 assertEquals "restart should fail." 1 $?
316 tail -3 ${LOGFILE}|grep "restarting xinetd" >/dev/null
317 assertEquals "Should log attempt to restart" 0 $?
320 test_reload_inetd() {
321 logger "test_reload_inetd"
323 # Might need init script.
324 if [ ! "$IAmRoot" ]; then
325 if [ ! -f "${SYSCONFDIR}/init.d/inetd" ]; then
326 mv ${MOCKDIR}/inetd ${SYSCONFDIR}/init.d
331 assertEquals "reload_inetd should reject argument 'foo' (return 1):" 1 $?
333 touch ${MOCKDIR}/success
335 assertEquals "reload_inetd" 0 $?
337 rm ${MOCKDIR}/success
338 reload_inetd "reload"
339 assertEquals "reload_inetd" 1 $?
340 tail -4 ${LOGFILE}|grep "\<inetd.*Attempting restart" >/dev/null
341 assertEquals "reload_inetd should try to restart." 0 $?
342 reload_inetd "restart"
343 assertEquals "restart should fail." 1 $?
344 tail -3 ${LOGFILE}|grep "Restarting inetd" >/dev/null
345 assertEquals "Should log attempt to restart" 0 $?
349 ######################################
350 # pre_install_functions
352 test_check_user_group_missing() {
353 logger "test_check_user_group_missing no param"
355 assertNotEquals "'check_user_group' should fail" 0 $?
356 logger "test_check_user_group_missing missing group"
357 [ ! "$IAmRoot" ] && rm -f ${SYSCONFDIR}/group
358 touch ${SYSCONFDIR}/group
359 for os in linux osx solaris; do
360 echo $os > ${MOCKDIR}/id_os
361 check_user_group "abracadabra"
362 assertNotEquals "'check_user group abracadabra' should not be found:" 0 $?
364 assertEquals "check_user_group should write" \
365 "User's primary group 'abracadabra' does not exist" \
370 good_group_entry="${amanda_group}:x:100:"
371 export good_group_entry
372 test_check_user_group_exists() {
373 logger "test_check_user_group user and group exist"
374 touch ${MOCKDIR}/id_exists
375 touch ${SYSCONFDIR}/group
376 # Non-root adds and entry to the mock group file
377 [ ! "$IAmRoot" ] && echo $good_group_entry > ${SYSCONFDIR}/group
378 for os in linux osx solaris; do
379 echo $os > ${MOCKDIR}/id_os
381 # Case 1: Amanda_user is correct.
382 echo ${amanda_group} > ${MOCKDIR}/id_group
383 check_user_group "${amanda_group}"
384 assertEquals "'check_user_group ${amanda_group}': id returns correct groupname" \
387 # Case 2: Amanda_user is not a member of the the correct primary group.
388 rm ${MOCKDIR}/id_group
389 check_user_group "${amanda_group}"
390 assertEquals "'check_user_group ${amanda_group}' when not a member" 1 $?
394 test_check_user_supplemental_group_missing() {
395 logger "test_check_user_supplemental_group missing"
396 [ ! "$IAmRoot" ] && echo $good_group_entry > ${SYSCONFDIR}/group
397 for os in linux osx solaris; do
398 echo $os > ${MOCKDIR}/id_os
399 check_user_supplemental_group ${sup_group}
400 assertEquals "'check_user supplemental-group ${sup_group}' when group missing" \
405 missing_group_member="${sup_group}:x:105:nobody"
406 export missing_group_member
407 good_sup_group_entry="${missing_group_member},${amanda_user}"
408 export good_sup_group_entry
410 test_check_user_supplemental_group_exists() {
411 logger "test_check_user_supplemental_group exists"
412 [ ! "$IAmRoot" ] && echo $missing_group_member > ${SYSCONFDIR}/group
413 check_user_supplemental_group ${sup_group}
414 assertEquals "'check_user_supplemental_group ${sup_group}' when amanda_user is not a member" \
417 [ ! "$IAmRoot" ] && echo ${good_sup_group_entry} > ${SYSCONFDIR}/group
418 check_user_supplemental_group ${sup_group}
419 assertEquals "'check_user_supplemental_group ${sup_group}' with correct membership" \
422 test_check_user_shell() {
423 logger "test_check_user_shell"
424 if [ ! "$IAmRoot" ]; then
425 echo "${good_passwd_entry}" > ${SYSCONFDIR}/passwd
427 # Case 1: Provide a matching shell
428 check_user_shell "/bin/bash"
429 assertEquals "check_user_shell /bin/bash (matching)" 0 $?
430 # Case 2: Provide a non-matching shell.
431 check_user_shell "/bin/ksh"
432 assertEquals "check_user_shell /bin/ksh (not matching)" 1 $?
435 test_check_user_homedir() {
436 logger 'test_check_user_homedir'
437 if [ ! "$IAmRoot" ]; then
438 echo "${good_passwd_entry}" > ${SYSCONFDIR}/passwd
440 # Case 1: Assume amanda_user is correct.
441 check_user_homedir "${AMANDAHOMEDIR}"
442 assertEquals "check_user_homedir ${AMANDAHOMEDIR}" 0 $?
443 # Case 2: Provide an incorrect homedir
444 check_user_homedir "/tmp"
445 assertEquals "check_user_homedir /tmp" 1 $?
448 test_check_user_uid() {
449 echo "${amanda_group}" > ${MOCKDIR}/id_group
450 touch ${MOCKDIR}/id_exists
451 logger 'test_check_user_uid'
452 for os in linux osx solaris; do
453 echo $os > ${MOCKDIR}/id_os
455 assertEquals "check_user_uid without a uid" 1 $?
456 logger 'test_check_user_uid wrong id'
458 assertEquals "check_user_uid uids don't match" 1 $?
459 logger 'test_check_user_uid correct id'
460 check_user_uid ${deb_uid}
464 test_check_homedir_dir_missing() {
465 logger "test_check_homedir_dir_missing"
466 # First make sure the dir is missing
467 rm -rf ${AMANDAHOMEDIR}
469 assertNotEquals "check_homedir returned 0, but homedir did not exist" 0 $?
472 # passwd file entry for Linux systems, maybe others. UID is correct
473 # for Debian as well.
474 good_passwd_entry="${amanda_user}:x:${mock_deb_uid}:6::${AMANDAHOMEDIR}:/bin/bash"
475 export good_passwd_entry
477 logger "test_create_user"
478 if [ ! "$IAmRoot" ]; then
480 echo "test_create_user: Creating mock passwd file."
481 echo "$good_passwd_entry" > ${SYSCONFDIR}/passwd
482 echo "test_create_user: tests skipped."
486 # Case 1: create_user should succeed.
488 assertEquals "create_user()" 0 $?
491 test_add_profiles() {
492 # Solaris only, but testing using mock usermod will run if not root
494 logger "test_add_profiles"
495 [ "$IAmRoot" ] && startSkipping
496 add_profiles "Profile foo,Profile bar"
497 assertEquals "add_profiles should succeed" 0 $?
498 flags=`cat ${mock_usermod_flags}`
499 assertEquals "usermod_flags should contain:" \
500 "usermod args: -P \"Profile foo,Profile bar\" ${amanda_user}" \
505 test_add_group_check_parameters_logs() {
506 rm -f ${MOCKDIR}/groupadd_rc ${MOCKDIR}/num_groups
507 # Return codes are integers.
508 printf '%i' 0 > ${MOCKDIR}/groupadd_rc
509 # Test that first parameter is required.
511 assertEquals "add_group without a group should fail." 1 $?
513 assertEquals "add_group should write" \
514 "Error: first argument was not a group to add." \
518 test_add_group_group_ok() {
519 # groupadd created group
520 printf '%i' 0 > ${MOCKDIR}/groupadd_rc
521 echo '${amanda_user} : prev_grp1' > ${MOCKDIR}/groups_output
523 assertEquals "add_group group ok" 0 $?
524 flags=`cat ${mock_usermod_flags}`
525 assertEquals "usermod_flags" \
526 "usermod args: -G prev_grp1,twinkle ${amanda_user}" \
529 # Make sure supplemental groups are preserved when adding groups to an
531 echo '${amanda_user} : prev_grp1 prev_grp2' > ${MOCKDIR}/groups_output
532 printf '%i' 1 > ${MOCKDIR}/num_groups
534 assertEquals "add_group group ok" 0 $?
535 flags=`cat ${mock_usermod_flags}`
536 assertEquals "usermod_flags should contain:" \
537 "usermod args: -G prev_grp1,prev_grp2,twinkle ${amanda_user}" \
541 test_create_homedir() {
542 logger "test_create_homedir"
543 rm -rf ${AMANDAHOMEDIR}
545 assertEquals "create_homedir returns 0" 0 $?
546 assertTrue "${AMANDAHOMEDIR} did not get created" "[ -d ${AMANDAHOMEDIR} ]"
547 if [ "$IAmRoot" ]; then
549 real_owner=`ls -ld $AMANDAHOMEDIR | awk '{ print $3":"$4; }'`
550 assertSame "${amanda_user}:${amanda_group}" "$real_owner"
553 "chown args: -R ${amanda_user}:${amanda_group} ${AMANDAHOMEDIR}" \
554 "`cat $mock_chown_flags`"
556 # A second run should succeed too.
558 assertEquals "When homedir exists, create_homedir returns 0:" 0 $?
559 # Later tests use ${AMANDAHOMEDIR}, so leave the dir there.
562 test_check_homedir_dir_existing() {
563 logger "test_check_homedir_dir_existing"
564 # Create the dir (example needed for other tests), then check again.
565 mkdir -p ${AMANDAHOMEDIR}/example
567 assertEquals "Homedir exists; check_homedir" 0 $?
570 test_create_logdir() {
571 logger "test_create_logdir"
572 # The logdir variable for the shell libs, not shunit2.
573 LOGDIR=$TMPDIR/amanda_log; export LOGDIR
575 rm -rf ${LOGDIR}.save
577 assertEquals "create_logdir clean system" 0 $?
578 if [ -n "$IAmRoot" ]; then
579 real_owner=`ls -ld $LOGDIR | awk '{ print $3":"$4; }'`
580 assertSame "${amanda_user}:${amanda_group}" "$real_owner"
583 "chown args: -R ${amanda_user}:${amanda_group} ${LOGDIR}"\
584 "`cat $mock_chown_flags`"
586 assertTrue "${LOGDIR} exists" "[ -d ${LOGDIR} ]"
587 # What happens if logdir is a file?
591 assertEquals "create_logdir" 0 $?
592 assertTrue "${LOGDIR} exists" "[ -d ${LOGDIR} ]"
593 assertTrue "${LOGDIR}/amanda_log.save backup exists" \
594 "[ -f ${LOGDIR}/amanda_log.save ]"
597 test_create_amandates() {
598 logger "test_create_amandates"
601 assertEquals "create_amandates" 0 $?
602 assertTrue "[ -f ${AMANDATES} ]"
605 test_check_amandates() {
606 logger "test_check_amandates"
607 touch $mock_chown_flags
608 touch $mock_chmod_flags
610 assertEquals "check_amandates" 0 $?
611 [ "$IAmRoot" ] && { startSkipping; echo "test_check_amandates: skipped"; }
613 "chown args: ${amanda_user}:${amanda_group} ${AMANDATES}" \
614 "`cat $mock_chown_flags`"
616 "chmod args: 0640 ${AMANDATES}" \
617 "`cat $mock_chmod_flags`"
620 test_a_create_gnupg() {
621 # We need to impose some order on a few tests because some functions
622 # rely on others. Tests are sorted alphabetically. Insert a letter after
623 # "test_" to impose order on particular tests
624 logger "test_create_gnupg"
626 assertEquals "create_gnupg" 0 $?
627 assertTrue "[ -d ${AMANDAHOMEDIR}/.gnupg ]"
630 assertEquals "create_gnupg dir existing" 0 $?
633 test_a_get_random_lines() {
634 logger "test_get_random_lines"
635 get_random_lines > ${TMPDIR}/lines
636 assertEquals "get_random_lines" 1 $?
637 get_random_lines 1 > ${TMPDIR}/lines
638 assertEquals "get_random_lines 1" 0 $?
639 assertEquals "get_random_lines 1 output" 1 "`sed -n '$=' ${TMPDIR}/lines`"
640 get_random_lines 20 > ${TMPDIR}/lines
641 assertEquals "get_random_lines 20 output" 20 "`sed -n '$=' ${TMPDIR}/lines`"
644 test_b_create_ampassphrase() {
645 rm -f ${AMANDAHOMEDIR}/.am_passphrase
646 logger "test_create_ampassphrase"
648 assertEquals "create_ampassphrase" 0 $?
650 "chown args: ${amanda_user}:${amanda_group} ${AMANDAHOMEDIR}/.am_passphrase" \
651 "`cat $mock_chown_flags`"
653 "chmod args: 0600 ${AMANDAHOMEDIR}/.am_passphrase" \
654 "`cat $mock_chmod_flags`"
655 # When .am_passphrase exists.
659 "Info: ${AMANDAHOMEDIR}/.am_passphrase already exists." \
661 rm ${AMANDAHOMEDIR}/.am_passphrase
664 test_b_create_amkey() {
665 logger "test_create_amkey"
666 # Missing .am_passphrase
667 [ -f ${AMANDAHOMEDIR}/.am_passphrase ] && rm ${AMANDAHOMEDIR}/.am_passphrase
669 assertEquals "create_amkey" 1 $?
672 "Error: ${AMANDAHOMEDIR}/.am_passphrase is missing, can't create amcrypt key." \
674 # Need .am_passphrase. Ignore these test errors if get_random_lines or
675 # create_gnupg tests failed.
676 get_random_lines 1 > ${AMANDAHOMEDIR}/.am_passphrase
678 assertEquals "create_amkey" 0 $?
679 # Test with existing key
681 assertEquals "create_amkey" 0 $?
684 "Info: Encryption key '${AMANDAHOMEDIR}/.gnupg/am_key.gpg' already exists." \
686 # make sure unencrypted am_key is not hanging around
687 assertFalse "[ -f ${AMANDAHOMEDIR}/.gnupg/am_key ]"
692 logger "test_check_gnupg"
694 assertEquals "check_gnupg" 0 $?
696 "chown args: -R ${amanda_user}:${amanda_group} ${AMANDAHOMEDIR}/.gnupg" \
697 "`cat $mock_chown_flags`"
699 "chmod args: -R u=rwX,go= ${AMANDAHOMEDIR}/.gnupg" \
700 "`cat $mock_chmod_flags`"
703 test_create_amandahosts() {
704 logger "test_create_amandahosts"
706 assertEquals "create_amandahosts:" 0 $?
707 assertEquals "${AMANDAHOMEDIR}/.amandahosts exists:" 0 $?
708 assertEquals "create_amandahosts" 0 $?
709 assertTrue "[ -f ${AMANDAHOMEDIR}/.amandahosts ]"
712 test_check_amandahosts_entry() {
713 logger "test_check_amandahosts_entry"
714 if [ -f ${AMANDAHOMEDIR}/.amandahosts ]; then
715 check_amandahosts_entry root amindexd amidxtaped
716 assertEquals "check_amandahosts_entry root amindexd amidxtaped" \
719 echo "test_check_amandahosts_entry: ${AMANDAHOMEDIR}/.amandahosts missing. test skipped"
724 test_check_amandahosts_perm() {
725 logger "test_check_amandahosts_perm"
726 check_amandahosts_perms
727 assertEquals "check_amandahosts_perms" 0 $?
728 [ "$IAmRoot" ] && { startSkipping; echo "test_check_amandahosts_perm: skipped"; }
730 "chown args: ${amanda_user}:${amanda_group} ${AMANDAHOMEDIR}/.amandahosts" \
731 "`cat $mock_chown_flags`"
733 "chmod args: 0600 ${AMANDAHOMEDIR}/.amandahosts" \
734 "`cat $mock_chmod_flags`"
737 test_create_ssh_key() {
738 logger "test_create_ssh_key"
739 keydir=${AMANDAHOMEDIR}/.ssh
741 create_ssh_key server
742 assertEquals "create_ssh_key" 0 $?
743 assertTrue "[ -f ${keydir}/id_rsa_amdump ]"
744 [ "$IAmRoot" ] && { startSkipping; echo "test_create_ssh_key: skipped"; }
746 "chown args: ${amanda_user}:${amanda_group} ${keydir} ${keydir}/id_rsa_amdump ${keydir}/id_rsa_amdump.pub" \
747 "`cat $mock_chown_flags`"
748 # Chmod is called twice, but we only get the 2nd invocation.
750 "chmod args: 0600 ${keydir}/id_rsa_amdump ${keydir}/id_rsa_amdump.pub" \
751 "`cat $mock_chmod_flags`"
755 # What happens if .ssh is a file?
756 touch ${AMANDAHOMEDIR}/.ssh
757 create_ssh_key client
758 assertEquals "create_ssh_key" 0 $?
759 assertTrue "[ -f ${keydir}.save ]"
760 assertTrue "[ -f ${keydir}/id_rsa_amrecover ]"
763 test_create_profile() {
764 logger "test_create_profile"
765 rm -f ${AMANDAHOMEDIR}/.profile
767 assertEquals "create_profile" 0 $?
768 assertTrue "[ -f ${AMANDAHOMEDIR}/.profile ]"
771 test_check_profile() {
772 logger "test_check_profile"
773 [ -f "${AMANDAHOMEDIR}/.profile" ] || touch ${AMANDAHOMEDIR}/.profile
775 assertEquals "check_profile" 0 $?
776 assertTrue "[ -s ${AMANDAHOMEDIR}/.profile ]"
777 [ "$IAmRoot" ] && { startSkipping; echo "test_check_profile: skipped"; }
779 "chown args: ${amanda_user}:${amanda_group} ${AMANDAHOMEDIR}/.profile" \
780 "`cat $mock_chown_flags`"
782 "chmod args: 0640 ${AMANDAHOMEDIR}/.profile" \
783 "`cat $mock_chmod_flags`"
786 test_install_client_conf() {
787 logger "test_install_client_conf"
789 touch ${MOCKDIR}/success
791 assertEquals "install_client_conf" 0 $?
792 prefix="install args:"
793 inst_files="${AMANDAHOMEDIR}/example/amanda-client.conf ${SYSCONFDIR}/amanda/"
796 "`cat $mock_install_flags`" \
797 "${prefix} -m 0600 -u ${amanda_user} -g ${amanda_group} ${inst_files}"
800 "`cat $mock_install_flags`" \
801 "${prefix} -m 0600 -o ${amanda_user} -g ${amanda_group} ${inst_files}"
807 ######################################
808 #TODO: post_rm_functions
810 # Run a single test, or let shunit run all tests
811 if [ $# -gt 0 ]; then
815 suite_addTest test___logger
816 suite_addTest test__log_output_of
817 for t in $SPECIFIC_TESTS; do
823 # Importing shunit2 triggers test enumeration, so must happen after
824 # all tests are defined.
825 . ${SHUNIT_INC}/shunit2
827 echo "shunit2 log is: ${LOGFILE}"
828 echo "mockdir is: ${MOCKDIR}"