UNPKG

okta-mcp-server

Version:

Model Context Protocol (MCP) server for Okta API operations with support for bulk operations and caching

156 lines 5.89 kB
#!/usr/bin/env node /** * Test script to demonstrate the mock Okta environment * Run with: npm run build && node dist/mocks/test-mock-environment.js */ import { MockOktaClient } from './mock-okta-client.js'; import { performance } from 'perf_hooks'; async function testMockEnvironment() { console.log('🚀 Testing Mock Okta Environment\n'); // Create mock client with large dataset const client = new MockOktaClient({ userCount: 10000, groupCount: 500, appCount: 100, policyCount: 50, seed: 12345, // Consistent data for testing networkConditions: 'normal', errorRate: 0.05, // 5% error rate for testing }); console.log('📊 Mock Data Statistics:'); console.log(client.getStats()); console.log(''); // Test 1: List users with pagination console.log('📋 Test 1: List Users with Pagination'); try { const start = performance.now(); const response1 = await client.listUsers({ limit: 50 }); const duration1 = performance.now() - start; console.log(`✅ Retrieved ${response1.data.length} users in ${duration1.toFixed(2)}ms`); console.log(` Rate Limit: ${response1.headers?.['x-rate-limit-remaining']}/${response1.headers?.['x-rate-limit-limit']}`); console.log(` Link Header: ${response1.headers?.link?.substring(0, 100)}...`); } catch (error) { console.log(`❌ Error: ${error.message}`); } console.log(''); // Test 2: Search users console.log('🔍 Test 2: Search Users'); try { const start = performance.now(); const response2 = await client.listUsers({ search: 'john', limit: 20 }); const duration2 = performance.now() - start; console.log(`✅ Found ${response2.data.length} users matching 'john' in ${duration2.toFixed(2)}ms`); } catch (error) { console.log(`❌ Error: ${error.message}`); } console.log(''); // Test 3: Get specific user console.log('👤 Test 3: Get Specific User'); try { const users = await client.listUsers({ limit: 1 }); if (users.data.length > 0) { const userId = users.data[0].id; const start = performance.now(); const user = await client.getUser(userId); const duration = performance.now() - start; console.log(`✅ Retrieved user ${user.profile.email} in ${duration.toFixed(2)}ms`); } } catch (error) { console.log(`❌ Error: ${error.message}`); } console.log(''); // Test 4: Create a new user console.log('➕ Test 4: Create New User'); try { const start = performance.now(); const newUser = await client.createUser({ profile: { firstName: 'Test', lastName: 'User', email: 'test.user@example.com', login: 'test.user@example.com', }, }, { activate: true }); const duration = performance.now() - start; console.log(`✅ Created user ${newUser.id} in ${duration.toFixed(2)}ms`); } catch (error) { console.log(`❌ Error: ${error.message}`); } console.log(''); // Test 5: Simulate rate limiting console.log('🚦 Test 5: Rate Limiting Simulation'); client.simulateRateLimitScenario('exhausted'); try { await client.listUsers(); } catch (error) { console.log(`✅ Rate limit working: ${error.errorCode} - ${error.errorSummary}`); } client.simulateRateLimitScenario('normal'); console.log(''); // Test 6: Network conditions console.log('🌐 Test 6: Network Conditions'); const conditions = ['fast', 'normal', 'slow']; for (const condition of conditions) { client.setNetworkConditions(condition); const start = performance.now(); await client.listUsers({ limit: 10 }); const duration = performance.now() - start; console.log(` ${condition}: ${duration.toFixed(2)}ms`); } console.log(''); // Test 7: Large batch operation console.log('📦 Test 7: Large Batch Operation'); client.setNetworkConditions('normal'); const batchStart = performance.now(); let totalUsers = 0; let pageCount = 0; let nextCursor; let limit = 200; while (pageCount < 10) { // Limit to 10 pages for demo const params = { limit }; if (nextCursor) { params.after = nextCursor; } const response = await client.listUsers(params); totalUsers += response.data.length; pageCount++; // Extract next cursor from link header const linkHeader = response.headers?.link; if (linkHeader) { const nextMatch = linkHeader.match(/after=([^&>]+)/); nextCursor = nextMatch ? nextMatch[1] : undefined; } else { break; } } const batchDuration = performance.now() - batchStart; console.log(`✅ Retrieved ${totalUsers} users across ${pageCount} pages in ${batchDuration.toFixed(2)}ms`); console.log(` Average: ${(batchDuration / pageCount).toFixed(2)}ms per page`); console.log(''); // Test 8: Error handling console.log('⚠️ Test 8: Error Handling'); client.setErrorRate(1.0); // Force errors let errorCount = 0; for (let i = 0; i < 5; i++) { try { await client.listUsers(); } catch (error) { errorCount++; console.log(` Error ${errorCount}: ${error.code || error.errorCode} - ${error.message || error.errorSummary}`); } } client.setErrorRate(0.02); // Reset to normal console.log(''); console.log('✅ Mock environment test completed!'); } // Run the test testMockEnvironment().catch(console.error); //# sourceMappingURL=test-mock-environment.js.map