Skip to content

Commit

Permalink
rustest: added pagination check in checker. needed for listing resources
Browse files Browse the repository at this point in the history
  • Loading branch information
lololozhkin committed Nov 3, 2023
1 parent c6aecea commit e3b0fd9
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions checkers/rustest/rustest.checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,21 @@ def get_page_of_tests(session: requests.Session, url: str, token: str, page: int
return resp_data, None


def get_page_of_users(session: requests.Session, url: str, token: str, page: int = 0) -> tuple[dict, Optional[CheckerError]]:
resp_data, _, err = get_json_response(
f'{url}/api/users',
'get',
headers={'Authorization': f'Bearer {token}'},
query={'page': page},
session=session,
)

if err is not None:
return {}, err.wrapped_by('cannot get page of tests')

return resp_data, None


def solve_test_with_answers(session: requests.Session, url: str, token: str, test_id: str, correct_answers: [int]) -> tuple[dict, Optional[CheckerError]]:
cur_state, err = get_test_state(session, url, token, test_id)
if err is not None:
Expand Down Expand Up @@ -292,6 +307,45 @@ def check(req: gornilo.CheckRequest) -> gornilo.Verdict:
print(f'check error: user doesn`t get the reward after winning the rustest, or reward is corrupted {final_state=}, {reward=}')
return gornilo.Verdict.MUMBLE('user doesn`t get the reward after winning the rustest, or reward is corrupted')

# check last page of users and tests
# to warm caches and avoid linear scan dos attacks
# (I have forgotten to implement it on the side of service)
resp, err = get_page_of_users(session, url, token, page=0)
if err is not None:
print(err.error_message)
return err.verdict

if 'pages_total' not in resp:
return gornilo.Verdict.MUMBLE('pagination of users doesn`t work')

pages_total = resp['pages_total']
if pages_total > 0:
resp, err = get_page_of_users(session, url, token, page=pages_total - 1)
if err is not None:
print(err.error_message)
return err.verdict

if 'users' not in resp or len(resp['users']) == 0:
return gornilo.Verdict.MUMBLE('pagination of users doesn`t work')

resp, err = get_page_of_tests(session, url, token, page=0)
if err is not None:
print(err.error_message)
return err.verdict

if 'pages_total' not in resp:
return gornilo.Verdict.MUMBLE('pagination of tests doesn`t work')

pages_total = resp['pages_total']
if pages_total > 0:
resp, err = get_page_of_tests(session, url, token, page=pages_total - 1)
if err is not None:
print(err.error_message)
return err.verdict

if 'rustests' not in resp or len(resp['rustests']) == 0:
return gornilo.Verdict.MUMBLE('pagination of tests doesn`t work')

return gornilo.Verdict.OK()


Expand Down

0 comments on commit e3b0fd9

Please sign in to comment.