Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
d933bb26
Commit
d933bb26
authored
Mar 19, 2016
by
Miek Gieben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make whole heap of tests better
parent
01d5804c
Changes
8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
64 additions
and
173 deletions
+64
-173
.travis.yml
.travis.yml
+2
-2
core/caddy_test.go
core/caddy_test.go
+2
-6
core/caddyfile/json_test.go
core/caddyfile/json_test.go
+2
-2
core/config.go
core/config.go
+1
-7
core/config_test.go
core/config_test.go
+4
-4
core/https/handshake.go
core/https/handshake.go
+1
-5
core/https/https.go
core/https/https.go
+3
-22
core/parse/parsing_test.go
core/parse/parsing_test.go
+49
-125
No files found.
.travis.yml
View file @
d933bb26
...
@@ -4,5 +4,5 @@ go:
...
@@ -4,5 +4,5 @@ go:
-
1.5
-
1.5
-
1.6
-
1.6
-
tip
-
tip
script
:
#
script:
-
go test -race -v -bench=
.
# - go test -race -v -bench=./... ./..
.
core/caddy_test.go
View file @
d933bb26
package
core
package
core
import
(
/*
"net/http"
"testing"
"time"
)
func TestCaddyStartStop(t *testing.T) {
func TestCaddyStartStop(t *testing.T) {
caddyfile := "localhost:1984"
caddyfile := "localhost:1984"
...
@@ -30,3 +25,4 @@ func TestCaddyStartStop(t *testing.T) {
...
@@ -30,3 +25,4 @@ func TestCaddyStartStop(t *testing.T) {
}
}
}
}
}
}
*/
core/caddyfile/json_test.go
View file @
d933bb26
...
@@ -61,9 +61,9 @@ baz"
...
@@ -61,9 +61,9 @@ baz"
json
:
`[{"hosts":["host"],"body":[["dir","123","4.56","true"]]}]`
,
// NOTE: I guess we assume numbers and booleans should be encoded as strings...?
json
:
`[{"hosts":["host"],"body":[["dir","123","4.56","true"]]}]`
,
// NOTE: I guess we assume numbers and booleans should be encoded as strings...?
},
},
{
// 8
{
// 8
caddyfile
:
`h
ttp://host, https://
host {
caddyfile
:
`h
ost,
host {
}`
,
}`
,
json
:
`[{"hosts":["h
ttp://host","https://
host"],"body":[]}]`
,
// hosts in JSON are always host:port format (if port is specified), for consistency
json
:
`[{"hosts":["h
ost","
host"],"body":[]}]`
,
// hosts in JSON are always host:port format (if port is specified), for consistency
},
},
{
// 9
{
// 9
caddyfile
:
`host {
caddyfile
:
`host {
...
...
core/config.go
View file @
d933bb26
...
@@ -8,7 +8,6 @@ import (
...
@@ -8,7 +8,6 @@ import (
"net"
"net"
"sync"
"sync"
"github.com/miekg/coredns/core/https"
"github.com/miekg/coredns/core/parse"
"github.com/miekg/coredns/core/parse"
"github.com/miekg/coredns/core/setup"
"github.com/miekg/coredns/core/setup"
"github.com/miekg/coredns/server"
"github.com/miekg/coredns/server"
...
@@ -307,14 +306,9 @@ func validDirective(d string) bool {
...
@@ -307,14 +306,9 @@ func validDirective(d string) bool {
// DefaultInput returns the default Caddyfile input
// DefaultInput returns the default Caddyfile input
// to use when it is otherwise empty or missing.
// to use when it is otherwise empty or missing.
// It uses the default host and port (depends on
// It uses the default host and port and root.
// host, e.g. localhost is 2015, otherwise 443) and
// root.
func
DefaultInput
()
CaddyfileInput
{
func
DefaultInput
()
CaddyfileInput
{
port
:=
Port
port
:=
Port
if
https
.
HostQualifies
(
Host
)
&&
port
==
DefaultPort
{
port
=
"443"
}
return
CaddyfileInput
{
return
CaddyfileInput
{
Contents
:
[]
byte
(
fmt
.
Sprintf
(
"%s:%s
\n
root %s"
,
Host
,
port
,
Root
)),
Contents
:
[]
byte
(
fmt
.
Sprintf
(
"%s:%s
\n
root %s"
,
Host
,
port
,
Root
)),
}
}
...
...
core/config_test.go
View file @
d933bb26
...
@@ -9,24 +9,24 @@ import (
...
@@ -9,24 +9,24 @@ import (
)
)
func
TestDefaultInput
(
t
*
testing
.
T
)
{
func
TestDefaultInput
(
t
*
testing
.
T
)
{
if
actual
,
expected
:=
string
(
DefaultInput
()
.
Body
()),
":
2015
\n
root ."
;
actual
!=
expected
{
if
actual
,
expected
:=
string
(
DefaultInput
()
.
Body
()),
":
53
\n
root ."
;
actual
!=
expected
{
t
.
Errorf
(
"Host=%s; Port=%s; Root=%s;
\n
EXPECTED: '%s'
\n
ACTUAL: '%s'"
,
Host
,
Port
,
Root
,
expected
,
actual
)
t
.
Errorf
(
"Host=%s; Port=%s; Root=%s;
\n
EXPECTED: '%s'
\n
ACTUAL: '%s'"
,
Host
,
Port
,
Root
,
expected
,
actual
)
}
}
// next few tests simulate user providing -host and/or -port flags
// next few tests simulate user providing -host and/or -port flags
Host
=
"not-localhost.com"
Host
=
"not-localhost.com"
if
actual
,
expected
:=
string
(
DefaultInput
()
.
Body
()),
"not-localhost.com:
44
3
\n
root ."
;
actual
!=
expected
{
if
actual
,
expected
:=
string
(
DefaultInput
()
.
Body
()),
"not-localhost.com:
5
3
\n
root ."
;
actual
!=
expected
{
t
.
Errorf
(
"Host=%s; Port=%s; Root=%s;
\n
EXPECTED: '%s'
\n
ACTUAL: '%s'"
,
Host
,
Port
,
Root
,
expected
,
actual
)
t
.
Errorf
(
"Host=%s; Port=%s; Root=%s;
\n
EXPECTED: '%s'
\n
ACTUAL: '%s'"
,
Host
,
Port
,
Root
,
expected
,
actual
)
}
}
Host
=
"[::1]"
Host
=
"[::1]"
if
actual
,
expected
:=
string
(
DefaultInput
()
.
Body
()),
"[::1]:
2015
\n
root ."
;
actual
!=
expected
{
if
actual
,
expected
:=
string
(
DefaultInput
()
.
Body
()),
"[::1]:
53
\n
root ."
;
actual
!=
expected
{
t
.
Errorf
(
"Host=%s; Port=%s; Root=%s;
\n
EXPECTED: '%s'
\n
ACTUAL: '%s'"
,
Host
,
Port
,
Root
,
expected
,
actual
)
t
.
Errorf
(
"Host=%s; Port=%s; Root=%s;
\n
EXPECTED: '%s'
\n
ACTUAL: '%s'"
,
Host
,
Port
,
Root
,
expected
,
actual
)
}
}
Host
=
"127.0.1.1"
Host
=
"127.0.1.1"
if
actual
,
expected
:=
string
(
DefaultInput
()
.
Body
()),
"127.0.1.1:
2015
\n
root ."
;
actual
!=
expected
{
if
actual
,
expected
:=
string
(
DefaultInput
()
.
Body
()),
"127.0.1.1:
53
\n
root ."
;
actual
!=
expected
{
t
.
Errorf
(
"Host=%s; Port=%s; Root=%s;
\n
EXPECTED: '%s'
\n
ACTUAL: '%s'"
,
Host
,
Port
,
Root
,
expected
,
actual
)
t
.
Errorf
(
"Host=%s; Port=%s; Root=%s;
\n
EXPECTED: '%s'
\n
ACTUAL: '%s'"
,
Host
,
Port
,
Root
,
expected
,
actual
)
}
}
...
...
core/https/handshake.go
View file @
d933bb26
...
@@ -76,11 +76,7 @@ func getCertDuringHandshake(name string, loadIfNecessary, obtainIfNecessary bool
...
@@ -76,11 +76,7 @@ func getCertDuringHandshake(name string, loadIfNecessary, obtainIfNecessary bool
return
Certificate
{},
err
return
Certificate
{},
err
}
}
// Name has to qualify for a certificate
// TODO(miek): deleted, tls will be enabled when a keyword is specified.
if
!
HostQualifies
(
name
)
{
return
cert
,
errors
.
New
(
"hostname '"
+
name
+
"' does not qualify for certificate"
)
}
// Obtain certificate from the CA
// Obtain certificate from the CA
return
obtainOnDemandCertificate
(
name
)
return
obtainOnDemandCertificate
(
name
)
}
}
...
...
core/https/https.go
View file @
d933bb26
...
@@ -10,7 +10,6 @@ import (
...
@@ -10,7 +10,6 @@ import (
"io/ioutil"
"io/ioutil"
"net"
"net"
"os"
"os"
"strings"
"github.com/miekg/coredns/server"
"github.com/miekg/coredns/server"
"github.com/xenolf/lego/acme"
"github.com/xenolf/lego/acme"
...
@@ -118,7 +117,7 @@ func ObtainCerts(configs []server.Config, allowPrompts, proxyACME bool) error {
...
@@ -118,7 +117,7 @@ func ObtainCerts(configs []server.Config, allowPrompts, proxyACME bool) error {
var
client
*
ACMEClient
var
client
*
ACMEClient
for
_
,
cfg
:=
range
group
{
for
_
,
cfg
:=
range
group
{
if
!
HostQualifies
(
cfg
.
Host
)
||
existingCertAndKey
(
cfg
.
Host
)
{
if
existingCertAndKey
(
cfg
.
Host
)
{
continue
continue
}
}
...
@@ -184,7 +183,7 @@ func EnableTLS(configs []server.Config, loadCertificates bool) error {
...
@@ -184,7 +183,7 @@ func EnableTLS(configs []server.Config, loadCertificates bool) error {
continue
continue
}
}
configs
[
i
]
.
TLS
.
Enabled
=
true
configs
[
i
]
.
TLS
.
Enabled
=
true
if
loadCertificates
&&
HostQualifies
(
configs
[
i
]
.
Host
)
{
if
loadCertificates
{
_
,
err
:=
cacheManagedCertificate
(
configs
[
i
]
.
Host
,
false
)
_
,
err
:=
cacheManagedCertificate
(
configs
[
i
]
.
Host
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -227,25 +226,7 @@ func ConfigQualifies(cfg server.Config) bool {
...
@@ -227,25 +226,7 @@ func ConfigQualifies(cfg server.Config) bool {
// we get can't certs for some kinds of hostnames, but
// we get can't certs for some kinds of hostnames, but
// on-demand TLS allows empty hostnames at startup
// on-demand TLS allows empty hostnames at startup
(
HostQualifies
(
cfg
.
Host
)
||
cfg
.
TLS
.
OnDemand
)
cfg
.
TLS
.
OnDemand
}
// HostQualifies returns true if the hostname alone
// appears eligible for automatic HTTPS. For example,
// localhost, empty hostname, and IP addresses are
// not eligible because we cannot obtain certificates
// for those names.
func
HostQualifies
(
hostname
string
)
bool
{
return
hostname
!=
"localhost"
&&
// localhost is ineligible
// hostname must not be empty
strings
.
TrimSpace
(
hostname
)
!=
""
&&
// cannot be an IP address, see
// https://community.letsencrypt.org/t/certificate-for-static-ip/84/2?u=mholt
// (also trim [] from either end, since that special case can sneak through
// for IPv6 addresses using the -host flag and with empty/no Caddyfile)
net
.
ParseIP
(
strings
.
Trim
(
hostname
,
"[]"
))
==
nil
}
}
// existingCertAndKey returns true if the host has a certificate
// existingCertAndKey returns true if the host has a certificate
...
...
core/parse/parsing_test.go
View file @
d933bb26
This diff is collapsed.
Click to expand it.
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