use EvalSymlinks to resolve 'current' to the correct version

'snappy policygen' takes a path to a yaml file as an argument. If the user
specifies /apps/foo/current/meta/package.yaml then the version is incorrectly
calculated to be 'current'. This issue was introduced in 8b04bd2d when fixing
CompareGeneratePolicyFromFile for sideloaded pkgs.

The fix adjusts parsePackageYamlFileWithVersion() to simply call EvalSymlinks()
to resolve the current symlink. Tested with store and sideloaded apps.
This commit is contained in:
Jamie Strandboge
2015-11-19 14:18:01 -06:00
parent ff2c351552
commit f61d7ad2b4
2 changed files with 39 additions and 1 deletions

View File

@@ -882,7 +882,13 @@ func parsePackageYamlFileWithVersion(fn string) (*packageYaml, error) {
// FIXME: duplicated code from snapp.go:NewSnapPartFromYaml,
// version is overriden by sideloaded versions
m.Version = filepath.Base(filepath.Dir(filepath.Dir(fn)))
// use EvalSymlinks to resolve 'current' to the correct version
dir, err := filepath.EvalSymlinks(filepath.Dir(filepath.Dir(fn)))
if err != nil {
return nil, err
}
m.Version = filepath.Base(dir)
return m, err
}

View File

@@ -35,6 +35,7 @@ import (
)
type SecurityTestSuite struct {
tempDir string
buildDir string
m *packageYaml
scFilterGenCall []string
@@ -47,6 +48,7 @@ var _ = Suite(&SecurityTestSuite{})
func (a *SecurityTestSuite) SetUpTest(c *C) {
a.buildDir = c.MkDir()
a.tempDir = c.MkDir()
os.MkdirAll(filepath.Join(a.buildDir, "meta"), 0755)
// set global sandbox
@@ -1017,3 +1019,33 @@ func (a *SecurityTestSuite) TestSecurityGeneratePolicyForServiceBinaryErrors(c *
err := sd.generatePolicyForServiceBinary(m, "binary", "/apps/app-no-origin/1.0")
c.Assert(err, ErrorMatches, "invalid package on system")
}
func (s *SecurityTestSuite) TestParsePackageYamlWithVersion(c *C) {
testVersion := "1.0"
dir := filepath.Join(s.tempDir, "foo", testVersion, "meta")
os.MkdirAll(dir, 0755)
y := filepath.Join(dir, "package.yaml")
ioutil.WriteFile(y, []byte(`
name: foo
version: 123456789
`), 0644)
m, err := parsePackageYamlFileWithVersion(y)
c.Assert(err, IsNil)
c.Assert(m.Version, Equals, testVersion)
}
func (s *SecurityTestSuite) TestParsePackageYamlWithVersionSymlink(c *C) {
testVersion := "1.0"
verDir := filepath.Join(s.tempDir, "foo", testVersion)
symDir := filepath.Join(s.tempDir, "foo", "current")
os.MkdirAll(filepath.Join(verDir, "meta"), 0755)
os.Symlink(verDir, symDir)
y := filepath.Join(symDir, "meta", "package.yaml")
ioutil.WriteFile(y, []byte(`
name: foo
version: 123456789
`), 0644)
m, err := parsePackageYamlFileWithVersion(y)
c.Assert(err, IsNil)
c.Assert(m.Version, Equals, testVersion)
}