Exemplo n.º 1
0
def test_bearer_body():
    client = Client("A")
    client.client_secret = "boarding pass"

    request_args = {"access_token": "Sesame"}

    cis = ResourceRequest()
    http_args = BearerBody(client).construct(cis, request_args)
    assert cis["access_token"] == "Sesame"
    print http_args
    assert http_args is None

    # ----------
    resp = AuthorizationResponse(code="code", state="state")
    grant = Grant()
    grant.add_code(resp)

    atr = AccessTokenResponse(access_token="2YotnFZFEjr1zCsicMWpAA",
                              token_type="example",
                              refresh_token="tGzv3JOkF0XG5Qx2TlKWIA",
                              example_parameter="example_value",
                              scope=["inner", "outer"])

    grant.add_token(atr)
    client.grant["state"] = grant

    cis = ResourceRequest()
    http_args = BearerBody(client).construct(cis, {},
                                             state="state",
                                             scope="inner")
    assert cis["access_token"] == "2YotnFZFEjr1zCsicMWpAA"
    print http_args
    assert http_args is None
Exemplo n.º 2
0
    def test_construct_with_request_args(self, client):
        request_args = {"access_token": "Sesame"}
        cis = ResourceRequest()
        http_args = BearerBody(client).construct(cis, request_args)

        assert cis["access_token"] == "Sesame"
        assert http_args is None
Exemplo n.º 3
0
    def test_construct_with_request(self, client):
        resp1 = AuthorizationResponse(code="auth_grant", state="state")
        client.parse_response(AuthorizationResponse, resp1.to_urlencoded(),
                              "urlencoded")
        resp2 = AccessTokenResponse(access_token="token1",
                                    token_type="Bearer", expires_in=0,
                                    state="state")
        client.parse_response(AccessTokenResponse, resp2.to_urlencoded(),
                              "urlencoded")

        cis = ResourceRequest()
        BearerBody(client).construct(cis, state="state")

        assert "access_token" in cis
        assert cis["access_token"] == "token1"
Exemplo n.º 4
0
    def test_construct_with_state(self, client):
        resp = AuthorizationResponse(code="code", state="state")
        grant = Grant()
        grant.add_code(resp)
        atr = AccessTokenResponse(access_token="2YotnFZFEjr1zCsicMWpAA",
                                  token_type="example",
                                  refresh_token="tGzv3JOkF0XG5Qx2TlKWIA",
                                  example_parameter="example_value",
                                  scope=["inner", "outer"])
        grant.add_token(atr)
        client.grant["state"] = grant

        cis = ResourceRequest()
        http_args = BearerBody(client).construct(cis, {}, state="state",
                                                 scope="inner")
        assert cis["access_token"] == "2YotnFZFEjr1zCsicMWpAA"
        assert http_args is None
Exemplo n.º 5
0
def test_bearer_body_get_token():
    client = Client("A")
    client.client_secret = "boarding pass"

    resp1 = AuthorizationResponse(code="auth_grant", state="state")
    client.parse_response(AuthorizationResponse, resp1.to_urlencoded(),
                          "urlencoded")
    resp2 = AccessTokenResponse(access_token="token1",
                                token_type="Bearer", expires_in=0,
                                state="state")
    client.parse_response(AccessTokenResponse, resp2.to_urlencoded(),
                          "urlencoded")

    cis = ResourceRequest()

    _ = BearerBody(client).construct(cis, state="state")

    assert "access_token" in cis
    assert cis["access_token"] == "token1"