GeezerVison is showing github.com — fix(cloudflare): stop the rate limiting action defaulting on a replac… · simstudioai/sim@a42e330
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/sim/blocks/blocks/cloudflare.ts +28-8Lines changed: 28 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -35,7 +35,7 @@ const SUBBLOCK_ALIASES: Record<string, Record<string, string>> = { | 35 | 35 | purge_cache: { tags: 'purgeTags' }, | 36 | 36 | create_ruleset: { name: 'rulesetName' }, | 37 | 37 | create_rate_limit_rule: { action: 'rateLimitAction' }, | 38 | | - update_rate_limit_rule: { action: 'rateLimitAction' }, | | 38 | + update_rate_limit_rule: { action: 'updateRateLimitAction' }, | 39 | 39 | create_access_application: { type: 'appType', tags: 'accessAppTags' }, | 40 | 40 | update_access_application: { type: 'appType', tags: 'accessAppTags' }, | 41 | 41 | list_access_applications: { name: 'listNameFilter', domain: 'accessAppDomainFilter' }, | @@ -801,9 +801,8 @@ export const CloudflareBlock: BlockConfig<CloudflareResponse> = { | 801 | 801 | title: 'Status Filter', | 802 | 802 | type: 'dropdown', | 803 | 803 | options: [ | 804 | | - { label: 'All', id: 'all' }, | 805 | | - { label: 'Active', id: 'active' }, | 806 | | - { label: 'Pending', id: 'pending' }, | | 804 | + { label: 'All statuses', id: 'all' }, | | 805 | + { label: 'Active only', id: '' }, | 807 | 806 | ], | 808 | 807 | value: () => 'all', | 809 | 808 | condition: { field: 'operation', value: 'list_certificates' }, | @@ -1346,10 +1345,27 @@ Return ONLY the JSON array - no explanations, no markdown fences.`, | 1346 | 1345 | { label: 'Log', id: 'log' }, | 1347 | 1346 | ], | 1348 | 1347 | value: () => 'block', | 1349 | | - condition: { | 1350 | | - field: 'operation', | 1351 | | - value: ['create_rate_limit_rule', 'update_rate_limit_rule'], | 1352 | | - }, | | 1348 | + condition: { field: 'operation', value: 'create_rate_limit_rule' }, | | 1349 | + }, | | 1350 | + { | | 1351 | + /** | | 1352 | + * The update endpoint replaces the rule, so a seeded action would rewrite | | 1353 | + * whatever the rule currently does the moment anything else is edited. | | 1354 | + * This control carries no default: the user has to state the action the | | 1355 | + * replaced rule should end up with. | | 1356 | + */ | | 1357 | + id: 'updateRateLimitAction', | | 1358 | + title: 'Action', | | 1359 | + type: 'dropdown', | | 1360 | + options: [ | | 1361 | + { label: 'Block', id: 'block' }, | | 1362 | + { label: 'Managed Challenge', id: 'managed_challenge' }, | | 1363 | + { label: 'JS Challenge', id: 'js_challenge' }, | | 1364 | + { label: 'Interactive Challenge', id: 'challenge' }, | | 1365 | + { label: 'Log', id: 'log' }, | | 1366 | + ], | | 1367 | + required: true, | | 1368 | + condition: { field: 'operation', value: 'update_rate_limit_rule' }, | 1353 | 1369 | }, | 1354 | 1370 | { | 1355 | 1371 | id: 'expression', | @@ -2511,6 +2527,10 @@ Return ONLY the JSON array - no explanations, no markdown fences.`, | 2511 | 2527 | type: 'string', | 2512 | 2528 | description: 'Action applied once a rate limit is exceeded', | 2513 | 2529 | }, | | 2530 | + updateRateLimitAction: { | | 2531 | + type: 'string', | | 2532 | + description: 'Action a replaced rate limiting rule ends up applying', | | 2533 | + }, | 2514 | 2534 | content: { type: 'string', description: 'DNS record content' }, | 2515 | 2535 | ttl: { type: 'number', description: 'Time to live in seconds' }, | 2516 | 2536 | proxied: { type: 'boolean', description: 'Whether Cloudflare proxy is enabled' }, | |
Collapse file Copy file name to clipboardExpand all lines: apps/sim/tools/cloudflare/cloudflare.test.ts +18-2Lines changed: 18 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -101,13 +101,28 @@ describe('subBlock ids that share a tool param keep their own default', () => { | 101 | 101 | expect(mapped.action).toBeUndefined() | 102 | 102 | }) | 103 | 103 |
| 104 | | - it('keeps the block default on the rate limiting operations', () => { | | 104 | + it('keeps the block default when creating a rate limiting rule', () => { | 105 | 105 | expect(mapFor('create_rate_limit_rule', { zoneId: 'zone1', rulesetId: 'rs1' }).action).toBe( | 106 | 106 | 'block' | 107 | 107 | ) | | 108 | + }) | | 109 | + | | 110 | + it('never seeds an action onto a rate limiting rule it is about to replace', () => { | | 111 | + // The update endpoint replaces the rule, so a seeded block would convert a | | 112 | + // live log or challenge rule into a hard block the moment anything else is | | 113 | + // edited. The user has to state the action instead. | 108 | 114 | expect( | 109 | 115 | mapFor('update_rate_limit_rule', { zoneId: 'zone1', rulesetId: 'rs1', ruleId: 'r1' }).action | 110 | | - ).toBe('block') | | 116 | + ).toBeUndefined() | | 117 | + | | 118 | + expect( | | 119 | + mapFor('update_rate_limit_rule', { | | 120 | + zoneId: 'zone1', | | 121 | + rulesetId: 'rs1', | | 122 | + ruleId: 'r1', | | 123 | + updateRateLimitAction: 'log', | | 124 | + }).action | | 125 | + ).toBe('log') | 111 | 126 | }) | 112 | 127 |
| 113 | 128 | it('strips the aliased control ids so they never reach a tool as params', () => { | @@ -119,6 +134,7 @@ describe('subBlock ids that share a tool param keep their own default', () => { | 119 | 134 | 'certificateStatus', | 120 | 135 | 'appType', | 121 | 136 | 'rateLimitAction', | | 137 | + 'updateRateLimitAction', | 122 | 138 | 'rulesetName', | 123 | 139 | 'zoneNameFilter', | 124 | 140 | 'zoneType', | |
Collapse file Copy file name to clipboardExpand all lines: apps/sim/tools/generated/tool-ids.ts +1-1Lines changed: 1 addition & 1 deletion Large diffs are not rendered by default. Collapse file Copy file name to clipboardExpand all lines: apps/sim/tools/generated/tool-metadata.ts +1-1Lines changed: 1 addition & 1 deletion Large diffs are not rendered by default. Collapse file Copy file name to clipboardExpand all lines: apps/sim/tools/generated/tool-outputs.ts +1-1Lines changed: 1 addition & 1 deletion Large diffs are not rendered by default.
|