KB N° 2549: TEST THE OPERATION OF A PROXY.PAC
How to validate the operation of a .pac proxy using a pactester.
Objective
Validate the operation of a .pac proxy using a pactester.
Context
A proxy.pac is used to declare the proxy address and port to client browsers. How can I validate the operation of the declared proxy.pac?
You can check the operation of a .pac proxy using the pacparser tool.
Pacparser is a library for analyzing the automatic proxy configuration of a .PAC file. Automatic proxy configuration files are a widely used proxy configuration method today. Web browsers can use a .PAC file to determine which proxy server to use, or whether a direct connection is required for a given URL. PAC files are written in JavaScript and can be programmed to return different substitution methods (e.g. "PROXY from Proxy1: port; DIRECT" ) depending on the URL, source IP address, protocol, etc.
PAC files open up many new possibilities. PAC files are now a widely accepted method of managing proxies, and companies are using them in the corporate environment. The most popular web browsers support .PAC files.
Since the .PAC proxy file evaluation mechanism is generated inside the browser and cannot be accessed from the outside, the only way to know which proxy the browser will use for a specific URL is by manually inspecting the .PAC proxy file. But manual inspection can be tedious and generate errors proportional to the size of the file.
The idea behind pacparser is to facilitate the analysis of .PAC files (C and python are currently supported).
Steps
Step 1
- The first step is to install this tool, which is available via the following command for Linux system environments:
$ sudo apt-get install libpacparser1 python-pacparser libpacparser-dev
For a Windows or Mac OS X system, go to this address: https: //code.google.com/p/pacparser/downloads/list
- To install the pacparser and pactester C library in the Windows environment :
Download the pacparser -vvv - win32.zip archive and extract it. A pacparser-v.v.v directory will be created.
- Copy all .DLL and pactester.exe files somewhere where the system can find them (e.g. directories that are already in the system path, such as C:\Windows) or simply add the pacparser directory to the system path (PATH).
- Link libpacparser.a and pacparser.lib in pacparser with the mingw and Visual Studio compiler tools respectively. Instructions for linking in pacparser on Visual Studio: http: //code.google.com/p/pacparser/wiki/LinkingOnVisualStudio
Python module
To install the python module of pacparser: download the pacparser - Python25 -vvv - win32.zip package and extract it. At the command prompt (cmd), go to the pacparser - Python25 -vvv -win32 directory and run setup.py install:
C:\temp > cd pacparser - Python25 - 1.0.5 -win32 C:\temp\pacparser - Python25 - 1.0.5 -win32 > setup.py install
If it fails for any reason, simply copy the pacparser directory into the python folder: C:\Python25\Lib\site-packages\pacparser.
Step 2
Once the pacparser tool has been installed, you can test the proxy.pac configuration file with python :
>>> import pacparser >>> pacparser.init() >>> pacparser.parse_pac_file('examples/wpad.dat') >>> pacparser.find_proxy('http://www.google.com', 'www.google.com') 'PROXY proxy1.manugarg.com:3128; PROXY proxy2.manugarg.com:3128; DIRECT' >>> pacparser.find_proxy('http://www2.manugarg.com', 'www2.manugarg.com') DIRECT' >>> pacparser.cleanup() >>> Step 3
It is also possible to test the .PAC file using the C language:
manugarg@hobbiton:~$ cat pactest.c #include <stdio.h> #include <pacparser.h> int main(int argc, char* argv[]) { char *proxy; pacparser_init(); pacparser_parse_pac_file(argv[1]); proxy = pacparser_find_proxy(argv[2], argv[3]); printf("%s\n", proxy); pacparser_cleanup(); } manugarg@hobbiton:~$ gcc -o pactest pactest.c -lpacparser manugarg@hobbiton:~$ ./pactest wpad.dat http://www.google.com www.google.com PROXY proxy1.manugarg.com:3128; PROXY proxy2.manugarg.com:3128; DIRECT
Validation
If the conditions are met, pacparser will return the desired proxy or will return DIRECT (no proxy).
This tool makes it easy to test the conditions of a .PAC file and avoid errors during deployment.