This repository was archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathtest_04_http.py
More file actions
72 lines (51 loc) · 1.85 KB
/
test_04_http.py
File metadata and controls
72 lines (51 loc) · 1.85 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
import os
from http.cookies import SimpleCookie
import pytest
from oidcrp.cookie import CookieDealer
from oidcrp.http import HTTPLib
from oidcrp.util import set_cookie
_dirname = os.path.dirname(os.path.abspath(__file__))
_keydir = os.path.join(_dirname, "data", "keys")
# CLIENT_CERT = open(os.path.join(_keydir,'cert.key')).read()
# CA_CERT = open(os.path.join(_keydir, 'cacert.pem')).read()
@pytest.fixture
def cookie_dealer():
class DummyServer():
def __init__(self):
self.symkey = b"0123456789012345"
return CookieDealer(DummyServer())
# def test_ca_cert():
# with pytest.raises(ValueError):
# HTTPLib(CA_CERT, False, CLIENT_CERT)
#
# _h = HTTPLib(CA_CERT, True, CLIENT_CERT)
# assert _h.request_args["verify"] == CA_CERT
def test_cookie(cookie_dealer):
cookie_value = "Something to pass along"
cookie_typ = "sso"
cookie_name = "Foobar"
kaka = cookie_dealer.create_cookie(cookie_value, cookie_typ,
cookie_name)
_h = HTTPLib()
set_cookie(_h.cookiejar, SimpleCookie(kaka[1]))
res = _h._cookies()
assert set(res.keys()) == {'Foobar'}
kwargs = _h.add_cookies({})
assert 'cookies' in kwargs
assert set(kwargs['cookies'].keys()) == {'Foobar'}
class DummyResponse(object):
def __init__(self, status_code, data, headers):
self.status_code = status_code
self.data = data
self.headers = headers
def test_set_cookie(cookie_dealer):
cookie_value = "Something to pass along"
cookie_typ = "sso"
cookie_name = "Foobar"
kaka = cookie_dealer.create_cookie(cookie_value, cookie_typ,
cookie_name)
_h = HTTPLib()
response = DummyResponse(200, 'OK', {"set-cookie": kaka[1]})
_h.set_cookie(response)
res = _h._cookies()
assert set(res.keys()) == {'Foobar'}