OLD | NEW |
(Empty) | |
| 1 # Copyright 2015, Google Inc. |
| 2 # All rights reserved. |
| 3 # |
| 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are |
| 6 # met: |
| 7 # |
| 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above |
| 11 # copyright notice, this list of conditions and the following disclaimer |
| 12 # in the documentation and/or other materials provided with the |
| 13 # distribution. |
| 14 # * Neither the name of Google Inc. nor the names of its |
| 15 # contributors may be used to endorse or promote products derived from |
| 16 # this software without specific prior written permission. |
| 17 # |
| 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 |
| 30 require 'grpc' |
| 31 |
| 32 def load_test_certs |
| 33 test_root = File.join(File.dirname(__FILE__), 'testdata') |
| 34 files = ['ca.pem', 'server1.key', 'server1.pem'] |
| 35 contents = files.map { |f| File.open(File.join(test_root, f)).read } |
| 36 [contents[0], [{ private_key: contents[1], cert_chain: contents[2] }], false] |
| 37 end |
| 38 |
| 39 describe GRPC::Core::ServerCredentials do |
| 40 Creds = GRPC::Core::ServerCredentials |
| 41 |
| 42 describe '#new' do |
| 43 it 'can be constructed from a fake CA PEM, server PEM and a server key' do |
| 44 creds = Creds.new('a', [{ private_key: 'a', cert_chain: 'b' }], false) |
| 45 expect(creds).to_not be_nil |
| 46 end |
| 47 |
| 48 it 'can be constructed using the test certificates' do |
| 49 certs = load_test_certs |
| 50 expect { Creds.new(*certs) }.not_to raise_error |
| 51 end |
| 52 |
| 53 it 'cannot be constructed without a nil key_cert pair array' do |
| 54 root_cert, _, _ = load_test_certs |
| 55 blk = proc do |
| 56 Creds.new(root_cert, nil, false) |
| 57 end |
| 58 expect(&blk).to raise_error |
| 59 end |
| 60 |
| 61 it 'cannot be constructed without any key_cert pairs' do |
| 62 root_cert, _, _ = load_test_certs |
| 63 blk = proc do |
| 64 Creds.new(root_cert, [], false) |
| 65 end |
| 66 expect(&blk).to raise_error |
| 67 end |
| 68 |
| 69 it 'cannot be constructed without a server cert chain' do |
| 70 root_cert, server_key, _ = load_test_certs |
| 71 blk = proc do |
| 72 Creds.new(root_cert, |
| 73 [{ server_key: server_key, cert_chain: nil }], |
| 74 false) |
| 75 end |
| 76 expect(&blk).to raise_error |
| 77 end |
| 78 |
| 79 it 'cannot be constructed without a server key' do |
| 80 root_cert, _, _ = load_test_certs |
| 81 blk = proc do |
| 82 Creds.new(root_cert, |
| 83 [{ server_key: nil, cert_chain: cert_chain }]) |
| 84 end |
| 85 expect(&blk).to raise_error |
| 86 end |
| 87 |
| 88 it 'can be constructed without a root_cret' do |
| 89 _, cert_pairs, _ = load_test_certs |
| 90 blk = proc { Creds.new(nil, cert_pairs, false) } |
| 91 expect(&blk).to_not raise_error |
| 92 end |
| 93 end |
| 94 end |
OLD | NEW |