@@ -20,7 +20,7 @@ func TestPoller(t *testing.T) {
20
20
backend := signing .NewFakeBackend ()
21
21
rng := rand .New (rand .NewSource (1234 ))
22
22
23
- certificates , powerTable := polling .MakeCertificates (t , rng , backend )
23
+ cg := polling .MakeCertificates (t , rng , backend )
24
24
25
25
ctx , cancel := context .WithCancel (context .Background ())
26
26
defer cancel ()
@@ -37,12 +37,11 @@ func TestPoller(t *testing.T) {
37
37
38
38
serverDs := ds_sync .MutexWrap (datastore .NewMapDatastore ())
39
39
40
- serverCs , err := certstore .CreateStore (ctx , serverDs , 0 , powerTable )
40
+ serverCs , err := certstore .CreateStore (ctx , serverDs , 0 , cg . PowerTable )
41
41
require .NoError (t , err )
42
42
43
- certificatesAdded := 10
44
- for _ , cert := range certificates [:certificatesAdded ] {
45
- require .NoError (t , serverCs .Put (ctx , cert ))
43
+ for cg .NextInstance < 10 {
44
+ require .NoError (t , serverCs .Put (ctx , cg .MakeCertificate ()))
46
45
}
47
46
48
47
server := certexchange.Server {
@@ -55,7 +54,7 @@ func TestPoller(t *testing.T) {
55
54
t .Cleanup (func () { require .NoError (t , server .Stop ()) })
56
55
57
56
clientDs := ds_sync .MutexWrap (datastore .NewMapDatastore ())
58
- clientCs , err := certstore .CreateStore (ctx , clientDs , 0 , powerTable )
57
+ clientCs , err := certstore .CreateStore (ctx , clientDs , 0 , cg . PowerTable )
59
58
require .NoError (t , err )
60
59
61
60
client := certexchange.Client {
@@ -82,21 +81,21 @@ func TestPoller(t *testing.T) {
82
81
res , err := poller .Poll (ctx , serverHost .ID ())
83
82
require .NoError (t , err )
84
83
require .Equal (t , polling .PollHit , res .Status )
85
- require .Equal (t , uint64 ( certificatesAdded ) , poller .NextInstance )
84
+ require .Equal (t , cg . NextInstance , poller .NextInstance )
86
85
}
87
86
88
87
// If we put a certificate on the client, we should call it a _miss_
89
88
{
90
- require .NoError (t , clientCs .Put (ctx , certificates [certificatesAdded ]))
89
+ cert := cg .MakeCertificate ()
90
+ require .NoError (t , clientCs .Put (ctx , cert ))
91
91
92
92
res , err := poller .Poll (ctx , serverHost .ID ())
93
93
require .NoError (t , err )
94
94
require .Equal (t , polling .PollMiss , res .Status )
95
- }
96
95
97
- // Add that cert to the server.
98
- require .NoError (t , serverCs .Put (ctx , certificates [ certificatesAdded ] ))
99
- certificatesAdded ++
96
+ // Add that cert to the server.
97
+ require .NoError (t , serverCs .Put (ctx , cert ))
98
+ }
100
99
101
100
// And now it's a hit!
102
101
{
@@ -106,31 +105,31 @@ func TestPoller(t *testing.T) {
106
105
}
107
106
108
107
// Add more than the request maximum (up till the last cert)
109
- for ; certificatesAdded < len ( certificates ) - 1 ; certificatesAdded ++ {
110
- require .NoError (t , serverCs .Put (ctx , certificates [ certificatesAdded ] ))
108
+ for cg . NextInstance < 500 {
109
+ require .NoError (t , serverCs .Put (ctx , cg . MakeCertificate () ))
111
110
}
112
111
113
112
// We should poll multiple times and completely catch up.
114
113
{
115
114
res , err := poller .Poll (ctx , serverHost .ID ())
116
115
require .NoError (t , err )
117
116
require .Equal (t , polling .PollHit , res .Status )
118
- require .Equal (t , uint64 ( certificatesAdded ) , poller .NextInstance )
117
+ require .Equal (t , cg . NextInstance , poller .NextInstance )
119
118
}
120
119
121
120
// We catch evil servers!
122
121
{
123
- lastCert := certificates [ certificatesAdded ]
124
- lastCert .Signature = []byte ("bad sig" )
125
- require .NoError (t , serverCs .Put (ctx , lastCert ))
122
+ badCert := cg . MakeCertificate ()
123
+ badCert .Signature = []byte ("bad sig" )
124
+ require .NoError (t , serverCs .Put (ctx , badCert ))
126
125
127
126
res , err := poller .Poll (ctx , serverHost .ID ())
128
127
require .NoError (t , err )
129
128
require .Equal (t , polling .PollIllegal , res .Status )
130
129
131
130
// And we don't store certificates from them!
132
- require .Equal (t , uint64 ( certificatesAdded ) , poller .NextInstance )
133
- _ , err = clientCs .Get (ctx , lastCert .GPBFTInstance )
131
+ require .Equal (t , badCert . GPBFTInstance , poller .NextInstance )
132
+ _ , err = clientCs .Get (ctx , badCert .GPBFTInstance )
134
133
require .ErrorIs (t , err , certstore .ErrCertNotFound )
135
134
}
136
135
0 commit comments