mirror of
https://github.com/simple-login/app.git
synced 2024-11-16 00:48:32 +01:00
fix test
This commit is contained in:
parent
264bab965a
commit
348c2271c6
2 changed files with 29 additions and 25 deletions
|
@ -6,7 +6,7 @@ from flask import url_for
|
||||||
|
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.jose_utils import verify_id_token, decode_id_token
|
from app.jose_utils import verify_id_token, decode_id_token
|
||||||
from app.models import Client, User
|
from app.models import Client, User, ClientUser
|
||||||
from app.oauth.views.authorize import (
|
from app.oauth.views.authorize import (
|
||||||
get_host_name_and_scheme,
|
get_host_name_and_scheme,
|
||||||
generate_access_token,
|
generate_access_token,
|
||||||
|
@ -192,14 +192,16 @@ def test_authorize_code_flow_no_openid_scope(flask_client):
|
||||||
assert not r.json["scope"]
|
assert not r.json["scope"]
|
||||||
assert r.json["token_type"] == "Bearer"
|
assert r.json["token_type"] == "Bearer"
|
||||||
|
|
||||||
|
client_user = ClientUser.first()
|
||||||
|
|
||||||
assert r.json["user"] == {
|
assert r.json["user"] == {
|
||||||
"avatar_url": None,
|
"avatar_url": None,
|
||||||
"client": "test client",
|
"client": "test client",
|
||||||
"email": "x@y.z",
|
"email": "x@y.z",
|
||||||
"email_verified": True,
|
"email_verified": True,
|
||||||
"id": 1,
|
"id": client_user.id,
|
||||||
"name": "AB CD",
|
"name": "AB CD",
|
||||||
"sub": "1",
|
"sub": str(client_user.id),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -280,14 +282,16 @@ def test_authorize_code_flow_with_openid_scope(flask_client):
|
||||||
assert r.json["scope"] == "openid"
|
assert r.json["scope"] == "openid"
|
||||||
assert r.json["token_type"] == "Bearer"
|
assert r.json["token_type"] == "Bearer"
|
||||||
|
|
||||||
|
client_user = ClientUser.first()
|
||||||
|
|
||||||
assert r.json["user"] == {
|
assert r.json["user"] == {
|
||||||
"avatar_url": None,
|
"avatar_url": None,
|
||||||
"client": "test client",
|
"client": "test client",
|
||||||
"email": "x@y.z",
|
"email": "x@y.z",
|
||||||
"email_verified": True,
|
"email_verified": True,
|
||||||
"id": 1,
|
"id": client_user.id,
|
||||||
"name": "AB CD",
|
"name": "AB CD",
|
||||||
"sub": "1",
|
"sub": str(client_user.id),
|
||||||
}
|
}
|
||||||
|
|
||||||
# id_token must be returned
|
# id_token must be returned
|
||||||
|
@ -601,14 +605,16 @@ def test_authorize_code_id_token_flow(flask_client):
|
||||||
assert not r.json["scope"]
|
assert not r.json["scope"]
|
||||||
assert r.json["token_type"] == "Bearer"
|
assert r.json["token_type"] == "Bearer"
|
||||||
|
|
||||||
|
client_user = ClientUser.first()
|
||||||
|
|
||||||
assert r.json["user"] == {
|
assert r.json["user"] == {
|
||||||
"avatar_url": None,
|
"avatar_url": None,
|
||||||
"client": "test client",
|
"client": "test client",
|
||||||
"email": "x@y.z",
|
"email": "x@y.z",
|
||||||
"email_verified": True,
|
"email_verified": True,
|
||||||
"id": 1,
|
"id": client_user.id,
|
||||||
"name": "AB CD",
|
"name": "AB CD",
|
||||||
"sub": "1",
|
"sub": str(client_user.id),
|
||||||
}
|
}
|
||||||
|
|
||||||
# id_token must be returned
|
# id_token must be returned
|
||||||
|
|
|
@ -3,28 +3,26 @@ from app.jose_utils import make_id_token, verify_id_token
|
||||||
from app.models import ClientUser, User, Client
|
from app.models import ClientUser, User, Client
|
||||||
|
|
||||||
|
|
||||||
def test_encode_decode(flask_app):
|
def test_encode_decode(flask_client):
|
||||||
with flask_app.app_context():
|
user = User.create(
|
||||||
user = User.create(
|
email="a@b.c", password="password", name="Test User", activated=True
|
||||||
email="a@b.c", password="password", name="Test User", activated=True
|
)
|
||||||
)
|
db.session.commit()
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
client1 = Client.create_new(name="Demo", user_id=user.id)
|
client1 = Client.create_new(name="Demo", user_id=user.id)
|
||||||
client1.oauth_client_id = "client-id"
|
client1.oauth_client_id = "client-id"
|
||||||
client1.oauth_client_secret = "client-secret"
|
client1.oauth_client_secret = "client-secret"
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
client_user = ClientUser.create(client_id=client1.id, user_id=user.id)
|
client_user = ClientUser.create(client_id=client1.id, user_id=user.id)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
jwt_token = make_id_token(client_user)
|
jwt_token = make_id_token(client_user)
|
||||||
|
|
||||||
assert type(jwt_token) is str
|
assert type(jwt_token) is str
|
||||||
assert verify_id_token(jwt_token)
|
assert verify_id_token(jwt_token)
|
||||||
|
|
||||||
|
|
||||||
def test_db_tear_down(flask_app):
|
def test_db_tear_down(flask_client):
|
||||||
"""make sure the db is reset after each test"""
|
"""make sure the db is reset after each test"""
|
||||||
with flask_app.app_context():
|
assert len(ClientUser.filter_by().all()) == 0
|
||||||
assert len(ClientUser.filter_by().all()) == 0
|
|
||||||
|
|
Loading…
Reference in a new issue