def test_call_credentials_composition(self): first = grpc.access_token_call_credentials('abc') second = grpc.access_token_call_credentials('def') third = grpc.access_token_call_credentials('ghi') first_and_second = grpc.composite_call_credentials(first, second) first_second_and_third = grpc.composite_call_credentials( first, second, third) self.assertIsInstance(first_and_second, grpc.CallCredentials) self.assertIsInstance(first_second_and_third, grpc.CallCredentials)
async def test_passing_credentials_fails_over_insecure_channel(self): call_credentials = grpc.composite_call_credentials( grpc.access_token_call_credentials("abc"), grpc.access_token_call_credentials("def"), ) with self.assertRaisesRegex( aio.UsageError, "Call credentials are only valid on secure channels"): self._stub.UnaryCall(messages_pb2.SimpleRequest(), credentials=call_credentials)
async def test_call_with_credentials(self): call_credentials = grpc.composite_call_credentials( grpc.access_token_call_credentials("abc"), grpc.access_token_call_credentials("def"), ) call = self._stub.UnaryCall(messages_pb2.SimpleRequest(), credentials=call_credentials) response = await call self.assertIsInstance(response, messages_pb2.SimpleResponse)
async def test_async_generator_secure_channel(self): async def request_generator(): for _ in range(self._STREAM_ITERATIONS): yield _STREAM_OUTPUT_REQUEST_ONE_RESPONSE call_credentials = grpc.composite_call_credentials( grpc.access_token_call_credentials("abc"), grpc.access_token_call_credentials("def"), ) call = self._stub.FullDuplexCall(request_generator(), credentials=call_credentials) async for response in call: self.assertEqual(_RESPONSE_PAYLOAD_SIZE, len(response.payload.body)) self.assertEqual(await call.code(), grpc.StatusCode.OK)
async def test_unary_stream_async_generator_secure(self): request = messages_pb2.StreamingOutputCallRequest() request.response_parameters.extend( messages_pb2.ResponseParameters(size=_RESPONSE_PAYLOAD_SIZE, ) for _ in range(_NUM_STREAM_RESPONSES)) call_credentials = grpc.composite_call_credentials( grpc.access_token_call_credentials("abc"), grpc.access_token_call_credentials("def"), ) call = self._stub.StreamingOutputCall(request, credentials=call_credentials) async for response in call: self.assertIsInstance(response, messages_pb2.StreamingOutputCallResponse) self.assertEqual(len(response.payload.body), _RESPONSE_PAYLOAD_SIZE) self.assertEqual(await call.code(), grpc.StatusCode.OK)