@@ -462,7 +462,7 @@ func TestFileManagerService_Rollback(t *testing.T) {
462462
463463func TestFileManagerService_DetermineFileActions (t * testing.T ) {
464464 ctx := context .Background ()
465- tempDir := os .TempDir ()
465+ tempDir := filepath . Clean ( os .TempDir () )
466466
467467 deleteTestFile := helpers .CreateFileWithErrorCheck (t , tempDir , "nginx_delete.conf" )
468468 defer helpers .RemoveFileWithErrorCheck (t , deleteTestFile .Name ())
@@ -492,6 +492,7 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
492492 require .NoError (t , addErr )
493493
494494 tests := []struct {
495+ allowedDirs []string
495496 expectedError error
496497 modifiedFiles map [string ]* model.FileCache
497498 currentFiles map [string ]* mpi.File
@@ -500,7 +501,8 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
500501 name string
501502 }{
502503 {
503- name : "Test 1: Add, Update & Delete Files" ,
504+ name : "Test 1: Add, Update & Delete Files" ,
505+ allowedDirs : []string {tempDir },
504506 modifiedFiles : map [string ]* model.FileCache {
505507 addTestFileName : {
506508 File : & mpi.File {
@@ -563,7 +565,8 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
563565 expectedError : nil ,
564566 },
565567 {
566- name : "Test 2: Files same as on disk" ,
568+ name : "Test 2: Files same as on disk" ,
569+ allowedDirs : []string {tempDir },
567570 modifiedFiles : map [string ]* model.FileCache {
568571 addTestFile .Name (): {
569572 File : & mpi.File {
@@ -598,6 +601,7 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
598601 },
599602 {
600603 name : "Test 3: File being deleted already doesn't exist" ,
604+ allowedDirs : []string {tempDir },
601605 modifiedFiles : make (map [string ]* model.FileCache ),
602606 currentFiles : map [string ]* mpi.File {
603607 "/unknown/file.conf" : {
@@ -620,6 +624,7 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
620624
621625 fakeFileServiceClient := & v1fakes.FakeFileServiceClient {}
622626 fileManagerService := NewFileManagerService (fakeFileServiceClient , types .AgentConfig (), & sync.RWMutex {})
627+ fileManagerService .agentConfig .AllowedDirectories = test .allowedDirs
623628 fileManagerService .agentConfig .LibDir = manifestDirPath
624629 fileManagerService .manifestFilePath = manifestFilePath
625630
@@ -794,6 +799,7 @@ func TestFileManagerService_UpdateManifestFile(t *testing.T) {
794799
795800 fakeFileServiceClient := & v1fakes.FakeFileServiceClient {}
796801 fileManagerService := NewFileManagerService (fakeFileServiceClient , types .AgentConfig (), & sync.RWMutex {})
802+ fileManagerService .agentConfig .AllowedDirectories = []string {"manifestDirPath" }
797803 fileManagerService .agentConfig .LibDir = manifestDirPath
798804 fileManagerService .manifestFilePath = file .Name ()
799805
0 commit comments