1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
//go:build !windows
// +build !windows
package client
import (
"os"
"path/filepath"
"gopkg.in/check.v1"
)
func (FileJSONStoreSuite) TestNewDirectoryExistsWrongPerm(c *check.C) {
tmp := c.MkDir()
p := filepath.Join(tmp, "tuf_raw.db")
err := os.Mkdir(p, 0750)
c.Assert(err, check.IsNil)
// Modify the directory permission and try again
err = os.Chmod(p, 0751)
c.Assert(err, check.IsNil)
s, err := NewFileJSONStore(p)
c.Assert(s, check.IsNil)
c.Assert(err, check.ErrorMatches, "permission bits for file tuf_raw.db failed.*")
}
func (FileJSONStoreSuite) TestNewNoCreate(c *check.C) {
tmp := c.MkDir()
p := filepath.Join(tmp, "tuf_raw.db")
// Clear the write bit for the user
err := os.Chmod(tmp, 0551)
c.Assert(err, check.IsNil)
s, err := NewFileJSONStore(p)
c.Assert(s, check.IsNil)
c.Assert(err, check.NotNil)
}
func (FileJSONStoreSuite) TestGetTooPermissive(c *check.C) {
tmp := c.MkDir()
p := filepath.Join(tmp, "tuf_raw.db")
s, err := NewFileJSONStore(p)
c.Assert(s, check.NotNil)
c.Assert(err, check.IsNil)
fp := filepath.Join(p, "meta.json")
err = os.WriteFile(fp, []byte{}, 0644)
c.Assert(err, check.IsNil)
md, err := s.GetMeta()
c.Assert(md, check.IsNil)
c.Assert(err, check.ErrorMatches, "permission bits for file meta.json failed.*")
}
|