def test_authentication(pre_reqs, registration, client1, wallet1):
    _, core_authnr, req_authnr = pre_reqs

    # Remove simple_authnr
    req_authnr._authenticators = req_authnr._authenticators[:-1]

    # Exception for unknown txn type
    op = {
        TXN_TYPE: 'random_txn_type',
        f.LEDGER_ID.nm: DOMAIN_LEDGER_ID,
        DATA: 1
    }
    # Just creating the request
    req = submitOp(wallet1, client1, op)
    with pytest.raises(NoAuthenticatorFound):
        req_authnr.authenticate(req.as_dict)

    # Empty set for query txn type
    op = {
        TXN_TYPE: GET_TXN,
        f.LEDGER_ID.nm: DOMAIN_LEDGER_ID,
        DATA: 1
    }
    # Just creating the request
    req = submitOp(wallet1, client1, op)
    assert set() == req_authnr.authenticate(req.as_dict)

    # identifier for write type
    req, new_wallet = new_client_request(None, randomString(), wallet1)
    core_authnr.addIdr(wallet1.defaultId,
                       wallet1.getVerkey(wallet1.defaultId))
    assert req_authnr.authenticate(req.as_dict) == {wallet1.defaultId, }
def testAuctionReqValidationPlugin(looper, nodeSet, wallet1, client1, tdir,
                                   pluginVerPath):
    # TODO: Test more cases
    plugin = PluginLoader(pluginVerPath)
    plugin = next(iter(plugin.plugins[PLUGIN_TYPE_VERIFICATION]))
    commonError = "client request invalid: InvalidClientRequest()"
    allCoros = []
    op = {
        TXN_TYPE: "dummy",
        DATA: {
            AMOUNT: 30
    }}
    req = submitOp(wallet1, client1, op)
    validTypes = ', '.join(plugin.validTxnTypes)
    update = {
        'reason': makeReason(commonError, "dummy is not a valid transaction "
                                          "type, must be one of {}"
                             .format(validTypes))}

    allCoros += [partial(checkReqNack, client1, node, req.identifier,
                         req.reqId, update) for node in nodeSet]

    op = {
        TXN_TYPE: AUCTION_START,
    }
    req = submitOp(wallet1, client1, op)
    update = {
        'reason': makeReason(commonError,
                             "{} attribute is missing or not in proper format"
                             .format(DATA))}

    allCoros += [partial(checkReqNack, client1, node, req.identifier,
                         req.reqId, update) for node in nodeSet]

    op = {
        TXN_TYPE: PLACE_BID,
    }
    req = submitOp(wallet1, client1, op)
    update = {
        'reason': makeReason(commonError,
                             "{} attribute is missing or not in proper format"
                             .format(DATA))}

    allCoros += [partial(checkReqNack, client1, node, req.identifier,
                         req.reqId, update) for node in nodeSet]

    op = {
        TXN_TYPE: PLACE_BID,
        DATA: "some string"
    }
    req = submitOp(wallet1, client1, op)
    update = {
        'reason': makeReason(commonError,
                             "{} attribute is missing or not in proper format"
                             .format(DATA))}

    allCoros += [partial(checkReqNack, client1, node, req.identifier,
                         req.reqId, update) for node in nodeSet]

    op = {
        TXN_TYPE: PLACE_BID,
        DATA: {
            AMOUNT: 453
    }}
    req = submitOp(wallet1, client1, op)
    update = {
        'reason': makeReason(commonError, "No id provided for auction")}

    allCoros += [partial(checkReqNack, client1, node, req.identifier,
                         req.reqId, update) for node in nodeSet]

    op = {
        TXN_TYPE: AUCTION_START,
        DATA: {}
    }
    req = submitOp(wallet1, client1, op)
    update = {
        'reason': makeReason(commonError, "No id provided for auction")}

    allCoros += [partial(checkReqNack, client1, node, req.identifier,
                         req.reqId, update) for node in nodeSet]

    op = {
        TXN_TYPE: AUCTION_END,
        DATA: {}
    }
    req = submitOp(wallet1, client1, op)
    update = {
        'reason': makeReason(commonError, "No id provided for auction")}

    allCoros += [partial(checkReqNack, client1, node, req.identifier,
                         req.reqId, update) for node in nodeSet]

    auctionId = str(uuid4())

    op = {
        TXN_TYPE: PLACE_BID,
        DATA: {
            ID: auctionId,
            AMOUNT: -3
        }
    }
    req = submitOp(wallet1, client1, op)
    update = {
        'reason': makeReason(commonError, "{} must be present and should be "
                                          "a number greater than 0"
                             .format(AMOUNT))}

    allCoros += [partial(checkReqNack, client1, node, req.identifier,
                         req.reqId, update) for node in nodeSet]

    looper.run(eventuallyAll(*allCoros, totalTimeout=5))

    for n in nodeSet:  # type: Node
        opVerifier, = n.opVerifiers
        assert opVerifier.count == 0
Beispiel #3
0
def testAuctionReqValidationPlugin(looper, nodeSet, wallet1, client1, tdir,
                                   pluginVerPath):
    # TODO: Test more cases
    plugin = PluginLoader(pluginVerPath)
    plugin = next(iter(plugin.plugins[PLUGIN_TYPE_VERIFICATION]))
    commonError = "client request invalid: InvalidClientRequest()"
    allCoros = []
    op = {TXN_TYPE: "dummy", DATA: {AMOUNT: 30}}
    req = submitOp(wallet1, client1, op)
    validTypes = ', '.join(plugin.validTxnTypes)
    update = {
        'reason':
        makeReason(
            commonError, "dummy is not a valid transaction "
            "type, must be one of {}".format(validTypes))
    }

    allCoros += [
        partial(checkReqNack, client1, node, req.reqId, update)
        for node in nodeSet
    ]

    op = {
        TXN_TYPE: AUCTION_START,
    }
    req = submitOp(wallet1, client1, op)
    update = {
        'reason':
        makeReason(
            commonError,
            "{} attribute is missing or not in proper format".format(DATA))
    }

    allCoros += [
        partial(checkReqNack, client1, node, req.reqId, update)
        for node in nodeSet
    ]

    op = {
        TXN_TYPE: PLACE_BID,
    }
    req = submitOp(wallet1, client1, op)
    update = {
        'reason':
        makeReason(
            commonError,
            "{} attribute is missing or not in proper format".format(DATA))
    }

    allCoros += [
        partial(checkReqNack, client1, node, req.reqId, update)
        for node in nodeSet
    ]

    op = {TXN_TYPE: PLACE_BID, DATA: "some string"}
    req = submitOp(wallet1, client1, op)
    update = {
        'reason':
        makeReason(
            commonError,
            "{} attribute is missing or not in proper format".format(DATA))
    }

    allCoros += [
        partial(checkReqNack, client1, node, req.reqId, update)
        for node in nodeSet
    ]

    op = {TXN_TYPE: PLACE_BID, DATA: {AMOUNT: 453}}
    req = submitOp(wallet1, client1, op)
    update = {'reason': makeReason(commonError, "No id provided for auction")}

    allCoros += [
        partial(checkReqNack, client1, node, req.reqId, update)
        for node in nodeSet
    ]

    op = {TXN_TYPE: AUCTION_START, DATA: {}}
    req = submitOp(wallet1, client1, op)
    update = {'reason': makeReason(commonError, "No id provided for auction")}

    allCoros += [
        partial(checkReqNack, client1, node, req.reqId, update)
        for node in nodeSet
    ]

    op = {TXN_TYPE: AUCTION_END, DATA: {}}
    req = submitOp(wallet1, client1, op)
    update = {'reason': makeReason(commonError, "No id provided for auction")}

    allCoros += [
        partial(checkReqNack, client1, node, req.reqId, update)
        for node in nodeSet
    ]

    auctionId = str(uuid4())

    op = {TXN_TYPE: PLACE_BID, DATA: {ID: auctionId, AMOUNT: -3}}
    req = submitOp(wallet1, client1, op)
    update = {
        'reason':
        makeReason(
            commonError, "{} must be present and should be "
            "a number greater than 0".format(AMOUNT))
    }

    allCoros += [
        partial(checkReqNack, client1, node, req.reqId, update)
        for node in nodeSet
    ]

    looper.run(eventuallyAll(*allCoros, totalTimeout=5))

    for n in nodeSet:  # type: Node
        opVerifier, = n.opVerifiers
        assert opVerifier.count == 0
Beispiel #4
0
def testBankReqValidationPlugin(looper, nodeSet, client1, wallet1, tdir,
                                pluginVerPath):
    plugin = PluginLoader(pluginVerPath)
    plugin = next(iter(plugin.plugins[PLUGIN_TYPE_VERIFICATION]))
    commonError = "client request invalid: InvalidClientRequest()"
    client2, wallet2 = setupClient(looper, nodeSet, tmpdir=tdir)
    req = submitOp(wallet1, client1, {
        TXN_TYPE: "dummy",
        TARGET_NYM: wallet2.defaultId,
        DATA: {
            AMOUNT: 30
        }
    })

    validTypes = ', '.join(plugin.validTxnTypes)
    update = {
        'reason':
        makeReason(
            commonError, "dummy is not a valid "
            "transaction type, must be "
            "one of {}".format(validTypes))
    }

    coros1 = [
        partial(checkReqNack, client1, node, req.identifier, req.reqId, update)
        for node in nodeSet
    ]

    req = submitOp(wallet1, client1, {
        TXN_TYPE: CREDIT,
        TARGET_NYM: wallet2.defaultId,
    })

    update = {
        'reason':
        makeReason(
            commonError,
            "{} attribute is missing or not in proper format".format(DATA))
    }

    coros2 = [
        partial(checkReqNack, client1, node, req.identifier, req.reqId, update)
        for node in nodeSet
    ]

    req = submitOp(wallet1, client1, {
        TXN_TYPE: CREDIT,
        TARGET_NYM: wallet2.defaultId,
        DATA: "some string"
    })

    update = {
        'reason':
        makeReason(
            commonError,
            "{} attribute is missing or not in proper format".format(DATA))
    }

    coros3 = [
        partial(checkReqNack, client1, node, req.identifier, req.reqId, update)
        for node in nodeSet
    ]

    req = submitOp(wallet1, client1, {
        TXN_TYPE: CREDIT,
        TARGET_NYM: wallet2.defaultId,
        DATA: {
            AMOUNT: -3
        }
    })

    update = {
        'reason':
        makeReason(
            commonError, "{} must be present and should be "
            "a number greater than 0".format(AMOUNT))
    }

    coros4 = [
        partial(checkReqNack, client1, node, req.identifier, req.reqId, update)
        for node in nodeSet
    ]

    timeout = waits.expectedReqAckQuorumTime()
    looper.run(
        eventuallyAll(*(coros1 + coros2 + coros3 + coros4),
                      totalTimeout=timeout))

    req = submitOp(wallet1, client1, {
        TXN_TYPE: CREDIT,
        TARGET_NYM: wallet2.defaultId,
        DATA: {
            AMOUNT: 30
        }
    })

    waitForSufficientRepliesForRequests(looper,
                                        client1,
                                        requests=[req],
                                        fVal=1)
    for n in nodeSet:  # type: Node
        opVerifier, = n.opVerifiers
        assert opVerifier.count == 1
def testBankReqValidationPlugin(looper, nodeSet, client1, wallet1, tdir,
                                pluginVerPath):
    plugin = PluginLoader(pluginVerPath)
    plugin = next(iter(plugin.plugins[PLUGIN_TYPE_VERIFICATION]))
    commonError = "client request invalid: InvalidClientRequest()"
    client2, wallet2 = setupClient(looper, nodeSet, tmpdir=tdir)
    req = submitOp(wallet1, client1, {
        TXN_TYPE: "dummy",
        TARGET_NYM: wallet2.defaultId,
        DATA: {
            AMOUNT: 30
        }})

    validTypes = ', '.join(plugin.validTxnTypes)
    update = {'reason': makeReason(commonError, "dummy is not a valid "
                                                "transaction type, must be "
                                                "one of {}".format(validTypes))}

    coros1 = [partial(checkReqNack, client1, node, req.identifier,
                      req.reqId, update) for node in nodeSet]

    req = submitOp(wallet1, client1, {
        TXN_TYPE: CREDIT,
        TARGET_NYM: wallet2.defaultId,
        })

    update = {
        'reason': makeReason(commonError,
                             "{} attribute is missing or not in proper format"
                             .format(DATA))}

    coros2 = [partial(checkReqNack, client1, node, req.identifier,
                      req.reqId, update) for node in nodeSet]

    req = submitOp(wallet1, client1, {
        TXN_TYPE: CREDIT,
        TARGET_NYM: wallet2.defaultId,
        DATA: "some string"})

    update = {
        'reason': makeReason(commonError,
                             "{} attribute is missing or not in proper format"
                             .format(DATA))}

    coros3 = [partial(checkReqNack, client1, node, req.identifier,
                      req.reqId, update) for node in nodeSet]

    req = submitOp(wallet1, client1, {
        TXN_TYPE: CREDIT,
        TARGET_NYM: wallet2.defaultId,
        DATA: {
            AMOUNT: -3
        }})

    update = {
        'reason': makeReason(commonError, "{} must be present and should be "
                                          "a number greater than 0"
                             .format(AMOUNT))}

    coros4 = [partial(checkReqNack, client1, node, req.identifier, req.reqId,
                      update) for node in nodeSet]

    looper.run(eventuallyAll(*(coros1+coros2+coros3+coros4), totalTimeout=5))

    req = submitOp(wallet1, client1, {
        TXN_TYPE: CREDIT,
        TARGET_NYM: wallet2.defaultId,
        DATA: {
            AMOUNT: 30
        }})
    looper.run(eventually(checkSufficientRepliesRecvd, client1.inBox,
                          req.reqId, 1,
                          retryWait=1, timeout=5))
    for n in nodeSet:  # type: Node
        opVerifier, = n.opVerifiers
        assert opVerifier.count == 1