|
1 | 1 | import { describe, expect, it } from 'vitest' |
2 | 2 | import { createDnsRecordTool } from '@/tools/cloudflare/create_dns_record' |
3 | 3 | import { deleteDnsRecordTool } from '@/tools/cloudflare/delete_dns_record' |
| 4 | +import { updateR2BucketLifecycleTool } from '@/tools/cloudflare/update_r2_bucket_lifecycle' |
4 | 5 | import { updateRulesetRuleTool } from '@/tools/cloudflare/update_ruleset_rule' |
5 | 6 |
|
6 | 7 | describe('Cloudflare provider request boundaries', () => { |
| 8 | + it.each([undefined, null, '', ' '])( |
| 9 | + 'rejects an R2 lifecycle replacement without explicit rules (%j)', |
| 10 | + (rules) => { |
| 11 | + const body = updateR2BucketLifecycleTool.request.body |
| 12 | + if (!body) throw new Error('Expected a request body') |
| 13 | + const wireInput = { apiKey: 'token', accountId: 'account', bucketName: 'bucket', rules } |
| 14 | + expect(() => Reflect.apply(body, undefined, [wireInput])).toThrow(/rules/) |
| 15 | + } |
| 16 | + ) |
| 17 | + |
| 18 | + it.each([[], '[]'])('preserves an explicit R2 lifecycle clear (%j)', (rules) => { |
| 19 | + const body = updateR2BucketLifecycleTool.request.body |
| 20 | + if (!body) throw new Error('Expected a request body') |
| 21 | + expect(body({ apiKey: 'token', accountId: 'account', bucketName: 'bucket', rules })).toEqual({ |
| 22 | + rules: [], |
| 23 | + }) |
| 24 | + }) |
| 25 | + |
| 26 | + it('preserves every explicitly supplied R2 lifecycle rule', () => { |
| 27 | + const body = updateR2BucketLifecycleTool.request.body |
| 28 | + if (!body) throw new Error('Expected a request body') |
| 29 | + const rules = [ |
| 30 | + { |
| 31 | + id: 'expire-logs', |
| 32 | + enabled: true, |
| 33 | + conditions: { prefix: 'logs/' }, |
| 34 | + deleteObjectsTransition: { condition: { type: 'Age', maxAge: 86400 } }, |
| 35 | + }, |
| 36 | + { |
| 37 | + id: 'retain-archive-transition', |
| 38 | + enabled: false, |
| 39 | + conditions: { prefix: 'archive/' }, |
| 40 | + storageClassTransitions: [ |
| 41 | + { condition: { type: 'Age', maxAge: 2592000 }, storageClass: 'InfrequentAccess' }, |
| 42 | + ], |
| 43 | + }, |
| 44 | + ] |
| 45 | + expect( |
| 46 | + body({ |
| 47 | + apiKey: 'token', |
| 48 | + accountId: 'account', |
| 49 | + bucketName: 'bucket', |
| 50 | + rules: JSON.stringify(rules), |
| 51 | + }) |
| 52 | + ).toEqual({ rules }) |
| 53 | + }) |
| 54 | + |
7 | 55 | it('rejects a DNS deletion identifier that would address the collection instead', () => { |
8 | 56 | const url = deleteDnsRecordTool.request.url |
9 | 57 | if (typeof url !== 'function') throw new Error('Expected a parameterized URL') |
|
0 commit comments