def test_upload_download_delete(db, u1client): filename = '/tmp/test.txt' with open(filename, 'w') as f: f.write('hello') with open(filename, 'r') as f: res = u1client.post('/common/attachments/', data={ 'file': f, 'content_type': 'text/plain', 'filename': 'test.txt' }) assert_success(response=res, status_code=201) data = res.json() id = data['id'] res = u1client.get(f'/common/attachments/{id}/download/') assert res.get('Content-Disposition') == 'attachment; filename="test.txt"' content = str(res.content, 'utf-8') assert content == 'hello' res = u1client.delete(f'/common/attachments/{id}/') assert res.status_code == 204 res = u1client.get('/common/attachments/') assert_success(response=res, status_code=200) data = res.json() assert data['count'] == 0
def test_switch(db, u1client): res = u1client.post(f'/auth/workspaces/2/switch/') assert_success(response=res, status_code=200) data = res.json() assert 'access_token' in data and 'refresh_token' in data access_token = data['access_token'] refresh_token = data['refresh_token'] assert_claim(token=access_token, workspace_id=2)
def test_create(db, u3client): res = u3client.post('/common/tpas/', data={ 'name': 'supertpa', 'description': 'most awesome tpa ever', 'enabled': True, 'redirect_uris': 'https://www.google.com/', 'secret': 'supertpa' }) assert_success(response=res, status_code=201) data = res.json()
def test_signup(db, client): res = client.post('/auth/basic/signup/', data={ 'email': '*****@*****.**', 'password': '******', 'first_name': 'User100', 'last_name': 'Earth' }) assert_success(response=res, status_code=200) data = res.json() assert 'access_token' in data and 'refresh_token' in data
def test_signin(db, client): res = client.post('/auth/basic/signin/', data={ 'email': '*****@*****.**', 'password': '******' }) assert_success(response=res, status_code=200) data = res.json() access_token = data['access_token'] refresh_token = data['refresh_token'] assert_claim(token=refresh_token, workspace_id=None, user_id=1) assert_claim(token=access_token, workspace_id=None, user_id=1)
def test_refresh_token(db, client): res = client.post('/auth/basic/signin/', data={ 'email': '*****@*****.**', 'password': '******' }) data = res.json() refresh_token = data['refresh_token'] res = client.post('/auth/token/', data={'refresh_token': refresh_token}) assert_success(response=res, status_code=200) data = res.json() assert 'access_token' in data
def tokens(u1client, code, code_verifier): res = u1client.post('/auth/o/token/', data={ 'client_id': 2, 'code': code, 'state': 'yabba', 'grant_type': 'authorization_code', 'code_verifier': code_verifier }) assert_success(response=res, status_code=200) data = res.json() assert 'access_token' in data assert 'refresh_token' in data return data['refresh_token'], data['access_token']
def test_access_token(u1client): code = authorize(u1client=u1client) refresh_token, access_token = tokens(u1client=u1client, code=code) res = u1client.post('/auth/o/token/', data={ 'client_id': 2, 'client_secret': 'password123', 'refresh_token': refresh_token, 'grant_type': 'refresh_token' }) assert_success(response=res, status_code=200) data = res.json() assert 'refresh_token' in data assert 'access_token' in data assert_claim(token=access_token, tpa_id=2)
def authorize(u1client): res = u1client.get('/auth/o/authorize/', data={ 'client_id': 2, 'response_type': 'code', 'state': 'yabba', 'redirect_uri': 'https://www.google.com/', 'scope': 'admin' }) assert_success(response=res, status_code=200) data = res.json() assert 'redirect_uri' in data redirect_uri = data['redirect_uri'] p = re.compile('.*code=(.*)&.*') m = p.match(redirect_uri) code = m.group(1) return code
def test_access_token(u1client, random_str1): code = authorize(u1client=u1client, code_verifier=random_str1) refresh_token, access_token = tokens(u1client=u1client, code=code, code_verifier=random_str1) res = u1client.post('/auth/o/token/', data={ 'client_id': 2, 'code_verifier': random_str1, 'refresh_token': refresh_token, 'grant_type': 'refresh_token' }) assert_success(response=res, status_code=200) data = res.json() assert 'refresh_token' in data assert 'access_token' in data assert_claim(token=access_token, tpa_id=2)
def test_list1(db, u1client): res = u1client.get('/common/attachments/') assert_success(response=res, status_code=200) data = res.json() assert data['count'] == 0
def test_list1(db, u1client): res = u1client.get('/auth/workspaces/') assert_success(response=res, status_code=200) data = res.json() assert data['count'] == 2
def test_create(db, u3client): res = u3client.post('/auth/workspaces/', data={"name": "workspace3"}) assert_success(response=res, status_code=201) data = res.json() assert data['name'] == 'workspace3'
def test_list2(db, u2client): res = u2client.get('/common/tpas/') assert_success(response=res, status_code=200) data = res.json() assert data['count'] == 0