Ejemplo n.º 1
0
def test_factory():
    sdb = DictSessionBackend()
    consumer = Consumer(
        sdb,
        client_config=CLIENT_CONFIG,
        server_info=SERVER_INFO,
        settings=CLIENT_SETTINGS,
        **CONSUMER_CONFIG,
    )
    sid = stateID("https://example.org/", consumer.seed)
    _state = sid
    consumer._backup(sid)
    consumer.sdb["seed:%s" % consumer.seed] = sid

    kaka = make_cookie(CLIENT_CONFIG["client_id"],
                       _state,
                       consumer.seed,
                       expire=360,
                       path="/")

    _oac = factory(
        kaka[1],
        sdb,
        CLIENT_CONFIG["client_id"],
        client_config=CLIENT_CONFIG,
        server_info=SERVER_INFO,
        **CONSUMER_CONFIG,
    )

    assert _oac.client_id == consumer.client_id
    assert _oac.seed == consumer.seed
Ejemplo n.º 2
0
def test_factory():
    _session_db = {}
    cons = Consumer(_session_db,
                    client_config=CLIENT_CONFIG,
                    server_info=SERVER_INFO,
                    **CONSUMER_CONFIG)

    sid = stateID("https://example.org/", cons.seed)
    cons.state = sid
    cons._backup(sid)
    cons.sdb["seed:%s" % cons.seed] = sid

    kaka = make_cookie(CLIENT_CONFIG["client_id"],
                       cons.state,
                       cons.seed,
                       expire=360,
                       path="/")

    _oac = factory(kaka[1],
                   _session_db,
                   CLIENT_CONFIG["client_id"],
                   client_config=CLIENT_CONFIG,
                   server_info=SERVER_INFO,
                   **CONSUMER_CONFIG)

    assert _oac
    assert _oac.state == cons.state
    assert _oac.seed == cons.seed
Ejemplo n.º 3
0
    def authn_reply(self, areq, aresp, bsid, **kwargs):
        """

        :param areq: Authorization Request
        :param aresp: Authorization Response
        :param bsid: Session id
        :param kwargs: Additional keyword args
        :return:
        """
        if "redirect_uri" in areq:
            # TODO verify that the uri is reasonable
            redirect_uri = areq["redirect_uri"]
        else:
            redirect_uri = self.urlmap[areq["client_id"]]

        location = location_url(areq["response_type"], redirect_uri,
                                aresp.to_urlencoded())

        LOG_DEBUG("Redirected to: '%s' (%s)" % (location, type(location)))

        # set cookie containing session ID

        cookie = make_cookie(self.cookie_name, bsid, self.seed)

        return Redirect(str(location), headers=[cookie])
    def authn_reply(self, areq, aresp, bsid, **kwargs):
        """

        :param areq: Authorization Request
        :param aresp: Authorization Response
        :param bsid: Session id
        :param kwargs: Additional keyword args
        :return:
        """
        if "redirect_uri" in areq:
            # TODO verify that the uri is reasonable
            redirect_uri = areq["redirect_uri"]
        else:
            redirect_uri = self.urlmap[areq["client_id"]]

        location = location_url(areq["response_type"], redirect_uri,
                                aresp.to_urlencoded())

        LOG_DEBUG("Redirected to: '%s' (%s)" % (location, type(location)))

        # set cookie containing session ID

        cookie = make_cookie(self.cookie_name, bsid, self.seed)

        return Redirect(str(location), headers=[cookie])
Ejemplo n.º 5
0
 def write_session_cookie(self, value, http_only=True, same_site=""):
     return make_cookie(
         self.session_cookie_name,
         value,
         self.seed,
         path="/",
         httponly=http_only,
         same_site=same_site,
     )
Ejemplo n.º 6
0
 def create_cookie(self, value, cookie_name=None, typ="uam", ttl=-1):
     if ttl < 0:
         ttl = self.cookie_ttl
     if cookie_name is None:
         cookie_name = self.srv.cookie_name
     timestamp = str(int(time.mktime(time.gmtime())))
     info = AES_encrypt(self.srv.symkey,
                        "::".join([value, timestamp, typ]),
                        self.srv.iv)
     cookie = make_cookie(cookie_name, info, self.srv.seed,
                          expire=ttl, domain="", path="")
     return cookie
Ejemplo n.º 7
0
def test_factory():
    sdb = {}
    consumer = Consumer(sdb, client_config=CLIENT_CONFIG,
                        server_info=SERVER_INFO, **CONSUMER_CONFIG)
    sid = stateID("https://example.org/", consumer.seed)
    _state = sid
    consumer._backup(sid)
    consumer.sdb["seed:%s" % consumer.seed] = sid

    kaka = make_cookie(CLIENT_CONFIG["client_id"], _state, consumer.seed,
                       expire=360, path="/")

    _oac = factory(kaka[1], sdb, CLIENT_CONFIG["client_id"],
                   client_config=CLIENT_CONFIG, server_info=SERVER_INFO,
                   **CONSUMER_CONFIG)

    assert _oac.client_id == consumer.client_id
    assert _oac.seed == consumer.seed
Ejemplo n.º 8
0
 def delete_session_cookie(self):
     return make_cookie(self.session_cookie_name, "", b"", path="/",
                        expire=-1)
Ejemplo n.º 9
0
 def write_session_cookie(self, value):
     return make_cookie(self.session_cookie_name, value, self.seed, path="/")
Ejemplo n.º 10
0
 def delete_session_cookie(self):
     return make_cookie(self.session_cookie_name, "", b"", path="/",
                        expire=-1)
Ejemplo n.º 11
0
 def write_session_cookie(self, value):
     return make_cookie(self.session_cookie_name, value, self.seed, path="/")