|
| 1 | +import { afterAll, beforeAll, describe, expect, it } from "vitest"; |
| 2 | +import { WranglerE2ETestHelper } from "./helpers/e2e-wrangler-test"; |
| 3 | +import { generateResourceName } from "./helpers/generate-resource-name"; |
| 4 | +import { normalizeOutput } from "./helpers/normalize"; |
| 5 | + |
| 6 | +describe("secrets-store", async () => { |
| 7 | + let cachedStoreId = ""; |
| 8 | + let cachedSecretId = ""; |
| 9 | + |
| 10 | + const storeName = generateResourceName("secrets-store-store"); |
| 11 | + const secretName = generateResourceName("secrets-store-secret"); |
| 12 | + const helper = new WranglerE2ETestHelper(); |
| 13 | + |
| 14 | + const originalColumns = process.stdout.columns; |
| 15 | + beforeAll(() => { |
| 16 | + process.stdout.columns = 180; |
| 17 | + }); |
| 18 | + |
| 19 | + afterAll(() => { |
| 20 | + process.stdout.columns = originalColumns; |
| 21 | + }); |
| 22 | + |
| 23 | + const normalize = (str: string) => { |
| 24 | + return normalizeOutput(str, { |
| 25 | + [storeName]: "tmp-e2e-secrets-store-store", |
| 26 | + [secretName]: "tmp-e2e-secrets-store-secret", |
| 27 | + [process.env.CLOUDFLARE_ACCOUNT_ID as string]: "CLOUDFLARE_ACCOUNT_ID", |
| 28 | + }); |
| 29 | + }; |
| 30 | + |
| 31 | + it("creates a store", async () => { |
| 32 | + const output = await helper.run( |
| 33 | + `wrangler secrets-store store create ${storeName} --remote` |
| 34 | + ); |
| 35 | + |
| 36 | + const regex = /ID:\s*(\w{32})/; |
| 37 | + const match = output.stdout.match(regex); |
| 38 | + |
| 39 | + if (match && match[1]) { |
| 40 | + cachedStoreId = match[1]; |
| 41 | + } else { |
| 42 | + throw new Error("No uuid for store found."); |
| 43 | + } |
| 44 | + |
| 45 | + expect(normalize(output.stdout)).toMatchInlineSnapshot(` |
| 46 | + "🔐 Creating store... (Name: tmp-e2e-secrets-store-store-00000000-0000-0000-0000-000000000000) |
| 47 | +✅ Created store! (Name: tmp-e2e-secrets-store-store-00000000-0000-0000-0000-000000000000, ID: 00000000000000000000000000000000)" |
| 48 | + `); |
| 49 | + }); |
| 50 | + |
| 51 | + it("lists stores", async () => { |
| 52 | + const output = await helper.run( |
| 53 | + `wrangler secrets-store store list --per-page 100 --remote` |
| 54 | + ); |
| 55 | + |
| 56 | + expect(normalize(output.stdout)).toContain( |
| 57 | + "tmp-e2e-secrets-store-store-00000000-0000-0000-0000-000000000000" |
| 58 | + ); |
| 59 | + }); |
| 60 | + |
| 61 | + it("creates a secret", async () => { |
| 62 | + const output = await helper.run( |
| 63 | + `wrangler secrets-store secret create ${cachedStoreId} --name ${secretName} --value shh --scopes workers --comment test --remote` |
| 64 | + ); |
| 65 | + |
| 66 | + const regex = /ID:\s*(\w{32})/; |
| 67 | + const match = output.stdout.match(regex); |
| 68 | + |
| 69 | + if (match && match[1]) { |
| 70 | + cachedSecretId = match[1]; |
| 71 | + } |
| 72 | + |
| 73 | + expect(normalize(output.stdout)).toContain( |
| 74 | + "🔐 Creating secret... (Name: tmp-e2e-secrets-store-secret-00000000-0000-0000-0000-000000000000, Value: REDACTED, Scopes: workers, Comment: test" |
| 75 | + ); |
| 76 | + expect(normalize(output.stdout)).toContain( |
| 77 | + "✅ Created secret! (ID: 00000000000000000000000000000000)" |
| 78 | + ); |
| 79 | + }); |
| 80 | + |
| 81 | + it("gets a secret", async () => { |
| 82 | + const output = await helper.run( |
| 83 | + `wrangler secrets-store secret get ${cachedStoreId} --secret-id ${cachedSecretId} --remote` |
| 84 | + ); |
| 85 | + |
| 86 | + expect(normalize(output.stdout)).toContain( |
| 87 | + "🔐 Getting secret... (ID: 00000000000000000000000000000000)" |
| 88 | + ); |
| 89 | + expect(normalize(output.stdout)).toContain( |
| 90 | + "tmp-e2e-secrets-store-secret-00000000-0000-0000-0000-000000000000" |
| 91 | + ); |
| 92 | + }); |
| 93 | + |
| 94 | + it("updates a secret", async () => { |
| 95 | + const output = await helper.run( |
| 96 | + `wrangler secrets-store secret update ${cachedStoreId} --secret-id ${cachedSecretId} --value shh --remote` |
| 97 | + ); |
| 98 | + |
| 99 | + expect(normalize(output.stdout)).toContain( |
| 100 | + "🔐 Updating secret... (ID: 00000000000000000000000000000000)" |
| 101 | + ); |
| 102 | + expect(normalize(output.stdout)).toContain( |
| 103 | + "✅ Updated secret! (ID: 00000000000000000000000000000000)" |
| 104 | + ); |
| 105 | + expect(normalize(output.stdout)).toContain( |
| 106 | + "tmp-e2e-secrets-store-secret-00000000-0000-0000-0000-00000000000" |
| 107 | + ); |
| 108 | + }); |
| 109 | + |
| 110 | + it("deletes a secret", async () => { |
| 111 | + const output = await helper.run( |
| 112 | + `wrangler secrets-store secret delete ${cachedStoreId} --secret-id ${cachedSecretId} --remote` |
| 113 | + ); |
| 114 | + |
| 115 | + expect(normalize(output.stdout)).toMatchInlineSnapshot(` |
| 116 | + "🔐 Deleting secret... (ID: 00000000000000000000000000000000) |
| 117 | +✅ Deleted secret! (ID: 00000000000000000000000000000000)" |
| 118 | + `); |
| 119 | + }); |
| 120 | + |
| 121 | + it("validates a secret is deleted", async () => { |
| 122 | + const output = await helper.run( |
| 123 | + `wrangler secrets-store secret get ${cachedStoreId} --secret-id ${cachedSecretId} --remote` |
| 124 | + ); |
| 125 | + |
| 126 | + expect(normalize(output.stdout)).toContain( |
| 127 | + "🔐 Getting secret... (ID: 00000000000000000000000000000000)" |
| 128 | + ); |
| 129 | + expect(normalize(output.stdout)).toContain("secret_not_found [code: 1001]"); |
| 130 | + }); |
| 131 | + |
| 132 | + it("deletes a store", async () => { |
| 133 | + const output = await helper.run( |
| 134 | + `wrangler secrets-store store delete ${cachedStoreId} --remote` |
| 135 | + ); |
| 136 | + |
| 137 | + expect(normalize(output.stdout)).toMatchInlineSnapshot(` |
| 138 | + "🔐 Deleting store... (Name: 00000000000000000000000000000000) |
| 139 | +✅ Deleted store! (ID: 00000000000000000000000000000000)" |
| 140 | + `); |
| 141 | + }); |
| 142 | + |
| 143 | + it("validates a store is deleted", async () => { |
| 144 | + const output = await helper.run( |
| 145 | + `wrangler secrets-store secret get ${cachedStoreId} --secret-id ${cachedSecretId} --remote` |
| 146 | + ); |
| 147 | + |
| 148 | + expect(normalize(output.stdout)).toContain( |
| 149 | + "🔐 Getting secret... (ID: 00000000000000000000000000000000)" |
| 150 | + ); |
| 151 | + expect(normalize(output.stdout)).toContain("store_not_found [code: 1001]"); |
| 152 | + }); |
| 153 | +}); |
0 commit comments