Skip to content

Commit

Permalink
add two tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy Krach <jkrach@pinterest.com>
  • Loading branch information
krockpot committed Jan 10, 2019
1 parent c636b38 commit 9fceab8
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions utils/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import (
const envPrefix = "NOTARY_TESTING_ENV_PREFIX"

const (
Cert = "../fixtures/notary-server.crt"
Key = "../fixtures/notary-server.key"
Root = "../fixtures/root-ca.crt"
Cert = "../fixtures/notary-server.crt"
Key = "../fixtures/notary-server.key"
Root = "../fixtures/root-ca.crt"
NoCert = "../fixtures/nonexistant.crt"
NoKey = "../fixtures/nonexistant.key"
)

// initializes a viper object with test configuration
Expand Down Expand Up @@ -417,6 +419,38 @@ func TestParseTLSWithTLS(t *testing.T) {
require.Equal(t, tlsConfig.ClientAuth, tls.RequireAndVerifyClientCert)
}

// Verifies that the GetCertificate function on the TLS Config object gives us what we expect
func TestTLSGetCertificate(t *testing.T) {
config := configure(fmt.Sprintf(`{
"server": {
"tls_cert_file": "%s",
"tls_key_file": "%s",
"client_ca_file": "%s"
}
}`, Cert, Key, Root))

tlsConfig, err := ParseServerTLS(config, false)
require.NoError(t, err)

certificate, err := tlsConfig.GetCertificate(nil)
require.NoError(t, err)

require.Equal(t, tlsConfig.Certificates[0], *certificate)
}

// Checks the helper function that reloads the certificate with some bad cases (File DNE, mismatched key/cert)
func TestLoadCertificateFailures(t *testing.T) {
// Cert DNE
_, err := loadCertificate(NoCert, Key)
require.Error(t, err)
// Key DNE
_, err = loadCertificate(Cert, NoKey)
require.Error(t, err)
// Mismatched
_, err = loadCertificate(Cert, Cert)
require.Error(t, err)
}

func TestParseTLSWithTLSRelativeToConfigFile(t *testing.T) {
currDir, err := os.Getwd()
require.NoError(t, err)
Expand Down

0 comments on commit 9fceab8

Please sign in to comment.