예제 #1
0
def verifNonce(bookStoreCLI, bookStoreConnected):
    checkCmdValid(bookStoreCLI, "generate verification nonce")
    search = re.search("^Verification nonce is (.*)$",
                       bookStoreCLI.lastCmdOutput, re.MULTILINE)
    assert search
    nonce = search.group(1)
    assert nonce
    return nonce
예제 #2
0
def tylerStoresAttributesAsKnownToBYU(tylerCreated, tylerCLI, nodesSetup,
                                      byuCLI, tylerConnected):
    issuerId = byuCLI.activeWallet.defaultId
    checkCmdValid(
        tylerCLI, "attribute known to {} first_name=Tyler, last_name=Ruff, "
        "birth_date=12/17/1991, expiry_date=12/31/2101, "
        "undergrad=True, "
        "postgrad=False".format(issuerId))
    assert issuerId in tylerCLI.attributeRepo.attributes
예제 #3
0
def storedCred(tylerCLI, storedCredAlias, byuCreatedCredential,
               credDefNameVersion, byuPubKey, byuCLI, tylerPreparedU):
    proofId, U = tylerPreparedU
    assert len(tylerCLI.activeWallet.credNames) == 0
    checkCmdValid(
        tylerCLI, "store credential A={}, e={}, vprimeprime={} for "
        "credential {} as {}".format(*byuCreatedCredential, proofId,
                                     storedCredAlias))
    assert len(tylerCLI.activeWallet.credNames) == 1
    assert tylerCLI.lastCmdOutput == "Credential stored"
예제 #4
0
    def _(attempt, expect=None, within=None, mapper=None, not_expect=None):
        cli = ctx['current_cli']

        # This if was not there earlier, but I felt a need to reuse this
        # feature (be, do, expect ...) without attempting anything
        # mostly because there will be something async which will do something,
        # hence I added the below if check

        if attempt:
            attempt = attempt.format(**mapper) if mapper else attempt
            checkCmdValid(cli, attempt)

        def check():
            nonlocal expect
            nonlocal not_expect

            def chk(obj, parity=True):
                if not obj:
                    return
                if isinstance(obj, str) or callable(obj):
                    obj = [obj]
                for e in obj:
                    if isinstance(e, str):
                        e = e.format(**mapper) if mapper else e
                        if parity:
                            assert e in cli.lastCmdOutput
                        else:
                            assert e not in cli.lastCmdOutput
                    elif callable(e):
                        # callables should raise exceptions to signal an error
                        if parity:
                            e(cli)
                        else:
                            try:
                                e(cli)
                            except:
                                # Since its a test so not using logger is not
                                # a big deal
                                traceback.print_exc()
                                continue
                            raise RuntimeError("did not expect success")
                    else:
                        raise AttributeError("only str, callable, or "
                                             "collections of str and callable "
                                             "are allowed")

            chk(expect)
            chk(not_expect, False)

        if within:
            cli.looper.run(eventually(check, timeout=within))
        else:
            check()
예제 #5
0
def testVerifyProof(preparedProof, bookStoreCLI, bookStoreConnected,
                    revealedAtrr):
    checkCmdValid(
        bookStoreCLI,
        "verify status is {} in proof {}".format(revealedAtrr, preparedProof))

    def chk():
        out = "Proof verified successfully"
        # TODO: Find out why this cant be done using lastCmdOutput
        assert out in [o['msg'] for o in bookStoreCLI.printeds]

    bookStoreCLI.looper.run(eventually(chk, retryWait=1, timeout=15))
예제 #6
0
def attrAddedToRepo(attrRepoInitialized):
    byuCLI = attrRepoInitialized
    proverId = "Tyler"
    assert byuCLI.attributeRepo.getAttributes(proverId) is None
    checkCmdValid(
        byuCLI, "add attribute first_name=Tyler, last_name=Ruff, "
        "birth_date=12/17/1991, expiry_date=12/31/2101, "
        "undergrad=True, "
        "postgrad=False for {}".format(proverId))
    assert byuCLI.lastCmdOutput == \
           "attribute added successfully for prover id {}".format(proverId)
    assert byuCLI.attributeRepo.getAttributes(proverId) is not None
예제 #7
0
def byuAddsIssuerKey(byuCLI, byuAddsCredDef, credDefNameVersion):
    origin = byuAddsCredDef
    key = (*credDefNameVersion, origin)
    credDef = byuCLI.activeWallet.getCredDef(key=key)
    cmd = ("send ISSUER_KEY reference={}".format(credDef.seqNo))
    checkCmdValid(byuCLI, cmd)

    def checkIsKAdded():
        assert byuCLI.activeWallet.getIssuerPublicKey((origin, credDef.seqNo))
        output = byuCLI.lastCmdOutput
        assert "issuer key is published" in output

    byuCLI.looper.run(eventually(checkIsKAdded, retryWait=1, timeout=15))
    return byuCLI.activeWallet.getIssuerPublicKey((origin, credDef.seqNo))
예제 #8
0
def preparedProof(tylerCLI, storedCred, verifNonce, storedCredAlias,
                  tylerPreparedU, revealedAtrr):
    """
       prepare proof of <credential alias> using nonce <nonce> for <revealed
       attrs>
       """
    checkCmdValid(
        tylerCLI, "prepare proof of {} using nonce {} for {}".format(
            storedCredAlias, verifNonce, revealedAtrr))
    assert tylerCLI.lastCmdOutput.startswith("Proof is:")
    pat = re.compile("Proof is: (.+)$")
    m = pat.search(tylerCLI.lastCmdOutput)
    if m:
        proof = m.groups()[0]
        return proof
def testAddGenesisTransactions(cli):
    nym = "cx3ePPiBdRyab1900mZdtlzF5FGmX06Fj2sAYbMdF18="
    role = STEWARD
    typ = NYM
    checkCmdValid(cli, "add genesis transaction {} dest={} role={}"
                  .format(typ, nym, role))
    nymCorrect = False
    roleCorrect = False

    for txn in cli.genesisTransactions:
        if not nymCorrect and txn.get(TARGET_NYM) == nym:
            nymCorrect = True
            if txn.get(ROLE) == role:
                roleCorrect = True

    assert nymCorrect and roleCorrect
    assert "Genesis transaction added" in cli.lastCmdOutput
예제 #10
0
def byuCreatedCredential(nodesSetup, byuCLI, tylerCLI,
                         tylerStoresAttributesAsKnownToBYU, tylerPreparedU,
                         credDefNameVersion):
    credDefName, credDefVersion = credDefNameVersion
    proofId, U = tylerPreparedU
    proverId = tylerCLI.activeWallet.defaultAlias
    checkCmdValid(
        byuCLI, "generate credential for {} for {} version {} with {}".format(
            proverId, credDefName, credDefVersion, U))
    assert "Credential:" in byuCLI.lastCmdOutput
    pat = re.compile(
        "A\s*=\s*([mod0-9\s]+), e\s*=\s*([mod0-9\s]+), vprimeprime\s*=\s*(["
        "mod0-9\s]+)")
    m = pat.search(byuCLI.lastCmdOutput)
    if m:
        A, e, vprimeprime = m.groups()
        return A, e, vprimeprime
def executeAndCheckGenTxn(cli, cmd, typ, nym, role=None, data=None):
    checkCmdValid(cli, cmd)
    nymCorrect = False
    roleCorrect = False if role else True
    dataCorrect = False if data else True
    typeCorrect = False if typ else True

    for txn in cli.genesisTransactions:
        if txn.get(TARGET_NYM) == nym:
            nymCorrect = True
            if txn.get(TYPE) == typ:
                typeCorrect = True
            if txn.get(ROLE) == role:
                roleCorrect = True
            if data and txn.get(DATA) == json.loads(data):
                dataCorrect = True

    assert typeCorrect and nymCorrect and roleCorrect and dataCorrect
    assert "Genesis transaction added" in cli.lastCmdOutput
def executeAndCheckGenTxn(cli, cmd, typ, nym, role=None, data=None):
    checkCmdValid(cli, cmd)
    nymCorrect = False
    roleCorrect = False if role else True
    dataCorrect = False if data else True
    typeCorrect = False if typ else True

    role = Roles[role].value if role else role
    for txn in cli.genesisTransactions:
        if txn.get(TARGET_NYM) == nym:
            nymCorrect = True
            if txn.get(TYPE) == typ:
                typeCorrect = True
            if txn.get(ROLE) == role:
                roleCorrect = True
            if data and txn.get(DATA) == json.loads(data):
                dataCorrect = True

    assert typeCorrect and nymCorrect and roleCorrect and dataCorrect
    assert "Genesis transaction added" in cli.lastCmdOutput
예제 #13
0
def byuAddsCredDef(byuCLI, byuCreated, tylerCreated, byuPubKey,
                   credDefNameVersion):
    credDefName, credDefVersion = credDefNameVersion
    # TODO tylerAdded ensures that activeClient is already set.
    """BYU writes a credential definition to Sovrin."""
    cmd = ("send CRED_DEF name={} version={} "
           "type=CL keys=undergrad,last_name,"
           "first_name,birth_date,postgrad,expiry_date".format(
               credDefName, credDefVersion))
    checkCmdValid(byuCLI, cmd)

    def checkCredAdded():
        txns = byuCLI.activeClient.getTxnsByType(CRED_DEF)
        assert any(txn[NAME] == credDefName and txn[VERSION] == credDefVersion
                   for txn in txns)
        output = byuCLI.lastCmdOutput
        assert "credential definition is published" in output
        assert credDefName in output

    byuCLI.looper.run(eventually(checkCredAdded, retryWait=1, timeout=15))
    return byuCLI.activeWallet.defaultId
예제 #14
0
def tylerPreparedU(nodesSetup, tylerCreated, tylerCLI, byuCLI, attrAddedToRepo,
                   byuAddsCredDef, byuAddsIssuerKey, credDefNameVersion,
                   tylerConnected, tylerStoresAttributesAsKnownToBYU):
    credDefName, credDefVersion = credDefNameVersion
    issuerIdentifier = byuAddsCredDef
    proverName = tylerCLI.activeWallet.defaultAlias
    checkCmdValid(
        tylerCLI, "request credential {} version {} from {} for {}".format(
            credDefName, credDefVersion, issuerIdentifier, proverName))

    def chk():
        out = "Credential request for {} for {} {} is".format(
            proverName, credDefName, credDefVersion)
        assert out in tylerCLI.lastCmdOutput

    tylerCLI.looper.run(eventually(chk, retryWait=1, timeout=15))
    U = None
    proofId = None
    pat = re.compile(
        "Credential id is ([a-f0-9\-]+) and U is ([0-9]+\s+mod\s+[0-9]+)")
    m = pat.search(tylerCLI.lastCmdOutput)
    if m:
        proofId, U = m.groups()
    return proofId, U
예제 #15
0
    def _(attempt, expect=None, within=None, mapper=None, not_expect=None):
        cli = ctx['current_cli']

        # This if was not there earlier, but I felt a need to reuse this
        # feature (be, do, expect ...) without attempting anything
        # mostly because there will be something async which will do something,
        # hence I added the below if check

        if attempt:
            attempt = attempt.format(**mapper) if mapper else attempt
            checkCmdValid(cli, attempt)

        def check():
            nonlocal expect
            nonlocal not_expect

            def chk(obj, parity=True):
                if not obj:
                    return
                if isinstance(obj, str) or callable(obj):
                    obj = [obj]
                for e in obj:
                    if isinstance(e, str):
                        e = e.format(**mapper) if mapper else e
                        try:
                            if parity:
                                assert e in cli.lastCmdOutput
                            else:
                                assert e not in cli.lastCmdOutput
                        except AssertionError as e:
                            extraMsg = ""
                            if not within:
                                extraMsg = "NOTE: 'within' parameter was not " \
                                           "provided, if test should wait for" \
                                           " sometime before considering this" \
                                           " check failed, then provide that" \
                                           " parameter with appropriate value"
                                separator = "-" * len(extraMsg)
                                extraMsg = "\n\n{}\n{}\n{}".format(
                                    separator, extraMsg, separator)
                            raise (AssertionError("{}{}".format(e, extraMsg)))
                    elif callable(e):
                        # callables should raise exceptions to signal an error
                        if parity:
                            e(cli)
                        else:
                            try:
                                e(cli)
                            except:
                                # Since its a test so not using logger is not
                                # a big deal
                                traceback.print_exc()
                                continue
                            raise RuntimeError("did not expect success")
                    else:
                        raise AttributeError("only str, callable, or "
                                             "collections of str and callable "
                                             "are allowed")

            chk(expect)
            chk(not_expect, False)

        if within:
            cli.looper.run(eventually(check, timeout=within))
        else:
            check()
예제 #16
0
def trusteeCreated(poolCLI, trusteePubKey):
    checkCmdValid(
        poolCLI, "add genesis transaction NYM dest={} role=STEWARD".format(
            trusteePubKey))
    assert "Genesis transaction added." in poolCLI.lastCmdOutput