mirror of
https://github.com/simple-login/app.git
synced 2024-11-13 23:51:13 +01:00
54 lines
2 KiB
Python
54 lines
2 KiB
Python
import flask
|
|
import pytest
|
|
|
|
from app.oauth_models import get_scopes, Scope, get_response_types, ResponseType
|
|
|
|
|
|
def test_get_scopes(flask_app):
|
|
with flask_app.test_request_context("/"):
|
|
scopes = get_scopes(flask.request)
|
|
assert scopes == set()
|
|
|
|
with flask_app.test_request_context("/?scope=email&scope=name"):
|
|
scopes = get_scopes(flask.request)
|
|
assert scopes == {Scope.NAME, Scope.EMAIL}
|
|
|
|
# a space between email and name
|
|
with flask_app.test_request_context("/?scope=email%20name"):
|
|
scopes = get_scopes(flask.request)
|
|
assert scopes == {Scope.NAME, Scope.EMAIL}
|
|
|
|
# a comma between email and name
|
|
with flask_app.test_request_context("/?scope=email,name"):
|
|
scopes = get_scopes(flask.request)
|
|
assert scopes == {Scope.NAME, Scope.EMAIL}
|
|
|
|
# non-existent scope: raise ValueError
|
|
with flask_app.test_request_context("/?scope=abcd"):
|
|
with pytest.raises(ValueError):
|
|
get_scopes(flask.request)
|
|
|
|
|
|
def test_get_response_types(flask_app):
|
|
with flask_app.test_request_context("/"):
|
|
response_types = get_response_types(flask.request)
|
|
assert response_types == set()
|
|
|
|
with flask_app.test_request_context("/?response_type=token&response_type=id_token"):
|
|
response_types = get_response_types(flask.request)
|
|
assert response_types == {ResponseType.TOKEN, ResponseType.ID_TOKEN}
|
|
|
|
# a space as separator
|
|
with flask_app.test_request_context("/?response_type=token%20id_token"):
|
|
response_types = get_response_types(flask.request)
|
|
assert response_types == {ResponseType.TOKEN, ResponseType.ID_TOKEN}
|
|
|
|
# a comma as separator
|
|
with flask_app.test_request_context("/?response_type=id_token,token"):
|
|
response_types = get_response_types(flask.request)
|
|
assert response_types == {ResponseType.TOKEN, ResponseType.ID_TOKEN}
|
|
|
|
# non-existent response_type: raise ValueError
|
|
with flask_app.test_request_context("/?response_type=abcd"):
|
|
with pytest.raises(ValueError):
|
|
get_response_types(flask.request)
|