2022-03-15 11:58:59 +00:00
|
|
|
#!/usr/bin/python3
|
2020-07-01 02:28:31 +00:00
|
|
|
|
2021-08-25 17:08:54 +00:00
|
|
|
import base64
|
|
|
|
import json
|
2020-07-01 02:28:31 +00:00
|
|
|
import os
|
|
|
|
import re
|
2021-08-25 17:08:54 +00:00
|
|
|
import random
|
2021-11-03 12:48:31 +00:00
|
|
|
import uuid
|
|
|
|
import base58
|
2021-08-25 17:08:54 +00:00
|
|
|
|
|
|
|
from neo3 import wallet
|
2022-05-20 11:18:14 +00:00
|
|
|
from common import (NEOFS_NETMAP, WALLET_PASS, NEOFS_ENDPOINT,
|
|
|
|
NEOFS_NETMAP_DICT, ASSETS_DIR)
|
|
|
|
from cli_helpers import _cmd_run
|
|
|
|
import json_transformers
|
2020-07-01 02:28:31 +00:00
|
|
|
from robot.api.deco import keyword
|
|
|
|
from robot.api import logger
|
2022-03-15 11:58:59 +00:00
|
|
|
|
2020-07-01 02:28:31 +00:00
|
|
|
ROBOT_AUTO_KEYWORDS = False
|
|
|
|
|
2021-01-17 11:55:10 +00:00
|
|
|
# path to neofs-cli executable
|
|
|
|
NEOFS_CLI_EXEC = os.getenv('NEOFS_CLI_EXEC', 'neofs-cli')
|
2020-11-18 15:15:57 +00:00
|
|
|
|
|
|
|
|
2022-03-15 11:58:59 +00:00
|
|
|
# TODO: move to neofs-keywords
|
2021-03-09 10:08:40 +00:00
|
|
|
@keyword('Get ScriptHash')
|
2021-08-25 17:08:54 +00:00
|
|
|
def get_scripthash(wif: str):
|
|
|
|
acc = wallet.Account.from_wif(wif, '')
|
|
|
|
return str(acc.script_hash)
|
2020-07-01 02:28:31 +00:00
|
|
|
|
2020-07-14 00:05:22 +00:00
|
|
|
|
2020-12-23 22:38:16 +00:00
|
|
|
@keyword('Verify Head Tombstone')
|
2022-02-01 13:42:41 +00:00
|
|
|
def verify_head_tombstone(wallet: str, cid: str, oid_ts: str, oid: str, addr: str):
|
2022-03-15 11:58:59 +00:00
|
|
|
# TODO: replace with HEAD from neofs_verbs.py
|
2021-04-02 14:29:41 +00:00
|
|
|
object_cmd = (
|
2022-02-01 13:42:41 +00:00
|
|
|
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} '
|
|
|
|
f'--config {WALLET_PASS} object head --cid {cid} --oid {oid_ts} --json'
|
2021-01-17 11:55:10 +00:00
|
|
|
)
|
2021-09-01 14:48:09 +00:00
|
|
|
output = _cmd_run(object_cmd)
|
|
|
|
full_headers = json.loads(output)
|
|
|
|
logger.info(f"Output: {full_headers}")
|
|
|
|
|
|
|
|
# Header verification
|
|
|
|
header_cid = full_headers["header"]["containerID"]["value"]
|
2022-05-20 11:18:14 +00:00
|
|
|
if json_transformers.json_reencode(header_cid) == cid:
|
2021-09-01 14:48:09 +00:00
|
|
|
logger.info(f"Header CID is expected: {cid} ({header_cid} in the output)")
|
|
|
|
else:
|
|
|
|
raise Exception("Header CID is not expected.")
|
2020-11-30 10:33:05 +00:00
|
|
|
|
2021-09-01 14:48:09 +00:00
|
|
|
header_owner = full_headers["header"]["ownerID"]["value"]
|
2022-05-20 11:18:14 +00:00
|
|
|
if json_transformers.json_reencode(header_owner) == addr:
|
2021-09-01 14:48:09 +00:00
|
|
|
logger.info(f"Header ownerID is expected: {addr} ({header_owner} in the output)")
|
|
|
|
else:
|
|
|
|
raise Exception("Header ownerID is not expected.")
|
2020-12-23 22:38:16 +00:00
|
|
|
|
2021-09-01 14:48:09 +00:00
|
|
|
header_type = full_headers["header"]["objectType"]
|
2022-05-20 11:18:14 +00:00
|
|
|
if header_type == "TOMBSTONE":
|
2021-09-01 14:48:09 +00:00
|
|
|
logger.info(f"Header Type is expected: {header_type}")
|
|
|
|
else:
|
|
|
|
raise Exception("Header Type is not expected.")
|
2020-12-23 22:38:16 +00:00
|
|
|
|
2021-09-01 14:48:09 +00:00
|
|
|
header_session_type = full_headers["header"]["sessionToken"]["body"]["object"]["verb"]
|
2022-05-20 11:18:14 +00:00
|
|
|
if header_session_type == "DELETE":
|
2021-09-01 14:48:09 +00:00
|
|
|
logger.info(f"Header Session Type is expected: {header_session_type}")
|
|
|
|
else:
|
|
|
|
raise Exception("Header Session Type is not expected.")
|
2020-07-01 02:28:31 +00:00
|
|
|
|
2021-09-01 14:48:09 +00:00
|
|
|
header_session_cid = full_headers["header"]["sessionToken"]["body"]["object"]["address"]["containerID"]["value"]
|
2022-05-20 11:18:14 +00:00
|
|
|
if json_transformers.json_reencode(header_session_cid) == cid:
|
2021-09-01 14:48:09 +00:00
|
|
|
logger.info(f"Header ownerID is expected: {addr} ({header_session_cid} in the output)")
|
|
|
|
else:
|
|
|
|
raise Exception("Header Session CID is not expected.")
|
2020-07-01 02:28:31 +00:00
|
|
|
|
2021-09-01 14:48:09 +00:00
|
|
|
header_session_oid = full_headers["header"]["sessionToken"]["body"]["object"]["address"]["objectID"]["value"]
|
2022-05-20 11:18:14 +00:00
|
|
|
if json_transformers.json_reencode(header_session_oid) == oid:
|
2021-09-01 14:48:09 +00:00
|
|
|
logger.info(f"Header Session OID (deleted object) is expected: {oid} ({header_session_oid} in the output)")
|
|
|
|
else:
|
|
|
|
raise Exception("Header Session OID (deleted object) is not expected.")
|
2020-07-01 02:28:31 +00:00
|
|
|
|
2020-11-28 03:41:35 +00:00
|
|
|
|
2021-09-09 08:13:37 +00:00
|
|
|
@keyword('Get control endpoint with wif')
|
|
|
|
def get_control_endpoint_with_wif(endpoint_number: str = ''):
|
|
|
|
if endpoint_number == '':
|
|
|
|
netmap = []
|
|
|
|
for key in NEOFS_NETMAP_DICT.keys():
|
|
|
|
netmap.append(key)
|
|
|
|
endpoint_num = random.sample(netmap, 1)[0]
|
|
|
|
logger.info(f'Random node chosen: {endpoint_num}')
|
|
|
|
else:
|
|
|
|
endpoint_num = endpoint_number
|
|
|
|
|
|
|
|
endpoint_values = NEOFS_NETMAP_DICT[f'{endpoint_num}']
|
|
|
|
endpoint_control = endpoint_values['control']
|
|
|
|
wif = endpoint_values['wif']
|
2022-03-11 16:08:14 +00:00
|
|
|
|
2021-09-09 08:13:37 +00:00
|
|
|
return endpoint_num, endpoint_control, wif
|
|
|
|
|
2022-04-25 09:53:20 +00:00
|
|
|
|
2021-10-04 16:16:49 +00:00
|
|
|
@keyword('Get Locode')
|
|
|
|
def get_locode():
|
|
|
|
endpoint_values = random.choice(list(NEOFS_NETMAP_DICT.values()))
|
|
|
|
locode = endpoint_values['UN-LOCODE']
|
|
|
|
logger.info(f'Random locode chosen: {locode}')
|
|
|
|
|
|
|
|
return locode
|
|
|
|
|
|
|
|
|
2021-11-03 12:48:31 +00:00
|
|
|
@keyword('Generate Session Token')
|
|
|
|
def generate_session_token(owner: str, pub_key: str, cid: str = "", wildcard: bool = False) -> str:
|
|
|
|
|
|
|
|
file_path = f"{os.getcwd()}/{ASSETS_DIR}/{str(uuid.uuid4())}"
|
|
|
|
|
|
|
|
owner_64 = base64.b64encode(base58.b58decode(owner)).decode('utf-8')
|
|
|
|
cid_64 = base64.b64encode(cid.encode('utf-8')).decode('utf-8')
|
|
|
|
pub_key_64 = base64.b64encode(bytes.fromhex(pub_key)).decode('utf-8')
|
|
|
|
id_64 = base64.b64encode(uuid.uuid4().bytes).decode('utf-8')
|
|
|
|
|
|
|
|
session_token = {
|
|
|
|
"body":{
|
|
|
|
"id":f"{id_64}",
|
|
|
|
"ownerID":{
|
|
|
|
"value":f"{owner_64}"
|
|
|
|
},
|
|
|
|
"lifetime":{
|
|
|
|
"exp":"100000000",
|
|
|
|
"nbf":"0",
|
|
|
|
"iat":"0"
|
|
|
|
},
|
|
|
|
"sessionKey":f"{pub_key_64}",
|
|
|
|
"container":{
|
|
|
|
"verb":"PUT",
|
|
|
|
"wildcard": wildcard,
|
|
|
|
**({ "containerID":{"value":f"{cid_64}"} } if not wildcard else {})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info(f"Got this Session Token: {session_token}")
|
|
|
|
|
|
|
|
with open(file_path, 'w', encoding='utf-8') as session_token_file:
|
|
|
|
json.dump(session_token, session_token_file, ensure_ascii=False, indent=4)
|
|
|
|
|
|
|
|
return file_path
|
|
|
|
|
|
|
|
|
|
|
|
@keyword ('Sign Session Token')
|
|
|
|
def sign_session_token(session_token: str, wallet: str, to_file: str=''):
|
|
|
|
if to_file:
|
2022-03-11 16:08:14 +00:00
|
|
|
to_file = f'--to {to_file}'
|
2021-11-03 12:48:31 +00:00
|
|
|
cmd = (
|
|
|
|
f'{NEOFS_CLI_EXEC} util sign session-token --from {session_token} '
|
2022-02-01 13:42:41 +00:00
|
|
|
f'-w {wallet} {to_file} --config {WALLET_PASS}'
|
2021-11-03 12:48:31 +00:00
|
|
|
)
|
|
|
|
logger.info(f"cmd: {cmd}")
|
2022-02-01 13:42:41 +00:00
|
|
|
_cmd_run(cmd)
|