| 1 |
// Copyright 2023 Google LLC |
| 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 |
|
| 15 |
package cert |
| 16 |
|
| 17 |
import ( |
| 18 |
"errors" |
| 19 |
"testing" |
| 20 |
) |
| 21 |
|
| 22 |
func TestEnterpriseCertificateProxySource_ConfigMissing(t *testing.T) { |
| 23 |
source, err := NewEnterpriseCertificateProxyProvider("missing.json") |
| 24 |
if got, want := err, errSourceUnavailable; !errors.Is(err, errSourceUnavailable) { |
| 25 |
t.Fatalf("got %v, want %v err", got, want) |
| 26 |
} |
| 27 |
if source != nil { |
| 28 |
t.Errorf("got %v, want nil source", source) |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
// This test launches a mock signer binary "test_signer.go" that uses a valid pem file. |
| 33 |
func TestEnterpriseCertificateProxySource_GetClientCertificateSuccess(t *testing.T) { |
| 34 |
source, err := NewEnterpriseCertificateProxyProvider("testdata/certificate_config.json") |
| 35 |
if err != nil { |
| 36 |
t.Fatal(err) |
| 37 |
} |
| 38 |
cert, err := source(nil) |
| 39 |
if err != nil { |
| 40 |
t.Fatal(err) |
| 41 |
} |
| 42 |
if cert.Certificate == nil { |
| 43 |
t.Fatal("got nil, want non-nil Certificate") |
| 44 |
} |
| 45 |
if cert.PrivateKey == nil { |
| 46 |
t.Fatal("got nil, want non-nil PrivateKey") |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
// This test launches a mock signer binary "test_signer.go" that uses an invalid pem file. |
| 51 |
func TestEnterpriseCertificateProxySource_InitializationFailure(t *testing.T) { |
| 52 |
_, err := NewEnterpriseCertificateProxyProvider("testdata/certificate_config_invalid_pem.json") |
| 53 |
if err == nil { |
| 54 |
t.Fatal("got nil, want non-nil err") |
| 55 |
} |
| 56 |
} |