mzcompose.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. """
  10. Test that `CREATE SECRET` and using secrets works using a local file for storage.
  11. """
  12. from materialize.mzcompose.composition import Composition
  13. from materialize.mzcompose.services.materialized import Materialized
  14. from materialize.mzcompose.services.testdrive import Testdrive
  15. SERVICES = [
  16. Materialized(),
  17. Testdrive(),
  18. ]
  19. def workflow_default(c: Composition) -> None:
  20. c.up("materialized")
  21. # ensure that the directory has restricted permissions
  22. c.exec(
  23. "materialized",
  24. "bash",
  25. "-c",
  26. "[[ `stat -c \"%a\" /mzdata/secrets` == '700' ]] && exit 0 || exit 1",
  27. )
  28. c.sql("CREATE SECRET secret AS 's3cret'")
  29. # Check that the contents of the secret have made it to the storage
  30. c.exec(
  31. "materialized",
  32. "bash",
  33. "-c",
  34. "[[ `cat /mzdata/secrets/*` == 's3cret' ]] && exit 0 || exit 1",
  35. )
  36. # Check that the file permissions are restrictive
  37. c.exec(
  38. "materialized",
  39. "bash",
  40. "-c",
  41. "[[ `stat -c \"%a\" /mzdata/secrets/*` == '600' ]] && exit 0 || exit 1",
  42. )
  43. # Check that alter secret gets reflected on disk
  44. c.sql("ALTER SECRET secret AS 'tops3cret'")
  45. c.exec(
  46. "materialized",
  47. "bash",
  48. "-c",
  49. "[[ `cat /mzdata/secrets/*` == 'tops3cret' ]] && exit 0 || exit 1",
  50. )
  51. # check that replacing the file did not change permissions
  52. c.exec(
  53. "materialized",
  54. "bash",
  55. "-c",
  56. "[[ `stat -c \"%a\" /mzdata/secrets/*` == '600' ]] && exit 0 || exit 1",
  57. )
  58. # Rename should not change the contents on disk
  59. c.sql("ALTER SECRET secret RENAME TO renamed_secret")
  60. # Check that the contents of the secret have made it to the storage
  61. c.exec(
  62. "materialized",
  63. "bash",
  64. "-c",
  65. "[[ `cat /mzdata/secrets/*` == 'tops3cret' ]] && exit 0 || exit 1",
  66. )
  67. c.sql("DROP SECRET renamed_secret")
  68. # Check that the file has been deleted from the storage
  69. c.exec(
  70. "materialized",
  71. "bash",
  72. "-c",
  73. "[[ -z `ls -A /mzdata/secrets` ]] && exit 0 || exit 1",
  74. )