_credentials_test.py
Go to the documentation of this file.
1 # Copyright 2016 gRPC authors.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """Tests of credentials."""
15 
16 import logging
17 import unittest
18 
19 import grpc
20 import six
21 
22 
23 class CredentialsTest(unittest.TestCase):
24 
29 
30  first_and_second = grpc.composite_call_credentials(first, second)
31  first_second_and_third = grpc.composite_call_credentials(
32  first, second, third)
33 
34  self.assertIsInstance(first_and_second, grpc.CallCredentials)
35  self.assertIsInstance(first_second_and_third, grpc.CallCredentials)
36 
38  first_call_credentials = grpc.access_token_call_credentials('abc')
39  second_call_credentials = grpc.access_token_call_credentials('def')
40  third_call_credentials = grpc.access_token_call_credentials('ghi')
41  channel_credentials = grpc.ssl_channel_credentials()
42 
43  channel_and_first = grpc.composite_channel_credentials(
44  channel_credentials, first_call_credentials)
45  channel_first_and_second = grpc.composite_channel_credentials(
46  channel_credentials, first_call_credentials,
47  second_call_credentials)
48  channel_first_second_and_third = grpc.composite_channel_credentials(
49  channel_credentials, first_call_credentials,
50  second_call_credentials, third_call_credentials)
51 
52  self.assertIsInstance(channel_and_first, grpc.ChannelCredentials)
53  self.assertIsInstance(channel_first_and_second, grpc.ChannelCredentials)
54  self.assertIsInstance(channel_first_second_and_third,
56 
57  @unittest.skipIf(six.PY2, 'only invalid in Python3')
59  self.assertRaises(
60  TypeError,
61  grpc.ssl_channel_credentials,
62  root_certificates='A Certificate',
63  private_key=None,
64  certificate_chain=None,
65  )
66 
67 
68 if __name__ == '__main__':
69  logging.basicConfig()
70  unittest.main(verbosity=2)
grpc.composite_call_credentials
def composite_call_credentials(*call_credentials)
Definition: src/python/grpcio/grpc/__init__.py:1676
grpc::ChannelCredentials
Definition: include/grpcpp/security/credentials.h:75
grpc.composite_channel_credentials
def composite_channel_credentials(channel_credentials, *call_credentials)
Definition: src/python/grpcio/grpc/__init__.py:1691
tests.unit._credentials_test.CredentialsTest.test_call_credentials_composition
def test_call_credentials_composition(self)
Definition: _credentials_test.py:25
tests.unit._credentials_test.CredentialsTest.test_channel_credentials_composition
def test_channel_credentials_composition(self)
Definition: _credentials_test.py:37
tests.unit._credentials_test.CredentialsTest
Definition: _credentials_test.py:23
tests.unit._credentials_test.CredentialsTest.test_invalid_string_certificate
def test_invalid_string_certificate(self)
Definition: _credentials_test.py:58
grpc.ssl_channel_credentials
def ssl_channel_credentials(root_certificates=None, private_key=None, certificate_chain=None)
Definition: src/python/grpcio/grpc/__init__.py:1607
grpc.access_token_call_credentials
def access_token_call_credentials(access_token)
Definition: src/python/grpcio/grpc/__init__.py:1659
grpc::CallCredentials
Definition: include/grpcpp/security/credentials.h:132


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:27