@@ -896,6 +896,7 @@ func (s *ClientSuite) TestUpdateMixAndMatchAttack(c *C) {
896896 c .Assert (s .repo .AddTargetWithExpires ("foo.txt" , nil , expires ), IsNil )
897897 c .Assert (s .repo .Snapshot (), IsNil )
898898 c .Assert (s .repo .Timestamp (), IsNil )
899+ c .Assert (s .repo .Commit (), IsNil )
899900 s .syncRemote (c )
900901 client := s .updatedClient (c )
901902
@@ -909,6 +910,7 @@ func (s *ClientSuite) TestUpdateMixAndMatchAttack(c *C) {
909910 c .Assert (s .repo .AddTargetWithExpires ("bar.txt" , nil , expires ), IsNil )
910911 c .Assert (s .repo .Snapshot (), IsNil )
911912 c .Assert (s .repo .Timestamp (), IsNil )
913+ c .Assert (s .repo .Commit (), IsNil )
912914 s .syncRemote (c )
913915 newTargets , ok := s .remote .meta ["targets.json" ]
914916 if ! ok {
@@ -964,6 +966,41 @@ func (s *ClientSuite) TestUpdateReplayAttack(c *C) {
964966 })
965967}
966968
969+ func (s * ClientSuite ) TestUpdateForkTimestamp (c * C ) {
970+ client := s .updatedClient (c )
971+
972+ // grab the remote timestamp.json
973+ oldTimestamp , ok := s .remote .meta ["timestamp.json" ]
974+ if ! ok {
975+ c .Fatal ("missing remote timestamp.json" )
976+ }
977+
978+ // generate a new timestamp and sync with the client
979+ version := client .timestampVer
980+ c .Assert (version > 0 , Equals , true )
981+ c .Assert (s .repo .Timestamp (), IsNil )
982+ s .syncRemote (c )
983+ _ , err := client .Update ()
984+ c .Assert (err , IsNil )
985+ newVersion := client .timestampVer
986+ c .Assert (newVersion > version , Equals , true )
987+
988+ // generate a new, different timestamp with the *same version*
989+ s .remote .meta ["timestamp.json" ] = oldTimestamp
990+ c .Assert (s .repo .Timestamp (), IsNil )
991+ c .Assert (client .timestampVer , Equals , newVersion ) // double-check: same version?
992+ s .syncRemote (c )
993+
994+ oldMeta , err := client .local .GetMeta ()
995+ c .Assert (err , IsNil )
996+ _ , err = client .Update ()
997+ c .Assert (err , IsNil ) // no error: the targets.json version didn't change, so there was no update!
998+ // Client shouldn't update!
999+ newMeta , err := client .local .GetMeta ()
1000+ c .Assert (err , IsNil )
1001+ c .Assert (oldMeta , DeepEquals , newMeta )
1002+ }
1003+
9671004func (s * ClientSuite ) TestUpdateTamperedTargets (c * C ) {
9681005 client := s .newClient (c )
9691006
@@ -998,6 +1035,7 @@ func (s *ClientSuite) TestUpdateTamperedTargets(c *C) {
9981035 c .Assert (err , IsNil )
9991036 s .store .SetMeta ("targets.json" , tamperedJSON )
10001037 s .store .Commit (false , nil , nil )
1038+ c .Assert (s .repo .Timestamp (), IsNil ) // unless timestamp changes, the client doesn't even look at "targets.json"
10011039 s .syncRemote (c )
10021040 _ , err = client .Update ()
10031041 c .Assert (err , DeepEquals , ErrWrongSize {"targets.json" , int64 (len (tamperedJSON )), int64 (len (targetsJSON ))})
0 commit comments