...

Source file src/github.com/theupdateframework/go-tuf/client/filejsonstore/perm_test.go

Documentation: github.com/theupdateframework/go-tuf/client/filejsonstore

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

View as plain text