-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix(triggers): env var resolution in provider configs #4160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+209
−1
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
|
|
||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| const { mockResolveWebhookRecordProviderConfig } = vi.hoisted(() => ({ | ||
| mockResolveWebhookRecordProviderConfig: vi.fn(), | ||
| })) | ||
|
|
||
| vi.mock('@/lib/webhooks/env-resolver', () => ({ | ||
| resolveWebhookRecordProviderConfig: mockResolveWebhookRecordProviderConfig, | ||
| })) | ||
|
|
||
| import { resolveWebhookExecutionProviderConfig } from './webhook-execution' | ||
|
|
||
| describe('resolveWebhookExecutionProviderConfig', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| it('returns the resolved webhook record when provider config resolution succeeds', async () => { | ||
| const webhookRecord = { | ||
| id: 'webhook-1', | ||
| providerConfig: { | ||
| botToken: '{{SLACK_BOT_TOKEN}}', | ||
| }, | ||
| } | ||
| const resolvedWebhookRecord = { | ||
| ...webhookRecord, | ||
| providerConfig: { | ||
| botToken: 'xoxb-resolved', | ||
| }, | ||
| } | ||
|
|
||
| mockResolveWebhookRecordProviderConfig.mockResolvedValue(resolvedWebhookRecord) | ||
|
|
||
| await expect( | ||
| resolveWebhookExecutionProviderConfig(webhookRecord, 'slack', 'user-1', 'workspace-1') | ||
| ).resolves.toEqual(resolvedWebhookRecord) | ||
|
|
||
| expect(mockResolveWebhookRecordProviderConfig).toHaveBeenCalledWith( | ||
| webhookRecord, | ||
| 'user-1', | ||
| 'workspace-1' | ||
| ) | ||
| }) | ||
|
|
||
| it('throws a contextual error when provider config resolution fails', async () => { | ||
| mockResolveWebhookRecordProviderConfig.mockRejectedValue(new Error('env lookup failed')) | ||
|
|
||
| await expect( | ||
| resolveWebhookExecutionProviderConfig( | ||
| { | ||
| id: 'webhook-1', | ||
| providerConfig: { | ||
| botToken: '{{SLACK_BOT_TOKEN}}', | ||
| }, | ||
| }, | ||
| 'slack', | ||
| 'user-1', | ||
| 'workspace-1' | ||
| ) | ||
| ).rejects.toThrow( | ||
| 'Failed to resolve webhook provider config for slack webhook webhook-1: env lookup failed' | ||
| ) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
|
|
||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| const { mockGetEffectiveDecryptedEnv } = vi.hoisted(() => ({ | ||
| mockGetEffectiveDecryptedEnv: vi.fn(), | ||
| })) | ||
|
|
||
| vi.mock('@/lib/environment/utils', () => ({ | ||
| getEffectiveDecryptedEnv: mockGetEffectiveDecryptedEnv, | ||
| })) | ||
|
|
||
| import { | ||
| resolveWebhookProviderConfig, | ||
| resolveWebhookRecordProviderConfig, | ||
| } from '@/lib/webhooks/env-resolver' | ||
|
|
||
| describe('webhook env resolver', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| mockGetEffectiveDecryptedEnv.mockResolvedValue({ | ||
| SLACK_BOT_TOKEN: 'xoxb-resolved', | ||
| SLACK_HOST: 'files.slack.com', | ||
| }) | ||
| }) | ||
|
|
||
| it('resolves environment variables inside webhook provider config', async () => { | ||
| const result = await resolveWebhookProviderConfig( | ||
| { | ||
| botToken: '{{SLACK_BOT_TOKEN}}', | ||
| includeFiles: true, | ||
| nested: { | ||
| url: 'https://{{SLACK_HOST}}/api/files.info', | ||
| }, | ||
| }, | ||
| 'user-1', | ||
| 'workspace-1' | ||
| ) | ||
|
|
||
| expect(result).toEqual({ | ||
| botToken: 'xoxb-resolved', | ||
| includeFiles: true, | ||
| nested: { | ||
| url: 'https://files.slack.com/api/files.info', | ||
| }, | ||
| }) | ||
| expect(mockGetEffectiveDecryptedEnv).toHaveBeenCalledWith('user-1', 'workspace-1') | ||
| }) | ||
|
|
||
| it('returns a cloned webhook record with resolved provider config', async () => { | ||
| const webhookRecord = { | ||
| id: 'webhook-1', | ||
| provider: 'slack', | ||
| providerConfig: { | ||
| botToken: '{{SLACK_BOT_TOKEN}}', | ||
| includeFiles: true, | ||
| }, | ||
| } | ||
|
|
||
| const result = await resolveWebhookRecordProviderConfig(webhookRecord, 'user-1', 'workspace-1') | ||
|
|
||
| expect(result).toEqual({ | ||
| ...webhookRecord, | ||
| providerConfig: { | ||
| botToken: 'xoxb-resolved', | ||
| includeFiles: true, | ||
| }, | ||
| }) | ||
| expect(result).not.toBe(webhookRecord) | ||
| expect(result.providerConfig).not.toBe(webhookRecord.providerConfig) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.