mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-13 22:51:08 -05:00
caddytls: Fix race condition in tests
This commit is contained in:
parent
8811853f6d
commit
1570bc5d03
1 changed files with 14 additions and 33 deletions
|
@ -47,11 +47,9 @@ func TestMain(m *testing.M) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetupParseBasic(t *testing.T) {
|
func TestSetupParseBasic(t *testing.T) {
|
||||||
cfg, certCache := testConfigForTLSSetup()
|
cfg := &Config{Manager: &certmagic.Config{}}
|
||||||
|
|
||||||
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
||||||
c := caddy.NewTestController("", `tls `+certFile+` `+keyFile+``)
|
c := caddy.NewTestController("", `tls `+certFile+` `+keyFile+``)
|
||||||
c.Set(CertCacheInstStorageKey, certCache)
|
|
||||||
|
|
||||||
err := setupTLS(c)
|
err := setupTLS(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -127,11 +125,10 @@ func TestSetupParseWithOptionalParams(t *testing.T) {
|
||||||
must_staple
|
must_staple
|
||||||
alpn http/1.1
|
alpn http/1.1
|
||||||
}`
|
}`
|
||||||
cfg, certCache := testConfigForTLSSetup()
|
|
||||||
|
|
||||||
|
cfg := &Config{Manager: &certmagic.Config{}}
|
||||||
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
||||||
c := caddy.NewTestController("", params)
|
c := caddy.NewTestController("", params)
|
||||||
c.Set(CertCacheInstStorageKey, certCache)
|
|
||||||
|
|
||||||
err := setupTLS(c)
|
err := setupTLS(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -163,10 +160,9 @@ func TestSetupDefaultWithOptionalParams(t *testing.T) {
|
||||||
params := `tls {
|
params := `tls {
|
||||||
ciphers RSA-3DES-EDE-CBC-SHA
|
ciphers RSA-3DES-EDE-CBC-SHA
|
||||||
}`
|
}`
|
||||||
cfg, certCache := testConfigForTLSSetup()
|
cfg := &Config{Manager: &certmagic.Config{}}
|
||||||
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
||||||
c := caddy.NewTestController("", params)
|
c := caddy.NewTestController("", params)
|
||||||
c.Set(CertCacheInstStorageKey, certCache)
|
|
||||||
|
|
||||||
err := setupTLS(c)
|
err := setupTLS(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -182,10 +178,9 @@ func TestSetupParseWithWrongOptionalParams(t *testing.T) {
|
||||||
params := `tls ` + certFile + ` ` + keyFile + ` {
|
params := `tls ` + certFile + ` ` + keyFile + ` {
|
||||||
protocols ssl tls
|
protocols ssl tls
|
||||||
}`
|
}`
|
||||||
cfg, certCache := testConfigForTLSSetup()
|
cfg := &Config{Manager: &certmagic.Config{}}
|
||||||
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
||||||
c := caddy.NewTestController("", params)
|
c := caddy.NewTestController("", params)
|
||||||
c.Set(CertCacheInstStorageKey, certCache)
|
|
||||||
|
|
||||||
err := setupTLS(c)
|
err := setupTLS(c)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -196,10 +191,9 @@ func TestSetupParseWithWrongOptionalParams(t *testing.T) {
|
||||||
params = `tls ` + certFile + ` ` + keyFile + ` {
|
params = `tls ` + certFile + ` ` + keyFile + ` {
|
||||||
ciphers not-valid-cipher
|
ciphers not-valid-cipher
|
||||||
}`
|
}`
|
||||||
cfg = new(Config)
|
cfg = &Config{Manager: &certmagic.Config{}}
|
||||||
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
||||||
c = caddy.NewTestController("", params)
|
c = caddy.NewTestController("", params)
|
||||||
c.Set(CertCacheInstStorageKey, certCache)
|
|
||||||
err = setupTLS(c)
|
err = setupTLS(c)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("Expected errors, but no error returned")
|
t.Error("Expected errors, but no error returned")
|
||||||
|
@ -209,7 +203,7 @@ func TestSetupParseWithWrongOptionalParams(t *testing.T) {
|
||||||
params = `tls {
|
params = `tls {
|
||||||
key_type ab123
|
key_type ab123
|
||||||
}`
|
}`
|
||||||
cfg = new(Config)
|
cfg = &Config{Manager: &certmagic.Config{}}
|
||||||
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
||||||
c = caddy.NewTestController("", params)
|
c = caddy.NewTestController("", params)
|
||||||
err = setupTLS(c)
|
err = setupTLS(c)
|
||||||
|
@ -221,10 +215,9 @@ func TestSetupParseWithWrongOptionalParams(t *testing.T) {
|
||||||
params = `tls {
|
params = `tls {
|
||||||
curves ab123, cd456, ef789
|
curves ab123, cd456, ef789
|
||||||
}`
|
}`
|
||||||
cfg = new(Config)
|
cfg = &Config{Manager: &certmagic.Config{}}
|
||||||
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
||||||
c = caddy.NewTestController("", params)
|
c = caddy.NewTestController("", params)
|
||||||
c.Set(CertCacheInstStorageKey, certCache)
|
|
||||||
err = setupTLS(c)
|
err = setupTLS(c)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("Expected errors, but no error returned")
|
t.Error("Expected errors, but no error returned")
|
||||||
|
@ -236,7 +229,7 @@ func TestSetupParseWithClientAuth(t *testing.T) {
|
||||||
params := `tls ` + certFile + ` ` + keyFile + ` {
|
params := `tls ` + certFile + ` ` + keyFile + ` {
|
||||||
clients
|
clients
|
||||||
}`
|
}`
|
||||||
cfg, _ := testConfigForTLSSetup()
|
cfg := &Config{Manager: &certmagic.Config{}}
|
||||||
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
||||||
c := caddy.NewTestController("", params)
|
c := caddy.NewTestController("", params)
|
||||||
err := setupTLS(c)
|
err := setupTLS(c)
|
||||||
|
@ -273,7 +266,7 @@ func TestSetupParseWithClientAuth(t *testing.T) {
|
||||||
cfg := &Config{Manager: certmagic.NewWithCache(certCache, certmagic.Config{})}
|
cfg := &Config{Manager: certmagic.NewWithCache(certCache, certmagic.Config{})}
|
||||||
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
||||||
c := caddy.NewTestController("", caseData.params)
|
c := caddy.NewTestController("", caseData.params)
|
||||||
c.Set(CertCacheInstStorageKey, certCache)
|
|
||||||
err := setupTLS(c)
|
err := setupTLS(c)
|
||||||
if caseData.expectedErr {
|
if caseData.expectedErr {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -323,11 +316,10 @@ func TestSetupParseWithCAUrl(t *testing.T) {
|
||||||
ca 1 2
|
ca 1 2
|
||||||
}`, true, ""},
|
}`, true, ""},
|
||||||
} {
|
} {
|
||||||
certCache := certmagic.NewCache(certmagic.DefaultStorage)
|
cfg := &Config{Manager: &certmagic.Config{}}
|
||||||
cfg := &Config{Manager: certmagic.NewWithCache(certCache, certmagic.Config{})}
|
|
||||||
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
||||||
c := caddy.NewTestController("", caseData.params)
|
c := caddy.NewTestController("", caseData.params)
|
||||||
c.Set(CertCacheInstStorageKey, certCache)
|
|
||||||
err := setupTLS(c)
|
err := setupTLS(c)
|
||||||
if caseData.expectedErr {
|
if caseData.expectedErr {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -349,10 +341,9 @@ func TestSetupParseWithKeyType(t *testing.T) {
|
||||||
params := `tls {
|
params := `tls {
|
||||||
key_type p384
|
key_type p384
|
||||||
}`
|
}`
|
||||||
cfg, certCache := testConfigForTLSSetup()
|
cfg := &Config{Manager: &certmagic.Config{}}
|
||||||
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
||||||
c := caddy.NewTestController("", params)
|
c := caddy.NewTestController("", params)
|
||||||
c.Set(CertCacheInstStorageKey, certCache)
|
|
||||||
|
|
||||||
err := setupTLS(c)
|
err := setupTLS(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -368,10 +359,9 @@ func TestSetupParseWithCurves(t *testing.T) {
|
||||||
params := `tls {
|
params := `tls {
|
||||||
curves x25519 p256 p384 p521
|
curves x25519 p256 p384 p521
|
||||||
}`
|
}`
|
||||||
cfg, certCache := testConfigForTLSSetup()
|
cfg := &Config{Manager: &certmagic.Config{}}
|
||||||
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
||||||
c := caddy.NewTestController("", params)
|
c := caddy.NewTestController("", params)
|
||||||
c.Set(CertCacheInstStorageKey, certCache)
|
|
||||||
|
|
||||||
err := setupTLS(c)
|
err := setupTLS(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -396,10 +386,9 @@ func TestSetupParseWithOneTLSProtocol(t *testing.T) {
|
||||||
params := `tls {
|
params := `tls {
|
||||||
protocols tls1.2
|
protocols tls1.2
|
||||||
}`
|
}`
|
||||||
cfg, certCache := testConfigForTLSSetup()
|
cfg := &Config{Manager: &certmagic.Config{}}
|
||||||
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
|
||||||
c := caddy.NewTestController("", params)
|
c := caddy.NewTestController("", params)
|
||||||
c.Set(CertCacheInstStorageKey, certCache)
|
|
||||||
|
|
||||||
err := setupTLS(c)
|
err := setupTLS(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -415,14 +404,6 @@ func TestSetupParseWithOneTLSProtocol(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testConfigForTLSSetup() (*Config, *certmagic.Cache) {
|
|
||||||
certCache := certmagic.NewCache(nil)
|
|
||||||
certCache.Stop()
|
|
||||||
return &Config{
|
|
||||||
Manager: certmagic.NewWithCache(certCache, certmagic.Config{}),
|
|
||||||
}, certCache
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
certFile = "test_cert.pem"
|
certFile = "test_cert.pem"
|
||||||
keyFile = "test_key.pem"
|
keyFile = "test_key.pem"
|
||||||
|
|
Loading…
Reference in a new issue