Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: rename "InitLocal" to "Init" #354

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ func NewClient(local LocalStore, remote RemoteStore) *Client {
}
}

// InitLocal initializes a local repository from root metadata.
// Init initializes a local repository from root metadata.
//
// The root's keys are extracted from the root and saved in local storage.
// Root expiration is not checked.
// It is expected that rootJSON was securely distributed with the software
// being updated.
func (c *Client) InitLocal(rootJSON []byte) error {
func (c *Client) Init(rootJSON []byte) error {
err := c.loadAndVerifyRootMeta(rootJSON, true /*ignoreExpiredCheck*/)
if err != nil {
return err
Expand Down
35 changes: 8 additions & 27 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (s *ClientSuite) rootMeta(c *C) []byte {
func (s *ClientSuite) newClient(c *C) *Client {
s.local = MemoryLocalStore()
client := NewClient(s.local, s.remote)
c.Assert(client.InitLocal(s.rootMeta(c)), IsNil)
c.Assert(client.Init(s.rootMeta(c)), IsNil)
return client
}

Expand Down Expand Up @@ -244,26 +244,7 @@ func (s *ClientSuite) assertErrExpired(c *C, err error, file string) {
c.Assert(expiredErr.Expired.Unix(), Equals, s.expiredTime.Round(time.Second).Unix())
}

func (s *ClientSuite) TestInit(c *C) {
client := NewClient(MemoryLocalStore(), s.remote)

// check invalid json
c.Assert(client.InitLocal(make([]byte, 0)), NotNil)
rootJson := `{ "signatures": [], "signed": {"version": "wrongtype"}, "spec_version": "1.0.0", "version": 1}`
err := client.InitLocal([]byte(rootJson))
c.Assert(err.Error(), Matches, "json: cannot unmarshal string.*")

// check Update() returns ErrNoRootKeys when uninitialized
_, err = client.Update()
c.Assert(err, Equals, ErrNoRootKeys)

// check Update() does not return ErrNoRootKeys after initialization
c.Assert(client.InitLocal(s.rootMeta(c)), IsNil)
_, err = client.Update()
c.Assert(err, IsNil)
}

func (s *ClientSuite) TestInitLocalAllowsExpired(c *C) {
func (s *ClientSuite) TestInitAllowsExpired(c *C) {
s.genKeyExpired(c, "targets")
c.Assert(s.repo.Snapshot(), IsNil)
c.Assert(s.repo.Timestamp(), IsNil)
Expand All @@ -273,11 +254,11 @@ func (s *ClientSuite) TestInitLocalAllowsExpired(c *C) {
bytes, err := io.ReadAll(s.remote.meta["root.json"])
c.Assert(err, IsNil)
s.withMetaExpired(func() {
c.Assert(client.InitLocal(bytes), IsNil)
c.Assert(client.Init(bytes), IsNil)
})
}

func (s *ClientSuite) TestInitLocal(c *C) {
func (s *ClientSuite) TestInit(c *C) {
client := NewClient(MemoryLocalStore(), s.remote)
bytes, err := io.ReadAll(s.remote.meta["root.json"])
c.Assert(err, IsNil)
Expand All @@ -290,7 +271,7 @@ func (s *ClientSuite) TestInitLocal(c *C) {
_, err = client.Update()
c.Assert(err, Equals, ErrNoRootKeys)

// check InitLocal() returns ErrInvalid when the root's signature is
// check Init() returns ErrInvalid when the root's signature is
// invalid
// modify root and marshal without regenerating signatures
root.Version = root.Version + 1
Expand All @@ -299,10 +280,10 @@ func (s *ClientSuite) TestInitLocal(c *C) {
dataSigned.Signed = rootBytes
dataBytes, err := json.Marshal(dataSigned)
c.Assert(err, IsNil)
c.Assert(client.InitLocal(dataBytes), Equals, verify.ErrInvalid)
c.Assert(client.Init(dataBytes), Equals, verify.ErrInvalid)

// check Update() does not return ErrNoRootKeys after initialization
c.Assert(client.InitLocal(bytes), IsNil)
c.Assert(client.Init(bytes), IsNil)
_, err = client.Update()
c.Assert(err, IsNil)
}
Expand Down Expand Up @@ -1042,7 +1023,7 @@ func (s *ClientSuite) TestUpdateHTTP(c *C) {
c.Assert(err, IsNil)
rootJsonBytes, err := json.Marshal(rootMeta)
c.Assert(err, IsNil)
c.Assert(client.InitLocal(rootJsonBytes), IsNil)
c.Assert(client.Init(rootJsonBytes), IsNil)

// check update is ok
targets, err := client.Update()
Expand Down
2 changes: 1 addition & 1 deletion client/delegations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func initTestDelegationClient(t *testing.T, dirPrefix string) (*Client, func() e
c := NewClient(MemoryLocalStore(), remote)
rawFile, err := ioutil.ReadFile(initialStateDir + "/" + "root.json")
assert.Nil(t, err)
assert.Nil(t, c.InitLocal(rawFile))
assert.Nil(t, c.Init(rawFile))
files, err := ioutil.ReadDir(initialStateDir)
assert.Nil(t, err)

Expand Down
2 changes: 1 addition & 1 deletion client/interop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (t *testCase) runStep(c *C, stepName string) {
c.Assert(err, IsNil)
rootJsonBytes, err := io.ReadAll(ioReader)
c.Assert(err, IsNil)
c.Assert(client.InitLocal(rootJsonBytes), IsNil)
c.Assert(client.Init(rootJsonBytes), IsNil)

// check update returns the correct updated targets
files, err := client.Update()
Expand Down
2 changes: 1 addition & 1 deletion client/python_interop/python_interop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (InteropSuite) TestGoClientPythonGenerated(c *C) {
client := client.NewClient(client.MemoryLocalStore(), remote)
rootJSON, err := ioutil.ReadFile(filepath.Join(testDataDir, dir, "repository", "metadata", "root.json"))
c.Assert(err, IsNil)
c.Assert(client.InitLocal(rootJSON), IsNil)
c.Assert(client.Init(rootJSON), IsNil)

// check update returns the correct updated targets
files, err := client.Update()
Expand Down
2 changes: 1 addition & 1 deletion cmd/tuf-client/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ func cmdInit(args *docopt.Args, client *tuf.Client) error {
if err != nil {
return err
}
return client.InitLocal(bytes)
return client.Init(bytes)
}