halfapi/tests/test_jwt_middleware.py

30 lines
731 B
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import jwt
import requests
import pytest
import json
import sys
from hashlib import sha256
from halfapi.app import app
from base64 import b64decode
def coucou():
return
def test_connected():
app.route('/', coucou)
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'])