Passing tests for invite routes

This commit is contained in:
shockrah 2021-02-25 16:05:46 -08:00
parent 212173f543
commit 05acbfa94e
3 changed files with 39 additions and 25 deletions

View File

@ -20,8 +20,8 @@ class Worker:
self.jwt = None # never gets assigned until /login is hit
self.basic_creds = self.__create_admin()
self.id = self.basic_creds['id']
self.secret = self.basic_creds['secret']
self.id = self.basic_creds['user']['id']
self.secret = self.basic_creds['user']['secret']
def __create_admin(self):
# /home/$user/.cargo/bin/cargo <- normally
@ -61,6 +61,24 @@ class Worker:
opts['jwt'] = auth
return opts
def run_test(self, test):
# {
# 'init': [method, uri, query_string_dict],
# 'auth':jwt|none,
# 'hope': <status-code>
# 'body': <bool> # show response body or not (optional
# }
# not 'try'ing these as misconfigurations are to be cleaned up before testing
method, path, opts = test['init']
auth = test['auth']
hope = test['hope']
if 'body' in test:
self.request(method, path, auth, opts, hope, show_body=test['body'])
else:
self.request(method, path, auth, opts, hope)
def logs(self):
ids = sorted(self.requests.keys()) # shared keys in requests/responses
for key in ids:
@ -118,10 +136,10 @@ class Worker:
def run(worker: Worker):
VOICE_CHAN = 1
TEXT_CHAN = 2
# Basically every test requires a jwt to be passed in so we grab that here
# Should this fail so should nearly every other test from this point
req_login = worker.request('post', '/login', 'basic',{}, 200)
print(worker.responses[req_login].json())
jwt = worker.responses[req_login].json()['jwt']
new_channel_name = time.time()
@ -144,11 +162,7 @@ def run(worker: Worker):
]
for test in channel_tests:
method, path, opts = test['init']
auth = test['auth']
hope = test['hope']
worker.request(method, path, auth, opts, hope)
worker.run_test(test)
msg_chan_name = time.time()
_id = worker.request('post', '/channels/create', jwt, {
@ -220,13 +234,7 @@ def run(worker: Worker):
]
for test in message_tests:
method, path, opts = test['init']
auth = test['auth']
hope = test['hope']
if 'body' in test:
worker.request(method, path, auth, opts, hope, show_body=test['body'])
else:
worker.request(method, path, auth, opts, hope)
worker.run_test(test)
@ -238,13 +246,20 @@ def run(worker: Worker):
]
for test in member_tests:
method, path, opts = test['init']
auth = test['auth']
hope = test['hope']
if 'body' in test:
worker.request(method, path, auth, opts, hope, show_body=test['body'])
else:
worker.request(method, path, auth, opts, hope)
worker.run_test(test)
invite_tests = [
{'init': ['post', '/invite/create', {}], 'auth': jwt, 'hope': 200, 'body': True},
{'init': ['get', '/invite/create', {}], 'auth': jwt, 'hope': 404, 'body': True},
]
for test in invite_tests:
worker.run_test(test)
# ad-hoc test for joining now
invite_req_id = worker.request('post', '/invite/create', jwt, {}, 200, True)
code = worker.responses[invite_req_id].json()['id']
worker.request('get', '/join', None, {'code': code}, 200, True)
worker.logs()
worker.test_stats()

View File

@ -122,7 +122,7 @@ impl Invite {
use chrono::Utc;
Invite {
id: (Utc::now() + chrono::Duration::minutes(30)).timestamp(),
id: (Utc::now() + chrono::Duration::minutes(30)).timestamp_millis(),
uses,
expires
}

View File

@ -37,9 +37,8 @@ async fn valid_invite(pool: &Pool, id: BigInt) -> bool {
if let Some(invite) = query {
// if expires at all
if invite.expires {
let now = Utc::now().timestamp();
let now = Utc::now().timestamp_millis();
// old?
println!("{} {}", now, invite.id);
let mut valid_status = now < invite.id;
// used?
if invite.uses.is_some() && valid_status == false {