@@ -4,11 +4,10 @@ package main
44//go:generate depstubber -vendor github.com/beego/beego/v2/server/web/context BeegoOutput,Context
55//go:generate depstubber -vendor github.com/gin-gonic/gin Context Default
66//go:generate depstubber -vendor github.com/gofiber/fiber/v2 Ctx New
7- //go:generate depstubber -vendor github.com/kataras/iris/v12 Context
7+ //go:generate depstubber -vendor github.com/kataras/iris/v12/context Context
88//go:generate depstubber -vendor github.com/labstack/echo/v4 Context New
99//go:generate depstubber -vendor github.com/spf13/afero Afero,RegexpFs,HttpFs,ReadOnlyFs,MemMapFs,OsFs,BasePathFs WriteReader,SafeWriteReader,WriteFile,ReadFile,ReadDir,NewOsFs,NewRegexpFs,NewReadOnlyFs,NewCacheOnReadFs,,NewHttpFs,NewBasePathFs,NewIOFS
1010
11-
1211import (
1312 "fmt"
1413 beego "github.com/beego/beego/v2/server/web"
@@ -29,68 +28,67 @@ func main() {
2928
3029func BeegoController (beegoController beego.Controller ) {
3130 beegoOutput := BeegoContext.BeegoOutput {}
32- beegoOutput .Download ("filepath" , "license.txt" )
31+ beegoOutput .Download ("filepath" , "license.txt" ) // $ FileSystemAccess="filepath"
3332 buffer := make ([]byte , 10 )
34- _ = beegoController .SaveToFileWithBuffer ("filenameExistsInForm" , "filepath" , buffer )
33+ _ = beegoController .SaveToFileWithBuffer ("filenameExistsInForm" , "filepath" , buffer ) // $ FileSystemAccess="filepath"
3534}
3635
3736func Afero (writer http.ResponseWriter , request * http.Request ) {
3837 filepath := request .URL .Query ()["filepath" ][0 ]
3938 //osFS := afero.NewMemMapFs()
4039 // OR
4140 osFS := afero .NewOsFs ()
42- fmt .Println (osFS .MkdirAll ("tmp/b" , 0755 ))
43- fmt .Println (afero .WriteFile (osFS , "tmp/a" , []byte ("this is me a !" ), 0755 ))
44- fmt .Println (afero .WriteFile (osFS , "tmp/b/c" , []byte ("this is me c !" ), 0755 ))
45- fmt .Println (afero .WriteFile (osFS , "tmp/d" , []byte ("this is me d !" ), 0755 ))
46- content , _ := afero .ReadFile (osFS , filepath )
41+ fmt .Println (osFS .MkdirAll (filepath , 0755 )) // $ FileSystemAccess=filepath
42+ fmt .Println (afero .WriteFile (osFS , filepath , []byte ("this is me a !" ), 0755 )) // $ FileSystemAccess=filepath
43+ content , _ := afero .ReadFile (osFS , filepath ) // $ FileSystemAccess=filepath
4744 fmt .Println (string (content ))
48- fmt .Println (osFS .Open (filepath ))
49- // BAD
50- fmt .Println (afero .SafeWriteReader (osFS , filepath , os .Stdout ))
51- fmt .Println (afero .WriteReader (osFS , filepath , os .Stdout ))
45+ fmt .Println (osFS .Open (filepath )) // $ FileSystemAccess=filepath
46+ // NOT OK
47+ fmt .Println (afero .SafeWriteReader (osFS , filepath , os .Stdout )) // $ FileSystemAccess=filepath
48+ fmt .Println (afero .WriteReader (osFS , filepath , os .Stdout )) // $ FileSystemAccess=filepath
5249
53- // RegexpFs ==> BAD
50+ // RegexpFs ==> NOT OK
5451 fmt .Println ("RegexpFs:" )
5552 regex , _ := regexp .Compile (".*" )
5653 regexpFs := afero .NewRegexpFs (osFS , regex )
57- fmt .Println (afero .ReadFile (regexpFs , filepath ))
54+ fmt .Println (afero .ReadFile (regexpFs , filepath )) // $ FileSystemAccess=filepath
5855
59- // ReadOnlyFS ==> BAD
56+ // ReadOnlyFS ==> NOT OK
6057 fmt .Println ("ReadOnlyFS:" )
6158 readOnlyFS := afero .NewReadOnlyFs (osFS )
62- fmt .Println (afero .ReadFile (readOnlyFS , filepath ))
59+ fmt .Println (afero .ReadFile (readOnlyFS , filepath )) // $ FileSystemAccess=filepath
6360
64- // CacheOnReadFs ==> BAD
61+ // CacheOnReadFs ==> NOT OK
6562 fmt .Println ("CacheOnReadFs:" )
6663 cacheOnReadFs := afero .NewCacheOnReadFs (osFS , osFS , 10 )
67- fmt .Println (afero .ReadFile (cacheOnReadFs , filepath ))
64+ fmt .Println (afero .ReadFile (cacheOnReadFs , filepath )) // $ FileSystemAccess=filepath
6865
69- // HttpFS ==> BAD
66+ // HttpFS ==> NOT OK
7067 fmt .Println ("HttpFS:" )
7168 httpFs := afero .NewHttpFs (osFS )
72- httpFile , _ := httpFs .Open (filepath )
69+ httpFile , _ := httpFs .Open (filepath ) // $ FileSystemAccess=filepath
7370 tmpbytes := make ([]byte , 30 )
7471 fmt .Println (httpFile .Read (tmpbytes ))
7572 fmt .Println (string (tmpbytes ))
7673
77- // osFS ==> BAD
74+ // osFS ==> NOT OK
7875 fmt .Println ("Afero:" )
79- afs := & afero.Afero {Fs : osFS }
80- fmt .Println (afs .ReadFile (filepath ))
76+ afs := & afero.Afero {Fs : osFS } // $ succ=&... pred=osFS
77+ fmt .Println (afs .ReadFile (filepath )) // $ FileSystemAccess=filepath
8178
82- // BasePathFs ==> BAD
79+ // BasePathFs ==> OK
8380 fmt .Println ("Afero:" )
84- basePathFs0 := & afero.Afero {Fs : afero .NewBasePathFs (osFS , "tmp" )}
85- fmt .Println (basePathFs0 .ReadFile (filepath ))
81+ newBasePathFs := afero .NewBasePathFs (osFS , "tmp" )
82+ basePathFs0 := & afero.Afero {Fs : newBasePathFs } // $ succ=&... pred=newBasePathFs
83+ fmt .Println (basePathFs0 .ReadFile (filepath )) // $ SPURIOUS: FileSystemAccess=filepath
8684
87- // IOFS ==> GOOD
85+ // IOFS ==> OK
8886 fmt .Println ("IOFS:" )
8987 ioFS := afero .NewIOFS (osFS )
9088 fmt .Println (ioFS .ReadFile (filepath ))
9189 fmt .Println (ioFS .Open (filepath ))
9290
93- // BasePathFs ==> GOOD
91+ // BasePathFs ==> OK
9492 fmt .Println ("BasePathFs:" )
9593 basePathFs := afero .NewBasePathFs (osFS , "tmp" )
9694 fmt .Println (afero .ReadFile (basePathFs , filepath ))
@@ -100,11 +98,13 @@ func Afero(writer http.ResponseWriter, request *http.Request) {
10098func Echo () {
10199 e := echo .New ()
102100 e .GET ("/" , func (c echo.Context ) error {
103- return c .File (c .QueryParam ("filePath" ))
101+ filepath := c .QueryParam ("filePath" )
102+ return c .File (filepath ) // $ FileSystemAccess=filepath
104103 })
105104
106105 e .GET ("/attachment" , func (c echo.Context ) error {
107- return c .Attachment (c .QueryParam ("filePath" ), "file name in response" )
106+ filepath := c .QueryParam ("filePath" )
107+ return c .Attachment (filepath , "file name in response" ) // $ FileSystemAccess=filepath
108108 })
109109 _ = e .Start (":1323" )
110110}
@@ -114,32 +114,32 @@ func Fiber() {
114114 app .Get ("/b" , func (c * fiber.Ctx ) error {
115115 filepath := c .Params ("filepath" )
116116 header , _ := c .FormFile ("f" )
117- _ = c .SaveFile (header , filepath )
118- return c .SendFile (filepath )
117+ _ = c .SaveFile (header , filepath ) // $ FileSystemAccess=filepath
118+ return c .SendFile (filepath ) // $ FileSystemAccess=filepath
119119 })
120120 _ = app .Listen (":3000" )
121121}
122122
123123func IrisTest (ctx context.Context ) {
124124 filepath := ctx .URLParam ("filepath" )
125- _ = ctx .SendFile (filepath , "file" )
126- _ = ctx .SendFileWithRate (filepath , "file" , 0 , 0 )
127- _ = ctx .ServeFile (filepath )
128- _ = ctx .ServeFileWithRate (filepath , 0 , 0 )
129- _ , _ , _ = ctx .UploadFormFiles (filepath , nil )
125+ _ = ctx .SendFile (filepath , "file" ) // $ FileSystemAccess=filepath
126+ _ = ctx .SendFileWithRate (filepath , "file" , 0 , 0 ) // $ FileSystemAccess=filepath
127+ _ = ctx .ServeFile (filepath ) // $ FileSystemAccess=filepath
128+ _ = ctx .ServeFileWithRate (filepath , 0 , 0 ) // $ FileSystemAccess=filepath
129+ _ , _ , _ = ctx .UploadFormFiles (filepath , nil ) // $ FileSystemAccess=filepath
130130 _ , fileHeader , _ := ctx .FormFile ("file" )
131- _ , _ = ctx .SaveFormFile (fileHeader , filepath )
131+ _ , _ = ctx .SaveFormFile (fileHeader , filepath ) // $ FileSystemAccess=filepath
132132
133133}
134134func Gin () {
135135 router := gin .Default ()
136136 router .POST ("/FormUploads" , func (c * gin.Context ) {
137137 filepath := c .Query ("filepath" )
138- c .File (filepath )
139- http .ServeFile (c .Writer , c .Request , filepath )
140- c .FileAttachment (filepath , "file name in response" )
138+ c .File (filepath ) // $ FileSystemAccess=filepath
139+ http .ServeFile (c .Writer , c .Request , filepath ) // $ FileSystemAccess=filepath
140+ c .FileAttachment (filepath , "file name in response" ) // $ FileSystemAccess=filepath
141141 file , _ := c .FormFile ("afile" )
142- _ = c .SaveUploadedFile (file , filepath )
142+ _ = c .SaveUploadedFile (file , filepath ) // $ FileSystemAccess=filepath
143143 })
144144 _ = router .Run ()
145145}
0 commit comments