slightly more coverage for now not fulll
- Old tests won't work anymore due to jwt things
This commit is contained in:
parent
ab12283507
commit
c79cf34dfd
@ -1,5 +1,5 @@
|
|||||||
import time
|
import time
|
||||||
import subprocess, os
|
import subprocess, os, sys
|
||||||
import json, requests
|
import json, requests
|
||||||
|
|
||||||
class Response:
|
class Response:
|
||||||
@ -20,17 +20,23 @@ class Test:
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
self.test_count = 0
|
self.test_count = 0
|
||||||
|
self.out = sys.stdout # changed before worker runtime
|
||||||
if create_admin:
|
if create_admin:
|
||||||
self.body = Test.__create_admin()
|
self.body = Test.__create_admin()
|
||||||
|
self.id = self.body['id']
|
||||||
|
self.secret = self.body['secret']
|
||||||
|
|
||||||
if init_verbose:
|
if init_verbose:
|
||||||
print(f'Using => {self.body}')
|
print(f'TESTBOT Using => {self.body}')
|
||||||
elif admin is not None:
|
elif admin is not None:
|
||||||
self.body = body
|
self.body = body
|
||||||
|
self.id = self.body['id']
|
||||||
|
self.secret = self.body['secret']
|
||||||
else:
|
else:
|
||||||
# for now we use this because my dev server has this fake ass acc on it
|
# for now we use this because my dev server has this fake ass acc on it
|
||||||
|
self.secret = 'mH7DfAfSLHhVbo9OW4dmqTbzzLnFaZQLxoZFIlKvKHm4NfpLyZsZrYdf12aACZXyEQxELOlBTe2rc36vTPVd8A==',
|
||||||
|
self.id = 2
|
||||||
self.body = {
|
self.body = {
|
||||||
'secret': 'JfW_Icct2P1WEo6PQlGb7l1IMd2QsRXAVarPoPZHZnj7NOMWBMdirnH9JqAKgrO5z3fb54QYsWlPPlRGowwFSA==',
|
|
||||||
'id': 1,
|
|
||||||
'name': 'owner sama uwu',
|
'name': 'owner sama uwu',
|
||||||
'joindate': 69,
|
'joindate': 69,
|
||||||
'status': 0,
|
'status': 0,
|
||||||
@ -39,6 +45,9 @@ class Test:
|
|||||||
|
|
||||||
self.base = base
|
self.base = base
|
||||||
|
|
||||||
|
def stdout_to_stderr(self):
|
||||||
|
self.out = sys.stderr
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __create_admin():
|
def __create_admin():
|
||||||
# /home/$user/.cargo/bin/cargo <- normally
|
# /home/$user/.cargo/bin/cargo <- normally
|
||||||
@ -50,17 +59,17 @@ class Test:
|
|||||||
return json.loads(proc.stdout)
|
return json.loads(proc.stdout)
|
||||||
except:
|
except:
|
||||||
import sys
|
import sys
|
||||||
print('UNABLE TO LOAD JSON DATA FROM -c flag', file=sys.stderr)
|
print('TESTBOT UNABLE TO LOAD JSON DATA FROM -c flag', file=sys.stderr)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
def log(self, params: dict, url: str, method: str, request: requests.Response, body=True):
|
||||||
def log(params: dict, url: str, method: str, request: requests.Response):
|
f = sys.stdout
|
||||||
print(f'{method} {url}')
|
print(f'TESTBOT {method} {url} {request.status_code}', file=self.out)
|
||||||
print(f'\t[Parameters]: {params}')
|
print(f'TESTBOT\t\t[Parameters]: {params}', file=self.out)
|
||||||
print(f'\t[Status Code]: {request.status_code}')
|
if body:
|
||||||
print(f'\t[Body]: {request.text}')
|
print(f'TESTBOT\t\t[Body]: {request.text}\n', file=self.out)
|
||||||
|
|
||||||
def _build_req_body(self, **options):
|
def _build_req_body(self, **options):
|
||||||
_map = self.body
|
_map = self.body
|
||||||
@ -71,29 +80,60 @@ class Test:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def post(self, url, **opts):
|
def post(self, url, jwt=False, **opts):
|
||||||
'''
|
'''
|
||||||
@returns text of response
|
@returns text of response
|
||||||
'''
|
'''
|
||||||
body = self._build_req_body(**opts)
|
options = opts
|
||||||
|
if jwt is False:
|
||||||
|
options['id'] = self.id
|
||||||
|
if isinstance(self.secret, tuple):
|
||||||
|
options['secret'] = self.secret[0]
|
||||||
|
else:
|
||||||
|
options['secret'] = self.secret
|
||||||
|
else:
|
||||||
|
options['jwt'] = jwt
|
||||||
|
|
||||||
|
body = self._build_req_body(**options)
|
||||||
r = requests.post(self.base + url, data=body)
|
r = requests.post(self.base + url, data=body)
|
||||||
self.log(opts, self.base + url, 'POST', r)
|
self.log(opts, self.base + url, 'POST', r)
|
||||||
|
|
||||||
return r.text
|
return r.text
|
||||||
|
|
||||||
def get(self, url, **opts):
|
def get(self, url, jwt=False, **opts):
|
||||||
'''
|
'''
|
||||||
@returns text of response
|
@returns text of response
|
||||||
'''
|
'''
|
||||||
body = self._build_req_body(**opts)
|
options = opts
|
||||||
|
if jwt is False:
|
||||||
|
options['id'] = self.id
|
||||||
|
if isinstance(self.secret, tuple):
|
||||||
|
options['secret'] = self.secret[0]
|
||||||
|
else:
|
||||||
|
options['secret'] = self.secret
|
||||||
|
else:
|
||||||
|
options['jwt'] = jwt
|
||||||
|
|
||||||
|
body = self._build_req_body(**options)
|
||||||
r = requests.get(self.base + url, data=body)
|
r = requests.get(self.base + url, data=body)
|
||||||
self.log(opts, self.base + url, 'GET', r)
|
self.log(opts, self.base + url, 'GET', r)
|
||||||
return r.text
|
return r.text
|
||||||
|
|
||||||
def delete(self, url, **opts):
|
def delete(self, url, jwt=False, **opts):
|
||||||
'''
|
'''
|
||||||
@returns text of response
|
@returns text of response
|
||||||
'''
|
'''
|
||||||
body = self._build_req_body(**opts)
|
options = opts
|
||||||
|
if jwt is False:
|
||||||
|
options['id'] = self.id
|
||||||
|
if isinstance(self.secret, tuple):
|
||||||
|
options['secret'] = self.secret[0]
|
||||||
|
else:
|
||||||
|
options['secret'] = self.secret
|
||||||
|
else:
|
||||||
|
options['jwt'] = jwt
|
||||||
|
|
||||||
|
body = self._build_req_body(**options)
|
||||||
r = requests.delete(self.base + url, data=body)
|
r = requests.delete(self.base + url, data=body)
|
||||||
self.log(opts, self.base + url, 'DELETE', r)
|
self.log(opts, self.base + url, 'DELETE', r)
|
||||||
return r.text
|
return r.text
|
||||||
@ -101,8 +141,31 @@ class Test:
|
|||||||
def creds(self):
|
def creds(self):
|
||||||
return self.body
|
return self.body
|
||||||
|
|
||||||
|
def auth_tests(worker):
|
||||||
|
worker.stdout_to_stderr()
|
||||||
|
|
||||||
|
# the first two are sanity checks and should not faill
|
||||||
|
worker.get('/channels/list') # Should 400 or something since we're not sending the right keys
|
||||||
|
jwt_response = worker.post('/login', jwt=False)
|
||||||
|
jwt = json.loads(jwt_response)['jwt']
|
||||||
|
worker.get('/channels/list', jwt=jwt) # maybe now we'll 200?
|
||||||
|
|
||||||
|
# now for some things that may/may not fail or something idk
|
||||||
|
cname = time.time()
|
||||||
|
# pass 200
|
||||||
|
newchannel = worker.post('/channels/create', jwt=jwt, name=f'{cname}', kind=1, description='some description')
|
||||||
|
newchannel = json.loads(newchannel)
|
||||||
|
|
||||||
|
# fail 400 or something
|
||||||
|
worker.post('/channels/create', jwt=jwt, name=f'{cname}', kind=1, description='some description')
|
||||||
|
|
||||||
|
# ez pass
|
||||||
|
worker.get('/channels/list', jwt=jwt)
|
||||||
|
# pass 200
|
||||||
|
worker.delete('/channels/delete', jwt=jwt, channel_id=newchannel['id'])
|
||||||
|
|
||||||
|
# these might be fucked now
|
||||||
def base_working_tests(worker):
|
def base_working_tests(worker):
|
||||||
print('')
|
|
||||||
# First the invites api gets some basic tests
|
# First the invites api gets some basic tests
|
||||||
|
|
||||||
# Channels things
|
# Channels things
|
||||||
@ -117,7 +180,6 @@ def base_working_tests(worker):
|
|||||||
worker.get('/channels/list')
|
worker.get('/channels/list')
|
||||||
|
|
||||||
# Messaging
|
# Messaging
|
||||||
|
|
||||||
msg_chan_id = time.time()
|
msg_chan_id = time.time()
|
||||||
msg_chan_raw = worker.post('/channels/create', name=f'{msg_chan_id}', kind=TEXT_CHANNEL)
|
msg_chan_raw = worker.post('/channels/create', name=f'{msg_chan_id}', kind=TEXT_CHANNEL)
|
||||||
msg_chan = json.loads(msg_chan_raw)
|
msg_chan = json.loads(msg_chan_raw)
|
||||||
@ -127,6 +189,7 @@ def base_working_tests(worker):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
worker = Test(create_admin=True, init_verbose=True)
|
worker = Test(create_admin=False, init_verbose=True)
|
||||||
base_working_tests(worker)
|
#base_working_tests(worker)
|
||||||
|
auth_tests(worker)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user