Skip to content

Commit d036843

Browse files
committed
Style
1 parent 5b5cfe6 commit d036843

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

tests/aio/test_credentials.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
class TestServiceAccountCredentials(ydb.aio.iam.ServiceAccountCredentials):
1111
def _channel_factory(self):
12-
return grpc.aio.insecure_channel(
13-
self._iam_endpoint
14-
)
12+
return grpc.aio.insecure_channel(self._iam_endpoint)
1513

1614
def get_expire_time(self):
1715
return self._expires_in - time.time()
@@ -25,7 +23,12 @@ def get_expire_time(self):
2523
@pytest.mark.asyncio
2624
async def test_yandex_service_account_credentials():
2725
server = tests.auth.test_credentials.IamTokenServiceTestServer()
28-
credentials = TestServiceAccountCredentials(tests.auth.test_credentials.SERVICE_ACCOUNT_ID, tests.auth.test_credentials.ACCESS_KEY_ID, tests.auth.test_credentials.PRIVATE_KEY, server.get_endpoint())
26+
credentials = TestServiceAccountCredentials(
27+
tests.auth.test_credentials.SERVICE_ACCOUNT_ID,
28+
tests.auth.test_credentials.ACCESS_KEY_ID,
29+
tests.auth.test_credentials.PRIVATE_KEY,
30+
server.get_endpoint(),
31+
)
2932
t = (await credentials.auth_metadata())[0][1]
3033
assert t == "test_token"
3134
assert credentials.get_expire_time() <= 42
@@ -42,7 +45,12 @@ def serve(s):
4245
serve_thread = threading.Thread(target=serve, args=(server,))
4346
serve_thread.start()
4447

45-
credentials = TestNebiusServiceAccountCredentials(tests.auth.test_credentials.SERVICE_ACCOUNT_ID, tests.auth.test_credentials.ACCESS_KEY_ID, tests.auth.test_credentials.PRIVATE_KEY, server.endpoint())
48+
credentials = TestNebiusServiceAccountCredentials(
49+
tests.auth.test_credentials.SERVICE_ACCOUNT_ID,
50+
tests.auth.test_credentials.ACCESS_KEY_ID,
51+
tests.auth.test_credentials.PRIVATE_KEY,
52+
server.endpoint(),
53+
)
4654
t = (await credentials.auth_metadata())[0][1]
4755
assert t == "test_nebius_token"
4856
assert credentials.get_expire_time() <= 42

tests/auth/test_credentials.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class IamTokenServiceForTest(iam_token_service_pb2_grpc.IamTokenServiceServicer)
3333
def Create(self, request, context):
3434
print("IAM token service request: {}".format(request))
3535
# Validate jwt:
36-
decoded = jwt.decode(request.jwt, key=PUBLIC_KEY, algorithms=["PS256"], audience="https://iam.api.cloud.yandex.net/iam/v1/tokens")
36+
decoded = jwt.decode(
37+
request.jwt, key=PUBLIC_KEY, algorithms=["PS256"], audience="https://iam.api.cloud.yandex.net/iam/v1/tokens"
38+
)
3739
assert decoded["iss"] == SERVICE_ACCOUNT_ID
3840
assert decoded["aud"] == "https://iam.api.cloud.yandex.net/iam/v1/tokens"
3941
assert abs(decoded["iat"] - time.time()) <= 60
@@ -61,9 +63,7 @@ def get_endpoint(self):
6163

6264
class TestServiceAccountCredentials(ydb.iam.ServiceAccountCredentials):
6365
def _channel_factory(self):
64-
return grpc.insecure_channel(
65-
self._iam_endpoint
66-
)
66+
return grpc.insecure_channel(self._iam_endpoint)
6767

6868
def get_expire_time(self):
6969
return self._expires_in - time.time()
@@ -93,7 +93,9 @@ def do_POST(self):
9393

9494
assert len(parsed_request["subject_token"]) == 1
9595
jwt_token = parsed_request["subject_token"][0]
96-
decoded = jwt.decode(jwt_token, key=PUBLIC_KEY, algorithms=["RS256"], audience="token-service.iam.new.nebiuscloud.net")
96+
decoded = jwt.decode(
97+
jwt_token, key=PUBLIC_KEY, algorithms=["RS256"], audience="token-service.iam.new.nebiuscloud.net"
98+
)
9799
assert decoded["iss"] == SERVICE_ACCOUNT_ID
98100
assert decoded["sub"] == SERVICE_ACCOUNT_ID
99101
assert decoded["aud"] == "token-service.iam.new.nebiuscloud.net"
@@ -104,7 +106,7 @@ def do_POST(self):
104106
"access_token": "test_nebius_token",
105107
"issued_token_type": "urn:ietf:params:oauth:token-type:access_token",
106108
"token_type": "Bearer",
107-
"expires_in": 42
109+
"expires_in": 42,
108110
}
109111

110112
self.send_response(200)

0 commit comments

Comments
 (0)