Created
November 10, 2015 14:40
-
-
Save liggitt/02c67567bd01f8f9b0f5 to your computer and use it in GitHub Desktop.
Test file for creating bad filenames
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package recycler | |
import ( | |
"io/ioutil" | |
"os" | |
"path" | |
"testing" | |
) | |
var filenames = []string{ | |
string([]byte{3}), // Ctrl+C | |
string([]byte{4}), // Ctrl+D | |
`white space`, | |
`new | |
line`, | |
`*`, | |
`~`, | |
`\`, | |
`\\`, | |
` && touch and-escape`, | |
` || touch or-escape`, | |
` ; touch semi-escape`, | |
` " touch quote-escape`, | |
` ' touch apos-escape`, | |
` }"; touch brace-escape`, | |
`env x='() { :;}; echo vulnerable'`, // shellshock | |
`$USER`, | |
`...`, | |
`.file`, | |
`中文`, // utf-8 | |
`κόσμε`, // utf-8 | |
`Iñtërnâtiônàlizætiøn`, // utf-8 | |
} | |
func makeTestDir(t *testing.T) string { | |
root, err := ioutil.TempDir("", "recycler-test-") | |
if err != nil { | |
t.Fatal(err) | |
} | |
for _, dir := range filenames { | |
dirpath := path.Join(root, dir) | |
if err := os.Mkdir(dirpath, os.FileMode(0755)); err != nil { | |
t.Errorf("Error writing dir %s\n%v", dirpath, err) | |
continue | |
} | |
for _, file := range filenames { | |
filepath := path.Join(dirpath, file) | |
if err := ioutil.WriteFile(filepath, []byte(filepath), os.FileMode(0755)); err != nil { | |
t.Errorf("Error writing file %s\n%v", filepath, err) | |
} | |
if _, err := os.Stat(filepath); err != nil { | |
t.Errorf("Error verifying file %s\n%v", filepath, err) | |
} | |
} | |
} | |
return root | |
} | |
func cleanupTestDir(t *testing.T, dir string) { | |
t.Error(dir) | |
// err := os.RemoveAll(dir) | |
// if err != nil { | |
// t.Fatal(err) | |
// } | |
} | |
func TestFilenames(t *testing.T) { | |
dir := makeTestDir(t) | |
defer cleanupTestDir(t, dir) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment