Debian Codegraph @

src/python/grpcio_tests/tests/unit/_credentials_test.py

raw
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
21
22 class CredentialsTest(unittest.TestCase):
23
24 def test_call_credentials_composition(self):
25 first = grpc.access_token_call_credentials('abc')
26 second = grpc.access_token_call_credentials('def')
27 third = grpc.access_token_call_credentials('ghi')
28
29 first_and_second = grpc.composite_call_credentials(first, second)
30 first_second_and_third = grpc.composite_call_credentials(
31 first, second, third)
32
33 self.assertIsInstance(first_and_second, grpc.CallCredentials)
34 self.assertIsInstance(first_second_and_third, grpc.CallCredentials)
35
36 def test_channel_credentials_composition(self):
37 first_call_credentials = grpc.access_token_call_credentials('abc')
38 second_call_credentials = grpc.access_token_call_credentials('def')
39 third_call_credentials = grpc.access_token_call_credentials('ghi')
40 channel_credentials = grpc.ssl_channel_credentials()
41
42 channel_and_first = grpc.composite_channel_credentials(
43 channel_credentials, first_call_credentials)
44 channel_first_and_second = grpc.composite_channel_credentials(
45 channel_credentials, first_call_credentials,
46 second_call_credentials)
47 channel_first_second_and_third = grpc.composite_channel_credentials(
48 channel_credentials, first_call_credentials,
49 second_call_credentials, third_call_credentials)
50
51 self.assertIsInstance(channel_and_first, grpc.ChannelCredentials)
52 self.assertIsInstance(channel_first_and_second, grpc.ChannelCredentials)
53 self.assertIsInstance(channel_first_second_and_third,
54 grpc.ChannelCredentials)
55
56 def test_invalid_string_certificate(self):
57 self.assertRaises(
58 TypeError,
59 grpc.ssl_channel_credentials,
60 root_certificates='A Certificate',
61 private_key=None,
62 certificate_chain=None,
63 )
64
65
66 if __name__ == '__main__':
67 logging.basicConfig()
68 unittest.main(verbosity=2)