Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
1570bc5d
Commit
1570bc5d
authored
Dec 13, 2018
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
caddytls: Fix race condition in tests
parent
8811853f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
33 deletions
+14
-33
caddytls/setup_test.go
caddytls/setup_test.go
+14
-33
No files found.
caddytls/setup_test.go
View file @
1570bc5d
...
@@ -47,11 +47,9 @@ func TestMain(m *testing.M) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment