Skip to content

Commit 50cf2dd

Browse files
committed
fix update jwt optional param default value
add test
1 parent e56d018 commit 50cf2dd

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

descope/management/jwt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class JWT(AuthBase):
1515
def update_jwt(
16-
self, jwt: str, custom_claims: dict, refresh_duration: Optional[int]
16+
self, jwt: str, custom_claims: dict, refresh_duration: Optional[int] = 0
1717
) -> str:
1818
"""
1919
Given a valid JWT, update it with custom claims, and update its authz claims as well

tests/management/test_jwt.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,31 @@ def test_update_jwt(self):
6969
timeout=DEFAULT_TIMEOUT_SECONDS,
7070
)
7171

72+
with patch("requests.post") as mock_post:
73+
network_resp = mock.Mock()
74+
network_resp.ok = True
75+
network_resp.json.return_value = json.loads("""{"jwt": "response"}""")
76+
mock_post.return_value = network_resp
77+
resp = client.mgmt.jwt.update_jwt("test", {"k1": "v1"})
78+
self.assertEqual(resp, "response")
79+
expected_uri = f"{common.DEFAULT_BASE_URL}{MgmtV1.update_jwt_path}"
80+
mock_post.assert_called_with(
81+
expected_uri,
82+
headers={
83+
**common.default_headers,
84+
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
85+
},
86+
json={
87+
"jwt": "test",
88+
"customClaims": {"k1": "v1"},
89+
"refreshDuration": 0,
90+
},
91+
allow_redirects=False,
92+
verify=True,
93+
params=None,
94+
timeout=DEFAULT_TIMEOUT_SECONDS,
95+
)
96+
7297
def test_impersonate(self):
7398
client = DescopeClient(
7499
self.dummy_project_id,

0 commit comments

Comments
 (0)