diff --git a/client/client.go b/client/client.go index 42756f8aa..188d8a8a8 100644 --- a/client/client.go +++ b/client/client.go @@ -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 diff --git a/client/client_test.go b/client/client_test.go index c23a96662..15fbb43ae 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -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 } @@ -248,9 +248,9 @@ func (s *ClientSuite) TestInit(c *C) { client := NewClient(MemoryLocalStore(), s.remote) // check invalid json - c.Assert(client.InitLocal(make([]byte, 0)), NotNil) + c.Assert(client.Init(make([]byte, 0)), NotNil) rootJson := `{ "signatures": [], "signed": {"version": "wrongtype"}, "spec_version": "1.0.0", "version": 1}` - err := client.InitLocal([]byte(rootJson)) + err := client.Init([]byte(rootJson)) c.Assert(err.Error(), Matches, "json: cannot unmarshal string.*") // check Update() returns ErrNoRootKeys when uninitialized @@ -258,12 +258,12 @@ func (s *ClientSuite) TestInit(c *C) { c.Assert(err, Equals, ErrNoRootKeys) // check Update() does not return ErrNoRootKeys after initialization - c.Assert(client.InitLocal(s.rootMeta(c)), IsNil) + c.Assert(client.Init(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) @@ -273,11 +273,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) @@ -290,7 +290,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 @@ -299,10 +299,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) } @@ -1042,7 +1042,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() diff --git a/client/delegations_test.go b/client/delegations_test.go index c7303aca1..250e7b700 100644 --- a/client/delegations_test.go +++ b/client/delegations_test.go @@ -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) diff --git a/client/interop_test.go b/client/interop_test.go index 8e4becbca..15ece0d33 100644 --- a/client/interop_test.go +++ b/client/interop_test.go @@ -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() diff --git a/client/python_interop/python_interop_test.go b/client/python_interop/python_interop_test.go index 7a4abdc6a..e2e2a9157 100644 --- a/client/python_interop/python_interop_test.go +++ b/client/python_interop/python_interop_test.go @@ -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() diff --git a/cmd/tuf-client/init.go b/cmd/tuf-client/init.go index f043c0b7c..b3a0f6aef 100644 --- a/cmd/tuf-client/init.go +++ b/cmd/tuf-client/init.go @@ -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) }