|
| 1 | +# PAC File Tester - Demo Guide |
| 2 | + |
| 3 | +## Quick Start Demo |
| 4 | + |
| 5 | +### Step 1: Open the Application |
| 6 | + |
| 7 | +The web server is running! Open your browser and navigate to: |
| 8 | +``` |
| 9 | +http://localhost:8000 |
| 10 | +``` |
| 11 | + |
| 12 | +### Step 2: Try These Test Scenarios |
| 13 | + |
| 14 | +#### Test Scenario 1: Plain Hostname |
| 15 | +1. **PAC File**: Use the content from `sample.pac` or paste: |
| 16 | + ```javascript |
| 17 | + function FindProxyForURL(url, host) { |
| 18 | + if (isPlainHostName(host)) { |
| 19 | + return "DIRECT"; |
| 20 | + } |
| 21 | + return "PROXY proxy.example.com:8080"; |
| 22 | + } |
| 23 | + ``` |
| 24 | + |
| 25 | +2. **Test URL**: `http://localhost` |
| 26 | + |
| 27 | +3. **Expected Result**: `DIRECT` |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +#### Test Scenario 2: Internal Network Check |
| 32 | +1. **PAC File**: Use `sample.pac` (already created) |
| 33 | + |
| 34 | +2. **Configuration**: |
| 35 | + - **Test URL**: `https://internal.company.com` |
| 36 | + - **Client IP**: `192.168.1.100` |
| 37 | + - **DNS Mappings**: |
| 38 | + - `internal.company.com` → `192.168.1.50` |
| 39 | + |
| 40 | +3. **Expected Result**: `DIRECT` (since both client and destination are internal) |
| 41 | + |
| 42 | +--- |
| 43 | + |
| 44 | +#### Test Scenario 3: External Site via Proxy |
| 45 | +1. **PAC File**: Use `sample.pac` |
| 46 | + |
| 47 | +2. **Configuration**: |
| 48 | + - **Test URL**: `https://www.google.com` |
| 49 | + - **Client IP**: `192.168.1.100` |
| 50 | + - **DNS Mappings**: |
| 51 | + - `www.google.com` → `142.250.185.46` |
| 52 | + |
| 53 | +3. **Expected Result**: `PROXY proxy.corporate.com:3128; DIRECT` |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +#### Test Scenario 4: Domain-Based Routing |
| 58 | +1. **PAC File**: Paste: |
| 59 | + ```javascript |
| 60 | + function FindProxyForURL(url, host) { |
| 61 | + // Go direct for plain hostnames |
| 62 | + if (isPlainHostName(host) || dnsDomainIs(host, '.local')) { |
| 63 | + return "DIRECT"; |
| 64 | + } |
| 65 | + |
| 66 | + // Check if host is resolvable (requires DNS mapping) |
| 67 | + if (dnsDomainIs(host, '.google.com') && isResolvable(host)) { |
| 68 | + return "PROXY google-proxy:8080"; |
| 69 | + } |
| 70 | + |
| 71 | + // Default proxy |
| 72 | + return "PROXY proxy.company.com:3128; DIRECT"; |
| 73 | + } |
| 74 | + ``` |
| 75 | + |
| 76 | +2. **Configuration**: |
| 77 | + - **Test URL**: `https://www.google.com` |
| 78 | + - **DNS Mappings**: |
| 79 | + - `www.google.com` → `142.250.185.46` |
| 80 | + |
| 81 | +3. **Expected Result**: `PROXY google-proxy:8080` |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +#### Test Scenario 5: IP Range Matching |
| 86 | +1. **PAC File**: Paste: |
| 87 | + ```javascript |
| 88 | + function FindProxyForURL(url, host) { |
| 89 | + // Check if client is in corporate network |
| 90 | + if (isInNet(myIpAddress(), "10.10.0.0", "255.255.0.0")) { |
| 91 | + return "PROXY internal-proxy:3128"; |
| 92 | + } |
| 93 | + |
| 94 | + // Check if destination is in local network |
| 95 | + var resolved = dnsResolve(host); |
| 96 | + if (resolved && isInNet(resolved, "192.168.0.0", "255.255.0.0")) { |
| 97 | + return "DIRECT"; |
| 98 | + } |
| 99 | + |
| 100 | + return "PROXY external-proxy:8080"; |
| 101 | + } |
| 102 | + ``` |
| 103 | + |
| 104 | +2. **Configuration**: |
| 105 | + - **Test URL**: `http://intranet.local` |
| 106 | + - **Client IP**: `10.10.100.50` |
| 107 | + - **DNS Mappings**: |
| 108 | + - `intranet.local` → `192.168.10.5` |
| 109 | + |
| 110 | +3. **Expected Result**: `PROXY internal-proxy:3128` |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +#### Test Scenario 6: Time-Based Routing |
| 115 | +1. **PAC File**: Paste: |
| 116 | + ```javascript |
| 117 | + function FindProxyForURL(url, host) { |
| 118 | + // Use fast proxy during business hours (9 AM - 5 PM) |
| 119 | + if (timeRange(9, 17)) { |
| 120 | + return "PROXY fast-proxy:8080"; |
| 121 | + } |
| 122 | + |
| 123 | + // Use slower proxy outside business hours |
| 124 | + return "PROXY slow-proxy:8080"; |
| 125 | + } |
| 126 | + ``` |
| 127 | + |
| 128 | +2. **Test URL**: `https://www.example.com` |
| 129 | + |
| 130 | +3. **Expected Result**: Depends on current time |
| 131 | + - During 9 AM - 5 PM: `PROXY fast-proxy:8080` |
| 132 | + - Outside those hours: `PROXY slow-proxy:8080` |
| 133 | + |
| 134 | +--- |
| 135 | + |
| 136 | +## Testing with Real PAC Files |
| 137 | + |
| 138 | +### Example: Google PAC File Pattern |
| 139 | +```javascript |
| 140 | +function FindProxyForURL(url, host) { |
| 141 | + // Bypass proxy for local addresses |
| 142 | + if (shExpMatch(host, "*.local") || |
| 143 | + shExpMatch(host, "127.*") || |
| 144 | + shExpMatch(host, "localhost")) { |
| 145 | + return "DIRECT"; |
| 146 | + } |
| 147 | + |
| 148 | + // Use specific proxy for certain domains |
| 149 | + if (shExpMatch(host, "*.example.com")) { |
| 150 | + return "PROXY proxy1.example.com:8080; PROXY proxy2.example.com:8080; DIRECT"; |
| 151 | + } |
| 152 | + |
| 153 | + // Default |
| 154 | + return "PROXY default-proxy.example.com:8080; DIRECT"; |
| 155 | +} |
| 156 | +``` |
| 157 | + |
| 158 | +**Test with**: |
| 159 | +- URL: `http://internal.example.com` |
| 160 | +- Expected: `PROXY proxy1.example.com:8080; PROXY proxy2.example.com:8080; DIRECT` |
| 161 | + |
| 162 | +--- |
| 163 | + |
| 164 | +## Debugging Tips |
| 165 | + |
| 166 | +1. **Check the Debug Information**: After testing, scroll down to see: |
| 167 | + - Which DNS lookups were performed |
| 168 | + - Whether `myIpAddress()` was called |
| 169 | + - The extracted hostname from the URL |
| 170 | + |
| 171 | +2. **Add DNS Mappings Progressively**: Start with no DNS mappings and add them as needed based on errors |
| 172 | + |
| 173 | +3. **Test Multiple URLs**: Use the same PAC file with different URLs to verify routing logic |
| 174 | + |
| 175 | +4. **Common Issues**: |
| 176 | + - If `dnsResolve(host)` returns null, add a DNS mapping for that host |
| 177 | + - If `myIpAddress()` returns unexpected value, set the Client IP field |
| 178 | + - Case sensitivity matters for domain names |
| 179 | + |
| 180 | +## Next Steps |
| 181 | + |
| 182 | +- Try uploading your own PAC file |
| 183 | +- Test against your actual proxy configuration |
| 184 | +- Share the web app with your team for testing PAC files |
| 185 | +- Deploy to a static hosting service (GitHub Pages, Netlify, etc.) |
| 186 | + |
| 187 | +## Feedback |
| 188 | + |
| 189 | +If you find any issues or have suggestions, please report them on the [Pacparser GitHub Issues](https://github.com/manugarg/pacparser/issues). |
0 commit comments