Skip to content

Commit 88b22ce

Browse files
committed
test: check the /workspace UID:GID is gitpod:gitpod
Signed-off-by: JenTing Hsiao <[email protected]>
1 parent cc49077 commit 88b22ce

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

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

Lines changed: 34 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,30 @@ 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+
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
930959
func checkGitFolderPermission(t *testing.T, rsa *rpc.Client, workspaceRoot string) {
931960
var findUserResp agent.ExecResponse
932961
var gitDir string = fmt.Sprintf("%s/%s", workspaceRoot, ".git")
@@ -937,7 +966,7 @@ func checkGitFolderPermission(t *testing.T, rsa *rpc.Client, workspaceRoot strin
937966
Args: []string{"!", "-user", "gitpod"},
938967
}, &findUserResp)
939968
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)
941970
}
942971

943972
var findGroupResp agent.ExecResponse
@@ -947,7 +976,7 @@ func checkGitFolderPermission(t *testing.T, rsa *rpc.Client, workspaceRoot strin
947976
Args: []string{"!", "-group", "gitpod"},
948977
}, &findGroupResp)
949978
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)
951980
}
952981
}
953982

0 commit comments

Comments
 (0)