Skip to main content
Glama
test-validation.ts3.02 kB
import { GitHubTools } from './src/mcp/tools.js'; import { GitHubClient } from './src/github/client.js'; // Mock client const mockClient = {} as GitHubClient; const tools = new GitHubTools(mockClient); console.log('🧪 Testing Input Validation'); console.log('='.repeat(60)); // Test cases const testCases = [ { name: 'Valid Repo', fn: () => tools['validateRepoParameter']('owner/repo'), expected: 'owner/repo', shouldThrow: false }, { name: 'Valid Repo with hyphen/dot', fn: () => tools['validateRepoParameter']('owner.name/repo-name'), expected: 'owner.name/repo-name', shouldThrow: false }, { name: 'Invalid Repo (no owner)', fn: () => tools['validateRepoParameter']('repo'), shouldThrow: true, errorMatch: 'Invalid repository format' }, { name: 'Invalid Repo (injection attempt)', fn: () => tools['validateRepoParameter']('owner/repo; rm -rf /'), shouldThrow: true, errorMatch: 'Invalid repository format' }, { name: 'Valid Username', fn: () => tools['validateUsernameParameter']('octocat'), expected: 'octocat', shouldThrow: false }, { name: 'Valid Username with @', fn: () => tools['validateUsernameParameter']('@octocat'), expected: 'octocat', shouldThrow: false }, { name: 'Invalid Username (injection attempt)', fn: () => tools['validateUsernameParameter']('octocat; drop table users'), shouldThrow: true, errorMatch: 'Invalid username format' }, { name: 'Invalid Username (space)', fn: () => tools['validateUsernameParameter']('octo cat'), shouldThrow: true, errorMatch: 'Invalid username format' } ]; let passed = 0; let failed = 0; for (const test of testCases) { try { const result = test.fn(); if (test.shouldThrow) { console.log(`❌ ${test.name}: Expected error but got success`); failed++; } else if (result !== test.expected) { console.log(`❌ ${test.name}: Expected "${test.expected}" but got "${result}"`); failed++; } else { console.log(`✅ ${test.name}`); passed++; } } catch (error: any) { if (test.shouldThrow) { if (test.errorMatch && error.message.includes(test.errorMatch)) { console.log(`✅ ${test.name}`); passed++; } else { console.log(`❌ ${test.name}: Expected error matching "${test.errorMatch}" but got "${error.message}"`); failed++; } } else { console.log(`❌ ${test.name}: Unexpected error: ${error.message}`); failed++; } } } console.log('='.repeat(60)); console.log(`Total: ${testCases.length}, Passed: ${passed}, Failed: ${failed}`); if (failed > 0) { process.exit(1); }

Latest Blog Posts

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/radireddy/github-mcp'

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