def test_verify_not_strict(key, value, monkeypatch):
    shr = SignedHttpRequest(SIGN_KEY)
    result = shr.sign(alg=ALG, **TEST_DATA)
    monkeypatch.setitem(TEST_DATA, key, value)
    shr.verify(signature=result,
               strict_query_params_verification=False,
               strict_headers_verification=False, **TEST_DATA)
Exemplo n.º 2
0
def test_verify_fail(param, value):
    shr = SignedHttpRequest(SIGN_KEY)
    result = shr.sign(alg=ALG, **DEFAULT_DATA)

    wrong_data = DEFAULT_DATA.copy()
    wrong_data[param] = value
    with pytest.raises(ValidationError):
        shr.verify(signature=result, **wrong_data)
Exemplo n.º 3
0
def test_verify_fail(param, value):
    shr = SignedHttpRequest(SIGN_KEY)
    result = shr.sign(alg=ALG, **DEFAULT_DATA)

    wrong_data = DEFAULT_DATA.copy()
    wrong_data[param] = value
    with pytest.raises(ValidationError):
        shr.verify(signature=result, **wrong_data)
Exemplo n.º 4
0
def test_verify_with_too_few(param):
    test_data = copy.deepcopy(DEFAULT_DATA)
    test_data[param]["foo"] = "bar"  # insert extra param
    shr = SignedHttpRequest(SIGN_KEY)
    result = shr.sign(alg=ALG, **test_data)

    with pytest.raises(ValidationError):
        shr.verify(signature=result, **DEFAULT_DATA)
def test_verify_strict(key, value, monkeypatch):
    shr = SignedHttpRequest(SIGN_KEY)
    result = shr.sign(alg=ALG, **TEST_DATA)
    monkeypatch.setitem(TEST_DATA, key, value)
    with pytest.raises(ValidationError):
        shr.verify(signature=result,
                   strict_query_params_verification=True,
                   strict_headers_verification=True, **TEST_DATA)
Exemplo n.º 6
0
def test_verify_with_too_few(param):
    test_data = copy.deepcopy(DEFAULT_DATA)
    test_data[param]["foo"] = "bar"  # insert extra param
    shr = SignedHttpRequest(SIGN_KEY)
    result = shr.sign(alg=ALG, **test_data)

    with pytest.raises(ValidationError):
        shr.verify(signature=result, **DEFAULT_DATA)
Exemplo n.º 7
0
def test_verify_reject_jws_wo_typ_pop():
    method = "GET"

    signature_without_typ = JWS(json.dumps(dict(m=method)), alg=ALG).sign_compact([SIGN_KEY])
    shr = SignedHttpRequest(SIGN_KEY)
    with pytest.raises(ValidationError) as exc:
        shr.verify(signature_without_typ, method=method)

    assert "typ" in str(exc.value)
Exemplo n.º 8
0
def test_verify_not_strict(param):
    shr = SignedHttpRequest(SIGN_KEY)
    result = shr.sign(alg=ALG, **DEFAULT_DATA)

    request_with_extra_params = copy.deepcopy(DEFAULT_DATA)
    request_with_extra_params[param]["foo"] = "bar"  # insert extra param
    shr.verify(
        signature=result, strict_query_params_verification=False, strict_headers_verification=False, **DEFAULT_DATA
    )
Exemplo n.º 9
0
def test_verify_not_strict(param):
    shr = SignedHttpRequest(SIGN_KEY)
    result = shr.sign(alg=ALG, **DEFAULT_DATA)

    request_with_extra_params = copy.deepcopy(DEFAULT_DATA)
    request_with_extra_params[param]["foo"] = "bar"  # insert extra param
    shr.verify(signature=result,
               strict_query_params_verification=False,
               strict_headers_verification=False,
               **DEFAULT_DATA)
Exemplo n.º 10
0
def test_verify_reject_jws_wo_typ_pop():
    method = "GET"

    signature_without_typ = JWS(json.dumps(dict(m=method)),
                                alg=ALG).sign_compact([SIGN_KEY])
    shr = SignedHttpRequest(SIGN_KEY)
    with pytest.raises(ValidationError) as exc:
        shr.verify(signature_without_typ, method=method)

    assert "typ" in str(exc.value)
Exemplo n.º 11
0
def test_verify_strict_with_too_many(param):
    shr = SignedHttpRequest(SIGN_KEY)
    result = shr.sign(alg=ALG, **DEFAULT_DATA)

    request_with_extra_params = copy.deepcopy(DEFAULT_DATA)
    request_with_extra_params[param]["foo"] = "bar"  # insert extra param
    with pytest.raises(ValidationError):
        shr.verify(signature=result,
                   strict_query_params_verification=True,
                   strict_headers_verification=True,
                   **request_with_extra_params)
Exemplo n.º 12
0
def test_verify_strict_with_too_many(param):
    shr = SignedHttpRequest(SIGN_KEY)
    result = shr.sign(alg=ALG, **DEFAULT_DATA)

    request_with_extra_params = copy.deepcopy(DEFAULT_DATA)
    request_with_extra_params[param]["foo"] = "bar"  # insert extra param
    with pytest.raises(ValidationError):
        shr.verify(
            signature=result,
            strict_query_params_verification=True,
            strict_headers_verification=True,
            **request_with_extra_params
        )
Exemplo n.º 13
0
def test_verify():
    timestamp = 12347456
    shr = SignedHttpRequest(SIGN_KEY)
    result = shr.sign(alg=ALG, time_stamp=12347456, **DEFAULT_DATA)
    signature = shr.verify(signature=result, **DEFAULT_DATA)

    assert signature["ts"] == timestamp
Exemplo n.º 14
0
def test_verify():
    timestamp = 12347456
    shr = SignedHttpRequest(SIGN_KEY)
    result = shr.sign(alg=ALG, time_stamp=12347456, **DEFAULT_DATA)
    signature = shr.verify(signature=result, **DEFAULT_DATA)

    assert signature["ts"] == timestamp
Exemplo n.º 15
0
    def eval_signed_http_request(self, pop_token, access_token, method, url,
                                 headers, body=''):
        kwargs = sign_http_args(method, url, headers, body)

        shr = SignedHttpRequest(self.token2key[access_token][0])
        return shr.verify(signature=pop_token,
                          strict_query_params_verification=True,
                          strict_headers_verification=True, **kwargs)
Exemplo n.º 16
0
    def eval_signed_http_request(self, pop_token, access_token, method, url,
                                 headers, body=''):
        kwargs = sign_http_args(method, url, headers, body)

        shr = SignedHttpRequest(self.token2key[access_token][0])
        return shr.verify(signature=pop_token,
                          strict_query_params_verification=True,
                          strict_headers_verification=True, **kwargs)
Exemplo n.º 17
0
    def userinfo_endpoint(self, request, **kwargs):
        access_token = self._parse_access_token(request)
        shr = SignedHttpRequest(self._get_client_public_key(access_token))
        http_signature = self._parse_signature(request)
        try:
            shr.verify(http_signature,
                       method=request["method"],
                       host=request["host"], path=request["path"],
                       query_params=request["query"],
                       headers=request["headers"],
                       body=request["body"],
                       strict_query_param_verification=True,
                       strict_headers_verification=False)
        except ValidationError:
            return self._error_response("access_denied",
                                        descr="Could not verify proof of "
                                              "possession")

        return self._do_user_info(self.access_tokens[access_token], **kwargs)
Exemplo n.º 18
0
    def userinfo_endpoint(self, request, **kwargs):
        access_token = self._parse_access_token(request)
        shr = SignedHttpRequest(self._get_client_public_key(access_token))
        http_signature = self._parse_signature(request)
        try:
            shr.verify(http_signature,
                       method=request["method"],
                       host=request["host"],
                       path=request["path"],
                       query_params=request["query"],
                       headers=request["headers"],
                       body=request["body"],
                       strict_query_param_verification=True,
                       strict_headers_verification=False)
        except ValidationError:
            return self._error_response("access_denied",
                                        descr="Could not verify proof of "
                                        "possession")

        return self._do_user_info(self.access_tokens[access_token], **kwargs)
Exemplo n.º 19
0
def test_verify_fail_wrong_key():
    shr = SignedHttpRequest(SIGN_KEY)
    result = shr.sign(alg=ALG, **DEFAULT_DATA)
    with pytest.raises(ValidationError):
        rshr = SignedHttpRequest(SYMKey(key="wrong_key", alg="HS256"))
        rshr.verify(signature=result, **DEFAULT_DATA)
Exemplo n.º 20
0
def test_verify_fail_on_missing_body():
    shr = SignedHttpRequest(SIGN_KEY)
    result = shr.sign(alg=ALG, body="abcdef")
    with pytest.raises(ValidationError):
        shr.verify(signature=result)
Exemplo n.º 21
0
def test_verify_fail_wrong_key():
    shr = SignedHttpRequest(SIGN_KEY)
    result = shr.sign(alg=ALG, **DEFAULT_DATA)
    with pytest.raises(ValidationError):
        rshr = SignedHttpRequest(SYMKey(key="wrong_key", alg="HS256"))
        rshr.verify(signature=result, **DEFAULT_DATA)
Exemplo n.º 22
0
def test_verify_fail_on_missing_body():
    shr = SignedHttpRequest(SIGN_KEY)
    result = shr.sign(alg=ALG, body="abcdef")
    with pytest.raises(ValidationError):
        shr.verify(signature=result)
def test_verify_fail(key, value, monkeypatch):
    shr = SignedHttpRequest(SIGN_KEY)
    result = shr.sign(alg=ALG, **TEST_DATA)
    monkeypatch.setitem(TEST_DATA, key, value)
    with pytest.raises(ValidationError):
        shr.verify(signature=result, **TEST_DATA)