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
9077cce1
Commit
9077cce1
authored
Sep 24, 2016
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for case insensitivity of keys and saving contexts
parent
76d9d695
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
3 deletions
+56
-3
caddyhttp/httpserver/plugin.go
caddyhttp/httpserver/plugin.go
+4
-3
caddyhttp/httpserver/plugin_test.go
caddyhttp/httpserver/plugin_test.go
+52
-0
No files found.
caddyhttp/httpserver/plugin.go
View file @
9077cce1
...
...
@@ -65,7 +65,7 @@ type httpContext struct {
func
(
h
*
httpContext
)
saveConfig
(
key
string
,
cfg
*
SiteConfig
)
{
h
.
siteConfigs
=
append
(
h
.
siteConfigs
,
cfg
)
h
.
keysToSiteConfigs
[
strings
.
ToLower
(
key
)
]
=
cfg
h
.
keysToSiteConfigs
[
key
]
=
cfg
}
// InspectServerBlocks make sure that everything checks out before
...
...
@@ -178,8 +178,9 @@ func GetConfig(c *caddy.Controller) *SiteConfig {
// we should only get here during tests because directive
// actions typically skip the server blocks where we make
// the configs
ctx
.
saveConfig
(
key
,
&
SiteConfig
{
Root
:
Root
,
TLS
:
new
(
caddytls
.
Config
)})
return
GetConfig
(
c
)
cfg
:=
&
SiteConfig
{
Root
:
Root
,
TLS
:
new
(
caddytls
.
Config
)}
ctx
.
saveConfig
(
key
,
cfg
)
return
cfg
}
// shortCaddyfileLoader loads a Caddyfile if positional arguments are
...
...
caddyhttp/httpserver/plugin_test.go
View file @
9077cce1
...
...
@@ -4,6 +4,7 @@ import (
"strings"
"testing"
"github.com/mholt/caddy"
"github.com/mholt/caddy/caddyfile"
)
...
...
@@ -138,6 +139,39 @@ func TestInspectServerBlocksWithCustomDefaultPort(t *testing.T) {
}
}
func
TestInspectServerBlocksCaseInsensitiveKey
(
t
*
testing
.
T
)
{
filename
:=
"Testfile"
ctx
:=
newContext
()
.
(
*
httpContext
)
input
:=
strings
.
NewReader
(
"localhost {
\n
}
\n
LOCALHOST {
\n
}"
)
sblocks
,
err
:=
caddyfile
.
Parse
(
filename
,
input
,
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"Expected no error setting up test, got: %v"
,
err
)
}
_
,
err
=
ctx
.
InspectServerBlocks
(
filename
,
sblocks
)
if
err
==
nil
{
t
.
Error
(
"Expected an error because keys on this server type are case-insensitive (so these are duplicated), but didn't get an error"
)
}
}
func
TestGetConfig
(
t
*
testing
.
T
)
{
// case insensitivity for key
con
:=
caddy
.
NewTestController
(
"http"
,
""
)
con
.
Key
=
"foo"
cfg
:=
GetConfig
(
con
)
con
.
Key
=
"FOO"
cfg2
:=
GetConfig
(
con
)
if
cfg
!=
cfg2
{
t
.
Errorf
(
"Expected same config using same key with different case; got %p and %p"
,
cfg
,
cfg2
)
}
// make sure different key returns different config
con
.
Key
=
"foobar"
cfg3
:=
GetConfig
(
con
)
if
cfg
==
cfg3
{
t
.
Errorf
(
"Expected different configs using when key is different; got %p and %p"
,
cfg
,
cfg3
)
}
}
func
TestDirectivesList
(
t
*
testing
.
T
)
{
for
i
,
dir1
:=
range
directives
{
if
dir1
==
""
{
...
...
@@ -157,3 +191,21 @@ func TestDirectivesList(t *testing.T) {
}
}
}
func
TestContextSaveConfig
(
t
*
testing
.
T
)
{
ctx
:=
newContext
()
.
(
*
httpContext
)
ctx
.
saveConfig
(
"foo"
,
new
(
SiteConfig
))
if
_
,
ok
:=
ctx
.
keysToSiteConfigs
[
"foo"
];
!
ok
{
t
.
Error
(
"Expected config to be saved, but it wasn't"
)
}
if
got
,
want
:=
len
(
ctx
.
siteConfigs
),
1
;
got
!=
want
{
t
.
Errorf
(
"Expected len(siteConfigs) == %d, but was %d"
,
want
,
got
)
}
ctx
.
saveConfig
(
"Foobar"
,
new
(
SiteConfig
))
if
_
,
ok
:=
ctx
.
keysToSiteConfigs
[
"foobar"
];
ok
{
t
.
Error
(
"Did not expect to get config with case-insensitive key, but did"
)
}
if
got
,
want
:=
len
(
ctx
.
siteConfigs
),
2
;
got
!=
want
{
t
.
Errorf
(
"Expected len(siteConfigs) == %d, but was %d"
,
want
,
got
)
}
}
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