Merge pull request #2815 from tonistiigi/entitlements-symlink-tests

bake: fix entitlement test when running from symlink temp
This commit is contained in:
Tõnis Tiigi 2024-11-25 10:08:19 -08:00 committed by GitHub
commit 42f7898c53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -175,15 +175,22 @@ func TestDedupePaths(t *testing.T) {
} }
func TestValidateEntitlements(t *testing.T) { func TestValidateEntitlements(t *testing.T) {
dir1, err := osutil.GetLongPathName(t.TempDir()) dir1 := t.TempDir()
dir2 := t.TempDir()
// the paths returned by entitlements validation will have symlinks resolved
expDir1, err := filepath.EvalSymlinks(dir1)
require.NoError(t, err) require.NoError(t, err)
dir2, err := osutil.GetLongPathName(t.TempDir()) expDir2, err := filepath.EvalSymlinks(dir2)
require.NoError(t, err) require.NoError(t, err)
escapeLink := filepath.Join(dir1, "escape_link") escapeLink := filepath.Join(dir1, "escape_link")
require.NoError(t, os.Symlink("../../aa", escapeLink)) require.NoError(t, os.Symlink("../../aa", escapeLink))
wd := osutil.GetWd() wd, err := os.Getwd()
require.NoError(t, err)
expWd, err := filepath.EvalSymlinks(wd)
require.NoError(t, err)
tcases := []struct { tcases := []struct {
name string name string
@ -208,7 +215,7 @@ func TestValidateEntitlements(t *testing.T) {
}, },
expected: EntitlementConf{ expected: EntitlementConf{
NetworkHost: true, NetworkHost: true,
FSRead: []string{wd}, FSRead: []string{expWd},
}, },
}, },
{ {
@ -222,7 +229,7 @@ func TestValidateEntitlements(t *testing.T) {
}, },
}, },
expected: EntitlementConf{ expected: EntitlementConf{
FSRead: []string{wd}, FSRead: []string{expWd},
}, },
}, },
{ {
@ -236,7 +243,7 @@ func TestValidateEntitlements(t *testing.T) {
expected: EntitlementConf{ expected: EntitlementConf{
NetworkHost: true, NetworkHost: true,
SecurityInsecure: true, SecurityInsecure: true,
FSRead: []string{wd}, FSRead: []string{expWd},
}, },
}, },
{ {
@ -252,7 +259,7 @@ func TestValidateEntitlements(t *testing.T) {
}, },
expected: EntitlementConf{ expected: EntitlementConf{
SecurityInsecure: true, SecurityInsecure: true,
FSRead: []string{wd}, FSRead: []string{expWd},
}, },
}, },
{ {
@ -266,7 +273,7 @@ func TestValidateEntitlements(t *testing.T) {
}, },
expected: EntitlementConf{ expected: EntitlementConf{
SSH: true, SSH: true,
FSRead: []string{wd}, FSRead: []string{expWd},
}, },
}, },
{ {
@ -295,11 +302,11 @@ func TestValidateEntitlements(t *testing.T) {
}, },
expected: EntitlementConf{ expected: EntitlementConf{
FSWrite: func() []string { FSWrite: func() []string {
exp := []string{dir1, dir2} exp := []string{expDir1, expDir2}
slices.Sort(exp) slices.Sort(exp)
return exp return exp
}(), }(),
FSRead: []string{wd}, FSRead: []string{expWd},
}, },
}, },
{ {
@ -328,7 +335,7 @@ func TestValidateEntitlements(t *testing.T) {
FSRead: []string{wd, dir1}, FSRead: []string{wd, dir1},
}, },
expected: EntitlementConf{ expected: EntitlementConf{
FSRead: []string{filepath.Join(dir1, "../..")}, FSRead: []string{filepath.Join(expDir1, "../..")},
}, },
}, },
{ {