@@ -3,10 +3,13 @@ package cli_tests
3
3
import (
4
4
"encoding/hex"
5
5
"encoding/json"
6
+ "github.com/0chain/errors"
7
+ "io/ioutil"
6
8
"net/http"
7
9
"os"
8
10
"path/filepath"
9
11
"regexp"
12
+ "strconv"
10
13
"strings"
11
14
"testing"
12
15
"time"
@@ -21,6 +24,10 @@ import (
21
24
22
25
func TestRestrictedBlobbers (testSetup * testing.T ) {
23
26
t := test .NewSystemTest (testSetup )
27
+
28
+ //Auth Ticket Round expiry we can add a big round number to create the allocation.
29
+ authTokenRoundExpiry := int (1e9 )
30
+
24
31
t .SetSmokeTests ("Create allocation for locking cost equal to the cost calculated should work" )
25
32
26
33
t .TestSetup ("register wallet and get blobbers" , func () {
@@ -92,9 +99,9 @@ func TestRestrictedBlobbers(testSetup *testing.T) {
92
99
wallet , err := getWallet (t , configPath )
93
100
require .Nil (t , err , "could not get wallet" )
94
101
95
- blobber1AuthTicket , err := getBlobberAuthTicket (t , blobber1 .Id , blobber1 .Url , wallet .ClientID )
102
+ blobber1AuthTicket , err := getBlobberAuthTicket (t , blobber1 .Id , blobber1 .Url , wallet .ClientID , authTokenRoundExpiry )
96
103
require .Nil (t , err , "could not get blobber1 auth ticket" )
97
- blobber2AuthTicket , err := getBlobberAuthTicket (t , blobber2 .Id , blobber2 .Url , wallet .ClientID )
104
+ blobber2AuthTicket , err := getBlobberAuthTicket (t , blobber2 .Id , blobber2 .Url , wallet .ClientID , authTokenRoundExpiry )
98
105
require .Nil (t , err , "could not get blobber2 auth ticket" )
99
106
100
107
var preferredBlobbers , blobberAuthTickets string
@@ -114,7 +121,16 @@ func TestRestrictedBlobbers(testSetup *testing.T) {
114
121
}
115
122
}
116
123
117
- options = map [string ]interface {}{"size" : "1024" , "data" : "3" , "parity" : "3" , "lock" : "0.5" , "preferred_blobbers" : preferredBlobbers , "blobber_auth_tickets" : blobberAuthTickets , "force" : "true" }
124
+ options = map [string ]interface {}{
125
+ "size" : "1024" ,
126
+ "data" : "3" ,
127
+ "parity" : "3" ,
128
+ "lock" : "0.5" ,
129
+ "preferred_blobbers" : preferredBlobbers ,
130
+ "blobber_auth_tickets" : blobberAuthTickets ,
131
+ "auth_round_expiry" : authTokenRoundExpiry ,
132
+ "force" : "true" ,
133
+ }
118
134
output , err = createNewAllocation (t , configPath , createParams (options ))
119
135
require .Nil (t , err , strings .Join (output , "\n " ))
120
136
require .True (t , len (output ) > 0 , "expected output length be at least 1" )
@@ -216,7 +232,7 @@ func TestRestrictedBlobbers(testSetup *testing.T) {
216
232
"is_restricted" : false ,
217
233
}))
218
234
require .Nil (t , err , strings .Join (output , "\n " ))
219
- addBlobberAuthTicket , err := getBlobberAuthTicket (t , blobberID , addBlobber .BaseURL , wallet .ClientID )
235
+ addBlobberAuthTicket , err := getBlobberAuthTicket (t , blobberID , addBlobber .BaseURL , wallet .ClientID , authTokenRoundExpiry )
220
236
require .Nil (t , err )
221
237
222
238
t .Cleanup (func () {
@@ -232,6 +248,7 @@ func TestRestrictedBlobbers(testSetup *testing.T) {
232
248
"allocation" : allocationID ,
233
249
"set_third_party_extendable" : nil ,
234
250
"add_blobber" : blobberID ,
251
+ "auth_round_expiry" : authTokenRoundExpiry ,
235
252
"add_blobber_auth_ticket" : addBlobberAuthTicket ,
236
253
})
237
254
@@ -287,7 +304,7 @@ func TestRestrictedBlobbers(testSetup *testing.T) {
287
304
"is_restricted" : false ,
288
305
}))
289
306
require .Nil (t , err , strings .Join (output , "\n " ))
290
- addBlobberAuthTicket , err := getBlobberAuthTicket (t , blobberID , addBlobber .BaseURL , wallet .ClientID )
307
+ addBlobberAuthTicket , err := getBlobberAuthTicket (t , blobberID , addBlobber .BaseURL , wallet .ClientID , authTokenRoundExpiry )
291
308
require .Nil (t , err )
292
309
293
310
t .Cleanup (func () {
@@ -304,6 +321,7 @@ func TestRestrictedBlobbers(testSetup *testing.T) {
304
321
"set_third_party_extendable" : nil ,
305
322
"add_blobber" : blobberID ,
306
323
"add_blobber_auth_ticket" : addBlobberAuthTicket ,
324
+ "auth_round_expiry" : authTokenRoundExpiry ,
307
325
"remove_blobber" : removeBlobber ,
308
326
})
309
327
@@ -317,22 +335,22 @@ func TestRestrictedBlobbers(testSetup *testing.T) {
317
335
})
318
336
}
319
337
320
- func getBlobberAuthTicket (t * test.SystemTest , blobberID , blobberUrl , clientID string ) (string , error ) {
338
+ func getBlobberAuthTicket (t * test.SystemTest , blobberID , blobberURL , clientID string , authTokenRoundExpiry int ) (string , error ) {
321
339
zboxWallet , err := getWalletForName (t , configPath , zboxTeamWallet )
322
340
require .Nil (t , err , "could not get zbox wallet" )
323
341
324
342
var authTicket string
325
343
signatureScheme := zcncrypto .NewSignatureScheme ("bls0chain" )
326
- _ = signatureScheme .SetPrivateKey ("85e2119f494cd40ca524f6342e8bdb7bef2af03fe9a08c8d9c1d9f14d6c64f14 " )
344
+ _ = signatureScheme .SetPrivateKey ("26e4adfa189350df06bf1983569e03a50fb69d6112386e76610e8b08cc90a009 " )
327
345
_ = signatureScheme .SetPublicKey (zboxWallet .ClientPublicKey )
328
346
329
347
signature , err := signatureScheme .Sign (hex .EncodeToString ([]byte (zboxWallet .ClientPublicKey )))
330
348
if err != nil {
331
349
return authTicket , err
332
350
}
333
351
334
- url := blobberUrl + "/v1/auth/generate?client_id=" + clientID
335
- req , err := http .NewRequest ("GET" , url , http . NoBody )
352
+ url := blobberURL + "/v1/auth/generate?client_id=" + clientID + "&round=" + strconv . FormatInt ( int64 ( authTokenRoundExpiry ), 10 )
353
+ req , err := http .NewRequest ("GET" , url , nil )
336
354
if err != nil {
337
355
return authTicket , err
338
356
}
@@ -347,12 +365,13 @@ func getBlobberAuthTicket(t *test.SystemTest, blobberID, blobberUrl, clientID st
347
365
var responseMap map [string ]string
348
366
err = json .NewDecoder (resp .Body ).Decode (& responseMap )
349
367
if err != nil {
350
- return "" , err
368
+ var body []byte
369
+ body , err = ioutil .ReadAll (resp .Body )
370
+ return "" , errors .Wrap (err , string (body ))
351
371
}
352
372
authTicket = responseMap ["auth_ticket" ]
353
373
if authTicket == "" {
354
- return "" , common .NewError ("500" , "Error getting auth ticket from blobber" )
374
+ common .NewError ("500" , "Error getting auth ticket from blobber" )
355
375
}
356
-
357
376
return authTicket , nil
358
377
}
0 commit comments