Exemplo n.º 1
0
def testGetAllHistories():
    seed = b'\x92[\xcb\xf4\xee5+\xcf\xd4b*%/\xabw8\xd4d\xa2\xf8\xad\xa7U\x19,\xcfS\x12\xa6l\xba"'

    dbing.setupDbEnv(DB_DIR_PATH)

    data = {
        "id":
        DID,
        "signer":
        0,
        "signers": [
            "NOf6ZghvGNbFc_wr3CC0tKZHz1qWAR4lD5aM-i0zSjw=",
            "NOf6ZghvGNbFc_wr3CC0tKZHz1qWAR4lD5aM-i0zSjw="
        ]
    }

    sigs = [help.signResource(json.dumps(data).encode(), SK)]

    history1 = dbing.saveHistory(DID, data, sigs)

    vk, sk, did, body = help.genDidHistory(seed, signer=0, numSigners=2)
    data = json.loads(body)
    sigs = [help.signResource(json.dumps(data).encode(), sk)]

    history2 = dbing.saveHistory(did, data, sigs)

    exp_data = {'data': [history1, history2]}

    actual_data = dbing.getAllHistories()

    assert actual_data == exp_data
Exemplo n.º 2
0
def testDeleteHistory():
    seed = b'\x92[\xcb\xf4\xee5+\xcf\xd4b*%/\xabw8\xd4d\xa2\xf8\xad\xa7U\x19,\xcfS\x12\xa6l\xba"'

    vk, sk, did, body = help.genDidHistory(seed, signer=0, numSigners=2)
    data = json.loads(body)
    sigs = [help.signResource(json.dumps(data).encode(), sk)]

    dbing.saveHistory(did, data, sigs)

    status = dbing.deleteHistory(did)

    assert status is True
    assert dbing.getHistory(did) is None
Exemplo n.º 3
0
def testGetHistory():
    dbing.setupDbEnv(DB_DIR_PATH)

    data = {
        "id":
        DID,
        "signer":
        0,
        "signers": [
            "NOf6ZghvGNbFc_wr3CC0tKZHz1qWAR4lD5aM-i0zSjw=",
            "NOf6ZghvGNbFc_wr3CC0tKZHz1qWAR4lD5aM-i0zSjw="
        ]
    }

    sigs = [help.signResource(json.dumps(data).encode(), SK)]

    exp_data = dbing.saveHistory(DID, data, sigs)

    actual_data = dbing.getHistory(DID)

    assert actual_data == exp_data
Exemplo n.º 4
0
def testSaveHistory():
    dbing.setupDbEnv(DB_DIR_PATH)

    data = {
        "id":
        DID,
        "signer":
        0,
        "signers": [
            "NOf6ZghvGNbFc_wr3CC0tKZHz1qWAR4lD5aM-i0zSjw=",
            "NOf6ZghvGNbFc_wr3CC0tKZHz1qWAR4lD5aM-i0zSjw="
        ]
    }

    sigs = [help.signResource(json.dumps(data).encode(), SK)]

    exp_data = dbing.saveHistory(DID, data, sigs)

    dbHistory = dbing.dideryDB.open_db(dbing.DB_KEY_HISTORY_NAME)

    with dbing.dideryDB.begin(db=dbHistory, write=True) as txn:
        actual_data = txn.get(DID.encode())

    assert actual_data == json.dumps(exp_data).encode()
Exemplo n.º 5
0
def testValidGetAll(client):
    history1 = {
        "id":
        "did:dad:NOf6ZghvGNbFc_wr3CC0tKZHz1qWAR4lD5aM-i0zSjw=",
        "changed":
        "2000-01-01T00:00:01+00:00",
        "signer":
        1,
        "signers": [
            "NOf6ZghvGNbFc_wr3CC0tKZHz1qWAR4lD5aM-i0zSjw=",
            "NOf6ZghvGNbFc_wr3CC0tKZHz1qWAR4lD5aM-i0zSjw=",
            "NOf6ZghvGNbFc_wr3CC0tKZHz1qWAR4lD5aM-i0zSjw="
        ]
    }
    history1_sigs = {
        "signer":
        "bANC2XMeQS2DGvazrW7n5NpBHgn7Pv9jrmxId0cxcjFjuHE4zi7AK-tsf2Ocim0p-b8Z5Go6TsyaURE0VKgVCw==",
        "rotation":
        "bANC2XMeQS2DGvazrW7n5NpBHgn7Pv9jrmxId0cxcjFjuHE4zi7AK-tsf2Ocim0p-b8Z5Go6TsyaURE0VKgVCw=="
    }
    db.saveHistory(DID, history1, history1_sigs)

    history2_did = "did:dad:KAApprffJUn1e9ugNmpM9JBswxJvEU8_XCljDCoxkII="
    history2 = {
        "id":
        history2_did,
        "changed":
        "2000-01-01T00:00:00+00:00",
        "signer":
        0,
        "signers": [
            "KAApprffJUn1e9ugNmpM9JBswxJvEU8_XCljDCoxkII=",
            "KAApprffJUn1e9ugNmpM9JBswxJvEU8_XCljDCoxkII=",
            "KAApprffJUn1e9ugNmpM9JBswxJvEU8_XCljDCoxkII=",
            "KAApprffJUn1e9ugNmpM9JBswxJvEU8_XCljDCoxkII="
        ]
    }
    history2_sigs = {
        "signer":
        "tR1_GN9E7oTYbAGebDTlliRJLjy5IFEHTjvimgg3g9xHJHp82cEyNMnViUbg_TULdGAdkpfvzT9icujXuC3EDw==",
        "rotation":
        "tR1_GN9E7oTYbAGebDTlliRJLjy5IFEHTjvimgg3g9xHJHp82cEyNMnViUbg_TULdGAdkpfvzT9icujXuC3EDw=="
    }
    db.saveHistory(history2_did, history2, history2_sigs)

    history3_did = "did:dad:iy67FstqFl_a5e-sni6yAWoj60-1E2RtzmMGjrjHaSY="
    history3 = {
        "id":
        history3_did,
        "changed":
        "2000-01-01T00:00:01+00:00",
        "signer":
        1,
        "signers": [
            "iy67FstqFl_a5e-sni6yAWoj60-1E2RtzmMGjrjHaSY=",
            "iy67FstqFl_a5e-sni6yAWoj60-1E2RtzmMGjrjHaSY=",
            "iy67FstqFl_a5e-sni6yAWoj60-1E2RtzmMGjrjHaSY="
        ]
    }
    history3_sigs = {
        "signer":
        "bu-HIoIp2ZtBqsZtURP_q6rm8WPuDQGtN6maXbDHZbVHJ-QfGpwvXkE-fmi7XymvQJnS9tZXFQ5MPos5u09HDw==",
        "rotation":
        "bu-HIoIp2ZtBqsZtURP_q6rm8WPuDQGtN6maXbDHZbVHJ-QfGpwvXkE-fmi7XymvQJnS9tZXFQ5MPos5u09HDw=="
    }
    db.saveHistory(history3_did, history3, history3_sigs)

    response = client.simulate_get(HISTORY_BASE_PATH)
    result = json.loads(response.content)

    exp_result = {
        "data": [{
            "history": history2,
            "signatures": history2_sigs
        }, {
            "history": history1,
            "signatures": history1_sigs
        }, {
            "history": history3,
            "signatures": history3_sigs
        }]
    }

    assert response.status == falcon.HTTP_200
    assert result == exp_result

    response = client.simulate_get(HISTORY_BASE_PATH,
                                   query_string="offset=100&limit=10")

    exp_result = {}

    assert response.status == falcon.HTTP_200
    assert json.loads(response.content) == exp_result