add apikey
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
from layercake.dynamodb import DynamoDBCollection, DynamoDBPersistenceLayer
|
||||
|
||||
import auth as app
|
||||
from auth import _parse_bearer_token
|
||||
|
||||
from .conftest import LambdaContext
|
||||
|
||||
|
||||
def test_bearer_jwt(lambda_context: LambdaContext, dynamodb_seeds):
|
||||
def test_bearer_jwt(lambda_context: LambdaContext):
|
||||
# You should mock the Cognito user to pass the test
|
||||
app.get_user = lambda *args, **kwargs: {
|
||||
'sub': '58efed8d-d276-41a8-8502-4ab8b5a6415e',
|
||||
@@ -29,6 +31,31 @@ def test_bearer_jwt(lambda_context: LambdaContext, dynamodb_seeds):
|
||||
}
|
||||
|
||||
|
||||
def test_bearer_apikey(
|
||||
dynamodb_seeds,
|
||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
app.collect = DynamoDBCollection(dynamodb_persistence_layer)
|
||||
|
||||
event = {
|
||||
'headers': {
|
||||
'authorization': 'Bearer sk-32504457-f133-4c00-936b-6aa712ca9f40',
|
||||
}
|
||||
}
|
||||
# This data was added from seeds
|
||||
assert app.lambda_handler(event, lambda_context) == {
|
||||
'isAuthorized': True,
|
||||
'context': {'tenant': {'name': 'default', 'id': '*'}},
|
||||
}
|
||||
|
||||
# This data was added from seeds
|
||||
assert app.lambda_handler(
|
||||
{'headers': {'authorization': 'Bearer sk-abc'}},
|
||||
lambda_context,
|
||||
) == {'isAuthorized': False}
|
||||
|
||||
|
||||
def test_parse_bearer_token_api_key():
|
||||
bearer = _parse_bearer_token(
|
||||
'Bearer sk-35433970-6857-4062-bb43-f71683b2f68e',
|
||||
|
||||
Reference in New Issue
Block a user