def test_fake_value_attr_credential(client): aaid = "".join(random.choice(string.ascii_letters) for i in range(10)) info = [ dict(value_set=["some val 1", "five", "love"], name="name_1", type="int"), dict(value_set=["3"], name="name_2", type="str"), ] insert = client.post( "/authorizable_attribute/", json={ "authorizable_attribute_id": aaid, "authorizable_attribute_info": info, "authorizable_attribute_info_optional": [], "reissuable": False, }, headers={"Authorization": "Bearer %s" % auth()}, ) assert insert.status_code == 201 keys = ZenContract(CONTRACTS.CITIZEN_KEYGEN).execute() contract = ZenContract(CONTRACTS.CITIZEN_REQ_BLIND_SIG) contract.keys(keys) blind_sign_request = contract.execute() values = [dict(name="some_fake_name", value="love"), dict(name="name_2", value="3")] r = client.post( "/credential/", json={ "authorizable_attribute_id": aaid, "values": values, "optional_values": [], "blind_sign_request": json.loads(blind_sign_request), }, ) assert r.status_code == 412 assert r.json()["detail"] == "Missing mandatory value 'name_1'" values = [ dict(name="some_fake_name", value="some_fake_value"), dict(name="name_2", value="3"), ] r = client.post( "/credential/", json={ "authorizable_attribute_id": aaid, "values": values, "optional_values": [], "blind_sign_request": json.loads(blind_sign_request), }, ) assert r.status_code == 412 assert r.json()["detail"] == "Missing mandatory value 'name_1'"
def test_no_found_aa_for_credential(client): keys = ZenContract(CONTRACTS.CITIZEN_KEYGEN).execute() contract = ZenContract(CONTRACTS.CITIZEN_REQ_BLIND_SIG) contract.keys(keys) blind_sign_request = contract.execute() values = [dict(name="name_1", value="love"), dict(name="name_2", value="3")] r = client.post( "/credential/", json={ "authorizable_attribute_id": "FAKE ID", "values": values, "optional_values": [], "blind_sign_request": json.loads(blind_sign_request), }, ) assert r.status_code == 404 assert r.json()["detail"] == "Authorizable Attribute not found"
def __issue_credential(keypair, bsr): contract = ZenContract(CONTRACTS.BLIND_SIGN, {"issuer_identifier": config.get("uid")}) contract.keys(keypair) contract.data(bsr) return contract.execute()
def authorizable_attribute( item: AuthorizableAttributeSchema = Body( ..., example={ "authorizable_attribute_id": "Authorizable Attribute %s" % "".join(random.choice(string.hexdigits) for i in range(10)), "authorizable_attribute_info": [ { "name": "email", "type": "str", "value_set": [ "*****@*****.**", "*****@*****.**", "*****@*****.**", ], }, { "name": "zip_code", "type": "int", "value_set": ["08001", "08002", "08003", "08004", "08005", "08006"], }, ], "authorizable_attribute_info_optional": [ { "name": "age", "type": "str", "value_set": ["0-18", "18-25", "25-45", ">45"], "k": 2, } ], "reissuable": False, }, ), token: str = Security(oauth2_scheme), ): info = [_.json() for _ in item.authorizable_attribute_info] optional = [_.json() for _ in item.authorizable_attribute_info_optional] keypair_contract = ZenContract(CONTRACTS.GENERATE_KEYPAIR, {"issuer_identifier": config.get("uid")}) keypair = keypair_contract.execute() contract = ZenContract(CONTRACTS.PUBLIC_VERIFY, {"issuer_identifier": config.get("uid")}) contract.keys(keypair) verification_key = contract.execute() aa = AuthorizableAttribute( authorizable_attribute_id=item.authorizable_attribute_id, authorizable_attribute_info=json.dumps(info), authorizable_attribute_info_optional=json.dumps(optional), keypair=keypair, verification_key=verification_key, reissuable=item.reissuable, ) try: DBSession.add(aa) DBSession.commit() except IntegrityError: DBSession.rollback() raise HTTPException(status_code=HTTP_409_CONFLICT, detail="Duplicate Authorizable Attribute Id") return { "verification_key": json.loads(verification_key), "credential_issuer_id": config.get("uid"), "authorizable_attribute_id": aa.authorizable_attribute_id, }
def test_keygen(): expected = "identifier public private".split() contract = ZenContract(CONTRACTS.CITIZEN_KEYGEN) _smart_contract_check(contract, expected)
def test_request(): keys = ZenContract(CONTRACTS.CITIZEN_KEYGEN).execute() expected = "request pi_s rk rr cm public".split() contract = ZenContract(CONTRACTS.CITIZEN_REQ_BLIND_SIG) contract.keys(keys) _smart_contract_check(contract, expected)
def test_issuer_public(): expected = "issuer_identifier verify beta alpha".split() contract = ZenContract(CONTRACTS.PUBLIC_VERIFY) contract.keys(ZenContract(CONTRACTS.GENERATE_KEYPAIR).execute()) _smart_contract_check(contract, expected)
def test_execute(): expected = ["encoding", "x", "zenroom", "sign", "schema", "curve"] contract = ZenContract(CONTRACTS.GENERATE_KEYPAIR) _smart_contract_check(contract, expected)
def test_zecontract(): smart_contract = ZenContract(CONTRACTS.GENERATE_KEYPAIR) assert smart_contract assert not smart_contract.data() assert not smart_contract.keys()
def test_keys(): smart_contract = ZenContract(CONTRACTS.GENERATE_KEYPAIR) smart_contract.keys("test") assert smart_contract.keys() == "test"
def test_generate_secret_key(): key = json.loads(ZenContract(CONTRACTS.GENERATE_KEYPAIR).execute()) keys = ["encoding", "zenroom", "sign", "schema", "curve"] for _ in keys: assert key["issuer_identifier"][_]