add test
This commit is contained in:
@@ -101,7 +101,6 @@ def _create_user(*, user: User, password: str):
|
|||||||
'sk': f'emails#{user.email}',
|
'sk': f'emails#{user.email}',
|
||||||
'email_verified': False,
|
'email_verified': False,
|
||||||
'email_primary': True,
|
'email_primary': True,
|
||||||
'mx_record_exists': False,
|
|
||||||
'created_at': now_,
|
'created_at': now_,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -145,13 +144,17 @@ def _update_user(*, old_user: User, new_user: User, password: str):
|
|||||||
key=KeyPair(new_user.id, '0'),
|
key=KeyPair(new_user.id, '0'),
|
||||||
update_expr='SET #name = :name, \
|
update_expr='SET #name = :name, \
|
||||||
email = :email, \
|
email = :email, \
|
||||||
updated_at = :now',
|
email_verified = :false, \
|
||||||
|
updated_at = :now \
|
||||||
|
ADD emails :emails', # Makes the email searchable
|
||||||
expr_attr_names={
|
expr_attr_names={
|
||||||
'#name': 'name',
|
'#name': 'name',
|
||||||
},
|
},
|
||||||
expr_attr_values={
|
expr_attr_values={
|
||||||
':name': new_user.name,
|
':name': new_user.name,
|
||||||
':email': new_user.email,
|
':email': new_user.email,
|
||||||
|
':emails': {new_user.email},
|
||||||
|
':false': False,
|
||||||
':now': now_,
|
':now': now_,
|
||||||
},
|
},
|
||||||
cond_expr='attribute_exists(sk)',
|
cond_expr='attribute_exists(sk)',
|
||||||
@@ -178,7 +181,6 @@ def _update_user(*, old_user: User, new_user: User, password: str):
|
|||||||
'sk': f'emails#{new_user.email}',
|
'sk': f'emails#{new_user.email}',
|
||||||
'email_verified': False,
|
'email_verified': False,
|
||||||
'email_primary': True,
|
'email_primary': True,
|
||||||
'mx_record_exists': False,
|
|
||||||
'created_at': now_,
|
'created_at': now_,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
from http import HTTPMethod, HTTPStatus
|
from http import HTTPMethod, HTTPStatus
|
||||||
|
|
||||||
from layercake.dynamodb import DynamoDBPersistenceLayer
|
from layercake.dynamodb import DynamoDBPersistenceLayer, SortKey, TransactKey
|
||||||
|
|
||||||
from ..conftest import HttpApiProxy, LambdaContext
|
from ..conftest import HttpApiProxy, LambdaContext
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ def test_preexisting_user(
|
|||||||
assert r['statusCode'] == HTTPStatus.OK
|
assert r['statusCode'] == HTTPStatus.OK
|
||||||
|
|
||||||
|
|
||||||
def test_preexisting_update_email(
|
def test_preexisting_user_conflict(
|
||||||
app,
|
app,
|
||||||
seeds,
|
seeds,
|
||||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||||
@@ -58,6 +58,47 @@ def test_preexisting_update_email(
|
|||||||
assert r['statusCode'] == HTTPStatus.CONFLICT
|
assert r['statusCode'] == HTTPStatus.CONFLICT
|
||||||
|
|
||||||
|
|
||||||
|
def test_preexisting_user_update_email(
|
||||||
|
app,
|
||||||
|
seeds,
|
||||||
|
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||||
|
http_api_proxy: HttpApiProxy,
|
||||||
|
lambda_context: LambdaContext,
|
||||||
|
):
|
||||||
|
r = app.lambda_handler(
|
||||||
|
http_api_proxy(
|
||||||
|
raw_path='/register',
|
||||||
|
method=HTTPMethod.POST,
|
||||||
|
body={
|
||||||
|
'id': '357db1c5-7442-4075-98a3-fbe5c938a419',
|
||||||
|
'name': 'Sérgio R Siqueira',
|
||||||
|
'cpf': '07879819908',
|
||||||
|
'password': 'Led@Zepellin',
|
||||||
|
'email': 'osergiosiqueira+pytest@gmail.com',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
lambda_context,
|
||||||
|
)
|
||||||
|
assert r['statusCode'] == HTTPStatus.OK
|
||||||
|
|
||||||
|
user = dynamodb_persistence_layer.collection.get_items(
|
||||||
|
TransactKey(
|
||||||
|
'357db1c5-7442-4075-98a3-fbe5c938a419',
|
||||||
|
)
|
||||||
|
+ SortKey('0')
|
||||||
|
+ SortKey('emails#osergiosiqueira+pytest@gmail.com')
|
||||||
|
+ SortKey('emails#sergio@somosbeta.com.br'),
|
||||||
|
flatten_top=False,
|
||||||
|
)
|
||||||
|
assert user['0']['email'] == 'osergiosiqueira+pytest@gmail.com'
|
||||||
|
assert 'emails#osergiosiqueira+pytest@gmail.com' in user
|
||||||
|
assert 'emails#sergio@somosbeta.com.br' in user
|
||||||
|
assert user['0']['emails'] == {
|
||||||
|
'sergio@somosbeta.com.br',
|
||||||
|
'osergiosiqueira+pytest@gmail.com',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_non_preexisting_user(
|
def test_non_preexisting_user(
|
||||||
app,
|
app,
|
||||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||||
|
|||||||
@@ -12,7 +12,9 @@
|
|||||||
{"id": "SESSION", "sk": "36af142e-9f6d-49d3-bfe9-6a6bd6ab2712", "user_id": "357db1c5-7442-4075-98a3-fbe5c938a419"}
|
{"id": "SESSION", "sk": "36af142e-9f6d-49d3-bfe9-6a6bd6ab2712", "user_id": "357db1c5-7442-4075-98a3-fbe5c938a419"}
|
||||||
|
|
||||||
// User data
|
// User data
|
||||||
{"id": "357db1c5-7442-4075-98a3-fbe5c938a419", "sk": "0", "name": "Sérgio R Siqueira", "email": "sergio@somosbeta.com.br", "cpf": "07879819908"}
|
{"id": "357db1c5-7442-4075-98a3-fbe5c938a419", "sk": "0", "name": "Sérgio R Siqueira", "email": "sergio@somosbeta.com.br", "cpf": "07879819908", "emails": ["sergio@somosbeta.com.br"]}
|
||||||
|
// Post-migrations (users): rename `emails#` to `EMAIL#`
|
||||||
|
{"id": "357db1c5-7442-4075-98a3-fbe5c938a419", "sk": "emails#sergio@somosbeta.com.br", "email_verified": true}
|
||||||
{"id": "357db1c5-7442-4075-98a3-fbe5c938a419", "sk": "PASSWORD", "hash": "$pbkdf2-sha256$29000$IuTcm7M2BiAEgPB.b.3dGw$d8xVCbx8zxg7MeQBrOvCOgniiilsIHEMHzoH/OXftLQ"}
|
{"id": "357db1c5-7442-4075-98a3-fbe5c938a419", "sk": "PASSWORD", "hash": "$pbkdf2-sha256$29000$IuTcm7M2BiAEgPB.b.3dGw$d8xVCbx8zxg7MeQBrOvCOgniiilsIHEMHzoH/OXftLQ"}
|
||||||
{"id": "357db1c5-7442-4075-98a3-fbe5c938a419", "sk": "SCOPE", "scope": ["openid", "profile", "email", "offline_access", "apps:admin"]}
|
{"id": "357db1c5-7442-4075-98a3-fbe5c938a419", "sk": "SCOPE", "scope": ["openid", "profile", "email", "offline_access", "apps:admin"]}
|
||||||
{"id": "357db1c5-7442-4075-98a3-fbe5c938a419", "sk": "SESSION#36af142e-9f6d-49d3-bfe9-6a6bd6ab2712", "created_at": "2025-09-17T13:44:34.544491-03:00", "ttl": 1760719474}
|
{"id": "357db1c5-7442-4075-98a3-fbe5c938a419", "sk": "SESSION#36af142e-9f6d-49d3-bfe9-6a6bd6ab2712", "created_at": "2025-09-17T13:44:34.544491-03:00", "ttl": 1760719474}
|
||||||
|
|||||||
Reference in New Issue
Block a user