mirror of
https://github.com/token2/snapd.git
synced 2026-03-13 11:15:47 -07:00
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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user