Skip to content

Commit eec6387

Browse files
author
gabino
committed
Handle SecretStr for password in UserCredential methods
1 parent a0388d1 commit eec6387

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

cuenca/resources/user_credentials.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
UserCredentialRequest,
66
UserCredentialUpdateRequest,
77
)
8+
from pydantic import SecretStr
89

910
from ..http import Session, session as global_session
1011
from .base import Creatable, Updateable
@@ -25,7 +26,10 @@ def create(
2526
session: Session = global_session,
2627
) -> 'UserCredential':
2728
req = UserCredentialRequest(password=password, user_id=user_id)
28-
return cls._create(**req.model_dump(), session=session)
29+
data = req.model_dump()
30+
if isinstance(data['password'], SecretStr):
31+
data['password'] = data['password'].get_secret_value()
32+
return cls._create(**data, session=session)
2933

3034
@classmethod
3135
def update(
@@ -40,4 +44,7 @@ def update(
4044
is_active=is_active,
4145
password=password,
4246
)
43-
return cls._update(id=user_id, **req.model_dump(), session=session)
47+
data = req.model_dump()
48+
if password and isinstance(data['password'], SecretStr):
49+
data['password'] = data['password'].get_secret_value()
50+
return cls._update(id=user_id, **data, session=session)

tests/resources/cassettes/test_update_password.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
interactions:
22
- request:
3-
body: '{"password": "222222"}'
3+
body: '{"password": "22222222"}'
44
headers:
55
Accept:
66
- '*/*'
@@ -54,7 +54,7 @@ interactions:
5454
code: 201
5555
message: Created
5656
- request:
57-
body: '{"password": "222222"}'
57+
body: '{"password": "22222222"}'
5858
headers:
5959
Accept:
6060
- '*/*'
@@ -108,7 +108,7 @@ interactions:
108108
code: 201
109109
message: Created
110110
- request:
111-
body: '{"is_active": null, "password": "111111"}'
111+
body: '{"is_active": null, "password": "11111111"}'
112112
headers:
113113
Accept:
114114
- '*/*'

tests/resources/test_user_credentials.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
@pytest.mark.vcr
99
def test_update_password():
10-
UserCredential.create('222222')
11-
UserLogin.create('222222')
12-
UserCredential.update(password='111111')
10+
UserCredential.create('22222222')
11+
UserLogin.create('22222222')
12+
UserCredential.update(password='11111111')
1313

1414

1515
@pytest.mark.vcr

0 commit comments

Comments
 (0)