How can we use Django LiveServerTestCase with Selenium to test https urls - python

Our end-to-end tests use Django's LiveServerTestCase with Selenium. So far we have only been able to run these on insecure urls. However, some of the libraries that we use (Square) require a page to be on https even in sandbox mode.
When attempting to connect to a secure url, Selenium/Chrome Webdriver simply shows the standard SSL not supported error:
This site can’t provide a secure connection chezpierre.localtest.me sent an invalid response.
ERR_SSL_PROTOCOL_ERROR
Does anyone know if it is possible to enable https on a LiveServerTestCase?
If not, does anyone have a working workaround for this? I'm trying to avoid running a separate https proxy on our build box, but it seems like it might be the only way.

After quick research I found out that this is impossible in Django suggested by this old code ticket https://code.djangoproject.com/ticket/25328
I also found out that you could setup a tunnel to bypass this issue. However this applies to django development server. This is kind of tricky so I am leaving links to posts as the method is rather long:
https://www.ianlewis.org/en/testing-https-djangos-development-server
or
How can I test https connections with Django as easily as I can non-https connections using 'runserver'?
ALTERNATIVE - In my opinion better
There is also a simpler way using an external package. It gives you out of the box a https capable django development server. The project is active and maintained
https://github.com/teddziuba/django-sslserver

Related

Running Django in IIS

I have a Python application that's that has been working correctly as backend for my website, up to now I have been running it using "python manage.py runserver IP:8000" in CMD. However I would like it to start using HTTPS, but when I try to access through my browser on https://IP:PORT I get the following error:
You're accessing the development server over HTTPS, but it only
supports HTTP.
The server I am running all of this is a Windows Center 2019 DataCenter, normally on a linux environment I would just use NGINX+GUNICORN.
I was browsing possible solutions and stumbled upon this, however I already am using IIS to host a website (My frontend), so I needed to figure out how to host several websites for the same IP, I have now found this.
Long story short, I configured the new IIS website for it to access my django, I then changed the hostname since both frontend and the new backend will using the same ip and ports (80, 443).
But now I have hit a spot where I'm confused due to my lack of experience in IIS and networking. I can't seem to understand how the request will go through to my Python-Django APP.
Something important to mention on how I access the Django APP in the past.
Lets say my front end is https://pr.app.com, whenever any request needed to be made to the backend. I would ask for said information in http://pr.app.com:8000/APIService/..../
This is how the binding for my frontend looks like
And this is the binding for the new backend where I changed the hostname as the second guide linked said
Any guidance or help would be most appreciated,
Thanks in advance
*Update
So I tried pausing my frontend website and used these bindings on the new backend website, I was able to get a screen of Django meaning it seems to be working or at least communicating.
Now I would need to have the hostname of the backend (pr.abcapi.com) somehow refer or redirect to the hostname of the frontend (pr.abc.com).
How could I achieve this?

Sharepoint api functions execute via python module through proxied communication

Has anyone tried to execute a sharepoint function via python module through a proxy? I’ve tried to use shareplum and other python modules to execute the sharepoint calls, but run into an issue with the tls version not being valid or ssl error. I’ve tried setting the tls version, but still get an invalid version for the ssl or the tls version depending. I know I’m able to access the proxy, but fail to access the sharepoint site with a bad authentication.
I can access other sites via request, but I know that I need shareplum or something similar to execute the sharepoint site functions. If not going through a proxy, then I have no issue. However, my company recently deployed a proxy and now my script is no longer working. The code to use shareplum is similar to the code provide by the git project. However, the git project assumes straightforward communication to the web server with https or http
I’ve tried changing the tls version to default 1.1 and 1.2, but neither work. I’ve also tried setting the protocol to http verses https and tried to first pass the proxy server, but no success. I tried using proxy manager using the proxy, then using the created session to access the sharepoint site, but that also fails. Using the proxy manager caused a bad authentication with the sharepoint site.

Use Django with SSL in order to integrate PayPal

I want to use PayPal in a Django Project and in order to do this I need Django to work with TSL 1.2. Since I haven't worked with such encryption yet, I need advice on how to setup Django in a way that works with an https version that works with PayPal. I already have a working ssl certificate and was able to use django-sslserver to make Django work with https, but PayPal still does not work with it. Could someone give a hint were I should be looking into for this kind of thing?
If you have a self-signed SSL certificate, then this is not going to work. You can get a free SSL certificate at Let's encrypt: https://letsencrypt.org/.
If you use the Javascript API your site has to be served over HTTPS as well because of CORS.

Is there any thing needed for https python web page

I been using python to create an web app and it has been doing well so far. Now I would like to encrypt the transmission of the data between client and server using https. The communication is generally just post form and web pages, no money transactions are involve. Is there anything I need to change to the python code except setting the server up with certificate and configurate it to use https? I see a lot of information regarding ssl for python and I not sure if I need those modules and python setup to make https work.
Thanks
Typically, the ssl part for Python web app is managed by some frontend web server like nginx, apache or so.
This does not require any modification of your code (assuming, you are not expecting user to authenticate by ssl certificate on client side, what is quite exotic, but possible scenario).
If you want to run pure Python solution, I would recommend using cherrypy, which is able providing rather reliable and performant web server part (it will be very likely slower then served behind nginx or apache).

Can you run ssl with bottle + AD Authenticate?

I have been looking at multiple sources and can't seem to get a good answer. I am trying to deploy a very simple app that displays information from a mongodb, accepts post data for input, uses SSL, and AD for Authentication.
I am using bottle with python 2.7, mongodb, on a windows 64-bit platform. I can switch to CentOS if that is completely necessary.
So far, none of the very few tutorials out there seem to work on my current configuration. Is what I'm asking for possible? Should I switch to a different framework?
tldr:
Can you run a bottle application with SSL and AD integration?
If not, what python framework would be nearly as easy and still have this functionality.
edit: I found this for flask. Could it work with bottle? Also, can it be done on windows?
There are definitely ways to accomplish your goal of having bottle use SSL + AD on windows.
SSL with bottle:
https://github.com/nickbabcock/bottle-ssl
http://dgtool.blogspot.com/2011/12/ssl-encryption-in-python-bottle.html
bottle on cherrypy server + ssl
python with AD (as well as information on windows specifically):
Authenticating against active directory using python + ldap
https://gist.github.com/ibeex/1288159
If you wanted to use session management for authentication you could pair the AD with bottle middleware such as beaker: bottle hooks with beaker session middleware and checking logins
Bottle itself does not have built in abilities to deal with SSL that I know of like flask. But the last SSL link above shows similar simple useability.

Categories