Skip to content

Commit

Permalink
Merge pull request #11 from C4T-BuT-S4D/cell
Browse files Browse the repository at this point in the history
Make checker more reliable
  • Loading branch information
jnovikov authored Feb 9, 2024
2 parents d7277e3 + bd9e59d commit c7389a9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
7 changes: 5 additions & 2 deletions checkers/cell/cell_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def subscribe(self, ws: websockets.sync.connection.Connection, op_id: int, sheet
return msg


def modify_cell(self, ws: websockets.sync.connection.Connection, op_id: int, sheet_id: str, cell: str, value: str, token: str):
def modify_cell(self, ws: websockets.sync.connection.Connection, op_id: int, sheet_id: str, cell: str, value: str, token: str, timeout: int = None):
payload = {
"id": op_id,
"rpc": {
Expand All @@ -108,8 +108,11 @@ def modify_cell(self, ws: websockets.sync.connection.Connection, op_id: int, she
}

ws.send(json.dumps(payload))
msg = self.c.decode_json(ws.recv(timeout=timeout), 'Invalid JSON received from RPC')
if not msg:
raise TimeoutError("Got empty response")

msg = self.c.decode_json(ws.recv(), 'Invalid JSON received from RPC')
self.c.assert_eq(type(msg), dict, 'Invalid JSON received from RPC')
self.c.assert_eq(msg.get('id'), op_id, 'Invalid id in RPC response')
return msg

29 changes: 22 additions & 7 deletions checkers/cell/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

class Checker(BaseChecker):
vulns: int = 1
timeout: int = 15
timeout: int = 20
uses_attack_data: bool = True

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -102,15 +102,30 @@ def check(self):

new_cell_value = rnd_string(30)
# Modify cell.
_modify_result = self.cm.modify_cell(ws_writer, 2, sid, 'B2', new_cell_value, modifyToken)
# Try to modify cell twice to solve the reliability issue.
for _attempt in range(0, 2):
try:
_modify_result = self.cm.modify_cell(ws_writer, 2, sid, 'B2', new_cell_value, modifyToken, timeout=self.timeout // 3)
break
except TimeoutError:
continue

self.assert_neq(_modify_result, None, 'Failed to modify cell: no response received')
self.assert_in('rpc', _modify_result.keys(), 'Invalid modify_cell response')
self.assert_eq(_modify_result.get('rpc', {}).get('data', {}).get('sheet', {}).get('title', None), sheet_name, 'Invalid sheet title in modify_cell response')
cell_values = [x.get('val', '') for x in _modify_result.get('rpc', {}).get('data').get('sheet', {}).get('cells', [])]
mb_sheet = _modify_result.get('rpc', {}).get('data', {}).get('sheet', {})
self.assert_eq(mb_sheet.get('title', None), sheet_name, 'Invalid sheet title in modify_cell response')
cell_values = [x.get('val', '') for x in mb_sheet.get('cells', [])]
self.assert_in(new_cell_value, cell_values, 'New cell value not found in modify_cell response')

# Fet update from reader.
expected_update = ws_reader.recv()
update_data = self.decode_json(expected_update, 'Invalid JSON received from sheet update')
# Get update from reader.
# Try to get update twice to solve the reliability issue.
for _attempt in range(0, 2):
expected_update = ws_reader.recv(timeout=self.timeout // 3)
update_data = self.decode_json(expected_update, 'Invalid JSON received from sheet update')
if update_data:
break

self.assert_eq(type(update_data), dict, 'Invalid JSON received from sheet update')
update_data = update_data.get('push', {}).get('pub', {}).get('data', {})
self.assert_eq(update_data.get('title', ''), sheet_name, 'Invalid sheet title returned from sheet update')
cell_values = [x.get('val', '') for x in update_data.get('cells', [])]
Expand Down
2 changes: 1 addition & 1 deletion services/cell/conf/rr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ http:
pool:
num_workers: 2
supervisor:
max_worker_memory: 100
max_worker_memory: 128
server:
command: 'php app.php'
relay: pipes
Expand Down

0 comments on commit c7389a9

Please sign in to comment.