Example #1
0
def test_key_new_load():
    owner = "http://lol.com"
    k = Key(owner)
    k.new()

    assert k.to_dict() == {
        "id": f"{owner}#main-key",
        "owner": owner,
        "publicKeyPem": k.pubkey_pem,
    }

    k2 = Key(owner)
    k2.load(k.privkey_pem)

    assert k2.to_dict() == k.to_dict()
Example #2
0
def test_httpsig():
    back = InMemBackend()
    ap.use_backend(back)

    k = Key("https://lol.com")
    k.new()
    back.FETCH_MOCK["https://lol.com#main-key"] = {
        "publicKey": k.to_dict(),
        "id": "https://lol.com",
    }

    httpretty.register_uri(httpretty.POST,
                           "https://remote-instance.com",
                           body="ok")

    auth = httpsig.HTTPSigAuth(k)
    resp = requests.post("https://remote-instance.com",
                         json={"ok": 1},
                         auth=auth)

    assert httpsig.verify_request(
        resp.request.method,
        resp.request.path_url,
        resp.request.headers,
        resp.request.body,
    )