60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
from http import HTTPMethod, HTTPStatus
|
|
|
|
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair, PartitionKey
|
|
|
|
from ..conftest import HttpApiProxy, LambdaContext
|
|
|
|
|
|
def test_authentication(
|
|
app,
|
|
seeds,
|
|
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
|
http_api_proxy: HttpApiProxy,
|
|
lambda_context: LambdaContext,
|
|
):
|
|
r = app.lambda_handler(
|
|
http_api_proxy(
|
|
raw_path='/authentication',
|
|
method=HTTPMethod.POST,
|
|
body={
|
|
'username': '07879819908',
|
|
'password': 'pytest@123',
|
|
},
|
|
),
|
|
lambda_context,
|
|
)
|
|
|
|
assert len(r['cookies']) == 1
|
|
|
|
session = dynamodb_persistence_layer.collection.query(PartitionKey('SESSION'))
|
|
# One seesion if created from seeds
|
|
assert len(session['items']) == 2
|
|
|
|
|
|
def test_invalid_password(
|
|
app,
|
|
seeds,
|
|
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
|
http_api_proxy: HttpApiProxy,
|
|
lambda_context: LambdaContext,
|
|
):
|
|
r = app.lambda_handler(
|
|
http_api_proxy(
|
|
raw_path='/authentication',
|
|
method=HTTPMethod.POST,
|
|
body={
|
|
'username': '07879819908',
|
|
'password': '123333',
|
|
},
|
|
),
|
|
lambda_context,
|
|
)
|
|
|
|
assert r['statusCode'] == HTTPStatus.UNAUTHORIZED
|
|
|
|
failed = dynamodb_persistence_layer.collection.get_item(
|
|
KeyPair('357db1c5-7442-4075-98a3-fbe5c938a419', 'LOGIN#FAILED_ATTEMPTS')
|
|
)
|
|
|
|
assert 'failed_attempts' in failed
|