I am testing a web application that is hosted in production behind SiteMinder, which authenticates the user and adds an HTTP header to each request that identifies that user.
The application does not work if the header is not present and I am trying to test it using Watir and Webdriver. This combination drives a real browser (e.g. Firefox) locally so I am not able to insert HTTP headers easily via WebDriver. Our local test environment does not have SiteMinder so I need a way to insert the headers.
I have set up Apache 2 as a reverse proxy and want to translate a request like:
GET /SM_USER=fred@company.com/application/index.html
into:
GET /application/index.html
SM_USER: fred@company.com
Our servers are all Solaris 10 and I am currently using Apache/2.0.63 as installed with the OS (we are not using it for anything else).
The closest I have got is to use SetEnvIf
and mod_rewrite
:
SetEnvIf Request_URI "SM_USER=([^/]+)" HTTP_SM_USER=$1
RewriteEngine on
RewriteRule ^/.+(/application/.+)$ http://apphost:9090$1 [P]
But the header is not being set. It appears that the value of Request_URI
is being rewritten before the SetEnvIf
directive is being executed, so SM_USER
is no longer in the URI.
If I am right about this, is it possible to change the order of execution so SetEnvIf
gets the original URI? Or do I need a different approach?
Best Answer
My colleague came up with a solution. I had made the mistake of assuming that using
SetEnvIf
by itself was sufficient. This is now working for us:This URI is proxied to
http://apphost:9090/application/index.html
with the HTTP headerSM_USER
set tofred@company.com
: