@@ -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,30 @@ 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
+ Dir : workspace ,
940
+ Command : "stat" ,
941
+ Args : []string {"-c" , "%U" },
942
+ }, & uid )
943
+ if err != nil || uid .ExitCode != 0 || strings .Trim (uid .Stdout , " \t \n " ) != "gitpod" {
944
+ t .Fatalf ("folder %s UID %s is incorrect, err:%v, exitCode:%d" , workspace , uid .Stdout , err , uid .ExitCode )
945
+ }
946
+
947
+ var gid agent.ExecResponse
948
+ err = rsa .Call ("WorkspaceAgent.Exec" , & agent.ExecRequest {
949
+ Dir : workspace ,
950
+ Command : "stat" ,
951
+ Args : []string {"-c" , "%G" },
952
+ }, & gid )
953
+ if err != nil || uid .ExitCode != 0 || strings .Trim (gid .Stdout , " \t \n " ) != "gitpod" {
954
+ t .Fatalf ("folder %s GID %s is incorrect, err:%v, exitCode:%d" , workspace , gid .Stdout , err , uid .ExitCode )
955
+ }
956
+ }
957
+
958
+ // checkGitFolderPermission checks the files/folders UID and GID under .git/ is gitpod
930
959
func checkGitFolderPermission (t * testing.T , rsa * rpc.Client , workspaceRoot string ) {
931
960
var findUserResp agent.ExecResponse
932
961
var gitDir string = fmt .Sprintf ("%s/%s" , workspaceRoot , ".git" )
@@ -937,7 +966,7 @@ func checkGitFolderPermission(t *testing.T, rsa *rpc.Client, workspaceRoot strin
937
966
Args : []string {"!" , "-user" , "gitpod" },
938
967
}, & findUserResp )
939
968
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 )
969
+ t .Fatalf ("incorrect UID under %s folder, err:%v, exitCode:%d, stdout:%s" , gitDir , err , findUserResp .ExitCode , findUserResp .Stdout )
941
970
}
942
971
943
972
var findGroupResp agent.ExecResponse
@@ -947,7 +976,7 @@ func checkGitFolderPermission(t *testing.T, rsa *rpc.Client, workspaceRoot strin
947
976
Args : []string {"!" , "-group" , "gitpod" },
948
977
}, & findGroupResp )
949
978
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 )
979
+ t .Fatalf ("incorrect GID under %s folder, err:%v, exitCode:%d, stdout:%s" , gitDir , err , findGroupResp .ExitCode , findGroupResp .Stdout )
951
980
}
952
981
}
953
982
0 commit comments