@@ -368,7 +368,10 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
368
368
// check prebuild log message exists
369
369
checkPrebuildLogExist (t , cfg , rsa , ws , test .WorkspaceRoot )
370
370
371
- // check the files/folders permission under .git/ is not gitpod
371
+ // check the folder permission is gitpod
372
+ checkFolderPermission (t , rsa , "/workspace" )
373
+
374
+ // check the files/folders permission under .git/ is gitpod
372
375
checkGitFolderPermission (t , rsa , test .WorkspaceRoot )
373
376
374
377
// write file foobar.txt and stop the workspace
@@ -807,7 +810,10 @@ func TestPrebuildAndRegularWorkspaceDifferentWorkspaceClass(t *testing.T) {
807
810
// check prebuild log message exists
808
811
checkPrebuildLogExist (t , cfg , rsa , ws , test .WorkspaceRoot )
809
812
810
- // check the files/folders permission under .git/ is not gitpod
813
+ // check the folder permission is gitpod
814
+ checkFolderPermission (t , rsa , "/workspace" )
815
+
816
+ // check the files/folders permission under .git/ is gitpod
811
817
checkGitFolderPermission (t , rsa , test .WorkspaceRoot )
812
818
})
813
819
}
@@ -926,7 +932,28 @@ func checkPrebuildLogExist(t *testing.T, cfg *envconf.Config, rsa *rpc.Client, w
926
932
t .Fatal ("did not find someFile from previous workspace instance" )
927
933
}
928
934
929
- // checkGitFolderPermission checks the files/folders permission under .git/ is not gitpod
935
+ // checkFolderPermission checks the folder UID and GID is gitpod
936
+ func checkFolderPermission (t * testing.T , rsa * rpc.Client , workspace string ) {
937
+ var uid agent.ExecResponse
938
+ err := rsa .Call ("WorkspaceAgent.Exec" , & agent.ExecRequest {
939
+ Command : "stat" ,
940
+ Args : []string {"--format" , "%U" , workspace },
941
+ }, & uid )
942
+ if err != nil || uid .ExitCode != 0 || strings .Trim (uid .Stdout , " \t \n " ) != "gitpod" {
943
+ t .Fatalf ("folder %s UID %s is incorrect, err:%v, exitCode:%d" , workspace , uid .Stdout , err , uid .ExitCode )
944
+ }
945
+
946
+ var gid agent.ExecResponse
947
+ err = rsa .Call ("WorkspaceAgent.Exec" , & agent.ExecRequest {
948
+ Command : "stat" ,
949
+ Args : []string {"--format" , "%G" , workspace },
950
+ }, & gid )
951
+ if err != nil || uid .ExitCode != 0 || strings .Trim (gid .Stdout , " \t \n " ) != "gitpod" {
952
+ t .Fatalf ("folder %s GID %s is incorrect, err:%v, exitCode:%d" , workspace , gid .Stdout , err , uid .ExitCode )
953
+ }
954
+ }
955
+
956
+ // checkGitFolderPermission checks the files/folders UID and GID under .git/ is gitpod
930
957
func checkGitFolderPermission (t * testing.T , rsa * rpc.Client , workspaceRoot string ) {
931
958
var findUserResp agent.ExecResponse
932
959
var gitDir string = fmt .Sprintf ("%s/%s" , workspaceRoot , ".git" )
@@ -937,7 +964,7 @@ func checkGitFolderPermission(t *testing.T, rsa *rpc.Client, workspaceRoot strin
937
964
Args : []string {"!" , "-user" , "gitpod" },
938
965
}, & findUserResp )
939
966
if err != nil || findUserResp .ExitCode != 0 || strings .Trim (findUserResp .Stdout , " \t \n " ) != "" {
940
- t .Fatalf ("incorrect file perimssion under %s folder, err:%v, exitCode:%d, stdout:%s" , gitDir , err , findUserResp .ExitCode , findUserResp .Stdout )
967
+ t .Fatalf ("incorrect UID under %s folder, err:%v, exitCode:%d, stdout:%s" , gitDir , err , findUserResp .ExitCode , findUserResp .Stdout )
941
968
}
942
969
943
970
var findGroupResp agent.ExecResponse
@@ -947,7 +974,7 @@ func checkGitFolderPermission(t *testing.T, rsa *rpc.Client, workspaceRoot strin
947
974
Args : []string {"!" , "-group" , "gitpod" },
948
975
}, & findGroupResp )
949
976
if err != nil || findGroupResp .ExitCode != 0 || strings .Trim (findGroupResp .Stdout , " \t \n " ) != "" {
950
- t .Fatalf ("incorrect group perimssion under %s folder, err:%v, exitCode:%d, stdout:%s" , gitDir , err , findGroupResp .ExitCode , findGroupResp .Stdout )
977
+ t .Fatalf ("incorrect GID under %s folder, err:%v, exitCode:%d, stdout:%s" , gitDir , err , findGroupResp .ExitCode , findGroupResp .Stdout )
951
978
}
952
979
}
953
980
0 commit comments