def testOnlyTrusteeCanSendPoolUpgrade(looper, sdk_pool_handle, sdk_wallet_steward, validUpgrade): # A steward sending POOL_UPGRADE but txn fails validUpgrade = deepcopy(validUpgrade) validUpgrade[NAME] = 'upgrade-20' validUpgrade[VERSION] = bumpedVersion() req = sdk_send_upgrade(looper, sdk_pool_handle, sdk_wallet_steward, validUpgrade) sdk_get_bad_response(looper, [req], RequestRejectedException, 'cannot do')
def test_client_cant_send_schema(looper, txnPoolNodeSet, sdk_wallet_client, sdk_wallet_trust_anchor, sdk_pool_handle): # Trust anchor can create schema in any case _, identifier = sdk_wallet_trust_anchor _, schema_json = looper.loop.run_until_complete( issuer_create_schema(identifier, "another_name", "2.0", json.dumps(["first", "last"]))) request = looper.loop.run_until_complete( build_schema_request(identifier, schema_json)) sdk_get_and_check_replies(looper, [ sdk_sign_and_submit_req(sdk_pool_handle, sdk_wallet_trust_anchor, request) ]) # Client cant create schema if ANYONE_CAN_WRITE flag set to True _, identifier = sdk_wallet_client _, schema_json = looper.loop.run_until_complete( issuer_create_schema(identifier, "another_name", "2.0", json.dumps(["first", "last"]))) request = looper.loop.run_until_complete( build_schema_request(identifier, schema_json)) sdk_get_bad_response( looper, [sdk_sign_and_submit_req(sdk_pool_handle, sdk_wallet_client, request)], RequestRejectedException, 'None role cannot add schema')
def testOnlyTrusteeCanSendPoolUpgradeForceTrue(looper, sdk_pool_handle, sdk_wallet_steward, validUpgradeExpForceTrue): req = sdk_send_upgrade(looper, sdk_pool_handle, sdk_wallet_steward, validUpgradeExpForceTrue) sdk_get_bad_response(looper, [req], RequestNackedException, 'Not enough TRUSTEE signatures')
def testOnlyTrusteeCanSendPoolUpgradeForceTrue(looper, sdk_pool_handle, sdk_wallet_steward, validUpgradeExpForceTrue): req = sdk_send_upgrade(looper, sdk_pool_handle, sdk_wallet_steward, validUpgradeExpForceTrue) sdk_get_bad_response(looper, [req], RequestNackedException, 'role is not accepted')
def test_nym_addition_fails_with_empty_verkey(looper, sdk_pool_handle, sdk_wallet_trustee): op = add_nym_operation(seed=b'a secret trust anchor seed......') op[VERKEY] = '' req = sdk_sign_and_submit_op(looper, sdk_pool_handle, sdk_wallet_trustee, op) sdk_get_bad_response(looper, [req], RequestNackedException, 'Neither a full verkey nor an abbreviated one')
def testNonTrustyCannotCancelUpgrade(looper, validUpgradeSent, sdk_pool_handle, sdk_wallet_steward, validUpgrade): validUpgradeCopy = deepcopy(validUpgrade) validUpgradeCopy[ACTION] = CANCEL req = sdk_send_upgrade(looper, sdk_pool_handle, sdk_wallet_steward, validUpgradeCopy) sdk_get_bad_response(looper, [req], RequestRejectedException, 'cannot do')
def testOnlyTrusteeCanSendPoolUpgradeForceTrue(looper, sdk_pool_handle, sdk_wallet_steward, validUpgradeExpForceTrue): req = sdk_send_upgrade(looper, sdk_pool_handle, sdk_wallet_steward, validUpgradeExpForceTrue) sdk_get_bad_response(looper, [req], RequestNackedException, '{} can not do this action'.format(STEWARD_STRING))
def testSendNymFailsIfIdentifierSizeIs15Bytes(looper, sdk_pool_handle, txnPoolNodeSet, nym_request, sdk_wallet_trustee): parameters = {'dest': rawToFriendly(randombytes(15)), 'role': TRUST_ANCHOR} nym_request[OPERATION].update(parameters) request_couple = sdk_sign_and_send_prepared_request( looper, sdk_wallet_trustee, sdk_pool_handle, json.dumps(nym_request)) sdk_get_bad_response(looper, [request_couple], RequestNackedException, '')
def test_only_trustee_send_pool_config_writes_true_force_false( nodeSet, looper, sdk_pool_handle, sdk_wallet_trustee, poolConfigWTFF): sdk_wallet_steward = sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_trustee, 'tmpname', STEWARD_STRING) req = sdk_pool_config_sent(looper, sdk_pool_handle, sdk_wallet_steward, poolConfigWTFF) sdk_get_bad_response(looper, [req], RequestRejectedException, 'cannot do')
def testSendNymHasInvalidSyntaxIfAllParametersAreOmitted( looper, sdk_pool_handle, txnPoolNodeSet, nym_request, sdk_wallet_trustee): for f in nym_request[OPERATION].keys(): nym_request[OPERATION][f] = '' request_couple = sdk_sign_and_send_prepared_request(looper, sdk_wallet_trustee, sdk_pool_handle, json.dumps(nym_request)) sdk_get_bad_response(looper, [request_couple], RequestNackedException, 'Reason: client request invalid')
def testSendNodeFailsIfClientPortIsEmpty(looper, sdk_pool_handle, nodeSet, sdk_node_theta_added, node_request): node_request['operation']['data'][CLIENT_PORT] = '' steward_wallet, node = sdk_node_theta_added request_couple = sdk_sign_and_send_prepared_request( looper, steward_wallet, sdk_pool_handle, json.dumps(node_request)) sdk_get_bad_response(looper, [request_couple], RequestNackedException, 'expected types') ensurePoolIsOperable(looper, sdk_pool_handle, steward_wallet)
def test_only_trustee_send_pool_config_writes_false_force_true( nodeSet, looper, sdk_pool_handle, sdk_wallet_trustee, poolConfigWFFT): sdk_wallet_steward = sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_trustee, 'tmpname', STEWARD_STRING) req = sdk_pool_config_sent(looper, sdk_pool_handle, sdk_wallet_steward, poolConfigWFFT) sdk_get_bad_response(looper, [req], RequestNackedException, "Not enough TRUSTEE signatures")
def test_only_trustee_send_pool_config_writes_false_force_true( nodeSet, looper, sdk_pool_handle, sdk_wallet_trustee, poolConfigWFFT): sdk_wallet_steward = sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_trustee, 'tmpname', STEWARD_STRING) req = sdk_pool_config_sent(looper, sdk_pool_handle, sdk_wallet_steward, poolConfigWFFT) sdk_get_bad_response(looper, [req], RequestNackedException, '{} can not do this action'.format(STEWARD_STRING))
def test_only_trustee_send_pool_config_writes_true_force_true( nodeSet, looper, sdk_pool_handle, sdk_wallet_trustee, poolConfigWTFT): sdk_wallet_steward = sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_trustee, 'tmpname', STEWARD_STRING) req = sdk_pool_config_sent(looper, sdk_pool_handle, sdk_wallet_steward, poolConfigWTFT) sdk_get_bad_response(looper, [req], RequestNackedException, 'role is not accepted')
def testSendNodeFailsIfAliasIsMissed(looper, sdk_pool_handle, nodeSet, sdk_node_theta_added, node_request): del node_request['operation']['data'][ALIAS] steward_wallet, node = sdk_node_theta_added request_couple = sdk_sign_and_send_prepared_request( looper, steward_wallet, sdk_pool_handle, json.dumps(node_request)) sdk_get_bad_response(looper, [request_couple], RequestNackedException, 'missed fields ') ensurePoolIsOperable(looper, sdk_pool_handle, steward_wallet)
def testSendNodeFailsIfClientPortIsHigherThanUpperBound( looper, sdk_pool_handle, nodeSet, sdk_node_theta_added, node_request): node_request['operation']['data'][CLIENT_PORT] = 65536 steward_wallet, node = sdk_node_theta_added request_couple = sdk_sign_and_send_prepared_request( looper, steward_wallet, sdk_pool_handle, json.dumps(node_request)) sdk_get_bad_response(looper, [request_couple], RequestNackedException, 'network port out of the range 0-65535') ensurePoolIsOperable(looper, sdk_pool_handle, steward_wallet)
def testSendNodeFailsIfSomeClientIpComponentsAreHigherThanUpperBound( looper, sdk_pool_handle, nodeSet, sdk_node_theta_added, node_request): node_request['operation']['data'][CLIENT_IP] = '122.62.256.13' steward_wallet, node = sdk_node_theta_added request_couple = sdk_sign_and_send_prepared_request( looper, steward_wallet, sdk_pool_handle, json.dumps(node_request)) sdk_get_bad_response(looper, [request_couple], RequestNackedException, 'invalid network ip address') ensurePoolIsOperable(looper, sdk_pool_handle, steward_wallet)
def testSendNodeFailsIfNodeIpIsEmpty(looper, sdk_pool_handle, nodeSet, sdk_node_theta_added, node_request): node_request['operation']['data'][NODE_IP] = '' steward_wallet, node = sdk_node_theta_added request_couple = sdk_sign_and_send_prepared_request( looper, steward_wallet, sdk_pool_handle, json.dumps(node_request)) sdk_get_bad_response(looper, [request_couple], RequestNackedException, 'invalid network ip address') ensurePoolIsOperable(looper, sdk_pool_handle, steward_wallet)
def testSendNodeFailsIfDataIsNotJson(looper, sdk_pool_handle, nodeSet, sdk_node_theta_added, node_request): node_request['operation']['data'] = 'not_json' steward_wallet, node = sdk_node_theta_added request_couple = sdk_sign_and_send_prepared_request( looper, steward_wallet, sdk_pool_handle, json.dumps(node_request)) sdk_get_bad_response(looper, [request_couple], RequestNackedException, 'invalid type') ensurePoolIsOperable(looper, sdk_pool_handle, steward_wallet)
def testSendNodeHasInvalidSyntaxIfDestIsMissed( looper, sdk_pool_handle, nodeSet, sdk_node_theta_added, node_request): del node_request['operation']['dest'] steward_wallet, node = sdk_node_theta_added request_couple = sdk_sign_and_send_prepared_request(looper, steward_wallet, sdk_pool_handle, json.dumps(node_request)) sdk_get_bad_response(looper, [request_couple], RequestNackedException, 'missed fields - dest') ensurePoolIsOperable(looper, sdk_pool_handle, steward_wallet)
def testSendNodeHasInvalidSyntaxIfAllParametersAreMissed( looper, sdk_pool_handle, nodeSet, sdk_node_theta_added, node_request): for f in node_request['operation'].keys(): node_request['operation'][f] = '' steward_wallet, node = sdk_node_theta_added request_couple = sdk_sign_and_send_prepared_request( looper, steward_wallet, sdk_pool_handle, json.dumps(node_request)) sdk_get_bad_response(looper, [request_couple], RequestNackedException, 'invalid type') ensurePoolIsOperable(looper, sdk_pool_handle, steward_wallet)
def testSendNodeFailsIfDestIsHexKey(looper, sdk_pool_handle, nodeSet, sdk_node_theta_added, node_request): node_request['operation']['dest'] = cryptonymToHex( node_request['operation']['dest']).decode() steward_wallet, node = sdk_node_theta_added request_couple = sdk_sign_and_send_prepared_request( looper, steward_wallet, sdk_pool_handle, json.dumps(node_request)) sdk_get_bad_response(looper, [request_couple], RequestNackedException, 'should not contain the following chars') ensurePoolIsOperable(looper, sdk_pool_handle, steward_wallet)
def test_accept_then_reject_upgrade( looper, sdk_pool_handle, sdk_wallet_trustee, validUpgradeSent, validUpgrade): upgrade_name = validUpgrade[NAME] error_msg = "InvalidClientRequest(\"Upgrade '{}' is already scheduled\"". \ format(upgrade_name) validUpgrade2 = deepcopy(validUpgrade) req = sdk_send_upgrade(looper, sdk_pool_handle, sdk_wallet_trustee, validUpgrade2) sdk_get_bad_response(looper, [req], RequestRejectedException, error_msg)
def testSendNodeHasInvalidSyntaxIfDestIsEmpty( looper, sdk_pool_handle, nodeSet, sdk_node_theta_added, node_request): node_request['operation']['dest'] = '' steward_wallet, node = sdk_node_theta_added request_couple = sdk_sign_and_send_prepared_request(looper, steward_wallet, sdk_pool_handle, json.dumps(node_request)) sdk_get_bad_response(looper, [request_couple], RequestNackedException, 'b58 decoded value length 0 should be one of [16, 32]') ensurePoolIsOperable(looper, sdk_pool_handle, steward_wallet)
def testSendNodeFailsIfServicesContainsUnknownValue( looper, sdk_pool_handle, nodeSet, sdk_node_theta_added, node_request): node_request['operation']['data'][SERVICES] = [VALIDATOR, 'DECIDER'] steward_wallet, node = sdk_node_theta_added request_couple = sdk_sign_and_send_prepared_request(looper, steward_wallet, sdk_pool_handle, json.dumps(node_request)) sdk_get_bad_response(looper, [request_couple], RequestNackedException, 'unknown value') ensurePoolIsOperable(looper, sdk_pool_handle, steward_wallet)
def testSendNodeFailsIfServicesIsValidatorValue( looper, sdk_pool_handle, nodeSet, sdk_node_theta_added, node_request): node_request['operation']['data'][SERVICES] = VALIDATOR # just string, not array steward_wallet, node = sdk_node_theta_added request_couple = sdk_sign_and_send_prepared_request(looper, steward_wallet, sdk_pool_handle, json.dumps(node_request)) sdk_get_bad_response(looper, [request_couple], RequestNackedException, 'expected types') ensurePoolIsOperable(looper, sdk_pool_handle, steward_wallet)
def testSendNodeFailsIfDestIsShortReadableName( looper, sdk_pool_handle, nodeSet, sdk_node_theta_added, node_request): node_request['operation']['dest'] = 'TheNewNode' steward_wallet, node = sdk_node_theta_added request_couple = sdk_sign_and_send_prepared_request(looper, steward_wallet, sdk_pool_handle, json.dumps(node_request)) sdk_get_bad_response(looper, [request_couple], RequestNackedException, 'b58 decoded value length 8 should be one of [16, 32]') ensurePoolIsOperable(looper, sdk_pool_handle, steward_wallet)
def testSendNodeSuccessIfDataContainsUnknownField( looper, sdk_pool_handle, nodeSet, sdk_node_theta_added, node_request): node_request['operation']['data'][SERVICES] = [] node_request['operation']['data']['extra'] = 42 steward_wallet, node = sdk_node_theta_added request_couple = sdk_sign_and_send_prepared_request(looper, steward_wallet, sdk_pool_handle, json.dumps(node_request)) sdk_get_bad_response(looper, [request_couple], RequestRejectedException, 'action is not allowed') ensurePoolIsOperable(looper, sdk_pool_handle, steward_wallet)
def test_accept_then_reject_upgrade(looper, sdk_pool_handle, sdk_wallet_trustee, validUpgradeSent, validUpgrade): upgrade_name = validUpgrade[NAME] error_msg = "Upgrade '{}' is already scheduled".format(upgrade_name) validUpgrade2 = deepcopy(validUpgrade) req = sdk_send_upgrade(looper, sdk_pool_handle, sdk_wallet_trustee, validUpgrade2) sdk_get_bad_response(looper, [req], RequestRejectedException, error_msg)
def testSendNymHasInvalidSyntaxForUuidIdentifierAndEmptyVerkey( looper, sdk_pool_handle, txnPoolNodeSet, nym_request, sdk_wallet_trustee): parameters = { 'dest': createUuidIdentifier(), 'verkey': '', 'role': TRUST_ANCHOR } nym_request[OPERATION].update(parameters) request_couple = sdk_sign_and_send_prepared_request(looper, sdk_wallet_trustee, sdk_pool_handle, json.dumps(nym_request)) sdk_get_bad_response(looper, [request_couple], RequestNackedException, 'Neither a full verkey nor an abbreviated one')
def test_send_node_with_invalid_dest_verkey(looper, sdk_pool_handle, sdk_wallet_steward, tdir, tconf): node_name = "Psi" new_steward_name = "testClientSteward" + randomString(3) new_steward_wallet_handle = sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_steward, alias=new_steward_name, role=STEWARD_STRING) sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort, key_proof = \ prepare_new_node_data(tconf, tdir, node_name) # Invalid dest passes static validation assert len(base58.b58decode(invalid_dest)) == 32 _, steward_did = new_steward_wallet_handle node_request = looper.loop.run_until_complete( prepare_node_request(steward_did, new_node_name=node_name, clientIp=clientIp, clientPort=clientPort, nodeIp=nodeIp, nodePort=nodePort, bls_key=bls_key, destination=invalid_dest, services=[VALIDATOR], key_proof=key_proof)) request_couple = sdk_sign_and_send_prepared_request( looper, new_steward_wallet_handle, sdk_pool_handle, node_request) sdk_get_bad_response(looper, [request_couple], RequestNackedException, 'Node\'s dest is not correct Ed25519 key.') node_request = looper.loop.run_until_complete( prepare_node_request(steward_did, new_node_name=node_name, clientIp=clientIp, clientPort=clientPort, nodeIp=nodeIp, nodePort=nodePort, bls_key=bls_key, sigseed=sigseed, services=[VALIDATOR], key_proof=key_proof)) node_request = json.loads(node_request) node_request['operation'][VERKEY] = invalid_dest node_request = json.dumps(node_request) request_couple = sdk_sign_and_send_prepared_request( looper, new_steward_wallet_handle, sdk_pool_handle, node_request) sdk_get_bad_response(looper, [request_couple], RequestNackedException, 'Node\'s verkey is not correct Ed25519 key.')
def test_request_none_protocol_version(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client, request_num): _, did = sdk_wallet_client req_objs = sdk_random_request_objects(request_num, identifier=did, protocol_version=None) for req_obj in req_objs: assert req_obj.protocolVersion == None signed_reqs = sdk_sign_request_objects(looper, sdk_wallet_client, req_objs) reqs = sdk_send_signed_requests(sdk_pool_handle, signed_reqs) sdk_get_bad_response(looper, reqs, RequestNackedException, 'missed fields - protocolVersion. ' + error_msg)
def test_request_with_invalid_version(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client, request_num): _, did = sdk_wallet_client reqs_obj = sdk_random_request_objects(request_num, identifier=did, protocol_version=-1) for req_obj in reqs_obj: assert req_obj.protocolVersion == -1 signed_reqs = sdk_sign_request_objects(looper, sdk_wallet_client, reqs_obj) reqs = sdk_send_signed_requests(sdk_pool_handle, signed_reqs) sdk_get_bad_response(looper, reqs, RequestNackedException, 'Unknown protocol version value. ' + error_msg)
def test_request_with_outdated_version(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client, request_num): _, did = sdk_wallet_client reqs_obj = sdk_random_request_objects(request_num, identifier=did, protocol_version=CURRENT_PROTOCOL_VERSION - 1) for req_obj in reqs_obj: assert req_obj.protocolVersion == CURRENT_PROTOCOL_VERSION - 1 signed_reqs = sdk_sign_request_objects(looper, sdk_wallet_client, reqs_obj) reqs = sdk_send_signed_requests(sdk_pool_handle, signed_reqs) sdk_get_bad_response(looper, reqs, RequestNackedException, 'differs from current protocol version. ' .format(CURRENT_PROTOCOL_VERSION) + error_msg)
def test_add_node_with_existing_data(looper, txnPoolNodeSet, tdir, tconf, sdk_pool_handle, sdk_wallet_stewards): alias = randomString(5) new_node_name = "Node-" + alias steward_wallet_handle = sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_stewards[0], alias="Steward-" + alias, role='STEWARD') # Setting already existing HAs existing_ha = txnPoolNodeSet[0].nodeReg[txnPoolNodeSet[-1].name] existing_cli_ha = txnPoolNodeSet[0].cliNodeReg[txnPoolNodeSet[-1].name + 'C'] # Check for existing alias node_request = create_specific_node_request( looper, steward_wallet_handle, tconf, tdir, txnPoolNodeSet[0].name) request_couple = sdk_sign_and_send_prepared_request(looper, steward_wallet_handle, sdk_pool_handle, node_request) sdk_get_bad_response(looper, [request_couple], RequestRejectedException, "Node's alias must be unique") # Check for existing node HAs node_request = create_specific_node_request( looper, steward_wallet_handle, tconf, tdir, new_node_name, new_node_ip=existing_ha[0], new_node_port=existing_ha[1]) request_couple = sdk_sign_and_send_prepared_request(looper, steward_wallet_handle, sdk_pool_handle, node_request) sdk_get_bad_response(looper, [request_couple], RequestRejectedException, "Node's nodestack addresses must be unique") # Check for existing client HAs node_request = create_specific_node_request( looper, steward_wallet_handle, tconf, tdir, new_node_name, new_client_ip=existing_cli_ha[0], new_client_port=existing_cli_ha[1]) request_couple = sdk_sign_and_send_prepared_request(looper, steward_wallet_handle, sdk_pool_handle, node_request) sdk_get_bad_response(looper, [request_couple], RequestRejectedException, "Node's clientstack addresses must be unique")
def testOnlyTrusteeCanSendPoolUpgradeForceTrue( looper, sdk_pool_handle, sdk_wallet_steward, validUpgradeExpForceTrue): req = sdk_send_upgrade(looper, sdk_pool_handle, sdk_wallet_steward, validUpgradeExpForceTrue) sdk_get_bad_response(looper, [req], RequestNackedException, 'cannot do')
def testNodeRejectsPoolUpgrade(looper, nodeSet, tdir, sdk_pool_handle, sdk_wallet_trustee, invalidUpgrade): req = sdk_send_upgrade(looper, sdk_pool_handle, sdk_wallet_trustee, invalidUpgrade) sdk_get_bad_response(looper, [req], RequestNackedException, 'since time span between upgrades')