Skip to content

Commit f96cbe6

Browse files
jentingroboquat
authored andcommitted
test: check the /workspace UID:GID is gitpod:gitpod
Signed-off-by: JenTing Hsiao <[email protected]>
1 parent c7cb625 commit f96cbe6

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

test/tests/components/ws-manager/prebuild_test.go

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,10 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
368368
// check prebuild log message exists
369369
checkPrebuildLogExist(t, cfg, rsa, ws, test.WorkspaceRoot)
370370

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
372375
checkGitFolderPermission(t, rsa, test.WorkspaceRoot)
373376

374377
// write file foobar.txt and stop the workspace
@@ -807,7 +810,10 @@ func TestPrebuildAndRegularWorkspaceDifferentWorkspaceClass(t *testing.T) {
807810
// check prebuild log message exists
808811
checkPrebuildLogExist(t, cfg, rsa, ws, test.WorkspaceRoot)
809812

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
811817
checkGitFolderPermission(t, rsa, test.WorkspaceRoot)
812818
})
813819
}
@@ -926,7 +932,28 @@ func checkPrebuildLogExist(t *testing.T, cfg *envconf.Config, rsa *rpc.Client, w
926932
t.Fatal("did not find someFile from previous workspace instance")
927933
}
928934

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
930957
func checkGitFolderPermission(t *testing.T, rsa *rpc.Client, workspaceRoot string) {
931958
var findUserResp agent.ExecResponse
932959
var gitDir string = fmt.Sprintf("%s/%s", workspaceRoot, ".git")
@@ -937,7 +964,7 @@ func checkGitFolderPermission(t *testing.T, rsa *rpc.Client, workspaceRoot strin
937964
Args: []string{"!", "-user", "gitpod"},
938965
}, &findUserResp)
939966
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)
941968
}
942969

943970
var findGroupResp agent.ExecResponse
@@ -947,7 +974,7 @@ func checkGitFolderPermission(t *testing.T, rsa *rpc.Client, workspaceRoot strin
947974
Args: []string{"!", "-group", "gitpod"},
948975
}, &findGroupResp)
949976
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)
951978
}
952979
}
953980

0 commit comments

Comments
 (0)