add session route
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
from http import HTTPMethod
|
||||
from http import HTTPMethod, HTTPStatus
|
||||
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer
|
||||
|
||||
from jose_ import generate_jwt
|
||||
from routes.session import new_session
|
||||
|
||||
from ..conftest import HttpApiProxy, LambdaContext
|
||||
|
||||
CLIENT_ID = 'd72d4005-1fa7-4430-9754-80d5e2487bb6'
|
||||
USER_ID = '357db1c5-7442-4075-98a3-fbe5c938a419'
|
||||
|
||||
|
||||
def test_authorize(
|
||||
app,
|
||||
@@ -14,12 +17,7 @@ def test_authorize(
|
||||
http_api_proxy: HttpApiProxy,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
client_id = 'd72d4005-1fa7-4430-9754-80d5e2487bb6'
|
||||
|
||||
id_token = generate_jwt(
|
||||
user_id='357db1c5-7442-4075-98a3-fbe5c938a419',
|
||||
email='sergio@somosbeta.com.br',
|
||||
)
|
||||
session_id = new_session(USER_ID)
|
||||
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
@@ -27,21 +25,21 @@ def test_authorize(
|
||||
method=HTTPMethod.GET,
|
||||
query_string_parameters={
|
||||
'response_type': 'code',
|
||||
'client_id': client_id,
|
||||
'client_id': CLIENT_ID,
|
||||
'redirect_uri': 'https://localhost/callback',
|
||||
'scope': 'openid offline_access',
|
||||
'nonce': '123',
|
||||
'state': '456',
|
||||
},
|
||||
cookies=[
|
||||
f'id_token={id_token}; HttpOnly; Secure',
|
||||
f'session_id={session_id}; HttpOnly; Secure',
|
||||
],
|
||||
),
|
||||
lambda_context,
|
||||
)
|
||||
|
||||
assert 'Location' in r['headers']
|
||||
print(r)
|
||||
# print(r)
|
||||
|
||||
r = dynamodb_persistence_layer.query(
|
||||
key_cond_expr='#pk = :pk',
|
||||
@@ -55,3 +53,34 @@ def test_authorize(
|
||||
|
||||
# One item was added from seeds
|
||||
assert len(r['items']) == 3
|
||||
|
||||
|
||||
def test_authorize_revoked(
|
||||
app,
|
||||
seeds,
|
||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
http_api_proxy: HttpApiProxy,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
invalid_session_id = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzaWQiOiIwNTgzNTBhYi02NGU1LTQ0MzEtYmQyNy01MGVhOWIxNmQxZGYiLCJzdWIiOiIzNTdkYjFjNS03NDQyLTQwNzUtOThhMy1mYmU1YzkzOGE0MTkiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0IiwiaWF0IjoxNzU1Mzk3Nzk5LCJleHAiOjE3NTUzOTg2OTl9.dDbiHYReVERbkNH2df4sXK2VIwT7G1KjNC5UrBuN6IQ'
|
||||
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
raw_path='/authorize',
|
||||
method=HTTPMethod.GET,
|
||||
query_string_parameters={
|
||||
'response_type': 'code',
|
||||
'client_id': CLIENT_ID,
|
||||
'redirect_uri': 'https://localhost/callback',
|
||||
'scope': 'openid offline_access',
|
||||
'nonce': '123',
|
||||
'state': '456',
|
||||
},
|
||||
cookies=[
|
||||
f'session_id={invalid_session_id}; HttpOnly; Secure',
|
||||
],
|
||||
),
|
||||
lambda_context,
|
||||
)
|
||||
|
||||
assert r['statusCode'] == HTTPStatus.BAD_REQUEST
|
||||
|
||||
Reference in New Issue
Block a user