Monday, December 29, 2014

JMeter proxy recording

With Apache JMeter, you can setup a proxy HTTP server that you can use to test your website for images that you wish to keep protected with a copyright watermark.  I have been able to use JMeter to test our photography website to ensure clients cannot download their images for free without the image including a watermark.  I want to ensure all images downloaded contain a watermark that cannot be easily removed with picture editing software in order to protect our business.  I have found that other photography websites use different methods for adding a watermark to the image which can be by-passed with a proxy server.  By using JMeter, I was able to download their high resolution images without the watermark since the image did not contain the watermark itself but was merely added as an overlay via a third party software.

To setup the proxy server for testing, first you need to download JMeter.  I have been using JMeter 2.9 for my testing since that is what I'm familiar with and the settings that I describe in this blog are for that version.  Later version of JMeter have changed the way that the server is configured so I've just stayed with the version that I know works for me.

Next, run the jmeter.bat file and configure the proxy server and configure the Test Plan.
  1. Add a Thread Group to the Test Plan.  Right click on Test Plan, select Add, Threads (Users), Thread Group
  2. Add an HTTP Request Defaults configuration element to the Thread Group.  Right click on the Thread Group, select Add, Config Element, HTTP Request Defaults.
  3. Add a Recording Controller element to the Thread Group.  Right click on the Thread Group and select Add, Logic Controller, Recording Controller.
Now, we need to configure the Workbench to record the traffic through a proxy.
  1. Add an HTTP Proxy Server element to the Workbench.  Right click on Workbench and select Non-Test Elements, HTTP Proxy Server.
  2. You can exclude files from downloading by adding URL Patters to the URL Patterns to Exclude list.  In my case, I typically exclude html, js, png, gif, bmp, swf, and css files since I'm using JMeter to test for jpg downloads only.  Each pattern to exclude should start with ".*\." and then include the file type to ignore.  So, to exclude html files, the pattern would be ".*\.html" which will match every character in the URL up to the last slash and then all characters after the slash up to html.
  3. To save the proxy responses to files, add a "Save Responses to a file" proxy element.  Right click on HTTP Proxy Server and select Add, Listener, Save Responses to a file.
  4. I like to configure the Save Responses to a file element by adding a Filename prefix to save all the files to a separate folder.  For this, just configure the Filename prefix item to include a folder name with a slash followed by a prefix for each file downloaded.  For example, "downloaded/file_" would save all files to the "downloaded" folder and each downloaded file would begin with "file_" as the file name.  I believe the key is just to include the slash character ('/') to define a folder structure.
  5. Alternative to saving the responses, you can view the responses in a tree.  Right click on HTTP Proxy Server and select Add, Listener, View Results Tree.
Next, you'll have to configure your browser to connect with the proxy server.  I find it easier to use and configure Firefox for this.  In the Firefox settings, modify the Connection Settings and select the Manual proxy configuration item.  Configure the HTTP Proxy item as localhost and the Port as 8080 (unless you changed the proxy server default port configuration in JMeter).  Ensure the "Use this proxy server for all protocols" option is checked and select the OK button.  In JMeter, start the proxy server by selecting the Start button on the HTTP Proxy Server workbench element.  This will allow Firefox to connect to the internet through the JMeter proxy and every HTTP request will go through the test server.

Finally, just enter in the web address that you wish to test for file downloads and all non-excluded results will be stored in the configured directory for downloading.  Find the image files in the download directory and open them up to see if your chosen watermarking third party library protects the image from client downloads.  If the watermark does not appear on the image, your clients may be able to download their images without having to buy your product.