Skip to content

Commit

Permalink
Merge pull request #2815 from tonistiigi/entitlements-symlink-tests
Browse files Browse the repository at this point in the history
bake: fix entitlement test when running from symlink temp
  • Loading branch information
tonistiigi authored Nov 25, 2024
2 parents 17eff25 + 3148c09 commit 42f7898
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions bake/entitlements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,22 @@ func TestDedupePaths(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)
dir2, err := osutil.GetLongPathName(t.TempDir())
expDir2, err := filepath.EvalSymlinks(dir2)
require.NoError(t, err)

escapeLink := filepath.Join(dir1, "escape_link")
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 {
name string
Expand All @@ -208,7 +215,7 @@ func TestValidateEntitlements(t *testing.T) {
},
expected: EntitlementConf{
NetworkHost: true,
FSRead: []string{wd},
FSRead: []string{expWd},
},
},
{
Expand All @@ -222,7 +229,7 @@ func TestValidateEntitlements(t *testing.T) {
},
},
expected: EntitlementConf{
FSRead: []string{wd},
FSRead: []string{expWd},
},
},
{
Expand All @@ -236,7 +243,7 @@ func TestValidateEntitlements(t *testing.T) {
expected: EntitlementConf{
NetworkHost: true,
SecurityInsecure: true,
FSRead: []string{wd},
FSRead: []string{expWd},
},
},
{
Expand All @@ -252,7 +259,7 @@ func TestValidateEntitlements(t *testing.T) {
},
expected: EntitlementConf{
SecurityInsecure: true,
FSRead: []string{wd},
FSRead: []string{expWd},
},
},
{
Expand All @@ -266,7 +273,7 @@ func TestValidateEntitlements(t *testing.T) {
},
expected: EntitlementConf{
SSH: true,
FSRead: []string{wd},
FSRead: []string{expWd},
},
},
{
Expand Down Expand Up @@ -295,11 +302,11 @@ func TestValidateEntitlements(t *testing.T) {
},
expected: EntitlementConf{
FSWrite: func() []string {
exp := []string{dir1, dir2}
exp := []string{expDir1, expDir2}
slices.Sort(exp)
return exp
}(),
FSRead: []string{wd},
FSRead: []string{expWd},
},
},
{
Expand Down Expand Up @@ -328,7 +335,7 @@ func TestValidateEntitlements(t *testing.T) {
FSRead: []string{wd, dir1},
},
expected: EntitlementConf{
FSRead: []string{filepath.Join(dir1, "../..")},
FSRead: []string{filepath.Join(expDir1, "../..")},
},
},
{
Expand Down

0 comments on commit 42f7898

Please sign in to comment.