]> git.r.bdr.sh - rbdr/mobius/blob - hotline/file_store.go
Sanitize file path input to prevent directory traversal
[rbdr/mobius] / hotline / file_store.go
1 package hotline
2
3 import (
4 "github.com/stretchr/testify/mock"
5 "os"
6 )
7
8 var FS FileStore
9
10 type FileStore interface {
11 Mkdir(name string, perm os.FileMode) error
12
13 Stat(name string) (os.FileInfo, error)
14 // TODO: implement
15
16 //Rename(oldpath string, newpath string) error
17 //RemoveAll(path string) error
18 }
19
20 type OSFileStore struct{}
21
22 func (fs OSFileStore) Mkdir(name string, perm os.FileMode) error {
23 return os.Mkdir(name, perm)
24 }
25
26 func (fs OSFileStore) Stat(name string) (os.FileInfo, error) {
27 return os.Stat(name)
28 }
29
30 type MockFileStore struct {
31 mock.Mock
32 }
33
34 func (mfs MockFileStore) Mkdir(name string, perm os.FileMode) error {
35 args := mfs.Called(name, perm)
36 return args.Error(0)
37 }
38
39 func (mfs MockFileStore) Stat(name string) (os.FileInfo, error) {
40 args := mfs.Called(name)
41 if args.Get(0) == nil {
42 return nil, args.Error(1)
43
44 }
45 return args.Get(0).(os.FileInfo), args.Error(1)
46 }