def test_add_url():
    issuer = KeyIssuer(httpc_params={"verify": True})
    url = "http://localhost/jwks.json"
    with responses.RequestsMock() as rsps:
        rsps.add(method="GET", url=url, json=JWK2, status=200)
        issuer.add(url)

    kb = issuer.find(url)
    assert len(kb) == 1
    assert kb[0].source == url
Ejemplo n.º 2
0
def test_key_issuer():
    kb = keybundle_from_local_file("file://%s/jwk.json" % BASE_PATH, "jwks", ["sig"])
    assert len(kb) == 1
    issuer = KeyIssuer()
    issuer.add(kb)

    _item = item.KeyIssuer().serialize(issuer)
    _iss = item.KeyIssuer().deserialize(_item)

    assert len(_iss) == 1  # 1 key
    assert len(_iss.get("sig", "rsa")) == 1  # 1 RSA key
    _kb = _iss[0]
    assert kb.difference(_kb) == []  # no difference
def test_items():
    issuer = KeyIssuer(name="foo")
    url = "http://localhost/jwks.json"
    with responses.RequestsMock() as rsps:
        rsps.add(method="GET", url=url, json=JWK2, status=200)
        issuer.add(url)

    issuer.add("LongRamblingKeyThatShouldBeLongEnough")

    items = issuer.items()
    assert set(items.keys()) == {None, url}
    assert items[None][0].keys()[0].kty == "oct"
    assert len(items[url][0].keys()) == 4
def test_str():
    issuer = KeyIssuer(name="foo")
    issuer.add("LongRamblingKeyThatShouldBeLongEnough")
    assert str(issuer).startswith('<KeyIssuer "foo" oct::')
def test_add_symmetric():
    issuer = KeyIssuer()
    issuer.add("LongRamblingKeyThatShouldBeLongEnough")
    kb = issuer.find(None)
    assert len(kb) == 1
    assert kb[0].keys()[0].kty == "oct"