egress.spec.ts 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. import { describe, expect, it } from 'vitest'
  2. import { clearedProxyEnv, installProxyFromEnvironment } from '@deepseek-ai/dsh-http-proxy'
  3. import { workerSpawnEnv } from '../src/host.ts'
  4. /** A proxy URL carrying credentials, the shape that must never reach model-authored code. */
  5. const CREDENTIALED_PROXY = 'http://alice:s3cret@proxy.example:8080'
  6. /** The launch environment of a user whose proxy needs a password. */
  7. const CREDENTIALED = {
  8. get: (name: string) => (name === 'HTTP_PROXY' || name === 'HTTPS_PROXY' ? { value: CREDENTIALED_PROXY } : undefined),
  9. }
  10. describe('workflow worker egress', () => {
  11. it('hands the worker no proxy configuration, credentialed or not', async () => {
  12. const dispose = await installProxyFromEnvironment(CREDENTIALED, () => undefined)
  13. try {
  14. const env = workerSpawnEnv()
  15. // The worker executes the model-authored script body, so a proxy URL that may carry
  16. // `user:password` must not be readable from its environment.
  17. for (const name of Object.keys(clearedProxyEnv())) expect(env).not.toHaveProperty(name)
  18. expect(env).not.toHaveProperty('NODE_USE_ENV_PROXY')
  19. expect(JSON.stringify(env)).not.toContain('s3cret')
  20. } finally {
  21. await dispose()
  22. }
  23. })
  24. it('still carries the platform temp path the worker needs on Windows', () => {
  25. expect(workerSpawnEnv('win32')).toHaveProperty('TMP')
  26. })
  27. })