backend_update_260131

This commit is contained in:
lusixing
2026-01-31 16:29:57 -08:00
parent 4b5b6fb976
commit e2c05af372
5 changed files with 268 additions and 36 deletions

View File

@@ -35,32 +35,35 @@ def login_user(username, password):
print(f"Failed to login {username}: {response.text}")
return None
def create_asset(token, title, private_key_shard, content_inner_encrypted):
def create_asset(token, title, private_key_shard, content_inner_encrypted, asset_type="note"):
url = f"{BASE_URL}/assets/create"
headers = {"Authorization": f"Bearer {token}"}
data = {
"title": title,
"type": asset_type,
"private_key_shard": str(private_key_shard),
"content_inner_encrypted": str(content_inner_encrypted)
}
response = requests.post(url, json=data, headers=headers)
if response.status_code == 200:
print(f"Asset '{title}' created successfully.")
return response.json()
asset_data = response.json()
print(f"Asset '{title}' (type: {asset_type}) created successfully.")
print(f" [校验] Timestamps: created_at={asset_data.get('created_at')}, updated_at={asset_data.get('updated_at')}")
return asset_data
else:
print(f"Failed to create asset: {response.text}")
return None
def assign_heir(token, asset_id, heir_name):
def assign_heir(token, asset_id, heir_email):
url = f"{BASE_URL}/assets/assign"
headers = {"Authorization": f"Bearer {token}"}
data = {
"asset_id": asset_id,
"heir_name": heir_name
"heir_email": heir_email
}
response = requests.post(url, json=data, headers=headers)
if response.status_code == 200:
print(f"Asset {asset_id} assigned to heir {heir_name} successfully.")
print(f"Asset {asset_id} assigned to heir {heir_email} successfully.")
return response.json()
else:
print(f"Failed to assign heir: {response.text}")
@@ -105,6 +108,17 @@ def get_my_assets(token):
print(f"Failed to retrieve assets: {response.text}")
return None
def get_designated_assets(token):
url = f"{BASE_URL}/assets/designated"
headers = {"Authorization": f"Bearer {token}"}
response = requests.get(url, headers=headers)
if response.status_code == 200:
print(f"Designated assets retrieved successfully.")
return response.json()
else:
print(f"Failed to retrieve designated assets: {response.text}")
return None
def main():
# 1. 创建三个用户
users = [
@@ -143,38 +157,60 @@ def main():
if not token1:
return
# 3. 创建个 asset
# 3. 创建个 asset
asset1 = create_asset(
token1,
"My Secret Asset1",
share_a,
ciphertext_1
ciphertext_1,
"note"
)
asset2 = create_asset(
token1,
"My Secret Asset2",
share_a,
ciphertext_1
ciphertext_1,
"note"
)
if not asset1 or not asset2:
asset3 = create_asset(
token1,
"My Secret Asset3",
share_a,
ciphertext_1,
"note"
)
if not asset1 or not asset2 or not asset3:
print(" [失败] 创建资产失败")
return
# 3.1 测试 /assets/get
print("\n [测试] 获取用户资产列表")
my_assets = get_my_assets(token1)
if my_assets:
print(f" [输出] 成功获取 {len(my_assets)} 个资产")
user1_assets = get_my_assets(token1)
if user1_assets:
print(f" [输出] 用户1共有 {len(user1_assets)} 个资产")
else:
print(" [失败] 无法获取资产列表")
# 4. 指定用户 2 为继承人
print("用户 1 指定用户 2 为继承人")
assign_heir(token1, asset1["id"], "user2")
print("用户 1 为用户 2 分配遗产")
assign_heir(token1, asset1["id"], "user2@example.com")
assign_heir(token1, asset2["id"], "user2@example.com")
# 4.1 用户2查询自己能继承多少遗产
print("\n [测试] 用户 2 查询自己被指定的资产")
token2_temp = login_user("user2", "pass123")
designated_assets = get_designated_assets(token2_temp)
if designated_assets:
print(f" [输出] 用户 2 共有 {len(designated_assets)} 个被指定的资产")
for asset in designated_assets:
print(f" - Asset ID: {asset['id']}, Title: {asset['title']}")
else:
print(" [失败] 无法获取被指定资产列表")
print("\n## 3. 继承流 (Inheritance Layer)")
# 5. Admin 宣布用户 1 挂了
print("Admin 宣布用户 1 挂了")