This commit is contained in:
2025-04-01 19:15:10 -03:00
parent dbe7a924e2
commit ef4bfc07f3
16 changed files with 197 additions and 44 deletions

View File

@@ -34,6 +34,7 @@ class HttpApiProxy:
body: dict = {},
*,
headers: dict = {},
auth_flow_type: str = 'USER_AUTH',
**kwargs,
) -> dict:
return {
@@ -59,7 +60,7 @@ class HttpApiProxy:
'custom:user_id': '5OxmMjL-ujoR5IMGegQz',
'sub': 'c4f30dbd-083e-4b84-aa50-c31afe9b9c01',
},
'auth_flow_type': 'USER_AUTH',
'auth_flow_type': auth_flow_type,
},
'jwt': {
'claims': {'claim1': 'value1', 'claim2': 'value2'},

View File

@@ -4,7 +4,7 @@ from http import HTTPMethod, HTTPStatus
from ..conftest import HttpApiProxy, LambdaContext
def test_me(
def test_settings(
mock_app,
dynamodb_seeds,
http_api_proxy: HttpApiProxy,
@@ -12,10 +12,7 @@ def test_me(
):
# This data was added from seeds
r = mock_app.lambda_handler(
http_api_proxy(
raw_path='/me',
method=HTTPMethod.GET,
),
http_api_proxy(raw_path='/settings', method=HTTPMethod.GET),
lambda_context,
)
@@ -37,7 +34,7 @@ def test_me(
'roles': ['ADMIN'],
},
],
'workspaces': [
'tenants': [
{
'sk': 'cJtK9SsnJhKPyxESe7g3DG',
'name': 'Beta Educação',

View File

@@ -5,8 +5,6 @@ from .conftest import LambdaContext
def test_bearer_jwt(lambda_context: LambdaContext):
import auth as app
# You should mock the Cognito user to pass the test
app.get_user = lambda *args, **kwargs: {
'sub': '58efed8d-d276-41a8-8502-4ab8b5a6415e',
@@ -32,11 +30,7 @@ def test_bearer_jwt(lambda_context: LambdaContext):
}
def test_bearer_apikey(
monkeypatch,
dynamodb_seeds,
lambda_context: LambdaContext,
):
def test_bearer_apikey(dynamodb_seeds, lambda_context: LambdaContext):
event = {
'headers': {
'authorization': 'Bearer sk-MzI1MDQ0NTctZjEzMy00YzAwLTkzNmItNmFhNzEyY2E5ZjQw',

View File

@@ -0,0 +1,31 @@
from http import HTTPMethod
from aws_lambda_powertools.event_handler.api_gateway import APIGatewayHttpResolver
from middlewares import TenantMiddleware
from .conftest import HttpApiProxy, LambdaContext
def test_eval(
dynamodb_seeds,
http_api_proxy: HttpApiProxy,
lambda_context: LambdaContext,
):
app = APIGatewayHttpResolver()
app.use(middlewares=[TenantMiddleware()])
@app.get('/')
def index():
return {}
result = app(
http_api_proxy(
raw_path='/',
method=HTTPMethod.GET,
headers={'Tenant': 'cJtK9SsnJhKPyxESe7g3DG'},
),
lambda_context,
)
assert result['statusCode'] == 200