From 5e0be92273868baeba37f39ff7dab5e7b3ccdd54 Mon Sep 17 00:00:00 2001 From: Mariano Cano Date: Tue, 16 Aug 2022 14:04:04 -0700 Subject: [PATCH] Allow option to skip the validation of config --- authority/config/config.go | 3 +++ authority/config/config_test.go | 21 ++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/authority/config/config.go b/authority/config/config.go index 9170bf9e..c5e74b39 100644 --- a/authority/config/config.go +++ b/authority/config/config.go @@ -72,6 +72,7 @@ type Config struct { Password string `json:"password,omitempty"` Templates *templates.Templates `json:"templates,omitempty"` CommonName string `json:"commonName,omitempty"` + SkipValidation bool `json:"-"` } // ASN1DN contains ASN1.DN attributes that are used in Subject and Issuer @@ -201,6 +202,8 @@ func (c *Config) Save(filename string) error { // Validate validates the configuration. func (c *Config) Validate() error { switch { + case c.SkipValidation: + return nil case c.Address == "": return errors.New("address cannot be empty") case len(c.DNSNames) == 0: diff --git a/authority/config/config_test.go b/authority/config/config_test.go index 5a05b3f6..9b5b26aa 100644 --- a/authority/config/config_test.go +++ b/authority/config/config_test.go @@ -35,9 +35,16 @@ func TestConfigValidate(t *testing.T) { type ConfigValidateTest struct { config *Config err error - tls TLSOptions + tls *TLSOptions } tests := map[string]func(*testing.T) ConfigValidateTest{ + "skip-validation": func(t *testing.T) ConfigValidateTest { + return ConfigValidateTest{ + config: &Config{ + SkipValidation: true, + }, + } + }, "empty-address": func(t *testing.T) ConfigValidateTest { return ConfigValidateTest{ config: &Config{ @@ -128,7 +135,7 @@ func TestConfigValidate(t *testing.T) { Password: "pass", AuthorityConfig: ac, }, - tls: DefaultTLSOptions, + tls: &DefaultTLSOptions, } }, "empty-TLS-values": func(t *testing.T) ConfigValidateTest { @@ -143,7 +150,7 @@ func TestConfigValidate(t *testing.T) { AuthorityConfig: ac, TLS: &TLSOptions{}, }, - tls: DefaultTLSOptions, + tls: &DefaultTLSOptions, } }, "custom-tls-values": func(t *testing.T) ConfigValidateTest { @@ -165,7 +172,7 @@ func TestConfigValidate(t *testing.T) { Renegotiation: true, }, }, - tls: TLSOptions{ + tls: &TLSOptions{ CipherSuites: CipherSuites{ "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305", }, @@ -209,9 +216,9 @@ func TestConfigValidate(t *testing.T) { } } else { if assert.Nil(t, tc.err) { - fmt.Printf("tc.tls = %+v\n", tc.tls) - fmt.Printf("*tc.config.TLS = %+v\n", *tc.config.TLS) - assert.Equals(t, *tc.config.TLS, tc.tls) + fmt.Printf("tc.tls = %v\n", tc.tls) + fmt.Printf("*tc.config.TLS = %v\n", tc.config.TLS) + assert.Equals(t, tc.config.TLS, tc.tls) } } })