• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16import unittest
17
18import grpc
19
20
21class CredentialsTest(unittest.TestCase):
22
23    def test_call_credentials_composition(self):
24        first = grpc.access_token_call_credentials('abc')
25        second = grpc.access_token_call_credentials('def')
26        third = grpc.access_token_call_credentials('ghi')
27
28        first_and_second = grpc.composite_call_credentials(first, second)
29        first_second_and_third = grpc.composite_call_credentials(
30            first, second, third)
31
32        self.assertIsInstance(first_and_second, grpc.CallCredentials)
33        self.assertIsInstance(first_second_and_third, grpc.CallCredentials)
34
35    def test_channel_credentials_composition(self):
36        first_call_credentials = grpc.access_token_call_credentials('abc')
37        second_call_credentials = grpc.access_token_call_credentials('def')
38        third_call_credentials = grpc.access_token_call_credentials('ghi')
39        channel_credentials = grpc.ssl_channel_credentials()
40
41        channel_and_first = grpc.composite_channel_credentials(
42            channel_credentials, first_call_credentials)
43        channel_first_and_second = grpc.composite_channel_credentials(
44            channel_credentials, first_call_credentials,
45            second_call_credentials)
46        channel_first_second_and_third = grpc.composite_channel_credentials(
47            channel_credentials, first_call_credentials,
48            second_call_credentials, third_call_credentials)
49
50        self.assertIsInstance(channel_and_first, grpc.ChannelCredentials)
51        self.assertIsInstance(channel_first_and_second, grpc.ChannelCredentials)
52        self.assertIsInstance(channel_first_second_and_third,
53                              grpc.ChannelCredentials)
54
55
56if __name__ == '__main__':
57    unittest.main(verbosity=2)
58