2020-07-03 11:42:10 +02:00
|
|
|
|
import jwt
|
2020-07-08 12:41:24 +02:00
|
|
|
|
import requests
|
|
|
|
|
import pytest
|
|
|
|
|
import json
|
|
|
|
|
import sys
|
|
|
|
|
from hashlib import sha256
|
|
|
|
|
from halfapi.app import app
|
|
|
|
|
from base64 import b64decode
|
2020-07-03 11:42:10 +02:00
|
|
|
|
|
|
|
|
|
def coucou():
|
|
|
|
|
return
|
|
|
|
|
def test_connected():
|
|
|
|
|
app.route('/', coucou)
|
2020-07-08 12:41:24 +02:00
|
|
|
|
|
|
|
|
|
def test_token():
|
|
|
|
|
# This test needs to have a running auth-lirmm on 127.0.0.1:3000
|
|
|
|
|
|
|
|
|
|
r = requests.post('http://127.0.0.1:3000/',
|
|
|
|
|
data={'email':'maizi', 'password':'a'})
|
|
|
|
|
|
|
|
|
|
assert len(r.text) > 0
|
|
|
|
|
res = json.loads(r.text)
|
|
|
|
|
assert 'token' in res.keys()
|
|
|
|
|
sys.stderr.write(f'Token : {res["token"]}\n')
|
|
|
|
|
secret = open('/etc/half_orm/secret').readline()
|
|
|
|
|
sys.stderr.write(f'Secret : {secret}\n')
|
|
|
|
|
assert jwt.decode(
|
|
|
|
|
res['token'],
|
|
|
|
|
secret, algorithms=['HS256'])
|