Skip to content
This repository was archived by the owner on Apr 30, 2021. It is now read-only.

Commit 77f5ca1

Browse files
author
Yevgeny Pats
committed
Add error handling to refresh token
1 parent b67df0f commit 77f5ca1

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

client/agent.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ func (c *FuzzitClient) runlibFuzzerMerge() error {
109109
return err
110110
}
111111

112-
c.refreshToken()
112+
if err := c.refreshToken(true); err != nil {
113+
return err
114+
}
113115
if err := c.archiveAndUpload("merge",
114116
fmt.Sprintf("orgs/%s/targets/%s/corpus.tar.gz", c.Org, c.targetId),
115117
"corpus.tar.gz"); err != nil {
@@ -191,7 +193,9 @@ func (c *FuzzitClient) runLibFuzzerFuzzing() error {
191193
select {
192194
case <-timeout:
193195
var fuzzingJob job
194-
c.refreshToken()
196+
if err := c.refreshToken(true); err != nil {
197+
return err
198+
}
195199
docRef := c.firestoreClient.Doc(fmt.Sprintf("orgs/%s/targets/%s/jobs/%s", c.Org, c.targetId, c.jobId))
196200
if docRef == nil {
197201
return fmt.Errorf("invalid resource")
@@ -239,7 +243,9 @@ func (c *FuzzitClient) runLibFuzzerFuzzing() error {
239243
}
240244
}
241245

242-
c.refreshToken()
246+
if err := c.refreshToken(true); err != nil {
247+
return err
248+
}
243249
err = c.uploadCrash(exitCode)
244250
if err != nil {
245251
return err
@@ -361,19 +367,22 @@ func (c *FuzzitClient) transitionStatus(status string) error {
361367
}
362368

363369
func (c *FuzzitClient) RunLibFuzzer(targetId string, jobId string, updateDB bool, fuzzingType string) error {
364-
err := c.refreshToken()
370+
if err := c.refreshToken(true); err != nil {
371+
return err
372+
}
373+
365374
c.targetId = targetId
366375
c.jobId = jobId
367376
c.updateDB = updateDB
368377

369-
if err = c.transitionToInProgress(); err != nil {
378+
if err := c.transitionToInProgress(); err != nil {
370379
return err
371380
}
372381

373-
if err = os.Mkdir("corpus", 0644); err != nil {
382+
if err := os.Mkdir("corpus", 0644); err != nil {
374383
return err
375384
}
376-
if err = os.Mkdir("seed", 0644); err != nil {
385+
if err := os.Mkdir("seed", 0644); err != nil {
377386
return err
378387
}
379388

@@ -411,6 +420,7 @@ func (c *FuzzitClient) RunLibFuzzer(targetId string, jobId string, updateDB bool
411420
}
412421
}
413422

423+
var err error
414424
if fuzzingType == "regression" {
415425
err = c.runLibFuzzerRegression()
416426
} else {

client/auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
"google.golang.org/api/option"
1616
)
1717

18-
func (c *FuzzitClient) refreshToken() error {
19-
if c.IdToken == "" || (time.Now().Unix()-c.LastRefresh) > 60*45 {
18+
func (c *FuzzitClient) refreshToken(force bool) error {
19+
if c.IdToken == "" || (time.Now().Unix()-c.LastRefresh) > 60*45 || force {
2020
createCustomTokenEndpoint := fmt.Sprintf("%s/createCustomToken?api_key=%s", FuzzitEndpoint, url.QueryEscape(c.ApiKey))
2121
r, err := c.httpClient.Get(createCustomTokenEndpoint)
2222
if err != nil {

client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
const FuzzitEndpoint = "https://app.fuzzit.dev"
13-
const Version = "v2.4.43"
13+
const Version = "v2.4.44"
1414

1515
type Target struct {
1616
Name string `firestore:"target_name"`
@@ -73,7 +73,7 @@ func NewFuzzitClient(apiKey string) (*FuzzitClient, error) {
7373
c := &FuzzitClient{}
7474
c.httpClient = &http.Client{Timeout: 60 * time.Second}
7575
c.ApiKey = apiKey
76-
err := c.refreshToken()
76+
err := c.refreshToken(false)
7777
if err != nil {
7878
return nil, err
7979
}

client/commands.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (c *FuzzitClient) DownloadFuzzer(dst string, target string, job string) err
121121
}
122122

123123
func (c *FuzzitClient) GetResource(resource string) error {
124-
err := c.refreshToken()
124+
err := c.refreshToken(false)
125125
if err != nil {
126126
return err
127127
}
@@ -178,7 +178,7 @@ func (c *FuzzitClient) GetResource(resource string) error {
178178
}
179179

180180
func (c *FuzzitClient) CreateTarget(target Target, seedPath string, skipIsExists bool) (*firestore.DocumentRef, error) {
181-
err := c.refreshToken()
181+
err := c.refreshToken(false)
182182
if err != nil {
183183
return nil, err
184184
}
@@ -322,7 +322,7 @@ chmod a+x fuzzit
322322
}
323323

324324
func (c *FuzzitClient) CreateJob(jobConfig Job, files []string) (*firestore.DocumentRef, error) {
325-
err := c.refreshToken()
325+
err := c.refreshToken(false)
326326
if err != nil {
327327
return nil, err
328328
}

0 commit comments

Comments
 (0)