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
f03ad807
Commit
f03ad807
authored
Dec 10, 2018
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update tests after large refactor
parent
a68b0108
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
58 deletions
+29
-58
caddy_test.go
caddy_test.go
+0
-38
caddyhttp/caddyhttp_test.go
caddyhttp/caddyhttp_test.go
+1
-1
caddyhttp/httpserver/https.go
caddyhttp/httpserver/https.go
+2
-1
caddyhttp/httpserver/https_test.go
caddyhttp/httpserver/https_test.go
+21
-17
caddyhttp/httpserver/plugin.go
caddyhttp/httpserver/plugin.go
+5
-1
No files found.
caddy_test.go
View file @
f03ad807
...
@@ -16,9 +16,7 @@ package caddy
...
@@ -16,9 +16,7 @@ package caddy
import
(
import
(
"fmt"
"fmt"
"net"
"reflect"
"reflect"
"strconv"
"sync"
"sync"
"testing"
"testing"
...
@@ -204,39 +202,3 @@ func TestIsInternal(t *testing.T) {
...
@@ -204,39 +202,3 @@ func TestIsInternal(t *testing.T) {
}
}
}
}
}
}
func
TestListenerAddrEqual
(
t
*
testing
.
T
)
{
ln1
,
err
:=
net
.
Listen
(
"tcp"
,
"[::]:0"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
ln1
.
Close
()
ln1port
:=
strconv
.
Itoa
(
ln1
.
Addr
()
.
(
*
net
.
TCPAddr
)
.
Port
)
ln2
,
err
:=
net
.
Listen
(
"tcp"
,
"127.0.0.1:0"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
ln2
.
Close
()
ln2port
:=
strconv
.
Itoa
(
ln2
.
Addr
()
.
(
*
net
.
TCPAddr
)
.
Port
)
for
i
,
test
:=
range
[]
struct
{
ln
net
.
Listener
addr
string
expect
bool
}{
{
ln1
,
":"
+
ln2port
,
false
},
{
ln1
,
"0.0.0.0:"
+
ln2port
,
false
},
{
ln1
,
"0.0.0.0"
,
false
},
{
ln1
,
":"
+
ln1port
,
true
},
{
ln1
,
"0.0.0.0:"
+
ln1port
,
true
},
{
ln2
,
":"
+
ln2port
,
false
},
{
ln2
,
"127.0.0.1:"
+
ln1port
,
false
},
{
ln2
,
"127.0.0.1"
,
false
},
{
ln2
,
"127.0.0.1:"
+
ln2port
,
true
},
}
{
if
got
,
want
:=
listenerAddrEqual
(
test
.
ln
,
test
.
addr
),
test
.
expect
;
got
!=
want
{
t
.
Errorf
(
"Test %d (%s == %s): expected %v but was %v"
,
i
,
test
.
addr
,
test
.
ln
.
Addr
()
.
String
(),
want
,
got
)
}
}
}
caddyhttp/caddyhttp_test.go
View file @
f03ad807
...
@@ -25,7 +25,7 @@ import (
...
@@ -25,7 +25,7 @@ import (
// ensure that the standard plugins are in fact plugged in
// ensure that the standard plugins are in fact plugged in
// and registered properly; this is a quick/naive way to do it.
// and registered properly; this is a quick/naive way to do it.
func
TestStandardPlugins
(
t
*
testing
.
T
)
{
func
TestStandardPlugins
(
t
*
testing
.
T
)
{
numStandardPlugins
:=
3
1
// importing caddyhttp plugs in this many plugins
numStandardPlugins
:=
3
0
// importing caddyhttp plugs in this many plugins
s
:=
caddy
.
DescribePlugins
()
s
:=
caddy
.
DescribePlugins
()
if
got
,
want
:=
strings
.
Count
(
s
,
"
\n
"
),
numStandardPlugins
+
5
;
got
!=
want
{
if
got
,
want
:=
strings
.
Count
(
s
,
"
\n
"
),
numStandardPlugins
+
5
;
got
!=
want
{
t
.
Errorf
(
"Expected all standard plugins to be plugged in, got:
\n
%s"
,
s
)
t
.
Errorf
(
"Expected all standard plugins to be plugged in, got:
\n
%s"
,
s
)
...
...
caddyhttp/httpserver/https.go
View file @
f03ad807
...
@@ -101,7 +101,8 @@ func markQualifiedForAutoHTTPS(configs []*SiteConfig) {
...
@@ -101,7 +101,8 @@ func markQualifiedForAutoHTTPS(configs []*SiteConfig) {
// value will always be nil.
// value will always be nil.
func
enableAutoHTTPS
(
configs
[]
*
SiteConfig
,
loadCertificates
bool
)
error
{
func
enableAutoHTTPS
(
configs
[]
*
SiteConfig
,
loadCertificates
bool
)
error
{
for
_
,
cfg
:=
range
configs
{
for
_
,
cfg
:=
range
configs
{
if
cfg
==
nil
||
cfg
.
TLS
==
nil
||
!
cfg
.
TLS
.
Managed
||
cfg
.
TLS
.
Manager
.
OnDemand
!=
nil
{
if
cfg
==
nil
||
cfg
.
TLS
==
nil
||
!
cfg
.
TLS
.
Managed
||
cfg
.
TLS
.
Manager
==
nil
||
cfg
.
TLS
.
Manager
.
OnDemand
!=
nil
{
continue
continue
}
}
cfg
.
TLS
.
Enabled
=
true
cfg
.
TLS
.
Enabled
=
true
...
...
caddyhttp/httpserver/https_test.go
View file @
f03ad807
...
@@ -151,18 +151,18 @@ func TestHostHasOtherPort(t *testing.T) {
...
@@ -151,18 +151,18 @@ func TestHostHasOtherPort(t *testing.T) {
func
TestMakePlaintextRedirects
(
t
*
testing
.
T
)
{
func
TestMakePlaintextRedirects
(
t
*
testing
.
T
)
{
configs
:=
[]
*
SiteConfig
{
configs
:=
[]
*
SiteConfig
{
// Happy path = standard redirect from 80 to 443
// Happy path = standard redirect from 80 to 443
{
Addr
:
Address
{
Host
:
"example.com"
},
TLS
:
&
caddytls
.
Config
{
Manage
r
:
&
certmagic
.
Config
{
Managed
:
true
}
}},
{
Addr
:
Address
{
Host
:
"example.com"
},
TLS
:
&
caddytls
.
Config
{
Manage
d
:
true
}},
// Host on port 80 already defined; don't change it (no redirect)
// Host on port 80 already defined; don't change it (no redirect)
{
Addr
:
Address
{
Host
:
"sub1.example.com"
,
Port
:
"80"
,
Scheme
:
"http"
},
TLS
:
new
(
caddytls
.
Config
)},
{
Addr
:
Address
{
Host
:
"sub1.example.com"
,
Port
:
"80"
,
Scheme
:
"http"
},
TLS
:
new
(
caddytls
.
Config
)},
{
Addr
:
Address
{
Host
:
"sub1.example.com"
},
TLS
:
&
caddytls
.
Config
{
Manage
r
:
&
certmagic
.
Config
{
Managed
:
true
}
}},
{
Addr
:
Address
{
Host
:
"sub1.example.com"
},
TLS
:
&
caddytls
.
Config
{
Manage
d
:
true
}},
// Redirect from port 80 to port 5000 in this case
// Redirect from port 80 to port 5000 in this case
{
Addr
:
Address
{
Host
:
"sub2.example.com"
,
Port
:
"5000"
},
TLS
:
&
caddytls
.
Config
{
Manage
r
:
&
certmagic
.
Config
{
Managed
:
true
}
}},
{
Addr
:
Address
{
Host
:
"sub2.example.com"
,
Port
:
"5000"
},
TLS
:
&
caddytls
.
Config
{
Manage
d
:
true
}},
// Can redirect from 80 to either 443 or 5001, but choose 443
// Can redirect from 80 to either 443 or 5001, but choose 443
{
Addr
:
Address
{
Host
:
"sub3.example.com"
,
Port
:
"443"
},
TLS
:
&
caddytls
.
Config
{
Manage
r
:
&
certmagic
.
Config
{
Managed
:
true
}
}},
{
Addr
:
Address
{
Host
:
"sub3.example.com"
,
Port
:
"443"
},
TLS
:
&
caddytls
.
Config
{
Manage
d
:
true
}},
{
Addr
:
Address
{
Host
:
"sub3.example.com"
,
Port
:
"5001"
,
Scheme
:
"https"
},
TLS
:
&
caddytls
.
Config
{
Manage
r
:
&
certmagic
.
Config
{
Managed
:
true
}
}},
{
Addr
:
Address
{
Host
:
"sub3.example.com"
,
Port
:
"5001"
,
Scheme
:
"https"
},
TLS
:
&
caddytls
.
Config
{
Manage
d
:
true
}},
}
}
result
:=
makePlaintextRedirects
(
configs
)
result
:=
makePlaintextRedirects
(
configs
)
...
@@ -176,7 +176,7 @@ func TestMakePlaintextRedirects(t *testing.T) {
...
@@ -176,7 +176,7 @@ func TestMakePlaintextRedirects(t *testing.T) {
func
TestEnableAutoHTTPS
(
t
*
testing
.
T
)
{
func
TestEnableAutoHTTPS
(
t
*
testing
.
T
)
{
configs
:=
[]
*
SiteConfig
{
configs
:=
[]
*
SiteConfig
{
{
Addr
:
Address
{
Host
:
"example.com"
},
TLS
:
&
caddytls
.
Config
{
Manage
r
:
&
certmagic
.
Config
{
Managed
:
true
}}},
{
Addr
:
Address
{
Host
:
"example.com"
},
TLS
:
&
caddytls
.
Config
{
Manage
d
:
true
,
Manager
:
&
certmagic
.
Config
{
}}},
{},
// not managed - no changes!
{},
// not managed - no changes!
}
}
...
@@ -197,18 +197,18 @@ func TestEnableAutoHTTPS(t *testing.T) {
...
@@ -197,18 +197,18 @@ func TestEnableAutoHTTPS(t *testing.T) {
func
TestMarkQualifiedForAutoHTTPS
(
t
*
testing
.
T
)
{
func
TestMarkQualifiedForAutoHTTPS
(
t
*
testing
.
T
)
{
// TODO: caddytls.TestQualifiesForManagedTLS and this test share nearly the same config list...
// TODO: caddytls.TestQualifiesForManagedTLS and this test share nearly the same config list...
configs
:=
[]
*
SiteConfig
{
configs
:=
[]
*
SiteConfig
{
{
Addr
:
Address
{
Host
:
""
},
TLS
:
new
(
caddytls
.
Config
)},
{
Addr
:
Address
{
Host
:
""
},
TLS
:
new
ManagedConfig
(
)},
{
Addr
:
Address
{
Host
:
"localhost"
},
TLS
:
new
(
caddytls
.
Config
)},
{
Addr
:
Address
{
Host
:
"localhost"
},
TLS
:
new
ManagedConfig
(
)},
{
Addr
:
Address
{
Host
:
"123.44.3.21"
},
TLS
:
new
(
caddytls
.
Config
)},
{
Addr
:
Address
{
Host
:
"123.44.3.21"
},
TLS
:
new
ManagedConfig
(
)},
{
Addr
:
Address
{
Host
:
"example.com"
},
TLS
:
new
(
caddytls
.
Config
)},
{
Addr
:
Address
{
Host
:
"example.com"
},
TLS
:
new
ManagedConfig
(
)},
{
Addr
:
Address
{
Host
:
"example.com"
},
TLS
:
&
caddytls
.
Config
{
Manual
:
true
}},
{
Addr
:
Address
{
Host
:
"example.com"
},
TLS
:
&
caddytls
.
Config
{
Manual
:
true
}},
{
Addr
:
Address
{
Host
:
"example.com"
},
TLS
:
&
caddytls
.
Config
{
ACMEEmail
:
"off"
}},
{
Addr
:
Address
{
Host
:
"example.com"
},
TLS
:
&
caddytls
.
Config
{
ACMEEmail
:
"off"
}},
{
Addr
:
Address
{
Host
:
"example.com"
},
TLS
:
&
caddytls
.
Config
{
ACMEEmail
:
"foo@bar.com"
}},
{
Addr
:
Address
{
Host
:
"example.com"
},
TLS
:
&
caddytls
.
Config
{
ACMEEmail
:
"foo@bar.com"
,
Manager
:
&
certmagic
.
Config
{}
}},
{
Addr
:
Address
{
Host
:
"example.com"
,
Scheme
:
"http"
},
TLS
:
new
(
caddytls
.
Config
)},
{
Addr
:
Address
{
Host
:
"example.com"
,
Scheme
:
"http"
},
TLS
:
new
ManagedConfig
(
)},
{
Addr
:
Address
{
Host
:
"example.com"
,
Port
:
"80"
},
TLS
:
new
(
caddytls
.
Config
)},
{
Addr
:
Address
{
Host
:
"example.com"
,
Port
:
"80"
},
TLS
:
new
ManagedConfig
(
)},
{
Addr
:
Address
{
Host
:
"example.com"
,
Port
:
"1234"
},
TLS
:
new
(
caddytls
.
Config
)},
{
Addr
:
Address
{
Host
:
"example.com"
,
Port
:
"1234"
},
TLS
:
new
ManagedConfig
(
)},
{
Addr
:
Address
{
Host
:
"example.com"
,
Scheme
:
"https"
},
TLS
:
new
(
caddytls
.
Config
)},
{
Addr
:
Address
{
Host
:
"example.com"
,
Scheme
:
"https"
},
TLS
:
new
ManagedConfig
(
)},
{
Addr
:
Address
{
Host
:
"example.com"
,
Port
:
"80"
,
Scheme
:
"https"
},
TLS
:
new
(
caddytls
.
Config
)},
{
Addr
:
Address
{
Host
:
"example.com"
,
Port
:
"80"
,
Scheme
:
"https"
},
TLS
:
new
ManagedConfig
(
)},
}
}
expectedManagedCount
:=
4
expectedManagedCount
:=
4
...
@@ -216,7 +216,7 @@ func TestMarkQualifiedForAutoHTTPS(t *testing.T) {
...
@@ -216,7 +216,7 @@ func TestMarkQualifiedForAutoHTTPS(t *testing.T) {
count
:=
0
count
:=
0
for
_
,
cfg
:=
range
configs
{
for
_
,
cfg
:=
range
configs
{
if
cfg
.
TLS
.
Manage
r
.
Manage
d
{
if
cfg
.
TLS
.
Managed
{
count
++
count
++
}
}
}
}
...
@@ -225,3 +225,7 @@ func TestMarkQualifiedForAutoHTTPS(t *testing.T) {
...
@@ -225,3 +225,7 @@ func TestMarkQualifiedForAutoHTTPS(t *testing.T) {
t
.
Errorf
(
"Expected %d managed configs, but got %d"
,
expectedManagedCount
,
count
)
t
.
Errorf
(
"Expected %d managed configs, but got %d"
,
expectedManagedCount
,
count
)
}
}
}
}
func
newManagedConfig
()
*
caddytls
.
Config
{
return
&
caddytls
.
Config
{
Manager
:
&
certmagic
.
Config
{}}
}
caddyhttp/httpserver/plugin.go
View file @
f03ad807
...
@@ -346,7 +346,11 @@ func GetConfig(c *caddy.Controller) *SiteConfig {
...
@@ -346,7 +346,11 @@ func GetConfig(c *caddy.Controller) *SiteConfig {
// we should only get here during tests because directive
// we should only get here during tests because directive
// actions typically skip the server blocks where we make
// actions typically skip the server blocks where we make
// the configs
// the configs
cfg
:=
&
SiteConfig
{
Root
:
Root
,
TLS
:
new
(
caddytls
.
Config
),
IndexPages
:
staticfiles
.
DefaultIndexPages
}
cfg
:=
&
SiteConfig
{
Root
:
Root
,
TLS
:
&
caddytls
.
Config
{
Manager
:
certmagic
.
NewDefault
()},
IndexPages
:
staticfiles
.
DefaultIndexPages
,
}
ctx
.
saveConfig
(
key
,
cfg
)
ctx
.
saveConfig
(
key
,
cfg
)
return
cfg
return
cfg
}
}
...
...
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