This wonderfully large commit replaces basically everything under the `server/filesystem` package, re-implementing essentially everything. This is related to https://github.com/pterodactyl/wings/security/advisories/GHSA-494h-9924-xww9 If any vulnerabilities related to symlinks persist after this commit, I will be very upset. Signed-off-by: Matthew Penner <me@matthewp.io>
		
			
				
	
	
		
			55 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package filesystem
 | 
						|
 | 
						|
import (
 | 
						|
	"context"
 | 
						|
	"os"
 | 
						|
	"testing"
 | 
						|
 | 
						|
	. "github.com/franela/goblin"
 | 
						|
)
 | 
						|
 | 
						|
// Given an archive named test.{ext}, with the following file structure:
 | 
						|
//
 | 
						|
//	test/
 | 
						|
//	|──inside/
 | 
						|
//	|────finside.txt
 | 
						|
//	|──outside.txt
 | 
						|
//
 | 
						|
// this test will ensure that it's being decompressed as expected
 | 
						|
func TestFilesystem_DecompressFile(t *testing.T) {
 | 
						|
	g := Goblin(t)
 | 
						|
	fs, rfs := NewFs()
 | 
						|
 | 
						|
	g.Describe("Decompress", func() {
 | 
						|
		for _, ext := range []string{"zip", "rar", "tar", "tar.gz"} {
 | 
						|
			g.It("can decompress a "+ext, func() {
 | 
						|
				// copy the file to the new FS
 | 
						|
				c, err := os.ReadFile("./testdata/test." + ext)
 | 
						|
				g.Assert(err).IsNil()
 | 
						|
				err = rfs.CreateServerFile("./test."+ext, c)
 | 
						|
				g.Assert(err).IsNil()
 | 
						|
 | 
						|
				// decompress
 | 
						|
				err = fs.DecompressFile(context.Background(), "/", "test."+ext)
 | 
						|
				g.Assert(err).IsNil()
 | 
						|
 | 
						|
				// make sure everything is where it is supposed to be
 | 
						|
				_, err = rfs.StatServerFile("test/outside.txt")
 | 
						|
				g.Assert(err).IsNil()
 | 
						|
 | 
						|
				st, err := rfs.StatServerFile("test/inside")
 | 
						|
				g.Assert(err).IsNil()
 | 
						|
				g.Assert(st.IsDir()).IsTrue()
 | 
						|
 | 
						|
				_, err = rfs.StatServerFile("test/inside/finside.txt")
 | 
						|
				g.Assert(err).IsNil()
 | 
						|
				g.Assert(st.IsDir()).IsTrue()
 | 
						|
			})
 | 
						|
		}
 | 
						|
 | 
						|
		g.AfterEach(func() {
 | 
						|
			_ = fs.TruncateRootDirectory()
 | 
						|
		})
 | 
						|
	})
 | 
						|
}
 |