/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_all.ksh

https://github.com/adilger/zfs · Korn Shell · 77 lines · 32 code · 16 blank · 29 comment · 5 complexity · 685a95c2552112d919048795df1abaae MD5 · raw file

  1. #!/bin/ksh -p
  2. #
  3. # CDDL HEADER START
  4. #
  5. # This file and its contents are supplied under the terms of the
  6. # Common Development and Distribution License ("CDDL"), version 1.0.
  7. # You may only use this file in accordance with the terms of version
  8. # 1.0 of the CDDL.
  9. #
  10. # A full copy of the text of the CDDL should have accompanied this
  11. # source. A copy of the CDDL is also available via the Internet at
  12. # http://www.illumos.org/license/CDDL.
  13. #
  14. # CDDL HEADER END
  15. #
  16. #
  17. # Copyright (c) 2017 Datto, Inc. All rights reserved.
  18. #
  19. . $STF_SUITE/include/libtest.shlib
  20. . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib
  21. #
  22. # DESCRIPTION:
  23. # 'zfs load-key -a' should load keys for all datasets.
  24. #
  25. # STRATEGY:
  26. # 1. Create an encrypted filesystem, encrypted zvol, and an encrypted pool
  27. # 2. Unmount all datasets and unload their keys
  28. # 3. Attempt to load all dataset keys
  29. # 4. Verify each dataset has its key loaded
  30. # 5. Attempt to mount the pool and filesystem
  31. #
  32. verify_runnable "both"
  33. function cleanup
  34. {
  35. datasetexists $TESTPOOL/$TESTFS1 && \
  36. log_must zfs destroy $TESTPOOL/$TESTFS1
  37. datasetexists $TESTPOOL/zvol && log_must zfs destroy $TESTPOOL/zvol
  38. poolexists $TESTPOOL1 && log_must destroy_pool $TESTPOOL1
  39. }
  40. log_onexit cleanup
  41. log_assert "'zfs load-key -a' should load keys for all datasets"
  42. log_must eval "echo $PASSPHRASE1 > /$TESTPOOL/pkey"
  43. log_must zfs create -o encryption=on -o keyformat=passphrase \
  44. -o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1
  45. log_must zfs create -V 64M -o encryption=on -o keyformat=passphrase \
  46. -o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/zvol
  47. typeset DISK2="$(echo $DISKS | awk '{ print $2}')"
  48. log_must zpool create -O encryption=on -O keyformat=passphrase \
  49. -O keylocation=file:///$TESTPOOL/pkey $TESTPOOL1 $DISK2
  50. log_must zfs unmount $TESTPOOL/$TESTFS1
  51. log_must zfs unload-key $TESTPOOL/$TESTFS1
  52. log_must zfs unload-key $TESTPOOL/zvol
  53. log_must zfs unmount $TESTPOOL1
  54. log_must zfs unload-key $TESTPOOL1
  55. log_must zfs load-key -a
  56. log_must key_available $TESTPOOL1
  57. log_must key_available $TESTPOOL/zvol
  58. log_must key_available $TESTPOOL/$TESTFS1
  59. log_must zfs mount $TESTPOOL1
  60. log_must zfs mount $TESTPOOL/$TESTFS1
  61. log_pass "'zfs load-key -a' loads keys for all datasets"