Исправить проверки lab2
Исправить Unicode-границы, пароль, токены, пагинацию и ответы зависимостей. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Focused regression checks for the lab2 security and pagination fixes."""
|
||||
import base64
|
||||
import uuid
|
||||
|
||||
from client import Client, arguments, check, run
|
||||
|
||||
|
||||
def main():
|
||||
args = arguments('Student regression checks')
|
||||
c = Client(args.base_url, args.ca_file)
|
||||
alice, bob, _, chat = c.bootstrap()
|
||||
|
||||
long_password = 'a' * 72 + 'x'
|
||||
username = 'edge_' + uuid.uuid4().hex[:12]
|
||||
registration = {
|
||||
'username': username,
|
||||
'display_name': 'Edge',
|
||||
'password': long_password,
|
||||
}
|
||||
c.call('POST', '/api/v1/users', 201, body=registration, schema='User')
|
||||
wrong = base64.b64encode((username + ':' + 'a' * 72 + 'y').encode()).decode()
|
||||
c.call('POST', '/api/v1/auth/sessions', 401,
|
||||
headers={'Authorization': 'Basic ' + wrong})
|
||||
|
||||
emoji = chr(0x1F600)
|
||||
unicode_user = {
|
||||
'username': 'unicode_' + uuid.uuid4().hex[:8],
|
||||
'display_name': emoji * 100,
|
||||
'password': emoji * 65 + 'a',
|
||||
}
|
||||
c.call('POST', '/api/v1/users', 201, body=unicode_user, schema='User')
|
||||
numeric = {'username': 'number_' + uuid.uuid4().hex[:8],
|
||||
'display_name': 123, 'password': 'password123456'}
|
||||
c.call('POST', '/api/v1/users', 400, body=numeric)
|
||||
|
||||
for number in range(5):
|
||||
c.call('POST', '/api/v1/chats', 201,
|
||||
body={'title': 'Page ' + str(number), 'member_ids': [alice['id'], bob['id']]},
|
||||
actor=alice, schema='Chat')
|
||||
page = c.call('GET', '/api/v1/chats?limit=1', actor=alice, schema='ChatPage')['json']
|
||||
check(page['next_cursor'] is not None, 'chat list ignored limit')
|
||||
c.call('GET', '/api/v1/chats?limit=0', 400, actor=alice)
|
||||
c.call('GET', '/api/v1/chats?limit=abc', 400, actor=alice)
|
||||
|
||||
other = c.call('POST', '/api/v1/chats', 201,
|
||||
body={'title': 'Other', 'member_ids': [alice['id'], bob['id']]},
|
||||
actor=alice, schema='Chat')['json']
|
||||
c.message(alice, chat, 'first')
|
||||
c.message(alice, chat, 'second')
|
||||
history = c.call('GET', '/api/v1/chats/' + chat['id'] + '/messages?limit=1',
|
||||
actor=alice, schema='MessagePage')['json']
|
||||
c.call('GET', '/api/v1/chats/' + other['id'] + '/messages?limit=1&cursor=' +
|
||||
history['next_cursor'], 400, actor=alice)
|
||||
c.call('GET', '/api/v1/chats/not-a-uuid', 400, actor=alice)
|
||||
|
||||
print('PASS: student regression checks')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run(main)
|
||||
Reference in New Issue
Block a user