@@ -28,9 +28,9 @@ import (
2828 "github.com/google/trillian/crypto"
2929 "github.com/google/trillian/crypto/keys/pem"
3030
31- "github.com/google/keytransparency/core/fake"
32- "github.com/google/keytransparency/core/crypto/signatures"
3331 "github.com/google/keytransparency/cmd/keytransparency-client/grpcc"
32+ "github.com/google/keytransparency/core/crypto/signatures"
33+ "github.com/google/keytransparency/core/fake"
3434)
3535
3636const (
@@ -46,9 +46,9 @@ func TestMonitor(t *testing.T) {
4646 env := NewEnv (t )
4747 defer env .Close (t )
4848 env .Client .RetryCount = 0
49-
50- // setup monitor:
49+ fakeAuth := GetNewOutgoingContextWithFakeAuth ("test@test.com" )
5150 c := spb .NewKeyTransparencyServiceClient (env .Conn )
51+ // setup monitor:
5252 resp , err := c .GetDomainInfo (bctx , & kpb.GetDomainInfoRequest {})
5353 if err != nil {
5454 t .Fatalf ("Couldn't retrieve domain info: %v" , err )
@@ -57,57 +57,60 @@ func TestMonitor(t *testing.T) {
5757 if err != nil {
5858 t .Fatalf ("Couldn't create signer: %v" , err )
5959 }
60- // logTree := resp.Log
60+ logTree := resp .Log
6161 mapTree := resp .Map
62+ _ = logTree
6263 store := storage .New ()
6364 // TODO(ismail): setup and use a real logVerifier instead:
6465 mon , err := monitor .New (fake .NewFakeTrillianLogVerifier (), mapTree , crypto .NewSHA256Signer (signer ), store )
6566 if err != nil {
6667 t .Fatalf ("Couldn't create monitor: %v" , err )
6768 }
68- // Initialization and CreateEpoch is called by NewEnv
6969 mcc := mupb .NewMutationServiceClient (env .Conn )
7070 mutCli := client .New (mcc , time .Second )
71- // verify first SMR
72- mutResp , err := mutCli .PollMutations (bctx , 1 )
73- if err != nil {
74- t .Fatalf ("Could not query mutations: %v" , err )
75- }
76- if err := mon .Process (mutResp ); err != nil {
77- t .Fatalf ("Monitor could process mutations: %v" , err )
78- }
79- mresp , err := store .Get (1 )
80- if err != nil {
81- t .Fatalf ("Could not read monitoring response: %v" , err )
82- }
83- for _ , err := range mresp .Errors {
84- t .Errorf ("Got error: %v" , err )
85- }
8671
87- // client sends one mutation, sequencer "signs", monitor verifies
88- userID := "test@test.com"
89- signers := []signatures.Signer {createSigner (t , testPrivKey1 )}
90- authorizedKeys := []* kpb.PublicKey {getAuthorizedKey (testPubKey1 )}
72+ for _ , tc := range []struct {
73+ // the userIDs to update, if no userIDs are provided, no update request
74+ // will be send before querying
75+ userIDs []string
76+ updateData []byte
77+ signers []signatures.Signer
78+ authorizedKeys []* kpb.PublicKey
79+ // the epoch to query after sending potential updates
80+ queryEpoch int64
81+ }{
82+ // query first epoch, don't update
83+ {[]string {}, nil , nil , nil , 1 },
84+ // create one mutation and new epoch (not forced like in sequencer):
85+ {[]string {"test@test.com" }, []byte ("testData" ), []signatures.Signer {createSigner (t , testPrivKey1 )}, []* kpb.PublicKey {getAuthorizedKey (testPubKey1 )}, 2 },
9186
92- _ , err = env .Client .Update (GetNewOutgoingContextWithFakeAuth ("test@test.com" ), userID , appID , []byte ("testProfile" ), signers , authorizedKeys )
93- if err != grpcc .ErrRetry {
94- t .Fatalf ("Could not send update request: %v" , err )
95- }
96- if err := env .Signer .CreateEpoch (bctx , false ); err != nil {
97- t .Errorf ("CreateEpoch(_): %v" , err )
98- }
99- mutResp , err = mutCli .PollMutations (bctx , 2 )
100- if err != nil {
101- t .Fatalf ("Could not query mutations: %v" , err )
102- }
103- if err := mon .Process (mutResp ); err != nil {
104- t .Fatalf ("Monitor could not process mutations: %v" , err )
105- }
106- mresp , err = store .Get (2 )
107- if err != nil {
108- t .Fatalf ("Could not read monitoring response: %v" , err )
109- }
110- for _ , err := range mresp .Errors {
111- t .Errorf ("Got error: %v" , err )
87+ // create several mutations and new epoch
88+
89+ } {
90+ // iterate over it
91+ for _ , userID := range tc .userIDs {
92+ _ , err = env .Client .Update (fakeAuth , userID , appID , tc .updateData , tc .signers , tc .authorizedKeys )
93+ if err != grpcc .ErrRetry {
94+ t .Fatalf ("Could not send update request: %v" , err )
95+ }
96+ }
97+
98+ if err := env .Signer .CreateEpoch (bctx , false ); err != nil {
99+ t .Errorf ("CreateEpoch(_): %v" , err )
100+ }
101+ mutResp , err := mutCli .PollMutations (bctx , tc .queryEpoch )
102+ if err != nil {
103+ t .Fatalf ("Could not query mutations: %v" , err )
104+ }
105+ if err := mon .Process (mutResp ); err != nil {
106+ t .Fatalf ("Monitor could not process mutations: %v" , err )
107+ }
108+ mresp , err := store .Get (tc .queryEpoch )
109+ if err != nil {
110+ t .Fatalf ("Could not read monitoring response: %v" , err )
111+ }
112+ for _ , err := range mresp .Errors {
113+ t .Errorf ("Got error: %v" , err )
114+ }
112115 }
113116}
0 commit comments