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
6af26e23
Commit
6af26e23
authored
Oct 14, 2015
by
makpoc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use null byte in filename to simulate 'unable to access' on both windows and linux
parent
f122b3bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
13 deletions
+8
-13
config/setup/root_test.go
config/setup/root_test.go
+8
-13
No files found.
config/setup/root_test.go
View file @
6af26e23
...
...
@@ -7,7 +7,6 @@ import (
"path/filepath"
"strings"
"testing"
"runtime"
)
func
TestRoot
(
t
*
testing
.
T
)
{
...
...
@@ -27,13 +26,13 @@ func TestRoot(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"BeforeTest: Failed to create temp file for testing! Error was: %v"
,
err
)
}
defer
func
()
{
defer
func
()
{
existingFile
.
Close
()
os
.
Remove
(
existingFile
.
Name
())
}()
unaccessiblePath
:=
getInaccessibleOsDependent
Path
(
existingFile
.
Name
())
inaccessiblePath
:=
getInaccessible
Path
(
existingFile
.
Name
())
tests
:=
[]
struct
{
input
string
shouldErr
bool
...
...
@@ -52,7 +51,7 @@ func TestRoot(t *testing.T) {
`root `
,
true
,
""
,
parseErrContent
,
},
{
fmt
.
Sprintf
(
`root %s`
,
u
naccessiblePath
),
true
,
""
,
unableToAccessErrContent
,
fmt
.
Sprintf
(
`root %s`
,
i
naccessiblePath
),
true
,
""
,
unableToAccessErrContent
,
},
{
fmt
.
Sprintf
(
`root {
...
...
@@ -103,11 +102,7 @@ func getTempDirPath() (string, error) {
return
tempDir
,
nil
}
func
getInaccessibleOsDependentPath
(
file
string
)
string
{
if
runtime
.
GOOS
==
"windows"
{
return
filepath
.
Join
(
"C:"
,
"file
\x00
name"
)
// 0 byte breaks the lstat syscall
}
else
{
// TODO - check if the zero-byte filename works for linux only. If it does - use it instead
return
filepath
.
Join
(
file
,
"some_name"
)
}
}
\ No newline at end of file
func
getInaccessiblePath
(
file
string
)
string
{
// null byte in filename is not allowed on Windows AND unix
return
filepath
.
Join
(
"C:"
,
"file
\x00
name"
)
}
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