mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-13 05:35:18 +01:00
refactor(docker): update TLS config validation to require both CertFile and KeyFile exists or both empty
This commit is contained in:
@@ -27,8 +27,8 @@ type DockerProviderConfigDetailed struct {
|
||||
|
||||
type DockerTLSConfig struct {
|
||||
CAFile string `json:"ca_file,omitempty" validate:"required"`
|
||||
CertFile string `json:"cert_file,omitempty" validate:"required"`
|
||||
KeyFile string `json:"key_file,omitempty" validate:"required"`
|
||||
CertFile string `json:"cert_file,omitempty" validate:"required_with=KeyFile"`
|
||||
KeyFile string `json:"key_file,omitempty" validate:"required_with=CertFile"`
|
||||
} // @name DockerTLSConfig
|
||||
|
||||
func (cfg *DockerProviderConfig) MarshalJSON() ([]byte, error) {
|
||||
|
||||
@@ -98,13 +98,29 @@ func TestDockerProviderConfigValidation(t *testing.T) {
|
||||
cert_file: /etc/ssl/cert.crt
|
||||
key_file: /etc/ssl/key.crt
|
||||
`, wantErr: false},
|
||||
{name: "invalid tls (missing cert file and key file)", yamlStr: `
|
||||
{name: "valid tls (only ca file)", yamlStr: `
|
||||
test:
|
||||
scheme: tls
|
||||
host: localhost
|
||||
port: 2375
|
||||
tls:
|
||||
ca_file: /etc/ssl/ca.crt
|
||||
`, wantErr: false},
|
||||
{name: "invalid tls (missing cert file)", yamlStr: `
|
||||
test:
|
||||
scheme: tls
|
||||
host: localhost
|
||||
port: 2375
|
||||
tls:
|
||||
key_file: /etc/ssl/key.crt
|
||||
`, wantErr: true},
|
||||
{name: "invalid tls (missing key file)", yamlStr: `
|
||||
test:
|
||||
scheme: tls
|
||||
host: localhost
|
||||
port: 2375
|
||||
tls:
|
||||
cert_file: /etc/ssl/cert.crt
|
||||
`, wantErr: true},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user