Allow option to skip the validation of config

This commit is contained in:
Mariano Cano 2022-08-16 14:04:04 -07:00
parent ae76d943c9
commit 5e0be92273
2 changed files with 17 additions and 7 deletions

View file

@ -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:

View file

@ -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)
}
}
})