@@ -174,17 +174,16 @@ func (s *ClientSuite) addRemoteTarget(c *C, name string) {
174
174
s .syncRemote (c )
175
175
}
176
176
177
- func (s * ClientSuite ) rootKeys (c * C ) []* data. PublicKey {
178
- rootKeys , err := s .repo .RootKeys ( )
177
+ func (s * ClientSuite ) rootMeta (c * C ) []byte {
178
+ meta , err := s .repo .RawMeta ( "root.json" )
179
179
c .Assert (err , IsNil )
180
- c .Assert (rootKeys , HasLen , 1 )
181
- return rootKeys
180
+ return meta
182
181
}
183
182
184
183
func (s * ClientSuite ) newClient (c * C ) * Client {
185
184
s .local = MemoryLocalStore ()
186
185
client := NewClient (s .local , s .remote )
187
- c .Assert (client .Init (s .rootKeys (c ), 1 ), IsNil )
186
+ c .Assert (client .InitLocal (s .rootMeta (c )), IsNil )
188
187
return client
189
188
}
190
189
@@ -243,39 +242,21 @@ func (s *ClientSuite) assertErrExpired(c *C, err error, file string) {
243
242
c .Assert (expiredErr .Expired .Unix (), Equals , s .expiredTime .Round (time .Second ).Unix ())
244
243
}
245
244
246
- func (s * ClientSuite ) TestInitRootTooLarge (c * C ) {
247
- client := NewClient (MemoryLocalStore (), s .remote )
248
- s .remote .meta ["root.json" ] = newFakeFile (make ([]byte , defaultRootDownloadLimit + 1 ))
249
- c .Assert (client .Init (s .rootKeys (c ), 0 ), Equals , ErrMetaTooLarge {"root.json" , defaultRootDownloadLimit + 1 , defaultRootDownloadLimit })
250
- }
251
-
252
- func (s * ClientSuite ) TestInitRootExpired (c * C ) {
253
- s .genKeyExpired (c , "targets" )
254
- c .Assert (s .repo .Snapshot (), IsNil )
255
- c .Assert (s .repo .Timestamp (), IsNil )
256
- c .Assert (s .repo .Commit (), IsNil )
257
- s .syncRemote (c )
258
- client := NewClient (MemoryLocalStore (), s .remote )
259
- s .withMetaExpired (func () {
260
- s .assertErrExpired (c , client .Init (s .rootKeys (c ), 1 ), "root.json" )
261
- })
262
- }
263
-
264
245
func (s * ClientSuite ) TestInit (c * C ) {
265
246
client := NewClient (MemoryLocalStore (), s .remote )
266
247
267
- // check Init() returns keys.ErrInvalidThreshold with an invalid threshold
268
- c .Assert (client .Init ( s . rootKeys ( c ) , 0 ), Equals , verify . ErrInvalidThreshold )
269
-
270
- // check Init() returns signed.ErrRoleThreshold when not enough keys
271
- c .Assert (client . Init ( s . rootKeys ( c ), 2 ), Equals , ErrInsufficientKeys )
248
+ // check invalid json
249
+ c .Assert (client .InitLocal ( make ([] byte , 0 )), NotNil )
250
+ rootJson := `{ "signatures": [], "signed": {"version": "wrongtype"}, "spec_version": "1.0.0", "version": 1}`
251
+ err := client . InitLocal ([] byte ( rootJson ))
252
+ c .Assert (err . Error ( ), Matches , "json: cannot unmarshal string.*" )
272
253
273
254
// check Update() returns ErrNoRootKeys when uninitialized
274
- _ , err : = client .Update ()
255
+ _ , err = client .Update ()
275
256
c .Assert (err , Equals , ErrNoRootKeys )
276
257
277
258
// check Update() does not return ErrNoRootKeys after initialization
278
- c .Assert (client .Init (s .rootKeys (c ), 1 ), IsNil )
259
+ c .Assert (client .InitLocal (s .rootMeta (c )), IsNil )
279
260
_ , err = client .Update ()
280
261
c .Assert (err , IsNil )
281
262
}
@@ -489,6 +470,8 @@ func (s *ClientSuite) TestUpdateRoots(c *C) {
489
470
{"testdata/Published2Times_targets_keyrotated" , nil , map [string ]int64 {"root" : 2 , "timestamp" : 2 , "snapshot" : 2 , "targets" : 2 }},
490
471
// timestamp role key rotation increase the timestamp.
491
472
{"testdata/Published2Times_timestamp_keyrotated" , nil , map [string ]int64 {"root" : 2 , "timestamp" : 2 , "snapshot" : 1 , "targets" : 1 }},
473
+ //root file size > defaultRootDownloadLimit
474
+ {"testdata/Published2Times_roottoolarge" , ErrMetaTooLarge {Name : "2.root.json" , Size : defaultRootDownloadLimit + 1 , MaxSize : defaultRootDownloadLimit }, map [string ]int64 {}},
492
475
}
493
476
494
477
for _ , test := range tests {
@@ -1053,10 +1036,11 @@ func (s *ClientSuite) TestUpdateHTTP(c *C) {
1053
1036
remote , err := HTTPRemoteStore (fmt .Sprintf ("http://%s/%s/repository" , addr , dir ), nil , nil )
1054
1037
c .Assert (err , IsNil )
1055
1038
client := NewClient (MemoryLocalStore (), remote )
1056
- rootKeys , err := repo .RootKeys ()
1039
+ rootMeta , err := repo .SignedMeta ("root.json" )
1040
+ c .Assert (err , IsNil )
1041
+ rootJsonBytes , err := json .Marshal (rootMeta )
1057
1042
c .Assert (err , IsNil )
1058
- c .Assert (rootKeys , HasLen , 1 )
1059
- c .Assert (client .Init (rootKeys , 1 ), IsNil )
1043
+ c .Assert (client .InitLocal (rootJsonBytes ), IsNil )
1060
1044
1061
1045
// check update is ok
1062
1046
targets , err := client .Update ()
0 commit comments