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
2bd6fd0a
Commit
2bd6fd0a
authored
Oct 18, 2016
by
Tw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
errors: don't join the absolute file path
fix issue #1188 Signed-off-by:
Tw
<
tw19881113@gmail.com
>
parent
94af3708
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
51 deletions
+31
-51
caddyhttp/errors/setup.go
caddyhttp/errors/setup.go
+3
-1
caddyhttp/errors/setup_test.go
caddyhttp/errors/setup_test.go
+28
-50
No files found.
caddyhttp/errors/setup.go
View file @
2bd6fd0a
...
...
@@ -115,7 +115,9 @@ func errorsParse(c *caddy.Controller) (*ErrorHandler, error) {
}
}
else
{
// Error page; ensure it exists
if
!
filepath
.
IsAbs
(
where
)
{
where
=
filepath
.
Join
(
cfg
.
Root
,
where
)
}
f
,
err
:=
os
.
Open
(
where
)
if
err
!=
nil
{
log
.
Printf
(
"[WARNING] Unable to open error page '%s': %v"
,
where
,
err
)
...
...
caddyhttp/errors/setup_test.go
View file @
2bd6fd0a
package
errors
import
(
"path/filepath"
"reflect"
"testing"
"github.com/mholt/caddy"
...
...
@@ -45,23 +47,28 @@ func TestSetup(t *testing.T) {
}
func
TestErrorsParse
(
t
*
testing
.
T
)
{
testAbs
,
err
:=
filepath
.
Abs
(
"./404.html"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
tests
:=
[]
struct
{
inputErrorsRules
string
shouldErr
bool
expectedErrorHandler
ErrorHandler
}{
{
`errors`
,
false
,
ErrorHandler
{
LogFile
:
""
,
ErrorPages
:
map
[
int
]
string
{}
,
}},
{
`errors errors.txt`
,
false
,
ErrorHandler
{
ErrorPages
:
map
[
int
]
string
{},
LogFile
:
"errors.txt"
,
}},
{
`errors visible`
,
false
,
ErrorHandler
{
LogFile
:
""
,
ErrorPages
:
map
[
int
]
string
{}
,
Debug
:
true
,
}},
{
`errors { log visible }`
,
false
,
ErrorHandler
{
LogFile
:
""
,
ErrorPages
:
map
[
int
]
string
{}
,
Debug
:
true
,
}},
{
`errors { log errors.txt
...
...
@@ -82,6 +89,7 @@ func TestErrorsParse(t *testing.T) {
MaxBackups
:
3
,
LocalTime
:
true
,
},
ErrorPages
:
map
[
int
]
string
{},
}},
{
`errors { log errors.txt {
size 3
...
...
@@ -115,15 +123,24 @@ func TestErrorsParse(t *testing.T) {
503
:
"503.html"
,
},
}},
// test absolute file path
{
`errors {
404 `
+
testAbs
+
`
}`
,
false
,
ErrorHandler
{
ErrorPages
:
map
[
int
]
string
{
404
:
testAbs
,
},
}},
// Next two test cases is the detection of duplicate status codes
{
`errors {
503 503.html
503 503.html
}`
,
true
,
ErrorHandler
{}},
}`
,
true
,
ErrorHandler
{
ErrorPages
:
map
[
int
]
string
{}
}},
{
`errors {
* generic_error.html
* generic_error.html
}`
,
true
,
ErrorHandler
{}},
}`
,
true
,
ErrorHandler
{
ErrorPages
:
map
[
int
]
string
{}
}},
}
for
i
,
test
:=
range
tests
{
actualErrorsRule
,
err
:=
errorsParse
(
caddy
.
NewTestController
(
"http"
,
test
.
inputErrorsRules
))
...
...
@@ -135,48 +152,9 @@ func TestErrorsParse(t *testing.T) {
}
else
if
err
!=
nil
&&
test
.
shouldErr
{
continue
}
if
actualErrorsRule
.
LogFile
!=
test
.
expectedErrorHandler
.
LogFile
{
t
.
Errorf
(
"Test %d expected LogFile to be %s, but got %s"
,
i
,
test
.
expectedErrorHandler
.
LogFile
,
actualErrorsRule
.
LogFile
)
}
if
actualErrorsRule
.
Debug
!=
test
.
expectedErrorHandler
.
Debug
{
t
.
Errorf
(
"Test %d expected Debug to be %v, but got %v"
,
i
,
test
.
expectedErrorHandler
.
Debug
,
actualErrorsRule
.
Debug
)
}
if
actualErrorsRule
.
LogRoller
!=
nil
&&
test
.
expectedErrorHandler
.
LogRoller
==
nil
||
actualErrorsRule
.
LogRoller
==
nil
&&
test
.
expectedErrorHandler
.
LogRoller
!=
nil
{
t
.
Fatalf
(
"Test %d expected LogRoller to be %v, but got %v"
,
i
,
test
.
expectedErrorHandler
.
LogRoller
,
actualErrorsRule
.
LogRoller
)
}
if
len
(
actualErrorsRule
.
ErrorPages
)
!=
len
(
test
.
expectedErrorHandler
.
ErrorPages
)
{
t
.
Fatalf
(
"Test %d expected %d no of Error pages, but got %d "
,
i
,
len
(
test
.
expectedErrorHandler
.
ErrorPages
),
len
(
actualErrorsRule
.
ErrorPages
))
if
!
reflect
.
DeepEqual
(
actualErrorsRule
,
&
test
.
expectedErrorHandler
)
{
t
.
Errorf
(
"Test %d expect %v, but got %v"
,
i
,
actualErrorsRule
,
test
.
expectedErrorHandler
)
}
if
actualErrorsRule
.
LogRoller
!=
nil
&&
test
.
expectedErrorHandler
.
LogRoller
!=
nil
{
if
actualErrorsRule
.
LogRoller
.
Filename
!=
test
.
expectedErrorHandler
.
LogRoller
.
Filename
{
t
.
Fatalf
(
"Test %d expected LogRoller Filename to be %s, but got %s"
,
i
,
test
.
expectedErrorHandler
.
LogRoller
.
Filename
,
actualErrorsRule
.
LogRoller
.
Filename
)
}
if
actualErrorsRule
.
LogRoller
.
MaxAge
!=
test
.
expectedErrorHandler
.
LogRoller
.
MaxAge
{
t
.
Fatalf
(
"Test %d expected LogRoller MaxAge to be %d, but got %d"
,
i
,
test
.
expectedErrorHandler
.
LogRoller
.
MaxAge
,
actualErrorsRule
.
LogRoller
.
MaxAge
)
}
if
actualErrorsRule
.
LogRoller
.
MaxBackups
!=
test
.
expectedErrorHandler
.
LogRoller
.
MaxBackups
{
t
.
Fatalf
(
"Test %d expected LogRoller MaxBackups to be %d, but got %d"
,
i
,
test
.
expectedErrorHandler
.
LogRoller
.
MaxBackups
,
actualErrorsRule
.
LogRoller
.
MaxBackups
)
}
if
actualErrorsRule
.
LogRoller
.
MaxSize
!=
test
.
expectedErrorHandler
.
LogRoller
.
MaxSize
{
t
.
Fatalf
(
"Test %d expected LogRoller MaxSize to be %d, but got %d"
,
i
,
test
.
expectedErrorHandler
.
LogRoller
.
MaxSize
,
actualErrorsRule
.
LogRoller
.
MaxSize
)
}
if
actualErrorsRule
.
LogRoller
.
LocalTime
!=
test
.
expectedErrorHandler
.
LogRoller
.
LocalTime
{
t
.
Fatalf
(
"Test %d expected LogRoller LocalTime to be %t, but got %t"
,
i
,
test
.
expectedErrorHandler
.
LogRoller
.
LocalTime
,
actualErrorsRule
.
LogRoller
.
LocalTime
)
}
}
if
actualErrorsRule
.
GenericErrorPage
!=
test
.
expectedErrorHandler
.
GenericErrorPage
{
t
.
Fatalf
(
"Test %d expected GenericErrorPage to be %v, but got %v"
,
i
,
test
.
expectedErrorHandler
.
GenericErrorPage
,
actualErrorsRule
.
GenericErrorPage
)
}
}
}
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