-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_session.py
60 lines (52 loc) · 2.18 KB
/
test_session.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from __future__ import unicode_literals
import unittest
from https_everywhere.session import HTTPSEverywhereSession
class TestRequestsSession(unittest.TestCase):
def test_freerangekitten_com(self):
url = "http://freerangekitten.com/"
s = HTTPSEverywhereSession()
r = s.get(url)
r.raise_for_status()
self.assertEqual(r.url, url.replace("http://", "https://"))
self.assertEqual(len(r.history), 1)
original = r.history[0]
self.assertEqual(original.url, url)
def test_example_com(self):
url = "http://example.com/"
s = HTTPSEverywhereSession()
r = s.get(url)
r.raise_for_status()
self.assertEqual(r.url, url)
self.assertEqual(r.history, [])
def test_webhostinggeeks_com_science(self):
# https://github.com/EFForg/https-everywhere/issues/18867
# http has wrong cert for quick failure, but an exception exists
url = "http://science.webhostinggeeks.com/"
s = HTTPSEverywhereSession()
r = s.get(url)
r.raise_for_status()
self.assertEqual(r.url, url)
self.assertEqual(r.history, [])
def test_fedmsg_com(self):
# https://github.com/EFForg/https-everywhere/issues/18867
# https redirects to http, but there are no rules to upgrade it to https
url = "http://fedmsg.com/"
s = HTTPSEverywhereSession()
r = s.get(url)
r.raise_for_status()
self.assertEqual(r.url, url)
self.assertEqual(r.history, [])
def test_python_org_packages(self):
# https://github.com/EFForg/https-everywhere/issues/18867
# https redirects to http, but there are no rules to upgrade it to https
url = "http://packages.python.org/"
s = HTTPSEverywhereSession()
r = s.get(url)
r.raise_for_status()
self.assertEqual(r.url, "https://pythonhosted.org/")
self.assertEqual(len(r.history), 2)
original = r.history[0]
self.assertEqual(original.url, url)
self.assertEqual(original.status_code, 302)
self.assertEqual(r.history[1].url, url.replace("http://", "https://"))
self.assertEqual(r.history[1].status_code, 301)