chore: import upstream snapshot with attribution
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,179 @@
|
||||
/**
|
||||
* @vitest-environment node
|
||||
*/
|
||||
import { inputValidationMock, inputValidationMockFns } from '@sim/testing'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
vi.mock('@/lib/core/security/input-validation.server', () => inputValidationMock)
|
||||
|
||||
import { emailBisonHandler } from '@/lib/webhooks/providers/emailbison'
|
||||
|
||||
const WEBHOOK_ID = 'webhook-uuid-1234'
|
||||
const PUBLIC_BASE_URL = 'https://my-instance.emailbison.com'
|
||||
|
||||
function makeWebhook(providerConfig: Record<string, unknown>) {
|
||||
return {
|
||||
id: WEBHOOK_ID,
|
||||
path: 'abc',
|
||||
providerConfig,
|
||||
} as unknown as Parameters<typeof emailBisonHandler.deleteSubscription>[0]['webhook']
|
||||
}
|
||||
|
||||
function jsonSecureResponse(status: number, body: Record<string, unknown>) {
|
||||
return {
|
||||
ok: status >= 200 && status < 300,
|
||||
status,
|
||||
statusText: '',
|
||||
headers: { get: () => null },
|
||||
body: { cancel: vi.fn() },
|
||||
json: vi.fn().mockResolvedValue(body),
|
||||
text: vi.fn().mockResolvedValue(JSON.stringify(body)),
|
||||
arrayBuffer: vi.fn(),
|
||||
}
|
||||
}
|
||||
|
||||
describe('emailBisonHandler createSubscription', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
process.env.NEXT_PUBLIC_APP_URL = 'https://app.example.com'
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
process.env.NEXT_PUBLIC_APP_URL = undefined
|
||||
})
|
||||
|
||||
it('rejects an apiBaseUrl that resolves to a blocked address before making a request', async () => {
|
||||
inputValidationMockFns.mockValidateUrlWithDNS.mockResolvedValue({
|
||||
isValid: false,
|
||||
error: 'URL resolves to a blocked address',
|
||||
})
|
||||
|
||||
const webhook = makeWebhook({
|
||||
apiKey: 'test-key',
|
||||
apiBaseUrl: 'https://169.254.169.254',
|
||||
triggerId: 'emailbison_email_sent',
|
||||
})
|
||||
|
||||
await expect(
|
||||
emailBisonHandler.createSubscription({
|
||||
webhook,
|
||||
workflow: {} as never,
|
||||
userId: 'user-1',
|
||||
requestId: 'req-1',
|
||||
} as never)
|
||||
).rejects.toThrow('Email Bison Instance URL could not be validated.')
|
||||
|
||||
expect(inputValidationMockFns.mockSecureFetchWithPinnedIP).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('creates the webhook subscription for a valid public instance URL', async () => {
|
||||
inputValidationMockFns.mockValidateUrlWithDNS.mockResolvedValue({
|
||||
isValid: true,
|
||||
resolvedIP: '203.0.113.10',
|
||||
})
|
||||
inputValidationMockFns.mockSecureFetchWithPinnedIP.mockResolvedValue(
|
||||
jsonSecureResponse(200, { data: { id: 42 } })
|
||||
)
|
||||
|
||||
const webhook = makeWebhook({
|
||||
apiKey: 'test-key',
|
||||
apiBaseUrl: PUBLIC_BASE_URL,
|
||||
triggerId: 'emailbison_email_sent',
|
||||
})
|
||||
|
||||
const result = await emailBisonHandler.createSubscription({
|
||||
webhook,
|
||||
workflow: {} as never,
|
||||
userId: 'user-1',
|
||||
requestId: 'req-1',
|
||||
} as never)
|
||||
|
||||
expect(result).toEqual({ providerConfigUpdates: { externalId: '42' } })
|
||||
expect(inputValidationMockFns.mockSecureFetchWithPinnedIP).toHaveBeenCalledWith(
|
||||
expect.stringContaining(PUBLIC_BASE_URL),
|
||||
'203.0.113.10',
|
||||
expect.objectContaining({ method: 'POST' })
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('emailBisonHandler deleteSubscription', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('rejects an apiBaseUrl that resolves to a blocked address before making a request', async () => {
|
||||
inputValidationMockFns.mockValidateUrlWithDNS.mockResolvedValue({
|
||||
isValid: false,
|
||||
error: 'URL resolves to a blocked address',
|
||||
})
|
||||
|
||||
const webhook = makeWebhook({
|
||||
apiKey: 'test-key',
|
||||
apiBaseUrl: 'https://127.0.0.1',
|
||||
externalId: '42',
|
||||
})
|
||||
|
||||
await emailBisonHandler.deleteSubscription({
|
||||
webhook,
|
||||
workflow: {} as never,
|
||||
requestId: 'req-1',
|
||||
strict: false,
|
||||
} as never)
|
||||
|
||||
expect(inputValidationMockFns.mockSecureFetchWithPinnedIP).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('throws when strict and the apiBaseUrl resolves to a blocked address', async () => {
|
||||
inputValidationMockFns.mockValidateUrlWithDNS.mockResolvedValue({
|
||||
isValid: false,
|
||||
error: 'URL resolves to a blocked address',
|
||||
})
|
||||
|
||||
const webhook = makeWebhook({
|
||||
apiKey: 'test-key',
|
||||
apiBaseUrl: 'https://127.0.0.1',
|
||||
externalId: '42',
|
||||
})
|
||||
|
||||
await expect(
|
||||
emailBisonHandler.deleteSubscription({
|
||||
webhook,
|
||||
workflow: {} as never,
|
||||
requestId: 'req-1',
|
||||
strict: true,
|
||||
} as never)
|
||||
).rejects.toThrow('Email Bison Instance URL could not be validated.')
|
||||
|
||||
expect(inputValidationMockFns.mockSecureFetchWithPinnedIP).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('deletes the webhook subscription for a valid public instance URL', async () => {
|
||||
inputValidationMockFns.mockValidateUrlWithDNS.mockResolvedValue({
|
||||
isValid: true,
|
||||
resolvedIP: '203.0.113.10',
|
||||
})
|
||||
inputValidationMockFns.mockSecureFetchWithPinnedIP.mockResolvedValue(
|
||||
jsonSecureResponse(200, {})
|
||||
)
|
||||
|
||||
const webhook = makeWebhook({
|
||||
apiKey: 'test-key',
|
||||
apiBaseUrl: PUBLIC_BASE_URL,
|
||||
externalId: '42',
|
||||
})
|
||||
|
||||
await emailBisonHandler.deleteSubscription({
|
||||
webhook,
|
||||
workflow: {} as never,
|
||||
requestId: 'req-1',
|
||||
strict: false,
|
||||
} as never)
|
||||
|
||||
expect(inputValidationMockFns.mockSecureFetchWithPinnedIP).toHaveBeenCalledWith(
|
||||
expect.stringContaining(PUBLIC_BASE_URL),
|
||||
'203.0.113.10',
|
||||
expect.objectContaining({ method: 'DELETE' })
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user