Pregunta

I have a Pyramid app that locks down certain functionality to HTTPS connections.

The server is fronted by nginx (usually) and I use PasteDeploy to detect the HTTPS connection. From my environment.ini:

[filter:proxy-prefix]
use = egg:PasteDeploy#prefix

If the connection is HTTPS, paste deploy sets the request.scheme variable to 'https'.

I'm trying to write some integrated tests right now, and I can't seem to figure out how to get the TestApp, as provided by webtest, to process a request as if it were HTTPS.

¿Fue útil?

Solución

Make sure that you are loading your full WSGI pipeline which includes your filters. If you are not, then the headers won't be translated by the middleware. Generally this means calling get_app on "main" instead of "myapp". Also I'd suggest trying WebTest's extra_environ option which may work, since ultimately the middleware is just setting environ['wsgi.url_scheme'].

testapp.get('/foo', extra_environ={'wsgi.url_scheme': 'https'})

Otros consejos

I tried combing through the docs a third time, and figured out a workaround based on PasteDeploy ( perhaps the right solution )...

PasteDeploy looks for 2 headers to set the https connection. I added them to the headers dict I use to manage the cookie session, and it seemed to work fine at first.

{
   "HTTP_X_FORWARDED_SCHEME" : 'https',
   "HTTP_X_FORWARDED_PROTO" : 'https',
}

PasteDeploy has an if/else chain, so only one is needed... but submitting both works.

the PasteDeploy doesn't seem to get called though - i see these headers/environment items in the app, but the https isn't set.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top