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
5c3085fe
Commit
5c3085fe
authored
Oct 14, 2015
by
Matt Holt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #271 from zmb3/windows_failures
Fix test failures on Windows.
parents
a914565f
26cbea9e
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
42 additions
and
20 deletions
+42
-20
config/setup/basicauth_test.go
config/setup/basicauth_test.go
+1
-1
config/setup/controller.go
config/setup/controller.go
+3
-1
config/setup/errors.go
config/setup/errors.go
+2
-2
config/setup/markdown.go
config/setup/markdown.go
+2
-2
config/setup/markdown_test.go
config/setup/markdown_test.go
+6
-4
middleware/basicauth/basicauth_test.go
middleware/basicauth/basicauth_test.go
+6
-2
middleware/markdown/generator.go
middleware/markdown/generator.go
+2
-1
middleware/markdown/page.go
middleware/markdown/page.go
+1
-1
middleware/markdown/process.go
middleware/markdown/process.go
+5
-2
middleware/middleware.go
middleware/middleware.go
+9
-2
middleware/middleware_test.go
middleware/middleware_test.go
+5
-2
No files found.
config/setup/basicauth_test.go
View file @
5c3085fe
...
...
@@ -38,7 +38,7 @@ func TestBasicAuthParse(t *testing.T) {
md5:$apr1$l42y8rex$pOA2VJ0x/0TwaFeAF9nX61`
var
skipHtpassword
bool
htfh
,
err
:=
ioutil
.
TempFile
(
""
,
"basicauth-"
)
htfh
,
err
:=
ioutil
.
TempFile
(
"
.
"
,
"basicauth-"
)
if
err
!=
nil
{
t
.
Logf
(
"Error creating temp file (%v), will skip htpassword test"
,
err
)
skipHtpassword
=
true
...
...
config/setup/controller.go
View file @
5c3085fe
...
...
@@ -24,7 +24,9 @@ type Controller struct {
// add-ons can use this as a convenience.
func
NewTestController
(
input
string
)
*
Controller
{
return
&
Controller
{
Config
:
&
server
.
Config
{},
Config
:
&
server
.
Config
{
Root
:
"."
,
},
Dispenser
:
parse
.
NewDispenser
(
"Testfile"
,
strings
.
NewReader
(
input
)),
}
}
...
...
config/setup/errors.go
View file @
5c3085fe
...
...
@@ -5,7 +5,7 @@ import (
"io"
"log"
"os"
"path"
"path
/filepath
"
"strconv"
"github.com/hashicorp/go-syslog"
...
...
@@ -105,7 +105,7 @@ func errorsParse(c *Controller) (*errors.ErrorHandler, error) {
}
}
else
{
// Error page; ensure it exists
where
=
path
.
Join
(
c
.
Root
,
where
)
where
=
file
path
.
Join
(
c
.
Root
,
where
)
f
,
err
:=
os
.
Open
(
where
)
if
err
!=
nil
{
fmt
.
Println
(
"Warning: Unable to open error page '"
+
where
+
"': "
+
err
.
Error
())
...
...
config/setup/markdown.go
View file @
5c3085fe
...
...
@@ -114,11 +114,11 @@ func loadParams(c *Controller, mdc *markdown.Config) error {
if
_
,
ok
:=
mdc
.
Templates
[
markdown
.
DefaultTemplate
];
ok
{
return
c
.
Err
(
"only one default template is allowed, use alias."
)
}
fpath
:=
filepath
.
Clean
(
c
.
Root
+
string
(
filepath
.
Separator
)
+
tArgs
[
0
]
)
fpath
:=
filepath
.
ToSlash
(
filepath
.
Clean
(
c
.
Root
+
string
(
filepath
.
Separator
)
+
tArgs
[
0
])
)
mdc
.
Templates
[
markdown
.
DefaultTemplate
]
=
fpath
return
nil
case
2
:
fpath
:=
filepath
.
Clean
(
c
.
Root
+
string
(
filepath
.
Separator
)
+
tArgs
[
1
]
)
fpath
:=
filepath
.
ToSlash
(
filepath
.
Clean
(
c
.
Root
+
string
(
filepath
.
Separator
)
+
tArgs
[
1
])
)
mdc
.
Templates
[
tArgs
[
0
]]
=
fpath
return
nil
default
:
...
...
config/setup/markdown_test.go
View file @
5c3085fe
package
setup
import
(
"bytes"
"fmt"
"io/ioutil"
"net/http"
...
...
@@ -92,7 +93,7 @@ func TestMarkdownStaticGen(t *testing.T) {
t
.
Fatalf
(
"An error occured when getting the file content: %v"
,
err
)
}
expectedBody
:=
`<!DOCTYPE html>
expectedBody
:=
[]
byte
(
`<!DOCTYPE html>
<html>
<head>
<title>first_post</title>
...
...
@@ -104,9 +105,10 @@ func TestMarkdownStaticGen(t *testing.T) {
</body>
</html>
`
if
string
(
html
)
!=
expectedBody
{
t
.
Fatalf
(
"Expected file content: %v got: %v"
,
expectedBody
,
html
)
`
)
if
!
bytes
.
Equal
(
html
,
expectedBody
)
{
t
.
Fatalf
(
"Expected file content: %s got: %s"
,
string
(
expectedBody
),
string
(
html
))
}
fp
:=
filepath
.
Join
(
c
.
Root
,
markdown
.
DefaultStaticDir
)
...
...
middleware/basicauth/basicauth_test.go
View file @
5c3085fe
...
...
@@ -7,6 +7,7 @@ import (
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
"github.com/mholt/caddy/middleware"
...
...
@@ -124,15 +125,18 @@ md5:$apr1$l42y8rex$pOA2VJ0x/0TwaFeAF9nX61`
t
.
Skipf
(
"Error creating temp file (%v), will skip htpassword test"
)
return
}
defer
os
.
Remove
(
htfh
.
Name
())
if
_
,
err
=
htfh
.
Write
([]
byte
(
htpasswdFile
));
err
!=
nil
{
t
.
Fatalf
(
"write htpasswd file %q: %v"
,
htfh
.
Name
(),
err
)
}
htfh
.
Close
()
defer
os
.
Remove
(
htfh
.
Name
())
for
i
,
username
:=
range
[]
string
{
"sha1"
,
"md5"
}
{
rule
:=
Rule
{
Username
:
username
,
Resources
:
[]
string
{
"/testing"
}}
if
rule
.
Password
,
err
=
GetHtpasswdMatcher
(
htfh
.
Name
(),
rule
.
Username
,
"/"
);
err
!=
nil
{
siteRoot
:=
filepath
.
Dir
(
htfh
.
Name
())
filename
:=
filepath
.
Base
(
htfh
.
Name
())
if
rule
.
Password
,
err
=
GetHtpasswdMatcher
(
filename
,
rule
.
Username
,
siteRoot
);
err
!=
nil
{
t
.
Fatalf
(
"GetHtpasswdMatcher(%q, %q): %v"
,
htfh
.
Name
(),
rule
.
Username
,
err
)
}
t
.
Logf
(
"%d. username=%q password=%v"
,
i
,
rule
.
Username
,
rule
.
Password
)
...
...
middleware/markdown/generator.go
View file @
5c3085fe
...
...
@@ -70,7 +70,7 @@ func generateLinks(md Markdown, cfg *Config) (bool, error) {
return
generated
,
g
.
lastErr
}
// generateStatic
Files generates static html
files from markdowns.
// generateStatic
HTML generates static HTML
files from markdowns.
func
generateStaticHTML
(
md
Markdown
,
cfg
*
Config
)
error
{
// If generated site already exists, clear it out
_
,
err
:=
os
.
Stat
(
cfg
.
StaticDir
)
...
...
@@ -98,6 +98,7 @@ func generateStaticHTML(md Markdown, cfg *Config) error {
if
err
!=
nil
{
return
err
}
reqPath
=
filepath
.
ToSlash
(
reqPath
)
reqPath
=
"/"
+
reqPath
// Generate the static file
...
...
middleware/markdown/page.go
View file @
5c3085fe
...
...
@@ -116,7 +116,7 @@ func (l *linkGen) generateLinks(md Markdown, cfg *Config) bool {
if
err
!=
nil
{
return
err
}
reqPath
=
"/"
+
reqPath
reqPath
=
"/"
+
filepath
.
ToSlash
(
reqPath
)
parser
:=
findParser
(
body
)
if
parser
==
nil
{
...
...
middleware/markdown/process.go
View file @
5c3085fe
...
...
@@ -134,7 +134,10 @@ func (md Markdown) generatePage(c *Config, requestPath string, content []byte) e
}
}
filePath
:=
filepath
.
Join
(
c
.
StaticDir
,
requestPath
)
// the URL will always use "/" as a path separator,
// convert that to a native path to support OS that
// use different path separators
filePath
:=
filepath
.
Join
(
c
.
StaticDir
,
filepath
.
FromSlash
(
requestPath
))
// If it is index file, use the directory instead
if
md
.
IsIndexFile
(
filepath
.
Base
(
requestPath
))
{
...
...
@@ -154,7 +157,7 @@ func (md Markdown) generatePage(c *Config, requestPath string, content []byte) e
}
c
.
Lock
()
c
.
StaticFiles
[
requestPath
]
=
file
Path
c
.
StaticFiles
[
requestPath
]
=
file
path
.
ToSlash
(
filePath
)
c
.
Unlock
()
}
...
...
middleware/middleware.go
View file @
5c3085fe
...
...
@@ -3,7 +3,7 @@ package middleware
import
(
"net/http"
"path
/filepath
"
"path"
)
type
(
...
...
@@ -57,12 +57,19 @@ func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err
// and false is returned. fpath must end in a forward slash '/'
// otherwise no index files will be tried (directory paths must end
// in a forward slash according to HTTP).
//
// All paths passed into and returned from this function use '/' as the
// path separator, just like URLs. IndexFle handles path manipulation
// internally for systems that use different path separators.
func
IndexFile
(
root
http
.
FileSystem
,
fpath
string
,
indexFiles
[]
string
)
(
string
,
bool
)
{
if
fpath
[
len
(
fpath
)
-
1
]
!=
'/'
||
root
==
nil
{
return
""
,
false
}
for
_
,
indexFile
:=
range
indexFiles
{
fp
:=
filepath
.
Join
(
fpath
,
indexFile
)
// func (http.FileSystem).Open wants all paths separated by "/",
// regardless of operating system convention, so use
// path.Join instead of filepath.Join
fp
:=
path
.
Join
(
fpath
,
indexFile
)
f
,
err
:=
root
.
Open
(
fp
)
if
err
==
nil
{
f
.
Close
()
...
...
middleware/middleware_test.go
View file @
5c3085fe
...
...
@@ -15,9 +15,12 @@ func TestIndexfile(t *testing.T) {
expectedBoolValue
bool
//return value
}{
{
http
.
Dir
(
"./templates/testdata"
),
"/images/"
,
[]
string
{
"img.htm"
},
http
.
Dir
(
"./templates/testdata"
),
"/images/"
,
[]
string
{
"img.htm"
},
false
,
"/images/img.htm"
,
true
,
"/images/img.htm"
,
true
,
},
}
for
i
,
test
:=
range
tests
{
...
...
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