Пример #1
0
def test_cookie_dealer_1():
    cd = CookieDealer(DummyServer())
    kaka = cd.create_cookie("Something to pass along", "sso", "Foobar")
    #print kaka
    value, _ts, typ = cd.get_cookie_value(kaka[1], "Foobar")
    assert value == "Something to pass along"
    assert typ == "sso"
Пример #2
0
def test_cookie_dealer_1():
    cd = CookieDealer(DummyServer())
    kaka = cd.create_cookie("Something to pass along", "sso", "Foobar")
    # print kaka
    value, _ts, typ = cd.get_cookie_value(kaka[1], "Foobar")
    assert value == "Something to pass along"
    assert typ == "sso"
Пример #3
0
    def _create_cookie(self, user, client_id, c_type="sso"):
        cd = CookieDealer(self.provider)
        set_cookie = cd.create_cookie("{}][{}".format(user, client_id), c_type,
                                      self.provider.sso_cookie_name)
        cookies_string = set_cookie[1]
        all_cookies = SimpleCookie()  # type: SimpleCookie

        try:
            cookies_string = cookies_string.decode()
        except (AttributeError, UnicodeDecodeError):
            pass

        all_cookies.load(cookies_string)

        return all_cookies
Пример #4
0
    def test_cookie_dealer_with_path(self):
        class DomServer:
            def __init__(self):
                self.symkey = b"0123456789012345"
                self.cookie_path = "/oidc"

        cookie_dealer = CookieDealer(DomServer())

        cookie_value = "Something to pass along"
        cookie_typ = "sso"
        cookie_name = "Foobar"

        kaka = cookie_dealer.create_cookie(cookie_value, cookie_typ, cookie_name)
        C = SimpleCookie()
        C.load(kaka[1])

        assert C[cookie_name]["path"] == "/oidc"
Пример #5
0
    def test_cookie_dealer_with_domain(self):
        class DomServer:
            def __init__(self):
                self.symkey = b"0123456789012345"
                self.cookie_domain = "op.example.org"

        cookie_dealer = CookieDealer(DomServer())

        cookie_value = "Something to pass along"
        cookie_typ = "sso"
        cookie_name = "Foobar"

        kaka = cookie_dealer.create_cookie(cookie_value, cookie_typ, cookie_name)
        C: SimpleCookie = SimpleCookie()
        C.load(kaka[1])

        assert C[cookie_name]["domain"] == "op.example.org"
Пример #6
0
    def test_cookie_dealer_with_domain(self):
        class DomServer():
            def __init__(self):
                self.symkey = b"0123456789012345"
                self.cookie_domain = "op.example.org"

        cookie_dealer = CookieDealer(DomServer())

        cookie_value = "Something to pass along"
        cookie_typ = "sso"
        cookie_name = "Foobar"

        kaka = cookie_dealer.create_cookie(cookie_value, cookie_typ,
                                           cookie_name)
        C = SimpleCookie()
        C.load(kaka[1])

        assert C[cookie_name]["domain"] == "op.example.org"
Пример #7
0
    def test_create_cookie_value_no_secure(self):
        cookie_value = "Something to pass along"
        cookie_typ = "sso"
        cookie_name = "Foobar"

        class DummyServer:
            def __init__(self):
                self.symkey = b"0123456789012345"

        cookie_dealer = CookieDealer(DummyServer(), secure=False)
        kaka = cookie_dealer.create_cookie(cookie_value, cookie_typ, cookie_name)
        value, timestamp, typ = cookie_dealer.get_cookie_value(kaka[1], "Foobar")

        assert (value, typ) == (cookie_value, cookie_typ)
        t = SimpleCookie()
        t.load(kaka[1])
        morsel = t["Foobar"]
        assert not morsel["secure"]
        assert morsel["httponly"]
Пример #8
0
    def test_cookie_dealer_with_domain(self):
        class DomServer():
            def __init__(self):
                self.symkey = b"0123456789012345"
                self.cookie_domain = "op.example.org"

        cookie_dealer = CookieDealer(DomServer())

        cookie_value = "Something to pass along"
        cookie_typ = "sso"
        cookie_name = "Foobar"

        kaka = cookie_dealer.create_cookie(cookie_value, cookie_typ,
                                           cookie_name)
        C = SimpleCookie()
        if PY2:
            # the backported SimpleCookie wants py3 str
            C.load(newstr(kaka[1]))
        else:
            C.load(kaka[1])

        assert C[cookie_name]["domain"] == "op.example.org"