forked from googleapis/google-api-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enterprise_cert_test.go
48 lines (44 loc) · 1.67 KB
/
enterprise_cert_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2022 Google LLC.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package cert
import (
"errors"
"testing"
)
func TestEnterpriseCertificateProxySource_ConfigMissing(t *testing.T) {
source, err := NewEnterpriseCertificateProxySource("missing.json")
if !errors.Is(err, errSourceUnavailable) {
t.Fatal("NewEnterpriseCertificateProxySource: expected errSourceUnavailable returned when config is missing.")
}
if source != nil {
t.Error("NewEnterpriseCertificateProxySource: expected nil source returned when config is missing.")
}
}
// This test launches a mock signer binary "test_signer.go" that uses a valid pem file.
func TestEnterpriseCertificateProxySource_GetClientCertificateSuccess(t *testing.T) {
source, err := NewEnterpriseCertificateProxySource("testdata/enterprise_certificate_config.json")
if err != nil {
t.Fatal(err)
}
cert, err := source(nil)
if err != nil {
t.Fatal(err)
}
if cert.Certificate == nil {
t.Error("getClientCertificate: want non-nil Certificate, got nil")
}
if cert.PrivateKey == nil {
t.Error("getClientCertificate: want non-nil PrivateKey, got nil")
}
}
// This test launches a mock signer binary "test_signer.go" that uses an invalid pem file.
func TestEnterpriseCertificateProxySource_InitializationFailure(t *testing.T) {
_, err := NewEnterpriseCertificateProxySource("testdata/enterprise_certificate_config_invalid_pem.json")
if err == nil {
t.Fatal("Expecting error.")
}
if got, want := err.Error(), "failed to parse public key: asn1: syntax error: sequence truncated"; got != want {
t.Errorf("NewEnterpriseCertificateProxySource: want err %v, got %v", want, got)
}
}