Skip to main content
Glama

SearXNG Server

proxy.test.ts3.94 kB
#!/usr/bin/env tsx /** * Unit Tests: proxy.ts * * Tests for proxy configuration and agent creation */ import { strict as assert } from 'node:assert'; import { createProxyAgent } from '../../src/proxy.js'; import { testFunction, createTestResults, printTestSummary } from '../helpers/test-utils.js'; import { EnvManager } from '../helpers/env-utils.js'; const results = createTestResults(); const envManager = new EnvManager(); async function runTests() { console.log('🧪 Testing: proxy.ts\n'); await testFunction('No proxy configuration returns undefined', () => { envManager.delete('HTTP_PROXY'); envManager.delete('HTTPS_PROXY'); envManager.delete('http_proxy'); envManager.delete('https_proxy'); const agent = createProxyAgent(); assert.equal(agent, undefined); envManager.restore(); }, results); await testFunction('HTTP proxy configuration', () => { envManager.set('HTTP_PROXY', 'http://proxy:8080'); const agent = createProxyAgent(); assert.ok(agent); assert.equal(agent.constructor.name, 'ProxyAgent'); envManager.restore(); }, results); await testFunction('HTTPS proxy configuration', () => { envManager.set('HTTPS_PROXY', 'https://proxy:8080'); const agent = createProxyAgent(); assert.ok(agent); assert.equal(agent.constructor.name, 'ProxyAgent'); envManager.restore(); }, results); await testFunction('Proxy with authentication', () => { envManager.set('HTTPS_PROXY', 'https://user:pass@proxy:8080'); const agent = createProxyAgent(); assert.ok(agent); envManager.restore(); }, results); await testFunction('Case-insensitive environment variables', () => { envManager.delete('HTTP_PROXY'); envManager.delete('HTTPS_PROXY'); envManager.set('http_proxy', 'http://lowercase-proxy:8080'); const agent = createProxyAgent(); assert.ok(agent); envManager.restore(); }, results); await testFunction('Invalid proxy URL handling', () => { envManager.set('HTTP_PROXY', 'not-a-url'); try { const agent = createProxyAgent(); // Should handle malformed URLs gracefully or throw assert.ok(agent === undefined || agent !== null); } catch (error) { // Error handling is acceptable for malformed URLs assert.ok(error instanceof Error); } envManager.restore(); }, results); await testFunction('Unsupported protocol throws error', () => { envManager.set('HTTP_PROXY', 'socks5://proxy:1080'); try { const agent = createProxyAgent(); assert.fail('Should have thrown error for unsupported protocol'); } catch (error) { assert.ok(error instanceof Error); assert.ok(error.message.includes('protocol') || error.message.includes('socks5')); } envManager.restore(); }, results); await testFunction('Different URL schemes', () => { const testUrls = ['http://example.com', 'https://example.com']; for (const url of testUrls) { envManager.set('HTTP_PROXY', 'http://proxy:8080'); try { const agent = createProxyAgent(); assert.ok(agent === undefined || agent !== null); } catch (error) { // Some URL schemes might not be supported, that's ok assert.ok(true); } envManager.restore(); } }, results); await testFunction('ProxyAgent has dispatch method', () => { envManager.set('HTTP_PROXY', 'http://proxy:8080'); const agent = createProxyAgent(); if (agent) { assert.ok(typeof agent.dispatch === 'function'); } envManager.restore(); }, results); printTestSummary(results, 'Proxy Module'); return results; } // Run if executed directly if (import.meta.url === `file://${process.argv[1]}`) { runTests().then(results => { process.exit(results.failed > 0 ? 1 : 0); }).catch(console.error); } export { runTests };

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ihor-sokoliuk/mcp-searxng'

If you have feedback or need assistance with the MCP directory API, please join our Discord server