secret.slt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. # Basic tests of the `CREATE SECRET`, `ALTER SECRET` and `DROP SECRET` DDL statements.
  10. mode cockroach
  11. # Start from a pristine server
  12. reset-server
  13. query TT
  14. SHOW SECRETS
  15. ----
  16. statement OK
  17. CREATE SECRET secret AS decode('c2VjcmV0Cg==', 'base64');
  18. statement OK
  19. CREATE SECRET IF NOT EXISTS secret AS decode('c2VjcmV0Cg==', 'base64');
  20. statement error catalog item 'secret' already exists
  21. CREATE SECRET secret AS decode('c2VjcmV0Cg==', 'base64');
  22. statement OK
  23. CREATE SECRET key AS decode('c2VjcmV0Cg==', 'base64');
  24. query TTT rowsort
  25. SELECT id, schema_id, name FROM mz_secrets
  26. ----
  27. u1 u3 secret
  28. u4 u3 key
  29. query TT rowsort
  30. SHOW SECRETS
  31. ----
  32. secret (empty)
  33. key (empty)
  34. query TT
  35. SHOW SECRETS LIKE 'k%'
  36. ----
  37. key (empty)
  38. statement OK
  39. CREATE TABLE t1 (f1 INTEGER);
  40. statement OK
  41. insert into t1 values (1);
  42. statement error catalog item 't1' already exists
  43. CREATE SECRET t1 AS decode('c2VjcmV0Cg==', 'base64');
  44. statement error t1 is a table not a secret
  45. ALTER SECRET t1 rename to t2;
  46. statement error t1 is a table not a secret
  47. ALTER SECRET t1 as 'textsecret';
  48. statement OK
  49. DROP SECRET secret
  50. statement error unknown catalog item 'secret'
  51. DROP SECRET secret
  52. statement OK
  53. DROP SECRET IF EXISTS secret
  54. statement OK
  55. CREATE SECRET secret AS decode('c2VjcmV0Cg==', 'base64');
  56. query TT rowsort
  57. SHOW SECRETS
  58. ----
  59. key (empty)
  60. secret (empty)
  61. statement OK
  62. ALTER SECRET key RENAME TO certificate
  63. query TT rowsort
  64. SHOW SECRETS
  65. ----
  66. certificate (empty)
  67. secret (empty)
  68. # Rename to an existing secret
  69. statement OK
  70. CREATE SECRET existing AS decode('c2VjcmV0Cg==', 'base64');
  71. statement error catalog item 'existing' already exists
  72. ALTER SECRET certificate RENAME TO existing
  73. statement error catalog item 't1' already exists
  74. ALTER SECRET certificate RENAME TO t1
  75. statement OK
  76. DROP SECRET existing
  77. # Rename across schemas
  78. statement error Expected end of statement, found dot
  79. ALTER SECRET public.certificate RENAME TO public2.certificate2;
  80. statement OK
  81. ALTER SECRET certificate as decode('c2VjcmV0Cg==', 'base64');
  82. statement error unknown catalog item 'nonexistant'
  83. ALTER SECRET nonexistant as decode('c2VjcmV0Cg==', 'base64');
  84. statement OK
  85. create schema testschema
  86. statement OK
  87. CREATE SECRET testschema.key AS decode('c2VjcmV0Cg==', 'base64');
  88. query TT rowsort
  89. SHOW SECRETS
  90. ----
  91. certificate (empty)
  92. secret (empty)
  93. query TT rowsort
  94. SHOW SECRETS FROM testschema
  95. ----
  96. key (empty)
  97. statement error AS does not allow subqueries
  98. create secret a AS (SELECT * from t1);
  99. statement OK
  100. CREATE SECRET roundtrip AS decode(encode('supersecret', 'base64') , 'base64');
  101. statement OK
  102. CREATE SECRET text_secret as 'text'
  103. statement OK
  104. CREATE SECRET byte_secret as 'text'::bytea;
  105. statement error AS must have type bytea, not type integer
  106. CREATE SECRET int_secret as 123456
  107. statement error secret value can not be null
  108. CREATE SECRET null_secret as NULL
  109. statement error AS must have type bytea, not type text
  110. create secret aa_secret as 'a' || 'a'
  111. statement OK
  112. create secret ab_secret as ('a' || 'b')::bytea
  113. statement OK
  114. create secret secret_512 as REPEAT('x', 1024 * 512)::bytea;
  115. statement error secrets can not be bigger than 512KiB
  116. create secret secret_1024 as REPEAT('x', 1024 * 1024)::bytea;
  117. # Test dropping multiple secrets in a single operation
  118. statement OK
  119. create schema to_be_dropped
  120. statement OK
  121. CREATE SECRET to_be_dropped.secret1 as 'text'
  122. statement OK
  123. CREATE SECRET to_be_dropped.secret2 as 'text'
  124. statement OK
  125. CREATE SECRET to_be_dropped.secret3 as 'text'
  126. statement OK
  127. DROP SCHEMA to_be_dropped CASCADE
  128. # Secret validation
  129. statement error secret value must be valid UTF-8
  130. CREATE SECRET invalid_cert AS '\x80';